diff --git a/package.json b/package.json index b9a1807..1d1e7e9 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "react-dom": "^17.0.0", "react-markdown": "^8.0.7", "react-router-dom": "^6.17.0", + "uuid": "^9.0.1", "vite": "^5.1.6", "vite-tsconfig-paths": "^4.3.2" }, diff --git a/src/components/Dashboard/ListSelections/NotificationsSection.jsx b/src/components/Dashboard/ListSelections/NotificationsSection.jsx index 4e17d25..b36bdcc 100644 --- a/src/components/Dashboard/ListSelections/NotificationsSection.jsx +++ b/src/components/Dashboard/ListSelections/NotificationsSection.jsx @@ -3,31 +3,77 @@ import useStyles from '../styles'; import { SettingsContext } from '../../../containers/ContextProvider/SettingsProvider'; import { EtasuStatusComponent } from '../../EtasuStatus/EtasuStatusComponent'; import axios from 'axios'; +import { createMedicationFromMedicationRequest } from '../../../util/fhir'; +import { standardsBasedGetEtasu } from '../../../util/util'; const NotificationsSection = () => { const [globalState, _] = useContext(SettingsContext); const classes = useStyles(); const [etasu, setEtasu] = useState([]); + const [medications, setMedications] = useState([]); useEffect(() => { - const patientFirstName = globalState.patient?.name?.at(0)?.given?.at(0); - const patientLastName = globalState.patient?.name?.at(0)?.family; - const patientDOB = globalState.patient?.birthDate; + setEtasu([]); + getMedicationRequest(); + }, []); + + useEffect(() => { + getAllEtasu(); + }, [medications]); - const etasuUrl = `${globalState.remsAdminServer}/etasu/met/patient/${patientFirstName}/${patientLastName}/${patientDOB}`; + const getMedicationRequest = () => { + const patientsMedications = []; axios({ method: 'get', - url: etasuUrl - }).then((response) => { - setEtasu(response.data); + url: `${globalState.baseUrl}/MedicationRequest?subject=Patient/${globalState.patient.id}` + }).then((result) => { + result?.data.entry.forEach((m) => { + const medication = createMedicationFromMedicationRequest(m.resource); + patientsMedications.push(medication); + }) + setMedications(patientsMedications); }, (error) =>{ console.error(error); - }) - }, []); + }); + }; + + const compileResponses = (newRequest, body) => { + if (newRequest.contained) { + newRequest.body = body; + setEtasu(prevState => [ ...prevState, newRequest]); + } + } + + const getAllEtasu = () => { + medications.forEach((medication) => { + const body = makeBody(medication); + const standardEtasuUrl = `${globalState.remsAdminServer}/4_0_0/GuidanceResponse/$rems-etasu`; + standardsBasedGetEtasu(standardEtasuUrl, body, compileResponses); + }); + + } + + const makeBody = (medication) => { + return { + resourceType: "Parameters", + parameter: [ + { + name: 'patient', + resource: globalState.patient + }, + { + name: 'medication', + resource: medication + } + ] + } + } + return (