From 15ea98617b7e63197685f3d42e072d4082636a1b Mon Sep 17 00:00:00 2001 From: Khavin Shankar Date: Mon, 23 Sep 2024 17:56:45 +0530 Subject: [PATCH] Cleanup bed types (#8456) --- .../e2e/facility_spec/FacilityCreation.cy.ts | 4 +-- .../e2e/facility_spec/FacilityManage.cy.ts | 2 +- src/Common/constants.tsx | 26 +------------------ src/Components/Facility/BedCapacity.tsx | 16 +++++++----- .../Facility/FacilityBedCapacity.tsx | 9 ++++--- src/Components/Facility/FacilityCreate.tsx | 4 +-- src/Locale/en/Facility.json | 5 ++++ 7 files changed, 27 insertions(+), 39 deletions(-) diff --git a/cypress/e2e/facility_spec/FacilityCreation.cy.ts b/cypress/e2e/facility_spec/FacilityCreation.cy.ts index 57735a9dcde..918e926d107 100644 --- a/cypress/e2e/facility_spec/FacilityCreation.cy.ts +++ b/cypress/e2e/facility_spec/FacilityCreation.cy.ts @@ -142,7 +142,7 @@ describe("Facility Creation", () => { facilityPage.submitForm(); cy.closeNotification(); // create multiple bed capacity and verify card reflection - facilityPage.selectBedType("Oxygen beds"); + facilityPage.selectBedType("Oxygen Supported Bed"); facilityPage.fillTotalCapacity(bedCapacity); facilityPage.fillCurrentlyOccupied(bedOccupancy); facilityPage.clickbedcapcityaddmore(); @@ -216,7 +216,7 @@ describe("Facility Creation", () => { facilityPage.fillPhoneNumber(facilityNumber); facilityPage.submitForm(); // add the bed capacity - facilityPage.selectBedType("Oxygen beds"); + facilityPage.selectBedType("Oxygen Supported Bed"); facilityPage.fillTotalCapacity(oxygenCapacity); facilityPage.fillCurrentlyOccupied(oxygenExpected); facilityPage.saveAndExitBedCapacityForm(); diff --git a/cypress/e2e/facility_spec/FacilityManage.cy.ts b/cypress/e2e/facility_spec/FacilityManage.cy.ts index e4f4ba40ff1..c53943733e9 100644 --- a/cypress/e2e/facility_spec/FacilityManage.cy.ts +++ b/cypress/e2e/facility_spec/FacilityManage.cy.ts @@ -138,7 +138,7 @@ describe("Facility Manage Functions", () => { it("Modify bed capacity in Facility detail page", () => { // add multiple new bed capacity facilityManage.clickFacilityAddBedTypeButton(); - facilityPage.selectBedType("Oxygen beds"); + facilityPage.selectBedType("Isolation Bed"); facilityPage.fillTotalCapacity(totalCapacity); facilityPage.fillCurrentlyOccupied(currentOccupied); facilityPage.saveAndExitBedCapacityForm(); diff --git a/src/Common/constants.tsx b/src/Common/constants.tsx index c2ddf842665..307e912844f 100644 --- a/src/Common/constants.tsx +++ b/src/Common/constants.tsx @@ -8,7 +8,6 @@ import { ConsentHIType, ConsentPurpose, } from "../Components/ABDM/types/consent"; -import careConfig from "@careConfig"; export const RESULTS_PER_PAGE_LIMIT = 14; export const PAGINATION_LIMIT = 36; @@ -217,30 +216,7 @@ export const DISCHARGED_PATIENT_SORT_OPTIONS: SortOption[] = [ { isAscending: false, value: "-name" }, ]; -const { kasp } = careConfig; - -const KASP_BED_TYPES = kasp.enabled - ? [ - { id: 40, text: kasp.string + " Ordinary Beds" }, - { id: 60, text: kasp.string + " Oxygen beds" }, - { id: 50, text: kasp.string + " ICU (ICU without ventilator)" }, - { id: 70, text: kasp.string + " ICU (ICU with ventilator)" }, - ] - : []; - -export const BED_TYPES: OptionsType[] = [ - { id: 1, text: "Ordinary Beds" }, - { id: 150, text: "Oxygen beds" }, - { id: 10, text: "ICU (ICU without ventilator)" }, - { id: 20, text: "Ventilator (ICU with ventilator)" }, - { id: 30, text: "Covid Ordinary Beds" }, - { id: 120, text: "Covid Oxygen beds" }, - { id: 110, text: "Covid ICU (ICU without ventilator)" }, - { id: 100, text: "Covid Ventilators (ICU with ventilator)" }, - ...KASP_BED_TYPES, - { id: 2, text: "Hostel" }, - { id: 3, text: "Single Room with Attached Bathroom" }, -]; +export const BED_TYPES = [100, 200, 300, 400, 500]; export const DOCTOR_SPECIALIZATION: Array = [ { id: 1, text: "General Medicine" }, diff --git a/src/Components/Facility/BedCapacity.tsx b/src/Components/Facility/BedCapacity.tsx index a4437823d5d..7d36190c441 100644 --- a/src/Components/Facility/BedCapacity.tsx +++ b/src/Components/Facility/BedCapacity.tsx @@ -1,14 +1,14 @@ import { useEffect, useReducer, useState } from "react"; import * as Notification from "../../Utils/Notifications.js"; -import { CapacityModal } from "./models"; +import { CapacityModal, OptionsType } from "./models"; import TextFormField from "../Form/FormFields/TextFormField"; import { Cancel, Submit } from "../Common/components/ButtonV2"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; import { FieldChangeEvent } from "../Form/FormFields/Utils"; +import { BED_TYPES } from "../../Common/constants"; import routes from "../../Redux/api"; import request from "../../Utils/request/request"; import { useTranslation } from "react-i18next"; -import { BED_TYPES } from "../../Common/constants.js"; interface BedCapacityProps extends CapacityModal { facilityId: string; @@ -52,8 +52,10 @@ export const BedCapacity = (props: BedCapacityProps) => { const { t } = useTranslation(); const { facilityId, handleClose, handleUpdate, className, id } = props; const [state, dispatch] = useReducer(bedCountReducer, initialState); - const [bedTypes, setBedTypes] = useState(BED_TYPES); const [isLastOptionType, setIsLastOptionType] = useState(false); + const [bedTypes, setBedTypes] = useState( + BED_TYPES.map((o) => ({ id: o, text: t(`bed_type__${o}`) })), + ); const [isLoading, setIsLoading] = useState(false); const headerText = !id ? "Add Bed Capacity" : "Edit Bed Capacity"; @@ -77,10 +79,11 @@ export const BedCapacity = (props: BedCapacityProps) => { // disable existing bed types const updatedBedTypes = BED_TYPES.map((type) => { const isExisting = existingData.find( - (i: CapacityModal) => i.room_type === type.id, + (i: CapacityModal) => i.room_type === type, ); return { - ...type, + id: type, + text: t(`bed_type__${type}`), disabled: !!isExisting, }; }); @@ -111,7 +114,8 @@ export const BedCapacity = (props: BedCapacityProps) => { useEffect(() => { const lastBedType = - bedTypes.filter((i) => i.disabled).length === BED_TYPES.length - 1; + bedTypes.filter((i: OptionsType) => i.disabled).length === + BED_TYPES.length - 1; setIsLastOptionType(lastBedType); }, [bedTypes]); diff --git a/src/Components/Facility/FacilityBedCapacity.tsx b/src/Components/Facility/FacilityBedCapacity.tsx index 77481fa8716..a293787afce 100644 --- a/src/Components/Facility/FacilityBedCapacity.tsx +++ b/src/Components/Facility/FacilityBedCapacity.tsx @@ -1,4 +1,5 @@ import { useState } from "react"; +import { BED_TYPES } from "../../Common/constants"; import routes from "../../Redux/api"; import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import useQuery from "../../Utils/request/useQuery"; @@ -7,9 +8,11 @@ import ButtonV2 from "../Common/components/ButtonV2"; import { BedCapacity } from "./BedCapacity"; import BedTypeCard from "./BedTypeCard"; import CareIcon from "../../CAREUI/icons/CareIcon"; -import { BED_TYPES } from "../../Common/constants"; +import { useTranslation } from "react-i18next"; export const FacilityBedCapacity = (props: any) => { + const { t } = useTranslation(); + const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false); const capacityQuery = useQuery(routes.getCapacity, { @@ -45,7 +48,7 @@ export const FacilityBedCapacity = (props: any) => { /> {BED_TYPES.map((x) => { const res = capacityQuery.data?.results.find((data) => { - return data.room_type === x.id; + return data.room_type === x; }); if ( res && @@ -64,7 +67,7 @@ export const FacilityBedCapacity = (props: any) => { bedCapacityId={res.id} key={`bed_${res.id}`} room_type={res.room_type} - label={x.text} + label={t(`bed_type__${x}`)} used={res.current_capacity} total={res.total_capacity} lastUpdated={res.modified_date} diff --git a/src/Components/Facility/FacilityCreate.tsx b/src/Components/Facility/FacilityCreate.tsx index 9c76e6e0ea0..1fe9d2e207e 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -564,7 +564,7 @@ export const FacilityCreate = (props: FacilityProps) => { /> {BED_TYPES.map((x) => { const res = capacityData.find((data) => { - return data.room_type === x.id; + return data.room_type === x; }); if (res) { const removeCurrentBedType = (bedTypeId: number | undefined) => { @@ -579,7 +579,7 @@ export const FacilityCreate = (props: FacilityProps) => { bedCapacityId={res.id} key={`bed_${res.id}`} room_type={res.room_type} - label={x.text} + label={t(`bed_type__${x}`)} used={res.current_capacity || 0} total={res.total_capacity || 0} lastUpdated={res.modified_date} diff --git a/src/Locale/en/Facility.json b/src/Locale/en/Facility.json index e061dee620e..4e835bec675 100644 --- a/src/Locale/en/Facility.json +++ b/src/Locale/en/Facility.json @@ -101,6 +101,11 @@ "duplicate_patient_record_birth_unknown": "Please contact your district care coordinator, the shifting facility or the patient themselves if you are not sure about the patient's year of birth.", "patient_transfer_birth_match_note": "Note: Year of birth must match the patient to process the transfer request.", "cover_image_updated_note": "It could take a while to see the updated cover image", + "bed_type__100": "ICU Bed", + "bed_type__200": "Ordinary Bed", + "bed_type__300": "Oxygen Supported Bed", + "bed_type__400": "Isolation Bed", + "bed_type__500": "Others", "available_features": "Available Features", "update_facility": "Update Facility", "configure_facility": "Configure Facility",