Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/assets/sass/components/_summary-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@
margin-top: nhsuk-spacing(2);
color: $nhsuk-secondary-text-colour;
}

@include nhsuk-media-query($from: tablet) {
.app-pharmacy-summary-list .nhsuk-summary-list__value {
width: 35%;
}

.app-pharmacy-summary-list__actions {
width: 35%;
white-space: nowrap;
}
}
61 changes: 61 additions & 0 deletions app/routes/pharmacies.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const hasVaccinationRecords = (data, organisationId) => {
}

const scenarioCompanyIds = ['P0191N', 'P15951']
const allowedPharmacyVaccineNames = ['flu', 'COVID-19', 'MenB']

const isoDaysAgo = (daysAgo) => {
const date = new Date()
Expand Down Expand Up @@ -1236,6 +1237,64 @@ module.exports = router => {
}
})

router.get('/pharmacies/:id/edit-vaccines', (req, res) => {
const data = req.session.data
const { id } = req.params
const organisation = data.organisations.find((org) => org.id === id)

if (!organisation) {
return res.redirect('/pharmacies')
}

const enabledVaccineNames = (organisation.vaccines || [])
.filter((vaccine) => vaccine.status === 'enabled')
.filter((vaccine) => allowedPharmacyVaccineNames.includes(vaccine.name))
.map((vaccine) => vaccine.name)

const availableVaccines = (data.vaccines || [])
.filter((vaccine) => allowedPharmacyVaccineNames.includes(vaccine.name))

res.render('pharmacies/edit-vaccines', {
organisation,
allVaccines: availableVaccines,
enabledVaccineNames
})
})

router.post('/pharmacies/:id/update-vaccines', (req, res) => {
const data = req.session.data
const { id } = req.params
const organisation = data.organisations.find((org) => org.id === id)

if (!organisation) {
return res.redirect('/pharmacies')
}

const selectedVaccinesRaw = req.body.vaccinesEnabled
const selectedVaccines = Array.isArray(selectedVaccinesRaw)
? selectedVaccinesRaw
: (selectedVaccinesRaw ? [selectedVaccinesRaw] : [])

organisation.vaccines ||= []
const allVaccineNames = allowedPharmacyVaccineNames

for (const vaccineName of allVaccineNames) {
const existingVaccine = organisation.vaccines.find((vaccine) => vaccine.name === vaccineName)
const isSelected = selectedVaccines.includes(vaccineName)

if (existingVaccine) {
existingVaccine.status = isSelected ? 'enabled' : 'disabled'
} else if (isSelected) {
organisation.vaccines.push({
name: vaccineName,
status: 'enabled'
})
}
}

return res.redirect(`/pharmacies/${id}?vaccinesUpdated=true`)
})


router.get('/pharmacies/:id', async (req, res) => {
const data = req.session.data
Expand All @@ -1247,6 +1306,7 @@ module.exports = router => {
const deactivatedFromPharmacyId = req.query.deactivatedFromPharmacyId
const reactivatedUserId = req.query.reactivatedUserId
const reactivatedFromPharmacyId = req.query.reactivatedFromPharmacyId
const vaccinesUpdated = req.query.vaccinesUpdated
const tab = (req.query.tab || 'active').toLowerCase()


Expand Down Expand Up @@ -1329,6 +1389,7 @@ module.exports = router => {
deactivatedFromPharmacyId,
reactivatedUser,
reactivatedFromPharmacyId,
vaccinesUpdated,
canDeletePharmacy
})
})
Expand Down
48 changes: 48 additions & 0 deletions app/views/pharmacies/edit-vaccines.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% extends 'layout.html' %}

{% set currentSection = "pharmacies" %}
{% set pageName = "Edit vaccines for " + organisation.name %}

{% block beforeContent %}
{{ backLink({
href: "/pharmacies/" + organisation.id,
text: "Back"
}) }}
{% endblock %}

{% block content %}
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
<form method="post" action="/pharmacies/{{ organisation.id }}/update-vaccines" novalidate>
{% set items = [] %}

{% for vaccine in (allVaccines | sort(false, false, "name")) %}
{% set items = (items.push({
value: vaccine.name,
text: "MenB" if vaccine.name == "MenB" else (vaccine.name | capitaliseFirstLetter)
}), items) %}
{% endfor %}

{{ checkboxes({
name: "vaccinesEnabled",
fieldset: {
legend: {
text: "Which vaccines can this pharmacy record?",
size: "l",
isPageHeading: true
}
},
hint: {
text: "Checking a vaccine will make it available for this pharmacy. Unchecking a vaccine will remove it from this pharmacy."
},
items: items,
values: enabledVaccineNames
}) }}

{{ button({
text: "Save changes"
}) }}
</form>
</div>
</div>
{% endblock %}
46 changes: 44 additions & 2 deletions app/views/pharmacies/pharmacy.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ <h3 class="nhsuk-notification-banner__heading">
}) }}
{% endif %}

{% if vaccinesUpdated == "true" %}
{% set html %}
<h3 class="nhsuk-notification-banner__heading">
Vaccines changed
</h3>
<p>The vaccines for {{ organisation.name }} have been updated.</p>
{% endset %}

{{ notificationBanner({
html: html,
type: "success"
}) }}
{% endif %}

<h1 class="nhsuk-heading-l">{{ pageName }}</h1>

{% set addressParts = [] %}
Expand All @@ -83,7 +97,25 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
{% set addressParts = (addressParts.push(organisation.address.postcode), addressParts) %}
{% endif %}

{% set addressHtml = addressParts | join(", ") %}
{% if organisation.address.line1 and organisation.address.town %}
{% set addressHtml = addressHtml | replace(", ", ",<br>") %}
{% endif %}

{% set vaccinesEnabled = [] %}
{% for vaccine in (organisation.vaccines or []) %}
{% if vaccine.status == "enabled" %}
{% set vaccinesEnabled = (vaccinesEnabled.push(vaccine.name), vaccinesEnabled) %}
{% endif %}
{% endfor %}

{% set vaccinesText = "None" %}
{% if (vaccinesEnabled | length) > 0 %}
{% set vaccinesText = (vaccinesEnabled | sort | join(", ")) | capitaliseFirstLetter %}
{% endif %}

{{ summaryList({
classes: "app-pharmacy-summary-list",
rows: [
{
key: {
Expand All @@ -98,15 +130,25 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
text: "Address"
},
value: {
text: addressParts | join(", ")
html: addressHtml
}
},
{
key: {
text: "Vaccines"
},
value: {
text: "COVID-19, flu"
text: vaccinesText
},
actions: {
classes: "app-pharmacy-summary-list__actions",
items: [
{
href: "/pharmacies/" + organisation.id + "/edit-vaccines",
text: "Edit vaccines",
visuallyHiddenText: "vaccines for " + organisation.name
}
]
}
}
]
Expand Down