Skip to content

Commit 976b438

Browse files
author
Chris Medykiewicz
committed
US adding insurers programs and services
1 parent 5658399 commit 976b438

File tree

5 files changed

+224
-61
lines changed

5 files changed

+224
-61
lines changed

frontend/src/api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
patchVisit,
1717
} from "./visitEndpoints"
1818
import { getInsurers } from "./insurersEndpoints"
19+
import { getPrograms } from "./programEndpoints"
1920

2021
const create = () => {
2122
const api = apisauce.create({
@@ -46,6 +47,7 @@ const create = () => {
4647
createVisits: createVisits(api),
4748
patchVisit: patchVisit(api),
4849
getInsurers: getInsurers(api),
50+
getPrograms: getPrograms(api),
4951
}
5052
}
5153

frontend/src/api/programEndpoints.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const getPrograms = api => async () => await api.get("programs/")

frontend/src/components/ParticipantInfo.js

Lines changed: 94 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const ParticipantInfo = observer(() => {
7474
const rootStore = useContext(rootStoreContext)
7575
const participantStore = rootStore.ParticipantStore
7676
const [participant, setParticipant] = React.useState({
77-
id: 0,
77+
id: null,
7878
firstName: "",
7979
lastName: "",
8080
lastFourSSN: 0,
@@ -86,24 +86,40 @@ const ParticipantInfo = observer(() => {
8686
hasInsurance: false,
8787
insuranceType: "",
8888
insurer: "",
89-
program: "",
90-
service: "",
9189
priority: "",
9290
note: "",
9391
})
9492
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({})
95100
const history = useHistory()
96101

97102
let currentParticipant = participantStore.getParticipant()
98103
let data = participantStore.getParticipantsList()
99104
let participantIndex = data.findIndex(
100105
val => val.pp_id === currentParticipant.pp_id
101106
)
102-
participantStore.getInsurers()
103107
// useEffect is a hook that gets called after every render/re-render. Empty array second argument prevents it from running again.
104108
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+
})()
105122
if (participantIndex > -1) {
106-
// assign incoming participant data if available
107123
setParticipant({
108124
id: data[participantIndex].id,
109125
firstName: data[participantIndex].first_name,
@@ -117,13 +133,17 @@ const ParticipantInfo = observer(() => {
117133
hasInsurance: data[participantIndex].is_insured,
118134
insuranceType: data[participantIndex],
119135
insurer: data[participantIndex].insurer,
120-
program: data[participantIndex].program,
121-
service: data[participantIndex].service,
122136
priority: data[participantIndex].priority,
123137
note: data[participantIndex].note,
124138
})
125139
}
126-
}, [data, participantIndex])
140+
}, [])
141+
142+
const setProgramAndShowServices = e => {
143+
setProgram(e.target.value)
144+
setShowServices(true)
145+
setServiceList(e.target.value.services)
146+
}
127147

128148
const createStartDate = () => {
129149
return format(new Date(), "yyyy-MM-dd")
@@ -151,11 +171,17 @@ const ParticipantInfo = observer(() => {
151171
is_insured: participant.hasInsurance,
152172
insuranceType: participant.insuranceType,
153173
insurer: participant.insurer,
154-
program: participant.program,
155-
service: participant.service,
156174
priority: participant.priority,
157175
note: participant.note,
158176
})
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+
})
159185
participantIndex > -1
160186
? participantStore.updateParticipant()
161187
: participantStore.createParticipant()
@@ -357,22 +383,23 @@ const ParticipantInfo = observer(() => {
357383
aria-label="insurance"
358384
name="hasInsurance"
359385
className={classes.group}
360-
value={participant.hasInsurance}
386+
value={participant.hasInsurance === true ? "yes" : "no"}
361387
onChange={e =>
362388
setParticipant({
363389
...participant,
364-
hasInsurance: e.target.value,
390+
hasInsurance:
391+
e.target.value === "yes" ? true : false,
365392
})
366393
}
367394
style={{ display: "inline" }}
368395
>
369396
<FormControlLabel
370-
value={true}
397+
value="yes"
371398
control={<Radio />}
372399
label="Yes"
373400
/>
374401
<FormControlLabel
375-
value={false}
402+
value="no"
376403
control={<Radio />}
377404
label="No"
378405
/>
@@ -401,8 +428,17 @@ const ParticipantInfo = observer(() => {
401428
id: "demo-controlled-open-select",
402429
}}
403430
>
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>
406442
))}
407443
</Select>
408444
</FormControl>
@@ -435,21 +471,21 @@ const ParticipantInfo = observer(() => {
435471
onClose={handleClose.program}
436472
onOpen={handleOpen.program}
437473
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)}
445476
inputProps={{
446477
name: "program",
447478
id: "demo-controlled-open-select",
448479
}}
449480
>
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+
))}
453489
</Select>
454490
</FormControl>
455491
</Grid>
@@ -458,27 +494,33 @@ const ParticipantInfo = observer(() => {
458494
<InputLabel htmlFor="demo-controlled-open-select">
459495
Select Service
460496
</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}
482524
</FormControl>
483525
</Grid>
484526
<br />
@@ -503,11 +545,11 @@ const ParticipantInfo = observer(() => {
503545
id: "demo-controlled-open-select",
504546
}}
505547
>
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>
511553
</Select>
512554
</FormControl>
513555
</Grid>

frontend/src/components/ParticipantsList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const ParticipantsList = observer(() => {
2222
useEffect(() => {
2323
setIsLoading(true)
2424
participantsStore.getParticipants()
25+
participantsStore.getInsurers()
2526
setIsLoading(false)
2627
}, [participantsStore])
2728

0 commit comments

Comments
 (0)