-
Notifications
You must be signed in to change notification settings - Fork 66
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
base: master
Are you sure you want to change the base?
Changes from 14 commits
a7c7ab2
7b9caa6
f9d0a36
0577b6e
6401a1f
a749327
36cbafd
170d535
8a362ce
c565abd
26804f8
7631136
fbde9be
3c9df3b
5822040
91d4dbc
a755e2d
0b84443
e7b6f30
76b38cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,6 +261,7 @@ def create_params | |
) | ||
end | ||
end | ||
|
||
# rubocop:enable Metrics/MethodLength | ||
|
||
def start_date | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,11 @@ | |
cnp_count += 1 if cnp?(appt) | ||
end | ||
|
||
if include[:eps] | ||
# TODO: prepare eps_appointments differently than vaos appointments | ||
appointments = merge_appointments(eps_appointments, appointments) | ||
end | ||
|
||
if Flipper.enabled?(:appointments_consolidation, user) | ||
filterer = AppointmentsPresentationFilter.new | ||
appointments = appointments.keep_if { |appt| filterer.user_facing?(appt) } | ||
|
@@ -65,8 +70,8 @@ | |
} | ||
end | ||
rescue Common::Client::Errors::ParsingError, Common::Client::Errors::ClientError, | ||
Common::Exceptions::GatewayTimeout, MAP::SecurityToken::Errors::ApplicationMismatchError, | ||
MAP::SecurityToken::Errors::MissingICNError => e | ||
Common::Exceptions::GatewayTimeout, MAP::SecurityToken::Errors::ApplicationMismatchError, | ||
MAP::SecurityToken::Errors::MissingICNError => e | ||
{ | ||
data: {}, | ||
meta: pagination(pagination_params).merge({ | ||
|
@@ -98,14 +103,14 @@ | |
params.compact_blank! | ||
with_monitoring do | ||
response = if Flipper.enabled?(APPOINTMENTS_USE_VPG, user) && | ||
Flipper.enabled?(APPOINTMENTS_ENABLE_OH_REQUESTS) | ||
Flipper.enabled?(APPOINTMENTS_ENABLE_OH_REQUESTS) | ||
perform(:post, appointments_base_path_vpg, params, headers) | ||
else | ||
perform(:post, appointments_base_path_vaos, params, headers) | ||
end | ||
|
||
if request_object_body[:kind] == 'clinic' && | ||
booked?(request_object_body) # a direct scheduled appointment | ||
booked?(request_object_body) # a direct scheduled appointment | ||
modify_desired_date(request_object_body, get_facility_timezone(request_object_body[:location_id])) | ||
end | ||
|
||
|
@@ -126,7 +131,7 @@ | |
def update_appointment(appt_id, status) | ||
with_monitoring do | ||
if Flipper.enabled?(ORACLE_HEALTH_CANCELLATIONS, user) && | ||
Flipper.enabled?(APPOINTMENTS_USE_VPG, user) | ||
Flipper.enabled?(APPOINTMENTS_USE_VPG, user) | ||
update_appointment_vpg(appt_id, status) | ||
get_appointment(appt_id) | ||
else | ||
|
@@ -204,6 +209,40 @@ | |
facility_info[:timezone]&.[](:time_zone_id) | ||
end | ||
|
||
def normalize_eps_appointment(appt) | ||
{ | ||
id: appt[:id].to_s, | ||
status: appt[:state] == 'submitted' ? 'booked' : 'proposed', | ||
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 | ||
|
||
def calculate_end_time(start_time) | ||
return nil unless start_time | ||
|
||
Time.zone.parse(start_time) + 60.minutes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we deduping by referralId? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, just marking this as a confirmation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please see if the vaos appointment data have |
||
sorted_data = merged_data.sort_by { |appt| appt.dig(:requestedPeriods, 0, :start) || '' } | ||
|
||
{ data: sorted_data } | ||
end | ||
|
||
memoize :get_facility_timezone_memoized | ||
|
||
private | ||
|
@@ -234,6 +273,7 @@ | |
{ message:, status:, icn: sanitized_icn, context: } | ||
end | ||
end | ||
|
||
# rubocop:enable Metrics/MethodLength | ||
|
||
# Modifies the appointment, extracting individual fields from the appointment. This currently includes: | ||
|
@@ -827,6 +867,16 @@ | |
|
||
SchemaContract::ValidationInitiator.call(user:, response:, contract_name:) | ||
end | ||
|
||
def eps_appointments_service | ||
@eps_appointments_service ||= | ||
Eps::AppointmentService.new(current_user) | ||
end | ||
|
||
def eps_appointments | ||
@eps_appointments ||= | ||
eps_appointments_service.get_appointments | ||
end | ||
end | ||
lee-delarm6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see if we can move this to a serializer for mapping the data to different fields for normalizing with vaos appointments