@f1studio/form-spec 5.0.0-alpha.111 → 5.0.0-alpha.112

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 (189) hide show
  1. package/FormSpec.FS/BitmaskHelpers.d.ts +23 -0
  2. package/FormSpec.FS/BitmaskHelpers.d.ts.map +1 -0
  3. package/FormSpec.FS/BlueprintValidation.d.ts +16 -0
  4. package/FormSpec.FS/BlueprintValidation.d.ts.map +1 -0
  5. package/FormSpec.FS/FormSpec.d.ts +19 -5
  6. package/FormSpec.FS/FormSpec.d.ts.map +1 -1
  7. package/FormSpec.FS/FormSpecHelpers.d.ts +4 -0
  8. package/FormSpec.FS/FormSpecHelpers.d.ts.map +1 -1
  9. package/FormSpec.FS/FormSpecValues.d.ts +5 -0
  10. package/FormSpec.FS/FormSpecValues.d.ts.map +1 -1
  11. package/FormSpec.FS/Helpers.d.ts.map +1 -1
  12. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRAdapter.d.ts +13 -0
  13. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRAdapter.d.ts.map +1 -0
  14. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRElementTypeMap.d.ts +22 -0
  15. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRElementTypeMap.d.ts.map +1 -0
  16. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.d.ts +22 -0
  17. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.d.ts.map +1 -0
  18. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.d.ts +130 -0
  19. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.d.ts.map +1 -0
  20. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.d.ts +37 -0
  21. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.d.ts.map +1 -0
  22. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.d.ts +231 -0
  23. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.d.ts.map +1 -0
  24. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.d.ts +10 -0
  25. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.d.ts.map +1 -0
  26. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.d.ts +55 -0
  27. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.d.ts.map +1 -0
  28. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.d.ts +69 -0
  29. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.d.ts.map +1 -0
  30. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.d.ts +21 -0
  31. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.d.ts.map +1 -0
  32. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.d.ts +133 -0
  33. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.d.ts.map +1 -0
  34. package/FormSpec.FS/Integrations/Adapters/CorEMR/FormSpecToCoreMRInsert.d.ts +52 -0
  35. package/FormSpec.FS/Integrations/Adapters/CorEMR/FormSpecToCoreMRInsert.d.ts.map +1 -0
  36. package/FormSpec.FS/Integrations/Adapters/FormSystemAdapter.d.ts +46 -0
  37. package/FormSpec.FS/Integrations/Adapters/FormSystemAdapter.d.ts.map +1 -0
  38. package/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormAdapter.d.ts +4 -0
  39. package/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormAdapter.d.ts.map +1 -0
  40. package/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormTypes.d.ts +36 -0
  41. package/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormTypes.d.ts.map +1 -0
  42. package/FormSpec.FS/Integrations/CorEMR/CorEmrTemplates.d.ts +95 -0
  43. package/FormSpec.FS/Integrations/CorEMR/CorEmrTemplates.d.ts.map +1 -0
  44. package/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.d.ts +449 -0
  45. package/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.d.ts.map +1 -0
  46. package/FormSpec.FS/Interop/FormSpec.Api.Helpers.d.ts.map +1 -1
  47. package/FormSpec.FS/Interop/FormSpec.Api.Option.d.ts +3 -1
  48. package/FormSpec.FS/Interop/FormSpec.Api.Option.d.ts.map +1 -1
  49. package/FormSpec.FS/Provenance.d.ts +10 -0
  50. package/FormSpec.FS/Provenance.d.ts.map +1 -0
  51. package/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.d.ts.map +1 -1
  52. package/FormSpec.TS/FormSpec.FS/BitmaskHelpers.js +56 -0
  53. package/FormSpec.TS/FormSpec.FS/BitmaskHelpers.js.map +1 -0
  54. package/FormSpec.TS/FormSpec.FS/BitmaskHelpers.ts.map +1 -0
  55. package/FormSpec.TS/FormSpec.FS/BlueprintValidation.js +116 -0
  56. package/FormSpec.TS/FormSpec.FS/BlueprintValidation.js.map +1 -0
  57. package/FormSpec.TS/FormSpec.FS/BlueprintValidation.ts.map +1 -0
  58. package/FormSpec.TS/FormSpec.FS/Designer.js +2 -2
  59. package/FormSpec.TS/FormSpec.FS/Designer.js.map +1 -1
  60. package/FormSpec.TS/FormSpec.FS/Designer.ts.map +1 -1
  61. package/FormSpec.TS/FormSpec.FS/FormSpec.js +72 -3
  62. package/FormSpec.TS/FormSpec.FS/FormSpec.js.map +1 -1
  63. package/FormSpec.TS/FormSpec.FS/FormSpec.ts.map +1 -1
  64. package/FormSpec.TS/FormSpec.FS/FormSpecHelpers.js +201 -3
  65. package/FormSpec.TS/FormSpec.FS/FormSpecHelpers.js.map +1 -1
  66. package/FormSpec.TS/FormSpec.FS/FormSpecHelpers.ts.map +1 -1
  67. package/FormSpec.TS/FormSpec.FS/FormSpecValues.js +38 -3
  68. package/FormSpec.TS/FormSpec.FS/FormSpecValues.js.map +1 -1
  69. package/FormSpec.TS/FormSpec.FS/FormSpecValues.ts.map +1 -1
  70. package/FormSpec.TS/FormSpec.FS/Helpers.js +44 -27
  71. package/FormSpec.TS/FormSpec.FS/Helpers.js.map +1 -1
  72. package/FormSpec.TS/FormSpec.FS/Helpers.ts.map +1 -1
  73. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRAdapter.js +45 -0
  74. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRAdapter.js.map +1 -0
  75. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRAdapter.ts.map +1 -0
  76. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRElementTypeMap.js +145 -0
  77. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRElementTypeMap.js.map +1 -0
  78. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRElementTypeMap.ts.map +1 -0
  79. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.js +139 -0
  80. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.js.map +1 -0
  81. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.ts.map +1 -0
  82. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.js +801 -0
  83. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.js.map +1 -0
  84. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.ts.map +1 -0
  85. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.js +121 -0
  86. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.js.map +1 -0
  87. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.ts.map +1 -0
  88. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.js +1380 -0
  89. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.js.map +1 -0
  90. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.ts.map +1 -0
  91. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.js +29 -0
  92. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.js.map +1 -0
  93. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.ts.map +1 -0
  94. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.js +172 -0
  95. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.js.map +1 -0
  96. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.ts.map +1 -0
  97. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.js +406 -0
  98. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.js.map +1 -0
  99. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.ts.map +1 -0
  100. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.js +317 -0
  101. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.js.map +1 -0
  102. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.ts.map +1 -0
  103. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.js +622 -0
  104. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.js.map +1 -0
  105. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.ts.map +1 -0
  106. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/FormSpecToCoreMRInsert.js +448 -0
  107. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/FormSpecToCoreMRInsert.js.map +1 -0
  108. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/CorEMR/FormSpecToCoreMRInsert.ts.map +1 -0
  109. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/FormSystemAdapter.js +198 -0
  110. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/FormSystemAdapter.js.map +1 -0
  111. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/FormSystemAdapter.ts.map +1 -0
  112. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormAdapter.js +57 -0
  113. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormAdapter.js.map +1 -0
  114. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormAdapter.ts.map +1 -0
  115. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormTypes.js +144 -0
  116. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormTypes.js.map +1 -0
  117. package/FormSpec.TS/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormTypes.ts.map +1 -0
  118. package/FormSpec.TS/FormSpec.FS/Integrations/CorEMR/CorEmrTemplates.js +258 -0
  119. package/FormSpec.TS/FormSpec.FS/Integrations/CorEMR/CorEmrTemplates.js.map +1 -0
  120. package/FormSpec.TS/FormSpec.FS/Integrations/CorEMR/CorEmrTemplates.ts.map +1 -0
  121. package/FormSpec.TS/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.js +1768 -0
  122. package/FormSpec.TS/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.js.map +1 -0
  123. package/FormSpec.TS/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.ts.map +1 -0
  124. package/FormSpec.TS/FormSpec.FS/Interop/FormSpec.Api.Helpers.js +22 -18
  125. package/FormSpec.TS/FormSpec.FS/Interop/FormSpec.Api.Helpers.js.map +1 -1
  126. package/FormSpec.TS/FormSpec.FS/Interop/FormSpec.Api.Helpers.ts.map +1 -1
  127. package/FormSpec.TS/FormSpec.FS/Interop/FormSpec.Api.Option.js +18 -6
  128. package/FormSpec.TS/FormSpec.FS/Interop/FormSpec.Api.Option.js.map +1 -1
  129. package/FormSpec.TS/FormSpec.FS/Interop/FormSpec.Api.Option.ts.map +1 -1
  130. package/FormSpec.TS/FormSpec.FS/PathwayExecutor.js +1 -1
  131. package/FormSpec.TS/FormSpec.FS/Provenance.js +41 -0
  132. package/FormSpec.TS/FormSpec.FS/Provenance.js.map +1 -0
  133. package/FormSpec.TS/FormSpec.FS/Provenance.ts.map +1 -0
  134. package/FormSpec.TS/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.js +36 -13
  135. package/FormSpec.TS/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.js.map +1 -1
  136. package/FormSpec.TS/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.ts.map +1 -1
  137. package/FormSpec.TS/FormSpec.FS/Renderers/PathwayRenderers.js +1 -1
  138. package/FormSpec.TS/PathwayExecutor.withPlugins.js +0 -5
  139. package/FormSpec.TS/PathwayExecutor.withPlugins.js.map +1 -1
  140. package/FormSpec.TS/PluginRegistration.js +2 -0
  141. package/FormSpec.TS/PluginRegistration.js.map +1 -1
  142. package/FormSpec.TS/PluginRegistration.ts.map +1 -1
  143. package/FormSpec.TS/fable_modules/project_cracked.json +1 -1
  144. package/FormSpec.TS/plugins/demographics/src/DemographicsField.js +918 -0
  145. package/FormSpec.TS/plugins/demographics/src/DemographicsField.js.map +1 -0
  146. package/FormSpec.TS/plugins/demographics/src/DemographicsField.ts.map +1 -0
  147. package/FormSpec.TS/plugins/likert/src/LikertField.js +1 -1
  148. package/PathwayExecutor.withPlugins.d.ts +0 -5
  149. package/PathwayExecutor.withPlugins.d.ts.map +1 -1
  150. package/README.md +7 -7
  151. package/fable_modules/Thoth.Json.10.4.1/Extra.fs.d.ts +3 -0
  152. package/fable_modules/Thoth.Json.10.4.1/Extra.fs.d.ts.map +1 -0
  153. package/package.json +4 -4
  154. package/plugins/demographics/src/DemographicsField.d.ts +104 -0
  155. package/plugins/demographics/src/DemographicsField.d.ts.map +1 -0
  156. package/src/FormSpec.FS/BitmaskHelpers.ts +52 -0
  157. package/src/FormSpec.FS/BlueprintValidation.ts +108 -0
  158. package/src/FormSpec.FS/Designer.ts +2 -2
  159. package/src/FormSpec.FS/FormSpec.ts +39 -8
  160. package/src/FormSpec.FS/FormSpecHelpers.ts +190 -12
  161. package/src/FormSpec.FS/FormSpecValues.ts +42 -3
  162. package/src/FormSpec.FS/Helpers.ts +44 -27
  163. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRAdapter.ts +37 -0
  164. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRElementTypeMap.ts +103 -0
  165. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.ts +129 -0
  166. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.ts +490 -0
  167. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.ts +87 -0
  168. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.ts +1046 -0
  169. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.ts +26 -0
  170. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.ts +161 -0
  171. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.ts +386 -0
  172. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.ts +320 -0
  173. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.ts +371 -0
  174. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/FormSpecToCoreMRInsert.ts +372 -0
  175. package/src/FormSpec.FS/Integrations/Adapters/FormSystemAdapter.ts +92 -0
  176. package/src/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormAdapter.ts +51 -0
  177. package/src/FormSpec.FS/Integrations/Adapters/ReactHookForm/ReactHookFormTypes.ts +71 -0
  178. package/src/FormSpec.FS/Integrations/CorEMR/CorEmrTemplates.ts +15 -0
  179. package/src/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.ts +825 -0
  180. package/src/FormSpec.FS/Interop/FormSpec.Api.Helpers.ts +19 -15
  181. package/src/FormSpec.FS/Interop/FormSpec.Api.Option.ts +13 -7
  182. package/src/FormSpec.FS/PathwayExecutor.ts +1 -1
  183. package/src/FormSpec.FS/Provenance.ts +19 -0
  184. package/src/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.ts +32 -12
  185. package/src/FormSpec.FS/Renderers/PathwayRenderers.ts +1 -1
  186. package/src/PathwayExecutor.withPlugins.ts +0 -5
  187. package/src/PluginRegistration.ts +2 -0
  188. package/src/plugins/demographics/src/DemographicsField.ts +502 -0
  189. package/src/plugins/likert/src/LikertField.ts +1 -1
@@ -0,0 +1,1046 @@
1
+ import { toString as toString_1, MatchFailureException, Record, Union } from "@fable-org/fable-library-js/Types.js";
2
+ import { class_type, list_type, int64_type, bool_type, record_type, float64_type, option_type, string_type, int32_type, union_type, TypeInfo } from "@fable-org/fable-library-js/Reflection.js";
3
+ import { float64, int32 } from "@fable-org/fable-library-js/Int32.js";
4
+ import { value as value_129, map, defaultArg, Option } from "@fable-org/fable-library-js/Option.js";
5
+ import { stringHash, IDisposable, disposeSafe, IEnumerator, getEnumerator, compareArrays, comparePrimitives, IComparable, IEquatable } from "@fable-org/fable-library-js/Util.js";
6
+ import { fromInt32, toInt64, int64 } from "@fable-org/fable-library-js/BigInt.js";
7
+ import { reverse, length, sortByDescending, cons, sortBy, choose, map as map_2, collect, exists, empty as empty_1, tryFind, head, isEmpty, ofArray, FSharpList } from "@fable-org/fable-library-js/List.js";
8
+ import { FSharpMap__get_IsEmpty, tryFind as tryFind_1, FSharpMap__TryFind, ofList, FSharpMap__ContainsKey, FSharpMap } from "@fable-org/fable-library-js/Map.js";
9
+ import { CoreMRFormData, CoreMRChoice, CoreMRItem, CoreMRTrigger, CoreMRTriggerEvent } from "../../CorEMR/CoreMRTypes.js";
10
+ import { toString, utcNow } from "@fable-org/fable-library-js/Date.js";
11
+ import { matches as matches_1, isMatch, create, match } from "@fable-org/fable-library-js/RegExp.js";
12
+ import { map as map_1, delay, toList } from "@fable-org/fable-library-js/Seq.js";
13
+ import { ClinicalPathway_PathwayExecutionMode_$union, ClinicalPathway_TransitionDefinition, Shared_StateKey, Shared_MatrixItemKey, Shared_FieldOptionKey, Shared_FieldKey, Shared_ConditionValue_$union, ClinicalPathway_TransitionCondition_$union, ClinicalPathway_StateType_$union, ClinicalPathway_StateDefinition, ClinicalPathway_ClinicalPathwaySpec, Spec_FormSpec$1, Spec_FormStep$1, Spec_FormField$1 } from "../../../FormSpec.js";
14
+ import { getElementTypeInfo } from "./CorEMRElementTypeMap.js";
15
+ import { Helpers_generateDeterministicGuidRaw } from "../../../Helpers.js";
16
+ import { substring, startsWith } from "@fable-org/fable-library-js/String.js";
17
+ import { StringBuilder__AppendLine, StringBuilder__AppendLine_Z721C83C5, StringBuilder_$ctor } from "@fable-org/fable-library-js/System.Text.js";
18
+ import { List_groupBy } from "@fable-org/fable-library-js/Seq2.js";
19
+ import { newGuid } from "@fable-org/fable-library-js/Guid.js";
20
+
21
+ export type ComplexityLevel_$union =
22
+ | ComplexityLevel<0>
23
+ | ComplexityLevel<1>
24
+ | ComplexityLevel<2>
25
+
26
+ export type ComplexityLevel_$cases = {
27
+ 0: ["Essential", []],
28
+ 1: ["Standard", []],
29
+ 2: ["Advanced", []]
30
+ }
31
+
32
+ export function ComplexityLevel_Essential() {
33
+ return new ComplexityLevel<0>(0, []);
34
+ }
35
+
36
+ export function ComplexityLevel_Standard() {
37
+ return new ComplexityLevel<1>(1, []);
38
+ }
39
+
40
+ export function ComplexityLevel_Advanced() {
41
+ return new ComplexityLevel<2>(2, []);
42
+ }
43
+
44
+ export class ComplexityLevel<Tag extends keyof ComplexityLevel_$cases> extends Union<Tag, ComplexityLevel_$cases[Tag][0]> {
45
+ constructor(readonly tag: Tag, readonly fields: ComplexityLevel_$cases[Tag][1]) {
46
+ super();
47
+ }
48
+ cases() {
49
+ return ["Essential", "Standard", "Advanced"];
50
+ }
51
+ }
52
+
53
+ export function ComplexityLevel_$reflection(): TypeInfo {
54
+ return union_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.ComplexityLevel", [], ComplexityLevel, () => [[], [], []]);
55
+ }
56
+
57
+ /**
58
+ * Get emoji representation of complexity
59
+ */
60
+ export function complexityToEmoji(_arg: ComplexityLevel_$union): string {
61
+ switch (_arg.tag) {
62
+ case /* Standard */ 1:
63
+ return "🟡";
64
+ case /* Advanced */ 2:
65
+ return "🔴";
66
+ default:
67
+ return "🟢";
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Get string representation of complexity
73
+ */
74
+ export function complexityToString(_arg: ComplexityLevel_$union): string {
75
+ switch (_arg.tag) {
76
+ case /* Standard */ 1:
77
+ return "Standard";
78
+ case /* Advanced */ 2:
79
+ return "Advanced";
80
+ default:
81
+ return "Essential";
82
+ }
83
+ }
84
+
85
+ export class InstructionItem extends Record implements IEquatable<InstructionItem>, IComparable<InstructionItem> {
86
+ readonly ItemId: int32;
87
+ readonly ItemType: int32;
88
+ readonly Text: string;
89
+ readonly Pattern: Option<string>;
90
+ readonly Confidence: float64;
91
+ readonly Complexity: ComplexityLevel_$union;
92
+ constructor(ItemId: int32, ItemType: int32, Text$: string, Pattern: Option<string>, Confidence: float64, Complexity: ComplexityLevel_$union) {
93
+ super();
94
+ this.ItemId = (ItemId | 0);
95
+ this.ItemType = (ItemType | 0);
96
+ this.Text = Text$;
97
+ this.Pattern = Pattern;
98
+ this.Confidence = Confidence;
99
+ this.Complexity = Complexity;
100
+ }
101
+ }
102
+
103
+ export function InstructionItem_$reflection(): TypeInfo {
104
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.InstructionItem", [], InstructionItem, () => [["ItemId", int32_type], ["ItemType", int32_type], ["Text", string_type], ["Pattern", option_type(string_type)], ["Confidence", float64_type], ["Complexity", ComplexityLevel_$reflection()]]);
105
+ }
106
+
107
+ export class FormReference extends Record implements IEquatable<FormReference>, IComparable<FormReference> {
108
+ readonly SourceItemId: int32;
109
+ readonly SourceText: string;
110
+ readonly ReferencedFormCode: string;
111
+ readonly ActionSuggested: string;
112
+ readonly Complexity: ComplexityLevel_$union;
113
+ constructor(SourceItemId: int32, SourceText: string, ReferencedFormCode: string, ActionSuggested: string, Complexity: ComplexityLevel_$union) {
114
+ super();
115
+ this.SourceItemId = (SourceItemId | 0);
116
+ this.SourceText = SourceText;
117
+ this.ReferencedFormCode = ReferencedFormCode;
118
+ this.ActionSuggested = ActionSuggested;
119
+ this.Complexity = Complexity;
120
+ }
121
+ }
122
+
123
+ export function FormReference_$reflection(): TypeInfo {
124
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.FormReference", [], FormReference, () => [["SourceItemId", int32_type], ["SourceText", string_type], ["ReferencedFormCode", string_type], ["ActionSuggested", string_type], ["Complexity", ComplexityLevel_$reflection()]]);
125
+ }
126
+
127
+ export class InferredRelationship extends Record implements IEquatable<InferredRelationship>, IComparable<InferredRelationship> {
128
+ readonly Field1: string;
129
+ readonly Field2: string;
130
+ readonly RelationType: string;
131
+ readonly Evidence: string;
132
+ readonly Confidence: float64;
133
+ readonly Complexity: ComplexityLevel_$union;
134
+ constructor(Field1: string, Field2: string, RelationType: string, Evidence: string, Confidence: float64, Complexity: ComplexityLevel_$union) {
135
+ super();
136
+ this.Field1 = Field1;
137
+ this.Field2 = Field2;
138
+ this.RelationType = RelationType;
139
+ this.Evidence = Evidence;
140
+ this.Confidence = Confidence;
141
+ this.Complexity = Complexity;
142
+ }
143
+ }
144
+
145
+ export function InferredRelationship_$reflection(): TypeInfo {
146
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.InferredRelationship", [], InferredRelationship, () => [["Field1", string_type], ["Field2", string_type], ["RelationType", string_type], ["Evidence", string_type], ["Confidence", float64_type], ["Complexity", ComplexityLevel_$reflection()]]);
147
+ }
148
+
149
+ export class ConfidenceMetrics extends Record implements IEquatable<ConfidenceMetrics>, IComparable<ConfidenceMetrics> {
150
+ readonly MechanicalConversionRate: float64;
151
+ readonly InstructionDetectionRate: float64;
152
+ readonly EnhancementOpportunities: int32;
153
+ readonly UnmappedItemCount: int32;
154
+ constructor(MechanicalConversionRate: float64, InstructionDetectionRate: float64, EnhancementOpportunities: int32, UnmappedItemCount: int32) {
155
+ super();
156
+ this.MechanicalConversionRate = MechanicalConversionRate;
157
+ this.InstructionDetectionRate = InstructionDetectionRate;
158
+ this.EnhancementOpportunities = (EnhancementOpportunities | 0);
159
+ this.UnmappedItemCount = (UnmappedItemCount | 0);
160
+ }
161
+ }
162
+
163
+ export function ConfidenceMetrics_$reflection(): TypeInfo {
164
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.ConfidenceMetrics", [], ConfidenceMetrics, () => [["MechanicalConversionRate", float64_type], ["InstructionDetectionRate", float64_type], ["EnhancementOpportunities", int32_type], ["UnmappedItemCount", int32_type]]);
165
+ }
166
+
167
+ export class FieldCatalogEntry extends Record implements IEquatable<FieldCatalogEntry>, IComparable<FieldCatalogEntry> {
168
+ readonly ItemId: int32;
169
+ readonly FieldKey: string;
170
+ readonly Label: string;
171
+ readonly FieldType: string;
172
+ readonly IsRequired: boolean;
173
+ readonly ParentId: Option<int32>;
174
+ readonly Notes: Option<string>;
175
+ readonly Complexity: ComplexityLevel_$union;
176
+ constructor(ItemId: int32, FieldKey: string, Label: string, FieldType: string, IsRequired: boolean, ParentId: Option<int32>, Notes: Option<string>, Complexity: ComplexityLevel_$union) {
177
+ super();
178
+ this.ItemId = (ItemId | 0);
179
+ this.FieldKey = FieldKey;
180
+ this.Label = Label;
181
+ this.FieldType = FieldType;
182
+ this.IsRequired = IsRequired;
183
+ this.ParentId = ParentId;
184
+ this.Notes = Notes;
185
+ this.Complexity = Complexity;
186
+ }
187
+ }
188
+
189
+ export function FieldCatalogEntry_$reflection(): TypeInfo {
190
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.FieldCatalogEntry", [], FieldCatalogEntry, () => [["ItemId", int32_type], ["FieldKey", string_type], ["Label", string_type], ["FieldType", string_type], ["IsRequired", bool_type], ["ParentId", option_type(int32_type)], ["Notes", option_type(string_type)], ["Complexity", ComplexityLevel_$reflection()]]);
191
+ }
192
+
193
+ export class ChoiceCatalogEntry extends Record implements IEquatable<ChoiceCatalogEntry>, IComparable<ChoiceCatalogEntry> {
194
+ readonly ChoiceId: int32;
195
+ readonly ItemId: int32;
196
+ readonly FieldKey: string;
197
+ readonly OptionKey: string;
198
+ readonly Text: string;
199
+ readonly Score: int64;
200
+ readonly Sequence: int32;
201
+ constructor(ChoiceId: int32, ItemId: int32, FieldKey: string, OptionKey: string, Text$: string, Score: int64, Sequence: int32) {
202
+ super();
203
+ this.ChoiceId = (ChoiceId | 0);
204
+ this.ItemId = (ItemId | 0);
205
+ this.FieldKey = FieldKey;
206
+ this.OptionKey = OptionKey;
207
+ this.Text = Text$;
208
+ this.Score = Score;
209
+ this.Sequence = (Sequence | 0);
210
+ }
211
+ }
212
+
213
+ export function ChoiceCatalogEntry_$reflection(): TypeInfo {
214
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.ChoiceCatalogEntry", [], ChoiceCatalogEntry, () => [["ChoiceId", int32_type], ["ItemId", int32_type], ["FieldKey", string_type], ["OptionKey", string_type], ["Text", string_type], ["Score", int64_type], ["Sequence", int32_type]]);
215
+ }
216
+
217
+ export class PathwayState extends Record implements IEquatable<PathwayState>, IComparable<PathwayState> {
218
+ readonly StateKey: string;
219
+ readonly StateType: string;
220
+ readonly StateLabel: string;
221
+ readonly StateOrder: int32;
222
+ constructor(StateKey: string, StateType: string, StateLabel: string, StateOrder: int32) {
223
+ super();
224
+ this.StateKey = StateKey;
225
+ this.StateType = StateType;
226
+ this.StateLabel = StateLabel;
227
+ this.StateOrder = (StateOrder | 0);
228
+ }
229
+ }
230
+
231
+ export function PathwayState_$reflection(): TypeInfo {
232
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.PathwayState", [], PathwayState, () => [["StateKey", string_type], ["StateType", string_type], ["StateLabel", string_type], ["StateOrder", int32_type]]);
233
+ }
234
+
235
+ export class PathwayTransition extends Record implements IEquatable<PathwayTransition>, IComparable<PathwayTransition> {
236
+ readonly TransitionKey: string;
237
+ readonly FromState: string;
238
+ readonly ToState: string;
239
+ readonly ConditionType: string;
240
+ readonly ConditionSummary: string;
241
+ constructor(TransitionKey: string, FromState: string, ToState: string, ConditionType: string, ConditionSummary: string) {
242
+ super();
243
+ this.TransitionKey = TransitionKey;
244
+ this.FromState = FromState;
245
+ this.ToState = ToState;
246
+ this.ConditionType = ConditionType;
247
+ this.ConditionSummary = ConditionSummary;
248
+ }
249
+ }
250
+
251
+ export function PathwayTransition_$reflection(): TypeInfo {
252
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.PathwayTransition", [], PathwayTransition, () => [["TransitionKey", string_type], ["FromState", string_type], ["ToState", string_type], ["ConditionType", string_type], ["ConditionSummary", string_type]]);
253
+ }
254
+
255
+ export class PathwayContext extends Record implements IEquatable<PathwayContext>, IComparable<PathwayContext> {
256
+ readonly States: FSharpList<PathwayState>;
257
+ readonly Transitions: FSharpList<PathwayTransition>;
258
+ readonly ExecutionMode: string;
259
+ constructor(States: FSharpList<PathwayState>, Transitions: FSharpList<PathwayTransition>, ExecutionMode: string) {
260
+ super();
261
+ this.States = States;
262
+ this.Transitions = Transitions;
263
+ this.ExecutionMode = ExecutionMode;
264
+ }
265
+ }
266
+
267
+ export function PathwayContext_$reflection(): TypeInfo {
268
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.PathwayContext", [], PathwayContext, () => [["States", list_type(PathwayState_$reflection())], ["Transitions", list_type(PathwayTransition_$reflection())], ["ExecutionMode", string_type]]);
269
+ }
270
+
271
+ export class SemanticReport extends Record implements IEquatable<SemanticReport>, IComparable<SemanticReport> {
272
+ readonly FormId: string;
273
+ readonly FormName: string;
274
+ readonly FormCode: Option<string>;
275
+ readonly FieldCatalog: FSharpList<FieldCatalogEntry>;
276
+ readonly ChoiceCatalog: FSharpList<ChoiceCatalogEntry>;
277
+ readonly PathwayContext: Option<PathwayContext>;
278
+ readonly UnmappedInstructions: FSharpList<InstructionItem>;
279
+ readonly InferredRelationships: FSharpList<InferredRelationship>;
280
+ readonly CrossFormReferences: FSharpList<FormReference>;
281
+ readonly Confidence: ConfidenceMetrics;
282
+ readonly GeneratedAt: Date;
283
+ readonly ActionTypeSuggestions: FSharpList<ActionTypeSuggestion>;
284
+ constructor(FormId: string, FormName: string, FormCode: Option<string>, FieldCatalog: FSharpList<FieldCatalogEntry>, ChoiceCatalog: FSharpList<ChoiceCatalogEntry>, PathwayContext: Option<PathwayContext>, UnmappedInstructions: FSharpList<InstructionItem>, InferredRelationships: FSharpList<InferredRelationship>, CrossFormReferences: FSharpList<FormReference>, Confidence: ConfidenceMetrics, GeneratedAt: Date, ActionTypeSuggestions: FSharpList<ActionTypeSuggestion>) {
285
+ super();
286
+ this.FormId = FormId;
287
+ this.FormName = FormName;
288
+ this.FormCode = FormCode;
289
+ this.FieldCatalog = FieldCatalog;
290
+ this.ChoiceCatalog = ChoiceCatalog;
291
+ this.PathwayContext = PathwayContext;
292
+ this.UnmappedInstructions = UnmappedInstructions;
293
+ this.InferredRelationships = InferredRelationships;
294
+ this.CrossFormReferences = CrossFormReferences;
295
+ this.Confidence = Confidence;
296
+ this.GeneratedAt = GeneratedAt;
297
+ this.ActionTypeSuggestions = ActionTypeSuggestions;
298
+ }
299
+ }
300
+
301
+ export function SemanticReport_$reflection(): TypeInfo {
302
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.SemanticReport", [], SemanticReport, () => [["FormId", class_type("System.Guid")], ["FormName", string_type], ["FormCode", option_type(string_type)], ["FieldCatalog", list_type(FieldCatalogEntry_$reflection())], ["ChoiceCatalog", list_type(ChoiceCatalogEntry_$reflection())], ["PathwayContext", option_type(PathwayContext_$reflection())], ["UnmappedInstructions", list_type(InstructionItem_$reflection())], ["InferredRelationships", list_type(InferredRelationship_$reflection())], ["CrossFormReferences", list_type(FormReference_$reflection())], ["Confidence", ConfidenceMetrics_$reflection()], ["GeneratedAt", class_type("System.DateTime")], ["ActionTypeSuggestions", list_type(ActionTypeSuggestion_$reflection())]]);
303
+ }
304
+
305
+ export class ActionTypeSuggestion extends Record implements IEquatable<ActionTypeSuggestion>, IComparable<ActionTypeSuggestion> {
306
+ readonly EventType: string;
307
+ readonly EventParams: FSharpMap<string, string>;
308
+ readonly SuggestedActionType: string;
309
+ readonly Confidence: float64;
310
+ readonly Reasoning: string;
311
+ readonly SuggestedParameters: Option<FSharpMap<string, string>>;
312
+ readonly TargetItemId: Option<int32>;
313
+ readonly TargetFieldKey: Option<string>;
314
+ constructor(EventType: string, EventParams: FSharpMap<string, string>, SuggestedActionType: string, Confidence: float64, Reasoning: string, SuggestedParameters: Option<FSharpMap<string, string>>, TargetItemId: Option<int32>, TargetFieldKey: Option<string>) {
315
+ super();
316
+ this.EventType = EventType;
317
+ this.EventParams = EventParams;
318
+ this.SuggestedActionType = SuggestedActionType;
319
+ this.Confidence = Confidence;
320
+ this.Reasoning = Reasoning;
321
+ this.SuggestedParameters = SuggestedParameters;
322
+ this.TargetItemId = TargetItemId;
323
+ this.TargetFieldKey = TargetFieldKey;
324
+ }
325
+ }
326
+
327
+ export function ActionTypeSuggestion_$reflection(): TypeInfo {
328
+ return record_type("FormSpec.Integrations.CorEMR.CorEMRSemanticReportBuilder.ActionTypeSuggestion", [], ActionTypeSuggestion, () => [["EventType", string_type], ["EventParams", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, string_type])], ["SuggestedActionType", string_type], ["Confidence", float64_type], ["Reasoning", string_type], ["SuggestedParameters", option_type(class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, string_type]))], ["TargetItemId", option_type(int32_type)], ["TargetFieldKey", option_type(string_type)]]);
329
+ }
330
+
331
+ /**
332
+ * Analyze CoreMR event type and suggest appropriate FormSpec action type
333
+ */
334
+ export function ActionTypeAnalysis_analyzeEventType(eventType: string, eventParams: FSharpMap<string, string>): [string, float64, string] {
335
+ const matchValue: string = eventType.toLowerCase();
336
+ switch (matchValue) {
337
+ case "task":
338
+ return ["task", 0.95, "CoreMR task events map directly to FormSpec task actions for workflow management"] as [string, float64, string];
339
+ case "taskcomplete":
340
+ return ["task", 0.9, "Task completion events should trigger task actions for workflow tracking"] as [string, float64, string];
341
+ case "alert":
342
+ return ["alert", 0.95, "CoreMR alert events map directly to FormSpec alert actions for clinical notifications"] as [string, float64, string];
343
+ case "medset":
344
+ if (FSharpMap__ContainsKey(eventParams, "quantity") ? true : FSharpMap__ContainsKey(eventParams, "refills")) {
345
+ return ["prescription", 0.9, "Medication event with quantity/refills suggests prescription action"] as [string, float64, string];
346
+ }
347
+ else {
348
+ return ["medication", 0.85, "Medication event suggests administration action"] as [string, float64, string];
349
+ }
350
+ case "problem":
351
+ return ["problem", 0.95, "Problem events map directly to FormSpec problem actions for problem list management"] as [string, float64, string];
352
+ default:
353
+ return ["documentation", 0.3, `Unknown CoreMR event type '${eventType}' - defaulting to documentation with low confidence`] as [string, float64, string];
354
+ }
355
+ }
356
+
357
+ /**
358
+ * Generate suggested parameters for FormSpec action based on CoreMR event
359
+ */
360
+ export function ActionTypeAnalysis_generateSuggestedParameters(actionType: string, eventParams: FSharpMap<string, string>): Option<FSharpMap<string, string>> {
361
+ switch (actionType) {
362
+ case "task":
363
+ return ofList<string, string>(ofArray([["category", defaultArg(FSharpMap__TryFind(eventParams, "cat_desc"), "General")] as [string, string], ["priority", "medium"] as [string, string], ["assignee", "Assigned Clinician"] as [string, string]]), {
364
+ Compare: comparePrimitives,
365
+ });
366
+ case "alert":
367
+ return ofList<string, string>(ofArray([["category", defaultArg(FSharpMap__TryFind(eventParams, "category_desc"), "Clinical")] as [string, string], ["severity", "medium"] as [string, string]]), {
368
+ Compare: comparePrimitives,
369
+ });
370
+ case "medication":
371
+ return ofList<string, string>(ofArray([["medication_name", defaultArg(FSharpMap__TryFind(eventParams, "medication_name"), "As prescribed")] as [string, string], ["dose", defaultArg(FSharpMap__TryFind(eventParams, "dose"), "As directed")] as [string, string], ["route", "PO"] as [string, string], ["frequency", "As directed"] as [string, string]]), {
372
+ Compare: comparePrimitives,
373
+ });
374
+ case "prescription":
375
+ return ofList<string, string>(ofArray([["medication_name", defaultArg(FSharpMap__TryFind(eventParams, "medication_name"), "As prescribed")] as [string, string], ["quantity", "30"] as [string, string]]), {
376
+ Compare: comparePrimitives,
377
+ });
378
+ case "problem":
379
+ return ofList<string, string>(ofArray([["problem_name", defaultArg(FSharpMap__TryFind(eventParams, "problem_desc"), "Clinical problem")] as [string, string], ["status", "active"] as [string, string]]), {
380
+ Compare: comparePrimitives,
381
+ });
382
+ default:
383
+ return undefined;
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Analyze a CoreMR trigger and generate action type suggestion
389
+ */
390
+ export function ActionTypeAnalysis_analyzeTrigger(trigger: CoreMRTrigger, fieldCatalog: FSharpList<FieldCatalogEntry>): Option<ActionTypeSuggestion> {
391
+ const matchValue: FSharpList<CoreMRTriggerEvent> = trigger.Events;
392
+ if (isEmpty(matchValue)) {
393
+ return undefined;
394
+ }
395
+ else {
396
+ const event: CoreMRTriggerEvent = head<CoreMRTriggerEvent>(matchValue);
397
+ const eventParams: FSharpMap<string, string> = event.EventParams;
398
+ const patternInput: [string, float64, string] = ActionTypeAnalysis_analyzeEventType(event.EventType, eventParams);
399
+ const suggestedActionType: string = patternInput[0];
400
+ return new ActionTypeSuggestion(event.EventType, eventParams, suggestedActionType, patternInput[1], patternInput[2], ActionTypeAnalysis_generateSuggestedParameters(suggestedActionType, eventParams), trigger.TargetItemId, map<FieldCatalogEntry, string>((f_1: FieldCatalogEntry): string => f_1.FieldKey, tryFind<FieldCatalogEntry>((f: FieldCatalogEntry): boolean => (f.ItemId === trigger.TargetItemId), fieldCatalog)));
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Create an empty semantic report
406
+ */
407
+ export function empty(formId: string, formName: string): SemanticReport {
408
+ return new SemanticReport(formId, formName, undefined, empty_1<FieldCatalogEntry>(), empty_1<ChoiceCatalogEntry>(), undefined, empty_1<InstructionItem>(), empty_1<InferredRelationship>(), empty_1<FormReference>(), new ConfidenceMetrics(0, 0, 0, 0), utcNow(), empty_1<ActionTypeSuggestion>());
409
+ }
410
+
411
+ /**
412
+ * Extract form code from name using pattern matching
413
+ */
414
+ export function extractFormCode(formName: string): Option<string> {
415
+ const m: any = match(create("\\b([A-Z]{2,3}-\\d{3}[A-Z]?)\\b"), formName);
416
+ if (m != null) {
417
+ return m[1] || "";
418
+ }
419
+ else {
420
+ return undefined;
421
+ }
422
+ }
423
+
424
+ /**
425
+ * Determine complexity based on instruction pattern
426
+ */
427
+ export function scoreInstructionComplexity(text: string, pattern: Option<string>): ComplexityLevel_$union {
428
+ let p: string, p_1: string;
429
+ if (pattern == null) {
430
+ if ((text.indexOf("protocol") >= 0) ? true : (text.indexOf("navigate") >= 0)) {
431
+ return ComplexityLevel_Advanced();
432
+ }
433
+ else if ((text.indexOf("if") >= 0) ? true : (text.indexOf("when") >= 0)) {
434
+ return ComplexityLevel_Standard();
435
+ }
436
+ else {
437
+ return ComplexityLevel_Essential();
438
+ }
439
+ }
440
+ else if ((p = value_129(pattern), (p.indexOf("cross-form") >= 0) ? true : (p.indexOf("protocol") >= 0))) {
441
+ const p_2: string = value_129(pattern);
442
+ return ComplexityLevel_Advanced();
443
+ }
444
+ else if ((p_1 = value_129(pattern), (p_1.indexOf("conditional") >= 0) ? true : (p_1.indexOf("if") >= 0))) {
445
+ const p_3: string = value_129(pattern);
446
+ return ComplexityLevel_Standard();
447
+ }
448
+ else {
449
+ return ComplexityLevel_Essential();
450
+ }
451
+ }
452
+
453
+ /**
454
+ * Determine field complexity based on requirements
455
+ */
456
+ export function scoreFieldComplexity(isRequired: boolean, hasDependency: boolean, hasComplexLogic: boolean): ComplexityLevel_$union {
457
+ if (hasComplexLogic) {
458
+ return ComplexityLevel_Advanced();
459
+ }
460
+ else if (isRequired) {
461
+ if (hasDependency) {
462
+ throw new MatchFailureException("/Users/luisfx/code/luisfx/f1-monorepo/packages/core/form-spec/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.fs", 302, 14);
463
+ }
464
+ else {
465
+ return ComplexityLevel_Essential();
466
+ }
467
+ }
468
+ else if (hasDependency) {
469
+ return ComplexityLevel_Standard();
470
+ }
471
+ else {
472
+ return ComplexityLevel_Standard();
473
+ }
474
+ }
475
+
476
+ /**
477
+ * Check if text contains conditional instruction
478
+ */
479
+ export function hasInstruction(text: string): boolean {
480
+ return exists<string>((p: string): boolean => isMatch(create(p, 1), text), ofArray(["\\bIf\\s+", "\\bWhen\\s+", "\\bcomplete\\s+", "\\bperform\\s+", "\\border\\s+", "\\brefer\\s+"]));
481
+ }
482
+
483
+ /**
484
+ * Check if text contains form reference
485
+ */
486
+ export function hasFormReference(text: string): boolean {
487
+ return isMatch(create("\\[[A-Z]{2,3}-\\d{3}[A-Z]?\\]"), text);
488
+ }
489
+
490
+ /**
491
+ * Extract form references from text
492
+ */
493
+ export function extractFormReferences(itemId: int32, text: string): FSharpList<FormReference> {
494
+ const matches: any = matches_1(create("\\[([A-Z]{2,3}-\\d{3}[A-Z]?)\\]"), text);
495
+ return toList<FormReference>(delay<FormReference>((): Iterable<FormReference> => map_1<any, FormReference>((m: any): FormReference => (new FormReference(itemId, text, m[1] || "", "Navigate to form", ComplexityLevel_Advanced())), matches)));
496
+ }
497
+
498
+ /**
499
+ * Build field catalog from CoreMR items and FormSpec
500
+ */
501
+ export function buildFieldCatalog<T>(items: FSharpList<CoreMRItem>, formSpec: Spec_FormSpec$1<T>): FSharpList<FieldCatalogEntry> {
502
+ const fieldDataMap: FSharpMap<string, [string, Option<string>]> = ofList<string, [string, Option<string>]>(collect<Spec_FormStep$1<T>, [string, [string, Option<string>]]>((step: Spec_FormStep$1<T>): FSharpList<[string, [string, Option<string>]]> => map_2<Spec_FormField$1<T>, [string, [string, Option<string>]]>((field: Spec_FormField$1<T>): [string, [string, Option<string>]] => ([field.Label, [field.FieldKey.fields[0], field.Notes] as [string, Option<string>]] as [string, [string, Option<string>]]), step.Fields), formSpec.Steps), {
503
+ Compare: comparePrimitives,
504
+ });
505
+ return choose<CoreMRItem, FieldCatalogEntry>((item: CoreMRItem): Option<FieldCatalogEntry> => {
506
+ const matchValue: Option<[string, Option<string>]> = tryFind_1<string, [string, Option<string>]>(item.Label, fieldDataMap);
507
+ if (matchValue == null) {
508
+ if (getElementTypeInfo(item.ItemTypeId).IsScaffold) {
509
+ return undefined;
510
+ }
511
+ else {
512
+ return new FieldCatalogEntry(item.ItemId, `unmapped_${item.ItemId}`, item.Label, item.ItemTypeName, item.IsRequired, item.ParentId, undefined, scoreFieldComplexity(item.IsRequired, item.ParentId != null, false));
513
+ }
514
+ }
515
+ else {
516
+ const notes: Option<string> = value_129(matchValue)[1];
517
+ return new FieldCatalogEntry(item.ItemId, value_129(matchValue)[0], item.Label, item.ItemTypeName, item.IsRequired, item.ParentId, notes, scoreFieldComplexity(item.IsRequired, item.ParentId != null, (notes != null) && (value_129(notes).indexOf("if") >= 0)));
518
+ }
519
+ }, items);
520
+ }
521
+
522
+ /**
523
+ * Build choice catalog from CoreMR choices and FormSpec
524
+ */
525
+ export function buildChoiceCatalog<T>(choices: FSharpList<CoreMRChoice>, formSpec: Spec_FormSpec$1<T>, fieldCatalog: FSharpList<FieldCatalogEntry>): FSharpList<ChoiceCatalogEntry> {
526
+ const fieldLookup: FSharpMap<int32, string> = ofList<int32, string>(map_2<FieldCatalogEntry, [int32, string]>((f: FieldCatalogEntry): [int32, string] => ([f.ItemId, f.FieldKey] as [int32, string]), fieldCatalog), {
527
+ Compare: comparePrimitives,
528
+ });
529
+ return sortBy<ChoiceCatalogEntry, [int32, int32]>((c: ChoiceCatalogEntry): [int32, int32] => ([c.ItemId, c.Sequence] as [int32, int32]), choose<CoreMRChoice, ChoiceCatalogEntry>((choice: CoreMRChoice): Option<ChoiceCatalogEntry> => {
530
+ const matchValue: Option<string> = tryFind_1<int32, string>(choice.ItemId, fieldLookup);
531
+ if (matchValue == null) {
532
+ return undefined;
533
+ }
534
+ else {
535
+ return new ChoiceCatalogEntry(choice.ChoiceId, choice.ItemId, value_129(matchValue), Helpers_generateDeterministicGuidRaw(`coremr:semantic-choice:${choice.ItemId}:${choice.ChoiceId}:${choice.Sequence}:${choice.Text}`), choice.Text, toInt64(fromInt32(choice.Score)), choice.Sequence);
536
+ }
537
+ }, choices), {
538
+ Compare: compareArrays,
539
+ });
540
+ }
541
+
542
+ /**
543
+ * Build pathway context from FormSpec clinical pathway
544
+ */
545
+ export function buildPathwayContext(pathway: Option<ClinicalPathway_ClinicalPathwaySpec>): Option<PathwayContext> {
546
+ let matchValue_3: ClinicalPathway_PathwayExecutionMode_$union;
547
+ if (pathway != null) {
548
+ const p: ClinicalPathway_ClinicalPathwaySpec = value_129(pathway);
549
+ return new PathwayContext(map_2<ClinicalPathway_StateDefinition, PathwayState>((state: ClinicalPathway_StateDefinition): PathwayState => {
550
+ let matchValue: ClinicalPathway_StateType_$union;
551
+ return new PathwayState(state.StateKey.fields[0], (matchValue = state.StateType, (matchValue.tag === /* Evaluation */ 1) ? "Evaluation" : ((matchValue.tag === /* Action */ 2) ? "Action" : ((matchValue.tag === /* Terminal */ 5) ? "Terminal" : ((matchValue.tag === /* CompoundAction */ 3) ? "CompoundAction" : ((matchValue.tag === /* ConditionalAction */ 4) ? "ConditionalAction" : (() => {
552
+ throw new Error("Match failure: F1.Studio.ClinicalPathway.StateType");
553
+ })()))))), state.StateLabel, state.StateOrder);
554
+ }, p.States), map_2<ClinicalPathway_TransitionDefinition, PathwayTransition>((trans: ClinicalPathway_TransitionDefinition): PathwayTransition => {
555
+ let matchValue_2: ClinicalPathway_TransitionCondition_$union;
556
+ const transKey: string = trans.TransitionKey.fields[0];
557
+ const fromKey: string = trans.FromState.fields[0];
558
+ const toKey: string = trans.ToState.fields[0];
559
+ let conditionSummary: string;
560
+ const matchValue_1: ClinicalPathway_TransitionCondition_$union = trans.Condition;
561
+ switch (matchValue_1.tag) {
562
+ case /* Always */ 8: {
563
+ conditionSummary = "Always";
564
+ break;
565
+ }
566
+ case /* FieldCondition */ 0: {
567
+ const value: Shared_ConditionValue_$union = matchValue_1.fields[2];
568
+ const fieldKey: Shared_FieldKey = matchValue_1.fields[0];
569
+ conditionSummary = (`Field: ${matchValue_1.fields[1]}`);
570
+ break;
571
+ }
572
+ case /* FieldOptionCondition */ 1: {
573
+ const value_1: Shared_ConditionValue_$union = matchValue_1.fields[4];
574
+ const optionKey: Shared_FieldOptionKey = matchValue_1.fields[2];
575
+ const itemKey: Option<Shared_MatrixItemKey> = matchValue_1.fields[1];
576
+ const fieldKey_1: Shared_FieldKey = matchValue_1.fields[0];
577
+ conditionSummary = (`Option: ${matchValue_1.fields[3]}`);
578
+ break;
579
+ }
580
+ case /* CompositeCondition */ 6: {
581
+ const conditions: FSharpList<ClinicalPathway_TransitionCondition_$union> = matchValue_1.fields[1];
582
+ conditionSummary = (`Composite: ${matchValue_1.fields[0]}`);
583
+ break;
584
+ }
585
+ case /* StateCondition */ 5: {
586
+ const stateKey: Shared_StateKey = matchValue_1.fields[0];
587
+ conditionSummary = (`State: ${matchValue_1.fields[1]}`);
588
+ break;
589
+ }
590
+ case /* TestResultCondition */ 7: {
591
+ conditionSummary = (`Test: ${matchValue_1.fields[0]} = ${matchValue_1.fields[1]}`);
592
+ break;
593
+ }
594
+ default:
595
+ throw new Error("Match failure: F1.Studio.ClinicalPathway.TransitionCondition");
596
+ }
597
+ return new PathwayTransition(transKey, fromKey, toKey, (matchValue_2 = trans.Condition, (matchValue_2.tag === /* Always */ 8) ? "automatic" : ((matchValue_2.tag === /* FieldCondition */ 0) ? "field" : ((matchValue_2.tag === /* FieldOptionCondition */ 1) ? "field_option" : ((matchValue_2.tag === /* CompositeCondition */ 6) ? "composite" : ((matchValue_2.tag === /* StateCondition */ 5) ? "state" : ((matchValue_2.tag === /* TestResultCondition */ 7) ? "test_result" : (() => {
598
+ throw new Error("Match failure: F1.Studio.ClinicalPathway.TransitionCondition");
599
+ })())))))), conditionSummary);
600
+ }, p.Transitions), (matchValue_3 = p.ExecutionMode, (matchValue_3.tag === /* MultiPathway */ 1) ? "MultiPathway" : ((matchValue_3.tag === /* TriggerBased */ 2) ? "TriggerBased" : "SinglePathway")));
601
+ }
602
+ else {
603
+ return undefined;
604
+ }
605
+ }
606
+
607
+ /**
608
+ * Add unmapped instruction to report with enhanced context
609
+ */
610
+ export function addUnmappedInstruction(report: SemanticReport, item: CoreMRItem): SemanticReport {
611
+ let matchValue: Option<string>, text: string;
612
+ const pattern: Option<string> = startsWith(item.Label, "If ", 5) ? ("Conditional instruction" + ((matchValue = ((text = item.Label, (text.indexOf("cardiac risk factors") >= 0) ? "Check Field 20984 (Cardiac Risk Factors)" : ((text.indexOf("no CV risk factors") >= 0) ? "Check Field 20984 is empty AND vitals normal" : ((text.indexOf("referral") >= 0) ? "Check if referral field has value" : undefined)))), (matchValue == null) ? "" : (" - " + value_129(matchValue))))) : undefined;
613
+ return new SemanticReport(report.FormId, report.FormName, report.FormCode, report.FieldCatalog, report.ChoiceCatalog, report.PathwayContext, cons(new InstructionItem(item.ItemId, item.ItemTypeId, item.Label, pattern, 0.75, scoreInstructionComplexity(item.Label, pattern)), report.UnmappedInstructions), report.InferredRelationships, report.CrossFormReferences, report.Confidence, report.GeneratedAt, report.ActionTypeSuggestions);
614
+ }
615
+
616
+ /**
617
+ * Add cross-form reference to report
618
+ */
619
+ export function addCrossFormReference(report: SemanticReport, reference: FormReference): SemanticReport {
620
+ return new SemanticReport(report.FormId, report.FormName, report.FormCode, report.FieldCatalog, report.ChoiceCatalog, report.PathwayContext, report.UnmappedInstructions, report.InferredRelationships, cons(reference, report.CrossFormReferences), report.Confidence, report.GeneratedAt, report.ActionTypeSuggestions);
621
+ }
622
+
623
+ /**
624
+ * Add inferred relationship to report
625
+ */
626
+ export function addInferredRelationship(report: SemanticReport, field1: string, field2: string, relationType: string, evidence: string): SemanticReport {
627
+ return new SemanticReport(report.FormId, report.FormName, report.FormCode, report.FieldCatalog, report.ChoiceCatalog, report.PathwayContext, report.UnmappedInstructions, cons(new InferredRelationship(field1, field2, relationType, evidence, 0.65, (relationType === "triggers") ? ComplexityLevel_Standard() : ((relationType === "requires") ? ComplexityLevel_Standard() : ((relationType === "correlates with") ? ComplexityLevel_Essential() : ComplexityLevel_Standard()))), report.InferredRelationships), report.CrossFormReferences, report.Confidence, report.GeneratedAt, report.ActionTypeSuggestions);
628
+ }
629
+
630
+ /**
631
+ * Build action type suggestions from CoreMR triggers
632
+ */
633
+ export function buildActionTypeSuggestions(triggers: FSharpList<CoreMRTrigger>, fieldCatalog: FSharpList<FieldCatalogEntry>): FSharpList<ActionTypeSuggestion> {
634
+ return sortByDescending<ActionTypeSuggestion, float64>((suggestion_2: ActionTypeSuggestion): float64 => suggestion_2.Confidence, choose<CoreMRTrigger, ActionTypeSuggestion>((trigger: CoreMRTrigger): Option<ActionTypeSuggestion> => {
635
+ const matchValue: Option<ActionTypeSuggestion> = ActionTypeAnalysis_analyzeTrigger(trigger, fieldCatalog);
636
+ let matchResult: int32, suggestion_1: ActionTypeSuggestion;
637
+ if (matchValue != null) {
638
+ if (value_129(matchValue).Confidence > 0.5) {
639
+ matchResult = 0;
640
+ suggestion_1 = value_129(matchValue);
641
+ }
642
+ else {
643
+ matchResult = 1;
644
+ }
645
+ }
646
+ else {
647
+ matchResult = 1;
648
+ }
649
+ switch (matchResult) {
650
+ case 0:
651
+ return suggestion_1!;
652
+ default:
653
+ return undefined;
654
+ }
655
+ }, triggers), {
656
+ Compare: comparePrimitives,
657
+ });
658
+ }
659
+
660
+ /**
661
+ * Add action type suggestion to the report
662
+ */
663
+ export function addActionTypeSuggestion(report: SemanticReport, suggestion: ActionTypeSuggestion): SemanticReport {
664
+ return new SemanticReport(report.FormId, report.FormName, report.FormCode, report.FieldCatalog, report.ChoiceCatalog, report.PathwayContext, report.UnmappedInstructions, report.InferredRelationships, report.CrossFormReferences, report.Confidence, report.GeneratedAt, cons(suggestion, report.ActionTypeSuggestions));
665
+ }
666
+
667
+ /**
668
+ * Calculate confidence metrics
669
+ */
670
+ export function calculateMetrics(report: SemanticReport, totalItems: int32, triggersConverted: int32): SemanticReport {
671
+ return new SemanticReport(report.FormId, report.FormName, report.FormCode, report.FieldCatalog, report.ChoiceCatalog, report.PathwayContext, report.UnmappedInstructions, report.InferredRelationships, report.CrossFormReferences, new ConfidenceMetrics((totalItems > 0) ? ((triggersConverted / totalItems) * 100) : 0, (totalItems > 0) ? ((length(report.UnmappedInstructions) / totalItems) * 100) : 0, (length(report.UnmappedInstructions) + length(report.InferredRelationships)) + length(report.CrossFormReferences), length(report.UnmappedInstructions)), report.GeneratedAt, report.ActionTypeSuggestions);
672
+ }
673
+
674
+ /**
675
+ * Convert report to markdown format
676
+ */
677
+ export function toMarkdown(report: SemanticReport): string {
678
+ let s: string;
679
+ const sb: any = StringBuilder_$ctor();
680
+ StringBuilder__AppendLine_Z721C83C5(sb, `# Semantic Analysis Report - Form ${report.FormId}`);
681
+ StringBuilder__AppendLine_Z721C83C5(sb, `## ${report.FormName}`);
682
+ if (report.FormCode != null) {
683
+ StringBuilder__AppendLine_Z721C83C5(sb, `**Form Code:** ${value_129(report.FormCode)}`);
684
+ }
685
+ StringBuilder__AppendLine(sb);
686
+ StringBuilder__AppendLine_Z721C83C5(sb, `*Generated: ${toString(report.GeneratedAt, "yyyy-MM-dd HH:mm:ss")} UTC*`);
687
+ StringBuilder__AppendLine(sb);
688
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Complexity Legend");
689
+ StringBuilder__AppendLine_Z721C83C5(sb, "🟢 **Essential** - Core functionality, required fields, simple mappings");
690
+ StringBuilder__AppendLine_Z721C83C5(sb, "🟡 **Standard** - Optional logic, basic conditions, common workflows");
691
+ StringBuilder__AppendLine_Z721C83C5(sb, "🔴 **Advanced** - Complex branching, cross-form refs, edge cases");
692
+ StringBuilder__AppendLine(sb);
693
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Summary Statistics");
694
+ StringBuilder__AppendLine_Z721C83C5(sb, `- Mechanical Conversion Rate: ${report.Confidence.MechanicalConversionRate}%`);
695
+ StringBuilder__AppendLine_Z721C83C5(sb, `- Instruction Detection Rate: ${report.Confidence.InstructionDetectionRate}%`);
696
+ StringBuilder__AppendLine_Z721C83C5(sb, `- Enhancement Opportunities: ${report.Confidence.EnhancementOpportunities}`);
697
+ StringBuilder__AppendLine_Z721C83C5(sb, `- Unmapped Items: ${report.Confidence.UnmappedItemCount}`);
698
+ StringBuilder__AppendLine(sb);
699
+ if (!isEmpty(report.FieldCatalog)) {
700
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Field Catalog");
701
+ StringBuilder__AppendLine_Z721C83C5(sb, "*Use these FieldKeys when creating conditions and references*");
702
+ StringBuilder__AppendLine(sb);
703
+ StringBuilder__AppendLine_Z721C83C5(sb, "| C | ItemId | FieldKey | Label | Type | Required | Notes |");
704
+ StringBuilder__AppendLine_Z721C83C5(sb, "|---|--------|----------|-------|------|----------|-------|");
705
+ const enumerator: IEnumerator<FieldCatalogEntry> = getEnumerator(report.FieldCatalog);
706
+ try {
707
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
708
+ const field: FieldCatalogEntry = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
709
+ StringBuilder__AppendLine_Z721C83C5(sb, `| ${complexityToEmoji(field.Complexity)} | ${field.ItemId} | \`${field.FieldKey}\` | ${field.Label} | ${field.FieldType} | ${field.IsRequired ? "Yes" : "No"} | ${(s = defaultArg(field.Notes, ""), (s.length > 50) ? (substring(s, 0, 47) + "...") : s)} |`);
710
+ }
711
+ }
712
+ finally {
713
+ disposeSafe(enumerator as IDisposable);
714
+ }
715
+ StringBuilder__AppendLine(sb);
716
+ }
717
+ if (!isEmpty(report.ChoiceCatalog)) {
718
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Choice Catalog");
719
+ StringBuilder__AppendLine_Z721C83C5(sb, "*Use these OptionKeys when creating field_option conditions*");
720
+ StringBuilder__AppendLine(sb);
721
+ StringBuilder__AppendLine_Z721C83C5(sb, "| ItemId | OptionKey | Text | Score |");
722
+ StringBuilder__AppendLine_Z721C83C5(sb, "|--------|-----------|------|-------|");
723
+ const enumerator_1: IEnumerator<ChoiceCatalogEntry> = getEnumerator(report.ChoiceCatalog);
724
+ try {
725
+ while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
726
+ const choice: ChoiceCatalogEntry = enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]();
727
+ StringBuilder__AppendLine_Z721C83C5(sb, `| ${choice.ItemId} | \`${choice.OptionKey}\` | ${choice.Text} | ${choice.Score} |`);
728
+ }
729
+ }
730
+ finally {
731
+ disposeSafe(enumerator_1 as IDisposable);
732
+ }
733
+ StringBuilder__AppendLine(sb);
734
+ }
735
+ const matchValue: Option<PathwayContext> = report.PathwayContext;
736
+ if (matchValue == null) {
737
+ }
738
+ else {
739
+ const context: PathwayContext = value_129(matchValue);
740
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Current Clinical Pathway");
741
+ StringBuilder__AppendLine_Z721C83C5(sb, `*Execution Mode: ${context.ExecutionMode}*`);
742
+ StringBuilder__AppendLine(sb);
743
+ StringBuilder__AppendLine_Z721C83C5(sb, "### Existing States");
744
+ StringBuilder__AppendLine_Z721C83C5(sb, "| StateKey | Type | Label |");
745
+ StringBuilder__AppendLine_Z721C83C5(sb, "|----------|------|-------|");
746
+ const enumerator_2: IEnumerator<PathwayState> = getEnumerator(sortBy<PathwayState, int32>((s_1: PathwayState): int32 => s_1.StateOrder, context.States, {
747
+ Compare: comparePrimitives,
748
+ }));
749
+ try {
750
+ while (enumerator_2["System.Collections.IEnumerator.MoveNext"]()) {
751
+ const state: PathwayState = enumerator_2["System.Collections.Generic.IEnumerator`1.get_Current"]();
752
+ StringBuilder__AppendLine_Z721C83C5(sb, `| \`${state.StateKey}\` | ${state.StateType} | ${state.StateLabel} |`);
753
+ }
754
+ }
755
+ finally {
756
+ disposeSafe(enumerator_2 as IDisposable);
757
+ }
758
+ StringBuilder__AppendLine(sb);
759
+ if (!isEmpty(context.Transitions)) {
760
+ StringBuilder__AppendLine_Z721C83C5(sb, "### Existing Transitions");
761
+ StringBuilder__AppendLine_Z721C83C5(sb, "| From → To | Condition |");
762
+ StringBuilder__AppendLine_Z721C83C5(sb, "|-----------|-----------|");
763
+ const enumerator_3: IEnumerator<PathwayTransition> = getEnumerator(context.Transitions);
764
+ try {
765
+ while (enumerator_3["System.Collections.IEnumerator.MoveNext"]()) {
766
+ const trans: PathwayTransition = enumerator_3["System.Collections.Generic.IEnumerator`1.get_Current"]();
767
+ StringBuilder__AppendLine_Z721C83C5(sb, `| \`${trans.FromState}\` → \`${trans.ToState}\` | ${trans.ConditionSummary} |`);
768
+ }
769
+ }
770
+ finally {
771
+ disposeSafe(enumerator_3 as IDisposable);
772
+ }
773
+ StringBuilder__AppendLine(sb);
774
+ }
775
+ }
776
+ if (!isEmpty(report.UnmappedInstructions)) {
777
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Unmapped Conditional Logic");
778
+ StringBuilder__AppendLine(sb);
779
+ const enumerator_4: IEnumerator<InstructionItem> = getEnumerator(reverse<InstructionItem>(report.UnmappedInstructions));
780
+ try {
781
+ while (enumerator_4["System.Collections.IEnumerator.MoveNext"]()) {
782
+ const inst: InstructionItem = enumerator_4["System.Collections.Generic.IEnumerator`1.get_Current"]();
783
+ StringBuilder__AppendLine_Z721C83C5(sb, `### ${complexityToEmoji(inst.Complexity)} Item ${inst.ItemId} (Type ${inst.ItemType})`);
784
+ StringBuilder__AppendLine_Z721C83C5(sb, `**Complexity:** ${complexityToString(inst.Complexity)}`);
785
+ StringBuilder__AppendLine_Z721C83C5(sb, `**Text:** ${inst.Text}`);
786
+ if (inst.Pattern != null) {
787
+ StringBuilder__AppendLine_Z721C83C5(sb, `**Pattern:** ${value_129(inst.Pattern)}`);
788
+ }
789
+ StringBuilder__AppendLine_Z721C83C5(sb, `**Confidence:** %P(F2)`);
790
+ StringBuilder__AppendLine(sb);
791
+ switch (inst.ItemId) {
792
+ case 21001: {
793
+ StringBuilder__AppendLine_Z721C83C5(sb, "**Clinical Context:** Emergency pathway for cardiac risk");
794
+ StringBuilder__AppendLine_Z721C83C5(sb, "**Suggested Actions:**");
795
+ StringBuilder__AppendLine_Z721C83C5(sb, "1. Check Field 20984 (Cardiac Risk Factors) for any value");
796
+ StringBuilder__AppendLine_Z721C83C5(sb, "2. If true: Create Task \'Contact HCP\' with urgent priority");
797
+ StringBuilder__AppendLine_Z721C83C5(sb, "3. If HCP unavailable: Create Alert \'911 Activation\'");
798
+ StringBuilder__AppendLine_Z721C83C5(sb, "4. Navigate to Emergency Protocol");
799
+ break;
800
+ }
801
+ case 21002: {
802
+ StringBuilder__AppendLine_Z721C83C5(sb, "**Clinical Context:** Conservative treatment pathway");
803
+ StringBuilder__AppendLine_Z721C83C5(sb, "**Suggested Actions:**");
804
+ StringBuilder__AppendLine_Z721C83C5(sb, "1. Check Field 20984 is empty AND vitals are normal");
805
+ StringBuilder__AppendLine_Z721C83C5(sb, "2. If true: Create Task \'Prescribe OTC medication\'");
806
+ StringBuilder__AppendLine_Z721C83C5(sb, "3. Document treatment in appropriate fields");
807
+ StringBuilder__AppendLine_Z721C83C5(sb, "4. Navigate to discharge instructions");
808
+ break;
809
+ }
810
+ default: {
811
+ StringBuilder__AppendLine_Z721C83C5(sb, "**Suggested Enhancement:**");
812
+ StringBuilder__AppendLine_Z721C83C5(sb, "```fsharp");
813
+ StringBuilder__AppendLine_Z721C83C5(sb, "// LLM should analyze this conditional and suggest:");
814
+ StringBuilder__AppendLine_Z721C83C5(sb, "// 1. What fields should be updated");
815
+ StringBuilder__AppendLine_Z721C83C5(sb, "// 2. What tasks should be created");
816
+ StringBuilder__AppendLine_Z721C83C5(sb, "// 3. What forms should be navigated to");
817
+ StringBuilder__AppendLine_Z721C83C5(sb, "```");
818
+ }
819
+ }
820
+ StringBuilder__AppendLine(sb);
821
+ }
822
+ }
823
+ finally {
824
+ disposeSafe(enumerator_4 as IDisposable);
825
+ }
826
+ }
827
+ if (!isEmpty(report.ActionTypeSuggestions)) {
828
+ StringBuilder__AppendLine_Z721C83C5(sb, "## 🚀 Action Type Intelligence");
829
+ StringBuilder__AppendLine(sb);
830
+ StringBuilder__AppendLine_Z721C83C5(sb, "**AI-Suggested FormSpec Action Types** based on CoreMR event analysis:");
831
+ StringBuilder__AppendLine(sb);
832
+ const enumerator_5: IEnumerator<[string, FSharpList<ActionTypeSuggestion>]> = getEnumerator(sortBy<[string, FSharpList<ActionTypeSuggestion>], string>((tuple: [string, FSharpList<ActionTypeSuggestion>]): string => tuple[0], List_groupBy<ActionTypeSuggestion, string>((s_2: ActionTypeSuggestion): string => s_2.SuggestedActionType, report.ActionTypeSuggestions, {
833
+ Equals: (x_1: string, y_1: string): boolean => (x_1 === y_1),
834
+ GetHashCode: stringHash,
835
+ }), {
836
+ Compare: comparePrimitives,
837
+ }));
838
+ try {
839
+ while (enumerator_5["System.Collections.IEnumerator.MoveNext"]()) {
840
+ const forLoopVar: [string, FSharpList<ActionTypeSuggestion>] = enumerator_5["System.Collections.Generic.IEnumerator`1.get_Current"]();
841
+ const suggestions: FSharpList<ActionTypeSuggestion> = forLoopVar[1];
842
+ StringBuilder__AppendLine_Z721C83C5(sb, `### \`action_type: "${forLoopVar[0]}"\` (${length(suggestions)} suggestions)`);
843
+ StringBuilder__AppendLine(sb);
844
+ const enumerator_6: IEnumerator<ActionTypeSuggestion> = getEnumerator(suggestions);
845
+ try {
846
+ while (enumerator_6["System.Collections.IEnumerator.MoveNext"]()) {
847
+ const suggestion: ActionTypeSuggestion = enumerator_6["System.Collections.Generic.IEnumerator`1.get_Current"]();
848
+ StringBuilder__AppendLine_Z721C83C5(sb, `**CoreMR Event**: \`${suggestion.EventType}\``);
849
+ const matchValue_1: Option<int32> = suggestion.TargetItemId;
850
+ if (matchValue_1 == null) {
851
+ }
852
+ else {
853
+ StringBuilder__AppendLine_Z721C83C5(sb, `- **Target Item**: ${value_129(matchValue_1)}`);
854
+ }
855
+ StringBuilder__AppendLine_Z721C83C5(sb, `- **Confidence**: %P(P0)`);
856
+ StringBuilder__AppendLine_Z721C83C5(sb, `- **Reasoning**: ${suggestion.Reasoning}`);
857
+ const matchValue_2: Option<FSharpMap<string, string>> = suggestion.SuggestedParameters;
858
+ let matchResult: int32, parameters_1: FSharpMap<string, string>;
859
+ if (matchValue_2 != null) {
860
+ if (!FSharpMap__get_IsEmpty(value_129(matchValue_2))) {
861
+ matchResult = 0;
862
+ parameters_1 = value_129(matchValue_2);
863
+ }
864
+ else {
865
+ matchResult = 1;
866
+ }
867
+ }
868
+ else {
869
+ matchResult = 1;
870
+ }
871
+ switch (matchResult) {
872
+ case 0: {
873
+ StringBuilder__AppendLine_Z721C83C5(sb, "- **Suggested Parameters**:");
874
+ const enumerator_7: IEnumerator<[string, string]> = getEnumerator(parameters_1!);
875
+ try {
876
+ while (enumerator_7["System.Collections.IEnumerator.MoveNext"]()) {
877
+ const kvp: [string, string] = enumerator_7["System.Collections.Generic.IEnumerator`1.get_Current"]();
878
+ StringBuilder__AppendLine_Z721C83C5(sb, ` - \`${kvp[0]}\`: "${kvp[1]}"`);
879
+ }
880
+ }
881
+ finally {
882
+ disposeSafe(enumerator_7 as IDisposable);
883
+ }
884
+ break;
885
+ }
886
+ }
887
+ StringBuilder__AppendLine_Z721C83C5(sb, "- **Example YAML**:");
888
+ StringBuilder__AppendLine_Z721C83C5(sb, " ```yaml");
889
+ StringBuilder__AppendLine_Z721C83C5(sb, ` action_type: "${suggestion.SuggestedActionType}"`);
890
+ StringBuilder__AppendLine_Z721C83C5(sb, ` description: "[Your clinical description based on ${suggestion.EventType} event]"`);
891
+ const matchValue_3: Option<FSharpMap<string, string>> = suggestion.SuggestedParameters;
892
+ let matchResult_1: int32, parameters_3: FSharpMap<string, string>;
893
+ if (matchValue_3 != null) {
894
+ if (!FSharpMap__get_IsEmpty(value_129(matchValue_3))) {
895
+ matchResult_1 = 0;
896
+ parameters_3 = value_129(matchValue_3);
897
+ }
898
+ else {
899
+ matchResult_1 = 1;
900
+ }
901
+ }
902
+ else {
903
+ matchResult_1 = 1;
904
+ }
905
+ switch (matchResult_1) {
906
+ case 0: {
907
+ StringBuilder__AppendLine_Z721C83C5(sb, " parameters:");
908
+ const enumerator_8: IEnumerator<[string, string]> = getEnumerator(parameters_3!);
909
+ try {
910
+ while (enumerator_8["System.Collections.IEnumerator.MoveNext"]()) {
911
+ const kvp_1: [string, string] = enumerator_8["System.Collections.Generic.IEnumerator`1.get_Current"]();
912
+ StringBuilder__AppendLine_Z721C83C5(sb, ` ${kvp_1[0]}: "${kvp_1[1]}"`);
913
+ }
914
+ }
915
+ finally {
916
+ disposeSafe(enumerator_8 as IDisposable);
917
+ }
918
+ break;
919
+ }
920
+ case 1: {
921
+ StringBuilder__AppendLine_Z721C83C5(sb, " parameters: {}");
922
+ break;
923
+ }
924
+ }
925
+ StringBuilder__AppendLine_Z721C83C5(sb, " ```");
926
+ StringBuilder__AppendLine(sb);
927
+ }
928
+ }
929
+ finally {
930
+ disposeSafe(enumerator_6 as IDisposable);
931
+ }
932
+ }
933
+ }
934
+ finally {
935
+ disposeSafe(enumerator_5 as IDisposable);
936
+ }
937
+ StringBuilder__AppendLine_Z721C83C5(sb, "💡 **LLM Guidance**: Use these suggestions to replace generic \"documentation\" actions with specific, clinically-appropriate action types.");
938
+ StringBuilder__AppendLine(sb);
939
+ }
940
+ if (!isEmpty(report.CrossFormReferences)) {
941
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Cross-Form References");
942
+ StringBuilder__AppendLine(sb);
943
+ const enumerator_9: IEnumerator<FormReference> = getEnumerator(reverse<FormReference>(report.CrossFormReferences));
944
+ try {
945
+ while (enumerator_9["System.Collections.IEnumerator.MoveNext"]()) {
946
+ const ref: FormReference = enumerator_9["System.Collections.Generic.IEnumerator`1.get_Current"]();
947
+ StringBuilder__AppendLine_Z721C83C5(sb, `- ${complexityToEmoji(ref.Complexity)} Item ${ref.SourceItemId}: References **[${ref.ReferencedFormCode}]**`);
948
+ StringBuilder__AppendLine_Z721C83C5(sb, ` - Context: ${(ref.SourceText.length > 100) ? (substring(ref.SourceText, 0, 100) + "...") : ref.SourceText}`);
949
+ StringBuilder__AppendLine_Z721C83C5(sb, ` - Suggested Action: ${ref.ActionSuggested}`);
950
+ StringBuilder__AppendLine(sb);
951
+ }
952
+ }
953
+ finally {
954
+ disposeSafe(enumerator_9 as IDisposable);
955
+ }
956
+ }
957
+ if (!isEmpty(report.InferredRelationships)) {
958
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Inferred Relationships");
959
+ StringBuilder__AppendLine(sb);
960
+ StringBuilder__AppendLine_Z721C83C5(sb, "| C | Field 1 | Relationship | Field 2 | Evidence | Confidence |");
961
+ StringBuilder__AppendLine_Z721C83C5(sb, "|---|---------|--------------|---------|----------|------------|");
962
+ const enumerator_10: IEnumerator<InferredRelationship> = getEnumerator(reverse<InferredRelationship>(report.InferredRelationships));
963
+ try {
964
+ while (enumerator_10["System.Collections.IEnumerator.MoveNext"]()) {
965
+ const rel: InferredRelationship = enumerator_10["System.Collections.Generic.IEnumerator`1.get_Current"]();
966
+ StringBuilder__AppendLine_Z721C83C5(sb, `| ${complexityToEmoji(rel.Complexity)} | ${rel.Field1} | ${rel.RelationType} | ${rel.Field2} | ${rel.Evidence} | %P(F2) |`);
967
+ }
968
+ }
969
+ finally {
970
+ disposeSafe(enumerator_10 as IDisposable);
971
+ }
972
+ StringBuilder__AppendLine(sb);
973
+ }
974
+ StringBuilder__AppendLine_Z721C83C5(sb, "## Recommended Enhancements");
975
+ StringBuilder__AppendLine(sb);
976
+ if (length(report.UnmappedInstructions) > 0) {
977
+ StringBuilder__AppendLine_Z721C83C5(sb, `1. **Parse ${length(report.UnmappedInstructions)} conditional instructions** for automated field updates`);
978
+ }
979
+ if (length(report.CrossFormReferences) > 0) {
980
+ StringBuilder__AppendLine_Z721C83C5(sb, `2. **Implement ${length(report.CrossFormReferences)} cross-form navigation** actions`);
981
+ }
982
+ if (length(report.InferredRelationships) > 0) {
983
+ StringBuilder__AppendLine_Z721C83C5(sb, `3. **Add ${length(report.InferredRelationships)} inferred field relationships** for better UX`);
984
+ }
985
+ StringBuilder__AppendLine(sb);
986
+ StringBuilder__AppendLine_Z721C83C5(sb, "## LLM Enhancement Prompts");
987
+ StringBuilder__AppendLine(sb);
988
+ StringBuilder__AppendLine_Z721C83C5(sb, "### For each unmapped instruction above:");
989
+ StringBuilder__AppendLine_Z721C83C5(sb, "```");
990
+ StringBuilder__AppendLine_Z721C83C5(sb, "Given the clinical context and instruction text,");
991
+ StringBuilder__AppendLine_Z721C83C5(sb, "suggest appropriate FormSpec actions:");
992
+ StringBuilder__AppendLine_Z721C83C5(sb, "1. SetFieldValue actions for automatic field updates");
993
+ StringBuilder__AppendLine_Z721C83C5(sb, "2. Task actions for clinical workflows");
994
+ StringBuilder__AppendLine_Z721C83C5(sb, "3. AdministerForm actions for form administration");
995
+ StringBuilder__AppendLine_Z721C83C5(sb, "4. Alert actions for critical conditions");
996
+ StringBuilder__AppendLine_Z721C83C5(sb, "```");
997
+ StringBuilder__AppendLine(sb);
998
+ StringBuilder__AppendLine_Z721C83C5(sb, "---");
999
+ StringBuilder__AppendLine_Z721C83C5(sb, "*This report identifies conversion opportunities that require semantic understanding.*");
1000
+ StringBuilder__AppendLine_Z721C83C5(sb, "*Use with LLM/MCP tools to complete the enhancement process.*");
1001
+ return toString_1(sb);
1002
+ }
1003
+
1004
+ /**
1005
+ * Main entry point to build a semantic report for CoreMR form data
1006
+ */
1007
+ export function buildReport(formData: CoreMRFormData): string {
1008
+ let report: SemanticReport = empty(newGuid(), formData.Metadata.FormName);
1009
+ const enumerator: IEnumerator<CoreMRItem> = getEnumerator(formData.Items);
1010
+ try {
1011
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
1012
+ const item: CoreMRItem = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
1013
+ if (hasInstruction(item.Label)) {
1014
+ report = addUnmappedInstruction(report, item);
1015
+ }
1016
+ const enumerator_1: IEnumerator<FormReference> = getEnumerator(extractFormReferences(item.ItemId, item.Label));
1017
+ try {
1018
+ while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
1019
+ const reference: FormReference = enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]();
1020
+ report = addCrossFormReference(report, reference);
1021
+ }
1022
+ }
1023
+ finally {
1024
+ disposeSafe(enumerator_1 as IDisposable);
1025
+ }
1026
+ }
1027
+ }
1028
+ finally {
1029
+ disposeSafe(enumerator as IDisposable);
1030
+ }
1031
+ const enumerator_2: IEnumerator<ActionTypeSuggestion> = getEnumerator(buildActionTypeSuggestions(formData.Triggers, empty_1<any>()));
1032
+ try {
1033
+ while (enumerator_2["System.Collections.IEnumerator.MoveNext"]()) {
1034
+ const suggestion: ActionTypeSuggestion = enumerator_2["System.Collections.Generic.IEnumerator`1.get_Current"]();
1035
+ report = addActionTypeSuggestion(report, suggestion);
1036
+ }
1037
+ }
1038
+ finally {
1039
+ disposeSafe(enumerator_2 as IDisposable);
1040
+ }
1041
+ const triggersConverted: int32 = length(formData.Triggers) | 0;
1042
+ report = calculateMetrics(report, length(formData.Items), triggersConverted);
1043
+ return toMarkdown(report);
1044
+ }
1045
+
1046
+ //# sourceMappingURL=CorEMRSemanticReportBuilder.ts.map