Skip to content

Commit

Permalink
Fix granuality for the birthdate
Browse files Browse the repository at this point in the history
Ref: #232
  • Loading branch information
projkov committed Dec 3, 2024
1 parent c7211f3 commit 3d23915
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/au_core_test_kit/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,25 @@ def required_comparators(name)
.map(&:to_s)
end

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

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 => date_comparator_value(comparator, date_element))
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)

Expand Down Expand Up @@ -543,8 +554,6 @@ def test_include_param(base_resources, params, patient_id, include_param, keep_s

search_and_check_response(search_params)

puts "fetch_all_bundled_resources #{fetch_all_bundled_resources}"

resources = fetch_all_bundled_resources.select { |resource| resource.resourceType == target_resource_type }
assert resources.present?, "No #{resource_type} were included in the search results"

Expand Down Expand Up @@ -795,7 +804,11 @@ def search_param_value(name, resource, include_system: false)
# All others have second + time offset precision
if /^\d{4}(-\d{2})?$/.match?(element) || # YYYY or YYYY-MM
(/^\d{4}-\d{2}-\d{2}$/.match?(element) && resource_type != 'Goal') # YYY-MM-DD AND Resource is NOT Goal
"gt#{(DateTime.xmlschema(element) - 1).xmlschema}"
if !(path == "birthDate" && resource_type == "Patient")
"gt#{(DateTime.xmlschema(element) - 1).xmlschema}"
else
"gt#{(DateTime.xmlschema(element) - 1).strftime("%F")}"
end
else
element
end
Expand All @@ -806,7 +819,6 @@ def search_param_value(name, resource, include_system: false)

break if search_value.present?
end

search_value&.gsub(',', '\\,')
end

Expand Down

0 comments on commit 3d23915

Please sign in to comment.