@@ -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,24 +86,40 @@ 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 ( )
98
103
let data = participantStore . getParticipantsList ( )
99
104
let participantIndex = data . findIndex (
100
105
val => val . pp_id === currentParticipant . pp_id
101
106
)
102
- participantStore . getInsurers ( )
103
107
// useEffect is a hook that gets called after every render/re-render. Empty array second argument prevents it from running again.
104
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
+ } ) ( )
105
122
if ( participantIndex > - 1 ) {
106
- // assign incoming participant data if available
107
123
setParticipant ( {
108
124
id : data [ participantIndex ] . id ,
109
125
firstName : data [ participantIndex ] . first_name ,
@@ -117,13 +133,17 @@ const ParticipantInfo = observer(() => {
117
133
hasInsurance : data [ participantIndex ] . is_insured ,
118
134
insuranceType : data [ participantIndex ] ,
119
135
insurer : data [ participantIndex ] . insurer ,
120
- program : data [ participantIndex ] . program ,
121
- service : data [ participantIndex ] . service ,
122
136
priority : data [ participantIndex ] . priority ,
123
137
note : data [ participantIndex ] . note ,
124
138
} )
125
139
}
126
- } , [ data , participantIndex ] )
140
+ } , [ ] )
141
+
142
+ const setProgramAndShowServices = e => {
143
+ setProgram ( e . target . value )
144
+ setShowServices ( true )
145
+ setServiceList ( e . target . value . services )
146
+ }
127
147
128
148
const createStartDate = ( ) => {
129
149
return format ( new Date ( ) , "yyyy-MM-dd" )
@@ -151,11 +171,17 @@ const ParticipantInfo = observer(() => {
151
171
is_insured : participant . hasInsurance ,
152
172
insuranceType : participant . insuranceType ,
153
173
insurer : participant . insurer ,
154
- program : participant . program ,
155
- service : participant . service ,
156
174
priority : participant . priority ,
157
175
note : participant . note ,
158
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
+ } )
159
185
participantIndex > - 1
160
186
? participantStore . updateParticipant ( )
161
187
: participantStore . createParticipant ( )
@@ -357,22 +383,23 @@ const ParticipantInfo = observer(() => {
357
383
aria-label = "insurance"
358
384
name = "hasInsurance"
359
385
className = { classes . group }
360
- value = { participant . hasInsurance }
386
+ value = { participant . hasInsurance === true ? "yes" : "no" }
361
387
onChange = { e =>
362
388
setParticipant ( {
363
389
...participant ,
364
- hasInsurance : e . target . value ,
390
+ hasInsurance :
391
+ e . target . value === "yes" ? true : false ,
365
392
} )
366
393
}
367
394
style = { { display : "inline" } }
368
395
>
369
396
< FormControlLabel
370
- value = { true }
397
+ value = "yes"
371
398
control = { < Radio /> }
372
399
label = "Yes"
373
400
/>
374
401
< FormControlLabel
375
- value = { false }
402
+ value = "no"
376
403
control = { < Radio /> }
377
404
label = "No"
378
405
/>
@@ -401,8 +428,17 @@ const ParticipantInfo = observer(() => {
401
428
id : "demo-controlled-open-select" ,
402
429
} }
403
430
>
404
- { participantStore . insurers . map ( ( insurer , index ) => (
405
- < MenuItem key = { index } > { insurer . name } </ 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 >
406
442
) ) }
407
443
</ Select >
408
444
</ FormControl >
@@ -435,21 +471,21 @@ const ParticipantInfo = observer(() => {
435
471
onClose = { handleClose . program }
436
472
onOpen = { handleOpen . program }
437
473
required
438
- value = { participant . program }
439
- onChange = { e =>
440
- setParticipant ( {
441
- ...participant ,
442
- program : e . target . value ,
443
- } )
444
- }
474
+ value = { program && program . name ? program . name : null }
475
+ onChange = { e => setProgramAndShowServices ( e ) }
445
476
inputProps = { {
446
477
name : "program" ,
447
478
id : "demo-controlled-open-select" ,
448
479
} }
449
480
>
450
- < MenuItem value = { "Program 1" } > Program 1</ MenuItem >
451
- < MenuItem value = { "Program 2" } > Program 2</ MenuItem >
452
- < 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
+ ) ) }
453
489
</ Select >
454
490
</ FormControl >
455
491
</ Grid >
@@ -458,27 +494,33 @@ const ParticipantInfo = observer(() => {
458
494
< InputLabel htmlFor = "demo-controlled-open-select" >
459
495
Select Service
460
496
</ InputLabel >
461
- < Select
462
- open = { open . service }
463
- onClose = { handleClose . service }
464
- onOpen = { handleOpen . service }
465
- required
466
- value = { participant . service }
467
- onChange = { e =>
468
- setParticipant ( {
469
- ...participant ,
470
- service : e . target . value ,
471
- } )
472
- }
473
- inputProps = { {
474
- name : "service" ,
475
- id : "demo-controlled-open-select" ,
476
- } }
477
- >
478
- < MenuItem value = { "Service 1" } > Service 1</ MenuItem >
479
- < MenuItem value = { "Service 2" } > Service 2</ MenuItem >
480
- < MenuItem value = { "Service 3" } > Service 3</ MenuItem >
481
- </ 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 }
482
524
</ FormControl >
483
525
</ Grid >
484
526
< br />
@@ -503,11 +545,11 @@ const ParticipantInfo = observer(() => {
503
545
id : "demo-controlled-open-select" ,
504
546
} }
505
547
>
506
- < MenuItem value = { "1 " } > 1 (Lowest)</ MenuItem >
507
- < MenuItem value = { "2 " } > 2</ MenuItem >
508
- < MenuItem value = { "3 " } > 3</ MenuItem >
509
- < MenuItem value = { "4 " } > 4</ MenuItem >
510
- < 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 >
511
553
</ Select >
512
554
</ FormControl >
513
555
</ Grid >
0 commit comments