Skip to content

Commit 947845d

Browse files
Update seed data, misc cleanup
1 parent 0e1f97a commit 947845d

File tree

7 files changed

+34
-18
lines changed

7 files changed

+34
-18
lines changed

app/data/session-data-defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (fs.existsSync(generationInfoPath)) {
4040
// Generate or load data
4141
if (needsRegeneration) {
4242
console.log('Generating new seed data...');
43-
require('../lib/generate-seed-data.js');
43+
require('../lib/generate-seed-data.js')();
4444

4545
// Save generation info
4646
fs.writeFileSync(

app/data/users.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = [
33
firstName: "Jane",
44
lastName: "Hitchin",
55
role: "mamographer",
6+
67
id: "ae7537b3-aed1-4620-87fd-9dc5b5bdc8cb",
78
breastScreeningUnit: "f66f2a7d-99a8-4793-8371-3d075e1a7c54"
89
}

app/lib/generate-seed-data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// app/lib/generate-seed-data.js
2+
// node app/lib/generate-seed-data.js
23

34
const { faker } = require('@faker-js/faker');
45
const weighted = require('weighted');

app/lib/generators/participant-generator.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,20 @@ const { generateBSUAppropriateAddress } = require('./address-generator');
66

77
// Generate a UK phone number
88
const generateUKPhoneNumber = () => {
9-
// 80% mobile, 20% landline
10-
if (Math.random() < 0.8) {
11-
// Mobile number formats
12-
const formats = [
13-
'07### ######', // Standard UK mobile
14-
'07#########', // No spaces
15-
'+447### ######' // International format
16-
];
17-
return faker.phone.number(faker.helpers.arrayElement(formats));
9+
const numberTypes = {
10+
'mobile': 0.8,
11+
'landline': 0.2
12+
}
13+
14+
if (weighted.select(numberTypes) === 'mobile') {
15+
const suffix = faker.number.int({ min: 900000, max: 900999 });
16+
return `07700${suffix}`; // Ofcom reserved range
1817
} else {
19-
// Get the BSU's area code from their phone number
20-
// Fallback to standard area codes if not available
21-
const areaCodes = ['0118', '01865', '0114', '020'];
22-
const areaCode = faker.helpers.arrayElement(areaCodes);
23-
return faker.phone.number(areaCode + ' ### ####');
18+
const areaCode = faker.helpers.arrayElement(['0118', '01865']);
19+
const suffix = faker.number.int({ min: 0, max: 999 }).toString().padStart(3, '0');
20+
return `${areaCode}4960${suffix}`; // Ofcom reserved range
2421
}
2522
};
26-
2723
// Helper functions for name formatting
2824
const formatName = (person) => ({
2925
get fullName() {
@@ -96,7 +92,7 @@ const generateParticipant = ({ ethnicities, breastScreeningUnits }) => {
9692
}).toISOString(),
9793
address: generateBSUAppropriateAddress(assignedBSU),
9894
phone: generateUKPhoneNumber(),
99-
email: `${faker.internet.userName().toLowerCase()}@example.com`,
95+
email: `${faker.internet.username().toLowerCase()}@example.com`,
10096
ethnicGroup,
10197
ethnicBackground
10298
},

app/lib/utils/strings.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ const noWrap = (input) => {
177177
return `<span class="app-nowrap">${input}</span>`;
178178
};
179179

180+
/**
181+
* Format phone number for display with spaces
182+
* @param {string} phoneNumber - Raw phone number string
183+
* @returns {string} Formatted phone number
184+
*/
185+
const formatPhoneNumber = (phoneNumber) => {
186+
if (!phoneNumber) return '';
187+
if (typeof phoneNumber !== 'string') return phoneNumber;
188+
189+
if (phoneNumber.startsWith('07')) {
190+
return `${phoneNumber.slice(0, 5)} ${phoneNumber.slice(5)}`;
191+
}
192+
193+
return `${phoneNumber.slice(0, 4)} ${phoneNumber.slice(4, 7)} ${phoneNumber.slice(7)}`;
194+
};
195+
180196
module.exports = {
181197
addIndefiniteArticle,
182198
formatCurrency,
@@ -193,4 +209,5 @@ module.exports = {
193209
startLowerCase,
194210
startsWith,
195211
stringLiteral,
212+
formatPhoneNumber,
196213
};

app/views/dashboard.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
{% set pageHeading = "Dashboard" %}
55

6+
{% set hideBackLink = true %}
67

78
{% block pageContent %}
89

app/views/participants/show.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ <h2 class="nhsuk-heading-m">Personal details</h2>
7070
<div class="nhsuk-summary-list__row">
7171
<dt class="nhsuk-summary-list__key">Phone</dt>
7272
<dd class="nhsuk-summary-list__value">
73-
{{ participant.demographicInformation.phone }}
73+
{{ participant.demographicInformation.phone | formatPhoneNumber }}
7474
</dd>
7575
</div>
7676
<div class="nhsuk-summary-list__row">

0 commit comments

Comments
 (0)