Class: Inferno::DSL::FHIREvaluation::Rules::AllMustSupportsPresent

Inherits:
Inferno::DSL::FHIREvaluation::Rule show all
Includes:
ProfileConformanceHelper, Inferno::DSL::FHIRResourceNavigation, MustSupportAssessment
Defined in:
lib/inferno/dsl/fhir_evaluation/rules/all_must_supports_present.rb

Overview

AllMustSupportsPresent checks that at least one instance of every MustSupport element defined in the given profiles is populated in the given data. MustSupport elements include plain elements, extensions, and slices. The basis of the test is metadata generated in a first pass that processes the profile into a list of fields, then the second pass check that all elements in the list are present. This metadata approach allows for customizing what is checked, for example elements may be added or removed, or choices may be defined where only one choice of multiple must be populated to demonstrate support.

Constant Summary

Constants included from ProfileConformanceHelper

ProfileConformanceHelper::DEFAULT_OPTIONS

Constants included from Inferno::DSL::FHIRResourceNavigation

Inferno::DSL::FHIRResourceNavigation::DAR_EXTENSION_URL, Inferno::DSL::FHIRResourceNavigation::PRIMITIVE_DATA_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MustSupportAssessment

#find_missing_elements, #missing_element_string, #missing_must_support_elements, #perform_must_support_assessment

Methods included from ProfileConformanceHelper

#conforms_to_profile?, #declares_meta_profile?

Methods included from Inferno::DSL::FHIRResourceNavigation

#current_and_child_values_match?, #find_a_value_at, #find_in_elements, #find_slice_via_discriminator, #flatten_bundles, #get_next_value, #get_primitive_type_value, #local_field_name, #matching_pattern_codeable_concept_slice?, #matching_pattern_coding_slice?, #matching_pattern_identifier_slice?, #matching_required_binding_slice?, #matching_slice?, #matching_type_slice?, #matching_value_slice?, #resolve_path, #verify_slice_by_values

Instance Attribute Details

#igObject

Returns the value of attribute ig.



22
23
24
# File 'lib/inferno/dsl/fhir_evaluation/rules/all_must_supports_present.rb', line 22

def ig
  @ig
end

#metadataObject

Returns the value of attribute metadata.



22
23
24
# File 'lib/inferno/dsl/fhir_evaluation/rules/all_must_supports_present.rb', line 22

def 
  @metadata
end

Instance Method Details

#check(context) ⇒ void

This method returns an undefined value.

check is invoked from the evaluator CLI and applies the logic for this Rule to the provided data. At least one instance of every MustSupport element defined in the profiles must be populated in the data. Findings from the rule will be added to context.results. The logic is configurable with a few options, but this method does not support customizing the metadata.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/inferno/dsl/fhir_evaluation/rules/all_must_supports_present.rb', line 30

def check(context)
  missing_items_by_profile = {}
  ig = context.ig
  ig.profiles.each do |profile|
    resources = pick_resources_for_profile(profile, context)
    if resources.blank?
      missing_items_by_profile[profile.url] = ['No matching resources were found to check']
      next
    end
    requirement_extension = context.config.data['Rule']['AllMustSupportsPresent']['RequirementExtensionUrl']
     = context.config.data['Rule']['AllMustSupportsPresent']['WriteMetadataForDebugging']
    missing_items = perform_must_support_assessment(profile, resources, ig, debug_metadata:,
                                                                            requirement_extension:)
    missing_items_by_profile[profile.url] = missing_items if missing_items.any?
  end

  if missing_items_by_profile.count.zero?
    result = EvaluationResult.new('All MustSupports are present', severity: 'success', rule: self)
  else
    message = 'Found Profiles with not all MustSupports represented:'
    missing_items_by_profile.each do |profile_url, missing_items|
      message += "\n\t\t#{profile_url}: #{missing_items.join(', ')}"
    end
    result = EvaluationResult.new(message, rule: self)
  end
  context.add_result result
end

#pick_resources_for_profile(profile, context) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/inferno/dsl/fhir_evaluation/rules/all_must_supports_present.rb', line 58

def pick_resources_for_profile(profile, context)
  conformance_options = context.config.data['Rule']['AllMustSupportsPresent']['ConformanceOptions'].to_options

  # Unless specifically looking for Bundles, break them out into the resources they include
  all_resources =
    if profile.type == 'Bundle'
      context.data
    else
      flatten_bundles(context.data)
    end

  all_resources.filter do |r|
    conforms_to_profile?(r, profile, conformance_options, context.validator)
  end
end