Skip to content

Commit

Permalink
FI-3059 MustSupport Choice between Practitioner.address and Practitio…
Browse files Browse the repository at this point in the history
…nerRole (#198)

* pass current ref server

* Run MustSupport test for each Practitioner

* Look good now

* Move PractitionerAddressTest module

* rubocop

* fix unit test issue

* Call resource_is_valid_with_target_profile?

* Update missing_must_support_message

* Auto generate practitioner_address_test (#200)

* auto generate practitioner_address_test for each allowed version

* remove commented codes

---------

Co-authored-by: Yunwei Wang <>

---------

Co-authored-by: Yunwei Wang <>
  • Loading branch information
yunwwang authored Oct 3, 2024
1 parent 653a58c commit 4519c9e
Show file tree
Hide file tree
Showing 20 changed files with 454 additions and 83 deletions.
8 changes: 2 additions & 6 deletions lib/us_core_test_kit/generated/v6.1.0/metadata.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/us_core_test_kit/generated/v6.1.0/practitioner_group.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions lib/us_core_test_kit/generated/v7.0.0/metadata.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/us_core_test_kit/generated/v7.0.0/practitioner_group.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/us_core_test_kit/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require_relative 'generator/search_test_generator'
require_relative 'generator/suite_generator'
require_relative 'generator/validation_test_generator'
require_relative 'generator/practitioner_address_test_generator'

module USCoreTestKit
class Generator
Expand Down Expand Up @@ -44,6 +45,7 @@ def generate
generate_validation_tests
generate_must_support_tests
generate_reference_resolution_tests
generate_practitioner_address_tests

generate_granular_scope_tests

Expand Down Expand Up @@ -120,6 +122,10 @@ def generate_granular_scope_groups
GranularScopeGroupGenerator.generate(ig_metadata, base_output_dir)
end

def generate_practitioner_address_tests
PractitionerAddressTestGenerator.generate(ig_metadata, base_output_dir)
end

def generate_suites
SuiteGenerator.generate(ig_metadata, base_output_dir)
end
Expand Down
3 changes: 1 addition & 2 deletions lib/us_core_test_kit/generator/group_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ def generate
def add_special_tests
return if group_metadata.reformatted_version == 'v311'

case group_metadata.resource
when 'DocumentReference'
if group_metadata.resource == 'DocumentReference'
group_metadata.add_test(
id: 'us_core_v400_document_reference_custodian_test',
file_name: '../../custom_groups/v4.0.0/document_reference_custodian_test.rb'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def handle_special_cases
add_must_support_choices
add_patient_uscdi_elements
update_smoking_status_effective
remove_practitioner_address
end

def add_must_support_choices
Expand Down Expand Up @@ -89,7 +90,12 @@ def update_smoking_status_effective

must_supports[:slices].delete_if { |slice| slice[:slice_id] == 'Observation.effective[x]:effectiveDateTime' }
must_supports[:elements] << { path: 'effective[x]' }
end

def remove_practitioner_address
return unless profile.type == 'Practitioner'

must_supports[:elements].delete_if { |element| element[:path].start_with?('address') }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def us_core_6_extractor
def handle_special_cases
us_core_6_extractor.add_patient_uscdi_elements
add_must_support_choices
us_core_6_extractor.remove_practitioner_address
end

def add_must_support_choices
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module USCoreTestKit
class Generator
class PractitionerAddressTestGenerator
class << self
def generate(ig_metadata, base_output_dir)
ig_metadata.groups
.reject { |group| SpecialCases.exclude_group? group }
.each { |group| new(group, base_output_dir).generate }
end
end

attr_accessor :group_metadata, :base_output_dir

def initialize(group_metadata, base_output_dir)
self.group_metadata = group_metadata
self.base_output_dir = base_output_dir
end

def template
@template ||= File.read(File.join(__dir__, 'templates', 'practitioner_address_test.rb.erb'))
end

def output
@output ||= ERB.new(template).result(binding)
end

def base_output_file_name
"#{class_name.underscore}.rb"
end

def output_file_directory
File.join(base_output_dir, profile_identifier)
end

def output_file_name
File.join(output_file_directory, base_output_file_name)
end

def profile_identifier
Naming.snake_case_for_profile(group_metadata)
end

def test_id
"us_core_#{group_metadata.reformatted_version}_practitioner_address_test"
end

def class_name
"PractitionerAddressTest"
end

def module_name
"USCore#{group_metadata.reformatted_version.upcase}"
end

def generate
return unless group_metadata.resource == 'Practitioner' && group_metadata.version[1].to_i > 5

FileUtils.mkdir_p(output_file_directory)
File.open(output_file_name, 'w') { |f| f.write(output) }

group_metadata.add_test(
id: test_id,
file_name: base_output_file_name
)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative '../../../practitioner_address_test'

module USCoreTestKit
module <%= module_name %>
class <%= class_name %> < Inferno::Test
include USCoreTestKit::PractitionerAddressTest

title 'Server support either Practitioner.address or PractitionerRole'
description %(
US Core Responders SHALL support either US Core PractitionerRole Profile or
these data elements in US Core Practitioner Profile

* Practitioner.address
* Practitioner.address.city
* Practitioner.address.country
* Practitioner.address.line
* Practitioner.address.postalCode
* Practitioner.address.state
)

id :<%= test_id %>

def self.metadata
@metadata ||= Generator::GroupMetadata.new(YAML.load_file(File.join(__dir__, 'metadata.yml'), aliases: true))
end

run do
verify_practitioner_address
end
end
end
end
Loading

0 comments on commit 4519c9e

Please sign in to comment.