Skip to content

Commit

Permalink
(fix) - O3-4015 - Ward App - patient should get unassigned from bed a…
Browse files Browse the repository at this point in the history
…t old l… (#1326)

* (fix) - O3-4015 - Ward App - patient get unassigned from bed at old location upon transfer to new location

* address PR comment
  • Loading branch information
chibongho authored Sep 25, 2024
1 parent fbeab75 commit b3d1e4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ describe('Testing AdmitPatientForm', () => {
});

it('should admit patient if no beds are configured', async () => {
const replacedProperty = jest.replaceProperty(mockWardPatientGroupDetails(), 'bedLayouts', []);
// @ts-ignore - we only need these two keys for now
mockedOpenmrsFetch.mockResolvedValue({
ok: true,
Expand All @@ -335,7 +334,7 @@ describe('Testing AdmitPatientForm', () => {
const admitButton = screen.getByRole('button', { name: 'Admit' });
expect(admitButton).toBeEnabled();
await user.click(admitButton);
expect(mockedOpenmrsFetch).toHaveBeenCalledTimes(1);
expect(mockedOpenmrsFetch).toHaveBeenCalledTimes(2);
expect(mockedOpenmrsFetch).toHaveBeenCalledWith('/ws/rest/v1/encounter', {
method: 'POST',
headers: {
Expand All @@ -354,11 +353,13 @@ describe('Testing AdmitPatientForm', () => {
],
},
});
expect(mockedOpenmrsFetch).toHaveBeenCalledWith(`/ws/rest/v1/beds/1?patientUuid=${mockPatientAlice.uuid}`, {
method: 'DELETE',
});
expect(mockedShowSnackbar).toHaveBeenCalledWith({
kind: 'success',
subtitle: 'Patient admitted successfully to Inpatient Ward',
title: 'Patient admitted successfully',
});
replacedProperty.restore();
});
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Button, ButtonSet, Column, Dropdown, DropdownSkeleton, Form, InlineNotification, Row } from '@carbon/react';
import { zodResolver } from '@hookform/resolvers/zod';
import { showSnackbar, useAppContext, useFeatureFlag, useSession } from '@openmrs/esm-framework';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { z } from 'zod';
import { Controller, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { useTranslation } from 'react-i18next';
import { Button, ButtonSet, Column, Dropdown, DropdownSkeleton, Form, InlineNotification, Row } from '@carbon/react';
import { showSnackbar, useAppContext, useFeatureFlag, useSession } from '@openmrs/esm-framework';
import { filterBeds } from '../../ward-view/ward-view.resource';
import type { BedLayout, WardPatientGroupDetails } from '../../types';
import { assignPatientToBed, createEncounter } from '../../ward.resource';
import { useInpatientRequest } from '../../hooks/useInpatientRequest';
import { z } from 'zod';
import useEmrConfiguration from '../../hooks/useEmrConfiguration';
import useWardLocation from '../../hooks/useWardLocation';
import type { AdmitPatientFormWorkspaceProps } from './types';
import type { BedLayout, WardPatientGroupDetails } from '../../types';
import { assignPatientToBed, createEncounter, removePatientFromBed } from '../../ward.resource';
import styles from './admit-patient-form.scss';
import type { AdmitPatientFormWorkspaceProps } from './types';

const AdmitPatientFormWorkspace: React.FC<AdmitPatientFormWorkspaceProps> = ({
patient,
Expand All @@ -25,11 +23,11 @@ const AdmitPatientFormWorkspace: React.FC<AdmitPatientFormWorkspaceProps> = ({
const { location } = useWardLocation();
const { currentProvider } = useSession();
const [isSubmitting, setIsSubmitting] = useState(false);
const { mutate: mutateInpatientRequest } = useInpatientRequest();
const { emrConfiguration, isLoadingEmrConfiguration, errorFetchingEmrConfiguration } = useEmrConfiguration();
const [showErrorNotifications, setShowErrorNotifications] = useState(false);
const wardPatientGrouping = useAppContext<WardPatientGroupDetails>('ward-patients-group');
const { isLoading, mutate: mutateAdmissionLocation } = wardPatientGrouping?.admissionLocationResponse ?? {};
const { mutate: mutateInpatientRequest } = wardPatientGrouping?.inpatientRequestResponse ?? {};
const beds = isLoading ? [] : wardPatientGrouping?.bedLayouts ?? [];
const isBedManagementModuleInstalled = useFeatureFlag('bedmanagement-module');
const getBedRepresentation = useCallback((bedLayout: BedLayout) => {
Expand Down Expand Up @@ -92,8 +90,15 @@ const AdmitPatientFormWorkspace: React.FC<AdmitPatientFormWorkspaceProps> = ({
if (response.ok) {
if (bedSelected) {
return assignPatientToBed(values.bedId, patient.uuid, response.data.uuid);
} else {
const bed = wardPatientGrouping.bedLayouts.find((bedLayout) =>
bedLayout.patients.some((p) => p.uuid == patient.uuid),
);
if (bed) {
return removePatientFromBed(bed.bedId, patient.uuid);
}
return response;
}
return response;
}
},
(err: Error) => {
Expand Down

0 comments on commit b3d1e4a

Please sign in to comment.