From c0b2c58cd81814cd70c4db79d0cfa61095be0550 Mon Sep 17 00:00:00 2001 From: Vanessa Fotso Date: Tue, 21 Jan 2025 10:03:56 -0500 Subject: [PATCH 1/4] update resource_is_valid method to conditionally loggin messages to runnable Signed-off-by: Vanessa Fotso --- Gemfile.lock | 1 + lib/inferno/dsl/fhir_resource_validation.rb | 8 +++++--- lib/inferno/dsl/fhir_validation.rb | 12 +++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7bc1fc777..007a66b38 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -331,6 +331,7 @@ PLATFORMS arm64-darwin-23 x86_64-darwin-20 x86_64-darwin-22 + x86_64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/lib/inferno/dsl/fhir_resource_validation.rb b/lib/inferno/dsl/fhir_resource_validation.rb index ee97e4030..d65d171af 100644 --- a/lib/inferno/dsl/fhir_resource_validation.rb +++ b/lib/inferno/dsl/fhir_resource_validation.rb @@ -157,7 +157,7 @@ def exclude_message(&block) end # @see Inferno::DSL::FHIRResourceValidation#resource_is_valid? - def resource_is_valid?(resource, profile_url, runnable) + def resource_is_valid?(resource, profile_url, runnable, log_messages: true) # rubocop:disable Metrics/CyclomaticComplexity profile_url ||= FHIR::Definitions.resource_definition(resource.resourceType).url begin @@ -173,8 +173,10 @@ def resource_is_valid?(resource, profile_url, runnable) message_hashes = message_hashes_from_outcome(outcome, resource, profile_url) - message_hashes - .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) } + if log_messages + message_hashes + .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) } + end unless response.status == 200 raise Inferno::Exceptions::ErrorInValidatorException, diff --git a/lib/inferno/dsl/fhir_validation.rb b/lib/inferno/dsl/fhir_validation.rb index 998777f02..e68ab978d 100644 --- a/lib/inferno/dsl/fhir_validation.rb +++ b/lib/inferno/dsl/fhir_validation.rb @@ -31,8 +31,8 @@ def self.included(klass) # @param profile_url [String] # @param validator [Symbol] the name of the validator to use # @return [Boolean] whether the resource is valid - def resource_is_valid?(resource: self.resource, profile_url: nil, validator: :default) - find_validator(validator).resource_is_valid?(resource, profile_url, self) + def resource_is_valid?(resource: self.resource, profile_url: nil, validator: :default, log_messages: true) + find_validator(validator).resource_is_valid?(resource, profile_url, self, log_messages:) end # Find a particular validator. Looks through a runnable's parents up to @@ -113,7 +113,7 @@ def exclude_message(&block) end # @see Inferno::DSL::FHIRValidation#resource_is_valid? - def resource_is_valid?(resource, profile_url, runnable) + def resource_is_valid?(resource, profile_url, runnable, log_messages: true) # rubocop:disable Metrics/CyclomaticComplexity profile_url ||= FHIR::Definitions.resource_definition(resource.resourceType).url begin @@ -128,8 +128,10 @@ def resource_is_valid?(resource, profile_url, runnable) message_hashes = message_hashes_from_outcome(outcome, resource, profile_url) - message_hashes - .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) } + if log_messages + message_hashes + .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) } + end unless response.status == 200 raise Inferno::Exceptions::ErrorInValidatorException, From f01941c4a4c581370faf60fd2ba1665dfb116e40 Mon Sep 17 00:00:00 2001 From: Vanessa Fotso Date: Tue, 21 Jan 2025 10:13:29 -0500 Subject: [PATCH 2/4] update spec Signed-off-by: Vanessa Fotso --- .../dsl/fhir_resource_validation_spec.rb | 19 +++++++++--- spec/inferno/dsl/fhir_validation_spec.rb | 30 +++++++++++++------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/spec/inferno/dsl/fhir_resource_validation_spec.rb b/spec/inferno/dsl/fhir_resource_validation_spec.rb index 216ca11cb..71d50a26f 100644 --- a/spec/inferno/dsl/fhir_resource_validation_spec.rb +++ b/spec/inferno/dsl/fhir_resource_validation_spec.rb @@ -153,11 +153,22 @@ .to_return(status: 200, body: invalid_outcome) end - it 'includes resourceType/id in error message' do - result = validator.resource_is_valid?(resource2, profile_url, runnable) + context 'when log_messages is set to true' do + it 'includes resourceType/id in error message' do + result = validator.resource_is_valid?(resource2, profile_url, runnable) - expect(result).to be(false) - expect(runnable.messages.first[:message]).to start_with("#{resource2.resourceType}/#{resource2.id}:") + expect(result).to be(false) + expect(runnable.messages.first[:message]).to start_with("#{resource2.resourceType}/#{resource2.id}:") + end + end + + context 'when log_messages is set to false' do + it 'does not log messages' do + result = validator.resource_is_valid?(resource2, profile_url, runnable, log_messages: false) + + expect(result).to be(false) + expect(runnable.messages).to be_empty + end end end diff --git a/spec/inferno/dsl/fhir_validation_spec.rb b/spec/inferno/dsl/fhir_validation_spec.rb index 94c5a3784..cbf25114f 100644 --- a/spec/inferno/dsl/fhir_validation_spec.rb +++ b/spec/inferno/dsl/fhir_validation_spec.rb @@ -114,19 +114,31 @@ .to_return(status: 200, body: invalid_outcome) end - it 'includes resourceType/id in error message' do - result = validator.resource_is_valid?(resource, profile_url, runnable) + context 'when log_messages is set to true' do + it 'includes resourceType/id in error message' do + result = validator.resource_is_valid?(resource, profile_url, runnable) - expect(result).to be(false) - expect(runnable.messages.first[:message]).to start_with("#{resource.resourceType}/#{resource.id}:") + expect(result).to be(false) + expect(runnable.messages.first[:message]).to start_with("#{resource.resourceType}/#{resource.id}:") + end + + it 'includes resourceType in error message if resource.id is nil' do + resource.id = nil + result = validator.resource_is_valid?(resource, profile_url, runnable) + + expect(result).to be(false) + expect(runnable.messages.first[:message]).to start_with("#{resource.resourceType}:") + end end - it 'includes resourceType in error message if resource.id is nil' do - resource.id = nil - result = validator.resource_is_valid?(resource, profile_url, runnable) + context 'when log_messages is set to false' do + it 'does not log messages' do + resource.id = nil + result = validator.resource_is_valid?(resource, profile_url, runnable, log_messages: false) - expect(result).to be(false) - expect(runnable.messages.first[:message]).to start_with("#{resource.resourceType}:") + expect(result).to be(false) + expect(runnable.messages).to be_empty + end end end From 94b30265f11c7b2facc80f3115c4be71f29d8efb Mon Sep 17 00:00:00 2001 From: Vanessa Fotso Date: Tue, 21 Jan 2025 10:52:58 -0500 Subject: [PATCH 3/4] update doc Signed-off-by: Vanessa Fotso --- lib/inferno/dsl/fhir_validation.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/inferno/dsl/fhir_validation.rb b/lib/inferno/dsl/fhir_validation.rb index e68ab978d..4faeeba63 100644 --- a/lib/inferno/dsl/fhir_validation.rb +++ b/lib/inferno/dsl/fhir_validation.rb @@ -30,6 +30,7 @@ def self.included(klass) # @param resource [FHIR::Model] # @param profile_url [String] # @param validator [Symbol] the name of the validator to use + # @param log_messages [Boolean] whether to log validation messages or not # @return [Boolean] whether the resource is valid def resource_is_valid?(resource: self.resource, profile_url: nil, validator: :default, log_messages: true) find_validator(validator).resource_is_valid?(resource, profile_url, self, log_messages:) From a10442071471c22640851f1f4db711b078bc96ce Mon Sep 17 00:00:00 2001 From: Vanessa Fotso Date: Tue, 21 Jan 2025 13:14:47 -0500 Subject: [PATCH 4/4] update param name Signed-off-by: Vanessa Fotso --- lib/inferno/dsl/fhir_resource_validation.rb | 4 ++-- lib/inferno/dsl/fhir_validation.rb | 13 ++++++++----- spec/inferno/dsl/fhir_resource_validation_spec.rb | 6 +++--- spec/inferno/dsl/fhir_validation_spec.rb | 6 +++--- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/inferno/dsl/fhir_resource_validation.rb b/lib/inferno/dsl/fhir_resource_validation.rb index d65d171af..794022889 100644 --- a/lib/inferno/dsl/fhir_resource_validation.rb +++ b/lib/inferno/dsl/fhir_resource_validation.rb @@ -157,7 +157,7 @@ def exclude_message(&block) end # @see Inferno::DSL::FHIRResourceValidation#resource_is_valid? - def resource_is_valid?(resource, profile_url, runnable, log_messages: true) # rubocop:disable Metrics/CyclomaticComplexity + def resource_is_valid?(resource, profile_url, runnable, add_messages_to_runnable: true) # rubocop:disable Metrics/CyclomaticComplexity profile_url ||= FHIR::Definitions.resource_definition(resource.resourceType).url begin @@ -173,7 +173,7 @@ def resource_is_valid?(resource, profile_url, runnable, log_messages: true) # ru message_hashes = message_hashes_from_outcome(outcome, resource, profile_url) - if log_messages + if add_messages_to_runnable message_hashes .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) } end diff --git a/lib/inferno/dsl/fhir_validation.rb b/lib/inferno/dsl/fhir_validation.rb index 4faeeba63..78fe34795 100644 --- a/lib/inferno/dsl/fhir_validation.rb +++ b/lib/inferno/dsl/fhir_validation.rb @@ -30,10 +30,13 @@ def self.included(klass) # @param resource [FHIR::Model] # @param profile_url [String] # @param validator [Symbol] the name of the validator to use - # @param log_messages [Boolean] whether to log validation messages or not + # @param add_messages_to_runnable [Boolean] whether to add validation messages to runnable or not # @return [Boolean] whether the resource is valid - def resource_is_valid?(resource: self.resource, profile_url: nil, validator: :default, log_messages: true) - find_validator(validator).resource_is_valid?(resource, profile_url, self, log_messages:) + def resource_is_valid?( + resource: self.resource, profile_url: nil, + validator: :default, add_messages_to_runnable: true + ) + find_validator(validator).resource_is_valid?(resource, profile_url, self, add_messages_to_runnable:) end # Find a particular validator. Looks through a runnable's parents up to @@ -114,7 +117,7 @@ def exclude_message(&block) end # @see Inferno::DSL::FHIRValidation#resource_is_valid? - def resource_is_valid?(resource, profile_url, runnable, log_messages: true) # rubocop:disable Metrics/CyclomaticComplexity + def resource_is_valid?(resource, profile_url, runnable, add_messages_to_runnable: true) # rubocop:disable Metrics/CyclomaticComplexity profile_url ||= FHIR::Definitions.resource_definition(resource.resourceType).url begin @@ -129,7 +132,7 @@ def resource_is_valid?(resource, profile_url, runnable, log_messages: true) # ru message_hashes = message_hashes_from_outcome(outcome, resource, profile_url) - if log_messages + if add_messages_to_runnable message_hashes .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) } end diff --git a/spec/inferno/dsl/fhir_resource_validation_spec.rb b/spec/inferno/dsl/fhir_resource_validation_spec.rb index 71d50a26f..8ac2ad28a 100644 --- a/spec/inferno/dsl/fhir_resource_validation_spec.rb +++ b/spec/inferno/dsl/fhir_resource_validation_spec.rb @@ -153,7 +153,7 @@ .to_return(status: 200, body: invalid_outcome) end - context 'when log_messages is set to true' do + context 'when add_messages_to_runnable is set to true' do it 'includes resourceType/id in error message' do result = validator.resource_is_valid?(resource2, profile_url, runnable) @@ -162,9 +162,9 @@ end end - context 'when log_messages is set to false' do + context 'when add_messages_to_runnable is set to false' do it 'does not log messages' do - result = validator.resource_is_valid?(resource2, profile_url, runnable, log_messages: false) + result = validator.resource_is_valid?(resource2, profile_url, runnable, add_messages_to_runnable: false) expect(result).to be(false) expect(runnable.messages).to be_empty diff --git a/spec/inferno/dsl/fhir_validation_spec.rb b/spec/inferno/dsl/fhir_validation_spec.rb index cbf25114f..c790fe200 100644 --- a/spec/inferno/dsl/fhir_validation_spec.rb +++ b/spec/inferno/dsl/fhir_validation_spec.rb @@ -114,7 +114,7 @@ .to_return(status: 200, body: invalid_outcome) end - context 'when log_messages is set to true' do + context 'when add_messages_to_runnable is set to true' do it 'includes resourceType/id in error message' do result = validator.resource_is_valid?(resource, profile_url, runnable) @@ -131,10 +131,10 @@ end end - context 'when log_messages is set to false' do + context 'when add_messages_to_runnable is set to false' do it 'does not log messages' do resource.id = nil - result = validator.resource_is_valid?(resource, profile_url, runnable, log_messages: false) + result = validator.resource_is_valid?(resource, profile_url, runnable, add_messages_to_runnable: false) expect(result).to be(false) expect(runnable.messages).to be_empty