Skip to content

Commit

Permalink
Merge branch 'trunk' into 186771101_vlp_rest_xml_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanB17 authored Jan 10, 2024
2 parents ee08090 + 528e66a commit ae0f8a8
Show file tree
Hide file tree
Showing 12 changed files with 1,381 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/aca_entities/async_api/fdsh_gateway/http_cms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,33 @@ channels:
headers:
Content-Type: application/json
Accept: application/json
/RIDPCrossCoreService:
publish:
operationId: /RIDPCrossCoreService
description: Send RIDP primary JSON request to CMS
message:
contentType: application/json
bindings:
http:
type: request
method: POST
contentType: application/json
headers:
Content-Type: application/json
Accept: application/json
subscribe:
operationId: /on/RIDPCrossCoreService
description: Receive RIDP primary JSON response from CMS
message:
contentType: application/json
bindings:
http:
type: response
method: GET
contentType: application/json
headers:
Content-Type: application/json
Accept: application/json
tags:
- name: linter_tag
description: placeholder that satisfies the linter
4 changes: 4 additions & 0 deletions lib/aca_entities/fdsh/ridp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@

# operations
require_relative 'ridp/h139/operations/generate_primary_request_payload'
require_relative 'ridp/rj139/operations/person_to_primary_request'
require_relative 'ridp/rj139/operations/cms_primary_response_to_cv3_primary_response'
require_relative 'ridp/rj139/operations/cms_secondary_response_to_cv3_secondary_response'
require_relative 'ridp/rj139/operations/evidence_to_secondary_request'

# happymapper
require 'aca_entities/serializers/xml/fdsh/ridp'
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
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
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
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
Loading

0 comments on commit ae0f8a8

Please sign in to comment.