Skip to content

Commit

Permalink
Update seed data, misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhorsford committed Nov 14, 2024
1 parent 0e1f97a commit 947845d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/data/session-data-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions app/data/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = [
firstName: "Jane",
lastName: "Hitchin",
role: "mamographer",
email: "[email protected]",
id: "ae7537b3-aed1-4620-87fd-9dc5b5bdc8cb",
breastScreeningUnit: "f66f2a7d-99a8-4793-8371-3d075e1a7c54"
}
Expand Down
1 change: 1 addition & 0 deletions app/lib/generate-seed-data.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
28 changes: 12 additions & 16 deletions app/lib/generators/participant-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
},
Expand Down
17 changes: 17 additions & 0 deletions app/lib/utils/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ const noWrap = (input) => {
return `<span class="app-nowrap">${input}</span>`;
};

/**
* 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,
Expand All @@ -193,4 +209,5 @@ module.exports = {
startLowerCase,
startsWith,
stringLiteral,
formatPhoneNumber,
};
1 change: 1 addition & 0 deletions app/views/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

{% set pageHeading = "Dashboard" %}

{% set hideBackLink = true %}

{% block pageContent %}

Expand Down
2 changes: 1 addition & 1 deletion app/views/participants/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h2 class="nhsuk-heading-m">Personal details</h2>
<div class="nhsuk-summary-list__row">
<dt class="nhsuk-summary-list__key">Phone</dt>
<dd class="nhsuk-summary-list__value">
{{ participant.demographicInformation.phone }}
{{ participant.demographicInformation.phone | formatPhoneNumber }}
</dd>
</div>
<div class="nhsuk-summary-list__row">
Expand Down

0 comments on commit 947845d

Please sign in to comment.