Class: FormProfiles::VA0873
- Inherits:
-
FormProfile
- Object
- FormProfile
- FormProfiles::VA0873
- Defined in:
- app/models/form_profiles/va_0873.rb
Instance Method Summary collapse
-
#fetch_school_name(facility_code) ⇒ Object
private
Retrieves the school name based on the facility code if available.
-
#handle_exception(exception, context) ⇒ Object
private
Logs the exception to Sentry and returns an empty object as a fallback.
-
#initialize_ava_profile ⇒ Object
private
Initializes the AVA profile for the form, retrieving school details if available.
-
#initialize_personal_information ⇒ Object
private
Initializes the personal information for the form with proper error handling.
-
#metadata ⇒ Object
private
Metadata for the form.
-
#preferred_name ⇒ Object
private
Retrieves the preferred name for the user.
- #prefill ⇒ Object
-
#profile ⇒ Object
private
Retrieves the profile from the AskVAApi service.
Instance Method Details
#fetch_school_name(facility_code) ⇒ Object (private)
Retrieves the school name based on the facility code if available
84 85 86 87 88 89 90 91 |
# File 'app/models/form_profiles/va_0873.rb', line 84 def fetch_school_name(facility_code) return nil if facility_code.nil? school = GIDSRedis.new.get_institution_details_v0(id: facility_code) school.dig(:data, :attributes, :name) rescue => e handle_exception(e, :school_name) end |
#handle_exception(exception, context) ⇒ Object (private)
Logs the exception to Sentry and returns an empty object as a fallback
94 95 96 97 |
# File 'app/models/form_profiles/va_0873.rb', line 94 def handle_exception(exception, context) log_exception_to_sentry(exception, {}, prefill: context) {} end |
#initialize_ava_profile ⇒ Object (private)
Initializes the AVA profile for the form, retrieving school details if available
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/form_profiles/va_0873.rb', line 54 def initialize_ava_profile school_name = fetch_school_name(profile.school_facility_code) payload = { school_facility_code: profile.school_facility_code, school_name:, business_phone: profile.business_phone, business_email: profile.business_email } VA0873::FormAvaProfile.new(payload) rescue => e handle_exception(e, :ava_profile) end |
#initialize_personal_information ⇒ Object (private)
Initializes the personal information for the form with proper error handling
42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/form_profiles/va_0873.rb', line 42 def initialize_personal_information service_number = profile.is_a?(Hash) ? profile[:service_number] : profile.service_number # Merge the user's normalized name, preferred name, and service number into the payload payload = user.full_name_normalized.merge(preferred_name:, service_number:) VA0873::FormPersonalInformation.new(payload) rescue => e handle_exception(e, :personal_information) end |
#metadata ⇒ Object (private)
Metadata for the form
100 101 102 103 104 105 106 |
# File 'app/models/form_profiles/va_0873.rb', line 100 def { version: 0, prefill: true, returnUrl: '/your-personal-information' } end |
#preferred_name ⇒ Object (private)
Retrieves the preferred name for the user
70 71 72 73 74 |
# File 'app/models/form_profiles/va_0873.rb', line 70 def preferred_name VAProfile::Demographics::Service.new(user).get_demographics.demographics.preferred_name.text rescue => e handle_exception(e, :preferred_name) end |
#prefill ⇒ Object
33 34 35 36 37 |
# File 'app/models/form_profiles/va_0873.rb', line 33 def prefill @personal_information = initialize_personal_information @ava_profile = initialize_ava_profile super end |
#profile ⇒ Object (private)
Retrieves the profile from the AskVAApi service
77 78 79 80 81 |
# File 'app/models/form_profiles/va_0873.rb', line 77 def profile @profile ||= AskVAApi::Profile::Retriever.new(icn: user.icn).call rescue => e handle_exception(e, :profile) end |