Skip to content

Commit

Permalink
moved null dispensed date values to the top always
Browse files Browse the repository at this point in the history
  • Loading branch information
agravell047 committed May 2, 2024
1 parent e25d925 commit 11aa514
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
6 changes: 4 additions & 2 deletions app/models/prescription_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class PrescriptionDetails < Prescription

def sorted_dispensed_date
has_refills = try(:rx_rf_records).present?
last_refill_date = Date.new(0)
default_date = Date.new(0)
last_refill_date = default_date

if has_refills
refills = rx_rf_records[0][1]
Expand All @@ -48,12 +49,13 @@ def sorted_dispensed_date
end
end

last_refill_date = nil if last_refill_date == default_date
if has_refills && last_refill_date.present?
last_refill_date.to_date
elsif dispensed_date.present?
dispensed_date.to_date
else
Date.new(0)
nil
end
end
end
25 changes: 16 additions & 9 deletions modules/my_health/app/helpers/my_health/prescription_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def sort_by(resource, sort_params)
resource.data = resource.data.sort do |a, b|
comparison = 0
sort_params.each_with_index do |field, index|
field1_a, field1_b = populate_sort_vars(field, a, b)
comparison = compare_fields(field1_a, field1_b, sort_orders[index])
is_descending = sort_orders[index]
field_a, field_b = populate_sort_vars(field, a, b, is_descending)
comparison = compare_fields(field_a, field_b, is_descending)
break if !comparison.zero? || field.nil?
end
comparison
Expand All @@ -44,28 +45,34 @@ def get_sort_order(fields)
end
end

def compare_fields(field_a, field_b, descending)
def compare_fields(field_a, field_b, is_descending)
if field_a > field_b
descending ? -1 : 1
is_descending ? -1 : 1
elsif field_a < field_b
descending ? 1 : -1
is_descending ? 1 : -1
else
0
end
end

def populate_sort_vars(field, a, b)
def populate_sort_vars(field, a, b, is_descending)
if field.nil?
[nil, nil]
else
[get_field_data(field, a), get_field_data(field, b)]
[get_field_data(field, a, is_descending), get_field_data(field, b, is_descending)]
end
end

def get_field_data(field, data)
def get_field_data(field, data, is_descending)
case field
when /dispensed_date/
data[:sorted_dispensed_date]
if data[:sorted_dispensed_date].nil? && is_descending
Date.new(9999, 12, 31)
elsif data[:sorted_dispensed_date].nil?
Date.new(0, 1, 1)
else
data[:sorted_dispensed_date]
end
when 'prescription_name'
if data[:disp_status] == 'Active: Non-VA' && data[:prescription_name].nil?
data[:orderable_item]
Expand Down

0 comments on commit 11aa514

Please sign in to comment.