Sha256: e276569ed7f389966220b5b86c69b6c76872917c789d68868acc53e6401783d6

Contents?: true

Size: 1.83 KB

Versions: 27

Compression:

Stored size: 1.83 KB

Contents

module USCoreTestKit
  module USCoreV400
    class DocumentReferenceCustodianTest < Inferno::Test
      id :us_core_v400_document_reference_custodian_test
      title 'DocumentReference resources returned during previous tests have custodian'
      description %(
        This test verifies the organization responsible for the DocumentReference is present either in DocumentReference.custodian
        or accessible in the Provenance resource targeting the DocumentReference using Provenance.agent.who or Provenance.agent.onBehalfOf.
      )

      def scratch_resources
        scratch[:document_reference_resources] ||= {}
      end

      def scratch_provenance_resources
        scratch[:provenance_resources] ||= {}
      end

      run do
        resources = scratch_resources[:all] || []
        provenances = scratch_provenance_resources[:all] || []

        skip_if resources.blank?,
                'No DocumentReference resources appear to be available. ' \
                'Please use patients with more information.'

        resources.each do |docref|
          has_custodian = docref.custodian.present?

          if provenances.present?
            has_agent = provenances.any? do |provenance|
              provenance.target.any? { |target| target.reference.end_with?("DocumentReference/#{docref.id}") } &&
              provenance.agent.any? { |agent| agent.who.present? || agent.onBehalfOf.present? }
            end
          end


          unless has_custodian || has_agent
            add_message('error',
                        "DocumentReference/#{docref.id} does not have DocumentReference.custodian, Provenance.agent.who, nor Provenance.agent.onBehalfOf")
          end
        end

        assert messages.blank?, "Resource does not have DocumentReference.custodian, Provenance.agent.who, nor Provenance.agent.onBehalfOf"
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
us_core_test_kit-0.9.3 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.9.2 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.9.1 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.9.0 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.8.2 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.8.1 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.8.0 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.7.2 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.7.1 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.7.0 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.6.5 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.6.4 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.6.3 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.6.2 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.6.1 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.6.0 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.5.0 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.4.7 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.4.6 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb
us_core_test_kit-0.4.5 lib/us_core_test_kit/custom_groups/v4.0.0/document_reference_custodian_test.rb