@@ -74,7 +74,7 @@ const ParticipantInfo = observer(() => {
74
74
const rootStore = useContext ( rootStoreContext )
75
75
const participantStore = rootStore . ParticipantStore
76
76
const [ participant , setParticipant ] = React . useState ( {
77
- id : 0 ,
77
+ id : null ,
78
78
firstName : "" ,
79
79
lastName : "" ,
80
80
lastFourSSN : 0 ,
@@ -86,12 +86,17 @@ const ParticipantInfo = observer(() => {
86
86
hasInsurance : false ,
87
87
insuranceType : "" ,
88
88
insurer : "" ,
89
- program : "" ,
90
- service : "" ,
91
89
priority : "" ,
92
90
note : "" ,
93
91
} )
94
92
const [ open , setOpen ] = React . useState ( "" )
93
+ const [ insurers , setInsurers ] = React . useState ( [ ] )
94
+ const [ programList , setProgramList ] = React . useState ( [ ] )
95
+ const [ program , setProgram ] = React . useState ( { } )
96
+ const [ showServices , setShowServices ] = React . useState ( false )
97
+ const [ serviceList , setServiceList ] = React . useState ( [ ] )
98
+ const [ service , setService ] = React . useState ( { } )
99
+ const [ prevVisit , setPrevVisit ] = React . useState ( { } )
95
100
const history = useHistory ( )
96
101
97
102
let currentParticipant = participantStore . getParticipant ( )
@@ -101,8 +106,20 @@ const ParticipantInfo = observer(() => {
101
106
)
102
107
// useEffect is a hook that gets called after every render/re-render. Empty array second argument prevents it from running again.
103
108
useEffect ( ( ) => {
109
+ ; ( async ( ) => {
110
+ await participantStore . getInsurers ( )
111
+ await participantStore . getPrograms ( )
112
+ if ( participantIndex > - 1 ) {
113
+ await participantStore . getVisits ( )
114
+ let v = await participantStore . getVisitsList ( )
115
+ let result = v . find ( val => val . participant . id === currentParticipant . id )
116
+ // eslint-disable-next-line no-console
117
+ setPrevVisit ( result )
118
+ }
119
+ setInsurers ( await participantStore . getInsuranceList ( ) )
120
+ setProgramList ( await participantStore . getProgramList ( ) )
121
+ } ) ( )
104
122
if ( participantIndex > - 1 ) {
105
- // assign incoming participant data if available
106
123
setParticipant ( {
107
124
id : data [ participantIndex ] . id ,
108
125
firstName : data [ participantIndex ] . first_name ,
@@ -116,14 +133,18 @@ const ParticipantInfo = observer(() => {
116
133
hasInsurance : data [ participantIndex ] . is_insured ,
117
134
insuranceType : data [ participantIndex ] ,
118
135
insurer : data [ participantIndex ] . insurer ,
119
- program : data [ participantIndex ] . program ,
120
- service : data [ participantIndex ] . service ,
121
136
priority : data [ participantIndex ] . priority ,
122
137
note : data [ participantIndex ] . note ,
123
138
} )
124
139
}
125
140
} , [ ] )
126
141
142
+ const setProgramAndShowServices = e => {
143
+ setProgram ( e . target . value )
144
+ setShowServices ( true )
145
+ setServiceList ( e . target . value . services )
146
+ }
147
+
127
148
const createStartDate = ( ) => {
128
149
return format ( new Date ( ) , "yyyy-MM-dd" )
129
150
}
@@ -150,11 +171,17 @@ const ParticipantInfo = observer(() => {
150
171
is_insured : participant . hasInsurance ,
151
172
insuranceType : participant . insuranceType ,
152
173
insurer : participant . insurer ,
153
- program : participant . program ,
154
- service : participant . service ,
155
174
priority : participant . priority ,
156
175
note : participant . note ,
157
176
} )
177
+ participantStore . setVisit ( {
178
+ id : prevVisit && prevVisit . id ? prevVisit . id : null ,
179
+ participant : participant . id ,
180
+ program : program . id ,
181
+ service : service . id ,
182
+ notes : participant . note ,
183
+ urgency : participant . priority ,
184
+ } )
158
185
participantIndex > - 1
159
186
? participantStore . updateParticipant ( )
160
187
: participantStore . createParticipant ( )
@@ -356,22 +383,23 @@ const ParticipantInfo = observer(() => {
356
383
aria-label = "insurance"
357
384
name = "hasInsurance"
358
385
className = { classes . group }
359
- value = { participant . hasInsurance }
386
+ value = { participant . hasInsurance === true ? "yes" : "no" }
360
387
onChange = { e =>
361
388
setParticipant ( {
362
389
...participant ,
363
- hasInsurance : e . target . value ,
390
+ hasInsurance :
391
+ e . target . value === "yes" ? true : false ,
364
392
} )
365
393
}
366
394
style = { { display : "inline" } }
367
395
>
368
396
< FormControlLabel
369
- value = { true }
397
+ value = "yes"
370
398
control = { < Radio /> }
371
399
label = "Yes"
372
400
/>
373
401
< FormControlLabel
374
- value = { false }
402
+ value = "no"
375
403
control = { < Radio /> }
376
404
label = "No"
377
405
/>
@@ -400,18 +428,18 @@ const ParticipantInfo = observer(() => {
400
428
id : "demo-controlled-open-select" ,
401
429
} }
402
430
>
403
- < MenuItem value = "" >
404
- < em > None </ em >
405
- </ MenuItem >
406
- < MenuItem value = { "Insurance Plan 1" } >
407
- Insurance Plan 1
408
- </ MenuItem >
409
- < MenuItem value = { "Insurance Plan 2" } >
410
- Insurance Plan 2
411
- </ MenuItem >
412
- < MenuItem value = { "Insurance Plan 3" } >
413
- Insurance Plan 3
414
- </ MenuItem >
431
+ { insurers . map ( ( company , index ) => (
432
+ < MenuItem
433
+ key = { index }
434
+ value = {
435
+ insurers && insurers . length > 0 ? company : null
436
+ }
437
+ >
438
+ { insurers && insurers . length > 0
439
+ ? company . name
440
+ : "" }
441
+ </ MenuItem >
442
+ ) ) }
415
443
</ Select >
416
444
</ FormControl >
417
445
</ Grid >
@@ -443,21 +471,21 @@ const ParticipantInfo = observer(() => {
443
471
onClose = { handleClose . program }
444
472
onOpen = { handleOpen . program }
445
473
required
446
- value = { participant . program }
447
- onChange = { e =>
448
- setParticipant ( {
449
- ...participant ,
450
- program : e . target . value ,
451
- } )
452
- }
474
+ value = { program && program . name ? program . name : null }
475
+ onChange = { e => setProgramAndShowServices ( e ) }
453
476
inputProps = { {
454
477
name : "program" ,
455
478
id : "demo-controlled-open-select" ,
456
479
} }
457
480
>
458
- < MenuItem value = { "Program 1" } > Program 1</ MenuItem >
459
- < MenuItem value = { "Program 2" } > Program 2</ MenuItem >
460
- < MenuItem value = { "Program 3" } > Program 3</ MenuItem >
481
+ { programList . map ( ( p , index ) => (
482
+ < MenuItem
483
+ key = { index }
484
+ value = { programList && programList . length > 0 ? p : 0 }
485
+ >
486
+ { programList && programList . length > 0 ? p . name : "" }
487
+ </ MenuItem >
488
+ ) ) }
461
489
</ Select >
462
490
</ FormControl >
463
491
</ Grid >
@@ -466,27 +494,33 @@ const ParticipantInfo = observer(() => {
466
494
< InputLabel htmlFor = "demo-controlled-open-select" >
467
495
Select Service
468
496
</ InputLabel >
469
- < Select
470
- open = { open . service }
471
- onClose = { handleClose . service }
472
- onOpen = { handleOpen . service }
473
- required
474
- value = { participant . service }
475
- onChange = { e =>
476
- setParticipant ( {
477
- ...participant ,
478
- service : e . target . value ,
479
- } )
480
- }
481
- inputProps = { {
482
- name : "service" ,
483
- id : "demo-controlled-open-select" ,
484
- } }
485
- >
486
- < MenuItem value = { "Service 1" } > Service 1</ MenuItem >
487
- < MenuItem value = { "Service 2" } > Service 2</ MenuItem >
488
- < MenuItem value = { "Service 3" } > Service 3</ MenuItem >
489
- </ Select >
497
+ { showServices ? (
498
+ < Select
499
+ open = { open . service }
500
+ onClose = { handleClose . service }
501
+ onOpen = { handleOpen . service }
502
+ required
503
+ value = { service && service . name ? service . name : null }
504
+ onChange = { e => setService ( e . target . value ) }
505
+ inputProps = { {
506
+ name : "service" ,
507
+ id : "demo-controlled-open-select" ,
508
+ } }
509
+ >
510
+ { serviceList . map ( ( s , index ) => (
511
+ < MenuItem
512
+ key = { index }
513
+ value = {
514
+ serviceList && serviceList . length > 0 ? s : 0
515
+ }
516
+ >
517
+ { serviceList && serviceList . length > 0
518
+ ? s . name
519
+ : "" }
520
+ </ MenuItem >
521
+ ) ) }
522
+ </ Select >
523
+ ) : null }
490
524
</ FormControl >
491
525
</ Grid >
492
526
< br />
@@ -511,11 +545,11 @@ const ParticipantInfo = observer(() => {
511
545
id : "demo-controlled-open-select" ,
512
546
} }
513
547
>
514
- < MenuItem value = { "1 " } > 1 (Lowest)</ MenuItem >
515
- < MenuItem value = { "2 " } > 2</ MenuItem >
516
- < MenuItem value = { "3 " } > 3</ MenuItem >
517
- < MenuItem value = { "4 " } > 4</ MenuItem >
518
- < MenuItem value = { "5 " } > 5 (Highest)</ MenuItem >
548
+ < MenuItem value = { "_1 " } > 1 (Lowest)</ MenuItem >
549
+ < MenuItem value = { "_2 " } > 2</ MenuItem >
550
+ < MenuItem value = { "_3 " } > 3</ MenuItem >
551
+ < MenuItem value = { "_4 " } > 4</ MenuItem >
552
+ < MenuItem value = { "_5 " } > 5 (Highest)</ MenuItem >
519
553
</ Select >
520
554
</ FormControl >
521
555
</ Grid >
0 commit comments