Module: AUCoreTestKit::ValidationTest

Includes:
AssertHelpers
Included in:
AUCoreV100::AllergyIntoleranceValidationTest, AUCoreV100::BloodpressureValidationTest, AUCoreV100::BodyheightValidationTest, AUCoreV100::BodytempValidationTest, AUCoreV100::BodyweightValidationTest, AUCoreV100::ConditionValidationTest, AUCoreV100::DiagnosticresultPathValidationTest, AUCoreV100::DiagnosticresultValidationTest, AUCoreV100::EncounterValidationTest, AUCoreV100::HeartrateValidationTest, AUCoreV100::ImmunizationValidationTest, AUCoreV100::LocationValidationTest, AUCoreV100::MedicationRequestValidationTest, AUCoreV100::MedicationValidationTest, AUCoreV100::OrganizationValidationTest, AUCoreV100::PatientValidationTest, AUCoreV100::PractitionerRoleValidationTest, AUCoreV100::PractitionerValidationTest, AUCoreV100::ProcedureValidationTest, AUCoreV100::ResprateValidationTest, AUCoreV100::SmokingstatusValidationTest, AUCoreV100::WaistcircumValidationTest, AUCoreV110_PREVIEW::AllergyIntoleranceValidationTest, AUCoreV110_PREVIEW::BloodpressureValidationTest, AUCoreV110_PREVIEW::BodyheightValidationTest, AUCoreV110_PREVIEW::BodytempValidationTest, AUCoreV110_PREVIEW::BodyweightValidationTest, AUCoreV110_PREVIEW::ConditionValidationTest, AUCoreV110_PREVIEW::DiagnosticresultPathValidationTest, AUCoreV110_PREVIEW::DiagnosticresultValidationTest, AUCoreV110_PREVIEW::EncounterValidationTest, AUCoreV110_PREVIEW::HeartrateValidationTest, AUCoreV110_PREVIEW::ImmunizationValidationTest, AUCoreV110_PREVIEW::LocationValidationTest, AUCoreV110_PREVIEW::MedicationRequestValidationTest, AUCoreV110_PREVIEW::MedicationStatementValidationTest, AUCoreV110_PREVIEW::MedicationValidationTest, AUCoreV110_PREVIEW::OrganizationValidationTest, AUCoreV110_PREVIEW::PatientValidationTest, AUCoreV110_PREVIEW::PractitionerRoleValidationTest, AUCoreV110_PREVIEW::PractitionerValidationTest, AUCoreV110_PREVIEW::ProcedureValidationTest, AUCoreV110_PREVIEW::RelatedPersonValidationTest, AUCoreV110_PREVIEW::ResprateValidationTest, AUCoreV110_PREVIEW::SmokingstatusValidationTest, AUCoreV110_PREVIEW::WaistcircumValidationTest, AUCoreV200_DRAFT::AllergyIntoleranceValidationTest, AUCoreV200_DRAFT::BloodpressureValidationTest, AUCoreV200_DRAFT::BodyheightValidationTest, AUCoreV200_DRAFT::BodytempValidationTest, AUCoreV200_DRAFT::BodyweightValidationTest, AUCoreV200_DRAFT::ConditionValidationTest, AUCoreV200_DRAFT::DiagnosticresultPathValidationTest, AUCoreV200_DRAFT::DiagnosticresultValidationTest, AUCoreV200_DRAFT::EncounterValidationTest, AUCoreV200_DRAFT::HealthcareServiceValidationTest, AUCoreV200_DRAFT::HeartrateValidationTest, AUCoreV200_DRAFT::ImmunizationValidationTest, AUCoreV200_DRAFT::LocationValidationTest, AUCoreV200_DRAFT::MedicationRequestValidationTest, AUCoreV200_DRAFT::MedicationStatementValidationTest, AUCoreV200_DRAFT::MedicationValidationTest, AUCoreV200_DRAFT::OrganizationValidationTest, AUCoreV200_DRAFT::PatientValidationTest, AUCoreV200_DRAFT::PractitionerRoleValidationTest, AUCoreV200_DRAFT::PractitionerValidationTest, AUCoreV200_DRAFT::ProcedureValidationTest, AUCoreV200_DRAFT::RelatedPersonValidationTest, AUCoreV200_DRAFT::ResprateValidationTest, AUCoreV200_DRAFT::SmokingstatusValidationTest, AUCoreV200_DRAFT::WaistcircumValidationTest
Defined in:
lib/au_core_test_kit/validation_test.rb

Constant Summary collapse

DAR_CODE_SYSTEM_URL =
'http://terminology.hl7.org/CodeSystem/data-absent-reason'
DAR_EXTENSION_URL =
'http://hl7.org/fhir/StructureDefinition/data-absent-reason'

Instance Method Summary collapse

Methods included from AssertHelpers

#act_if_with_message, #act_with_message, #conditional_skip_with_msg, #skip_with_msg

Instance Method Details

#check_for_dar(resource) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/au_core_test_kit/validation_test.rb', line 33

def check_for_dar(resource)
  unless scratch[:dar_code_found]
    resource.each_element do |element, _meta, _path|
      next unless element.is_a?(FHIR::Coding)

      check_for_dar_code(element)
    end
  end

  return if scratch[:dar_extension_found]

  check_for_dar_extension(resource)
end

#check_for_dar_code(coding) ⇒ Object



47
48
49
50
51
52
# File 'lib/au_core_test_kit/validation_test.rb', line 47

def check_for_dar_code(coding)
  return unless coding.code == 'unknown' && coding.system == DAR_CODE_SYSTEM_URL

  scratch[:dar_code_found] = true
  output dar_code_found: 'true'
end

#check_for_dar_extension(resource) ⇒ Object



54
55
56
57
58
59
# File 'lib/au_core_test_kit/validation_test.rb', line 54

def check_for_dar_extension(resource)
  return unless resource.source_contents&.include? DAR_EXTENSION_URL

  scratch[:dar_extension_found] = true
  output dar_extension_found: 'true'
end

#perform_validation_test(resources, profile_url, profile_version, skip_if_empty: true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/au_core_test_kit/validation_test.rb', line 12

def perform_validation_test(resources,
                            profile_url,
                            profile_version,
                            skip_if_empty: true)
  conditional_skip_with_msg skip_if_empty && resources.blank?,
                            "No #{resource_type} resources conforming to the #{profile_url} profile were returned"

  omit_if resources.blank?,
          "No #{resource_type} resources provided so the #{profile_url} profile does not apply"

  profile_with_version = "#{profile_url}|#{profile_version}"
  resources.each do |resource|
    resource_is_valid?(resource:, profile_url: profile_with_version)
    check_for_dar(resource)
  end

  errors_found = messages.any? { |message| message[:type] == 'error' }

  assert !errors_found, "Resource does not conform to the profile #{profile_with_version}"
end