Class: Form1010cg::Service
- Inherits:
-
Object
- Object
- Form1010cg::Service
- Extended by:
- Forwardable
- Includes:
- SentryLogging
- Defined in:
- app/services/form1010cg/service.rb
Defined Under Namespace
Classes: InvalidVeteranStatus
Constant Summary collapse
- NOT_FOUND =
'NOT_FOUND'
- AUDITOR =
Form1010cg::Auditor.new
Instance Attribute Summary collapse
-
#claim ⇒ Object
SavedClaim::CaregiversAssistanceClaim.
-
#submission ⇒ Object
SavedClaim::CaregiversAssistanceClaim.
Class Method Summary collapse
Instance Method Summary collapse
-
#assert_veteran_status ⇒ nil
Will raise an error unless the veteran specified on the claim’s data can be found in MVI.
-
#build_metadata ⇒ Object
Returns a metadata hash:.
- #generate_records(claim_pdf_path, poa_attachment_path) ⇒ Object private
-
#icn_for(form_subject) ⇒ String | NOT_FOUND
Will search MVI for the provided form subject and return (1) the matching profile’s ICN or (2) ‘NOT_FOUND`.
-
#initialize(claim, submission = nil) ⇒ Service
constructor
A new instance of Service.
- #log_mpi_search_result(form_subject, result) ⇒ Object private
- #mpi_service ⇒ Object private
- #mpi_service_find_profile_by_attributes(form_subject_data) ⇒ Object private
- #process_claim_v2! ⇒ Object
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(claim, submission = nil) ⇒ Service
Returns a new instance of Service.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/services/form1010cg/service.rb', line 37 def initialize(claim, submission = nil) # This service makes assumptions on what data is present on the claim # Make sure the claim is valid, so we can be assured the required data is present. claim.valid? || raise(Common::Exceptions::ValidationErrors, claim) # The CaregiversAssistanceClaim we are processing with this service @claim = claim # The Form1010cg::Submission @submission = submission # Store for the search results we will run on MPI @cache = { # [form_subject]: String - The person's ICN # [form_subject]: NOT_FOUND - This person could not be found in MPI # [form_subject]: nil - An MPI search has not been conducted for this person icns: {} } end |
Instance Attribute Details
#claim ⇒ Object
SavedClaim::CaregiversAssistanceClaim
18 19 20 |
# File 'app/services/form1010cg/service.rb', line 18 def claim @claim end |
#submission ⇒ Object
SavedClaim::CaregiversAssistanceClaim
18 19 20 |
# File 'app/services/form1010cg/service.rb', line 18 def submission @submission end |
Class Method Details
.collect_attachments(claim) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/form1010cg/service.rb', line 24 def self.(claim) = claim.parsed_form['poaAttachmentId'] claim_pdf_path = claim.to_pdf(sign: true) = nil if = Form1010cg::Attachment.find_by(guid: claim.parsed_form['poaAttachmentId']) = .to_local_file if end [claim_pdf_path, ] end |
Instance Method Details
#assert_veteran_status ⇒ nil
Will raise an error unless the veteran specified on the claim’s data can be found in MVI
74 75 76 77 78 79 80 |
# File 'app/services/form1010cg/service.rb', line 74 def assert_veteran_status if icn_for('veteran') == NOT_FOUND error = InvalidVeteranStatus.new log_exception_to_sentry(error) raise error end end |
#build_metadata ⇒ Object
Returns a metadata hash:
{
veteran: {
is_veteran: true | false | nil,
icn: String | nil
},
primaryCaregiver?: { icn: String | nil },
secondaryCaregiverOne?: { icn: String | nil },
secondaryCaregiverTwo?: { icn: String | nil }
}
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/services/form1010cg/service.rb', line 93 def # Set the ICN's for each form_subject on the metadata hash = claim.form_subjects.each_with_object({}) do |form_subject, obj| icn = icn_for(form_subject) obj[form_subject.snakecase.to_sym] = { icn: icn == NOT_FOUND ? nil : icn } end # Disabling the veteran status search since there is an issue with searching # for a veteran status using an ICN. Only edipi works. Consider adding this back in # once ICN searches work or we refactor our veteran status search to use the edipi. [:veteran][:is_veteran] = false end |
#generate_records(claim_pdf_path, poa_attachment_path) ⇒ Object (private)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/services/form1010cg/service.rb', line 145 def generate_records(claim_pdf_path, ) [ { file_path: claim_pdf_path, document_type: CARMA::Models::Attachment::DOCUMENT_TYPES['10-10CG'] }, { file_path: , document_type: CARMA::Models::Attachment::DOCUMENT_TYPES['POA'] } ].map do |doc_data| next if doc_data[:file_path].blank? CARMA::Models::Attachment.new( doc_data.merge( carma_case_id: nil, veteran_name: { first: claim.parsed_form.dig('veteran', 'fullName', 'first'), last: claim.parsed_form.dig('veteran', 'fullName', 'last') }, document_date: claim.created_at, id: nil ) ).to_request_payload.compact end.compact end |
#icn_for(form_subject) ⇒ String | NOT_FOUND
Will search MVI for the provided form subject and return (1) the matching profile’s ICN or (2) ‘NOT_FOUND`. The result will be cached and subsequent calls will return the cached value, preventing additional api requests.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/services/form1010cg/service.rb', line 114 def icn_for(form_subject) cached_icn = @cache[:icns][form_subject] return cached_icn unless cached_icn.nil? form_subject_data = claim.parsed_form[form_subject] if form_subject_data['ssnOrTin'].nil? log_mpi_search_result form_subject, :skipped return @cache[:icns][form_subject] = NOT_FOUND end response = mpi_service_find_profile_by_attributes(form_subject_data) if response.ok? log_mpi_search_result form_subject, :found return @cache[:icns][form_subject] = response.profile.icn end if response.not_found? Sentry.set_extras(mpi_transaction_id: response.error&.) log_mpi_search_result form_subject, :not_found return @cache[:icns][form_subject] = NOT_FOUND end raise response.error if response.error @cache[:icns][form_subject] = NOT_FOUND end |
#log_mpi_search_result(form_subject, result) ⇒ Object (private)
180 181 182 183 184 185 186 |
# File 'app/services/form1010cg/service.rb', line 180 def log_mpi_search_result(form_subject, result) self.class::AUDITOR.log_mpi_search_result( claim_guid: claim.guid, form_subject:, result: ) end |
#mpi_service ⇒ Object (private)
176 177 178 |
# File 'app/services/form1010cg/service.rb', line 176 def mpi_service @mpi_service ||= MPI::Service.new end |
#mpi_service_find_profile_by_attributes(form_subject_data) ⇒ Object (private)
169 170 171 172 173 174 |
# File 'app/services/form1010cg/service.rb', line 169 def mpi_service_find_profile_by_attributes(form_subject_data) mpi_service.find_profile_by_attributes(first_name: form_subject_data['fullName']['first'], last_name: form_subject_data['fullName']['last'], birth_date: form_subject_data['dateOfBirth'], ssn: form_subject_data['ssnOrTin']) end |
#process_claim_v2! ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/services/form1010cg/service.rb', line 57 def process_claim_v2! payload = CARMA::Models::Submission.from_claim(claim, ).to_request_payload claim_pdf_path, = self.class.(claim) payload[:records] = generate_records(claim_pdf_path, ) [claim_pdf_path, ].each { |p| File.delete(p) if p.present? } CARMA::Client::MuleSoftClient.new.create_submission_v2(payload) rescue => e log_exception_to_sentry(e, { form: '10-10CG', claim_guid: claim.guid }) raise e end |