22
33const { faker } = require ( '@faker-js/faker' )
44const weighted = require ( 'weighted' )
5+ const dayjs = require ( 'dayjs' )
56
6- // Example pregnancy details
7- const PREGNANCY_DETAILS = [
8- 'due in November' ,
9- 'due in December' ,
10- 'due in January' ,
11- 'due next month' ,
12- '8 weeks pregnant' ,
13- '12 weeks pregnant' ,
14- '20 weeks pregnant' ,
15- '30 weeks pregnant'
16- ]
17-
18- // Example recent pregnancy details
19- const RECENT_PREGNANCY_DETAILS = [
20- 'gave birth two weeks ago' ,
21- 'gave birth one month ago' ,
22- 'gave birth six weeks ago' ,
23- 'gave birth two months ago' ,
24- 'gave birth three months ago'
25- ]
26-
27- // Example breastfeeding durations
28- const BREASTFEEDING_DURATIONS = [
29- 'since January' ,
30- 'since March' ,
31- 'for 2 weeks' ,
32- 'for 6 weeks' ,
33- 'for 3 months' ,
34- 'for 6 months' ,
35- 'for 1 year'
36- ]
7+ // Generate a past date in 'MMMM YYYY' format
8+ const randomPastDate = ( minMonthsAgo , maxMonthsAgo ) => {
9+ const monthsAgo = faker . number . int ( { min : minMonthsAgo , max : maxMonthsAgo } )
10+ return dayjs ( ) . subtract ( monthsAgo , 'month' ) . format ( 'MMMM YYYY' )
11+ }
3712
38- // Example recent breastfeeding stopped
39- const RECENTLY_STOPPED_BREASTFEEDING = [
40- 'two weeks ago' ,
41- 'one month ago' ,
42- 'two months ago' ,
43- 'three months ago' ,
44- 'stopped last week'
45- ]
13+ // Generate a future date in 'MMMM YYYY' format
14+ const randomFutureDate = ( minMonthsAhead , maxMonthsAhead ) => {
15+ const monthsAhead = faker . number . int ( { min : minMonthsAhead , max : maxMonthsAhead } )
16+ return dayjs ( ) . add ( monthsAhead , 'month' ) . format ( 'MMMM YYYY' )
17+ }
4618
4719/**
4820 * Generate pregnancy and breastfeeding information
@@ -70,10 +42,12 @@ const generatePregnancyAndBreastfeeding = (options = {}) => {
7042
7143 // Add conditional fields based on pregnancy status
7244 if ( info . pregnancyStatus === 'yes' ) {
73- info . currentlyPregnantDetails = faker . helpers . arrayElement ( PREGNANCY_DETAILS )
45+ // Due date 1-9 months in future
46+ info . pregnancyDueDate = randomFutureDate ( 1 , 9 )
7447 }
7548 else if ( info . pregnancyStatus === 'noButRecently' ) {
76- info . recentlyPregnantDetails = faker . helpers . arrayElement ( RECENT_PREGNANCY_DETAILS )
49+ // Pregnancy ended 1-5 months ago
50+ info . pregnancyEndDate = randomPastDate ( 1 , 5 )
7751 }
7852
7953 // Weighted selection of breastfeeding status
@@ -97,10 +71,12 @@ const generatePregnancyAndBreastfeeding = (options = {}) => {
9771
9872 // Add conditional fields based on breastfeeding status
9973 if ( info . breastfeedingStatus === 'yes' ) {
100- info . currentlyBreastfeedingDuration = faker . helpers . arrayElement ( BREASTFEEDING_DURATIONS )
74+ // Started breastfeeding 2 weeks to 18 months ago
75+ info . breastfeedingStartDate = randomPastDate ( 0 , 18 )
10176 }
10277 else if ( info . breastfeedingStatus === 'recentlyStopped' ) {
103- info . recentlyBreastfeedingDuration = faker . helpers . arrayElement ( RECENTLY_STOPPED_BREASTFEEDING )
78+ // Stopped breastfeeding 1-4 months ago
79+ info . breastfeedingStopDate = randomPastDate ( 1 , 4 )
10480 }
10581
10682 return info
0 commit comments