Class: MHVMedicalRecordsPolicy
- Inherits:
-
Struct
- Object
- Struct
- MHVMedicalRecordsPolicy
- Defined in:
- app/policies/mhv_medical_records_policy.rb
Constant Summary collapse
- MR_ACCOUNT_TYPES =
%w[Premium].freeze
Instance Attribute Summary collapse
-
#mhv_medical_records ⇒ Object
Returns the value of attribute mhv_medical_records.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #access? ⇒ Boolean
- #log_denial_details(message, error) ⇒ Object private
- #validate_client(response) ⇒ Object private
Instance Attribute Details
#mhv_medical_records ⇒ Object
Returns the value of attribute mhv_medical_records
5 6 7 |
# File 'app/policies/mhv_medical_records_policy.rb', line 5 def mhv_medical_records @mhv_medical_records end |
#user ⇒ Object
Returns the value of attribute user
5 6 7 |
# File 'app/policies/mhv_medical_records_policy.rb', line 5 def user @user end |
Instance Method Details
#access? ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/policies/mhv_medical_records_policy.rb', line 8 def access? if Flipper.enabled?(:mhv_medical_records_new_eligibility_check) begin client = UserEligibility::Client.new(user.mhv_correlation_id, user.icn) response = client.get_is_valid_sm_user validate_client(response) && user.va_patient? rescue => e log_denial_details('ERROR FETCHING SM USER ELIGIBILITY', e) false end else MR_ACCOUNT_TYPES.include?(user.mhv_account_type) && user.va_patient? end end |
#log_denial_details(message, error) ⇒ Object (private)
33 34 35 36 37 38 39 40 |
# File 'app/policies/mhv_medical_records_policy.rb', line 33 def log_denial_details(, error) Rails.logger.info(, mhv_id: user.mhv_correlation_id.presence || 'false', sign_in_service: user.identity.sign_in[:service_name], va_facilities: user.va_treatment_facility_ids.length, va_patient: user.va_patient?, message: error.) end |
#validate_client(response) ⇒ Object (private)
25 26 27 28 29 30 31 |
# File 'app/policies/mhv_medical_records_policy.rb', line 25 def validate_client(response) [ 'MHV Premium SM account with no logins in past 26 months', 'MHV Premium SM account with Logins in past 26 months', 'MHV Premium account with no SM' ].any? { |substring| response['accountStatus'].include?(substring) } end |