From 57a7dfa9b9163fb5096121bb3099bb7b141bacc4 Mon Sep 17 00:00:00 2001 From: Bhargav Kodali Date: Tue, 1 Oct 2024 13:30:13 -0700 Subject: [PATCH] use admissionLocation as source of truth --- .../src/ward-view-header/ward-metrics.component.tsx | 8 +++++--- .../src/ward-view-header/ward-metrics.test.tsx | 13 ++----------- .../src/ward-view/ward-view.resource.ts | 10 +++++----- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/esm-ward-app/src/ward-view-header/ward-metrics.component.tsx b/packages/esm-ward-app/src/ward-view-header/ward-metrics.component.tsx index 0008158d5..87005bab2 100644 --- a/packages/esm-ward-app/src/ward-view-header/ward-metrics.component.tsx +++ b/packages/esm-ward-app/src/ward-view-header/ward-metrics.component.tsx @@ -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('ward-patients-group'); - const { admissionLocationResponse, inpatientAdmissionResponse, inpatientRequestResponse } = wardPatientGroup || {}; + const { admissionLocationResponse, inpatientAdmissionResponse, inpatientRequestResponse, bedLayouts } = + wardPatientGroup || {}; + const { isLoading, error } = admissionLocationResponse ?? {}; const isDataLoading = admissionLocationResponse?.isLoading || inpatientAdmissionResponse?.isLoading || @@ -34,7 +35,8 @@ const WardMetrics = () => { description: error.message, }); } - const wardMetricValues = getWardMetrics(beds, wardPatientGroup); + + const wardMetricValues = getWardMetrics(bedLayouts, wardPatientGroup); return (
{isBedManagementModuleInstalled ? ( diff --git a/packages/esm-ward-app/src/ward-view-header/ward-metrics.test.tsx b/packages/esm-ward-app/src/ward-view-header/ward-metrics.test.tsx index 84b7bdbb7..557b5bdea 100644 --- a/packages/esm-ward-app/src/ward-view-header/ward-metrics.test.tsx +++ b/packages/esm-ward-app/src/ward-view-header/ward-metrics.test.tsx @@ -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, @@ -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(), @@ -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(); for (let [key, value] of Object.entries(bedMetrics)) { const fieldName = wardMetrics.find((metric) => metric.name == key)?.defaultTranslation; diff --git a/packages/esm-ward-app/src/ward-view/ward-view.resource.ts b/packages/esm-ward-app/src/ward-view/ward-view.resource.ts index c934107e0..295671dc1 100644 --- a/packages/esm-ward-app/src/ward-view/ward-view.resource.ts +++ b/packages/esm-ward-app/src/ward-view/ward-view.resource.ts @@ -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; @@ -72,7 +73,6 @@ export function createAndGetWardPatientGrouping( const wardUnadmittedPatientsWithBed = new Map(); const bedLayouts = admissionLocation && filterBeds(admissionLocation); const allWardPatientUuids = new Set(); - let wardPatientPendingCount = 0; bedLayouts?.map((bedLayout) => { const { patients } = bedLayout;