Skip to content

Commit 176bee8

Browse files
committed
Display FHIR Communications resources from the FHIR server
1 parent 64cf242 commit 176bee8

File tree

4 files changed

+204
-1
lines changed

4 files changed

+204
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Button, Grid } from "@mui/material";
2+
import DeleteIcon from '@mui/icons-material/Delete';
3+
import useStyles from './styles';
4+
5+
6+
const Communication = props => {
7+
const classes = useStyles();
8+
const { communication, deleteCommunication } = props;
9+
10+
const convertTimeStamp = (timeStamp) => {
11+
const date = new Date(timeStamp);
12+
return date.toLocaleString();
13+
};
14+
15+
return (
16+
<div>
17+
<Grid container>
18+
<Grid className={classes.communicationHeader} item xs={2}>
19+
{`ID: ${communication.id}`}
20+
</Grid>
21+
<Grid className={classes.communicationHeader} item xs={8.7}>
22+
{`Received: ${convertTimeStamp(communication.received)}`}
23+
</Grid>
24+
<Grid className={classes.communicationHeaderButton} item xs={1.3}>
25+
<Button
26+
fullWidth
27+
variant="contained"
28+
color="error"
29+
startIcon={<DeleteIcon />}
30+
onClick={() => {
31+
deleteCommunication(communication.id);
32+
}}
33+
>
34+
Clear
35+
</Button>
36+
</Grid>
37+
<Grid className={classes.communicationDescription} item xs={12}>
38+
{communication.payload[0].contentString}
39+
</Grid>
40+
</Grid>
41+
</div>
42+
);
43+
};
44+
45+
export default Communication;
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import { useEffect, useState } from 'react';
2+
3+
import { Button, Grid } from '@mui/material';
4+
import NotificationsIcon from '@mui/icons-material/Notifications';
5+
import Badge from '@mui/material/Badge';
6+
import Dialog from '@mui/material/Dialog';
7+
import DialogTitle from '@mui/material/DialogTitle';
8+
import DialogContent from '@mui/material/DialogContent';
9+
import { Refresh } from '@mui/icons-material'
10+
11+
import { styled } from '@mui/material/styles';
12+
import Paper from '@mui/material/Paper';
13+
import Communication from './Communication';
14+
15+
const CommunicationsDialog = props => {
16+
const { client, token } = props;
17+
const [state, setState] = useState({
18+
client: client,
19+
token: token,
20+
initialLoad: true,
21+
communicationCount: 0,
22+
communications: [],
23+
open: false
24+
});
25+
26+
const debugLog = (message) => {
27+
console.log('CommunicationsDialog: ' + message);
28+
};
29+
30+
useEffect(() => {
31+
// reload on page load and dialog open
32+
if (state.initialLoad) {
33+
setState(prevState => ({ ...prevState, initialLoad: false}));
34+
getCommunications();
35+
}
36+
37+
const interval = setInterval(() => {
38+
// page load...
39+
getCommunications();
40+
41+
}, 1000 * 5) // reload every 5 seconds
42+
43+
return () => clearInterval(interval);
44+
45+
});
46+
47+
const getCommunications = () => {
48+
if (state.client) {
49+
// try to read communications from FHIR server
50+
state.client
51+
.request(`Communication?recipient=${props.token?.userId}`, {
52+
graph: false,
53+
flat: true
54+
})
55+
.then(bundle => {
56+
loadCommunications(bundle);
57+
});
58+
}
59+
}
60+
61+
const deleteCommunication = (id) => {
62+
debugLog('deleteCommunication: ' + id);
63+
if (id) {
64+
state.client.delete(`Communication/${id}`).then(() => {
65+
debugLog(`Deleted communication: ${id}`);
66+
});
67+
}
68+
}
69+
70+
const loadCommunications = (bundle) => {
71+
let count = bundle.length;
72+
setState(prevState => ({ ...prevState, communicationCount: count, communications: bundle}));
73+
};
74+
75+
const handleClose = () => {
76+
setState(prevState => ({ ...prevState, open: false}));
77+
};
78+
79+
const Item = styled(Paper)(({ theme }) => ({
80+
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#EDF6FF',
81+
...theme.typography.body2,
82+
padding: theme.spacing(1),
83+
textAlign: 'left',
84+
color: theme.palette.text.secondary,
85+
}));
86+
87+
const renderCommunications = () => {
88+
return (
89+
<Grid container spacing={2} sx={{ mt: 2 }}>
90+
{state.communications.map(communication => {
91+
return (
92+
<Grid item xs={12} sm={12}>
93+
<Item><Communication communication={communication} deleteCommunication={deleteCommunication}/></Item>
94+
</Grid>
95+
);
96+
})}
97+
</Grid>
98+
);
99+
}
100+
101+
return (
102+
<span>
103+
<span onClick={() => {
104+
setState(prevState => ({ ...prevState, open: true, initialLoad: true}));
105+
}} >
106+
<Badge badgeContent={state.communicationCount} color="primary">
107+
<NotificationsIcon sx={{ fontSize: 26, verticalAlign: 'middle' }} />
108+
</Badge></span>
109+
<Dialog fullWidth maxWidth='md' onClose={handleClose} open={state.open}>
110+
<DialogTitle>
111+
<Grid container>
112+
<Grid item xs={10}>
113+
<NotificationsIcon sx={{ fontSize: 26, verticalAlign: 'middle' }} />
114+
Communications ({state.communicationCount})
115+
</Grid>
116+
<Grid item xs={2}>
117+
<Button
118+
variant="contained"
119+
startIcon={<Refresh />}
120+
onClick={() => {
121+
getCommunications();
122+
}}
123+
>
124+
Refresh
125+
</Button>
126+
</Grid>
127+
</Grid>
128+
</DialogTitle>
129+
130+
<DialogContent>
131+
{ renderCommunications() }
132+
</DialogContent>
133+
134+
</Dialog>
135+
</span>
136+
);
137+
};
138+
139+
export default CommunicationsDialog;

src/components/RequestDashboard/Home.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import SettingsIcon from '@mui/icons-material/Settings';
66
import AccountBoxIcon from '@mui/icons-material/AccountBox';
77
import MedicalServicesIcon from '@mui/icons-material/MedicalServices';
88

9+
import CommunicationsDialog from './CommunicationsDialog';
910
import useStyles from './styles';
1011
import PatientSection from './PatientSection';
1112
import SettingsSection from './SettingsSection';
1213
import TasksSection from './TasksSection';
1314

15+
1416
import { logout } from '../../util/auth';
1517

1618
const Home = props => {
@@ -82,8 +84,12 @@ const Home = props => {
8284
{/* spacer */}
8385
{/** */}
8486
{section ? (
85-
<Grid className={classes.spacer} item xs={4}>
87+
<Grid className={classes.spacer} item xs={5}>
8688
<span className={classes.loginIcon}>
89+
<CommunicationsDialog
90+
client={props.client} token={token}
91+
/>
92+
&nbsp;&nbsp;
8793
<AccountBoxIcon sx={{ fontSize: 48, verticalAlign: 'middle' }} /> {token.name}
8894
<Button variant="outlined" className={classes.whiteButton} onClick={logout}>
8995
Logout

src/components/RequestDashboard/styles.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ export default makeStyles(
158158
borderColor: 'white !important',
159159
marginRight: '5px !important',
160160
marginLeft: '20px !important'
161+
},
162+
communicationHeader: {
163+
fontSize: '12px',
164+
color: '#777',
165+
borderBottom: '1px solid #e3e3ef'
166+
},
167+
communicationDescription: {
168+
fontSize: '18px',
169+
padding: '8px 0px 10px 2px'
170+
},
171+
communicationHeaderButton: {
172+
height: '40px',
173+
borderBottom: '1px solid #e3e3ef'
161174
}
162175
}),
163176

0 commit comments

Comments
 (0)