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-58591 MHV-57739 Authentication for MHV Classic radiology endpoint #17381

Merged
merged 15 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
MHV-57739 Got radiology authentication working with session locking
  • Loading branch information
mmoyer-va committed Jul 2, 2024
commit 141203df144608a293d867166d652fc762f2eb04
5 changes: 5 additions & 0 deletions config/locales/exceptions.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ en:
code: "MEDICALRECORDS_404"
detail: "The resource could not be found"
status: 404
BBINTERNAL_400:
<<: *external_defaults
code: "BBINTERNAL_400"
detail: "Upstream service responded with Bad Request"
status: 400
BBINTERNAL_401:
<<: *external_defaults
code: "BBINTERNAL_401"
Expand Down
3 changes: 3 additions & 0 deletions config/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ development: &defaults
mhv_session_lock:
namespace: mhv-session-lock
each_ttl: 10
mhv_mr_bb_session_lock:
namespace: mhv-mr-bb-session-lock
each_ttl: 10
mdot:
namespace: mdot
each_ttl: 1800
Expand Down
37 changes: 20 additions & 17 deletions lib/medical_records/bb_internal/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,47 @@ class Client < Common::Client::Base
client_session BBInternal::ClientSession

def get_radiology
response = perform(:get, "bluebutton/radiology/phr/#{session.patient_id}", nil, token_headers)
response = perform(:get, "bluebutton/radiology/phrList/#{session.patient_id}", nil, token_headers)
response.body
end

private

##
# Override this to ensure a unique namespace for the redis lock.
#
def session_config_key
:mhv_mr_bb_session_lock
end

##
# Override MHVSessionBasedClient's method so we can get the patientId and store it as well.
#
def get_session
new_session = @session.class.new(user_id: 11_383_839,
patient_id: 11_383_893,
expires_at: 'Wed, 15 Jan 2025 00:00:00 GMT',
token: 'ENC(MA0ECJh1RjEgZFMhAgEQC4nF8QKGKGmZuYg7kVN8CGTImSTyeRVyXIeUOtSUP4PoUkdGKwuDnAAn)')

# # Call MHVSessionBasedClient.get_session
# session = super
# Call MHVSessionBasedClient.get_session
@session = super

# # Supplement session with patientId
# patient_id = get_patient_id
# session.patient_id = patient_id
# Supplement session with patientId
session.patient_id = get_patient_id

new_session.save
new_session
session.save
session
end

def get_patient_id
response = perform(:get, "usermgmt/patient/uid/#{@session.user_id}", nil, token_headers)
response.body
11_383_893

response.body['ipas']&.first&.dig('patientId')

# TODO: Raise an error if patient_id is nil
# raise NoPatientIdError, 'No patientId found' if patient_id.nil?
end

##
# Override MHVSessionBasedClient's method, because we need more control over the path.
#
def get_session_tagged
response = perform(:get, 'usermgmt/auth/session', nil, auth_headers)
response.body
perform(:get, 'usermgmt/auth/session', nil, auth_headers)
end
end
end
4 changes: 2 additions & 2 deletions lib/medical_records/bb_internal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'common/client/middleware/request/camelcase'
require 'common/client/middleware/request/multipart_request'
require 'common/client/middleware/response/json_parser'
require 'common/client/middleware/response/raise_error'
require 'common/client/middleware/response/raise_custom_error'
require 'common/client/middleware/response/mhv_errors'
require 'common/client/middleware/response/snakecase'
require 'faraday/multipart'
Expand Down Expand Up @@ -54,7 +54,7 @@ def connection
# conn.request(:curl, ::Logger.new(STDOUT), :warn) unless Rails.env.production?
# conn.response(:logger, ::Logger.new(STDOUT), bodies: true) unless Rails.env.production?

conn.response :raise_error, error_prefix: service_name
conn.response :raise_custom_error, error_prefix: service_name
conn.response :mhv_errors
conn.response :mhv_xml_html_errors
conn.response :json_parser
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'medical_records/client'
require 'medical_records/bb_internal/client'
require 'medical_records/phr_mgr/client'

module MyHealth
Expand All @@ -10,7 +11,7 @@ class MrController < ApplicationController
service_tag 'mhv-medical-records'

# skip_before_action :authenticate
before_action :authenticate_bb
before_action :authenticate_bb_client

rescue_from ::MedicalRecords::PatientNotFound do |_exception|
render body: nil, status: :accepted
Expand All @@ -31,7 +32,7 @@ def bb_client
@bb_client ||= BBInternal::Client.new(current_user.mhv_correlation_id)
end

def authenticate_bb
def authenticate_bb_client
bb_client.authenticate
end

Expand Down
Loading