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 %} +
Go back to the Vaccines section and check the site's status before trying again.
+ +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.
+ + + + + +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.
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.