Skip to content

Commit 5d9b045

Browse files
Refactor list of all organisations (#539)
A bit of code tidying-up ahead of looking at organisation management stuff.
1 parent fdcfded commit 5d9b045

File tree

14 files changed

+3215
-676
lines changed

14 files changed

+3215
-676
lines changed

app/data/all-organisations.js

Lines changed: 3134 additions & 0 deletions
Large diffs are not rendered by default.

app/data/organisations.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// These are organisations set up as using RAVS
12
module.exports = [
23
{
34
id: "RCF",
@@ -8082,7 +8083,7 @@ module.exports = [
80828083
status: "Closed",
80838084
dateClosed: "2024-12-04",
80848085
type: "NHS Trust",
8085-
region: "Y61"
8086+
region: "Y62"
80868087
},
80878088
{
80888089
id: "RLQ",
@@ -8125,7 +8126,7 @@ module.exports = [
81258126
status: "Closed",
81268127
dateClosed: "2025-02-12",
81278128
type: "NHS Trust",
8128-
region: "Y61"
8129+
region: "Y62"
81298130
},
81308131
{
81318132
id: "RX8",

app/data/session-data-defaults.js

Lines changed: 3 additions & 497 deletions
Large diffs are not rendered by default.

app/routes/apply.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ module.exports = router => {
88
if (error === "no-pharmacy") {
99
errors.push({
1010
text: "Select pharmacy",
11-
href: "#organisation-code"
11+
href: "#organisation-id"
1212
})
1313
} else if (error === "existing-account") {
1414
errors.push({
1515
text: "This pharmacy already has access to the service.",
16-
href: "#organisation-code"
16+
href: "#organisation-id"
1717
})
1818
}
1919

@@ -25,8 +25,8 @@ module.exports = router => {
2525

2626
router.post('/apply/answer-pharmacy', (req, res) => {
2727
const data = req.session.data
28-
const organisationCode = data.organisationCode
29-
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
28+
const organisationId = data.organisationId
29+
const organisation = data.allOrganisations.find((organisation) => organisation.id === organisationId)
3030

3131
if (!organisation) {
3232
res.redirect('/apply/start?error=no-pharmacy');
@@ -36,18 +36,14 @@ module.exports = router => {
3636
res.redirect('/apply/check-pharmacy')
3737
}
3838

39-
res.render('apply/start', {
40-
errors
41-
})
42-
4339
})
4440

4541

4642
// Show organisation check page
4743
router.get('/apply/check-pharmacy', (req, res) => {
4844
const data = req.session.data
49-
const organisationCode = data.organisationCode
50-
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
45+
const organisationId = data.organisationId
46+
const organisation = data.allOrganisations.find((organisation) => organisation.id === organisationId)
5147
if (!organisation) { res.redirect('/apply/start'); return }
5248

5349
res.render('apply/check-pharmacy', {
@@ -58,8 +54,8 @@ module.exports = router => {
5854
// Check your answers page
5955
router.get('/apply/check', (req, res) => {
6056
const data = req.session.data
61-
const organisationCode = data.organisationCode
62-
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
57+
const organisationId = data.organisationId
58+
const organisation = data.allOrganisations.find((organisation) => organisation.id === organisationId)
6359
if (!organisation) { res.redirect('/apply/start'); return }
6460

6561
res.render('apply/check', {
@@ -70,8 +66,8 @@ module.exports = router => {
7066
// Check your email page
7167
router.get('/apply/check-your-email', (req, res) => {
7268
const data = req.session.data
73-
const organisationCode = data.organisationCode
74-
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
69+
const organisationId = data.organisationId
70+
const organisation = data.allOrganisations.find((organisation) => organisation.id === organisationId)
7571

7672
if (!organisation) { res.redirect('/apply/start'); return }
7773

@@ -90,8 +86,8 @@ module.exports = router => {
9086
// Welcome email mockup
9187
router.get('/apply/welcome-email', (req, res) => {
9288
const data = req.session.data
93-
const organisationCode = data.organisationCode
94-
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
89+
const organisationId = data.organisationId
90+
const organisation = data.allOrganisations.find((organisation) => organisation.id === organisationId)
9591
if (!organisation) { res.redirect('/apply/start'); return }
9692

9793
res.render('apply/welcome-email', {

app/routes/record-vaccinations.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,8 @@ module.exports = router => {
811811
let errors = []
812812
let locationType = req.session.data.locationType
813813

814+
const careHomes = req.session.data.allOrganisations.filter((organisation) => organisation.type === "Care home")
815+
814816
if (req.query.showErrors === "yes") {
815817
if (!locationType) {
816818
errors.push({
@@ -821,7 +823,8 @@ module.exports = router => {
821823
}
822824

823825
res.render('record-vaccinations/location', {
824-
errors
826+
errors,
827+
careHomes
825828
})
826829
})
827830

@@ -1089,12 +1092,19 @@ module.exports = router => {
10891092
const data = req.session.data
10901093
const vaccinator = data.users.find((user) => user.id === data.vaccinatorId)
10911094

1095+
let careHome
1096+
10921097
// Get the details of the vaccine product
10931098
const vaccineProduct = data.vaccines.find((vaccine) => vaccine.name === data.vaccine)?.products.find((vaccineProduct) => vaccineProduct.name === data.vaccineProduct)
10941099

1100+
if (data.locationType === "Care home") {
1101+
careHome = data.allOrganisations.find((organisation) => organisation.id === data.careHomeId)
1102+
}
1103+
10951104
res.render('record-vaccinations/check', {
10961105
vaccinator,
1097-
vaccineProduct
1106+
vaccineProduct,
1107+
careHome
10981108
})
10991109
})
11001110

app/routes/regions.js

Lines changed: 27 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = router => {
77

88
const organisations = data.organisations.filter((organisation) => (organisation.region === currentRegion.id) && (["Active", "Invited", "Deactivated"].includes(organisation.status)))
99

10-
const closedOrganisationsCount = data.organisations.filter((organisation) => (organisation.region === "Y61" && organisation.status == "Closed")).length
10+
const closedOrganisationsCount = data.organisations.filter((organisation) => (organisation.region === currentRegion.id && organisation.status == "Closed")).length
1111

1212
res.render('regions/index', {
1313
organisations,
@@ -28,7 +28,7 @@ module.exports = router => {
2828

2929
router.get('/regions/review/:id', (req, res) => {
3030
const data = req.session.data
31-
const organisation = data.organisations.find((org) => org.id === req.params.id)
31+
const organisation = data.allOrganisations.find((org) => org.id === req.params.id)
3232

3333
res.render('regions/organisation-request', {
3434
organisation
@@ -37,7 +37,7 @@ module.exports = router => {
3737

3838
router.get('/regions/accept/:id', (req, res) => {
3939
const data = req.session.data
40-
const organisation = data.organisations.find((org) => org.id === req.params.id)
40+
const organisation = data.allOrganisations.find((org) => org.id === req.params.id)
4141

4242
res.render('regions/accept', {
4343
organisation
@@ -46,49 +46,33 @@ module.exports = router => {
4646

4747
// Inviting an organisation
4848
router.post('/regions/add', (req, res) => {
49+
const data = req.session.data
50+
const currentRegion = res.locals.currentRegion
4951

50-
const organisationCode = req.session.data.organisationCode
51-
const addedUserId = Math.floor(Math.random() * 10000000).toString()
52-
53-
let organisationName, organisationLine1, organisationTown, organisationPostcode, organisationType
52+
const organisationId = data.organisationId
53+
const organisation = data.allOrganisations.find((org) => org.id === organisationId)
5454

55-
if (organisationCode.startsWith('FA')) {
56-
organisationName = req.session.data.nhsPharmacies[organisationCode].name
57-
organisationLine1 = req.session.data.nhsPharmacies[organisationCode].address
58-
organisationTown = req.session.data.nhsPharmacies[organisationCode].town
59-
organisationPostcode = req.session.data.nhsPharmacies[organisationCode].postcode
60-
organisationType = 'Community Pharmacy'
61-
} else {
62-
organisationName = req.session.data.nhsTrusts[organisationCode]
63-
organisationLine1 = 'Cobbett House, Oxford Road'
64-
organisationTown = 'Manchester'
65-
organisationPostcode = 'M13 9WL'
66-
organisationType = 'NHS Trust'
67-
}
55+
const addedUserId = Math.floor(Math.random() * 10000000).toString()
6856

6957
// Add organisation
7058
req.session.data.organisations.push({
71-
id: req.session.data.organisationCode,
72-
name: organisationName,
73-
address: {
74-
line1: organisationLine1,
75-
town: organisationTown,
76-
postcode: organisationPostcode
77-
},
78-
type: organisationType,
59+
id: organisation.id,
60+
name: organisation.name,
61+
address: organisation.address,
62+
type: organisation.type,
7963
status: 'Invited',
80-
region: "Y61"
64+
region: currentRegion.id
8165
})
8266

8367
req.session.data.users.push({
8468
id: addedUserId,
8569
email: req.session.data.email,
8670
status: 'Invited',
87-
firstName: req.session.data.firstName,
88-
lastName: req.session.data.lastName,
71+
firstName: data.firstName,
72+
lastName: data.lastName,
8973
organisations: [
9074
{
91-
id: req.session.data.organisationCode,
75+
id: organisation.id,
9276
status: "Invited",
9377
permissionLevel: "Lead administrator"
9478
}
@@ -97,115 +81,38 @@ module.exports = router => {
9781

9882
// Remove data from adding organisation flow
9983
req.session.data.email = ''
100-
req.session.data.organisationCode = ''
84+
req.session.data.organisationId = ''
10185
req.session.data.firstName = ''
10286
req.session.data.lastName = ''
10387

104-
res.redirect('/regions/organisations/' + organisationCode)
88+
res.redirect('/regions/organisations/' + organisationId)
10589
})
10690

10791
router.get('/regions/organisation-details', (req, res) => {
108-
const organisationCode = req.session.data.organisationCode
109-
110-
let organisationName, organisationLine1, organisationTown, organisationPostcode, organisationType, legallyClosed
111-
112-
if (organisationCode.startsWith('FA')) {
113-
organisationName = req.session.data.nhsPharmacies[organisationCode].name
114-
organisationLine1 = req.session.data.nhsPharmacies[organisationCode].address
115-
organisationTown = req.session.data.nhsPharmacies[organisationCode].town
116-
organisationPostcode = req.session.data.nhsPharmacies[organisationCode].postcode
117-
legallyClosed = req.session.data.nhsPharmacies[organisationCode].legallyClosed
118-
organisationType = 'Community Pharmacy'
119-
} else {
120-
organisationName = req.session.data.nhsTrusts[organisationCode]
121-
legallyClosed = false
122-
organisationLine1 = 'Cobbett House, Oxford Road'
123-
organisationTown = 'Manchester'
124-
organisationPostcode = 'M13 9WL'
125-
organisationType = 'NHS Trust'
126-
}
127-
128-
const organisation = {
129-
code: organisationCode,
130-
name: organisationName,
131-
type: organisationType,
132-
address: {
133-
line1: organisationLine1,
134-
town: organisationTown,
135-
postcode: organisationPostcode
136-
},
137-
legallyClosed: legallyClosed
138-
}
92+
const data = req.session.data
93+
const organisationId = data.organisationId
94+
const organisation = data.allOrganisations.find((organisation) => organisation.id === organisationId)
13995

14096
res.render('regions/organisation-details', {
14197
organisation
14298
})
14399
})
144100

145101
router.get('/regions/add-email', (req, res) => {
146-
const organisationCode = req.session.data.organisationCode
147-
148-
let organisationName, organisationLine1, organisationTown, organisationPostcode, organisationType
149-
150-
if (organisationCode.startsWith('FA')) {
151-
organisationName = req.session.data.nhsPharmacies[organisationCode].name
152-
organisationLine1 = req.session.data.nhsPharmacies[organisationCode].address
153-
organisationTown = req.session.data.nhsPharmacies[organisationCode].town
154-
organisationPostcode = req.session.data.nhsPharmacies[organisationCode].postcode
155-
organisationType = 'Community Pharmacy'
156-
} else {
157-
organisationName = req.session.data.nhsTrusts[organisationCode]
158-
organisationLine1 = 'Cobbett House, Oxford Road'
159-
organisationTown = 'Manchester'
160-
organisationPostcode = 'M13 9WL'
161-
organisationType = 'NHS Trust'
162-
}
163-
164-
const organisation = {
165-
id: organisationCode,
166-
name: organisationName,
167-
type: organisationType,
168-
address: {
169-
line1: organisationLine1,
170-
town: organisationTown,
171-
postcode: organisationPostcode
172-
}
173-
}
102+
const data = req.session.data
103+
const organisationId = data.organisationId
104+
const organisation = data.allOrganisations.find((organisation) => organisation.id === organisationId)
174105

175106
res.render('regions/add-email', {
176107
organisation
177108
})
178109
})
179110

180111
router.get('/regions/check-and-send', (req, res) => {
181-
const organisationCode = req.session.data.organisationCode
182-
183-
let organisationName, organisationLine1, organisationTown, organisationPostcode, organisationType
184-
185-
if (organisationCode.startsWith('FA')) {
186-
organisationName = req.session.data.nhsPharmacies[organisationCode].name
187-
organisationLine1 = req.session.data.nhsPharmacies[organisationCode].address
188-
organisationTown = req.session.data.nhsPharmacies[organisationCode].town
189-
organisationPostcode = req.session.data.nhsPharmacies[organisationCode].postcode
190-
organisationType = 'Community Pharmacy'
191-
} else {
192-
organisationName = req.session.data.nhsTrusts[organisationCode]
193-
organisationLine1 = '73 Roman Rd'
194-
organisationTown = 'Leeds'
195-
organisationPostcode = 'LS2 5ZN'
196-
organisationType = 'NHS Trust'
197-
}
112+
const data = req.session.data
113+
const organisationId = data.organisationId
114+
const organisation = data.allOrganisations.find((organisation) => organisation.id === organisationId)
198115

199-
const organisation = {
200-
id: organisationCode,
201-
name: organisationName,
202-
type: organisationType,
203-
address: {
204-
line1: organisationLine1,
205-
town: organisationTown,
206-
postcode: organisationPostcode
207-
}
208-
}
209116

210117
res.render('regions/check-and-send', {
211118
organisation

app/views/apply/check-pharmacy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
5050
text: "Address"
5151
},
5252
value: {
53-
html: (organisation.address.line1 + "<br>" + organisation.address.town + "<br>" + organisation.address.postcode) if organisation.address else ""
53+
html: (organisation.address) if organisation.address else ""
5454
}
5555
}
5656
]

app/views/apply/start.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
3636
{% set options = [] %}
3737
{% set items = [{ text: "", value: ""}] %}
3838

39-
{% for organisation in data.organisations %}
40-
{% if organisation.type == "Community Pharmacy" %}
39+
{% for organisation in data.allOrganisations | sort(false, false, "name") %}
40+
{% if organisation.type == "Community pharmacy" %}
4141
{% set items = (items.push({
42-
text: organisation.name + ", " + organisation.address.line1 + ", " + (organisation.address.postcode | upper) + " (" + organisation.id + ")",
42+
text: organisation.name + ", " + organisation.address + ", " + (organisation.address.postcode | upper) + " (" + organisation.id + ")",
4343
value: organisation.id,
44-
selected: (organisation.id === data.organisationCode)
44+
selected: (organisation.id === data.organisationId)
4545
}), items) %}
4646
{% endif %}
4747
{% endfor %}
4848

4949
{{ select({
50-
id: "organisation-code",
51-
name: "organisationCode",
50+
id: "organisation-id",
51+
name: "organisationId",
5252
label: {
5353
text: "Find your pharmacy",
5454
classes: "nhsuk-label--m nhsuk-u-margin-bottom-1"

0 commit comments

Comments
 (0)