-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into 186771101_vlp_rest_xml_updates
- Loading branch information
Showing
12 changed files
with
1,381 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
lib/aca_entities/fdsh/ridp/rj139/operations/cms_primary_response_to_cv3_primary_response.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require "json-schema" | ||
|
||
module AcaEntities | ||
module Fdsh | ||
module Ridp | ||
module Rj139 | ||
module Operations | ||
# convert cms ridp primary response payload into a cv3 primary request | ||
class CmsPrimaryResponseToCv3PrimaryResponse | ||
include Dry::Monads[:result, :do, :try] | ||
|
||
def call(params) | ||
payload = yield validate_payload(params) | ||
response = yield construct_primary_response(payload) | ||
validate_primary_response(response) | ||
end | ||
|
||
private | ||
|
||
def validate_payload(payload) | ||
schema_data = JSON.parse(File.read(Pathname.pwd.join("lib/aca_entities/fdsh/ridp/rj139/schemas/RIDP-Response-schema.json"))) | ||
|
||
result = begin | ||
JSON::Validator.fully_validate(schema_data, JSON.parse(payload.to_json)) | ||
rescue JSON::Schema::ValidationError => e | ||
e.message | ||
end | ||
result.empty? ? Success(payload) : Failure(result.to_s) | ||
end | ||
|
||
def construct_primary_response(payload) | ||
parsed_paylod = JSON.parse(payload.to_json) | ||
ridp = parsed_paylod["ridpResponse"] | ||
result_hash = { | ||
Response: { | ||
ResponseMetadata: { | ||
ResponseCode: ridp["responseMetadata"]["responseCode"], | ||
ResponseDescriptionText: ridp["responseMetadata"]["responseText"], | ||
TDSResponseDescriptionText: ridp["responseMetadata"]["tdsResponseText"] | ||
}, | ||
VerificationResponse: { | ||
SessionIdentification: ridp["sessionIdentification"], | ||
DSHReferenceNumber: ridp["hubReferenceNumber"], | ||
FinalDecisionCode: ridp["finalDecisionCode"], | ||
VerificationQuestions: get_question_set(ridp) | ||
} | ||
} | ||
} | ||
|
||
Success(result_hash) | ||
end | ||
|
||
def get_question_set(ridp) | ||
return unless ridp.keys.include?("verificationQuestionArray") | ||
|
||
verification_question_set = [] | ||
|
||
ridp["verificationQuestionArray"].each do |question_set| | ||
mapped_array = { | ||
VerificationQuestionText: question_set["verificationQuestionSet"]["verificationQuestionText"], | ||
VerificationAnswerChoiceText: question_set["verificationQuestionSet"]["verificationAnswerChoiceArray"].map do |c| | ||
c["verificationAnswerChoiceText"] | ||
end | ||
} | ||
verification_question_set << mapped_array | ||
end | ||
|
||
{ VerificationQuestionSet: verification_question_set } | ||
end | ||
|
||
def validate_primary_response(payload) | ||
result = ::AcaEntities::Fdsh::Ridp::H139::PrimaryResponseContract.new.call(payload) | ||
|
||
if result.success? | ||
Success(payload) | ||
else | ||
Failure("Invalid response, #{result.errors.to_h}") | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
69 changes: 69 additions & 0 deletions
69
...a_entities/fdsh/ridp/rj139/operations/cms_secondary_response_to_cv3_secondary_response.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require "json-schema" | ||
|
||
module AcaEntities | ||
module Fdsh | ||
module Ridp | ||
module Rj139 | ||
module Operations | ||
# convert cms ridp secondary response payload into a cv3 secondary request | ||
class CmsSecondaryResponseToCv3SecondaryResponse | ||
include Dry::Monads[:result, :do, :try] | ||
|
||
def call(params) | ||
payload = yield validate_payload(params) | ||
response = yield construct_secondary_response(payload) | ||
validate_secondary_response(response) | ||
end | ||
|
||
private | ||
|
||
def validate_payload(payload) | ||
schema_data = JSON.parse(File.read(Pathname.pwd.join("lib/aca_entities/fdsh/ridp/rj139/schemas/RIDP-Response-schema.json"))) | ||
|
||
result = begin | ||
JSON::Validator.fully_validate(schema_data, JSON.parse(payload.to_json)) | ||
rescue JSON::Schema::ValidationError => e | ||
e.message | ||
end | ||
result.empty? ? Success(payload) : Failure(result.to_s) | ||
end | ||
|
||
def construct_secondary_response(payload) | ||
parsed_paylod = JSON.parse(payload.to_json) | ||
ridp = parsed_paylod["ridpResponse"] | ||
result_hash = { | ||
Response: { | ||
ResponseMetadata: { | ||
ResponseCode: ridp["responseMetadata"]["responseCode"], | ||
ResponseDescriptionText: ridp["responseMetadata"]["responseText"], | ||
TDSResponseDescriptionText: ridp["responseMetadata"]["tdsResponseText"] | ||
}, | ||
VerificationResponse: { | ||
SessionIdentification: ridp["sessionIdentification"], | ||
DSHReferenceNumber: ridp["hubReferenceNumber"], | ||
FinalDecisionCode: ridp["finalDecisionCode"] | ||
} | ||
} | ||
} | ||
Success(result_hash) | ||
end | ||
|
||
def validate_secondary_response(payload) | ||
result = ::AcaEntities::Fdsh::Ridp::H139::SecondaryResponseContract.new.call(payload) | ||
|
||
if result.success? | ||
Success(payload) | ||
else | ||
Failure("Invalid response, #{result.errors.to_h}") | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
60 changes: 60 additions & 0 deletions
60
lib/aca_entities/fdsh/ridp/rj139/operations/evidence_to_secondary_request.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require "json-schema" | ||
|
||
module AcaEntities | ||
module Fdsh | ||
module Ridp | ||
module Rj139 | ||
module Operations | ||
# convert evidence entity to ridp secondary request | ||
class EvidenceToSecondaryRequest | ||
include Dry::Monads[:result, :do, :try] | ||
|
||
def call(params) | ||
payload = yield construct_initial_request(params) | ||
validate_payload(payload) | ||
end | ||
|
||
private | ||
|
||
def construct_initial_request(payload) | ||
request = { ridpRequest: { secondaryRequest: construct_primary_request(payload) } } | ||
Success(request) | ||
end | ||
|
||
def construct_primary_request(payload) | ||
{ | ||
verificationAnswerArray: construct_answer_array(payload[:VerificationAnswerSet]), | ||
sessionIdentification: payload[:SessionIdentification], | ||
hubReferenceNumber: payload[:transmission_id] | ||
} | ||
end | ||
|
||
def construct_answer_array(answers) | ||
answers[:VerificationAnswers].collect do |answer| | ||
{ verificationAnswerSet: { verificationAnswer: answer[:VerificatonAnswer]&.to_s, | ||
verificationQuestionNumber: answer[:VerificationQuestionNumber]&.to_s } } | ||
end | ||
end | ||
|
||
def validate_payload(payload) | ||
schema_data = JSON.parse(File.read(Pathname.pwd.join("lib/aca_entities/fdsh/ridp/rj139/schemas/RIDP-Request-schema.json"))) | ||
|
||
# CMS requested no blank data be sent in the request | ||
payload[:ridpRequest][:secondaryRequest].delete_if { |_k, v| v.blank? } | ||
|
||
result = begin | ||
JSON::Validator.fully_validate(schema_data, JSON.parse(payload.to_json)) | ||
rescue JSON::Schema::ValidationError => e | ||
e.message | ||
end | ||
result.empty? ? Success(payload.to_json) : Failure(result.to_s) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
93 changes: 93 additions & 0 deletions
93
lib/aca_entities/fdsh/ridp/rj139/operations/person_to_primary_request.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require "json-schema" | ||
|
||
module AcaEntities | ||
module Fdsh | ||
module Ridp | ||
module Rj139 | ||
module Operations | ||
# convert person entity to ridp primary request | ||
class PersonToPrimaryRequest | ||
include Dry::Monads[:result, :do, :try] | ||
|
||
def call(params) | ||
payload = yield construct_initial_request(params) | ||
validate_payload(payload) | ||
end | ||
|
||
private | ||
|
||
def construct_initial_request(payload) | ||
request = { ridpRequest: { primaryRequest: construct_primary_request(payload) } } | ||
Success(request) | ||
end | ||
|
||
def construct_primary_request(payload) | ||
{ | ||
person: construct_person_demographics(payload), | ||
contactInformation: construct_contact_information(payload) | ||
} | ||
end | ||
|
||
def construct_person_demographics(payload) | ||
{ | ||
personSurName: payload.person_name.last_name&.gsub(/[^A-Za-z]/, ''), | ||
personMiddleName: payload.person_name.middle_name&.gsub(/[^A-Za-z]/, ''), | ||
personGivenName: payload.person_name.first_name&.gsub(/[^A-Za-z]/, ''), | ||
personBirthDate: construct_birth_date(payload), | ||
personSuffixName: payload.person_name.name_sfx&.gsub(/[^A-Za-z]/, ''), | ||
personSocialSecurityNumber: decrypt_ssn(payload.person_demographics.encrypted_ssn), | ||
personPreferredLanguage: construct_language_code(payload.person_demographics&.language_code) | ||
} | ||
end | ||
|
||
def construct_language_code(language_preference) | ||
lan_mapper = { 'en' => 'eng', 'es' => 'spa' } | ||
return 'eng' unless lan_mapper.keys.include?(language_preference) | ||
lan_mapper[language_preference] | ||
end | ||
|
||
def construct_birth_date(person) | ||
person&.person_demographics&.dob | ||
end | ||
|
||
def decrypt_ssn(encrypted_ssn) | ||
return nil if encrypted_ssn.blank? | ||
|
||
AcaEntities::Operations::Encryption::Decrypt.new.call({ value: encrypted_ssn }).value! | ||
end | ||
|
||
def construct_contact_information(payload) | ||
home_address = payload.home_address || payload.addresses&.last | ||
home_phone = payload.phones ? (payload.home_phone || payload.phones&.last) : nil | ||
{ | ||
streetName: home_address&.address_1&.gsub(/[^0-9A-Za-z\s]/, ''), | ||
cityName: home_address&.city&.gsub(/[^0-9A-Za-z]/, ''), | ||
usStateCode: home_address&.state, | ||
zipCode: home_address&.zip, | ||
telephoneNumber: home_phone&.full_phone_number | ||
} | ||
end | ||
|
||
def validate_payload(payload) | ||
schema_data = JSON.parse(File.read(Pathname.pwd.join("lib/aca_entities/fdsh/ridp/rj139/schemas/RIDP-Request-schema.json"))) | ||
|
||
# CMS requested no blank data be sent in the request | ||
payload[:ridpRequest][:primaryRequest][:person].delete_if { |_k, v| v.blank? } | ||
payload[:ridpRequest][:primaryRequest][:contactInformation].delete_if { |_k, v| v.blank? } | ||
|
||
result = begin | ||
JSON::Validator.fully_validate(schema_data, JSON.parse(payload.to_json)) | ||
rescue JSON::Schema::ValidationError => e | ||
e.message | ||
end | ||
result.empty? ? Success(payload.to_json) : Failure(result.to_s) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.