Skip to content

Commit a6f17a8

Browse files
committed
MHV-68159 Migration to new MHV API Gateway
1 parent dd75cd7 commit a6f17a8

File tree

8 files changed

+78
-13
lines changed

8 files changed

+78
-13
lines changed

config/features.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,10 @@ features:
10431043
actor_type: user
10441044
description: Show/hide content related to Vitals in Medical Records
10451045
enable_in_development: true
1046+
mhv_medical_records_migrate_to_api_gateway:
1047+
actor_type: user
1048+
description: Enables the switch to the new MHV API Gateway endpoints
1049+
enable_in_development: true
10461050
mhv_medical_records_phr_refresh_on_login:
10471051
actor_type: user
10481052
description: Enables/disables the PHR refresh for MHV users when logging into VA.gov

lib/common/client/concerns/mhv_jwt_session_client.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ def validate_session_params
7878

7979
def get_session_tagged
8080
Sentry.set_tags(error: 'mhv_session')
81-
env = perform(:post, '/mhvapi/security/v1/login', auth_body, auth_headers)
81+
env = if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
82+
perform(:post, '/v1/security/login', auth_body, auth_headers)
83+
else
84+
perform(:post, '/mhvapi/security/v1/login', auth_body, auth_headers)
85+
end
8286
Sentry.get_current_scope.tags.delete(:error)
8387
env
8488
end
@@ -93,6 +97,9 @@ def patient_fhir_id
9397

9498
def auth_headers
9599
config.base_request_headers.merge('Content-Type' => 'application/json')
100+
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
101+
config.base_request_headers.merge('x-api-key' => Settings.mhv.medical_records.x_api_key)
102+
end
96103
end
97104

98105
def auth_body

lib/medical_records/client.rb

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Client < Common::Client::Base
1414
include Common::Client::Concerns::MhvFhirSessionClient
1515

1616
# Default number of records to request per call when searching
17-
DEFAULT_COUNT = 9999
17+
DEFAULT_COUNT = 3000
1818

1919
# LOINC codes for clinical notes
2020
PHYSICIAN_PROCEDURE_NOTE = '11506-3' # Physician procedure note
@@ -43,7 +43,11 @@ class Client < Common::Client::Base
4343
# @return [String] Base path for dependent URLs
4444
#
4545
def base_path
46-
"#{Settings.mhv.medical_records.host}/fhir/"
46+
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
47+
"#{Settings.mhv.api_gateway.hosts.fhir}/fhir/"
48+
else
49+
"#{Settings.mhv.medical_records.host}/fhir/"
50+
end
4751
end
4852

4953
##
@@ -214,6 +218,10 @@ def fhir_search(fhir_model, params)
214218
#
215219
def fhir_search_query(fhir_model, params)
216220
default_headers = { 'Cache-Control': 'no-cache' }
221+
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
222+
default_headers.merge('x-api-key' => Settings.mhv.medical_records.x_api_key)
223+
end
224+
217225
params[:headers] = default_headers.merge(params.fetch(:headers, {}))
218226

219227
params[:search][:parameters].merge!(_count: DEFAULT_COUNT)
@@ -224,7 +232,12 @@ def fhir_search_query(fhir_model, params)
224232
end
225233

226234
def fhir_read(fhir_model, id)
227-
result = fhir_client.read(fhir_model, id)
235+
default_headers = {}
236+
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
237+
default_headers.merge!('x-api-key' => Settings.mhv.medical_records.x_api_key)
238+
end
239+
240+
result = fhir_client.read(fhir_model, id, nil, nil, { headers: default_headers })
228241
handle_api_errors(result) if result.resource.nil?
229242
result.resource
230243
end

lib/medical_records/configuration.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def app_token
2626
# @return [String] Base path for dependent URLs
2727
#
2828
def base_path
29-
Settings.mhv.medical_records.host
29+
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
30+
Settings.mhv.api_gateway.hosts.security
31+
else
32+
Settings.mhv.medical_records.host
33+
end
3034
end
3135

3236
##

lib/medical_records/phr_mgr/client.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize(icn)
2828
# @return [Fixnum] Call status
2929
#
3030
def post_phrmgr_refresh
31-
response = perform(:post, "refresh/#{@icn}", nil, self.class.configuration.x_auth_key_headers)
31+
response = perform(:post, "refresh/#{@icn}", nil, self.class.configuration.phr_headers)
3232
# response_hash = JSON.parse(response.body)
3333
response&.status
3434
end
@@ -39,7 +39,7 @@ def post_phrmgr_refresh
3939
# @return [Hash] Patient status
4040
#
4141
def get_phrmgr_status
42-
response = perform(:get, "status/#{@icn}", nil, self.class.configuration.x_auth_key_headers)
42+
response = perform(:get, "status/#{@icn}", nil, self.class.configuration.phr_headers)
4343
response.body
4444
end
4545

@@ -49,7 +49,7 @@ def get_phrmgr_status
4949
# @return - military service record in text format
5050
#
5151
def get_military_service(edipi)
52-
headers = self.class.configuration.x_auth_key_headers.merge({ 'Accept' => 'text/plain' })
52+
headers = self.class.configuration.phr_headers.merge({ 'Accept' => 'text/plain' })
5353
response = perform(:get, "dod/vaprofile/#{edipi}", nil, headers)
5454
response.body
5555
end

lib/medical_records/phr_mgr/configuration.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ class Configuration < Common::Client::Configuration::REST
1919
# @return [String] Base path for dependent URLs
2020
#
2121
def base_path
22-
"#{Settings.mhv.medical_records.host}/mhvapi/v2/phrmgr/"
22+
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
23+
"#{Settings.mhv.api_gateway.hosts.phrmgr}/v2/phrmgr/"
24+
else
25+
"#{Settings.mhv.medical_records.host}/mhvapi/v2/phrmgr/"
26+
end
2327
end
2428

2529
##
26-
# @return [Hash] Headers with X-Authorization-Key header value for dependent URLs
30+
# @return [Hash] Headers with X-Authorization-Key and x-api-key header values for dependent URLs
2731
#
28-
def x_auth_key_headers
32+
def phr_headers
2933
base_request_headers.merge('X-Authorization-Key' => Settings.mhv.medical_records.x_auth_key)
34+
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
35+
base_request_headers.merge('x-api-key' => Settings.mhv.medical_records.x_api_key)
36+
end
3037
end
3138

3239
##
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
# Monkeypatch to allow read to take custom headers. This allows us to inject the x-api-key header
4+
# when accessing FHIR via the MHV API Gateway.
5+
# Patched version: department-of-veterans-affairs/fhir_client (fork of 5.0.3)
6+
module FHIR
7+
module Sections
8+
module Crud
9+
def read(klass, id, format = nil, summary = nil, options = {})
10+
options = { resource: klass, id:, format: format || @default_format }.merge(options)
11+
options[:summary] = summary if summary
12+
13+
# Build the default headers (using the provided format if any)
14+
base_headers = {}
15+
base_headers[:accept] = format.to_s if format
16+
17+
# Grab any custom headers provided in the options
18+
extra_headers = options[:headers] || {}
19+
20+
# Merge custom headers into the default FHIR headers
21+
reply = get resource_url(options), fhir_headers(base_headers).merge(extra_headers)
22+
23+
reply.resource = parse_reply(klass, format || @default_format, reply)
24+
reply.resource_class = klass
25+
reply
26+
end
27+
end
28+
end
29+
end

modules/my_health/config/initializers/fhir_search_patch.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# frozen_string_literal: true
22

33
# Monkeypatch to allow fhir_search to take custom headers. This is to allow us to bypass the FHIR
4-
# server's cache when requesting a Patient resource.
5-
# Patched version: fhir_client (5.0.3)
4+
# server's cache when requesting a FHIR resource. It also allows us to inject the x-api-key header
5+
# when accessing FHIR via the MHV API Gateway.
6+
# Patched version: department-of-veterans-affairs/fhir_client (fork of 5.0.3)
67
module FHIR
78
module Sections
89
module Search

0 commit comments

Comments
 (0)