diff --git a/src/App.tsx b/src/App.tsx index a147b7c..be972d9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,5 @@ import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; +import { AppContext, AppContextType, PatientObjSubset } from './context/AppContext'; import { AppContext, AppContextType } from './context/AppContext'; import { useState } from 'react'; import PatientSearch from './components/patientSearch/Patient'; @@ -13,11 +14,40 @@ import Moh731SyncQueueComponent from './components/RdeSync/Moh731Sync.component' import Observation from './components/observations/Observation'; const App = () => { - // eslint-disable-next-line @typescript-eslint/ban-types - const [currentPatient] = useState([]); + const [currentPatient, setCurrentPatient] = useState({ + preferredName: { + uuid: '', + display: '', + links: [], + }, + preferredAddress: { + uuid: '', + display: '', + links: [], + }, + gender: '', + age: 0, + birthdate: '', + }); + const contextValue: AppContextType = { - currentPatient, + currentPatient: { + preferredName: currentPatient.preferredName || { + uuid: '', + display: '', + links: [], + }, + preferredAddress: currentPatient.preferredAddress || { + uuid: '', + display: '', + links: [], + }, + gender: currentPatient.gender || '', + age: currentPatient.age || 0, + birthdate: currentPatient.birthdate || '', + }, + setCurrentPatient, }; return ( diff --git a/src/components/PatientInformation.tsx b/src/components/PatientInformation.tsx index 1c9947e..03aafd7 100644 --- a/src/components/PatientInformation.tsx +++ b/src/components/PatientInformation.tsx @@ -5,51 +5,44 @@ import SideNavBar from './SideNavBar/SideNavBar'; const PatientInformation = () => { const { currentPatient } = useContext(AppContext); - return ( <>
- {currentPatient.length <= 1 ? ( - currentPatient.map((info: any = {}, index) => ( - <> -
+ <> +
-

{info[0].person.preferredName.display[0]}

+

{currentPatient?.preferredName?.display?.[0]}

-

{info[0].person.preferredName.display}

+

{currentPatient?.preferredName?.display}

-
+
Address -

{info[0].person.preferredAddress.display}

+

{currentPatient?.preferredAddress?.display}

Gender -

{info[0]?.person.gender}

+

{currentPatient?.gender}

Age -

{info[0]?.person.age}

+

{currentPatient?.age}

Date of Birth -

{new Date(info[0]?.person.birthdate).toLocaleString().split(' ')[0].slice(0, -1)}

+

{currentPatient?.birthdate}

- )) - ) : ( -

Go to search patient..

- )}
); diff --git a/src/components/SideNavBar/SideNavBar.tsx b/src/components/SideNavBar/SideNavBar.tsx index df889f7..e96a683 100644 --- a/src/components/SideNavBar/SideNavBar.tsx +++ b/src/components/SideNavBar/SideNavBar.tsx @@ -3,26 +3,21 @@ import { AiOutlineInfoCircle } from 'react-icons/ai'; import { BsPencilSquare } from 'react-icons/bs'; import { FaWalking, FaRegCalendarAlt } from 'react-icons/fa'; import { BiBandAid } from 'react-icons/bi'; -import { NavLink } from 'react-router-dom'; -import { AppContext } from '../../context/AppContext'; - +import { NavLink, useParams } from 'react-router-dom'; const SideNavBar = () => { const activeStyle = { color: '#2FBAF1', cursor: 'pointer', }; - const { currentPatient } = useContext(AppContext); + const {id} = useParams() - const patientId = currentPatient.map((info: any = {}) => { - return info[0].uuid; - }); return (