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
66 lines (58 loc) · 1.72 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
62
63
64
65
66
import React, { useEffect, useState } from 'react'
import { Alert } from '@hospitalrun/components'
import { useTranslation } from 'react-i18next'
import format from 'date-fns/format'
import { useHistory } from 'react-router-dom'
import Lab from '../../model/Lab'
import LabRepository from '../../clients/db/LabRepository'
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 LabRepository.findAllByPatientId(patientId)
setLabs(fetchedLabs)
}
fetch()
}, [patientId])
const onTableRowClick = (lab: Lab) => {
history.push(`/labs/${lab.id}`)
}
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 className="table table-hover">
<thead className="thead-light">
<tr>
<th>{t('labs.lab.type')}</th>
<th>{t('labs.lab.requestedOn')}</th>
<th>{t('labs.lab.status')}</th>
</tr>
</thead>
<tbody>
{labs.map((lab) => (
<tr onClick={() => onTableRowClick(lab)} key={lab.id}>
<td>{lab.type}</td>
<td>{format(new Date(lab.requestedOn), 'yyyy-MM-dd hh:mm a')}</td>
<td>{lab.status}</td>
</tr>
))}
</tbody>
</table>
)}
</div>
)
}
export default LabsTab