-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCaseCollection.tsx
More file actions
208 lines (198 loc) · 6.54 KB
/
CaseCollection.tsx
File metadata and controls
208 lines (198 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import axios from 'axios';
import { useEffect, useState, SetStateAction } from 'react';
import {
Button,
Card,
CardContent,
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow
} from '@mui/material';
import IconButton from '@mui/material/IconButton';
import DeleteIcon from '@mui/icons-material/Delete';
import { Refresh } from '@mui/icons-material';
import CircleIcon from '@mui/icons-material/Circle';
import Tooltip from '@mui/material/Tooltip';
import FormPopup from '../FormPopup';
export type RemsCase = {
case_number?: string;
auth_number?: string;
patientFirstName?: string;
patientLastName?: string;
patientDOB?: string;
drugCode?: string;
drugName?: number;
status?: string;
dispenseStatus?: string;
metRequirements:
| {
metRequirementId: string;
requirementsDescription: string;
requirementName: string;
stakeholderId: string;
completed: boolean;
}[];
_id: string;
};
const CaseCollection = (props: { refresh: boolean }) => {
const [allData, setAllData] = useState<RemsCase[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [open, setOpen] = useState(false);
const [rowData, setRowData] = useState({});
useEffect(() => {
if (props.refresh) {
getAllRemsCase();
}
}, [props.refresh]);
useEffect(() => {
getAllRemsCase();
}, []);
const getAllRemsCase = async () => {
const url = process.env.RESOURCE_SERVER + 'api/all/remscase';
await axios
.get(url)
.then(function (response: { data: SetStateAction<RemsCase[]> }) {
setAllData(response.data);
setIsLoading(false);
})
.catch((error: any) => {
setIsLoading(false);
console.log('Error -- > ', error);
});
};
const deleteSingleRow = async (event: any, row: RemsCase) => {
const url = process.env.RESOURCE_SERVER + 'api/remsCase/deleteOne';
await axios
.post(url, { data: { params: row } })
.then(function (response: { data: any; status: number }) {
if (response.status === 200) {
getAllRemsCase();
}
})
.catch((error: any) => {
setIsLoading(false);
console.log('Error -- > ', error);
});
};
const openForms = (event: any, row: RemsCase) => {
setRowData(row);
setOpen(true);
}
const handleClose = () => {
setOpen(false);
}
const formattedReqs = (row: RemsCase) => {
let allCompleted = true;
let color = '#f0ad4e';
let tooltip = 'Forms not completed';
row.metRequirements.forEach((req: any) => {
if (!req.completed) {
allCompleted = false;
}
});
if (allCompleted) {
color = 'green';
tooltip = 'Forms completed';
}
return (
<Tooltip title={tooltip}>
<IconButton onClick={(event: any) => openForms(event, row)}>
<CircleIcon sx={{color: color}} />
</IconButton>
</Tooltip>
)
};
if (allData.length < 1 && !isLoading) {
return (
<Card style={{ padding: '15px' }}>
<div className="right-btn">
<Button
variant="contained"
startIcon={<Refresh />}
onClick={() => {
getAllRemsCase();
}}
>
Refresh
</Button>
</div>
<h1>No data</h1>
</Card>
);
} else {
return (
<Card sx={{ bgColor: '#F5F5F7' }}>
<div className="right-btn">
<Button
variant="contained"
sx={{backgroundColor: '#2F6A47'}}
startIcon={<Refresh />}
onClick={() => {
getAllRemsCase();
}}
>
Refresh
</Button>
</div>
<Card>
<Card>
<CardContent>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead sx={{ fontWeight: 'bold' }}>
<TableRow sx={{ fontWeight: 'bold' }}>
<TableCell align="right">Case Number</TableCell>
<TableCell align="right">Patient First Name</TableCell>
<TableCell align="right">Patient Last Name</TableCell>
<TableCell align="right">Drug Name</TableCell>
<TableCell align="right">Drug Code</TableCell>
<TableCell align="right">Patient DOB</TableCell>
<TableCell align="right">Status</TableCell>
<TableCell align="right">Dispense Status</TableCell>
<TableCell align="left">Authorization Number</TableCell>
<TableCell align="right">Met Requirements</TableCell>
<TableCell align="right">Delete</TableCell>
</TableRow>
</TableHead>
<TableBody>
{allData.map(row => {
const metReq = formattedReqs(row);
return (
<TableRow key={row.case_number}>
<TableCell align="right">{row.case_number}</TableCell>
<TableCell align="right">{row.patientFirstName}</TableCell>
<TableCell align="right">{row.patientLastName}</TableCell>
<TableCell align="right">{row.drugName}</TableCell>
<TableCell align="right">{row.drugCode}</TableCell>
<TableCell align="right">{row.patientDOB}</TableCell>
<TableCell align="right">{row.status}</TableCell>
<TableCell align="right">{row.dispenseStatus}</TableCell>
<TableCell align="right">{row.auth_number}</TableCell>
<TableCell align="center">{metReq}</TableCell>
<TableCell align="right">
<IconButton
aria-label="delete"
onClick={(event: any) => deleteSingleRow(event, row)}
>
<DeleteIcon />
</IconButton>
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
</CardContent>
</Card>
</Card>
<FormPopup open={open} handleClose={handleClose} data={rowData} />
</Card>
);
}
};
export default CaseCollection;