Module: Inferno::DSL::FHIREvaluation::ProfileConformanceHelper

Included in:
Rules::AllMustSupportsPresent
Defined in:
lib/inferno/dsl/fhir_evaluation/profile_conformance_helper.rb

Overview

This module is used to decide whether a resource instantiates a given profile. Aligning resources to profiles is necessary when evaluating the comprehensiveness of the resources with respect to those profiles, unfortunately it’s impossible to programmatically determine intent. (i.e, is this resource supposed to instantiate this profile?) This module offers some approaches to make that determination.

Constant Summary collapse

DEFAULT_OPTIONS =
{
  considerMetaProfile: true,
  considerValidationResults: false,
  considerOnlyResourceType: false
}.freeze

Instance Method Summary collapse

Instance Method Details

#conforms_to_profile?(resource, profile, options = DEFAULT_OPTIONS, validator = nil) {|resource| ... } ⇒ Boolean

Check whether the given resource conforms to the given profile, using the given options to select which approaches are considered. Current options: - If the resource is the right resourceType - If the resource claims conformance in resource.meta.profile - If the resource validates against the profile using the FHIR validator (NOT YET IMPLEMENTED) - If the resource meets other criteria defined in the block. As an example, the block may look for the presence of certain codes, such as LOINC “8867-4” in an Observation category code suggests that the resource intended to conform to a “Heart Rate” profile

Parameters:

  • resource (FHIR::Resource)
  • profile (FHIR::StructureDefinition)
  • options (Hash) (defaults to: DEFAULT_OPTIONS)

    Hash of boolean-valued options. See DEFAULT_OPTIONS for defaults and keys

  • validator (Inferno::DSL::FHIRResourceValidation::Validator) (defaults to: nil)

Yield Parameters:

  • resource (FHIR::Resource)

    The original resource

Yield Returns:

  • (Boolean)

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/inferno/dsl/fhir_evaluation/profile_conformance_helper.rb', line 32

def conforms_to_profile?(resource, profile, options = DEFAULT_OPTIONS, validator = nil) # rubocop:disable Metrics/CyclomaticComplexity
  return false if resource.resourceType != profile.type

  return true if options[:considerOnlyResourceType]

  return true if options[:considerMetaProfile] && declares_meta_profile?(resource, profile)

  return true if options[:considerValidationResults] && validates_profile?(resource, profile, validator)

  return true if block_given? && yield(resource)

  false
end

#declares_meta_profile?(resource, profile) ⇒ Boolean

Check if the given resource claims conformance to the profile, versioned or unversioned, based on resource.meta.profile.

Parameters:

  • resource (FHIR::Resource)
  • profile (FHIR::StructureDefinition)

Returns:

  • (Boolean)


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

def declares_meta_profile?(resource, profile)
  declared_profiles = resource&.meta&.profile || []
  profile_url = profile.url
  versioned_url = "#{profile_url}|#{profile.version}"

  declared_profiles.include?(profile_url) || declared_profiles.include?(versioned_url)
end