Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-3211: Use admission Location as source of truth for detemining occupied beds #1333

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e710137
feat-metrics
kb019 Jun 25, 2024
f56fc3a
resolve conflicts
kb019 Aug 19, 2024
5104ac5
update metrics
kb019 Aug 26, 2024
321625b
Merge branch 'main' into feat/metrics
kb019 Aug 28, 2024
801177b
correct test
kb019 Aug 28, 2024
dd661e0
refactor useAdmission
kb019 Aug 29, 2024
c870aba
Merge branch 'main' of https://github.com/openmrs/openmrs-esm-patient…
kb019 Aug 29, 2024
7c947c8
fix e2e tests
kb019 Aug 29, 2024
82b6817
(refactor) Refactor registration form cancel modal to match conventio…
denniskigen Aug 28, 2024
9a4671a
(feat) 03-3404: follow-up -ensure the dateAppointmentScheduled <= ap…
lucyjemutai Aug 28, 2024
7bb7ed3
Merge branch 'feat/metrics' of https://github.com/kb019/openmrs-esm-p…
kb019 Aug 29, 2024
6a7e24d
correct yarn.lock
kb019 Aug 29, 2024
5e7d993
Merge branch 'main' of https://github.com/openmrs/openmrs-esm-patient…
kb019 Aug 29, 2024
a83b944
fix metrics calculations
kb019 Sep 4, 2024
74d4137
resolve conflicts
kb019 Sep 4, 2024
e4671c5
add internationalization
kb019 Sep 16, 2024
d1f9f4b
correct mocks
kb019 Sep 17, 2024
4211d83
add dir attribute
kb019 Sep 17, 2024
d2bb04d
resolve conflicts
kb019 Sep 18, 2024
bc68943
Merge branch 'main' of https://github.com/openmrs/openmrs-esm-patient…
kb019 Sep 18, 2024
9a1ca44
remove i18n code
kb019 Sep 18, 2024
18f854a
clean code
kb019 Sep 20, 2024
7eac5bf
Merge branch 'main' of https://github.com/openmrs/openmrs-esm-patient…
kb019 Sep 20, 2024
57a7dfa
use admissionLocation as source of truth
kb019 Oct 1, 2024
37101fc
resolved conflicts
kb019 Oct 1, 2024
a8c7bfa
Update packages/esm-ward-app/src/ward-view/ward-view.resource.ts
kb019 Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ const wardMetrics = [{ name: 'patients' }, { name: 'freeBeds' }, { name: 'capaci

const WardMetrics = () => {
const { location } = useWardLocation();
const { beds, isLoading, error } = useBeds({ locationUuid: location.uuid });
const { t } = useTranslation();
const isBedManagementModuleInstalled = useFeatureFlag('bedmanagement-module');
const wardPatientGroup = useAppContext<WardPatientGroupDetails>('ward-patients-group');
const { admissionLocationResponse, inpatientAdmissionResponse, inpatientRequestResponse } = wardPatientGroup || {};
const { admissionLocationResponse, inpatientAdmissionResponse, inpatientRequestResponse, bedLayouts } =
wardPatientGroup || {};
const { isLoading, error } = admissionLocationResponse ?? {};
const isDataLoading =
admissionLocationResponse?.isLoading ||
inpatientAdmissionResponse?.isLoading ||
Expand All @@ -34,7 +35,8 @@ const WardMetrics = () => {
description: error.message,
});
}
const wardMetricValues = getWardMetrics(beds, wardPatientGroup);

const wardMetricValues = getWardMetrics(bedLayouts, wardPatientGroup);
return (
<div className={styles.metricsContainer}>
{isBedManagementModuleInstalled ? (
Expand Down
13 changes: 2 additions & 11 deletions packages/esm-ward-app/src/ward-view-header/ward-metrics.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import WardMetrics from './ward-metrics.component';
import { renderWithSwr } from '../../../../tools/test-utils';
import { useBeds } from '../hooks/useBeds';
import { mockWardBeds } from '../../../../__mocks__/wardBeds.mock';
import {
createAndGetWardPatientGrouping,
getInpatientAdmissionsUuidMap,
Expand Down Expand Up @@ -52,14 +50,6 @@ jest.mock('../hooks/useInpatientRequest', () => ({
useInpatientRequest: jest.fn(),
}));

jest.mocked(useBeds).mockReturnValue({
error: undefined,
mutate: jest.fn(),
isValidating: false,
isLoading: false,
beds: mockWardBeds,
});

const mockAdmissionLocationResponse = jest.mocked(useAdmissionLocation).mockReturnValue({
error: undefined,
mutate: jest.fn(),
Expand Down Expand Up @@ -90,7 +80,8 @@ describe('Ward Metrics', () => {
errorFetchingLocation: null,
invalidLocation: true,
});
const bedMetrics = getWardMetrics(mockWardBeds, mockWardPatientGroupDetails);
const { bedLayouts } = mockWardPatientGroupDetails;
const bedMetrics = getWardMetrics(bedLayouts, mockWardPatientGroupDetails);
renderWithSwr(<WardMetrics />);
for (let [key, value] of Object.entries(bedMetrics)) {
const fieldName = wardMetrics.find((metric) => metric.name == key)?.defaultTranslation;
Expand Down
10 changes: 5 additions & 5 deletions packages/esm-ward-app/src/ward-view/ward-view.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ export function filterBeds(admissionLocation: AdmissionLocationFetchResponse): B
const bedLayouts = admissionLocation.bedLayouts
.filter((bl) => bl.bedId)
.sort((bedA, bedB) => collator.compare(bedA.bedNumber, bedB.bedNumber));

return bedLayouts;
}

//TODO: This implementation will change when the api is ready
export function getWardMetrics(beds: Bed[], wardPatientGroup: WardPatientGroupDetails): WardMetrics {
export function getWardMetrics(bedLayouts: BedLayout[], wardPatientGroup: WardPatientGroupDetails): WardMetrics {
const bedMetrics = {
patients: '--',
freeBeds: '--',
capacity: '--',
};
if (beds == null || beds.length == 0) return bedMetrics;
const total = beds.length;
const occupiedBeds = beds.filter((bed) => bed.status === 'OCCUPIED');
if (bedLayouts == null || bedLayouts.length == 0) return bedMetrics;
const total = bedLayouts.length;
const occupiedBeds = bedLayouts.filter((bed) => bed.patients.length);
kb019 marked this conversation as resolved.
Show resolved Hide resolved
const patients = occupiedBeds.length;
const freeBeds = total - patients;
const capacity = total != 0 ? Math.trunc((wardPatientGroup.totalPatientsCount / total) * 100) : 0;
Expand Down Expand Up @@ -72,7 +73,6 @@ export function createAndGetWardPatientGrouping(
const wardUnadmittedPatientsWithBed = new Map<string, Patient>();
const bedLayouts = admissionLocation && filterBeds(admissionLocation);
const allWardPatientUuids = new Set<string>();

let wardPatientPendingCount = 0;
bedLayouts?.map((bedLayout) => {
const { patients } = bedLayout;
Expand Down
Loading