Skip to content

Commit

Permalink
(fix) O3-3849 Ward App - make patient header appear consistently in a…
Browse files Browse the repository at this point in the history
…ll ward workspaces
  • Loading branch information
chibongho committed Oct 29, 2024
1 parent 8761fb7 commit 1f03fee
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 221 deletions.
144 changes: 72 additions & 72 deletions __mocks__/inpatient-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,81 @@ import { mockLocationInpatientWard } from './locations.mock';
import { mockPatientAlice } from './patient.mock';
import { mockVisitAlice } from './visits.mock';

export const mockInpatientRequest: InpatientRequest[] = [
{
patient: mockPatientAlice,
visit: mockVisitAlice,
dispositionLocation: mockLocationInpatientWard,
dispositionType: 'ADMIT',
disposition: {
uuid: '6c047a20-c2bf-43ef-9e88-6da7b17e8c1a',
export const mockInpatientRequestAlice: InpatientRequest = {
patient: mockPatientAlice,
visit: mockVisitAlice,
dispositionLocation: mockLocationInpatientWard,
dispositionType: 'ADMIT',
disposition: {
uuid: '6c047a20-c2bf-43ef-9e88-6da7b17e8c1a',
display: 'Admit to hospital',
name: {
display: 'Admit to hospital',
name: {
display: 'Admit to hospital',
uuid: 'b1e494ef-4779-4262-bc42-56a79c39303c',
name: 'Admit to hospital',
locale: 'en',
localePreferred: true,
conceptNameType: 'FULLY_SPECIFIED',
},
datatype: {
uuid: '8d4a4c94-c2cc-11de-8d13-0010c6dffd0f',
display: 'N/A',
},
conceptClass: {
uuid: '8d492774-c2cc-11de-8d13-0010c6dffd0f',
display: 'Misc',
},
set: false,
version: null,
retired: false,
names: [
{
uuid: '122a523c-cbec-4283-991f-858f44ffccca',
display: 'Hospital admission',
},
{
uuid: 'b1e494ef-4779-4262-bc42-56a79c39303c',
name: 'Admit to hospital',
locale: 'en',
localePreferred: true,
conceptNameType: 'FULLY_SPECIFIED',
display: 'Admit to hospital',
},
datatype: {
uuid: '8d4a4c94-c2cc-11de-8d13-0010c6dffd0f',
display: 'N/A',
{
uuid: 'f72fadb0-d5db-102d-ad2a-000c29c2a5d7',
display: "ADMIS Á L'HÔPITAL",
},
conceptClass: {
uuid: '8d492774-c2cc-11de-8d13-0010c6dffd0f',
display: 'Misc',
{
uuid: 'acdcc1d2-7414-4337-890e-c8ccbccda41a',
display: 'Admèt nan lopital',
},
set: false,
version: null,
retired: false,
names: [
{
uuid: '122a523c-cbec-4283-991f-858f44ffccca',
display: 'Hospital admission',
},
{
uuid: 'b1e494ef-4779-4262-bc42-56a79c39303c',
display: 'Admit to hospital',
},
{
uuid: 'f72fadb0-d5db-102d-ad2a-000c29c2a5d7',
display: "ADMIS Á L'HÔPITAL",
},
{
uuid: 'acdcc1d2-7414-4337-890e-c8ccbccda41a',
display: 'Admèt nan lopital',
},
{
uuid: '4f12edd7-e516-493b-bc21-da1a9d29873f',
display: "Admettre à l'hôpital",
},
],
descriptions: [
{
uuid: '7d29309b-faaa-4767-83e6-6c75117fc569',
display: 'patient will be admitted from the clinic to the hospital for managment of an acute problem.',
},
],
mappings: [
{
uuid: '75a1a11e-4943-102e-96e9-000c29c2a5d7',
display: 'PIH: ADMIT TO HOSPITAL',
},
{
uuid: 'b260d122-4864-102e-96e9-000c29c2a5d7',
display: 'PIH: 3799',
},
],
answers: [],
setMembers: [],
attributes: [],
resourceVersion: '2.0',
},
dispositionEncounter: {
uuid: '6c047a20-c2bf-43ef-9e88-6da7b17e8c1a',
display: 'Admit to hospital',
encounterDatetime: '2021-09-28T11:00:00.000Z',
},
{
uuid: '4f12edd7-e516-493b-bc21-da1a9d29873f',
display: "Admettre à l'hôpital",
},
],
descriptions: [
{
uuid: '7d29309b-faaa-4767-83e6-6c75117fc569',
display: 'patient will be admitted from the clinic to the hospital for managment of an acute problem.',
},
],
mappings: [
{
uuid: '75a1a11e-4943-102e-96e9-000c29c2a5d7',
display: 'PIH: ADMIT TO HOSPITAL',
},
{
uuid: 'b260d122-4864-102e-96e9-000c29c2a5d7',
display: 'PIH: 3799',
},
],
answers: [],
setMembers: [],
attributes: [],
resourceVersion: '2.0',
},
dispositionEncounter: {
uuid: '6c047a20-c2bf-43ef-9e88-6da7b17e8c1a',
display: 'Admit to hospital',
encounterDatetime: '2021-09-28T11:00:00.000Z',
},
];
};

export const mockInpatientRequests = [mockInpatientRequestAlice];
9 changes: 5 additions & 4 deletions packages/esm-ward-app/mock.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mockAdmissionLocation, mockInpatientAdmissions, mockInpatientRequest } from '__mocks__';
import { mockAdmissionLocation, mockInpatientAdmissions, mockInpatientRequests } from '__mocks__';
import { useAdmissionLocation } from './src/hooks/useAdmissionLocation';
import { useInpatientAdmission } from './src/hooks/useInpatientAdmission';
import { createAndGetWardPatientGrouping } from './src/ward-view/ward-view.resource';
Expand Down Expand Up @@ -38,22 +38,23 @@ const mockInpatientAdmissionResponse = jest.mocked(useInpatientAdmission).mockRe
});

const mockInpatientRequestResponse = jest.mocked(useInpatientRequest).mockReturnValue({
inpatientRequests: mockInpatientRequest,
inpatientRequests: mockInpatientRequests,
hasMore: false,
loadMore: jest.fn(),
isValidating: false,
isLoading: false,
error: undefined,
mutate: jest.fn(),
totalCount: mockInpatientRequest.length,
totalCount: mockInpatientRequests.length,
});

export const mockWardPatientGroupDetails = jest.mocked(useWardPatientGrouping).mockReturnValue({
admissionLocationResponse: mockAdmissionLocationResponse(),
inpatientAdmissionResponse: mockInpatientAdmissionResponse(),
inpatientRequestResponse: mockInpatientRequestResponse(),
...createAndGetWardPatientGrouping(mockInpatientAdmissions, mockAdmissionLocation, mockInpatientRequest),
...createAndGetWardPatientGrouping(mockInpatientAdmissions, mockAdmissionLocation, mockInpatientRequests),
isLoading: false,
mutate: jest.fn(),
});

export const mockWardViewContext: WardViewContext = {
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-ward-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"name": "ward-patient-workspace",
"component": "wardPatientWorkspace",
"type": "ward",
"title": "Ward Patient",
"title": "Ward patient",
"width": "extra-wide",
"hasOwnSidebar": true,
"sidebarFamily": "ward-patient"
Expand Down
18 changes: 5 additions & 13 deletions packages/esm-ward-app/src/ward-view-header/ward-metrics.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { useAppContext } from '@openmrs/esm-framework';
import { screen } from '@testing-library/react';
import React from 'react';
import WardMetrics from './ward-metrics.component';
import { renderWithSwr } from '../../../../tools/test-utils';
import {
createAndGetWardPatientGrouping,
getInpatientAdmissionsUuidMap,
getWardMetrics,
} from '../ward-view/ward-view.resource';
import { useAdmissionLocation } from '../hooks/useAdmissionLocation';
import { mockAdmissionLocation, mockInpatientAdmissions, mockInpatientRequest } from '__mocks__';
import { useInpatientAdmission } from '../hooks/useInpatientAdmission';
import useWardLocation from '../hooks/useWardLocation';
import { screen } from '@testing-library/react';
import { useAppContext } from '@openmrs/esm-framework';
import { type WardViewContext } from '../types';
import { mockWardViewContext } from '../../mock';
import { type WardViewContext } from '../types';
import { getWardMetrics } from '../ward-view/ward-view.resource';
import WardMetrics from './ward-metrics.component';

const wardMetrics = [
{ name: 'patients', key: 'patients', defaultTranslation: 'Patients' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import useWardLocation from '../../hooks/useWardLocation';
import type { WardPatientCardType, WardPatientWorkspaceProps, WardViewContext } from '../../types';
import { useAdmitPatient } from '../../ward.resource';
import { AdmissionRequestsWorkspaceContext } from '../admission-request-workspace/admission-requests.workspace';
import type { AdmitPatientFormWorkspaceProps } from '../admit-patient-form-workspace/types';
import styles from './admission-request-card.scss';

const AdmissionRequestCardActions: WardPatientCardType = (wardPatient) => {
Expand All @@ -25,10 +24,8 @@ const AdmissionRequestCardActions: WardPatientCardType = (wardPatient) => {
const { WardPatientHeader, wardPatientGroupDetails } = useAppContext<WardViewContext>('ward-view-context') ?? {};
const { admitPatient, isLoadingEmrConfiguration, errorFetchingEmrConfiguration } = useAdmitPatient();

const launchPatientAdmissionForm = useCallback(
() => launchWorkspace<AdmitPatientFormWorkspaceProps>('admit-patient-form-workspace', { patient, dispositionType }),
[],
);
const launchPatientAdmissionForm = () =>
launchWorkspace<WardPatientWorkspaceProps>('admit-patient-form-workspace', { wardPatient, WardPatientHeader });

const launchPatientTransferForm = useCallback(() => {
launchWorkspace<WardPatientWorkspaceProps>('patient-transfer-request-workspace', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
@use '@carbon/layout';
@use '@openmrs/esm-styleguide/src/vars' as *;

.flexWrapper {
height: 100%;
display: flex;
flex-direction: column;
color: #393939;
}

.form {
display: flex;
height: 100%;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { showSnackbar, useAppContext, useFeatureFlag, useSession } from '@openmrs/esm-framework';
import {
CloseWorkspaceOptions,
type DefaultWorkspaceProps,
showSnackbar,
useAppContext,
useFeatureFlag,
useSession,
} from '@openmrs/esm-framework';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { mockLocationInpatientWard, mockPatientAlice } from '../../../../../__mocks__';
import { mockInpatientRequestAlice, mockLocationInpatientWard, mockPatientAlice } from '../../../../../__mocks__';
import { renderWithSwr } from '../../../../../tools';
import { mockWardPatientGroupDetails, mockWardViewContext } from '../../../mock';
import { useAssignedBedByPatient } from '../../hooks/useAssignedBedByPatient';
import useWardLocation from '../../hooks/useWardLocation';
import type { DispositionType, WardViewContext } from '../../types';
import type { DispositionType, WardPatient, WardViewContext } from '../../types';
import { assignPatientToBed, removePatientFromBed, useAdmitPatient } from '../../ward.resource';
import AdmitPatientFormWorkspace from './admit-patient-form.workspace';
import type { AdmitPatientFormWorkspaceProps } from './types';

jest.mock('../../hooks/useAdmissionLocation', () => ({
useAdmissionLocation: jest.fn(),
Expand Down Expand Up @@ -52,25 +58,35 @@ const mockedUseAdmitPatient = jest.mocked(useAdmitPatient);

jest.mocked(useAppContext<WardViewContext>).mockReturnValue(mockWardViewContext);

const mockedAdmitPatient = jest.fn();
const mockUseAdmitPatientObj: ReturnType<typeof useAdmitPatient> = {
admitPatient: jest.fn(),
admitPatient: mockedAdmitPatient,
isLoadingEmrConfiguration: false,
errorFetchingEmrConfiguration: false,
};
jest.mocked(useAdmitPatient).mockReturnValue(mockUseAdmitPatientObj);
const mockedAdmitPatient = mockUseAdmitPatientObj.admitPatient;

const mockWorkspaceProps: AdmitPatientFormWorkspaceProps = {
patient: mockPatientAlice,
closeWorkspace: jest.fn(),
const mockWorkspaceProps: DefaultWorkspaceProps = {
closeWorkspaceWithSavedChanges: jest.fn(),
promptBeforeClosing: jest.fn(),
setTitle: jest.fn(),
dispositionType: 'ADMIT',
closeWorkspace: jest.fn(),
};

const mockWardPatientAliceProps: WardPatient = {
visit: mockInpatientRequestAlice.visit,
patient: mockPatientAlice,
bed: null,
inpatientAdmission: null,
inpatientRequest: mockInpatientRequestAlice,
};

function renderAdmissionForm(dispositionType: DispositionType = 'ADMIT') {
renderWithSwr(<AdmitPatientFormWorkspace {...{ ...mockWorkspaceProps, dispositionType }} />);
function renderAdmissionForm() {
renderWithSwr(
<AdmitPatientFormWorkspace
{...{ ...mockWorkspaceProps, wardPatient: mockWardPatientAliceProps, WardPatientHeader: jest.fn() }}
/>,
);
}

describe('Testing AdmitPatientForm', () => {
Expand Down
Loading

0 comments on commit 1f03fee

Please sign in to comment.