diff --git a/src/Common/constants.tsx b/src/Common/constants.tsx index 6e5a9e33e4e..b812fd9655a 100644 --- a/src/Common/constants.tsx +++ b/src/Common/constants.tsx @@ -1,4 +1,3 @@ -import { IConfig } from "./hooks/useConfig"; import { PatientCategory } from "../Components/Facility/models"; import { SortOption } from "../Components/Common/SortDropdown"; import { dateQueryString } from "../Utils/utils"; @@ -217,33 +216,7 @@ export const DISCHARGED_PATIENT_SORT_OPTIONS: SortOption[] = [ { isAscending: false, value: "-name" }, ]; -export const getBedTypes = ({ - kasp_enabled, - kasp_string, -}: Pick) => { - const kaspBedTypes = 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)" }, - ] - : []; - - return [ - { 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)" }, - ...kaspBedTypes, - { 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 c0f239203d5..5be1f712a98 100644 --- a/src/Components/Facility/BedCapacity.tsx +++ b/src/Components/Facility/BedCapacity.tsx @@ -5,8 +5,7 @@ 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 useConfig from "../../Common/hooks/useConfig"; -import { getBedTypes } from "../../Common/constants"; +import { BED_TYPES } from "../../Common/constants"; import routes from "../../Redux/api"; import request from "../../Utils/request/request"; import { useTranslation } from "react-i18next"; @@ -51,11 +50,12 @@ const bedCountReducer = (state = initialState, action: any) => { export const BedCapacity = (props: BedCapacityProps) => { const { t } = useTranslation(); - const config = useConfig(); const { facilityId, handleClose, handleUpdate, className, id } = props; const [state, dispatch] = useReducer(bedCountReducer, initialState); const [isLastOptionType, setIsLastOptionType] = useState(false); - const [bedTypes, setBedTypes] = useState(getBedTypes(config)); + 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"; @@ -73,16 +73,17 @@ export const BedCapacity = (props: BedCapacityProps) => { if (capacityQuery?.data) { const existingData = capacityQuery.data?.results; // if all options are diabled - if (existingData.length === getBedTypes(config).length) { + if (existingData.length === BED_TYPES.length) { return; } // disable existing bed types - const updatedBedTypes = getBedTypes(config).map((type: OptionsType) => { + 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, }; }); @@ -114,7 +115,7 @@ export const BedCapacity = (props: BedCapacityProps) => { useEffect(() => { const lastBedType = bedTypes.filter((i: OptionsType) => i.disabled).length === - getBedTypes(config).length - 1; + BED_TYPES.length - 1; setIsLastOptionType(lastBedType); }, [bedTypes]); diff --git a/src/Components/Facility/FacilityBedCapacity.tsx b/src/Components/Facility/FacilityBedCapacity.tsx index e2a24b3fab3..a293787afce 100644 --- a/src/Components/Facility/FacilityBedCapacity.tsx +++ b/src/Components/Facility/FacilityBedCapacity.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { getBedTypes } from "../../Common/constants"; +import { BED_TYPES } from "../../Common/constants"; import routes from "../../Redux/api"; import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import useQuery from "../../Utils/request/useQuery"; @@ -7,12 +7,13 @@ import DialogModal from "../Common/Dialog"; import ButtonV2 from "../Common/components/ButtonV2"; import { BedCapacity } from "./BedCapacity"; import BedTypeCard from "./BedTypeCard"; -import useConfig from "../../Common/hooks/useConfig"; import CareIcon from "../../CAREUI/icons/CareIcon"; +import { useTranslation } from "react-i18next"; export const FacilityBedCapacity = (props: any) => { + const { t } = useTranslation(); + const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false); - const config = useConfig(); const capacityQuery = useQuery(routes.getCapacity, { pathParams: { facilityId: props.facilityId }, @@ -45,9 +46,9 @@ export const FacilityBedCapacity = (props: any) => { return; }} /> - {getBedTypes(config).map((x) => { + {BED_TYPES.map((x) => { const res = capacityQuery.data?.results.find((data) => { - return data.room_type === x.id; + return data.room_type === x; }); if ( res && @@ -66,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 337be5703cc..88e546fa440 100644 --- a/src/Components/Facility/FacilityCreate.tsx +++ b/src/Components/Facility/FacilityCreate.tsx @@ -11,7 +11,7 @@ import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave.js"; import { FACILITY_FEATURE_TYPES, FACILITY_TYPES, - getBedTypes, + BED_TYPES, } from "../../Common/constants"; import { MultiSelectFormField, @@ -561,9 +561,9 @@ export const FacilityCreate = (props: FacilityProps) => { return; }} /> - {getBedTypes({ kasp_string, kasp_enabled }).map((x) => { + {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) => { @@ -578,7 +578,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 16bc6610631..1249f990134 100644 --- a/src/Locale/en/Facility.json +++ b/src/Locale/en/Facility.json @@ -60,5 +60,10 @@ "duplicate_patient_record_rejection": "I confirm that the suspect / patient I want to create is not on the list.", "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" + "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 Bed", + "bed_type__400": "Isolation Bed", + "bed_type__500": "Others" } \ No newline at end of file