Class: DaVinciCRDTestKit::ClientFHIRApiSearchTest
- Inherits:
-
Inferno::Test
- Object
- Inferno::Test
- DaVinciCRDTestKit::ClientFHIRApiSearchTest
- Defined in:
- lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb
Instance Attribute Summary collapse
-
#successful_search ⇒ Object
Returns the value of attribute successful_search.
Instance Method Summary collapse
- #bad_resource_id_message(expected_id, actual_id) ⇒ Object
- #check_id_search_result_entry(bundle_entry, search_id, entry_resource_type) ⇒ Object
- #check_include_reference(base_resource_entry, include_resource_id, include_resource_type) ⇒ Object
- #get_reference_field(reference_type, entry) ⇒ Object
- #id_search_result_check(bundle, search_id) ⇒ Object
-
#include_search_result_check(bundle, search_id, included_resource_type) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #include_searches ⇒ Object
- #perform_fhir_search(search_params, tags) ⇒ Object
- #reference_search_paramaters ⇒ Object
- #reference_search_result_check(bundle, reference_id, reference_type) ⇒ Object
- #resource_type ⇒ Object
- #search_type ⇒ Object
- #status_search_result_check(bundle, status) ⇒ Object
Instance Attribute Details
#successful_search ⇒ Object
Returns the value of attribute successful_search.
13 14 15 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 13 def successful_search @successful_search end |
Instance Method Details
#bad_resource_id_message(expected_id, actual_id) ⇒ Object
31 32 33 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 31 def (expected_id, actual_id) "Expected resource to have id: `#{expected_id}`, but found `#{actual_id}`" end |
#check_id_search_result_entry(bundle_entry, search_id, entry_resource_type) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 59 def check_id_search_result_entry(bundle_entry, search_id, entry_resource_type) assert_resource_type(entry_resource_type, resource: bundle_entry) assert bundle_entry.id.present?, "Expected id field in returned #{entry_resource_type} resource" assert bundle_entry.id == search_id, (search_id, bundle_entry.id) end |
#check_include_reference(base_resource_entry, include_resource_id, include_resource_type) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 85 def check_include_reference(base_resource_entry, include_resource_id, include_resource_type) base_resource_references = Array.wrap(get_reference_field(include_resource_type, base_resource_entry)).compact assert(base_resource_references.present?, %( #{resource_type} resource with id #{base_resource_entry.id} did not include the field that references a #{include_resource_type} resource} )) base_resource_reference_match_found = base_resource_references.any? do |base_resource_reference| base_resource_reference.reference_id == include_resource_id end assert(base_resource_reference_match_found, %( The #{resource_type} resource in search result bundle with id #{base_resource_entry.id} did not have a #{include_resource_type} reference with an id of `#{include_resource_id}`.` )) end |
#get_reference_field(reference_type, entry) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 142 def get_reference_field(reference_type, entry) case reference_type when 'patient' entry.beneficiary when 'practitioner' entry.practitioner when 'organization' if resource_type == 'Encounter' entry.serviceProvider else entry.organization end when 'location' locations = entry.location locations.map(&:location) end end |
#id_search_result_check(bundle, search_id) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 68 def id_search_result_check(bundle, search_id) warning do assert bundle.entry.any?, "Search result bundle is empty for #{resource_type} _id search with an id of `#{search_id}`" end return if bundle.entry.empty? self.successful_search = true bundle.entry .reject { |entry| entry&.resource&.resourceType == 'OperationOutcome' } .map(&:resource) .each do |resource| check_id_search_result_entry(resource, search_id, resource_type) end end |
#include_search_result_check(bundle, search_id, included_resource_type) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 103 def include_search_result_check(bundle, search_id, included_resource_type) # rubocop:disable Metrics/CyclomaticComplexity warning do assert bundle.entry.any?, "Search result bundle is empty for #{resource_type} _include #{search_type} search with an id of `#{search_id}`" end return if bundle.entry.empty? self.successful_search = true base_resource_entry_list = bundle.entry.select do |entry| entry.resource&.resourceType == resource_type end assert(base_resource_entry_list.length == 1, %( The #{included_resource_type} _include search for #{resource_type} resource with id #{search_id} should include exactly 1 #{resource_type} resource, instead got #{base_resource_entry_list.length}. )) base_resource_entry = base_resource_entry_list.first.resource bundle.entry .map(&:resource) .each do |resource| entry_resource_type = resource.resourceType if entry_resource_type == resource_type check_id_search_result_entry(resource, search_id, entry_resource_type) elsif entry_resource_type != 'OperationOutcome' entry_resource_type = included_resource_type.capitalize assert_resource_type(entry_resource_type, resource:) included_resource_id = resource.id assert included_resource_id.present?, "Expected id field in returned #{entry_resource_type} resource" check_include_reference(base_resource_entry, included_resource_id, included_resource_type) end end end |
#include_searches ⇒ Object
23 24 25 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 23 def include_searches ['organization_include', 'practitioner_include', 'location_include'] end |
#perform_fhir_search(search_params, tags) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 35 def perform_fhir_search(search_params, ) fhir_search(resource_type, params: search_params, tags:) assert_response_status(200) assert_resource_type(:bundle) resource end |
#reference_search_paramaters ⇒ Object
27 28 29 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 27 def reference_search_paramaters ['organization', 'practitioner', 'patient'] end |
#reference_search_result_check(bundle, reference_id, reference_type) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 160 def reference_search_result_check(bundle, reference_id, reference_type) warning do assert bundle.entry.any?, %( Search result bundle is empty for #{resource_type} #{reference_type} search with a #{reference_type} id `#{reference_id}` ) end return if bundle.entry.empty? self.successful_search = true bundle.entry .reject { |entry| entry&.resource&.resourceType == 'OperationOutcome' } .map(&:resource) .each do |resource| assert_resource_type(resource_type, resource:) entry_reference_field = get_reference_field(reference_type, resource) assert( entry_reference_field.present?, %( #{resource_type} resource with id #{resource.id} did not include the field that references a #{reference_type} resource ) ) entry_reference_id = entry_reference_field.reference_id assert( entry_reference_id == reference_id, %( The #{resource_type} resource in search result bundle with id #{resource.id} should have a #{reference_type} reference with an id of `#{reference_id}`, instead got: `#{entry_reference_id}` ) ) end end |
#resource_type ⇒ Object
15 16 17 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 15 def resource_type config.[:resource_type] end |
#search_type ⇒ Object
19 20 21 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 19 def search_type config.[:search_type] end |
#status_search_result_check(bundle, status) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/davinci_crd_test_kit/client_tests/client_fhir_api_search_test.rb', line 42 def status_search_result_check(bundle, status) return if bundle.entry.empty? self.successful_search = true bundle.entry .reject { |entry| entry&.resource&.resourceType == 'OperationOutcome' } .map(&:resource) .each do |resource| assert_resource_type(resource_type, resource:) assert(resource.status == status, %( Each #{resource_type} resource in search result bundle should have a status of `#{status}`, instead got: `#{resource.status}` for resource with id: `#{resource.id}` )) end end |