11import React , { memo , useState , useEffect } from 'react' ;
22import useStyles from './styles' ;
3- import DashboardElement from './DashboardElement' ;
4- import FormControlLabel from '@mui/material/FormControlLabel' ;
5- import Checkbox from '@mui/material/Checkbox' ;
63import Box from '@mui/material/Box' ;
74import Drawer from '@mui/material/Drawer' ;
85import CssBaseline from '@mui/material/CssBaseline' ;
96import Toolbar from '@mui/material/Toolbar' ;
107import List from '@mui/material/List' ;
118import Divider from '@mui/material/Divider' ;
129import AssignmentIcon from '@mui/icons-material/Assignment' ;
10+ import ListAltIcon from '@mui/icons-material/ListAlt' ;
1311import MedicationIcon from '@mui/icons-material/Medication' ;
1412import BiotechIcon from '@mui/icons-material/Biotech' ;
1513import LogoutIcon from '@mui/icons-material/Logout' ;
@@ -21,34 +19,28 @@ import NotificationsIcon from '@mui/icons-material/Notifications';
2119import AlarmIcon from '@mui/icons-material/Alarm' ;
2220import SettingsIcon from '@mui/icons-material/Settings' ;
2321import MedicalInformationIcon from '@mui/icons-material/MedicalInformation' ;
24- import { Paper } from '@mui/material' ;
22+ import FormsSection from './ListSelections/FormsSection' ;
23+ import EmptySection from './ListSelections/EmptySection' ;
24+ import PatientTaskSection from './ListSelections/PatientTaskSection' ;
2525
2626const Dashboard = props => {
2727 const classes = useStyles ( ) ;
28- const [ resources , setResources ] = useState ( [ ] ) ;
29- const [ message , setMessage ] = useState ( 'Loading...' ) ;
30- const [ checked , setChecked ] = useState ( true ) ;
31- const drawerWidth = '340px' ;
32- const handleChange = event => {
33- setChecked ( event . target . checked ) ;
34- } ;
28+ const [ selectedIndex , setSelectedIndex ] = useState ( 3 ) ;
3529
36- const addResources = bundle => {
37- if ( bundle . entry ) {
38- bundle . entry . forEach ( e => {
39- const resource = e . resource ;
40- setResources ( resources => [ ...resources , resource ] ) ;
41- } ) ;
42- }
30+ const handleListItemClick = ( event , index ) => {
31+ setSelectedIndex ( index ) ;
4332 } ;
33+
34+ const drawerWidth = '340px' ;
35+
4436 const createIcons = ( ) => {
4537 const icons = [ ] ;
4638 const style = { fontSize : '40px' } ;
4739 const itemStyle = { height : '80px' } ;
48- const qStyle = { height : '80px' , backgroundColor : '#f5f5fa' } ;
4940 icons . push ( [ 'Notifications' , < NotificationsIcon sx = { style } /> , itemStyle ] ) ;
5041 icons . push ( [ 'Appointments' , < AlarmIcon sx = { style } /> , itemStyle ] ) ;
51- icons . push ( [ 'Questionnaire Forms' , < AssignmentIcon sx = { style } /> , qStyle ] ) ;
42+ icons . push ( [ 'Tasks' , < AssignmentIcon sx = { style } /> , itemStyle ] ) ;
43+ icons . push ( [ 'Questionnaire Forms' , < ListAltIcon sx = { style } /> , itemStyle ] ) ;
5244 icons . push ( [ 'Health Data' , < MedicalInformationIcon sx = { style } /> , itemStyle ] ) ;
5345 icons . push ( [ 'Medications' , < MedicationIcon sx = { style } /> , itemStyle ] ) ;
5446 icons . push ( [ 'Tests and Results' , < BiotechIcon sx = { style } /> , itemStyle ] ) ;
@@ -57,32 +49,25 @@ const Dashboard = props => {
5749
5850 return icons ;
5951 } ;
52+
6053 useEffect ( ( ) => {
61- if ( props . client . patient . id ) {
62- props . client . patient
63- . request ( 'QuestionnaireResponse' , { pageLimit : 0 , onPage : addResources } )
64- . then ( ( ) => {
65- setMessage (
66- 'No QuestionnaireResponses Found for user with patientId: ' + props . client . patient . id
67- ) ;
68- } ) ;
69- } else {
70- setMessage ( 'Invalid patient: No patientId provided' ) ;
54+ if ( selectedIndex === 8 ) {
55+ // logout - set client to null to display login page
56+ props . logout ( ) ;
7157 }
72- } , [ props . client . patient ] ) ;
58+ } , [ selectedIndex ] ) ;
7359
74- const renderElements = ( ) => {
75- let resourcesToRender = [ ] ;
76- if ( checked ) {
77- resourcesToRender = resources . filter ( e => {
78- return e . status === 'in-progress' ;
79- } ) ;
80- } else {
81- resourcesToRender = resources ;
60+ const renderBody = ( ) => {
61+ switch ( selectedIndex ) {
62+ case 2 :
63+ return < PatientTaskSection client = { props . client } /> ;
64+ case 3 :
65+ return < FormsSection client = { props . client } /> ;
66+ default :
67+ return < EmptySection /> ;
8268 }
83- resourcesToRender . reverse ( ) ;
84- return resourcesToRender ;
8569 } ;
70+
8671 return (
8772 < div >
8873 < Box sx = { { display : 'flex' } } >
@@ -102,8 +87,13 @@ const Dashboard = props => {
10287 < List >
10388 { createIcons ( ) . map ( ( option , index ) => (
10489 < div key = { `icon-${ index } ` } >
105- < ListItem key = { option [ 0 ] } style = { option [ 2 ] } disablePadding >
106- < ListItemButton >
90+ < ListItem
91+ key = { option [ 0 ] }
92+ style = { option [ 2 ] }
93+ selected = { selectedIndex === index }
94+ disablePadding
95+ >
96+ < ListItemButton onClick = { event => handleListItemClick ( event , index ) } >
10797 < ListItemIcon > { option [ 1 ] } </ ListItemIcon >
10898 < ListItemText
10999 primaryTypographyProps = { { fontSize : '18px' } }
@@ -119,28 +109,7 @@ const Dashboard = props => {
119109 </ Drawer >
120110 < Box component = "main" sx = { { flexGrow : 1 , p : 3 } } >
121111 < Toolbar />
122- < div className = { classes . dashboardArea } >
123- < h2 className = { classes . elementHeader } > Available Forms</ h2 >
124- < FormControlLabel
125- style = { { float : 'right' } }
126- control = { < Checkbox checked = { checked } onChange = { handleChange } /> }
127- label = "Only show in-progress forms"
128- />
129- { resources . length > 0 ? (
130- renderElements ( ) . map ( e => {
131- return (
132- < DashboardElement
133- key = { e . id }
134- status = { e . status }
135- resource = { e }
136- client = { props . client }
137- />
138- ) ;
139- } )
140- ) : (
141- < Paper className = { classes . dashboardElement } > { message } </ Paper >
142- ) }
143- </ div >
112+ { renderBody ( ) }
144113 </ Box >
145114 </ Box >
146115 </ div >
0 commit comments