Skip to content

Commit

Permalink
MHV-55345 Handle patient not found for Notes domain. (#15734)
Browse files Browse the repository at this point in the history
* MHV-55345 Added 204 for all domains

* MHV-55245 Handle PatiendNotFound in the session calls

* MHV-55345 Update tests to check for PatientNotFound

* MHV-55345 Raise PatientNotFound if the patient FHIR ID is missing

* MHV-55345 Remove test code

* MHV-55345 Fixed a unit test

* MHV-55345 Moved shared code into MrController
  • Loading branch information
mmoyer-va authored Feb 29, 2024
1 parent 535bc9e commit 1a20c94
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 39 deletions.
4 changes: 4 additions & 0 deletions lib/common/client/concerns/mhv_fhir_session_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def get_session

begin
get_patient_fhir_id(session.token) if session.token && patient_fhir_id.nil?
rescue MedicalRecords::PatientNotFound
# Don't raise this exception, as it will bubble up to a shared class where we don't
# want to handle it. Instead we simply don't set the Patient FHIR ID and raise an
# exception later in medical_records/client.rb where it will be easier to handle.
rescue => e
exception ||= e
end
Expand Down
2 changes: 2 additions & 0 deletions lib/medical_records/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def sessionless_fhir_client(bearer_token)
# @return [FHIR::Client]
#
def fhir_client
raise MedicalRecords::PatientNotFound if patient_fhir_id.nil?

@fhir_client ||= sessionless_fhir_client(jwt_bearer_token)
end

Expand Down
4 changes: 4 additions & 0 deletions modules/my_health/app/controllers/my_health/mr_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class MrController < ApplicationController

# skip_before_action :authenticate

rescue_from ::MedicalRecords::PatientNotFound do |_exception|
render body: nil, status: :accepted
end

protected

def client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ class AllergiesController < MrController
def index
resource = client.list_allergies
render json: resource.to_json
rescue ::MedicalRecords::PatientNotFound
render body: nil, status: :accepted
end

def show
allergy_id = params[:id].try(:to_i)
resource = client.get_allergy(allergy_id)
render json: resource.to_json
rescue ::MedicalRecords::PatientNotFound
render body: nil, status: :accepted
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ module V1
class ClinicalNotesController < MrController
def index
resource = client.list_clinical_notes
raise Common::Exceptions::InternalServerError if resource.blank?

render json: resource.to_json
end

def show
note_id = params[:id].try(:to_i)
resource = client.get_clinical_note(note_id)
raise Common::Exceptions::InternalServerError if resource.blank?

render json: resource.to_json
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ module V1
class ConditionsController < MrController
def index
resource = client.list_conditions
raise Common::Exceptions::InternalServerError if resource.blank?

render json: resource.to_json
end

def show
condition_id = params[:id].try(:to_i)
resource = client.get_condition(condition_id)
raise Common::Exceptions::InternalServerError if resource.blank?

render json: resource.to_json
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ class VaccinesController < MrController
def index
resource = client.list_vaccines
render json: resource.to_json
rescue ::MedicalRecords::PatientNotFound
render body: nil, status: :accepted
end

def show
vaccine_id = params[:id].try(:to_i)
resource = client.get_vaccine(vaccine_id)
render json: resource.to_json
rescue ::MedicalRecords::PatientNotFound
render body: nil, status: :accepted
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module V1
class VitalsController < MrController
def index
resource = client.list_vitals
raise Common::Exceptions::InternalServerError if resource.blank?

render json: resource.to_json
end
end
Expand Down
19 changes: 19 additions & 0 deletions modules/my_health/spec/request/v1/allergies_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,24 @@
expect(response).to be_successful
expect(response.body).to be_a(String)
end

context 'when the patient is not found' do
before do
allow_any_instance_of(MedicalRecords::Client).to receive(:list_allergies)
.and_raise(MedicalRecords::PatientNotFound)
allow_any_instance_of(MedicalRecords::Client).to receive(:get_allergy)
.and_raise(MedicalRecords::PatientNotFound)
end

it 'returns a 202 Accepted response for GET #index' do
get '/my_health/v1/medical_records/allergies'
expect(response).to have_http_status(:accepted)
end

it 'returns a 202 Accepted response for GET #show' do
get '/my_health/v1/medical_records/allergies/30242'
expect(response).to have_http_status(:accepted)
end
end
end
end
19 changes: 19 additions & 0 deletions modules/my_health/spec/request/v1/clinical_notes_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,24 @@
expect(response).to be_successful
expect(response.body).to be_a(String)
end

context 'when the patient is not found' do
before do
allow_any_instance_of(MedicalRecords::Client).to receive(:list_clinical_notes)
.and_raise(MedicalRecords::PatientNotFound)
allow_any_instance_of(MedicalRecords::Client).to receive(:get_clinical_note)
.and_raise(MedicalRecords::PatientNotFound)
end

it 'returns a 202 Accepted response for GET #index' do
get '/my_health/v1/medical_records/clinical_notes'
expect(response).to have_http_status(:accepted)
end

it 'returns a 202 Accepted response for GET #show' do
get '/my_health/v1/medical_records/clinical_notes/1175305'
expect(response).to have_http_status(:accepted)
end
end
end
end
39 changes: 18 additions & 21 deletions modules/my_health/spec/request/v1/conditions_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,23 @@
expect(response.body).to be_a(String)
end

# TODO: These aren't great error-condition tests because they will eventually be valid API calls.
# Instead, when we get real data from MHV, update these to record actual error cases. For now I
# have commented these out.

# it 'responds with an error to GET #index when no patient ID is provided' do
# VCR.use_cassette('mr_client/get_a_list_of_health_conditions_error') do
# get '/my_health/v1/medical_records/conditions?patient_id='
# end

# expect(response).to have_http_status(:bad_request)
# expect(response.body).to include 'Parameter value missing in request'
# end

# it 'responds with an error to GET #show when no condition ID is provided' do
# VCR.use_cassette('mr_client/get_a_health_condition_error') do
# get '/my_health/v1/medical_records/conditions'
# end

# expect(response).to have_http_status(:bad_request)
# expect(response.body).to include 'Parameter value missing in request'
# end
context 'when the patient is not found' do
before do
allow_any_instance_of(MedicalRecords::Client).to receive(:list_conditions)
.and_raise(MedicalRecords::PatientNotFound)
allow_any_instance_of(MedicalRecords::Client).to receive(:get_condition)
.and_raise(MedicalRecords::PatientNotFound)
end

it 'returns a 202 Accepted response for GET #index' do
get '/my_health/v1/medical_records/conditions'
expect(response).to have_http_status(:accepted)
end

it 'returns a 202 Accepted response for GET #show' do
get '/my_health/v1/medical_records/conditions/39274'
expect(response).to have_http_status(:accepted)
end
end
end
end
19 changes: 19 additions & 0 deletions modules/my_health/spec/request/v1/labs_and_tests_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,24 @@
expect(response).to be_successful
expect(response.body).to be_a(String)
end

context 'when the patient is not found' do
before do
allow_any_instance_of(MedicalRecords::Client).to receive(:list_labs_and_tests)
.and_raise(MedicalRecords::PatientNotFound)
allow_any_instance_of(MedicalRecords::Client).to receive(:get_diagnostic_report)
.and_raise(MedicalRecords::PatientNotFound)
end

it 'returns a 202 Accepted response for GET #index' do
get '/my_health/v1/medical_records/labs_and_tests'
expect(response).to have_http_status(:accepted)
end

it 'returns a 202 Accepted response for GET #show' do
get '/my_health/v1/medical_records/labs_and_tests/40766'
expect(response).to have_http_status(:accepted)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'rails_helper'
require 'support/mr_client_helpers'
require 'medical_records/client'
require 'medical_records/phr_mgr/client'

RSpec.describe 'Medical Records Session', type: :request do
include MedicalRecords::ClientHelpers
Expand All @@ -14,6 +15,7 @@

before do
allow(MedicalRecords::Client).to receive(:new).and_return(authenticated_client)
allow(PHRMgr::Client).to receive(:new).and_return(PHRMgr::Client.new(12_345))
sign_in_as(current_user)
end

Expand All @@ -23,4 +25,25 @@
expect(response).to have_http_status(:no_content)
expect(response.body).to be_empty
end

it 'responds to GET #status' do
VCR.use_cassette('mr_client/get_phr_status') do
get '/my_health/v1/medical_records/session/status'
end

expect(response).to be_successful
expect(response.body).to be_a(String)
end

context 'when the patient is not found' do
before do
allow_any_instance_of(PHRMgr::Client).to receive(:get_phrmgr_status)
.and_raise(MedicalRecords::PatientNotFound)
end

it 'returns a 202 Accepted response for GET #index' do
get '/my_health/v1/medical_records/session/status'
expect(response).to have_http_status(:accepted)
end
end
end
19 changes: 19 additions & 0 deletions modules/my_health/spec/request/v1/vaccines_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,24 @@
expect(response).to be_successful
expect(response.body).to be_a(String)
end

context 'when the patient is not found' do
before do
allow_any_instance_of(MedicalRecords::Client).to receive(:list_vaccines)
.and_raise(MedicalRecords::PatientNotFound)
allow_any_instance_of(MedicalRecords::Client).to receive(:get_vaccine)
.and_raise(MedicalRecords::PatientNotFound)
end

it 'returns a 202 Accepted response for GET #index' do
get '/my_health/v1/medical_records/vaccines'
expect(response).to have_http_status(:accepted)
end

it 'returns a 202 Accepted response for GET #show' do
get '/my_health/v1/medical_records/vaccines/2954'
expect(response).to have_http_status(:accepted)
end
end
end
end
12 changes: 12 additions & 0 deletions modules/my_health/spec/request/v1/vitals_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,17 @@
expect(response).to be_successful
expect(response.body).to be_a(String)
end

context 'when the patient is not found' do
before do
allow_any_instance_of(MedicalRecords::Client).to receive(:list_vitals)
.and_raise(MedicalRecords::PatientNotFound)
end

it 'returns a 202 Accepted response for GET #index' do
get '/my_health/v1/medical_records/vitals'
expect(response).to have_http_status(:accepted)
end
end
end
end
53 changes: 53 additions & 0 deletions spec/support/vcr_cassettes/mr_client/get_phr_status.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1a20c94

Please sign in to comment.