Class: Lighthouse::VeteransHealth::Client
Overview
Instance Method Summary
collapse
#increment, #increment_failure, #increment_total, #with_monitoring
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
Initializes the Veterans Health client.
Lighthouse::VeteransHealth::Client.new(‘12345’)
28
29
30
31
|
# File 'lib/lighthouse/veterans_health/client.rb', line 28
def initialize(icn)
@icn = icn
raise ArgumentError, 'no ICN passed in for LH API request.' if icn.blank?
end
|
Instance Method Details
#authenticate(params) ⇒ Object
129
130
131
132
133
134
135
136
|
# File 'lib/lighthouse/veterans_health/client.rb', line 129
def authenticate(params)
perform(
:post,
'oauth2/health/system/v1/token',
URI.encode_www_form(params),
{ 'Content-Type': 'application/x-www-form-urlencoded' }
)
end
|
#authenticate_as_system(json_web_token) ⇒ Object
154
155
156
|
# File 'lib/lighthouse/veterans_health/client.rb', line 154
def authenticate_as_system(json_web_token)
authenticate(payload(json_web_token)).body['access_token']
end
|
#base64_icn ⇒ Object
138
139
140
|
# File 'lib/lighthouse/veterans_health/client.rb', line 138
def base64_icn
@base64_icn ||= Base64.encode64 JSON.generate({ patient: @icn.to_s }, space: ' ')
end
|
#bearer_token ⇒ Object
142
143
144
|
# File 'lib/lighthouse/veterans_health/client.rb', line 142
def bearer_token
@bearer_token ||= retrieve_bearer_token
end
|
#collect_all_entries(next_page, collection) ⇒ Object
115
116
117
118
119
120
121
122
123
|
# File 'lib/lighthouse/veterans_health/client.rb', line 115
def collect_all_entries(next_page, collection)
while next_page.present?
next_response = perform_get(URI(next_page).path + "?#{URI(next_page).query}")
collection.concat(next_response.body['entry'])
next_page = next_response.body['link'].find { |link| link['relation'] == 'next' }&.[]('url')
end
collection
end
|
#get_allergy_intolerance(id) ⇒ Object
59
60
61
|
# File 'lib/lighthouse/veterans_health/client.rb', line 59
def get_allergy_intolerance(id)
perform_get("services/fhir/v0/r4/AllergyIntolerance/#{id}")
end
|
#get_list(first_response) ⇒ Object
Returns Faraday::Env response with all the pages of data.
107
108
109
110
111
112
113
|
# File 'lib/lighthouse/veterans_health/client.rb', line 107
def get_list(first_response)
next_page = first_response.body['link'].find { |link| link['relation'] == 'next' }&.[]('url')
return first_response unless next_page
first_response.body['entry'] = collect_all_entries(next_page, first_response.body['entry'])
first_response
end
|
#get_observation(id) ⇒ Object
91
92
93
|
# File 'lib/lighthouse/veterans_health/client.rb', line 91
def get_observation(id)
perform_get("services/fhir/v0/r4/Observation/#{id}")
end
|
146
147
148
|
# File 'lib/lighthouse/veterans_health/client.rb', line 146
def
@headers_hash ||= Configuration..merge({ Authorization: "Bearer #{bearer_token}" })
end
|
#list_allergy_intolerances ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/lighthouse/veterans_health/client.rb', line 49
def list_allergy_intolerances
params = {
patient: @icn,
_count: 100
}
first_response = perform_get('services/fhir/v0/r4/AllergyIntolerance', **params.compact)
get_list(first_response)
end
|
#list_bp_observations ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/lighthouse/veterans_health/client.rb', line 63
def list_bp_observations
params = {
category: 'vital-signs',
code: '85354-9'
}
list_observations(params)
end
|
#list_conditions ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/lighthouse/veterans_health/client.rb', line 71
def list_conditions
params = {
patient: @icn,
_count: 100
}
first_response = perform_get('services/fhir/v0/r4/Condition', **params)
get_list(first_response)
end
|
#list_diagnostic_reports(params = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/lighthouse/veterans_health/client.rb', line 33
def list_diagnostic_reports(params = {})
params = {
patient: @icn,
category: params[:category],
code: params[:code],
date: params[:date],
status: params[:status],
_lastUpdated: params[:lastUpdated],
page: params[:page],
_count: params[:count]
}
first_response = perform_get('services/fhir/v0/r4/DiagnosticReport', **params.compact)
get_list(first_response)
end
|
#list_medication_requests ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'lib/lighthouse/veterans_health/client.rb', line 95
def list_medication_requests
params = {
patient: @icn,
_count: 100
}
first_response = perform_get('services/fhir/v0/r4/MedicationRequest', **params)
get_list(first_response)
end
|
#list_observations(params_override = {}) ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'lib/lighthouse/veterans_health/client.rb', line 81
def list_observations(params_override = {})
params = {
patient: @icn,
_count: 100
}.merge(params_override)
first_response = perform_get('services/fhir/v0/r4/Observation', **params)
get_list(first_response)
end
|
#payload(json_web_token) ⇒ Object
158
159
160
161
162
163
164
165
166
|
# File 'lib/lighthouse/veterans_health/client.rb', line 158
def payload(json_web_token)
{
grant_type: 'client_credentials',
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
client_assertion: json_web_token,
scope: Settings.lighthouse.veterans_health.fast_tracker.api_scope.join(' '),
launch: base64_icn
}.as_json
end
|
125
126
127
|
# File 'lib/lighthouse/veterans_health/client.rb', line 125
def perform_get(uri_path, **params)
perform(:get, uri_path, params, )
end
|
#retrieve_bearer_token ⇒ Object
150
151
152
|
# File 'lib/lighthouse/veterans_health/client.rb', line 150
def retrieve_bearer_token
authenticate_as_system(JwtWrapper.new.token)
end
|