Class: SavedClaim::EducationBenefits::VA10203

Inherits:
SavedClaim::EducationBenefits show all
Includes:
SentryLogging
Defined in:
app/models/saved_claim/education_benefits/va_10203.rb

Defined Under Namespace

Classes: Submit10203Error

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods inherited from SavedClaim::EducationBenefits

#add_education_benefits_claim, form_class, #in_progress_form_id, #regional_office_address

Methods inherited from SavedClaim

add_form_and_validation, #after_create_metrics, #after_destroy_metrics, #attachment_keys, #business_line, #confirmation_number, #email, #form_is_string, #form_matches_schema, #form_must_be_string, #insert_notification, #open_struct_form, #parsed_form, #process_attachments!, #submitted_at, #to_pdf, #update_form, #va_notification?, #validate_form, #validate_schema

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Instance Method Details

#after_submit(user) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 13

def after_submit(user)
  @user = user
  if @user.present?
    @gi_bill_status = get_gi_bill_status
    create_stem_automated_decision
  end

  email_sent(false)

  send_confirmation_email if Flipper.enabled?(:form21_10203_confirmation_email)

  if @user.present? && FeatureFlipper.send_email?
    education_benefits_claim.education_stem_automated_decision.update(confirmation_email_sent_at: Time.zone.now)

    authorized = @user.authorize(:evss, :access?)

    if authorized
      EducationForm::SendSchoolCertifyingOfficialsEmail.perform_async(id, less_than_six_months?,
                                                                      get_facility_code)
    end
  end
end

#create_stem_automated_decisionObject



36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 36

def create_stem_automated_decision
  logger.info "EDIPI available for submit STEM claim id=#{education_benefits_claim.id}: #{@user.edipi.present?}"

  education_benefits_claim.build_education_stem_automated_decision(
    user_uuid: @user.uuid,
    user_account: @user.,
    auth_headers_json: EVSS::AuthHeaders.new(@user).to_h.to_json,
    poa: get_user_poa,
    remaining_entitlement:
  ).save
end

#email_sent(sco_email_sent) ⇒ Object



48
49
50
51
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 48

def email_sent(sco_email_sent)
  update_form('scoEmailSent', sco_email_sent)
  save
end

#get_facility_codeObject (private)



73
74
75
76
77
78
79
80
81
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 73

def get_facility_code
  return {} if @gi_bill_status == {} || @gi_bill_status.enrollments.blank?

  most_recent = @gi_bill_status.enrollments.max_by(&:begin_date)

  return {} if most_recent.blank?

  most_recent.facility_code
end

#get_gi_bill_statusObject (private)



65
66
67
68
69
70
71
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 65

def get_gi_bill_status
  service = BenefitsEducation::Service.new(@user.icn)
  service.get_gi_bill_status
rescue => e
  Rails.logger.error "Failed to retrieve GiBillStatus data: #{e.message}"
  {}
end

#get_user_poaObject



53
54
55
56
57
58
59
60
61
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 53

def get_user_poa
  # stem_automated_decision feature disables EVSS call  for POA which will be removed in a future PR
  return nil if Flipper.enabled?(:stem_automated_decision, @user)

  @user.power_of_attorney.present? ? true : nil
rescue => e
  log_exception_to_sentry(Submit10203Error.new("Failed to retrieve VSOSearch data: #{e.message}"))
  nil
end

#less_than_six_months?Boolean (private)

Returns:

  • (Boolean)


108
109
110
111
112
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 108

def less_than_six_months?
  return false if remaining_entitlement.blank?

  remaining_entitlement <= 180
end

#remaining_entitlementObject (private)



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 83

def remaining_entitlement
  if Settings.vsp_environment != 'production'
    service = BenefitsEducation::Service.new(@user.icn)
    Rails.logger.info '#### 10203 Lighthouse ##########'
    Rails.logger.info "#### User Info ########## \n #{@user.to_json}"
    Rails.logger.info @user.to_json
    Rails.logger.info "#### Request Info ########## \n #{service.inspect}"

    if @gi_bill_status == {} || @gi_bill_status.remaining_entitlement.blank?
      Rails.logger.info '#### remaining_entitlement data: none ##########'
    end

    return nil if @gi_bill_status == {} || @gi_bill_status.remaining_entitlement.blank?

    Rails.logger.info "#### remaining_entitlement data ########## \n @gi_bill_status.to_json"
  elsif @gi_bill_status == {} || @gi_bill_status.remaining_entitlement.blank?
    return nil
  end

  months = @gi_bill_status.remaining_entitlement.months
  days = @gi_bill_status.remaining_entitlement.days

  ((months * 30) + days)
end

#send_confirmation_emailObject (private)



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/models/saved_claim/education_benefits/va_10203.rb', line 114

def send_confirmation_email
  parsed_form = JSON.parse(form)
  email = parsed_form['email']
  return if email.blank?

  VANotify::EmailJob.perform_async(
    email,
    Settings.vanotify.services.va_gov.template_id.form21_10203_confirmation_email,
    {
      'first_name' => parsed_form.dig('veteranFullName', 'first')&.upcase.presence,
      'date_submitted' => Time.zone.today.strftime('%B %d, %Y'),
      'confirmation_number' => education_benefits_claim.confirmation_number,
      'regional_office_address' => regional_office_address
    }
  )
end