From 57e8be61c73dc1955d492e2f9a2f8ab67ed5d628 Mon Sep 17 00:00:00 2001 From: yunwwang Date: Tue, 11 Jan 2022 15:37:25 -0600 Subject: [PATCH] FI-1380 Update validator service to v2.1.0 (#420) * Update HL7Validator details filter * Update validator-wrapper to v2.1.0 * Remove resource.id tests since those are handled by validator now --- config.yml | 2 +- docker-compose.postgres.yml | 2 +- docker-compose.yml | 2 +- lib/app/utils/hl7_validator.rb | 33 ++++------------- test/unit/hl7_validator_test.rb | 66 +-------------------------------- 5 files changed, 12 insertions(+), 93 deletions(-) diff --git a/config.yml b/config.yml index 1238a905..b01a22c1 100644 --- a/config.yml +++ b/config.yml @@ -46,7 +46,7 @@ external_resource_validator_url: http://validator_service:4567 # The expected version of the external validator. The app will display a warning if # the found version doesn't match the expected version exactly. -external_resource_validator_version: '1.2.1' +external_resource_validator_version: '2.1.0' # The list of testing modules which will be made available. These entries must # match the "name" field in the .yml files in lib/modules. diff --git a/docker-compose.postgres.yml b/docker-compose.postgres.yml index 3dee85a9..a83d83d6 100644 --- a/docker-compose.postgres.yml +++ b/docker-compose.postgres.yml @@ -28,7 +28,7 @@ services: POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_USER: postgres validator_service: - image: infernocommunity/fhir-validator-service:v1.2.1 + image: infernocommunity/fhir-validator-service:v2.1.0 restart: unless-stopped networks: - inferno-production diff --git a/docker-compose.yml b/docker-compose.yml index 5464c7bc..9d3db445 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: depends_on: - validator_service validator_service: - image: infernocommunity/fhir-validator-service:v1.2.1 + image: infernocommunity/fhir-validator-service:v2.1.0 environment: DISABLE_TX: 'true' nginx: diff --git a/lib/app/utils/hl7_validator.rb b/lib/app/utils/hl7_validator.rb index f515a4e5..9027be96 100644 --- a/lib/app/utils/hl7_validator.rb +++ b/lib/app/utils/hl7_validator.rb @@ -6,11 +6,14 @@ module Inferno # A validator that calls out to the HL7 validator API class HL7Validator ISSUE_DETAILS_FILTER = [ + # This will be fixed with https://jira.hl7.org/browse/FHIR-28099 %r{^Sub-extension url 'introspect' is not defined by the Extension http://fhir-registry\.smarthealthit\.org/StructureDefinition/oauth-uris$}, + # This will be fixed with https://jira.hl7.org/browse/FHIR-28099 %r{^Sub-extension url 'revoke' is not defined by the Extension http://fhir-registry\.smarthealthit\.org/StructureDefinition/oauth-uris$}, - /is not a valid Target for this element \(must be one of \[\]\)$/, # This is fixed in FHIR Validator v5.3.8 - /^vs-1: if Observation\.effective\[x\] is dateTime and has a value then that value shall be precise to the day/, # Invalid invariant in FHIR v4.0.1 - /^us-core-1: Datetime must be at least to day/ # Invalid invariant in US Core v3.1.1 + # Invalid invariant in FHIR v4.0.1 + /^vs-1: 'if Observation\.effective\[x\] is dateTime and has a value then that value shall be precise to the day'/, + # Invalid invariant in US Core v3.1.1 + /^us-core-1: 'Datetime must be at least to day.'/ ].freeze @validator_url = nil attr_accessor :expected_version @@ -31,29 +34,7 @@ def validate(resource, fhir_models_klass, profile_url = nil) result = RestClient.post "#{@validator_url}/validate", resource.source_contents, params: { profile: profile_url } outcome = fhir_models_klass.from_contents(result.body) - result = issues_by_severity(outcome.issue) - - id_errors = validate_resource_id(resource) - - result[:errors].concat(id_errors) - - result - end - - # FHIR validator does not valid Resource.id /^[A-Za-z0-9\-\.]{1,64}$/ - # So Inferno has to check Resource.id against this regex. - # This should be removed after FHIR validator fix - def validate_resource_id(resource) - errors = [] - - walk_resource(resource) do |value, meta, path| - next unless meta['type'] == 'id' - next unless value.present? - - errors << "#{resource.resourceType}.#{path}: FHIR id value shall match Regex /^[A-Za-z0-9\-\.]{1,64}$/" unless value.match?(/^[A-Za-z0-9\-\.]{1,64}$/) - end - - errors + issues_by_severity(outcome.issue) end # @return [String] the version of the validator currently being used or nil diff --git a/test/unit/hl7_validator_test.rb b/test/unit/hl7_validator_test.rb index 60c77630..c0fc9867 100644 --- a/test/unit/hl7_validator_test.rb +++ b/test/unit/hl7_validator_test.rb @@ -43,27 +43,9 @@ ) result = @validator.validate(@resource, FHIR, @profile) - assert_equal 2, result[:errors].length + assert_equal 3, result[:errors].length assert_equal 1, result[:warnings].length - assert_equal 5, result[:information].length - end - - it 'adds Resource id error' do - outcome = load_fixture('hl7_validator_operation_outcome') - @resource.id = '1234567890123456789012345678901234567890123456789012345678901234567890' - - stub_request(:post, "#{@validator_url}/validate") - .with( - query: { 'profile': @profile }, - body: @resource.source_contents - ) - .to_return( - status: 200, - body: outcome - ) - - result = @validator.validate(@resource, FHIR, @profile) - assert(result[:errors].any? { |err| err.match?(/FHIR id value shall match Regex/) }) + assert_equal 4, result[:information].length end end @@ -81,48 +63,4 @@ assert_nil @validator.version end end - - describe 'Validating Resource ID' do - before do - @resource = FHIR::Patient.new - end - - it 'catches Resource id longer than 64 characters' do - @resource.id = '1234567890123456789012345678901234567890123456789012345678901234567890' - result = @validator.validate_resource_id(@resource) - - refute result.empty? - assert result.first.match?(/^Patient\.id: FHIR id value shall match Regex/) - end - - it 'catches Resource id with invalid character' do - @resource.id = '1234567890$' - result = @validator.validate_resource_id(@resource) - - refute result.empty? - assert result.first.match?(/^Patient\.id: FHIR id value shall match Regex/) - end - - it 'catches Resource id in internal resource' do - @resource.id = '1234567890123456789012345678901234567890123456789012345678901234567890' - bundle = wrap_resources_in_bundle(@resource) - bundle.id = '1234567890$' - result = @validator.validate_resource_id(bundle) - - assert result.size == 2 - end - - it 'passes Resource without id' do - result = @validator.validate_resource_id(@resource) - - assert result.empty? - end - - it 'passes Resource with valid id' do - @resource.id = 'A-123.b' - result = @validator.validate_resource_id(@resource) - - assert result.empty? - end - end end