forked from HL7-DaVinci/crd-request-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPatientSearchBar.jsx
More file actions
122 lines (111 loc) · 3.9 KB
/
PatientSearchBar.jsx
File metadata and controls
122 lines (111 loc) · 3.9 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
import { Autocomplete, Box, TextField } from '@mui/material';
import { Grid, Button } from '@mui/material';
import PeopleIcon from '@mui/icons-material/People';
import { useEffect, useState } from 'react';
import { PrefetchTemplate } from '../../../PrefetchTemplate';
import { defaultValues } from '../../../util/data';
import PatientBox from '../../SMARTBox/PatientBox';
import './PatientSearchBarStyle.css';
import { getPatientFirstAndLastName } from '../../../util/util';
const PatientSearchBar = props => {
const [options] = useState(defaultValues);
const [input, setInput] = useState('');
const [listOfPatients, setListOfPatients] = useState([]);
useEffect(() => {
const newList = props.searchablePatients.map(patient => ({
id: patient.id,
name: getPatientFirstAndLastName(patient)
}));
setListOfPatients([newList]);
}, [props.searchablePatients]);
function getFilteredLength(searchString, listOfPatients) {
const filteredListOfPatients = listOfPatients[0].filter(element => {
if (searchString === '') {
return element;
} else {
return element.name.toLowerCase().includes(searchString);
}
});
return filteredListOfPatients.length;
}
const showAllPatients = () => {
props.callback('patient', {});
props.callback('expanded', false);
};
function patientSearchBar() {
return (
<Box className="search-box-container">
<Grid container>
<Grid item xs={9}>
<span className="search-header">
<p>Filter patient list</p>
<Autocomplete
className="search-box"
disablePortal
id="search-box"
onInputChange={(event, newInputValue) => {
setInput(newInputValue.toLowerCase());
}}
options={listOfPatients[0].map(item => item.name)}
renderInput={params => <TextField {...params} label="Search" />}
/>
<p>
Showing {getFilteredLength(input, listOfPatients)} of{' '}
{props.searchablePatients.length} records
</p>
</span>
</Grid>
<Grid item xs={3}>
<Button
variant="contained"
startIcon={<PeopleIcon />}
onClick={() => {
showAllPatients();
}}
style={{ padding: '10px', paddingLeft: '20px', paddingRight: '20px' }}
>
Select all Patients
</Button>
</Grid>
</Grid>
{displayFilteredPatientList(input, listOfPatients[0])}
</Box>
);
}
function displayFilteredPatientList(searchString, listOfPatients) {
const filteredListOfPatients = listOfPatients.filter(element => {
if (searchString === '') {
return element;
} else {
return element.name.toLowerCase().includes(searchString);
}
});
return (
<Box>
{filteredListOfPatients.map(patient => {
return (
<span key={patient.id}>
<PatientBox
key={patient.id}
patient={props.searchablePatients.find(item => item.id === patient.id)}
client={props.client}
request={props.request}
launchUrl={props.launchUrl}
callback={props.callback}
callbackMap={props.callbackMap}
updatePrefetchCallback={PrefetchTemplate.generateQueries}
clearCallback={props.clearCallback}
options={options}
responseExpirationDays={props.responseExpirationDays}
user={props.user}
showButtons={props.showButtons}
/>
</span>
);
})}
</Box>
);
}
return <span>{listOfPatients[0] ? patientSearchBar() : 'loading...'}</span>;
};
export default PatientSearchBar;