Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MHV-68159 Migration to new MHV API Gateway #21157

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,10 @@ features:
actor_type: user
description: Show/hide content related to Vitals in Medical Records
enable_in_development: true
mhv_medical_records_migrate_to_api_gateway:
actor_type: user
description: Enables the switch to the new MHV API Gateway endpoints
enable_in_development: true
mhv_medical_records_phr_refresh_on_login:
actor_type: user
description: Enables/disables the PHR refresh for MHV users when logging into VA.gov
Expand Down
9 changes: 8 additions & 1 deletion lib/common/client/concerns/mhv_jwt_session_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def validate_session_params

def get_session_tagged
Sentry.set_tags(error: 'mhv_session')
env = perform(:post, '/mhvapi/security/v1/login', auth_body, auth_headers)
env = if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
perform(:post, '/v1/security/login', auth_body, auth_headers)
else
perform(:post, '/mhvapi/security/v1/login', auth_body, auth_headers)
end
Sentry.get_current_scope.tags.delete(:error)
env
end
Expand All @@ -93,6 +97,9 @@ def patient_fhir_id

def auth_headers
config.base_request_headers.merge('Content-Type' => 'application/json')
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
config.base_request_headers.merge('x-api-key' => Settings.mhv.medical_records.x_api_key)
end
end

def auth_body
Expand Down
19 changes: 16 additions & 3 deletions lib/medical_records/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Client < Common::Client::Base
include Common::Client::Concerns::MhvFhirSessionClient

# Default number of records to request per call when searching
DEFAULT_COUNT = 9999
DEFAULT_COUNT = 3000

# LOINC codes for clinical notes
PHYSICIAN_PROCEDURE_NOTE = '11506-3' # Physician procedure note
Expand Down Expand Up @@ -43,7 +43,11 @@ class Client < Common::Client::Base
# @return [String] Base path for dependent URLs
#
def base_path
"#{Settings.mhv.medical_records.host}/fhir/"
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
"#{Settings.mhv.api_gateway.hosts.fhir}/fhir/"
else
"#{Settings.mhv.medical_records.host}/fhir/"
end
end

##
Expand Down Expand Up @@ -214,6 +218,10 @@ def fhir_search(fhir_model, params)
#
def fhir_search_query(fhir_model, params)
default_headers = { 'Cache-Control': 'no-cache' }
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
default_headers.merge('x-api-key' => Settings.mhv.medical_records.x_api_key)
end

params[:headers] = default_headers.merge(params.fetch(:headers, {}))

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

def fhir_read(fhir_model, id)
result = fhir_client.read(fhir_model, id)
default_headers = {}
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
default_headers.merge!('x-api-key' => Settings.mhv.medical_records.x_api_key)
end

result = fhir_client.read(fhir_model, id, nil, nil, { headers: default_headers })
handle_api_errors(result) if result.resource.nil?
result.resource
end
Expand Down
6 changes: 5 additions & 1 deletion lib/medical_records/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def app_token
# @return [String] Base path for dependent URLs
#
def base_path
Settings.mhv.medical_records.host
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
Settings.mhv.api_gateway.hosts.security
else
Settings.mhv.medical_records.host
end
end

##
Expand Down
6 changes: 3 additions & 3 deletions lib/medical_records/phr_mgr/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(icn)
# @return [Fixnum] Call status
#
def post_phrmgr_refresh
response = perform(:post, "refresh/#{@icn}", nil, self.class.configuration.x_auth_key_headers)
response = perform(:post, "refresh/#{@icn}", nil, self.class.configuration.phr_headers)
# response_hash = JSON.parse(response.body)
response&.status
end
Expand All @@ -39,7 +39,7 @@ def post_phrmgr_refresh
# @return [Hash] Patient status
#
def get_phrmgr_status
response = perform(:get, "status/#{@icn}", nil, self.class.configuration.x_auth_key_headers)
response = perform(:get, "status/#{@icn}", nil, self.class.configuration.phr_headers)
response.body
end

Expand All @@ -49,7 +49,7 @@ def get_phrmgr_status
# @return - military service record in text format
#
def get_military_service(edipi)
headers = self.class.configuration.x_auth_key_headers.merge({ 'Accept' => 'text/plain' })
headers = self.class.configuration.phr_headers.merge({ 'Accept' => 'text/plain' })
response = perform(:get, "dod/vaprofile/#{edipi}", nil, headers)
response.body
end
Expand Down
13 changes: 10 additions & 3 deletions lib/medical_records/phr_mgr/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ class Configuration < Common::Client::Configuration::REST
# @return [String] Base path for dependent URLs
#
def base_path
"#{Settings.mhv.medical_records.host}/mhvapi/v2/phrmgr/"
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
"#{Settings.mhv.api_gateway.hosts.phrmgr}/v2/phrmgr/"
else
"#{Settings.mhv.medical_records.host}/mhvapi/v2/phrmgr/"
end
end

##
# @return [Hash] Headers with X-Authorization-Key header value for dependent URLs
# @return [Hash] Headers with X-Authorization-Key and x-api-key header values for dependent URLs
#
def x_auth_key_headers
def phr_headers
base_request_headers.merge('X-Authorization-Key' => Settings.mhv.medical_records.x_auth_key)
if Flipper.enabled?(:mhv_medical_records_migrate_to_api_gateway)
base_request_headers.merge('x-api-key' => Settings.mhv.medical_records.x_api_key)
end
end

##
Expand Down
29 changes: 29 additions & 0 deletions modules/my_health/config/initializers/fhir_read_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

# Monkeypatch to allow read to take custom headers. This allows us to inject the x-api-key header
# when accessing FHIR via the MHV API Gateway.
# Patched version: department-of-veterans-affairs/fhir_client (fork of 5.0.3)
module FHIR
module Sections
module Crud
def read(klass, id, format = nil, summary = nil, options = {})
options = { resource: klass, id:, format: format || @default_format }.merge(options)
options[:summary] = summary if summary

# Build the default headers (using the provided format if any)
base_headers = {}
base_headers[:accept] = format.to_s if format

# Grab any custom headers provided in the options
extra_headers = options[:headers] || {}

# Merge custom headers into the default FHIR headers
reply = get resource_url(options), fhir_headers(base_headers).merge(extra_headers)

reply.resource = parse_reply(klass, format || @default_format, reply)
reply.resource_class = klass
reply
end
end
end
end
5 changes: 3 additions & 2 deletions modules/my_health/config/initializers/fhir_search_patch.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

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