From 947845d73c229b8fc0611af9633c9387fbd9cd9f Mon Sep 17 00:00:00 2001 From: Ed Horsford Date: Thu, 14 Nov 2024 15:09:09 +0000 Subject: [PATCH] Update seed data, misc cleanup --- app/data/session-data-defaults.js | 2 +- app/data/users.js | 1 + app/lib/generate-seed-data.js | 1 + app/lib/generators/participant-generator.js | 28 +++++++++------------ app/lib/utils/strings.js | 17 +++++++++++++ app/views/dashboard.html | 1 + app/views/participants/show.html | 2 +- 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/data/session-data-defaults.js b/app/data/session-data-defaults.js index bfec6f5..eebb2a1 100644 --- a/app/data/session-data-defaults.js +++ b/app/data/session-data-defaults.js @@ -40,7 +40,7 @@ if (fs.existsSync(generationInfoPath)) { // Generate or load data if (needsRegeneration) { console.log('Generating new seed data...'); - require('../lib/generate-seed-data.js'); + require('../lib/generate-seed-data.js')(); // Save generation info fs.writeFileSync( diff --git a/app/data/users.js b/app/data/users.js index ba8682a..6e08a66 100644 --- a/app/data/users.js +++ b/app/data/users.js @@ -3,6 +3,7 @@ module.exports = [ firstName: "Jane", lastName: "Hitchin", role: "mamographer", + email: "j.hitchin4@nhs.net", id: "ae7537b3-aed1-4620-87fd-9dc5b5bdc8cb", breastScreeningUnit: "f66f2a7d-99a8-4793-8371-3d075e1a7c54" } diff --git a/app/lib/generate-seed-data.js b/app/lib/generate-seed-data.js index 94965c3..d5abdbe 100644 --- a/app/lib/generate-seed-data.js +++ b/app/lib/generate-seed-data.js @@ -1,4 +1,5 @@ // app/lib/generate-seed-data.js +// node app/lib/generate-seed-data.js const { faker } = require('@faker-js/faker'); const weighted = require('weighted'); diff --git a/app/lib/generators/participant-generator.js b/app/lib/generators/participant-generator.js index 91a268a..436bc07 100644 --- a/app/lib/generators/participant-generator.js +++ b/app/lib/generators/participant-generator.js @@ -6,24 +6,20 @@ const { generateBSUAppropriateAddress } = require('./address-generator'); // Generate a UK phone number const generateUKPhoneNumber = () => { - // 80% mobile, 20% landline - if (Math.random() < 0.8) { - // Mobile number formats - const formats = [ - '07### ######', // Standard UK mobile - '07#########', // No spaces - '+447### ######' // International format - ]; - return faker.phone.number(faker.helpers.arrayElement(formats)); + const numberTypes = { + 'mobile': 0.8, + 'landline': 0.2 + } + + if (weighted.select(numberTypes) === 'mobile') { + const suffix = faker.number.int({ min: 900000, max: 900999 }); + return `07700${suffix}`; // Ofcom reserved range } else { - // Get the BSU's area code from their phone number - // Fallback to standard area codes if not available - const areaCodes = ['0118', '01865', '0114', '020']; - const areaCode = faker.helpers.arrayElement(areaCodes); - return faker.phone.number(areaCode + ' ### ####'); + const areaCode = faker.helpers.arrayElement(['0118', '01865']); + const suffix = faker.number.int({ min: 0, max: 999 }).toString().padStart(3, '0'); + return `${areaCode}4960${suffix}`; // Ofcom reserved range } }; - // Helper functions for name formatting const formatName = (person) => ({ get fullName() { @@ -96,7 +92,7 @@ const generateParticipant = ({ ethnicities, breastScreeningUnits }) => { }).toISOString(), address: generateBSUAppropriateAddress(assignedBSU), phone: generateUKPhoneNumber(), - email: `${faker.internet.userName().toLowerCase()}@example.com`, + email: `${faker.internet.username().toLowerCase()}@example.com`, ethnicGroup, ethnicBackground }, diff --git a/app/lib/utils/strings.js b/app/lib/utils/strings.js index 29eb2b7..cbfe33c 100644 --- a/app/lib/utils/strings.js +++ b/app/lib/utils/strings.js @@ -177,6 +177,22 @@ const noWrap = (input) => { return `${input}`; }; +/** + * Format phone number for display with spaces + * @param {string} phoneNumber - Raw phone number string + * @returns {string} Formatted phone number + */ +const formatPhoneNumber = (phoneNumber) => { + if (!phoneNumber) return ''; + if (typeof phoneNumber !== 'string') return phoneNumber; + + if (phoneNumber.startsWith('07')) { + return `${phoneNumber.slice(0, 5)} ${phoneNumber.slice(5)}`; + } + + return `${phoneNumber.slice(0, 4)} ${phoneNumber.slice(4, 7)} ${phoneNumber.slice(7)}`; +}; + module.exports = { addIndefiniteArticle, formatCurrency, @@ -193,4 +209,5 @@ module.exports = { startLowerCase, startsWith, stringLiteral, + formatPhoneNumber, }; diff --git a/app/views/dashboard.html b/app/views/dashboard.html index 1ae833b..63e745e 100755 --- a/app/views/dashboard.html +++ b/app/views/dashboard.html @@ -3,6 +3,7 @@ {% set pageHeading = "Dashboard" %} +{% set hideBackLink = true %} {% block pageContent %} diff --git a/app/views/participants/show.html b/app/views/participants/show.html index 82b85c1..11d05b5 100644 --- a/app/views/participants/show.html +++ b/app/views/participants/show.html @@ -70,7 +70,7 @@

Personal details

Phone
- {{ participant.demographicInformation.phone }} + {{ participant.demographicInformation.phone | formatPhoneNumber }}