Module: USCoreTestKit::MustSupportTest
- Extended by:
- Forwardable
- Includes:
- FHIRResourceNavigation
- Included in:
- PractitionerAddressTest, USCoreV311::AllergyIntoleranceMustSupportTest, USCoreV311::BodyheightMustSupportTest, USCoreV311::BodytempMustSupportTest, USCoreV311::BodyweightMustSupportTest, USCoreV311::BpMustSupportTest, USCoreV311::CarePlanMustSupportTest, USCoreV311::CareTeamMustSupportTest, USCoreV311::ConditionMustSupportTest, USCoreV311::DeviceMustSupportTest, USCoreV311::DiagnosticReportLabMustSupportTest, USCoreV311::DiagnosticReportNoteMustSupportTest, USCoreV311::DocumentReferenceMustSupportTest, USCoreV311::EncounterMustSupportTest, USCoreV311::GoalMustSupportTest, USCoreV311::HeadCircumferenceMustSupportTest, USCoreV311::HeartrateMustSupportTest, USCoreV311::ImmunizationMustSupportTest, USCoreV311::MedicationRequestMustSupportTest, USCoreV311::ObservationLabMustSupportTest, USCoreV311::OrganizationMustSupportTest, USCoreV311::PatientMustSupportTest, USCoreV311::PediatricBmiForAgeMustSupportTest, USCoreV311::PediatricWeightForHeightMustSupportTest, USCoreV311::PractitionerMustSupportTest, USCoreV311::ProcedureMustSupportTest, USCoreV311::ProvenanceMustSupportTest, USCoreV311::PulseOximetryMustSupportTest, USCoreV311::ResprateMustSupportTest, USCoreV311::SmokingstatusMustSupportTest, USCoreV400::AllergyIntoleranceMustSupportTest, USCoreV400::BloodPressureMustSupportTest, USCoreV400::BmiMustSupportTest, USCoreV400::BodyHeightMustSupportTest, USCoreV400::BodyTemperatureMustSupportTest, USCoreV400::BodyWeightMustSupportTest, USCoreV400::CarePlanMustSupportTest, USCoreV400::CareTeamMustSupportTest, USCoreV400::ConditionMustSupportTest, USCoreV400::DeviceMustSupportTest, USCoreV400::DiagnosticReportLabMustSupportTest, USCoreV400::DiagnosticReportNoteMustSupportTest, USCoreV400::DocumentReferenceMustSupportTest, USCoreV400::EncounterMustSupportTest, USCoreV400::GoalMustSupportTest, USCoreV400::HeadCircumferenceMustSupportTest, USCoreV400::HeadCircumferencePercentileMustSupportTest, USCoreV400::HeartRateMustSupportTest, USCoreV400::ImmunizationMustSupportTest, USCoreV400::MedicationRequestMustSupportTest, USCoreV400::ObservationLabMustSupportTest, USCoreV400::OrganizationMustSupportTest, USCoreV400::PatientMustSupportTest, USCoreV400::PediatricBmiForAgeMustSupportTest, USCoreV400::PediatricWeightForHeightMustSupportTest, USCoreV400::PractitionerMustSupportTest, USCoreV400::ProcedureMustSupportTest, USCoreV400::ProvenanceMustSupportTest, USCoreV400::PulseOximetryMustSupportTest, USCoreV400::RespiratoryRateMustSupportTest, USCoreV400::SmokingstatusMustSupportTest, USCoreV501::AllergyIntoleranceMustSupportTest, USCoreV501::BloodPressureMustSupportTest, USCoreV501::BmiMustSupportTest, USCoreV501::BodyHeightMustSupportTest, USCoreV501::BodyTemperatureMustSupportTest, USCoreV501::BodyWeightMustSupportTest, USCoreV501::CarePlanMustSupportTest, USCoreV501::CareTeamMustSupportTest, USCoreV501::ConditionEncounterDiagnosisMustSupportTest, USCoreV501::ConditionProblemsHealthConcernsMustSupportTest, USCoreV501::DeviceMustSupportTest, USCoreV501::DiagnosticReportLabMustSupportTest, USCoreV501::DiagnosticReportNoteMustSupportTest, USCoreV501::DocumentReferenceMustSupportTest, USCoreV501::EncounterMustSupportTest, USCoreV501::GoalMustSupportTest, USCoreV501::HeadCircumferenceMustSupportTest, USCoreV501::HeadCircumferencePercentileMustSupportTest, USCoreV501::HeartRateMustSupportTest, USCoreV501::ImmunizationMustSupportTest, USCoreV501::MedicationRequestMustSupportTest, USCoreV501::ObservationClinicalTestMustSupportTest, USCoreV501::ObservationImagingMustSupportTest, USCoreV501::ObservationLabMustSupportTest, USCoreV501::ObservationSdohAssessmentMustSupportTest, USCoreV501::ObservationSexualOrientationMustSupportTest, USCoreV501::ObservationSocialHistoryMustSupportTest, USCoreV501::OrganizationMustSupportTest, USCoreV501::PatientMustSupportTest, USCoreV501::PediatricBmiForAgeMustSupportTest, USCoreV501::PediatricWeightForHeightMustSupportTest, USCoreV501::PractitionerMustSupportTest, USCoreV501::PractitionerRoleMustSupportTest, USCoreV501::ProcedureMustSupportTest, USCoreV501::ProvenanceMustSupportTest, USCoreV501::PulseOximetryMustSupportTest, USCoreV501::QuestionnaireResponseMustSupportTest, USCoreV501::RelatedPersonMustSupportTest, USCoreV501::RespiratoryRateMustSupportTest, USCoreV501::ServiceRequestMustSupportTest, USCoreV501::SmokingstatusMustSupportTest, USCoreV610::AllergyIntoleranceMustSupportTest, USCoreV610::BloodPressureMustSupportTest, USCoreV610::BmiMustSupportTest, USCoreV610::BodyHeightMustSupportTest, USCoreV610::BodyTemperatureMustSupportTest, USCoreV610::BodyWeightMustSupportTest, USCoreV610::CarePlanMustSupportTest, USCoreV610::CareTeamMustSupportTest, USCoreV610::ConditionEncounterDiagnosisMustSupportTest, USCoreV610::ConditionProblemsHealthConcernsMustSupportTest, USCoreV610::CoverageMustSupportTest, USCoreV610::DeviceMustSupportTest, USCoreV610::DiagnosticReportLabMustSupportTest, USCoreV610::DiagnosticReportNoteMustSupportTest, USCoreV610::DocumentReferenceMustSupportTest, USCoreV610::EncounterMustSupportTest, USCoreV610::GoalMustSupportTest, USCoreV610::HeadCircumferenceMustSupportTest, USCoreV610::HeadCircumferencePercentileMustSupportTest, USCoreV610::HeartRateMustSupportTest, USCoreV610::ImmunizationMustSupportTest, USCoreV610::MedicationDispenseMustSupportTest, USCoreV610::MedicationRequestMustSupportTest, USCoreV610::ObservationClinicalResultMustSupportTest, USCoreV610::ObservationLabMustSupportTest, USCoreV610::ObservationOccupationMustSupportTest, USCoreV610::ObservationPregnancyintentMustSupportTest, USCoreV610::ObservationPregnancystatusMustSupportTest, USCoreV610::ObservationScreeningAssessmentMustSupportTest, USCoreV610::ObservationSexualOrientationMustSupportTest, USCoreV610::OrganizationMustSupportTest, USCoreV610::PatientMustSupportTest, USCoreV610::PediatricBmiForAgeMustSupportTest, USCoreV610::PediatricWeightForHeightMustSupportTest, USCoreV610::PractitionerMustSupportTest, USCoreV610::PractitionerRoleMustSupportTest, USCoreV610::ProcedureMustSupportTest, USCoreV610::ProvenanceMustSupportTest, USCoreV610::PulseOximetryMustSupportTest, USCoreV610::QuestionnaireResponseMustSupportTest, USCoreV610::RelatedPersonMustSupportTest, USCoreV610::RespiratoryRateMustSupportTest, USCoreV610::ServiceRequestMustSupportTest, USCoreV610::SimpleObservationMustSupportTest, USCoreV610::SmokingstatusMustSupportTest, USCoreV610::SpecimenMustSupportTest, USCoreV700::AllergyIntoleranceMustSupportTest, USCoreV700::AverageBloodPressureMustSupportTest, USCoreV700::BloodPressureMustSupportTest, USCoreV700::BmiMustSupportTest, USCoreV700::BodyHeightMustSupportTest, USCoreV700::BodyTemperatureMustSupportTest, USCoreV700::BodyWeightMustSupportTest, USCoreV700::CareExperiencePreferenceMustSupportTest, USCoreV700::CarePlanMustSupportTest, USCoreV700::CareTeamMustSupportTest, USCoreV700::ConditionEncounterDiagnosisMustSupportTest, USCoreV700::ConditionProblemsHealthConcernsMustSupportTest, USCoreV700::CoverageMustSupportTest, USCoreV700::DeviceMustSupportTest, USCoreV700::DiagnosticReportLabMustSupportTest, USCoreV700::DiagnosticReportNoteMustSupportTest, USCoreV700::DocumentReferenceMustSupportTest, USCoreV700::EncounterMustSupportTest, USCoreV700::GoalMustSupportTest, USCoreV700::HeadCircumferenceMustSupportTest, USCoreV700::HeadCircumferencePercentileMustSupportTest, USCoreV700::HeartRateMustSupportTest, USCoreV700::ImmunizationMustSupportTest, USCoreV700::LocationMustSupportTest, USCoreV700::MedicationDispenseMustSupportTest, USCoreV700::MedicationRequestMustSupportTest, USCoreV700::ObservationClinicalResultMustSupportTest, USCoreV700::ObservationLabMustSupportTest, USCoreV700::ObservationOccupationMustSupportTest, USCoreV700::ObservationPregnancyintentMustSupportTest, USCoreV700::ObservationPregnancystatusMustSupportTest, USCoreV700::ObservationScreeningAssessmentMustSupportTest, USCoreV700::ObservationSexualOrientationMustSupportTest, USCoreV700::OrganizationMustSupportTest, USCoreV700::PatientMustSupportTest, USCoreV700::PediatricBmiForAgeMustSupportTest, USCoreV700::PediatricWeightForHeightMustSupportTest, USCoreV700::PractitionerMustSupportTest, USCoreV700::PractitionerRoleMustSupportTest, USCoreV700::ProcedureMustSupportTest, USCoreV700::ProvenanceMustSupportTest, USCoreV700::PulseOximetryMustSupportTest, USCoreV700::QuestionnaireResponseMustSupportTest, USCoreV700::RelatedPersonMustSupportTest, USCoreV700::RespiratoryRateMustSupportTest, USCoreV700::ServiceRequestMustSupportTest, USCoreV700::SimpleObservationMustSupportTest, USCoreV700::SmokingstatusMustSupportTest, USCoreV700::SpecimenMustSupportTest, USCoreV700::TreatmentInterventionPreferenceMustSupportTest
- Defined in:
- lib/us_core_test_kit/must_support_test.rb
Constant Summary
Constants included from FHIRResourceNavigation
FHIRResourceNavigation::DAR_EXTENSION_URL, FHIRResourceNavigation::PRIMITIVE_DATA_TYPES
Instance Method Summary collapse
- #all_scratch_resources ⇒ Object
- #exclude_uscdi_only_test? ⇒ Boolean
- #find_missing_elements(resources, must_support_elements) ⇒ Object
- #find_slice(resource, path, discriminator) ⇒ Object
- #find_slice_by_values(element, value_definitions) ⇒ Object
- #handle_must_support_choices ⇒ Object
- #is_any_choice_supported?(choices) ⇒ Boolean
- #missing_element_string(element_definition) ⇒ Object
- #missing_elements(resources = []) ⇒ Object
- #missing_extensions(resources = []) ⇒ Object
- #missing_must_support_strings ⇒ Object
- #missing_slices(resources = []) ⇒ Object
- #must_support_elements ⇒ Object
- #must_support_extensions ⇒ Object
- #must_support_slices ⇒ Object
- #perform_must_support_test(resources) ⇒ Object
Methods included from FHIRResourceNavigation
#find_a_value_at, #find_slice_via_discriminator, #get_next_value, #get_primitive_type_value, #resolve_path, #verify_slice_by_values
Instance Method Details
#all_scratch_resources ⇒ Object
10 11 12 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 10 def all_scratch_resources scratch_resources[:all] end |
#exclude_uscdi_only_test? ⇒ Boolean
70 71 72 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 70 def exclude_uscdi_only_test? config.[:exclude_uscdi_only_test] == true end |
#find_missing_elements(resources, must_support_elements) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 114 def find_missing_elements(resources, must_support_elements) must_support_elements.select do |element_definition| resources.none? do |resource| path = element_definition[:path] ms_extension_urls = must_support_extensions.select { |ex| ex[:path] == "#{path}.extension" } .map { |ex| ex[:url] } value_found = find_a_value_at(resource, path) do |value| if value.instance_of?(USCoreTestKit::PrimitiveType) && ms_extension_urls.present? urls = value.extension&.map(&:url) has_ms_extension = (urls & ms_extension_urls).present? end unless has_ms_extension value = value.value if value.instance_of?(USCoreTestKit::PrimitiveType) value_without_extensions = value.respond_to?(:to_hash) ? value.to_hash.reject { |key, _| key == 'extension' } : value end (has_ms_extension || 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 end |
#find_slice(resource, path, discriminator) ⇒ Object
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 160 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) do |coding| discriminator[:values].any? { |value| value[:system] == coding.system && value[:code] == coding.code } end end end end |
#find_slice_by_values(element, value_definitions) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 207 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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 30 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
47 48 49 50 51 52 53 54 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 47 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
62 63 64 65 66 67 68 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 62 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
109 110 111 112 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 109 def missing_elements(resources = []) @missing_elements ||= find_missing_elements(resources, must_support_elements) @missing_elements end |
#missing_extensions(resources = []) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 82 def missing_extensions(resources = []) @missing_extensions ||= must_support_extensions.select do |extension_definition| resources.none? do |resource| path = extension_definition[:path] if path == 'extension' resource.extension.any? { |extension| extension.url == extension_definition[:url] } else extension = find_a_value_at(resource, path) do |el| el.url == extension_definition[:url] end extension.present? end end end end |
#missing_must_support_strings ⇒ Object
56 57 58 59 60 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 56 def missing_must_support_strings 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] } end |
#missing_slices(resources = []) ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 150 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_elements ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 101 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_extensions ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 74 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_slices ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/us_core_test_kit/must_support_test.rb', line 142 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
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/us_core_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 .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 |