|
15 | 15 |
|
16 | 16 | before do |
17 | 17 | sign_in_as(current_user) |
18 | | - allow_any_instance_of(User).to receive(:va_treatment_facility_ids).and_return(%w[200CRNR]) |
19 | | - allow_any_instance_of(User).to receive(:cerner_facility_ids).and_return([]) |
| 18 | + allow_any_instance_of(User).to receive(:va_treatment_facility_ids).and_return([]) |
| 19 | + allow_any_instance_of(User).to receive(:cerner_facility_ids).and_return(%w[668]) |
20 | 20 | end |
21 | 21 |
|
22 | 22 | describe 'GET /my_health/v2/medical_records/imaging' do |
|
52 | 52 | end |
53 | 53 | end |
54 | 54 |
|
| 55 | + context 'with Vista facility data' do |
| 56 | + before do |
| 57 | + allow_any_instance_of(User).to receive(:va_treatment_facility_ids).and_return(%w[453]) |
| 58 | + allow_any_instance_of(User).to receive(:cerner_facility_ids).and_return([]) |
| 59 | + end |
| 60 | + |
| 61 | + it 'returns Vista imaging studies with study-level modality' do |
| 62 | + VCR.use_cassette('unified_health_data/get_imaging_studies_vista_200', match_requests_on: %i[method path]) do |
| 63 | + get path, headers: { 'X-Key-Inflection' => 'camel' }, params: default_params |
| 64 | + end |
| 65 | + expect(response).to be_successful |
| 66 | + json_response = JSON.parse(response.body) |
| 67 | + expect(json_response).to be_an(Array) |
| 68 | + expect(json_response.size).to eq(2) |
| 69 | + |
| 70 | + knee_study = json_response.find { |s| s['attributes']['description'] == 'KNEE 4 OR MORE VIEWS (LEFT)' } |
| 71 | + ct_study = json_response.find { |s| s['attributes']['description'] == 'CT THORAX W/CONT' } |
| 72 | + |
| 73 | + expect(knee_study).to be_present |
| 74 | + expect(knee_study['attributes']['status']).to eq('available') |
| 75 | + expect(knee_study['attributes']['date']).to be_present |
| 76 | + expect(knee_study['attributes']['imageCount']).to eq(4) |
| 77 | + expect(knee_study['attributes']['modality']).to eq('DX') |
| 78 | + expect(knee_study['id']).to start_with('urn-vastudy-453-') |
| 79 | + |
| 80 | + expect(ct_study).to be_present |
| 81 | + expect(ct_study['attributes']['modality']).to eq('CT') |
| 82 | + expect(ct_study['attributes']['imageCount']).to eq(1) |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + context 'with mixed Vista and Oracle Health facility data' do |
| 87 | + before do |
| 88 | + allow_any_instance_of(User).to receive(:va_treatment_facility_ids).and_return(%w[453]) |
| 89 | + allow_any_instance_of(User).to receive(:cerner_facility_ids).and_return(%w[668]) |
| 90 | + end |
| 91 | + |
| 92 | + it 'returns studies from both Vista and Oracle Health facilities' do |
| 93 | + VCR.use_cassette('unified_health_data/get_imaging_studies_mixed_200', match_requests_on: %i[method path]) do |
| 94 | + get path, headers: { 'X-Key-Inflection' => 'camel' }, params: default_params |
| 95 | + end |
| 96 | + expect(response).to be_successful |
| 97 | + json_response = JSON.parse(response.body) |
| 98 | + expect(json_response).to be_an(Array) |
| 99 | + expect(json_response.size).to eq(4) |
| 100 | + |
| 101 | + vista_studies = json_response.select { |s| s['id'].start_with?('urn-vastudy-453-') } |
| 102 | + oh_studies = json_response.select { |s| s['id'].start_with?('urn-vastudy-200CRNR-') } |
| 103 | + |
| 104 | + expect(vista_studies.size).to eq(2) |
| 105 | + expect(oh_studies.size).to eq(2) |
| 106 | + |
| 107 | + # Vista studies have study-level modality codes |
| 108 | + expect(vista_studies.first['attributes']['modality']).to be_present |
| 109 | + |
| 110 | + # OH studies include notes |
| 111 | + oh_with_notes = oh_studies.find { |s| s['attributes']['notes']&.any? } |
| 112 | + expect(oh_with_notes).to be_present |
| 113 | + end |
| 114 | + end |
| 115 | + |
| 116 | + context 'when user has numeric Cerner facility IDs' do |
| 117 | + before do |
| 118 | + allow_any_instance_of(User).to receive(:va_treatment_facility_ids).and_return(%w[453]) |
| 119 | + allow_any_instance_of(User).to receive(:cerner_facility_ids).and_return(%w[668 552]) |
| 120 | + end |
| 121 | + |
| 122 | + it 'passes 200CRNR sentinel instead of numeric Cerner station numbers' do |
| 123 | + expect_any_instance_of(UnifiedHealthData::ImagingService).to receive(:get_imaging_studies) |
| 124 | + .with(hash_including(site_ids: %w[453 200CRNR])) |
| 125 | + .and_return([]) |
| 126 | + |
| 127 | + get path, headers: { 'X-Key-Inflection' => 'camel' }, params: default_params |
| 128 | + expect(response).to be_successful |
| 129 | + end |
| 130 | + end |
| 131 | + |
| 132 | + context 'when user has no Cerner facilities' do |
| 133 | + before do |
| 134 | + allow_any_instance_of(User).to receive(:va_treatment_facility_ids).and_return(%w[453 358]) |
| 135 | + allow_any_instance_of(User).to receive(:cerner_facility_ids).and_return([]) |
| 136 | + end |
| 137 | + |
| 138 | + # NOTE: Cannot assert site_ids args via expect_any_instance_of here because |
| 139 | + # ActionController::Live processes requests in a separate thread, and nested |
| 140 | + # allow_any_instance_of overrides don't reliably propagate to that thread. |
| 141 | + # The "numeric Cerner facility IDs" context above covers the positive sentinel case. |
| 142 | + it 'returns a successful response without injecting 200CRNR' do |
| 143 | + VCR.use_cassette('unified_health_data/get_imaging_studies_vista_200', match_requests_on: %i[method path]) do |
| 144 | + get path, headers: { 'X-Key-Inflection' => 'camel' }, params: default_params |
| 145 | + end |
| 146 | + expect(response).to be_successful |
| 147 | + end |
| 148 | + end |
| 149 | + |
55 | 150 | context 'error responses' do |
56 | 151 | it 'returns a 500 response when there is a server error' do |
57 | 152 | allow_any_instance_of(UnifiedHealthData::ImagingService).to receive(:get_imaging_studies) |
|
0 commit comments