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 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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 @@ -1846,6 +1846,7 @@ vaos:
api_url: "https://api.wellhive.com"
base_path: "care-navigation/v1"
scopes: "care-nav"
fake_patient_id: "fake_patient_id"

accredited_representative_portal:
pilot_users_email_poa_codes: ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def create_params
)
end
end

# rubocop:enable Metrics/MethodLength

def start_date
Expand Down
60 changes: 55 additions & 5 deletions modules/vaos/app/services/vaos/v2/appointments_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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,

Check failure on line 73 in modules/vaos/app/services/vaos/v2/appointments_service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
MAP::SecurityToken::Errors::MissingICNError => e

Check failure on line 74 in modules/vaos/app/services/vaos/v2/appointments_service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
{
data: {},
meta: pagination(pagination_params).merge({
Expand Down Expand Up @@ -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)

Check failure on line 106 in modules/vaos/app/services/vaos/v2/appointments_service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/MultilineOperationIndentation: Align the operands of a condition in an `if` statement spanning multiple lines.
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

Check failure on line 113 in modules/vaos/app/services/vaos/v2/appointments_service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/MultilineOperationIndentation: Align the operands of a condition in an `if` statement spanning multiple lines.
modify_desired_date(request_object_body, get_facility_timezone(request_object_body[:location_id]))
end

Expand All @@ -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)

Check failure on line 134 in modules/vaos/app/services/vaos/v2/appointments_service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/MultilineOperationIndentation: Align the operands of a condition in an `if` statement spanning multiple lines.
update_appointment_vpg(appt_id, status)
get_appointment(appt_id)
else
Expand Down Expand Up @@ -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
Copy link
Contributor

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


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 +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:
Expand Down Expand Up @@ -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
Loading