Skip to content

Commit

Permalink
Patient relationship failures (#19887)
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-mccurdy authored Dec 18, 2024
1 parent 620033b commit e459d58
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ def index
relationships_params[:facility_id]
)

serialized = VAOS::V2::VAOSSerializer.new.serialize(response, 'relationship')
serialized.each { |relationship| relationship.delete(:id) }

render json: { data: serialized }
render json: response
end

private
Expand Down
40 changes: 39 additions & 1 deletion modules/vaos/app/services/vaos/v2/relationships_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,48 @@ def get_patient_relationships(clinic_service_id, facility_id)
}

response = perform(:get, "/vpg/v1/patients/#{user.icn}/relationships", params, headers)
relationships = response[:body][:data][:relationships].map { |relationship| OpenStruct.new(relationship) }

response[:body][:data][:relationships].map { |relationship| OpenStruct.new(relationship) }
data = VAOS::V2::VAOSSerializer.new.serialize(relationships, 'relationship')
data.each { |relationship| relationship.delete(:id) }

{ data: data, meta: partial_errors(response) }
end
end

private

def partial_errors(response)
return { failures: [] } if response.body[:failures].blank?

log_partial_errors(response)

{
failures: response.body[:failures]
}
end

# Logs partial errors from a response.
#
# @param response [Faraday::Env] The response object containing the status and body.
#
# @return [nil]
#
def log_partial_errors(response)
return unless response.status == 200

failures_dup = response.body[:failures].deep_dup
failures_dup.each do |failure|
detail = failure[:detail]
failure[:detail] = VAOS::Anonymizers.anonymize_icns(detail) if detail.present?
end

log_message_to_sentry(
'VAOS::V2::RelationshipsService#get_patient_relationships has response errors.',
:info,
failures: failures_dup.to_json
)
end
end
end
end
39 changes: 0 additions & 39 deletions modules/vaos/spec/request/v2/relationships_request_spec.rb

This file was deleted.

70 changes: 70 additions & 0 deletions modules/vaos/spec/requests/vaos/v2/relationships_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'relationships', :skip_mvi, type: :request do
before do
sign_in_as(current_user)
allow_any_instance_of(VAOS::UserService).to receive(:session).and_return('stubbed_token')
allow(Flipper).to receive(:enabled?).and_return(true)
end

let(:inflection_header) { { 'X-Key-Inflection' => 'camel' } }

context 'loa3 user' do
let(:current_user) { build(:user, :vaos) }

describe 'GET relationships' do
let(:params) { { clinical_service_id: 'primaryCare', facility_id: '100' } }

context 'patient relationships' do
it 'successfully returns patient relationships' do
VCR.use_cassette('vaos/v2/relationships/get_relationships',
match_requests_on: %i[method path query]) do
get '/vaos/v2/relationships?clinicalServiceId=primaryCare&facilityId=100', params:,
headers: inflection_header
expect(response).to have_http_status(:ok)

relationships = JSON.parse(response.body)['data']
expect(relationships).not_to be_nil
expect(relationships.length).to eq(4)
relationships.each do |relationship|
expect(relationship['type']).to eq('relationship')
end

meta = JSON.parse(response.body)['meta']
expect(meta['failures']).to eq([])
end
end

it 'returns patient relationships containing partial errors' do
VCR.use_cassette('vaos/v2/relationships/get_relationships_partial_error',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)
get '/vaos/v2/relationships?clinicalServiceId=primaryCare&facilityId=100', params:,
headers: inflection_header
expect(response).to have_http_status(:ok)

relationships = JSON.parse(response.body)['data']
expect(relationships).not_to be_nil
expect(relationships.length).to eq(4)
relationships.each do |relationship|
expect(relationship['type']).to eq('relationship')
end

meta = JSON.parse(response.body)['meta']
expect(meta['failures'].length).to eq(1)
expect(meta['failures'][0]['system']).to eq('CFA')
expect(meta['failures'][0]['id']).to eq('id-string')
expect(meta['failures'][0]['status']).to eq('status-string')
expect(meta['failures'][0]['detail']).to eq('detail-string')
expect(meta['failures'][0]['traceId']).to eq('traceId-string')
expect(meta['failures'][0]['code']).to eq(0)

expect(Rails.logger).to have_received(:info).at_least(:once)
end
end
end
end
end
end

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

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

0 comments on commit e459d58

Please sign in to comment.