Class: Inferno::DSL::FHIREvaluation::Rules::AllDefinedExtensionsHaveExamples
- Inherits:
- 
      Inferno::DSL::FHIREvaluation::Rule
      
        - Object
- Inferno::DSL::FHIREvaluation::Rule
- Inferno::DSL::FHIREvaluation::Rules::AllDefinedExtensionsHaveExamples
 
- Defined in:
- lib/inferno/dsl/fhir_evaluation/rules/all_defined_extensions_have_examples.rb
Instance Attribute Summary collapse
- 
  
    
      #unused_extensions  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute unused_extensions. 
- 
  
    
      #used_extensions  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute used_extensions. 
Instance Method Summary collapse
- 
  
    
      #check(context)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #extension_urls(resource)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #get_unused_extensions(extensions, &extension_filter)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Instance Attribute Details
#unused_extensions ⇒ Object
Returns the value of attribute unused_extensions.
| 8 9 10 | # File 'lib/inferno/dsl/fhir_evaluation/rules/all_defined_extensions_have_examples.rb', line 8 def unused_extensions @unused_extensions end | 
#used_extensions ⇒ Object
Returns the value of attribute used_extensions.
| 8 9 10 | # File 'lib/inferno/dsl/fhir_evaluation/rules/all_defined_extensions_have_examples.rb', line 8 def used_extensions @used_extensions end | 
Instance Method Details
#check(context) ⇒ Object
| 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # File 'lib/inferno/dsl/fhir_evaluation/rules/all_defined_extensions_have_examples.rb', line 10 def check(context) @used_extensions = context.data.map { |e| extension_urls(e) }.flatten.uniq @unused_extensions = [] get_unused_extensions(context.ig.extensions) do |extension| next true if extension.context.any? do |ctx| # Skip extensions that are defined for definitional artifacts. # For example, US Core's uscdi-requirement extension is applied to # the profiles and extensions of the IG, not data that conforms to the IG. # There may eventually be cases where SD/ED are data, so this may become configurable. ctx.expression == 'StructureDefinition' || ctx.expression == 'ElementDefinition' end versioned_url = "#{extension.url}|#{extension.version}" used_extensions.include?(extension.url) || used_extensions.include?(versioned_url) end if unused_extensions.any? = "Found defined extensions in the IG without examples: \n\t #{unused_extensions.join(', ')}" result = EvaluationResult.new(, rule: self) else = 'All defined extensions in the IG have examples.' result = EvaluationResult.new(, severity: 'success', rule: self) end context.add_result result end | 
#extension_urls(resource) ⇒ Object
| 38 39 40 41 42 43 44 45 46 47 | # File 'lib/inferno/dsl/fhir_evaluation/rules/all_defined_extensions_have_examples.rb', line 38 def extension_urls(resource) urls = [] resource.each_element do |value, , path| path_elements = path.split('.') next unless path_elements.length > 1 urls << value if path_elements[-2].include?('extension') && path_elements[-1] == 'url' end urls.uniq end | 
#get_unused_extensions(extensions, &extension_filter) ⇒ Object
| 49 50 51 52 53 | # File 'lib/inferno/dsl/fhir_evaluation/rules/all_defined_extensions_have_examples.rb', line 49 def get_unused_extensions(extensions, &extension_filter) extensions.each do |extension| unused_extensions.push extension.url unless extension_filter.call(extension) end end |