Skip to content

Commit a442c76

Browse files
Add shortcut for setting up vaccines (#387)
This adds an action to let you set up batches for all available vaccines in a single click, rather than having to use the interface each time.
1 parent 402677f commit a442c76

File tree

6 files changed

+83
-3
lines changed

6 files changed

+83
-3
lines changed

app/routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require('./routes/lists')(router)
1717
require('./routes/support')(router)
1818
require('./routes/auth')(router)
1919
require('./routes/home')(router)
20+
require('./routes/helpers')(router)
2021

2122

2223

app/routes/helpers.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module.exports = router => {
2+
3+
router.get('/prototype-setup/setup-batches', (req, res) => {
4+
5+
const data = req.session.data
6+
let vaccineStock = data.vaccineStock
7+
8+
const dateNow = new Date()
9+
const millisecondsPerDay = 86400000
10+
11+
const vaccines = data.vaccines
12+
const siteId = "RW3NM"
13+
14+
for (vaccine of vaccines) {
15+
for (vaccineProduct of vaccine.products) {
16+
17+
const numberOfBatchesToAdd = 1 + Math.floor(Math.random() * 10)
18+
19+
let batches = []
20+
21+
const generatedVaccineId = Math.floor(Math.random() * 10000000).toString()
22+
23+
for (let step = 0; step < numberOfBatchesToAdd; step++) {
24+
25+
const generatedBatchId = Math.floor(Math.random() * 10000000).toString()
26+
const generatedBatchNumber = "AB" + Math.floor(Math.random() * 1000000).toString()
27+
28+
const generatedExpiryDate = new Date(dateNow.getTime() + (Math.random() * 100 * millisecondsPerDay)).toISOString()
29+
30+
batches.push({
31+
id: generatedBatchId,
32+
batchNumber: generatedBatchNumber,
33+
expiryDate: generatedExpiryDate
34+
})
35+
}
36+
37+
vaccineStock.push({
38+
id: generatedVaccineId,
39+
vaccine: vaccine.name,
40+
vaccineProduct: vaccineProduct.name,
41+
siteId: siteId,
42+
batches: batches
43+
})
44+
}
45+
}
46+
47+
48+
res.redirect('/vaccines')
49+
});
50+
51+
}

app/views/layout.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
{
5555
URL: "/prototype-admin/reset-data",
5656
label: "Reset prototype test data"
57+
},
58+
{
59+
URL: "/prototype-setup",
60+
label: "Prototype data setup"
5761
}
5862
]
5963
})}}

app/views/prototype-setup.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% extends 'layout.html' %}
2+
3+
{% set pageName = "" %}
4+
5+
{% block header %}
6+
{% include "includes/header-logged-out.html" %}
7+
{% endblock %}
8+
9+
{% block content %}
10+
<div class="nhsuk-grid-row">
11+
<div class="nhsuk-grid-column-two-thirds">
12+
13+
<h1 class="nhsuk-heading-l">Prototype data setup</h1>
14+
15+
<p>Use these links to change how the data in the prototype is set up.</p>
16+
17+
<ul class="nhsuk-list">
18+
<li><a href="/prototype-setup/setup-batches">Add batches for all vaccines</a></li>
19+
</ul>
20+
21+
</div>
22+
</div>
23+
24+
{% endblock %}

app/views/record-vaccinations/vaccine.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
{% for vaccineProduct in (vaccine.products) %}
5858
{% set productItems = (productItems.push({
5959
value: vaccineProduct.name,
60-
text: vaccineProduct.name
60+
text: (vaccineProduct.name | capitaliseFirstLetter )
6161
}), productItems) %}
6262
{% endfor %}
6363

@@ -77,7 +77,7 @@
7777

7878
{% set items = (items.push({
7979
value: vaccine.name,
80-
text: vaccine.name,
80+
text: (vaccine.name | capitaliseFirstLetter),
8181
conditional: {
8282
html: conditionalHtml
8383
} if vaccine.products

app/views/vaccines/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ <h1 class="nhsuk-heading-xl">Vaccines</h1>
102102
{% for vaccineProduct in vaccineProductsAtSite %}
103103
<tr class="nhsuk-table__row">
104104
<td class="nhsuk-table__cell">
105-
{{ vaccineAtSite }}
105+
{{ vaccineAtSite | capitaliseFirstLetter }}
106106
</td>
107107
<td class="nhsuk-table__cell">
108108
{{ vaccineProduct }}

0 commit comments

Comments
 (0)