diff --git a/app/filters.js b/app/filters.js index d8e467d..e6c88c4 100644 --- a/app/filters.js +++ b/app/filters.js @@ -10,6 +10,15 @@ module.exports = function (env) { /* eslint-disable-line no-unused-vars */ */ const filters = prototypeFilters; + + filters.dayName = function(isoDate) { + + const date = new Date(Date.parse(isoDate)) + const dateFormatter = new Intl.DateTimeFormat('en-GB', {weekday: 'short'}); + + return dateFormatter.format(date) + } + /* ------------------------------------------------------------------ add your methods to the filters obj below this comment block: @example: diff --git a/app/routes.js b/app/routes.js index 60a40eb..983dd67 100644 --- a/app/routes.js +++ b/app/routes.js @@ -12,5 +12,6 @@ require('./routes/reports')(router) require('./routes/prototype-admin')(router) require('./routes/support')(router) require('./routes/auth')(router) +require('./routes/home')(router) module.exports = router; diff --git a/app/routes/home.js b/app/routes/home.js new file mode 100644 index 0000000..76ed984 --- /dev/null +++ b/app/routes/home.js @@ -0,0 +1,92 @@ +module.exports = router => { + + // Dashboard + router.get('/home', (req, res) => { + + const dateToday = new Date() + + const stats = [] + + let vaccines = ["RSV", "Pertussis"] + + if (Math.random() > 0.5) { vaccines.push("Flu") } + if (Math.random() > 0.5) { vaccines.push("Covid") } + + for (vaccine of vaccines) { + + let vaccineStat = { + vaccine: vaccine, + days: [] + } + + for (let i = -1; i < 8; i++) { + + let day = new Date(dateToday) + day.setDate(day.getDate() - i) + + let count = Math.round(Math.random() * 20) + 1 + if (i > 0) { + count += Math.round(Math.random() * 150) + } + + vaccineStat.days.push({ + date: day.toISOString().substring(0,10), + count: count + }) + } + + stats.push(vaccineStat) + } + + res.render('home/index', { + stats + }) + }) + + // Site-specific dashboard + router.get('/home/:siteId', (req, res) => { + + const siteId = req.params.siteId + const site = req.session.data.sites[siteId] + const dateToday = new Date() + const stats = [] + + let vaccines = ["RSV", "Pertussis"] + + if (Math.random() > 0.5) { vaccines.push("Flu") } + if (Math.random() > 0.5) { vaccines.push("Covid") } + + for (vaccine of vaccines) { + + let vaccineStat = { + vaccine: vaccine, + days: [] + } + + for (let i = -1; i < 8; i++) { + + let day = new Date(dateToday) + day.setDate(day.getDate() - i) + + let count = Math.round(Math.random() * 5) + 1 + if (i > 0) { + count += Math.round(Math.random() * 30) + } + + vaccineStat.days.push({ + date: day.toISOString().substring(0,10), + count: count + }) + } + + stats.push(vaccineStat) + } + + + res.render('home/site', { + site, + siteId, + stats + }) + }) +} diff --git a/app/views/home/index.html b/app/views/home/index.html new file mode 100644 index 0000000..e9a2038 --- /dev/null +++ b/app/views/home/index.html @@ -0,0 +1,169 @@ +{% extends 'layout.html' %} + +{% block pageTitle %} + {{ currentOrganisation.name }} – Home +{% endblock %} + +{% set currentSection = "home" %} + +{% set sites = [] %} +{% for vaccine in (data.vaccines) %} + {% if not (sites | arrayOrStringIncludes(vaccine.siteCode)) %} + {% set sites = (sites.push(vaccine.siteCode), sites) %} + {% endif %} +{% endfor %} + +{% block content %} +
38
+ Today + {% endset %} + + {{ card({ + headingHtml: cardHtml + }) }} +134
+ Past 7 days + {% endset %} + + {{ card({ + headingHtml: cardHtml + }) }} +546
+ October so far + {% endset %} + + {{ card({ + headingHtml: cardHtml + }) }} +16,141
+ Since 1 Sep 2024 + {% endset %} + + {{ card({ + headingHtml: cardHtml + }) }} ++ Date + | + {% for vaccineStat in stats %} ++ {{ vaccineStat.vaccine }} + | + {% endfor %} ++ Total + | +
---|---|---|
+ {% if loop.index0 == 1 %} + Today + {% else %} + {{ date.date | dayName }} {{ date.date | govukDate("truncate") }} + + {% if loop.index0 == 2 %}(yesterday){% endif %} + {% endif %} + | + + {% set dayIndex = loop.index0 %} + {% for vaccineStat in stats %} + {% set total = total + vaccineStat.days[dayIndex].count %} +{{ vaccineStat.days[dayIndex].count }} | + {% endfor %} +{{ total }} | +
+ Site + | + {% for vaccineStat in stats %} ++ {{ vaccineStat.vaccine }} + | + {% endfor %} ++ Total + | +
---|---|---|
{{ data.sites[site].name }} | + {% for vaccineStat in stats %} + {% set count = ((vaccineStat.days | first).count) * 3 %} + {% set runningTotal = runningTotal + count %} +{{ count }} | + {% endfor %} +{{ runningTotal }} | +
For a more detailed breakdown, create a report.
+ +38
+ Today + {% endset %} + + {{ card({ + headingHtml: cardHtml + }) }} +134
+ Past 7 days + {% endset %} + + {{ card({ + headingHtml: cardHtml + }) }} +318
+ October so far + {% endset %} + + {{ card({ + headingHtml: cardHtml + }) }} +9,812
+ Since 1 Sep 2024 + {% endset %} + + {{ card({ + headingHtml: cardHtml + }) }} ++ Date + | + {% for vaccineStat in stats %} ++ {{ vaccineStat.vaccine }} + | + {% endfor %} ++ Total + | +
---|---|---|
+ {% if loop.index0 == 1 %} + Today + {% else %} + {{ date.date | dayName }} {{ date.date | govukDate("truncate") }} + + {% if loop.index0 == 2 %}(yesterday){% endif %} + {% endif %} + | + + {% set dayIndex = loop.index0 %} + {% for vaccineStat in stats %} + {% set total = total + vaccineStat.days[dayIndex].count %} +{{ vaccineStat.days[dayIndex].count }} | + {% endfor %} +{{ total }} | +