Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Dec 14, 2023
1 parent ee701a1 commit a0b872d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
51 changes: 45 additions & 6 deletions lib/inferno/dsl/fhir_resource_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ def url(validator_url = nil)
end

# Set the IGs that the validator will need to load
# Example: ["hl7.fhir.us.core#4.0.0"]
# @example
# igs "hl7.fhir.us.core#4.0.0"
# @example
# igs("hl7.fhir.us.core#3.1.1", "hl7.fhir.us.core#6.0.0")
# @param validator_igs [Array<String>]
def igs(validator_igs = nil)
cli_context.igs(validator_igs) if validator_igs
def igs(*validator_igs)
cli_context(igs: validator_igs) if validator_igs

cli_context.igs
end
Expand All @@ -72,11 +75,20 @@ def igs(validator_igs = nil)
# end
# end
#
# @example
# fhir_resource_validator do
# url 'http://example.org/validator'
# cli_context({
# noExtensibleBindingMessages: true,
# txServer: nil
# })
# end
#
# @param definition [Hash] raw fields to set, optional
def cli_context(definition = nil, &)
if @cli_context
if definition
@cli_context.definition.merge!(definition)
merge_into_cli_context(definition)
elsif block_given?
@cli_context.instance_eval(&)
end
Expand All @@ -86,6 +98,21 @@ def cli_context(definition = nil, &)
@cli_context
end

# @private
def merge_into_cli_context(new_def)
@cli_context.definition.merge!(new_def) do |_key, old_val, new_val|
case old_val
when Array
# take the union of the 2
old_val | new_val
when Hash
old_val.merge(new_val)
else
new_val
end
end
end

# @private
def additional_validations
@additional_validations ||= []
Expand Down Expand Up @@ -302,9 +329,21 @@ def method_missing(method_name, *args)
# Interpret any other method as setting a field on cliContext.
# Follow the same format as `Validator.url` here:
# only set the value if one is provided.
# Array or Hash values will be merged if a value is already present.
# args will be an empty array if no value is provided.
definition[method_name] = args[0] unless args.empty?

unless args.empty?
new_val = args[0]
old_val = definition[method_name]
definition[method_name] = case old_val
when Array
# take the union of the 2
old_val | new_val
when Hash
old_val.merge(new_val)
else
new_val
end
end
definition[method_name]
end

Expand Down
5 changes: 3 additions & 2 deletions spec/inferno/dsl/fhir_resource_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,12 @@
it 'uses the right cli_context when submitting the validation request' do
v3 = Inferno::DSL::FHIRResourceValidation::Validator.new do
url 'http://example.com'
igs ['hl7.fhir.us.core#1.0.1']
igs 'hl7.fhir.us.core#1.0.1'
cli_context do
txServer nil
displayWarnings true
doNative true
igs ['hl7.fhir.us.core#3.1.1']
end
end

Expand All @@ -212,7 +213,7 @@
sv: '4.0.1',
doNative: true,
extensions: ['any'],
igs: ['hl7.fhir.us.core#1.0.1'],
igs: ['hl7.fhir.us.core#1.0.1', 'hl7.fhir.us.core#3.1.1'],
txServer: nil,
displayWarnings: true,
profiles: [profile_url]
Expand Down

0 comments on commit a0b872d

Please sign in to comment.