|
| 1 | +import { ClinicBooking } from '../models/clinic-booking.js' |
| 2 | + |
1 | 3 | import { camelToKebabCase } from './string.js' |
2 | 4 |
|
| 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 | + */ |
3 | 78 | const getHealthQuestionPath = (key, pathPrefix) => { |
4 | 79 | return `${pathPrefix}health-question-${camelToKebabCase(key)}` |
5 | 80 | } |
|
0 commit comments