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

adding merge functionality for eps to regular appointments #19754

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1837,4 +1837,5 @@ vaos:
api_url: "https://api.wellhive.com"
base_path: "care-navigation/v1"
scopes: "care-nav"
fake_patient_id: "fake_patient_id"

17 changes: 15 additions & 2 deletions modules/vaos/app/controllers/vaos/v2/appointments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ class AppointmentsController < VAOS::BaseController
COMMENT = 'comment'

def index
appointments[:data].each do |appt|
merged_appointments = appointments_service.merge_appointments(eps_appointments, appointments)
lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved

merged_appointments.each do |appt|
lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved
set_facility_error_msg(appt) if include_index_params[:facilities]
scrape_appt_comments_and_log_details(appt, index_method_logging_name, PAP_COMPLIANCE_TELE)
log_appt_creation_time(appt)
end

serializer = VAOS::V2::VAOSSerializer.new
serialized = serializer.serialize(appointments[:data], 'appointments')
serialized = serializer.serialize(merged_appointments, 'appointments')

if !appointments[:meta][:failures]&.empty?
lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved
StatsDMetric.new(key: STATSD_KEY).save
Expand Down Expand Up @@ -82,6 +84,11 @@ def appointments_service
VAOS::V2::AppointmentsService.new(current_user)
end

def eps_appointments_service
@eps_appointments_service ||=
Eps::AppointmentService.new(current_user)
end

def mobile_facility_service
@mobile_facility_service ||=
VAOS::V2::MobileFacilityService.new(current_user)
Expand All @@ -92,6 +99,11 @@ def appointments
appointments_service.get_appointments(start_date, end_date, statuses, pagination_params, include_index_params)
end

def eps_appointments
@eps_appointments ||=
eps_appointments_service.get_appointments(patient_id: Settings.vaos.eps.fake_patient_id)
lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved
end

def appointment
@appointment ||=
appointments_service.get_appointment(appointment_id, include_show_params)
Expand Down Expand Up @@ -261,6 +273,7 @@ def create_params
)
end
end

# rubocop:enable Metrics/MethodLength

def start_date
Expand Down
49 changes: 49 additions & 0 deletions modules/vaos/app/services/vaos/v2/appointments_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,54 @@ def get_facility_timezone_memoized(facility_location_id)
facility_info[:timezone]&.[](:time_zone_id)
end

def normalize_eps_appointment(appt)
{
id: appt[:id].to_s,
status: map_state_to_status(appt[:state]),
lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved
patientIcn: appt[:patientId],
created: appt.dig(:appointmentDetails, :lastRetrieved),
requestedPeriods: [
{
start: appt.dig(:appointmentDetails, :start),
end: calculate_end_time(appt.dig(:appointmentDetails, :start))
}
].compact,
locationId: appt[:locationId],
clinic: appt[:clinic],
contact: appt[:contact]
}.compact
end

# rubocop:disable Lint/DuplicateBranch
def map_state_to_status(state)
case state&.downcase
when 'draft'
'proposed'
when 'submitted'
'booked'
else
'proposed'
end
lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved
end

# rubocop:enable Lint/DuplicateBranch

def calculate_end_time(start_time)
return nil unless start_time

Time.zone.parse(start_time) + 60.minutes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is going to use the timezone of the runtime, which might be different from the patient's timezone. And if that's the case and we're showing the start time in patient's timezone, the end time could be incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the start and end from the same data point though, shouldn't this match up? This is from where the method is entered:

start: appt.dig(:appointmentDetails, :start),
end: calculate_end_time(appt.dig(:appointmentDetails, :start))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timezone is in UTC we have found, so we will also inform the front end to change it to the user's time zone

lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved
end

def merge_appointments(new_appointments, basic_appointments)
lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved
normalized_new = new_appointments[:appointments].map { |appt| normalize_eps_appointment(appt) }
basic_data = basic_appointments[:data].is_a?(Array) ? basic_appointments[:data] : [basic_appointments[:data]]
lee-delarm6 marked this conversation as resolved.
Show resolved Hide resolved
existing_ids = basic_data.to_set { |a| a[:referralId] }
merged_data = basic_data + normalized_new.reject { |a| existing_ids.include?(a[:referralId]) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we deduping by referralId?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just marking this as a confirmation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please see if the vaos appointment data have referralId & is available under referralId key?

sorted_data = merged_data.sort_by { |appt| appt.dig(:requestedPeriods, 0, :start) || '' }

{ data: sorted_data }
end

memoize :get_facility_timezone_memoized

private
Expand Down Expand Up @@ -234,6 +282,7 @@ def parse_possible_token_related_errors(e)
{ message:, status:, icn: sanitized_icn, context: }
end
end

# rubocop:enable Metrics/MethodLength

# Modifies the appointment, extracting individual fields from the appointment. This currently includes:
Expand Down
Loading