diff --git a/src/components/PatientInformation.tsx b/src/components/PatientInformation.tsx index 0d0d0df..4ac48ae 100644 --- a/src/components/PatientInformation.tsx +++ b/src/components/PatientInformation.tsx @@ -1,55 +1,77 @@ -import { useContext } from 'react'; -import { AppContext } from '../context/AppContext' -import Header from './Header/Header'; -import SideNavBar from './SideNavBar/SideNavBar'; - +import { useParams } from "react-router-dom"; +import Header from "./Header/Header"; +import SideNavBar from "./SideNavBar/SideNavBar"; +import useSWR from "swr"; +import { ClipLoader } from "react-spinners"; const PatientInformation = () => { - const { currentPatient } = useContext(AppContext) + const routeParams = useParams(); + const { id } = routeParams; + + const fetcher = (...args: [string]) => + fetch(...args).then((res) => res.json()); + + const { data, isLoading } = useSWR( + `/openmrs/ws/rest/v1/patient/${id}`, + fetcher + ); - return ( + return ( + <> + {isLoading ? ( +
+ +
+ ) : ( <> -
- -
- {currentPatient.length <= 1 ? currentPatient.map((info: any = {}, index) => ( - <> -
-
-
-

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

-
-
-

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

-
+
+ +
+
+
+
+

+ {data?.person?.display[0]} +

-
- -
- Address -

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

-
-
- Gender -

{info[0]?.person.gender}

-
-
- Age -

{info[0]?.person.age}

-
-
- Date of Birth -

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

-
+
+

+ {data?.person?.display} +

+
+
+
+
+ Address +

{data?.person?.preferredAddress?.display}

+
+ Gender +

{data?.person?.gender}

+
+
+ Age +

{data?.person?.age}

+
+
+ Date of Birth +

+ {new Date(data?.person?.birthdate) + .toLocaleString() + .split(" ")[0] + .slice(0, -1)} +

+
+
- - )) : (

Go to search patient..

)} -
+
- ) - -} + )} + + ); +}; -export default PatientInformation; \ No newline at end of file +export default PatientInformation;