-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3b2d3a
commit 2120d40
Showing
6 changed files
with
123 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
lib/inferno/dsl/fhir_evaluator/rules/abstract_has_examples_rule.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../evaluator_util' | ||
|
||
module FhirEvaluator | ||
module Rules | ||
class HasExamples < Rule | ||
def check(_context) | ||
'' | ||
end | ||
|
||
def unused_resource_urls | ||
@unused_resource_urls ||= [] | ||
end | ||
|
||
def used_resources | ||
@used_resources ||= [] | ||
end | ||
|
||
def get_unused_resource_urls(ig_data, &resource_filter) | ||
ig_data.each do |resource| | ||
unused_resource_urls.push resource.url unless resource_filter.call(resource) | ||
end | ||
end | ||
end | ||
end | ||
end |
44 changes: 44 additions & 0 deletions
44
lib/inferno/dsl/fhir_evaluator/rules/all_defined_extensions_have_examples.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module FhirEvaluator | ||
module Rules | ||
class AllIGExtensionsHaveExamples < HasExamples | ||
def check(context) | ||
@used_resources = context.data.map { |e| extension_urls(e) }.flatten.uniq | ||
get_unused_resource_urls(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_resources.include?(extension.url) || used_resources.include?(versioned_url) | ||
end | ||
|
||
if unused_resource_urls.any? | ||
message = "Found unused extensions defined in the IG: #{unused_resource_urls.join(', ')}" | ||
result = EvaluationResult.new(message, rule: self) | ||
else | ||
message = 'All defined extensions are represented in examples' | ||
result = EvaluationResult.new(message, severity: 'success', rule: self) | ||
end | ||
|
||
context.add_result result | ||
end | ||
|
||
def extension_urls(resource) | ||
urls = [] | ||
resource.each_element do |value, _metadata, 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 | ||
end | ||
end | ||
end |