Skip to content

Commit b1f208c

Browse files
authored
US258: create visit from pre-existing participant (#261)
1 parent a4d4b3f commit b1f208c

File tree

5 files changed

+174
-118
lines changed

5 files changed

+174
-118
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const getFrontDeskEvent = api => async id =>
2-
await api.get(`front-desk-events/${id}/`)
2+
await api.get(`/front-desk-events/${id}/`)
33

44
export const postFrontDeskEvent = api => async data =>
5-
await api.post("front-desk-events/", data)
5+
await api.post("/front-desk-events/", data)
66

77
export const patchFrontDeskEvent = api => async (id, data) =>
8-
await api.patch(`front-desk-events/${id}/`, data)
8+
await api.patch(`/front-desk-events/${id}/`, data)

frontend/src/components/ParticipantInfo.js

Lines changed: 137 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,45 @@ const ParticipantInfo = observer(() => {
8282
const rootStore = useContext(rootStoreContext)
8383
// particiant store derived from root store
8484
const participantStore = rootStore.ParticipantStore
85+
// TODO: refactor after v1.0.0 release
86+
const queueStore = rootStore.QueueStore
8587
// set up history for routing pushes
8688
const history = useHistory()
8789
// get existing participant if applicable else its undefined
8890
const existingParticipant = toJS(participantStore.participant)
8991
// get existing visit if applicable else its undefined
9092
const existingVisit = toJS(participantStore.visit)
9193
const insurers = toJS(participantStore.insurers)
92-
const programList = toJS(participantStore.programs)
94+
let programList = toJS(participantStore.programs)
9395
const serviceList = toJS(participantStore.services)
9496

97+
// TODO: refactor after v1.0.0 release
98+
if (existingParticipant.id && !existingVisit.id) {
99+
let filterThesePrograms = []
100+
queueStore.participantWithPrograms.forEach(currentparticipantprograms => {
101+
if (existingParticipant.id === currentparticipantprograms.id) {
102+
filterThesePrograms.push(toJS(currentparticipantprograms.programs.name))
103+
}
104+
})
105+
if (programList.length > 0) {
106+
programList = programList.filter(
107+
program =>
108+
program.name !==
109+
filterThesePrograms[filterThesePrograms.indexOf(program.name)]
110+
)
111+
}
112+
}
113+
// -----------------------------------
114+
95115
useEffect(() => {
96116
// kick off api calls for insurance list from Mobx
97117
participantStore.getInsurers()
98118
// kick off api calls for program list from Mobx
99119
participantStore.getPrograms()
120+
// TODO: refactor after v1.0.0 release
121+
const queueSize = Object.keys(queueStore.queues).length
122+
for (let i = 1; i <= queueSize; i++) queueStore.getQueue(i)
123+
// -----------------------------------
100124
// eslint-disable-next-line react-hooks/exhaustive-deps
101125
}, [])
102126

@@ -110,6 +134,7 @@ const ParticipantInfo = observer(() => {
110134
// if existing participant and no vist we are coming from search, so update particiapnt only
111135
} else if (existingParticipant.id && !existingVisit.id) {
112136
participantStore.updateParticipant()
137+
participantStore.createVisit()
113138
// otherwise we are adding a new participant because both participant and visit will be undefined
114139
} else {
115140
participantStore.createParticipant()
@@ -356,136 +381,133 @@ const ParticipantInfo = observer(() => {
356381
</div>
357382
</Grid>
358383

359-
{(!existingParticipant.id && !existingVisit.id) ||
360-
(existingParticipant.id && existingVisit.id) ? (
361-
<div>
362-
<Typography
363-
style={{ textAlign: "left" }}
364-
component="h5"
365-
variant="h5"
366-
gutterBottom
367-
>
368-
<br />
369-
<br />
370-
2. Check In Participant
371-
</Typography>
372-
<Grid container>
373-
<FormGroup className="participant-info">
374-
<Grid container>
375-
<Grid item xs>
376-
<FormControl className={classes.formControl}>
377-
<InputLabel htmlFor="demo-controlled-open-select">
378-
Choose Program
379-
</InputLabel>
384+
<div>
385+
<Typography
386+
style={{ textAlign: "left" }}
387+
component="h5"
388+
variant="h5"
389+
gutterBottom
390+
>
391+
<br />
392+
<br />
393+
2. Check In Participant
394+
</Typography>
395+
<Grid container>
396+
<FormGroup className="participant-info">
397+
<Grid container>
398+
<Grid item xs>
399+
<FormControl className={classes.formControl}>
400+
<InputLabel htmlFor="demo-controlled-open-select">
401+
Choose Program
402+
</InputLabel>
403+
<Select
404+
required
405+
value={existingVisit.program}
406+
onChange={e => {
407+
participantStore.setVisitProgram(e.target.value)
408+
findAndSaveServiceListings(e)
409+
}}
410+
inputProps={{
411+
name: "program",
412+
id: "demo-controlled-open-select",
413+
}}
414+
>
415+
{programList.map(program => (
416+
<MenuItem
417+
key={program.id}
418+
value={
419+
programList && programList.length > 0
420+
? program.id
421+
: ""
422+
}
423+
>
424+
{programList && programList.length > 0
425+
? program.name
426+
: ""}
427+
</MenuItem>
428+
))}
429+
</Select>
430+
</FormControl>
431+
</Grid>
432+
433+
<Grid item xs>
434+
<FormControl className={classes.formControl}>
435+
<InputLabel htmlFor="demo-controlled-open-select">
436+
Select Service
437+
</InputLabel>
438+
{existingVisit.program && serviceList.length > 0 ? (
380439
<Select
381440
required
382-
value={existingVisit.program}
383-
onChange={e => {
384-
participantStore.setVisitProgram(e.target.value)
385-
findAndSaveServiceListings(e)
386-
}}
441+
value={existingVisit.service}
442+
onChange={e =>
443+
participantStore.setVisitService(e.target.value)
444+
}
387445
inputProps={{
388-
name: "program",
446+
name: "service",
389447
id: "demo-controlled-open-select",
390448
}}
391449
>
392-
{programList.map(program => (
450+
{serviceList.map(service => (
393451
<MenuItem
394-
key={program.id}
452+
key={service.id}
395453
value={
396-
programList && programList.length > 0
397-
? program.id
454+
serviceList && serviceList.length > 0
455+
? service.id
398456
: ""
399457
}
400458
>
401-
{programList && programList.length > 0
402-
? program.name
459+
{serviceList && serviceList.length > 0
460+
? service.name
403461
: ""}
404462
</MenuItem>
405463
))}
406464
</Select>
407-
</FormControl>
408-
</Grid>
409-
410-
<Grid item xs>
411-
<FormControl className={classes.formControl}>
412-
<InputLabel htmlFor="demo-controlled-open-select">
413-
Select Service
414-
</InputLabel>
415-
{existingVisit.program && serviceList.length > 0 ? (
416-
<Select
417-
required
418-
value={existingVisit.service}
419-
onChange={e =>
420-
participantStore.setVisitService(e.target.value)
421-
}
422-
inputProps={{
423-
name: "service",
424-
id: "demo-controlled-open-select",
425-
}}
426-
>
427-
{serviceList.map(service => (
428-
<MenuItem
429-
key={service.id}
430-
value={
431-
serviceList && serviceList.length > 0
432-
? service.id
433-
: ""
434-
}
435-
>
436-
{serviceList && serviceList.length > 0
437-
? service.name
438-
: ""}
439-
</MenuItem>
440-
))}
441-
</Select>
442-
) : null}
443-
</FormControl>
444-
</Grid>
445-
<br />
446-
<Grid item xs>
447-
<FormControl className={classes.formControl}>
448-
<InputLabel htmlFor="demo-controlled-open-select">
449-
Select Priority Level
450-
</InputLabel>
451-
<Select
452-
value={existingVisit.urgency}
453-
onChange={e =>
454-
participantStore.setVisitUrgency(e.target.value)
455-
}
456-
inputProps={{
457-
name: "priorityLevel",
458-
id: "demo-controlled-open-select",
459-
}}
460-
>
461-
<MenuItem value={"_1"}>1 (Lowest)</MenuItem>
462-
<MenuItem value={"_2"}>2</MenuItem>
463-
<MenuItem value={"_3"}>3</MenuItem>
464-
<MenuItem value={"_4"}>4</MenuItem>
465-
<MenuItem value={"_5"}>5 (Highest)</MenuItem>
466-
</Select>
467-
</FormControl>
468-
</Grid>
469-
<br />
470-
<TextField
471-
id="standard-full-width"
472-
style={{ margin: 8, marginTop: 40 }}
473-
placeholder="Add a note"
474-
onChange={e =>
475-
participantStore.setVisitNotes(e.target.value)
476-
}
477-
value={existingVisit.notes}
478-
fullWidth
479-
margin="normal"
480-
InputLabelProps={{
481-
shrink: true,
482-
}}
483-
/>
465+
) : null}
466+
</FormControl>
484467
</Grid>
485-
</FormGroup>
486-
</Grid>
487-
</div>
488-
) : null}
468+
<br />
469+
<Grid item xs>
470+
<FormControl className={classes.formControl}>
471+
<InputLabel htmlFor="demo-controlled-open-select">
472+
Select Priority Level
473+
</InputLabel>
474+
<Select
475+
value={existingVisit.urgency}
476+
onChange={e =>
477+
participantStore.setVisitUrgency(e.target.value)
478+
}
479+
inputProps={{
480+
name: "priorityLevel",
481+
id: "demo-controlled-open-select",
482+
}}
483+
>
484+
<MenuItem value={"_1"}>1 (Lowest)</MenuItem>
485+
<MenuItem value={"_2"}>2</MenuItem>
486+
<MenuItem value={"_3"}>3</MenuItem>
487+
<MenuItem value={"_4"}>4</MenuItem>
488+
<MenuItem value={"_5"}>5 (Highest)</MenuItem>
489+
</Select>
490+
</FormControl>
491+
</Grid>
492+
<br />
493+
<TextField
494+
id="standard-full-width"
495+
style={{ margin: 8, marginTop: 40 }}
496+
placeholder="Add a note"
497+
onChange={e =>
498+
participantStore.setVisitNotes(e.target.value)
499+
}
500+
value={existingVisit.notes}
501+
fullWidth
502+
margin="normal"
503+
InputLabelProps={{
504+
shrink: true,
505+
}}
506+
/>
507+
</Grid>
508+
</FormGroup>
509+
</Grid>
510+
</div>
489511

490512
<Button
491513
style={{

frontend/src/components/ParticipantsList.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ const ParticipantsList = observer(() => {
5656
const handleParticipant = (e, participant) => {
5757
participantStore.setParticipant(participant)
5858
participantStore.setDefaultVisit()
59+
participantStore.setVisit({
60+
participant: participant.id,
61+
})
5962
}
6063

6164
return (

frontend/src/stores/ParticipantStore.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class ParticipantStore {
2424
// flag for triggering route to Queue table once Participant Info has bee sent
2525
@observable routeToQueueTable = false
2626
@observable services = []
27+
@observable visitList = []
2728

2829
// computed
2930
// if user has input a value for search, enable search else disable search
@@ -36,6 +37,11 @@ export class ParticipantStore {
3637
: false
3738
return !hasSearchString
3839
}
40+
@computed get hasVisit() {
41+
return this.visitList.map(visit => {
42+
return visit.participant === this.participant.id ? true : false
43+
})
44+
}
3945

4046
// Setters
4147
@action setDefaultParticipant = () => {
@@ -148,6 +154,9 @@ export class ParticipantStore {
148154
@action setServiceList = data => {
149155
this.services = data
150156
}
157+
@action setVisitsList = data => {
158+
this.visitList = data
159+
}
151160

152161
// Utils
153162
createStartDate = () => {
@@ -238,6 +247,16 @@ export class ParticipantStore {
238247
throw "ParticipantStore: getFrontEndDeskEvents() Failed => " + error
239248
}
240249
})
250+
getVisits = flow(function*() {
251+
try {
252+
const { ok, data } = yield api.getVisits()
253+
if (ok && data) {
254+
this.setVisitsList(data)
255+
}
256+
} catch (error) {
257+
throw "ParticipantStore: getVisits() Failed => " + error
258+
}
259+
})
241260
// called on => ParticipantInfo.js
242261
// only update basic facts about the participant
243262
updateParticipant = flow(function*() {

frontend/src/stores/QueueStore.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class QueueStore {
2020
8: [],
2121
9: [],
2222
}
23+
// TODO: refactor after v1.0.0 release
24+
@observable participantWithPrograms = []
2325

2426
//Set tab order here
2527
@computed get queueStats() {
@@ -75,6 +77,16 @@ export class QueueStore {
7577
@action
7678
setQueue(queueIndex, data) {
7779
this.queues[queueIndex] = data.sort((a, b) => +b.urgency[1] - +a.urgency[1])
80+
// TODO: refactor after v1.0.0 release
81+
this.participantWithPrograms = [
82+
...this.participantWithPrograms,
83+
...data.map(queueItem => {
84+
return {
85+
id: queueItem.participant.id,
86+
programs: { id: queueItem.program.id, name: queueItem.program.name },
87+
}
88+
}),
89+
]
7890
}
7991

8092
//Return the longest wait time in minutes

0 commit comments

Comments
 (0)