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

Cleanup bed types #8456

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
29 changes: 1 addition & 28 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -217,33 +216,7 @@ export const DISCHARGED_PATIENT_SORT_OPTIONS: SortOption[] = [
{ isAscending: false, value: "-name" },
];

export const getBedTypes = ({
kasp_enabled,
kasp_string,
}: Pick<IConfig, "kasp_enabled" | "kasp_string">) => {
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<OptionsType> = [
{ id: 1, text: "General Medicine" },
Expand Down
19 changes: 10 additions & 9 deletions src/Components/Facility/BedCapacity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<OptionsType[]>(getBedTypes(config));
const [bedTypes, setBedTypes] = useState<OptionsType[]>(
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";
Expand All @@ -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,
};
});
Expand Down Expand Up @@ -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]);

Expand Down
13 changes: 7 additions & 6 deletions src/Components/Facility/FacilityBedCapacity.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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";
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 },
Expand Down Expand Up @@ -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 &&
Expand All @@ -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}
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Facility/FacilityCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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}
Expand Down
7 changes: 6 additions & 1 deletion src/Locale/en/Facility.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 Supported Bed",
"bed_type__400": "Isolation Bed",
"bed_type__500": "Others"
}
Loading