formanitor 0.0.32 → 0.0.33

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.d.cts CHANGED
@@ -435,6 +435,9 @@ interface FormState {
435
435
  pendingUploads: number;
436
436
  }
437
437
 
438
+ declare const MAR_MEDICATION_ORDERS_META_KEY: "mar_medication_orders";
439
+ declare function fieldMetaRequestsMarMedicationOrdersButton(meta: Record<string, unknown> | undefined): boolean;
440
+
438
441
  interface SavedState {
439
442
  values: FormValues;
440
443
  meta: {
@@ -598,6 +601,16 @@ type FieldHandler = {
598
601
  * from diagnosis text input.
599
602
  */
600
603
  onFetchDiagnosisGrades?: (query: string) => Promise<any>;
604
+ /**
605
+ * Host opens MAR / medication-orders UI (e.g. IPD discharge). On success the host
606
+ * should update this field's value in form state.
607
+ */
608
+ onOpenMedicationOrders?: () => void | Promise<void>;
609
+ /**
610
+ * Host opens CMDash discharge medication orders slide-over. On save, return the
611
+ * prescription payload so the widget can normalize and store it in form state.
612
+ */
613
+ onOpenDischargeMedicationOrders?: () => Promise<any | null> | any | null;
601
614
  };
602
615
  type FieldHandlersMap = Record<string, FieldHandler>;
603
616
  declare function useFieldHandlers(fieldId: string): FieldHandler;
@@ -926,4 +939,4 @@ declare const SmartTextareaWidget: React.FC<{
926
939
  fieldId: string;
927
940
  }>;
928
941
 
929
- export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, type NumberFieldDef, type Permission, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
942
+ export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, type NumberFieldDef, type Permission, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
package/dist/index.d.ts CHANGED
@@ -435,6 +435,9 @@ interface FormState {
435
435
  pendingUploads: number;
436
436
  }
437
437
 
438
+ declare const MAR_MEDICATION_ORDERS_META_KEY: "mar_medication_orders";
439
+ declare function fieldMetaRequestsMarMedicationOrdersButton(meta: Record<string, unknown> | undefined): boolean;
440
+
438
441
  interface SavedState {
439
442
  values: FormValues;
440
443
  meta: {
@@ -598,6 +601,16 @@ type FieldHandler = {
598
601
  * from diagnosis text input.
599
602
  */
600
603
  onFetchDiagnosisGrades?: (query: string) => Promise<any>;
604
+ /**
605
+ * Host opens MAR / medication-orders UI (e.g. IPD discharge). On success the host
606
+ * should update this field's value in form state.
607
+ */
608
+ onOpenMedicationOrders?: () => void | Promise<void>;
609
+ /**
610
+ * Host opens CMDash discharge medication orders slide-over. On save, return the
611
+ * prescription payload so the widget can normalize and store it in form state.
612
+ */
613
+ onOpenDischargeMedicationOrders?: () => Promise<any | null> | any | null;
601
614
  };
602
615
  type FieldHandlersMap = Record<string, FieldHandler>;
603
616
  declare function useFieldHandlers(fieldId: string): FieldHandler;
@@ -926,4 +939,4 @@ declare const SmartTextareaWidget: React.FC<{
926
939
  fieldId: string;
927
940
  }>;
928
941
 
929
- export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, type NumberFieldDef, type Permission, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
942
+ export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, type NumberFieldDef, type Permission, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
package/dist/index.mjs CHANGED
@@ -23,6 +23,13 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
23
23
  import nlp from 'compromise';
24
24
  import * as SliderPrimitive from '@radix-ui/react-slider';
25
25
 
26
+ // src/core/marMedicationOrdersMeta.ts
27
+ var MAR_MEDICATION_ORDERS_META_KEY = "mar_medication_orders";
28
+ function fieldMetaRequestsMarMedicationOrdersButton(meta) {
29
+ if (!meta || typeof meta !== "object") return false;
30
+ return meta[MAR_MEDICATION_ORDERS_META_KEY] === true;
31
+ }
32
+
26
33
  // src/core/validate.ts
27
34
  var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
28
35
  function validateField(value, field) {
@@ -7539,6 +7546,206 @@ var OrthopedicExamWidget = ({ fieldId }) => {
7539
7546
  ) : null
7540
7547
  ] });
7541
7548
  };
7549
+ var MarMedicationOrdersWidget = ({ fieldId }) => {
7550
+ const { fieldDef, value, setTouched, error, disabled, touched } = useField(fieldId);
7551
+ const { state } = useForm();
7552
+ const handlers = useFieldHandlers(fieldId);
7553
+ const showError = !!error && (touched || state.submitAttempted);
7554
+ const onOpen = useCallback(async () => {
7555
+ await handlers.onOpenMedicationOrders?.();
7556
+ setTouched();
7557
+ }, [handlers, setTouched]);
7558
+ if (!fieldDef || fieldDef.type !== "textarea") return null;
7559
+ const textDef = fieldDef;
7560
+ const height = textDef.height;
7561
+ const theme = getThemeConfig("textarea", fieldDef.theme);
7562
+ const wrapperClass = theme?.wrapperClassName ?? "space-y-2";
7563
+ const labelClass = theme?.labelClassName;
7564
+ const labelContent = /* @__PURE__ */ jsxs(Fragment, { children: [
7565
+ fieldDef.label,
7566
+ " ",
7567
+ fieldDef.required && /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
7568
+ ] });
7569
+ const labelEl = theme ? /* @__PURE__ */ jsx(Label, { htmlFor: fieldId, className: labelClass, children: labelContent }) : /* @__PURE__ */ jsx(Label, { htmlFor: fieldId, children: labelContent });
7570
+ const text = typeof value === "string" ? value : value == null ? "" : String(value);
7571
+ const hasHandler = typeof handlers.onOpenMedicationOrders === "function";
7572
+ return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
7573
+ labelEl,
7574
+ fieldDef.description && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: fieldDef.description }),
7575
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-3", children: [
7576
+ /* @__PURE__ */ jsx(
7577
+ "div",
7578
+ {
7579
+ id: fieldId,
7580
+ className: cn(
7581
+ "min-h-[80px] flex-1 rounded-md border border-input bg-background px-3 py-2 text-sm whitespace-pre-wrap",
7582
+ showError && "border-red-500",
7583
+ !text && "text-muted-foreground"
7584
+ ),
7585
+ style: height != null ? { minHeight: height } : void 0,
7586
+ "aria-readonly": "true",
7587
+ children: text || fieldDef.placeholder || "No medication orders added."
7588
+ }
7589
+ ),
7590
+ /* @__PURE__ */ jsx(
7591
+ Button,
7592
+ {
7593
+ type: "button",
7594
+ variant: "default",
7595
+ disabled: disabled || !hasHandler,
7596
+ onClick: onOpen,
7597
+ className: "shrink-0 sm:mt-0",
7598
+ children: "Add medication orders"
7599
+ }
7600
+ )
7601
+ ] }),
7602
+ showError && /* @__PURE__ */ jsx("p", { className: "text-xs text-red-500", children: error })
7603
+ ] });
7604
+ };
7605
+ function parseFieldValue(value) {
7606
+ if (value == null) return { orders: [], display_lines: [] };
7607
+ if (Array.isArray(value)) {
7608
+ return {
7609
+ orders: value,
7610
+ display_lines: value.map(() => null)
7611
+ };
7612
+ }
7613
+ if (typeof value === "object") {
7614
+ const v = value;
7615
+ const orders = Array.isArray(v.orders) ? v.orders : [];
7616
+ const rawLines = Array.isArray(v.display_lines) ? v.display_lines : Array.isArray(v.displayLines) ? v.displayLines : [];
7617
+ const display_lines = orders.map((_, i) => rawLines[i] ?? null);
7618
+ return { orders, display_lines };
7619
+ }
7620
+ return { orders: [], display_lines: [] };
7621
+ }
7622
+ function normalizePrescription(res) {
7623
+ const pharmacyOrderId = res.pharmacy_order_id ?? void 0;
7624
+ const orders = Array.isArray(res.orders) ? res.orders : [];
7625
+ const linesRaw = Array.isArray(res.display_lines) ? res.display_lines : [];
7626
+ const mapped = orders.filter((o) => o && typeof o.id === "string").map((o) => ({
7627
+ id: o.id,
7628
+ item_id: o.item_id == null ? void 0 : String(o.item_id),
7629
+ item_name: o.item_name ?? void 0,
7630
+ generic_name: o.generic_name ?? void 0,
7631
+ dose: o.dose == null ? void 0 : String(o.dose),
7632
+ route: o.route ?? void 0,
7633
+ frequency: o.frequency ?? void 0,
7634
+ admin_times: Array.isArray(o.admin_times) ? o.admin_times : void 0,
7635
+ meal_sleep_timing: o.meal_sleep_timing ?? void 0,
7636
+ start_date: o.start_date ?? void 0,
7637
+ end_date: o.end_date ?? void 0,
7638
+ order_type: o.order_type ?? void 0,
7639
+ status: o.status ?? void 0,
7640
+ notes: o.notes ?? null,
7641
+ pharmacy_order_id: pharmacyOrderId
7642
+ }));
7643
+ const display_lines = mapped.map((_, i) => linesRaw[i] ?? null);
7644
+ return { orders: mapped, display_lines };
7645
+ }
7646
+ function formatDuration(start, end) {
7647
+ if (!start && !end) return null;
7648
+ if (start && end) return `${start} \u2192 ${end}`;
7649
+ return start ? `Start: ${start}` : `End: ${end}`;
7650
+ }
7651
+ var DischargeMedicationOrdersWidget = ({ fieldId }) => {
7652
+ const { fieldDef, value, setValue, setTouched, error, disabled, touched, visible } = useField(fieldId);
7653
+ const { state } = useForm();
7654
+ const handlers = useFieldHandlers(fieldId);
7655
+ const showError = !!error && (touched || state.submitAttempted);
7656
+ const { orders, display_lines } = useMemo(() => parseFieldValue(value), [value]);
7657
+ const onAdd = useCallback(async () => {
7658
+ setTouched();
7659
+ const fn = handlers.onOpenDischargeMedicationOrders;
7660
+ if (!fn) return;
7661
+ const res = await fn();
7662
+ if (!res || typeof res !== "object") return;
7663
+ const normalized = normalizePrescription(res);
7664
+ setValue({
7665
+ orders: normalized.orders,
7666
+ display_lines: normalized.display_lines
7667
+ });
7668
+ }, [handlers.onOpenDischargeMedicationOrders, setTouched, setValue]);
7669
+ const onDelete = useCallback(
7670
+ (id) => {
7671
+ setTouched();
7672
+ const idx = orders.findIndex((o) => o.id === id);
7673
+ if (idx === -1) return;
7674
+ setValue({
7675
+ orders: orders.filter((o) => o.id !== id),
7676
+ display_lines: display_lines.filter((_, i) => i !== idx)
7677
+ });
7678
+ },
7679
+ [orders, display_lines, setTouched, setValue]
7680
+ );
7681
+ if (!visible || !fieldDef) return null;
7682
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
7683
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
7684
+ /* @__PURE__ */ jsxs(Label, { className: "text-sm font-medium", children: [
7685
+ fieldDef.label,
7686
+ " ",
7687
+ fieldDef.required && /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
7688
+ ] }),
7689
+ /* @__PURE__ */ jsx(Button, { type: "button", onClick: onAdd, disabled: disabled || !handlers.onOpenDischargeMedicationOrders, children: "Add medicine" })
7690
+ ] }),
7691
+ fieldDef.description && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: fieldDef.description }),
7692
+ orders.length === 0 ? /* @__PURE__ */ jsx(
7693
+ "div",
7694
+ {
7695
+ className: cn(
7696
+ "rounded-md border border-input bg-background px-3 py-3 text-sm text-muted-foreground",
7697
+ showError && "border-red-500"
7698
+ ),
7699
+ children: "No medicines added."
7700
+ }
7701
+ ) : /* @__PURE__ */ jsx("div", { className: "space-y-2", children: orders.map((o, rowIdx) => {
7702
+ const line = display_lines[rowIdx];
7703
+ const duration = formatDuration(o.start_date, o.end_date);
7704
+ const header = typeof line?.name === "string" && line.name.trim() || o.item_name || "Medicine";
7705
+ const sub = o.generic_name ? o.generic_name : null;
7706
+ const line1 = [o.dose && `Dose: ${o.dose}`, o.route && `Route: ${o.route}`].filter(Boolean).join(" \u2022 ");
7707
+ const line2 = [
7708
+ o.frequency && `Freq: ${o.frequency}`,
7709
+ o.meal_sleep_timing && `Meal/Sleep: ${o.meal_sleep_timing}`,
7710
+ o.admin_times?.length ? `Times: ${o.admin_times.join(", ")}` : null
7711
+ ].filter(Boolean).join(" \u2022 ");
7712
+ const line3 = [
7713
+ duration ? `Duration: ${duration}` : null,
7714
+ o.order_type ? `Type: ${o.order_type}` : null,
7715
+ o.status ? `Status: ${o.status}` : null
7716
+ ].filter(Boolean).join(" \u2022 ");
7717
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-md border border-input bg-background p-3", children: [
7718
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
7719
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
7720
+ /* @__PURE__ */ jsx("div", { className: "font-semibold text-sm truncate", children: header }),
7721
+ sub && /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground mt-0.5 truncate", children: sub })
7722
+ ] }),
7723
+ /* @__PURE__ */ jsx(
7724
+ Button,
7725
+ {
7726
+ type: "button",
7727
+ variant: "ghost",
7728
+ className: "h-8 w-8 p-0 text-destructive",
7729
+ onClick: () => onDelete(o.id),
7730
+ "aria-label": "Delete medicine",
7731
+ children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" })
7732
+ }
7733
+ )
7734
+ ] }),
7735
+ /* @__PURE__ */ jsxs("div", { className: "mt-2 space-y-1 text-xs text-muted-foreground", children: [
7736
+ line1 && /* @__PURE__ */ jsx("div", { children: line1 }),
7737
+ line2 && /* @__PURE__ */ jsx("div", { children: line2 }),
7738
+ line3 && /* @__PURE__ */ jsx("div", { children: line3 }),
7739
+ o.notes && /* @__PURE__ */ jsxs("div", { className: "text-foreground/80", children: [
7740
+ "Notes: ",
7741
+ o.notes
7742
+ ] })
7743
+ ] })
7744
+ ] }, o.id);
7745
+ }) }),
7746
+ showError && /* @__PURE__ */ jsx("p", { className: "text-xs text-red-500", children: error })
7747
+ ] });
7748
+ };
7542
7749
  var FieldRenderer = ({ fieldId }) => {
7543
7750
  const { fieldDef, visible } = useField(fieldId);
7544
7751
  if (!visible || !fieldDef) {
@@ -7552,6 +7759,9 @@ function renderWidget(fieldId, fieldDef) {
7552
7759
  case "number":
7553
7760
  return /* @__PURE__ */ jsx(TextWidget, { fieldId });
7554
7761
  case "textarea":
7762
+ if (fieldMetaRequestsMarMedicationOrdersButton(fieldDef.meta)) {
7763
+ return /* @__PURE__ */ jsx(MarMedicationOrdersWidget, { fieldId });
7764
+ }
7555
7765
  return /* @__PURE__ */ jsx(TextWidget, { fieldId });
7556
7766
  case "richtext":
7557
7767
  return /* @__PURE__ */ jsx(RichTextWidget, { fieldId });
@@ -7579,6 +7789,8 @@ function renderWidget(fieldId, fieldDef) {
7579
7789
  return /* @__PURE__ */ jsx(EditableTableWidget, { fieldId });
7580
7790
  case "medications":
7581
7791
  return /* @__PURE__ */ jsx(AddMedicationWidget, { fieldId });
7792
+ case "discharge_medication_orders":
7793
+ return /* @__PURE__ */ jsx(DischargeMedicationOrdersWidget, { fieldId });
7582
7794
  case "investigations":
7583
7795
  return /* @__PURE__ */ jsx(AddInvestigationWidget, { fieldId });
7584
7796
  case "procedures":
@@ -8206,6 +8418,53 @@ var ReadOnlyReferral = ({ fieldDef, value }) => {
8206
8418
  }) })
8207
8419
  ] });
8208
8420
  };
8421
+ function isOrderArray(value) {
8422
+ return Array.isArray(value) && value.every(
8423
+ (v) => v != null && typeof v === "object" && typeof v.id === "string"
8424
+ );
8425
+ }
8426
+ function formatDuration2(start, end) {
8427
+ if (!start && !end) return null;
8428
+ if (start && end) return `${start} \u2192 ${end}`;
8429
+ return start ? `Start: ${start}` : `End: ${end}`;
8430
+ }
8431
+ var ReadOnlyDischargeMedicationOrders = ({ fieldDef, value }) => {
8432
+ const orders = useMemo(() => isOrderArray(value) ? value : [], [value]);
8433
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
8434
+ /* @__PURE__ */ jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
8435
+ orders.length === 0 ? /* @__PURE__ */ jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem]", children: /* @__PURE__ */ jsx("span", { className: "text-gray-400 italic", children: "No medicines added" }) }) : /* @__PURE__ */ jsx("div", { className: "space-y-2", children: orders.map((o) => {
8436
+ const duration = formatDuration2(o.start_date, o.end_date);
8437
+ const header = o.item_name ?? "Medicine";
8438
+ const sub = o.generic_name ? o.generic_name : null;
8439
+ const line1 = [o.dose && `Dose: ${o.dose}`, o.route && `Route: ${o.route}`].filter(Boolean).join(" \u2022 ");
8440
+ const line2 = [
8441
+ o.frequency && `Freq: ${o.frequency}`,
8442
+ o.meal_sleep_timing && `Meal/Sleep: ${o.meal_sleep_timing}`,
8443
+ o.admin_times?.length ? `Times: ${o.admin_times.join(", ")}` : null
8444
+ ].filter(Boolean).join(" \u2022 ");
8445
+ const line3 = [
8446
+ duration ? `Duration: ${duration}` : null,
8447
+ o.order_type ? `Type: ${o.order_type}` : null,
8448
+ o.status ? `Status: ${o.status}` : null
8449
+ ].filter(Boolean).join(" \u2022 ");
8450
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-md border border-gray-200 bg-gray-50 p-3", children: [
8451
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
8452
+ /* @__PURE__ */ jsx("div", { className: "font-semibold text-sm truncate text-gray-900", children: header }),
8453
+ sub && /* @__PURE__ */ jsx("div", { className: "text-xs text-gray-500 mt-0.5 truncate", children: sub })
8454
+ ] }),
8455
+ /* @__PURE__ */ jsxs("div", { className: "mt-2 space-y-1 text-xs text-gray-600", children: [
8456
+ line1 && /* @__PURE__ */ jsx("div", { children: line1 }),
8457
+ line2 && /* @__PURE__ */ jsx("div", { children: line2 }),
8458
+ line3 && /* @__PURE__ */ jsx("div", { children: line3 }),
8459
+ o.notes && /* @__PURE__ */ jsxs("div", { className: "text-gray-800/90", children: [
8460
+ "Notes: ",
8461
+ o.notes
8462
+ ] })
8463
+ ] })
8464
+ ] }, o.id);
8465
+ }) })
8466
+ ] });
8467
+ };
8209
8468
  var ReadOnlyFieldRenderer = ({ fieldDef, value }) => {
8210
8469
  if (!fieldDef) return null;
8211
8470
  switch (fieldDef.type) {
@@ -8238,6 +8497,8 @@ var ReadOnlyFieldRenderer = ({ fieldDef, value }) => {
8238
8497
  return /* @__PURE__ */ jsx(ReadOnlyTable, { fieldDef, value });
8239
8498
  case "referral":
8240
8499
  return /* @__PURE__ */ jsx(ReadOnlyReferral, { fieldDef, value });
8500
+ case "discharge_medication_orders":
8501
+ return /* @__PURE__ */ jsx(ReadOnlyDischargeMedicationOrders, { fieldDef, value });
8241
8502
  case "static_text": {
8242
8503
  const def = fieldDef;
8243
8504
  const size = def.size ?? "regular";
@@ -8439,6 +8700,6 @@ function createUploadHandler(options) {
8439
8700
  };
8440
8701
  }
8441
8702
 
8442
- export { AddInvestigationField, AddMedicationField, DifferentialDiagnosis, DynamicForm, EMAIL_REGEX, FieldRenderer, FormControls, FormProvider, FormStore, ImageUploadWidget, MediaUploadWidget, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, RichTextWidget, SignatureUploadWidget, SmartForm, SmartTextareaWidget, createUploadHandler, evaluateRules, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
8703
+ export { AddInvestigationField, AddMedicationField, DifferentialDiagnosis, DynamicForm, EMAIL_REGEX, FieldRenderer, FormControls, FormProvider, FormStore, ImageUploadWidget, MAR_MEDICATION_ORDERS_META_KEY, MediaUploadWidget, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, RichTextWidget, SignatureUploadWidget, SmartForm, SmartTextareaWidget, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
8443
8704
  //# sourceMappingURL=index.mjs.map
8444
8705
  //# sourceMappingURL=index.mjs.map