Skip to content

Commit

Permalink
use admissionLocation as source of truth
Browse files Browse the repository at this point in the history
  • Loading branch information
kb019 committed Oct 1, 2024
1 parent 7eac5bf commit 57a7dfa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
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);
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

0 comments on commit 57a7dfa

Please sign in to comment.