Skip to content
Merged
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
10 changes: 6 additions & 4 deletions app/lib/ods.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { capitaliseFromOds } = require('./utils/capitalise-from-ods.js')


// There are 2 different ODS APIs, the old ORD API and the newer FHIR-based API.
// The ORD API is officially deprecated and may be retired in the future.
Expand Down Expand Up @@ -32,7 +34,7 @@ async function fetchPaginatedOrganisations(queryParams) {
const results = (data.Organisations || []).map(function(org) {
return {
id: org.OrgId,
name: org.Name,
name: capitaliseFromOds(org.Name),
address: {
postcode: org.PostCode
}
Expand Down Expand Up @@ -81,10 +83,10 @@ async function getOrganisation(id) {

const organisation = {
id: data.id,
name: data.name,
name: capitaliseFromOds(data.name),
address: {
line1: data.address[0].line[0],
town: data.address[0].city,
line1: capitaliseFromOds(data.address[0].line[0]),
town: capitaliseFromOds(data.address[0].city),
postcode: data.address[0].postalCode
}
}
Expand Down
39 changes: 39 additions & 0 deletions app/lib/utils/capitalise-from-ods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Words that should remain lowercase (unless at the start)
const lowercaseWords = ['and', 'the', 'of', 'in', 'for', 'on', 'at', 'to', 'by', 'with', 'a', 'an'];

// Acronyms that should remain uppercase
const acronyms = ['NHS', 'GP', 'PCN', 'CCG', 'ICB', 'CIC', 'UK', 'LLP', 'PLC'];

module.exports.capitaliseFromOds = function(input) {
if (!input) return input;

const words = input.toLowerCase().split(/\s+/);

const capitalisedWords = words.map((word, index) => {
// Check if word is initials (e.g. "p.g." or "a.b.c.")
if (/^([a-z]\.)+$/i.test(word)) {
return word.toUpperCase();
}

// Check if word is a single letter (keep uppercase)
if (/^[a-z]$/i.test(word)) {
return word.toUpperCase();
}

// Check if upper-cased word is an acronym
const upperWord = word.toUpperCase();
if (acronyms.includes(upperWord)) {
return upperWord;
}

// Check if word should remain lowercase (but not if it's the first word)
if (index !== 0 && lowercaseWords.includes(word)) {
return word;
}

// Capitalise first letter, rest lowercase
return word.charAt(0).toUpperCase() + word.slice(1);
});

return capitalisedWords.join(' ');
}
56 changes: 56 additions & 0 deletions app/routes/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ module.exports = router => {
})
})

// Check list of selected pharmacies
router.post('/apply/pharmacy-chain-check-remove-one', (req, res) => {
const data = req.session.data
const pharmacyIdToRemove = data.pharmacyIdToRemove

data.pharmacyIds = data.pharmacyIds.filter(id => id !== pharmacyIdToRemove)

res.redirect('/apply/pharmacy-chain-check')
})


// Check your answers page
router.get('/apply/check', (req, res) => {
const data = req.session.data
Expand Down Expand Up @@ -157,6 +168,51 @@ module.exports = router => {
res.redirect('/apply/check-your-email')
})

// Routing after the final check answers for chains page
router.post('/apply/check-chain-answer', async (req, res) => {
const data = req.session.data

let pharmacies = await getPharmaciesBelongingToOrganisation(data.pharmacyChainId)

pharmacies = pharmacies.filter((pharmacy) => {
return data.pharmacyIds.includes(pharmacy.id)
})

let userOrganisationPermissions = []

for (const pharmacy of pharmacies) {

// Add the pharmacy itself as the single site
pharmacy.sites = [
{
id: pharmacy.id,
name: pharmacy.name,
address: pharmacy.address
}
]

data.organisations.push(pharmacy)
userOrganisationPermissions.push({
id: pharmacy.id,
permissionLevel: 'Lead administrator',
status: 'Active',
vaccinator: false
})
}

const user = {
id: Math.floor(Math.random() * 10000000).toString(),
firstName: data.firstName,
lastName: data.lastName,
email: data.email,
organisations: userOrganisationPermissions
}

data.users.push(user)

res.redirect('/apply/check-your-email-chain')
})

// Welcome email mockup
router.get('/apply/welcome-email', (req, res) => {
const data = req.session.data
Expand Down
17 changes: 7 additions & 10 deletions app/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = router => {
req.session.data.currentUserId = user.id;
req.session.data.currentOrganisationId = userOrganisationIds[0]

res.redirect('/survey')
res.redirect('/home')

} else if (userRegionIds.length === 1) {

Expand All @@ -55,7 +55,10 @@ module.exports = router => {
} else if (organisationsUserIsAnAdminAt.length > 1) {

req.session.data.currentUserId = user.id
res.redirect('/auth/select-mode')

// Skipping the select mode screen for research purposes
res.redirect('/auth/select-organisation')
// res.redirect('/auth/select-mode')

} else {

Expand All @@ -79,7 +82,7 @@ module.exports = router => {
req.session.data.currentUserId = data.userId


res.redirect('/survey')
res.redirect('/home')
} else {
res.redirect('/auth/select-mode')
}
Expand All @@ -102,18 +105,12 @@ module.exports = router => {
})

router.post('/select-organisation', (req, res) => {

const data = req.session.data
const email = data.email
const user = data.users.find((user) => user.email === email)

const selectedOrganisationId = req.session.data.organisationId

if (selectedOrganisationId) {
req.session.data.currentUserId = user.id;
req.session.data.currentOrganisationId = selectedOrganisationId;

res.redirect('/survey')
res.redirect('/home')
} else {

res.redirect('/auth/select-organisation')
Expand Down
2 changes: 1 addition & 1 deletion app/routes/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = router => {
// organisation
vaccinationsRecorded = allVaccinationsRecorded.filter((vaccination)=> vaccination.organisationId === currentOrganisation.id)

if (sites.length === 0) {
if (!sites.length || sites.length === 0) {
sites = [currentOrganisation]
}

Expand Down
2 changes: 2 additions & 0 deletions app/routes/vaccines.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ module.exports = (router) => {

for (const vaccine of vaccinesAdded) {

currentOrganisation.vaccines ||= []

let vaccineToEnable = currentOrganisation.vaccines.find((vaccine) => vaccine.name === vaccine)

if (vaccineToEnable) {
Expand Down
18 changes: 12 additions & 6 deletions app/views/apply/check-chain.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
<h1 class="nhsuk-heading-l">{{ pageName }}</h1>

{% set pharmaciesHtml %}
{% for pharmacy in pharmacies %}
{{ pharmacy.name | capitalize }} ({{ pharmacy.id }})
<br>
{% endfor %}
{% if (pharmacies | length) <= 10 %}
<ul class="nhsuk-list">
{% for pharmacy in pharmacies %}
<li>{{ pharmacy.name }} ({{ pharmacy.id }})</li>
{% endfor %}
</ul>
{% else %}
{{ pharmacies | length }} pharmacies
{% endif %}

{% endset %}

<h2 class="nhsuk-heading-m">Your pharmacies</h2>
Expand All @@ -29,7 +35,7 @@ <h2 class="nhsuk-heading-m">Your pharmacies</h2>
text: "Company"
},
value: {
html: (pharmacyChain.name | capitalize)
html: pharmacyChain.name
},
actions: {
items: [
Expand Down Expand Up @@ -146,7 +152,7 @@ <h2 class="nhsuk-heading-m">2nd lead administrator</h2>
}) }}
{% endif %}

<form action="/apply/check-your-email-chain" method="post">
<form action="/apply/check-chain-answer" method="post">
{{ button({
text: "Confirm"
}) }}
Expand Down
4 changes: 2 additions & 2 deletions app/views/apply/check-pharmacy-chain.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
text: "Name"
},
value: {
text: organisation.name | capitalize
text: organisation.name
}
},
{
Expand All @@ -46,7 +46,7 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
text: "Address"
},
value: {
html: (organisation.address.line1 | capitalize) + "<br>" + (organisation.address.town | capitalize) + "<br>" + organisation.address.postcode
html: organisation.address.line1 + "<br>" + organisation.address.town + "<br>" + organisation.address.postcode
}
}
]
Expand Down
31 changes: 16 additions & 15 deletions app/views/apply/pharmacies.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'layout.html' %}

{% set pageName = "" %}
{% set pageName = "Select the pharmacies where you want to start using RAVS" %}


{% block beforeContent %}
Expand All @@ -16,22 +16,23 @@
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">

{% set items = [
{
text: "Select all",
value: "",
attributes: {
"data-select-all": "true"
}
},
{
divider: "or"
}
] %}
{% set items = [] %}
{% if pharmacies | length > 1 %}
{% set items = (items.push({
text: "Select all",
value: "",
attributes: {
"data-select-all": "true"
}
}), items) %}
{% set items = (items.push({
divider: "or"
}), items) %}
{% endif %}

{% for pharmacy in pharmacies %}
{% set items = (items.push({
text: (pharmacy.name | capitalize) + ", " + pharmacy.address.postcode + " (" + pharmacy.id + ")",
text: pharmacy.name + ", " + pharmacy.address.postcode + " (" + pharmacy.id + ")",
value: pharmacy.id
}), items) %}
{% endfor %}
Expand All @@ -44,7 +45,7 @@
values: data.pharmacyIds,
fieldset: {
legend: {
text: "Select the pharmacies where you want to start using RAVS",
text: pageName,
size: "l"
}
},
Expand Down
17 changes: 11 additions & 6 deletions app/views/apply/pharmacy-chain-check.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

<p>You have selected <b>{{ pharmacies | length }} pharmacies</b>.</p>
<p>You have selected <b>{{ pharmacies | length | plural("pharmacy") }}</b>.</p>

<table>
<thead>
Expand All @@ -28,12 +28,17 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>

{% for pharmacy in pharmacies %}
<tr>
<td>{{ pharmacy.name | capitalize }}, {{ pharmacy.address.postcode }} ({{ pharmacy.id }})</td>
<td>{{ pharmacy.name }}, {{ pharmacy.address.postcode }} ({{ pharmacy.id }})</td>
<td class="nhsuk-u-text-align-right">
{{ button({
text: "Remove",
classes: "nhsuk-button--small nhsuk-button--secondary nhsuk-u-margin-bottom-0"
}) }}
{% if pharmacies | length > 1 %}
<form action="/apply/pharmacy-chain-check-remove-one" method="post">
<input type="hidden" name="pharmacyIdToRemove" value="{{ pharmacy.id }}">
{{ button({
text: "Remove",
classes: "nhsuk-button--small nhsuk-button--secondary nhsuk-u-margin-bottom-0"
}) }}
</form>
{% endif %}
</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion app/views/apply/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

{% for pharmacyCompany in (allPharmacyCompanies | sort(false, false, "name")) %}
{% set pharmacyCompanyItems = (pharmacyCompanyItems.push({
text: (pharmacyCompany.name | capitalize) + " (" + (pharmacyCompany.id) + ")",
text: (pharmacyCompany.name) + " (" + (pharmacyCompany.id) + ")",
value: pharmacyCompany.id
}), pharmacyCompanyItems) %}
{% endfor %}
Expand Down
12 changes: 6 additions & 6 deletions app/views/apply/welcome-email-chain.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ <h2 class="nhsuk-heading-s">1. Activate your Okta account</h2>
<p>If you cannot find the email, check your spam or junk.</p>

<h2 class="nhsuk-heading-s">2. Log in to the Record a vaccination service</h2>
<p>Once you’ve activated your Okta account, log in to <a href="https://www.ravs.england.nhs.uk">www.ravs.england.nhs.uk</a> using your Okta username and password.</p>
<p>Once you’ve activated your Okta account, log in to <a href="/auth/okta-sign-in?email={{ data.email }}">www.ravs.england.nhs.uk</a> using your Okta username and password.</p>
<p>You can also access the service through your Okta account by clicking ‘RAVS (PROD) app’.</p>

<h2 class="nhsuk-heading-s">3. Add users to individual pharmacies</h2>
<p>When you log in, you'll see a list of pharmacies where you now have access to the service.</p>
<p>To give more users access to the service at individual pharmacies:</p>
<p>To give more users access to the service at individual pharmacies:</p>

<ul class="nhsuk-list nhsuk-list--bullet">
<li>select a pharmacy from the list</li>
<li>go to the Manage users section and add users</li>
</ul>

<h2 class="nhsuk-heading-s">Training and support</h2>
<p>To help you get started, you can:</p>
<ul class="nhsuk-list nhsuk-list--bullet">
Expand All @@ -50,9 +50,9 @@ <h2 class="nhsuk-heading-s">Training and support</h2>

<p>Do not reply to this email as we do not check this inbox.</p>
<p>To contact us, go to: <a href="https://www.ravs.england.nhs.uk/help-and-support">Record a vaccination: Help and support</a></p>





</div>
</div>

Expand Down
Loading