@f1studio/form-spec 5.0.0-alpha.101 → 5.0.0-alpha.103

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.
Files changed (161) hide show
  1. package/Components/HelloComponent.d.ts +20 -0
  2. package/Components/HelloComponent.d.ts.map +1 -0
  3. package/Designer.d.ts.map +1 -0
  4. package/FormSpec.TS/Designer.js +2 -2
  5. package/FormSpec.TS/Designer.js.map +1 -1
  6. package/FormSpec.TS/Designer.ts.map +1 -1
  7. package/FormSpec.TS/FormSpec.js +210 -143
  8. package/FormSpec.TS/FormSpec.js.map +1 -1
  9. package/FormSpec.TS/FormSpec.ts.map +1 -1
  10. package/FormSpec.TS/FormSpecHelpers.js +62 -40
  11. package/FormSpec.TS/FormSpecHelpers.js.map +1 -1
  12. package/FormSpec.TS/FormSpecHelpers.ts.map +1 -1
  13. package/FormSpec.TS/FormSpecValues.js +207 -0
  14. package/FormSpec.TS/FormSpecValues.js.map +1 -0
  15. package/FormSpec.TS/FormSpecValues.ts.map +1 -0
  16. package/FormSpec.TS/Helpers.js +26 -25
  17. package/FormSpec.TS/Helpers.js.map +1 -1
  18. package/FormSpec.TS/Helpers.ts.map +1 -1
  19. package/FormSpec.TS/Interop/FormSpec.Api.Helpers.js +85 -125
  20. package/FormSpec.TS/Interop/FormSpec.Api.Helpers.js.map +1 -1
  21. package/FormSpec.TS/Interop/FormSpec.Api.Helpers.ts.map +1 -1
  22. package/FormSpec.TS/Interop/FormSpec.Api.Option.js +37 -7
  23. package/FormSpec.TS/Interop/FormSpec.Api.Option.js.map +1 -1
  24. package/FormSpec.TS/Interop/FormSpec.Api.Option.ts.map +1 -1
  25. package/FormSpec.TS/Interop/FormSpec.Values.Api.Option.js +103 -80
  26. package/FormSpec.TS/Interop/FormSpec.Values.Api.Option.js.map +1 -1
  27. package/FormSpec.TS/Interop/FormSpec.Values.Api.Option.ts.map +1 -1
  28. package/FormSpec.TS/PathwayExecutor.js +371 -125
  29. package/FormSpec.TS/PathwayExecutor.js.map +1 -1
  30. package/FormSpec.TS/PathwayExecutor.ts.map +1 -1
  31. package/FormSpec.TS/PathwayValidator.js +14 -26
  32. package/FormSpec.TS/PathwayValidator.js.map +1 -1
  33. package/FormSpec.TS/PathwayValidator.ts.map +1 -1
  34. package/FormSpec.TS/Renderers/FormSpecMarkdownRenderer.ts.map +1 -1
  35. package/FormSpec.TS/Renderers/PathwayRenderers.js +35 -26
  36. package/FormSpec.TS/Renderers/PathwayRenderers.js.map +1 -1
  37. package/FormSpec.TS/Renderers/PathwayRenderers.ts.map +1 -1
  38. package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Base.fs +0 -0
  39. package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Error.fs +0 -0
  40. package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Extensions.fs +0 -0
  41. package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Fable.Form.fableproj +0 -0
  42. package/FormSpec.TS/fable_modules/Fable.Form.3.0.0/Field.fs +0 -0
  43. package/FormSpec.TS/fable_modules/Fable.Form.Simple.5.0.1/Fable.Form.Simple.fableproj +0 -0
  44. package/FormSpec.TS/fable_modules/Fable.Form.Simple.5.0.1/Form.fs +0 -0
  45. package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Extensions.fs +0 -0
  46. package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Hooks.fs +0 -0
  47. package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.Types.fableproj +0 -0
  48. package/FormSpec.TS/fable_modules/Fable.React.Types.18.3.0/Fable.React.fs +0 -0
  49. package/FormSpec.TS/fable_modules/Fable.ReactDom.Types.18.2.0/Fable.ReactDom.Types.fableproj +0 -0
  50. package/FormSpec.TS/fable_modules/Fable.ReactDom.Types.18.2.0/Fable.ReactDom.fs +0 -0
  51. package/FormSpec.TS/fable_modules/Feliz.2.7.0/BorderStyle.fs +0 -0
  52. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Colors.fs +0 -0
  53. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Feliz.fableproj +0 -0
  54. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Fonts.fs +0 -0
  55. package/FormSpec.TS/fable_modules/Feliz.2.7.0/GridTypes.fs +0 -0
  56. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Html.fs +0 -0
  57. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Interop.fs +0 -0
  58. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Key.fs +0 -0
  59. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Length.fs +0 -0
  60. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Locale.fs +0 -0
  61. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Properties.fs +0 -0
  62. package/FormSpec.TS/fable_modules/Feliz.2.7.0/React.fs +0 -0
  63. package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactDOM.fs +0 -0
  64. package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactInterop.js +0 -0
  65. package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactInterop.js.map +0 -0
  66. package/FormSpec.TS/fable_modules/Feliz.2.7.0/ReactTypes.fs +0 -0
  67. package/FormSpec.TS/fable_modules/Feliz.2.7.0/StyleTypes.fs +0 -0
  68. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Styles.fs +0 -0
  69. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Svg.fs +0 -0
  70. package/FormSpec.TS/fable_modules/Feliz.2.7.0/TextDecorationLine.fs +0 -0
  71. package/FormSpec.TS/fable_modules/Feliz.2.7.0/TextDecorationStyle.fs +0 -0
  72. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Transform.fs +0 -0
  73. package/FormSpec.TS/fable_modules/Feliz.2.7.0/TransformOrigin.fs +0 -0
  74. package/FormSpec.TS/fable_modules/Feliz.2.7.0/TransitionProperty.fs +0 -0
  75. package/FormSpec.TS/fable_modules/Feliz.2.7.0/Types.fs +0 -0
  76. package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Decode.fs +0 -0
  77. package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Encode.fs +0 -0
  78. package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Encode.fs.js.map +1 -1
  79. package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Encode.fs.ts.map +1 -1
  80. package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Extra.fs +0 -0
  81. package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Thoth.Json.fableproj +0 -0
  82. package/FormSpec.TS/fable_modules/Thoth.Json.10.4.1/Types.fs +0 -0
  83. package/FormSpec.TS/fable_modules/project_cracked.json +1 -1
  84. package/FormSpec.d.ts +56 -43
  85. package/FormSpec.d.ts.map +1 -0
  86. package/FormSpecHelpers.d.ts +18 -12
  87. package/FormSpecHelpers.d.ts.map +1 -0
  88. package/FormSpecValues.d.ts +62 -0
  89. package/FormSpecValues.d.ts.map +1 -0
  90. package/Helpers.d.ts +11 -10
  91. package/Helpers.d.ts.map +1 -0
  92. package/Interfaces.d.ts.map +1 -0
  93. package/Interop/FormSpec.Api.Helpers.d.ts +25 -28
  94. package/Interop/FormSpec.Api.Helpers.d.ts.map +1 -1
  95. package/Interop/FormSpec.Api.Option.d.ts +10 -6
  96. package/Interop/FormSpec.Api.Option.d.ts.map +1 -1
  97. package/Interop/FormSpec.Values.Api.Option.d.ts +35 -22
  98. package/Interop/FormSpec.Values.Api.Option.d.ts.map +1 -1
  99. package/Logging/LogTypes.d.ts +112 -0
  100. package/Logging/LogTypes.d.ts.map +1 -0
  101. package/Migrator.d.ts.map +1 -0
  102. package/PathwayDataExtractor.d.ts.map +1 -0
  103. package/PathwayExecutor.d.ts +63 -33
  104. package/PathwayExecutor.d.ts.map +1 -0
  105. package/PathwayValidator.d.ts.map +1 -0
  106. package/PluginInterface.d.ts.map +1 -0
  107. package/Prelude.d.ts.map +1 -0
  108. package/README.TS.md +621 -621
  109. package/README.md +98 -85
  110. package/Renderers/FormSpecMarkdownRenderer.d.ts +11 -0
  111. package/Renderers/FormSpecMarkdownRenderer.d.ts.map +1 -0
  112. package/Renderers/MermaidRenderer.d.ts +48 -0
  113. package/Renderers/MermaidRenderer.d.ts.map +1 -0
  114. package/Renderers/PathwayRenderers.d.ts +59 -0
  115. package/Renderers/PathwayRenderers.d.ts.map +1 -0
  116. package/fable_modules/Thoth.Json.10.4.1/Decode.fs.d.ts +126 -0
  117. package/fable_modules/Thoth.Json.10.4.1/Decode.fs.d.ts.map +1 -0
  118. package/fable_modules/Thoth.Json.10.4.1/Encode.fs.d.ts +163 -0
  119. package/fable_modules/Thoth.Json.10.4.1/Encode.fs.d.ts.map +1 -0
  120. package/fable_modules/Thoth.Json.10.4.1/Types.fs.d.ts +66 -0
  121. package/fable_modules/Thoth.Json.10.4.1/Types.fs.d.ts.map +1 -0
  122. package/package.json +53 -39
  123. package/src/Components/HelloComponent.ts +48 -48
  124. package/src/Designer.ts +389 -389
  125. package/src/FormSpec.ts +3154 -3114
  126. package/src/FormSpecHelpers.ts +397 -374
  127. package/src/FormSpecValues.ts +158 -0
  128. package/src/Helpers.ts +766 -765
  129. package/src/Interfaces.ts +166 -166
  130. package/src/Interop/FormSpec.Api.Helpers.ts +835 -872
  131. package/src/Interop/FormSpec.Api.Option.ts +1637 -1618
  132. package/src/Interop/FormSpec.Values.Api.Option.ts +1241 -1214
  133. package/src/Logging/LogTypes.ts +212 -212
  134. package/src/Migrator.ts +156 -156
  135. package/src/PathwayDataExtractor.ts +290 -290
  136. package/src/PathwayExecutor.ts +1379 -1102
  137. package/src/PathwayValidator.ts +238 -244
  138. package/src/PluginInterface.ts +79 -79
  139. package/src/Prelude.ts +21 -21
  140. package/src/Renderers/FormSpecMarkdownRenderer.ts +875 -874
  141. package/src/Renderers/MermaidRenderer.ts +218 -218
  142. package/src/Renderers/PathwayRenderers.ts +208 -200
  143. package/src/Components/HelloComponent.ts.map +0 -1
  144. package/src/Designer.ts.map +0 -1
  145. package/src/FormSpec.ts.map +0 -1
  146. package/src/FormSpecHelpers.ts.map +0 -1
  147. package/src/Helpers.ts.map +0 -1
  148. package/src/Interfaces.ts.map +0 -1
  149. package/src/Interop/FormSpec.Api.Helpers.ts.map +0 -1
  150. package/src/Interop/FormSpec.Api.Option.ts.map +0 -1
  151. package/src/Interop/FormSpec.Values.Api.Option.ts.map +0 -1
  152. package/src/Logging/LogTypes.ts.map +0 -1
  153. package/src/Migrator.ts.map +0 -1
  154. package/src/PathwayDataExtractor.ts.map +0 -1
  155. package/src/PathwayExecutor.ts.map +0 -1
  156. package/src/PathwayValidator.ts.map +0 -1
  157. package/src/PluginInterface.ts.map +0 -1
  158. package/src/Prelude.ts.map +0 -1
  159. package/src/Renderers/FormSpecMarkdownRenderer.ts.map +0 -1
  160. package/src/Renderers/MermaidRenderer.ts.map +0 -1
  161. package/src/Renderers/PathwayRenderers.ts.map +0 -1
@@ -1,872 +1,835 @@
1
- import { map as map_3, some, value as value_11, unwrap, defaultArgWith as defaultArgWith_1, Option, defaultArg as defaultArg_1 } from "@fable-org/fable-library-js/Option.js";
2
- import { tryPick, singleton, exists, filter, map as map_2, ofArray as ofArray_1, ofSeq, empty, collect, tryFind, FSharpList } from "@fable-org/fable-library-js/List.js";
3
- import { join, printf, toConsole } from "@fable-org/fable-library-js/String.js";
4
- import { Auto_generateBoxedEncoder_437914C6, toString } from "../fable_modules/Thoth.Json.10.4.1/Encode.fs.js";
5
- import { array_type, string_type, union_type, TypeInfo, obj_type } from "@fable-org/fable-library-js/Reflection.js";
6
- import { Auto_generateBoxedDecoder_Z6670B51, fromString } from "../fable_modules/Thoth.Json.10.4.1/Decode.fs.js";
7
- import { equals, compare, IDisposable, disposeSafe, IEnumerator, getEnumerator, IMap, isArrayLike, uncurry2 } from "@fable-org/fable-library-js/Util.js";
8
- import { ClinicalPathway_StateType_$union, ClinicalPathway_TaskPriority_$union, ClinicalPathway_AlertSeverity_$union, ClinicalPathway_ReferralUrgency_$union, ClinicalPathway_ActionInfo_$union, ClinicalPathway_NavigateToFormAction, ClinicalPathway_ProblemAction, ClinicalPathway_AlertAction, ClinicalPathway_EducationAction, ClinicalPathway_ProcedureAction, ClinicalPathway_TestAction, ClinicalPathway_DocumentationAction, ClinicalPathway_FieldValueSource_$union, ClinicalPathway_SetFieldValueAction, ClinicalPathway_PrescriptionAction, ClinicalPathway_MedicationAction, ClinicalPathway_ReferralAction, ClinicalPathway_ClinicalPathwaySpec, ClinicalPathway_PathRequirement, ClinicalPathway_ConstraintDefinition, ClinicalPathway_PathwayExecutionMode_SinglePathway, ClinicalPathway_SinglePathwayConfig, ClinicalPathway_SelectionStrategy_HighestPriority, ClinicalPathway_TransitionDefinition, ClinicalPathway_TransitionCondition_FieldCondition, Shared_ConditionValue_Single, ClinicalPathway_FieldEvaluator_Equals, Shared_TransitionKey, ClinicalPathway_StateType_Terminal, ClinicalPathway_TerminalInfo, ClinicalPathway_StateDefinition, ClinicalPathway_StateType_Action, ClinicalPathway_ActionInfo_Task, ClinicalPathway_TaskAction, ClinicalPathway_DueDate_Today, ClinicalPathway_TaskPriority_Medium, ClinicalPathway_TaskPriority_Low, ClinicalPathway_TaskPriority_High, Shared_StateKey, Spec_FieldType_PluginField, Spec_PluginFieldConfig, Spec_FieldType_Matrix, Spec_MatrixInfo, Spec_FieldType_Text, Spec_TextInfo, Spec_FieldType_CheckboxList, Spec_MultiChoiceInfo, Shared_FieldOptionKey, Spec_FieldType_Checkbox, Spec_BooleanInfo, Shared_FieldKey, Values_StepOrder, Values_FieldDetails$1, Shared_FieldOption, Shared_FieldValue_Single, Shared_FieldValue_PluginData, Shared_PluginDataProperty, Shared_PluginPropertyKey, Shared_FieldValue_Matrix, Shared_MatrixAnswer, Shared_MatrixItemKey, Shared_FieldValue_Multiple, Shared_FieldAnswer, Values_DynamicFormSpecDetails, Values_Signature, Values_FormStatus_Pending, Spec_FormStep$1, Spec_FormField$1, Values_DynamicFormResultData$1, Values_DynamicFormResultData$1_$reflection, Spec_FieldType_$union, Spec_FormSpec$1, Spec_FormSpec$1_$reflection, Spec_FieldType_$reflection } from "../FormSpec.js";
9
- import { FSharpResult$2_$union } from "@fable-org/fable-library-js/Result.js";
10
- import { Union } from "@fable-org/fable-library-js/Types.js";
11
- import { IOptionalGetter, array as array_4, IGetters, dict, string, IRequiredGetter, object, fromString as fromString_1 } from "../fable_modules/Thoth.Json.10.4.1/Decode.fs.js";
12
- import { ErrorReason_$union } from "../fable_modules/Thoth.Json.10.4.1/Types.fs.js";
13
- import { toSeq, tryFind as tryFind_1, ofList, ofSeq as ofSeq_1, FSharpMap } from "@fable-org/fable-library-js/Map.js";
14
- import { addToDict } from "@fable-org/fable-library-js/MapUtil.js";
15
- import { mapIndexed, map as map_1, choose } from "@fable-org/fable-library-js/Seq.js";
16
- import { ofArray } from "@fable-org/fable-library-js/Set.js";
17
- import { map } from "@fable-org/fable-library-js/Array.js";
18
- import { int32 } from "@fable-org/fable-library-js/Int32.js";
19
- import { newGuid, parse } from "@fable-org/fable-library-js/Guid.js";
20
- import { now } from "@fable-org/fable-library-js/DateOffset.js";
21
- import { initializeExecution } from "../PathwayExecutor.js";
22
-
23
- /**
24
- * Get value from Option or return default (SAFE - recommended)
25
- * TypeScript: <T>(opt: Option<T>, defaultValue: T) => T
26
- * Usage: Api.defaultArg(formSpec.Code, "unknown")
27
- */
28
- export function defaultArg<T>(opt: Option<T>, defaultValue: T): T {
29
- return defaultArg_1(opt, defaultValue);
30
- }
31
-
32
- /**
33
- * Get value from Option or compute default using function (SAFE - recommended)
34
- * TypeScript: <T>(opt: Option<T>, defThunk: () => T) => T
35
- * Usage: Api.defaultArgWith(formSpec.Code, () => "unknown")
36
- */
37
- export function defaultArgWith<T>(opt: Option<T>, defThunk: (() => T)): T {
38
- return defaultArgWith_1<T>(opt, defThunk);
39
- }
40
-
41
- /**
42
- * Check if Option is Some
43
- * TypeScript: <T>(opt: Option<T>) => boolean
44
- * Usage: if (Api.isSome(formSpec.Code)) { ... }
45
- */
46
- export function isSome<T>(opt: Option<T>): boolean {
47
- return opt != null;
48
- }
49
-
50
- /**
51
- * Check if Option is None
52
- * TypeScript: <T>(opt: Option<T>) => boolean
53
- * Usage: if (Api.isNone(formSpec.Code)) { ... }
54
- */
55
- export function isNone<T>(opt: Option<T>): boolean {
56
- return opt == null;
57
- }
58
-
59
- export function listToArray<T>(list: FSharpList<T>): T[] {
60
- return Array.from(list);
61
- }
62
-
63
- export function serializeFormSpec(formSpec: any): string {
64
- toConsole(printf("[API.Helpers] Serializing FormSpec!!"));
65
- toConsole(`[API.Helpers] FormSpec: ${formSpec}`);
66
- return toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(formSpec));
67
- }
68
-
69
- export function deserializeFormSpec(json: string): Option<Spec_FormSpec$1<Spec_FieldType_$union>> {
70
- toConsole(printf("[API.Helpers] Deserializing FormSpec"));
71
- const matchValue: FSharpResult$2_$union<Spec_FormSpec$1<Spec_FieldType_$union>, string> = fromString<Spec_FormSpec$1<Spec_FieldType_$union>>(uncurry2(Auto_generateBoxedDecoder_Z6670B51(Spec_FormSpec$1_$reflection(Spec_FieldType_$reflection()), undefined, undefined)), json);
72
- if (matchValue.tag === /* Error */ 1) {
73
- throw new Error(`[API.Helpers] Deserialization failed: ${matchValue.fields[0]}`);
74
- }
75
- else {
76
- return matchValue.fields[0];
77
- }
78
- }
79
-
80
- export function serializeDynamicFormResultData(data: Values_DynamicFormResultData$1<Spec_FieldType_$union>): string {
81
- toConsole(printf("[API.Helpers] Serializing DynamicFormResultData"));
82
- return toString(0, Auto_generateBoxedEncoder_437914C6(Values_DynamicFormResultData$1_$reflection(Spec_FieldType_$reflection()), undefined, undefined, undefined)(data));
83
- }
84
-
85
- export function deserializeDynamicFormResultData(json: string): Option<Values_DynamicFormResultData$1<Spec_FieldType_$union>> {
86
- const matchValue: FSharpResult$2_$union<Values_DynamicFormResultData$1<Spec_FieldType_$union>, string> = fromString<Values_DynamicFormResultData$1<Spec_FieldType_$union>>(uncurry2(Auto_generateBoxedDecoder_Z6670B51(Values_DynamicFormResultData$1_$reflection(Spec_FieldType_$reflection()), undefined, undefined)), json);
87
- if (matchValue.tag === /* Error */ 1) {
88
- return undefined;
89
- }
90
- else {
91
- return matchValue.fields[0];
92
- }
93
- }
94
-
95
- /**
96
- * Find FormField by its FieldKey string representation
97
- */
98
- export function findFieldByKey(spec: Spec_FormSpec$1<Spec_FieldType_$union>, fieldKeyString: string): Option<Spec_FormField$1<Spec_FieldType_$union>> {
99
- return tryFind<Spec_FormField$1<Spec_FieldType_$union>>((field: Spec_FormField$1<Spec_FieldType_$union>): boolean => (field.FieldKey.fields[0] === fieldKeyString), collect<Spec_FormStep$1<Spec_FieldType_$union>, Spec_FormField$1<Spec_FieldType_$union>>((step: Spec_FormStep$1<Spec_FieldType_$union>): FSharpList<Spec_FormField$1<Spec_FieldType_$union>> => step.Fields, spec.Steps));
100
- }
101
-
102
- export type ExpectedFieldValueType_$union =
103
- | ExpectedFieldValueType<0>
104
- | ExpectedFieldValueType<1>
105
- | ExpectedFieldValueType<2>
106
- | ExpectedFieldValueType<3>
107
-
108
- export type ExpectedFieldValueType_$cases = {
109
- 0: ["SingleValue", []],
110
- 1: ["MultipleValues", []],
111
- 2: ["MatrixValue", []],
112
- 3: ["PluginDataValue", []]
113
- }
114
-
115
- export function ExpectedFieldValueType_SingleValue() {
116
- return new ExpectedFieldValueType<0>(0, []);
117
- }
118
-
119
- export function ExpectedFieldValueType_MultipleValues() {
120
- return new ExpectedFieldValueType<1>(1, []);
121
- }
122
-
123
- export function ExpectedFieldValueType_MatrixValue() {
124
- return new ExpectedFieldValueType<2>(2, []);
125
- }
126
-
127
- export function ExpectedFieldValueType_PluginDataValue() {
128
- return new ExpectedFieldValueType<3>(3, []);
129
- }
130
-
131
- export class ExpectedFieldValueType<Tag extends keyof ExpectedFieldValueType_$cases> extends Union<Tag, ExpectedFieldValueType_$cases[Tag][0]> {
132
- constructor(readonly tag: Tag, readonly fields: ExpectedFieldValueType_$cases[Tag][1]) {
133
- super();
134
- }
135
- cases() {
136
- return ["SingleValue", "MultipleValues", "MatrixValue", "PluginDataValue"];
137
- }
138
- }
139
-
140
- export function ExpectedFieldValueType_$reflection(): TypeInfo {
141
- return union_type("FormSpec.Interop.Helpers.ExpectedFieldValueType", [], ExpectedFieldValueType, () => [[], [], [], []]);
142
- }
143
-
144
- export function getExpectedFieldValueType(fieldType: Spec_FieldType_$union): ExpectedFieldValueType_$union {
145
- switch (fieldType.tag) {
146
- case /* TextArea */ 1:
147
- return ExpectedFieldValueType_SingleValue();
148
- case /* Email */ 2:
149
- return ExpectedFieldValueType_SingleValue();
150
- case /* Password */ 3:
151
- return ExpectedFieldValueType_SingleValue();
152
- case /* Search */ 4:
153
- return ExpectedFieldValueType_SingleValue();
154
- case /* Color */ 5:
155
- return ExpectedFieldValueType_SingleValue();
156
- case /* Number */ 6:
157
- return ExpectedFieldValueType_SingleValue();
158
- case /* Tel */ 7:
159
- return ExpectedFieldValueType_SingleValue();
160
- case /* Date */ 8:
161
- return ExpectedFieldValueType_SingleValue();
162
- case /* DateTimeLocal */ 9:
163
- return ExpectedFieldValueType_SingleValue();
164
- case /* Time */ 10:
165
- return ExpectedFieldValueType_SingleValue();
166
- case /* Checkbox */ 11:
167
- return ExpectedFieldValueType_SingleValue();
168
- case /* Radio */ 12:
169
- return ExpectedFieldValueType_SingleValue();
170
- case /* SingleChoice */ 13:
171
- return ExpectedFieldValueType_SingleValue();
172
- case /* Dropdown */ 14:
173
- return ExpectedFieldValueType_SingleValue();
174
- case /* TextAutoComplete */ 18:
175
- return ExpectedFieldValueType_SingleValue();
176
- case /* Signature */ 20:
177
- return ExpectedFieldValueType_SingleValue();
178
- case /* Message */ 21:
179
- return ExpectedFieldValueType_SingleValue();
180
- case /* CheckboxList */ 16:
181
- return ExpectedFieldValueType_MultipleValues();
182
- case /* MultiChoice */ 15:
183
- return ExpectedFieldValueType_MultipleValues();
184
- case /* TagList */ 17:
185
- return ExpectedFieldValueType_MultipleValues();
186
- case /* Matrix */ 19:
187
- return ExpectedFieldValueType_MatrixValue();
188
- case /* PluginField */ 22:
189
- return ExpectedFieldValueType_PluginDataValue();
190
- default:
191
- return ExpectedFieldValueType_SingleValue();
192
- }
193
- }
194
-
195
- export function decodeAsString(fieldKey: string, obj: any): string {
196
- let matchValue: FSharpResult$2_$union<string, string>;
197
- const json: string = toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(obj));
198
- matchValue = fromString<string>(uncurry2(Auto_generateBoxedDecoder_Z6670B51(string_type, undefined, undefined)), json);
199
- if (matchValue.tag === /* Error */ 1) {
200
- if (typeof obj === "string") {
201
- const str = obj as string;
202
- return str;
203
- }
204
- else {
205
- throw new Error(`Field ${fieldKey}: Expected string value, got ${"Object"}`);
206
- }
207
- }
208
- else {
209
- return matchValue.fields[0];
210
- }
211
- }
212
-
213
- export function decodeAsStringArray(fieldKey: string, obj: any): string[] {
214
- if (isArrayLike(obj)) {
215
- return obj;
216
- }
217
- else if (isArrayLike(obj)) {
218
- const resizeArray: string[] = obj;
219
- return resizeArray.slice();
220
- }
221
- else if (typeof obj === "string") {
222
- return [obj];
223
- }
224
- else {
225
- try {
226
- let matchValue: FSharpResult$2_$union<string[], string>;
227
- const json: string = toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(obj));
228
- matchValue = fromString<string[]>(uncurry2(Auto_generateBoxedDecoder_Z6670B51(array_type(string_type), undefined, undefined)), json);
229
- if (matchValue.tag === /* Error */ 1) {
230
- throw new Error(`Field ${fieldKey}: Expected string array, got ${"Object"}`);
231
- }
232
- else {
233
- return matchValue.fields[0];
234
- }
235
- }
236
- catch (ex: any) {
237
- throw new Error(`Field ${fieldKey}: Expected string array, got ${"Object"}`);
238
- }
239
- }
240
- }
241
-
242
- export function decodeAsMatrixValue(fieldKey: string, obj: any): { description: string, values: IMap<string, string> } {
243
- let str: string;
244
- const objAsString: string = (typeof obj === "string") ? ((str = (obj as string), str)) : toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(obj));
245
- try {
246
- const matchValue: FSharpResult$2_$union<{ description: string, values: IMap<string, string> }, string> = fromString_1<{ description: string, values: IMap<string, string> }>((path_2: string, v: any): FSharpResult$2_$union<{ description: string, values: IMap<string, string> }, [string, ErrorReason_$union]> => object<{ description: string, values: IMap<string, string> }>((get$: IGetters): { description: string, values: IMap<string, string> } => {
247
- let description: string;
248
- const objectArg: IRequiredGetter = get$.Required;
249
- description = objectArg.Field<string>("description", string);
250
- let valuesMap: FSharpMap<string, string>;
251
- const arg_3: ((arg0: string) => ((arg0: any) => FSharpResult$2_$union<FSharpMap<string, string>, [string, ErrorReason_$union]>)) = dict<string>(string);
252
- const objectArg_1: IRequiredGetter = get$.Required;
253
- valuesMap = objectArg_1.Field<FSharpMap<string, string>>("values", uncurry2(arg_3));
254
- const valuesDict: IMap<string, string> = new Map<string, string>([]);
255
- const enumerator: IEnumerator<[string, string]> = getEnumerator(valuesMap);
256
- try {
257
- while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
258
- const kvp: [string, string] = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
259
- addToDict(valuesDict, kvp[0], kvp[1]);
260
- }
261
- }
262
- finally {
263
- disposeSafe(enumerator as IDisposable);
264
- }
265
- return {
266
- description: description,
267
- values: valuesDict,
268
- };
269
- }, path_2, v), objAsString);
270
- if (matchValue.tag === /* Error */ 1) {
271
- throw new Error(`Field ${fieldKey}: Invalid matrix data format - ${matchValue.fields[0]}`);
272
- }
273
- else {
274
- return matchValue.fields[0];
275
- }
276
- }
277
- catch (ex: any) {
278
- throw new Error(`Field ${fieldKey}: Failed to decode matrix value - ${ex.message}`);
279
- }
280
- }
281
-
282
- export function decodeAsPluginDataArray(fieldKey: string, obj: any): { dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }[] {
283
- let str: string;
284
- const objAsString: string = (typeof obj === "string") ? ((str = (obj as string), str)) : toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(obj));
285
- try {
286
- const matchValue: FSharpResult$2_$union<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }[], string> = fromString_1<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }[]>((path_8: string, value_10: any): FSharpResult$2_$union<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }[], [string, ErrorReason_$union]> => array_4<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }>((path_7: string, v: any): FSharpResult$2_$union<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }, [string, ErrorReason_$union]> => object<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }>((get$: IGetters): { dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string } => {
287
- let objectArg_6: IOptionalGetter;
288
- let propertyKey: string;
289
- const objectArg: IRequiredGetter = get$.Required;
290
- propertyKey = objectArg.Field<string>("propertyKey", string);
291
- let name: string;
292
- const objectArg_1: IRequiredGetter = get$.Required;
293
- name = objectArg_1.Field<string>("name", string);
294
- let dataType: string;
295
- const objectArg_2: IRequiredGetter = get$.Required;
296
- dataType = objectArg_2.Field<string>("dataType", string);
297
- let value_6: string;
298
- const objectArg_3: IRequiredGetter = get$.Required;
299
- value_6 = objectArg_3.Field<string>("value", string);
300
- let displayName: Option<string>;
301
- const objectArg_4: IOptionalGetter = get$.Optional;
302
- displayName = objectArg_4.Field<string>("displayName", string);
303
- let unit: Option<string>;
304
- const objectArg_5: IOptionalGetter = get$.Optional;
305
- unit = objectArg_5.Field<string>("unit", string);
306
- return {
307
- dataType: dataType,
308
- description: unwrap((objectArg_6 = get$.Optional, objectArg_6.Field<string>("description", string))),
309
- displayName: unwrap(displayName),
310
- name: name,
311
- propertyKey: propertyKey,
312
- unit: unwrap(unit),
313
- value: value_6,
314
- };
315
- }, path_7, v), path_8, value_10), objAsString);
316
- if (matchValue.tag === /* Error */ 1) {
317
- throw new Error(`Field ${fieldKey}: Invalid plugin data format - ${matchValue.fields[0]}`);
318
- }
319
- else {
320
- return matchValue.fields[0];
321
- }
322
- }
323
- catch (ex: any) {
324
- throw new Error(`Field ${fieldKey}: Failed to decode plugin data - ${ex.message}`);
325
- }
326
- }
327
-
328
- export function createFormFieldData(fieldKey: string, objectValue: any): { fieldKey: string, objectValue: any } {
329
- return {
330
- fieldKey: fieldKey,
331
- objectValue: objectValue,
332
- };
333
- }
334
-
335
- /**
336
- * Build DynamicFormResultData from FormSpec with comprehensive type validation
337
- * TypeScript: (formSpec: FormSpec, fieldData: FieldInput[]) => DynamicFormResultData
338
- * Where FieldInput = SingleValueInput | MultipleValueInput | MatrixValueInput | PluginValueInput
339
- */
340
- export function buildDynamicFormResultData(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, fieldData: { fieldKey: string, objectValue: any }[]): Values_DynamicFormResultData$1<Spec_FieldType_$union> {
341
- const resultFormSpecDetails: Values_DynamicFormSpecDetails = new Values_DynamicFormSpecDetails(formSpec.Id, formSpec.Code, formSpec.FormSpecVersion, formSpec.FormSpecVersion, formSpec.Score, Values_FormStatus_Pending(), empty<Values_Signature>());
342
- const allFieldDetails: FSharpList<[Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>]> = ofSeq<[Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>]>(choose<{ fieldKey: string, objectValue: any }, [Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>]>((input: { fieldKey: string, objectValue: any }): Option<[Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>]> => {
343
- let matchValue_1: ExpectedFieldValueType_$union, matrixData: { description: string, values: IMap<string, string> }, matchValue_2: Spec_FieldType_$union;
344
- const matchValue: Option<Spec_FormField$1<Spec_FieldType_$union>> = findFieldByKey(formSpec, input.fieldKey);
345
- if (matchValue == null) {
346
- toConsole(`Warning: Field ${input.fieldKey} not found in FormSpec`);
347
- return undefined;
348
- }
349
- else {
350
- const field: Spec_FormField$1<Spec_FieldType_$union> = value_11(matchValue);
351
- try {
352
- return [field, new Values_FieldDetails$1(field.FieldOrder, field.FieldKey, field.Label, (matchValue_1 = getExpectedFieldValueType(field.FieldType), (matchValue_1.tag === /* MultipleValues */ 1) ? Shared_FieldValue_Multiple(ofArray<Shared_FieldAnswer>(map<string, Shared_FieldAnswer>((value: string): Shared_FieldAnswer => (new Shared_FieldAnswer(field.FieldKey, field.Label, value)), decodeAsStringArray(input.fieldKey, input.objectValue)), {
353
- Compare: compare,
354
- })) : ((matchValue_1.tag === /* MatrixValue */ 2) ? ((matrixData = decodeAsMatrixValue(input.fieldKey, input.objectValue), Shared_FieldValue_Matrix(new Shared_MatrixAnswer(field.FieldKey, matrixData.description, ofSeq_1<Shared_MatrixItemKey, string>(map_1<[string, string], [Shared_MatrixItemKey, string]>((kvp: [string, string]): [Shared_MatrixItemKey, string] => ([new Shared_MatrixItemKey(parse(kvp[0])), kvp[1]] as [Shared_MatrixItemKey, string]), matrixData.values), {
355
- Compare: compare,
356
- }))))) : ((matchValue_1.tag === /* PluginDataValue */ 3) ? Shared_FieldValue_PluginData(ofArray_1<Shared_PluginDataProperty>(map<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }, Shared_PluginDataProperty>((prop: { dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }): Shared_PluginDataProperty => (new Shared_PluginDataProperty(new Shared_PluginPropertyKey(parse(prop.propertyKey)), prop.name, prop.dataType, prop.value, prop.displayName, prop.unit, prop.description)), decodeAsPluginDataArray(input.fieldKey, input.objectValue)))) : Shared_FieldValue_Single(new Shared_FieldAnswer(field.FieldKey, field.Label, decodeAsString(input.fieldKey, input.objectValue)))))), field.FieldType, (matchValue_2 = field.FieldType, (matchValue_2.tag === /* Radio */ 12) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* SingleChoice */ 13) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* Dropdown */ 14) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* MultiChoice */ 15) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* CheckboxList */ 16) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* TagList */ 17) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* TextAutoComplete */ 18) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* Matrix */ 19) ? matchValue_2.fields[0].Options : empty<Shared_FieldOption>())))))))))] as [Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>];
357
- }
358
- catch (ex: any) {
359
- toConsole(`Error processing field ${input.fieldKey}: ${ex.message}`);
360
- return undefined;
361
- }
362
- }
363
- }, fieldData));
364
- return new Values_DynamicFormResultData$1(resultFormSpecDetails, ofList<Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>>(map_2<Spec_FormStep$1<Spec_FieldType_$union>, [Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>]>((step: Spec_FormStep$1<Spec_FieldType_$union>): [Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>] => ([new Values_StepOrder(step.StepOrder), ofList<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>(map_2<[Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>], [Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>]>((tupledArg_1: [Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>]): [Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>] => {
365
- const fieldDetails_1: Values_FieldDetails$1<Spec_FieldType_$union> = tupledArg_1[1];
366
- return [fieldDetails_1.Key, fieldDetails_1] as [Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>];
367
- }, filter<[Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>]>((tupledArg: [Spec_FormField$1<Spec_FieldType_$union>, Values_FieldDetails$1<Spec_FieldType_$union>]): boolean => exists<Spec_FormField$1<Spec_FieldType_$union>>((stepField: Spec_FormField$1<Spec_FieldType_$union>): boolean => equals(stepField.FieldKey, tupledArg[0].FieldKey), step.Fields), allFieldDetails)), {
368
- Compare: compare,
369
- })] as [Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>]), formSpec.Steps), {
370
- Compare: compare,
371
- }));
372
- }
373
-
374
- /**
375
- * Create a checkbox field with the given parameters
376
- * TypeScript: createCheckboxField(fieldKey: string, label: string, isOptional: boolean)
377
- */
378
- export function createCheckboxField(fieldKeyString: string, label: string, isOptional: boolean): Spec_FormField$1<Spec_FieldType_$union> {
379
- return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, isOptional, false, Spec_FieldType_Checkbox(new Spec_BooleanInfo(undefined, undefined)));
380
- }
381
-
382
- /**
383
- * Create a checkbox list field with options
384
- * TypeScript: createCheckboxListField(fieldKey: string, label: string, options: {value: string, description: string, optionKey: string}[])
385
- */
386
- export function createCheckboxListField(fieldKeyString: string, label: string, options: { description: string, optionKey: string, value: string }[]): Spec_FormField$1<Spec_FieldType_$union> {
387
- const fieldOptions: FSharpList<Shared_FieldOption> = ofSeq<Shared_FieldOption>(mapIndexed<{ description: string, optionKey: string, value: string }, Shared_FieldOption>((_arg: int32, opt: { description: string, optionKey: string, value: string }): Shared_FieldOption => (new Shared_FieldOption(opt.description, opt.value, new Shared_FieldOptionKey(parse(opt.optionKey)))), options));
388
- return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, false, false, Spec_FieldType_CheckboxList(new Spec_MultiChoiceInfo(fieldOptions)));
389
- }
390
-
391
- /**
392
- * Create a text field
393
- * TypeScript: createTextField(fieldKey: string, label: string, isOptional: boolean)
394
- */
395
- export function createTextField(fieldKeyString: string, label: string, isOptional: boolean): Spec_FormField$1<Spec_FieldType_$union> {
396
- return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, isOptional, false, Spec_FieldType_Text(new Spec_TextInfo(undefined)));
397
- }
398
-
399
- /**
400
- * Create a form step with fields
401
- * TypeScript: createFormStep(stepOrder: number, stepLabel: string, fields: FormField[])
402
- */
403
- export function createFormStep(stepOrder: int32, stepLabel: string, fields: Spec_FormField$1<Spec_FieldType_$union>[]): Spec_FormStep$1<Spec_FieldType_$union> {
404
- return new Spec_FormStep$1(stepOrder, stepLabel, ofSeq<Spec_FormField$1<Spec_FieldType_$union>>(mapIndexed<Spec_FormField$1<Spec_FieldType_$union>, Spec_FormField$1<Spec_FieldType_$union>>((index: int32, field: Spec_FormField$1<Spec_FieldType_$union>): Spec_FormField$1<Spec_FieldType_$union> => (new Spec_FormField$1(index + 1, field.FieldKey, field.Label, field.Notes, field.DependsOn, field.IsOptional, field.IsDeprecated, field.FieldType)), fields)));
405
- }
406
-
407
- /**
408
- * Create a FormSpec with basic information
409
- * TypeScript: createFormSpec(id: string, title: string, steps: FormStep[])
410
- */
411
- export function createFormSpec(idString: string, title: string, steps: Spec_FormStep$1<Spec_FieldType_$union>[]): Spec_FormSpec$1<Spec_FieldType_$union> {
412
- return new Spec_FormSpec$1(parse(idString), "DYN", title, "Dynamically created FormSpec", "1.0.0", "2.0.5", ofSeq<Spec_FormStep$1<Spec_FieldType_$union>>(steps), empty<string>(), undefined, empty<string>(), false, false, undefined);
413
- }
414
-
415
- /**
416
- * Create a field option
417
- * TypeScript: createFieldOption(description: string, value: string, optionKey: string)
418
- */
419
- export function createFieldOption(description: string, value: string, optionKeyString: string): Shared_FieldOption {
420
- return new Shared_FieldOption(description, value, new Shared_FieldOptionKey(parse(optionKeyString)));
421
- }
422
-
423
- /**
424
- * Create a matrix field
425
- * TypeScript: createMatrixField(fieldKey: string, label: string, items: FieldOption[], options: FieldOption[])
426
- */
427
- export function createMatrixField(fieldKeyString: string, label: string, items: Shared_FieldOption[], options: Shared_FieldOption[]): Spec_FormField$1<Spec_FieldType_$union> {
428
- return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, false, false, Spec_FieldType_Matrix(new Spec_MatrixInfo(ofSeq<Shared_FieldOption>(items), ofSeq<Shared_FieldOption>(options))));
429
- }
430
-
431
- /**
432
- * Create a plugin field
433
- * TypeScript: createPluginField(fieldKey: string, label: string, config: {pluginId: string, fieldName: string})
434
- */
435
- export function createPluginField(fieldKeyString: string, label: string, config: { fieldName: string, pluginId: string }): Spec_FormField$1<Spec_FieldType_$union> {
436
- return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, false, false, Spec_FieldType_PluginField(new Spec_PluginFieldConfig(config.pluginId, config.fieldName)));
437
- }
438
-
439
- /**
440
- * Create an action state that executes a task
441
- * TypeScript: createActionState(stateKey: string, label: string, taskDescription: string, priority?: string)
442
- */
443
- export function createActionState(stateKeyString: string, label: string, taskDescription: string, priority: Option<string>): ClinicalPathway_StateDefinition {
444
- return new ClinicalPathway_StateDefinition(new Shared_StateKey(parse(stateKeyString)), label, 1, ClinicalPathway_StateType_Action(ClinicalPathway_ActionInfo_Task(new ClinicalPathway_TaskAction("Clinical", taskDescription, (priority != null) ? ((value_11(priority) === "High") ? ClinicalPathway_TaskPriority_High() : ((value_11(priority) === "Low") ? ClinicalPathway_TaskPriority_Low() : ClinicalPathway_TaskPriority_Medium())) : ClinicalPathway_TaskPriority_Medium(), ClinicalPathway_DueDate_Today(), "Clinical Staff", undefined))), undefined);
445
- }
446
-
447
- /**
448
- * Create a terminal state that ends the pathway
449
- * TypeScript: createTerminalState(stateKey: string, outcome: string)
450
- */
451
- export function createTerminalState(stateKeyString: string, outcome: string): ClinicalPathway_StateDefinition {
452
- return new ClinicalPathway_StateDefinition(new Shared_StateKey(parse(stateKeyString)), outcome, 1, ClinicalPathway_StateType_Terminal(new ClinicalPathway_TerminalInfo("Complete", outcome, undefined)), undefined);
453
- }
454
-
455
- /**
456
- * Create a transition between states based on field condition
457
- * TypeScript: createTransition(transitionKey: string, fromState: string, toState: string, fieldKey: string, expectedValue: string)
458
- */
459
- export function createTransition(transitionKeyString: string, fromStateString: string, toStateString: string, fieldKeyString: string, expectedValue: string): ClinicalPathway_TransitionDefinition {
460
- return new ClinicalPathway_TransitionDefinition(new Shared_TransitionKey(parse(transitionKeyString)), new Shared_StateKey(parse(fromStateString)), new Shared_StateKey(parse(toStateString)), ClinicalPathway_TransitionCondition_FieldCondition(new Shared_FieldKey(parse(fieldKeyString)), ClinicalPathway_FieldEvaluator_Equals(), Shared_ConditionValue_Single(expectedValue)), undefined);
461
- }
462
-
463
- /**
464
- * Create a clinical pathway with states and transitions
465
- * TypeScript: createClinicalPathway(name: string, states: StateDefinition[], transitions: TransitionDefinition[])
466
- */
467
- export function createClinicalPathway(name: string, states: ClinicalPathway_StateDefinition[], transitions: ClinicalPathway_TransitionDefinition[]): ClinicalPathway_ClinicalPathwaySpec {
468
- let copyOfStruct: string;
469
- const statesWithOrder: FSharpList<ClinicalPathway_StateDefinition> = ofSeq<ClinicalPathway_StateDefinition>(mapIndexed<ClinicalPathway_StateDefinition, ClinicalPathway_StateDefinition>((index: int32, state: ClinicalPathway_StateDefinition): ClinicalPathway_StateDefinition => (new ClinicalPathway_StateDefinition(state.StateKey, state.StateLabel, index + 1, state.StateType, state.DependsOn)), states));
470
- return new ClinicalPathway_ClinicalPathwaySpec((copyOfStruct = newGuid(), copyOfStruct), name, "1.0.0", "Dynamic Builder", ClinicalPathway_PathwayExecutionMode_SinglePathway(new ClinicalPathway_SinglePathwayConfig(ClinicalPathway_SelectionStrategy_HighestPriority(), true)), new Shared_StateKey("00000000-0000-0000-0000-000000000001"), statesWithOrder, ofSeq<ClinicalPathway_TransitionDefinition>(transitions), empty<ClinicalPathway_ConstraintDefinition>(), empty<ClinicalPathway_PathRequirement>(), now(), undefined, undefined, undefined);
471
- }
472
-
473
- /**
474
- * Add a clinical pathway to an existing FormSpec
475
- * TypeScript: addPathwayToFormSpec(formSpec: FormSpec, pathway: ClinicalPathwaySpec)
476
- */
477
- export function addPathwayToFormSpec(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, pathway: ClinicalPathway_ClinicalPathwaySpec): Spec_FormSpec$1<Spec_FieldType_$union> {
478
- return new Spec_FormSpec$1(formSpec.Id, formSpec.Code, formSpec.Title, formSpec.Abstract, formSpec.Version, formSpec.FormSpecVersion, formSpec.Steps, formSpec.CategoryTags, formSpec.Score, formSpec.AssociatedCodes, formSpec.RequiresReview, formSpec.RequiresReviewAndApproval, pathway);
479
- }
480
-
481
- /**
482
- * Extract form field data from DynamicFormResultData in TypeScript-friendly format
483
- * TypeScript: getFieldDataFromFormResult(formData: DynamicFormResultData, stepOrder: number, fieldKey: string)
484
- */
485
- export function getFieldDataFromFormResult(formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>, stepOrder: int32, fieldKeyString: string): Option<any> {
486
- const fieldKey: Shared_FieldKey = new Shared_FieldKey(parse(fieldKeyString));
487
- const matchValue: Option<FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>> = tryFind_1<Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>>(new Values_StepOrder(stepOrder), formData.ResultSteps);
488
- if (matchValue == null) {
489
- return undefined;
490
- }
491
- else {
492
- const matchValue_1: Option<Values_FieldDetails$1<Spec_FieldType_$union>> = tryFind_1<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>(fieldKey, value_11(matchValue));
493
- if (matchValue_1 == null) {
494
- return undefined;
495
- }
496
- else {
497
- const fieldDetails: Values_FieldDetails$1<Spec_FieldType_$union> = value_11(matchValue_1);
498
- return some({
499
- FieldOrder: fieldDetails.FieldOrder,
500
- FieldType: fieldDetails.FieldType,
501
- FieldValue: fieldDetails.FieldValue,
502
- Key: fieldKeyString,
503
- Label: fieldDetails.Label,
504
- });
505
- }
506
- }
507
- }
508
-
509
- /**
510
- * Get all step orders from DynamicFormResultData
511
- * TypeScript: getFormResultStepOrders(formData: DynamicFormResultData)
512
- */
513
- export function getFormResultStepOrders(formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): int32[] {
514
- const collection: Iterable<int32> = map_1<[Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>], int32>((tupledArg: [Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>]): int32 => tupledArg[0].fields[0], toSeq<Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>>(formData.ResultSteps));
515
- return Array.from(collection);
516
- }
517
-
518
- /**
519
- * Get all field keys for a specific step from DynamicFormResultData
520
- * TypeScript: getFormResultFieldKeys(formData: DynamicFormResultData, stepOrder: number)
521
- */
522
- export function getFormResultFieldKeys(formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>, stepOrder: int32): string[] {
523
- const matchValue: Option<FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>> = tryFind_1<Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>>(new Values_StepOrder(stepOrder), formData.ResultSteps);
524
- if (matchValue == null) {
525
- return [];
526
- }
527
- else {
528
- const collection: Iterable<string> = map_1<Shared_FieldKey, string>((_arg: Shared_FieldKey): string => _arg.fields[0], map_1<[Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>], Shared_FieldKey>((tuple: [Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>]): Shared_FieldKey => tuple[0], toSeq<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>(value_11(matchValue))));
529
- return Array.from(collection);
530
- }
531
- }
532
-
533
- /**
534
- * Get the ResultSteps as a TypeScript-friendly structure
535
- * TypeScript: getResultSteps(formResult: DynamicFormResultData)
536
- */
537
- export function getResultSteps(formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): any {
538
- return formData.ResultSteps;
539
- }
540
-
541
- /**
542
- * Get a specific field value from the result
543
- * TypeScript: getFieldValue(formResult: DynamicFormResultData, stepOrder: number, fieldKey: string)
544
- */
545
- export function getFieldValue(formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>, stepOrder: int32, fieldKeyString: string): Option<any> {
546
- const fieldKey: Shared_FieldKey = new Shared_FieldKey(parse(fieldKeyString));
547
- const matchValue: Option<FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>> = tryFind_1<Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>>(new Values_StepOrder(stepOrder), formData.ResultSteps);
548
- if (matchValue == null) {
549
- return undefined;
550
- }
551
- else {
552
- const matchValue_1: Option<Values_FieldDetails$1<Spec_FieldType_$union>> = tryFind_1<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>(fieldKey, value_11(matchValue));
553
- if (matchValue_1 == null) {
554
- return undefined;
555
- }
556
- else {
557
- return some(value_11(matchValue_1).FieldValue);
558
- }
559
- }
560
- }
561
-
562
- /**
563
- * Get complete field details from the result
564
- * TypeScript: getFieldDetails(formResult: DynamicFormResultData, stepOrder: number, fieldKey: string)
565
- */
566
- export function getFieldDetails(formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>, stepOrder: int32, fieldKeyString: string): Option<any> {
567
- const fieldKey: Shared_FieldKey = new Shared_FieldKey(parse(fieldKeyString));
568
- const matchValue: Option<FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>> = tryFind_1<Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>>(new Values_StepOrder(stepOrder), formData.ResultSteps);
569
- if (matchValue == null) {
570
- return undefined;
571
- }
572
- else {
573
- const matchValue_1: Option<Values_FieldDetails$1<Spec_FieldType_$union>> = tryFind_1<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>(fieldKey, value_11(matchValue));
574
- if (matchValue_1 == null) {
575
- return undefined;
576
- }
577
- else {
578
- return some(value_11(matchValue_1));
579
- }
580
- }
581
- }
582
-
583
- /**
584
- * Create a complete test FormSpec for buildDynamicFormResultData testing
585
- * TypeScript: createTestFormSpec()
586
- */
587
- export function createTestFormSpec(): Spec_FormSpec$1<Spec_FieldType_$union> {
588
- const option1: Shared_FieldOption = new Shared_FieldOption("Option 1", "opt1", new Shared_FieldOptionKey(newGuid()));
589
- const option2: Shared_FieldOption = new Shared_FieldOption("Option 2", "opt2", new Shared_FieldOptionKey(newGuid()));
590
- const testStep: Spec_FormStep$1<Spec_FieldType_$union> = new Spec_FormStep$1(1, "Test Step", ofArray_1([new Spec_FormField$1(1, new Shared_FieldKey("11111111-1111-1111-1111-111111111111"), "Test Text Field", undefined, undefined, false, false, Spec_FieldType_Text(new Spec_TextInfo(undefined))), new Spec_FormField$1(2, new Shared_FieldKey("22222222-2222-2222-2222-222222222222"), "Test Checkbox List", undefined, undefined, false, false, Spec_FieldType_CheckboxList(new Spec_MultiChoiceInfo(ofArray_1([option1, option2])))), new Spec_FormField$1(3, new Shared_FieldKey("33333333-3333-3333-3333-333333333333"), "Test Matrix", undefined, undefined, false, false, Spec_FieldType_Matrix(new Spec_MatrixInfo(ofArray_1([option1, option2]), ofArray_1([new Shared_FieldOption("Scale 1", "1", new Shared_FieldOptionKey(newGuid())), new Shared_FieldOption("Scale 2", "2", new Shared_FieldOptionKey(newGuid()))])))), new Spec_FormField$1(4, new Shared_FieldKey("44444444-4444-4444-4444-444444444444"), "Test Plugin Field", undefined, undefined, false, false, Spec_FieldType_PluginField(new Spec_PluginFieldConfig("test.plugin", "Test Plugin")))]));
591
- return new Spec_FormSpec$1(newGuid(), "TEST-001", "Test Form", "Test form for buildDynamicFormResultData", "1.0.0", "5.0.0", singleton(testStep), empty<string>(), undefined, empty<string>(), false, false, undefined);
592
- }
593
-
594
- /**
595
- * Safe pathway execution initialization wrapper
596
- * TypeScript: initializePathwayExecution(formSpec: FormSpec, pathway: ClinicalPathwaySpec, formData: DynamicFormResultData)
597
- */
598
- export function initializePathwayExecution(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, pathway: ClinicalPathway_ClinicalPathwaySpec, formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): any {
599
- try {
600
- return initializeExecution<Spec_FieldType_$union>(formSpec, formData);
601
- }
602
- catch (ex: any) {
603
- return {
604
- ErrorMessage: ex.message,
605
- ErrorType: "Exception",
606
- IsError: true,
607
- };
608
- }
609
- }
610
-
611
- /**
612
- * Get field type information in TypeScript-friendly format
613
- * TypeScript: getFieldTypeInfo(field: FormField) => {typeName: string, isRequired: boolean}
614
- */
615
- export function getFieldTypeInfo(field: Spec_FormField$1<Spec_FieldType_$union>): { isRequired: boolean, typeName: string } {
616
- let matchValue: Spec_FieldType_$union;
617
- return {
618
- isRequired: !field.IsOptional,
619
- typeName: (matchValue = field.FieldType, (matchValue.tag === /* TextArea */ 1) ? "TextArea" : ((matchValue.tag === /* Email */ 2) ? "Email" : ((matchValue.tag === /* Password */ 3) ? "Password" : ((matchValue.tag === /* Search */ 4) ? "Search" : ((matchValue.tag === /* Color */ 5) ? "Color" : ((matchValue.tag === /* Number */ 6) ? "Number" : ((matchValue.tag === /* Tel */ 7) ? "Tel" : ((matchValue.tag === /* Date */ 8) ? "Date" : ((matchValue.tag === /* DateTimeLocal */ 9) ? "DateTimeLocal" : ((matchValue.tag === /* Time */ 10) ? "Time" : ((matchValue.tag === /* Checkbox */ 11) ? "Checkbox" : ((matchValue.tag === /* Radio */ 12) ? "Radio" : ((matchValue.tag === /* SingleChoice */ 13) ? "SingleChoice" : ((matchValue.tag === /* Dropdown */ 14) ? "Dropdown" : ((matchValue.tag === /* TextAutoComplete */ 18) ? "TextAutoComplete" : ((matchValue.tag === /* MultiChoice */ 15) ? "MultiChoice" : ((matchValue.tag === /* CheckboxList */ 16) ? "CheckboxList" : ((matchValue.tag === /* TagList */ 17) ? "TagList" : ((matchValue.tag === /* Matrix */ 19) ? "Matrix" : ((matchValue.tag === /* Signature */ 20) ? "Signature" : ((matchValue.tag === /* Message */ 21) ? "Message" : ((matchValue.tag === /* PluginField */ 22) ? "PluginField" : "Text")))))))))))))))))))))),
620
- };
621
- }
622
-
623
- /**
624
- * Extract choice options from fields that support them
625
- * TypeScript: getFieldChoiceOptions(field: FormField) => {key: string, label: string, value: string}[] | null
626
- */
627
- export function getFieldChoiceOptions(field: Spec_FormField$1<Spec_FieldType_$union>): Option<{ key: string, label: string, value: string }[]> {
628
- let collection: FSharpList<{ key: string, label: string, value: string }>, collection_1: FSharpList<{ key: string, label: string, value: string }>, collection_2: FSharpList<{ key: string, label: string, value: string }>, collection_3: FSharpList<{ key: string, label: string, value: string }>, collection_4: FSharpList<{ key: string, label: string, value: string }>, collection_5: FSharpList<{ key: string, label: string, value: string }>, collection_6: FSharpList<{ key: string, label: string, value: string }>;
629
- const matchValue: Spec_FieldType_$union = field.FieldType;
630
- switch (matchValue.tag) {
631
- case /* Radio */ 12:
632
- return (collection = map_2<Shared_FieldOption, { key: string, label: string, value: string }>((opt: Shared_FieldOption): { key: string, label: string, value: string } => ({
633
- key: opt.OptionKey.fields[0],
634
- label: opt.Description,
635
- value: opt.Value,
636
- }), matchValue.fields[0].Options), Array.from(collection));
637
- case /* SingleChoice */ 13:
638
- return (collection_1 = map_2<Shared_FieldOption, { key: string, label: string, value: string }>((opt_1: Shared_FieldOption): { key: string, label: string, value: string } => ({
639
- key: opt_1.OptionKey.fields[0],
640
- label: opt_1.Description,
641
- value: opt_1.Value,
642
- }), matchValue.fields[0].Options), Array.from(collection_1));
643
- case /* Dropdown */ 14:
644
- return (collection_2 = map_2<Shared_FieldOption, { key: string, label: string, value: string }>((opt_2: Shared_FieldOption): { key: string, label: string, value: string } => ({
645
- key: opt_2.OptionKey.fields[0],
646
- label: opt_2.Description,
647
- value: opt_2.Value,
648
- }), matchValue.fields[0].Options), Array.from(collection_2));
649
- case /* MultiChoice */ 15:
650
- return (collection_3 = map_2<Shared_FieldOption, { key: string, label: string, value: string }>((opt_3: Shared_FieldOption): { key: string, label: string, value: string } => ({
651
- key: opt_3.OptionKey.fields[0],
652
- label: opt_3.Description,
653
- value: opt_3.Value,
654
- }), matchValue.fields[0].Options), Array.from(collection_3));
655
- case /* CheckboxList */ 16:
656
- return (collection_4 = map_2<Shared_FieldOption, { key: string, label: string, value: string }>((opt_4: Shared_FieldOption): { key: string, label: string, value: string } => ({
657
- key: opt_4.OptionKey.fields[0],
658
- label: opt_4.Description,
659
- value: opt_4.Value,
660
- }), matchValue.fields[0].Options), Array.from(collection_4));
661
- case /* TagList */ 17:
662
- return (collection_5 = map_2<Shared_FieldOption, { key: string, label: string, value: string }>((opt_5: Shared_FieldOption): { key: string, label: string, value: string } => ({
663
- key: opt_5.OptionKey.fields[0],
664
- label: opt_5.Description,
665
- value: opt_5.Value,
666
- }), matchValue.fields[0].Options), Array.from(collection_5));
667
- case /* TextAutoComplete */ 18:
668
- return (collection_6 = map_2<Shared_FieldOption, { key: string, label: string, value: string }>((opt_6: Shared_FieldOption): { key: string, label: string, value: string } => ({
669
- key: opt_6.OptionKey.fields[0],
670
- label: opt_6.Description,
671
- value: opt_6.Value,
672
- }), matchValue.fields[0].Options), Array.from(collection_6));
673
- default:
674
- return undefined;
675
- }
676
- }
677
-
678
- /**
679
- * Extract matrix field structure (items and options)
680
- * TypeScript: getFieldMatrixInfo(field: FormField) => {items: {key: string, label: string}[], options: {key: string, description: string, value: string}[]} | null
681
- */
682
- export function getFieldMatrixInfo(field: Spec_FormField$1<Spec_FieldType_$union>): Option<{ items: { key: string, label: string }[], options: { description: string, key: string, value: string }[] }> {
683
- let collection: FSharpList<{ key: string, label: string }>, collection_1: FSharpList<{ description: string, key: string, value: string }>;
684
- const matchValue: Spec_FieldType_$union = field.FieldType;
685
- if (matchValue.tag === /* Matrix */ 19) {
686
- const matrixInfo: Spec_MatrixInfo = matchValue.fields[0];
687
- return {
688
- items: (collection = map_2<Shared_FieldOption, { key: string, label: string }>((item: Shared_FieldOption): { key: string, label: string } => ({
689
- key: item.OptionKey.fields[0],
690
- label: item.Description,
691
- }), matrixInfo.Items), Array.from(collection)),
692
- options: (collection_1 = map_2<Shared_FieldOption, { description: string, key: string, value: string }>((opt: Shared_FieldOption): { description: string, key: string, value: string } => ({
693
- description: opt.Description,
694
- key: opt.OptionKey.fields[0],
695
- value: opt.Value,
696
- }), matrixInfo.Options), Array.from(collection_1)),
697
- };
698
- }
699
- else {
700
- return undefined;
701
- }
702
- }
703
-
704
- /**
705
- * Extract GUID string from FieldKey (single-case DU)
706
- * TypeScript: getFieldKeyString(fieldKey: FieldKey) => string
707
- */
708
- export function getFieldKeyString(fieldKey: Shared_FieldKey): string {
709
- return fieldKey.fields[0];
710
- }
711
-
712
- /**
713
- * Convert ClinicalPathway ActionInfo to TypeScript-friendly objects
714
- * TypeScript: convertActionInfo(action: ActionInfo) => {type: string, description: string, ...}
715
- */
716
- export function convertActionInfo(action: ClinicalPathway_ActionInfo_$union): any {
717
- let matchValue_1: ClinicalPathway_ReferralUrgency_$union, matchValue_3: ClinicalPathway_AlertSeverity_$union, matchValue: ClinicalPathway_TaskPriority_$union;
718
- switch (action.tag) {
719
- case /* Referral */ 2: {
720
- const referral: ClinicalPathway_ReferralAction = action.fields[0];
721
- return {
722
- description: `Refer to ${referral.Target}`,
723
- reason: referral.Reason,
724
- type: "referral",
725
- urgency: (matchValue_1 = referral.Urgency, (matchValue_1.tag === /* Routine */ 1) ? (`routine-${matchValue_1.fields[0]}`) : ((matchValue_1.tag === /* AsNeeded */ 2) ? "asNeeded" : "immediate")),
726
- };
727
- }
728
- case /* Medication */ 0: {
729
- const med: ClinicalPathway_MedicationAction = action.fields[0];
730
- return {
731
- description: `${med.Name} - ${med.Dose} ${med.Route}`,
732
- dose: med.Dose,
733
- duration: med.Duration,
734
- frequency: med.Frequency,
735
- medicationName: med.Name,
736
- route: med.Route,
737
- type: "medication",
738
- };
739
- }
740
- case /* Prescription */ 9: {
741
- const presc: ClinicalPathway_PrescriptionAction = action.fields[0];
742
- return {
743
- description: `${presc.Medication} - ${presc.Dose} ${presc.Route}`,
744
- dose: presc.Dose,
745
- duration: presc.Duration,
746
- frequency: presc.Frequency,
747
- medication: presc.Medication,
748
- quantity: presc.Quantity,
749
- route: presc.Route,
750
- type: "prescription",
751
- };
752
- }
753
- case /* SetFieldValue */ 10: {
754
- const setField: ClinicalPathway_SetFieldValueAction = action.fields[0];
755
- let valueStr: string;
756
- const matchValue_2: ClinicalPathway_FieldValueSource_$union = setField.Value;
757
- valueStr = ((matchValue_2.tag === /* FieldReference */ 1) ? (`Reference to ${matchValue_2.fields[0].fields[0]}`) : ((matchValue_2.tag === /* OptionKey */ 2) ? (`Option ${matchValue_2.fields[0].fields[0]}`) : matchValue_2.fields[0]));
758
- const fieldGuid: string = setField.TargetField.fields[0];
759
- return {
760
- description: `Set field ${fieldGuid} to ${valueStr}`,
761
- fieldKey: fieldGuid,
762
- type: "setFieldValue",
763
- value: valueStr,
764
- };
765
- }
766
- case /* Documentation */ 5: {
767
- const doc: ClinicalPathway_DocumentationAction = action.fields[0];
768
- return {
769
- description: `Document: ${doc.FormName}`,
770
- formName: doc.FormName,
771
- purpose: doc.Purpose,
772
- required: doc.Required,
773
- type: "documentation",
774
- };
775
- }
776
- case /* Test */ 1: {
777
- const test: ClinicalPathway_TestAction = action.fields[0];
778
- return {
779
- description: `${test.TestName} (${test.TestType})`,
780
- testName: test.TestName,
781
- testType: test.TestType,
782
- type: "test",
783
- };
784
- }
785
- case /* Procedure */ 4: {
786
- const proc: ClinicalPathway_ProcedureAction = action.fields[0];
787
- return {
788
- description: `${proc.Name}: ${proc.Description}`,
789
- procedureDescription: proc.Description,
790
- procedureName: proc.Name,
791
- type: "procedure",
792
- };
793
- }
794
- case /* Education */ 3: {
795
- const edu: ClinicalPathway_EducationAction = action.fields[0];
796
- return {
797
- description: `Education: ${join(", ", edu.Topics)}`,
798
- topics: edu.Topics,
799
- type: "education",
800
- };
801
- }
802
- case /* Alert */ 7: {
803
- const alert: ClinicalPathway_AlertAction = action.fields[0];
804
- return {
805
- category: alert.Category,
806
- description: alert.Message,
807
- severity: (matchValue_3 = alert.Severity, (matchValue_3.tag === /* High */ 2) ? "high" : ((matchValue_3.tag === /* Medium */ 1) ? "medium" : ((matchValue_3.tag === /* Low */ 0) ? "low" : "critical"))),
808
- type: "alert",
809
- };
810
- }
811
- case /* Problem */ 8: {
812
- const prob: ClinicalPathway_ProblemAction = action.fields[0];
813
- return {
814
- description: `${prob.ProblemName}${defaultArg_1(map_3<string, string>((code: string): string => (` (ICD: ${code})`), prob.IcdCode), "")}`,
815
- icdCode: unwrap(prob.IcdCode),
816
- problemName: prob.ProblemName,
817
- type: "problem",
818
- };
819
- }
820
- case /* NavigateToForm */ 11: {
821
- const nav: ClinicalPathway_NavigateToFormAction = action.fields[0];
822
- const formCode: string = defaultArg_1(nav.FormCode, nav.FormId);
823
- return {
824
- description: `Navigate to form: ${formCode}`,
825
- formCode: formCode,
826
- type: "navigateToForm",
827
- };
828
- }
829
- default: {
830
- const task: ClinicalPathway_TaskAction = action.fields[0];
831
- return {
832
- category: task.Category,
833
- description: task.Description,
834
- priority: (matchValue = task.Priority, (matchValue.tag === /* Medium */ 1) ? "medium" : ((matchValue.tag === /* Low */ 2) ? "low" : "high")),
835
- type: "task",
836
- };
837
- }
838
- }
839
- }
840
-
841
- /**
842
- * Find the StateKey for a given ActionInfo in a ClinicalPathwaySpec
843
- * TypeScript: stateKeyForAction(pathway: ClinicalPathwaySpec, action: ActionInfo) => string | null
844
- */
845
- export function stateKeyForAction(pathway: ClinicalPathway_ClinicalPathwaySpec, action: ClinicalPathway_ActionInfo_$union): Option<string> {
846
- toConsole(printf("PathwayId: %A"))(pathway.PathwayId);
847
- toConsole(printf("Finding state key for action: %A"))(action);
848
- return tryPick<ClinicalPathway_StateDefinition, string>((state: ClinicalPathway_StateDefinition): Option<string> => {
849
- const matchValue: ClinicalPathway_StateType_$union = state.StateType;
850
- let matchResult: int32, actionInfo_1: ClinicalPathway_ActionInfo_$union;
851
- if (matchValue.tag === /* Action */ 2) {
852
- if (equals(matchValue.fields[0], action)) {
853
- matchResult = 0;
854
- actionInfo_1 = matchValue.fields[0];
855
- }
856
- else {
857
- matchResult = 1;
858
- }
859
- }
860
- else {
861
- matchResult = 1;
862
- }
863
- switch (matchResult) {
864
- case 0:
865
- return state.StateKey.fields[0];
866
- default:
867
- return undefined;
868
- }
869
- }, pathway.States);
870
- }
871
-
872
- //# sourceMappingURL=FormSpec.Api.Helpers.ts.map
1
+ import { value as value_11, map, unwrap, defaultArgWith as defaultArgWith_1, Option, defaultArg as defaultArg_1 } from "@fable-org/fable-library-js/Option.js";
2
+ import { tryPick, singleton, map as map_3, empty, ofArray as ofArray_1, ofSeq, fold, collect, tryFind, FSharpList } from "@fable-org/fable-library-js/List.js";
3
+ import { join, printf, toConsole } from "@fable-org/fable-library-js/String.js";
4
+ import { Auto_generateBoxedEncoder_437914C6, toString } from "../fable_modules/Thoth.Json.10.4.1/Encode.fs.js";
5
+ import { array_type, string_type, union_type, TypeInfo, obj_type } from "@fable-org/fable-library-js/Reflection.js";
6
+ import { Auto_generateBoxedDecoder_Z6670B51, fromString } from "../fable_modules/Thoth.Json.10.4.1/Decode.fs.js";
7
+ import { equals, compare, IDisposable, disposeSafe, IEnumerator, getEnumerator, IMap, isArrayLike, uncurry2 } from "@fable-org/fable-library-js/Util.js";
8
+ import { ClinicalPathway_StateType_$union, ClinicalPathway_TaskPriority_$union, ClinicalPathway_AlertSeverity_$union, ClinicalPathway_ReferralUrgency_$union, ClinicalPathway_ActionInfo_$union, ClinicalPathway_NavigateToFormAction, ClinicalPathway_ProblemAction, ClinicalPathway_AlertAction, ClinicalPathway_EducationAction, ClinicalPathway_ProcedureAction, ClinicalPathway_TestAction, ClinicalPathway_DocumentationAction, ClinicalPathway_FieldValueSource_$union, ClinicalPathway_SetFieldValueAction, ClinicalPathway_PrescriptionAction, ClinicalPathway_MedicationAction, ClinicalPathway_ReferralAction, ClinicalPathway_ClinicalPathwaySpec, ClinicalPathway_PathRequirement, ClinicalPathway_ConstraintDefinition, ClinicalPathway_PathwayExecutionMode_SinglePathway, ClinicalPathway_SinglePathwayConfig, ClinicalPathway_SelectionStrategy_HighestPriority, ClinicalPathway_TransitionDefinition, ClinicalPathway_TransitionCondition_FieldCondition, Shared_ConditionValue_Single, ClinicalPathway_FieldEvaluator_Equals, Shared_TransitionKey, ClinicalPathway_StateType_Terminal, ClinicalPathway_TerminalInfo, ClinicalPathway_StateDefinition, ClinicalPathway_StateType_Action, ClinicalPathway_ActionInfo_Task, ClinicalPathway_TaskAction, ClinicalPathway_DueDate_Today, ClinicalPathway_TaskPriority_Medium, ClinicalPathway_TaskPriority_Low, ClinicalPathway_TaskPriority_High, Shared_StateKey, Spec_FieldType_PluginField, Spec_PluginFieldConfig, Spec_FieldType_Matrix, Spec_MatrixInfo, Spec_FormLifecycle_Blueprint, Spec_FieldType_Text, Spec_TextInfo, Spec_FieldType_CheckboxList, Spec_MultiChoiceInfo, Shared_FieldOptionKey, Spec_FieldType_Checkbox, Spec_BooleanInfo, Shared_FieldKey, Shared_FieldOption, Shared_FieldValue_Single, Shared_FieldValue_PluginData, Shared_PluginDataProperty, Shared_PluginPropertyKey, Shared_FieldValue_Matrix, Shared_MatrixAnswer, Shared_MatrixItemKey, Shared_FieldValue_Multiple, Shared_FieldAnswer, Spec_FormStep$1, Spec_FormField$1, Spec_FieldType_$union, Spec_FormSpec$1, Spec_FormSpec$1_$reflection, Spec_FieldType_$reflection } from "../FormSpec.js";
9
+ import { FSharpResult$2_Ok, FSharpResult$2_Error, FSharpResult$2_$union } from "@fable-org/fable-library-js/Result.js";
10
+ import { Union } from "@fable-org/fable-library-js/Types.js";
11
+ import { IOptionalGetter, array as array_4, IGetters, dict, string, IRequiredGetter, object, fromString as fromString_1 } from "../fable_modules/Thoth.Json.10.4.1/Decode.fs.js";
12
+ import { ErrorReason_$union } from "../fable_modules/Thoth.Json.10.4.1/Types.fs.js";
13
+ import { ofSeq as ofSeq_1, FSharpMap } from "@fable-org/fable-library-js/Map.js";
14
+ import { addToDict } from "@fable-org/fable-library-js/MapUtil.js";
15
+ import { getFieldDetails as getFieldDetails_1, FieldDetails$1, findStepIndexForField, updateField } from "../FormSpecValues.js";
16
+ import { int32 } from "@fable-org/fable-library-js/Int32.js";
17
+ import { mapIndexed, map as map_2, choose } from "@fable-org/fable-library-js/Seq.js";
18
+ import { ofArray } from "@fable-org/fable-library-js/Set.js";
19
+ import { map as map_1 } from "@fable-org/fable-library-js/Array.js";
20
+ import { newGuid, parse } from "@fable-org/fable-library-js/Guid.js";
21
+ import { now } from "@fable-org/fable-library-js/DateOffset.js";
22
+ import { initializeExecution } from "../PathwayExecutor.js";
23
+
24
+ /**
25
+ * Get value from Option or return default (SAFE - recommended)
26
+ * TypeScript: <T>(opt: Option<T>, defaultValue: T) => T
27
+ * Usage: Api.defaultArg(formSpec.Code, "unknown")
28
+ */
29
+ export function defaultArg<T>(opt: Option<T>, defaultValue: T): T {
30
+ return defaultArg_1(opt, defaultValue);
31
+ }
32
+
33
+ /**
34
+ * Get value from Option or compute default using function (SAFE - recommended)
35
+ * TypeScript: <T>(opt: Option<T>, defThunk: () => T) => T
36
+ * Usage: Api.defaultArgWith(formSpec.Code, () => "unknown")
37
+ */
38
+ export function defaultArgWith<T>(opt: Option<T>, defThunk: (() => T)): T {
39
+ return defaultArgWith_1<T>(opt, defThunk);
40
+ }
41
+
42
+ /**
43
+ * Check if Option is Some
44
+ * TypeScript: <T>(opt: Option<T>) => boolean
45
+ * Usage: if (Api.isSome(formSpec.Code)) { ... }
46
+ */
47
+ export function isSome<T>(opt: Option<T>): boolean {
48
+ return opt != null;
49
+ }
50
+
51
+ /**
52
+ * Check if Option is None
53
+ * TypeScript: <T>(opt: Option<T>) => boolean
54
+ * Usage: if (Api.isNone(formSpec.Code)) { ... }
55
+ */
56
+ export function isNone<T>(opt: Option<T>): boolean {
57
+ return opt == null;
58
+ }
59
+
60
+ export function listToArray<T>(list: FSharpList<T>): T[] {
61
+ return Array.from(list);
62
+ }
63
+
64
+ export function serializeFormSpec(formSpec: any): string {
65
+ toConsole(printf("[API.Helpers] Serializing FormSpec!!"));
66
+ toConsole(`[API.Helpers] FormSpec: ${formSpec}`);
67
+ return toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(formSpec));
68
+ }
69
+
70
+ export function deserializeFormSpec(json: string): Option<Spec_FormSpec$1<Spec_FieldType_$union>> {
71
+ toConsole(printf("[API.Helpers] Deserializing FormSpec"));
72
+ const matchValue: FSharpResult$2_$union<Spec_FormSpec$1<Spec_FieldType_$union>, string> = fromString<Spec_FormSpec$1<Spec_FieldType_$union>>(uncurry2(Auto_generateBoxedDecoder_Z6670B51(Spec_FormSpec$1_$reflection(Spec_FieldType_$reflection()), undefined, undefined)), json);
73
+ if (matchValue.tag === /* Error */ 1) {
74
+ throw new Error(`[API.Helpers] Deserialization failed: ${matchValue.fields[0]}`);
75
+ }
76
+ else {
77
+ return matchValue.fields[0];
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Find FormField by its FieldKey string representation
83
+ */
84
+ export function findFieldByKey(spec: Spec_FormSpec$1<Spec_FieldType_$union>, fieldKeyString: string): Option<Spec_FormField$1<Spec_FieldType_$union>> {
85
+ return tryFind<Spec_FormField$1<Spec_FieldType_$union>>((field: Spec_FormField$1<Spec_FieldType_$union>): boolean => (field.FieldKey.fields[0] === fieldKeyString), collect<Spec_FormStep$1<Spec_FieldType_$union>, Spec_FormField$1<Spec_FieldType_$union>>((step: Spec_FormStep$1<Spec_FieldType_$union>): FSharpList<Spec_FormField$1<Spec_FieldType_$union>> => step.Fields, spec.Steps));
86
+ }
87
+
88
+ export type ExpectedFieldValueType_$union =
89
+ | ExpectedFieldValueType<0>
90
+ | ExpectedFieldValueType<1>
91
+ | ExpectedFieldValueType<2>
92
+ | ExpectedFieldValueType<3>
93
+
94
+ export type ExpectedFieldValueType_$cases = {
95
+ 0: ["SingleValue", []],
96
+ 1: ["MultipleValues", []],
97
+ 2: ["MatrixValue", []],
98
+ 3: ["PluginDataValue", []]
99
+ }
100
+
101
+ export function ExpectedFieldValueType_SingleValue() {
102
+ return new ExpectedFieldValueType<0>(0, []);
103
+ }
104
+
105
+ export function ExpectedFieldValueType_MultipleValues() {
106
+ return new ExpectedFieldValueType<1>(1, []);
107
+ }
108
+
109
+ export function ExpectedFieldValueType_MatrixValue() {
110
+ return new ExpectedFieldValueType<2>(2, []);
111
+ }
112
+
113
+ export function ExpectedFieldValueType_PluginDataValue() {
114
+ return new ExpectedFieldValueType<3>(3, []);
115
+ }
116
+
117
+ export class ExpectedFieldValueType<Tag extends keyof ExpectedFieldValueType_$cases> extends Union<Tag, ExpectedFieldValueType_$cases[Tag][0]> {
118
+ constructor(readonly tag: Tag, readonly fields: ExpectedFieldValueType_$cases[Tag][1]) {
119
+ super();
120
+ }
121
+ cases() {
122
+ return ["SingleValue", "MultipleValues", "MatrixValue", "PluginDataValue"];
123
+ }
124
+ }
125
+
126
+ export function ExpectedFieldValueType_$reflection(): TypeInfo {
127
+ return union_type("FormSpec.Interop.Helpers.ExpectedFieldValueType", [], ExpectedFieldValueType, () => [[], [], [], []]);
128
+ }
129
+
130
+ export function getExpectedFieldValueType(fieldType: Spec_FieldType_$union): ExpectedFieldValueType_$union {
131
+ switch (fieldType.tag) {
132
+ case /* TextArea */ 1:
133
+ return ExpectedFieldValueType_SingleValue();
134
+ case /* Email */ 2:
135
+ return ExpectedFieldValueType_SingleValue();
136
+ case /* Password */ 3:
137
+ return ExpectedFieldValueType_SingleValue();
138
+ case /* Search */ 4:
139
+ return ExpectedFieldValueType_SingleValue();
140
+ case /* Color */ 5:
141
+ return ExpectedFieldValueType_SingleValue();
142
+ case /* Number */ 6:
143
+ return ExpectedFieldValueType_SingleValue();
144
+ case /* Tel */ 7:
145
+ return ExpectedFieldValueType_SingleValue();
146
+ case /* Date */ 8:
147
+ return ExpectedFieldValueType_SingleValue();
148
+ case /* DateTimeLocal */ 9:
149
+ return ExpectedFieldValueType_SingleValue();
150
+ case /* Time */ 10:
151
+ return ExpectedFieldValueType_SingleValue();
152
+ case /* Checkbox */ 11:
153
+ return ExpectedFieldValueType_SingleValue();
154
+ case /* Radio */ 12:
155
+ return ExpectedFieldValueType_SingleValue();
156
+ case /* SingleChoice */ 13:
157
+ return ExpectedFieldValueType_SingleValue();
158
+ case /* Dropdown */ 14:
159
+ return ExpectedFieldValueType_SingleValue();
160
+ case /* TextAutoComplete */ 18:
161
+ return ExpectedFieldValueType_SingleValue();
162
+ case /* Signature */ 20:
163
+ return ExpectedFieldValueType_SingleValue();
164
+ case /* Message */ 21:
165
+ return ExpectedFieldValueType_SingleValue();
166
+ case /* CheckboxList */ 16:
167
+ return ExpectedFieldValueType_MultipleValues();
168
+ case /* MultiChoice */ 15:
169
+ return ExpectedFieldValueType_MultipleValues();
170
+ case /* TagList */ 17:
171
+ return ExpectedFieldValueType_MultipleValues();
172
+ case /* Matrix */ 19:
173
+ return ExpectedFieldValueType_MatrixValue();
174
+ case /* PluginField */ 22:
175
+ return ExpectedFieldValueType_PluginDataValue();
176
+ default:
177
+ return ExpectedFieldValueType_SingleValue();
178
+ }
179
+ }
180
+
181
+ export function decodeAsString(fieldKey: string, obj: any): string {
182
+ let matchValue: FSharpResult$2_$union<string, string>;
183
+ const json: string = toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(obj));
184
+ matchValue = fromString<string>(uncurry2(Auto_generateBoxedDecoder_Z6670B51(string_type, undefined, undefined)), json);
185
+ if (matchValue.tag === /* Error */ 1) {
186
+ if (typeof obj === "string") {
187
+ const str = obj as string;
188
+ return str;
189
+ }
190
+ else {
191
+ throw new Error(`Field ${fieldKey}: Expected string value, got ${"Object"}`);
192
+ }
193
+ }
194
+ else {
195
+ return matchValue.fields[0];
196
+ }
197
+ }
198
+
199
+ export function decodeAsStringArray(fieldKey: string, obj: any): string[] {
200
+ if (isArrayLike(obj)) {
201
+ return obj;
202
+ }
203
+ else if (isArrayLike(obj)) {
204
+ const resizeArray: string[] = obj;
205
+ return resizeArray.slice();
206
+ }
207
+ else if (typeof obj === "string") {
208
+ return [obj];
209
+ }
210
+ else {
211
+ try {
212
+ let matchValue: FSharpResult$2_$union<string[], string>;
213
+ const json: string = toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(obj));
214
+ matchValue = fromString<string[]>(uncurry2(Auto_generateBoxedDecoder_Z6670B51(array_type(string_type), undefined, undefined)), json);
215
+ if (matchValue.tag === /* Error */ 1) {
216
+ throw new Error(`Field ${fieldKey}: Expected string array, got ${"Object"}`);
217
+ }
218
+ else {
219
+ return matchValue.fields[0];
220
+ }
221
+ }
222
+ catch (ex: any) {
223
+ throw new Error(`Field ${fieldKey}: Expected string array, got ${"Object"}`);
224
+ }
225
+ }
226
+ }
227
+
228
+ export function decodeAsMatrixValue(fieldKey: string, obj: any): { description: string, values: IMap<string, string> } {
229
+ let str: string;
230
+ const objAsString: string = (typeof obj === "string") ? ((str = (obj as string), str)) : toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(obj));
231
+ try {
232
+ const matchValue_1: FSharpResult$2_$union<{ description: string, values: IMap<string, string> }, string> = fromString_1<{ description: string, values: IMap<string, string> }>((path_2: string, v: any): FSharpResult$2_$union<{ description: string, values: IMap<string, string> }, [string, ErrorReason_$union]> => object<{ description: string, values: IMap<string, string> }>((get$: IGetters): { description: string, values: IMap<string, string> } => {
233
+ let description: string;
234
+ const objectArg: IRequiredGetter = get$.Required;
235
+ description = objectArg.Field<string>("description", string);
236
+ let valuesMap: FSharpMap<string, string>;
237
+ const arg_3: ((arg0: string) => ((arg0: any) => FSharpResult$2_$union<FSharpMap<string, string>, [string, ErrorReason_$union]>)) = dict<string>(string);
238
+ const objectArg_1: IRequiredGetter = get$.Required;
239
+ valuesMap = objectArg_1.Field<FSharpMap<string, string>>("values", uncurry2(arg_3));
240
+ const valuesDict: IMap<string, string> = new Map<string, string>([]);
241
+ const enumerator: IEnumerator<[string, string]> = getEnumerator(valuesMap);
242
+ try {
243
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
244
+ const kvp: [string, string] = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
245
+ addToDict(valuesDict, kvp[0], kvp[1]);
246
+ }
247
+ }
248
+ finally {
249
+ disposeSafe(enumerator as IDisposable);
250
+ }
251
+ return {
252
+ description: description,
253
+ values: valuesDict,
254
+ };
255
+ }, path_2, v), objAsString);
256
+ if (matchValue_1.tag === /* Error */ 1) {
257
+ let matchValue_2: FSharpResult$2_$union<{ description: string, values: IMap<string, string> }, string>;
258
+ const matchValue: FSharpResult$2_$union<FSharpMap<string, string>, string> = fromString_1<FSharpMap<string, string>>(uncurry2(dict<string>(string)), objAsString);
259
+ if (matchValue.tag === /* Error */ 1) {
260
+ matchValue_2 = FSharpResult$2_Error<{ description: string, values: IMap<string, string> }, string>("Not a plain key-value object");
261
+ }
262
+ else {
263
+ const valuesMap_1: FSharpMap<string, string> = matchValue.fields[0];
264
+ const valuesDict_1: IMap<string, string> = new Map<string, string>([]);
265
+ const enumerator_1: IEnumerator<[string, string]> = getEnumerator(valuesMap_1);
266
+ try {
267
+ while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
268
+ const kvp_1: [string, string] = enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]();
269
+ addToDict(valuesDict_1, kvp_1[0], kvp_1[1]);
270
+ }
271
+ }
272
+ finally {
273
+ disposeSafe(enumerator_1 as IDisposable);
274
+ }
275
+ matchValue_2 = FSharpResult$2_Ok<{ description: string, values: IMap<string, string> }, string>({
276
+ description: "",
277
+ values: valuesDict_1,
278
+ });
279
+ }
280
+ if (matchValue_2.tag === /* Error */ 1) {
281
+ throw new Error(`Field ${fieldKey}: Invalid matrix data format - ${matchValue_2.fields[0]}`);
282
+ }
283
+ else {
284
+ return matchValue_2.fields[0];
285
+ }
286
+ }
287
+ else {
288
+ return matchValue_1.fields[0];
289
+ }
290
+ }
291
+ catch (ex: any) {
292
+ throw new Error(`Field ${fieldKey}: Failed to decode matrix value - ${ex.message}`);
293
+ }
294
+ }
295
+
296
+ export function decodeAsPluginDataArray(fieldKey: string, obj: any): { dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }[] {
297
+ let str: string;
298
+ const objAsString: string = (typeof obj === "string") ? ((str = (obj as string), str)) : toString(0, Auto_generateBoxedEncoder_437914C6(obj_type, undefined, undefined, undefined)(obj));
299
+ try {
300
+ const matchValue: FSharpResult$2_$union<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }[], string> = fromString_1<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }[]>((path_8: string, value_10: any): FSharpResult$2_$union<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }[], [string, ErrorReason_$union]> => array_4<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }>((path_7: string, v: any): FSharpResult$2_$union<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }, [string, ErrorReason_$union]> => object<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }>((get$: IGetters): { dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string } => {
301
+ let objectArg_6: IOptionalGetter;
302
+ let propertyKey: string;
303
+ const objectArg: IRequiredGetter = get$.Required;
304
+ propertyKey = objectArg.Field<string>("propertyKey", string);
305
+ let name: string;
306
+ const objectArg_1: IRequiredGetter = get$.Required;
307
+ name = objectArg_1.Field<string>("name", string);
308
+ let dataType: string;
309
+ const objectArg_2: IRequiredGetter = get$.Required;
310
+ dataType = objectArg_2.Field<string>("dataType", string);
311
+ let value_6: string;
312
+ const objectArg_3: IRequiredGetter = get$.Required;
313
+ value_6 = objectArg_3.Field<string>("value", string);
314
+ let displayName: Option<string>;
315
+ const objectArg_4: IOptionalGetter = get$.Optional;
316
+ displayName = objectArg_4.Field<string>("displayName", string);
317
+ let unit: Option<string>;
318
+ const objectArg_5: IOptionalGetter = get$.Optional;
319
+ unit = objectArg_5.Field<string>("unit", string);
320
+ return {
321
+ dataType: dataType,
322
+ description: unwrap((objectArg_6 = get$.Optional, objectArg_6.Field<string>("description", string))),
323
+ displayName: unwrap(displayName),
324
+ name: name,
325
+ propertyKey: propertyKey,
326
+ unit: unwrap(unit),
327
+ value: value_6,
328
+ };
329
+ }, path_7, v), path_8, value_10), objAsString);
330
+ if (matchValue.tag === /* Error */ 1) {
331
+ throw new Error(`Field ${fieldKey}: Invalid plugin data format - ${matchValue.fields[0]}`);
332
+ }
333
+ else {
334
+ return matchValue.fields[0];
335
+ }
336
+ }
337
+ catch (ex: any) {
338
+ throw new Error(`Field ${fieldKey}: Failed to decode plugin data - ${ex.message}`);
339
+ }
340
+ }
341
+
342
+ export function createFormFieldData(fieldKey: string, objectValue: any): { fieldKey: string, objectValue: any } {
343
+ return {
344
+ fieldKey: fieldKey,
345
+ objectValue: objectValue,
346
+ };
347
+ }
348
+
349
+ /**
350
+ * Build FormSpec with field values applied. Primary API - pathway uses FormSpec directly.
351
+ * TypeScript: buildFormSpecWithValues(formSpec: FormSpec, fieldData: FieldInput[]) => FormSpec
352
+ */
353
+ export function buildFormSpecWithValues(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, fieldData: { fieldKey: string, objectValue: any }[]): Spec_FormSpec$1<Spec_FieldType_$union> {
354
+ return fold<[Spec_FormField$1<Spec_FieldType_$union>, FieldDetails$1<Spec_FieldType_$union>], Spec_FormSpec$1<Spec_FieldType_$union>>((spec: Spec_FormSpec$1<Spec_FieldType_$union>, tupledArg: [Spec_FormField$1<Spec_FieldType_$union>, FieldDetails$1<Spec_FieldType_$union>]): Spec_FormSpec$1<Spec_FieldType_$union> => {
355
+ const field_1: Spec_FormField$1<Spec_FieldType_$union> = tupledArg[0];
356
+ return defaultArg_1(map<int32, Spec_FormSpec$1<Spec_FieldType_$union>>((stepIdx: int32): Spec_FormSpec$1<Spec_FieldType_$union> => updateField<Spec_FieldType_$union>(spec, field_1.FieldKey, tupledArg[1].FieldValue, stepIdx), findStepIndexForField<Spec_FieldType_$union>(spec, field_1.FieldKey)), spec);
357
+ }, formSpec, ofSeq<[Spec_FormField$1<Spec_FieldType_$union>, FieldDetails$1<Spec_FieldType_$union>]>(choose<{ fieldKey: string, objectValue: any }, [Spec_FormField$1<Spec_FieldType_$union>, FieldDetails$1<Spec_FieldType_$union>]>((input: { fieldKey: string, objectValue: any }): Option<[Spec_FormField$1<Spec_FieldType_$union>, FieldDetails$1<Spec_FieldType_$union>]> => {
358
+ let matchValue_1: ExpectedFieldValueType_$union, matrixData: { description: string, values: IMap<string, string> }, matchValue_2: Spec_FieldType_$union;
359
+ const matchValue: Option<Spec_FormField$1<Spec_FieldType_$union>> = findFieldByKey(formSpec, input.fieldKey);
360
+ if (matchValue == null) {
361
+ toConsole(`Warning: Field ${input.fieldKey} not found in FormSpec`);
362
+ return undefined;
363
+ }
364
+ else {
365
+ const field: Spec_FormField$1<Spec_FieldType_$union> = value_11(matchValue);
366
+ try {
367
+ return [field, new FieldDetails$1(field.FieldOrder, field.FieldKey, field.Label, (matchValue_1 = getExpectedFieldValueType(field.FieldType), (matchValue_1.tag === /* MultipleValues */ 1) ? Shared_FieldValue_Multiple(ofArray<Shared_FieldAnswer>(map_1<string, Shared_FieldAnswer>((value: string): Shared_FieldAnswer => (new Shared_FieldAnswer(field.FieldKey, field.Label, value)), decodeAsStringArray(input.fieldKey, input.objectValue)), {
368
+ Compare: compare,
369
+ })) : ((matchValue_1.tag === /* MatrixValue */ 2) ? ((matrixData = decodeAsMatrixValue(input.fieldKey, input.objectValue), Shared_FieldValue_Matrix(new Shared_MatrixAnswer(field.FieldKey, matrixData.description, ofSeq_1<Shared_MatrixItemKey, string>(map_2<[string, string], [Shared_MatrixItemKey, string]>((kvp: [string, string]): [Shared_MatrixItemKey, string] => ([new Shared_MatrixItemKey(parse(kvp[0])), kvp[1]] as [Shared_MatrixItemKey, string]), matrixData.values), {
370
+ Compare: compare,
371
+ }))))) : ((matchValue_1.tag === /* PluginDataValue */ 3) ? Shared_FieldValue_PluginData(ofArray_1<Shared_PluginDataProperty>(map_1<{ dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }, Shared_PluginDataProperty>((prop: { dataType: string, description?: string, displayName?: string, name: string, propertyKey: string, unit?: string, value: string }): Shared_PluginDataProperty => (new Shared_PluginDataProperty(new Shared_PluginPropertyKey(parse(prop.propertyKey)), prop.name, prop.dataType, prop.value, prop.displayName, prop.unit, prop.description)), decodeAsPluginDataArray(input.fieldKey, input.objectValue)))) : Shared_FieldValue_Single(new Shared_FieldAnswer(field.FieldKey, field.Label, decodeAsString(input.fieldKey, input.objectValue)))))), field.FieldType, (matchValue_2 = field.FieldType, (matchValue_2.tag === /* Radio */ 12) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* SingleChoice */ 13) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* Dropdown */ 14) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* MultiChoice */ 15) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* CheckboxList */ 16) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* TagList */ 17) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* TextAutoComplete */ 18) ? matchValue_2.fields[0].Options : ((matchValue_2.tag === /* Matrix */ 19) ? matchValue_2.fields[0].Options : empty<Shared_FieldOption>())))))))))] as [Spec_FormField$1<Spec_FieldType_$union>, FieldDetails$1<Spec_FieldType_$union>];
372
+ }
373
+ catch (ex: any) {
374
+ toConsole(`Error processing field ${input.fieldKey}: ${ex.message}`);
375
+ return undefined;
376
+ }
377
+ }
378
+ }, fieldData)));
379
+ }
380
+
381
+ /**
382
+ * Create a checkbox field with the given parameters
383
+ * TypeScript: createCheckboxField(fieldKey: string, label: string, isOptional: boolean)
384
+ */
385
+ export function createCheckboxField(fieldKeyString: string, label: string, isOptional: boolean): Spec_FormField$1<Spec_FieldType_$union> {
386
+ return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, isOptional, false, Spec_FieldType_Checkbox(new Spec_BooleanInfo(undefined, undefined)), undefined);
387
+ }
388
+
389
+ /**
390
+ * Create a checkbox list field with options
391
+ * TypeScript: createCheckboxListField(fieldKey: string, label: string, options: {value: string, description: string, optionKey: string}[])
392
+ */
393
+ export function createCheckboxListField(fieldKeyString: string, label: string, options: { description: string, optionKey: string, value: string }[]): Spec_FormField$1<Spec_FieldType_$union> {
394
+ const fieldOptions: FSharpList<Shared_FieldOption> = ofSeq<Shared_FieldOption>(mapIndexed<{ description: string, optionKey: string, value: string }, Shared_FieldOption>((_arg: int32, opt: { description: string, optionKey: string, value: string }): Shared_FieldOption => (new Shared_FieldOption(opt.description, opt.value, new Shared_FieldOptionKey(parse(opt.optionKey)), undefined)), options));
395
+ return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, false, false, Spec_FieldType_CheckboxList(new Spec_MultiChoiceInfo(fieldOptions)), undefined);
396
+ }
397
+
398
+ /**
399
+ * Create a text field
400
+ * TypeScript: createTextField(fieldKey: string, label: string, isOptional: boolean)
401
+ */
402
+ export function createTextField(fieldKeyString: string, label: string, isOptional: boolean): Spec_FormField$1<Spec_FieldType_$union> {
403
+ return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, isOptional, false, Spec_FieldType_Text(new Spec_TextInfo(undefined)), undefined);
404
+ }
405
+
406
+ /**
407
+ * Create a form step with fields
408
+ * TypeScript: createFormStep(stepOrder: number, stepLabel: string, fields: FormField[])
409
+ */
410
+ export function createFormStep(stepOrder: int32, stepLabel: string, fields: Spec_FormField$1<Spec_FieldType_$union>[]): Spec_FormStep$1<Spec_FieldType_$union> {
411
+ return new Spec_FormStep$1(stepOrder, stepLabel, ofSeq<Spec_FormField$1<Spec_FieldType_$union>>(mapIndexed<Spec_FormField$1<Spec_FieldType_$union>, Spec_FormField$1<Spec_FieldType_$union>>((index: int32, field: Spec_FormField$1<Spec_FieldType_$union>): Spec_FormField$1<Spec_FieldType_$union> => (new Spec_FormField$1(index + 1, field.FieldKey, field.Label, field.Notes, field.DependsOn, field.IsOptional, field.IsDeprecated, field.FieldType, field.Value)), fields)));
412
+ }
413
+
414
+ /**
415
+ * Create a FormSpec with basic information
416
+ * TypeScript: createFormSpec(id: string, title: string, steps: FormStep[])
417
+ */
418
+ export function createFormSpec(idString: string, title: string, steps: Spec_FormStep$1<Spec_FieldType_$union>[]): Spec_FormSpec$1<Spec_FieldType_$union> {
419
+ return new Spec_FormSpec$1(parse(idString), "DYN", title, "Dynamically created FormSpec", "1.0.0", "2.0.5", ofSeq<Spec_FormStep$1<Spec_FieldType_$union>>(steps), empty<string>(), undefined, empty<string>(), false, false, undefined, Spec_FormLifecycle_Blueprint(), undefined);
420
+ }
421
+
422
+ /**
423
+ * Create a field option
424
+ * TypeScript: createFieldOption(description: string, value: string, optionKey: string)
425
+ */
426
+ export function createFieldOption(description: string, value: string, optionKeyString: string): Shared_FieldOption {
427
+ return new Shared_FieldOption(description, value, new Shared_FieldOptionKey(parse(optionKeyString)), undefined);
428
+ }
429
+
430
+ /**
431
+ * Create a matrix field
432
+ * TypeScript: createMatrixField(fieldKey: string, label: string, items: FieldOption[], options: FieldOption[])
433
+ */
434
+ export function createMatrixField(fieldKeyString: string, label: string, items: Shared_FieldOption[], options: Shared_FieldOption[]): Spec_FormField$1<Spec_FieldType_$union> {
435
+ return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, false, false, Spec_FieldType_Matrix(new Spec_MatrixInfo(ofSeq<Shared_FieldOption>(items), ofSeq<Shared_FieldOption>(options))), undefined);
436
+ }
437
+
438
+ /**
439
+ * Create a plugin field
440
+ * TypeScript: createPluginField(fieldKey: string, label: string, config: {pluginId: string, fieldName: string})
441
+ */
442
+ export function createPluginField(fieldKeyString: string, label: string, config: { fieldName: string, pluginId: string }): Spec_FormField$1<Spec_FieldType_$union> {
443
+ return new Spec_FormField$1(1, new Shared_FieldKey(parse(fieldKeyString)), label, undefined, undefined, false, false, Spec_FieldType_PluginField(new Spec_PluginFieldConfig(config.pluginId, config.fieldName)), undefined);
444
+ }
445
+
446
+ /**
447
+ * Create an action state that executes a task
448
+ * TypeScript: createActionState(stateKey: string, label: string, taskDescription: string, priority?: string)
449
+ */
450
+ export function createActionState(stateKeyString: string, label: string, taskDescription: string, priority: Option<string>): ClinicalPathway_StateDefinition {
451
+ return new ClinicalPathway_StateDefinition(new Shared_StateKey(parse(stateKeyString)), label, 1, ClinicalPathway_StateType_Action(ClinicalPathway_ActionInfo_Task(new ClinicalPathway_TaskAction("Clinical", taskDescription, (priority != null) ? ((value_11(priority) === "High") ? ClinicalPathway_TaskPriority_High() : ((value_11(priority) === "Low") ? ClinicalPathway_TaskPriority_Low() : ClinicalPathway_TaskPriority_Medium())) : ClinicalPathway_TaskPriority_Medium(), ClinicalPathway_DueDate_Today(), "Clinical Staff", undefined))), undefined);
452
+ }
453
+
454
+ /**
455
+ * Create a terminal state that ends the pathway
456
+ * TypeScript: createTerminalState(stateKey: string, outcome: string)
457
+ */
458
+ export function createTerminalState(stateKeyString: string, outcome: string): ClinicalPathway_StateDefinition {
459
+ return new ClinicalPathway_StateDefinition(new Shared_StateKey(parse(stateKeyString)), outcome, 1, ClinicalPathway_StateType_Terminal(new ClinicalPathway_TerminalInfo("Complete", outcome, undefined)), undefined);
460
+ }
461
+
462
+ /**
463
+ * Create a transition between states based on field condition
464
+ * TypeScript: createTransition(transitionKey: string, fromState: string, toState: string, fieldKey: string, expectedValue: string)
465
+ */
466
+ export function createTransition(transitionKeyString: string, fromStateString: string, toStateString: string, fieldKeyString: string, expectedValue: string): ClinicalPathway_TransitionDefinition {
467
+ return new ClinicalPathway_TransitionDefinition(new Shared_TransitionKey(parse(transitionKeyString)), new Shared_StateKey(parse(fromStateString)), new Shared_StateKey(parse(toStateString)), ClinicalPathway_TransitionCondition_FieldCondition(new Shared_FieldKey(parse(fieldKeyString)), ClinicalPathway_FieldEvaluator_Equals(), Shared_ConditionValue_Single(expectedValue)), undefined);
468
+ }
469
+
470
+ /**
471
+ * Create a clinical pathway with states and transitions
472
+ * TypeScript: createClinicalPathway(name: string, states: StateDefinition[], transitions: TransitionDefinition[])
473
+ */
474
+ export function createClinicalPathway(name: string, states: ClinicalPathway_StateDefinition[], transitions: ClinicalPathway_TransitionDefinition[]): ClinicalPathway_ClinicalPathwaySpec {
475
+ let copyOfStruct: string;
476
+ const statesWithOrder: FSharpList<ClinicalPathway_StateDefinition> = ofSeq<ClinicalPathway_StateDefinition>(mapIndexed<ClinicalPathway_StateDefinition, ClinicalPathway_StateDefinition>((index: int32, state: ClinicalPathway_StateDefinition): ClinicalPathway_StateDefinition => (new ClinicalPathway_StateDefinition(state.StateKey, state.StateLabel, index + 1, state.StateType, state.DependsOn)), states));
477
+ return new ClinicalPathway_ClinicalPathwaySpec((copyOfStruct = newGuid(), copyOfStruct), name, "1.0.0", "Dynamic Builder", ClinicalPathway_PathwayExecutionMode_SinglePathway(new ClinicalPathway_SinglePathwayConfig(ClinicalPathway_SelectionStrategy_HighestPriority(), true)), new Shared_StateKey("00000000-0000-0000-0000-000000000001"), statesWithOrder, ofSeq<ClinicalPathway_TransitionDefinition>(transitions), empty<ClinicalPathway_ConstraintDefinition>(), empty<ClinicalPathway_PathRequirement>(), now(), undefined, undefined, undefined);
478
+ }
479
+
480
+ /**
481
+ * Add a clinical pathway to an existing FormSpec
482
+ * TypeScript: addPathwayToFormSpec(formSpec: FormSpec, pathway: ClinicalPathwaySpec)
483
+ */
484
+ export function addPathwayToFormSpec(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, pathway: ClinicalPathway_ClinicalPathwaySpec): Spec_FormSpec$1<Spec_FieldType_$union> {
485
+ return new Spec_FormSpec$1(formSpec.Id, formSpec.Code, formSpec.Title, formSpec.Abstract, formSpec.Version, formSpec.FormSpecVersion, formSpec.Steps, formSpec.CategoryTags, formSpec.Score, formSpec.AssociatedCodes, formSpec.RequiresReview, formSpec.RequiresReviewAndApproval, pathway, formSpec.Lifecycle, formSpec.FilledMeta);
486
+ }
487
+
488
+ /**
489
+ * Extract form field data from FormSpec in TypeScript-friendly format
490
+ * TypeScript: getFieldDataFromFormSpec(formSpec: FormSpec, stepOrder: number, fieldKey: string)
491
+ */
492
+ export function getFieldDataFromFormSpec(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, _stepOrder: int32, fieldKeyString: string): Option<any> {
493
+ return map<FieldDetails$1<Spec_FieldType_$union>, any>((fieldDetails: FieldDetails$1<Spec_FieldType_$union>): any => ({
494
+ FieldOrder: fieldDetails.FieldOrder,
495
+ FieldType: fieldDetails.FieldType,
496
+ FieldValue: fieldDetails.FieldValue,
497
+ Key: fieldKeyString,
498
+ Label: fieldDetails.Label,
499
+ }), getFieldDetails_1(formSpec, new Shared_FieldKey(parse(fieldKeyString))));
500
+ }
501
+
502
+ /**
503
+ * Get all step orders from FormSpec
504
+ * TypeScript: getFormResultStepOrders(formSpec: FormSpec)
505
+ */
506
+ export function getFormResultStepOrders(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): int32[] {
507
+ const collection: FSharpList<int32> = map_3<Spec_FormStep$1<Spec_FieldType_$union>, int32>((step: Spec_FormStep$1<Spec_FieldType_$union>): int32 => step.StepOrder, formSpec.Steps);
508
+ return Array.from(collection);
509
+ }
510
+
511
+ /**
512
+ * Get all field keys for a specific step from FormSpec
513
+ * TypeScript: getFormResultFieldKeys(formSpec: FormSpec, stepOrder: number)
514
+ */
515
+ export function getFormResultFieldKeys(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, stepOrder: int32): string[] {
516
+ return defaultArgWith_1<string[]>(map<Spec_FormStep$1<Spec_FieldType_$union>, string[]>((step_1: Spec_FormStep$1<Spec_FieldType_$union>): string[] => {
517
+ const collection: FSharpList<string> = map_3<Spec_FormField$1<Spec_FieldType_$union>, string>((f: Spec_FormField$1<Spec_FieldType_$union>): string => f.FieldKey.fields[0], step_1.Fields);
518
+ return Array.from(collection);
519
+ }, tryFind<Spec_FormStep$1<Spec_FieldType_$union>>((step: Spec_FormStep$1<Spec_FieldType_$union>): boolean => (step.StepOrder === stepOrder), formSpec.Steps)), (): string[] => []);
520
+ }
521
+
522
+ /**
523
+ * Get the FormSpec as TypeScript-friendly structure
524
+ * TypeScript: getResultSteps(formSpec: FormSpec)
525
+ */
526
+ export function getResultSteps(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): any {
527
+ return formSpec;
528
+ }
529
+
530
+ /**
531
+ * Get a specific field value from FormSpec
532
+ * TypeScript: getFieldValue(formSpec: FormSpec, stepOrder: number, fieldKey: string)
533
+ */
534
+ export function getFieldValue(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, _stepOrder: int32, fieldKeyString: string): Option<any> {
535
+ return map<FieldDetails$1<Spec_FieldType_$union>, any>((details: FieldDetails$1<Spec_FieldType_$union>): any => details.FieldValue, getFieldDetails_1(formSpec, new Shared_FieldKey(parse(fieldKeyString))));
536
+ }
537
+
538
+ /**
539
+ * Get complete field details from FormSpec
540
+ * TypeScript: getFieldDetails(formSpec: FormSpec, stepOrder: number, fieldKey: string)
541
+ */
542
+ export function getFieldDetails(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, _stepOrder: int32, fieldKeyString: string): Option<any> {
543
+ return map<FieldDetails$1<Spec_FieldType_$union>, any>((details: FieldDetails$1<Spec_FieldType_$union>): any => details, getFieldDetails_1(formSpec, new Shared_FieldKey(parse(fieldKeyString))));
544
+ }
545
+
546
+ /**
547
+ * Create a complete test FormSpec for buildDynamicFormResultData testing
548
+ * TypeScript: createTestFormSpec()
549
+ */
550
+ export function createTestFormSpec(): Spec_FormSpec$1<Spec_FieldType_$union> {
551
+ const option1: Shared_FieldOption = new Shared_FieldOption("Option 1", "opt1", new Shared_FieldOptionKey(newGuid()), undefined);
552
+ const option2: Shared_FieldOption = new Shared_FieldOption("Option 2", "opt2", new Shared_FieldOptionKey(newGuid()), undefined);
553
+ const testStep: Spec_FormStep$1<Spec_FieldType_$union> = new Spec_FormStep$1(1, "Test Step", ofArray_1([new Spec_FormField$1(1, new Shared_FieldKey("11111111-1111-1111-1111-111111111111"), "Test Text Field", undefined, undefined, false, false, Spec_FieldType_Text(new Spec_TextInfo(undefined)), undefined), new Spec_FormField$1(2, new Shared_FieldKey("22222222-2222-2222-2222-222222222222"), "Test Checkbox List", undefined, undefined, false, false, Spec_FieldType_CheckboxList(new Spec_MultiChoiceInfo(ofArray_1([option1, option2]))), undefined), new Spec_FormField$1(3, new Shared_FieldKey("33333333-3333-3333-3333-333333333333"), "Test Matrix", undefined, undefined, false, false, Spec_FieldType_Matrix(new Spec_MatrixInfo(ofArray_1([option1, option2]), ofArray_1([new Shared_FieldOption("Scale 1", "1", new Shared_FieldOptionKey(newGuid()), 1), new Shared_FieldOption("Scale 2", "2", new Shared_FieldOptionKey(newGuid()), 2)]))), undefined), new Spec_FormField$1(4, new Shared_FieldKey("44444444-4444-4444-4444-444444444444"), "Test Plugin Field", undefined, undefined, false, false, Spec_FieldType_PluginField(new Spec_PluginFieldConfig("test.plugin", "Test Plugin")), undefined)]));
554
+ return new Spec_FormSpec$1(newGuid(), "TEST-001", "Test Form", "Test form for buildDynamicFormResultData", "1.0.0", "5.0.0", singleton(testStep), empty<string>(), undefined, empty<string>(), false, false, undefined, Spec_FormLifecycle_Blueprint(), undefined);
555
+ }
556
+
557
+ /**
558
+ * Safe pathway execution initialization wrapper
559
+ * TypeScript: initializePathwayExecution(formSpec: FormSpec) - FormSpec must include ClinicalPathway and field values
560
+ */
561
+ export function initializePathwayExecution(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): any {
562
+ try {
563
+ return initializeExecution(formSpec);
564
+ }
565
+ catch (ex: any) {
566
+ return {
567
+ ErrorMessage: ex.message,
568
+ ErrorType: "Exception",
569
+ IsError: true,
570
+ };
571
+ }
572
+ }
573
+
574
+ /**
575
+ * Get field type information in TypeScript-friendly format
576
+ * TypeScript: getFieldTypeInfo(field: FormField) => {typeName: string, isRequired: boolean}
577
+ */
578
+ export function getFieldTypeInfo(field: Spec_FormField$1<Spec_FieldType_$union>): { isRequired: boolean, typeName: string } {
579
+ let matchValue: Spec_FieldType_$union;
580
+ return {
581
+ isRequired: !field.IsOptional,
582
+ typeName: (matchValue = field.FieldType, (matchValue.tag === /* TextArea */ 1) ? "TextArea" : ((matchValue.tag === /* Email */ 2) ? "Email" : ((matchValue.tag === /* Password */ 3) ? "Password" : ((matchValue.tag === /* Search */ 4) ? "Search" : ((matchValue.tag === /* Color */ 5) ? "Color" : ((matchValue.tag === /* Number */ 6) ? "Number" : ((matchValue.tag === /* Tel */ 7) ? "Tel" : ((matchValue.tag === /* Date */ 8) ? "Date" : ((matchValue.tag === /* DateTimeLocal */ 9) ? "DateTimeLocal" : ((matchValue.tag === /* Time */ 10) ? "Time" : ((matchValue.tag === /* Checkbox */ 11) ? "Checkbox" : ((matchValue.tag === /* Radio */ 12) ? "Radio" : ((matchValue.tag === /* SingleChoice */ 13) ? "SingleChoice" : ((matchValue.tag === /* Dropdown */ 14) ? "Dropdown" : ((matchValue.tag === /* TextAutoComplete */ 18) ? "TextAutoComplete" : ((matchValue.tag === /* MultiChoice */ 15) ? "MultiChoice" : ((matchValue.tag === /* CheckboxList */ 16) ? "CheckboxList" : ((matchValue.tag === /* TagList */ 17) ? "TagList" : ((matchValue.tag === /* Matrix */ 19) ? "Matrix" : ((matchValue.tag === /* Signature */ 20) ? "Signature" : ((matchValue.tag === /* Message */ 21) ? "Message" : ((matchValue.tag === /* PluginField */ 22) ? "PluginField" : "Text")))))))))))))))))))))),
583
+ };
584
+ }
585
+
586
+ /**
587
+ * Extract choice options from fields that support them
588
+ * TypeScript: getFieldChoiceOptions(field: FormField) => {key: string, label: string, value: string}[] | null
589
+ */
590
+ export function getFieldChoiceOptions(field: Spec_FormField$1<Spec_FieldType_$union>): Option<{ key: string, label: string, value: string }[]> {
591
+ let collection: FSharpList<{ key: string, label: string, value: string }>, collection_1: FSharpList<{ key: string, label: string, value: string }>, collection_2: FSharpList<{ key: string, label: string, value: string }>, collection_3: FSharpList<{ key: string, label: string, value: string }>, collection_4: FSharpList<{ key: string, label: string, value: string }>, collection_5: FSharpList<{ key: string, label: string, value: string }>, collection_6: FSharpList<{ key: string, label: string, value: string }>;
592
+ const matchValue: Spec_FieldType_$union = field.FieldType;
593
+ switch (matchValue.tag) {
594
+ case /* Radio */ 12:
595
+ return (collection = map_3<Shared_FieldOption, { key: string, label: string, value: string }>((opt: Shared_FieldOption): { key: string, label: string, value: string } => ({
596
+ key: opt.OptionKey.fields[0],
597
+ label: opt.Description,
598
+ value: opt.Value,
599
+ }), matchValue.fields[0].Options), Array.from(collection));
600
+ case /* SingleChoice */ 13:
601
+ return (collection_1 = map_3<Shared_FieldOption, { key: string, label: string, value: string }>((opt_1: Shared_FieldOption): { key: string, label: string, value: string } => ({
602
+ key: opt_1.OptionKey.fields[0],
603
+ label: opt_1.Description,
604
+ value: opt_1.Value,
605
+ }), matchValue.fields[0].Options), Array.from(collection_1));
606
+ case /* Dropdown */ 14:
607
+ return (collection_2 = map_3<Shared_FieldOption, { key: string, label: string, value: string }>((opt_2: Shared_FieldOption): { key: string, label: string, value: string } => ({
608
+ key: opt_2.OptionKey.fields[0],
609
+ label: opt_2.Description,
610
+ value: opt_2.Value,
611
+ }), matchValue.fields[0].Options), Array.from(collection_2));
612
+ case /* MultiChoice */ 15:
613
+ return (collection_3 = map_3<Shared_FieldOption, { key: string, label: string, value: string }>((opt_3: Shared_FieldOption): { key: string, label: string, value: string } => ({
614
+ key: opt_3.OptionKey.fields[0],
615
+ label: opt_3.Description,
616
+ value: opt_3.Value,
617
+ }), matchValue.fields[0].Options), Array.from(collection_3));
618
+ case /* CheckboxList */ 16:
619
+ return (collection_4 = map_3<Shared_FieldOption, { key: string, label: string, value: string }>((opt_4: Shared_FieldOption): { key: string, label: string, value: string } => ({
620
+ key: opt_4.OptionKey.fields[0],
621
+ label: opt_4.Description,
622
+ value: opt_4.Value,
623
+ }), matchValue.fields[0].Options), Array.from(collection_4));
624
+ case /* TagList */ 17:
625
+ return (collection_5 = map_3<Shared_FieldOption, { key: string, label: string, value: string }>((opt_5: Shared_FieldOption): { key: string, label: string, value: string } => ({
626
+ key: opt_5.OptionKey.fields[0],
627
+ label: opt_5.Description,
628
+ value: opt_5.Value,
629
+ }), matchValue.fields[0].Options), Array.from(collection_5));
630
+ case /* TextAutoComplete */ 18:
631
+ return (collection_6 = map_3<Shared_FieldOption, { key: string, label: string, value: string }>((opt_6: Shared_FieldOption): { key: string, label: string, value: string } => ({
632
+ key: opt_6.OptionKey.fields[0],
633
+ label: opt_6.Description,
634
+ value: opt_6.Value,
635
+ }), matchValue.fields[0].Options), Array.from(collection_6));
636
+ default:
637
+ return undefined;
638
+ }
639
+ }
640
+
641
+ /**
642
+ * Extract matrix field structure (items and options)
643
+ * TypeScript: getFieldMatrixInfo(field: FormField) => {items: {key: string, label: string}[], options: {key: string, description: string, value: string}[]} | null
644
+ */
645
+ export function getFieldMatrixInfo(field: Spec_FormField$1<Spec_FieldType_$union>): Option<{ items: { key: string, label: string }[], options: { description: string, key: string, value: string }[] }> {
646
+ let collection: FSharpList<{ key: string, label: string }>, collection_1: FSharpList<{ description: string, key: string, value: string }>;
647
+ const matchValue: Spec_FieldType_$union = field.FieldType;
648
+ if (matchValue.tag === /* Matrix */ 19) {
649
+ const matrixInfo: Spec_MatrixInfo = matchValue.fields[0];
650
+ return {
651
+ items: (collection = map_3<Shared_FieldOption, { key: string, label: string }>((item: Shared_FieldOption): { key: string, label: string } => ({
652
+ key: item.OptionKey.fields[0],
653
+ label: item.Description,
654
+ }), matrixInfo.Items), Array.from(collection)),
655
+ options: (collection_1 = map_3<Shared_FieldOption, { description: string, key: string, value: string }>((opt: Shared_FieldOption): { description: string, key: string, value: string } => ({
656
+ description: opt.Description,
657
+ key: opt.OptionKey.fields[0],
658
+ value: opt.Value,
659
+ }), matrixInfo.Options), Array.from(collection_1)),
660
+ };
661
+ }
662
+ else {
663
+ return undefined;
664
+ }
665
+ }
666
+
667
+ /**
668
+ * Extract GUID string from FieldKey (single-case DU)
669
+ * TypeScript: getFieldKeyString(fieldKey: FieldKey) => string
670
+ */
671
+ export function getFieldKeyString(fieldKey: Shared_FieldKey): string {
672
+ return fieldKey.fields[0];
673
+ }
674
+
675
+ /**
676
+ * Convert ClinicalPathway ActionInfo to TypeScript-friendly objects
677
+ * TypeScript: convertActionInfo(action: ActionInfo) => {type: string, description: string, ...}
678
+ */
679
+ export function convertActionInfo(action: ClinicalPathway_ActionInfo_$union): any {
680
+ let matchValue_1: ClinicalPathway_ReferralUrgency_$union, matchValue_3: ClinicalPathway_AlertSeverity_$union, matchValue: ClinicalPathway_TaskPriority_$union;
681
+ switch (action.tag) {
682
+ case /* Referral */ 2: {
683
+ const referral: ClinicalPathway_ReferralAction = action.fields[0];
684
+ return {
685
+ description: `Refer to ${referral.Target}`,
686
+ reason: referral.Reason,
687
+ type: "referral",
688
+ urgency: (matchValue_1 = referral.Urgency, (matchValue_1.tag === /* Routine */ 1) ? (`routine-${matchValue_1.fields[0]}`) : ((matchValue_1.tag === /* AsNeeded */ 2) ? "asNeeded" : "immediate")),
689
+ };
690
+ }
691
+ case /* Medication */ 0: {
692
+ const med: ClinicalPathway_MedicationAction = action.fields[0];
693
+ return {
694
+ description: `${med.Name} - ${med.Dose} ${med.Route}`,
695
+ dose: med.Dose,
696
+ duration: med.Duration,
697
+ frequency: med.Frequency,
698
+ medicationName: med.Name,
699
+ route: med.Route,
700
+ type: "medication",
701
+ };
702
+ }
703
+ case /* Prescription */ 9: {
704
+ const presc: ClinicalPathway_PrescriptionAction = action.fields[0];
705
+ return {
706
+ description: `${presc.Medication} - ${presc.Dose} ${presc.Route}`,
707
+ dose: presc.Dose,
708
+ duration: presc.Duration,
709
+ frequency: presc.Frequency,
710
+ medication: presc.Medication,
711
+ quantity: presc.Quantity,
712
+ route: presc.Route,
713
+ type: "prescription",
714
+ };
715
+ }
716
+ case /* SetFieldValue */ 10: {
717
+ const setField: ClinicalPathway_SetFieldValueAction = action.fields[0];
718
+ let valueStr: string;
719
+ const matchValue_2: ClinicalPathway_FieldValueSource_$union = setField.Value;
720
+ valueStr = ((matchValue_2.tag === /* FieldReference */ 1) ? (`Reference to ${matchValue_2.fields[0].fields[0]}`) : ((matchValue_2.tag === /* OptionKey */ 2) ? (`Option ${matchValue_2.fields[0].fields[0]}`) : matchValue_2.fields[0]));
721
+ const fieldGuid: string = setField.TargetField.fields[0];
722
+ return {
723
+ description: `Set field ${fieldGuid} to ${valueStr}`,
724
+ fieldKey: fieldGuid,
725
+ type: "setFieldValue",
726
+ value: valueStr,
727
+ };
728
+ }
729
+ case /* Documentation */ 5: {
730
+ const doc: ClinicalPathway_DocumentationAction = action.fields[0];
731
+ return {
732
+ description: `Document: ${doc.FormName}`,
733
+ formName: doc.FormName,
734
+ purpose: doc.Purpose,
735
+ required: doc.Required,
736
+ type: "documentation",
737
+ };
738
+ }
739
+ case /* Test */ 1: {
740
+ const test: ClinicalPathway_TestAction = action.fields[0];
741
+ return {
742
+ description: `${test.TestName} (${test.TestType})`,
743
+ testName: test.TestName,
744
+ testType: test.TestType,
745
+ type: "test",
746
+ };
747
+ }
748
+ case /* Procedure */ 4: {
749
+ const proc: ClinicalPathway_ProcedureAction = action.fields[0];
750
+ return {
751
+ description: `${proc.Name}: ${proc.Description}`,
752
+ procedureDescription: proc.Description,
753
+ procedureName: proc.Name,
754
+ type: "procedure",
755
+ };
756
+ }
757
+ case /* Education */ 3: {
758
+ const edu: ClinicalPathway_EducationAction = action.fields[0];
759
+ return {
760
+ description: `Education: ${join(", ", edu.Topics)}`,
761
+ topics: edu.Topics,
762
+ type: "education",
763
+ };
764
+ }
765
+ case /* Alert */ 7: {
766
+ const alert: ClinicalPathway_AlertAction = action.fields[0];
767
+ return {
768
+ category: alert.Category,
769
+ description: alert.Message,
770
+ severity: (matchValue_3 = alert.Severity, (matchValue_3.tag === /* High */ 2) ? "high" : ((matchValue_3.tag === /* Medium */ 1) ? "medium" : ((matchValue_3.tag === /* Low */ 0) ? "low" : "critical"))),
771
+ type: "alert",
772
+ };
773
+ }
774
+ case /* Problem */ 8: {
775
+ const prob: ClinicalPathway_ProblemAction = action.fields[0];
776
+ return {
777
+ description: `${prob.ProblemName}${defaultArg_1(map<string, string>((code: string): string => (` (ICD: ${code})`), prob.IcdCode), "")}`,
778
+ icdCode: unwrap(prob.IcdCode),
779
+ problemName: prob.ProblemName,
780
+ type: "problem",
781
+ };
782
+ }
783
+ case /* NavigateToForm */ 11: {
784
+ const nav: ClinicalPathway_NavigateToFormAction = action.fields[0];
785
+ const formCode: string = defaultArg_1(nav.FormCode, nav.FormId);
786
+ return {
787
+ description: `Navigate to form: ${formCode}`,
788
+ formCode: formCode,
789
+ type: "navigateToForm",
790
+ };
791
+ }
792
+ default: {
793
+ const task: ClinicalPathway_TaskAction = action.fields[0];
794
+ return {
795
+ category: task.Category,
796
+ description: task.Description,
797
+ priority: (matchValue = task.Priority, (matchValue.tag === /* Medium */ 1) ? "medium" : ((matchValue.tag === /* Low */ 2) ? "low" : "high")),
798
+ type: "task",
799
+ };
800
+ }
801
+ }
802
+ }
803
+
804
+ /**
805
+ * Find the StateKey for a given ActionInfo in a ClinicalPathwaySpec
806
+ * TypeScript: stateKeyForAction(pathway: ClinicalPathwaySpec, action: ActionInfo) => string | null
807
+ */
808
+ export function stateKeyForAction(pathway: ClinicalPathway_ClinicalPathwaySpec, action: ClinicalPathway_ActionInfo_$union): Option<string> {
809
+ toConsole(printf("PathwayId: %A"))(pathway.PathwayId);
810
+ toConsole(printf("Finding state key for action: %A"))(action);
811
+ return tryPick<ClinicalPathway_StateDefinition, string>((state: ClinicalPathway_StateDefinition): Option<string> => {
812
+ const matchValue: ClinicalPathway_StateType_$union = state.StateType;
813
+ let matchResult: int32, actionInfo_1: ClinicalPathway_ActionInfo_$union;
814
+ if (matchValue.tag === /* Action */ 2) {
815
+ if (equals(matchValue.fields[0], action)) {
816
+ matchResult = 0;
817
+ actionInfo_1 = matchValue.fields[0];
818
+ }
819
+ else {
820
+ matchResult = 1;
821
+ }
822
+ }
823
+ else {
824
+ matchResult = 1;
825
+ }
826
+ switch (matchResult) {
827
+ case 0:
828
+ return state.StateKey.fields[0];
829
+ default:
830
+ return undefined;
831
+ }
832
+ }, pathway.States);
833
+ }
834
+
835
+ //# sourceMappingURL=FormSpec.Api.Helpers.ts.map