Skip to content

Commit 109a340

Browse files
Fix must support navigation for Bundle entry type slice sub-elements
1 parent 55e3330 commit 109a340

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

lib/inferno/dsl/fhir_resource_navigation.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def find_slice_via_discriminator(element, property)
124124
slice_name = local_field_name(property.to_s.split(':')[1])
125125

126126
slice_by_name = metadata.must_supports[:slices].find { |slice| slice[:slice_name] == slice_name }
127+
return nil if slice_by_name.blank?
128+
127129
discriminator = slice_by_name[:discriminator]
128130
slices = Array.wrap(element.send(element_name))
129131
slices.find { |slice| matching_slice?(slice, discriminator) }
@@ -192,6 +194,7 @@ def matching_type_slice?(slice, discriminator)
192194
when 'String'
193195
slice_value.is_a? String
194196
else
197+
slice_value = slice_value.resource if slice_value.is_a?(FHIR::Bundle::Entry)
195198
slice_value.is_a? FHIR.const_get(discriminator[:code])
196199
end
197200
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
:name: profile_pas_inquiry_request_bundle
3+
:class_name: ProfilePasInquiryRequestBundleSequence
4+
:version: v2.2.0
5+
:reformatted_version: v220
6+
:resource: Bundle
7+
:profile_url: http://hl7.org/fhir/us/davinci-pas/StructureDefinition/profile-pas-inquiry-request-bundle
8+
:profile_name: PAS Inquiry Request Bundle
9+
:profile_version: 2.2.0
10+
:title: Inquiry Request Bundle
11+
:short_description: Verify support for the server capabilities required by the PAS
12+
Inquiry Request Bundle.
13+
:interactions: []
14+
:operations: []
15+
:required_concepts: []
16+
:must_supports:
17+
:extensions: []
18+
:slices:
19+
- :slice_id: Bundle.entry:Claim
20+
:slice_name: Claim
21+
:path: entry
22+
:discriminator:
23+
:type: type
24+
:code: Claim
25+
:elements:
26+
- :path: identifier
27+
- :path: timestamp
28+
- :path: entry
29+
- :path: entry:Claim.fullUrl
30+
- :path: entry:Claim.resource
31+
:mandatory_elements:
32+
- Bundle.identifier
33+
- Bundle.type
34+
- Bundle.timestamp
35+
- Bundle.entry
36+
- Bundle.entry.fullUrl
37+
- Bundle.entry.resource
38+
:bindings:
39+
- :type: code
40+
:strength: required
41+
:system: http://hl7.org/fhir/ValueSet/bundle-type
42+
:path: type
43+
:references: []
44+
:tests: []
45+
:delayed_references: []

spec/inferno/dsl/fhir_resource_navigation_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,22 @@ def metadata_fixture(filename)
173173
expect(matcher).to_not be_matching_type_slice(slice, discriminator)
174174
end
175175

176+
it 'matches a Bundle::Entry by unwrapping resource when no discriminator path' do
177+
slice = FHIR::Bundle::Entry.new(
178+
resource: FHIR::Claim.new
179+
)
180+
discriminator = { code: 'Claim' }
181+
expect(matcher).to be_matching_type_slice(slice, discriminator)
182+
end
183+
184+
it 'does not match a Bundle::Entry with wrong resource type when no discriminator path' do
185+
slice = FHIR::Bundle::Entry.new(
186+
resource: FHIR::Patient.new
187+
)
188+
discriminator = { code: 'Claim' }
189+
expect(matcher).to_not be_matching_type_slice(slice, discriminator)
190+
end
191+
176192
it 'matches type slice with path for appropriate type' do
177193
slice = FHIR::Bundle::Entry.new(
178194
resource: FHIR::Patient.new

spec/inferno/dsl/must_support_assessment_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,51 @@ def run_with_metadata(resources, metadata)
422422
end
423423
end
424424

425+
context 'with type slicing on a Bundle with slice sub-elements' do
426+
let(:pas_inquiry_bundle_metadata) do
427+
metadata_fixture('pas_inquiry_request_bundle_v220.yml')
428+
end
429+
430+
let(:pas_inquiry_bundle) do
431+
FHIR::Bundle.new(
432+
identifier: {
433+
system: 'http://example.org/SUBMITTER_TRANSACTION_IDENTIFIER',
434+
value: '16139462398'
435+
},
436+
type: 'collection',
437+
timestamp: '2025-06-24T07:34:00+05:00',
438+
entry: [
439+
{
440+
fullUrl: 'http://example.com/Claim/123',
441+
resource: FHIR::Claim.new
442+
}
443+
]
444+
)
445+
end
446+
447+
it 'passes when slice sub-elements fullUrl and resource are present' do
448+
result = run_with_metadata([pas_inquiry_bundle], pas_inquiry_bundle_metadata)
449+
expect(result).to be_empty
450+
end
451+
452+
it 'reports entry:Claim.fullUrl missing when fullUrl is absent' do
453+
pas_inquiry_bundle.entry.first.fullUrl = nil
454+
455+
result = run_with_metadata([pas_inquiry_bundle], pas_inquiry_bundle_metadata)
456+
expect(result).to include('entry:Claim.fullUrl')
457+
expect(result).to_not include('entry:Claim.resource')
458+
end
459+
460+
it 'reports both slice and sub-elements missing when no Claim entry exists' do
461+
pas_inquiry_bundle.entry.clear
462+
463+
result = run_with_metadata([pas_inquiry_bundle], pas_inquiry_bundle_metadata)
464+
expect(result).to include('Bundle.entry:Claim')
465+
expect(result).to include('entry:Claim.fullUrl')
466+
expect(result).to include('entry:Claim.resource')
467+
end
468+
end
469+
425470
context 'with requiredBinding slicing' do
426471
context 'when Condition ProblemsHealthConcerns' do
427472
let(:condition_problems_health_concerns_metadata) do

0 commit comments

Comments
 (0)