Skip to content

Commit b66970c

Browse files
committed
Iterate over multiple appointments in clinic booking journey
Still need to do the same for the health questions, but there are other missing pieces of the puzzle to address before I can get that working.
1 parent 3fe73a4 commit b66970c

2 files changed

Lines changed: 78 additions & 44 deletions

File tree

app/controllers/book-into-a-clinic.js

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import _ from 'lodash'
44

55
import { ParentalRelationship, SessionPresets } from '../enums.js'
66
import { ClinicAppointment, ClinicBooking } from '../models.js'
7+
import { getAllAppointmentPaths } from '../utils/clinic-appointment.js'
78
import { kebabToCamelCase } from '../utils/string.js'
89

910
export const bookIntoClinicController = {
@@ -149,50 +150,8 @@ export const bookIntoClinicController = {
149150
[`/${session_preset_slug}`]: {},
150151
[`/${session_preset_slug}/${booking_uuid}/new/child-count`]: {},
151152

152-
// Child journey
153-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/child`]:
154-
{},
155-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/dob`]:
156-
{},
157-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/address`]:
158-
{},
159-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/parental-relationship`]:
160-
{
161-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/parental-responsibility`]:
162-
{
163-
data: 'appointment.parentHasParentalResponsibility',
164-
value: 'false'
165-
}
166-
},
167-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/vaccination-choice`]:
168-
{},
169-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/extra-time`]:
170-
{},
171-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/preferred-location`]:
172-
{
173-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/clinic-location`]:
174-
{
175-
data: 'transaction.preferredLocation',
176-
value: 'NE12 7ET'
177-
}
178-
},
179-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/preferred-location-matches`]:
180-
{
181-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/preferred-location`]:
182-
{
183-
data: 'transaction.preferredLocation',
184-
value: 'retry'
185-
}
186-
},
187-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/clinic-location`]:
188-
{},
189-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/clinic-date`]:
190-
{},
191-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/appointment-time-range`]:
192-
{},
193-
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/appointment-time`]:
194-
{},
195-
// TODO: logic to loop back if more than one appointment
153+
// Appointment journey; once per child
154+
...getAllAppointmentPaths(booking),
196155

197156
// Parent journey
198157
[`/${session_preset_slug}/${booking_uuid}/new/parent`]: {

app/utils/clinic-appointment.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
1+
import { ClinicBooking } from '../models/clinic-booking.js'
2+
13
import { camelToKebabCase } from './string.js'
24

5+
/**
6+
* Get wizard journey paths and forking details for all appointments in the given clinic booking
7+
*
8+
* @param {ClinicBooking} booking - the clinic booking whose appointment journeys we're mapping
9+
* @returns {object} An object containing all relevants page and forks
10+
*/
11+
export const getAllAppointmentPaths = (booking) => {
12+
const booking_uuid = booking.uuid
13+
const session_preset_slug = booking.sessionPreset.slug
14+
15+
const allPaths = booking.appointments_ids.map((appointment_uuid) => {
16+
return {
17+
// Child details
18+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/child`]:
19+
{},
20+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/dob`]:
21+
{},
22+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/address`]:
23+
{},
24+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/parental-relationship`]:
25+
{
26+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/parental-responsibility`]:
27+
{
28+
data: 'appointment.parentHasParentalResponsibility',
29+
value: 'false'
30+
}
31+
},
32+
33+
// Appointment-length influences
34+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/vaccination-choice`]:
35+
{},
36+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/extra-time`]:
37+
{},
38+
39+
// Clinic and slot selection
40+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/preferred-location`]:
41+
{
42+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/clinic-location`]:
43+
{
44+
data: 'transaction.preferredLocation',
45+
value: 'NE12 7ET'
46+
}
47+
},
48+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/preferred-location-matches`]:
49+
{
50+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/preferred-location`]:
51+
{
52+
data: 'transaction.preferredLocation',
53+
value: 'retry'
54+
}
55+
},
56+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/clinic-location`]:
57+
{},
58+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/clinic-date`]:
59+
{},
60+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/appointment-time-range`]:
61+
{},
62+
[`/${session_preset_slug}/${booking_uuid}/new/${appointment_uuid}/appointment-time`]:
63+
{}
64+
}
65+
})
66+
67+
// Merge all the appointments' paths into a single sequence, preserving order
68+
return Object.assign({}, ...allPaths)
69+
}
70+
71+
/**
72+
* Get the path for a single health question
73+
*
74+
* @param {string} key
75+
* @param {string} pathPrefix
76+
* @returns
77+
*/
378
const getHealthQuestionPath = (key, pathPrefix) => {
479
return `${pathPrefix}health-question-${camelToKebabCase(key)}`
580
}

0 commit comments

Comments
 (0)