Class: MHVMedicalRecordsPolicy

Inherits:
Struct
  • Object
show all
Defined in:
app/policies/mhv_medical_records_policy.rb

Constant Summary collapse

MR_ACCOUNT_TYPES =
%w[Premium].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mhv_medical_recordsObject

Returns the value of attribute mhv_medical_records

Returns:

  • (Object)

    the current value of mhv_medical_records



5
6
7
# File 'app/policies/mhv_medical_records_policy.rb', line 5

def mhv_medical_records
  @mhv_medical_records
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



5
6
7
# File 'app/policies/mhv_medical_records_policy.rb', line 5

def user
  @user
end

Instance Method Details

#access?Boolean

Returns:

  • (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.) && 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(message, error)
  Rails.logger.info(message,
                    mhv_id: user.mhv_correlation_id.presence || 'false',
                    sign_in_service: user.identity.[:service_name],
                    va_facilities: user.va_treatment_facility_ids.length,
                    va_patient: user.va_patient?,
                    message: error.message)
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