Skip to content

Commit d5134c5

Browse files
authored
Merge pull request #204 from CodeForPhilly/US-change-name-adding-insurers-services-and-programs
Us change name adding insurers services and programs
2 parents 4c43395 + e8e207f commit d5134c5

File tree

6 files changed

+239
-64
lines changed

6 files changed

+239
-64
lines changed

frontend/src/api/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
createVisits,
1616
patchVisit,
1717
} from "./visitEndpoints"
18+
import { getInsurers } from "./insurersEndpoints"
19+
import { getPrograms } from "./programEndpoints"
1820

1921
const create = () => {
2022
const api = apisauce.create({
@@ -44,6 +46,8 @@ const create = () => {
4446
updateVisits: updateVisits(api),
4547
createVisits: createVisits(api),
4648
patchVisit: patchVisit(api),
49+
getInsurers: getInsurers(api),
50+
getPrograms: getPrograms(api),
4751
}
4852
}
4953

frontend/src/api/insurersEndpoints.js

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

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 & 60 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,12 +86,17 @@ 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()
@@ -101,8 +106,20 @@ const ParticipantInfo = observer(() => {
101106
)
102107
// useEffect is a hook that gets called after every render/re-render. Empty array second argument prevents it from running again.
103108
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+
})()
104122
if (participantIndex > -1) {
105-
// assign incoming participant data if available
106123
setParticipant({
107124
id: data[participantIndex].id,
108125
firstName: data[participantIndex].first_name,
@@ -116,14 +133,18 @@ const ParticipantInfo = observer(() => {
116133
hasInsurance: data[participantIndex].is_insured,
117134
insuranceType: data[participantIndex],
118135
insurer: data[participantIndex].insurer,
119-
program: data[participantIndex].program,
120-
service: data[participantIndex].service,
121136
priority: data[participantIndex].priority,
122137
note: data[participantIndex].note,
123138
})
124139
}
125140
}, [])
126141

142+
const setProgramAndShowServices = e => {
143+
setProgram(e.target.value)
144+
setShowServices(true)
145+
setServiceList(e.target.value.services)
146+
}
147+
127148
const createStartDate = () => {
128149
return format(new Date(), "yyyy-MM-dd")
129150
}
@@ -150,11 +171,17 @@ const ParticipantInfo = observer(() => {
150171
is_insured: participant.hasInsurance,
151172
insuranceType: participant.insuranceType,
152173
insurer: participant.insurer,
153-
program: participant.program,
154-
service: participant.service,
155174
priority: participant.priority,
156175
note: participant.note,
157176
})
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+
})
158185
participantIndex > -1
159186
? participantStore.updateParticipant()
160187
: participantStore.createParticipant()
@@ -356,22 +383,23 @@ const ParticipantInfo = observer(() => {
356383
aria-label="insurance"
357384
name="hasInsurance"
358385
className={classes.group}
359-
value={participant.hasInsurance}
386+
value={participant.hasInsurance === true ? "yes" : "no"}
360387
onChange={e =>
361388
setParticipant({
362389
...participant,
363-
hasInsurance: e.target.value,
390+
hasInsurance:
391+
e.target.value === "yes" ? true : false,
364392
})
365393
}
366394
style={{ display: "inline" }}
367395
>
368396
<FormControlLabel
369-
value={true}
397+
value="yes"
370398
control={<Radio />}
371399
label="Yes"
372400
/>
373401
<FormControlLabel
374-
value={false}
402+
value="no"
375403
control={<Radio />}
376404
label="No"
377405
/>
@@ -400,18 +428,18 @@ const ParticipantInfo = observer(() => {
400428
id: "demo-controlled-open-select",
401429
}}
402430
>
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+
))}
415443
</Select>
416444
</FormControl>
417445
</Grid>
@@ -443,21 +471,21 @@ const ParticipantInfo = observer(() => {
443471
onClose={handleClose.program}
444472
onOpen={handleOpen.program}
445473
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)}
453476
inputProps={{
454477
name: "program",
455478
id: "demo-controlled-open-select",
456479
}}
457480
>
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+
))}
461489
</Select>
462490
</FormControl>
463491
</Grid>
@@ -466,27 +494,33 @@ const ParticipantInfo = observer(() => {
466494
<InputLabel htmlFor="demo-controlled-open-select">
467495
Select Service
468496
</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}
490524
</FormControl>
491525
</Grid>
492526
<br />
@@ -511,11 +545,11 @@ const ParticipantInfo = observer(() => {
511545
id: "demo-controlled-open-select",
512546
}}
513547
>
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>
519553
</Select>
520554
</FormControl>
521555
</Grid>

frontend/src/components/ParticipantsList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const ParticipantsList = observer(() => {
5050
useEffect(() => {
5151
setIsLoading(true)
5252
participantsStore.getParticipants()
53+
participantsStore.getInsurers()
5354
setIsLoading(false)
5455
}, [participantsStore])
5556

0 commit comments

Comments
 (0)