-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refactor/mpi-workflow
- Loading branch information
Showing
7 changed files
with
133 additions
and
67 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
82 changes: 82 additions & 0 deletions
82
packages/esm-ward-app/src/ward-workspace/admit-patient-button.component.tsx
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,82 @@ | ||
import { Button } from '@carbon/react'; | ||
import { | ||
ArrowRightIcon, | ||
launchWorkspace, | ||
showSnackbar, | ||
useAppContext, | ||
useFeatureFlag, | ||
useLayoutType, | ||
} from '@openmrs/esm-framework'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import useWardLocation from '../hooks/useWardLocation'; | ||
import type { WardPatient, WardPatientWorkspaceProps, WardViewContext } from '../types'; | ||
import { useAdmitPatient } from '../ward.resource'; | ||
|
||
interface AdmissionPatientButtonProps { | ||
wardPatient: WardPatient; | ||
onAdmitPatientSuccess(); | ||
} | ||
|
||
const AdmissionPatientButton: React.FC<AdmissionPatientButtonProps> = ({ wardPatient, onAdmitPatientSuccess }) => { | ||
const { patient, inpatientRequest, bed } = wardPatient ?? {}; | ||
const dispositionType = inpatientRequest?.dispositionType ?? 'ADMIT'; | ||
const { t } = useTranslation(); | ||
const { location } = useWardLocation(); | ||
const responsiveSize = useLayoutType() === 'tablet' ? 'lg' : 'md'; | ||
const { WardPatientHeader, wardPatientGroupDetails } = useAppContext<WardViewContext>('ward-view-context') ?? {}; | ||
const { admitPatient, isLoadingEmrConfiguration, errorFetchingEmrConfiguration } = useAdmitPatient(); | ||
|
||
const launchPatientAdmissionForm = () => | ||
launchWorkspace<WardPatientWorkspaceProps>('admit-patient-form-workspace', { wardPatient, WardPatientHeader }); | ||
|
||
const isBedManagementModuleInstalled = useFeatureFlag('bedmanagement-module'); | ||
|
||
// If bed management module is installed and the patient does not currently assigned a bed, | ||
// open the next form for bed selection. If not, admit patient directly | ||
// (Note that it is possible, albeit an edge case, for a patient to have a bed assigned while not admitted) | ||
const onAdmit = () => { | ||
if (isBedManagementModuleInstalled && !bed) { | ||
launchPatientAdmissionForm(); | ||
} else { | ||
admitPatient(patient, dispositionType) | ||
.then( | ||
(response) => { | ||
if (response && response?.ok) { | ||
showSnackbar({ | ||
kind: 'success', | ||
title: t('patientAdmittedSuccessfully', 'Patient admitted successfully'), | ||
subtitle: t('patientAdmittedWoBed', 'Patient admitted successfully to {{location}}', { | ||
location: location?.display, | ||
}), | ||
}); | ||
} | ||
}, | ||
(err: Error) => { | ||
showSnackbar({ | ||
kind: 'error', | ||
title: t('errorCreatingEncounter', 'Failed to admit patient'), | ||
subtitle: err.message, | ||
}); | ||
}, | ||
) | ||
.finally(() => { | ||
wardPatientGroupDetails?.mutate?.(); | ||
onAdmitPatientSuccess(); | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button | ||
kind="ghost" | ||
renderIcon={ArrowRightIcon} | ||
size={responsiveSize} | ||
disabled={isLoadingEmrConfiguration || errorFetchingEmrConfiguration} | ||
onClick={onAdmit}> | ||
{t('admitPatient', 'Admit patient')} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default AdmissionPatientButton; |
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