This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
LabsTab.tsx
61 lines (53 loc) · 1.65 KB
/
LabsTab.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Alert, Table } from '@hospitalrun/components'
import format from 'date-fns/format'
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useHistory } from 'react-router-dom'
import PatientRepository from '../../shared/db/PatientRepository'
import Lab from '../../shared/model/Lab'
interface Props {
patientId: string
}
const LabsTab = (props: Props) => {
const history = useHistory()
const { patientId } = props
const { t } = useTranslation()
const [labs, setLabs] = useState<Lab[]>([])
useEffect(() => {
const fetch = async () => {
const fetchedLabs = await PatientRepository.getLabs(patientId)
setLabs(fetchedLabs)
}
fetch()
}, [patientId])
return (
<div>
{(!labs || labs.length === 0) && (
<Alert
color="warning"
title={t('patient.labs.warning.noLabs')}
message={t('patient.labs.noLabsMessage')}
/>
)}
{labs && labs.length > 0 && (
<Table
tableClassName="table table-hover"
actionsHeaderText={t('actions.label')}
getID={(row) => row.id}
data={labs}
columns={[
{ label: t('labs.lab.type'), key: 'type' },
{
label: t('labs.lab.requestedOn'),
key: 'requestedOn',
formatter: (row) => format(new Date(row.requestedOn), 'yyyy-MM-dd hh:mm a'),
},
{ label: t('labs.lab.status'), key: 'status' },
]}
actions={[{ label: t('actions.view'), action: (row) => history.push(`/labs/${row.id}`) }]}
/>
)}
</div>
)
}
export default LabsTab