Module: CarinForBlueButtonTestKit::ValidationTest

Included in:
CARIN4BBV110::CoverageValidationTest, CARIN4BBV110::EobInpatientInstitutionalValidationTest, CARIN4BBV110::EobOutpatientInstitutionalValidationTest, CARIN4BBV110::EobPharmacyValidationTest, CARIN4BBV110::EobProfessionalNonClinicianValidationTest, CARIN4BBV110::EobValidationTest, CARIN4BBV110::OrganizationValidationTest, CARIN4BBV110::PatientValidationTest, CARIN4BBV110::PractitionerValidationTest, CARIN4BBV200::CoverageValidationTest, CARIN4BBV200::EobInpatientInstitutionalValidationTest, CARIN4BBV200::EobOralValidationTest, CARIN4BBV200::EobOutpatientInstitutionalValidationTest, CARIN4BBV200::EobPharmacyValidationTest, CARIN4BBV200::EobProfessionalNonClinicianValidationTest, CARIN4BBV200::EobValidationTest, CARIN4BBV200::OrganizationValidationTest, CARIN4BBV200::PatientValidationTest, CARIN4BBV200::PractitionerValidationTest, CARIN4BBV200::RelatedPersonValidationTest, CARIN4BBV200DEVNONFINANCIAL::CoverageValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobInpatientInstitutionalNonFinancialValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobInpatientInstitutionalValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobOralNonFinancialValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobOralValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobOutpatientInstitutionalNonFinancialValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobOutpatientInstitutionalValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobPharmacyNonFinancialValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobPharmacyValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobProfessionalNonClinicianNonFinancialValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobProfessionalNonClinicianValidationTest, CARIN4BBV200DEVNONFINANCIAL::EobValidationTest, CARIN4BBV200DEVNONFINANCIAL::OrganizationValidationTest, CARIN4BBV200DEVNONFINANCIAL::PatientValidationTest, CARIN4BBV200DEVNONFINANCIAL::PractitionerValidationTest, CARIN4BBV200DEVNONFINANCIAL::RelatedPersonValidationTest
Defined in:
lib/carin_for_blue_button_test_kit/validation_test.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#check_for_dar(resource) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/carin_for_blue_button_test_kit/validation_test.rb', line 28

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
  
  unless scratch[:dar_extension_found]
    check_for_dar_extension(resource)
  end
end

#check_for_dar_code(coding) ⇒ Object



42
43
44
45
46
47
# File 'lib/carin_for_blue_button_test_kit/validation_test.rb', line 42

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



49
50
51
52
53
54
# File 'lib/carin_for_blue_button_test_kit/validation_test.rb', line 49

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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/carin_for_blue_button_test_kit/validation_test.rb', line 6

def perform_validation_test(resources,
                            profile_url,
                            profile_version,
                            skip_if_empty: true)
  
  skip_if 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: 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