Class: IpaTestKit::ProvenanceValidator

Inherits:
Object
  • Object
show all
Includes:
FHIRResourceNavigation
Defined in:
lib/ipa_test_kit/provenance_validator.rb

Constant Summary

Constants included from FHIRResourceNavigation

FHIRResourceNavigation::DAR_EXTENSION_URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FHIRResourceNavigation

#find_a_value_at, #get_next_value, #resolve_path

Constructor Details

#initialize(resource) ⇒ ProvenanceValidator

Returns a new instance of ProvenanceValidator.



13
14
15
16
# File 'lib/ipa_test_kit/provenance_validator.rb', line 13

def initialize(resource)
  @resource = resource
  @validation_messages = []
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



11
12
13
# File 'lib/ipa_test_kit/provenance_validator.rb', line 11

def resource
  @resource
end

#validation_messagesObject (readonly)

Returns the value of attribute validation_messages.



11
12
13
# File 'lib/ipa_test_kit/provenance_validator.rb', line 11

def validation_messages
  @validation_messages
end

Class Method Details

.validateObject



7
8
9
# File 'lib/ipa_test_kit/provenance_validator.rb', line 7

def self.validate(...)
  new(...).validate
end

Instance Method Details

#validateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ipa_test_kit/provenance_validator.rb', line 18

def validate
  # Invariant provenance-1 in US Core 5 causes validation error. See FHIR-39518
  return validation_messages unless resource.instance_of?(FHIR::Provenance)

  failed_provenance =
    find_a_value_at(resource, 'agent') do |agent|
      ['Practitioner', 'Device'].any? { |resource_type| agent.who.reference&.include?(resource_type) } &&
      agent.onBehalfOf.nil?
    end

  if failed_provenance.present?
    validation_messages << {
      type: 'error',
      message: "#{resource.resourceType}/#{resource.id}: Rule provenance-1: 'onBehalfOf SHALL be present when Provenance.agent.who is a Practitioner or Device' Failed"
    }
  end

  validation_messages
end