forked from HospitalRun/hospitalrun-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(viewpatient): added labs tab to ViewPatient
A patient can see all his requests for labs in the Labs tab fix HospitalRun#1972
- Loading branch information
Showing
9 changed files
with
807 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import '../../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import configureMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
import { mount } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import { Router } from 'react-router' | ||
import { Provider } from 'react-redux' | ||
import * as components from '@hospitalrun/components' | ||
import format from 'date-fns/format' | ||
import { act } from 'react-dom/test-utils' | ||
import LabsTab from '../../../patients/labs/LabsTab' | ||
import Patient from '../../../model/Patient' | ||
import Lab from '../../../model/Lab' | ||
import Permissions from '../../../model/Permissions' | ||
import LabRepository from '../../../clients/db/LabRepository' | ||
|
||
const expectedPatient = { | ||
id: '123', | ||
labs: [ | ||
{ | ||
patientId: '123', | ||
type: 'type', | ||
status: 'requested', | ||
requestedOn: new Date().toISOString(), | ||
} as Lab, | ||
], | ||
} as Patient | ||
|
||
const mockStore = configureMockStore([thunk]) | ||
const history = createMemoryHistory() | ||
|
||
let user: any | ||
let store: any | ||
|
||
const setup = (patient = expectedPatient, permissions = [Permissions.WritePatients]) => { | ||
user = { permissions } | ||
store = mockStore({ patient, user }) | ||
jest.spyOn(LabRepository, 'findLabsByPatientId').mockResolvedValue(expectedPatient.labs as Lab[]) | ||
const wrapper = mount( | ||
<Router history={history}> | ||
<Provider store={store}> | ||
<LabsTab patientId={patient.id} /> | ||
</Provider> | ||
</Router>, | ||
) | ||
|
||
return wrapper | ||
} | ||
|
||
describe('Labs Tab', () => { | ||
it('should list the patients labs', async () => { | ||
const expectedLabs = expectedPatient.labs as Lab[] | ||
let wrapper: any | ||
await act(async () => { | ||
wrapper = await setup() | ||
}) | ||
wrapper.update() | ||
|
||
const table = wrapper.find('table') | ||
const tableHeader = wrapper.find('thead') | ||
const tableHeaders = wrapper.find('th') | ||
const tableBody = wrapper.find('tbody') | ||
const tableData = wrapper.find('td') | ||
|
||
expect(table).toHaveLength(1) | ||
expect(tableHeader).toHaveLength(1) | ||
expect(tableBody).toHaveLength(1) | ||
expect(tableHeaders.at(0).text()).toEqual('labs.lab.type') | ||
expect(tableHeaders.at(1).text()).toEqual('labs.lab.requestedOn') | ||
expect(tableHeaders.at(2).text()).toEqual('labs.lab.status') | ||
expect(tableData.at(0).text()).toEqual(expectedLabs[0].type) | ||
expect(tableData.at(1).text()).toEqual( | ||
format(new Date(expectedLabs[0].requestedOn), 'yyyy-MM-dd hh:mm a'), | ||
) | ||
expect(tableData.at(2).text()).toEqual(expectedLabs[0].status) | ||
}) | ||
|
||
it('should render a warning message if the patient does not have any labs', () => { | ||
const wrapper = setup({ ...expectedPatient, labs: [] }) | ||
|
||
const alert = wrapper.find(components.Alert) | ||
|
||
expect(alert).toHaveLength(1) | ||
expect(alert.prop('title')).toEqual('patient.labs.warning.noLabs') | ||
expect(alert.prop('message')).toEqual('patient.labs.noLabsMessage') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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' | ||
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.findLabsByPatientId(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters