Skip to content

Commit 42a50b6

Browse files
committed
Prove we appropriately can handle _elements query parameters
Currently we skip the read interaction and refer to a bug report in the Spark repository.
1 parent 6be7711 commit 42a50b6

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
module Crucible
2+
module Tests
3+
class ElementsSearchParameterTest < BaseSuite
4+
5+
def id
6+
'ElementsSearchParameterTest'
7+
end
8+
9+
def description
10+
'Searching with _elements should return resources containing only the requested elements'
11+
end
12+
13+
def initialize(client1, client2 = nil)
14+
super(client1, client2)
15+
@tags.append('incendilabs')
16+
@category = { id: 'incendilabs', title: 'Incendilabs' }
17+
@supported_versions = [:stu3, :r4]
18+
end
19+
20+
def setup
21+
@patient = ResourceGenerator.minimal_patient('elements-search-parameter', 'Elements', version_namespace)
22+
@patient.gender = 'male'
23+
@patient.birthDate = '1974-12-25'
24+
25+
reply = @client.create(@patient)
26+
assert_response_ok(reply)
27+
@patient_id = reply.id
28+
29+
# Sleep to allow the server to index the new Patient before we attempt to search for it.
30+
# This only applies if the server uses an asynchronous indexing process.
31+
sleep(0.2)
32+
end
33+
34+
def teardown
35+
@client.destroy(version_namespace.const_get(:Patient), @patient_id) unless @patient_id.nil?
36+
end
37+
38+
def elements_search_options
39+
{
40+
search: {
41+
compartment: nil,
42+
parameters: {
43+
'_id' => @patient_id,
44+
'_elements' => 'name,birthDate'
45+
}
46+
}
47+
}
48+
end
49+
50+
test 'I_ELEMENTS_001', 'Search with _elements returns only requested Patient elements' do
51+
metadata {
52+
links "#{BASE_SPEC_LINK}/search.html#elements"
53+
links "#{REST_SPEC_LINK}#search"
54+
validates resource: 'Patient', methods: ['search']
55+
}
56+
57+
reply = @client.search(version_namespace.const_get(:Patient), elements_search_options)
58+
59+
assert_response_ok(reply)
60+
assert_bundle_response(reply)
61+
62+
entries = reply.resource.entry || []
63+
64+
outcome_entries = entries.select do |e|
65+
e.resource.is_a?(version_namespace.const_get(:OperationOutcome)) &&
66+
e.search&.mode == 'outcome'
67+
end
68+
69+
assert(
70+
outcome_entries.empty?,
71+
'Expected _elements to be handled as a general search result parameter, but the searchset Bundle contained an OperationOutcome entry with search.mode=outcome',
72+
reply.body
73+
)
74+
75+
patient_entries = entries.select do |e|
76+
e.resource.is_a?(version_namespace.const_get(:Patient))
77+
end
78+
79+
assert_equal 1, patient_entries.size, 'Expected search by _id and _elements to return exactly one Patient entry.', reply.body
80+
81+
patient = patient_entries.first.resource
82+
assert_equal @patient_id, patient.id, 'Expected the Patient id to be retained even when _elements omits id.', reply.body
83+
assert(patient.name && patient.name.any?, 'Expected Patient.name to be retained when _elements includes name.', reply.body)
84+
assert(patient.gender.nil?, 'Expected Patient.gender to be omitted when _elements only includes name,birthDate.', reply.body)
85+
assert_equal '1974-12-25', patient.birthDate, 'Expected Patient.birthDate to be retained when _elements includes birthDate.', reply.body
86+
end
87+
88+
test 'I_ELEMENTS_002', 'Read with _elements returns only requested Patient elements' do
89+
skip 'https://github.com/FirelyTeam/spark/issues/1336'
90+
91+
metadata {
92+
links "#{BASE_SPEC_LINK}/http.html#read"
93+
links "#{BASE_SPEC_LINK}/search.html#elements"
94+
validates resource: 'Patient', methods: ['read']
95+
}
96+
97+
reply = @client.get(URI::encode("Patient/#{@patient_id}?_elements=name,birthDate"), @client.fhir_headers)
98+
reply.resource = @client.parse_reply(version_namespace.const_get(:Patient), @client.default_format, reply)
99+
100+
assert_response_ok(reply)
101+
assert_resource_type(:Patient, reply.resource)
102+
103+
patient = reply.resource
104+
assert_equal @patient_id, patient.id, 'Expected the Patient id to be retained even when _elements omits id.', reply.body
105+
assert(patient.name && patient.name.any?, 'Expected Patient.name to be retained when _elements includes name.', reply.body)
106+
assert(patient.gender.nil?, 'Expected Patient.gender to be omitted when _elements only includes name,birthDate.', reply.body)
107+
assert_equal '1974-12-25', patient.birthDate, 'Expected Patient.birthDate to be retained when _elements includes birthDate.', reply.body
108+
end
109+
110+
end
111+
end
112+
end

0 commit comments

Comments
 (0)