diff --git a/src/components/Dashboard/Dashboard.jsx b/src/components/Dashboard/Dashboard.jsx index 95aae834..10f1ea0b 100644 --- a/src/components/Dashboard/Dashboard.jsx +++ b/src/components/Dashboard/Dashboard.jsx @@ -22,10 +22,24 @@ import MedicalInformationIcon from '@mui/icons-material/MedicalInformation'; import FormsSection from './ListSelections/FormsSection'; import EmptySection from './ListSelections/EmptySection'; import PatientTaskSection from './ListSelections/PatientTaskSection'; +import MedicationsSection from './ListSelections/MedicationsSection'; + +// Since we're using JS and can't use TS enums +const Section = Object.freeze({ + NOTIFICATIONS: 0, + APPOINTMENTS: 1, + TASKS: 2, + QUESTIONNAIRE_FORMS: 3, + HEALTH_DATA: 4, + MEDICATIONS: 5, + TESTS_AND_RESULTS: 6, + SETTINGS: 7, + LOGOUT: 8 +}); const Dashboard = props => { const classes = useStyles(); - const [selectedIndex, setSelectedIndex] = useState(3); + const [selectedIndex, setSelectedIndex] = useState(Section.QUESTIONNAIRE_FORMS); const handleListItemClick = (event, index) => { setSelectedIndex(index); @@ -51,7 +65,7 @@ const Dashboard = props => { }; useEffect(() => { - if (selectedIndex === 8) { + if (selectedIndex === Section.LOGOUT) { // logout - set client to null to display login page props.logout(); } @@ -59,10 +73,12 @@ const Dashboard = props => { const renderBody = () => { switch (selectedIndex) { - case 2: + case Section.TASKS: return ; - case 3: + case Section.QUESTIONNAIRE_FORMS: return ; + case Section.MEDICATIONS: + return ; default: return ; } @@ -87,13 +103,11 @@ const Dashboard = props => { {createIcons().map((option, index) => (
- - handleListItemClick(event, index)}> + + handleListItemClick(event, index)} + selected={selectedIndex === index} + > {option[1]} { +const FormElement = props => { const classes = useStyles(); const resource = props.resource; const clientState = props.client.state; @@ -56,4 +56,4 @@ const DashboardElement = props => { ); }; -export default memo(DashboardElement); +export default memo(FormElement); diff --git a/src/components/Dashboard/ListSelections/FormsSection.jsx b/src/components/Dashboard/ListSelections/FormsSection.jsx index 34491555..d9f7f258 100644 --- a/src/components/Dashboard/ListSelections/FormsSection.jsx +++ b/src/components/Dashboard/ListSelections/FormsSection.jsx @@ -1,6 +1,6 @@ import React, { memo, useState, useEffect } from 'react'; import { Paper } from '@mui/material'; -import DashboardElement from '../DashboardElement'; +import FormElement from '../FormElement'; import FormControlLabel from '@mui/material/FormControlLabel'; import Checkbox from '@mui/material/Checkbox'; import useStyles from '../styles'; @@ -61,9 +61,7 @@ const FormsSection = props => { /> {resources.length > 0 ? ( renderElements().map(e => { - return ( - - ); + return ; }) ) : ( {message} diff --git a/src/components/Dashboard/ListSelections/MedicationsSection.jsx b/src/components/Dashboard/ListSelections/MedicationsSection.jsx new file mode 100644 index 00000000..146b72fe --- /dev/null +++ b/src/components/Dashboard/ListSelections/MedicationsSection.jsx @@ -0,0 +1,87 @@ +import React, { memo, useState, useEffect } from 'react'; +import { Paper, Typography } from '@mui/material'; +import FormControlLabel from '@mui/material/FormControlLabel'; +import useStyles from '../styles'; +import { MedicationStatus } from '../../MedicationStatus/MedicationStatus'; +import axios from 'axios'; + +const MedicationsSection = props => { + const classes = useStyles(); + const [message, setMessage] = useState('Loading...'); + const [resources, setResources] = useState([]); + const patientId = props.client.patient.id; + + useEffect(() => { + if (patientId) { + props.client.patient + .request('MedicationDispense', { + pageLimit: 0, + onPage: addResources, + resolveReferences: 'authorizingPrescription' + }) + .then(() => { + setMessage(`No MedicationDispenses found for user with patientId: ${patientId}`); + }); + } else { + setMessage('Invalid patient: No patientId provided'); + } + }, [props.client.patient]); + + const addResources = bundle => { + if (bundle.entry && bundle.entry.length > 0) { + setResources(bundle.entry.map(entry => entry.resource)); + } + }; + + return ( +
+

Available Medications

+ {resources.length > 0 ? ( + resources.map(resource => ( + + )) + ) : ( + {message} + )} +
+ ); +}; + +const MedicationElement = props => { + const { initialMedicationDispense, client } = props; + const [lastCheckedMedicationTime, setMedicationTime] = useState(null); + const [medicationDispense, setMedicationDispense] = useState(initialMedicationDispense); + const ehrUrl = client.state.serverUrl; + const patientId = client.patient.id; + const medicationRequest = medicationDispense?.authorizingPrescription?.[0]; + + const getMedicationStatus = () => { + setMedicationTime(Date.now()); + + if (client?.patient && patientId) { + client.request(`MedicationDispense/${medicationDispense.id}`, { + pageLimit: 0, + onPage: bundle => { + setMedicationDispense(bundle.entry[0].resource); + }, + resolveReferences: 'authorizingPrescription' + }); + } + }; + + return ( + + ); +}; + +export default memo(MedicationsSection); diff --git a/src/components/MedicationStatus/MedicationStatus.jsx b/src/components/MedicationStatus/MedicationStatus.jsx index d023bdc8..5fac43f3 100644 --- a/src/components/MedicationStatus/MedicationStatus.jsx +++ b/src/components/MedicationStatus/MedicationStatus.jsx @@ -1,7 +1,7 @@ import { MedicationStatusButton } from './MedicationStatusButton.jsx'; import { MedicationStatusModal } from './MedicationStatusModal.jsx'; import { useState, useEffect } from 'react'; -import { Card } from '@mui/material'; +import { Card, Typography } from '@mui/material'; export const MedicationStatus = props => { const { ehrUrl, request, medicationDispense, getMedicationStatus, lastCheckedMedicationTime } = @@ -20,6 +20,9 @@ export const MedicationStatus = props => { return ( + + {request?.medicationCodeableConcept?.coding?.[0].display} + { - const classes = useStyles(); const [state, dispatch] = React.useContext(SettingsContext); - // TODO: Make request builder use react-hooks return (
{state.startup ? (