|
| 1 | +/** @jsxImportSource @emotion/react */ |
| 2 | +import React, { useState } from 'react'; |
| 3 | + |
| 4 | +import { Button, Icon } from '@orfium/ictinus'; |
| 5 | +import { useGetHospital, useGetPatient } from 'hooks/api/patientHooks'; |
| 6 | +import { useHistory, useRouteMatch } from 'react-router-dom'; |
| 7 | + |
| 8 | +import { ButtonContainer, PageTitle, PageWrapper } from '../../common.style'; |
| 9 | +import { Tabs } from '../../components/Tabs'; |
| 10 | +import urls from '../../routing/urls'; |
| 11 | +import GeneralInformation from './components/GeneralInformation'; |
| 12 | +import { ComponentWrapper } from './PatientDetails.style'; |
| 13 | + |
| 14 | +const tabs = [ |
| 15 | + { label: 'General Information', value: 'info' }, |
| 16 | + { label: 'Episodes', value: 'episodes' }, |
| 17 | +]; |
| 18 | + |
| 19 | +const PatientDetails: React.FC = () => { |
| 20 | + const match = useRouteMatch<{ hospitalID?: string; patientID?: string }>(); |
| 21 | + const [activeTab, setActiveTab] = useState('info'); |
| 22 | + const history = useHistory(); |
| 23 | + |
| 24 | + const { hospitalID, patientID } = match.params; |
| 25 | + |
| 26 | + const { data: patient, isLoading: isPatientLoading } = useGetPatient(patientID ?? ''); |
| 27 | + const { data: hospital, isLoading: isHospitalLoading } = useGetHospital(hospitalID ?? ''); |
| 28 | + |
| 29 | + const isLoading = isHospitalLoading || isPatientLoading; |
| 30 | + |
| 31 | + return ( |
| 32 | + <PageWrapper> |
| 33 | + <PageTitle> |
| 34 | + <Icon |
| 35 | + name="fatArrowLeft" |
| 36 | + size={24} |
| 37 | + color={'lightGray-700'} |
| 38 | + onClick={() => { |
| 39 | + history.push(urls.patients()); |
| 40 | + }} |
| 41 | + /> |
| 42 | + Patient Details |
| 43 | + </PageTitle> |
| 44 | + <Tabs |
| 45 | + matchActiveDataType={activeTab} |
| 46 | + onTabClick={(tabId) => { |
| 47 | + setActiveTab(tabId); |
| 48 | + }} |
| 49 | + tabs={tabs} |
| 50 | + shouldDisplayTabs |
| 51 | + /> |
| 52 | + <ComponentWrapper> |
| 53 | + {activeTab === 'info' ? ( |
| 54 | + <GeneralInformation patient={patient} hospital={hospital} /> |
| 55 | + ) : ( |
| 56 | + <div>Episodes</div> |
| 57 | + )} |
| 58 | + </ComponentWrapper> |
| 59 | + <ButtonContainer> |
| 60 | + <Button color={'blue-500'} buttonType="button" disabled={isLoading} block size="md"> |
| 61 | + Register new episode |
| 62 | + </Button> |
| 63 | + </ButtonContainer> |
| 64 | + </PageWrapper> |
| 65 | + ); |
| 66 | +}; |
| 67 | + |
| 68 | +export default PatientDetails; |
0 commit comments