33const { faker } = require ( '@faker-js/faker' ) ;
44const generateId = require ( '../utils/id-generator' ) ;
55const dayjs = require ( 'dayjs' ) ;
6+ const weighted = require ( 'weighted' ) ;
67const 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
6889const 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