Module: AUCoreTestKit::MustSupportTest

Extended by:
Forwardable
Includes:
AssertHelpers, FHIRResourceNavigation
Included in:
AUCoreV100::AllergyIntoleranceMustSupportTest, AUCoreV100::BloodpressureMustSupportTest, AUCoreV100::BodyheightMustSupportTest, AUCoreV100::BodytempMustSupportTest, AUCoreV100::BodyweightMustSupportTest, AUCoreV100::ConditionMustSupportTest, AUCoreV100::DiagnosticresultMustSupportTest, AUCoreV100::DiagnosticresultPathMustSupportTest, AUCoreV100::EncounterMustSupportTest, AUCoreV100::HeartrateMustSupportTest, AUCoreV100::ImmunizationMustSupportTest, AUCoreV100::LocationMustSupportTest, AUCoreV100::MedicationRequestMustSupportTest, AUCoreV100::OrganizationMustSupportTest, AUCoreV100::PatientMustSupportTest, AUCoreV100::PractitionerMustSupportTest, AUCoreV100::PractitionerRoleMustSupportTest, AUCoreV100::ProcedureMustSupportTest, AUCoreV100::ResprateMustSupportTest, AUCoreV100::SmokingstatusMustSupportTest, AUCoreV100::WaistcircumMustSupportTest, AUCoreV110_PREVIEW::AllergyIntoleranceMustSupportTest, AUCoreV110_PREVIEW::BloodpressureMustSupportTest, AUCoreV110_PREVIEW::BodyheightMustSupportTest, AUCoreV110_PREVIEW::BodytempMustSupportTest, AUCoreV110_PREVIEW::BodyweightMustSupportTest, AUCoreV110_PREVIEW::ConditionMustSupportTest, AUCoreV110_PREVIEW::DiagnosticresultMustSupportTest, AUCoreV110_PREVIEW::DiagnosticresultPathMustSupportTest, AUCoreV110_PREVIEW::EncounterMustSupportTest, AUCoreV110_PREVIEW::HeartrateMustSupportTest, AUCoreV110_PREVIEW::ImmunizationMustSupportTest, AUCoreV110_PREVIEW::LocationMustSupportTest, AUCoreV110_PREVIEW::MedicationRequestMustSupportTest, AUCoreV110_PREVIEW::MedicationStatementMustSupportTest, AUCoreV110_PREVIEW::OrganizationMustSupportTest, AUCoreV110_PREVIEW::PatientMustSupportTest, AUCoreV110_PREVIEW::PractitionerMustSupportTest, AUCoreV110_PREVIEW::PractitionerRoleMustSupportTest, AUCoreV110_PREVIEW::ProcedureMustSupportTest, AUCoreV110_PREVIEW::RelatedPersonMustSupportTest, AUCoreV110_PREVIEW::ResprateMustSupportTest, AUCoreV110_PREVIEW::SmokingstatusMustSupportTest, AUCoreV110_PREVIEW::WaistcircumMustSupportTest, AUCoreV200_DRAFT::AllergyIntoleranceMustSupportTest, AUCoreV200_DRAFT::BloodpressureMustSupportTest, AUCoreV200_DRAFT::BodyheightMustSupportTest, AUCoreV200_DRAFT::BodytempMustSupportTest, AUCoreV200_DRAFT::BodyweightMustSupportTest, AUCoreV200_DRAFT::ConditionMustSupportTest, AUCoreV200_DRAFT::DiagnosticresultMustSupportTest, AUCoreV200_DRAFT::DiagnosticresultPathMustSupportTest, AUCoreV200_DRAFT::EncounterMustSupportTest, AUCoreV200_DRAFT::HealthcareServiceMustSupportTest, AUCoreV200_DRAFT::HeartrateMustSupportTest, AUCoreV200_DRAFT::ImmunizationMustSupportTest, AUCoreV200_DRAFT::LocationMustSupportTest, AUCoreV200_DRAFT::MedicationRequestMustSupportTest, AUCoreV200_DRAFT::MedicationStatementMustSupportTest, AUCoreV200_DRAFT::OrganizationMustSupportTest, AUCoreV200_DRAFT::PatientMustSupportTest, AUCoreV200_DRAFT::PractitionerMustSupportTest, AUCoreV200_DRAFT::PractitionerRoleMustSupportTest, AUCoreV200_DRAFT::ProcedureMustSupportTest, AUCoreV200_DRAFT::RelatedPersonMustSupportTest, AUCoreV200_DRAFT::ResprateMustSupportTest, AUCoreV200_DRAFT::SmokingstatusMustSupportTest, AUCoreV200_DRAFT::WaistcircumMustSupportTest
Defined in:
lib/au_core_test_kit/must_support_test.rb

Constant Summary

Constants included from FHIRResourceNavigation

FHIRResourceNavigation::DAR_EXTENSION_URL

Instance Method Summary collapse

Methods included from AssertHelpers

#act_if_with_message, #act_with_message, #conditional_skip_with_msg, #skip_with_msg

Methods included from FHIRResourceNavigation

#find_a_value_at, #find_slice_via_discriminator, #get_extension_url, #get_next_value, #get_value_from_extension, #is_extension?, #resolve_path, #verify_slice_by_values

Instance Method Details

#all_scratch_resourcesObject



15
16
17
# File 'lib/au_core_test_kit/must_support_test.rb', line 15

def all_scratch_resources
  scratch_resources[:all]
end

#exclude_uscdi_only_test?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/au_core_test_kit/must_support_test.rb', line 80

def exclude_uscdi_only_test?
  config.options[:exclude_uscdi_only_test] == true
end

#find_slice(resource, path, discriminator) ⇒ Object



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
183
184
185
186
187
188
189
# File 'lib/au_core_test_kit/must_support_test.rb', line 147

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



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/au_core_test_kit/must_support_test.rb', line 191

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 =
          if child_element_value_definitions.present?
            find_slice_by_values(el_found, child_element_value_definitions)
          else
            true
          end

        current_element_values_match && child_element_values_match
      end
    end
  end
end

#handle_must_support_choicesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/au_core_test_kit/must_support_test.rb', line 34

def handle_must_support_choices
  missing_elements.delete_if do |element|
    choices = .must_supports[:choices].find { |choice| choice[:paths]&.include?(element[:path]) }
    is_any_choice_supported?(choices)
  end

  missing_extensions.delete_if do |extension|
    choices = .must_supports[:choices].find { |choice| choice[:extension_ids]&.include?(extension[:id]) }
    is_any_choice_supported?(choices)
  end

  missing_slices.delete_if do |slice|
    choices = .must_supports[:choices].find { |choice| choice[:slice_names]&.include?(slice[:name]) }
    is_any_choice_supported?(choices)
  end
end

#is_any_choice_supported?(choices) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/au_core_test_kit/must_support_test.rb', line 51

def is_any_choice_supported?(choices)
  choices.present? &&
    (
      choices[:paths]&.any? { |path| missing_elements.none? { |element| element[:path] == path } } ||
      choices[:extension_ids]&.any? do |extension_id|
        missing_extensions.none? do |extension|
          extension[:id] == extension_id
        end
      end ||
      choices[:slice_names]&.any? { |slice_name| missing_slices.none? { |slice| slice[:name] == slice_name } }
    )
end

#missing_element_string(element_definition) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/au_core_test_kit/must_support_test.rb', line 72

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/au_core_test_kit/must_support_test.rb', line 110

def missing_elements(resources = [])
  @missing_elements ||=
    must_support_elements.select do |element_definition|
      resources.none? do |resource|
        path = element_definition[:path] # .delete_suffix('[x]')
        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 == element_definition[:fixed_value])
        end
        # Note that false.present? => false, which is why we need to add this extra check
        value_found.present? || value_found == false
      end
    end
  @missing_elements
end

#missing_extensions(resources = []) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/au_core_test_kit/must_support_test.rb', line 92

def missing_extensions(resources = [])
  @missing_extensions ||=
    must_support_extensions.select do |extension_definition|
      resources.none? do |resource|
        resource_extensions_url_arr = Helpers.extract_extensions_from_resource(resource).map { |ext| ext['url'] }
        resource_extensions_url_arr.include? extension_definition[:url]
      end
    end
end

#missing_must_support_stringsObject



64
65
66
67
68
69
70
# File 'lib/au_core_test_kit/must_support_test.rb', line 64

def missing_must_support_strings
  result = missing_elements.map { |element_definition| missing_element_string(element_definition) } +
    missing_slices.map { |slice_definition| slice_definition[:slice_id] } +
    missing_extensions.map { |extension_definition| extension_definition[:id] }

  result.map { |missing_element| "'#{missing_element}'" }
end

#missing_slices(resources = []) ⇒ Object



137
138
139
140
141
142
143
144
145
# File 'lib/au_core_test_kit/must_support_test.rb', line 137

def missing_slices(resources = [])
  @missing_slices ||=
    must_support_slices.select do |slice|
      resources.none? do |resource|
        path = slice[:path] # .delete_suffix('[x]')
        find_slice(resource, path, slice[:discriminator]).present?
      end
    end
end

#must_support_elementsObject



102
103
104
105
106
107
108
# File 'lib/au_core_test_kit/must_support_test.rb', line 102

def must_support_elements
  if exclude_uscdi_only_test?
    .must_supports[:elements].reject { |element| element[:uscdi_only] }
  else
    .must_supports[:elements]
  end
end

#must_support_extensionsObject



84
85
86
87
88
89
90
# File 'lib/au_core_test_kit/must_support_test.rb', line 84

def must_support_extensions
  if exclude_uscdi_only_test?
    .must_supports[:extensions].reject { |extension| extension[:uscdi_only] }
  else
    .must_supports[:extensions]
  end
end

#must_support_slicesObject



129
130
131
132
133
134
135
# File 'lib/au_core_test_kit/must_support_test.rb', line 129

def must_support_slices
  if exclude_uscdi_only_test?
    .must_supports[:slices].reject { |slice| slice[:uscdi_only] }
  else
    .must_supports[:slices]
  end
end

#perform_must_support_test(resources) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/au_core_test_kit/must_support_test.rb', line 19

def perform_must_support_test(resources)
  conditional_skip_with_msg resources.blank?, "No #{resource_type} resources were found"

  missing_elements(resources)
  missing_slices(resources)
  missing_extensions(resources)

  handle_must_support_choices if .must_supports[:choices].present?

  pass if (missing_elements + missing_slices + missing_extensions).empty?
  skip_with_msg "Could not find #{missing_must_support_strings.join(', ')} element(s) in the #{resources.length} " \
       "provided #{resource_type} resource(s). To prevent this issue, please add the missing must support "\
       "elements to at least one #{resource_type} resource on the server."
end