Module: DaVinciPDexTestKit::PDexPayerClient::ClientValidationTest

Overview

Common utilities for Clinical Data Request Tests This module will be included in Inferno::Entities::Test

Instance Method Summary collapse

Instance Method Details

#all_member_match_requestsObject



109
110
111
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 109

def all_member_match_requests
  @all_member_match_requests ||= load_tagged_requests(MEMBER_MATCH_TAG)
end

#all_patient_id_search_requestsObject



105
106
107
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 105

def all_patient_id_search_requests
  @everything_request ||= load_tagged_requests(PATIENT_ID_REQUEST_TAG)
end

#check_resource_type_fetched_instances(resource_type) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 7

def check_resource_type_fetched_instances(resource_type)
  load_clinical_data_into_scratch
  
  skip_if scratch[resource_type].nil?, "No requests made for #{resource_type.to_s} resources."
  
  not_fetched = []
  SET_TO_BE_GATHERED[resource_type].each do |target_id|
    not_fetched << target_id unless scratch[resource_type].any? { |resource| resource.id == target_id }
  end

  assert not_fetched.length == 0, 
        "Expected #{resource_type.to_s} instances not fetched: #{not_fetched.join(', ')}." 
end

#connect_bundle(export_binary) ⇒ Object



86
87
88
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 86

def connect_bundle(export_binary)
  export_binary.split(/(?<=}\n)(?={)/).map { |str| FHIR.from_contents(str)}
end

#everything_requestObject



70
71
72
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 70

def everything_request
  @everything_request ||= load_tagged_requests(EVERYTHING_TAG).first
end

#export_requestObject



78
79
80
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 78

def export_request
  @export_request ||= load_tagged_requests(EXPORT_TAG).first
end

#export_resourcesObject



90
91
92
93
94
95
96
97
98
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 90

def export_resources
  @export_resources ||=
    (
      load_tagged_requests(BINARY_TAG)
      .select { |binary_read| binary_read.status == 200 }
      .map { |binary_read| binary_read.response_body.split("\n") }
      .flatten
    ).map { |resource_in_binary| FHIR.from_contents(resource_in_binary) }
end

#export_status_requestObject



82
83
84
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 82

def export_status_request
  @export_status_request ||= load_tagged_requests(EXPORT_STATUS_TAG).first
end

#flattened_all_resourcesObject



113
114
115
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 113

def flattened_all_resources
  @flattened_all_resources ||= previous_clinical_data_request_resources.values.flatten
end

#load_clinical_data_into_scratchObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 42

def load_clinical_data_into_scratch
  return if scratch['loaded'].present?

  previous_clinical_data_request_resources.each do |request, resources|
    resources.each do |resource|
      scratch[resource.resourceType.to_sym] ||= []
      scratch[resource.resourceType.to_sym] |= [resource]
    end
  end

  if !export_resources.empty?
    info "Attempted an $export request"
    export_resources.each do |resource|
      scratch[resource.resourceType.to_sym] ||= []
      scratch[resource.resourceType.to_sym] |= [resource]
    end
  end

  scratch['loaded'] = true
end

#member_match_requestObject



74
75
76
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 74

def member_match_request
  @member_match_request ||= load_tagged_requests(MEMBER_MATCH_TAG).first
end

#previous_clinical_data_request_resourcesHash<Inferno::Entities::Request, Array<FHIR::Model>>

Returns:

  • (Hash<Inferno::Entities::Request, Array<FHIR::Model>>)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 22

def previous_clinical_data_request_resources
  return_hash = Hash.new { |hash, key| hash[key] = [] }

  previous_clinical_data_requests.each_with_object(return_hash) do |request, request_resource_hash|

    request_resources = []
    if (request.status == 200) && request.resource # XXX request.response_body ?
      case request.resource.resourceType
      when 'Bundle'
        request_resources = request.resource.entry.map(&:resource)
      # when '...' # TODO handle other special resources
      else
        request_resources = [request.resource]
      end
    end

    request_resource_hash[request].concat(request_resources)
  end
end

#previous_clinical_data_requestsArray<Inferno::Entities::Request>

Returns:

  • (Array<Inferno::Entities::Request>)


64
65
66
67
68
# File 'lib/davinci_pdex_test_kit/pdex_payer_client/client_validation_test.rb', line 64

def previous_clinical_data_requests
  [] + load_tagged_requests(RESOURCE_API_TAG) +
       load_tagged_requests(RESOURCE_ID_TAG) +
       load_tagged_requests(EVERYTHING_TAG) # TODO add export request
end