Module: CarinForBlueButtonTestKit::ReadTest

Included in:
CARIN4BBV110::CoverageReadTest, CARIN4BBV110::EobInpatientInstitutionalReadTest, CARIN4BBV110::EobOutpatientInstitutionalReadTest, CARIN4BBV110::EobPharmacyReadTest, CARIN4BBV110::EobProfessionalNonClinicianReadTest, CARIN4BBV110::EobReadTest, CARIN4BBV110::OrganizationReadTest, CARIN4BBV110::PatientReadTest, CARIN4BBV110::PractitionerReadTest, CARIN4BBV200::CoverageReadTest, CARIN4BBV200::EobInpatientInstitutionalReadTest, CARIN4BBV200::EobOralReadTest, CARIN4BBV200::EobOutpatientInstitutionalReadTest, CARIN4BBV200::EobPharmacyReadTest, CARIN4BBV200::EobProfessionalNonClinicianReadTest, CARIN4BBV200::EobReadTest, CARIN4BBV200::OrganizationReadTest, CARIN4BBV200::PatientReadTest, CARIN4BBV200::PractitionerReadTest, CARIN4BBV200::RelatedPersonReadTest, CARIN4BBV200DEVNONFINANCIAL::CoverageReadTest, CARIN4BBV200DEVNONFINANCIAL::EobInpatientInstitutionalNonFinancialReadTest, CARIN4BBV200DEVNONFINANCIAL::EobInpatientInstitutionalReadTest, CARIN4BBV200DEVNONFINANCIAL::EobOralNonFinancialReadTest, CARIN4BBV200DEVNONFINANCIAL::EobOralReadTest, CARIN4BBV200DEVNONFINANCIAL::EobOutpatientInstitutionalNonFinancialReadTest, CARIN4BBV200DEVNONFINANCIAL::EobOutpatientInstitutionalReadTest, CARIN4BBV200DEVNONFINANCIAL::EobPharmacyNonFinancialReadTest, CARIN4BBV200DEVNONFINANCIAL::EobPharmacyReadTest, CARIN4BBV200DEVNONFINANCIAL::EobProfessionalNonClinicianNonFinancialReadTest, CARIN4BBV200DEVNONFINANCIAL::EobProfessionalNonClinicianReadTest, CARIN4BBV200DEVNONFINANCIAL::EobReadTest, CARIN4BBV200DEVNONFINANCIAL::OrganizationReadTest, CARIN4BBV200DEVNONFINANCIAL::PatientReadTest, CARIN4BBV200DEVNONFINANCIAL::PractitionerReadTest, CARIN4BBV200DEVNONFINANCIAL::RelatedPersonReadTest
Defined in:
lib/carin_for_blue_button_test_kit/read_test.rb

Instance Method Summary collapse

Instance Method Details

#all_scratch_resourcesObject



3
4
5
# File 'lib/carin_for_blue_button_test_kit/read_test.rb', line 3

def all_scratch_resources
  scratch_resources[:all] ||= []
end

#bad_resource_id_message(expected_id) ⇒ Object



54
55
56
# File 'lib/carin_for_blue_button_test_kit/read_test.rb', line 54

def bad_resource_id_message(expected_id)
  "Expected resource to have id: `#{expected_id.inspect}`, but found `#{resource.id.inspect}`"
end

#no_resources_skip_messageObject



49
50
51
52
# File 'lib/carin_for_blue_button_test_kit/read_test.rb', line 49

def no_resources_skip_message
  "No #{resource_type} resources appear to be available. " \
  'Please use patients with more information.'
end

#perform_read_test(resources, _reply_handler = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/carin_for_blue_button_test_kit/read_test.rb', line 7

def perform_read_test(resources, _reply_handler = nil)
  skip_if resources.blank? && resource_ids.blank?, no_resources_skip_message
  resources_to_read_ids = resource_ids
  if resources_to_read_ids.blank?
    resources_to_read = readable_resources(resources)

    assert resources_to_read.present?, "No #{resource_type} id found."
    resources_to_read_ids = resources_to_read.map { |resource| resource_id(resource) }
  end

  if config.options[:read_all_resources]
    resources_to_read_ids.each do |id|
      read_and_validate(id)
    end
  else
    read_and_validate(resources_to_read_ids.first)
  end
end

#read_and_validate(id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/carin_for_blue_button_test_kit/read_test.rb', line 34

def read_and_validate(id)
  fhir_read resource_type, id

  assert_response_status(200)
  assert_resource_type(resource_type)
  assert resource.id.present? && resource.id == id, bad_resource_id_message(id)

  all_scratch_resources << resource
  all_scratch_resources.uniq!
end

#readable_resources(resources) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/carin_for_blue_button_test_kit/read_test.rb', line 26

def readable_resources(resources)
  resources
    .select { |resource| resource.is_a?(resource_class) || resource.is_a?(FHIR::Reference) }
    .select { |resource| (resource.is_a?(FHIR::Reference) ? resource.reference.split('/').last : resource.id).present? }
    .compact
    .uniq { |resource| resource.is_a?(FHIR::Reference) ? resource.reference.split('/').last : resource.id }
end

#resource_classObject



58
59
60
# File 'lib/carin_for_blue_button_test_kit/read_test.rb', line 58

def resource_class
  FHIR.const_get(resource_type)
end

#resource_id(resource) ⇒ Object



45
46
47
# File 'lib/carin_for_blue_button_test_kit/read_test.rb', line 45

def resource_id(resource)
  resource.is_a?(FHIR::Reference) ? resource.reference.split('/').last : resource.id
end