formanitor 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +220 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -3
- package/dist/index.d.ts +59 -3
- package/dist/index.mjs +220 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -338,7 +338,7 @@ var FormStore = class {
|
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
340
|
this.config.onDraftChange?.(payload);
|
|
341
|
-
},
|
|
341
|
+
}, 5e3);
|
|
342
342
|
}
|
|
343
343
|
async save() {
|
|
344
344
|
const payload = {
|
|
@@ -634,12 +634,27 @@ var FormStore = class {
|
|
|
634
634
|
}
|
|
635
635
|
};
|
|
636
636
|
var FormContext = createContext(null);
|
|
637
|
+
var emptyFrequentItems = {
|
|
638
|
+
medications: [],
|
|
639
|
+
investigations: [],
|
|
640
|
+
procedures: []
|
|
641
|
+
};
|
|
642
|
+
var FrequentItemsContext = createContext(emptyFrequentItems);
|
|
637
643
|
var FieldHandlersContext = createContext({});
|
|
638
644
|
function useFieldHandlers(fieldId) {
|
|
639
645
|
const map = useContext(FieldHandlersContext);
|
|
640
646
|
return map[fieldId] ?? { onSearch: async () => [], recentlyUsed: [] };
|
|
641
647
|
}
|
|
642
|
-
|
|
648
|
+
function useFrequentItems() {
|
|
649
|
+
return useContext(FrequentItemsContext);
|
|
650
|
+
}
|
|
651
|
+
var FormProvider = ({
|
|
652
|
+
schema,
|
|
653
|
+
config,
|
|
654
|
+
fieldHandlers,
|
|
655
|
+
frequentItems,
|
|
656
|
+
children
|
|
657
|
+
}) => {
|
|
643
658
|
const storeRef = useRef(null);
|
|
644
659
|
if (!storeRef.current) {
|
|
645
660
|
storeRef.current = new FormStore(schema, config);
|
|
@@ -652,7 +667,8 @@ var FormProvider = ({ schema, config, fieldHandlers, children }) => {
|
|
|
652
667
|
useEffect(() => {
|
|
653
668
|
storeRef.current?.load();
|
|
654
669
|
}, []);
|
|
655
|
-
|
|
670
|
+
const frequentItemsValue = frequentItems ?? emptyFrequentItems;
|
|
671
|
+
return /* @__PURE__ */ jsx(FormContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsx(FieldHandlersContext.Provider, { value: fieldHandlers ?? {}, children: /* @__PURE__ */ jsx(FrequentItemsContext.Provider, { value: frequentItemsValue, children }) }) });
|
|
656
672
|
};
|
|
657
673
|
function useFormStore() {
|
|
658
674
|
const context = useContext(FormContext);
|
|
@@ -2470,6 +2486,7 @@ var AddEntityDialog = ({
|
|
|
2470
2486
|
onClose,
|
|
2471
2487
|
title,
|
|
2472
2488
|
recentlyUsedSlot,
|
|
2489
|
+
chipSectionLabel = "Recently Used",
|
|
2473
2490
|
children,
|
|
2474
2491
|
actionSlot
|
|
2475
2492
|
}) => {
|
|
@@ -2477,7 +2494,7 @@ var AddEntityDialog = ({
|
|
|
2477
2494
|
/* @__PURE__ */ jsx(DialogHeader, { className: "px-6 pt-6 pb-4 shrink-0", children: /* @__PURE__ */ jsx(DialogTitle, { className: "text-lg font-semibold", children: title }) }),
|
|
2478
2495
|
/* @__PURE__ */ jsxs("div", { className: "px-6 flex flex-col gap-4 overflow-y-auto flex-1 min-h-0 pb-4", children: [
|
|
2479
2496
|
recentlyUsedSlot && /* @__PURE__ */ jsxs("div", { children: [
|
|
2480
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mb-2", children:
|
|
2497
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mb-2", children: chipSectionLabel }),
|
|
2481
2498
|
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: recentlyUsedSlot })
|
|
2482
2499
|
] }),
|
|
2483
2500
|
children
|
|
@@ -2502,9 +2519,9 @@ function mapToMedication(result) {
|
|
|
2502
2519
|
};
|
|
2503
2520
|
}
|
|
2504
2521
|
function mapAIMedicationToMedication(ai) {
|
|
2505
|
-
const id =
|
|
2522
|
+
const id = ai.id != null ? String(ai.id) : "";
|
|
2506
2523
|
return {
|
|
2507
|
-
id
|
|
2524
|
+
id,
|
|
2508
2525
|
brand_name: ai.brand_name ?? "",
|
|
2509
2526
|
generic_name: ai.generic_name ?? "",
|
|
2510
2527
|
frequency: "custom",
|
|
@@ -2520,7 +2537,7 @@ function mapAIMedicationToMedication(ai) {
|
|
|
2520
2537
|
}
|
|
2521
2538
|
function createCustomMedication(name, customId) {
|
|
2522
2539
|
return {
|
|
2523
|
-
id: customId,
|
|
2540
|
+
id: String(customId),
|
|
2524
2541
|
brand_name: name.trim(),
|
|
2525
2542
|
generic_name: "",
|
|
2526
2543
|
frequency: "custom",
|
|
@@ -2534,6 +2551,39 @@ function createCustomMedication(name, customId) {
|
|
|
2534
2551
|
notes: ""
|
|
2535
2552
|
};
|
|
2536
2553
|
}
|
|
2554
|
+
function parseDuration(duration) {
|
|
2555
|
+
if (!duration || !duration.trim()) return { value: "3", unit: "days" };
|
|
2556
|
+
const lower = duration.trim().toLowerCase();
|
|
2557
|
+
const match = lower.match(/^(\d+)\s*(day|days|week|weeks|month|months)?$/);
|
|
2558
|
+
if (!match) return { value: "3", unit: "days" };
|
|
2559
|
+
const value = match[1] ?? "3";
|
|
2560
|
+
const unitWord = match[2] ?? "days";
|
|
2561
|
+
const unit = unitWord.startsWith("month") ? "months" : unitWord.startsWith("week") ? "weeks" : "days";
|
|
2562
|
+
return { value, unit };
|
|
2563
|
+
}
|
|
2564
|
+
function mapFrequentItemToMedication(item) {
|
|
2565
|
+
const parsed = parseDuration(item.duration);
|
|
2566
|
+
const duration_value = item.duration_value ?? parsed.value;
|
|
2567
|
+
const duration_unit = item.duration_unit ?? parsed.unit;
|
|
2568
|
+
const before_after = item.before_after === "BEFORE FOOD" ? "BEFORE FOOD" : "AFTER FOOD";
|
|
2569
|
+
const routeNote = item.route ? `Route: ${item.route}` : "";
|
|
2570
|
+
const baseNotes = item.notes?.trim() || "";
|
|
2571
|
+
const combinedNotes = [baseNotes, routeNote.trim()].filter((part) => part.length > 0).join(" \u2014 ");
|
|
2572
|
+
return {
|
|
2573
|
+
id: item.id,
|
|
2574
|
+
brand_name: item.brand_name ?? item.name,
|
|
2575
|
+
generic_name: item.short_name ?? "",
|
|
2576
|
+
frequency: item.frequency ?? "custom",
|
|
2577
|
+
is_custom: false,
|
|
2578
|
+
duration_value,
|
|
2579
|
+
duration_unit,
|
|
2580
|
+
before_after,
|
|
2581
|
+
morning: item.morning ?? "0",
|
|
2582
|
+
afternoon: item.afternoon ?? "0",
|
|
2583
|
+
night: item.night ?? "0",
|
|
2584
|
+
notes: combinedNotes
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2537
2587
|
function Spinner({
|
|
2538
2588
|
value,
|
|
2539
2589
|
onChange
|
|
@@ -2581,11 +2631,14 @@ function MedicationCard({
|
|
|
2581
2631
|
onChange: (e) => set("frequency", e.target.value),
|
|
2582
2632
|
children: [
|
|
2583
2633
|
/* @__PURE__ */ jsx("option", { value: "custom", children: "select frequency" }),
|
|
2584
|
-
/* @__PURE__ */ jsx("option", { value: "
|
|
2585
|
-
/* @__PURE__ */ jsx("option", { value: "
|
|
2586
|
-
/* @__PURE__ */ jsx("option", { value: "
|
|
2587
|
-
/* @__PURE__ */ jsx("option", { value: "
|
|
2588
|
-
/* @__PURE__ */ jsx("option", { value: "
|
|
2634
|
+
/* @__PURE__ */ jsx("option", { value: "qid", children: "4 times a day (QID)" }),
|
|
2635
|
+
/* @__PURE__ */ jsx("option", { value: "alternate_day", children: "Alternate day" }),
|
|
2636
|
+
/* @__PURE__ */ jsx("option", { value: "once_weekly", children: "Once weekly" }),
|
|
2637
|
+
/* @__PURE__ */ jsx("option", { value: "once_monthly", children: "Once monthly" }),
|
|
2638
|
+
/* @__PURE__ */ jsx("option", { value: "as_needed", children: "As needed" }),
|
|
2639
|
+
/* @__PURE__ */ jsx("option", { value: "fort_night", children: "Fort night" }),
|
|
2640
|
+
/* @__PURE__ */ jsx("option", { value: "at_bed_time", children: "At Bed time" }),
|
|
2641
|
+
/* @__PURE__ */ jsx("option", { value: "sos", children: "SOS only" })
|
|
2589
2642
|
]
|
|
2590
2643
|
}
|
|
2591
2644
|
),
|
|
@@ -2724,6 +2777,7 @@ var AddMedicationField = ({
|
|
|
2724
2777
|
onChange,
|
|
2725
2778
|
onSearch,
|
|
2726
2779
|
recentlyUsed = [],
|
|
2780
|
+
frequentItems = [],
|
|
2727
2781
|
suggestedMedications = []
|
|
2728
2782
|
}) => {
|
|
2729
2783
|
const [open, setOpen] = useState(false);
|
|
@@ -2769,6 +2823,13 @@ var AddMedicationField = ({
|
|
|
2769
2823
|
onChange([...safeValue, mapToMedication(result)]);
|
|
2770
2824
|
}
|
|
2771
2825
|
}
|
|
2826
|
+
function handleFrequentItemToggle(item) {
|
|
2827
|
+
if (addedIds.has(String(item.id))) {
|
|
2828
|
+
onChange(safeValue.filter((m) => String(m.id) !== String(item.id)));
|
|
2829
|
+
} else {
|
|
2830
|
+
onChange([...safeValue, mapFrequentItemToMedication(item)]);
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2772
2833
|
function handleResultClick(result) {
|
|
2773
2834
|
if (addedIds.has(String(result.id))) return;
|
|
2774
2835
|
setAddingResultId(result.id);
|
|
@@ -2819,6 +2880,26 @@ var AddMedicationField = ({
|
|
|
2819
2880
|
r.id
|
|
2820
2881
|
);
|
|
2821
2882
|
});
|
|
2883
|
+
const limitedFrequentItems = frequentItems.slice(0, 25);
|
|
2884
|
+
const frequentItemChips = limitedFrequentItems.length > 0 ? limitedFrequentItems.map((item) => {
|
|
2885
|
+
const isAdded = addedIds.has(String(item.id));
|
|
2886
|
+
return /* @__PURE__ */ jsxs(
|
|
2887
|
+
"button",
|
|
2888
|
+
{
|
|
2889
|
+
type: "button",
|
|
2890
|
+
onClick: () => handleFrequentItemToggle(item),
|
|
2891
|
+
className: cn(
|
|
2892
|
+
"rounded-full border text-[11px] px-2 py-0.5 transition-colors cursor-pointer",
|
|
2893
|
+
isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
|
|
2894
|
+
),
|
|
2895
|
+
children: [
|
|
2896
|
+
isAdded && /* @__PURE__ */ jsx("span", { className: "mr-1", children: "\u2713" }),
|
|
2897
|
+
item.brand_name ?? item.name
|
|
2898
|
+
]
|
|
2899
|
+
},
|
|
2900
|
+
item.id
|
|
2901
|
+
);
|
|
2902
|
+
}) : [];
|
|
2822
2903
|
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
2904
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2824
2905
|
/* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: label }),
|
|
@@ -2832,22 +2913,6 @@ var AddMedicationField = ({
|
|
|
2832
2913
|
}
|
|
2833
2914
|
)
|
|
2834
2915
|
] }),
|
|
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
2916
|
/* @__PURE__ */ jsx("div", { className: "space-y-2", children: safeValue.map((med, i) => /* @__PURE__ */ jsx(
|
|
2852
2917
|
MedicationCard,
|
|
2853
2918
|
{
|
|
@@ -2863,7 +2928,8 @@ var AddMedicationField = ({
|
|
|
2863
2928
|
open,
|
|
2864
2929
|
onClose: () => setOpen(false),
|
|
2865
2930
|
title: "Add Medication",
|
|
2866
|
-
recentlyUsedSlot: recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
|
|
2931
|
+
recentlyUsedSlot: frequentItemChips.length > 0 ? frequentItemChips : recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
|
|
2932
|
+
chipSectionLabel: frequentItemChips.length > 0 ? "Frequently used" : void 0,
|
|
2867
2933
|
actionSlot: /* @__PURE__ */ jsx(
|
|
2868
2934
|
"button",
|
|
2869
2935
|
{
|
|
@@ -2888,6 +2954,22 @@ var AddMedicationField = ({
|
|
|
2888
2954
|
className: "border border-border rounded-md focus-visible:ring-0"
|
|
2889
2955
|
}
|
|
2890
2956
|
),
|
|
2957
|
+
suggestedMedications.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1.5 items-center", children: [
|
|
2958
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground mr-1", children: "Suggestions:" }),
|
|
2959
|
+
suggestedMedications.filter((s) => !addedIds.has(String(s.id))).slice(0, 25).map((s) => /* @__PURE__ */ jsxs(
|
|
2960
|
+
"button",
|
|
2961
|
+
{
|
|
2962
|
+
type: "button",
|
|
2963
|
+
onClick: () => handleAddSuggestion(s),
|
|
2964
|
+
className: "inline-flex items-center gap-1 rounded-full border border-dashed border-purple-300 bg-purple-50/80 text-purple-800 text-[11px] px-2 py-0.5 hover:bg-purple-100 transition-colors cursor-pointer",
|
|
2965
|
+
children: [
|
|
2966
|
+
/* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" }),
|
|
2967
|
+
s.brand_name || s.generic_name || String(s.id)
|
|
2968
|
+
]
|
|
2969
|
+
},
|
|
2970
|
+
String(s.id)
|
|
2971
|
+
))
|
|
2972
|
+
] }),
|
|
2891
2973
|
loading && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground text-center py-2", children: "Searching\u2026" }),
|
|
2892
2974
|
!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
2975
|
SearchResultCard,
|
|
@@ -2907,6 +2989,7 @@ var AddMedicationWidget = ({ fieldId }) => {
|
|
|
2907
2989
|
const { value, setValue } = useField(fieldId);
|
|
2908
2990
|
const handlers = useFieldHandlers(fieldId);
|
|
2909
2991
|
const { medications: suggestedMedications } = useAISuggestions();
|
|
2992
|
+
const { medications: frequentMedications } = useFrequentItems();
|
|
2910
2993
|
const safeValue = Array.isArray(value) ? value : [];
|
|
2911
2994
|
return /* @__PURE__ */ jsx(
|
|
2912
2995
|
AddMedicationField,
|
|
@@ -2915,6 +2998,7 @@ var AddMedicationWidget = ({ fieldId }) => {
|
|
|
2915
2998
|
onChange: setValue,
|
|
2916
2999
|
onSearch: handlers.onSearch,
|
|
2917
3000
|
recentlyUsed: handlers.recentlyUsed,
|
|
3001
|
+
frequentItems: frequentMedications,
|
|
2918
3002
|
suggestedMedications
|
|
2919
3003
|
}
|
|
2920
3004
|
);
|
|
@@ -2933,13 +3017,15 @@ var AddInvestigationField = ({
|
|
|
2933
3017
|
value,
|
|
2934
3018
|
onChange,
|
|
2935
3019
|
onSearch,
|
|
2936
|
-
recentlyUsed = []
|
|
3020
|
+
recentlyUsed = [],
|
|
3021
|
+
frequentItems = []
|
|
2937
3022
|
}) => {
|
|
2938
3023
|
const [open, setOpen] = useState(false);
|
|
2939
3024
|
const [query, setQuery] = useState("");
|
|
2940
3025
|
const [results, setResults] = useState([]);
|
|
2941
3026
|
const [loading, setLoading] = useState(false);
|
|
2942
3027
|
const [addingId, setAddingId] = useState(null);
|
|
3028
|
+
const [addingFrequentId, setAddingFrequentId] = useState(null);
|
|
2943
3029
|
const debounceRef = useRef(null);
|
|
2944
3030
|
const valueRef = useRef([]);
|
|
2945
3031
|
const searchInputRef = useRef(null);
|
|
@@ -2950,6 +3036,7 @@ var AddInvestigationField = ({
|
|
|
2950
3036
|
setQuery("");
|
|
2951
3037
|
setResults([]);
|
|
2952
3038
|
setAddingId(null);
|
|
3039
|
+
setAddingFrequentId(null);
|
|
2953
3040
|
}
|
|
2954
3041
|
}, [open]);
|
|
2955
3042
|
function handleQueryChange(q) {
|
|
@@ -2995,6 +3082,26 @@ var AddInvestigationField = ({
|
|
|
2995
3082
|
addInvestigation(result);
|
|
2996
3083
|
}
|
|
2997
3084
|
}
|
|
3085
|
+
async function handleFrequentItemToggle(item) {
|
|
3086
|
+
const id = String(item.id);
|
|
3087
|
+
const addedById = addedIds.has(id);
|
|
3088
|
+
const addedByName = value.some((inv) => inv.name === item.name);
|
|
3089
|
+
if (addedById || addedByName) {
|
|
3090
|
+
if (addedById) removeInvestigation(id);
|
|
3091
|
+
else onChange(value.filter((inv) => inv.name !== item.name));
|
|
3092
|
+
return;
|
|
3093
|
+
}
|
|
3094
|
+
setAddingFrequentId(id);
|
|
3095
|
+
try {
|
|
3096
|
+
const searchResults = await onSearch(item.name);
|
|
3097
|
+
const first = searchResults?.[0];
|
|
3098
|
+
if (first && !valueRef.current.some((inv) => inv.id === first.id)) {
|
|
3099
|
+
onChange([...valueRef.current, mapToInvestigation(first)]);
|
|
3100
|
+
}
|
|
3101
|
+
} finally {
|
|
3102
|
+
setAddingFrequentId(null);
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
2998
3105
|
const recentlyUsedChips = recentlyUsed.map((r) => {
|
|
2999
3106
|
const isAdded = addedIds.has(r.id);
|
|
3000
3107
|
return /* @__PURE__ */ jsxs(
|
|
@@ -3014,6 +3121,30 @@ var AddInvestigationField = ({
|
|
|
3014
3121
|
r.id
|
|
3015
3122
|
);
|
|
3016
3123
|
});
|
|
3124
|
+
const limitedFrequentItems = frequentItems.slice(0, 25);
|
|
3125
|
+
const frequentItemChips = limitedFrequentItems.length > 0 ? limitedFrequentItems.map((item) => {
|
|
3126
|
+
const id = String(item.id);
|
|
3127
|
+
const isAdded = value.some((inv) => inv.id === id) || value.some((inv) => inv.name === item.name);
|
|
3128
|
+
const isAdding = addingFrequentId === id;
|
|
3129
|
+
return /* @__PURE__ */ jsxs(
|
|
3130
|
+
"button",
|
|
3131
|
+
{
|
|
3132
|
+
type: "button",
|
|
3133
|
+
disabled: isAdding,
|
|
3134
|
+
onClick: () => handleFrequentItemToggle(item),
|
|
3135
|
+
className: cn(
|
|
3136
|
+
"rounded-full border text-xs px-3 py-1 transition-colors",
|
|
3137
|
+
isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50",
|
|
3138
|
+
isAdding && "opacity-70 pointer-events-none"
|
|
3139
|
+
),
|
|
3140
|
+
children: [
|
|
3141
|
+
isAdded && /* @__PURE__ */ jsx("span", { className: "mr-1", children: "\u2713" }),
|
|
3142
|
+
isAdding ? "\u2026" : item.name
|
|
3143
|
+
]
|
|
3144
|
+
},
|
|
3145
|
+
item.id
|
|
3146
|
+
);
|
|
3147
|
+
}) : [];
|
|
3017
3148
|
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
3149
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
|
|
3019
3150
|
/* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: label }),
|
|
@@ -3052,7 +3183,8 @@ var AddInvestigationField = ({
|
|
|
3052
3183
|
open,
|
|
3053
3184
|
onClose: () => setOpen(false),
|
|
3054
3185
|
title: "Add Investigation",
|
|
3055
|
-
recentlyUsedSlot: recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
|
|
3186
|
+
recentlyUsedSlot: frequentItemChips.length > 0 ? frequentItemChips : recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
|
|
3187
|
+
chipSectionLabel: frequentItemChips.length > 0 ? "Frequently used" : void 0,
|
|
3056
3188
|
children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
3057
3189
|
/* @__PURE__ */ jsx(
|
|
3058
3190
|
Input,
|
|
@@ -3092,13 +3224,15 @@ var AddInvestigationField = ({
|
|
|
3092
3224
|
var AddInvestigationWidget = ({ fieldId }) => {
|
|
3093
3225
|
const { value, setValue } = useField(fieldId);
|
|
3094
3226
|
const handlers = useFieldHandlers(fieldId);
|
|
3227
|
+
const { investigations: frequentInvestigations } = useFrequentItems();
|
|
3095
3228
|
return /* @__PURE__ */ jsx(
|
|
3096
3229
|
AddInvestigationField,
|
|
3097
3230
|
{
|
|
3098
3231
|
value: value ?? [],
|
|
3099
3232
|
onChange: setValue,
|
|
3100
3233
|
onSearch: handlers.onSearch,
|
|
3101
|
-
recentlyUsed: handlers.recentlyUsed
|
|
3234
|
+
recentlyUsed: handlers.recentlyUsed,
|
|
3235
|
+
frequentItems: frequentInvestigations
|
|
3102
3236
|
}
|
|
3103
3237
|
);
|
|
3104
3238
|
};
|
|
@@ -3116,13 +3250,15 @@ var AddProcedureField = ({
|
|
|
3116
3250
|
value,
|
|
3117
3251
|
onChange,
|
|
3118
3252
|
onSearch,
|
|
3119
|
-
recentlyUsed = []
|
|
3253
|
+
recentlyUsed = [],
|
|
3254
|
+
frequentItems = []
|
|
3120
3255
|
}) => {
|
|
3121
3256
|
const [open, setOpen] = useState(false);
|
|
3122
3257
|
const [query, setQuery] = useState("");
|
|
3123
3258
|
const [results, setResults] = useState([]);
|
|
3124
3259
|
const [loading, setLoading] = useState(false);
|
|
3125
3260
|
const [addingId, setAddingId] = useState(null);
|
|
3261
|
+
const [addingFrequentId, setAddingFrequentId] = useState(null);
|
|
3126
3262
|
const debounceRef = useRef(null);
|
|
3127
3263
|
const valueRef = useRef([]);
|
|
3128
3264
|
const searchInputRef = useRef(null);
|
|
@@ -3133,6 +3269,7 @@ var AddProcedureField = ({
|
|
|
3133
3269
|
setQuery("");
|
|
3134
3270
|
setResults([]);
|
|
3135
3271
|
setAddingId(null);
|
|
3272
|
+
setAddingFrequentId(null);
|
|
3136
3273
|
}
|
|
3137
3274
|
}, [open]);
|
|
3138
3275
|
function handleQueryChange(q) {
|
|
@@ -3178,6 +3315,26 @@ var AddProcedureField = ({
|
|
|
3178
3315
|
addProcedure(result);
|
|
3179
3316
|
}
|
|
3180
3317
|
}
|
|
3318
|
+
async function handleFrequentItemToggle(item) {
|
|
3319
|
+
const id = String(item.id);
|
|
3320
|
+
const addedById = addedIds.has(id);
|
|
3321
|
+
const addedByName = value.some((proc) => proc.name === item.name);
|
|
3322
|
+
if (addedById || addedByName) {
|
|
3323
|
+
if (addedById) removeProcedure(id);
|
|
3324
|
+
else onChange(value.filter((proc) => proc.name !== item.name));
|
|
3325
|
+
return;
|
|
3326
|
+
}
|
|
3327
|
+
setAddingFrequentId(id);
|
|
3328
|
+
try {
|
|
3329
|
+
const searchResults = await onSearch(item.name);
|
|
3330
|
+
const first = searchResults?.[0];
|
|
3331
|
+
if (first && !valueRef.current.some((proc) => proc.id === first.id)) {
|
|
3332
|
+
onChange([...valueRef.current, mapToProcedure(first)]);
|
|
3333
|
+
}
|
|
3334
|
+
} finally {
|
|
3335
|
+
setAddingFrequentId(null);
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3181
3338
|
const recentlyUsedChips = recentlyUsed.map((r) => {
|
|
3182
3339
|
const isAdded = addedIds.has(r.id);
|
|
3183
3340
|
return /* @__PURE__ */ jsxs(
|
|
@@ -3197,6 +3354,30 @@ var AddProcedureField = ({
|
|
|
3197
3354
|
r.id
|
|
3198
3355
|
);
|
|
3199
3356
|
});
|
|
3357
|
+
const limitedFrequentItems = frequentItems.slice(0, 25);
|
|
3358
|
+
const frequentItemChips = limitedFrequentItems.length > 0 ? limitedFrequentItems.map((item) => {
|
|
3359
|
+
const id = String(item.id);
|
|
3360
|
+
const isAdded = value.some((proc) => proc.id === id) || value.some((proc) => proc.name === item.name);
|
|
3361
|
+
const isAdding = addingFrequentId === id;
|
|
3362
|
+
return /* @__PURE__ */ jsxs(
|
|
3363
|
+
"button",
|
|
3364
|
+
{
|
|
3365
|
+
type: "button",
|
|
3366
|
+
disabled: isAdding,
|
|
3367
|
+
onClick: () => handleFrequentItemToggle(item),
|
|
3368
|
+
className: cn(
|
|
3369
|
+
"rounded-full border text-xs px-3 py-1 transition-colors",
|
|
3370
|
+
isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50",
|
|
3371
|
+
isAdding && "opacity-70 pointer-events-none"
|
|
3372
|
+
),
|
|
3373
|
+
children: [
|
|
3374
|
+
isAdded && /* @__PURE__ */ jsx("span", { className: "mr-1", children: "\u2713" }),
|
|
3375
|
+
isAdding ? "\u2026" : item.name
|
|
3376
|
+
]
|
|
3377
|
+
},
|
|
3378
|
+
item.id
|
|
3379
|
+
);
|
|
3380
|
+
}) : [];
|
|
3200
3381
|
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
3382
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
|
|
3202
3383
|
/* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: label }),
|
|
@@ -3235,7 +3416,8 @@ var AddProcedureField = ({
|
|
|
3235
3416
|
open,
|
|
3236
3417
|
onClose: () => setOpen(false),
|
|
3237
3418
|
title: "Add Procedure",
|
|
3238
|
-
recentlyUsedSlot: recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
|
|
3419
|
+
recentlyUsedSlot: frequentItemChips.length > 0 ? frequentItemChips : recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
|
|
3420
|
+
chipSectionLabel: frequentItemChips.length > 0 ? "Frequently used" : void 0,
|
|
3239
3421
|
children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
3240
3422
|
/* @__PURE__ */ jsx(
|
|
3241
3423
|
Input,
|
|
@@ -3275,13 +3457,15 @@ var AddProcedureField = ({
|
|
|
3275
3457
|
var AddProcedureWidget = ({ fieldId }) => {
|
|
3276
3458
|
const { value, setValue } = useField(fieldId);
|
|
3277
3459
|
const handlers = useFieldHandlers(fieldId);
|
|
3460
|
+
const { procedures: frequentProcedures } = useFrequentItems();
|
|
3278
3461
|
return /* @__PURE__ */ jsx(
|
|
3279
3462
|
AddProcedureField,
|
|
3280
3463
|
{
|
|
3281
3464
|
value: value ?? [],
|
|
3282
3465
|
onChange: setValue,
|
|
3283
3466
|
onSearch: handlers.onSearch,
|
|
3284
|
-
recentlyUsed: handlers.recentlyUsed
|
|
3467
|
+
recentlyUsed: handlers.recentlyUsed,
|
|
3468
|
+
frequentItems: frequentProcedures
|
|
3285
3469
|
}
|
|
3286
3470
|
);
|
|
3287
3471
|
};
|
|
@@ -5594,6 +5778,6 @@ function createUploadHandler(options) {
|
|
|
5594
5778
|
};
|
|
5595
5779
|
}
|
|
5596
5780
|
|
|
5597
|
-
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 };
|
|
5781
|
+
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, useFrequentItems, useSmartKeywords, validateField, validateForm };
|
|
5598
5782
|
//# sourceMappingURL=index.mjs.map
|
|
5599
5783
|
//# sourceMappingURL=index.mjs.map
|