Class: USCoreTestKit::ProvenanceValidator

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

Constant Summary

Constants included from FHIRResourceNavigation

FHIRResourceNavigation::DAR_EXTENSION_URL, FHIRResourceNavigation::PRIMITIVE_DATA_TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FHIRResourceNavigation

#find_a_value_at, #find_slice_via_discriminator, #get_next_value, #get_primitive_type_value, #resolve_path, #verify_slice_by_values

Constructor Details

#initialize(resource) ⇒ ProvenanceValidator

Returns a new instance of ProvenanceValidator.



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

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

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



9
10
11
# File 'lib/us_core_test_kit/provenance_validator.rb', line 9

def resource
  @resource
end

#validation_messagesObject (readonly)

Returns the value of attribute validation_messages.



9
10
11
# File 'lib/us_core_test_kit/provenance_validator.rb', line 9

def validation_messages
  @validation_messages
end

Class Method Details

.validateObject



5
6
7
# File 'lib/us_core_test_kit/provenance_validator.rb', line 5

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

Instance Method Details

#validateObject



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

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