Skip to content

Commit 0f8157c

Browse files
authored
Clinic setup pt2 (#246)
Main changes are: * Added all clinic locations to the default team * Switch between radios and autocomplete depending on number of clinic locations * Various bug fixes and robustness measures Squashed commit messages: * Fix "undefined" in clinic session page's caption Was trying to show the year groups, but that's a school session only thing. * Use autocomplete for clinic selection with many clinics Use radio buttons with 16 or fewer clinics, or the autocomplete search field over that. * Give the 'default' clinic a specific name and address * Give the Coventry team all of its clinic locations Now that we let the user choose a location, we're fine to show all of them. * Reduce the number of faked clinic bookings to keep on top of memory issues. * Improve the content on the vaccination periods page * Make clinic setup robust to lack of date entry Previously, the lack of a date would cause the recording of session start and end times to fail, as the Date object we wanted to create was invalid with only times in it. * If vaccinator counts are consistent, simplify check-answers * Take the MMR consent comms question out of clinics * Content refinements for the vaccination-periods page. As suggested by EmmaH-F.
1 parent f8e603e commit 0f8157c

10 files changed

Lines changed: 98 additions & 38 deletions

File tree

app/controllers/session.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import {
2424
Session,
2525
Team
2626
} from '../models.js'
27-
import { getDateValueDifference } from '../utils/date.js'
27+
import {
28+
convertIsoDateToObject,
29+
getDateValueDifference,
30+
today
31+
} from '../utils/date.js'
2832
import { getResults, getPagination } from '../utils/pagination.js'
2933
import { getSessionYearGroups } from '../utils/session.js'
3034
import { formatYearGroup } from '../utils/string.js'
@@ -563,7 +567,8 @@ export const sessionController = {
563567
[`/${session_id}/${type}/appointment-length`]: {}
564568
}),
565569
//[`/${session_id}/${type}/date-check`]: {},
566-
...(session.presetNames?.includes(SessionPresetName.MMR)
570+
...(session.presetNames?.includes(SessionPresetName.MMR) &&
571+
session.type === SessionType.School
567572
? {
568573
[`/${session_id}/${type}/mmr-consent`]: {}
569574
}
@@ -587,17 +592,28 @@ export const sessionController = {
587592
response.locals.paths.next =
588593
response.locals.paths.next || `${session.uri}/new/check-answers`
589594

590-
response.locals.clinicIdItems = Object.values(team.clinics)
591-
.map((clinic) => new Clinic(clinic))
592-
.map((clinic) => ({
593-
text: clinic.name,
594-
value: clinic.id,
595-
...(clinic.address && {
596-
attributes: {
597-
'data-hint': clinic.formatted.address
598-
}
599-
})
600-
}))
595+
// Set up different methods for clinic selection, based on number of clinics
596+
if (session.type === SessionType.Clinic) {
597+
const usableNumberOfRadios = 16
598+
if (team.clinics.length <= usableNumberOfRadios) {
599+
response.locals.clinicRadios = Object.values(team.clinics)
600+
.map((clinic) => new Clinic(clinic))
601+
.map((clinic) => ({
602+
text: clinic.name,
603+
value: clinic.id,
604+
...(clinic.address && {
605+
attributes: {
606+
'data-hint': clinic.formatted.address
607+
},
608+
hint: {
609+
text: clinic.formatted.address
610+
}
611+
})
612+
}))
613+
} else {
614+
response.locals.clinics = Clinic.findAll(data)
615+
}
616+
}
601617

602618
if (session.type === SessionType.School) {
603619
const schools = School.findAll(data)
@@ -667,11 +683,14 @@ export const sessionController = {
667683
for (const [period_id, vaccinationPeriod] of Object.entries(
668684
request.body.vaccinationPeriods
669685
)) {
686+
const sessionDate_ = session.date
687+
? session.date_
688+
: convertIsoDateToObject(today())
670689
ClinicVaccinationPeriod.update(
671690
period_id,
672691
_.merge(
673-
// make sure we keep up to date with the session date
674-
{ startAt_: session.date_, endAt_: session.date_ },
692+
// make sure the period start and end have date information as well as time
693+
{ startAt_: { ...sessionDate_ }, endAt_: { ...sessionDate_ } },
675694
vaccinationPeriod
676695
),
677696
data.wizard

app/datasets/clinics.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,10 @@ export default {
439439
},
440440
X99999: {
441441
id: 'X99999',
442-
name: 'Community clinic',
443-
addressLevel1: 'Coventry',
442+
name: 'The Kenilworth Centre',
443+
addressLine1: 'Abbey End',
444+
addressLevel1: 'Kenilworth',
445+
postalCode: 'CV8 1QJ',
444446
team_id: '001',
445447
presetNames
446448
}

app/datasets/teams.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import clinics from './clinics.js'
12
import schools from './schools.js'
23

34
export default [
@@ -9,7 +10,9 @@ export default [
910
tel: '01632 960000',
1011
privacyPolicyUrl: 'https://www.covwarkpt.nhs.uk/download.cfm?ver=8286',
1112
password: 'secret',
12-
clinic_ids: ['X99999'],
13+
clinic_ids: Object.values(clinics)
14+
.filter((clinic) => clinic.team_id == '001')
15+
.map((clinic) => clinic.id),
1316
school_ids: Object.keys(schools)
1417
}
1518
]

app/locales/en.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,11 +2186,15 @@ export const en = {
21862186
title: 'Which year groups do you want to invite to this session?'
21872187
},
21882188
clinic: {
2189-
label: 'Clinic',
2190-
title: 'Where is this community clinic taking place?'
2189+
label: 'Clinic location',
2190+
title: 'Where is this community clinic taking place?',
2191+
search: {
2192+
label: 'Select a clinic location'
2193+
}
21912194
},
21922195
vaccinationPeriods: {
21932196
title: 'When will the session start and end?',
2197+
hint: 'Parents will be able to book appointments between these times.',
21942198
label: 'Vaccination period(s)',
21952199
period: {
21962200
title: 'Vaccination period %d',
@@ -2208,7 +2212,7 @@ export const en = {
22082212
},
22092213
addPeriod: {
22102214
description:
2211-
'Adding multiple vaccination periods will allow you to schedule breaks and to vary staffing levels across the session.',
2215+
'Adding more than one time period allows you to schedule breaks and vary staffing levels across the session.',
22122216
label: 'Add another period'
22132217
}
22142218
},

app/models/clinic.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ export class Clinic extends Location {
2323
return `/teams/${this.team_id}/clinics/${this.id}`
2424
}
2525

26+
/**
27+
* Find all
28+
*
29+
* @param {object} context - Context
30+
* @returns {Array<Clinic>|undefined} All clinics on the context
31+
* @static
32+
*/
33+
static findAll(context) {
34+
return Object.values(context.clinics).map(
35+
(clinic) => new Clinic(clinic, context)
36+
)
37+
}
38+
2639
/**
2740
* Find one
2841
*

app/views/session/form/check-answers.njk

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
session won't find them on its global context
5757
#}
5858
{% set startAndEndTimes = "" %}
59-
{% set vaccinatorCount = vaccinationPeriods[0].vaccinatorCount if vaccinationPeriods.length === 1 else "" %}
59+
{% set vaccinatorCounts = "" %}
60+
{% set lastVaccinatorCount = -1 %}
61+
{% set hasVariableVaccinatorCounts = false %}
6062
{% set totalSlots = 0 %}
6163
{% for vaccinationPeriod in vaccinationPeriods %}
6264
{% set thisPeriod = __("session.vaccinators.input.singlePeriodLabel", {
@@ -71,10 +73,15 @@
7173

7274
{% set totalSlots = totalSlots + vaccinationPeriod.appointmentCount(session.appointmentLength) %}
7375

74-
{% if vaccinationPeriods.length > 1 %}
75-
{% set vaccinatorCount = vaccinatorCount + vaccinationPeriod.vaccinatorCount + " from " + thisPeriod + "<br>" %}
76+
{% set vaccinatorCounts = vaccinatorCounts + vaccinationPeriod.vaccinatorCount + " from " + thisPeriod + "<br>" %}
77+
{% if lastVaccinatorCount !== -1 and lastVaccinatorCount !== vaccinationPeriod.vaccinatorCount %}
78+
{% set hasVariableVaccinatorCounts = true %}
7679
{% endif %}
80+
{% set lastVaccinatorCount = vaccinationPeriod.vaccinatorCount %}
7781
{% endfor %}
82+
{% if not hasVariableVaccinatorCounts %}
83+
{% set vaccinatorCounts = lastVaccinatorCount %}
84+
{% endif %}
7885

7986
{{ summaryList({
8087
card: {
@@ -103,7 +110,7 @@
103110
},
104111
vaccinators: {
105112
href: session.uri + "/new/vaccinators",
106-
value: vaccinatorCount
113+
value: vaccinatorCounts
107114
},
108115
appointmentLength: {
109116
href: session.uri + "/new/appointment-length"

app/views/session/form/clinic.njk

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
{% set title = __("session.clinic.title") %}
44

55
{% block form %}
6-
{{ radios({
7-
fieldset: {
8-
legend: {
9-
isPageHeading: true,
10-
text: title,
11-
size: "l"
6+
{{ appHeading({
7+
title: title
8+
}) }}
9+
10+
{% if clinicRadios %}
11+
{{ radios({
12+
items: clinicRadios,
13+
decorate: "session.clinic_id"
14+
})}}
15+
{% else %}
16+
{{ select({
17+
label: { text: __("session.clinic.search.label") },
18+
items: locationItems(clinics, session.clinic_id),
19+
decorate: "session.clinic_id",
20+
attributes: {
21+
"data-module": "app-autocomplete"
1222
}
13-
},
14-
items: clinicIdItems,
15-
decorate: "session.clinic_id"
16-
})}}
23+
}) }}
24+
{% endif %}
1725
{% endblock %}

app/views/session/form/vaccination-periods.njk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
{% block form %}
77
{{ appHeading({
88
title: title
9-
})}}
9+
}) }}
1010

11+
{{ __("session.vaccinationPeriods.hint") | nhsukMarkdown }}
12+
1113
{% for vaccinationPeriod in vaccinationPeriods %}
1214
{% call fieldset({
1315
legend: {

app/views/session/show.njk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
{% set title = session.shortName %}
44
{% set heading = title %}
5-
{% set caption = session.formatted.date + "" + session.formatted.yearGroups %}
5+
{% set caption = session.formatted.date
6+
+ ("" + session.formatted.yearGroups if session.type === SessionType.School)
7+
%}
68

79
{% block content %}
810
{{ warningCallout({

lib/create-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import { generateDataFile } from './generate-data-file.js'
7070
const totalUsers = Number(process.env.USERS) || 20
7171
const totalTeams = Number(process.env.TEAMS) || 5
7272
const totalBatches = Number(process.env.BATCHES) || 100
73-
const totalClinicBookings = Number(process.env.CLINIC_BOOKINGS) || 20
73+
const totalClinicBookings = Number(process.env.CLINIC_BOOKINGS) || 10
7474
const totalPatients = Number(process.env.RECORDS) || 4000
7575

7676
// Context

0 commit comments

Comments
 (0)