Module: Inferno::DSL::MustSupportAssessment

Included in:
FHIREvaluation::Rules::AllMustSupportsPresent
Defined in:
lib/inferno/dsl/must_support_assessment.rb

Overview

The MustSupportAssessment module contains the logic for tests that check "All Must Support elements are present". Generally, test authors should use assert_must_support_elements_present or missing_must_support_elements DSL methods. A few additional methods are exposed to support the transition of existing tests that call into these methods directly.

Instance Method Summary collapse

Instance Method Details

#find_missing_elements(resources, must_support_elements) ⇒ Object



58
59
60
# File 'lib/inferno/dsl/must_support_assessment.rb', line 58

def find_missing_elements(resources, must_support_elements)
  InternalMustSupportLogic.new().find_missing_elements(resources, must_support_elements)
end

#missing_element_string(element_definition) ⇒ Object



62
63
64
# File 'lib/inferno/dsl/must_support_assessment.rb', line 62

def missing_element_string(element_definition)
  InternalMustSupportLogic.new.missing_element_string(element_definition)
end

#missing_must_support_elements(resources, profile_url, validator_name: :default, metadata: nil, requirement_extension: nil) {|MustSupportMetadataExtractor| ... } ⇒ Array<String>

Find any Must Support elements defined on the given profile that are missing in the given resources. Must Support elements are identified on the profile StructureDefinition and pre-parsed into metadata, which may be customized prior to the check by passing a block. Alternate metadata may be provided directly. Set test suite config flag debug_must_support_metadata: true to log the metadata to a file for debugging.

Parameters:

  • resources (Array<FHIR::Resource>)
  • profile_url (String)
  • validator_name (Symbol) (defaults to: :default)

    Name of the FHIR Validator that references the IG the profile is in

  • metadata (Inferno::DSL::ProfileMetadata, #must_supports) (defaults to: nil)

    MustSupport Metadata (optional), if provided the check will use this instead of re-generating metadata from the profile. Must respond to #must_supports, returning a Hash with :elements, :extensions, and :slices keys (and optionally :choices and :recursive_elements) -- the shape produced by Inferno::DSL::MustSupportMetadataExtractor#must_supports. ProfileMetadata is a base class test kits can subclass to build these objects, eg from generated YAML, instead of hand-rolling one.

  • requirement_extension (String) (defaults to: nil)

    Extension URL that implies "required" as an alternative to the MS flag

Yields:

Returns:

  • (Array<String>)

    List of missing elements



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/inferno/dsl/must_support_assessment.rb', line 27

def missing_must_support_elements(resources, profile_url, validator_name: :default, metadata: nil,
                                  requirement_extension: nil, &)
   = config.options[:debug_must_support_metadata]

  if .present?
    InternalMustSupportLogic.new.(resources, , debug_metadata:)
  else
    ig, profile = find_ig_and_profile(profile_url, validator_name)
    perform_must_support_assessment(profile, resources, ig, debug_metadata:, requirement_extension:, &)
  end
end

#perform_must_support_assessment(profile, resources, ig, debug_metadata: false, requirement_extension: nil) {|Metadata| ... } ⇒ Array<String>

perform_must_support_assessment allows customizing the metadata with a block. Customizing the metadata may add, modify, or remove items. For instance, US Core 3.1.1 Patient "Previous Name" is defined as MS only in narrative. Choices are also defined only in narrative.

Parameters:

  • profile (FHIR::StructureDefinition)
  • resources (Array<FHIR::Model>)
  • ig (Inferno::Entities::IG)
  • debug_metadata (Boolean) (defaults to: false)

    if true, write out the final metadata used to a temporary file

  • requirement_extension (String) (defaults to: nil)

    Extension URL that implies "required" as an alternative to the MS flag

Yields:

  • (Metadata)

    Customize the metadata before running the test

Returns:

  • (Array<String>)

    list of elements that were not found in the provided resources



50
51
52
53
54
55
56
# File 'lib/inferno/dsl/must_support_assessment.rb', line 50

def perform_must_support_assessment(profile, resources, ig, debug_metadata: false, requirement_extension: nil)
  test_impl = InternalMustSupportLogic.new
   = test_impl.(profile, ig, requirement_extension:)
  yield  if block_given?

  test_impl.(resources, , debug_metadata:)
end