carin_for_blue_button_test_kit 0.16.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc3ae018d5c2d1d66757dbc4aee6581aa9fff6133fadd08e53bfb878e3d195c7
|
|
4
|
+
data.tar.gz: b43255fea81dd2448331859f79d097ec95c9a3875ff59c002ef7b6ece99ecf63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6021765b19efc64ce350efa5e6add36d8ed530b0f182292d3eb4e25a66b8923a7558052810bd6ef6640f455c6417c198e2f65cc017e79dd270419bdbc94b2dcb
|
|
7
|
+
data.tar.gz: d2c4241a4ffb4f10a45eb087f36207436814b959bad48a30d7369957f0b6814d86c7181e47a2ffba84b322fa67fcac068f9a7ada37ba12450d380f17ca1d2220
|
|
@@ -169,15 +169,16 @@ module CarinForBlueButtonTestKit
|
|
|
169
169
|
|
|
170
170
|
resources
|
|
171
171
|
.select { |resource| resource.is_a?(resource_class) || resource.is_a?(FHIR::Reference) }
|
|
172
|
-
.select { |resource| (resource.is_a?(FHIR::Reference) ? resource.reference
|
|
172
|
+
.select { |resource| (resource.is_a?(FHIR::Reference) ? resource.reference&.split('/')&.last : resource.id).present? }
|
|
173
|
+
.compact
|
|
174
|
+
.uniq { |resource| resource.is_a?(FHIR::Reference) ? resource.reference&.split('/')&.last : resource.id }
|
|
173
175
|
.compact
|
|
174
|
-
.uniq { |resource| resource.is_a?(FHIR::Reference) ? resource.reference.split('/').last : resource.id }
|
|
175
176
|
end
|
|
176
177
|
|
|
177
178
|
def resource_id(resource)
|
|
178
179
|
return if resource.blank?
|
|
179
180
|
|
|
180
|
-
resource.is_a?(FHIR::Reference) ? resource.reference
|
|
181
|
+
resource.is_a?(FHIR::Reference) ? resource.reference&.split('/')&.last : resource.id
|
|
181
182
|
end
|
|
182
183
|
|
|
183
184
|
def perform_response_validation(returned_resources, search_params)
|
|
@@ -240,7 +241,7 @@ module CarinForBlueButtonTestKit
|
|
|
240
241
|
def match_found?(values_found, type, param_value)
|
|
241
242
|
case type
|
|
242
243
|
when 'Reference'
|
|
243
|
-
values_found.any? { |val| param_value.split(',').any? { |item| val
|
|
244
|
+
values_found.any? { |val| param_value.split(',').any? { |item| val&.include?(item) } }
|
|
244
245
|
when 'CodeableConcept'
|
|
245
246
|
codings = values_found.flat_map { |val| val.coding || nil }.compact
|
|
246
247
|
if param_value.include? '|'
|
|
@@ -423,7 +424,7 @@ module CarinForBlueButtonTestKit
|
|
|
423
424
|
def matched_base_resources(_resource, referenced_resource_types, returned_resources_all, values_found)
|
|
424
425
|
included_refs = included_refs(returned_resources_all, referenced_resource_types)
|
|
425
426
|
|
|
426
|
-
values_found.select { |value| value.is_a?(FHIR::Reference) }.select do |base_resource_references|
|
|
427
|
+
values_found.select { |value| value.is_a?(FHIR::Reference) && value.reference.present? }.select do |base_resource_references|
|
|
427
428
|
included_refs.any? do |referenced_resource|
|
|
428
429
|
reference_match?(base_resource_references.reference, referenced_resource)
|
|
429
430
|
end
|
|
@@ -440,6 +441,8 @@ module CarinForBlueButtonTestKit
|
|
|
440
441
|
end
|
|
441
442
|
|
|
442
443
|
def reference_match?(reference, local_reference)
|
|
444
|
+
return false if reference.blank?
|
|
445
|
+
|
|
443
446
|
regex_pattern = %r{^(#{Regexp.escape(local_reference)}|\S+/#{Regexp.escape(local_reference)}(?:[/|]\S+)*)$}
|
|
444
447
|
reference.match?(regex_pattern)
|
|
445
448
|
end
|
|
@@ -468,7 +471,7 @@ module CarinForBlueButtonTestKit
|
|
|
468
471
|
resources.each do |resource|
|
|
469
472
|
references_to_save.each do |reference_to_save|
|
|
470
473
|
resolve_path(resource, reference_to_save[:path])
|
|
471
|
-
.select { |reference| reference.is_a?(FHIR::Reference) && !reference.contained? }
|
|
474
|
+
.select { |reference| reference.is_a?(FHIR::Reference) && !reference.contained? && reference.reference.present? }
|
|
472
475
|
.each do |reference|
|
|
473
476
|
resource_type = reference.resource_class.name.demodulize
|
|
474
477
|
need_to_save = reference_to_save[:resources].include?(resource_type)
|
|
@@ -174,12 +174,8 @@ module CarinForBlueButtonTestKit
|
|
|
174
174
|
|
|
175
175
|
def replace_bundle_urls(bundle)
|
|
176
176
|
reference_server_base = ENV.fetch('FHIR_REFERENCE_SERVER')
|
|
177
|
-
bundle&.link&.
|
|
178
|
-
bundle&.entry&.
|
|
179
|
-
{ fullUrl: bundled_resource.fullUrl.gsub(reference_server_base, new_link),
|
|
180
|
-
resource: bundled_resource.resource,
|
|
181
|
-
search: bundled_resource.search }
|
|
182
|
-
end
|
|
177
|
+
bundle&.link&.each { |link| link.url = link.url.gsub(reference_server_base, new_link) }
|
|
178
|
+
bundle&.entry&.each { |entry| entry.fullUrl = entry.fullUrl.gsub(reference_server_base, new_link) }
|
|
183
179
|
bundle
|
|
184
180
|
end
|
|
185
181
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: carin_for_blue_button_test_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.16.
|
|
4
|
+
version: 0.16.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Morrison
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-09-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: inferno_core
|
|
@@ -16,20 +16,20 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.
|
|
19
|
+
version: '1.4'
|
|
20
20
|
- - ">="
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: 1.3
|
|
22
|
+
version: 1.4.3
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - "~>"
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '1.
|
|
29
|
+
version: '1.4'
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 1.3
|
|
32
|
+
version: 1.4.3
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: smart_app_launch_test_kit
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -814,7 +814,6 @@ files:
|
|
|
814
814
|
- lib/carin_for_blue_button_test_kit/requirements/generated/c4bb_v200_requirements_coverage.csv
|
|
815
815
|
- lib/carin_for_blue_button_test_kit/requirements/generated/c4bb_v200devnonfinancial_requirements_coverage.csv
|
|
816
816
|
- lib/carin_for_blue_button_test_kit/requirements/hl7.fhir.us.carin-bb_2.0.0_reqs.xlsx
|
|
817
|
-
- lib/carin_for_blue_button_test_kit/search_test.rb
|
|
818
817
|
- lib/carin_for_blue_button_test_kit/search_test_properties.rb
|
|
819
818
|
- lib/carin_for_blue_button_test_kit/validation_test.rb
|
|
820
819
|
- lib/carin_for_blue_button_test_kit/version.rb
|
|
@@ -1,781 +0,0 @@
|
|
|
1
|
-
require_relative 'date_search_validator'
|
|
2
|
-
require_relative 'fhir_resource_navigation'
|
|
3
|
-
require_relative 'search_test_properties'
|
|
4
|
-
|
|
5
|
-
module CarinForBlueButtonTestKit
|
|
6
|
-
module SearchTest
|
|
7
|
-
extend Forwardable
|
|
8
|
-
include DateSearchValidation
|
|
9
|
-
include FHIRResourceNavigation
|
|
10
|
-
|
|
11
|
-
def_delegators 'self.class', :metadata, :provenance_metadata, :properties
|
|
12
|
-
def_delegators 'properties',
|
|
13
|
-
:resource_type,
|
|
14
|
-
:search_param_names,
|
|
15
|
-
:saves_delayed_references?,
|
|
16
|
-
:first_search?,
|
|
17
|
-
:fixed_value_search?,
|
|
18
|
-
:possible_status_search?,
|
|
19
|
-
:test_medication_inclusion?,
|
|
20
|
-
:test_post_search?,
|
|
21
|
-
:token_search_params,
|
|
22
|
-
:test_reference_variants?,
|
|
23
|
-
:params_with_comparators,
|
|
24
|
-
:multiple_or_search_params
|
|
25
|
-
|
|
26
|
-
def all_search_params
|
|
27
|
-
@all_search_params ||=
|
|
28
|
-
patient_id_list.each_with_object({}) do |patient_id, params|
|
|
29
|
-
params[patient_id] ||= []
|
|
30
|
-
new_params =
|
|
31
|
-
if fixed_value_search?
|
|
32
|
-
fixed_value_search_param_values.map { |value| fixed_value_search_params(value, patient_id) }
|
|
33
|
-
else
|
|
34
|
-
[search_params_with_values(search_param_names, patient_id)]
|
|
35
|
-
end
|
|
36
|
-
new_params.reject! do |params|
|
|
37
|
-
params.any? { |_key, value| value.blank? }
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
params[patient_id].concat(new_params)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def all_provenance_revinclude_search_params
|
|
45
|
-
@all_provenance_revinclude_search_params ||=
|
|
46
|
-
all_search_params.transform_values! do |params_list|
|
|
47
|
-
params_list.map { |params| params.merge(_revinclude: 'Provenance:target') }
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def any_valid_search_params?(search_params)
|
|
52
|
-
search_params.any? { |_patient_id, params| params.present? }
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def run_provenance_revinclude_search_test
|
|
56
|
-
# TODO: skip if not supported?
|
|
57
|
-
skip_if !any_valid_search_params?(all_provenance_revinclude_search_params), unable_to_resolve_params_message
|
|
58
|
-
|
|
59
|
-
provenance_resources =
|
|
60
|
-
all_provenance_revinclude_search_params.flat_map do |_patient_id, params_list|
|
|
61
|
-
params_list.flat_map do |params|
|
|
62
|
-
fhir_search resource_type, params: params
|
|
63
|
-
|
|
64
|
-
perform_search_with_status(params, patient_id) if response[:status] == 400 && possible_status_search?
|
|
65
|
-
|
|
66
|
-
check_search_response
|
|
67
|
-
|
|
68
|
-
fetch_all_bundled_resources(additional_resource_types: ['Provenance'])
|
|
69
|
-
.select { |resource| resource.resourceType == 'Provenance' }
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
scratch_provenance_resources[:all] ||= []
|
|
74
|
-
scratch_provenance_resources[:all].concat(provenance_resources)
|
|
75
|
-
|
|
76
|
-
save_delayed_references(provenance_resources, 'Provenance')
|
|
77
|
-
|
|
78
|
-
skip_if provenance_resources.empty?, no_resources_skip_message('Provenance')
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def run_search_test
|
|
82
|
-
# TODO: skip if not supported?
|
|
83
|
-
skip_if !any_valid_search_params?(all_search_params), unable_to_resolve_params_message
|
|
84
|
-
|
|
85
|
-
resources_returned =
|
|
86
|
-
all_search_params.flat_map do |patient_id, params_list|
|
|
87
|
-
params_list.flat_map { |params| perform_search(params, patient_id) }
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
skip_if resources_returned.empty?, no_resources_skip_message
|
|
91
|
-
|
|
92
|
-
perform_multiple_or_search_test if multiple_or_search_params.present?
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def perform_search(params, patient_id)
|
|
96
|
-
fhir_search resource_type, params: params
|
|
97
|
-
|
|
98
|
-
perform_search_with_status(params, patient_id) if response[:status] == 400 && possible_status_search?
|
|
99
|
-
|
|
100
|
-
check_search_response
|
|
101
|
-
|
|
102
|
-
resources_returned =
|
|
103
|
-
fetch_all_bundled_resources.select { |resource| resource.resourceType == resource_type }
|
|
104
|
-
|
|
105
|
-
return [] if resources_returned.blank?
|
|
106
|
-
|
|
107
|
-
perform_comparator_searches(params, patient_id) if params_with_comparators.present?
|
|
108
|
-
|
|
109
|
-
filter_conditions(resources_returned) if resource_type == 'Condition' && metadata.version == 'v5.0.1'
|
|
110
|
-
filter_devices(resources_returned) if resource_type == 'Device'
|
|
111
|
-
|
|
112
|
-
if first_search?
|
|
113
|
-
all_scratch_resources.concat(resources_returned).uniq!
|
|
114
|
-
scratch_resources_for_patient(patient_id).concat(resources_returned).uniq!
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
resources_returned.each do |resource|
|
|
118
|
-
check_resource_against_params(resource, params)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
save_delayed_references(resources_returned) if saves_delayed_references?
|
|
122
|
-
|
|
123
|
-
return resources_returned if all_search_variants_tested?
|
|
124
|
-
|
|
125
|
-
perform_post_search(resources_returned, params) if test_post_search?
|
|
126
|
-
test_medication_inclusion(resources_returned, params, patient_id) if test_medication_inclusion?
|
|
127
|
-
perform_reference_with_type_search(params, resources_returned.count) if test_reference_variants?
|
|
128
|
-
perform_search_with_system(params, patient_id) if token_search_params.present?
|
|
129
|
-
|
|
130
|
-
resources_returned
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def perform_post_search(get_search_resources, params)
|
|
134
|
-
fhir_search resource_type, params: params, search_method: :post
|
|
135
|
-
|
|
136
|
-
check_search_response
|
|
137
|
-
|
|
138
|
-
post_search_resources = fetch_all_bundled_resources.select { |resource| resource.resourceType == resource_type }
|
|
139
|
-
|
|
140
|
-
filter_conditions(post_search_resources) if resource_type == 'Condition' && metadata.version == 'v5.0.1'
|
|
141
|
-
filter_devices(post_search_resources) if resource_type == 'Device'
|
|
142
|
-
|
|
143
|
-
get_resource_count = get_search_resources.length
|
|
144
|
-
post_resource_count = post_search_resources.length
|
|
145
|
-
|
|
146
|
-
search_variant_test_records[:post_variant] = true
|
|
147
|
-
|
|
148
|
-
assert get_resource_count == post_resource_count,
|
|
149
|
-
"Expected search by POST to return the same results as search by GET, " \
|
|
150
|
-
"but GET search returned #{get_resource_count} resources, and POST search " \
|
|
151
|
-
"returned #{post_resource_count} resources."
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def filter_devices(resources)
|
|
155
|
-
codes_to_include = implantable_device_codes&.split(',')&.map(&:strip)
|
|
156
|
-
return resources if codes_to_include.blank?
|
|
157
|
-
|
|
158
|
-
resources.select! do |resource|
|
|
159
|
-
resource&.type&.coding&.any? { |coding| codes_to_include.include?(coding.code) }
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def filter_conditions(resources)
|
|
164
|
-
# HL7 JIRA FHIR-37917. US Core v5.0.1 does not required patient+category.
|
|
165
|
-
# In order to distinguish which resources matches the current profile, Inferno has to manually filter
|
|
166
|
-
# the result of first search, which is searching by patient.
|
|
167
|
-
resources.select! do |resource|
|
|
168
|
-
resource.category.any? do |category|
|
|
169
|
-
category.coding.any? do |coding|
|
|
170
|
-
metadata.search_definitions[:category][:values].include? coding.code
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def search_and_check_response(params, resource_type = self.resource_type)
|
|
177
|
-
fhir_search resource_type, params: params
|
|
178
|
-
|
|
179
|
-
check_search_response
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def check_search_response
|
|
183
|
-
assert_response_status(200)
|
|
184
|
-
assert_resource_type(:bundle)
|
|
185
|
-
# NOTE: how do we want to handle validating Bundles?
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
def search_variant_test_records
|
|
189
|
-
@search_variant_test_records ||= initial_search_variant_test_records
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def initial_search_variant_test_records
|
|
193
|
-
{}.tap do |records|
|
|
194
|
-
records[:post_variant] = false if test_post_search?
|
|
195
|
-
records[:medication_inclusion] = false if test_medication_inclusion?
|
|
196
|
-
records[:reference_variants] = false if test_reference_variants?
|
|
197
|
-
records[:token_variants] = false if token_search_params.present?
|
|
198
|
-
records[:comparator_searches] = Set.new if params_with_comparators.present?
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
def all_search_variants_tested?
|
|
203
|
-
search_variant_test_records.all? { |_variant, tested| tested.present? } &&
|
|
204
|
-
all_comparator_searches_tested?
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def all_comparator_searches_tested?
|
|
208
|
-
return true if params_with_comparators.blank?
|
|
209
|
-
|
|
210
|
-
Set.new(params_with_comparators) == search_variant_test_records[:comparator_searches]
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def date_comparator_value(comparator, date)
|
|
214
|
-
date = date.start || date.end if date.is_a? FHIR::Period
|
|
215
|
-
case comparator
|
|
216
|
-
when 'lt', 'le'
|
|
217
|
-
comparator + (DateTime.xmlschema(date) + 1).xmlschema
|
|
218
|
-
when 'gt', 'ge'
|
|
219
|
-
comparator + (DateTime.xmlschema(date) - 1).xmlschema
|
|
220
|
-
else
|
|
221
|
-
# ''
|
|
222
|
-
raise "Unsupported comparator '#{comparator}'"
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
def required_comparators(name)
|
|
227
|
-
metadata
|
|
228
|
-
.search_definitions
|
|
229
|
-
.dig(name.to_sym, :comparators)
|
|
230
|
-
.select { |_comparator, expectation| expectation == 'SHALL' }
|
|
231
|
-
.keys
|
|
232
|
-
.map(&:to_s)
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
def perform_comparator_searches(params, patient_id)
|
|
236
|
-
params_with_comparators.each do |name|
|
|
237
|
-
next if search_variant_test_records[:comparator_searches].include? name
|
|
238
|
-
|
|
239
|
-
required_comparators(name).each do |comparator|
|
|
240
|
-
paths = search_param_paths(name).first
|
|
241
|
-
date_element = find_a_value_at(scratch_resources_for_patient(patient_id), paths)
|
|
242
|
-
params_with_comparator = params.merge(name => date_comparator_value(comparator, date_element))
|
|
243
|
-
|
|
244
|
-
search_and_check_response(params_with_comparator)
|
|
245
|
-
|
|
246
|
-
fetch_all_bundled_resources.each do |resource|
|
|
247
|
-
check_resource_against_params(resource, params_with_comparator) if resource.resourceType == resource_type
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
search_variant_test_records[:comparator_searches] << name
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
def perform_reference_with_type_search(params, resource_count)
|
|
256
|
-
return if resource_count == 0
|
|
257
|
-
return if search_variant_test_records[:reference_variants]
|
|
258
|
-
|
|
259
|
-
new_search_params = params.merge('patient' => "Patient/#{params['patient']}")
|
|
260
|
-
search_and_check_response(new_search_params)
|
|
261
|
-
|
|
262
|
-
reference_with_type_resources = fetch_all_bundled_resources.select { |resource| resource.resourceType == resource_type }
|
|
263
|
-
|
|
264
|
-
filter_conditions(reference_with_type_resources) if resource_type == 'Condition' && metadata.version == 'v5.0.1'
|
|
265
|
-
filter_devices(reference_with_type_resources) if resource_type == 'Device'
|
|
266
|
-
|
|
267
|
-
new_resource_count = reference_with_type_resources.count
|
|
268
|
-
|
|
269
|
-
assert new_resource_count == resource_count,
|
|
270
|
-
"Expected search by `#{params['patient']}` to to return the same results as searching " \
|
|
271
|
-
"by `#{new_search_params['patient']}`, but found #{resource_count} resources with " \
|
|
272
|
-
"`#{params['patient']}` and #{new_resource_count} with `#{new_search_params['patient']}`"
|
|
273
|
-
|
|
274
|
-
search_variant_test_records[:reference_variants] = true
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
def perform_search_with_system(params, patient_id)
|
|
278
|
-
return if search_variant_test_records[:token_variants]
|
|
279
|
-
|
|
280
|
-
new_search_params = search_params_with_values(token_search_params, patient_id, include_system: true)
|
|
281
|
-
return if new_search_params.any? { |_name, value| value.blank? }
|
|
282
|
-
|
|
283
|
-
search_params = params.merge(new_search_params)
|
|
284
|
-
search_and_check_response(search_params)
|
|
285
|
-
|
|
286
|
-
resources_returned =
|
|
287
|
-
fetch_all_bundled_resources
|
|
288
|
-
.select { |resource| resource.resourceType == resource_type }
|
|
289
|
-
|
|
290
|
-
assert resources_returned.present?, "No resources were returned when searching by `system|code`"
|
|
291
|
-
|
|
292
|
-
search_variant_test_records[:token_variants] = true
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
def perform_search_with_status(
|
|
296
|
-
original_params,
|
|
297
|
-
patient_id,
|
|
298
|
-
status_search_values: self.status_search_values,
|
|
299
|
-
resource_type: self.resource_type
|
|
300
|
-
)
|
|
301
|
-
assert resource.is_a?(FHIR::OperationOutcome), "Server returned a status of 400 without an OperationOutcome"
|
|
302
|
-
# TODO: warn about documenting status requirements
|
|
303
|
-
status_search_values.flat_map do |status_value|
|
|
304
|
-
search_params = original_params.merge("#{status_search_param_name}": status_value)
|
|
305
|
-
|
|
306
|
-
search_and_check_response(search_params)
|
|
307
|
-
|
|
308
|
-
entries = resource.entry.select { |entry| entry.resource.resourceType == resource_type }
|
|
309
|
-
|
|
310
|
-
if entries.present?
|
|
311
|
-
original_params.merge!("#{status_search_param_name}": status_value)
|
|
312
|
-
break
|
|
313
|
-
end
|
|
314
|
-
end
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
def status_search_param_name
|
|
318
|
-
@status_search_param_name ||=
|
|
319
|
-
metadata.search_definitions.keys.find { |key| key.to_s.include? 'status' }
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
def status_search_values
|
|
323
|
-
default_search_values(status_search_param_name)
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
def default_search_values(param_name)
|
|
327
|
-
definition = metadata.search_definitions[param_name]
|
|
328
|
-
return [] if definition.blank?
|
|
329
|
-
|
|
330
|
-
definition[:multiple_or] == 'SHALL' ? [definition[:values].join(',')] : Array.wrap(definition[:values])
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
def perform_multiple_or_search_test
|
|
335
|
-
resolved_one = false
|
|
336
|
-
|
|
337
|
-
all_search_params.each do |patient_id, params_list|
|
|
338
|
-
next unless params_list.present?
|
|
339
|
-
|
|
340
|
-
search_params = params_list.first
|
|
341
|
-
existing_values = {}
|
|
342
|
-
missing_values = {}
|
|
343
|
-
|
|
344
|
-
multiple_or_search_params.each do |param_name|
|
|
345
|
-
search_value = default_search_values(param_name.to_sym)
|
|
346
|
-
search_params = search_params.merge("#{param_name}" => search_value)
|
|
347
|
-
existing_values[param_name.to_sym] = scratch_resources_for_patient(patient_id).map(¶m_name.to_sym).compact.uniq
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
# skip patient without multiple-or values
|
|
351
|
-
next if existing_values.values.any?(&:empty?)
|
|
352
|
-
|
|
353
|
-
resolved_one = true
|
|
354
|
-
|
|
355
|
-
search_and_check_response(search_params)
|
|
356
|
-
|
|
357
|
-
resources_returned =
|
|
358
|
-
fetch_all_bundled_resources
|
|
359
|
-
.select { |resource| resource.resourceType == resource_type }
|
|
360
|
-
|
|
361
|
-
multiple_or_search_params.each do |param_name|
|
|
362
|
-
missing_values[param_name.to_sym] = existing_values[param_name.to_sym] - resources_returned.map(¶m_name.to_sym)
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
missing_value_message = missing_values
|
|
366
|
-
.reject { |_param_name, missing_value| missing_value.empty? }
|
|
367
|
-
.map { |param_name, missing_value| "#{missing_value.join(',')} values from #{param_name}" }
|
|
368
|
-
.join(' and ')
|
|
369
|
-
|
|
370
|
-
assert missing_value_message.blank?, "Could not find #{missing_value_message} in any of the resources returned for Patient/#{patient_id}"
|
|
371
|
-
|
|
372
|
-
break if resolved_one
|
|
373
|
-
end
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
def test_medication_inclusion(medication_requests, params, patient_id)
|
|
377
|
-
return if search_variant_test_records[:medication_inclusion]
|
|
378
|
-
|
|
379
|
-
scratch[:medication_resources] ||= {}
|
|
380
|
-
scratch[:medication_resources][:all] ||= []
|
|
381
|
-
scratch[:medication_resources][patient_id] ||= []
|
|
382
|
-
scratch[:medication_resources][:contained] ||= []
|
|
383
|
-
|
|
384
|
-
requests_with_external_references =
|
|
385
|
-
medication_requests
|
|
386
|
-
.select { |request| request&.medicationReference&.present? }
|
|
387
|
-
.reject { |request| request&.medicationReference&.reference&.start_with? '#' }
|
|
388
|
-
|
|
389
|
-
contained_medications =
|
|
390
|
-
medication_requests
|
|
391
|
-
.select { |request| request&.medicationReference&.reference&.start_with? '#' }
|
|
392
|
-
.flat_map(&:contained)
|
|
393
|
-
.select { |resource| resource.resourceType == 'Medication' }
|
|
394
|
-
|
|
395
|
-
scratch[:medication_resources][:all] += contained_medications
|
|
396
|
-
scratch[:medication_resources][patient_id] += contained_medications
|
|
397
|
-
scratch[:medication_resources][:contained] += contained_medications
|
|
398
|
-
|
|
399
|
-
return if requests_with_external_references.blank?
|
|
400
|
-
|
|
401
|
-
search_params = params.merge(_include: 'MedicationRequest:medication')
|
|
402
|
-
|
|
403
|
-
search_and_check_response(search_params)
|
|
404
|
-
|
|
405
|
-
medications = fetch_all_bundled_resources.select { |resource| resource.resourceType == 'Medication' }
|
|
406
|
-
assert medications.present?, 'No Medications were included in the search results'
|
|
407
|
-
|
|
408
|
-
medications.uniq!(&:id)
|
|
409
|
-
|
|
410
|
-
scratch[:medication_resources][:all] += medications
|
|
411
|
-
scratch[:medication_resources][patient_id] += medications
|
|
412
|
-
|
|
413
|
-
search_variant_test_records[:medication_inclusion] = true
|
|
414
|
-
end
|
|
415
|
-
|
|
416
|
-
def all_scratch_resources
|
|
417
|
-
scratch_resources[:all] ||= []
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
def scratch_resources_for_patient(patient_id)
|
|
421
|
-
return all_scratch_resources if patient_id.nil?
|
|
422
|
-
|
|
423
|
-
scratch_resources[patient_id] ||= []
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
def references_to_save(resource_type = nil)
|
|
427
|
-
reference_metadata = resource_type == 'Provenance' ? provenance_metadata : metadata
|
|
428
|
-
reference_metadata.delayed_references
|
|
429
|
-
end
|
|
430
|
-
|
|
431
|
-
def fixed_value_search_param_name
|
|
432
|
-
(search_param_names - ['patient']).first
|
|
433
|
-
end
|
|
434
|
-
|
|
435
|
-
def fixed_value_search_param_values
|
|
436
|
-
metadata.search_definitions[fixed_value_search_param_name.to_sym][:values]
|
|
437
|
-
end
|
|
438
|
-
|
|
439
|
-
def fixed_value_search_params(value, patient_id)
|
|
440
|
-
search_param_names.each_with_object({}) do |name, params|
|
|
441
|
-
patient_id_param?(name) ? params[name] = patient_id : params[name] = value
|
|
442
|
-
end
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
def search_params_with_values(search_param_names, patient_id, include_system: false)
|
|
446
|
-
resources = scratch_resources_for_patient(patient_id)
|
|
447
|
-
|
|
448
|
-
#if resources.empty?
|
|
449
|
-
#return search_param_names.each_with_object({}) do |name, params|
|
|
450
|
-
#value = patient_id_param?(name) ? patient_id : nil
|
|
451
|
-
#params[name] = value
|
|
452
|
-
# end
|
|
453
|
-
#end
|
|
454
|
-
|
|
455
|
-
params_with_partial_value = resources.each_with_object({}) do |resource, outer_params|
|
|
456
|
-
results_from_one_resource = search_param_names.each_with_object({}) do |name, params|
|
|
457
|
-
value = patient_id_param?(name) ? patient_id : search_param_value(name, resource, include_system: include_system)
|
|
458
|
-
params[name] = value
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
outer_params.merge!(results_from_one_resource)
|
|
462
|
-
|
|
463
|
-
# stop if all parameter values are found
|
|
464
|
-
return outer_params if outer_params.all? { |_key, value| value.present? }
|
|
465
|
-
end
|
|
466
|
-
|
|
467
|
-
params_with_partial_value
|
|
468
|
-
end
|
|
469
|
-
|
|
470
|
-
def patient_id_list
|
|
471
|
-
return [nil] unless respond_to? :patient_ids
|
|
472
|
-
|
|
473
|
-
patient_ids.split(',').map(&:strip)
|
|
474
|
-
end
|
|
475
|
-
|
|
476
|
-
def patient_search?
|
|
477
|
-
search_param_names.any? { |name| patient_id_param? name }
|
|
478
|
-
end
|
|
479
|
-
|
|
480
|
-
def patient_id_param?(name)
|
|
481
|
-
name == 'patient' || (name == '_id' && resource_type == 'Patient')
|
|
482
|
-
end
|
|
483
|
-
|
|
484
|
-
def search_param_paths(name)
|
|
485
|
-
paths = metadata.search_definitions[name.to_sym][:paths]
|
|
486
|
-
if paths.first =='class'
|
|
487
|
-
paths[0] = 'local_class'
|
|
488
|
-
end
|
|
489
|
-
|
|
490
|
-
paths
|
|
491
|
-
end
|
|
492
|
-
|
|
493
|
-
def all_search_params_present?(params)
|
|
494
|
-
params.all? { |_name, value| value.present? }
|
|
495
|
-
end
|
|
496
|
-
|
|
497
|
-
def array_of_codes(array)
|
|
498
|
-
array.map { |name| "`#{name}`" }.join(', ')
|
|
499
|
-
end
|
|
500
|
-
|
|
501
|
-
def unable_to_resolve_params_message
|
|
502
|
-
"Could not find values for all search params #{array_of_codes(search_param_names)}"
|
|
503
|
-
end
|
|
504
|
-
|
|
505
|
-
def empty_search_params_message(empty_search_params)
|
|
506
|
-
"Could not find values for the search parameters #{array_of_codes(empty_search_params.keys)}"
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
def no_resources_skip_message(resource_type = self.resource_type)
|
|
510
|
-
msg = "No #{resource_type} resources appear to be available"
|
|
511
|
-
|
|
512
|
-
if (resource_type == 'Device' && implantable_device_codes.present?)
|
|
513
|
-
msg.concat(" with the following Device Type Code filter: #{implantable_device_codes}")
|
|
514
|
-
end
|
|
515
|
-
|
|
516
|
-
msg + ". Please use patients with more information"
|
|
517
|
-
end
|
|
518
|
-
|
|
519
|
-
def fetch_all_bundled_resources(
|
|
520
|
-
reply_handler: nil,
|
|
521
|
-
max_pages: 20,
|
|
522
|
-
additional_resource_types: [],
|
|
523
|
-
resource_type: self.resource_type
|
|
524
|
-
)
|
|
525
|
-
page_count = 1
|
|
526
|
-
resources = []
|
|
527
|
-
bundle = resource
|
|
528
|
-
|
|
529
|
-
until bundle.nil? || page_count == max_pages
|
|
530
|
-
resources += bundle&.entry&.map { |entry| entry&.resource }
|
|
531
|
-
next_bundle_link = bundle&.link&.find { |link| link.relation == 'next' }&.url
|
|
532
|
-
reply_handler&.call(response)
|
|
533
|
-
|
|
534
|
-
break if next_bundle_link.blank?
|
|
535
|
-
|
|
536
|
-
reply = fhir_client.raw_read_url(next_bundle_link)
|
|
537
|
-
|
|
538
|
-
store_request('outgoing') { reply }
|
|
539
|
-
error_message = cant_resolve_next_bundle_message(next_bundle_link)
|
|
540
|
-
|
|
541
|
-
assert_response_status(200)
|
|
542
|
-
assert_valid_json(reply.body, error_message)
|
|
543
|
-
|
|
544
|
-
bundle = fhir_client.parse_reply(FHIR::Bundle, fhir_client.default_format, reply)
|
|
545
|
-
|
|
546
|
-
page_count += 1
|
|
547
|
-
end
|
|
548
|
-
|
|
549
|
-
valid_resource_types = [resource_type, 'OperationOutcome'].concat(additional_resource_types)
|
|
550
|
-
valid_resource_types << 'Medication' if resource_type == 'MedicationRequest'
|
|
551
|
-
|
|
552
|
-
invalid_resource_types =
|
|
553
|
-
resources.reject { |entry| valid_resource_types.include? entry.resourceType }
|
|
554
|
-
.map(&:resourceType)
|
|
555
|
-
.uniq
|
|
556
|
-
|
|
557
|
-
if invalid_resource_types.any?
|
|
558
|
-
info "Received resource type(s) #{invalid_resource_types.join(', ')} in search bundle, " \
|
|
559
|
-
"but only expected resource types #{valid_resource_types.join(', ')}. " + \
|
|
560
|
-
"This is unusual but allowed if the server believes additional resource types are relevant."
|
|
561
|
-
end
|
|
562
|
-
|
|
563
|
-
resources
|
|
564
|
-
end
|
|
565
|
-
|
|
566
|
-
def cant_resolve_next_bundle_message(link)
|
|
567
|
-
"Could not resolve next bundle: #{link}"
|
|
568
|
-
end
|
|
569
|
-
|
|
570
|
-
def search_param_value(name, resource, include_system: false)
|
|
571
|
-
paths = search_param_paths(name)
|
|
572
|
-
search_value = nil
|
|
573
|
-
paths.each do |path|
|
|
574
|
-
element = find_a_value_at(resource, path) { |element| element_has_valid_value?(element, include_system) }
|
|
575
|
-
|
|
576
|
-
search_value =
|
|
577
|
-
case element
|
|
578
|
-
when FHIR::Period
|
|
579
|
-
if element.start.present?
|
|
580
|
-
'gt' + (DateTime.xmlschema(element.start) - 1).xmlschema
|
|
581
|
-
else
|
|
582
|
-
end_datetime = get_fhir_datetime_range(element.end)[:end]
|
|
583
|
-
'lt' + (end_datetime + 1).xmlschema
|
|
584
|
-
end
|
|
585
|
-
when FHIR::Reference
|
|
586
|
-
element.reference
|
|
587
|
-
when FHIR::CodeableConcept
|
|
588
|
-
if include_system
|
|
589
|
-
coding =
|
|
590
|
-
find_a_value_at(element, 'coding') { |coding| coding.code.present? && coding.system.present? }
|
|
591
|
-
"#{coding.system}|#{coding.code}"
|
|
592
|
-
else
|
|
593
|
-
find_a_value_at(element, 'coding.code')
|
|
594
|
-
end
|
|
595
|
-
when FHIR::Identifier
|
|
596
|
-
include_system ? "#{element.system}|#{element.value}" : element.value
|
|
597
|
-
when FHIR::Coding
|
|
598
|
-
include_system ? "#{element.system}|#{element.code}" : element.code
|
|
599
|
-
when FHIR::HumanName
|
|
600
|
-
element.family || element.given&.first || element.text
|
|
601
|
-
when FHIR::Address
|
|
602
|
-
element.text || element.city || element.state || element.postalCode || element.country
|
|
603
|
-
else
|
|
604
|
-
if metadata.version != 'v3.1.1' &&
|
|
605
|
-
metadata.search_definitions[name.to_sym][:type] == 'date' &&
|
|
606
|
-
params_with_comparators&.include?(name)
|
|
607
|
-
# convert date search to greath-than comparator search with correct precision
|
|
608
|
-
# For all date search parameters:
|
|
609
|
-
# Patient.birthDate does not mandate comparators so cannot be converted
|
|
610
|
-
# Goal.target-date has day precision
|
|
611
|
-
# All others have second + time offset precision
|
|
612
|
-
if /^\d{4}(-\d{2})?$/.match?(element) || # YYYY or YYYY-MM
|
|
613
|
-
(/^\d{4}-\d{2}-\d{2}$/.match?(element) && resource_type != "Goal") # YYY-MM-DD AND Resource is NOT Goal
|
|
614
|
-
"gt#{(DateTime.xmlschema(element)-1).xmlschema}"
|
|
615
|
-
else
|
|
616
|
-
element
|
|
617
|
-
end
|
|
618
|
-
else
|
|
619
|
-
element
|
|
620
|
-
end
|
|
621
|
-
end
|
|
622
|
-
|
|
623
|
-
break if search_value.present?
|
|
624
|
-
end
|
|
625
|
-
|
|
626
|
-
escaped_value = search_value&.gsub(',', '\\,')
|
|
627
|
-
escaped_value
|
|
628
|
-
end
|
|
629
|
-
|
|
630
|
-
def element_has_valid_value?(element, include_system)
|
|
631
|
-
case element
|
|
632
|
-
when FHIR::Reference
|
|
633
|
-
element.reference.present?
|
|
634
|
-
when FHIR::CodeableConcept
|
|
635
|
-
if include_system
|
|
636
|
-
coding =
|
|
637
|
-
find_a_value_at(element, 'coding') { |coding| coding.code.present? && coding.system.present? }
|
|
638
|
-
coding.present?
|
|
639
|
-
else
|
|
640
|
-
find_a_value_at(element, 'coding.code').present?
|
|
641
|
-
end
|
|
642
|
-
when FHIR::Identifier
|
|
643
|
-
include_system ? element.value.present? && element.system.present? : element.value.present?
|
|
644
|
-
when FHIR::Coding
|
|
645
|
-
include_system ? element.code.present? && element.system.present? : element.code.present?
|
|
646
|
-
when FHIR::HumanName
|
|
647
|
-
(element.family || element.given&.first || element.text).present?
|
|
648
|
-
when FHIR::Address
|
|
649
|
-
(element.text || element.city || element.state || element.postalCode || element.country).present?
|
|
650
|
-
else
|
|
651
|
-
true
|
|
652
|
-
end
|
|
653
|
-
end
|
|
654
|
-
|
|
655
|
-
def save_resource_reference(resource_type, reference)
|
|
656
|
-
scratch[:references] ||= {}
|
|
657
|
-
scratch[:references][resource_type] ||= Set.new
|
|
658
|
-
scratch[:references][resource_type] << reference
|
|
659
|
-
end
|
|
660
|
-
|
|
661
|
-
def save_delayed_references(resources, containing_resource_type = self.resource_type)
|
|
662
|
-
resources.each do |resource|
|
|
663
|
-
references_to_save(containing_resource_type).each do |reference_to_save|
|
|
664
|
-
resolve_path(resource, reference_to_save[:path])
|
|
665
|
-
.select { |reference| reference.is_a?(FHIR::Reference) && !reference.contained? }
|
|
666
|
-
.each do |reference|
|
|
667
|
-
resource_type = reference.resource_class.name.demodulize
|
|
668
|
-
need_to_save = reference_to_save[:resources].include?(resource_type)
|
|
669
|
-
next unless need_to_save
|
|
670
|
-
|
|
671
|
-
save_resource_reference(resource_type, reference)
|
|
672
|
-
end
|
|
673
|
-
end
|
|
674
|
-
end
|
|
675
|
-
end
|
|
676
|
-
|
|
677
|
-
#### RESULT CHECKING ####
|
|
678
|
-
|
|
679
|
-
def check_resource_against_params(resource, params)
|
|
680
|
-
params.each do |name, escaped_search_value|
|
|
681
|
-
#unescape search value
|
|
682
|
-
search_value = escaped_search_value&.gsub('\\,', ',')
|
|
683
|
-
paths = search_param_paths(name)
|
|
684
|
-
|
|
685
|
-
match_found = false
|
|
686
|
-
values_found = []
|
|
687
|
-
|
|
688
|
-
paths.each do |path|
|
|
689
|
-
type = metadata.search_definitions[name.to_sym][:type]
|
|
690
|
-
values_found =
|
|
691
|
-
resolve_path(resource, path)
|
|
692
|
-
.map do |value|
|
|
693
|
-
if value.is_a? FHIR::Reference
|
|
694
|
-
value.reference
|
|
695
|
-
else
|
|
696
|
-
value
|
|
697
|
-
end
|
|
698
|
-
end
|
|
699
|
-
|
|
700
|
-
match_found =
|
|
701
|
-
case type
|
|
702
|
-
when 'Period', 'date', 'instant', 'dateTime'
|
|
703
|
-
values_found.any? { |date| validate_date_search(search_value, date) }
|
|
704
|
-
when 'HumanName'
|
|
705
|
-
# When a string search parameter refers to the types HumanName and Address,
|
|
706
|
-
# the search covers the elements of type string, and does not cover elements such as use and period
|
|
707
|
-
# https://www.hl7.org/fhir/search.html#string
|
|
708
|
-
search_value_downcase = search_value.downcase
|
|
709
|
-
values_found.any? do |name|
|
|
710
|
-
name&.text&.downcase&.start_with?(search_value_downcase) ||
|
|
711
|
-
name&.family&.downcase&.start_with?(search_value_downcase) ||
|
|
712
|
-
name&.given&.any? { |given| given.downcase.start_with?(search_value_downcase) } ||
|
|
713
|
-
name&.prefix&.any? { |prefix| prefix.downcase.start_with?(search_value_downcase) } ||
|
|
714
|
-
name&.suffix&.any? { |suffix| suffix.downcase.start_with?(search_value_downcase) }
|
|
715
|
-
end
|
|
716
|
-
when 'Address'
|
|
717
|
-
search_value_downcase = search_value.downcase
|
|
718
|
-
values_found.any? do |address|
|
|
719
|
-
address&.text&.downcase&.start_with?(search_value_downcase) ||
|
|
720
|
-
address&.city&.downcase&.start_with?(search_value_downcase) ||
|
|
721
|
-
address&.state&.downcase&.start_with?(search_value_downcase) ||
|
|
722
|
-
address&.postalCode&.downcase&.start_with?(search_value_downcase) ||
|
|
723
|
-
address&.country&.downcase&.start_with?(search_value_downcase)
|
|
724
|
-
end
|
|
725
|
-
when 'CodeableConcept'
|
|
726
|
-
# FHIR token search (https://www.hl7.org/fhir/search.html#token): "When in doubt, servers SHOULD
|
|
727
|
-
# treat tokens in a case-insensitive manner, on the grounds that including undesired data has
|
|
728
|
-
# less safety implications than excluding desired behavior".
|
|
729
|
-
codings = values_found.flat_map(&:coding)
|
|
730
|
-
if search_value.include? '|'
|
|
731
|
-
system = search_value.split('|').first
|
|
732
|
-
code = search_value.split('|').last
|
|
733
|
-
codings&.any? { |coding| coding.system == system && coding.code&.casecmp?(code) }
|
|
734
|
-
else
|
|
735
|
-
codings&.any? { |coding| coding.code&.casecmp?(search_value) }
|
|
736
|
-
end
|
|
737
|
-
when 'Coding'
|
|
738
|
-
if search_value.include? '|'
|
|
739
|
-
system = search_value.split('|').first
|
|
740
|
-
code = search_value.split('|').last
|
|
741
|
-
values_found.any? { |coding| coding.system == system && coding.code&.casecmp?(code) }
|
|
742
|
-
else
|
|
743
|
-
values_found.any? { |coding| coding.code&.casecmp?(search_value) }
|
|
744
|
-
end
|
|
745
|
-
when 'Identifier'
|
|
746
|
-
if search_value.include? '|'
|
|
747
|
-
values_found.any? { |identifier| "#{identifier.system}|#{identifier.value}" == search_value }
|
|
748
|
-
else
|
|
749
|
-
values_found.any? { |identifier| identifier.value == search_value }
|
|
750
|
-
end
|
|
751
|
-
when 'string'
|
|
752
|
-
searched_values = search_value.downcase.split(/(?<!\\\\),/).map{ |string| string.gsub('\\,', ',') }
|
|
753
|
-
values_found.any? do |value_found|
|
|
754
|
-
searched_values.any? { |searched_value| value_found.downcase.starts_with? searched_value }
|
|
755
|
-
end
|
|
756
|
-
else
|
|
757
|
-
# searching by patient requires special case because we are searching by a resource identifier
|
|
758
|
-
# references can also be URLs, so we may need to resolve those URLs
|
|
759
|
-
if ['subject', 'patient'].include? name.to_s
|
|
760
|
-
id = search_value.split('Patient/').last
|
|
761
|
-
possible_values = [id, "Patient/#{id}", "#{url}/Patient/#{id}"]
|
|
762
|
-
values_found.any? do |reference|
|
|
763
|
-
possible_values.include? reference
|
|
764
|
-
end
|
|
765
|
-
else
|
|
766
|
-
search_values = search_value.split(/(?<!\\\\),/).map { |string| string.gsub('\\,', ',') }
|
|
767
|
-
values_found.any? { |value_found| search_values.include? value_found }
|
|
768
|
-
end
|
|
769
|
-
end
|
|
770
|
-
|
|
771
|
-
break if match_found
|
|
772
|
-
end
|
|
773
|
-
|
|
774
|
-
assert match_found,
|
|
775
|
-
"#{resource_type}/#{resource.id} did not match the search parameters:\n" \
|
|
776
|
-
"* Expected: #{search_value}\n" \
|
|
777
|
-
"* Found: #{values_found.map(&:inspect).join(', ')}"
|
|
778
|
-
end
|
|
779
|
-
end
|
|
780
|
-
end
|
|
781
|
-
end
|