Skip to content

Commit 758603b

Browse files
Update lists interface (#486)
This updates the Lists interface so that you're now asked which date the list is for, but if you select 'No date' then you're asked to give the list a name instead. The interface is now a bit more 'working' so that it can be tested. --------- Co-authored-by: Frankie Roberto <[email protected]>
1 parent 9e26ff6 commit 758603b

30 files changed

+732
-2309
lines changed

app/data/session-data-defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
users: users,
1212
vaccines: vaccines,
1313
vaccineStock: [],
14+
lists: [],
1415
nhsNumberKnown: "yes",
1516
currentUserId: "2387441662601",
1617
currentOrganisationId: "RW3",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Returns a date object from a valid year, month, and day.
2+
// Note: inputs can be strings, and month is based on 1 = Jan
3+
// rather than 0 = Jan
4+
// Time is set to midday
5+
6+
/**
7+
* Returns a date object from a valid year, month, and day.
8+
*
9+
* Note: inputs can be strings, and month is based on 1 = Jan
10+
* rather than 0 = Jan
11+
*
12+
* @param {String | Int} year - The year as a string or number
13+
* @param {String | Int} month - The month as a string or number
14+
* @param {String | Int} day - The day as a string or number
15+
* @returns {*} Either a valid Date object or null
16+
*/
17+
function dateFromYearMonthDay(year, month, day) {
18+
const yearInt = parseInt(year)
19+
const monthInt = parseInt(month)
20+
const dayInt = parseInt(day)
21+
22+
if (yearInt > 0 && monthInt > 0 && dayInt > 0) {
23+
return new Date(yearInt, (monthInt - 1), dayInt, 12)
24+
} else {
25+
return null
26+
}
27+
}
28+
29+
module.exports.dateFromYearMonthDay = dateFromYearMonthDay
30+

app/routes/lists.js

Lines changed: 258 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,277 @@
1+
const { randomItem } = require('../lib/utils/random-item.js')
2+
const { dateFromYearMonthDay } = require('../lib/utils/date-from-year-month-day.js')
3+
4+
15
module.exports = router => {
26

7+
const listOfFirstNames = ["Scott", "Siera", "Ramsey", "Blair", "Gretchen", "Kelli", "Sheridan", "Anya", "Alexis", "Kegan", "Jamia", "Sunny", "Haley", "Elsa", "Ayanna", "Chiara", "Zander", "Oswaldo", "Paris", "Bennett", "Reyna", "Camryn", "Nehemiah", "Craig", "Jalil", "Derick", "Easton", "Mohammed", "Arnold", "Linnea", "Edna", "Cameron", "Gissell", "Melina", "Annalise", "Jalin", "Aric", "Kentrell", "Nyla", "Leslie", "Maranda", "Kinley", "Montana", "Britney", "Uriah", "Raul", "Vincent", "Dustin", "Grant", "Kia"]
8+
9+
const listOfLastNames = ["Menendez", "Salisbury", "Mateo", "Alarcon", "Lenz", "Potter", "Kramer", "Trevino", "Singleton", "Batchelor", "Witte", "Rhoades", "Barragan", "Watson", "Fiore", "Beattie", "Parr", "Traylor", "Gillette", "Kim", "Fennell", "Eubanks", "Ko", "Mcfarlane", "Waite", "Gaines", "Rosado", "Rao", "Bynum", "Wentz", "Cheng", "Loera", "Hyman", "Ferrell", "Nixon", "Pierre", "Strand", "Wirth", "Delagarza", "Dixon", "Yoon", "Hines", "Hinds", "Barron", "Bruce", "Pease", "Rhodes", "Doss", "Marsh", "France"]
310

411
router.get('/lists', (req, res) => {
12+
const data = req.session.data
13+
const currentOrganisation = res.locals.currentOrganisation
14+
const lists = data.lists.filter((list) => list.organisationId === currentOrganisation.id)
515

6-
const currentOrganisation = res.locals.currentOrganisation;
7-
const lists = currentOrganisation.lists || []
16+
const vaccinesAdded = data.vaccineStock.length
17+
18+
if (vaccinesAdded === 0) { return res.render('lists/no-vaccines-added') }
19+
if (lists.length === 0) { return res.render('lists/no-lists-created') }
20+
21+
const listSiteIds = [...new Set(lists.map((list) => list.siteId))]
22+
const sites = currentOrganisation.sites.filter((site) => listSiteIds.includes(site.id))
823

924
res.render('lists/index', {
10-
lists
25+
sites
26+
})
27+
28+
})
29+
30+
router.get('/lists/site/:siteId', (req, res) => {
31+
const currentOrganisation = res.locals.currentOrganisation
32+
const siteId = req.params.siteId
33+
const site = currentOrganisation.sites.find((site) => site.id === siteId)
34+
const lists = req.session.data.lists.filter((list) => list.organisationId === currentOrganisation.id).filter((list) => list.siteId === siteId)
35+
36+
let justAddedList = null
37+
if (req.query.justAddedId) {
38+
justAddedList = req.session.data.lists.find((list) => list.id == req.query.justAddedId)
39+
}
40+
41+
res.render('lists/team-lists', {
42+
lists,
43+
site,
44+
justAddedList
45+
})
46+
})
47+
48+
router.get('/lists/team', (req, res) => {
49+
const data = req.session.data
50+
let sites = res.locals.currentOrganisation.sites || []
51+
52+
const vaccineStock = data.vaccineStock
53+
const siteIdsWithVaccines = [...new Set(vaccineStock.map((vaccineAdded) => vaccineAdded.siteId))]
54+
55+
sites = sites.filter((site) => siteIdsWithVaccines.includes(site.id))
56+
57+
res.render('lists/team', {
58+
sites
59+
})
60+
61+
})
62+
63+
router.get('/lists/date', (req, res) => {
64+
const today = new Date()
65+
const day = 86400000 // number of milliseconds in a day
66+
const daysToInclude = 5
67+
68+
let dates = []
69+
70+
for (let i = 0; i < daysToInclude; i++) {
71+
let date = new Date(today.getTime() - (i * day))
72+
73+
dates.push(date.toISOString().substring(0,10))
74+
}
75+
76+
res.render('lists/date', {
77+
dates
1178
})
1279

1380
})
1481

15-
router.post('/lists/add-numbers', (req, res) => {
82+
router.post('/lists/date-answer', (req, res) => {
83+
const date = req.session.data.date
84+
85+
if (date === '') {
86+
87+
res.redirect('/lists/name')
88+
89+
} else {
90+
91+
res.redirect('/lists/add-nhs-numbers')
92+
93+
}
94+
})
95+
96+
router.post('/lists/create', (req, res) => {
97+
const data = req.session.data
98+
const currentOrganisation = res.locals.currentOrganisation
1699

17-
const currentOrganisation = res.locals.currentOrganisation;
18-
currentOrganisation.lists ||= []
100+
const date = data.date
101+
const otherDate = data.otherDate
102+
const name = data.name
103+
const siteId = data.siteId
104+
const nhsNumbers = data.nhsNumbers.split(/\n/)
105+
const id = Math.floor(Math.random() * 10000000).toString()
19106

20-
// This bit isn’t working yet so faked for now.
21-
currentOrganisation.lists.push({
22-
siteCode: "TODO"
107+
// Only 1 of these is set
108+
let listDate, listName
109+
110+
if (date === "") {
111+
// Name based list
112+
listDate = null
113+
listName = name
114+
} else {
115+
// Date based list
116+
listName = null
117+
118+
if (date === "other-date") {
119+
listDate = dateFromYearMonthDay(otherDate.year, otherDate.month, otherDate.day).toISOString().substring(0,10)
120+
} else {
121+
listDate = date
122+
}
123+
}
124+
125+
const patients = nhsNumbers.map(function(nhsNumber) {
126+
return {
127+
nhsNumber: nhsNumber,
128+
firstName: randomItem(listOfFirstNames),
129+
lastName: randomItem(listOfLastNames),
130+
dateOfBirth: "1945-01-18"
131+
}
132+
})
133+
134+
data.lists.push({
135+
id: id,
136+
organisationId: currentOrganisation.id,
137+
siteId: siteId,
138+
date: listDate,
139+
name: listName,
140+
patients: patients
23141
})
24142

25-
res.redirect('/lists/list')
143+
// reset values
144+
data.date = null
145+
data.otherDate = null
146+
data.name = null
147+
data.nhsNumbers = null
148+
149+
res.redirect(`/lists/site/${siteId}?justAddedId=${id}`)
26150

27151
})
28152

153+
router.get('/lists/list/:id', (req, res) => {
154+
const data = req.session.data
155+
const id = req.params.id
156+
const q = req.query.q
157+
const patientList = data.lists.find((list) => list.id === id)
158+
159+
if (!patientList) { return res.redirect('/lists') }
160+
161+
const totalPatients = patientList.patients.length
162+
163+
let patients = patientList.patients
164+
165+
if (q && q !== "") {
166+
167+
patients = patients.filter(function(patient) {
168+
return (
169+
patient.firstName.toLowerCase().startsWith(q.toLowerCase()) ||
170+
patient.lastName.toLowerCase().startsWith(q.toLowerCase()) ||
171+
(patient.firstName + " " + patient.lastName).toLowerCase().startsWith(q.toLowerCase()) ||
172+
patient.nhsNumber === q
173+
)
174+
175+
})
176+
}
177+
178+
res.render('lists/list', {
179+
patientList,
180+
patients,
181+
totalPatients
182+
})
183+
})
184+
185+
router.get('/lists/list/:id/edit-name', (req, res) => {
186+
const data = req.session.data
187+
const id = req.params.id
188+
const patientList = data.lists.find((list) => list.id === id)
189+
190+
if (!patientList) { return res.redirect('/lists') }
191+
192+
res.render('lists/edit-name', {
193+
patientList
194+
})
195+
})
196+
197+
router.post('/lists/:id/update-name', (req, res) => {
198+
const data = req.session.data
199+
const id = req.params.id
200+
const patientList = data.lists.find((list) => list.id === id)
201+
202+
if (!patientList) { return res.redirect('/lists') }
203+
204+
patientList.name = data.name
205+
206+
res.redirect(`/lists/list/${patientList.id}`)
207+
})
208+
209+
router.get('/lists/list/:id/add', (req, res) => {
210+
const data = req.session.data
211+
const id = req.params.id
212+
const patientList = data.lists.find((list) => list.id === id)
213+
214+
if (!patientList) { return res.redirect('/lists') }
215+
216+
res.render('lists/add-more-nhs-numbers', {
217+
patientList
218+
})
219+
})
220+
221+
router.post('/lists/:id/nhs-numbers-added', (req, res) => {
222+
const data = req.session.data
223+
const id = req.params.id
224+
const patientList = data.lists.find((list) => list.id === id)
225+
226+
if (!patientList) { return res.redirect('/lists') }
227+
228+
const nhsNumbers = data.nhsNumbers.split(/\n/)
229+
230+
for (nhsNumber of nhsNumbers) {
231+
patientList.patients.push({
232+
nhsNumber: nhsNumber,
233+
firstName: randomItem(listOfFirstNames),
234+
lastName: randomItem(listOfLastNames),
235+
dateOfBirth: "1945-01-18"
236+
})
237+
}
238+
239+
// reset values
240+
data.date = null
241+
data.otherDate = {}
242+
data.name = null
243+
data.nhsNumbers = null
244+
245+
res.redirect(`/lists/list/${patientList.id}`)
246+
247+
})
248+
249+
router.get('/lists/list/:id/delete', (req, res) => {
250+
const data = req.session.data
251+
const id = req.params.id
252+
const patientList = data.lists.find((list) => list.id === id)
253+
254+
if (!patientList) { return res.redirect('/lists') }
255+
256+
res.render('lists/delete', {
257+
patientList
258+
})
259+
})
260+
261+
router.post('/lists/:id/deleted', (req, res) => {
262+
const data = req.session.data
263+
const id = req.params.id
264+
const patientList = data.lists.find((list) => list.id === id)
265+
const siteId = patientList.siteId
266+
267+
if (!patientList) { return res.redirect('/lists') }
268+
269+
// Remove item from array using 'splice', which takes an index
270+
data.lists.splice(data.lists.indexOf(patientList), 1)
271+
272+
res.redirect(`/lists/site/${siteId}?justDeleted=true`)
273+
274+
})
275+
276+
29277
}

app/views/includes/header-logged-in-organisation.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@
3232
},
3333
{
3434
href: "/record-vaccinations",
35-
text: ("Record vaccinations <span class=\"nhsuk-tag app-tag--header nhsuk-u-margin-left-2\">New</span>") | safe,
35+
text: "Record vaccinations",
3636
active: (currentSection == "vaccinate")
3737
},
38+
{
39+
href: "/lists",
40+
text: ("Lists <span class=\"nhsuk-tag app-tag--header nhsuk-u-margin-left-2\">New</span>") | safe,
41+
active: (currentSection == "lists")
42+
},
3843
{
3944
href: "/vaccines",
4045
text: "Vaccines",
4146
active: (currentSection == "vaccines")
4247
} if (currentUser and (["Lead administrator", "Administrator"] | arrayOrStringIncludes(organisationSetting.permissionLevel))),
4348
{
4449
href: "/records",
45-
html: "Records <span class=\"nhsuk-tag app-tag--header nhsuk-u-margin-left-2\">New</span>" | safe,
50+
text: "Records",
4651
active: (currentSection == "records")
4752
} if (currentUser and (["Lead administrator", "Administrator"] | arrayOrStringIncludes(organisationSetting.permissionLevel))),
4853
{

0 commit comments

Comments
 (0)