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
7 changed files
with
166 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
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,42 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | ||
import Lab from '../model/Lab' | ||
import { AppThunk } from '../store' | ||
import LabRepository from '../clients/db/LabRepository' | ||
|
||
interface LabsState { | ||
isLoading: boolean | ||
labs: Lab[] | ||
} | ||
|
||
const initialState: LabsState = { | ||
isLoading: false, | ||
labs: [], | ||
} | ||
|
||
function startLoading(state: LabsState) { | ||
state.isLoading = true | ||
} | ||
|
||
const labsSlice = createSlice({ | ||
name: 'labs', | ||
initialState, | ||
reducers: { | ||
fetchLabsStart: startLoading, | ||
fetchLabsSuccess: (state, { payload }: PayloadAction<Lab[]>) => { | ||
state.isLoading = false | ||
state.labs = payload | ||
}, | ||
}, | ||
}) | ||
|
||
export const { fetchLabsStart, fetchLabsSuccess } = labsSlice.actions | ||
|
||
export const fetchPatientLabs = (patientId: string): AppThunk => async (dispatch) => { | ||
dispatch(fetchLabsStart()) | ||
|
||
const labs = await LabRepository.searchPatientLabs(patientId) | ||
|
||
dispatch(fetchLabsSuccess(labs)) | ||
} | ||
|
||
export default labsSlice.reducer |
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,63 @@ | ||
import React, { useEffect } from 'react' | ||
import { Alert } from '@hospitalrun/components' | ||
import { useTranslation } from 'react-i18next' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import format from 'date-fns/format' | ||
import { useHistory } from 'react-router' | ||
import { RootState } from '../../store' | ||
import { fetchPatientLabs } from '../../labs/labs-slice' | ||
import Lab from '../../model/Lab' | ||
|
||
interface Props { | ||
patientId: string | ||
} | ||
|
||
const Labs = (props: Props) => { | ||
const dispatch = useDispatch() | ||
const history = useHistory() | ||
const { patientId } = props | ||
const { t } = useTranslation() | ||
const { labs } = useSelector((state: RootState) => state.labs) | ||
|
||
useEffect(() => { | ||
dispatch(fetchPatientLabs(patientId)) | ||
}, [dispatch, 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.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 Labs |
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