Skip to content

Commit 07513cc

Browse files
Add assessment clinic type, clean up code
1 parent ed9e67e commit 07513cc

File tree

11 files changed

+235
-165
lines changed

11 files changed

+235
-165
lines changed

app/config.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@ module.exports = {
3838
},
3939

4040
screening: {
41-
// Outcomes and their probabilities
4241
outcomes: {
43-
clear: 0.95,
44-
needs_further_tests: 0.04,
45-
cancer_detected: 0.01
46-
},
47-
48-
// Standard images taken during screening
49-
standardImages: ['RCC', 'LCC', 'RMLO', 'LMLO']
42+
screening: {
43+
'clear': 0.95,
44+
'needs_further_tests': 0.04,
45+
'cancer_detected': 0.01
46+
},
47+
assessment: {
48+
'clear': 0.4,
49+
'needs_further_tests': 0.45,
50+
'cancer_detected': 0.15
51+
}
52+
}
5053
},
5154

5255
// Data generation settings

app/data/breast-screening-units.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = [
1515
},
1616
phoneNumber: "01865235621",
1717
abbreviation: "OXF",
18+
serviceTypes: ['screening', 'assessment'], // Can do both
1819
// Default operating hours for the BSU
1920
sessionPatterns: [
2021
{
@@ -62,10 +63,11 @@ module.exports = [
6263
// },
6364
{
6465
id: "2yt5dukk", // Must be hardcoded so it matches generated data
65-
name: "Mobile Unit WX71 HCP",
66+
name: "Mobile Unit JA1 CP7",
6667
type: "mobile_unit",
6768
isMainSite: false,
68-
registration: "WX71 HCP",
69+
serviceTypes: ['screening'], // Can only do screening
70+
registration: "JA1 CP7",
6971
// Override BSU session patterns for this location
7072
sessionPatterns: [
7173
{
@@ -82,6 +84,7 @@ module.exports = [
8284
name: "Mobile Unit WX71 HCR",
8385
type: "mobile_unit",
8486
isMainSite: false,
87+
serviceTypes: ['screening'], // Can only do screening
8588
registration: "WX71 HCR",
8689
// Override BSU session patterns for this location
8790
sessionPatterns: [

app/lib/generate-seed-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const generateData = async () => {
5757
slot,
5858
participant,
5959
clinic,
60-
outcomeWeights: config.screening.outcomes
60+
outcomeWeights: config.screening.outcomes[clinic.serviceType]
6161
});
6262
});
6363

app/lib/generators/clinic-generator.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
const { faker } = require('@faker-js/faker');
44
const generateId = require('../utils/id-generator');
55
const dayjs = require('dayjs');
6+
const weighted = require('weighted');
67
const config = require('../../config');
78

9+
const determineServiceType = (location, breastScreeningUnit) => {
10+
// First check location-specific service types
11+
const serviceTypes = location.serviceTypes || breastScreeningUnit.serviceTypes;
812

9-
const generateTimeSlots = (date, sessionTimes) => {
13+
// If still no service types, default to screening
14+
if (!serviceTypes) {
15+
return 'screening';
16+
}
17+
18+
// If location/BSU only supports one service type, use that
19+
if (serviceTypes.length === 1) {
20+
return serviceTypes[0];
21+
}
22+
23+
// For locations that can do both, weight towards screening
24+
return weighted.select({
25+
'screening': 0.8,
26+
'assessment': 0.2
27+
});
28+
};
29+
30+
const generateTimeSlots = (date, sessionTimes, serviceType) => {
1031
const { slotDurationMinutes } = config.clinics;
1132

1233
const slots = [];
@@ -19,8 +40,8 @@ const generateTimeSlots = (date, sessionTimes) => {
1940
slots.push({
2041
id: slotId,
2142
dateTime: new Date(currentTime).toISOString(),
22-
type: 'screening',
23-
capacity: 2,
43+
type: serviceType, // Use the clinic's service type
44+
capacity: serviceType === 'assessment' ? 1 : 2, // Assessment clinics don't double book
2445
bookedCount: 0,
2546
period: `${sessionTimes.startTime}-${sessionTimes.endTime}`
2647
});
@@ -66,13 +87,15 @@ const determineSessionType = (sessionTimes) => {
6687
};
6788

6889
const generateClinic = (date, location, breastScreeningUnit, sessionTimes) => {
69-
const slots = generateTimeSlots(date, sessionTimes);
90+
const serviceType = determineServiceType(location, breastScreeningUnit);
91+
const slots = generateTimeSlots(date, sessionTimes, serviceType);
7092

7193
return {
7294
id: generateId(),
7395
date: date.toISOString().split('T')[0],
7496
breastScreeningUnitId: breastScreeningUnit.id,
7597
clinicType: location.type,
98+
serviceType,
7699
locationId: location.id,
77100
siteName: location.type === 'mobile_unit' ? generateMobileSiteName() : null,
78101
slots,
@@ -83,9 +106,9 @@ const generateClinic = (date, location, breastScreeningUnit, sessionTimes) => {
83106
support: []
84107
},
85108
targetCapacity: {
86-
bookingPercent: config.clinics.targetBookingPercent,
87-
attendancePercent: config.clinics.targetAttendancePercent,
88-
totalSlots: slots.length * 2
109+
bookingPercent: serviceType === 'assessment' ? 100 : config.clinics.targetBookingPercent,
110+
attendancePercent: serviceType === 'assessment' ? 95 : config.clinics.targetAttendancePercent,
111+
totalSlots: slots.length * (serviceType === 'assessment' ? 1 : 2)
89112
},
90113
notes: null,
91114
sessionTimes,

0 commit comments

Comments
 (0)