@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,374 +1,397 @@
1
- import { value as value_2, Option, bind } from "@fable-org/fable-library-js/Option.js";
2
- import { Shared_FieldValue_Single, Shared_FieldValue_PluginData, Shared_FieldValue_Matrix, Shared_MatrixAnswer, Shared_FieldValue_Multiple, Shared_ConditionValue_Single, Shared_ConditionValue_PluginData, Shared_ConditionValue_Matrix, Shared_ConditionValue_Multiple, Spec_FormSpec$1, ClinicalPathway_ConstraintDefinition, ClinicalPathway_ConstraintType_$union, ClinicalPathway_TransitionDefinition, ClinicalPathway_ClinicalPathwaySpec, Spec_FormStep$1, Spec_FormField$1, ClinicalPathway_TransitionCondition_$union, ClinicalPathway_LogicalOp_$union, Shared_PluginPropertyKey, Shared_FieldOptionKey, Shared_ConditionValue_$union, ClinicalPathway_FieldEvaluator_$union, Values_DynamicFormResultData$1, Values_StepOrder, Shared_FieldKey, Spec_FieldType_$union, Values_FieldDetails$1, Shared_PluginDataProperty_$reflection, Shared_PluginDataProperty, Shared_MatrixItemKey, Shared_FieldAnswer, Shared_FieldValue_$union } from "./FormSpec.js";
3
- import { join } from "@fable-org/fable-library-js/String.js";
4
- import { singleton, head, isEmpty, ofSeq, iterate, forAll, exists, FSharpList, map } from "@fable-org/fable-library-js/List.js";
5
- import { map as map_1, toList } from "@fable-org/fable-library-js/Set.js";
6
- import { iterate as iterate_1, FSharpMap, tryFind, toList as toList_1 } from "@fable-org/fable-library-js/Map.js";
7
- import { Auto_generateBoxedEncoder_437914C6, toString } from "./fable_modules/Thoth.Json.10.4.1/Encode.fs.js";
8
- import { list_type } from "@fable-org/fable-library-js/Reflection.js";
9
- import { int32, float64 } from "@fable-org/fable-library-js/Int32.js";
10
- import { tryParse } from "@fable-org/fable-library-js/Double.js";
11
- import { FSharpRef } from "@fable-org/fable-library-js/Types.js";
12
- import { FSharpResult$2_$union, FSharpResult$2_Error, FSharpResult$2_Ok } from "@fable-org/fable-library-js/Result.js";
13
- import { addRangeInPlace } from "@fable-org/fable-library-js/Array.js";
14
- import { compare, comparePrimitives } from "@fable-org/fable-library-js/Util.js";
15
-
16
- /**
17
- * Extract a field value as a string from form data
18
- */
19
- export function getFieldValue(fieldKey: Shared_FieldKey, formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): Option<string> {
20
- return bind<Values_FieldDetails$1<Spec_FieldType_$union>, string>((fieldDetails: Values_FieldDetails$1<Spec_FieldType_$union>): Option<string> => {
21
- const matchValue: Shared_FieldValue_$union = fieldDetails.FieldValue;
22
- switch (matchValue.tag) {
23
- case /* Multiple */ 1:
24
- return join(",", map<Shared_FieldAnswer, string>((a: Shared_FieldAnswer): string => a.Value, toList<Shared_FieldAnswer>(matchValue.fields[0])));
25
- case /* Matrix */ 2:
26
- return join(",", map<[Shared_MatrixItemKey, string], string>((tuple: [Shared_MatrixItemKey, string]): string => tuple[1], toList_1<Shared_MatrixItemKey, string>(matchValue.fields[0].Values)));
27
- case /* PluginData */ 3: {
28
- const pluginData: FSharpList<Shared_PluginDataProperty> = matchValue.fields[0];
29
- return toString(0, Auto_generateBoxedEncoder_437914C6(list_type(Shared_PluginDataProperty_$reflection()), undefined, undefined, undefined)(pluginData));
30
- }
31
- default:
32
- return matchValue.fields[0].Value;
33
- }
34
- }, bind<FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>, Values_FieldDetails$1<Spec_FieldType_$union>>((stepValues: FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>): Option<Values_FieldDetails$1<Spec_FieldType_$union>> => tryFind<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>(fieldKey, stepValues), tryFind<Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>>(new Values_StepOrder(1), formData.ResultSteps)));
35
- }
36
-
37
- /**
38
- * Check if a field has a specific value
39
- */
40
- export function fieldHasValue(fieldKey: Shared_FieldKey, expectedValue: string, formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): boolean {
41
- const matchValue: Option<string> = getFieldValue(fieldKey, formData);
42
- if (matchValue == null) {
43
- return false;
44
- }
45
- else {
46
- return value_2(matchValue) === expectedValue;
47
- }
48
- }
49
-
50
- /**
51
- * Check if a field value is greater than a threshold
52
- */
53
- export function fieldGreaterThan(fieldKey: Shared_FieldKey, threshold: float64, formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): boolean {
54
- const matchValue: Option<string> = getFieldValue(fieldKey, formData);
55
- if (matchValue == null) {
56
- return false;
57
- }
58
- else {
59
- let matchValue_1: [boolean, float64];
60
- let outArg = 0;
61
- matchValue_1 = ([tryParse(value_2(matchValue), new FSharpRef<float64>((): float64 => outArg, (v: float64): void => {
62
- outArg = v;
63
- })), outArg] as [boolean, float64]);
64
- if (matchValue_1[0]) {
65
- return matchValue_1[1] > threshold;
66
- }
67
- else {
68
- return false;
69
- }
70
- }
71
- }
72
-
73
- /**
74
- * Check if a field value is less than a threshold
75
- */
76
- export function fieldLessThan(fieldKey: Shared_FieldKey, threshold: float64, formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): boolean {
77
- const matchValue: Option<string> = getFieldValue(fieldKey, formData);
78
- if (matchValue == null) {
79
- return false;
80
- }
81
- else {
82
- let matchValue_1: [boolean, float64];
83
- let outArg = 0;
84
- matchValue_1 = ([tryParse(value_2(matchValue), new FSharpRef<float64>((): float64 => outArg, (v: float64): void => {
85
- outArg = v;
86
- })), outArg] as [boolean, float64]);
87
- if (matchValue_1[0]) {
88
- return matchValue_1[1] < threshold;
89
- }
90
- else {
91
- return false;
92
- }
93
- }
94
- }
95
-
96
- /**
97
- * Evaluate a single field condition (string-based, for backward compatibility)
98
- */
99
- export function evaluateFieldCondition(fieldKey: Shared_FieldKey, evaluator: ClinicalPathway_FieldEvaluator_$union, expectedValue: string, formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): boolean {
100
- switch (evaluator.tag) {
101
- case /* Equals */ 0:
102
- return fieldHasValue(fieldKey, expectedValue, formData);
103
- case /* NotEquals */ 1:
104
- return !fieldHasValue(fieldKey, expectedValue, formData);
105
- case /* GreaterThan */ 5: {
106
- let matchValue: [boolean, float64];
107
- let outArg = 0;
108
- matchValue = ([tryParse(expectedValue, new FSharpRef<float64>((): float64 => outArg, (v: float64): void => {
109
- outArg = v;
110
- })), outArg] as [boolean, float64]);
111
- if (matchValue[0]) {
112
- return fieldGreaterThan(fieldKey, matchValue[1], formData);
113
- }
114
- else {
115
- return false;
116
- }
117
- }
118
- case /* LessThan */ 7: {
119
- let matchValue_1: [boolean, float64];
120
- let outArg_1 = 0;
121
- matchValue_1 = ([tryParse(expectedValue, new FSharpRef<float64>((): float64 => outArg_1, (v_1: float64): void => {
122
- outArg_1 = v_1;
123
- })), outArg_1] as [boolean, float64]);
124
- if (matchValue_1[0]) {
125
- return fieldLessThan(fieldKey, matchValue_1[1], formData);
126
- }
127
- else {
128
- return false;
129
- }
130
- }
131
- case /* GreaterOrEqual */ 6: {
132
- let matchValue_2: [boolean, float64];
133
- let outArg_2 = 0;
134
- matchValue_2 = ([tryParse(expectedValue, new FSharpRef<float64>((): float64 => outArg_2, (v_2: float64): void => {
135
- outArg_2 = v_2;
136
- })), outArg_2] as [boolean, float64]);
137
- if (matchValue_2[0]) {
138
- if (fieldGreaterThan(fieldKey, matchValue_2[1], formData)) {
139
- return true;
140
- }
141
- else {
142
- return fieldHasValue(fieldKey, expectedValue, formData);
143
- }
144
- }
145
- else {
146
- return false;
147
- }
148
- }
149
- case /* LessOrEqual */ 8: {
150
- let matchValue_3: [boolean, float64];
151
- let outArg_3 = 0;
152
- matchValue_3 = ([tryParse(expectedValue, new FSharpRef<float64>((): float64 => outArg_3, (v_3: float64): void => {
153
- outArg_3 = v_3;
154
- })), outArg_3] as [boolean, float64]);
155
- if (matchValue_3[0]) {
156
- if (fieldLessThan(fieldKey, matchValue_3[1], formData)) {
157
- return true;
158
- }
159
- else {
160
- return fieldHasValue(fieldKey, expectedValue, formData);
161
- }
162
- }
163
- else {
164
- return false;
165
- }
166
- }
167
- default:
168
- return false;
169
- }
170
- }
171
-
172
- /**
173
- * Recursively evaluate a transition condition
174
- */
175
- export function evaluateCondition(formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>, condition: ClinicalPathway_TransitionCondition_$union): boolean {
176
- switch (condition.tag) {
177
- case /* FieldCondition */ 0: {
178
- const conditionValue: Shared_ConditionValue_$union = condition.fields[2];
179
- return evaluateFieldCondition(condition.fields[0], condition.fields[1], (conditionValue.tag === /* Multiple */ 1) ? join(",", toList<string>(conditionValue.fields[0])) : ((conditionValue.tag === /* Matrix */ 2) ? join(",", map<[Shared_MatrixItemKey, string], string>((tupledArg: [Shared_MatrixItemKey, string]): string => tupledArg[1], toList_1<Shared_MatrixItemKey, string>(conditionValue.fields[0]))) : ((conditionValue.tag === /* PluginData */ 3) ? conditionValue.fields[0].Value : conditionValue.fields[0])), formData);
180
- }
181
- case /* FieldOptionCondition */ 1: {
182
- const optionKey: Shared_FieldOptionKey = condition.fields[2];
183
- const fieldKey_1: Shared_FieldKey = condition.fields[0];
184
- const fieldItemKey: Option<Shared_MatrixItemKey> = condition.fields[1];
185
- const evaluator_1: ClinicalPathway_FieldEvaluator_$union = condition.fields[3];
186
- const conditionValue_1: Shared_ConditionValue_$union = condition.fields[4];
187
- return evaluateFieldCondition((fieldItemKey == null) ? fieldKey_1 : (new Shared_FieldKey(value_2(fieldItemKey).fields[0])), evaluator_1, (conditionValue_1.tag === /* Multiple */ 1) ? join(",", toList<string>(conditionValue_1.fields[0])) : ((conditionValue_1.tag === /* Matrix */ 2) ? join(",", map<[Shared_MatrixItemKey, string], string>((tupledArg_1: [Shared_MatrixItemKey, string]): string => tupledArg_1[1], toList_1<Shared_MatrixItemKey, string>(conditionValue_1.fields[0]))) : ((conditionValue_1.tag === /* PluginData */ 3) ? conditionValue_1.fields[0].Value : conditionValue_1.fields[0])), formData);
188
- }
189
- case /* PluginPropertyCondition */ 2: {
190
- const propertyKey: Shared_PluginPropertyKey = condition.fields[1];
191
- const fieldKey_2: Shared_FieldKey = condition.fields[0];
192
- const evaluator_2: ClinicalPathway_FieldEvaluator_$union = condition.fields[2];
193
- const conditionValue_2: Shared_ConditionValue_$union = condition.fields[3];
194
- const expectedValueStr_2: string = (conditionValue_2.tag === /* Multiple */ 1) ? join(",", toList<string>(conditionValue_2.fields[0])) : ((conditionValue_2.tag === /* Matrix */ 2) ? join(",", map<[Shared_MatrixItemKey, string], string>((tupledArg_2: [Shared_MatrixItemKey, string]): string => tupledArg_2[1], toList_1<Shared_MatrixItemKey, string>(conditionValue_2.fields[0]))) : ((conditionValue_2.tag === /* PluginData */ 3) ? conditionValue_2.fields[0].Value : conditionValue_2.fields[0]));
195
- return false;
196
- }
197
- case /* CompositeCondition */ 4: {
198
- const operator: ClinicalPathway_LogicalOp_$union = condition.fields[0];
199
- const conditions: FSharpList<ClinicalPathway_TransitionCondition_$union> = condition.fields[1];
200
- switch (operator.tag) {
201
- case /* Or */ 1:
202
- return exists<ClinicalPathway_TransitionCondition_$union>((condition_2: ClinicalPathway_TransitionCondition_$union): boolean => evaluateCondition(formData, condition_2), conditions);
203
- case /* Not */ 2:
204
- throw new Error("Not operator should not be used directly with CompositeCondition");
205
- default:
206
- return forAll<ClinicalPathway_TransitionCondition_$union>((condition_1: ClinicalPathway_TransitionCondition_$union): boolean => evaluateCondition(formData, condition_1), conditions);
207
- }
208
- }
209
- case /* StateCondition */ 3:
210
- return true;
211
- case /* TestResultCondition */ 5:
212
- return true;
213
- default:
214
- return true;
215
- }
216
- }
217
-
218
- /**
219
- * Validate that a FormSpec only uses GUID field keys
220
- */
221
- export function validateFormSpecFieldKeys(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): FSharpResult$2_$union<void, FSharpList<string>> {
222
- const errors: string[] = [];
223
- iterate<Spec_FormStep$1<Spec_FieldType_$union>>((step: Spec_FormStep$1<Spec_FieldType_$union>): void => {
224
- iterate<Spec_FormField$1<Spec_FieldType_$union>>((field: Spec_FormField$1<Spec_FieldType_$union>): void => {
225
- if (field.FieldKey.fields[0] === "00000000-0000-0000-0000-000000000000") {
226
- void (errors.push(`Field '${field.Label}' has empty GUID field key`));
227
- }
228
- }, step.Fields);
229
- }, formSpec.Steps);
230
- const matchValue: Option<ClinicalPathway_ClinicalPathwaySpec> = formSpec.ClinicalPathway;
231
- if (matchValue == null) {
232
- }
233
- else {
234
- const pathway: ClinicalPathway_ClinicalPathwaySpec = value_2(matchValue);
235
- pathway.States;
236
- iterate<ClinicalPathway_TransitionDefinition>((transition: ClinicalPathway_TransitionDefinition): void => {
237
- const validateCondition = (condition: ClinicalPathway_TransitionCondition_$union): void => {
238
- switch (condition.tag) {
239
- case /* FieldCondition */ 0: {
240
- if (condition.fields[0].fields[0] === "00000000-0000-0000-0000-000000000000") {
241
- void (errors.push(`Transition '${transition.TransitionKey}' has empty GUID field key in condition`));
242
- }
243
- break;
244
- }
245
- case /* PluginPropertyCondition */ 2: {
246
- const propGuid: string = condition.fields[1].fields[0];
247
- if (condition.fields[0].fields[0] === "00000000-0000-0000-0000-000000000000") {
248
- void (errors.push(`Transition '${transition.TransitionKey}' has empty GUID field key in plugin property condition`));
249
- }
250
- if (propGuid === "00000000-0000-0000-0000-000000000000") {
251
- void (errors.push(`Transition '${transition.TransitionKey}' has empty GUID property key in plugin property condition`));
252
- }
253
- break;
254
- }
255
- case /* CompositeCondition */ 4: {
256
- iterate<ClinicalPathway_TransitionCondition_$union>(validateCondition, condition.fields[1]);
257
- break;
258
- }
259
- default:
260
- undefined;
261
- }
262
- };
263
- validateCondition(transition.Condition);
264
- }, pathway.Transitions);
265
- iterate<ClinicalPathway_ConstraintDefinition>((constraintDef: ClinicalPathway_ConstraintDefinition): void => {
266
- const matchValue_1: ClinicalPathway_ConstraintType_$union = constraintDef.ConstraintType;
267
- if (matchValue_1.tag === /* RequiredField */ 3) {
268
- if (matchValue_1.fields[0].fields[0] === "00000000-0000-0000-0000-000000000000") {
269
- void (errors.push(`Constraint '${constraintDef.ConstraintKey}' has empty GUID field key`));
270
- }
271
- }
272
- }, pathway.Constraints);
273
- }
274
- if (errors.length === 0) {
275
- return FSharpResult$2_Ok<void, FSharpList<string>>(undefined);
276
- }
277
- else {
278
- return FSharpResult$2_Error<void, FSharpList<string>>(ofSeq<string>(errors));
279
- }
280
- }
281
-
282
- /**
283
- * Validate that form data only contains GUID field keys
284
- */
285
- export function validateFormDataFieldKeys(formData: Values_DynamicFormResultData$1<Spec_FieldType_$union>): FSharpResult$2_$union<void, FSharpList<string>> {
286
- const errors: string[] = [];
287
- iterate_1<Values_StepOrder, FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>>((stepOrder: Values_StepOrder, stepValues: FSharpMap<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>): void => {
288
- iterate_1<Shared_FieldKey, Values_FieldDetails$1<Spec_FieldType_$union>>((fieldKey: Shared_FieldKey, _arg: Values_FieldDetails$1<Spec_FieldType_$union>): void => {
289
- if (fieldKey.fields[0] === "00000000-0000-0000-0000-000000000000") {
290
- void (errors.push(`Step ${stepOrder} contains field with empty GUID`));
291
- }
292
- }, stepValues);
293
- }, formData.ResultSteps);
294
- if (errors.length === 0) {
295
- return FSharpResult$2_Ok<void, FSharpList<string>>(undefined);
296
- }
297
- else {
298
- return FSharpResult$2_Error<void, FSharpList<string>>(ofSeq<string>(errors));
299
- }
300
- }
301
-
302
- /**
303
- * Comprehensive validation that ensures FormSpec only works with GUID keys
304
- */
305
- export function validateGuidOnlyFormSpec(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, formData: Option<Values_DynamicFormResultData$1<Spec_FieldType_$union>>): FSharpResult$2_$union<void, FSharpList<string>> {
306
- const errors: string[] = [];
307
- const matchValue: FSharpResult$2_$union<void, FSharpList<string>> = validateFormSpecFieldKeys(formSpec);
308
- if (matchValue.tag === /* Ok */ 0) {
309
- }
310
- else {
311
- addRangeInPlace(matchValue.fields[0], errors);
312
- }
313
- if (formData == null) {
314
- }
315
- else {
316
- const matchValue_1: FSharpResult$2_$union<void, FSharpList<string>> = validateFormDataFieldKeys(value_2(formData));
317
- if (matchValue_1.tag === /* Ok */ 0) {
318
- }
319
- else {
320
- addRangeInPlace(matchValue_1.fields[0], errors);
321
- }
322
- }
323
- if (errors.length === 0) {
324
- return FSharpResult$2_Ok<void, FSharpList<string>>(undefined);
325
- }
326
- else {
327
- return FSharpResult$2_Error<void, FSharpList<string>>(ofSeq<string>(errors));
328
- }
329
- }
330
-
331
- /**
332
- * Convert FieldValue to ConditionValue (extracts just the values, no FieldAnswer wrapper)
333
- */
334
- export function fieldValueToConditionValue(fieldValue: Shared_FieldValue_$union): Shared_ConditionValue_$union {
335
- switch (fieldValue.tag) {
336
- case /* Multiple */ 1:
337
- return Shared_ConditionValue_Multiple(map_1<Shared_FieldAnswer, string>((a: Shared_FieldAnswer): string => a.Value, fieldValue.fields[0], {
338
- Compare: comparePrimitives,
339
- }));
340
- case /* Matrix */ 2:
341
- return Shared_ConditionValue_Matrix(fieldValue.fields[0].Values);
342
- case /* PluginData */ 3: {
343
- const pluginDataList: FSharpList<Shared_PluginDataProperty> = fieldValue.fields[0];
344
- if (!isEmpty(pluginDataList)) {
345
- return Shared_ConditionValue_PluginData(head(pluginDataList));
346
- }
347
- else {
348
- throw new Error("Empty plugin data list cannot be converted to ConditionValue");
349
- }
350
- }
351
- default:
352
- return Shared_ConditionValue_Single(fieldValue.fields[0].Value);
353
- }
354
- }
355
-
356
- /**
357
- * Convert ConditionValue to FieldValue (for evaluation - needs fieldKey for FieldAnswer)
358
- */
359
- export function conditionValueToFieldValue(conditionValue: Shared_ConditionValue_$union, fieldKey: Shared_FieldKey, fieldLabel: string): Shared_FieldValue_$union {
360
- switch (conditionValue.tag) {
361
- case /* Multiple */ 1:
362
- return Shared_FieldValue_Multiple(map_1<string, Shared_FieldAnswer>((value_1: string): Shared_FieldAnswer => (new Shared_FieldAnswer(fieldKey, fieldLabel, value_1)), conditionValue.fields[0], {
363
- Compare: compare,
364
- }));
365
- case /* Matrix */ 2:
366
- return Shared_FieldValue_Matrix(new Shared_MatrixAnswer(fieldKey, fieldLabel, conditionValue.fields[0]));
367
- case /* PluginData */ 3:
368
- return Shared_FieldValue_PluginData(singleton(conditionValue.fields[0]));
369
- default:
370
- return Shared_FieldValue_Single(new Shared_FieldAnswer(fieldKey, fieldLabel, conditionValue.fields[0]));
371
- }
372
- }
373
-
374
- //# sourceMappingURL=FormSpecHelpers.ts.map
1
+ import { singleton, head, isEmpty, ofSeq, iterate, forAll, exists, FSharpList, empty, sortBy, mapIndexed, map } from "@fable-org/fable-library-js/List.js";
2
+ import { float64, int32 } from "@fable-org/fable-library-js/Int32.js";
3
+ import { getFieldDetails, FormSpecMetadata, FieldDetails$1 } from "./FormSpecValues.js";
4
+ import { Shared_FieldValue_Single, Shared_FieldValue_PluginData, Shared_FieldValue_Matrix, Shared_MatrixAnswer, Shared_FieldValue_Multiple, Shared_ConditionValue_Single, Shared_ConditionValue_PluginData, Shared_ConditionValue_Matrix, Shared_ConditionValue_Multiple, ClinicalPathway_ConstraintDefinition, ClinicalPathway_ConstraintType_$union, ClinicalPathway_TransitionDefinition, ClinicalPathway_ClinicalPathwaySpec, ClinicalPathway_TransitionCondition_$union, ClinicalPathway_LogicalOp_$union, Shared_PluginPropertyKey, Shared_FieldOptionKey, Shared_ConditionValue_$union, ClinicalPathway_FieldEvaluator_$union, Shared_PluginDataProperty_$reflection, Shared_PluginDataProperty, Shared_MatrixItemKey, Shared_FieldAnswer, Shared_FieldValue_$union, Spec_FormSpec$1, Spec_FormLifecycle_Draft, Values_StepOrder, Spec_FormStep$1, Shared_FieldKey, Spec_FormField$1, Spec_FieldType_$union } from "./FormSpec.js";
5
+ import { FSharpMap, toList } from "@fable-org/fable-library-js/Map.js";
6
+ import { compare, comparePrimitives } from "@fable-org/fable-library-js/Util.js";
7
+ import { newGuid } from "@fable-org/fable-library-js/Guid.js";
8
+ import { value as value_2, Option, bind } from "@fable-org/fable-library-js/Option.js";
9
+ import { join } from "@fable-org/fable-library-js/String.js";
10
+ import { map as map_1, toList as toList_1 } from "@fable-org/fable-library-js/Set.js";
11
+ import { Auto_generateBoxedEncoder_437914C6, toString } from "./fable_modules/Thoth.Json.10.4.1/Encode.fs.js";
12
+ import { list_type } from "@fable-org/fable-library-js/Reflection.js";
13
+ import { tryParse } from "@fable-org/fable-library-js/Double.js";
14
+ import { FSharpRef } from "@fable-org/fable-library-js/Types.js";
15
+ import { FSharpResult$2_$union, FSharpResult$2_Error, FSharpResult$2_Ok } from "@fable-org/fable-library-js/Result.js";
16
+ import { addRangeInPlace } from "@fable-org/fable-library-js/Array.js";
17
+
18
+ /**
19
+ * Build minimal FormSpec structure from ResultSteps Map (for TS interop when formSpec not available)
20
+ */
21
+ export function buildFormSpecFromResultStepsMap(details: FormSpecMetadata, stepsMap: FSharpMap<Values_StepOrder, FSharpMap<Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>>>): Spec_FormSpec$1<Spec_FieldType_$union> {
22
+ return new Spec_FormSpec$1(details.FormSpecId, details.FormSpecCode, "", "", details.DynamicVersion, details.FormSpecVersion, map<[Values_StepOrder, FSharpMap<Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>>], Spec_FormStep$1<Spec_FieldType_$union>>((tupledArg_1: [Values_StepOrder, FSharpMap<Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>>]): Spec_FormStep$1<Spec_FieldType_$union> => {
23
+ const stepOrder: int32 = tupledArg_1[0].fields[0] | 0;
24
+ return new Spec_FormStep$1(stepOrder, `Step ${stepOrder}`, mapIndexed<[Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>], Spec_FormField$1<Spec_FieldType_$union>>((i: int32, tupledArg_3: [Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>]): Spec_FormField$1<Spec_FieldType_$union> => {
25
+ const fd_1: FieldDetails$1<Spec_FieldType_$union> = tupledArg_3[1];
26
+ return new Spec_FormField$1(i + 1, tupledArg_3[0], fd_1.Label, undefined, undefined, false, false, fd_1.FieldType, fd_1.FieldValue);
27
+ }, sortBy<[Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>], int32>((tupledArg_2: [Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>]): int32 => tupledArg_2[1].FieldOrder, toList<Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>>(tupledArg_1[1]), {
28
+ Compare: comparePrimitives,
29
+ })));
30
+ }, sortBy<[Values_StepOrder, FSharpMap<Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>>], int32>((tupledArg: [Values_StepOrder, FSharpMap<Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>>]): int32 => tupledArg[0].fields[0], toList<Values_StepOrder, FSharpMap<Shared_FieldKey, FieldDetails$1<Spec_FieldType_$union>>>(stepsMap), {
31
+ Compare: comparePrimitives,
32
+ })), empty<string>(), details.MaxScore, empty<string>(), false, false, undefined, Spec_FormLifecycle_Draft(newGuid()), undefined);
33
+ }
34
+
35
+ /**
36
+ * Extract a field value as a string from FormSpec
37
+ */
38
+ export function getFieldValue(fieldKey: Shared_FieldKey, formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): Option<string> {
39
+ return bind<FieldDetails$1<Spec_FieldType_$union>, string>((fieldDetails: FieldDetails$1<Spec_FieldType_$union>): Option<string> => {
40
+ const matchValue: Shared_FieldValue_$union = fieldDetails.FieldValue;
41
+ switch (matchValue.tag) {
42
+ case /* Multiple */ 1:
43
+ return join(",", map<Shared_FieldAnswer, string>((a: Shared_FieldAnswer): string => a.Value, toList_1<Shared_FieldAnswer>(matchValue.fields[0])));
44
+ case /* Matrix */ 2:
45
+ return join(",", map<[Shared_MatrixItemKey, string], string>((tuple: [Shared_MatrixItemKey, string]): string => tuple[1], toList<Shared_MatrixItemKey, string>(matchValue.fields[0].Values)));
46
+ case /* PluginData */ 3: {
47
+ const pluginData: FSharpList<Shared_PluginDataProperty> = matchValue.fields[0];
48
+ return toString(0, Auto_generateBoxedEncoder_437914C6(list_type(Shared_PluginDataProperty_$reflection()), undefined, undefined, undefined)(pluginData));
49
+ }
50
+ default:
51
+ return matchValue.fields[0].Value;
52
+ }
53
+ }, getFieldDetails(formSpec, fieldKey));
54
+ }
55
+
56
+ /**
57
+ * Check if a field has a specific value
58
+ */
59
+ export function fieldHasValue(fieldKey: Shared_FieldKey, expectedValue: string, formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): boolean {
60
+ const matchValue: Option<string> = getFieldValue(fieldKey, formSpec);
61
+ if (matchValue == null) {
62
+ return false;
63
+ }
64
+ else {
65
+ return value_2(matchValue) === expectedValue;
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Check if a field value is greater than a threshold
71
+ */
72
+ export function fieldGreaterThan(fieldKey: Shared_FieldKey, threshold: float64, formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): boolean {
73
+ const matchValue: Option<string> = getFieldValue(fieldKey, formSpec);
74
+ if (matchValue == null) {
75
+ return false;
76
+ }
77
+ else {
78
+ let matchValue_1: [boolean, float64];
79
+ let outArg = 0;
80
+ matchValue_1 = ([tryParse(value_2(matchValue), new FSharpRef<float64>((): float64 => outArg, (v: float64): void => {
81
+ outArg = v;
82
+ })), outArg] as [boolean, float64]);
83
+ if (matchValue_1[0]) {
84
+ return matchValue_1[1] > threshold;
85
+ }
86
+ else {
87
+ return false;
88
+ }
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Check if a field value is less than a threshold
94
+ */
95
+ export function fieldLessThan(fieldKey: Shared_FieldKey, threshold: float64, formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): boolean {
96
+ const matchValue: Option<string> = getFieldValue(fieldKey, formSpec);
97
+ if (matchValue == null) {
98
+ return false;
99
+ }
100
+ else {
101
+ let matchValue_1: [boolean, float64];
102
+ let outArg = 0;
103
+ matchValue_1 = ([tryParse(value_2(matchValue), new FSharpRef<float64>((): float64 => outArg, (v: float64): void => {
104
+ outArg = v;
105
+ })), outArg] as [boolean, float64]);
106
+ if (matchValue_1[0]) {
107
+ return matchValue_1[1] < threshold;
108
+ }
109
+ else {
110
+ return false;
111
+ }
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Evaluate a single field condition (string-based, for backward compatibility)
117
+ */
118
+ export function evaluateFieldCondition(fieldKey: Shared_FieldKey, evaluator: ClinicalPathway_FieldEvaluator_$union, expectedValue: string, formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): boolean {
119
+ switch (evaluator.tag) {
120
+ case /* Equals */ 0:
121
+ return fieldHasValue(fieldKey, expectedValue, formSpec);
122
+ case /* NotEquals */ 1:
123
+ return !fieldHasValue(fieldKey, expectedValue, formSpec);
124
+ case /* GreaterThan */ 5: {
125
+ let matchValue: [boolean, float64];
126
+ let outArg = 0;
127
+ matchValue = ([tryParse(expectedValue, new FSharpRef<float64>((): float64 => outArg, (v: float64): void => {
128
+ outArg = v;
129
+ })), outArg] as [boolean, float64]);
130
+ if (matchValue[0]) {
131
+ return fieldGreaterThan(fieldKey, matchValue[1], formSpec);
132
+ }
133
+ else {
134
+ return false;
135
+ }
136
+ }
137
+ case /* LessThan */ 7: {
138
+ let matchValue_1: [boolean, float64];
139
+ let outArg_1 = 0;
140
+ matchValue_1 = ([tryParse(expectedValue, new FSharpRef<float64>((): float64 => outArg_1, (v_1: float64): void => {
141
+ outArg_1 = v_1;
142
+ })), outArg_1] as [boolean, float64]);
143
+ if (matchValue_1[0]) {
144
+ return fieldLessThan(fieldKey, matchValue_1[1], formSpec);
145
+ }
146
+ else {
147
+ return false;
148
+ }
149
+ }
150
+ case /* GreaterOrEqual */ 6: {
151
+ let matchValue_2: [boolean, float64];
152
+ let outArg_2 = 0;
153
+ matchValue_2 = ([tryParse(expectedValue, new FSharpRef<float64>((): float64 => outArg_2, (v_2: float64): void => {
154
+ outArg_2 = v_2;
155
+ })), outArg_2] as [boolean, float64]);
156
+ if (matchValue_2[0]) {
157
+ if (fieldGreaterThan(fieldKey, matchValue_2[1], formSpec)) {
158
+ return true;
159
+ }
160
+ else {
161
+ return fieldHasValue(fieldKey, expectedValue, formSpec);
162
+ }
163
+ }
164
+ else {
165
+ return false;
166
+ }
167
+ }
168
+ case /* LessOrEqual */ 8: {
169
+ let matchValue_3: [boolean, float64];
170
+ let outArg_3 = 0;
171
+ matchValue_3 = ([tryParse(expectedValue, new FSharpRef<float64>((): float64 => outArg_3, (v_3: float64): void => {
172
+ outArg_3 = v_3;
173
+ })), outArg_3] as [boolean, float64]);
174
+ if (matchValue_3[0]) {
175
+ if (fieldLessThan(fieldKey, matchValue_3[1], formSpec)) {
176
+ return true;
177
+ }
178
+ else {
179
+ return fieldHasValue(fieldKey, expectedValue, formSpec);
180
+ }
181
+ }
182
+ else {
183
+ return false;
184
+ }
185
+ }
186
+ default:
187
+ return false;
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Recursively evaluate a transition condition
193
+ */
194
+ export function evaluateCondition(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, condition: ClinicalPathway_TransitionCondition_$union): boolean {
195
+ switch (condition.tag) {
196
+ case /* ScoreInRange */ 3:
197
+ return false;
198
+ case /* FieldScoreInRange */ 4:
199
+ return false;
200
+ case /* FieldCondition */ 0: {
201
+ const conditionValue: Shared_ConditionValue_$union = condition.fields[2];
202
+ return evaluateFieldCondition(condition.fields[0], condition.fields[1], (conditionValue.tag === /* Multiple */ 1) ? join(",", toList_1<string>(conditionValue.fields[0])) : ((conditionValue.tag === /* Matrix */ 2) ? join(",", map<[Shared_MatrixItemKey, string], string>((tupledArg: [Shared_MatrixItemKey, string]): string => tupledArg[1], toList<Shared_MatrixItemKey, string>(conditionValue.fields[0]))) : ((conditionValue.tag === /* PluginData */ 3) ? conditionValue.fields[0].Value : conditionValue.fields[0])), formSpec);
203
+ }
204
+ case /* FieldOptionCondition */ 1: {
205
+ const optionKey: Shared_FieldOptionKey = condition.fields[2];
206
+ const fieldKey_1: Shared_FieldKey = condition.fields[0];
207
+ const fieldItemKey: Option<Shared_MatrixItemKey> = condition.fields[1];
208
+ const evaluator_1: ClinicalPathway_FieldEvaluator_$union = condition.fields[3];
209
+ const conditionValue_1: Shared_ConditionValue_$union = condition.fields[4];
210
+ return evaluateFieldCondition((fieldItemKey == null) ? fieldKey_1 : (new Shared_FieldKey(value_2(fieldItemKey).fields[0])), evaluator_1, (conditionValue_1.tag === /* Multiple */ 1) ? join(",", toList_1<string>(conditionValue_1.fields[0])) : ((conditionValue_1.tag === /* Matrix */ 2) ? join(",", map<[Shared_MatrixItemKey, string], string>((tupledArg_1: [Shared_MatrixItemKey, string]): string => tupledArg_1[1], toList<Shared_MatrixItemKey, string>(conditionValue_1.fields[0]))) : ((conditionValue_1.tag === /* PluginData */ 3) ? conditionValue_1.fields[0].Value : conditionValue_1.fields[0])), formSpec);
211
+ }
212
+ case /* PluginPropertyCondition */ 2: {
213
+ const propertyKey: Shared_PluginPropertyKey = condition.fields[1];
214
+ const fieldKey_2: Shared_FieldKey = condition.fields[0];
215
+ const evaluator_2: ClinicalPathway_FieldEvaluator_$union = condition.fields[2];
216
+ const conditionValue_2: Shared_ConditionValue_$union = condition.fields[3];
217
+ const expectedValueStr_2: string = (conditionValue_2.tag === /* Multiple */ 1) ? join(",", toList_1<string>(conditionValue_2.fields[0])) : ((conditionValue_2.tag === /* Matrix */ 2) ? join(",", map<[Shared_MatrixItemKey, string], string>((tupledArg_2: [Shared_MatrixItemKey, string]): string => tupledArg_2[1], toList<Shared_MatrixItemKey, string>(conditionValue_2.fields[0]))) : ((conditionValue_2.tag === /* PluginData */ 3) ? conditionValue_2.fields[0].Value : conditionValue_2.fields[0]));
218
+ return false;
219
+ }
220
+ case /* CompositeCondition */ 6: {
221
+ const operator: ClinicalPathway_LogicalOp_$union = condition.fields[0];
222
+ const conditions: FSharpList<ClinicalPathway_TransitionCondition_$union> = condition.fields[1];
223
+ switch (operator.tag) {
224
+ case /* Or */ 1:
225
+ return exists<ClinicalPathway_TransitionCondition_$union>((condition_2: ClinicalPathway_TransitionCondition_$union): boolean => evaluateCondition(formSpec, condition_2), conditions);
226
+ case /* Not */ 2:
227
+ throw new Error("Not operator should not be used directly with CompositeCondition");
228
+ default:
229
+ return forAll<ClinicalPathway_TransitionCondition_$union>((condition_1: ClinicalPathway_TransitionCondition_$union): boolean => evaluateCondition(formSpec, condition_1), conditions);
230
+ }
231
+ }
232
+ case /* StateCondition */ 5:
233
+ return true;
234
+ case /* TestResultCondition */ 7:
235
+ return true;
236
+ default:
237
+ return true;
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Validate that a FormSpec only uses GUID field keys
243
+ */
244
+ export function validateFormSpecFieldKeys(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): FSharpResult$2_$union<void, FSharpList<string>> {
245
+ const errors: string[] = [];
246
+ iterate<Spec_FormStep$1<Spec_FieldType_$union>>((step: Spec_FormStep$1<Spec_FieldType_$union>): void => {
247
+ iterate<Spec_FormField$1<Spec_FieldType_$union>>((field: Spec_FormField$1<Spec_FieldType_$union>): void => {
248
+ if (field.FieldKey.fields[0] === "00000000-0000-0000-0000-000000000000") {
249
+ void (errors.push(`Field '${field.Label}' has empty GUID field key`));
250
+ }
251
+ }, step.Fields);
252
+ }, formSpec.Steps);
253
+ const matchValue: Option<ClinicalPathway_ClinicalPathwaySpec> = formSpec.ClinicalPathway;
254
+ if (matchValue == null) {
255
+ }
256
+ else {
257
+ const pathway: ClinicalPathway_ClinicalPathwaySpec = value_2(matchValue);
258
+ pathway.States;
259
+ iterate<ClinicalPathway_TransitionDefinition>((transition: ClinicalPathway_TransitionDefinition): void => {
260
+ const validateCondition = (condition: ClinicalPathway_TransitionCondition_$union): void => {
261
+ switch (condition.tag) {
262
+ case /* FieldCondition */ 0: {
263
+ if (condition.fields[0].fields[0] === "00000000-0000-0000-0000-000000000000") {
264
+ void (errors.push(`Transition '${transition.TransitionKey}' has empty GUID field key in condition`));
265
+ }
266
+ break;
267
+ }
268
+ case /* PluginPropertyCondition */ 2: {
269
+ const propGuid: string = condition.fields[1].fields[0];
270
+ if (condition.fields[0].fields[0] === "00000000-0000-0000-0000-000000000000") {
271
+ void (errors.push(`Transition '${transition.TransitionKey}' has empty GUID field key in plugin property condition`));
272
+ }
273
+ if (propGuid === "00000000-0000-0000-0000-000000000000") {
274
+ void (errors.push(`Transition '${transition.TransitionKey}' has empty GUID property key in plugin property condition`));
275
+ }
276
+ break;
277
+ }
278
+ case /* CompositeCondition */ 6: {
279
+ iterate<ClinicalPathway_TransitionCondition_$union>(validateCondition, condition.fields[1]);
280
+ break;
281
+ }
282
+ default:
283
+ undefined;
284
+ }
285
+ };
286
+ validateCondition(transition.Condition);
287
+ }, pathway.Transitions);
288
+ iterate<ClinicalPathway_ConstraintDefinition>((constraintDef: ClinicalPathway_ConstraintDefinition): void => {
289
+ const matchValue_1: ClinicalPathway_ConstraintType_$union = constraintDef.ConstraintType;
290
+ if (matchValue_1.tag === /* RequiredField */ 3) {
291
+ if (matchValue_1.fields[0].fields[0] === "00000000-0000-0000-0000-000000000000") {
292
+ void (errors.push(`Constraint '${constraintDef.ConstraintKey}' has empty GUID field key`));
293
+ }
294
+ }
295
+ }, pathway.Constraints);
296
+ }
297
+ if (errors.length === 0) {
298
+ return FSharpResult$2_Ok<void, FSharpList<string>>(undefined);
299
+ }
300
+ else {
301
+ return FSharpResult$2_Error<void, FSharpList<string>>(ofSeq<string>(errors));
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Validate that FormSpec only contains GUID field keys (for form data validation)
307
+ */
308
+ export function validateFormDataFieldKeys(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>): FSharpResult$2_$union<void, FSharpList<string>> {
309
+ const errors: string[] = [];
310
+ iterate<Spec_FormStep$1<Spec_FieldType_$union>>((step: Spec_FormStep$1<Spec_FieldType_$union>): void => {
311
+ iterate<Spec_FormField$1<Spec_FieldType_$union>>((field: Spec_FormField$1<Spec_FieldType_$union>): void => {
312
+ if (field.FieldKey.fields[0] === "00000000-0000-0000-0000-000000000000") {
313
+ void (errors.push(`Step ${step.StepOrder} contains field with empty GUID`));
314
+ }
315
+ }, step.Fields);
316
+ }, formSpec.Steps);
317
+ if (errors.length === 0) {
318
+ return FSharpResult$2_Ok<void, FSharpList<string>>(undefined);
319
+ }
320
+ else {
321
+ return FSharpResult$2_Error<void, FSharpList<string>>(ofSeq<string>(errors));
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Comprehensive validation that ensures FormSpec only works with GUID keys
327
+ */
328
+ export function validateGuidOnlyFormSpec(formSpec: Spec_FormSpec$1<Spec_FieldType_$union>, formSpecWithValues: Option<Spec_FormSpec$1<Spec_FieldType_$union>>): FSharpResult$2_$union<void, FSharpList<string>> {
329
+ const errors: string[] = [];
330
+ const matchValue: FSharpResult$2_$union<void, FSharpList<string>> = validateFormSpecFieldKeys(formSpec);
331
+ if (matchValue.tag === /* Ok */ 0) {
332
+ }
333
+ else {
334
+ addRangeInPlace(matchValue.fields[0], errors);
335
+ }
336
+ if (formSpecWithValues == null) {
337
+ }
338
+ else {
339
+ const matchValue_1: FSharpResult$2_$union<void, FSharpList<string>> = validateFormDataFieldKeys(value_2(formSpecWithValues));
340
+ if (matchValue_1.tag === /* Ok */ 0) {
341
+ }
342
+ else {
343
+ addRangeInPlace(matchValue_1.fields[0], errors);
344
+ }
345
+ }
346
+ if (errors.length === 0) {
347
+ return FSharpResult$2_Ok<void, FSharpList<string>>(undefined);
348
+ }
349
+ else {
350
+ return FSharpResult$2_Error<void, FSharpList<string>>(ofSeq<string>(errors));
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Convert FieldValue to ConditionValue (extracts just the values, no FieldAnswer wrapper)
356
+ */
357
+ export function fieldValueToConditionValue(fieldValue: Shared_FieldValue_$union): Shared_ConditionValue_$union {
358
+ switch (fieldValue.tag) {
359
+ case /* Multiple */ 1:
360
+ return Shared_ConditionValue_Multiple(map_1<Shared_FieldAnswer, string>((a: Shared_FieldAnswer): string => a.Value, fieldValue.fields[0], {
361
+ Compare: comparePrimitives,
362
+ }));
363
+ case /* Matrix */ 2:
364
+ return Shared_ConditionValue_Matrix(fieldValue.fields[0].Values);
365
+ case /* PluginData */ 3: {
366
+ const pluginDataList: FSharpList<Shared_PluginDataProperty> = fieldValue.fields[0];
367
+ if (!isEmpty(pluginDataList)) {
368
+ return Shared_ConditionValue_PluginData(head(pluginDataList));
369
+ }
370
+ else {
371
+ throw new Error("Empty plugin data list cannot be converted to ConditionValue");
372
+ }
373
+ }
374
+ default:
375
+ return Shared_ConditionValue_Single(fieldValue.fields[0].Value);
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Convert ConditionValue to FieldValue (for evaluation - needs fieldKey for FieldAnswer)
381
+ */
382
+ export function conditionValueToFieldValue(conditionValue: Shared_ConditionValue_$union, fieldKey: Shared_FieldKey, fieldLabel: string): Shared_FieldValue_$union {
383
+ switch (conditionValue.tag) {
384
+ case /* Multiple */ 1:
385
+ return Shared_FieldValue_Multiple(map_1<string, Shared_FieldAnswer>((value_1: string): Shared_FieldAnswer => (new Shared_FieldAnswer(fieldKey, fieldLabel, value_1)), conditionValue.fields[0], {
386
+ Compare: compare,
387
+ }));
388
+ case /* Matrix */ 2:
389
+ return Shared_FieldValue_Matrix(new Shared_MatrixAnswer(fieldKey, fieldLabel, conditionValue.fields[0]));
390
+ case /* PluginData */ 3:
391
+ return Shared_FieldValue_PluginData(singleton(conditionValue.fields[0]));
392
+ default:
393
+ return Shared_FieldValue_Single(new Shared_FieldAnswer(fieldKey, fieldLabel, conditionValue.fields[0]));
394
+ }
395
+ }
396
+
397
+ //# sourceMappingURL=FormSpecHelpers.ts.map