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 ? ( +
{info[0].person.preferredAddress.display}
-{info[0]?.person.gender}
-{info[0]?.person.age}
-{new Date(info[0]?.person.birthdate).toLocaleString().split(" ")[0].slice(0,-1)}
-{data?.person?.preferredAddress?.display}
{data?.person?.gender}
+{data?.person?.age}
++ {new Date(data?.person?.birthdate) + .toLocaleString() + .split(" ")[0] + .slice(0, -1)} +
+Go to search patient..
)} -