22
33const { faker } = require ( '@faker-js/faker' ) ;
44const generateId = require ( '../utils/id-generator' ) ;
5- const weighted = require ( 'weighted' ) ;
6-
7- const CLINIC_TYPES = [
8- { type : 'hospital' , weight : 0.7 } ,
9- { type : 'mobile_unit' , weight : 0.3 }
10- ] ;
5+ const dayjs = require ( 'dayjs' ) ;
116
127const generateTimeSlots = ( date , config ) => {
138 const slots = [ ] ;
@@ -29,29 +24,66 @@ const generateTimeSlots = (date, config) => {
2924 return slots ;
3025} ;
3126
27+ const determineClinicStatus = ( date ) => {
28+ const now = dayjs ( ) ;
29+ const clinicDate = dayjs ( date ) ;
30+ const clinicStart = clinicDate . hour ( 8 ) ; // Assume clinic starts at 8am
31+ const clinicEnd = clinicDate . hour ( 17 ) ; // Assume clinic ends at 5pm
32+
33+ if ( clinicDate . isBefore ( now , 'day' ) ) {
34+ return 'closed' ;
35+ } else if ( clinicDate . isAfter ( now , 'day' ) ) {
36+ return 'scheduled' ;
37+ } else {
38+ // Today - check time
39+ if ( now . isBefore ( clinicStart ) ) {
40+ return 'scheduled' ;
41+ } else if ( now . isAfter ( clinicEnd ) ) {
42+ return 'closed' ;
43+ } else {
44+ return 'in_progress' ;
45+ }
46+ }
47+ } ;
48+
49+ const generateMobileSiteName = ( ) => {
50+ const sites = [
51+ "Tesco Extra Banbury" ,
52+ "Witney Community Hospital" ,
53+ "Thame Community Hospital" ,
54+ "Bicester Community Hospital" ,
55+ "Sainsbury's Kidlington" ,
56+ "Carterton Health Centre" ,
57+ "Wantage Community Hospital" ,
58+ "Tesco Faringdon" ,
59+ "Didcot Civic Hall" ,
60+ "Chipping Norton Health Centre"
61+ ] ;
62+
63+ return faker . helpers . arrayElement ( sites ) ;
64+ } ;
65+
3266// Generate multiple clinics for a BSU on a given day
3367const generateClinicsForBSU = ( { date, breastScreeningUnit, config } ) => {
3468 // Determine number of clinics for this BSU today (1-2)
3569 const numberOfClinics = Math . random ( ) < 0.3 ? 2 : 1 ;
3670
37- return Array . from ( { length : numberOfClinics } , ( ) => {
38- // If this is the second clinic for the day, make it more likely to be a mobile unit
39- const isSecondClinic = numberOfClinics === 2 ;
40- const clinicType = weighted . select (
41- CLINIC_TYPES . map ( t => t . type ) ,
42- CLINIC_TYPES . map ( t => isSecondClinic ? ( t . type === 'mobile_unit' ? 0.7 : 0.3 ) : t . weight )
43- ) ;
44-
71+ // Randomly select locations from available ones
72+ const selectedLocations = faker . helpers . arrayElements (
73+ breastScreeningUnit . locations ,
74+ { min : numberOfClinics , max : numberOfClinics }
75+ ) ;
76+
77+ return selectedLocations . map ( location => {
4578 return {
4679 id : generateId ( ) ,
4780 date : date . toISOString ( ) . split ( 'T' ) [ 0 ] ,
4881 breastScreeningUnitId : breastScreeningUnit . id ,
49- clinicType,
50- location : clinicType === 'hospital' ?
51- breastScreeningUnit . address :
52- generateMobileLocation ( breastScreeningUnit ) ,
82+ clinicType : location . type ,
83+ locationId : location . id ,
84+ siteName : location . type === 'mobile_unit' ? generateMobileSiteName ( ) : null ,
5385 slots : generateTimeSlots ( date , config ) ,
54- status : date < new Date ( ) ? 'completed' : 'scheduled' ,
86+ status : determineClinicStatus ( date ) ,
5587 staffing : {
5688 mamographers : [ ] ,
5789 radiologists : [ ] ,
@@ -64,26 +96,6 @@ const generateClinicsForBSU = ({ date, breastScreeningUnit, config }) => {
6496 } ) ;
6597} ;
6698
67- const generateMobileLocation = ( bsu ) => {
68- const locations = [
69- 'Community Centre' ,
70- 'Health Centre' ,
71- 'Leisure Centre' ,
72- 'Shopping Centre Car Park' ,
73- 'Supermarket Car Park'
74- ] ;
75-
76- const location = faker . helpers . arrayElement ( locations ) ;
77- return {
78- name : `${ faker . location . city ( ) } ${ location } ` ,
79- address : {
80- line1 : faker . location . streetAddress ( ) ,
81- city : faker . location . city ( ) ,
82- postcode : faker . location . zipCode ( '??# #??' )
83- }
84- } ;
85- } ;
86-
8799module . exports = {
88100 generateClinicsForBSU
89101} ;
0 commit comments