diff --git a/app/assets/javascript/main.js b/app/assets/javascript/main.js index c7464192..dabe5ee9 100644 --- a/app/assets/javascript/main.js +++ b/app/assets/javascript/main.js @@ -9,6 +9,7 @@ import { CheckboxFilter } from './checkbox-filter.js' import { CheckboxSelectAll } from './checkbox-select-all.js' import { CheckboxSelectedCount } from './checkbox-selected-count.js' import { RadiosFilter } from './radios-filter.js' +import './vaccine-site-filter.js' // Initiate NHS.UK frontend components on page load document.addEventListener('DOMContentLoaded', () => { diff --git a/app/assets/javascript/vaccine-site-filter.js b/app/assets/javascript/vaccine-site-filter.js new file mode 100644 index 00000000..048a5324 --- /dev/null +++ b/app/assets/javascript/vaccine-site-filter.js @@ -0,0 +1,16 @@ +// Filter vaccine site sections from the site select menu + +document.addEventListener('DOMContentLoaded', () => { + const select = document.getElementById('select-1') + const siteSections = document.querySelectorAll('[data-vaccine-site]') + + if (!select || siteSections.length === 0) return + + select.addEventListener('change', () => { + const selectedSite = select.value + + siteSections.forEach((siteSection) => { + siteSection.hidden = selectedSite !== '' && siteSection.dataset.vaccineSite !== selectedSite + }) + }) +}) diff --git a/app/routes/vaccines.js b/app/routes/vaccines.js index a799cb13..00783010 100644 --- a/app/routes/vaccines.js +++ b/app/routes/vaccines.js @@ -224,11 +224,24 @@ module.exports = (router) => { // Mark site as closed router.post('/vaccines/sites/:siteId/deactivated', (req, res) => { const currentOrganisationSites = res.locals.currentOrganisation.sites || [] + const data = req.session.data const site = currentOrganisationSites.find((item) => item.id === req.params.siteId) if (!site) { res.redirect('/vaccines'); return } site.status = 'closed' + const today = new Date().toISOString().substring(0, 10) + data.vaccineStock + .filter((vaccine) => vaccine.organisationId === res.locals.currentOrganisation.id && vaccine.siteId === site.id) + .forEach((vaccine) => { + vaccine.batches.forEach((batch) => { + if (!batch.deactivatedDate && batch.expiryDate >= today) { + batch.deactivatedDate = today + batch.deactivationReason = 'site' + } + }) + }) + res.redirect(`/vaccines?siteTab=deactivated&deactivatedSite=true&siteName=${encodeURIComponent(site.name)}`) }) @@ -246,11 +259,23 @@ module.exports = (router) => { // Mark site as active router.post('/vaccines/sites/:siteId/reactivated', (req, res) => { const currentOrganisationSites = res.locals.currentOrganisation.sites || [] + const data = req.session.data const site = currentOrganisationSites.find((item) => item.id === req.params.siteId) if (!site) { res.redirect('/vaccines'); return } delete site.status + data.vaccineStock + .filter((vaccine) => vaccine.organisationId === res.locals.currentOrganisation.id && vaccine.siteId === site.id) + .forEach((vaccine) => { + vaccine.batches.forEach((batch) => { + if (batch.deactivationReason === 'site') { + batch.deactivatedDate = null + delete batch.deactivationReason + } + }) + }) + res.redirect(`/vaccines?siteTab=active&reactivatedSite=true&siteName=${encodeURIComponent(site.name)}`) }) @@ -345,7 +370,9 @@ module.exports = (router) => { const currentTab = requestedTab === 'inactive' && batchesByStatus.inactive.length === 0 ? 'active' - : requestedTab + : requestedTab === 'active' && batchesByStatus.active.length === 0 && batchesByStatus.inactive.length > 0 + ? 'inactive' + : requestedTab const filteredBatches = batchesByStatus[currentTab] const totalBatches = filteredBatches.length @@ -496,6 +523,7 @@ module.exports = (router) => { let deactivatedDate = new Date() batch.deactivatedDate = deactivatedDate.toISOString().substring(0,10) + batch.deactivationReason = 'manual' res.redirect(`/vaccines/${vaccine.id}?tab=inactive&deactivated=true&batchNumber=${encodeURIComponent(batch.batchNumber)}`) }) diff --git a/app/views/errors/problem-deactivating-site-2-users-trying.html b/app/views/errors/problem-deactivating-site-2-users-trying.html new file mode 100644 index 00000000..87c74104 --- /dev/null +++ b/app/views/errors/problem-deactivating-site-2-users-trying.html @@ -0,0 +1,16 @@ +{% extends 'layout.html' %} + +{% set pageName = "There is a problem deactivating this site" %} +{% set currentSection = "vaccines" %} + + +{% block content %} +
+
+ +

{{ pageName }}

+

Go back to the Vaccines section and check the site's status before trying again.

+ +
+
+{% endblock %} diff --git a/app/views/errors/site-deactivated.html b/app/views/errors/site-deactivated.html new file mode 100644 index 00000000..b43e6fa6 --- /dev/null +++ b/app/views/errors/site-deactivated.html @@ -0,0 +1,25 @@ +{% extends 'layout.html' %} + +{% set pageName = "There is a problem saving this vaccination" %} + +{% block content %} + +
+
+ +

{{ pageName }}

+ +

You cannot save this vaccination because [site name] has been deactivated.

+ +

An administrator can reactivate the site in the Vaccines setion. Once the site is reactivated, you will be able to record this vaccination but you will have to start again.

+ +

If no one is available to reactivate the site, record it on paper.

+ +

Download our paper form (opens in new tab)

+ +

Go back to Record vaccinations

+ +
+
+ +{% endblock %} diff --git a/app/views/errors/vaccine-disabled.html b/app/views/errors/vaccine-disabled.html index 39ac1704..1adc96d2 100644 --- a/app/views/errors/vaccine-disabled.html +++ b/app/views/errors/vaccine-disabled.html @@ -3,20 +3,21 @@ {% set pageName = "There is a problem saving this vaccination" %} {% block content %} +
+

{{ pageName }}

You cannot save this vaccination because a regional lead has removed your access to [vaccine name] vaccines.

If you have already vaccinated the patient, record it on paper and contact your regional lead.

-

Go back to the Check and confirm page to see details of the vaccination.

Download our paper form (opens in new tab)

- + +

Go back to the Check and confirm page to see details of the vaccination.

- {% endblock %} diff --git a/app/views/index.html b/app/views/index.html index 3e8db27a..caeeac19 100755 --- a/app/views/index.html +++ b/app/views/index.html @@ -283,7 +283,7 @@

Error pages

], [ { - html: "Rate limited (429 error)" + html: "Sorry, there is a problem with the service (rate limited, 429 error)" }, { text: "When too many requests are made in a short time." @@ -291,10 +291,26 @@

Error pages

], [ { - html: "Problem saving the vaccination (Regional admin has removed vaccines mid-recording)" + html: "There is a problem saving this vaccination" }, { - text: "When a vaccination programme becomes unavailable during the recording flow." + text: "When a regional user has removed access to a vaccine type mid-recording." + } + ], + [ + { + html: "There is a problem saving this vaccination" + }, + { + text: "When a site is deactivated during the recording flow." + } + ], + [ + { + html: "There is a problem deactivating this site" + }, + { + text: "When there is a problem deactivating a site because 2 users are trying to do this at the same time or because of another issue such as API failure." } ] ] diff --git a/app/views/vaccines/deactivate-site.html b/app/views/vaccines/deactivate-site.html index 6b9cea0d..c10ef5f9 100644 --- a/app/views/vaccines/deactivate-site.html +++ b/app/views/vaccines/deactivate-site.html @@ -14,7 +14,7 @@

{{ pageName }}

-

Are you sure you want to deactivate this site?

+

Are you sure you want to deactivate this site? Once deactivated, the site will have no active batches and you will not be able to record any vaccinations there. You can reactivate it at anytime.

{{ button({ diff --git a/app/views/vaccines/index.html b/app/views/vaccines/index.html index 19a19862..e4fb06b6 100644 --- a/app/views/vaccines/index.html +++ b/app/views/vaccines/index.html @@ -111,15 +111,19 @@

Vaccines

{{ appSecondaryNavigation({ visuallyHiddenTitle: "Sites by status", - items: [{ + items: [ + { text: "Active sites (" + activeSitesCount + ")", href: "/vaccines?siteTab=active", current: (currentSiteTab == "active") - }, { + } if activeSitesCount != "0" + , + { text: "Deactivated sites (" + deactivatedSitesCount + ")", href: "/vaccines?siteTab=deactivated", current: (currentSiteTab == "deactivated") - }] + } if deactivatedSitesCount != "0" + ] }) }}
@@ -130,8 +134,9 @@

Vaccines

selected: true }] %} - {% for site in filteredSites %} - {% set filterItems = (filterItems.push({text: currentOrganisation.sites[site].name, value: site}), filterItems) %} + {% for siteId in filteredSites %} + {% set site = currentOrganisation.sites | findById(siteId) %} + {% set filterItems = (filterItems.push({text: site.name, value: siteId}), filterItems) %} {% endfor %} @@ -158,6 +163,7 @@

Vaccines

{% set site = currentOrganisation.sites | findById(siteId) %} +
@@ -229,13 +235,16 @@

Vaccines

{{ site.name }}
- {% if site.status != "closed" %} + {% if site.status != "closed" and (filteredSites | length) <= 1 %} + {# Don't show anything, because we don't want users to close the last site #} + {% elif site.status != "closed" %}

No longer using this site? Deactivate {{ site.name }}

- {% else %} -
-

Using this site again? Reactivate {{ site.name }}

+ {% else %} +
+

Using this site again? Reactivate {{ site.name }}

{% endif %} +
{% endfor %} diff --git a/app/views/vaccines/product-page.html b/app/views/vaccines/product-page.html index 30e234ed..23be3c69 100644 --- a/app/views/vaccines/product-page.html +++ b/app/views/vaccines/product-page.html @@ -122,11 +122,15 @@

Batches {% set activeCount = activeBatchesCount | default(0) %} {% set inactiveCount = inactiveBatchesCount | default(0) %} - {% set secondaryNavItems = [{ - text: "Active (" + activeCount + ")", - href: "/vaccines/" + vaccine.id + "?tab=active", - current: (currentTab == "active") - }] %} + {% set secondaryNavItems = [] %} + + {% if activeCount > 0 %} + {% set secondaryNavItems = (secondaryNavItems.push({ + text: "Active (" + activeCount + ")", + href: "/vaccines/" + vaccine.id + "?tab=active", + current: (currentTab == "active") + }), secondaryNavItems) %} + {% endif %} {% if inactiveCount > 0 %} {% set secondaryNavItems = (secondaryNavItems.push({ @@ -212,7 +216,9 @@

Batches {% endif %} - {% if batch.deactivatedDate %} + {% if batch.deactivationReason == "site" %} + Site deactivated + {% elif batch.deactivatedDate %} Deactivated by user {% elif (batch.expiryDate | daysAgo) > 0 %} Expired