Skip to content

Commit 288e640

Browse files
107600 update eps appt show endpoint response (#21780)
* update model to include is_latest and last_retrieved attrs * update eps appts serializer as per requested format and content from FE * update eps appt show endpoint needed to pass referral object into the serializer * remove old model no longer needed * rubocop fixes * update model to take additional parameters to ingest and expose attributes for serialization * update serializer to utilize updated object paremeter now wrapped by singular model * update controller to utilize updated appointment model and serializer * revert var names to cut down on LOC * re-add model and spec to cut down on LOC, will remove in separate PR * rubocop fix * update req spec * revert var names to cut down on LOC * remove comment * revert changes for LOC, will clean up in separate pr
1 parent 204222d commit 288e640

File tree

5 files changed

+233
-286
lines changed

5 files changed

+233
-286
lines changed

modules/vaos/app/controllers/vaos/v2/eps_appointments_controller.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,29 @@ def show
1111

1212
raise Common::Exceptions::RecordNotFound, message: 'Record not found' if appointment[:state] == 'draft'
1313

14-
referral_detail = fetch_referral_detail(appointment)
15-
provider = fetch_provider(appointment)
16-
enriched_provider = Eps::EnrichedProvider.from_referral(provider, referral_detail)
17-
18-
response = OpenStruct.new(
19-
id: appointment[:id],
20-
appointment:,
21-
provider: enriched_provider
22-
)
23-
24-
render json: Eps::EpsAppointmentSerializer.new(response)
14+
response_object = assemble_appt_response_object(appointment)
15+
render json: response_object
2516
end
2617

2718
private
2819

20+
##
21+
# Assembles a structured response object for an EPS appointment by:
22+
# 1. Fetching referral details if a referral number exists
23+
# 2. Fetching provider information if a provider service ID exists
24+
# 3. Creating a comprehensive EpsAppointment object with all related data
25+
# 4. Serializing the appointment object
26+
#
27+
# @param appointment_data [Hash] Raw appointment data from the EPS service
28+
# @return [Eps::EpsAppointmentSerializer] Serialized appointment with referral and provider data
29+
def assemble_appt_response_object(appointment_data)
30+
referral_detail = fetch_referral_detail(appointment_data)
31+
provider = fetch_provider(appointment_data)
32+
eps_appointment = VAOS::V2::EpsAppointment.new(appointment_data, referral_detail, provider)
33+
34+
Eps::EpsAppointmentSerializer.new(eps_appointment)
35+
end
36+
2937
##
3038
# Retrieves referral details from CCRA service for the given appointment if a referral number is present.
3139
#

modules/vaos/app/models/vaos/v2/eps_appointment.rb

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,34 @@
33
module VAOS
44
module V2
55
class EpsAppointment
6-
def initialize(params = {})
7-
appointment_details = params[:appointment_details]
8-
referral_details = params[:referral]
6+
attr_reader :id, :status, :patient_icn, :created, :location_id, :clinic,
7+
:start, :is_latest, :last_retrieved, :contact, :referral_id,
8+
:referral, :provider_service_id, :provider_name,
9+
:provider, :type_of_care, :referral_phone_number
910

10-
@id = params[:id]&.to_s
11-
@status = appointment_details[:status]
12-
@patient_icn = params[:patient_id]
11+
def initialize(appointment_data = {}, referral_detail = nil, provider = nil)
12+
appointment_details = appointment_data[:appointment_details]
13+
referral_details = appointment_data[:referral]
14+
15+
@id = appointment_data[:id]&.to_s
16+
@status = determine_status(appointment_details[:status])
17+
@patient_icn = appointment_data[:patient_id]
1318
@created = appointment_details[:last_retrieved]
14-
@location_id = params[:network_id]
15-
@clinic = params[:provider_service_id]
16-
@start = params.dig(:appointment_details, :start)
17-
@contact = params[:contact]
19+
@location_id = appointment_data[:network_id]
20+
@clinic = appointment_data[:provider_service_id]
21+
@start = appointment_data.dig(:appointment_details, :start)
22+
@is_latest = appointment_data.dig(:appointment_details, :is_latest)
23+
@last_retrieved = appointment_data.dig(:appointment_details, :last_retrieved)
24+
@contact = appointment_data[:contact]
1825
@referral_id = referral_details[:referral_number]
1926
@referral = { referral_number: referral_details[:referral_number]&.to_s }
20-
@provider_service_id = params[:provider_service_id]
21-
@provider_name = params.dig(:provider, :name).presence || 'unknown'
27+
@provider_service_id = appointment_data[:provider_service_id]
28+
@provider_name = appointment_data.dig(:provider, :name).presence || 'unknown'
29+
30+
@type_of_care = referral_detail&.category_of_care
31+
@referral_phone_number = referral_detail&.phone_number
32+
33+
@provider = provider
2234
end
2335

2436
def serializable_hash
@@ -38,6 +50,21 @@ def serializable_hash
3850
}.compact
3951
end
4052

53+
# Provide proper encapsulation of provider data
54+
def provider_details
55+
return nil if provider.nil?
56+
57+
{
58+
id: provider.id,
59+
name: provider.name,
60+
is_active: provider.is_active,
61+
organization: provider.provider_organization,
62+
location: provider.location,
63+
network_ids: provider.network_ids,
64+
phone_number: referral_phone_number
65+
}.compact
66+
end
67+
4168
private
4269

4370
def determine_status(status)

modules/vaos/app/serializers/eps/eps_appointment_serializer.rb

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,25 @@ module Eps
44
class EpsAppointmentSerializer
55
include JSONAPI::Serializer
66

7-
attribute :appointment do |object|
8-
next if object.appointment.nil?
7+
attribute :id, &:id
98

10-
VAOS::V2::EpsAppointment.new(object.appointment).serializable_hash
11-
end
9+
attribute :status, &:status
10+
11+
attribute :start, &:start
12+
13+
attribute :type_of_care, &:type_of_care
1214

13-
attribute :provider do |object|
14-
next if object.provider.nil?
15-
16-
{
17-
id: object.provider.id,
18-
name: object.provider.name,
19-
is_active: object.provider.is_active,
20-
individual_providers: object.provider.individual_providers,
21-
provider_organization: object.provider.provider_organization,
22-
location: object.provider.location,
23-
network_ids: object.provider.network_ids,
24-
scheduling_notes: object.provider.scheduling_notes,
25-
appointment_types: object.provider.appointment_types,
26-
specialties: object.provider.specialties,
27-
visit_mode: object.provider.visit_mode,
28-
features: object.provider.features,
29-
phone_number: object.provider.phone_number
30-
}.compact
15+
attribute :is_latest, &:is_latest
16+
17+
attribute :last_retrieved, &:last_retrieved
18+
19+
attribute :modality do |_object|
20+
# NOTE: this is intentionally hardcoded for now for prototype,
21+
# will be updated once confirmed that the data will be available
22+
# from the referral object
23+
'OV'
3124
end
25+
26+
attribute :provider, &:provider_details
3227
end
3328
end

modules/vaos/spec/requests/vaos/v2/eps_appointments_spec.rb

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,57 +42,26 @@
4242
'id' => 'qdm61cJ5',
4343
'type' => 'eps_appointment',
4444
'attributes' => {
45-
'appointment' => {
46-
'id' => 'qdm61cJ5',
47-
'status' => 'booked',
48-
'patientIcn' => 'care-nav-patient-casey',
49-
'created' => '2025-02-10T14:35:44Z',
50-
'locationId' => 'sandbox-network-5vuTac8v',
51-
'clinic' => 'Aq7wgAux',
52-
'start' => '2024-11-21T18:00:00Z',
53-
'referralId' => '12345',
54-
'referral' => { 'referralNumber' => '12345' },
55-
'providerServiceId' => 'Aq7wgAux',
56-
'providerName' => 'unknown'
57-
},
45+
'id' => 'qdm61cJ5',
46+
'status' => 'booked',
47+
'start' => '2024-11-21T18:00:00Z',
48+
'typeOfCare' => nil,
49+
'isLatest' => true,
50+
'lastRetrieved' => '2025-02-10T14:35:44Z',
51+
'modality' => 'OV',
5852
'provider' => {
5953
'id' => 'test-provider-id',
6054
'name' => 'Timothy Bob',
6155
'isActive' => true,
62-
'individualProviders' => [
63-
{
64-
'name' => 'Timothy Bob', 'npi' => 'test-npi'
65-
}
66-
],
67-
'providerOrganization' => {
68-
'name' => 'test-provider-org-name'
69-
},
56+
'organization' => { 'name' => 'test-provider-org-name' },
7057
'location' => {
7158
'name' => 'Test Medical Complex',
7259
'address' => '207 Davishill Ln',
7360
'latitude' => 33.058736,
7461
'longitude' => -80.032819,
7562
'timezone' => 'America/New_York'
7663
},
77-
'networkIds' => [
78-
'sandbox-network-test'
79-
],
80-
'schedulingNotes' => 'New patients need to send their previous records to the office prior to their' \
81-
' appt.',
82-
'appointmentTypes' => [
83-
{
84-
'id' => 'off',
85-
'name' => 'Office Visit',
86-
'isSelfSchedulable' => true
87-
}
88-
],
89-
'specialties' => [
90-
{
91-
'id' => 'test-id',
92-
'name' => 'Urology'
93-
}
94-
],
95-
'visitMode' => 'phone'
64+
'networkIds' => ['sandbox-network-test']
9665
}
9766
}
9867
}

0 commit comments

Comments
 (0)