Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process scheduled_time_string before creating a hearing via ScheduleHearingTask #22152

16 changes: 0 additions & 16 deletions app/models/tasks/schedule_hearing_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ def create_schedule_hearing_tasks(params)
task_values = params.delete(:business_payloads)[:values]
hearing = create_hearing(task_values)

# Convert scheduled_time_string to a UTC time string
task_values[:scheduled_time_string] = convert_scheduled_time_to_utc(task_values[:scheduled_time_string])

# Create the virtual hearing if the attributes have been passed
if task_values[:virtual_hearing_attributes].present?
@alerts = VirtualHearings::ConvertToVirtualHearingService
Expand All @@ -219,19 +216,6 @@ def create_schedule_hearing_tasks(params)
created_tasks
end

def convert_scheduled_time_to_utc(time_string)
if time_string.present?
# Find the AM/PM index value in the string
index = time_string.include?("AM") ? time_string.index("AM") + 2 : time_string.index("PM") + 2

# Generate the scheduled_time in UTC and update the scheduled_time_string
scheduled_time = time_string[0..index].strip
timezone = time_string[index..-1].strip
return Time.use_zone(timezone) { Time.zone.parse(scheduled_time) }.utc
end
nil
end

# Method to change the hearing request type on an appeal
def change_hearing_request_type(params, current_user)
change_hearing_request_type_task = ChangeHearingRequestTypeTask.create!(
Expand Down
5 changes: 3 additions & 2 deletions app/repositories/hearing_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def fix_hearings_timezone(scheduled_time_string)
# rubocop:disable Metrics/MethodLength
def slot_new_hearing(attrs, override_full_hearing_day_validation: false)
hearing_day = HearingDay.find(attrs[:hearing_day_id])
processed_scheduled_time = HearingTimeService.convert_scheduled_time_to_utc(attrs[:scheduled_time_string])

fail HearingDayFull if !override_full_hearing_day_validation && hearing_day.hearing_day_full?

if attrs[:appeal].is_a?(LegacyAppeal)
scheduled_for = HearingTimeService.legacy_formatted_scheduled_for(
scheduled_for: hearing_day.scheduled_for,
scheduled_time_string: attrs[:scheduled_time_string]
scheduled_time_string: processed_scheduled_time
)
vacols_hearing = create_vacols_hearing(
hearing_day: hearing_day,
Expand All @@ -75,7 +76,7 @@ def slot_new_hearing(attrs, override_full_hearing_day_validation: false)
appeal: attrs[:appeal],
hearing_day_id: hearing_day.id,
hearing_location_attributes: attrs[:hearing_location_attrs] || {},
scheduled_time: attrs[:scheduled_time_string],
scheduled_time: processed_scheduled_time,
scheduled_in_timezone: fix_hearings_timezone(attrs[:scheduled_time_string]),
override_full_hearing_day_validation: override_full_hearing_day_validation,
notes: attrs[:notes]
Expand Down
19 changes: 18 additions & 1 deletion app/services/hearing_time_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def build_params_with_time(_hearing, update_params)

def legacy_formatted_scheduled_for(scheduled_for:, scheduled_time_string:)
# Parse the scheduled_time_string as a UTC time
scheduled_time_in_utc = Time.zone.parse(scheduled_time_string).utc
scheduled_time_in_utc = if scheduled_time_string.is_a?(String)
Time.zone.parse(scheduled_time_string).utc
else
scheduled_time_string
end

time = scheduled_for.to_datetime
Time.use_zone(VacolsHelper::VACOLS_DEFAULT_TIMEZONE) do
Expand All @@ -47,6 +51,19 @@ def time_to_string(time)
"#{pad_time(datetime.hour)}:#{pad_time(datetime.min)}"
end

def convert_scheduled_time_to_utc(time_string)
if time_string.present?
# Find the AM/PM index value in the string
index = time_string.include?("AM") ? time_string.index("AM") + 2 : time_string.index("PM") + 2

# Generate the scheduled_time in UTC and update the scheduled_time_string
scheduled_time = time_string[0..index].strip
timezone = time_string[index..-1].strip
return Time.use_zone(timezone) { Time.zone.parse(scheduled_time) }.utc
end
nil
end

private

def pad_time(time)
Expand Down
3 changes: 1 addition & 2 deletions spec/models/tasks/assign_hearing_disposition_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
expect(hearing.notes).to eq hearing_notes
end
expect(hearing_class.last.hearing_location.facility_id).to eq "vba_370"
scheduled_time = hearing_class.last.scheduled_for.zone == "EDT" ? "01:30PM" : "12:30PM"
expect(hearing_class.last.scheduled_for.strftime("%I:%M%p")).to eq scheduled_time
expect(hearing_class.last.scheduled_for.strftime("%I:%M%p")).to eq "12:30PM"
expect(HearingTask.count).to eq 2
expect(HearingTask.order(:id).first.cancelled?).to be_truthy
expect(HearingTask.order(:id).last.hearing_task_association.hearing.id).to eq hearing_class.last.id
Expand Down
Loading