Module: CarinForBlueButtonTestKit::MustSupportTest
- Extended by:
- Forwardable
- Includes:
- FHIRResourceNavigation
- Included in:
- CARIN4BBV110::CoverageMustSupportTest, CARIN4BBV110::EobInpatientInstitutionalMustSupportTest, CARIN4BBV110::EobMustSupportTest, CARIN4BBV110::EobOutpatientInstitutionalMustSupportTest, CARIN4BBV110::EobPharmacyMustSupportTest, CARIN4BBV110::EobProfessionalNonClinicianMustSupportTest, CARIN4BBV110::OrganizationMustSupportTest, CARIN4BBV110::PatientMustSupportTest, CARIN4BBV110::PractitionerMustSupportTest, CARIN4BBV200::CoverageMustSupportTest, CARIN4BBV200::EobInpatientInstitutionalMustSupportTest, CARIN4BBV200::EobMustSupportTest, CARIN4BBV200::EobOralMustSupportTest, CARIN4BBV200::EobOutpatientInstitutionalMustSupportTest, CARIN4BBV200::EobPharmacyMustSupportTest, CARIN4BBV200::EobProfessionalNonClinicianMustSupportTest, CARIN4BBV200::OrganizationMustSupportTest, CARIN4BBV200::PatientMustSupportTest, CARIN4BBV200::PractitionerMustSupportTest, CARIN4BBV200::RelatedPersonMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::CoverageMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobInpatientInstitutionalMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobInpatientInstitutionalNonFinancialMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobOralMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobOralNonFinancialMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobOutpatientInstitutionalMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobOutpatientInstitutionalNonFinancialMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobPharmacyMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobPharmacyNonFinancialMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobProfessionalNonClinicianMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::EobProfessionalNonClinicianNonFinancialMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::OrganizationMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::PatientMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::PractitionerMustSupportTest, CARIN4BBV200DEVNONFINANCIAL::RelatedPersonMustSupportTest
- Defined in:
- lib/carin_for_blue_button_test_kit/must_support_test.rb
Constant Summary
FHIRResourceNavigation::DAR_EXTENSION_URL
Instance Method Summary
collapse
#find_a_value_at, #get_next_value, #resolve_path
Instance Method Details
#all_scratch_resources ⇒ Object
10
11
12
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 10
def all_scratch_resources
scratch_resources[:all]
end
|
#exclude_uscdi_only_test? ⇒ Boolean
71
72
73
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 71
def exclude_uscdi_only_test?
config.options[:exclude_uscdi_only_test] == true
end
|
#find_slice(resource, path, discriminator) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 140
def find_slice(resource, path, discriminator)
find_a_value_at(resource, path) do |element|
case discriminator[:type]
when 'patternCodeableConcept'
coding_path = discriminator[:path].present? ? "#{discriminator[:path]}.coding" : 'coding'
find_a_value_at(element, coding_path) do |coding|
coding.code == discriminator[:code] && coding.system == discriminator[:system]
end
when 'patternCoding'
coding_path = discriminator[:path].present? ? discriminator[:path] : ''
find_a_value_at(element, coding_path) do |coding|
coding.code == discriminator[:code] && coding.system == discriminator[:system]
end
when 'patternIdentifier'
find_a_value_at(element, discriminator[:path]) { |identifier| identifier.system == discriminator[:system] }
when 'value'
values = discriminator[:values].map { |value| value.merge(path: value[:path].split('.')) }
find_slice_by_values(element, values)
when 'type'
case discriminator[:code]
when 'Date'
begin
Date.parse(element)
rescue ArgumentError
false
end
when 'DateTime'
begin
DateTime.parse(element)
rescue ArgumentError
false
end
when 'String'
element.is_a? String
else
element.is_a? FHIR.const_get(discriminator[:code])
end
when 'requiredBinding'
coding_path = discriminator[:path].present? ? "#{discriminator[:path]}.coding" : 'coding'
find_a_value_at(element, coding_path) {|coding| discriminator[:values].include?(coding.code) }
end
end
end
|
#find_slice_by_values(element, value_definitions) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 184
def find_slice_by_values(element, value_definitions)
path_prefixes = value_definitions.map { |value_definition| value_definition[:path].first }.uniq
Array.wrap(element).find do |el|
path_prefixes.all? do |path_prefix|
value_definitions_for_path =
value_definitions
.select { |value_definition| value_definition[:path].first == path_prefix }
.each { |value_definition| value_definition[:path].shift }
find_a_value_at(el, path_prefix) do |el_found|
child_element_value_definitions, current_element_value_definitions =
value_definitions_for_path.partition { |value_definition| value_definition[:path].present? }
current_element_values_match =
current_element_value_definitions
.all? { |value_definition| value_definition[:value] == el_found }
child_element_values_match =
child_element_value_definitions.present? ?
find_slice_by_values(el_found, child_element_value_definitions) : true
current_element_values_match && child_element_values_match
end
end
end
end
|
#handle_must_support_choices ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 31
def handle_must_support_choices
missing_elements.delete_if do |element|
choices = metadata.must_supports[:choices].find { |choice| choice[:paths]&.include?(element[:path]) }
is_any_choice_supported?(choices)
end
missing_extensions.delete_if do |extension|
choices = metadata.must_supports[:choices].find { |choice| choice[:extension_ids]&.include?(extension[:id]) }
is_any_choice_supported?(choices)
end
missing_slices.delete_if do |slice|
choices = metadata.must_supports[:choices].find { |choice| choice[:slice_names]&.include?(slice[:name]) }
is_any_choice_supported?(choices)
end
end
|
#is_any_choice_supported?(choices) ⇒ Boolean
48
49
50
51
52
53
54
55
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 48
def is_any_choice_supported? (choices)
choices.present? &&
(
choices[:paths]&.any? { |path| missing_elements.none? { |element| element[:path] == path } } ||
choices[:extension_ids]&.any? { |extension_id| missing_extensions.none? { |extension| extension[:id] == extension_id} } ||
choices[:slice_names]&.any? { |slice_name| missing_slices.none? { |slice| slice[:name] == slice_name} }
)
end
|
#missing_element_string(element_definition) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 63
def missing_element_string(element_definition)
if element_definition[:fixed_value].present?
"#{element_definition[:path]}:#{element_definition[:fixed_value]}"
else
element_definition[:path]
end
end
|
#missing_elements(resources = []) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 100
def missing_elements(resources = [])
@missing_elements ||=
must_support_elements.select do |element_definition|
resources.none? do |resource|
path = element_definition[:path] value_found = find_a_value_at(resource, path) do |value|
value_without_extensions =
value.respond_to?(:to_hash) ? value.to_hash.reject { |key, _| key == 'extension' } : value
(value_without_extensions.present? || value_without_extensions == false) &&
(element_definition[:fixed_value].blank? || value.try(:source_hash) == element_definition[:fixed_value] || value == element_definition[:fixed_value])
end
value_found.present? || value_found == false
end
end
@missing_elements
end
|
#missing_extensions(resources = []) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 83
def missing_extensions(resources = [])
@missing_extensions ||=
must_support_extensions.select do |extension_definition|
resources.none? do |resource|
resource.extension.any? { |extension| extension.url == extension_definition[:url] }
end
end
end
|
#missing_must_support_strings ⇒ Object
57
58
59
60
61
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 57
def missing_must_support_strings
missing_elements.map { |element_definition| missing_element_string(element_definition) } +
missing_slices.map { |slice_definition| slice_definition[:name] } +
missing_extensions.map { |extension_definition| extension_definition[:id] }
end
|
#missing_slices(resources = []) ⇒ Object
130
131
132
133
134
135
136
137
138
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 130
def missing_slices(resources = [])
@missing_slices ||=
must_support_slices.select do |slice|
resources.none? do |resource|
path = slice[:path] find_slice(resource, path, slice[:discriminator]).present?
end
end
end
|
#must_support_elements ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 92
def must_support_elements
if exclude_uscdi_only_test?
metadata.must_supports[:elements].reject{ |element| element[:uscdi_only] }
else
metadata.must_supports[:elements]
end
end
|
#must_support_extensions ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 75
def must_support_extensions
if exclude_uscdi_only_test?
metadata.must_supports[:extensions].reject{ |extension| extension[:uscdi_only] }
else
metadata.must_supports[:extensions]
end
end
|
#must_support_slices ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 122
def must_support_slices
if exclude_uscdi_only_test?
metadata.must_supports[:slices].reject{ |slice| slice[:uscdi_only] }
else
metadata.must_supports[:slices]
end
end
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/carin_for_blue_button_test_kit/must_support_test.rb', line 14
def perform_must_support_test(resources)
skip_if resources.blank?, "No #{resource_type} resources were found"
missing_elements(resources)
missing_slices(resources)
missing_extensions(resources)
handle_must_support_choices if metadata.must_supports[:choices].present?
if (missing_elements + missing_slices + missing_extensions).length.zero?
pass
end
skip "Could not find #{missing_must_support_strings.join(', ')} in the #{resources.length} " \
"provided #{resource_type} resource(s)"
end
|