diff --git a/app/lib/ods.js b/app/lib/ods.js index debd8b46..bb7c8b50 100644 --- a/app/lib/ods.js +++ b/app/lib/ods.js @@ -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. @@ -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 } @@ -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 } } diff --git a/app/lib/utils/capitalise-from-ods.js b/app/lib/utils/capitalise-from-ods.js new file mode 100644 index 00000000..d43b0630 --- /dev/null +++ b/app/lib/utils/capitalise-from-ods.js @@ -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(' '); +} diff --git a/app/routes/apply.js b/app/routes/apply.js index 3abcbed4..acb4ff84 100644 --- a/app/routes/apply.js +++ b/app/routes/apply.js @@ -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 @@ -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 diff --git a/app/routes/auth.js b/app/routes/auth.js index 20548c23..500b18cf 100644 --- a/app/routes/auth.js +++ b/app/routes/auth.js @@ -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) { @@ -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 { @@ -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') } @@ -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') diff --git a/app/routes/home.js b/app/routes/home.js index 5cd163cd..bc890a75 100644 --- a/app/routes/home.js +++ b/app/routes/home.js @@ -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] } diff --git a/app/routes/vaccines.js b/app/routes/vaccines.js index 5ef4a696..1ed8a0f0 100644 --- a/app/routes/vaccines.js +++ b/app/routes/vaccines.js @@ -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) { diff --git a/app/views/apply/check-chain.html b/app/views/apply/check-chain.html index 3fb1087a..7f8b8d07 100644 --- a/app/views/apply/check-chain.html +++ b/app/views/apply/check-chain.html @@ -15,10 +15,16 @@