Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 074483a

Browse files
authored
Send 200CRNR value to SCDF for OH facilities (#27564)
* Send 200CRNR value to SCDF for OH facilities * Addressed Copilot spec concerns
1 parent b64d70b commit 074483a

4 files changed

Lines changed: 600 additions & 5 deletions

File tree

modules/my_health/app/controllers/my_health/v2/imaging_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,18 @@ def default_end_date
177177
Time.zone.today.strftime('%Y-%m-%d')
178178
end
179179

180-
# Combines the user's VistA treatment facility IDs and Cerner (Oracle Health)
181-
# facility IDs to build the full list of sites for SCDF imaging queries.
180+
# Combines the user's VistA treatment facility IDs and Oracle Health indicator
181+
# to build the full list of sites for SCDF imaging queries.
182+
# SCDF expects the sentinel value '200CRNR' when a user has any Cerner-transitioned
183+
# facilities, rather than individual Cerner station numbers.
184+
ORACLE_HEALTH_SITE_ID = '200CRNR'
185+
182186
def user_site_ids
183187
vista_ids = @current_user.va_treatment_facility_ids || []
184188
cerner_ids = @current_user.cerner_facility_ids || []
185-
site_ids = (vista_ids + cerner_ids).map(&:to_s).uniq
189+
site_ids = vista_ids.map(&:to_s)
190+
site_ids << ORACLE_HEALTH_SITE_ID if cerner_ids.present?
191+
site_ids.uniq!
186192

187193
if site_ids.empty?
188194
Rails.logger.warn(

modules/my_health/spec/requests/my_health/v2/imaging_spec.rb

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
before do
1717
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])
2020
end
2121

2222
describe 'GET /my_health/v2/medical_records/imaging' do
@@ -52,6 +52,101 @@
5252
end
5353
end
5454

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+
55150
context 'error responses' do
56151
it 'returns a 500 response when there is a server error' do
57152
allow_any_instance_of(UnifiedHealthData::ImagingService).to receive(:get_imaging_studies)

0 commit comments

Comments
 (0)