Module: AUCoreTestKit::SearchTest
- Extended by:
- Forwardable
- Includes:
- AssertHelpers, DateSearchValidation, FHIRResourceNavigation, ReadTest
- Included in:
- AUCoreV100::AllergyIntoleranceClinicalStatusSearchTest, AUCoreV100::AllergyIntolerancePatientClinicalStatusSearchTest, AUCoreV100::AllergyIntolerancePatientSearchTest, AUCoreV100::BloodpressureCategorySearchTest, AUCoreV100::BloodpressureCodeMultipleOrSearchTest, AUCoreV100::BloodpressureCodeSearchTest, AUCoreV100::BloodpressureDateMultipleAndSearchTest, AUCoreV100::BloodpressureDateSearchTest, AUCoreV100::BloodpressurePatientCategoryDateSearchTest, AUCoreV100::BloodpressurePatientCategorySearchTest, AUCoreV100::BloodpressurePatientCategoryStatusSearchTest, AUCoreV100::BloodpressurePatientCodeDateSearchTest, AUCoreV100::BloodpressurePatientCodeSearchTest, AUCoreV100::BloodpressurePatientSearchTest, AUCoreV100::BloodpressureStatusMultipleOrSearchTest, AUCoreV100::BloodpressureStatusSearchTest, AUCoreV100::BodyheightCategorySearchTest, AUCoreV100::BodyheightCodeMultipleOrSearchTest, AUCoreV100::BodyheightCodeSearchTest, AUCoreV100::BodyheightDateMultipleAndSearchTest, AUCoreV100::BodyheightDateSearchTest, AUCoreV100::BodyheightPatientCategoryDateSearchTest, AUCoreV100::BodyheightPatientCategorySearchTest, AUCoreV100::BodyheightPatientCategoryStatusSearchTest, AUCoreV100::BodyheightPatientCodeDateSearchTest, AUCoreV100::BodyheightPatientCodeSearchTest, AUCoreV100::BodyheightPatientSearchTest, AUCoreV100::BodyheightStatusMultipleOrSearchTest, AUCoreV100::BodyheightStatusSearchTest, AUCoreV100::BodytempCategorySearchTest, AUCoreV100::BodytempCodeMultipleOrSearchTest, AUCoreV100::BodytempCodeSearchTest, AUCoreV100::BodytempDateMultipleAndSearchTest, AUCoreV100::BodytempDateSearchTest, AUCoreV100::BodytempPatientCategoryDateSearchTest, AUCoreV100::BodytempPatientCategorySearchTest, AUCoreV100::BodytempPatientCategoryStatusSearchTest, AUCoreV100::BodytempPatientCodeDateSearchTest, AUCoreV100::BodytempPatientCodeSearchTest, AUCoreV100::BodytempPatientSearchTest, AUCoreV100::BodytempStatusMultipleOrSearchTest, AUCoreV100::BodytempStatusSearchTest, AUCoreV100::BodyweightCategorySearchTest, AUCoreV100::BodyweightCodeMultipleOrSearchTest, AUCoreV100::BodyweightCodeSearchTest, AUCoreV100::BodyweightDateMultipleAndSearchTest, AUCoreV100::BodyweightDateSearchTest, AUCoreV100::BodyweightPatientCategoryDateSearchTest, AUCoreV100::BodyweightPatientCategorySearchTest, AUCoreV100::BodyweightPatientCategoryStatusSearchTest, AUCoreV100::BodyweightPatientCodeDateSearchTest, AUCoreV100::BodyweightPatientCodeSearchTest, AUCoreV100::BodyweightPatientSearchTest, AUCoreV100::BodyweightStatusMultipleOrSearchTest, AUCoreV100::BodyweightStatusSearchTest, AUCoreV100::ConditionCategorySearchTest, AUCoreV100::ConditionClinicalStatusSearchTest, AUCoreV100::ConditionCodeMultipleOrSearchTest, AUCoreV100::ConditionCodeSearchTest, AUCoreV100::ConditionOnsetDateSearchTest, AUCoreV100::ConditionOnset_dateMultipleAndSearchTest, AUCoreV100::ConditionPatientCategoryClinicalStatusSearchTest, AUCoreV100::ConditionPatientCategorySearchTest, AUCoreV100::ConditionPatientClinicalStatusSearchTest, AUCoreV100::ConditionPatientCodeSearchTest, AUCoreV100::ConditionPatientOnsetDateSearchTest, AUCoreV100::ConditionPatientSearchTest, AUCoreV100::DiagnosticresultCategorySearchTest, AUCoreV100::DiagnosticresultCodeMultipleOrSearchTest, AUCoreV100::DiagnosticresultCodeSearchTest, AUCoreV100::DiagnosticresultDateMultipleAndSearchTest, AUCoreV100::DiagnosticresultDateSearchTest, AUCoreV100::DiagnosticresultPathCategorySearchTest, AUCoreV100::DiagnosticresultPathCodeMultipleOrSearchTest, AUCoreV100::DiagnosticresultPathCodeSearchTest, AUCoreV100::DiagnosticresultPathDateMultipleAndSearchTest, AUCoreV100::DiagnosticresultPathDateSearchTest, AUCoreV100::DiagnosticresultPathPatientCategoryDateSearchTest, AUCoreV100::DiagnosticresultPathPatientCategorySearchTest, AUCoreV100::DiagnosticresultPathPatientCategoryStatusSearchTest, AUCoreV100::DiagnosticresultPathPatientCodeDateSearchTest, AUCoreV100::DiagnosticresultPathPatientCodeSearchTest, AUCoreV100::DiagnosticresultPathPatientSearchTest, AUCoreV100::DiagnosticresultPathStatusMultipleOrSearchTest, AUCoreV100::DiagnosticresultPathStatusSearchTest, AUCoreV100::DiagnosticresultPatientCategoryDateSearchTest, AUCoreV100::DiagnosticresultPatientCategorySearchTest, AUCoreV100::DiagnosticresultPatientCategoryStatusSearchTest, AUCoreV100::DiagnosticresultPatientCodeDateSearchTest, AUCoreV100::DiagnosticresultPatientCodeSearchTest, AUCoreV100::DiagnosticresultPatientSearchTest, AUCoreV100::DiagnosticresultStatusMultipleOrSearchTest, AUCoreV100::DiagnosticresultStatusSearchTest, AUCoreV100::EncounterClassPatientSearchTest, AUCoreV100::EncounterClassSearchTest, AUCoreV100::EncounterDateMultipleAndSearchTest, AUCoreV100::EncounterDatePatientSearchTest, AUCoreV100::EncounterDateSearchTest, AUCoreV100::EncounterLocationSearchTest, AUCoreV100::EncounterPatientLocationSearchTest, AUCoreV100::EncounterPatientSearchTest, AUCoreV100::EncounterPatientStatusSearchTest, AUCoreV100::EncounterStatusMultipleOrSearchTest, AUCoreV100::EncounterStatusSearchTest, AUCoreV100::HeartrateCategorySearchTest, AUCoreV100::HeartrateCodeMultipleOrSearchTest, AUCoreV100::HeartrateCodeSearchTest, AUCoreV100::HeartrateDateMultipleAndSearchTest, AUCoreV100::HeartrateDateSearchTest, AUCoreV100::HeartratePatientCategoryDateSearchTest, AUCoreV100::HeartratePatientCategorySearchTest, AUCoreV100::HeartratePatientCategoryStatusSearchTest, AUCoreV100::HeartratePatientCodeDateSearchTest, AUCoreV100::HeartratePatientCodeSearchTest, AUCoreV100::HeartratePatientSearchTest, AUCoreV100::HeartrateStatusMultipleOrSearchTest, AUCoreV100::HeartrateStatusSearchTest, AUCoreV100::ImmunizationDateMultipleAndSearchTest, AUCoreV100::ImmunizationDateSearchTest, AUCoreV100::ImmunizationPatientDateSearchTest, AUCoreV100::ImmunizationPatientSearchTest, AUCoreV100::ImmunizationPatientStatusSearchTest, AUCoreV100::ImmunizationPatientVaccineCodeSearchTest, AUCoreV100::ImmunizationStatusSearchTest, AUCoreV100::ImmunizationVaccineCodeSearchTest, AUCoreV100::ImmunizationVaccine_codeMultipleOrSearchTest, AUCoreV100::LocationAddressCitySearchTest, AUCoreV100::LocationAddressPostalcodeSearchTest, AUCoreV100::LocationAddressSearchTest, AUCoreV100::LocationAddressStateSearchTest, AUCoreV100::LocationNameSearchTest, AUCoreV100::MedicationRequestAuthoredonMultipleAndSearchTest, AUCoreV100::MedicationRequestAuthoredonSearchTest, AUCoreV100::MedicationRequestIdIncludeMedicationTest, AUCoreV100::MedicationRequestIdSearchTest, AUCoreV100::MedicationRequestIntentMultipleOrSearchTest, AUCoreV100::MedicationRequestIntentSearchTest, AUCoreV100::MedicationRequestPatientIncludeMedicationTest, AUCoreV100::MedicationRequestPatientIntentAuthoredonIncludeMedicationTest, AUCoreV100::MedicationRequestPatientIntentAuthoredonSearchTest, AUCoreV100::MedicationRequestPatientIntentIncludeMedicationTest, AUCoreV100::MedicationRequestPatientIntentSearchTest, AUCoreV100::MedicationRequestPatientIntentStatusIncludeMedicationTest, AUCoreV100::MedicationRequestPatientIntentStatusSearchTest, AUCoreV100::MedicationRequestPatientSearchTest, AUCoreV100::MedicationRequestPatientStatusSearchTest, AUCoreV100::MedicationRequestStatusMultipleOrSearchTest, AUCoreV100::MedicationRequestStatusSearchTest, AUCoreV100::OrganizationAddressSearchTest, AUCoreV100::OrganizationIdSearchTest, AUCoreV100::OrganizationIdentifierSearchTest, AUCoreV100::OrganizationNameSearchTest, AUCoreV100::PatientBirthdateFamilySearchTest, AUCoreV100::PatientBirthdateMultipleAndSearchTest, AUCoreV100::PatientBirthdateNameSearchTest, AUCoreV100::PatientBirthdateSearchTest, AUCoreV100::PatientFamilyGenderSearchTest, AUCoreV100::PatientFamilySearchTest, AUCoreV100::PatientGenderIdentitySearchTest, AUCoreV100::PatientGenderNameSearchTest, AUCoreV100::PatientGenderSearchTest, AUCoreV100::PatientGender_identityMultipleAndSearchTest, AUCoreV100::PatientGender_identityMultipleOrSearchTest, AUCoreV100::PatientIdSearchTest, AUCoreV100::PatientIdentifierSearchTest, AUCoreV100::PatientIndigenousStatusSearchTest, AUCoreV100::PatientIndigenous_statusMultipleAndSearchTest, AUCoreV100::PatientIndigenous_statusMultipleOrSearchTest, AUCoreV100::PatientNameSearchTest, AUCoreV100::PractitionerIdSearchTest, AUCoreV100::PractitionerIdentifierSearchTest, AUCoreV100::PractitionerNameSearchTest, AUCoreV100::PractitionerRoleIdIncludePractitionerTest, AUCoreV100::PractitionerRoleIdSearchTest, AUCoreV100::PractitionerRoleIdentifierIncludePractitionerTest, AUCoreV100::PractitionerRoleIdentifierSearchTest, AUCoreV100::PractitionerRoleOrganizationSearchTest, AUCoreV100::PractitionerRolePractitionerIncludePractitionerTest, AUCoreV100::PractitionerRolePractitionerMultipleAndSearchTest, AUCoreV100::PractitionerRolePractitionerMultipleOrSearchTest, AUCoreV100::PractitionerRolePractitionerSearchTest, AUCoreV100::PractitionerRoleRoleSearchTest, AUCoreV100::PractitionerRoleSpecialtyIncludePractitionerTest, AUCoreV100::PractitionerRoleSpecialtySearchTest, AUCoreV100::ProcedureCodeMultipleOrSearchTest, AUCoreV100::ProcedureCodeSearchTest, AUCoreV100::ProcedureDateMultipleAndSearchTest, AUCoreV100::ProcedureDateSearchTest, AUCoreV100::ProcedurePatientCodeDateSearchTest, AUCoreV100::ProcedurePatientDateSearchTest, AUCoreV100::ProcedurePatientSearchTest, AUCoreV100::ProcedurePatientStatusSearchTest, AUCoreV100::ProcedureStatusMultipleOrSearchTest, AUCoreV100::ProcedureStatusSearchTest, AUCoreV100::ResprateCategorySearchTest, AUCoreV100::ResprateCodeMultipleOrSearchTest, AUCoreV100::ResprateCodeSearchTest, AUCoreV100::ResprateDateMultipleAndSearchTest, AUCoreV100::ResprateDateSearchTest, AUCoreV100::RespratePatientCategoryDateSearchTest, AUCoreV100::RespratePatientCategorySearchTest, AUCoreV100::RespratePatientCategoryStatusSearchTest, AUCoreV100::RespratePatientCodeDateSearchTest, AUCoreV100::RespratePatientCodeSearchTest, AUCoreV100::RespratePatientSearchTest, AUCoreV100::ResprateStatusMultipleOrSearchTest, AUCoreV100::ResprateStatusSearchTest, AUCoreV100::SmokingstatusCategorySearchTest, AUCoreV100::SmokingstatusCodeMultipleOrSearchTest, AUCoreV100::SmokingstatusCodeSearchTest, AUCoreV100::SmokingstatusDateMultipleAndSearchTest, AUCoreV100::SmokingstatusDateSearchTest, AUCoreV100::SmokingstatusPatientCategoryDateSearchTest, AUCoreV100::SmokingstatusPatientCategorySearchTest, AUCoreV100::SmokingstatusPatientCategoryStatusSearchTest, AUCoreV100::SmokingstatusPatientCodeDateSearchTest, AUCoreV100::SmokingstatusPatientCodeSearchTest, AUCoreV100::SmokingstatusPatientSearchTest, AUCoreV100::SmokingstatusStatusMultipleOrSearchTest, AUCoreV100::SmokingstatusStatusSearchTest, AUCoreV100::WaistcircumCategorySearchTest, AUCoreV100::WaistcircumCodeMultipleOrSearchTest, AUCoreV100::WaistcircumCodeSearchTest, AUCoreV100::WaistcircumDateMultipleAndSearchTest, AUCoreV100::WaistcircumDateSearchTest, AUCoreV100::WaistcircumPatientCategoryDateSearchTest, AUCoreV100::WaistcircumPatientCategorySearchTest, AUCoreV100::WaistcircumPatientCategoryStatusSearchTest, AUCoreV100::WaistcircumPatientCodeDateSearchTest, AUCoreV100::WaistcircumPatientCodeSearchTest, AUCoreV100::WaistcircumPatientSearchTest, AUCoreV100::WaistcircumStatusMultipleOrSearchTest, AUCoreV100::WaistcircumStatusSearchTest, ChainedSearchTest, ClinicalNoteTypeTest, SpecialIdentifierSearchTest
- Defined in:
- lib/au_core_test_kit/search_test.rb
Constant Summary
FHIRResourceNavigation::DAR_EXTENSION_URL
Instance Method Summary
collapse
-
#all_comparator_searches_tested? ⇒ Boolean
-
#all_provenance_revinclude_search_params ⇒ Object
-
#all_scratch_resources ⇒ Object
-
#all_search_params ⇒ Object
-
#all_search_params_present?(params) ⇒ Boolean
-
#all_search_variants_tested? ⇒ Boolean
-
#any_valid_search_params?(search_params) ⇒ Boolean
-
#array_of_codes(array) ⇒ Object
-
#birthdate_comparator_value(comparator, date) ⇒ Object
-
#cant_resolve_next_bundle_message(link) ⇒ Object
-
#chain_search_restriction(search_parameter) ⇒ Object
-
#check_availability_of_count_search_parameter(resource_type, params) ⇒ Object
-
#check_resource_against_params(resource, params) ⇒ Object
-
#check_search_response ⇒ Object
-
#date_comparator_value(comparator, date) ⇒ Object
-
#default_search_values(param_name) ⇒ Object
-
#default_search_values_clean(param_name) ⇒ Object
-
#default_values_for_param(param_name) ⇒ Object
-
#element_has_valid_value?(element, include_system) ⇒ Boolean
-
#empty_search_params_message(empty_search_params) ⇒ Object
-
#extension_check(resource, extension_url) ⇒ Object
-
#extract_existing_values_safety(resources_arr, param_name) ⇒ Object
-
#fetch_all_bundled_resources(reply_handler: nil, max_pages: 20, additional_resource_types: [], resource_type: self.resource_type) ⇒ Object
-
#filter_conditions(resources) ⇒ Object
-
#filter_devices(resources) ⇒ Object
-
#find_include_resources(params, patient_id, include_param, _keep_search_variant = true) ⇒ Object
-
#fixed_value_search_param_name ⇒ Object
-
#fixed_value_search_param_values ⇒ Object
-
#fixed_value_search_params(value, patient_id) ⇒ Object
-
#initial_search_variant_test_records ⇒ Object
-
#insufficient_number_of_values(values_to_search) ⇒ Object
-
#is_count_available_for_resource_type?(resource_type, params) ⇒ Boolean
-
#is_reference_match?(reference, local_reference) ⇒ Boolean
-
#modify_value_by_multiple_type(values, multiple_type) ⇒ Object
-
#no_resources_skip_message(resource_type = self.resource_type) ⇒ Object
-
#optional_search_and_check_response(params, resource_type = self.resource_type) ⇒ Object
-
#patient_id_list ⇒ Object
-
#patient_id_param?(name) ⇒ Boolean
-
#patient_search? ⇒ Boolean
-
#perform_comparator_searches(params, patient_id) ⇒ Object
-
#perform_multiple_and_search_test ⇒ Object
-
#perform_multiple_or_search_test ⇒ Object
-
#perform_multiple_search_test(multiple_type) ⇒ Object
-
#perform_post_search(get_search_resources, params) ⇒ Object
-
#perform_reference_with_type_search(params, resource_count) ⇒ Object
-
#perform_search(params, patient_id) ⇒ Object
-
#perform_search_with_status(original_params, _patient_id, status_search_values: self.status_search_values, resource_type: self.resource_type) ⇒ Object
-
#perform_search_with_system(params, patient_id) ⇒ Object
-
#references_to_save(resource_type = nil) ⇒ Object
-
#required_comparators(name) ⇒ Object
-
#run_include_test ⇒ Object
-
#run_provenance_revinclude_search_test ⇒ Object
-
#run_read_test_and_skip_first_search(patient_id) ⇒ Object
-
#run_search_test ⇒ Object
-
#run_search_test_with_system ⇒ Object
-
#save_delayed_references(resources, containing_resource_type = resource_type) ⇒ Object
-
#save_resource_reference(resource_type, reference) ⇒ Object
-
#scratch_resources_for_patient(patient_id) ⇒ Object
-
#search_and_check_response(params, resource_type = self.resource_type) ⇒ Object
-
#search_by_patient_id_is_available(patient_id) ⇒ Object
-
#search_param_paths(name) ⇒ Object
-
#search_param_value(name, resource, include_system: false) ⇒ Object
-
#search_params_with_values(search_param_names, patient_id, include_system: false) ⇒ Object
-
#search_variant_test_records ⇒ Object
-
#status_search_param_name ⇒ Object
-
#status_search_values ⇒ Object
-
#test_include_param(base_resources, params, patient_id, include_param, keep_search_variant = true) ⇒ Object
-
#unable_to_resolve_params_message ⇒ Object
#act_if_with_message, #act_with_message, #conditional_skip_with_msg, #skip_with_msg
Methods included from ReadTest
#bad_resource_id_message, #basic_read_and_validate, #create_reference, #fetch_resource_ids, #get_resources_to_read_from_arr_ids, #no_resources_custom_skip_message, #perform_read_test, #read_and_validate, #read_and_validate_as_first, #read_and_validate_resourses_arr, #readable_resources, #resource_class, #resource_id, #resource_ids_str_to_arr
#find_a_value_at, #find_slice_via_discriminator, #get_extension_url, #get_next_value, #get_value_from_extension, #is_extension?, #resolve_path, #verify_slice_by_values
#fhir_date_comparer, #get_fhir_datetime_range, #get_fhir_period_range, #is_date?, #validate_date_search, #validate_datetime_search, #validate_period_search
Instance Method Details
#all_comparator_searches_tested? ⇒ Boolean
288
289
290
291
292
|
# File 'lib/au_core_test_kit/search_test.rb', line 288
def all_comparator_searches_tested?
return true if params_with_comparators.blank?
Set.new(params_with_comparators) == search_variant_test_records[:comparator_searches]
end
|
#all_provenance_revinclude_search_params ⇒ Object
59
60
61
62
63
64
|
# File 'lib/au_core_test_kit/search_test.rb', line 59
def all_provenance_revinclude_search_params
@all_provenance_revinclude_search_params ||=
all_search_params.transform_values! do |params_list|
params_list.map { |params| params.merge(_revinclude: 'Provenance:target') }
end
end
|
#all_scratch_resources ⇒ Object
597
598
599
|
# File 'lib/au_core_test_kit/search_test.rb', line 597
def all_scratch_resources
scratch_resources[:all] ||= []
end
|
#all_search_params ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/au_core_test_kit/search_test.rb', line 41
def all_search_params
@all_search_params ||=
patient_id_list.each_with_object({}) do |patient_id, params|
params[patient_id] ||= []
new_params =
if fixed_value_search?
fixed_value_search_param_values.map { |value| fixed_value_search_params(value, patient_id) }
else
[search_params_with_values(search_param_names, patient_id)]
end
new_params.reject! do |params|
params.any? { |_key, value| value.blank? }
end
params[patient_id].concat(new_params)
end
end
|
#all_search_params_present?(params) ⇒ Boolean
681
682
683
|
# File 'lib/au_core_test_kit/search_test.rb', line 681
def all_search_params_present?(params)
params.all? { |_name, value| value.present? }
end
|
#all_search_variants_tested? ⇒ Boolean
283
284
285
286
|
# File 'lib/au_core_test_kit/search_test.rb', line 283
def all_search_variants_tested?
search_variant_test_records.all? { |_variant, tested| tested.present? } &&
all_comparator_searches_tested?
end
|
#any_valid_search_params?(search_params) ⇒ Boolean
66
67
68
|
# File 'lib/au_core_test_kit/search_test.rb', line 66
def any_valid_search_params?(search_params)
search_params.any? { |_patient_id, params| params.present? }
end
|
#array_of_codes(array) ⇒ Object
685
686
687
|
# File 'lib/au_core_test_kit/search_test.rb', line 685
def array_of_codes(array)
array.map { |name| "`#{name}`" }.join(', ')
end
|
#birthdate_comparator_value(comparator, date) ⇒ Object
316
317
318
319
320
321
322
323
324
325
|
# File 'lib/au_core_test_kit/search_test.rb', line 316
def birthdate_comparator_value(comparator, date)
case comparator
when 'lt', 'le'
comparator + (DateTime.xmlschema(date) + 1).strftime('%F')
when 'gt', 'ge'
comparator + (DateTime.xmlschema(date) - 1).strftime('%F')
else
raise "Unsupported comparator '#{comparator}'"
end
end
|
#cant_resolve_next_bundle_message(link) ⇒ Object
763
764
765
|
# File 'lib/au_core_test_kit/search_test.rb', line 763
def cant_resolve_next_bundle_message(link)
"Could not resolve next bundle: #{link}"
end
|
#chain_search_restriction(search_parameter) ⇒ Object
712
713
714
|
# File 'lib/au_core_test_kit/search_test.rb', line 712
def chain_search_restriction(search_parameter)
"I don't know how to run a chain search with this search parameter: #{search_parameter} (generator restrictions)."
end
|
#check_availability_of_count_search_parameter(resource_type, params) ⇒ Object
139
140
141
142
143
144
145
|
# File 'lib/au_core_test_kit/search_test.rb', line 139
def check_availability_of_count_search_parameter(resource_type, params)
search_params = params.merge({ _count: 1 })
fhir_search(resource_type, params: search_params)
response[:status] == 200
end
|
#check_resource_against_params(resource, params) ⇒ Object
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
|
# File 'lib/au_core_test_kit/search_test.rb', line 887
def check_resource_against_params(resource, params)
params.each do |name, escaped_search_value|
search_value = escaped_search_value&.gsub('\\,', ',')
paths = search_param_paths(name)
match_found = false
values_found = []
if %w[indigenous-status gender-identity].include?(name)
search_param_extension_map = {
'indigenous-status' => 'http://hl7.org.au/fhir/StructureDefinition/indigenous-status',
'gender-identity' => 'http://hl7.org/fhir/StructureDefinition/individual-genderIdentity'
}
values_found = [extension_check(resource, search_param_extension_map[name])]
match_found = search_value.to_s == values_found.first if values_found.length.positive?
else
paths.each do |path|
type = metadata.search_definitions[name.to_sym][:type]
values_found =
resolve_path(resource, path)
.map do |value|
if value.is_a? FHIR::Reference
value.reference
else
value
end
end
match_found =
case type
when 'Period', 'date', 'instant', 'dateTime'
values_found.any? { |date| validate_date_search(search_value, date) }
when 'HumanName'
search_value_downcase = search_value.downcase
values_found.any? do |name|
name&.text&.downcase&.start_with?(search_value_downcase) ||
name&.family&.downcase&.start_with?(search_value_downcase) ||
name&.given&.any? { |given| given.downcase.start_with?(search_value_downcase) } ||
name&.prefix&.any? { |prefix| prefix.downcase.start_with?(search_value_downcase) } ||
name&.suffix&.any? { |suffix| suffix.downcase.start_with?(search_value_downcase) }
end
when 'Address'
search_value_downcase = search_value.downcase
values_found.any? do |address|
address&.text&.downcase&.start_with?(search_value_downcase) ||
address&.city&.downcase&.start_with?(search_value_downcase) ||
address&.state&.downcase&.start_with?(search_value_downcase) ||
address&.postalCode&.downcase&.start_with?(search_value_downcase) ||
address&.country&.downcase&.start_with?(search_value_downcase)
end
when 'CodeableConcept'
codings = values_found.flat_map(&:coding)
if search_value.include? '|'
system = search_value.split('|').first
code = search_value.split('|').last
codings&.any? { |coding| coding.system == system && coding.code&.casecmp?(code) }
else
codings&.any? { |coding| coding.code&.casecmp?(search_value) }
end
when 'Coding'
if search_value.include? '|'
system = search_value.split('|').first
code = search_value.split('|').last
values_found.any? { |coding| coding.system == system && coding.code&.casecmp?(code) }
else
values_found.any? { |coding| coding.code&.casecmp?(search_value) }
end
when 'Identifier'
if search_value.include? '|'
values_found.any? { |identifier| "#{identifier.system}|#{identifier.value}" == search_value }
else
values_found.any? { |identifier| identifier.value == search_value }
end
when 'string'
searched_values = search_value.downcase.split(/(?<!\\\\),/).map { |string| string.gsub('\\,', ',') }
values_found.any? do |value_found|
searched_values.any? { |searched_value| value_found.downcase.starts_with? searched_value }
end
else
if %w[subject patient].include? name.to_s
id = search_value.split('Patient/').last
possible_values = [id, "Patient/#{id}", "#{url}/Patient/#{id}"]
values_found.any? do |reference|
possible_values.include? reference
end
else
search_values = search_value.split(/(?<!\\\\),/).map { |string| string.gsub('\\,', ',') }
values_found.any? { |value_found| search_values.include? value_found }
end
end
break if match_found
end
end
assert match_found,
"#{resource_type}/#{resource.id} did not match the search parameters:\n" \
"* Expected: #{search_value}\n" \
"* Found: #{values_found.map(&:inspect).join(', ')}"
end
end
|
#check_search_response ⇒ Object
263
264
265
266
267
|
# File 'lib/au_core_test_kit/search_test.rb', line 263
def check_search_response
assert_response_status(200)
assert_resource_type(:bundle)
end
|
#date_comparator_value(comparator, date) ⇒ Object
294
295
296
297
298
299
300
301
302
303
304
305
|
# File 'lib/au_core_test_kit/search_test.rb', line 294
def date_comparator_value(comparator, date)
date = date.start || date.end if date.is_a? FHIR::Period
case comparator
when 'lt', 'le'
comparator + (DateTime.xmlschema(date) + 1).xmlschema
when 'gt', 'ge'
comparator + (DateTime.xmlschema(date) - 1).xmlschema
else
raise "Unsupported comparator '#{comparator}'"
end
end
|
#default_search_values(param_name) ⇒ Object
432
433
434
435
436
437
|
# File 'lib/au_core_test_kit/search_test.rb', line 432
def default_search_values(param_name)
definition = metadata.search_definitions[param_name]
return [] if definition.blank?
definition[:multiple_or] == 'SHALL' || definition[:multiple_or] == 'SHOULD' ? [definition[:values].join(',')] : Array.wrap(definition[:values])
end
|
#default_search_values_clean(param_name) ⇒ Object
439
440
441
442
443
444
|
# File 'lib/au_core_test_kit/search_test.rb', line 439
def default_search_values_clean(param_name)
definition = metadata.search_definitions[param_name]
return [] if definition.blank?
definition[:values]
end
|
#default_values_for_param(param_name) ⇒ Object
425
426
427
428
429
430
|
# File 'lib/au_core_test_kit/search_test.rb', line 425
def default_values_for_param(param_name)
definition = metadata.search_definitions[param_name]
return [] if definition.blank?
definition[:values]
end
|
#element_has_valid_value?(element, include_system) ⇒ Boolean
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
|
# File 'lib/au_core_test_kit/search_test.rb', line 829
def element_has_valid_value?(element, include_system)
case element
when FHIR::Reference
element.reference.present?
when FHIR::CodeableConcept
if include_system
coding =
find_a_value_at(element, 'coding') { |coding| coding.code.present? && coding.system.present? }
coding.present?
else
find_a_value_at(element, 'coding.code').present?
end
when FHIR::Identifier
include_system ? element.value.present? && element.system.present? : element.value.present?
when FHIR::Coding
include_system ? element.code.present? && element.system.present? : element.code.present?
when FHIR::HumanName
(element.family || element.given&.first || element.text).present?
when FHIR::Address
(element.text || element.city || element.state || element.postalCode || element.country).present?
else
true
end
end
|
#empty_search_params_message(empty_search_params) ⇒ Object
700
701
702
|
# File 'lib/au_core_test_kit/search_test.rb', line 700
def empty_search_params_message(empty_search_params)
"Could not find values for the search parameters #{array_of_codes(empty_search_params.keys)}"
end
|
#extension_check(resource, extension_url) ⇒ Object
878
879
880
881
882
883
884
885
|
# File 'lib/au_core_test_kit/search_test.rb', line 878
def extension_check(resource, extension_url)
extension_elements = resource.extension.filter { |ext| ext.url == extension_url }
extension_element = extension_elements.first
return extension_element.extension.first.valueCodeableConcept.coding.first.code if extension_url == 'http://hl7.org/fhir/StructureDefinition/individual-genderIdentity'
extension_element.valueCoding.code
end
|
446
447
448
449
450
451
452
453
454
455
|
# File 'lib/au_core_test_kit/search_test.rb', line 446
def (resources_arr, param_name)
results = []
resources_arr.each do |resource|
temp = search_param_value(param_name, resource)
results << temp
end
results.compact.uniq
end
|
#fetch_all_bundled_resources(reply_handler: nil, max_pages: 20, additional_resource_types: [], resource_type: self.resource_type) ⇒ Object
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
|
# File 'lib/au_core_test_kit/search_test.rb', line 716
def fetch_all_bundled_resources(
reply_handler: nil,
max_pages: 20,
additional_resource_types: [],
resource_type: self.resource_type
)
page_count = 1
resources = []
bundle = resource
until bundle.nil? || page_count == max_pages
resources += bundle&.entry&.map { |entry| entry&.resource }
next_bundle_link = bundle&.link&.find { |link| link.relation == 'next' }&.url
reply_handler&.call(response)
break if next_bundle_link.blank?
reply = fhir_client.raw_read_url(next_bundle_link)
store_request('outgoing') { reply }
error_message = cant_resolve_next_bundle_message(next_bundle_link)
assert_response_status(200)
assert_valid_json(reply.body, error_message)
bundle = fhir_client.parse_reply(FHIR::Bundle, fhir_client.default_format, reply)
page_count += 1
end
valid_resource_types = [resource_type, 'OperationOutcome'].concat(additional_resource_types)
valid_resource_types << 'Medication' if %w[MedicationRequest MedicationDispense].include?(resource_type)
invalid_resource_types =
resources.reject { |entry| valid_resource_types.include? entry.resourceType }
.map(&:resourceType)
.uniq
if invalid_resource_types.any?
info "Received resource type(s) #{invalid_resource_types.join(', ')} in search bundle, " \
"but only expected resource types #{valid_resource_types.join(', ')}. " \
'This is unusual but allowed if the server believes additional resource types are relevant.'
end
resources
end
|
#filter_conditions(resources) ⇒ Object
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/au_core_test_kit/search_test.rb', line 241
def filter_conditions(resources)
resources.select! do |resource|
resource.category.any? do |category|
category.coding.any? do |coding|
metadata.search_definitions[:category][:values].include? coding.code
end
end
end
end
|
#filter_devices(resources) ⇒ Object
232
233
234
235
236
237
238
239
|
# File 'lib/au_core_test_kit/search_test.rb', line 232
def filter_devices(resources)
codes_to_include = implantable_device_codes&.split(',')&.map(&:strip)
return resources if codes_to_include.blank?
resources.select! do |resource|
resource&.type&.coding&.any? { |coding| codes_to_include.include?(coding.code) }
end
end
|
#find_include_resources(params, patient_id, include_param, _keep_search_variant = true) ⇒ Object
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
# File 'lib/au_core_test_kit/search_test.rb', line 508
def find_include_resources(params, patient_id, include_param, _keep_search_variant = true)
resources_to_check = "#{include_param['target_resource'].downcase}_resources".to_sym
target_resource_type = include_param['target_resource']
scratch[resources_to_check] ||= {}
scratch[resources_to_check][:all] ||= []
scratch[resources_to_check][patient_id] ||= []
scratch[resources_to_check][:contained] ||= []
search_params = params.merge(_include: include_param['parameter'])
search_and_check_response(search_params)
resources = fetch_all_bundled_resources.select { |resource| resource.resourceType == target_resource_type }
resources.uniq!(&:id)
scratch[resources_to_check][:all] += resources
scratch[resources_to_check][patient_id] += resources
scratch[resources_to_check][:contained] += resources
resources
end
|
#fixed_value_search_param_name ⇒ Object
612
613
614
|
# File 'lib/au_core_test_kit/search_test.rb', line 612
def fixed_value_search_param_name
(search_param_names - ['patient']).first
end
|
#fixed_value_search_param_values ⇒ Object
616
617
618
|
# File 'lib/au_core_test_kit/search_test.rb', line 616
def fixed_value_search_param_values
metadata.search_definitions[fixed_value_search_param_name.to_sym][:values]
end
|
#fixed_value_search_params(value, patient_id) ⇒ Object
620
621
622
623
624
|
# File 'lib/au_core_test_kit/search_test.rb', line 620
def fixed_value_search_params(value, patient_id)
search_param_names.each_with_object({}) do |name, params|
params[name] = patient_id_param?(name) ? patient_id : value
end
end
|
#initial_search_variant_test_records ⇒ Object
273
274
275
276
277
278
279
280
281
|
# File 'lib/au_core_test_kit/search_test.rb', line 273
def initial_search_variant_test_records
{}.tap do |records|
records[:post_variant] = false if test_post_search?
records[:inclusion] = false if includes&.length&.positive?
records[:reference_variants] = false if test_reference_variants?
records[:token_variants] = false if token_search_params.present?
records[:comparator_searches] = Set.new if params_with_comparators.present?
end
end
|
#insufficient_number_of_values(values_to_search) ⇒ Object
689
690
691
692
693
694
|
# File 'lib/au_core_test_kit/search_test.rb', line 689
def insufficient_number_of_values(values_to_search)
"Insufficient number of values for the search. The number of values should be more than 1. The current number of values is #{values_to_search.length}."
end
|
#is_count_available_for_resource_type?(resource_type, params) ⇒ Boolean
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/au_core_test_kit/search_test.rb', line 147
def is_count_available_for_resource_type?(resource_type, params)
resource_sym = resource_type.to_sym
count = scratch&.dig(:info, resource_sym, :count)
return count unless count.nil?
result = check_availability_of_count_search_parameter(resource_type, params)
scratch[:info] ||= {}
scratch[:info][resource_sym] ||= {}
scratch[:info][resource_sym][:count] ||= result
result
end
|
#is_reference_match?(reference, local_reference) ⇒ Boolean
592
593
594
595
|
# File 'lib/au_core_test_kit/search_test.rb', line 592
def is_reference_match?(reference, local_reference)
regex_pattern = %r{^(#{Regexp.escape(local_reference)}|\S+/#{Regexp.escape(local_reference)}(?:[/|]\S+)*)$}
reference.match?(regex_pattern)
end
|
#modify_value_by_multiple_type(values, multiple_type) ⇒ Object
465
466
467
468
469
|
# File 'lib/au_core_test_kit/search_test.rb', line 465
def modify_value_by_multiple_type(values, multiple_type)
return [values.join(',')] if multiple_type == 'or'
Array.wrap(values)
end
|
#no_resources_skip_message(resource_type = self.resource_type) ⇒ Object
704
705
706
707
708
709
710
|
# File 'lib/au_core_test_kit/search_test.rb', line 704
def no_resources_skip_message(resource_type = self.resource_type)
msg = "No #{resource_type} resources appear to be available"
msg.concat(" with the following Device Type Code filter: #{implantable_device_codes}") if resource_type == 'Device' && implantable_device_codes.present?
"#{msg}. Please use patients with more information"
end
|
#optional_search_and_check_response(params, resource_type = self.resource_type) ⇒ Object
259
260
261
|
# File 'lib/au_core_test_kit/search_test.rb', line 259
def optional_search_and_check_response(params, resource_type = self.resource_type)
fhir_search(resource_type, params:)
end
|
#patient_id_list ⇒ Object
660
661
662
663
664
|
# File 'lib/au_core_test_kit/search_test.rb', line 660
def patient_id_list
return [nil] unless respond_to? :patient_ids
patient_ids.split(',').map(&:strip)
end
|
#patient_id_param?(name) ⇒ Boolean
670
671
672
|
# File 'lib/au_core_test_kit/search_test.rb', line 670
def patient_id_param?(name)
name == 'patient' || (name == '_id' && resource_type == 'Patient')
end
|
#patient_search? ⇒ Boolean
666
667
668
|
# File 'lib/au_core_test_kit/search_test.rb', line 666
def patient_search?
search_param_names.any? { |name| patient_id_param? name }
end
|
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
# File 'lib/au_core_test_kit/search_test.rb', line 327
def perform_comparator_searches(params, patient_id)
params_with_comparators.each do |name|
next if search_variant_test_records[:comparator_searches].include? name
required_comparators(name).each do |comparator|
paths = search_param_paths(name).first
date_element = find_a_value_at(scratch_resources_for_patient(patient_id), paths)
params_with_comparator = params.merge(name => name != 'birthdate' ? date_comparator_value(comparator, date_element) : birthdate_comparator_value(comparator, date_element))
search_and_check_response(params_with_comparator)
fetch_all_bundled_resources.each do |resource|
check_resource_against_params(resource, params_with_comparator) if resource.resourceType == resource_type
end
end
search_variant_test_records[:comparator_searches] << name
end
end
|
461
462
463
|
# File 'lib/au_core_test_kit/search_test.rb', line 461
def perform_multiple_and_search_test
perform_multiple_search_test('and')
end
|
457
458
459
|
# File 'lib/au_core_test_kit/search_test.rb', line 457
def perform_multiple_or_search_test
perform_multiple_search_test('or')
end
|
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
# File 'lib/au_core_test_kit/search_test.rb', line 471
def perform_multiple_search_test(multiple_type)
if search_param_names.length > 2
skip 'Inconsistent state of the test (params to search more than 2)'
elsif search_param_names.empty?
skip 'Inconsistent state of the test (number of params to search is 0)'
else
param_name = search_param_names[0]
default_search_values = default_search_values_clean(param_name.to_sym)
if default_search_values.length > 1
if default_search_values.length == 2
search_params = { param_name => modify_value_by_multiple_type(default_search_values, multiple_type) }
search_and_check_response(search_params)
else
chunk_size = 2
search_params_slices = default_search_values.each_slice(chunk_size).to_a
search_params_slices.pop if search_params_slices.last.length < chunk_size
search_params_slices.each do |values_slice|
search_params = { param_name => modify_value_by_multiple_type(values_slice, multiple_type) }
search_and_check_response(search_params)
end
end
else
resources_arr = all_search_params.map { |patient_id, _params_list| scratch_resources_for_patient(patient_id) }.flatten
resources_arr = scratch_resources[:all].filter { |r| r.resourceType == resource_type } if resources_arr.empty? && search_by_target_resource_data
existing_values = (resources_arr, param_name)
if existing_values.length > 1
search_params = { param_name => modify_value_by_multiple_type(existing_values, multiple_type) }
search_and_check_response(search_params)
else
skip insufficient_number_of_values(existing_values)
end
end
end
end
|
#perform_post_search(get_search_resources, params) ⇒ Object
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/au_core_test_kit/search_test.rb', line 211
def perform_post_search(get_search_resources, params)
fhir_search resource_type, params:, search_method: :post
check_search_response
post_search_resources = fetch_all_bundled_resources.select { |resource| resource.resourceType == resource_type }
filter_conditions(post_search_resources) if resource_type == 'Condition' && metadata.version == 'v5.0.1'
filter_devices(post_search_resources) if resource_type == 'Device'
get_resource_count = get_search_resources.length
post_resource_count = post_search_resources.length
search_variant_test_records[:post_variant] = true
assert get_resource_count == post_resource_count,
'Expected search by POST to return the same results as search by GET, ' \
"but GET search returned #{get_resource_count} resources, and POST search " \
"returned #{post_resource_count} resources."
end
|
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
# File 'lib/au_core_test_kit/search_test.rb', line 347
def perform_reference_with_type_search(params, resource_count)
return if resource_count.zero?
return if search_variant_test_records[:reference_variants]
if params.keys.include?('patient')
new_search_params = params.merge('patient' => "Patient/#{params['patient']}")
else
param_key = params.keys.first
new_search_params = params.merge(param_key => params[param_key].split('/').last)
end
search_and_check_response(new_search_params)
reference_with_type_resources = fetch_all_bundled_resources.select do |resource|
resource.resourceType == resource_type
end
filter_conditions(reference_with_type_resources) if resource_type == 'Condition' && metadata.version == 'v5.0.1'
filter_devices(reference_with_type_resources) if resource_type == 'Device'
new_resource_count = reference_with_type_resources.count
assert new_resource_count == resource_count,
"Expected search by `#{params['patient']}` to to return the same results as searching " \
"by `#{new_search_params['patient']}`, but found #{resource_count} resources with " \
"`#{params['patient']}` and #{new_resource_count} with `#{new_search_params['patient']}`"
search_variant_test_records[:reference_variants] = true
end
|
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/au_core_test_kit/search_test.rb', line 162
def perform_search(params, patient_id)
search_params = is_count_available_for_resource_type?(resource_type, params) == false ? params : params.merge({ _count: 10 })
fhir_search(resource_type, params: search_params)
if SearchTestHelpers.search_by_reference?(search_params)
search_params = SearchTestHelpers.replace_full_reference_search_param_to_id(search_params)
fhir_search(resource_type, params: search_params)
end
perform_search_with_status(params, patient_id) if response[:status] == 400 && possible_status_search?
check_search_response
fetch_all_bundled_resources = is_count_available_for_resource_type?(resource_type, params) == false ? fetch_all_bundled_resources() : fetch_all_bundled_resources(max_pages: 2)
resources_returned =
fetch_all_bundled_resources.select { |resource| resource.resourceType == resource_type }
return [] if resources_returned.blank?
perform_comparator_searches(params, patient_id) if params_with_comparators.present?
filter_conditions(resources_returned) if resource_type == 'Condition' && metadata.version == 'v5.0.1'
filter_devices(resources_returned) if resource_type == 'Device'
if first_search?
all_scratch_resources.concat(resources_returned).uniq!
scratch_resources_for_patient(patient_id).concat(resources_returned).uniq!
end
resources_returned.each do |resource|
check_resource_against_params(resource, params)
end
save_delayed_references(resources_returned) if saves_delayed_references?
return resources_returned if all_search_variants_tested?
perform_post_search(resources_returned, params) if test_post_search?
if includes.present?
includes.each do |include_param|
test_include_param(resources_returned, params, patient_id, include_param)
end
end
perform_reference_with_type_search(params, resources_returned.count) if test_reference_variants?
perform_search_with_system(params, patient_id) if token_search_params.present?
resources_returned
end
|
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
# File 'lib/au_core_test_kit/search_test.rb', line 394
def perform_search_with_status(
original_params,
_patient_id,
status_search_values: self.status_search_values,
resource_type: self.resource_type
)
assert resource.is_a?(FHIR::OperationOutcome), 'Server returned a status of 400 without an OperationOutcome'
status_search_values.flat_map do |status_value|
search_params = original_params.merge("#{status_search_param_name}": status_value)
search_and_check_response(search_params)
entries = resource.entry.select { |entry| entry.resource.resourceType == resource_type }
if entries.present?
original_params.merge!("#{status_search_param_name}": status_value)
break
end
end
end
|
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
# File 'lib/au_core_test_kit/search_test.rb', line 376
def perform_search_with_system(params, patient_id)
return if search_variant_test_records[:token_variants]
new_search_params = search_params_with_values(token_search_params, patient_id, include_system: true)
return if new_search_params.any? { |_name, value| value.blank? }
search_params = params.merge(new_search_params)
search_and_check_response(search_params)
resources_returned =
fetch_all_bundled_resources
.select { |resource| resource.resourceType == resource_type }
assert resources_returned.present?, 'No resources were returned when searching by `system|code`'
search_variant_test_records[:token_variants] = true
end
|
#references_to_save(resource_type = nil) ⇒ Object
607
608
609
610
|
# File 'lib/au_core_test_kit/search_test.rb', line 607
def references_to_save(resource_type = nil)
reference_metadata = resource_type == 'Provenance' ? provenance_metadata : metadata
reference_metadata.delayed_references
end
|
#required_comparators(name) ⇒ Object
307
308
309
310
311
312
313
314
|
# File 'lib/au_core_test_kit/search_test.rb', line 307
def required_comparators(name)
metadata
.search_definitions
.dig(name.to_sym, :comparators)
.select { |_comparator, expectation| expectation == 'SHALL' }
.keys
.map(&:to_s)
end
|
#run_include_test ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/au_core_test_kit/search_test.rb', line 110
def run_include_test
resources = []
all_search_params.each do |patient_id, params_list|
params_list.each do |params|
includes.each do |include_param|
patient_resources = find_include_resources(
params,
patient_id,
include_param,
false
)
if patient_resources.length.positive?
resources.concat(patient_resources)
break
end
end
end
break if resources.length.positive?
end
pass if resources.length.positive?
skip_with_msg 'No resources were included in the search results'
end
|
#run_provenance_revinclude_search_test ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/au_core_test_kit/search_test.rb', line 70
def run_provenance_revinclude_search_test
conditional_skip_with_msg !any_valid_search_params?(all_provenance_revinclude_search_params), unable_to_resolve_params_message
provenance_resources =
all_provenance_revinclude_search_params.flat_map do |_patient_id, params_list|
params_list.flat_map do |params|
fhir_search(resource_type, params:)
perform_search_with_status(params, patient_id) if response[:status] == 400 && possible_status_search?
check_search_response
fetch_all_bundled_resources(additional_resource_types: ['Provenance'])
.select { |resource| resource.resourceType == 'Provenance' }
end
end
scratch_provenance_resources[:all] ||= []
scratch_provenance_resources[:all].concat(provenance_resources)
save_delayed_references(provenance_resources, 'Provenance')
end
|
#run_read_test_and_skip_first_search(patient_id) ⇒ Object
134
135
136
137
|
# File 'lib/au_core_test_kit/search_test.rb', line 134
def run_read_test_and_skip_first_search(patient_id)
resource = create_reference('Patient', patient_id)
read_and_validate_as_first(resource, patient_id)
end
|
#run_search_test ⇒ Object
102
103
104
|
# File 'lib/au_core_test_kit/search_test.rb', line 102
def run_search_test
run_search_test_common(method(:perform_search))
end
|
#run_search_test_with_system ⇒ Object
106
107
108
|
# File 'lib/au_core_test_kit/search_test.rb', line 106
def run_search_test_with_system
run_search_test_common(method(:perform_search_with_system))
end
|
#save_delayed_references(resources, containing_resource_type = resource_type) ⇒ Object
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
|
# File 'lib/au_core_test_kit/search_test.rb', line 860
def save_delayed_references(resources, containing_resource_type = resource_type)
resources.each do |resource|
references_to_save(containing_resource_type).each do |reference_to_save|
resolve_path(resource, reference_to_save[:path])
.select { |reference| reference.is_a?(FHIR::Reference) && !reference.contained? && reference.reference.present?}
.each do |reference|
resource_type = reference.resource_class.name.demodulize
need_to_save = reference_to_save[:resources].include?(resource_type)
next unless need_to_save
save_resource_reference(resource_type, reference)
end
end
end
end
|
#save_resource_reference(resource_type, reference) ⇒ Object
854
855
856
857
858
|
# File 'lib/au_core_test_kit/search_test.rb', line 854
def save_resource_reference(resource_type, reference)
scratch[:references] ||= {}
scratch[:references][resource_type] ||= Set.new
scratch[:references][resource_type] << reference
end
|
#scratch_resources_for_patient(patient_id) ⇒ Object
601
602
603
604
605
|
# File 'lib/au_core_test_kit/search_test.rb', line 601
def scratch_resources_for_patient(patient_id)
return all_scratch_resources if patient_id.nil?
scratch_resources[patient_id] ||= []
end
|
#search_and_check_response(params, resource_type = self.resource_type) ⇒ Object
254
255
256
257
|
# File 'lib/au_core_test_kit/search_test.rb', line 254
def search_and_check_response(params, resource_type = self.resource_type)
fhir_search(resource_type, params:)
check_search_response
end
|
#search_by_patient_id_is_available(patient_id) ⇒ Object
97
98
99
100
|
# File 'lib/au_core_test_kit/search_test.rb', line 97
def search_by_patient_id_is_available(patient_id)
fhir_search('Patient', params: { _id: patient_id })
response[:status] == 200
end
|
#search_param_paths(name) ⇒ Object
674
675
676
677
678
679
|
# File 'lib/au_core_test_kit/search_test.rb', line 674
def search_param_paths(name)
paths = metadata.search_definitions[name.to_sym][:paths]
paths[0] = 'local_class' if paths.first == 'class'
paths
end
|
#search_param_value(name, resource, include_system: false) ⇒ Object
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
# File 'lib/au_core_test_kit/search_test.rb', line 767
def search_param_value(name, resource, include_system: false)
paths = search_param_paths(name)
search_value = nil
paths.each do |path|
element = find_a_value_at(resource, path) { |element| element_has_valid_value?(element, include_system) }
search_value =
case element
when FHIR::Period
if element.start.present?
"gt#{(DateTime.xmlschema(element.start) - 1).xmlschema}"
else
end_datetime = get_fhir_datetime_range(element.end)[:end]
"lt#{(end_datetime + 1).xmlschema}"
end
when FHIR::Reference
element.reference
when FHIR::CodeableConcept
if include_system
coding =
find_a_value_at(element, 'coding') { |coding| coding.code.present? && coding.system.present? }
"#{coding.system}|#{coding.code}"
else
find_a_value_at(element, 'coding.code')
end
when FHIR::Identifier
include_system ? "#{element.system}|#{element.value}" : element.value
when FHIR::Coding
include_system ? "#{element.system}|#{element.code}" : element.code
when FHIR::HumanName
element.family || element.given&.first || element.text
when FHIR::Address
element.text || element.city || element.state || element.postalCode || element.country
else
if metadata.version != 'v3.1.1' &&
metadata.search_definitions[name.to_sym][:type] == 'date' &&
params_with_comparators&.include?(name)
if /^\d{4}(-\d{2})?$/.match?(element) || (/^\d{4}-\d{2}-\d{2}$/.match?(element) && resource_type != 'Goal') if !(path == 'birthDate' && resource_type == 'Patient')
"gt#{(DateTime.xmlschema(element) - 1).xmlschema}"
else
"gt#{(DateTime.xmlschema(element) - 1).strftime('%F')}"
end
else
element
end
else
element
end
end
break if search_value.present?
end
search_value&.gsub(',', '\\,')
end
|
#search_params_with_values(search_param_names, patient_id, include_system: false) ⇒ Object
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
|
# File 'lib/au_core_test_kit/search_test.rb', line 626
def search_params_with_values(search_param_names, patient_id, include_system: false)
resources = scratch_resources_for_patient(patient_id)
if resources.empty?
return search_param_names.each_with_object({}) do |name, params|
value = patient_id_param?(name) ? patient_id : nil
if value.nil? && use_any_data_for_search
scratch_resources[:all].each do |resource|
value = search_param_value(name, resource, include_system:)
break if value.present?
end
end
params[name] = value
end
end
resources.each_with_object({}) do |resource, outer_params|
results_from_one_resource = search_param_names.each_with_object({}) do |name, params|
value = if patient_id_param?(name)
patient_id
else
search_param_value(name, resource,
include_system:)
end
params[name] = value
end
outer_params.merge!(results_from_one_resource)
return outer_params if outer_params.all? { |_key, value| value.present? }
end
end
|
#search_variant_test_records ⇒ Object
269
270
271
|
# File 'lib/au_core_test_kit/search_test.rb', line 269
def search_variant_test_records
@search_variant_test_records ||= initial_search_variant_test_records
end
|
#status_search_param_name ⇒ Object
416
417
418
419
|
# File 'lib/au_core_test_kit/search_test.rb', line 416
def status_search_param_name
@status_search_param_name ||=
metadata.search_definitions.keys.find { |key| key.to_s.include? 'status' }
end
|
#status_search_values ⇒ Object
421
422
423
|
# File 'lib/au_core_test_kit/search_test.rb', line 421
def status_search_values
default_search_values(status_search_param_name)
end
|
#test_include_param(base_resources, params, patient_id, include_param, keep_search_variant = true) ⇒ Object
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
# File 'lib/au_core_test_kit/search_test.rb', line 529
def test_include_param(base_resources, params, patient_id, include_param, keep_search_variant = true)
return if keep_search_variant && search_variant_test_records[:inclusion]
resources_to_check = "#{include_param['target_resource'].downcase}_resources".to_sym
target_resource_type = include_param['target_resource']
scratch[resources_to_check] ||= {}
scratch[resources_to_check][:all] ||= []
scratch[resources_to_check][patient_id] ||= []
scratch[resources_to_check][:contained] ||= []
base_resources_with_external_reference =
base_resources
.select { |resource| resource&.to_hash&.[](include_param['paths'].first)&.present? }
.reject { |resource| resource&.to_hash&.[](include_param['paths'].first)&.fetch('reference', '')&.start_with?('#') }
contained_resources =
base_resources
.select { |resource| resource&.to_hash&.[](include_param['paths'].first)&.fetch('reference', '')&.start_with?('#') }
.flat_map(&:contained)
.select { |resource| resource.resourceType == target_resource_type }
scratch[resources_to_check][:all] += contained_resources
scratch[resources_to_check][patient_id] += contained_resources
scratch[resources_to_check][:contained] += contained_resources
return if base_resources_with_external_reference.blank?
search_params = params.merge(_include: include_param['parameter'])
search_and_check_response(search_params)
resources = fetch_all_bundled_resources.select { |resource| resource.resourceType == target_resource_type }
assert resources.present?, "No #{resource_type} were included in the search results"
included_resources = resources.map { |resource| "#{resource.resourceType}/#{resource.id}" }
matched_base_resources = base_resources_with_external_reference.select do |base_resource|
included_resources.any? do |resource_reference|
is_reference_match?(base_resource&.to_hash&.[](include_param['paths'].first)&.fetch('reference', ''), resource_reference)
end
end
not_matched_included_resources = included_resources.select do |resource_reference|
matched_base_resources.none? do |base_resource|
is_reference_match?(base_resource&.to_hash&.[](include_param['paths'].first)&.fetch('reference', ''), resource_reference)
end
end
not_matched_included_medications_string = not_matched_included_resources.join(',')
assert not_matched_included_resources.empty?,
"No #{resource_type} references #{not_matched_included_medications_string} in the search result."
resources.uniq!(&:id)
scratch[resources_to_check][:all] += resources
scratch[resources_to_check][patient_id] += resources
return unless keep_search_variant
search_variant_test_records[:inclusion] = true
end
|
#unable_to_resolve_params_message ⇒ Object
696
697
698
|
# File 'lib/au_core_test_kit/search_test.rb', line 696
def unable_to_resolve_params_message
"Could not find values for all search params #{array_of_codes(search_param_names)}"
end
|