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:.
-
#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.
- #process_claim_v2! ⇒ Object
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Constructor Details
#initialize(claim, submission = nil) ⇒ Service
Returns a new instance of Service.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/services/form1010cg/service.rb', line 45 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 MVI and eMIS @cache = { # [form_subject]: String - The person's ICN # [form_subject]: NOT_FOUND - This person could not be found in MVI # [form_subject]: nil - An MVI search has not been conducted for this person icns: {}, # [form_subject]: true - This person is a veteran # [form_subject]: false - This person's veteran status cannot be confirmed # [form_subject]: nil - An eMIS search has not been conducted for this person veteran_statuses: {} } 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
.carma_client ⇒ Object
39 40 41 42 43 |
# File 'app/services/form1010cg/service.rb', line 39 def self.carma_client client = CARMA::Client::MuleSoftClient.new Rails.logger.info "[10-10CG] Using #{client.class} for submissions" client end |
.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
83 84 85 86 87 88 89 |
# File 'app/services/form1010cg/service.rb', line 83 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 }
}
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/services/form1010cg/service.rb', line 102 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 emis # 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 serach to use the edipi. [:veteran][:is_veteran] = false 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.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/services/form1010cg/service.rb', line 123 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? Raven.extra_context(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 |
#process_claim_v2! ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'app/services/form1010cg/service.rb', line 69 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) end |