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 all 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 @@ -1860,6 +1860,7 @@ vaos:
api_url: "https://api.wellhive.com"
base_path: "care-navigation/v1"
scopes: "care-nav"
fake_patient_id: "fake_patient_id"

ogc:
form21a_service_url:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

module VAOS
module V2
class EpsAppointmentSerializer
def serialize(appt)
{
id: appt[:id].to_s,
status: appt[:state] == 'booked',
patientIcn: appt[:patientId],
created: appt.dig(:appointmentDetails, :lastRetrieved),
requestedPeriods: prepare_requested_periods(appt[:appointmentDetails]),
locationId: appt[:locationId],
clinic: appt[:clinic],
start: appt[:start],
contact: appt[:contact],
referralID: appt.dig(:referral, :referralNumber),
referral: {
referralNumber: appt.dig(:referral, :referralNumber).to_s
}
}.compact
end

private

def prepare_requested_periods(details)
[
{
start: details[:start]
}
].compact
end

def calculate_end_time(start_time)
return nil unless start_time

Time.zone.parse(start_time) + 60.minutes
end
end
end
end
29 changes: 29 additions & 0 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 @@ def get_appointments(start_date, end_date, statuses = nil, pagination_params = {
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 Down Expand Up @@ -205,6 +210,15 @@ def get_facility_timezone_memoized(facility_location_id)
facility_info[:timezone]&.[](:time_zone_id)
end

def merge_appointments(eps_appointments, appointments)
normalized_new = eps_appointments.map { |appt| eps_serializer.serialize(appt) }
existing_ids = appointments.to_set { |a| a.dig(:referral, :referralNumber) }
merged_data = appointments + normalized_new.reject do |a|
existing_ids.include?(a.dig(:referral, :referralNumber))
end
merged_data.sort_by { |appt| appt[:start] || '' }
end

memoize :get_facility_timezone_memoized

private
Expand Down Expand Up @@ -235,6 +249,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 Expand Up @@ -902,6 +917,20 @@ def validate_response_schema(response, contract_name)

SchemaContract::ValidationInitiator.call(user:, response:, contract_name:)
end

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

def eps_appointments
@eps_appointments ||=
eps_appointments_service.get_appointments
end

def eps_serializer
@eps_serializer ||= VAOS::V2::EpsAppointmentSerializer.new
end
end
end
end
73 changes: 73 additions & 0 deletions modules/vaos/spec/services/v2/appointment_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,65 @@

let(:provider_name) { 'TEST PROVIDER NAME' }

let(:eps_appointments) do
[
{
id: 123,
state: 'submitted',
patientId: '456',
start: '2024-12-01T10:00:00Z',
appointmentDetails: {
lastRetrieved: '2024-12-01T10:00:00Z',
start: '2024-12-01T10:00:00Z'
},
locationId: '789',
clinic: 'Clinic A',
contact: '123-456-7890',
referral: {
referralNumber: 'ref123'
},
status: 'booked',
created: '2024-11-01T10:00:00Z'
},
{
id: 124,
state: 'proposed',
patientId: '457',
start: '2024-12-02T10:00:00Z',
appointmentDetails: {
lastRetrieved: '2024-12-02T10:00:00Z',
start: '2024-12-02T10:00:00Z'
},
locationId: '790',
clinic: 'Clinic B',
contact: '123-456-7891',
referral: {
referralNumber: 'ref124'
},
status: 'booked',
created: '2024-12-01T10:00:00Z'
},
{
id: 125,
state: 'submitted',
patientId: '458',
start: '2024-12-03T10:00:00Z',
appointmentDetails: {
lastRetrieved: '2024-12-03T10:00:00Z',
start: '2024-12-03T10:00:00Z'
},
locationId: '791',
clinic: 'Clinic C',
contact: '123-456-7892',
referral: {
referralNumber: 'ref125'
},
status: 'booked',
created: '2024-11-01T10:00:00Z'
}
]
end

mock_facility = {
test: 'test',
timezone: {
Expand Down Expand Up @@ -1052,6 +1111,20 @@
end
end

describe '#get_appointments merge' do
context 'when include eps is true' do
it 'merges eps appointments with vaos appointments' do
VCR.use_cassette('vaos/eps/get_appointments_200_with_merge',
match_requests_on: %i[method path query], allow_playback_repeats: true, tag: :force_utf8) do
allow_any_instance_of(Eps::AppointmentService).to receive(:get_appointments).and_return(eps_appointments)
result = subject.get_appointments(start_date, end_date, nil, {}, { eps: true })
expect(result[:data].map { |appt| appt.dig(:referral, :referralNumber) }).to include('ref124', 'ref125')
expect(result[:data].map { |appt| appt[:id].to_s }).to include('101', '102')
end
end
end
end

describe '#convert_appointment_time' do
let(:manila_appt) do
{
Expand Down
Loading
Loading