Skip to content

Commit

Permalink
Adds support for units for max_dosage (#6897)
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad authored Dec 23, 2023
1 parent 89c6382 commit d906c6a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = FormFieldBaseProps<string> & {
className?: string | undefined;
min?: string | number;
max?: string | number;
units: string[];
units: readonly string[];
};

export default function NumericWithUnitsFormField(props: Props) {
Expand Down
13 changes: 9 additions & 4 deletions src/Components/Medicine/CreatePrescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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}
/>
</div>
Expand All @@ -86,9 +90,10 @@ export default function CreatePrescriptionForm(props: {
{...field("indicator", RequiredFieldValidator())}
required
/>
<TextFormField
<NumericWithUnitsFormField
className="flex-1"
label={t("max_dosage_24_hrs")}
type="number"
units={DOSAGE_UNITS}
min={0}
{...field("max_dosage")}
/>
Expand Down
9 changes: 5 additions & 4 deletions src/Components/Medicine/EditPrescriptionForm.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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}
/>
</div>
Expand All @@ -114,9 +114,10 @@ export default function EditPrescriptionForm(props: Props) {
{...field("indicator", RequiredFieldValidator())}
required
/>
<TextFormField
<NumericWithUnitsFormField
className="flex-1"
label={t("max_dosage_24_hrs")}
type="number"
units={DOSAGE_UNITS}
min={0}
{...field("max_dosage")}
/>
Expand Down
15 changes: 13 additions & 2 deletions src/Components/Medicine/models.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d906c6a

Please sign in to comment.