Class: AppealSubmission

Inherits:
ApplicationRecord show all
Includes:
DecisionReview::SavedClaim::Service
Defined in:
app/models/appeal_submission.rb

Constant Summary collapse

APPEAL_TYPES =
%w[HLR NOD SC].freeze

Constants included from DecisionReview::SavedClaim::Service

DecisionReview::SavedClaim::Service::VALID_CLASS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DecisionReview::SavedClaim::Service

#store_saved_claim

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Class Method Details

.submit_nod(request_body_hash:, current_user:, decision_review_service: nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/appeal_submission.rb', line 43

def self.submit_nod(request_body_hash:, current_user:, decision_review_service: nil)
  ActiveRecord::Base.transaction do
    raise 'Must pass in a version of the DecisionReview Service' if decision_review_service.nil?

    appeal_submission = new(type_of_appeal: 'NOD',
                            user_uuid: current_user.uuid,
                            user_account: current_user.,
                            board_review_option: request_body_hash['data']['attributes']['boardReviewOption'],
                            upload_metadata: decision_review_service.class.(current_user))

    form = request_body_hash.to_json # serialize before modifications are made to request body
    uploads_arr = request_body_hash.delete('nodUploads') || []
    nod_response_body = decision_review_service.create_notice_of_disagreement(request_body: request_body_hash,
                                                                              user: current_user)
                                               .body

    guid = nod_response_body.dig('data', 'id')
    appeal_submission. = guid
    appeal_submission.save!

    appeal_submission.store_saved_claim(claim_class: SavedClaim::NoticeOfDisagreement, form:, guid:)

    # Clear in-progress form if submit was successful
    InProgressForm.form_for_user('10182', current_user)&.destroy!

    appeal_submission.enqueue_uploads(uploads_arr, current_user)
    nod_response_body
  end
end

Instance Method Details

#current_email_addressObject



81
82
83
84
85
86
87
88
89
# File 'app/models/appeal_submission.rb', line 81

def current_email_address
  sc = SavedClaim.find_by(guid: )
  form = JSON.parse(sc.form)

  email = form.dig('data', 'attributes', 'veteran', 'email')
  raise 'Failed to retrieve email address' if email.nil?

  email
end

#enqueue_uploads(uploads_arr, _user) ⇒ Object



73
74
75
76
77
78
79
# File 'app/models/appeal_submission.rb', line 73

def enqueue_uploads(uploads_arr, _user)
  uploads_arr.each do |upload_attrs|
    asu = AppealSubmissionUpload.create!(decision_review_evidence_attachment_guid: upload_attrs['confirmationCode'],
                                         appeal_submission_id: id)
    DecisionReview::SubmitUpload.perform_async(asu.id)
  end
end

#get_mpi_profileObject



91
92
93
94
95
96
97
98
99
100
# File 'app/models/appeal_submission.rb', line 91

def get_mpi_profile
  @mpi_profile ||= begin
    service = ::MPI::Service.new
    response = service.find_profile_by_identifier(identifier: user_uuid, identifier_type: 'idme')&.profile
    response ||= service.find_profile_by_identifier(identifier: user_uuid, identifier_type: 'logingov')&.profile
    raise 'Failed to fetch MPI profile' if response.nil?

    response
  end
end