From 6b04fb7edf01b03cd9bd3a067abe6fccca24eee6 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Sat, 23 Dec 2023 17:28:41 +0530 Subject: [PATCH] Adds support for units for `max_dosage` --- .../Form/FormFields/NumericWithUnitsFormField.tsx | 2 +- .../Medicine/CreatePrescriptionForm.tsx | 13 +++++++++---- src/Components/Medicine/EditPrescriptionForm.tsx | 9 +++++---- src/Components/Medicine/models.ts | 15 +++++++++++++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Components/Form/FormFields/NumericWithUnitsFormField.tsx b/src/Components/Form/FormFields/NumericWithUnitsFormField.tsx index 02f98a7ba17..d0dae7ddff5 100644 --- a/src/Components/Form/FormFields/NumericWithUnitsFormField.tsx +++ b/src/Components/Form/FormFields/NumericWithUnitsFormField.tsx @@ -9,7 +9,7 @@ type Props = FormFieldBaseProps & { className?: string | undefined; min?: string | number; max?: string | number; - units: string[]; + units: readonly string[]; }; export default function NumericWithUnitsFormField(props: Props) { diff --git a/src/Components/Medicine/CreatePrescriptionForm.tsx b/src/Components/Medicine/CreatePrescriptionForm.tsx index d6691ebbc03..2725ab4e728 100644 --- a/src/Components/Medicine/CreatePrescriptionForm.tsx +++ b/src/Components/Medicine/CreatePrescriptionForm.tsx @@ -3,7 +3,11 @@ import Form from "../Form/Form"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; import TextFormField from "../Form/FormFields/TextFormField"; -import { MedicineAdministrationRecord, Prescription } from "./models"; +import { + DOSAGE_UNITS, + MedicineAdministrationRecord, + Prescription, +} from "./models"; import { useState } from "react"; import NumericWithUnitsFormField from "../Form/FormFields/NumericWithUnitsFormField"; import { useTranslation } from "react-i18next"; @@ -74,7 +78,7 @@ export default function CreatePrescriptionForm(props: { label={t("dosage")} {...field("dosage", RequiredFieldValidator())} required - units={["mg", "g", "ml", "drop(s)", "ampule(s)", "tsp"]} + units={DOSAGE_UNITS} min={0} /> @@ -86,9 +90,10 @@ export default function CreatePrescriptionForm(props: { {...field("indicator", RequiredFieldValidator())} required /> - diff --git a/src/Components/Medicine/EditPrescriptionForm.tsx b/src/Components/Medicine/EditPrescriptionForm.tsx index 42a9b39f7ea..2bd3805af73 100644 --- a/src/Components/Medicine/EditPrescriptionForm.tsx +++ b/src/Components/Medicine/EditPrescriptionForm.tsx @@ -1,6 +1,6 @@ import { useState } from "react"; import Form from "../Form/Form"; -import { Prescription } from "./models"; +import { DOSAGE_UNITS, Prescription } from "./models"; import request from "../../Utils/request/request"; import * as Notification from "../../Utils/Notifications"; import useSlug from "../../Common/hooks/useSlug"; @@ -102,7 +102,7 @@ export default function EditPrescriptionForm(props: Props) { label={t("dosage")} {...field("dosage", RequiredFieldValidator())} required - units={["mg", "g", "ml", "drop(s)", "ampule(s)", "tsp"]} + units={DOSAGE_UNITS} min={0} /> @@ -114,9 +114,10 @@ export default function EditPrescriptionForm(props: Props) { {...field("indicator", RequiredFieldValidator())} required /> - diff --git a/src/Components/Medicine/models.ts b/src/Components/Medicine/models.ts index ee42b03eca2..4fca9b6f972 100644 --- a/src/Components/Medicine/models.ts +++ b/src/Components/Medicine/models.ts @@ -1,12 +1,23 @@ import { PerformedByModel } from "../HCX/misc"; +export const DOSAGE_UNITS = [ + "mg", + "g", + "ml", + "drop(s)", + "ampule(s)", + "tsp", +] as const; + +export type DosageValue = `${number} ${(typeof DOSAGE_UNITS)[number]}`; + interface BasePrescription { readonly id: string; medicine?: string; medicine_object?: MedibaseMedicine; medicine_old?: string; route?: "ORAL" | "IV" | "IM" | "SC"; - dosage: string; + dosage: DosageValue; notes?: string; meta?: object; readonly prescription_type?: "DISCHARGE" | "REGULAR"; @@ -40,7 +51,7 @@ export interface NormalPrescription extends BasePrescription { export interface PRNPrescription extends BasePrescription { indicator: string; - max_dosage?: string; + max_dosage?: DosageValue; min_hours_between_doses?: number; is_prn: true; frequency?: undefined;