Module: CarinForBlueButtonTestKit::ClientValidationTest

Instance Method Summary collapse

Instance Method Details

#all_resource_typesObject



3
4
5
6
7
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 3

def all_resource_types
  ['Patient', 'Coverage', 'Organization', 'Practitioner', 'RelatedPerson',
   'ExplanationOfBenefit_Inpatient_Institutional', 'ExplanationOfBenefit_Outpatient_Institutional',
   'ExplanationOfBenefit_Oral', 'ExplanationOfBenefit_Pharmacy', 'ExplanationOfBenefit_Professional_NonClinician']
end

#connect_bundle(export_binary) ⇒ Object



81
82
83
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 81

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

#extract_eob_profile(resource) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 22

def extract_eob_profile(resource)
  profile_url = resource.meta.profile.find do |profile|
    profile.include?('StructureDefinition/C4BB-ExplanationOfBenefit')
  end
  match = %r{http://hl7.org/fhir/us/carin-bb/StructureDefinition/(.*)}.match(profile_url)
  return unless match.present?

  match[1].delete_prefix('C4BB-ExplanationOfBenefit-').split('|')[0].gsub('-', '_')
end

#flattened_all_resourcesObject



89
90
91
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 89

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

#previous_claims_data_request_resources(resource_type_tag) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 9

def previous_claims_data_request_resources(resource_type_tag)
  hash = Hash.new { |hash, key| hash[key] = [] }
  previous_claims_data_requests(resource_type_tag).each_with_object(hash) do |request, request_resource_hash|
    request_resources =
      if request.status == 200
        request.resource.entry.map(&:resource)
      else
        []
      end
    request_resource_hash[request].concat(request_resources)
  end
end

#previous_claims_data_request_resources_scratch(resource_type_tag) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 32

def previous_claims_data_request_resources_scratch(resource_type_tag)
  previous_claims_data_request_resources(resource_type_tag).each do |request, resources|
    resources.each do |resource|
      next unless resource_type_tag.to_s.include?(resource.resourceType)

      if resource.resourceType == 'ExplanationOfBenefit'
        profile = extract_eob_profile(resource)
        identifier = "#{resource.resourceType}_#{profile}"
        scratch[identifier.to_sym] ||= []
        scratch[identifier.to_sym] |= [resource]
      end
      scratch[resource.resourceType.to_sym] ||= []
      scratch[resource.resourceType.to_sym] |= [resource]
    end
  end
end

#previous_claims_data_requests(resource_type_tag = nil) ⇒ Object



85
86
87
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 85

def previous_claims_data_requests(resource_type_tag = nil)
  load_tagged_requests(RESOURCE_API_TAG, resource_type_tag.to_s)
end

#previous_claims_data_search_parameters_scratch(resource_type_tag) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 54

def previous_claims_data_search_parameters_scratch(resource_type_tag)
  previous_claims_data_request_resources(resource_type_tag).each_key do |request|
    endpoint_resource = resource_type_endpoint(request.url)
    search_params = request.tags - [RESOURCE_API_TAG, resource_type_tag.to_s] - all_resource_types

    scratch[:"#{endpoint_resource}Search"] ||= []
    search_params.each do |search_param|
      unless scratch[:"#{endpoint_resource}Search"].include?(search_param)
        scratch[:"#{endpoint_resource}Search"].append(search_param)
      end
    end
  end
  scratch[:SavedSearchParams] = true
end

#previous_resource_requests(resource_type_tag) ⇒ Object



49
50
51
52
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 49

def previous_resource_requests(resource_type_tag)
  previous_claims_data_request_resources_scratch(resource_type_tag)
  scratch[resource_type_tag]
end

#resource_previous_search_params(resource_tag) ⇒ Object



69
70
71
72
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 69

def resource_previous_search_params(resource_tag)
  previous_claims_data_search_parameters_scratch(resource_tag)
  scratch[resource_tag]
end

#resource_type_endpoint(url) ⇒ Object



74
75
76
77
78
79
# File 'lib/carin_for_blue_button_test_kit/client/v2.0.0/client_validation_test.rb', line 74

def resource_type_endpoint(url)
  return unless url.start_with?('http://', 'https://')

  match = %r{custom/c4bb_v200_client/fhir/(.*)\?}.match(url)
  match[1] if match.present?
end