formanitor 0.0.32 → 0.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -58,6 +58,13 @@ var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespace(DialogPrimitive)
58
58
  var nlp__default = /*#__PURE__*/_interopDefault(nlp);
59
59
  var SliderPrimitive__namespace = /*#__PURE__*/_interopNamespace(SliderPrimitive);
60
60
 
61
+ // src/core/marMedicationOrdersMeta.ts
62
+ var MAR_MEDICATION_ORDERS_META_KEY = "mar_medication_orders";
63
+ function fieldMetaRequestsMarMedicationOrdersButton(meta) {
64
+ if (!meta || typeof meta !== "object") return false;
65
+ return meta[MAR_MEDICATION_ORDERS_META_KEY] === true;
66
+ }
67
+
61
68
  // src/core/validate.ts
62
69
  var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
63
70
  function validateField(value, field) {
@@ -725,6 +732,7 @@ var emptyFrequentItems = {
725
732
  procedures: []
726
733
  };
727
734
  var FrequentItemsContext = React15.createContext(emptyFrequentItems);
735
+ var PackagesContext = React15.createContext([]);
728
736
  var FieldHandlersContext = React15.createContext({});
729
737
  function useFieldHandlers(fieldId) {
730
738
  const map = React15.useContext(FieldHandlersContext);
@@ -733,11 +741,15 @@ function useFieldHandlers(fieldId) {
733
741
  function useFrequentItems() {
734
742
  return React15.useContext(FrequentItemsContext);
735
743
  }
744
+ function usePackages() {
745
+ return React15.useContext(PackagesContext);
746
+ }
736
747
  var FormProvider = ({
737
748
  schema,
738
749
  config,
739
750
  fieldHandlers,
740
751
  frequentItems,
752
+ packages,
741
753
  children
742
754
  }) => {
743
755
  const storeRef = React15.useRef(null);
@@ -753,7 +765,7 @@ var FormProvider = ({
753
765
  storeRef.current?.load();
754
766
  }, []);
755
767
  const frequentItemsValue = frequentItems ?? emptyFrequentItems;
756
- return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsxRuntime.jsx(FieldHandlersContext.Provider, { value: fieldHandlers ?? {}, children: /* @__PURE__ */ jsxRuntime.jsx(FrequentItemsContext.Provider, { value: frequentItemsValue, children: /* @__PURE__ */ jsxRuntime.jsx(VoiceContextProvider, { children }) }) }) });
768
+ return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsxRuntime.jsx(FieldHandlersContext.Provider, { value: fieldHandlers ?? {}, children: /* @__PURE__ */ jsxRuntime.jsx(FrequentItemsContext.Provider, { value: frequentItemsValue, children: /* @__PURE__ */ jsxRuntime.jsx(PackagesContext.Provider, { value: packages ?? [], children: /* @__PURE__ */ jsxRuntime.jsx(VoiceContextProvider, { children }) }) }) }) });
757
769
  };
758
770
  function useFormStore() {
759
771
  const context = React15.useContext(FormContext);
@@ -3106,18 +3118,20 @@ var AddEntityDialog = ({
3106
3118
  open,
3107
3119
  onClose,
3108
3120
  title,
3121
+ chipSections,
3109
3122
  recentlyUsedSlot,
3110
3123
  chipSectionLabel = "Recently Used",
3111
3124
  children,
3112
3125
  actionSlot
3113
3126
  }) => {
3114
- return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange: (o) => !o && onClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "max-w-lg w-full p-0 gap-0 flex flex-col max-h-[90vh] overflow-hidden", children: [
3127
+ const sections = chipSections ?? (recentlyUsedSlot ? [{ label: chipSectionLabel, content: recentlyUsedSlot }] : []);
3128
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange: (o) => !o && onClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "max-w-4xl w-full p-0 gap-0 flex flex-col max-h-[90vh] overflow-hidden", children: [
3115
3129
  /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { className: "px-6 pt-6 pb-4 shrink-0", children: /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "text-lg font-semibold", children: title }) }),
3116
3130
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 flex flex-col gap-4 overflow-y-auto flex-1 min-h-0 pb-4", children: [
3117
- recentlyUsedSlot && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3118
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mb-2", children: chipSectionLabel }),
3119
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: recentlyUsedSlot })
3120
- ] }),
3131
+ sections.map((section) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3132
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mb-2", children: section.label }),
3133
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: section.content })
3134
+ ] }, section.label)),
3121
3135
  children
3122
3136
  ] }),
3123
3137
  actionSlot != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4 flex justify-end shrink-0 border-t border-border bg-background", children: actionSlot })
@@ -3659,7 +3673,8 @@ var AddInvestigationField = ({
3659
3673
  onChange,
3660
3674
  onSearch,
3661
3675
  recentlyUsed = [],
3662
- frequentItems = []
3676
+ frequentItems = [],
3677
+ packages = []
3663
3678
  }) => {
3664
3679
  const [open, setOpen] = React15.useState(false);
3665
3680
  const [query, setQuery] = React15.useState("");
@@ -3670,6 +3685,8 @@ var AddInvestigationField = ({
3670
3685
  const debounceRef = React15.useRef(null);
3671
3686
  const valueRef = React15.useRef([]);
3672
3687
  const searchInputRef = React15.useRef(null);
3688
+ const addedByPackage = React15.useRef(/* @__PURE__ */ new Map());
3689
+ const [selectedPackageIds, setSelectedPackageIds] = React15.useState(/* @__PURE__ */ new Set());
3673
3690
  const safeValue = Array.isArray(value) ? value : [];
3674
3691
  valueRef.current = safeValue;
3675
3692
  const addedIds = new Set(safeValue.map((inv) => inv.id));
@@ -3744,6 +3761,27 @@ var AddInvestigationField = ({
3744
3761
  setAddingFrequentId(null);
3745
3762
  }
3746
3763
  }
3764
+ function handlePackageToggle(pkg) {
3765
+ const alreadyAdded = addedByPackage.current.has(pkg.id);
3766
+ if (alreadyAdded) {
3767
+ const idsToRemove = new Set(addedByPackage.current.get(pkg.id) ?? []);
3768
+ onChange(valueRef.current.filter((inv) => !idsToRemove.has(inv.id)));
3769
+ addedByPackage.current.delete(pkg.id);
3770
+ setSelectedPackageIds((prev) => {
3771
+ const next = new Set(prev);
3772
+ next.delete(pkg.id);
3773
+ return next;
3774
+ });
3775
+ } else {
3776
+ const currentIds = new Set(valueRef.current.map((inv) => inv.id));
3777
+ const newTests = pkg.tests.filter((t) => !currentIds.has(t.id)).map((t) => mapToInvestigation(t));
3778
+ if (newTests.length > 0) {
3779
+ onChange([...valueRef.current, ...newTests]);
3780
+ }
3781
+ addedByPackage.current.set(pkg.id, newTests.map((t) => t.id));
3782
+ setSelectedPackageIds((prev) => new Set(prev).add(pkg.id));
3783
+ }
3784
+ }
3747
3785
  const recentlyUsedChips = recentlyUsed.map((r) => {
3748
3786
  const isAdded = addedIds.has(r.id);
3749
3787
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -3787,6 +3825,38 @@ var AddInvestigationField = ({
3787
3825
  item.id
3788
3826
  );
3789
3827
  }) : [];
3828
+ const packageChips = packages.map((pkg) => {
3829
+ const isAdded = selectedPackageIds.has(pkg.id);
3830
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3831
+ "button",
3832
+ {
3833
+ type: "button",
3834
+ onClick: () => handlePackageToggle(pkg),
3835
+ className: cn(
3836
+ "rounded-full border text-xs px-4 py-1.5 transition-colors flex items-center gap-2",
3837
+ isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
3838
+ ),
3839
+ children: [
3840
+ isAdded && /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u2713" }),
3841
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold", children: pkg.name }),
3842
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn(
3843
+ "rounded-full px-1.5 py-0.5 text-[10px] font-medium",
3844
+ isAdded ? "bg-green-100 text-green-600" : "bg-purple-100 text-purple-600"
3845
+ ), children: pkg.tests.length })
3846
+ ]
3847
+ },
3848
+ pkg.id
3849
+ );
3850
+ });
3851
+ const chipSections = [];
3852
+ if (frequentItemChips.length > 0) {
3853
+ chipSections.push({ label: "Frequently used", content: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: frequentItemChips }) });
3854
+ } else if (recentlyUsedChips.length > 0) {
3855
+ chipSections.push({ label: "Recently Used", content: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: recentlyUsedChips }) });
3856
+ }
3857
+ if (packageChips.length > 0) {
3858
+ chipSections.push({ label: "Packages", content: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: packageChips }) });
3859
+ }
3790
3860
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md overflow-hidden flex flex-col bg-white border border-[#D0D0D0] space-y-3 p-3 h-fit", children: [
3791
3861
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
3792
3862
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-semibold", children: label }),
@@ -3825,8 +3895,7 @@ var AddInvestigationField = ({
3825
3895
  open,
3826
3896
  onClose: () => setOpen(false),
3827
3897
  title: "Add Investigation",
3828
- recentlyUsedSlot: frequentItemChips.length > 0 ? frequentItemChips : recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
3829
- chipSectionLabel: frequentItemChips.length > 0 ? "Frequently used" : void 0,
3898
+ chipSections: chipSections.length > 0 ? chipSections : void 0,
3830
3899
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
3831
3900
  /* @__PURE__ */ jsxRuntime.jsx(
3832
3901
  Input,
@@ -3867,6 +3936,7 @@ var AddInvestigationWidget = ({ fieldId }) => {
3867
3936
  const { value, setValue } = useField(fieldId);
3868
3937
  const handlers = useFieldHandlers(fieldId);
3869
3938
  const { investigations: frequentInvestigations } = useFrequentItems();
3939
+ const packages = usePackages();
3870
3940
  const safeValue = Array.isArray(value) ? value : [];
3871
3941
  return /* @__PURE__ */ jsxRuntime.jsx(
3872
3942
  AddInvestigationField,
@@ -3875,7 +3945,8 @@ var AddInvestigationWidget = ({ fieldId }) => {
3875
3945
  onChange: setValue,
3876
3946
  onSearch: handlers.onSearch,
3877
3947
  recentlyUsed: handlers.recentlyUsed,
3878
- frequentItems: frequentInvestigations
3948
+ frequentItems: frequentInvestigations,
3949
+ packages
3879
3950
  }
3880
3951
  );
3881
3952
  };
@@ -7574,6 +7645,206 @@ var OrthopedicExamWidget = ({ fieldId }) => {
7574
7645
  ) : null
7575
7646
  ] });
7576
7647
  };
7648
+ var MarMedicationOrdersWidget = ({ fieldId }) => {
7649
+ const { fieldDef, value, setTouched, error, disabled, touched } = useField(fieldId);
7650
+ const { state } = useForm();
7651
+ const handlers = useFieldHandlers(fieldId);
7652
+ const showError = !!error && (touched || state.submitAttempted);
7653
+ const onOpen = React15.useCallback(async () => {
7654
+ await handlers.onOpenMedicationOrders?.();
7655
+ setTouched();
7656
+ }, [handlers, setTouched]);
7657
+ if (!fieldDef || fieldDef.type !== "textarea") return null;
7658
+ const textDef = fieldDef;
7659
+ const height = textDef.height;
7660
+ const theme = getThemeConfig("textarea", fieldDef.theme);
7661
+ const wrapperClass = theme?.wrapperClassName ?? "space-y-2";
7662
+ const labelClass = theme?.labelClassName;
7663
+ const labelContent = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7664
+ fieldDef.label,
7665
+ " ",
7666
+ fieldDef.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-red-500", children: "*" })
7667
+ ] });
7668
+ const labelEl = theme ? /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, className: labelClass, children: labelContent }) : /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, children: labelContent });
7669
+ const text = typeof value === "string" ? value : value == null ? "" : String(value);
7670
+ const hasHandler = typeof handlers.onOpenMedicationOrders === "function";
7671
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: wrapperClass, children: [
7672
+ labelEl,
7673
+ fieldDef.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: fieldDef.description }),
7674
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-3", children: [
7675
+ /* @__PURE__ */ jsxRuntime.jsx(
7676
+ "div",
7677
+ {
7678
+ id: fieldId,
7679
+ className: cn(
7680
+ "min-h-[80px] flex-1 rounded-md border border-input bg-background px-3 py-2 text-sm whitespace-pre-wrap",
7681
+ showError && "border-red-500",
7682
+ !text && "text-muted-foreground"
7683
+ ),
7684
+ style: height != null ? { minHeight: height } : void 0,
7685
+ "aria-readonly": "true",
7686
+ children: text || fieldDef.placeholder || "No medication orders added."
7687
+ }
7688
+ ),
7689
+ /* @__PURE__ */ jsxRuntime.jsx(
7690
+ Button,
7691
+ {
7692
+ type: "button",
7693
+ variant: "default",
7694
+ disabled: disabled || !hasHandler,
7695
+ onClick: onOpen,
7696
+ className: "shrink-0 sm:mt-0",
7697
+ children: "Add medication orders"
7698
+ }
7699
+ )
7700
+ ] }),
7701
+ showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
7702
+ ] });
7703
+ };
7704
+ function parseFieldValue(value) {
7705
+ if (value == null) return { orders: [], display_lines: [] };
7706
+ if (Array.isArray(value)) {
7707
+ return {
7708
+ orders: value,
7709
+ display_lines: value.map(() => null)
7710
+ };
7711
+ }
7712
+ if (typeof value === "object") {
7713
+ const v = value;
7714
+ const orders = Array.isArray(v.orders) ? v.orders : [];
7715
+ const rawLines = Array.isArray(v.display_lines) ? v.display_lines : Array.isArray(v.displayLines) ? v.displayLines : [];
7716
+ const display_lines = orders.map((_, i) => rawLines[i] ?? null);
7717
+ return { orders, display_lines };
7718
+ }
7719
+ return { orders: [], display_lines: [] };
7720
+ }
7721
+ function normalizePrescription(res) {
7722
+ const pharmacyOrderId = res.pharmacy_order_id ?? void 0;
7723
+ const orders = Array.isArray(res.orders) ? res.orders : [];
7724
+ const linesRaw = Array.isArray(res.display_lines) ? res.display_lines : [];
7725
+ const mapped = orders.filter((o) => o && typeof o.id === "string").map((o) => ({
7726
+ id: o.id,
7727
+ item_id: o.item_id == null ? void 0 : String(o.item_id),
7728
+ item_name: o.item_name ?? void 0,
7729
+ generic_name: o.generic_name ?? void 0,
7730
+ dose: o.dose == null ? void 0 : String(o.dose),
7731
+ route: o.route ?? void 0,
7732
+ frequency: o.frequency ?? void 0,
7733
+ admin_times: Array.isArray(o.admin_times) ? o.admin_times : void 0,
7734
+ meal_sleep_timing: o.meal_sleep_timing ?? void 0,
7735
+ start_date: o.start_date ?? void 0,
7736
+ end_date: o.end_date ?? void 0,
7737
+ order_type: o.order_type ?? void 0,
7738
+ status: o.status ?? void 0,
7739
+ notes: o.notes ?? null,
7740
+ pharmacy_order_id: pharmacyOrderId
7741
+ }));
7742
+ const display_lines = mapped.map((_, i) => linesRaw[i] ?? null);
7743
+ return { orders: mapped, display_lines };
7744
+ }
7745
+ function formatDuration(start, end) {
7746
+ if (!start && !end) return null;
7747
+ if (start && end) return `${start} \u2192 ${end}`;
7748
+ return start ? `Start: ${start}` : `End: ${end}`;
7749
+ }
7750
+ var DischargeMedicationOrdersWidget = ({ fieldId }) => {
7751
+ const { fieldDef, value, setValue, setTouched, error, disabled, touched, visible } = useField(fieldId);
7752
+ const { state } = useForm();
7753
+ const handlers = useFieldHandlers(fieldId);
7754
+ const showError = !!error && (touched || state.submitAttempted);
7755
+ const { orders, display_lines } = React15.useMemo(() => parseFieldValue(value), [value]);
7756
+ const onAdd = React15.useCallback(async () => {
7757
+ setTouched();
7758
+ const fn = handlers.onOpenDischargeMedicationOrders;
7759
+ if (!fn) return;
7760
+ const res = await fn();
7761
+ if (!res || typeof res !== "object") return;
7762
+ const normalized = normalizePrescription(res);
7763
+ setValue({
7764
+ orders: normalized.orders,
7765
+ display_lines: normalized.display_lines
7766
+ });
7767
+ }, [handlers.onOpenDischargeMedicationOrders, setTouched, setValue]);
7768
+ const onDelete = React15.useCallback(
7769
+ (id) => {
7770
+ setTouched();
7771
+ const idx = orders.findIndex((o) => o.id === id);
7772
+ if (idx === -1) return;
7773
+ setValue({
7774
+ orders: orders.filter((o) => o.id !== id),
7775
+ display_lines: display_lines.filter((_, i) => i !== idx)
7776
+ });
7777
+ },
7778
+ [orders, display_lines, setTouched, setValue]
7779
+ );
7780
+ if (!visible || !fieldDef) return null;
7781
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
7782
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
7783
+ /* @__PURE__ */ jsxRuntime.jsxs(Label, { className: "text-sm font-medium", children: [
7784
+ fieldDef.label,
7785
+ " ",
7786
+ fieldDef.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-red-500", children: "*" })
7787
+ ] }),
7788
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", onClick: onAdd, disabled: disabled || !handlers.onOpenDischargeMedicationOrders, children: "Add medicine" })
7789
+ ] }),
7790
+ fieldDef.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: fieldDef.description }),
7791
+ orders.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(
7792
+ "div",
7793
+ {
7794
+ className: cn(
7795
+ "rounded-md border border-input bg-background px-3 py-3 text-sm text-muted-foreground",
7796
+ showError && "border-red-500"
7797
+ ),
7798
+ children: "No medicines added."
7799
+ }
7800
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: orders.map((o, rowIdx) => {
7801
+ const line = display_lines[rowIdx];
7802
+ const duration = formatDuration(o.start_date, o.end_date);
7803
+ const header = typeof line?.name === "string" && line.name.trim() || o.item_name || "Medicine";
7804
+ const sub = o.generic_name ? o.generic_name : null;
7805
+ const line1 = [o.dose && `Dose: ${o.dose}`, o.route && `Route: ${o.route}`].filter(Boolean).join(" \u2022 ");
7806
+ const line2 = [
7807
+ o.frequency && `Freq: ${o.frequency}`,
7808
+ o.meal_sleep_timing && `Meal/Sleep: ${o.meal_sleep_timing}`,
7809
+ o.admin_times?.length ? `Times: ${o.admin_times.join(", ")}` : null
7810
+ ].filter(Boolean).join(" \u2022 ");
7811
+ const line3 = [
7812
+ duration ? `Duration: ${duration}` : null,
7813
+ o.order_type ? `Type: ${o.order_type}` : null,
7814
+ o.status ? `Status: ${o.status}` : null
7815
+ ].filter(Boolean).join(" \u2022 ");
7816
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md border border-input bg-background p-3", children: [
7817
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-3", children: [
7818
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
7819
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-semibold text-sm truncate", children: header }),
7820
+ sub && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-muted-foreground mt-0.5 truncate", children: sub })
7821
+ ] }),
7822
+ /* @__PURE__ */ jsxRuntime.jsx(
7823
+ Button,
7824
+ {
7825
+ type: "button",
7826
+ variant: "ghost",
7827
+ className: "h-8 w-8 p-0 text-destructive",
7828
+ onClick: () => onDelete(o.id),
7829
+ "aria-label": "Delete medicine",
7830
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "h-4 w-4" })
7831
+ }
7832
+ )
7833
+ ] }),
7834
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 space-y-1 text-xs text-muted-foreground", children: [
7835
+ line1 && /* @__PURE__ */ jsxRuntime.jsx("div", { children: line1 }),
7836
+ line2 && /* @__PURE__ */ jsxRuntime.jsx("div", { children: line2 }),
7837
+ line3 && /* @__PURE__ */ jsxRuntime.jsx("div", { children: line3 }),
7838
+ o.notes && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-foreground/80", children: [
7839
+ "Notes: ",
7840
+ o.notes
7841
+ ] })
7842
+ ] })
7843
+ ] }, o.id);
7844
+ }) }),
7845
+ showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
7846
+ ] });
7847
+ };
7577
7848
  var FieldRenderer = ({ fieldId }) => {
7578
7849
  const { fieldDef, visible } = useField(fieldId);
7579
7850
  if (!visible || !fieldDef) {
@@ -7587,6 +7858,9 @@ function renderWidget(fieldId, fieldDef) {
7587
7858
  case "number":
7588
7859
  return /* @__PURE__ */ jsxRuntime.jsx(TextWidget, { fieldId });
7589
7860
  case "textarea":
7861
+ if (fieldMetaRequestsMarMedicationOrdersButton(fieldDef.meta)) {
7862
+ return /* @__PURE__ */ jsxRuntime.jsx(MarMedicationOrdersWidget, { fieldId });
7863
+ }
7590
7864
  return /* @__PURE__ */ jsxRuntime.jsx(TextWidget, { fieldId });
7591
7865
  case "richtext":
7592
7866
  return /* @__PURE__ */ jsxRuntime.jsx(RichTextWidget, { fieldId });
@@ -7614,6 +7888,8 @@ function renderWidget(fieldId, fieldDef) {
7614
7888
  return /* @__PURE__ */ jsxRuntime.jsx(EditableTableWidget, { fieldId });
7615
7889
  case "medications":
7616
7890
  return /* @__PURE__ */ jsxRuntime.jsx(AddMedicationWidget, { fieldId });
7891
+ case "discharge_medication_orders":
7892
+ return /* @__PURE__ */ jsxRuntime.jsx(DischargeMedicationOrdersWidget, { fieldId });
7617
7893
  case "investigations":
7618
7894
  return /* @__PURE__ */ jsxRuntime.jsx(AddInvestigationWidget, { fieldId });
7619
7895
  case "procedures":
@@ -8241,6 +8517,53 @@ var ReadOnlyReferral = ({ fieldDef, value }) => {
8241
8517
  }) })
8242
8518
  ] });
8243
8519
  };
8520
+ function isOrderArray(value) {
8521
+ return Array.isArray(value) && value.every(
8522
+ (v) => v != null && typeof v === "object" && typeof v.id === "string"
8523
+ );
8524
+ }
8525
+ function formatDuration2(start, end) {
8526
+ if (!start && !end) return null;
8527
+ if (start && end) return `${start} \u2192 ${end}`;
8528
+ return start ? `Start: ${start}` : `End: ${end}`;
8529
+ }
8530
+ var ReadOnlyDischargeMedicationOrders = ({ fieldDef, value }) => {
8531
+ const orders = React15.useMemo(() => isOrderArray(value) ? value : [], [value]);
8532
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
8533
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
8534
+ orders.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem]", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "No medicines added" }) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: orders.map((o) => {
8535
+ const duration = formatDuration2(o.start_date, o.end_date);
8536
+ const header = o.item_name ?? "Medicine";
8537
+ const sub = o.generic_name ? o.generic_name : null;
8538
+ const line1 = [o.dose && `Dose: ${o.dose}`, o.route && `Route: ${o.route}`].filter(Boolean).join(" \u2022 ");
8539
+ const line2 = [
8540
+ o.frequency && `Freq: ${o.frequency}`,
8541
+ o.meal_sleep_timing && `Meal/Sleep: ${o.meal_sleep_timing}`,
8542
+ o.admin_times?.length ? `Times: ${o.admin_times.join(", ")}` : null
8543
+ ].filter(Boolean).join(" \u2022 ");
8544
+ const line3 = [
8545
+ duration ? `Duration: ${duration}` : null,
8546
+ o.order_type ? `Type: ${o.order_type}` : null,
8547
+ o.status ? `Status: ${o.status}` : null
8548
+ ].filter(Boolean).join(" \u2022 ");
8549
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md border border-gray-200 bg-gray-50 p-3", children: [
8550
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
8551
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-semibold text-sm truncate text-gray-900", children: header }),
8552
+ sub && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-500 mt-0.5 truncate", children: sub })
8553
+ ] }),
8554
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 space-y-1 text-xs text-gray-600", children: [
8555
+ line1 && /* @__PURE__ */ jsxRuntime.jsx("div", { children: line1 }),
8556
+ line2 && /* @__PURE__ */ jsxRuntime.jsx("div", { children: line2 }),
8557
+ line3 && /* @__PURE__ */ jsxRuntime.jsx("div", { children: line3 }),
8558
+ o.notes && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-gray-800/90", children: [
8559
+ "Notes: ",
8560
+ o.notes
8561
+ ] })
8562
+ ] })
8563
+ ] }, o.id);
8564
+ }) })
8565
+ ] });
8566
+ };
8244
8567
  var ReadOnlyFieldRenderer = ({ fieldDef, value }) => {
8245
8568
  if (!fieldDef) return null;
8246
8569
  switch (fieldDef.type) {
@@ -8273,6 +8596,8 @@ var ReadOnlyFieldRenderer = ({ fieldDef, value }) => {
8273
8596
  return /* @__PURE__ */ jsxRuntime.jsx(ReadOnlyTable, { fieldDef, value });
8274
8597
  case "referral":
8275
8598
  return /* @__PURE__ */ jsxRuntime.jsx(ReadOnlyReferral, { fieldDef, value });
8599
+ case "discharge_medication_orders":
8600
+ return /* @__PURE__ */ jsxRuntime.jsx(ReadOnlyDischargeMedicationOrders, { fieldDef, value });
8276
8601
  case "static_text": {
8277
8602
  const def = fieldDef;
8278
8603
  const size = def.size ?? "regular";
@@ -8484,6 +8809,7 @@ exports.FormControls = FormControls;
8484
8809
  exports.FormProvider = FormProvider;
8485
8810
  exports.FormStore = FormStore;
8486
8811
  exports.ImageUploadWidget = ImageUploadWidget;
8812
+ exports.MAR_MEDICATION_ORDERS_META_KEY = MAR_MEDICATION_ORDERS_META_KEY;
8487
8813
  exports.MediaUploadWidget = MediaUploadWidget;
8488
8814
  exports.ReadOnlyForm = ReadOnlyForm;
8489
8815
  exports.ReadOnlyImageUpload = ReadOnlyImageUpload;
@@ -8496,11 +8822,13 @@ exports.SmartForm = SmartForm;
8496
8822
  exports.SmartTextareaWidget = SmartTextareaWidget;
8497
8823
  exports.createUploadHandler = createUploadHandler;
8498
8824
  exports.evaluateRules = evaluateRules;
8825
+ exports.fieldMetaRequestsMarMedicationOrdersButton = fieldMetaRequestsMarMedicationOrdersButton;
8499
8826
  exports.useField = useField;
8500
8827
  exports.useFieldHandlers = useFieldHandlers;
8501
8828
  exports.useForm = useForm;
8502
8829
  exports.useFormStore = useFormStore;
8503
8830
  exports.useFrequentItems = useFrequentItems;
8831
+ exports.usePackages = usePackages;
8504
8832
  exports.useSmartKeywords = useSmartKeywords;
8505
8833
  exports.validateField = validateField;
8506
8834
  exports.validateForm = validateForm;