formanitor 0.0.33 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -308,6 +308,18 @@ interface DoctorFrequentItems {
308
308
  investigations?: InvestigationFrequentItem[];
309
309
  procedures?: ProcedureFrequentItem[];
310
310
  }
311
+ interface DiagnosticPackageTest {
312
+ id: string;
313
+ name: string;
314
+ }
315
+ interface DiagnosticPackage {
316
+ id: string;
317
+ name: string;
318
+ code: string;
319
+ description?: string;
320
+ department?: string;
321
+ tests: DiagnosticPackageTest[];
322
+ }
311
323
  type FieldDef = TextFieldDef | RichTextFieldDef | NumberFieldDef | SelectFieldDef | RadioFieldDef | CheckboxFieldDef | RepeatableFieldDef | ImageUploadFieldDef | MediaUploadFieldDef | SignatureFieldDef | EditableTableFieldDef | StaticTextFieldDef | MedicationsFieldDef | InvestigationsFieldDef | ProceduresFieldDef | DifferentialDiagnosisFieldDef | VitalsFieldDef | ReferralFieldDef | FollowupFieldDef | SmartTextareaFieldDef | DiagnosisTextareaFieldDef | BaseFieldDef;
312
324
  interface Condition {
313
325
  field?: string;
@@ -615,6 +627,7 @@ type FieldHandler = {
615
627
  type FieldHandlersMap = Record<string, FieldHandler>;
616
628
  declare function useFieldHandlers(fieldId: string): FieldHandler;
617
629
  declare function useFrequentItems(): DoctorFrequentItems;
630
+ declare function usePackages(): DiagnosticPackage[];
618
631
  interface FormProviderProps {
619
632
  schema: FormDef;
620
633
  config?: StoreConfig;
@@ -624,6 +637,7 @@ interface FormProviderProps {
624
637
  * Consumer fetches and passes this; Forminator flows it to medications, investigations, and procedures widgets.
625
638
  */
626
639
  frequentItems?: DoctorFrequentItems;
640
+ packages?: DiagnosticPackage[];
627
641
  children: React.ReactNode;
628
642
  }
629
643
  declare const FormProvider: React.FC<FormProviderProps>;
@@ -895,8 +909,8 @@ type AddInvestigationFieldProps = {
895
909
  onChange: (items: Investigation[]) => void;
896
910
  onSearch: (query: string) => Promise<InvestigationSearchResult[]>;
897
911
  recentlyUsed?: InvestigationSearchResult[];
898
- /** Doctor-scoped frequently used investigations (from FormProvider frequentItems) */
899
912
  frequentItems?: InvestigationFrequentItem[];
913
+ packages?: DiagnosticPackage[];
900
914
  };
901
915
  declare const AddInvestigationField: React.FC<AddInvestigationFieldProps>;
902
916
 
@@ -939,4 +953,4 @@ declare const SmartTextareaWidget: React.FC<{
939
953
  fieldId: string;
940
954
  }>;
941
955
 
942
- export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, type NumberFieldDef, type Permission, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
956
+ export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, type DiagnosticPackage, type DiagnosticPackageTest, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, type NumberFieldDef, type Permission, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
package/dist/index.d.ts CHANGED
@@ -308,6 +308,18 @@ interface DoctorFrequentItems {
308
308
  investigations?: InvestigationFrequentItem[];
309
309
  procedures?: ProcedureFrequentItem[];
310
310
  }
311
+ interface DiagnosticPackageTest {
312
+ id: string;
313
+ name: string;
314
+ }
315
+ interface DiagnosticPackage {
316
+ id: string;
317
+ name: string;
318
+ code: string;
319
+ description?: string;
320
+ department?: string;
321
+ tests: DiagnosticPackageTest[];
322
+ }
311
323
  type FieldDef = TextFieldDef | RichTextFieldDef | NumberFieldDef | SelectFieldDef | RadioFieldDef | CheckboxFieldDef | RepeatableFieldDef | ImageUploadFieldDef | MediaUploadFieldDef | SignatureFieldDef | EditableTableFieldDef | StaticTextFieldDef | MedicationsFieldDef | InvestigationsFieldDef | ProceduresFieldDef | DifferentialDiagnosisFieldDef | VitalsFieldDef | ReferralFieldDef | FollowupFieldDef | SmartTextareaFieldDef | DiagnosisTextareaFieldDef | BaseFieldDef;
312
324
  interface Condition {
313
325
  field?: string;
@@ -615,6 +627,7 @@ type FieldHandler = {
615
627
  type FieldHandlersMap = Record<string, FieldHandler>;
616
628
  declare function useFieldHandlers(fieldId: string): FieldHandler;
617
629
  declare function useFrequentItems(): DoctorFrequentItems;
630
+ declare function usePackages(): DiagnosticPackage[];
618
631
  interface FormProviderProps {
619
632
  schema: FormDef;
620
633
  config?: StoreConfig;
@@ -624,6 +637,7 @@ interface FormProviderProps {
624
637
  * Consumer fetches and passes this; Forminator flows it to medications, investigations, and procedures widgets.
625
638
  */
626
639
  frequentItems?: DoctorFrequentItems;
640
+ packages?: DiagnosticPackage[];
627
641
  children: React.ReactNode;
628
642
  }
629
643
  declare const FormProvider: React.FC<FormProviderProps>;
@@ -895,8 +909,8 @@ type AddInvestigationFieldProps = {
895
909
  onChange: (items: Investigation[]) => void;
896
910
  onSearch: (query: string) => Promise<InvestigationSearchResult[]>;
897
911
  recentlyUsed?: InvestigationSearchResult[];
898
- /** Doctor-scoped frequently used investigations (from FormProvider frequentItems) */
899
912
  frequentItems?: InvestigationFrequentItem[];
913
+ packages?: DiagnosticPackage[];
900
914
  };
901
915
  declare const AddInvestigationField: React.FC<AddInvestigationFieldProps>;
902
916
 
@@ -939,4 +953,4 @@ declare const SmartTextareaWidget: React.FC<{
939
953
  fieldId: string;
940
954
  }>;
941
955
 
942
- export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, type NumberFieldDef, type Permission, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
956
+ export { type AIDifferentialDiagnosisItem, AddInvestigationField, type AddInvestigationFieldProps, AddMedicationField, type AddMedicationFieldProps, type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, type DiagnosisGradeSelection, type DiagnosisTextareaFieldDef, type DiagnosisTextareaValue, type DiagnosticPackage, type DiagnosticPackageTest, DifferentialDiagnosis, type DifferentialDiagnosisFieldDef, type DifferentialDiagnosisItem, type DifferentialDiagnosisProps, type DoctorFrequentItems, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type ExtractedKeywordMatch, type FieldDef, type FieldHandler, type FieldHandlersMap, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, type FollowupFieldDef, type FollowupValue, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type FormulaComputation, type FormulaExpr, type ImageUploadFieldDef, ImageUploadWidget, type Investigation, type InvestigationFrequentItem, type InvestigationSearchResult, type InvestigationsFieldDef, type LayoutNode, MAR_MEDICATION_ORDERS_META_KEY, type MatchedCondition, type MediaUploadFieldDef, MediaUploadWidget, type Medication, type MedicationFrequentItem, type MedicationSearchResult, type MedicationsFieldDef, type NumberFieldDef, type Permission, type PresignedUploadResponse, type ProcedureFrequentItem, type ProceduresFieldDef, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, type ReferralFieldDef, type ReferralItem, type RepeatableFieldDef, type RichTextFieldDef, RichTextWidget, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, SmartForm, type SmartFormProps, type SmartKeywordsResult, type SmartTextareaFieldDef, type SmartTextareaValue, SmartTextareaWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type VitalsFieldDef, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
package/dist/index.mjs CHANGED
@@ -618,6 +618,11 @@ var FormStore = class {
618
618
  this.config.role = next.role;
619
619
  needsReeval = true;
620
620
  }
621
+ if (next.prefillData !== void 0 && next.prefillData !== this.prefillData) {
622
+ this.prefillData = next.prefillData;
623
+ this.state.values = applyPrefill(this.state.values, this.schema.fields, this.prefillData);
624
+ needsReeval = true;
625
+ }
621
626
  if (needsReeval) {
622
627
  this.evaluate();
623
628
  this.notify();
@@ -697,6 +702,7 @@ var emptyFrequentItems = {
697
702
  procedures: []
698
703
  };
699
704
  var FrequentItemsContext = createContext(emptyFrequentItems);
705
+ var PackagesContext = createContext([]);
700
706
  var FieldHandlersContext = createContext({});
701
707
  function useFieldHandlers(fieldId) {
702
708
  const map = useContext(FieldHandlersContext);
@@ -705,11 +711,15 @@ function useFieldHandlers(fieldId) {
705
711
  function useFrequentItems() {
706
712
  return useContext(FrequentItemsContext);
707
713
  }
714
+ function usePackages() {
715
+ return useContext(PackagesContext);
716
+ }
708
717
  var FormProvider = ({
709
718
  schema,
710
719
  config,
711
720
  fieldHandlers,
712
721
  frequentItems,
722
+ packages,
713
723
  children
714
724
  }) => {
715
725
  const storeRef = useRef(null);
@@ -725,7 +735,7 @@ var FormProvider = ({
725
735
  storeRef.current?.load();
726
736
  }, []);
727
737
  const frequentItemsValue = frequentItems ?? emptyFrequentItems;
728
- return /* @__PURE__ */ jsx(FormContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsx(FieldHandlersContext.Provider, { value: fieldHandlers ?? {}, children: /* @__PURE__ */ jsx(FrequentItemsContext.Provider, { value: frequentItemsValue, children: /* @__PURE__ */ jsx(VoiceContextProvider, { children }) }) }) });
738
+ return /* @__PURE__ */ jsx(FormContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsx(FieldHandlersContext.Provider, { value: fieldHandlers ?? {}, children: /* @__PURE__ */ jsx(FrequentItemsContext.Provider, { value: frequentItemsValue, children: /* @__PURE__ */ jsx(PackagesContext.Provider, { value: packages ?? [], children: /* @__PURE__ */ jsx(VoiceContextProvider, { children }) }) }) }) });
729
739
  };
730
740
  function useFormStore() {
731
741
  const context = useContext(FormContext);
@@ -3078,18 +3088,20 @@ var AddEntityDialog = ({
3078
3088
  open,
3079
3089
  onClose,
3080
3090
  title,
3091
+ chipSections,
3081
3092
  recentlyUsedSlot,
3082
3093
  chipSectionLabel = "Recently Used",
3083
3094
  children,
3084
3095
  actionSlot
3085
3096
  }) => {
3086
- 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: [
3097
+ const sections = chipSections ?? (recentlyUsedSlot ? [{ label: chipSectionLabel, content: recentlyUsedSlot }] : []);
3098
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: (o) => !o && onClose(), children: /* @__PURE__ */ jsxs(DialogContent, { className: "max-w-4xl w-full p-0 gap-0 flex flex-col max-h-[90vh] overflow-hidden", children: [
3087
3099
  /* @__PURE__ */ jsx(DialogHeader, { className: "px-6 pt-6 pb-4 shrink-0", children: /* @__PURE__ */ jsx(DialogTitle, { className: "text-lg font-semibold", children: title }) }),
3088
3100
  /* @__PURE__ */ jsxs("div", { className: "px-6 flex flex-col gap-4 overflow-y-auto flex-1 min-h-0 pb-4", children: [
3089
- recentlyUsedSlot && /* @__PURE__ */ jsxs("div", { children: [
3090
- /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mb-2", children: chipSectionLabel }),
3091
- /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: recentlyUsedSlot })
3092
- ] }),
3101
+ sections.map((section) => /* @__PURE__ */ jsxs("div", { children: [
3102
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mb-2", children: section.label }),
3103
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: section.content })
3104
+ ] }, section.label)),
3093
3105
  children
3094
3106
  ] }),
3095
3107
  actionSlot != null && /* @__PURE__ */ jsx("div", { className: "px-6 py-4 flex justify-end shrink-0 border-t border-border bg-background", children: actionSlot })
@@ -3631,7 +3643,8 @@ var AddInvestigationField = ({
3631
3643
  onChange,
3632
3644
  onSearch,
3633
3645
  recentlyUsed = [],
3634
- frequentItems = []
3646
+ frequentItems = [],
3647
+ packages = []
3635
3648
  }) => {
3636
3649
  const [open, setOpen] = useState(false);
3637
3650
  const [query, setQuery] = useState("");
@@ -3642,6 +3655,8 @@ var AddInvestigationField = ({
3642
3655
  const debounceRef = useRef(null);
3643
3656
  const valueRef = useRef([]);
3644
3657
  const searchInputRef = useRef(null);
3658
+ const addedByPackage = useRef(/* @__PURE__ */ new Map());
3659
+ const [selectedPackageIds, setSelectedPackageIds] = useState(/* @__PURE__ */ new Set());
3645
3660
  const safeValue = Array.isArray(value) ? value : [];
3646
3661
  valueRef.current = safeValue;
3647
3662
  const addedIds = new Set(safeValue.map((inv) => inv.id));
@@ -3716,6 +3731,27 @@ var AddInvestigationField = ({
3716
3731
  setAddingFrequentId(null);
3717
3732
  }
3718
3733
  }
3734
+ function handlePackageToggle(pkg) {
3735
+ const alreadyAdded = addedByPackage.current.has(pkg.id);
3736
+ if (alreadyAdded) {
3737
+ const idsToRemove = new Set(addedByPackage.current.get(pkg.id) ?? []);
3738
+ onChange(valueRef.current.filter((inv) => !idsToRemove.has(inv.id)));
3739
+ addedByPackage.current.delete(pkg.id);
3740
+ setSelectedPackageIds((prev) => {
3741
+ const next = new Set(prev);
3742
+ next.delete(pkg.id);
3743
+ return next;
3744
+ });
3745
+ } else {
3746
+ const currentIds = new Set(valueRef.current.map((inv) => inv.id));
3747
+ const newTests = pkg.tests.filter((t) => !currentIds.has(t.id)).map((t) => mapToInvestigation(t));
3748
+ if (newTests.length > 0) {
3749
+ onChange([...valueRef.current, ...newTests]);
3750
+ }
3751
+ addedByPackage.current.set(pkg.id, newTests.map((t) => t.id));
3752
+ setSelectedPackageIds((prev) => new Set(prev).add(pkg.id));
3753
+ }
3754
+ }
3719
3755
  const recentlyUsedChips = recentlyUsed.map((r) => {
3720
3756
  const isAdded = addedIds.has(r.id);
3721
3757
  return /* @__PURE__ */ jsxs(
@@ -3759,6 +3795,38 @@ var AddInvestigationField = ({
3759
3795
  item.id
3760
3796
  );
3761
3797
  }) : [];
3798
+ const packageChips = packages.map((pkg) => {
3799
+ const isAdded = selectedPackageIds.has(pkg.id);
3800
+ return /* @__PURE__ */ jsxs(
3801
+ "button",
3802
+ {
3803
+ type: "button",
3804
+ onClick: () => handlePackageToggle(pkg),
3805
+ className: cn(
3806
+ "rounded-full border text-xs px-4 py-1.5 transition-colors flex items-center gap-2",
3807
+ isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
3808
+ ),
3809
+ children: [
3810
+ isAdded && /* @__PURE__ */ jsx("span", { children: "\u2713" }),
3811
+ /* @__PURE__ */ jsx("span", { className: "font-semibold", children: pkg.name }),
3812
+ /* @__PURE__ */ jsx("span", { className: cn(
3813
+ "rounded-full px-1.5 py-0.5 text-[10px] font-medium",
3814
+ isAdded ? "bg-green-100 text-green-600" : "bg-purple-100 text-purple-600"
3815
+ ), children: pkg.tests.length })
3816
+ ]
3817
+ },
3818
+ pkg.id
3819
+ );
3820
+ });
3821
+ const chipSections = [];
3822
+ if (frequentItemChips.length > 0) {
3823
+ chipSections.push({ label: "Frequently used", content: /* @__PURE__ */ jsx(Fragment, { children: frequentItemChips }) });
3824
+ } else if (recentlyUsedChips.length > 0) {
3825
+ chipSections.push({ label: "Recently Used", content: /* @__PURE__ */ jsx(Fragment, { children: recentlyUsedChips }) });
3826
+ }
3827
+ if (packageChips.length > 0) {
3828
+ chipSections.push({ label: "Packages", content: /* @__PURE__ */ jsx(Fragment, { children: packageChips }) });
3829
+ }
3762
3830
  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: [
3763
3831
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
3764
3832
  /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: label }),
@@ -3797,8 +3865,7 @@ var AddInvestigationField = ({
3797
3865
  open,
3798
3866
  onClose: () => setOpen(false),
3799
3867
  title: "Add Investigation",
3800
- recentlyUsedSlot: frequentItemChips.length > 0 ? frequentItemChips : recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
3801
- chipSectionLabel: frequentItemChips.length > 0 ? "Frequently used" : void 0,
3868
+ chipSections: chipSections.length > 0 ? chipSections : void 0,
3802
3869
  children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
3803
3870
  /* @__PURE__ */ jsx(
3804
3871
  Input,
@@ -3839,6 +3906,7 @@ var AddInvestigationWidget = ({ fieldId }) => {
3839
3906
  const { value, setValue } = useField(fieldId);
3840
3907
  const handlers = useFieldHandlers(fieldId);
3841
3908
  const { investigations: frequentInvestigations } = useFrequentItems();
3909
+ const packages = usePackages();
3842
3910
  const safeValue = Array.isArray(value) ? value : [];
3843
3911
  return /* @__PURE__ */ jsx(
3844
3912
  AddInvestigationField,
@@ -3847,7 +3915,8 @@ var AddInvestigationWidget = ({ fieldId }) => {
3847
3915
  onChange: setValue,
3848
3916
  onSearch: handlers.onSearch,
3849
3917
  recentlyUsed: handlers.recentlyUsed,
3850
- frequentItems: frequentInvestigations
3918
+ frequentItems: frequentInvestigations,
3919
+ packages
3851
3920
  }
3852
3921
  );
3853
3922
  };
@@ -8418,10 +8487,21 @@ var ReadOnlyReferral = ({ fieldDef, value }) => {
8418
8487
  }) })
8419
8488
  ] });
8420
8489
  };
8421
- function isOrderArray(value) {
8422
- return Array.isArray(value) && value.every(
8423
- (v) => v != null && typeof v === "object" && typeof v.id === "string"
8424
- );
8490
+ function parseOrders(value) {
8491
+ if (value == null) return [];
8492
+ if (Array.isArray(value)) {
8493
+ return value.filter(
8494
+ (v) => v != null && typeof v === "object" && typeof v.id === "string"
8495
+ );
8496
+ }
8497
+ if (typeof value === "object") {
8498
+ const v = value;
8499
+ const orders = Array.isArray(v.orders) ? v.orders : [];
8500
+ return orders.filter(
8501
+ (o) => o != null && typeof o === "object" && typeof o.id === "string"
8502
+ );
8503
+ }
8504
+ return [];
8425
8505
  }
8426
8506
  function formatDuration2(start, end) {
8427
8507
  if (!start && !end) return null;
@@ -8429,7 +8509,7 @@ function formatDuration2(start, end) {
8429
8509
  return start ? `Start: ${start}` : `End: ${end}`;
8430
8510
  }
8431
8511
  var ReadOnlyDischargeMedicationOrders = ({ fieldDef, value }) => {
8432
- const orders = useMemo(() => isOrderArray(value) ? value : [], [value]);
8512
+ const orders = useMemo(() => parseOrders(value), [value]);
8433
8513
  return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
8434
8514
  /* @__PURE__ */ jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
8435
8515
  orders.length === 0 ? /* @__PURE__ */ jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem]", children: /* @__PURE__ */ jsx("span", { className: "text-gray-400 italic", children: "No medicines added" }) }) : /* @__PURE__ */ jsx("div", { className: "space-y-2", children: orders.map((o) => {
@@ -8700,6 +8780,6 @@ function createUploadHandler(options) {
8700
8780
  };
8701
8781
  }
8702
8782
 
8703
- export { AddInvestigationField, AddMedicationField, DifferentialDiagnosis, DynamicForm, EMAIL_REGEX, FieldRenderer, FormControls, FormProvider, FormStore, ImageUploadWidget, MAR_MEDICATION_ORDERS_META_KEY, MediaUploadWidget, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, RichTextWidget, SignatureUploadWidget, SmartForm, SmartTextareaWidget, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, useSmartKeywords, validateField, validateForm };
8783
+ export { AddInvestigationField, AddMedicationField, DifferentialDiagnosis, DynamicForm, EMAIL_REGEX, FieldRenderer, FormControls, FormProvider, FormStore, ImageUploadWidget, MAR_MEDICATION_ORDERS_META_KEY, MediaUploadWidget, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlyMediaUpload, ReadOnlySignature, ReadOnlyTable, RichTextWidget, SignatureUploadWidget, SmartForm, SmartTextareaWidget, createUploadHandler, evaluateRules, fieldMetaRequestsMarMedicationOrdersButton, useField, useFieldHandlers, useForm, useFormStore, useFrequentItems, usePackages, useSmartKeywords, validateField, validateForm };
8704
8784
  //# sourceMappingURL=index.mjs.map
8705
8785
  //# sourceMappingURL=index.mjs.map