Module: USCoreTestKit::ReferenceResolutionTest
- Extended by:
- Forwardable
- Includes:
- FHIRResourceNavigation
- Included in:
- USCoreV311::AllergyIntoleranceReferenceResolutionTest, USCoreV311::BodyheightReferenceResolutionTest, USCoreV311::BodytempReferenceResolutionTest, USCoreV311::BodyweightReferenceResolutionTest, USCoreV311::BpReferenceResolutionTest, USCoreV311::CarePlanReferenceResolutionTest, USCoreV311::CareTeamReferenceResolutionTest, USCoreV311::ConditionReferenceResolutionTest, USCoreV311::DeviceReferenceResolutionTest, USCoreV311::DiagnosticReportLabReferenceResolutionTest, USCoreV311::DiagnosticReportNoteReferenceResolutionTest, USCoreV311::DocumentReferenceReferenceResolutionTest, USCoreV311::EncounterReferenceResolutionTest, USCoreV311::GoalReferenceResolutionTest, USCoreV311::HeadCircumferenceReferenceResolutionTest, USCoreV311::HeartrateReferenceResolutionTest, USCoreV311::ImmunizationReferenceResolutionTest, USCoreV311::MedicationRequestReferenceResolutionTest, USCoreV311::ObservationLabReferenceResolutionTest, USCoreV311::PediatricBmiForAgeReferenceResolutionTest, USCoreV311::PediatricWeightForHeightReferenceResolutionTest, USCoreV311::ProcedureReferenceResolutionTest, USCoreV311::ProvenanceReferenceResolutionTest, USCoreV311::PulseOximetryReferenceResolutionTest, USCoreV311::ResprateReferenceResolutionTest, USCoreV311::SmokingstatusReferenceResolutionTest, USCoreV400::AllergyIntoleranceReferenceResolutionTest, USCoreV400::BloodPressureReferenceResolutionTest, USCoreV400::BmiReferenceResolutionTest, USCoreV400::BodyHeightReferenceResolutionTest, USCoreV400::BodyTemperatureReferenceResolutionTest, USCoreV400::BodyWeightReferenceResolutionTest, USCoreV400::CarePlanReferenceResolutionTest, USCoreV400::CareTeamReferenceResolutionTest, USCoreV400::ConditionReferenceResolutionTest, USCoreV400::DeviceReferenceResolutionTest, USCoreV400::DiagnosticReportLabReferenceResolutionTest, USCoreV400::DiagnosticReportNoteReferenceResolutionTest, USCoreV400::DocumentReferenceReferenceResolutionTest, USCoreV400::EncounterReferenceResolutionTest, USCoreV400::GoalReferenceResolutionTest, USCoreV400::HeadCircumferencePercentileReferenceResolutionTest, USCoreV400::HeadCircumferenceReferenceResolutionTest, USCoreV400::HeartRateReferenceResolutionTest, USCoreV400::ImmunizationReferenceResolutionTest, USCoreV400::MedicationRequestReferenceResolutionTest, USCoreV400::ObservationLabReferenceResolutionTest, USCoreV400::PediatricBmiForAgeReferenceResolutionTest, USCoreV400::PediatricWeightForHeightReferenceResolutionTest, USCoreV400::ProcedureReferenceResolutionTest, USCoreV400::ProvenanceReferenceResolutionTest, USCoreV400::PulseOximetryReferenceResolutionTest, USCoreV400::RespiratoryRateReferenceResolutionTest, USCoreV400::SmokingstatusReferenceResolutionTest, USCoreV501::AllergyIntoleranceReferenceResolutionTest, USCoreV501::BloodPressureReferenceResolutionTest, USCoreV501::BmiReferenceResolutionTest, USCoreV501::BodyHeightReferenceResolutionTest, USCoreV501::BodyTemperatureReferenceResolutionTest, USCoreV501::BodyWeightReferenceResolutionTest, USCoreV501::CarePlanReferenceResolutionTest, USCoreV501::CareTeamReferenceResolutionTest, USCoreV501::ConditionEncounterDiagnosisReferenceResolutionTest, USCoreV501::ConditionProblemsHealthConcernsReferenceResolutionTest, USCoreV501::DeviceReferenceResolutionTest, USCoreV501::DiagnosticReportLabReferenceResolutionTest, USCoreV501::DiagnosticReportNoteReferenceResolutionTest, USCoreV501::DocumentReferenceReferenceResolutionTest, USCoreV501::EncounterReferenceResolutionTest, USCoreV501::GoalReferenceResolutionTest, USCoreV501::HeadCircumferencePercentileReferenceResolutionTest, USCoreV501::HeadCircumferenceReferenceResolutionTest, USCoreV501::HeartRateReferenceResolutionTest, USCoreV501::ImmunizationReferenceResolutionTest, USCoreV501::MedicationRequestReferenceResolutionTest, USCoreV501::ObservationClinicalTestReferenceResolutionTest, USCoreV501::ObservationImagingReferenceResolutionTest, USCoreV501::ObservationLabReferenceResolutionTest, USCoreV501::ObservationSdohAssessmentReferenceResolutionTest, USCoreV501::ObservationSexualOrientationReferenceResolutionTest, USCoreV501::ObservationSocialHistoryReferenceResolutionTest, USCoreV501::PediatricBmiForAgeReferenceResolutionTest, USCoreV501::PediatricWeightForHeightReferenceResolutionTest, USCoreV501::ProcedureReferenceResolutionTest, USCoreV501::ProvenanceReferenceResolutionTest, USCoreV501::PulseOximetryReferenceResolutionTest, USCoreV501::QuestionnaireResponseReferenceResolutionTest, USCoreV501::RelatedPersonReferenceResolutionTest, USCoreV501::RespiratoryRateReferenceResolutionTest, USCoreV501::ServiceRequestReferenceResolutionTest, USCoreV501::SmokingstatusReferenceResolutionTest
- Defined in:
- lib/us_core_test_kit/reference_resolution_test.rb
Constant Summary
Constants included from FHIRResourceNavigation
FHIRResourceNavigation::DAR_EXTENSION_URL
Instance Method Summary collapse
- #must_support_references ⇒ Object
- #must_support_references_with_target_profile ⇒ Object
- #no_resources_skip_message ⇒ Object
- #perform_reference_resolution_test(resources) ⇒ Object
- #record_resolved_reference(reference) ⇒ Object
- #resolved_references ⇒ Object
- #resource_is_valid_with_target_profile?(resource, target_profile) ⇒ Boolean
- #unresolved_references(resources = []) ⇒ Object
- #unresolved_references_strings ⇒ Object
- #validate_reference_resolution(resource, reference, target_profile) ⇒ Object
Methods included from FHIRResourceNavigation
#find_a_value_at, #get_next_value, #resolve_path
Instance Method Details
#must_support_references ⇒ Object
39 40 41 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 39 def must_support_references .must_supports[:elements].select { |element_definition| element_definition[:types]&.include?('Reference') } end |
#must_support_references_with_target_profile ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 43 def must_support_references_with_target_profile # mapping array of target_profiles to array of {path, target_profile} pair must_support_references.map do |element_definition| (element_definition[:target_profiles] || ['']).map do |target_profile| { path: element_definition[:path], target_profile: target_profile } end end.flatten end |
#no_resources_skip_message ⇒ Object
34 35 36 37 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 34 def "No #{resource_type} resources appear to be available. " \ 'Please use patients with more information.' end |
#perform_reference_resolution_test(resources) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 10 def perform_reference_resolution_test(resources) skip_if resources.blank?, pass if unresolved_references(resources).length.zero? skip "Could not resolve Must Support references #{unresolved_references_strings.join(', ')}" end |
#record_resolved_reference(reference) ⇒ Object
26 27 28 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 26 def record_resolved_reference(reference) resolved_references.add?(reference.reference) end |
#resolved_references ⇒ Object
30 31 32 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 30 def resolved_references scratch[:resolved_references] ||= Set.new end |
#resource_is_valid_with_target_profile?(resource, target_profile) ⇒ Boolean
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 136 def resource_is_valid_with_target_profile?(resource, target_profile) return true if target_profile.blank? # Only need to know if the resource is valid. # Calling resource_is_valid? causes validation errors to be logged. validator = find_validator(:default) outcome = FHIR::OperationOutcome.new(JSON.parse(validator.validate(resource, target_profile))) = outcome.issue&.map { |issue| validator.(issue, resource) } || [] .concat(validator.(resource, target_profile)) validator.() .none? { || [:type] == 'error' } end |
#unresolved_references(resources = []) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 55 def unresolved_references(resources = []) @unresolved_references ||= must_support_references_with_target_profile.select do |reference_path_profile_pair| path = reference_path_profile_pair[:path] target_profile = reference_path_profile_pair[:target_profile] found_one_reference = false resolve_one_reference = resources.any? do |resource| value_found = resolve_path(resource, path) next if value_found.empty? found_one_reference = true value_found.any? do |reference| validate_reference_resolution(resource, reference, target_profile) end end found_one_reference && !resolve_one_reference end if .must_supports[:choices].present? @unresolved_references.delete_if do |reference| choice_profiles = .must_supports[:choices].find { |choice| choice[:target_profiles]&.include?(reference[:target_profile]) } choice_profiles.present? && choice_profiles[:target_profiles]&.any? { |profile| @unresolved_references.none? { |element| element[:target_profile] == profile } } end end @unresolved_references end |
#unresolved_references_strings ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 18 def unresolved_references_strings unresolved_reference_hash = unresolved_references.each_with_object(Hash.new { |hash, key| hash[key] = [] }) do |missing, hash| hash[missing[:path]] << missing[:target_profile] end unresolved_reference_hash.map { |path, profiles| "#{path}#{"(#{profiles.join('|')})" unless profiles.first.empty?}" } end |
#validate_reference_resolution(resource, reference, target_profile) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/us_core_test_kit/reference_resolution_test.rb', line 89 def validate_reference_resolution(resource, reference, target_profile) return true if resolved_references.include?(reference.reference) && target_profile.blank? if reference.contained? # if reference_id is blank it is referring to itself, so we know it exists return true if reference.reference_id.blank? return resource.contained.any? do |contained_resource| contained_resource&.id == reference.reference_id && resource_is_valid_with_target_profile?(contained_resource, target_profile) end end reference_type = reference.resource_type reference_id = reference.reference_id resolved_resource = begin if reference.relative? begin reference.resource_class rescue NameError return false end fhir_read(reference_type, reference_id)&.resource else if reference.base_uri.chomp('/') == fhir_client.instance_variable_get(:@base_service_url).chomp('/') fhir_read(reference_type, reference_id)&.resource else get(reference.reference)&.resource end end rescue StandardError => e Inferno::Application['logger'].error("Unable to resolve reference #{reference.reference}") Inferno::Application['logger'].error(e.) return false end return false unless resolved_resource&.resourceType == reference_type && resolved_resource&.id == reference_id return false unless resource_is_valid_with_target_profile?(resolved_resource, target_profile) record_resolved_reference(reference) true end |