formanitor 0.0.11 → 0.0.14

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.mjs CHANGED
@@ -1,19 +1,21 @@
1
1
  import * as React11 from 'react';
2
- import React11__default, { createContext, useRef, useEffect, useContext, useState, useMemo } from 'react';
2
+ import React11__default, { createContext, useContext, useRef, useEffect, useState, useMemo, useCallback } from 'react';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
4
  import { clsx } from 'clsx';
5
5
  import { twMerge } from 'tailwind-merge';
6
6
  import * as LabelPrimitive from '@radix-ui/react-label';
7
7
  import { cva } from 'class-variance-authority';
8
8
  import * as SelectPrimitive from '@radix-ui/react-select';
9
- import { ChevronDown, ChevronUp, Check, Circle, X, Image, Upload, Trash2, PenTool, Plus, ChevronRight, Calendar as Calendar$1, Clock, ChevronLeft } from 'lucide-react';
9
+ import { ChevronDown, ChevronUp, Check, Circle, X, Image, Upload, Trash2, Plus, Loader2, PenTool, ChevronRight, Calendar as Calendar$1, ChevronLeft, RefreshCw, Clock } from 'lucide-react';
10
10
  import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
11
11
  import { Slot } from '@radix-ui/react-slot';
12
- import { format } from 'date-fns';
12
+ import { format, addDays, addWeeks, addMonths, differenceInCalendarDays, parseISO } from 'date-fns';
13
13
  import { DayPicker } from 'react-day-picker';
14
14
  import * as PopoverPrimitive from '@radix-ui/react-popover';
15
15
  import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
16
16
  import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
17
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
18
+ import nlp from 'compromise';
17
19
 
18
20
  // src/core/validate.ts
19
21
  var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -26,6 +28,11 @@ function validateField(value, field) {
26
28
  if (Array.isArray(value) && value.length === 0) {
27
29
  return "This field is required";
28
30
  }
31
+ if (field.type === "smart_textarea" && typeof value === "object" && !Array.isArray(value)) {
32
+ if (!value.text || value.text.trim() === "") {
33
+ return "This field is required";
34
+ }
35
+ }
29
36
  }
30
37
  if (value === null || value === void 0 || value === "") {
31
38
  return null;
@@ -213,6 +220,7 @@ var FormStore = class {
213
220
  } else {
214
221
  if (field.type === "repeatable") values[field.id] = [];
215
222
  else if (field.type === "checkbox") values[field.id] = [];
223
+ else if (field.type === "smart_textarea") values[field.id] = { text: "", extractedKeywords: [] };
216
224
  else values[field.id] = null;
217
225
  }
218
226
  });
@@ -253,6 +261,31 @@ var FormStore = class {
253
261
  this.scheduleSave();
254
262
  }
255
263
  }
264
+ /**
265
+ * Set multiple values at once (e.g. from AI analysis). Only updates keys that
266
+ * exist in the schema. Runs evaluate/notify/save once.
267
+ * @param partial Map of fieldId -> value
268
+ * @param options.touch If false, do not mark fields as touched (e.g. for AI-suggested values)
269
+ */
270
+ setValues(partial, options) {
271
+ const touch = options?.touch !== false;
272
+ let changed = false;
273
+ const newValues = { ...this.state.values };
274
+ const newTouched = { ...this.state.touched };
275
+ for (const [fieldId, value] of Object.entries(partial)) {
276
+ if (!this.fieldMap[fieldId]) continue;
277
+ if (newValues[fieldId] === value) continue;
278
+ newValues[fieldId] = value;
279
+ if (touch) newTouched[fieldId] = true;
280
+ changed = true;
281
+ }
282
+ if (!changed) return;
283
+ this.state.values = newValues;
284
+ this.state.touched = newTouched;
285
+ this.evaluate();
286
+ this.notify();
287
+ this.scheduleSave();
288
+ }
256
289
  setTouched(fieldId) {
257
290
  if (this.state.touched[fieldId]) return;
258
291
  this.state.touched = { ...this.state.touched, [fieldId]: true };
@@ -335,6 +368,15 @@ var FormStore = class {
335
368
  getSerializedValuesForSubmission() {
336
369
  return this.serializeValuesForSubmission(this.state.values);
337
370
  }
371
+ /**
372
+ * Raw form values as stored internally, without any serialization or
373
+ * transformation. Useful when consumers need access to richer structures
374
+ * (e.g. smart_textarea keyword metadata) alongside the flattened values
375
+ * returned by getSerializedValuesForSubmission.
376
+ */
377
+ getRawValues() {
378
+ return { ...this.state.values };
379
+ }
338
380
  serializeValuesForSubmission(values) {
339
381
  const result = { ...values };
340
382
  this.schema.fields.forEach((field) => {
@@ -342,6 +384,11 @@ var FormStore = class {
342
384
  delete result[field.id];
343
385
  return;
344
386
  }
387
+ if (field.type === "smart_textarea") {
388
+ const raw = values[field.id];
389
+ result[field.id] = raw?.text ?? null;
390
+ return;
391
+ }
345
392
  if (field.type === "image_upload" || field.type === "signature") {
346
393
  const raw = values[field.id];
347
394
  if (raw !== void 0 && raw !== null && raw !== "") {
@@ -402,6 +449,36 @@ var FormStore = class {
402
449
  this.state.values[comp.target] = 0;
403
450
  }
404
451
  }
452
+ } else if (comp.type === "formula") {
453
+ const evalExpr = (expr) => {
454
+ if (expr.type === "field") {
455
+ return Number(this.state.values[expr.field]) || 0;
456
+ }
457
+ if (expr.type === "number") {
458
+ return expr.value;
459
+ }
460
+ const left = evalExpr(expr.left);
461
+ const right = evalExpr(expr.right);
462
+ switch (expr.op) {
463
+ case "+":
464
+ return left + right;
465
+ case "-":
466
+ return left - right;
467
+ case "*":
468
+ return left * right;
469
+ case "/":
470
+ return right === 0 ? 0 : left / right;
471
+ case "**":
472
+ return Math.pow(left, right);
473
+ default:
474
+ return 0;
475
+ }
476
+ };
477
+ const result = evalExpr(comp.expression);
478
+ const value = Number.isFinite(result) ? Math.round(result * 10) / 10 : "";
479
+ if (this.state.values[comp.target] !== value) {
480
+ this.state.values[comp.target] = value;
481
+ }
405
482
  }
406
483
  });
407
484
  }
@@ -557,7 +634,12 @@ var FormStore = class {
557
634
  }
558
635
  };
559
636
  var FormContext = createContext(null);
560
- var FormProvider = ({ schema, config, children }) => {
637
+ var FieldHandlersContext = createContext({});
638
+ function useFieldHandlers(fieldId) {
639
+ const map = useContext(FieldHandlersContext);
640
+ return map[fieldId] ?? { onSearch: async () => [], recentlyUsed: [] };
641
+ }
642
+ var FormProvider = ({ schema, config, fieldHandlers, children }) => {
561
643
  const storeRef = useRef(null);
562
644
  if (!storeRef.current) {
563
645
  storeRef.current = new FormStore(schema, config);
@@ -570,7 +652,7 @@ var FormProvider = ({ schema, config, children }) => {
570
652
  useEffect(() => {
571
653
  storeRef.current?.load();
572
654
  }, []);
573
- return /* @__PURE__ */ jsx(FormContext.Provider, { value: storeRef.current, children });
655
+ return /* @__PURE__ */ jsx(FormContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsx(FieldHandlersContext.Provider, { value: fieldHandlers ?? {}, children }) });
574
656
  };
575
657
  function useFormStore() {
576
658
  const context = useContext(FormContext);
@@ -597,6 +679,7 @@ function useForm() {
597
679
  availableTransitions: store.getAvailableTransitions(),
598
680
  hasPersistence: store.hasPersistence(),
599
681
  getSerializedValues: store.getSerializedValuesForSubmission.bind(store),
682
+ getRawValues: store.getRawValues.bind(store),
600
683
  markSubmitAttempted: store.markSubmitAttempted.bind(store),
601
684
  flushPendingUploads: store.flushPendingUploads.bind(store)
602
685
  };
@@ -663,8 +746,9 @@ var Textarea = React11.forwardRef(
663
746
  return /* @__PURE__ */ jsx(
664
747
  "textarea",
665
748
  {
749
+ spellCheck: false,
666
750
  className: cn(
667
- "flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
751
+ "flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",
668
752
  height == null && "min-h-[80px]",
669
753
  className
670
754
  ),
@@ -676,6 +760,28 @@ var Textarea = React11.forwardRef(
676
760
  }
677
761
  );
678
762
  Textarea.displayName = "Textarea";
763
+
764
+ // src/ui/themes/textareaThemes.ts
765
+ var textareaThemes = {
766
+ "highlight-label": {
767
+ wrapperClassName: "rounded-md overflow-hidden flex flex-col border border-[#D0D0D0]",
768
+ labelClassName: "rounded-t-md bg-[#FEE8EC] px-3 py-1 text-sm shrink-0 z-[1] text-slate-600",
769
+ inputClassName: "rounded-t-none rounded-b-md border-0 border-t border-[#D0D0D0] text-xs resize-none -mt-1 min-w-0 bg-white text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-offset-0 disabled:cursor-not-allowed disabled:opacity-50"
770
+ }
771
+ };
772
+
773
+ // src/ui/themes/index.ts
774
+ var themeRegistries = {
775
+ textarea: textareaThemes,
776
+ text: textareaThemes
777
+ // same themes can apply to single-line text if desired
778
+ };
779
+ function getThemeConfig(fieldType, themeName) {
780
+ if (!themeName) return void 0;
781
+ const registry = themeRegistries[fieldType];
782
+ if (!registry) return void 0;
783
+ return registry[themeName];
784
+ }
679
785
  var TextWidget = ({ fieldId }) => {
680
786
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
681
787
  const { state } = useForm();
@@ -684,12 +790,20 @@ var TextWidget = ({ fieldId }) => {
684
790
  const Component = fieldDef.type === "textarea" || fieldDef.type === "richtext" ? Textarea : Input;
685
791
  const isTextarea = fieldDef.type === "textarea" || fieldDef.type === "richtext";
686
792
  const height = isTextarea && "height" in fieldDef ? fieldDef.height : void 0;
687
- return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
688
- /* @__PURE__ */ jsxs(Label, { htmlFor: fieldId, children: [
689
- fieldDef.label,
690
- " ",
691
- fieldDef.required && /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
692
- ] }),
793
+ const theme = getThemeConfig(
794
+ isTextarea ? "textarea" : "text",
795
+ fieldDef.theme
796
+ );
797
+ const wrapperClass = theme?.wrapperClassName ?? "space-y-2";
798
+ const labelClass = theme?.labelClassName;
799
+ const inputClass = cn(theme?.inputClassName, showError && "border-red-500");
800
+ const labelContent = /* @__PURE__ */ jsxs(Fragment, { children: [
801
+ fieldDef.label,
802
+ " ",
803
+ fieldDef.required && /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
804
+ ] });
805
+ return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
806
+ theme ? /* @__PURE__ */ jsx(Label, { htmlFor: fieldId, className: labelClass, children: labelContent }) : /* @__PURE__ */ jsx(Label, { htmlFor: fieldId, children: labelContent }),
693
807
  /* @__PURE__ */ jsx(
694
808
  Component,
695
809
  {
@@ -699,7 +813,7 @@ var TextWidget = ({ fieldId }) => {
699
813
  onBlur: setTouched,
700
814
  disabled,
701
815
  type: fieldDef.type === "number" ? "number" : "text",
702
- className: showError ? "border-red-500" : "",
816
+ className: inputClass,
703
817
  ...isTextarea && { height }
704
818
  }
705
819
  ),
@@ -2275,135 +2389,2100 @@ var CheckboxWidget = ({ fieldId }) => {
2275
2389
  showError && /* @__PURE__ */ jsx("p", { className: "text-xs text-red-500", children: error })
2276
2390
  ] });
2277
2391
  };
2278
- var FieldRenderer = ({ fieldId }) => {
2279
- const { fieldDef, visible } = useField(fieldId);
2280
- if (!visible || !fieldDef) {
2281
- return null;
2392
+ var AISuggestionsContext = createContext({});
2393
+ function useAISuggestions() {
2394
+ return useContext(AISuggestionsContext);
2395
+ }
2396
+ var AISuggestionsProvider = AISuggestionsContext.Provider;
2397
+ var Dialog = DialogPrimitive.Root;
2398
+ var DialogPortal = DialogPrimitive.Portal;
2399
+ var DialogOverlay = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
2400
+ DialogPrimitive.Overlay,
2401
+ {
2402
+ ref,
2403
+ className: cn(
2404
+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
2405
+ className
2406
+ ),
2407
+ ...props
2282
2408
  }
2283
- switch (fieldDef.type) {
2284
- case "text":
2285
- case "number":
2286
- return /* @__PURE__ */ jsx(TextWidget, { fieldId });
2287
- case "textarea":
2288
- case "richtext":
2289
- return /* @__PURE__ */ jsx(TextWidget, { fieldId });
2290
- case "date":
2291
- return /* @__PURE__ */ jsx(DateWidget, { fieldId });
2292
- case "datetime":
2293
- return /* @__PURE__ */ jsx(DateTimeWidget, { fieldId });
2294
- case "select":
2295
- return /* @__PURE__ */ jsx(SelectWidget, { fieldId });
2296
- case "radio":
2297
- return /* @__PURE__ */ jsx(RadioWidget, { fieldId });
2298
- case "checkbox":
2299
- return /* @__PURE__ */ jsx(CheckboxWidget, { fieldId });
2300
- case "multiselect":
2301
- return /* @__PURE__ */ jsx(MultiSelectWidget, { fieldId });
2302
- case "repeatable":
2303
- return /* @__PURE__ */ jsx(RepeatableWidget, { fieldId });
2304
- case "image_upload":
2305
- return /* @__PURE__ */ jsx(ImageUploadWidget, { fieldId });
2306
- case "signature":
2307
- return /* @__PURE__ */ jsx(SignatureUploadWidget, { fieldId });
2308
- case "editable_table":
2309
- return /* @__PURE__ */ jsx(EditableTableWidget, { fieldId });
2310
- case "static_text": {
2311
- const def = fieldDef;
2312
- const size = def.size ?? "regular";
2313
- const labelClass = size === "large" ? "text-base" : "text-sm";
2314
- const descClass = size === "large" ? "text-sm" : "text-xs";
2315
- return /* @__PURE__ */ jsxs("div", { className: `${labelClass} text-muted-foreground`, children: [
2316
- def.label,
2317
- def.description && /* @__PURE__ */ jsx("p", { className: `mt-1 ${descClass} opacity-90`, children: def.description })
2318
- ] });
2409
+ ));
2410
+ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
2411
+ var DialogContent = React11.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(DialogPortal, { children: [
2412
+ /* @__PURE__ */ jsx(DialogOverlay, {}),
2413
+ /* @__PURE__ */ jsxs(
2414
+ DialogPrimitive.Content,
2415
+ {
2416
+ ref,
2417
+ className: cn(
2418
+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
2419
+ className
2420
+ ),
2421
+ ...props,
2422
+ children: [
2423
+ children,
2424
+ /* @__PURE__ */ jsxs(DialogPrimitive.Close, { className: "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground", children: [
2425
+ /* @__PURE__ */ jsx(X, { className: "h-4 w-4" }),
2426
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
2427
+ ] })
2428
+ ]
2319
2429
  }
2320
- default:
2321
- return /* @__PURE__ */ jsxs("div", { className: "text-red-500", children: [
2322
- "Unknown field type: ",
2323
- fieldDef.type
2324
- ] });
2430
+ )
2431
+ ] }));
2432
+ DialogContent.displayName = DialogPrimitive.Content.displayName;
2433
+ var DialogHeader = ({
2434
+ className,
2435
+ ...props
2436
+ }) => /* @__PURE__ */ jsx(
2437
+ "div",
2438
+ {
2439
+ className: cn(
2440
+ "flex flex-col space-y-1.5 text-center sm:text-left",
2441
+ className
2442
+ ),
2443
+ ...props
2444
+ }
2445
+ );
2446
+ DialogHeader.displayName = "DialogHeader";
2447
+ var DialogTitle = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
2448
+ DialogPrimitive.Title,
2449
+ {
2450
+ ref,
2451
+ className: cn(
2452
+ "text-lg font-semibold leading-none tracking-tight",
2453
+ className
2454
+ ),
2455
+ ...props
2456
+ }
2457
+ ));
2458
+ DialogTitle.displayName = DialogPrimitive.Title.displayName;
2459
+ var DialogDescription = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
2460
+ DialogPrimitive.Description,
2461
+ {
2462
+ ref,
2463
+ className: cn("text-sm text-muted-foreground", className),
2464
+ ...props
2325
2465
  }
2466
+ ));
2467
+ DialogDescription.displayName = DialogPrimitive.Description.displayName;
2468
+ var AddEntityDialog = ({
2469
+ open,
2470
+ onClose,
2471
+ title,
2472
+ recentlyUsedSlot,
2473
+ children,
2474
+ actionSlot
2475
+ }) => {
2476
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: (o) => !o && onClose(), children: /* @__PURE__ */ jsxs(DialogContent, { className: "max-w-lg w-full p-0 gap-0 flex flex-col max-h-[90vh] overflow-hidden", children: [
2477
+ /* @__PURE__ */ jsx(DialogHeader, { className: "px-6 pt-6 pb-4 shrink-0", children: /* @__PURE__ */ jsx(DialogTitle, { className: "text-lg font-semibold", children: title }) }),
2478
+ /* @__PURE__ */ jsxs("div", { className: "px-6 flex flex-col gap-4 overflow-y-auto flex-1 min-h-0 pb-4", children: [
2479
+ recentlyUsedSlot && /* @__PURE__ */ jsxs("div", { children: [
2480
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mb-2", children: "Recently Used" }),
2481
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: recentlyUsedSlot })
2482
+ ] }),
2483
+ children
2484
+ ] }),
2485
+ actionSlot != null && /* @__PURE__ */ jsx("div", { className: "px-6 py-4 flex justify-end shrink-0 border-t border-border bg-background", children: actionSlot })
2486
+ ] }) });
2326
2487
  };
2327
- var Section = ({ title, children }) => {
2328
- const [expanded, setExpanded] = useState(true);
2329
- const handleToggle = () => setExpanded((prev) => !prev);
2330
- const contentClassName = cn(
2331
- "overflow-hidden transition-[height] duration-200 ease-in-out",
2332
- !expanded && "hidden"
2333
- );
2334
- return /* @__PURE__ */ jsxs("div", { className: "mb-6 border rounded-lg bg-white shadow-sm overflow-hidden", children: [
2335
- /* @__PURE__ */ jsxs(
2488
+ function mapToMedication(result) {
2489
+ return {
2490
+ id: result.id,
2491
+ brand_name: result.name,
2492
+ generic_name: result.generic_name ?? "",
2493
+ frequency: "custom",
2494
+ is_custom: false,
2495
+ duration_value: "3",
2496
+ duration_unit: "days",
2497
+ before_after: "AFTER FOOD",
2498
+ morning: "0",
2499
+ afternoon: "0",
2500
+ night: "0",
2501
+ notes: ""
2502
+ };
2503
+ }
2504
+ function mapAIMedicationToMedication(ai) {
2505
+ const id = typeof ai.id === "string" ? Number.parseInt(ai.id, 10) || 0 : Number(ai.id);
2506
+ return {
2507
+ id: Number.isNaN(id) ? 0 : id,
2508
+ brand_name: ai.brand_name ?? "",
2509
+ generic_name: ai.generic_name ?? "",
2510
+ frequency: "custom",
2511
+ is_custom: false,
2512
+ duration_value: "3",
2513
+ duration_unit: "days",
2514
+ before_after: "AFTER FOOD",
2515
+ morning: "1",
2516
+ afternoon: "0",
2517
+ night: "1",
2518
+ notes: ai.reason ?? ""
2519
+ };
2520
+ }
2521
+ function createCustomMedication(name, customId) {
2522
+ return {
2523
+ id: customId,
2524
+ brand_name: name.trim(),
2525
+ generic_name: "",
2526
+ frequency: "custom",
2527
+ is_custom: true,
2528
+ duration_value: "3",
2529
+ duration_unit: "days",
2530
+ before_after: "AFTER FOOD",
2531
+ morning: "0",
2532
+ afternoon: "0",
2533
+ night: "0",
2534
+ notes: ""
2535
+ };
2536
+ }
2537
+ function Spinner({
2538
+ value,
2539
+ onChange
2540
+ }) {
2541
+ const num = parseInt(value, 10) || 0;
2542
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center", children: [
2543
+ /* @__PURE__ */ jsx(
2336
2544
  "button",
2337
2545
  {
2338
2546
  type: "button",
2339
- onClick: handleToggle,
2340
- className: "w-full flex items-center justify-between gap-2 p-4 text-left border-b hover:bg-gray-50/80 transition-colors",
2341
- children: [
2342
- /* @__PURE__ */ jsx("h3", { className: "text-lg font-medium", children: title }),
2343
- /* @__PURE__ */ jsx("span", { className: "flex-shrink-0 text-muted-foreground", "aria-hidden": true, children: expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-5 w-5" }) })
2344
- ]
2547
+ className: "text-muted-foreground hover:text-foreground cursor-pointer",
2548
+ onClick: () => onChange(String(num + 1)),
2549
+ children: /* @__PURE__ */ jsx(ChevronUp, { className: "h-3 w-3" })
2345
2550
  }
2346
2551
  ),
2347
- /* @__PURE__ */ jsx("div", { className: contentClassName, children: /* @__PURE__ */ jsx("div", { className: "p-4 pt-4 space-y-4 border-t-0", children }) })
2348
- ] });
2349
- };
2350
- var ColumnLayout = ({
2351
- columns,
2352
- label,
2353
- children
2354
- }) => {
2355
- const gridCols = Math.max(1, Math.min(columns, 12));
2356
- const gridClass = `grid gap-4 w-full`;
2357
- const style = {
2358
- gridTemplateColumns: `repeat(${gridCols}, minmax(0, 1fr))`
2359
- };
2360
- return /* @__PURE__ */ jsxs("div", { className: "mb-6", children: [
2361
- label != null && label !== "" && /* @__PURE__ */ jsx("div", { className: "mb-2 text-sm font-medium text-gray-700", children: label }),
2362
- /* @__PURE__ */ jsx("div", { className: gridClass, style, children })
2552
+ /* @__PURE__ */ jsx("span", { className: "text-sm w-4 text-center leading-none", children: num }),
2553
+ /* @__PURE__ */ jsx(
2554
+ "button",
2555
+ {
2556
+ type: "button",
2557
+ className: "text-muted-foreground hover:text-foreground cursor-pointer",
2558
+ onClick: () => onChange(String(Math.max(0, num - 1))),
2559
+ children: /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3" })
2560
+ }
2561
+ )
2363
2562
  ] });
2364
- };
2365
- var DynamicForm = () => {
2366
- const store = useFormStore();
2367
- const schema = store.getSchema();
2368
- const { state } = useForm();
2369
- return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
2370
- /* @__PURE__ */ jsxs("div", { className: "mb-4", children: [
2371
- /* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold", children: schema.title }),
2372
- /* @__PURE__ */ jsxs("div", { className: "text-sm text-gray-500", children: [
2373
- "Version: ",
2374
- schema.version,
2375
- " | State: ",
2376
- state.workflowState
2377
- ] })
2563
+ }
2564
+ function MedicationCard({
2565
+ med,
2566
+ onUpdate,
2567
+ onRemove
2568
+ }) {
2569
+ const [notesOpen, setNotesOpen] = useState(false);
2570
+ function set(key, val) {
2571
+ onUpdate({ ...med, [key]: val });
2572
+ }
2573
+ return /* @__PURE__ */ jsxs("div", { className: "bg-gray-50 rounded-lg p-3 space-y-2", children: [
2574
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [
2575
+ /* @__PURE__ */ jsx("span", { className: "font-semibold text-sm flex-1 min-w-0 truncate", children: med.brand_name }),
2576
+ /* @__PURE__ */ jsxs(
2577
+ "select",
2578
+ {
2579
+ className: "text-xs border border-border rounded px-2 py-1 bg-white shrink-0",
2580
+ value: med.frequency,
2581
+ onChange: (e) => set("frequency", e.target.value),
2582
+ children: [
2583
+ /* @__PURE__ */ jsx("option", { value: "custom", children: "select frequency" }),
2584
+ /* @__PURE__ */ jsx("option", { value: "OD", children: "OD" }),
2585
+ /* @__PURE__ */ jsx("option", { value: "BD", children: "BD" }),
2586
+ /* @__PURE__ */ jsx("option", { value: "TDS", children: "TDS" }),
2587
+ /* @__PURE__ */ jsx("option", { value: "QID", children: "QID" }),
2588
+ /* @__PURE__ */ jsx("option", { value: "SOS", children: "SOS" })
2589
+ ]
2590
+ }
2591
+ ),
2592
+ /* @__PURE__ */ jsx("div", { className: "flex gap-4 items-center shrink-0", children: ["morning", "afternoon", "night"].map((slot) => /* @__PURE__ */ jsx(
2593
+ "span",
2594
+ {
2595
+ className: "text-[10px] font-semibold uppercase text-muted-foreground tracking-wide",
2596
+ children: slot === "afternoon" ? "AFTERNOON" : slot === "morning" ? "MORNING" : "NIGHT"
2597
+ },
2598
+ slot
2599
+ )) }),
2600
+ /* @__PURE__ */ jsx(
2601
+ "button",
2602
+ {
2603
+ type: "button",
2604
+ onClick: onRemove,
2605
+ className: "text-red-400 hover:text-red-600 shrink-0 p-1 cursor-pointer",
2606
+ children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" })
2607
+ }
2608
+ )
2378
2609
  ] }),
2379
- schema.layout.map((node) => {
2380
- if (node.type === "section") {
2381
- return /* @__PURE__ */ jsx(Section, { title: node.title, children: node.children.map(
2382
- (child, index) => typeof child === "string" ? /* @__PURE__ */ jsx(FieldRenderer, { fieldId: child }, child) : child.type === "column_layout" ? /* @__PURE__ */ jsx(
2383
- ColumnLayout,
2610
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 flex-wrap", children: [
2611
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 shrink-0", children: [
2612
+ /* @__PURE__ */ jsx(
2613
+ "input",
2614
+ {
2615
+ type: "text",
2616
+ inputMode: "numeric",
2617
+ pattern: "[0-9]*",
2618
+ className: "w-11 text-sm border border-border rounded px-2 py-1 bg-white",
2619
+ value: med.duration_value,
2620
+ onChange: (e) => {
2621
+ const v = e.target.value.replace(/\D/g, "");
2622
+ set("duration_value", v === "" ? "" : v);
2623
+ }
2624
+ }
2625
+ ),
2626
+ /* @__PURE__ */ jsxs(
2627
+ "select",
2628
+ {
2629
+ className: "text-xs border border-border rounded px-2 py-1 bg-white",
2630
+ value: med.duration_unit,
2631
+ onChange: (e) => set("duration_unit", e.target.value),
2632
+ children: [
2633
+ /* @__PURE__ */ jsx("option", { value: "days", children: "days" }),
2634
+ /* @__PURE__ */ jsx("option", { value: "weeks", children: "weeks" }),
2635
+ /* @__PURE__ */ jsx("option", { value: "months", children: "months" })
2636
+ ]
2637
+ }
2638
+ )
2639
+ ] }),
2640
+ /* @__PURE__ */ jsx("div", { className: "flex gap-2 items-center flex-1 min-w-0 justify-end", children: ["morning", "afternoon", "night"].map((slot) => /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center gap-0.5", children: /* @__PURE__ */ jsx(Spinner, { value: med[slot], onChange: (v) => set(slot, v) }) }, slot)) }),
2641
+ /* @__PURE__ */ jsxs(
2642
+ "select",
2643
+ {
2644
+ className: "text-xs border border-border rounded px-2 py-1 bg-white shrink-0",
2645
+ value: med.before_after === "AFTER FOOD" ? "AF" : "BF",
2646
+ onChange: (e) => set("before_after", e.target.value === "AF" ? "AFTER FOOD" : "BEFORE FOOD"),
2647
+ children: [
2648
+ /* @__PURE__ */ jsx("option", { value: "AF", children: "AF" }),
2649
+ /* @__PURE__ */ jsx("option", { value: "BF", children: "BF" })
2650
+ ]
2651
+ }
2652
+ )
2653
+ ] }),
2654
+ /* @__PURE__ */ jsxs(
2655
+ "div",
2656
+ {
2657
+ role: "button",
2658
+ tabIndex: 0,
2659
+ onClick: () => setNotesOpen((o) => !o),
2660
+ onKeyDown: (e) => {
2661
+ if (e.key === "Enter" || e.key === " ") {
2662
+ e.preventDefault();
2663
+ setNotesOpen((o) => !o);
2664
+ }
2665
+ },
2666
+ className: cn(
2667
+ "flex items-center gap-2 w-full text-left text-xs text-muted-foreground hover:text-foreground",
2668
+ "cursor-pointer py-2 px-2 rounded border border-transparent hover:bg-gray-100/80 transition-colors"
2669
+ ),
2670
+ children: [
2671
+ /* @__PURE__ */ jsx(
2672
+ ChevronRight,
2384
2673
  {
2385
- columns: child.columns,
2386
- label: child.label,
2387
- children: child.children.map((fieldId) => /* @__PURE__ */ jsx(FieldRenderer, { fieldId }, fieldId))
2388
- },
2389
- child.id
2390
- ) : /* @__PURE__ */ jsx(React11__default.Fragment, {}, child.id ?? index)
2391
- ) }, node.id);
2674
+ className: cn("h-3 w-3 shrink-0 transition-transform", notesOpen && "rotate-90")
2675
+ }
2676
+ ),
2677
+ /* @__PURE__ */ jsx("span", { children: "Medicine Notes" })
2678
+ ]
2392
2679
  }
2393
- if (node.type === "column_layout") {
2394
- return /* @__PURE__ */ jsx(
2395
- ColumnLayout,
2396
- {
2397
- columns: node.columns,
2398
- label: node.label,
2399
- children: node.children.map((fieldId) => /* @__PURE__ */ jsx(FieldRenderer, { fieldId }, fieldId))
2400
- },
2401
- node.id
2402
- );
2680
+ ),
2681
+ notesOpen && /* @__PURE__ */ jsx("div", { className: "relative z-10 mt-0.5", children: /* @__PURE__ */ jsx(
2682
+ "textarea",
2683
+ {
2684
+ className: "block w-full text-xs border border-border rounded px-2 py-1 resize-none bg-white min-h-0",
2685
+ rows: 2,
2686
+ placeholder: "Add notes...",
2687
+ value: med.notes,
2688
+ onChange: (e) => set("notes", e.target.value)
2403
2689
  }
2404
- return null;
2405
- })
2690
+ ) })
2406
2691
  ] });
2692
+ }
2693
+ var ADD_FEEDBACK_MS = 320;
2694
+ function SearchResultCard({
2695
+ result,
2696
+ isAdding,
2697
+ onSelect
2698
+ }) {
2699
+ return /* @__PURE__ */ jsxs(
2700
+ "button",
2701
+ {
2702
+ type: "button",
2703
+ onClick: onSelect,
2704
+ className: cn(
2705
+ "w-full text-left border rounded-lg px-3 py-2 transition-all duration-300 ease-out cursor-pointer flex items-center justify-between gap-2",
2706
+ isAdding ? "border-green-400 bg-green-50 scale-[0.98]" : "border-border bg-white hover:bg-gray-50"
2707
+ ),
2708
+ children: [
2709
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 text-left", children: [
2710
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold leading-tight truncate", children: result.name }),
2711
+ result.generic_name && /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground mt-0.5 truncate", children: [
2712
+ "Generic: ",
2713
+ result.generic_name
2714
+ ] })
2715
+ ] }),
2716
+ isAdding && /* @__PURE__ */ jsx(Check, { className: "h-4 w-4 shrink-0 text-green-600" })
2717
+ ]
2718
+ }
2719
+ );
2720
+ }
2721
+ var AddMedicationField = ({
2722
+ label = "Medications",
2723
+ value,
2724
+ onChange,
2725
+ onSearch,
2726
+ recentlyUsed = [],
2727
+ suggestedMedications = []
2728
+ }) => {
2729
+ const [open, setOpen] = useState(false);
2730
+ const [query, setQuery] = useState("");
2731
+ const [results, setResults] = useState([]);
2732
+ const [loading, setLoading] = useState(false);
2733
+ const [addingResultId, setAddingResultId] = useState(null);
2734
+ const debounceRef = useRef(null);
2735
+ const customIdRef = useRef(-1);
2736
+ const valueRef = useRef([]);
2737
+ const searchInputRef = useRef(null);
2738
+ const safeValue = Array.isArray(value) ? value : [];
2739
+ valueRef.current = safeValue;
2740
+ const addedIds = new Set(safeValue.map((m) => String(m.id)));
2741
+ useEffect(() => {
2742
+ if (!open) {
2743
+ setQuery("");
2744
+ setResults([]);
2745
+ setAddingResultId(null);
2746
+ }
2747
+ }, [open]);
2748
+ function handleQueryChange(q) {
2749
+ setQuery(q);
2750
+ if (debounceRef.current) clearTimeout(debounceRef.current);
2751
+ if (!q.trim()) {
2752
+ setResults([]);
2753
+ return;
2754
+ }
2755
+ debounceRef.current = setTimeout(async () => {
2756
+ setLoading(true);
2757
+ try {
2758
+ const res = await onSearch(q);
2759
+ setResults(res);
2760
+ } finally {
2761
+ setLoading(false);
2762
+ }
2763
+ }, 500);
2764
+ }
2765
+ function handleRecentlyUsedToggle(result) {
2766
+ if (addedIds.has(String(result.id))) {
2767
+ onChange(safeValue.filter((m) => String(m.id) !== String(result.id)));
2768
+ } else {
2769
+ onChange([...safeValue, mapToMedication(result)]);
2770
+ }
2771
+ }
2772
+ function handleResultClick(result) {
2773
+ if (addedIds.has(String(result.id))) return;
2774
+ setAddingResultId(result.id);
2775
+ setTimeout(() => {
2776
+ onChange([...valueRef.current, mapToMedication(result)]);
2777
+ setAddingResultId(null);
2778
+ setQuery("");
2779
+ setResults([]);
2780
+ setTimeout(() => searchInputRef.current?.focus(), 0);
2781
+ }, ADD_FEEDBACK_MS);
2782
+ }
2783
+ function handleSave() {
2784
+ const trimmed = query.trim();
2785
+ if (!trimmed) return;
2786
+ const customId = customIdRef.current--;
2787
+ onChange([...safeValue, createCustomMedication(trimmed, customId)]);
2788
+ setQuery("");
2789
+ setResults([]);
2790
+ }
2791
+ function handleAddSuggestion(ai) {
2792
+ if (addedIds.has(String(ai.id))) return;
2793
+ onChange([...safeValue, mapAIMedicationToMedication(ai)]);
2794
+ }
2795
+ function updateMed(index, updated) {
2796
+ const next = [...safeValue];
2797
+ next[index] = updated;
2798
+ onChange(next);
2799
+ }
2800
+ function removeMed(index) {
2801
+ onChange(safeValue.filter((_, i) => i !== index));
2802
+ }
2803
+ const recentlyUsedChips = recentlyUsed.map((r) => {
2804
+ const isAdded = addedIds.has(String(r.id));
2805
+ return /* @__PURE__ */ jsxs(
2806
+ "button",
2807
+ {
2808
+ type: "button",
2809
+ onClick: () => handleRecentlyUsedToggle(r),
2810
+ className: cn(
2811
+ "rounded-full border text-xs px-3 py-1 transition-colors cursor-pointer",
2812
+ isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
2813
+ ),
2814
+ children: [
2815
+ isAdded && /* @__PURE__ */ jsx("span", { className: "mr-1", children: "\u2713" }),
2816
+ r.name
2817
+ ]
2818
+ },
2819
+ r.id
2820
+ );
2821
+ });
2822
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-md overflow-hidden flex flex-col border bg-white border-[#D0D0D0] space-y-3 p-3 h-fit", children: [
2823
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
2824
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: label }),
2825
+ /* @__PURE__ */ jsx(
2826
+ "button",
2827
+ {
2828
+ type: "button",
2829
+ onClick: () => setOpen(true),
2830
+ className: "text-sm font-semibold text-purple-600 hover:text-purple-800 cursor-pointer",
2831
+ children: "ADD"
2832
+ }
2833
+ )
2834
+ ] }),
2835
+ suggestedMedications.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1.5 items-center", children: [
2836
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground mr-1", children: "Suggestions:" }),
2837
+ suggestedMedications.filter((s) => !addedIds.has(String(s.id))).map((s) => /* @__PURE__ */ jsxs(
2838
+ "button",
2839
+ {
2840
+ type: "button",
2841
+ onClick: () => handleAddSuggestion(s),
2842
+ className: "inline-flex items-center gap-1 rounded-full border border-dashed border-purple-300 bg-purple-50/80 text-purple-800 text-xs px-2.5 py-1 hover:bg-purple-100 transition-colors cursor-pointer",
2843
+ children: [
2844
+ /* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" }),
2845
+ s.brand_name || s.generic_name || String(s.id)
2846
+ ]
2847
+ },
2848
+ String(s.id)
2849
+ ))
2850
+ ] }),
2851
+ /* @__PURE__ */ jsx("div", { className: "space-y-2", children: safeValue.map((med, i) => /* @__PURE__ */ jsx(
2852
+ MedicationCard,
2853
+ {
2854
+ med,
2855
+ onUpdate: (u) => updateMed(i, u),
2856
+ onRemove: () => removeMed(i)
2857
+ },
2858
+ med.id
2859
+ )) }),
2860
+ /* @__PURE__ */ jsx(
2861
+ AddEntityDialog,
2862
+ {
2863
+ open,
2864
+ onClose: () => setOpen(false),
2865
+ title: "Add Medication",
2866
+ recentlyUsedSlot: recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
2867
+ actionSlot: /* @__PURE__ */ jsx(
2868
+ "button",
2869
+ {
2870
+ type: "button",
2871
+ disabled: !query.trim(),
2872
+ onClick: handleSave,
2873
+ className: cn(
2874
+ "rounded-md px-5 py-2 text-sm font-semibold bg-primary text-primary-foreground hover:bg-primary/90 transition-opacity cursor-pointer",
2875
+ !query.trim() && "opacity-40 cursor-not-allowed"
2876
+ ),
2877
+ children: "Save Medicine"
2878
+ }
2879
+ ),
2880
+ children: /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2881
+ /* @__PURE__ */ jsx(
2882
+ Input,
2883
+ {
2884
+ ref: searchInputRef,
2885
+ value: query,
2886
+ onChange: (e) => handleQueryChange(e.target.value),
2887
+ placeholder: "Search medicines...",
2888
+ className: "border border-border rounded-md focus-visible:ring-0"
2889
+ }
2890
+ ),
2891
+ loading && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground text-center py-2", children: "Searching\u2026" }),
2892
+ !loading && results.length > 0 && /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-2 max-h-64 overflow-y-auto", children: results.map((r) => /* @__PURE__ */ jsx(
2893
+ SearchResultCard,
2894
+ {
2895
+ result: r,
2896
+ isAdding: addingResultId === r.id,
2897
+ onSelect: () => handleResultClick(r)
2898
+ },
2899
+ r.id
2900
+ )) })
2901
+ ] })
2902
+ }
2903
+ )
2904
+ ] });
2905
+ };
2906
+ var AddMedicationWidget = ({ fieldId }) => {
2907
+ const { value, setValue } = useField(fieldId);
2908
+ const handlers = useFieldHandlers(fieldId);
2909
+ const { medications: suggestedMedications } = useAISuggestions();
2910
+ const safeValue = Array.isArray(value) ? value : [];
2911
+ return /* @__PURE__ */ jsx(
2912
+ AddMedicationField,
2913
+ {
2914
+ value: safeValue,
2915
+ onChange: setValue,
2916
+ onSearch: handlers.onSearch,
2917
+ recentlyUsed: handlers.recentlyUsed,
2918
+ suggestedMedications
2919
+ }
2920
+ );
2921
+ };
2922
+ var ADD_FEEDBACK_MS2 = 320;
2923
+ function mapToInvestigation(result) {
2924
+ return {
2925
+ ...result,
2926
+ label: result.name,
2927
+ is_custom: false,
2928
+ fromAI: false
2929
+ };
2930
+ }
2931
+ var AddInvestigationField = ({
2932
+ label = "Investigations",
2933
+ value,
2934
+ onChange,
2935
+ onSearch,
2936
+ recentlyUsed = []
2937
+ }) => {
2938
+ const [open, setOpen] = useState(false);
2939
+ const [query, setQuery] = useState("");
2940
+ const [results, setResults] = useState([]);
2941
+ const [loading, setLoading] = useState(false);
2942
+ const [addingId, setAddingId] = useState(null);
2943
+ const debounceRef = useRef(null);
2944
+ const valueRef = useRef([]);
2945
+ const searchInputRef = useRef(null);
2946
+ valueRef.current = value;
2947
+ const addedIds = new Set(value.map((inv) => inv.id));
2948
+ useEffect(() => {
2949
+ if (!open) {
2950
+ setQuery("");
2951
+ setResults([]);
2952
+ setAddingId(null);
2953
+ }
2954
+ }, [open]);
2955
+ function handleQueryChange(q) {
2956
+ setQuery(q);
2957
+ if (debounceRef.current) clearTimeout(debounceRef.current);
2958
+ if (!q.trim()) {
2959
+ setResults([]);
2960
+ return;
2961
+ }
2962
+ debounceRef.current = setTimeout(async () => {
2963
+ setLoading(true);
2964
+ try {
2965
+ const res = await onSearch(q);
2966
+ setResults(res);
2967
+ } finally {
2968
+ setLoading(false);
2969
+ }
2970
+ }, 500);
2971
+ }
2972
+ function addInvestigation(result) {
2973
+ if (!addedIds.has(result.id)) {
2974
+ onChange([...valueRef.current, mapToInvestigation(result)]);
2975
+ }
2976
+ setQuery("");
2977
+ setResults([]);
2978
+ }
2979
+ function handleResultClick(result) {
2980
+ if (addedIds.has(result.id)) return;
2981
+ setAddingId(result.id);
2982
+ setTimeout(() => {
2983
+ addInvestigation(result);
2984
+ setAddingId(null);
2985
+ setTimeout(() => searchInputRef.current?.focus(), 0);
2986
+ }, ADD_FEEDBACK_MS2);
2987
+ }
2988
+ function removeInvestigation(id) {
2989
+ onChange(value.filter((inv) => inv.id !== id));
2990
+ }
2991
+ function handleRecentlyUsedToggle(result) {
2992
+ if (addedIds.has(result.id)) {
2993
+ removeInvestigation(result.id);
2994
+ } else {
2995
+ addInvestigation(result);
2996
+ }
2997
+ }
2998
+ const recentlyUsedChips = recentlyUsed.map((r) => {
2999
+ const isAdded = addedIds.has(r.id);
3000
+ return /* @__PURE__ */ jsxs(
3001
+ "button",
3002
+ {
3003
+ type: "button",
3004
+ onClick: () => handleRecentlyUsedToggle(r),
3005
+ className: cn(
3006
+ "rounded-full border text-xs px-3 py-1 transition-colors",
3007
+ isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
3008
+ ),
3009
+ children: [
3010
+ isAdded && /* @__PURE__ */ jsx("span", { className: "mr-1", children: "\u2713" }),
3011
+ r.name
3012
+ ]
3013
+ },
3014
+ r.id
3015
+ );
3016
+ });
3017
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-md overflow-hidden flex flex-col bg-white border border-[#D0D0D0] space-y-3 p-3 h-fit", children: [
3018
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
3019
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: label }),
3020
+ /* @__PURE__ */ jsx(
3021
+ "button",
3022
+ {
3023
+ type: "button",
3024
+ onClick: () => setOpen(true),
3025
+ className: "text-sm font-semibold text-purple-600 hover:text-purple-800 cursor-pointer",
3026
+ children: "ADD"
3027
+ }
3028
+ )
3029
+ ] }),
3030
+ value.length > 0 && /* @__PURE__ */ jsx("div", { className: "divide-y divide-border rounded-lg border border-border overflow-hidden", children: value.map((inv) => /* @__PURE__ */ jsxs(
3031
+ "div",
3032
+ {
3033
+ className: "flex items-center justify-between px-3 py-2 bg-white hover:bg-gray-50",
3034
+ children: [
3035
+ /* @__PURE__ */ jsx("span", { className: "text-sm", children: inv.name }),
3036
+ /* @__PURE__ */ jsx(
3037
+ "button",
3038
+ {
3039
+ type: "button",
3040
+ onClick: () => removeInvestigation(inv.id),
3041
+ className: "text-muted-foreground hover:text-red-500 transition-colors cursor-pointer",
3042
+ children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
3043
+ }
3044
+ )
3045
+ ]
3046
+ },
3047
+ inv.id
3048
+ )) }),
3049
+ /* @__PURE__ */ jsx(
3050
+ AddEntityDialog,
3051
+ {
3052
+ open,
3053
+ onClose: () => setOpen(false),
3054
+ title: "Add Investigation",
3055
+ recentlyUsedSlot: recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
3056
+ children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
3057
+ /* @__PURE__ */ jsx(
3058
+ Input,
3059
+ {
3060
+ ref: searchInputRef,
3061
+ value: query,
3062
+ onChange: (e) => handleQueryChange(e.target.value),
3063
+ placeholder: "Search for an investigation...",
3064
+ className: "border border-border rounded-md focus-visible:ring-0"
3065
+ }
3066
+ ),
3067
+ loading && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground py-1", children: "Searching\u2026" }),
3068
+ !loading && results.length > 0 && /* @__PURE__ */ jsx("div", { className: "border border-border rounded-md overflow-hidden", children: results.map((r) => {
3069
+ const isAdding = addingId === r.id;
3070
+ return /* @__PURE__ */ jsxs(
3071
+ "button",
3072
+ {
3073
+ type: "button",
3074
+ onClick: () => handleResultClick(r),
3075
+ className: cn(
3076
+ "w-full text-left px-3 py-2 text-sm transition-all duration-300 ease-out border-b border-border last:border-b-0 cursor-pointer flex items-center justify-between gap-2",
3077
+ isAdding ? "bg-green-50 border-green-200" : "hover:bg-gray-50"
3078
+ ),
3079
+ children: [
3080
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: r.name }),
3081
+ isAdding && /* @__PURE__ */ jsx(Check, { className: "h-4 w-4 shrink-0 text-green-600" })
3082
+ ]
3083
+ },
3084
+ r.id
3085
+ );
3086
+ }) })
3087
+ ] })
3088
+ }
3089
+ )
3090
+ ] });
3091
+ };
3092
+ var AddInvestigationWidget = ({ fieldId }) => {
3093
+ const { value, setValue } = useField(fieldId);
3094
+ const handlers = useFieldHandlers(fieldId);
3095
+ return /* @__PURE__ */ jsx(
3096
+ AddInvestigationField,
3097
+ {
3098
+ value: value ?? [],
3099
+ onChange: setValue,
3100
+ onSearch: handlers.onSearch,
3101
+ recentlyUsed: handlers.recentlyUsed
3102
+ }
3103
+ );
3104
+ };
3105
+ var ADD_FEEDBACK_MS3 = 320;
3106
+ function mapToProcedure(result) {
3107
+ return {
3108
+ ...result,
3109
+ label: result.name,
3110
+ is_custom: false,
3111
+ fromAI: false
3112
+ };
3113
+ }
3114
+ var AddProcedureField = ({
3115
+ label = "Procedures",
3116
+ value,
3117
+ onChange,
3118
+ onSearch,
3119
+ recentlyUsed = []
3120
+ }) => {
3121
+ const [open, setOpen] = useState(false);
3122
+ const [query, setQuery] = useState("");
3123
+ const [results, setResults] = useState([]);
3124
+ const [loading, setLoading] = useState(false);
3125
+ const [addingId, setAddingId] = useState(null);
3126
+ const debounceRef = useRef(null);
3127
+ const valueRef = useRef([]);
3128
+ const searchInputRef = useRef(null);
3129
+ valueRef.current = value;
3130
+ const addedIds = new Set(value.map((proc) => proc.id));
3131
+ useEffect(() => {
3132
+ if (!open) {
3133
+ setQuery("");
3134
+ setResults([]);
3135
+ setAddingId(null);
3136
+ }
3137
+ }, [open]);
3138
+ function handleQueryChange(q) {
3139
+ setQuery(q);
3140
+ if (debounceRef.current) clearTimeout(debounceRef.current);
3141
+ if (!q.trim()) {
3142
+ setResults([]);
3143
+ return;
3144
+ }
3145
+ debounceRef.current = setTimeout(async () => {
3146
+ setLoading(true);
3147
+ try {
3148
+ const res = await onSearch(q);
3149
+ setResults(res);
3150
+ } finally {
3151
+ setLoading(false);
3152
+ }
3153
+ }, 500);
3154
+ }
3155
+ function addProcedure(result) {
3156
+ if (!addedIds.has(result.id)) {
3157
+ onChange([...valueRef.current, mapToProcedure(result)]);
3158
+ }
3159
+ setQuery("");
3160
+ setResults([]);
3161
+ }
3162
+ function handleResultClick(result) {
3163
+ if (addedIds.has(result.id)) return;
3164
+ setAddingId(result.id);
3165
+ setTimeout(() => {
3166
+ addProcedure(result);
3167
+ setAddingId(null);
3168
+ setTimeout(() => searchInputRef.current?.focus(), 0);
3169
+ }, ADD_FEEDBACK_MS3);
3170
+ }
3171
+ function removeProcedure(id) {
3172
+ onChange(value.filter((proc) => proc.id !== id));
3173
+ }
3174
+ function handleRecentlyUsedToggle(result) {
3175
+ if (addedIds.has(result.id)) {
3176
+ removeProcedure(result.id);
3177
+ } else {
3178
+ addProcedure(result);
3179
+ }
3180
+ }
3181
+ const recentlyUsedChips = recentlyUsed.map((r) => {
3182
+ const isAdded = addedIds.has(r.id);
3183
+ return /* @__PURE__ */ jsxs(
3184
+ "button",
3185
+ {
3186
+ type: "button",
3187
+ onClick: () => handleRecentlyUsedToggle(r),
3188
+ className: cn(
3189
+ "rounded-full border text-xs px-3 py-1 transition-colors",
3190
+ isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
3191
+ ),
3192
+ children: [
3193
+ isAdded && /* @__PURE__ */ jsx("span", { className: "mr-1", children: "\u2713" }),
3194
+ r.name
3195
+ ]
3196
+ },
3197
+ r.id
3198
+ );
3199
+ });
3200
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-md overflow-hidden flex flex-col bg-white border border-[#D0D0D0] space-y-3 p-3 h-fit", children: [
3201
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
3202
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: label }),
3203
+ /* @__PURE__ */ jsx(
3204
+ "button",
3205
+ {
3206
+ type: "button",
3207
+ onClick: () => setOpen(true),
3208
+ className: "text-sm font-semibold text-purple-600 hover:text-purple-800 cursor-pointer",
3209
+ children: "ADD"
3210
+ }
3211
+ )
3212
+ ] }),
3213
+ value.length > 0 && /* @__PURE__ */ jsx("div", { className: "divide-y divide-border rounded-lg border border-border overflow-hidden", children: value.map((proc) => /* @__PURE__ */ jsxs(
3214
+ "div",
3215
+ {
3216
+ className: "flex items-center justify-between px-3 py-2 bg-white hover:bg-gray-50",
3217
+ children: [
3218
+ /* @__PURE__ */ jsx("span", { className: "text-sm", children: proc.name }),
3219
+ /* @__PURE__ */ jsx(
3220
+ "button",
3221
+ {
3222
+ type: "button",
3223
+ onClick: () => removeProcedure(proc.id),
3224
+ className: "text-muted-foreground hover:text-red-500 transition-colors cursor-pointer",
3225
+ children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
3226
+ }
3227
+ )
3228
+ ]
3229
+ },
3230
+ proc.id
3231
+ )) }),
3232
+ /* @__PURE__ */ jsx(
3233
+ AddEntityDialog,
3234
+ {
3235
+ open,
3236
+ onClose: () => setOpen(false),
3237
+ title: "Add Procedure",
3238
+ recentlyUsedSlot: recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
3239
+ children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
3240
+ /* @__PURE__ */ jsx(
3241
+ Input,
3242
+ {
3243
+ ref: searchInputRef,
3244
+ value: query,
3245
+ onChange: (e) => handleQueryChange(e.target.value),
3246
+ placeholder: "Search for a procedure...",
3247
+ className: "border border-border rounded-md focus-visible:ring-0"
3248
+ }
3249
+ ),
3250
+ loading && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground py-1", children: "Searching\u2026" }),
3251
+ !loading && results.length > 0 && /* @__PURE__ */ jsx("div", { className: "border border-border rounded-md overflow-hidden", children: results.map((r) => {
3252
+ const isAdding = addingId === r.id;
3253
+ return /* @__PURE__ */ jsxs(
3254
+ "button",
3255
+ {
3256
+ type: "button",
3257
+ onClick: () => handleResultClick(r),
3258
+ className: cn(
3259
+ "w-full text-left px-3 py-2 text-sm transition-all duration-300 ease-out border-b border-border last:border-b-0 cursor-pointer flex items-center justify-between gap-2",
3260
+ isAdding ? "bg-green-50 border-green-200" : "hover:bg-gray-50"
3261
+ ),
3262
+ children: [
3263
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: r.name }),
3264
+ isAdding && /* @__PURE__ */ jsx(Check, { className: "h-4 w-4 shrink-0 text-green-600" })
3265
+ ]
3266
+ },
3267
+ r.id
3268
+ );
3269
+ }) })
3270
+ ] })
3271
+ }
3272
+ )
3273
+ ] });
3274
+ };
3275
+ var AddProcedureWidget = ({ fieldId }) => {
3276
+ const { value, setValue } = useField(fieldId);
3277
+ const handlers = useFieldHandlers(fieldId);
3278
+ return /* @__PURE__ */ jsx(
3279
+ AddProcedureField,
3280
+ {
3281
+ value: value ?? [],
3282
+ onChange: setValue,
3283
+ onSearch: handlers.onSearch,
3284
+ recentlyUsed: handlers.recentlyUsed
3285
+ }
3286
+ );
3287
+ };
3288
+ function getStatusBasedClass(status) {
3289
+ switch ((status || "").toLowerCase()) {
3290
+ case "high":
3291
+ return "bg-red-100 text-red-500";
3292
+ case "medium":
3293
+ return "bg-yellow-100 text-yellow-600";
3294
+ case "low":
3295
+ return "bg-green-100 text-green-600";
3296
+ default:
3297
+ return "bg-gray-200 text-gray-600";
3298
+ }
3299
+ }
3300
+ function DiagnosisCard({ item, defaultOpen = false }) {
3301
+ const [open, setOpen] = useState(defaultOpen);
3302
+ return /* @__PURE__ */ jsxs("div", { className: "border border-gray-200 rounded-lg bg-[#F2F2F2] mb-2 last:mb-0 overflow-hidden", children: [
3303
+ /* @__PURE__ */ jsxs(
3304
+ "button",
3305
+ {
3306
+ type: "button",
3307
+ onClick: () => setOpen((o) => !o),
3308
+ className: cn(
3309
+ "w-full text-left flex items-center gap-2 py-2 px-3 rounded-lg",
3310
+ "cursor-pointer hover:bg-gray-200/60 transition-colors"
3311
+ ),
3312
+ children: [
3313
+ /* @__PURE__ */ jsx(
3314
+ ChevronRight,
3315
+ {
3316
+ className: cn("h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform", open && "rotate-90")
3317
+ }
3318
+ ),
3319
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
3320
+ /* @__PURE__ */ jsx("div", { className: "text-xs text-gray-500 font-medium", children: item.category.charAt(0).toUpperCase() + item.category.slice(1) }),
3321
+ /* @__PURE__ */ jsx("div", { className: "text-sm text-black font-semibold mt-0.5 leading-tight", children: item.condition })
3322
+ ] })
3323
+ ]
3324
+ }
3325
+ ),
3326
+ open && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 px-3 pb-3 pt-0 pl-9", children: [
3327
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-between text-xs font-semibold text-gray-500", children: [
3328
+ /* @__PURE__ */ jsx("span", { children: "LIKELIHOOD" }),
3329
+ /* @__PURE__ */ jsx("span", { children: "SEVERITY" }),
3330
+ /* @__PURE__ */ jsx("span", { children: "TREATABILITY" })
3331
+ ] }),
3332
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-between gap-2", children: [
3333
+ /* @__PURE__ */ jsx("span", { className: cn("px-2.5 py-0.5 rounded-full text-xs font-bold shrink-0", getStatusBasedClass(item.likelihood)), children: item.likelihood }),
3334
+ /* @__PURE__ */ jsx("span", { className: cn("px-2.5 py-0.5 rounded-full text-xs font-bold shrink-0", getStatusBasedClass(item.severity)), children: item.severity }),
3335
+ /* @__PURE__ */ jsx("span", { className: cn("px-2.5 py-0.5 rounded-full text-xs font-bold shrink-0", getStatusBasedClass(item.treatability)), children: item.treatability })
3336
+ ] }),
3337
+ item.keyFeatures && item.keyFeatures.length > 0 && /* @__PURE__ */ jsxs("div", { className: "pt-1", children: [
3338
+ /* @__PURE__ */ jsx("div", { className: "text-xs font-semibold text-gray-500 mb-0.5 uppercase tracking-wider", children: "Key Features" }),
3339
+ /* @__PURE__ */ jsx("ul", { className: "list-disc pl-4 text-xs text-gray-700 space-y-0.5", children: item.keyFeatures.map((feature, i) => /* @__PURE__ */ jsx("li", { children: feature }, i)) })
3340
+ ] }),
3341
+ item.nextSteps && item.nextSteps.length > 0 && /* @__PURE__ */ jsxs("div", { className: "pt-1", children: [
3342
+ /* @__PURE__ */ jsx("div", { className: "text-xs font-semibold text-gray-500 mb-0.5 uppercase tracking-wider", children: "Next Steps" }),
3343
+ /* @__PURE__ */ jsx("ul", { className: "list-disc pl-4 text-xs text-gray-700 space-y-0.5", children: item.nextSteps.map((step, i) => /* @__PURE__ */ jsx("li", { children: step }, i)) })
3344
+ ] })
3345
+ ] })
3346
+ ] });
3347
+ }
3348
+ var DifferentialDiagnosis = ({
3349
+ differentialDiagnosis,
3350
+ className = "",
3351
+ height = "300px"
3352
+ }) => {
3353
+ const hasItems = Array.isArray(differentialDiagnosis) && differentialDiagnosis.length > 0;
3354
+ return /* @__PURE__ */ jsxs(
3355
+ "div",
3356
+ {
3357
+ className: cn(
3358
+ "rounded-md overflow-hidden flex flex-col border border-[#D0D0D0]",
3359
+ className
3360
+ ),
3361
+ children: [
3362
+ /* @__PURE__ */ jsx("div", { className: "rounded-t-md bg-[#FEE8EC] px-3 py-1.5 text-xs shrink-0 z-[1] text-slate-600 flex items-center font-semibold", children: /* @__PURE__ */ jsx("span", { children: "Differential Diagnosis" }) }),
3363
+ /* @__PURE__ */ jsxs(
3364
+ "div",
3365
+ {
3366
+ className: cn(
3367
+ "relative bg-white rounded-b-md border-t border-[#D0D0D0] overflow-y-auto p-3",
3368
+ "focus-visible:outline-none"
3369
+ ),
3370
+ style: { minHeight: height, maxHeight: height },
3371
+ children: [
3372
+ hasItems ? differentialDiagnosis.map((item, idx) => /* @__PURE__ */ jsx(DiagnosisCard, { item, defaultOpen: idx === 0 }, idx)) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "No differential diagnosis yet." }),
3373
+ /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-x-0 bottom-0 h-[30%] bg-gradient-to-t from-white via-white/80 to-transparent" })
3374
+ ]
3375
+ }
3376
+ )
3377
+ ]
3378
+ }
3379
+ );
3380
+ };
3381
+ var DifferentialDiagnosisWidget = ({ fieldId }) => {
3382
+ const { value } = useField(fieldId);
3383
+ const items = Array.isArray(value) ? value : [];
3384
+ return /* @__PURE__ */ jsx(DifferentialDiagnosis, { differentialDiagnosis: items });
3385
+ };
3386
+ var Spinner2 = React11.forwardRef(
3387
+ ({ className, size = "md", ...props }, ref) => {
3388
+ const sizeClasses = {
3389
+ sm: "h-4 w-4 border-2",
3390
+ md: "h-6 w-6 border-2",
3391
+ lg: "h-8 w-8 border-3"
3392
+ };
3393
+ return /* @__PURE__ */ jsx(
3394
+ "div",
3395
+ {
3396
+ ref,
3397
+ className: cn(
3398
+ "animate-spin rounded-full border-primary border-t-transparent",
3399
+ sizeClasses[size],
3400
+ className
3401
+ ),
3402
+ ...props,
3403
+ children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading..." })
3404
+ }
3405
+ );
3406
+ }
3407
+ );
3408
+ Spinner2.displayName = "Spinner";
3409
+ function buildItems(data) {
3410
+ const items = [];
3411
+ const hasBP = data.blood_pressure_systolic != null || data.blood_pressure_diastolic != null;
3412
+ if (hasBP) {
3413
+ const sys = data.blood_pressure_systolic ?? "\u2013";
3414
+ const dia = data.blood_pressure_diastolic ?? "\u2013";
3415
+ items.push({ label: "BP", value: `${sys}/${dia}` });
3416
+ }
3417
+ if (data.heart_rate != null)
3418
+ items.push({ label: "Heart Rate", value: `${data.heart_rate} bpm` });
3419
+ if (data.respiratory_rate != null)
3420
+ items.push({ label: "Resp. Rate", value: `${data.respiratory_rate}/min` });
3421
+ if (data.oxygen_saturation != null)
3422
+ items.push({ label: "SpO\u2082", value: `${data.oxygen_saturation}%` });
3423
+ if (data.temperature != null)
3424
+ items.push({ label: "Temp", value: `${data.temperature} \xB0F` });
3425
+ if (data.height != null)
3426
+ items.push({ label: "Height", value: `${data.height} cm` });
3427
+ if (data.weight != null)
3428
+ items.push({ label: "Weight", value: `${data.weight} kg` });
3429
+ if (data.bmi != null)
3430
+ items.push({ label: "BMI", value: `${data.bmi}` });
3431
+ if (data.blood_sugar != null)
3432
+ items.push({ label: "Blood Sugar", value: `${data.blood_sugar} mg/dL` });
3433
+ if (data.circumference_of_head_in_cms != null)
3434
+ items.push({ label: "Head Circ.", value: `${data.circumference_of_head_in_cms} cm` });
3435
+ if (data.circumference_of_waist_in_cms != null)
3436
+ items.push({ label: "Waist Circ.", value: `${data.circumference_of_waist_in_cms} cm` });
3437
+ return items;
3438
+ }
3439
+ function formatRecordedAt(iso) {
3440
+ if (!iso) return "";
3441
+ try {
3442
+ return new Date(iso).toLocaleString(void 0, {
3443
+ day: "2-digit",
3444
+ month: "short",
3445
+ year: "numeric",
3446
+ hour: "2-digit",
3447
+ minute: "2-digit"
3448
+ });
3449
+ } catch {
3450
+ return iso;
3451
+ }
3452
+ }
3453
+ function VitalChip({ label, value }) {
3454
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0 rounded-md min-w-fit px-1.5", children: [
3455
+ /* @__PURE__ */ jsx("span", { className: "text-[10px] font-sm text-gray-500 uppercase tracking-wide leading-none", children: label }),
3456
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-gray-900 leading-tight", children: value })
3457
+ ] });
3458
+ }
3459
+ var Vitals = ({
3460
+ data,
3461
+ loading = false,
3462
+ error = null,
3463
+ onRefresh,
3464
+ className
3465
+ }) => {
3466
+ const items = data ? buildItems(data) : [];
3467
+ const hasItems = items.length > 0;
3468
+ const recordedAt = data?.recorded_at ? formatRecordedAt(data.recorded_at) : null;
3469
+ const notes = data?.notes?.trim() || null;
3470
+ return /* @__PURE__ */ jsx(
3471
+ "div",
3472
+ {
3473
+ className: cn(
3474
+ "rounded-md overflow-hidden border border-[#D0D0D0] bg-white px-2 py-2",
3475
+ className
3476
+ ),
3477
+ children: loading && !hasItems ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 py-1", children: [
3478
+ /* @__PURE__ */ jsx(Spinner2, { size: "sm" }),
3479
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Loading vitals\u2026" })
3480
+ ] }) : error ? /* @__PURE__ */ jsx("p", { className: "text-xs text-red-500 py-1", children: error }) : hasItems ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
3481
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-3 gap-y-1", children: [
3482
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-x-2 gap-y-0.5", children: items.map((item) => /* @__PURE__ */ jsx(VitalChip, { ...item }, item.label)) }),
3483
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end gap-0.5 shrink-0", children: [
3484
+ recordedAt && /* @__PURE__ */ jsx("span", { className: "text-[10px] text-slate-500", children: recordedAt }),
3485
+ onRefresh && /* @__PURE__ */ jsxs(
3486
+ "button",
3487
+ {
3488
+ type: "button",
3489
+ onClick: onRefresh,
3490
+ disabled: loading,
3491
+ className: cn(
3492
+ "flex items-center gap-0.5 text-[10px] font-medium text-slate-600",
3493
+ "hover:text-slate-900 transition-colors disabled:opacity-50 cursor-pointer"
3494
+ ),
3495
+ "aria-label": "Refresh vitals",
3496
+ children: [
3497
+ /* @__PURE__ */ jsx(RefreshCw, { className: cn("h-2.5 w-2.5", loading && "animate-spin") }),
3498
+ /* @__PURE__ */ jsx("span", { children: "Refresh" })
3499
+ ]
3500
+ }
3501
+ )
3502
+ ] })
3503
+ ] }),
3504
+ notes && /* @__PURE__ */ jsx("p", { className: "text-xs text-gray-600 pt-1.5 mt-0.5", children: notes })
3505
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 py-1", children: [
3506
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "No vitals recorded." }),
3507
+ onRefresh && /* @__PURE__ */ jsxs(
3508
+ "button",
3509
+ {
3510
+ type: "button",
3511
+ onClick: onRefresh,
3512
+ disabled: loading,
3513
+ className: cn(
3514
+ "flex items-center gap-0.5 text-[10px] font-medium text-slate-600",
3515
+ "hover:text-slate-900 transition-colors disabled:opacity-50 shrink-0"
3516
+ ),
3517
+ "aria-label": "Refresh vitals",
3518
+ children: [
3519
+ /* @__PURE__ */ jsx(RefreshCw, { className: cn("h-2.5 w-2.5", loading && "animate-spin") }),
3520
+ /* @__PURE__ */ jsx("span", { children: "Refresh" })
3521
+ ]
3522
+ }
3523
+ )
3524
+ ] })
3525
+ }
3526
+ );
3527
+ };
3528
+ var VitalsWidget = ({ fieldId }) => {
3529
+ const { value, setValue, fieldDef } = useField(fieldId);
3530
+ const handlers = useFieldHandlers(fieldId);
3531
+ const [loading, setLoading] = useState(false);
3532
+ const [error, setError] = useState(null);
3533
+ console.log("[VitalsWidget] fieldId:", fieldId, "| onFetch present:", !!handlers.onFetch, "| value:", value);
3534
+ const fetchVitals = useCallback(async () => {
3535
+ if (!handlers.onFetch) return;
3536
+ setLoading(true);
3537
+ setError(null);
3538
+ try {
3539
+ const data = await handlers.onFetch();
3540
+ console.log("[VitalsWidget] fetched data:", data);
3541
+ setValue(data);
3542
+ } catch {
3543
+ setError("Failed to load vitals. Please try again.");
3544
+ } finally {
3545
+ setLoading(false);
3546
+ }
3547
+ }, [handlers, setValue]);
3548
+ useEffect(() => {
3549
+ fetchVitals();
3550
+ }, []);
3551
+ return /* @__PURE__ */ jsx(
3552
+ Vitals,
3553
+ {
3554
+ label: fieldDef?.label ?? "Vitals",
3555
+ data: value ?? null,
3556
+ loading,
3557
+ error,
3558
+ onRefresh: handlers.onFetch ? fetchVitals : void 0
3559
+ }
3560
+ );
3561
+ };
3562
+ function normalizeOptions(response) {
3563
+ if (Array.isArray(response)) {
3564
+ return response.map((o) => ({ label: String(o.label), value: String(o.value) }));
3565
+ }
3566
+ if (response?.specializations?.length) {
3567
+ return response.specializations.map((s) => ({ label: s, value: s }));
3568
+ }
3569
+ return [];
3570
+ }
3571
+ function normalizeValue(value) {
3572
+ if (!value || !Array.isArray(value)) return [];
3573
+ return value.map((item) => {
3574
+ if (item && typeof item === "object" && "specialization" in item) {
3575
+ const s = item.specialization;
3576
+ const u = item.is_urgent;
3577
+ return { specialization: String(s), is_urgent: Boolean(u) };
3578
+ }
3579
+ return { specialization: String(item), is_urgent: false };
3580
+ });
3581
+ }
3582
+ var ReferralWidget = ({ fieldId }) => {
3583
+ const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
3584
+ const handlers = useFieldHandlers(fieldId);
3585
+ const [options, setOptions] = useState([]);
3586
+ const [loading, setLoading] = useState(false);
3587
+ const { state } = useForm();
3588
+ const showError = !!error && (touched || state.submitAttempted);
3589
+ const selectedItems = normalizeValue(value);
3590
+ const availableOptions = options.filter(
3591
+ (opt) => !selectedItems.some((item) => item.specialization === opt.value)
3592
+ );
3593
+ const loadOptions = useCallback(async () => {
3594
+ if (handlers.onFetchOptions) {
3595
+ setLoading(true);
3596
+ try {
3597
+ const res = await handlers.onFetchOptions();
3598
+ setOptions(normalizeOptions(res));
3599
+ } finally {
3600
+ setLoading(false);
3601
+ }
3602
+ return;
3603
+ }
3604
+ const def = fieldDef;
3605
+ if (def?.options?.length) {
3606
+ setOptions(def.options.map((o) => ({ label: String(o.label), value: String(o.value) })));
3607
+ } else if (def?.dataSource) {
3608
+ setLoading(true);
3609
+ fetchOptions(def.dataSource.source, def.dataSource.params).then((opts) => setOptions(opts.map((o) => ({ label: String(o.label), value: String(o.value) })))).finally(() => setLoading(false));
3610
+ } else {
3611
+ setOptions([]);
3612
+ }
3613
+ }, [fieldDef, handlers]);
3614
+ useEffect(() => {
3615
+ if (!fieldDef) return;
3616
+ loadOptions();
3617
+ }, [fieldDef, loadOptions]);
3618
+ const handleAdd = useCallback(
3619
+ (specialization) => {
3620
+ const next = [...selectedItems, { specialization, is_urgent: false }];
3621
+ setValue(next);
3622
+ setTouched();
3623
+ },
3624
+ [selectedItems, setValue, setTouched]
3625
+ );
3626
+ const handleRemove = useCallback(
3627
+ (specialization) => {
3628
+ const next = selectedItems.filter((item) => item.specialization !== specialization);
3629
+ setValue(next);
3630
+ setTouched();
3631
+ },
3632
+ [selectedItems, setValue, setTouched]
3633
+ );
3634
+ const handleToggleUrgent = useCallback(
3635
+ (specialization) => {
3636
+ const next = selectedItems.map(
3637
+ (item) => item.specialization === specialization ? { ...item, is_urgent: !item.is_urgent } : item
3638
+ );
3639
+ setValue(next);
3640
+ setTouched();
3641
+ },
3642
+ [selectedItems, setValue, setTouched]
3643
+ );
3644
+ if (!fieldDef) return null;
3645
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
3646
+ /* @__PURE__ */ jsxs(Label, { htmlFor: fieldId, children: [
3647
+ "Referral to ",
3648
+ fieldDef.required && /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
3649
+ ] }),
3650
+ loading && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Loading..." }),
3651
+ !loading && /* @__PURE__ */ jsxs(Fragment, { children: [
3652
+ /* @__PURE__ */ jsxs(
3653
+ Select,
3654
+ {
3655
+ disabled,
3656
+ value: "",
3657
+ onValueChange: (val) => {
3658
+ if (val) {
3659
+ handleAdd(val);
3660
+ }
3661
+ },
3662
+ children: [
3663
+ /* @__PURE__ */ jsx(SelectTrigger, { id: fieldId, className: showError ? "border-red-500" : "", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Select specializations..." }) }),
3664
+ /* @__PURE__ */ jsxs(SelectContent, { children: [
3665
+ availableOptions.map((opt) => /* @__PURE__ */ jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value)),
3666
+ availableOptions.length === 0 && /* @__PURE__ */ jsx("div", { className: "py-2 px-2 text-sm text-muted-foreground", children: "All specializations selected" })
3667
+ ] })
3668
+ ]
3669
+ },
3670
+ `referral-${selectedItems.map((i) => i.specialization).join(",")}`
3671
+ ),
3672
+ selectedItems.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5 mt-1.5", children: selectedItems.map((item) => {
3673
+ const isUrgent = item.is_urgent;
3674
+ const chipClass = isUrgent ? "inline-flex items-center gap-0.5 px-2 py-0.5 bg-red-100 text-red-800 border border-red-300 rounded-full text-xs max-w-full cursor-pointer hover:bg-red-200 transition-colors" : "inline-flex items-center gap-0.5 px-2 py-0.5 bg-blue-100 text-blue-800 rounded-full text-xs max-w-full cursor-pointer hover:bg-blue-200 transition-colors";
3675
+ return /* @__PURE__ */ jsxs(
3676
+ "div",
3677
+ {
3678
+ className: chipClass,
3679
+ onClick: (e) => {
3680
+ if (e.target instanceof HTMLElement && e.target.closest("button")) return;
3681
+ handleToggleUrgent(item.specialization);
3682
+ },
3683
+ children: [
3684
+ isUrgent && /* @__PURE__ */ jsx("span", { className: "flex-shrink-0 bg-red-600 text-white text-[10px] font-bold px-1 py-0.5 rounded mr-1", children: "U" }),
3685
+ /* @__PURE__ */ jsx("span", { className: "truncate max-w-[120px]", children: item.specialization }),
3686
+ /* @__PURE__ */ jsx(
3687
+ "button",
3688
+ {
3689
+ type: "button",
3690
+ onClick: (e) => {
3691
+ e.stopPropagation();
3692
+ handleRemove(item.specialization);
3693
+ },
3694
+ className: "ml-0.5 text-blue-600 hover:text-blue-800 focus:outline-none flex-shrink-0 text-sm leading-none",
3695
+ "aria-label": `Remove ${item.specialization}`,
3696
+ children: "\xD7"
3697
+ }
3698
+ )
3699
+ ]
3700
+ },
3701
+ item.specialization
3702
+ );
3703
+ }) }),
3704
+ selectedItems.length === 0 && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: "No specializations selected" }),
3705
+ selectedItems.length > 0 && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1.5", children: "Click a chip to mark as urgent" })
3706
+ ] }),
3707
+ showError && /* @__PURE__ */ jsx("p", { className: "text-xs text-red-500", children: error })
3708
+ ] });
3709
+ };
3710
+ var Card = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
3711
+ "div",
3712
+ {
3713
+ ref,
3714
+ className: cn(
3715
+ "rounded-lg border bg-card text-card-foreground shadow-sm",
3716
+ className
3717
+ ),
3718
+ ...props
3719
+ }
3720
+ ));
3721
+ Card.displayName = "Card";
3722
+ var CardHeader = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
3723
+ "div",
3724
+ {
3725
+ ref,
3726
+ className: cn("flex flex-col space-y-1.5 p-6", className),
3727
+ ...props
3728
+ }
3729
+ ));
3730
+ CardHeader.displayName = "CardHeader";
3731
+ var CardTitle = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
3732
+ "h3",
3733
+ {
3734
+ ref,
3735
+ className: cn(
3736
+ "text-2xl font-semibold leading-none tracking-tight",
3737
+ className
3738
+ ),
3739
+ ...props
3740
+ }
3741
+ ));
3742
+ CardTitle.displayName = "CardTitle";
3743
+ var CardDescription = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
3744
+ "p",
3745
+ {
3746
+ ref,
3747
+ className: cn("text-sm text-muted-foreground", className),
3748
+ ...props
3749
+ }
3750
+ ));
3751
+ CardDescription.displayName = "CardDescription";
3752
+ var CardContent = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: cn("p-6 pt-0", className), ...props }));
3753
+ CardContent.displayName = "CardContent";
3754
+ var CardFooter = React11.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
3755
+ "div",
3756
+ {
3757
+ ref,
3758
+ className: cn("flex items-center p-6 pt-0", className),
3759
+ ...props
3760
+ }
3761
+ ));
3762
+ CardFooter.displayName = "CardFooter";
3763
+ var FOLLOWUP_TYPE_OPTIONS = [
3764
+ { value: "no followup", label: "No Follow-up" },
3765
+ { value: "one time", label: "One Time" }
3766
+ ];
3767
+ var UNIT_OPTIONS = [
3768
+ { value: "days", label: "Days" },
3769
+ { value: "weeks", label: "Weeks" },
3770
+ { value: "months", label: "Months" }
3771
+ ];
3772
+ function durationToDays(valueNum, unit) {
3773
+ const today = /* @__PURE__ */ new Date();
3774
+ today.setHours(0, 0, 0, 0);
3775
+ let target;
3776
+ if (unit === "days") target = addDays(today, valueNum);
3777
+ else if (unit === "weeks") target = addWeeks(today, valueNum);
3778
+ else target = addMonths(today, valueNum);
3779
+ return Math.max(0, differenceInCalendarDays(target, today));
3780
+ }
3781
+ function dateToDays(date) {
3782
+ const today = /* @__PURE__ */ new Date();
3783
+ today.setHours(0, 0, 0, 0);
3784
+ const d = new Date(date);
3785
+ d.setHours(0, 0, 0, 0);
3786
+ return Math.max(0, differenceInCalendarDays(d, today));
3787
+ }
3788
+ function daysToDate(days) {
3789
+ const today = /* @__PURE__ */ new Date();
3790
+ today.setHours(0, 0, 0, 0);
3791
+ return addDays(today, days);
3792
+ }
3793
+ function normalizeFollowup(value) {
3794
+ if (value === false || value === null || value === void 0) return false;
3795
+ if (typeof value !== "object") return false;
3796
+ const o = value;
3797
+ if (o.followupType !== "one time") return false;
3798
+ if (typeof o.value === "string" && o.unit === "days") {
3799
+ return { followupType: "one time", value: o.value, unit: "days" };
3800
+ }
3801
+ const today = /* @__PURE__ */ new Date();
3802
+ today.setHours(0, 0, 0, 0);
3803
+ if (o.mode === "date" && typeof o.date === "string") {
3804
+ const d = parseLocalDate(o.date);
3805
+ if (d) {
3806
+ const days2 = dateToDays(d);
3807
+ return { followupType: "one time", value: String(days2), unit: "days" };
3808
+ }
3809
+ }
3810
+ const val = o.value != null ? Number(String(o.value)) : 7;
3811
+ const u = o.unit === "weeks" || o.unit === "months" ? o.unit : "days";
3812
+ const days = durationToDays(Number.isNaN(val) ? 7 : val, u);
3813
+ return { followupType: "one time", value: String(days), unit: "days" };
3814
+ }
3815
+ function getDefaultDate() {
3816
+ const d = /* @__PURE__ */ new Date();
3817
+ d.setDate(d.getDate() + 7);
3818
+ return d;
3819
+ }
3820
+ function parseLocalDate(dateString) {
3821
+ if (!dateString) return null;
3822
+ try {
3823
+ return parseISO(dateString);
3824
+ } catch {
3825
+ const parts = dateString.split("-");
3826
+ if (parts.length === 3) {
3827
+ const y = parseInt(parts[0], 10);
3828
+ const m = parseInt(parts[1], 10) - 1;
3829
+ const d = parseInt(parts[2], 10);
3830
+ if (!Number.isNaN(y) && !Number.isNaN(m) && !Number.isNaN(d)) {
3831
+ return new Date(y, m, d);
3832
+ }
3833
+ }
3834
+ return null;
3835
+ }
3836
+ }
3837
+ var FollowupWidget = ({ fieldId }) => {
3838
+ const { fieldDef, value, setValue, setTouched, error, disabled, visible } = useField(fieldId);
3839
+ const followup = normalizeFollowup(value);
3840
+ const [calendarOpen, setCalendarOpen] = useState(false);
3841
+ const currentFollowupType = followup ? followup.followupType : "no followup";
3842
+ const hasFollowup = followup !== false;
3843
+ const [displayMode, setDisplayMode] = useState("duration");
3844
+ const [displayUnit, setDisplayUnit] = useState("days");
3845
+ const daysNum = hasFollowup ? parseInt(followup.value, 10) || 7 : 7;
3846
+ const currentDate = hasFollowup ? daysToDate(daysNum) : null;
3847
+ const followupMode = displayMode;
3848
+ const currentValue = hasFollowup && displayUnit === "days" ? followup.value : hasFollowup ? String(
3849
+ displayUnit === "weeks" ? Math.round(daysNum / 7) || 1 : Math.round(daysNum / 30) || 1
3850
+ ) : "7";
3851
+ const currentUnit = displayUnit;
3852
+ const handleFollowupTypeChange = useCallback(
3853
+ (newType) => {
3854
+ setTouched();
3855
+ if (newType === "no followup") {
3856
+ setValue(false);
3857
+ setCalendarOpen(false);
3858
+ return;
3859
+ }
3860
+ setValue({
3861
+ followupType: "one time",
3862
+ value: hasFollowup ? followup.value : "7",
3863
+ unit: "days"
3864
+ });
3865
+ },
3866
+ [followup, hasFollowup, setValue, setTouched]
3867
+ );
3868
+ const handleModeChange = useCallback((newMode) => {
3869
+ setDisplayMode(newMode);
3870
+ if (newMode === "date") setCalendarOpen(false);
3871
+ }, []);
3872
+ const handleValueChange = useCallback(
3873
+ (newValue) => {
3874
+ setTouched();
3875
+ const num = parseInt(newValue, 10);
3876
+ const min = displayUnit === "days" ? 0 : 1;
3877
+ const valid = (Number.isNaN(num) ? min : num) >= min || newValue === "";
3878
+ if (!valid && newValue !== "") {
3879
+ setValue({ followupType: "one time", value: String(displayUnit === "days" ? 0 : durationToDays(1, displayUnit)), unit: "days" });
3880
+ return;
3881
+ }
3882
+ const days = durationToDays(Number.isNaN(num) ? displayUnit === "days" ? 0 : 1 : num, displayUnit);
3883
+ setValue({ followupType: "one time", value: String(days), unit: "days" });
3884
+ },
3885
+ [displayUnit, setValue, setTouched]
3886
+ );
3887
+ const handleUnitChange = useCallback((newUnit) => {
3888
+ setDisplayUnit(newUnit);
3889
+ }, []);
3890
+ const handleDateSelect = useCallback(
3891
+ (selected) => {
3892
+ setTouched();
3893
+ setCalendarOpen(false);
3894
+ if (!selected) return;
3895
+ const days = dateToDays(selected);
3896
+ setValue({ followupType: "one time", value: String(days), unit: "days" });
3897
+ },
3898
+ [setValue, setTouched]
3899
+ );
3900
+ if (!visible || !fieldDef) return null;
3901
+ const minDate = /* @__PURE__ */ new Date();
3902
+ minDate.setHours(0, 0, 0, 0);
3903
+ const selectedDate = currentDate || getDefaultDate();
3904
+ return /* @__PURE__ */ jsx(Card, { className: cn(error && "border-destructive"), children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-1 p-2", children: [
3905
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between gap-2", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center flex-shrink-0 gap-2", children: [
3906
+ /* @__PURE__ */ jsx(Label, { className: "text-xs font-semibold text-muted-foreground", children: "Follow-up" }),
3907
+ /* @__PURE__ */ jsxs(
3908
+ Select,
3909
+ {
3910
+ value: currentFollowupType,
3911
+ onValueChange: (v) => handleFollowupTypeChange(v),
3912
+ disabled,
3913
+ children: [
3914
+ /* @__PURE__ */ jsx(SelectTrigger, { className: "w-[140px] border-none bg-muted/50 text-xs py-1 focus:outline-none focus:ring-0 focus:ring-offset-0", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
3915
+ /* @__PURE__ */ jsx(SelectContent, { children: FOLLOWUP_TYPE_OPTIONS.map((opt) => /* @__PURE__ */ jsx(SelectItem, { value: opt.value, className: "text-xs", children: opt.label }, opt.value)) })
3916
+ ]
3917
+ }
3918
+ )
3919
+ ] }) }),
3920
+ currentFollowupType !== "no followup" && /* @__PURE__ */ jsxs(Fragment, { children: [
3921
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
3922
+ /* @__PURE__ */ jsx(Label, { className: "text-xs font-medium text-muted-foreground", children: "Schedule by:" }),
3923
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
3924
+ /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2 cursor-pointer", children: [
3925
+ /* @__PURE__ */ jsx(
3926
+ "input",
3927
+ {
3928
+ type: "radio",
3929
+ name: `followup-mode-${fieldId}`,
3930
+ value: "duration",
3931
+ checked: followupMode === "duration",
3932
+ onChange: () => handleModeChange("duration"),
3933
+ className: "h-4 w-4 text-primary focus:ring-primary",
3934
+ disabled
3935
+ }
3936
+ ),
3937
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Duration" })
3938
+ ] }),
3939
+ /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2 cursor-pointer", children: [
3940
+ /* @__PURE__ */ jsx(
3941
+ "input",
3942
+ {
3943
+ type: "radio",
3944
+ name: `followup-mode-${fieldId}`,
3945
+ value: "date",
3946
+ checked: followupMode === "date",
3947
+ onChange: () => handleModeChange("date"),
3948
+ className: "h-4 w-4 text-primary focus:ring-primary",
3949
+ disabled
3950
+ }
3951
+ ),
3952
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Date" })
3953
+ ] })
3954
+ ] })
3955
+ ] }),
3956
+ followupMode === "duration" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
3957
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-muted-foreground", children: "In" }),
3958
+ /* @__PURE__ */ jsx(
3959
+ "input",
3960
+ {
3961
+ type: "number",
3962
+ min: currentUnit === "days" ? 0 : 1,
3963
+ value: currentValue,
3964
+ onChange: (e) => handleValueChange(e.target.value),
3965
+ disabled,
3966
+ className: "w-16 py-1.5 px-2 border border-input rounded-md text-center text-sm focus:outline-none focus:ring-2 focus:ring-ring",
3967
+ placeholder: "7"
3968
+ }
3969
+ ),
3970
+ /* @__PURE__ */ jsxs(
3971
+ Select,
3972
+ {
3973
+ value: currentUnit,
3974
+ onValueChange: (v) => handleUnitChange(v),
3975
+ disabled,
3976
+ children: [
3977
+ /* @__PURE__ */ jsx(SelectTrigger, { className: "w-[100px] h-8 text-xs", children: /* @__PURE__ */ jsx(SelectValue, { className: "text-xs" }) }),
3978
+ /* @__PURE__ */ jsx(SelectContent, { children: UNIT_OPTIONS.map((opt) => /* @__PURE__ */ jsx(SelectItem, { value: opt.value, className: "text-xs", children: opt.label }, opt.value)) })
3979
+ ]
3980
+ }
3981
+ )
3982
+ ] }),
3983
+ followupMode === "date" && /* @__PURE__ */ jsxs(Popover, { open: calendarOpen, onOpenChange: setCalendarOpen, children: [
3984
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
3985
+ Button,
3986
+ {
3987
+ type: "button",
3988
+ variant: "outline",
3989
+ className: "w-full justify-start text-left font-normal h-9",
3990
+ disabled,
3991
+ children: [
3992
+ /* @__PURE__ */ jsx(Calendar$1, { className: "mr-2 h-4 w-4 text-muted-foreground" }),
3993
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: hasFollowup && currentDate ? format(currentDate, "MMM d, yyyy") : "Select date" })
3994
+ ]
3995
+ }
3996
+ ) }),
3997
+ /* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", align: "start", children: /* @__PURE__ */ jsx(
3998
+ Calendar,
3999
+ {
4000
+ mode: "single",
4001
+ selected: selectedDate,
4002
+ onSelect: handleDateSelect,
4003
+ disabled: (date) => date < minDate,
4004
+ initialFocus: true
4005
+ }
4006
+ ) })
4007
+ ] }),
4008
+ /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
4009
+ "One-time appointment",
4010
+ " ",
4011
+ followupMode === "duration" ? `in ${currentValue} ${currentUnit}` : hasFollowup && currentDate ? `on ${format(currentDate, "MMM d, yyyy")}` : "date to be selected"
4012
+ ] })
4013
+ ] }),
4014
+ error && /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: error })
4015
+ ] }) });
4016
+ };
4017
+ function useSmartKeywords(text, onSearch, debounceDelay = 1e3) {
4018
+ console.log("[useSmartKeywords] render", {
4019
+ textLength: text?.length ?? 0,
4020
+ hasOnSearch: typeof onSearch === "function",
4021
+ debounceDelay
4022
+ });
4023
+ const [extractedNouns, setExtractedNouns] = useState([]);
4024
+ const [matchedConditions, setMatchedConditions] = useState([]);
4025
+ const [isProcessing, setIsProcessing] = useState(false);
4026
+ const [error, setError] = useState(null);
4027
+ const timerRef = useRef(null);
4028
+ const abortRef = useRef(0);
4029
+ const processText = useCallback(
4030
+ async (input, runId) => {
4031
+ if (!input || input.trim().length === 0) {
4032
+ console.log("[useSmartKeywords] skip empty input", {
4033
+ runId,
4034
+ inputLength: input?.length ?? 0
4035
+ });
4036
+ setExtractedNouns([]);
4037
+ setMatchedConditions([]);
4038
+ setIsProcessing(false);
4039
+ return;
4040
+ }
4041
+ console.log("[useSmartKeywords] processText start", {
4042
+ runId,
4043
+ inputLength: input.length
4044
+ });
4045
+ setIsProcessing(true);
4046
+ setError(null);
4047
+ try {
4048
+ const nouns = extractNouns(input);
4049
+ const uniqueNouns = Array.from(new Set(nouns));
4050
+ console.log("[useSmartKeywords] extracted nouns", {
4051
+ runId,
4052
+ nouns,
4053
+ uniqueNouns
4054
+ });
4055
+ if (runId !== abortRef.current) return;
4056
+ setExtractedNouns(uniqueNouns);
4057
+ if (uniqueNouns.length === 0) {
4058
+ console.log("[useSmartKeywords] no nouns, skipping search", { runId });
4059
+ setMatchedConditions([]);
4060
+ setIsProcessing(false);
4061
+ return;
4062
+ }
4063
+ const searchResults = await Promise.all(
4064
+ uniqueNouns.map(async (noun) => {
4065
+ const normalised = noun.replace(/\s+/g, " ").replace(/^[\s-]+/, "").trim();
4066
+ try {
4067
+ console.log("[useSmartKeywords] onSearch call", { runId, noun, normalised });
4068
+ const results = await onSearch(normalised);
4069
+ console.log("[useSmartKeywords] onSearch result", {
4070
+ runId,
4071
+ noun,
4072
+ normalised,
4073
+ count: Array.isArray(results) ? results.length : 0
4074
+ });
4075
+ const first = Array.isArray(results) && results.length > 0 ? [results[0]] : [];
4076
+ return { keyword: normalised, matches: first };
4077
+ } catch (err) {
4078
+ console.error("[useSmartKeywords] onSearch error", { runId, noun, err });
4079
+ return { keyword: normalised || noun, matches: [] };
4080
+ }
4081
+ })
4082
+ );
4083
+ if (runId !== abortRef.current) return;
4084
+ const allMatches = searchResults.flatMap(
4085
+ ({ keyword, matches }) => matches.map((record) => ({
4086
+ extractedKeyword: keyword,
4087
+ matchedCondition: {
4088
+ id: record.id,
4089
+ name: record.name,
4090
+ created_at: record.created_at,
4091
+ updated_at: record.updated_at
4092
+ }
4093
+ }))
4094
+ );
4095
+ console.log("[useSmartKeywords] allMatches computed", {
4096
+ runId,
4097
+ matchesCount: allMatches.length
4098
+ });
4099
+ setMatchedConditions(allMatches);
4100
+ } catch (err) {
4101
+ if (runId !== abortRef.current) return;
4102
+ console.error("[useSmartKeywords] processText error", { runId, err });
4103
+ setError(err instanceof Error ? err.message : "Keyword extraction failed");
4104
+ } finally {
4105
+ if (runId === abortRef.current) {
4106
+ console.log("[useSmartKeywords] processText end", { runId });
4107
+ setIsProcessing(false);
4108
+ }
4109
+ }
4110
+ },
4111
+ [onSearch]
4112
+ );
4113
+ useEffect(() => {
4114
+ if (timerRef.current) clearTimeout(timerRef.current);
4115
+ const runId = ++abortRef.current;
4116
+ console.log("[useSmartKeywords] schedule debounce", {
4117
+ runId,
4118
+ debounceDelay,
4119
+ textLength: text?.length ?? 0
4120
+ });
4121
+ timerRef.current = setTimeout(() => {
4122
+ console.log("[useSmartKeywords] debounce fired", { runId });
4123
+ processText(text, runId);
4124
+ }, debounceDelay);
4125
+ return () => {
4126
+ if (timerRef.current) clearTimeout(timerRef.current);
4127
+ };
4128
+ }, [text, debounceDelay, processText]);
4129
+ return { extractedNouns, matchedConditions, isProcessing, error };
4130
+ }
4131
+ function extractNouns(text) {
4132
+ const doc = nlp(text);
4133
+ const rawNouns = doc.nouns().out("array");
4134
+ const cleaned = rawNouns.map((n) => n.replace(/[^\w\s-]/g, "").trim().toLowerCase()).filter((n) => n.length > 2);
4135
+ console.log("[useSmartKeywords] extractNouns", {
4136
+ inputLength: text?.length ?? 0,
4137
+ rawNouns,
4138
+ cleaned
4139
+ });
4140
+ return cleaned;
4141
+ }
4142
+ var SmartTextareaWidget = ({ fieldId }) => {
4143
+ const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
4144
+ const { state } = useForm();
4145
+ const handler = useFieldHandlers(fieldId);
4146
+ const def = fieldDef;
4147
+ const structured = value;
4148
+ const textValue = structured?.text ?? "";
4149
+ const showError = !!error && (touched || state.submitAttempted);
4150
+ const onSearch = useCallback(
4151
+ (query) => handler.onSearch(query),
4152
+ [handler]
4153
+ );
4154
+ const { matchedConditions, isProcessing } = useSmartKeywords(
4155
+ textValue,
4156
+ onSearch,
4157
+ def?.debounceDelay ?? 1e3
4158
+ );
4159
+ const currentKeywords = structured?.extractedKeywords ?? [];
4160
+ const nextKeywords = useMemo(() => {
4161
+ if (matchedConditions.length === 0 && currentKeywords.length === 0) return currentKeywords;
4162
+ if (matchedConditions.length === currentKeywords.length && matchedConditions.every(
4163
+ (m, i) => m.matchedCondition.id === currentKeywords[i]?.matchedCondition.id && m.extractedKeyword === currentKeywords[i]?.extractedKeyword
4164
+ )) {
4165
+ return currentKeywords;
4166
+ }
4167
+ return matchedConditions;
4168
+ }, [matchedConditions, currentKeywords]);
4169
+ const writeValue = useCallback(
4170
+ (text, keywords) => {
4171
+ const next = { text, extractedKeywords: keywords };
4172
+ setValue(next);
4173
+ },
4174
+ [setValue]
4175
+ );
4176
+ React11__default.useEffect(() => {
4177
+ if (nextKeywords !== currentKeywords) {
4178
+ writeValue(textValue, nextKeywords);
4179
+ }
4180
+ }, [nextKeywords]);
4181
+ const handleTextChange = useCallback(
4182
+ (e) => {
4183
+ writeValue(e.target.value, currentKeywords);
4184
+ },
4185
+ [writeValue, currentKeywords]
4186
+ );
4187
+ if (!def) return null;
4188
+ const height = def.height;
4189
+ const theme = getThemeConfig("textarea", def.theme);
4190
+ const wrapperClass = theme?.wrapperClassName ?? "space-y-2";
4191
+ const labelClass = theme?.labelClassName;
4192
+ const inputClass = cn(theme?.inputClassName, showError && "border-red-500");
4193
+ const labelContent = /* @__PURE__ */ jsxs(Fragment, { children: [
4194
+ def.label,
4195
+ " ",
4196
+ def.required && /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" }),
4197
+ isProcessing && /* @__PURE__ */ jsx(Loader2, { className: "inline-block ml-1.5 h-3 w-3 animate-spin text-muted-foreground" })
4198
+ ] });
4199
+ return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
4200
+ theme ? /* @__PURE__ */ jsx(Label, { htmlFor: fieldId, className: labelClass, children: labelContent }) : /* @__PURE__ */ jsx(Label, { htmlFor: fieldId, children: labelContent }),
4201
+ /* @__PURE__ */ jsx(
4202
+ Textarea,
4203
+ {
4204
+ id: fieldId,
4205
+ value: textValue,
4206
+ onChange: handleTextChange,
4207
+ onBlur: setTouched,
4208
+ disabled,
4209
+ placeholder: def.placeholder,
4210
+ className: inputClass,
4211
+ ...height != null ? { height } : {}
4212
+ }
4213
+ ),
4214
+ showError && /* @__PURE__ */ jsx("p", { className: "text-xs text-red-500", children: error })
4215
+ ] });
4216
+ };
4217
+ var FieldRenderer = ({ fieldId }) => {
4218
+ const { fieldDef, visible } = useField(fieldId);
4219
+ if (!visible || !fieldDef) {
4220
+ return null;
4221
+ }
4222
+ switch (fieldDef.type) {
4223
+ case "text":
4224
+ case "number":
4225
+ return /* @__PURE__ */ jsx(TextWidget, { fieldId });
4226
+ case "textarea":
4227
+ case "richtext":
4228
+ return /* @__PURE__ */ jsx(TextWidget, { fieldId });
4229
+ case "date":
4230
+ return /* @__PURE__ */ jsx(DateWidget, { fieldId });
4231
+ case "datetime":
4232
+ return /* @__PURE__ */ jsx(DateTimeWidget, { fieldId });
4233
+ case "select":
4234
+ return /* @__PURE__ */ jsx(SelectWidget, { fieldId });
4235
+ case "radio":
4236
+ return /* @__PURE__ */ jsx(RadioWidget, { fieldId });
4237
+ case "checkbox":
4238
+ return /* @__PURE__ */ jsx(CheckboxWidget, { fieldId });
4239
+ case "multiselect":
4240
+ return /* @__PURE__ */ jsx(MultiSelectWidget, { fieldId });
4241
+ case "repeatable":
4242
+ return /* @__PURE__ */ jsx(RepeatableWidget, { fieldId });
4243
+ case "image_upload":
4244
+ return /* @__PURE__ */ jsx(ImageUploadWidget, { fieldId });
4245
+ case "signature":
4246
+ return /* @__PURE__ */ jsx(SignatureUploadWidget, { fieldId });
4247
+ case "editable_table":
4248
+ return /* @__PURE__ */ jsx(EditableTableWidget, { fieldId });
4249
+ case "medications":
4250
+ return /* @__PURE__ */ jsx(AddMedicationWidget, { fieldId });
4251
+ case "investigations":
4252
+ return /* @__PURE__ */ jsx(AddInvestigationWidget, { fieldId });
4253
+ case "procedures":
4254
+ return /* @__PURE__ */ jsx(AddProcedureWidget, { fieldId });
4255
+ case "differential_diagnosis":
4256
+ return /* @__PURE__ */ jsx(DifferentialDiagnosisWidget, { fieldId });
4257
+ case "vitals":
4258
+ return /* @__PURE__ */ jsx(VitalsWidget, { fieldId });
4259
+ case "referral":
4260
+ return /* @__PURE__ */ jsx(ReferralWidget, { fieldId });
4261
+ case "followup":
4262
+ return /* @__PURE__ */ jsx(FollowupWidget, { fieldId });
4263
+ case "smart_textarea":
4264
+ return /* @__PURE__ */ jsx(SmartTextareaWidget, { fieldId });
4265
+ case "static_text": {
4266
+ const def = fieldDef;
4267
+ const size = def.size ?? "regular";
4268
+ const labelClass = size === "large" ? "text-base" : "text-sm";
4269
+ const descClass = size === "large" ? "text-sm" : "text-xs";
4270
+ return /* @__PURE__ */ jsxs("div", { className: `${labelClass} text-muted-foreground`, children: [
4271
+ def.label,
4272
+ def.description && /* @__PURE__ */ jsx("p", { className: `mt-1 ${descClass} opacity-90`, children: def.description })
4273
+ ] });
4274
+ }
4275
+ default:
4276
+ return /* @__PURE__ */ jsxs("div", { className: "text-red-500", children: [
4277
+ "Unknown field type: ",
4278
+ fieldDef.type
4279
+ ] });
4280
+ }
4281
+ };
4282
+ var Section = ({ title, children }) => {
4283
+ const [expanded, setExpanded] = useState(true);
4284
+ const handleToggle = () => setExpanded((prev) => !prev);
4285
+ const contentClassName = cn(
4286
+ "overflow-hidden transition-[height] duration-200 ease-in-out",
4287
+ !expanded && "hidden"
4288
+ );
4289
+ return /* @__PURE__ */ jsxs("div", { className: "mb-6 border rounded-lg bg-white shadow-sm overflow-hidden", children: [
4290
+ /* @__PURE__ */ jsxs(
4291
+ "button",
4292
+ {
4293
+ type: "button",
4294
+ onClick: handleToggle,
4295
+ className: "w-full flex items-center justify-between gap-2 p-4 text-left border-b hover:bg-gray-50/80 transition-colors",
4296
+ children: [
4297
+ /* @__PURE__ */ jsx("h3", { className: "text-lg font-medium", children: title }),
4298
+ /* @__PURE__ */ jsx("span", { className: "flex-shrink-0 text-muted-foreground", "aria-hidden": true, children: expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-5 w-5" }) })
4299
+ ]
4300
+ }
4301
+ ),
4302
+ /* @__PURE__ */ jsx("div", { className: contentClassName, children: /* @__PURE__ */ jsx("div", { className: "p-4 pt-4 space-y-4 border-t-0", children }) })
4303
+ ] });
4304
+ };
4305
+ var ColumnLayout = ({
4306
+ columns,
4307
+ label,
4308
+ children
4309
+ }) => {
4310
+ const gridCols = Math.max(1, Math.min(columns, 12));
4311
+ const gridClass = `grid gap-4 w-full`;
4312
+ const style = {
4313
+ gridTemplateColumns: `repeat(${gridCols}, minmax(0, 1fr))`
4314
+ };
4315
+ return /* @__PURE__ */ jsxs("div", { className: "mb-6", children: [
4316
+ label != null && label !== "" && /* @__PURE__ */ jsx("div", { className: "mb-2 text-sm font-medium text-gray-700", children: label }),
4317
+ /* @__PURE__ */ jsx("div", { className: gridClass, style, children })
4318
+ ] });
4319
+ };
4320
+ var DynamicForm = () => {
4321
+ const store = useFormStore();
4322
+ const schema = store.getSchema();
4323
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
4324
+ /* @__PURE__ */ jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold", children: schema.title }) }),
4325
+ schema.layout.map((node) => {
4326
+ if (node.type === "section") {
4327
+ return /* @__PURE__ */ jsx(Section, { title: node.title, children: node.children.map(
4328
+ (child, index) => typeof child === "string" ? /* @__PURE__ */ jsx(FieldRenderer, { fieldId: child }, child) : child.type === "column_layout" ? /* @__PURE__ */ jsx(
4329
+ ColumnLayout,
4330
+ {
4331
+ columns: child.columns,
4332
+ label: child.label,
4333
+ children: child.children.map((fieldId) => /* @__PURE__ */ jsx(FieldRenderer, { fieldId }, fieldId))
4334
+ },
4335
+ child.id
4336
+ ) : /* @__PURE__ */ jsx(React11__default.Fragment, {}, child.id ?? index)
4337
+ ) }, node.id);
4338
+ }
4339
+ if (node.type === "column_layout") {
4340
+ return /* @__PURE__ */ jsx(
4341
+ ColumnLayout,
4342
+ {
4343
+ columns: node.columns,
4344
+ label: node.label,
4345
+ children: node.children.map((fieldId) => /* @__PURE__ */ jsx(FieldRenderer, { fieldId }, fieldId))
4346
+ },
4347
+ node.id
4348
+ );
4349
+ }
4350
+ return null;
4351
+ })
4352
+ ] });
4353
+ };
4354
+ var SUGGESTION_KEYS = /* @__PURE__ */ new Set(["medications", "investigations", "procedures"]);
4355
+ function shallowEqualKeys(a, b) {
4356
+ const keysA = Object.keys(a);
4357
+ const keysB = Object.keys(b);
4358
+ if (keysA.length !== keysB.length) return false;
4359
+ for (const k of keysA) {
4360
+ if (!keysB.includes(k) || a[k] !== b[k]) return false;
4361
+ }
4362
+ return true;
4363
+ }
4364
+ function normalizeAIMedications(arr) {
4365
+ let parsed = arr;
4366
+ if (typeof arr === "string") {
4367
+ try {
4368
+ parsed = JSON.parse(arr);
4369
+ } catch {
4370
+ return [];
4371
+ }
4372
+ }
4373
+ if (!Array.isArray(parsed)) return [];
4374
+ return parsed.filter((item) => item != null && typeof item === "object" && "id" in item && "brand_name" in item);
4375
+ }
4376
+ function normalizeDifferentialDiagnosis(val) {
4377
+ let parsed = val;
4378
+ if (typeof val === "string") {
4379
+ try {
4380
+ parsed = JSON.parse(val);
4381
+ } catch {
4382
+ return [];
4383
+ }
4384
+ }
4385
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
4386
+ const result = [];
4387
+ for (const [category, group] of Object.entries(parsed)) {
4388
+ if (!group || typeof group !== "object") continue;
4389
+ const conditions = Array.isArray(group.conditions) ? group.conditions : [];
4390
+ for (const cond of conditions) {
4391
+ if (!cond || typeof cond !== "object") continue;
4392
+ const {
4393
+ condition,
4394
+ likelihood,
4395
+ severity,
4396
+ treatability,
4397
+ keyFeatures,
4398
+ nextSteps
4399
+ } = cond;
4400
+ if (!condition || !likelihood || !severity || !treatability) continue;
4401
+ result.push({
4402
+ category,
4403
+ condition,
4404
+ likelihood,
4405
+ severity,
4406
+ treatability,
4407
+ keyFeatures: Array.isArray(keyFeatures) ? keyFeatures : void 0,
4408
+ nextSteps: Array.isArray(nextSteps) ? nextSteps : void 0
4409
+ });
4410
+ }
4411
+ }
4412
+ return result;
4413
+ }
4414
+ if (!Array.isArray(parsed)) return [];
4415
+ return parsed.filter(
4416
+ (item) => item != null && typeof item === "object" && "category" in item && "condition" in item && "likelihood" in item && "severity" in item && "treatability" in item
4417
+ );
4418
+ }
4419
+ var SmartForm = ({
4420
+ aiAnalysisResult
4421
+ }) => {
4422
+ const store = useFormStore();
4423
+ const schema = store.getSchema();
4424
+ const prevAiResultRef = useRef(void 0);
4425
+ const aiSuggestions = useMemo(() => {
4426
+ if (aiAnalysisResult == null) return { medications: [] };
4427
+ const medications = normalizeAIMedications(aiAnalysisResult.medications);
4428
+ return { medications };
4429
+ }, [aiAnalysisResult]);
4430
+ useEffect(() => {
4431
+ if (aiAnalysisResult == null || Object.keys(aiAnalysisResult).length === 0) return;
4432
+ const prev = prevAiResultRef.current;
4433
+ if (prev != null && prev === aiAnalysisResult && shallowEqualKeys(prev, aiAnalysisResult)) return;
4434
+ prevAiResultRef.current = { ...aiAnalysisResult };
4435
+ const DD_KEYS = /* @__PURE__ */ new Set(["differentialDiagnosis", "differentialdiagnosis"]);
4436
+ const toApply = {};
4437
+ for (const [key, val] of Object.entries(aiAnalysisResult)) {
4438
+ if (!SUGGESTION_KEYS.has(key) && !DD_KEYS.has(key)) toApply[key] = val;
4439
+ }
4440
+ const rawDd = aiAnalysisResult.differentialDiagnosis ?? aiAnalysisResult.differentialdiagnosis;
4441
+ if (rawDd != null) {
4442
+ toApply.differentialdiagnosis = normalizeDifferentialDiagnosis(rawDd);
4443
+ }
4444
+ if (Object.keys(toApply).length > 0) store.setValues(toApply, { touch: false });
4445
+ }, [store, aiAnalysisResult]);
4446
+ const fieldIds = [];
4447
+ function collect(child) {
4448
+ if (typeof child === "string") {
4449
+ fieldIds.push(child);
4450
+ } else if (child.type === "column_layout") {
4451
+ child.children.forEach((id) => fieldIds.push(id));
4452
+ }
4453
+ }
4454
+ schema.layout.forEach((node) => {
4455
+ if (node.type === "section") {
4456
+ node.children.forEach(collect);
4457
+ } else if (node.type === "column_layout") {
4458
+ node.children.forEach((id) => fieldIds.push(id));
4459
+ }
4460
+ });
4461
+ return /* @__PURE__ */ jsx(AISuggestionsProvider, { value: aiSuggestions, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-4 gap-2 w-full items-start", children: [
4462
+ /* @__PURE__ */ jsx("div", { className: "col-span-1 flex flex-col gap-2", children: fieldIds.map((fieldId) => {
4463
+ const fieldDef = store.getFieldDef(fieldId);
4464
+ if (!fieldDef) return null;
4465
+ const position = fieldDef.position ?? "center";
4466
+ if (position !== "left") return null;
4467
+ return /* @__PURE__ */ jsx(FieldRenderer, { fieldId }, fieldId);
4468
+ }) }),
4469
+ /* @__PURE__ */ jsx("div", { className: "col-span-2 grid grid-cols-2 gap-x-2 space-y-2", children: fieldIds.map((fieldId) => {
4470
+ const fieldDef = store.getFieldDef(fieldId);
4471
+ if (!fieldDef) return null;
4472
+ const position = fieldDef.position ?? "center";
4473
+ if (position !== "center") return null;
4474
+ const colSpanRaw = fieldDef.colSpan ?? 1;
4475
+ const colSpan = colSpanRaw === 2 ? 2 : 1;
4476
+ return /* @__PURE__ */ jsx("div", { className: colSpan === 2 ? "col-span-2" : "col-span-1", children: /* @__PURE__ */ jsx(FieldRenderer, { fieldId }) }, fieldId);
4477
+ }) }),
4478
+ /* @__PURE__ */ jsx("div", { className: "col-span-1 flex flex-col gap-2", children: fieldIds.map((fieldId) => {
4479
+ const fieldDef = store.getFieldDef(fieldId);
4480
+ if (!fieldDef) return null;
4481
+ const position = fieldDef.position ?? "center";
4482
+ if (position !== "right") return null;
4483
+ return /* @__PURE__ */ jsx(FieldRenderer, { fieldId }, fieldId);
4484
+ }) })
4485
+ ] }) });
2407
4486
  };
2408
4487
  var ReadOnlyText = ({ fieldDef, value }) => {
2409
4488
  if (!fieldDef) return null;
@@ -2931,6 +5010,6 @@ function createUploadHandler(options) {
2931
5010
  };
2932
5011
  }
2933
5012
 
2934
- export { DynamicForm, EMAIL_REGEX, FieldRenderer, FormControls, FormProvider, FormStore, ImageUploadWidget, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlySignature, ReadOnlyTable, SignatureUploadWidget, createUploadHandler, evaluateRules, useField, useForm, useFormStore, validateField, validateForm };
5013
+ export { AddInvestigationField, AddMedicationField, DifferentialDiagnosis, DynamicForm, EMAIL_REGEX, FieldRenderer, FormControls, FormProvider, FormStore, ImageUploadWidget, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlySignature, ReadOnlyTable, SignatureUploadWidget, SmartForm, SmartTextareaWidget, createUploadHandler, evaluateRules, useField, useFieldHandlers, useForm, useFormStore, useSmartKeywords, validateField, validateForm };
2935
5014
  //# sourceMappingURL=index.mjs.map
2936
5015
  //# sourceMappingURL=index.mjs.map