From a060ac80dabb5ef501e1c7543baf8c79560e5f5c Mon Sep 17 00:00:00 2001 From: Oren Mittman Date: Thu, 18 Apr 2024 15:58:54 -0400 Subject: [PATCH] extract miscellaneous LocalBGS operations Move miscellaneous operations out so that: - it is easier to look at base-level functionality without all of these various operation implementations intermingled - these various operation implementations can eventually be organized according to the standards we've used for other operations --- .../bgs_service/claim_management_service.rb | 4 + .../claims_api/lib/bgs_service/local_bgs.rb | 195 +---------------- .../local_bgs/miscellaneous_operations.rb | 198 ++++++++++++++++++ 3 files changed, 203 insertions(+), 194 deletions(-) create mode 100644 modules/claims_api/lib/bgs_service/local_bgs/miscellaneous_operations.rb diff --git a/modules/claims_api/lib/bgs_service/claim_management_service.rb b/modules/claims_api/lib/bgs_service/claim_management_service.rb index 2dd7981c084..39fce5ccff0 100644 --- a/modules/claims_api/lib/bgs_service/claim_management_service.rb +++ b/modules/claims_api/lib/bgs_service/claim_management_service.rb @@ -24,5 +24,9 @@ def update_claim_level_suspense(claim:) make_request(endpoint: bean_name, action: 'updateClaimLevelSuspense', body:) end + + def to_camelcase(claim:) + claim.deep_transform_keys { |k| k.to_s.camelize(:lower) } + end end end diff --git a/modules/claims_api/lib/bgs_service/local_bgs.rb b/modules/claims_api/lib/bgs_service/local_bgs.rb index 70cec2d24df..10849948ec1 100644 --- a/modules/claims_api/lib/bgs_service/local_bgs.rb +++ b/modules/claims_api/lib/bgs_service/local_bgs.rb @@ -8,7 +8,7 @@ require 'claims_api/claim_logger' require 'claims_api/error/soap_error_handler' -require 'claims_api/evss_bgs_mapper' +require_relative 'local_bgs/miscellaneous_operations' module ClaimsApi class LocalBGS @@ -77,141 +77,6 @@ def healthcheck(endpoint) wsdl.status end - def find_poa_by_participant_id(id) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - - EOXML - - { ptcpntId: id }.each do |k, v| - body.xpath("./*[local-name()='#{k}']")[0].content = v - end - - make_request(endpoint: 'ClaimantServiceBean/ClaimantWebService', action: 'findPOAByPtcpntId', body:, - key: 'return') - end - - def find_by_ssn(ssn) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - - EOXML - - { ssn: }.each do |k, v| - body.xpath("./*[local-name()='#{k}']")[0].content = v - end - - make_request(endpoint: 'PersonWebServiceBean/PersonWebService', action: 'findPersonBySSN', body:, - key: 'PersonDTO') - end - - def find_poa_history_by_ptcpnt_id(id) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - - EOXML - - { ptcpntId: id }.each do |k, v| - body.xpath("./*[local-name()='#{k}']")[0].content = v - end - - make_request(endpoint: 'OrgWebServiceBean/OrgWebService', action: 'findPoaHistoryByPtcpntId', body:, - key: 'PoaHistory') - end - - def find_benefit_claims_status_by_ptcpnt_id(id) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - - EOXML - - { ptcpntId: id }.each do |k, v| - body.xpath("./*[local-name()='#{k}']")[0].content = v - end - - make_request(endpoint: 'EBenefitsBnftClaimStatusWebServiceBean/EBenefitsBnftClaimStatusWebService', - action: 'findBenefitClaimsStatusByPtcpntId', body:) - end - - def claims_count(id) - find_benefit_claims_status_by_ptcpnt_id(id).count - rescue ::Common::Exceptions::ResourceNotFound - 0 - end - - def find_benefit_claim_details_by_benefit_claim_id(id) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - - EOXML - - { bnftClaimId: id }.each do |k, v| - body.xpath("./*[local-name()='#{k}']")[0].content = v - end - - make_request(endpoint: 'EBenefitsBnftClaimStatusWebServiceBean/EBenefitsBnftClaimStatusWebService', - action: 'findBenefitClaimDetailsByBnftClaimId', body:) - end - - def insert_intent_to_file(options) - request_body = construct_itf_body(options) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - - - EOXML - - request_body.each do |k, z| - node = Nokogiri::XML::Node.new k.to_s, body - node.content = z.to_s - opt = body.at('intentToFileDTO') - node.parent = opt - end - make_request(endpoint: 'IntentToFileWebServiceBean/IntentToFileWebService', action: 'insertIntentToFile', - body:, key: 'IntentToFileDTO') - end - - def find_tracked_items(id) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - - EOXML - - { claimId: id }.each do |k, v| - body.xpath("./*[local-name()='#{k}']")[0].content = v - end - - make_request(endpoint: 'TrackedItemService/TrackedItemService', action: 'findTrackedItems', body:, - key: 'BenefitClaim') - end - - def find_intent_to_file_by_ptcpnt_id_itf_type_cd(id, type) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - - EOXML - - ptcpnt_id = body.at 'ptcpntId' - ptcpnt_id.content = id.to_s - itf_type_cd = body.at 'itfTypeCd' - itf_type_cd.content = type.to_s - - response = - make_request( - endpoint: 'IntentToFileWebServiceBean/IntentToFileWebService', - action: 'findIntentToFileByPtcpntIdItfTypeCd', - body: - ) - - Array.wrap(response[:intent_to_file_dto]) - end - - # BEGIN: switching v1 from evss to bgs. Delete after EVSS is no longer available. Fix controller first. - def update_from_remote(id) - bgs_claim = find_benefit_claim_details_by_benefit_claim_id(id) - transform_bgs_claim_to_evss(bgs_claim) - end - - def all(id) - claims = find_benefit_claims_status_by_ptcpnt_id(id) - return [] if claims.count < 1 || claims[:benefit_claims_dto].blank? - - transform_bgs_claims_to_evss(claims) - end - # END: switching v1 from evss to bgs. Delete after EVSS is no longer available. Fix controller first. - private def header # rubocop:disable Metrics/MethodLength @@ -320,19 +185,6 @@ def make_request(endpoint:, action:, body:, key: nil, namespaces: {}, transform_ end end - def construct_itf_body(options) - request_body = { - itfTypeCd: options[:intent_to_file_type_code], - ptcpntVetId: options[:participant_vet_id], - rcvdDt: options[:received_date], - signtrInd: options[:signature_indicated], - submtrApplcnTypeCd: options[:submitter_application_icn_type_code] - } - request_body[:ptcpntClmantId] = options[:participant_claimant_id] if options.key?(:participant_claimant_id) - request_body[:clmantSsn] = options[:claimant_ssn] if options.key?(:claimant_ssn) - request_body - end - def log_duration(event: 'default', **extra_params) # Who are we to question sidekiq's use of CLOCK_MONOTONIC to avoid negative durations? # https://github.com/sidekiq/sidekiq/issues/3999 @@ -350,50 +202,5 @@ def log_duration(event: 'default', **extra_params) def soap_error_handler ClaimsApi::SoapErrorHandler.new end - - def transform_bgs_claim_to_evss(claim) - bgs_claim = ClaimsApi::EvssBgsMapper.new(claim[:benefit_claim_details_dto]) - return if bgs_claim.nil? - - bgs_claim.map_and_build_object - end - - def transform_bgs_claims_to_evss(claims) - claims_array = [claims[:benefit_claims_dto][:benefit_claim]].flatten - claims_array&.map do |claim| - bgs_claim = ClaimsApi::EvssBgsMapper.new(claim) - bgs_claim.map_and_build_object - end - end - - def to_camelcase(claim:) - claim.deep_transform_keys { |k| k.to_s.camelize(:lower) } - end - - def convert_nil_values(options) - arg_strg = '' - options.each do |option| - arg = option[0].to_s.camelize(:lower) - arg_strg += (option[1].nil? ? "<#{arg} xsi:nil='true'/>" : "<#{arg}>#{option[1]}") - end - arg_strg - end - - def validate_opts!(opts, required_keys) - keys = opts.keys.map(&:to_s) - required_keys = required_keys.map(&:to_s) - missing_keys = required_keys - keys - raise ArgumentError, "Missing required keys: #{missing_keys.join(', ')}" if missing_keys.present? - end - - def jrn - { - jrn_dt: Time.current.iso8601, - jrn_lctn_id: Settings.bgs.client_station_id, - jrn_status_type_cd: 'U', - jrn_user_id: Settings.bgs.client_username, - jrn_obj_id: Settings.bgs.application - } - end end end diff --git a/modules/claims_api/lib/bgs_service/local_bgs/miscellaneous_operations.rb b/modules/claims_api/lib/bgs_service/local_bgs/miscellaneous_operations.rb new file mode 100644 index 00000000000..fce254c04e6 --- /dev/null +++ b/modules/claims_api/lib/bgs_service/local_bgs/miscellaneous_operations.rb @@ -0,0 +1,198 @@ +# frozen_string_literal: true + +require 'claims_api/evss_bgs_mapper' + +module ClaimsApi + class LocalBGS + def find_poa_by_participant_id(id) + body = Nokogiri::XML::DocumentFragment.parse <<~EOXML + + EOXML + + { ptcpntId: id }.each do |k, v| + body.xpath("./*[local-name()='#{k}']")[0].content = v + end + + make_request(endpoint: 'ClaimantServiceBean/ClaimantWebService', action: 'findPOAByPtcpntId', body:, + key: 'return') + end + + def find_by_ssn(ssn) + body = Nokogiri::XML::DocumentFragment.parse <<~EOXML + + EOXML + + { ssn: }.each do |k, v| + body.xpath("./*[local-name()='#{k}']")[0].content = v + end + + make_request(endpoint: 'PersonWebServiceBean/PersonWebService', action: 'findPersonBySSN', body:, + key: 'PersonDTO') + end + + def find_poa_history_by_ptcpnt_id(id) + body = Nokogiri::XML::DocumentFragment.parse <<~EOXML + + EOXML + + { ptcpntId: id }.each do |k, v| + body.xpath("./*[local-name()='#{k}']")[0].content = v + end + + make_request(endpoint: 'OrgWebServiceBean/OrgWebService', action: 'findPoaHistoryByPtcpntId', body:, + key: 'PoaHistory') + end + + def find_benefit_claims_status_by_ptcpnt_id(id) + body = Nokogiri::XML::DocumentFragment.parse <<~EOXML + + EOXML + + { ptcpntId: id }.each do |k, v| + body.xpath("./*[local-name()='#{k}']")[0].content = v + end + + make_request(endpoint: 'EBenefitsBnftClaimStatusWebServiceBean/EBenefitsBnftClaimStatusWebService', + action: 'findBenefitClaimsStatusByPtcpntId', body:) + end + + def claims_count(id) + find_benefit_claims_status_by_ptcpnt_id(id).count + rescue ::Common::Exceptions::ResourceNotFound + 0 + end + + def find_benefit_claim_details_by_benefit_claim_id(id) + body = Nokogiri::XML::DocumentFragment.parse <<~EOXML + + EOXML + + { bnftClaimId: id }.each do |k, v| + body.xpath("./*[local-name()='#{k}']")[0].content = v + end + + make_request(endpoint: 'EBenefitsBnftClaimStatusWebServiceBean/EBenefitsBnftClaimStatusWebService', + action: 'findBenefitClaimDetailsByBnftClaimId', body:) + end + + def insert_intent_to_file(options) + request_body = construct_itf_body(options) + body = Nokogiri::XML::DocumentFragment.parse <<~EOXML + + + EOXML + + request_body.each do |k, z| + node = Nokogiri::XML::Node.new k.to_s, body + node.content = z.to_s + opt = body.at('intentToFileDTO') + node.parent = opt + end + make_request(endpoint: 'IntentToFileWebServiceBean/IntentToFileWebService', action: 'insertIntentToFile', + body:, key: 'IntentToFileDTO') + end + + def find_tracked_items(id) + body = Nokogiri::XML::DocumentFragment.parse <<~EOXML + + EOXML + + { claimId: id }.each do |k, v| + body.xpath("./*[local-name()='#{k}']")[0].content = v + end + + make_request(endpoint: 'TrackedItemService/TrackedItemService', action: 'findTrackedItems', body:, + key: 'BenefitClaim') + end + + def find_intent_to_file_by_ptcpnt_id_itf_type_cd(id, type) + body = Nokogiri::XML::DocumentFragment.parse <<~EOXML + + EOXML + + ptcpnt_id = body.at 'ptcpntId' + ptcpnt_id.content = id.to_s + itf_type_cd = body.at 'itfTypeCd' + itf_type_cd.content = type.to_s + + response = + make_request( + endpoint: 'IntentToFileWebServiceBean/IntentToFileWebService', + action: 'findIntentToFileByPtcpntIdItfTypeCd', + body: + ) + + Array.wrap(response[:intent_to_file_dto]) + end + + # BEGIN: switching v1 from evss to bgs. Delete after EVSS is no longer available. Fix controller first. + def update_from_remote(id) + bgs_claim = find_benefit_claim_details_by_benefit_claim_id(id) + transform_bgs_claim_to_evss(bgs_claim) + end + + def all(id) + claims = find_benefit_claims_status_by_ptcpnt_id(id) + return [] if claims.count < 1 || claims[:benefit_claims_dto].blank? + + transform_bgs_claims_to_evss(claims) + end + # END: switching v1 from evss to bgs. Delete after EVSS is no longer available. Fix controller first. + + private + + def construct_itf_body(options) + request_body = { + itfTypeCd: options[:intent_to_file_type_code], + ptcpntVetId: options[:participant_vet_id], + rcvdDt: options[:received_date], + signtrInd: options[:signature_indicated], + submtrApplcnTypeCd: options[:submitter_application_icn_type_code] + } + request_body[:ptcpntClmantId] = options[:participant_claimant_id] if options.key?(:participant_claimant_id) + request_body[:clmantSsn] = options[:claimant_ssn] if options.key?(:claimant_ssn) + request_body + end + + def transform_bgs_claim_to_evss(claim) + bgs_claim = ClaimsApi::EvssBgsMapper.new(claim[:benefit_claim_details_dto]) + return if bgs_claim.nil? + + bgs_claim.map_and_build_object + end + + def transform_bgs_claims_to_evss(claims) + claims_array = [claims[:benefit_claims_dto][:benefit_claim]].flatten + claims_array&.map do |claim| + bgs_claim = ClaimsApi::EvssBgsMapper.new(claim) + bgs_claim.map_and_build_object + end + end + + def convert_nil_values(options) + arg_strg = '' + options.each do |option| + arg = option[0].to_s.camelize(:lower) + arg_strg += (option[1].nil? ? "<#{arg} xsi:nil='true'/>" : "<#{arg}>#{option[1]}") + end + arg_strg + end + + def validate_opts!(opts, required_keys) + keys = opts.keys.map(&:to_s) + required_keys = required_keys.map(&:to_s) + missing_keys = required_keys - keys + raise ArgumentError, "Missing required keys: #{missing_keys.join(', ')}" if missing_keys.present? + end + + def jrn + { + jrn_dt: Time.current.iso8601, + jrn_lctn_id: Settings.bgs.client_station_id, + jrn_status_type_cd: 'U', + jrn_user_id: Settings.bgs.client_username, + jrn_obj_id: Settings.bgs.application + } + end + end +end