@f1studio/form-spec 5.0.0-alpha.167 → 5.0.0-alpha.169

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 (194) hide show
  1. package/FormSpec.FS/BlueprintValidation.d.ts +6 -3
  2. package/FormSpec.FS/BlueprintValidation.d.ts.map +1 -1
  3. package/FormSpec.FS/BlueprintValidation.js +39 -15
  4. package/FormSpec.FS/BlueprintValidation.js.map +1 -1
  5. package/FormSpec.FS/Designer.d.ts.map +1 -1
  6. package/FormSpec.FS/Designer.js +1 -1
  7. package/FormSpec.FS/Designer.js.map +1 -1
  8. package/FormSpec.FS/FormSpec.d.ts +108 -58
  9. package/FormSpec.FS/FormSpec.d.ts.map +1 -1
  10. package/FormSpec.FS/FormSpec.js +319 -129
  11. package/FormSpec.FS/FormSpec.js.map +1 -1
  12. package/FormSpec.FS/FormSpecHelpers.d.ts.map +1 -1
  13. package/FormSpec.FS/FormSpecHelpers.js +1 -1
  14. package/FormSpec.FS/FormSpecHelpers.js.map +1 -1
  15. package/FormSpec.FS/FormSpecValues.d.ts.map +1 -1
  16. package/FormSpec.FS/FormSpecValues.js +5 -2
  17. package/FormSpec.FS/FormSpecValues.js.map +1 -1
  18. package/FormSpec.FS/Helpers.d.ts.map +1 -1
  19. package/FormSpec.FS/Helpers.js +14 -9
  20. package/FormSpec.FS/Helpers.js.map +1 -1
  21. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.d.ts.map +1 -1
  22. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.js +1 -1
  23. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.js.map +1 -1
  24. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.d.ts +1 -1
  25. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.d.ts.map +1 -1
  26. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.js +1 -1
  27. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.js.map +1 -1
  28. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.d.ts +3 -3
  29. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.d.ts.map +1 -1
  30. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.js +7 -5
  31. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.js.map +1 -1
  32. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.d.ts.map +1 -1
  33. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.js +11 -10
  34. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.js.map +1 -1
  35. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.d.ts.map +1 -1
  36. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.js +1 -9
  37. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.js.map +1 -1
  38. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateMapper.d.ts +11 -4
  39. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateMapper.d.ts.map +1 -1
  40. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateMapper.js +30 -28
  41. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateMapper.js.map +1 -1
  42. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.d.ts +3 -9
  43. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.d.ts.map +1 -1
  44. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.js +4 -31
  45. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.js.map +1 -1
  46. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.d.ts.map +1 -1
  47. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.js +2 -6
  48. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.js.map +1 -1
  49. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImportPipeline.d.ts +45 -0
  50. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImportPipeline.d.ts.map +1 -0
  51. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImportPipeline.js +141 -0
  52. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImportPipeline.js.map +1 -0
  53. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImporterAnalysis.d.ts +326 -0
  54. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImporterAnalysis.d.ts.map +1 -0
  55. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImporterAnalysis.js +1743 -0
  56. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImporterAnalysis.js.map +1 -0
  57. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.d.ts +8 -8
  58. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.d.ts.map +1 -1
  59. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.js +6 -6
  60. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.js.map +1 -1
  61. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRTriggerEnrichment.d.ts +21 -15
  62. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRTriggerEnrichment.d.ts.map +1 -1
  63. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRTriggerEnrichment.js +83 -80
  64. package/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRTriggerEnrichment.js.map +1 -1
  65. package/FormSpec.FS/Integrations/CorEMR/CoreMRPathwayMapper.d.ts +51 -0
  66. package/FormSpec.FS/Integrations/CorEMR/CoreMRPathwayMapper.d.ts.map +1 -0
  67. package/FormSpec.FS/Integrations/CorEMR/CoreMRPathwayMapper.js +939 -0
  68. package/FormSpec.FS/Integrations/CorEMR/CoreMRPathwayMapper.js.map +1 -0
  69. package/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.d.ts +2 -17
  70. package/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.d.ts.map +1 -1
  71. package/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.js +1 -66
  72. package/FormSpec.FS/Integrations/CorEMR/{TemplateManifestDecoder.d.ts → FormTemplateDecoder.d.ts} +53 -45
  73. package/FormSpec.FS/Integrations/CorEMR/FormTemplateDecoder.d.ts.map +1 -0
  74. package/FormSpec.FS/Integrations/CorEMR/{TemplateManifestDecoder.js → FormTemplateDecoder.js} +544 -254
  75. package/FormSpec.FS/Integrations/CorEMR/FormTemplateDecoder.js.map +1 -0
  76. package/FormSpec.FS/Integrations/CorEMR/FormTemplateDomainDecoder.d.ts +7 -0
  77. package/FormSpec.FS/Integrations/CorEMR/FormTemplateDomainDecoder.d.ts.map +1 -0
  78. package/FormSpec.FS/Integrations/CorEMR/FormTemplateDomainDecoder.js +280 -0
  79. package/FormSpec.FS/Integrations/CorEMR/FormTemplateDomainDecoder.js.map +1 -0
  80. package/FormSpec.FS/Interop/FormSpec.Api.Helpers.d.ts +16 -4
  81. package/FormSpec.FS/Interop/FormSpec.Api.Helpers.d.ts.map +1 -1
  82. package/FormSpec.FS/Interop/FormSpec.Api.Helpers.js +63 -18
  83. package/FormSpec.FS/Interop/FormSpec.Api.Helpers.js.map +1 -1
  84. package/FormSpec.FS/Interop/FormSpec.Api.Option.d.ts +4 -4
  85. package/FormSpec.FS/Interop/FormSpec.Api.Option.d.ts.map +1 -1
  86. package/FormSpec.FS/Interop/FormSpec.Api.Option.js +2 -2
  87. package/FormSpec.FS/Interop/FormSpec.Api.Option.js.map +1 -1
  88. package/FormSpec.FS/PathwayDataExtractor.d.ts.map +1 -1
  89. package/FormSpec.FS/PathwayDataExtractor.js +39 -18
  90. package/FormSpec.FS/PathwayDataExtractor.js.map +1 -1
  91. package/FormSpec.FS/PathwayExecutor.d.ts +10 -10
  92. package/FormSpec.FS/PathwayExecutor.d.ts.map +1 -1
  93. package/FormSpec.FS/PathwayExecutor.js +14 -14
  94. package/FormSpec.FS/PathwayExecutor.js.map +1 -1
  95. package/FormSpec.FS/PathwayValidator.d.ts.map +1 -1
  96. package/FormSpec.FS/PathwayValidator.js +8 -5
  97. package/FormSpec.FS/PathwayValidator.js.map +1 -1
  98. package/FormSpec.FS/Provenance.d.ts +15 -7
  99. package/FormSpec.FS/Provenance.d.ts.map +1 -1
  100. package/FormSpec.FS/Provenance.js +11 -11
  101. package/FormSpec.FS/Provenance.js.map +1 -1
  102. package/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.d.ts.map +1 -1
  103. package/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.js +16 -7
  104. package/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.js.map +1 -1
  105. package/FormSpec.FS/Renderers/MermaidRenderer.d.ts.map +1 -1
  106. package/FormSpec.FS/Renderers/MermaidRenderer.js +4 -8
  107. package/FormSpec.FS/Renderers/MermaidRenderer.js.map +1 -1
  108. package/FormSpec.FS/Renderers/PathwayRenderers.d.ts.map +1 -1
  109. package/FormSpec.FS/Renderers/PathwayRenderers.js +5 -4
  110. package/FormSpec.FS/Renderers/PathwayRenderers.js.map +1 -1
  111. package/FormSpec.FS/TriggerActionDto.d.ts +32 -21
  112. package/FormSpec.FS/TriggerActionDto.d.ts.map +1 -1
  113. package/FormSpec.FS/TriggerActionDto.js +247 -61
  114. package/FormSpec.FS/TriggerActionDto.js.map +1 -1
  115. package/README.md +7 -7
  116. package/package.json +1 -1
  117. package/plugins/allergyfinder/src/AllergyFinderField.d.ts.map +1 -1
  118. package/plugins/allergyfinder/src/AllergyFinderField.js +2 -2
  119. package/plugins/allergyfinder/src/AllergyFinderField.js.map +1 -1
  120. package/plugins/bmi/src/BMIField.d.ts.map +1 -1
  121. package/plugins/bmi/src/BMIField.js +21 -15
  122. package/plugins/bmi/src/BMIField.js.map +1 -1
  123. package/plugins/demographics/src/DemographicsField.d.ts.map +1 -1
  124. package/plugins/demographics/src/DemographicsField.js +4 -4
  125. package/plugins/demographics/src/DemographicsField.js.map +1 -1
  126. package/plugins/likert/src/LikertField.d.ts.map +1 -1
  127. package/plugins/likert/src/LikertField.js +40 -35
  128. package/plugins/likert/src/LikertField.js.map +1 -1
  129. package/plugins/signature/src/SignatureField.d.ts.map +1 -1
  130. package/plugins/signature/src/SignatureField.js +4 -3
  131. package/plugins/signature/src/SignatureField.js.map +1 -1
  132. package/plugins/vitals/src/VitalsField.d.ts.map +1 -1
  133. package/plugins/vitals/src/VitalsField.js +4 -4
  134. package/plugins/vitals/src/VitalsField.js.map +1 -1
  135. package/src/FormSpec.FS/BlueprintValidation.ts +55 -24
  136. package/src/FormSpec.FS/Designer.ts +2 -2
  137. package/src/FormSpec.FS/FormSpec.ts +223 -100
  138. package/src/FormSpec.FS/FormSpecHelpers.ts +2 -2
  139. package/src/FormSpec.FS/FormSpecValues.ts +6 -3
  140. package/src/FormSpec.FS/Helpers.ts +16 -11
  141. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFieldTypeMapper.ts +2 -2
  142. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRFormSpecValidator.ts +3 -3
  143. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSectioning.ts +10 -8
  144. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRSemanticReportBuilder.ts +6 -5
  145. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRStepsBuilder.ts +1 -10
  146. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateMapper.ts +35 -30
  147. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTemplateToFormSpec.ts +7 -26
  148. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMREncoder.ts +2 -6
  149. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImportPipeline.ts +115 -0
  150. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRImporterAnalysis.ts +1059 -0
  151. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRSourceMap.ts +10 -10
  152. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CoreMRTriggerEnrichment.ts +61 -88
  153. package/src/FormSpec.FS/Integrations/CorEMR/CoreMRPathwayMapper.ts +926 -0
  154. package/src/FormSpec.FS/Integrations/CorEMR/CoreMRTypes.ts +3 -37
  155. package/src/FormSpec.FS/Integrations/CorEMR/FormTemplateDecoder.ts +1284 -0
  156. package/src/FormSpec.FS/Integrations/CorEMR/FormTemplateDomainDecoder.ts +287 -0
  157. package/src/FormSpec.FS/Interop/FormSpec.Api.Helpers.ts +76 -25
  158. package/src/FormSpec.FS/Interop/FormSpec.Api.Option.ts +6 -6
  159. package/src/FormSpec.FS/PathwayDataExtractor.ts +40 -20
  160. package/src/FormSpec.FS/PathwayExecutor.ts +26 -26
  161. package/src/FormSpec.FS/PathwayValidator.ts +8 -5
  162. package/src/FormSpec.FS/Provenance.ts +23 -15
  163. package/src/FormSpec.FS/Renderers/FormSpecMarkdownRenderer.ts +18 -8
  164. package/src/FormSpec.FS/Renderers/MermaidRenderer.ts +6 -10
  165. package/src/FormSpec.FS/Renderers/PathwayRenderers.ts +5 -5
  166. package/src/FormSpec.FS/TriggerActionDto.ts +247 -74
  167. package/src/plugins/allergyfinder/src/AllergyFinderField.ts +3 -3
  168. package/src/plugins/bmi/src/BMIField.ts +12 -5
  169. package/src/plugins/demographics/src/DemographicsField.ts +5 -5
  170. package/src/plugins/likert/src/LikertField.ts +16 -11
  171. package/src/plugins/signature/src/SignatureField.ts +4 -3
  172. package/src/plugins/vitals/src/VitalsField.ts +5 -5
  173. package/src/vye-os-contracts-fs/src/Core/Ids.ts +8 -8
  174. package/src/vye-os-contracts-fs/src/CoreMR/FormTemplate.ts +715 -0
  175. package/vye-os-contracts-fs/src/Core/Ids.d.ts +4 -4
  176. package/vye-os-contracts-fs/src/Core/Ids.d.ts.map +1 -1
  177. package/vye-os-contracts-fs/src/Core/Ids.js +18 -18
  178. package/vye-os-contracts-fs/src/CoreMR/FormTemplate.d.ts +310 -0
  179. package/vye-os-contracts-fs/src/CoreMR/FormTemplate.d.ts.map +1 -0
  180. package/vye-os-contracts-fs/src/CoreMR/FormTemplate.js +1242 -0
  181. package/vye-os-contracts-fs/src/CoreMR/FormTemplate.js.map +1 -0
  182. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.d.ts +0 -69
  183. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.d.ts.map +0 -1
  184. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.js +0 -447
  185. package/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.js.map +0 -1
  186. package/FormSpec.FS/Integrations/CorEMR/ItemTriggerConverter.d.ts +0 -19
  187. package/FormSpec.FS/Integrations/CorEMR/ItemTriggerConverter.d.ts.map +0 -1
  188. package/FormSpec.FS/Integrations/CorEMR/ItemTriggerConverter.js +0 -643
  189. package/FormSpec.FS/Integrations/CorEMR/ItemTriggerConverter.js.map +0 -1
  190. package/FormSpec.FS/Integrations/CorEMR/TemplateManifestDecoder.d.ts.map +0 -1
  191. package/FormSpec.FS/Integrations/CorEMR/TemplateManifestDecoder.js.map +0 -1
  192. package/src/FormSpec.FS/Integrations/Adapters/CorEMR/CorEMRTriggerConverter.ts +0 -412
  193. package/src/FormSpec.FS/Integrations/CorEMR/ItemTriggerConverter.ts +0 -588
  194. package/src/FormSpec.FS/Integrations/CorEMR/TemplateManifestDecoder.ts +0 -1054
@@ -0,0 +1,926 @@
1
+ import { Helpers_canonicalizeFieldKey, Helpers_generateDeterministicGuidRaw } from "../../Helpers.js";
2
+ import { Action, NonEmpty_toList, NonEmpty$1, GroupChange_$union, ProblemOrder, MedsetOrder, TreatmentOrder, Standing, TaskOrder, Cadence_$union, Trigger, StatedAction, ActionRead_$union, Ref, Action_$union, Join, Join_$union, Priority, Timing_$union, StatedCondition, Condition_$union, ChoiceId, Comparison_$union } from "../../../vye-os-contracts-fs/src/CoreMR/FormTemplate.js";
3
+ import { indexed, append, sort, exists, collect, filter, sortBy, length, ofArray, fold, zip, tail, head as head_1, isEmpty, map as map_1, singleton, FSharpList, empty, choose, tryFind } from "@fable-org/fable-library-js/List.js";
4
+ import { IDisposable, disposeSafe, IEnumerator, getEnumerator, numberHash, stringHash, safeHash, comparePrimitives, equals } from "@fable-org/fable-library-js/Util.js";
5
+ import { ReleaseAvailability$1_$union, TemplateForm, TemplateChoice, TemplateItem } from "./FormTemplateDecoder.js";
6
+ import { defaultArg, bind, map, value, Option } from "@fable-org/fable-library-js/Option.js";
7
+ import { parse, int32 } from "@fable-org/fable-library-js/Int32.js";
8
+ import { decimal } from "@fable-org/fable-library-js/Decimal.js";
9
+ import { ClinicalPathway_PathwayExecutionMode_MultiPathway, ClinicalPathway_MultiPathwayConfig, ClinicalPathway_ConflictResolution_CombineActions, ClinicalPathway_CombinationStrategy_AllMatching, ClinicalPathway_ClinicalPathwaySpec, ClinicalPathway_PathRequirement, ClinicalPathway_ConstraintDefinition, ClinicalPathway_PathwayExecutionMode_TriggerBased, ClinicalPathway_TriggerBasedConfig, ClinicalPathway_TransitionDefinition, Shared_TransitionKey, ClinicalPathway_StateType_Terminal, ClinicalPathway_TerminalInfo, ClinicalPathway_StateDefinition, ClinicalPathway_StateType_Evaluation, ClinicalPathway_EvaluationInfo, Shared_StateKey, ClinicalPathway_StateType_$union, ClinicalPathway_StateType_CompoundAction, ClinicalPathway_StateType_Action, ClinicalPathway_PathwayAction, ClinicalPathway_ActionOrigin_CoreMRTrigger, ClinicalPathway_CoreMRTriggerRef, ClinicalPathway_ActionInfo_Alert, ClinicalPathway_AlertAction, ClinicalPathway_ActionInfo_ChangeGroups, ClinicalPathway_GroupChangeAction, ClinicalPathway_GroupRef, ClinicalPathway_GroupChange_AddToGroups, ClinicalPathway_GroupChange_$union, ClinicalPathway_GroupChange_RemoveFromGroups, ClinicalPathway_ActionInfo_Problem, ClinicalPathway_ProblemAction, ClinicalPathway_ProblemStatus_Active, ClinicalPathway_ActionInfo_Medset, ClinicalPathway_MedsetAction, ClinicalPathway_ActionInfo_Treatment, ClinicalPathway_TreatmentAction, ClinicalPathway_ActionInfo_$union, ClinicalPathway_ActionInfo_Task, ClinicalPathway_TaskAction, ClinicalPathway_Cadence_OnSchedule, ClinicalPathway_StandingSchedule, ClinicalPathway_Cadence_Every, ClinicalPathway_TransitionCondition_Always, ClinicalPathway_TransitionCondition_CompositeCondition, ClinicalPathway_LogicalOp_$union, ClinicalPathway_LogicalOp_And, ClinicalPathway_LogicalOp_Or, ClinicalPathway_TransitionCondition_$union, ClinicalPathway_TransitionCondition_FieldCondition, ClinicalPathway_TransitionCondition_PluginPropertyCondition, Shared_PluginPropertyKey, Shared_ConditionValue_Single, Shared_ConditionValue_Multiple, Shared_ConditionValue_$union, Shared_FieldKey, ClinicalPathway_DueDate_$union, ClinicalPathway_DueDate_AsStated, ClinicalPathway_DueDate_DaysFromNow, ClinicalPathway_DueDate_Tomorrow, ClinicalPathway_DueDate_Today, ClinicalPathway_TaskPriority_$union, ClinicalPathway_TaskPriority_Stated, ClinicalPathway_TaskPriority_Low, ClinicalPathway_TaskPriority_Medium, ClinicalPathway_TaskPriority_High, ClinicalPathway_TriggerTiming_$union, ClinicalPathway_TriggerTiming_OnFormSave, ClinicalPathway_TriggerTiming_OnFormLoad, ClinicalPathway_TriggerTiming_OnFormSubmit, ClinicalPathway_FieldEvaluator_$union, ClinicalPathway_FieldEvaluator_Equals, ClinicalPathway_FieldEvaluator_LessOrEqual, ClinicalPathway_FieldEvaluator_LessThan, ClinicalPathway_FieldEvaluator_GreaterOrEqual, ClinicalPathway_FieldEvaluator_GreaterThan, ClinicalPathway_FieldEvaluator_NotEquals, ClinicalPathway_FieldEvaluator_NotInSet, ClinicalPathway_FieldEvaluator_ContainsAll, ClinicalPathway_FieldEvaluator_InSet } from "../../FormSpec.js";
10
+ import { match } from "@fable-org/fable-library-js/RegExp.js";
11
+ import { FSharpMap__ContainsKey, FSharpMap, tryFind as tryFind_1 } from "@fable-org/fable-library-js/Map.js";
12
+ import { printf, join, substring, isNullOrEmpty, interpolate, toText } from "@fable-org/fable-library-js/String.js";
13
+ import { ofList } from "@fable-org/fable-library-js/Set.js";
14
+ import { List_distinctBy, List_distinct } from "@fable-org/fable-library-js/Seq2.js";
15
+ import { empty as empty_1, singleton as singleton_1, collect as collect_1, append as append_1, delay, toList } from "@fable-org/fable-library-js/Seq.js";
16
+
17
+ function stableGuid(name: string): string {
18
+ return Helpers_generateDeterministicGuidRaw(`coremr:item_trigger:${name}`);
19
+ }
20
+
21
+ function comparisonWord(c: Comparison_$union): string {
22
+ switch (c.tag) {
23
+ case /* LessOrEqual */ 1:
24
+ return "less_equals";
25
+ case /* Equal */ 2:
26
+ return "equals";
27
+ case /* NotEqual */ 3:
28
+ return "not_equals";
29
+ case /* GreaterOrEqual */ 4:
30
+ return "greater_equals";
31
+ case /* Greater */ 5:
32
+ return "greater";
33
+ default:
34
+ return "less";
35
+ }
36
+ }
37
+
38
+ function textsOf(items: FSharpList<TemplateItem>, c: StatedCondition): [string, FSharpList<string>] {
39
+ const chosen = (ids: FSharpList<ChoiceId>): FSharpList<string> => {
40
+ const matchValue: Option<TemplateItem> = tryFind<TemplateItem>((i: TemplateItem): boolean => equals(i.ItemId, c.SourceItem), items);
41
+ if (matchValue != null) {
42
+ const item: TemplateItem = value(matchValue);
43
+ return choose<ChoiceId, string>((_arg: ChoiceId): Option<string> => {
44
+ const id: int32 = _arg.fields[0] | 0;
45
+ return map<TemplateChoice, string>((ch_1: TemplateChoice): string => ch_1.Text, tryFind<TemplateChoice>((ch: TemplateChoice): boolean => (ch.ChoiceId === id), item.Choices));
46
+ }, ids);
47
+ }
48
+ else {
49
+ return empty<string>();
50
+ }
51
+ };
52
+ const matchValue_1: Condition_$union = c.Test;
53
+ switch (matchValue_1.tag) {
54
+ case /* AllChosen */ 1:
55
+ return ["all", chosen(matchValue_1.fields[0])] as [string, FSharpList<string>];
56
+ case /* NoneChosen */ 2:
57
+ return ["none", chosen(matchValue_1.fields[0])] as [string, FSharpList<string>];
58
+ case /* VitalIs */ 3: {
59
+ const threshold: decimal = matchValue_1.fields[2];
60
+ return [comparisonWord(matchValue_1.fields[1]), singleton(threshold.toString())] as [string, FSharpList<string>];
61
+ }
62
+ case /* BooleanIs */ 4:
63
+ return ["equals", singleton(matchValue_1.fields[0] ? "true" : "false")] as [string, FSharpList<string>];
64
+ case /* TextCompares */ 5: {
65
+ const text: string = matchValue_1.fields[1];
66
+ return [comparisonWord(matchValue_1.fields[0]), singleton(text)] as [string, FSharpList<string>];
67
+ }
68
+ case /* UnmodelledCondition */ 6:
69
+ throw new Error(`CoreMRPathwayMapper: condition \`${matchValue_1.fields[0]} ${matchValue_1.fields[1]}\` is not modelled (${matchValue_1.fields[2]}) — \`refusalFor\` refuses it first`);
70
+ default:
71
+ return ["any", chosen(matchValue_1.fields[0])] as [string, FSharpList<string>];
72
+ }
73
+ }
74
+
75
+ export function convertOperator(test: Condition_$union, values: FSharpList<string>): ClinicalPathway_FieldEvaluator_$union {
76
+ const canonValues: FSharpList<string> = map_1<string, string>(Helpers_canonicalizeFieldKey, values);
77
+ let matchResult: int32, cmp: Comparison_$union;
78
+ switch (test.tag) {
79
+ case /* AllChosen */ 1: {
80
+ matchResult = 1;
81
+ break;
82
+ }
83
+ case /* NoneChosen */ 2: {
84
+ matchResult = 2;
85
+ break;
86
+ }
87
+ case /* VitalIs */ 3: {
88
+ matchResult = 3;
89
+ cmp = test.fields[1];
90
+ break;
91
+ }
92
+ case /* TextCompares */ 5: {
93
+ matchResult = 3;
94
+ cmp = test.fields[0];
95
+ break;
96
+ }
97
+ case /* BooleanIs */ 4: {
98
+ matchResult = 4;
99
+ break;
100
+ }
101
+ case /* UnmodelledCondition */ 6: {
102
+ matchResult = 5;
103
+ break;
104
+ }
105
+ default:
106
+ matchResult = 0;
107
+ }
108
+ switch (matchResult) {
109
+ case 0:
110
+ return ClinicalPathway_FieldEvaluator_InSet(canonValues);
111
+ case 1:
112
+ return ClinicalPathway_FieldEvaluator_ContainsAll(canonValues);
113
+ case 2:
114
+ return ClinicalPathway_FieldEvaluator_NotInSet(canonValues);
115
+ case 3: {
116
+ const _arg: Comparison_$union = cmp!;
117
+ switch (_arg.tag) {
118
+ case /* NotEqual */ 3:
119
+ return ClinicalPathway_FieldEvaluator_NotEquals();
120
+ case /* Greater */ 5:
121
+ return ClinicalPathway_FieldEvaluator_GreaterThan();
122
+ case /* GreaterOrEqual */ 4:
123
+ return ClinicalPathway_FieldEvaluator_GreaterOrEqual();
124
+ case /* Less */ 0:
125
+ return ClinicalPathway_FieldEvaluator_LessThan();
126
+ case /* LessOrEqual */ 1:
127
+ return ClinicalPathway_FieldEvaluator_LessOrEqual();
128
+ default:
129
+ return ClinicalPathway_FieldEvaluator_Equals();
130
+ }
131
+ }
132
+ case 4:
133
+ return ClinicalPathway_FieldEvaluator_Equals();
134
+ default:
135
+ throw new Error(`CoreMRPathwayMapper: unmodelled condition \`${test.fields[0]} ${test.fields[1]}\` reached the mapper`);
136
+ }
137
+ }
138
+
139
+ export function convertTiming(timing: Timing_$union): ClinicalPathway_TriggerTiming_$union {
140
+ switch (timing.tag) {
141
+ case /* OnLock */ 1:
142
+ return ClinicalPathway_TriggerTiming_OnFormSubmit();
143
+ case /* OnFirstOpen */ 2:
144
+ return ClinicalPathway_TriggerTiming_OnFormLoad();
145
+ case /* UnrecognisedTiming */ 3:
146
+ throw new Error(`CoreMRPathwayMapper: event \`${timing.fields[0]}\` is not modelled — \`refusalFor\` refuses it first`);
147
+ default:
148
+ return ClinicalPathway_TriggerTiming_OnFormSave();
149
+ }
150
+ }
151
+
152
+ function convertPriority(_arg: Priority): ClinicalPathway_TaskPriority_$union {
153
+ const p: int32 = _arg.fields[0] | 0;
154
+ switch (p) {
155
+ case 1:
156
+ return ClinicalPathway_TaskPriority_High();
157
+ case 2:
158
+ return ClinicalPathway_TaskPriority_Medium();
159
+ case 3:
160
+ return ClinicalPathway_TaskPriority_Low();
161
+ default:
162
+ return ClinicalPathway_TaskPriority_Stated(p);
163
+ }
164
+ }
165
+
166
+ function parseDueDate(stated: string): ClinicalPathway_DueDate_$union {
167
+ const m: any = match(/^\+\s*(\d+)\s*(day|days|week|weeks)$/gu, stated.trim().toLowerCase());
168
+ const matchValue: string = stated.trim().toLowerCase();
169
+ switch (matchValue) {
170
+ case "today":
171
+ return ClinicalPathway_DueDate_Today();
172
+ case "tomorrow":
173
+ return ClinicalPathway_DueDate_Tomorrow();
174
+ default:
175
+ if (m != null) {
176
+ const n: int32 = parse(m[1] || "", 511, false, 32) | 0;
177
+ return ClinicalPathway_DueDate_DaysFromNow((m[2] || "").startsWith("week") ? (7 * n) : n);
178
+ }
179
+ else {
180
+ return ClinicalPathway_DueDate_AsStated(stated);
181
+ }
182
+ }
183
+ }
184
+
185
+ function requiredDue(what: string, stated: Option<string>): ClinicalPathway_DueDate_$union {
186
+ if (stated == null) {
187
+ throw new Error(`CoreMRPathwayMapper: ${what} states no date — none is invented`);
188
+ }
189
+ else {
190
+ return parseDueDate(value(stated));
191
+ }
192
+ }
193
+
194
+ export function convertCondition(items: FSharpList<TemplateItem>, cond: StatedCondition, itemFieldKeyMap: FSharpMap<int32, Shared_FieldKey>): ClinicalPathway_TransitionCondition_$union {
195
+ let fieldKey: Shared_FieldKey;
196
+ const matchValue: Option<Shared_FieldKey> = bind<int32, Shared_FieldKey>((item: int32): Option<Shared_FieldKey> => tryFind_1<int32, Shared_FieldKey>(item, itemFieldKeyMap), cond.SourceItem);
197
+ if (matchValue == null) {
198
+ throw new Error(toText(interpolate("CoreMRPathwayMapper: condition on item %A%P() is not a field — `nonFieldRefusal` refuses it first", [cond.SourceItem])));
199
+ }
200
+ else {
201
+ fieldKey = value(matchValue);
202
+ }
203
+ const values: FSharpList<string> = textsOf(items, cond)[1];
204
+ const evaluator: ClinicalPathway_FieldEvaluator_$union = convertOperator(cond.Test, values);
205
+ const canonicalize = Helpers_canonicalizeFieldKey;
206
+ let condValue: Shared_ConditionValue_$union;
207
+ const matchValue_1: Condition_$union = cond.Test;
208
+ switch (matchValue_1.tag) {
209
+ case /* AnyChosen */ 0:
210
+ case /* AllChosen */ 1:
211
+ case /* NoneChosen */ 2: {
212
+ condValue = Shared_ConditionValue_Multiple(ofList<string>(map_1<string, string>(canonicalize, values), {
213
+ Compare: comparePrimitives,
214
+ }));
215
+ break;
216
+ }
217
+ default:
218
+ condValue = (isEmpty(values) ? Shared_ConditionValue_Single("") : Shared_ConditionValue_Single(canonicalize(head_1(values))));
219
+ }
220
+ const matchValue_2: Condition_$union = cond.Test;
221
+ let matchResult: int32;
222
+ if (matchValue_2.tag === /* VitalIs */ 3) {
223
+ switch (matchValue_2.fields[0].tag) {
224
+ case /* SystolicBP */ 0: {
225
+ matchResult = 0;
226
+ break;
227
+ }
228
+ case /* DiastolicBP */ 1: {
229
+ matchResult = 1;
230
+ break;
231
+ }
232
+ default:
233
+ matchResult = 2;
234
+ }
235
+ }
236
+ else {
237
+ matchResult = 2;
238
+ }
239
+ switch (matchResult) {
240
+ case 0:
241
+ return ClinicalPathway_TransitionCondition_PluginPropertyCondition(fieldKey, new Shared_PluginPropertyKey(stableGuid("bp_systolic")), evaluator, condValue);
242
+ case 1:
243
+ return ClinicalPathway_TransitionCondition_PluginPropertyCondition(fieldKey, new Shared_PluginPropertyKey(stableGuid("bp_diastolic")), evaluator, condValue);
244
+ default:
245
+ return ClinicalPathway_TransitionCondition_FieldCondition(fieldKey, evaluator, condValue);
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Combine a trigger's conditions: the LEFT FOLD of each later condition's OWN join (CTA-033). The head's join is
251
+ * the release's default and is ignored (10245: head "&&", every later row "||" on all 18 St Johns chains — they
252
+ * read as OR; the old head-join made them AND). ⭐ A chain with one join throughout is ONE composite (the shape
253
+ * the pathway always had); a mixed chain nests left to right ((a op b) op c) — 0 at St Johns.
254
+ * ⛔ An unrecognised join never reaches here: `refusalFor` refuses its template by name.
255
+ */
256
+ export function combineConditions(items: FSharpList<TemplateItem>, conditions: FSharpList<StatedCondition>, itemFieldKeyMap: FSharpMap<int32, Shared_FieldKey>): ClinicalPathway_TransitionCondition_$union {
257
+ if (!isEmpty(conditions)) {
258
+ if (isEmpty(tail(conditions))) {
259
+ return convertCondition(items, head_1(conditions), itemFieldKeyMap);
260
+ }
261
+ else {
262
+ const ops: FSharpList<ClinicalPathway_LogicalOp_$union> = map_1<StatedCondition, ClinicalPathway_LogicalOp_$union>((c: StatedCondition): ClinicalPathway_LogicalOp_$union => {
263
+ const matchValue: Option<Join_$union> = c.Join;
264
+ if (matchValue == null) {
265
+ throw new Error("CoreMRPathwayMapper: a later condition states no join — the release cannot say how it combines");
266
+ }
267
+ else {
268
+ switch (value(matchValue).tag) {
269
+ case /* Or */ 1:
270
+ return ClinicalPathway_LogicalOp_Or();
271
+ case /* UnrecognisedJoin */ 2: {
272
+ const j: string = (value(matchValue) as Join<2>).fields[0];
273
+ throw new Error(`CoreMRPathwayMapper: join \`${j}\` is not modelled — \`refusalFor\` refuses it first`);
274
+ }
275
+ default:
276
+ return ClinicalPathway_LogicalOp_And();
277
+ }
278
+ }
279
+ }, tail(conditions));
280
+ const matchValue_1: FSharpList<ClinicalPathway_LogicalOp_$union> = List_distinct<ClinicalPathway_LogicalOp_$union>(ops, {
281
+ Equals: equals,
282
+ GetHashCode: safeHash,
283
+ });
284
+ let matchResult: int32, op: ClinicalPathway_LogicalOp_$union;
285
+ if (!isEmpty(matchValue_1)) {
286
+ if (isEmpty(tail(matchValue_1))) {
287
+ matchResult = 0;
288
+ op = head_1(matchValue_1);
289
+ }
290
+ else {
291
+ matchResult = 1;
292
+ }
293
+ }
294
+ else {
295
+ matchResult = 1;
296
+ }
297
+ switch (matchResult) {
298
+ case 0:
299
+ return ClinicalPathway_TransitionCondition_CompositeCondition(op!, map_1<StatedCondition, ClinicalPathway_TransitionCondition_$union>((c_1: StatedCondition): ClinicalPathway_TransitionCondition_$union => convertCondition(items, c_1, itemFieldKeyMap), conditions));
300
+ default: {
301
+ const list_3: FSharpList<[ClinicalPathway_LogicalOp_$union, StatedCondition]> = zip<ClinicalPathway_LogicalOp_$union, StatedCondition>(ops, tail(conditions));
302
+ return fold<[ClinicalPathway_LogicalOp_$union, StatedCondition], ClinicalPathway_TransitionCondition_$union>((acc: ClinicalPathway_TransitionCondition_$union, tupledArg: [ClinicalPathway_LogicalOp_$union, StatedCondition]): ClinicalPathway_TransitionCondition_$union => ClinicalPathway_TransitionCondition_CompositeCondition(tupledArg[0], ofArray([acc, convertCondition(items, tupledArg[1], itemFieldKeyMap)])), convertCondition(items, head_1(conditions), itemFieldKeyMap), list_3);
303
+ }
304
+ }
305
+ }
306
+ }
307
+ else {
308
+ return ClinicalPathway_TransitionCondition_Always();
309
+ }
310
+ }
311
+
312
+ function kindWord(a: Action_$union): string {
313
+ switch (a.tag) {
314
+ case /* Alert */ 2:
315
+ return "alert";
316
+ case /* Problem */ 3:
317
+ return "problem";
318
+ case /* Medset */ 4:
319
+ return "medset";
320
+ case /* StandingOrder */ 1:
321
+ if (a.fields[1].tag === /* Treatment */ 1) {
322
+ return "treatment";
323
+ }
324
+ else {
325
+ return "recurring_task";
326
+ }
327
+ case /* ChangeGroups */ 5:
328
+ return "groups";
329
+ default:
330
+ return "task";
331
+ }
332
+ }
333
+
334
+ function nameOf(r: Ref): string {
335
+ return defaultArg<string>(r.Name, "");
336
+ }
337
+
338
+ function modelledActions(t: Trigger): FSharpList<Action_$union> {
339
+ return map_1<StatedAction, Action_$union>((a: StatedAction): Action_$union => {
340
+ const matchValue: ActionRead_$union = a.Read;
341
+ if (matchValue.tag === /* Unmodelled */ 1) {
342
+ throw new Error(`CoreMRPathwayMapper: action ${a.ActionId} (\`${matchValue.fields[0]}\`) is unmodelled (${matchValue.fields[1]}) — \`refusalFor\` refuses it first`);
343
+ }
344
+ else {
345
+ return matchValue.fields[0];
346
+ }
347
+ }, t.Actions);
348
+ }
349
+
350
+ function standingOf(cadence: Cadence_$union): ClinicalPathway_StandingSchedule {
351
+ if (cadence.tag === /* Every */ 1) {
352
+ const until: string = cadence.fields[1];
353
+ return new ClinicalPathway_StandingSchedule(ClinicalPathway_Cadence_Every(cadence.fields[0], until), parseDueDate(until));
354
+ }
355
+ else {
356
+ const schedule: Ref = cadence.fields[0];
357
+ return new ClinicalPathway_StandingSchedule(ClinicalPathway_Cadence_OnSchedule(schedule.Id, schedule.Name), map<string, ClinicalPathway_DueDate_$union>(parseDueDate, cadence.fields[1]));
358
+ }
359
+ }
360
+
361
+ function taskOf(task: TaskOrder, standing: Option<ClinicalPathway_StandingSchedule>): ClinicalPathway_ActionInfo_$union {
362
+ return ClinicalPathway_ActionInfo_Task(new ClinicalPathway_TaskAction(task.Category.Id, nameOf(task.Category), task.Description, convertPriority(task.Priority), requiredDue("a task", task.Due), undefined, standing));
363
+ }
364
+
365
+ export function convertAction(action: Action_$union): ClinicalPathway_ActionInfo_$union {
366
+ switch (action.tag) {
367
+ case /* OneOffTask */ 0: {
368
+ const task: TaskOrder = action.fields[0];
369
+ return taskOf(task, undefined);
370
+ }
371
+ case /* StandingOrder */ 1:
372
+ if (action.fields[1].tag === /* Treatment */ 1) {
373
+ const cadence_1: Cadence_$union = action.fields[0];
374
+ const treatment: TreatmentOrder = (action.fields[1] as Standing<1>).fields[0];
375
+ return ClinicalPathway_ActionInfo_Treatment(new ClinicalPathway_TreatmentAction(treatment.Treatment.Id, treatment.Treatment.Name, map<Ref, int32>((r: Ref): int32 => r.Id, treatment.Provider), treatment.Instructions, parseDueDate(treatment.Start), standingOf(cadence_1), undefined, undefined, undefined));
376
+ }
377
+ else {
378
+ const cadence: Cadence_$union = action.fields[0];
379
+ const task_1: TaskOrder = (action.fields[1] as Standing<0>).fields[0];
380
+ return taskOf(task_1, standingOf(cadence));
381
+ }
382
+ case /* Medset */ 4: {
383
+ const medset: MedsetOrder = action.fields[0];
384
+ return ClinicalPathway_ActionInfo_Medset(new ClinicalPathway_MedsetAction(medset.Medset.Id, nameOf(medset.Medset), map<Ref, int32>((r_1: Ref): int32 => r_1.Id, medset.Prescriber), map<Ref, int32>((r_2: Ref): int32 => r_2.Id, medset.Pharmacy), requiredDue("a medset", medset.Start)));
385
+ }
386
+ case /* Problem */ 3: {
387
+ const problem: ProblemOrder = action.fields[0];
388
+ return ClinicalPathway_ActionInfo_Problem(new ClinicalPathway_ProblemAction(problem.Problem.Id, problem.Problem.Name, undefined, undefined, ClinicalPathway_ProblemStatus_Active(), undefined, problem.Chronic, problem.Severity, problem.Inflammation));
389
+ }
390
+ case /* ChangeGroups */ 5: {
391
+ const change: GroupChange_$union = action.fields[0];
392
+ const patternInput: [ClinicalPathway_GroupChange_$union, NonEmpty$1<Ref>] = (change.tag === /* RemoveFrom */ 1) ? ([ClinicalPathway_GroupChange_RemoveFromGroups(), change.fields[0]] as [ClinicalPathway_GroupChange_$union, NonEmpty$1<Ref>]) : ([ClinicalPathway_GroupChange_AddToGroups(), change.fields[0]] as [ClinicalPathway_GroupChange_$union, NonEmpty$1<Ref>]);
393
+ return ClinicalPathway_ActionInfo_ChangeGroups(new ClinicalPathway_GroupChangeAction(patternInput[0], map_1<Ref, ClinicalPathway_GroupRef>((r_3: Ref): ClinicalPathway_GroupRef => (new ClinicalPathway_GroupRef(r_3.Id, r_3.Name)), NonEmpty_toList<Ref>(patternInput[1]))));
394
+ }
395
+ default: {
396
+ const category: Ref = action.fields[0];
397
+ const categoryName: string = nameOf(category);
398
+ return ClinicalPathway_ActionInfo_Alert(new ClinicalPathway_AlertAction(category.Id, categoryName, categoryName, undefined, undefined));
399
+ }
400
+ }
401
+ }
402
+
403
+ export function generateEvaluationLabel(trigger: Trigger, items: FSharpList<TemplateItem>): string {
404
+ let item_1: TemplateItem, item_2: TemplateItem;
405
+ let fieldLabel: string;
406
+ const matchValue: FSharpList<StatedCondition> = trigger.Conditions;
407
+ if (!isEmpty(matchValue)) {
408
+ const head: StatedCondition = head_1(matchValue);
409
+ const matchValue_1: Option<TemplateItem> = bind<int32, TemplateItem>((id: int32): Option<TemplateItem> => tryFind<TemplateItem>((i: TemplateItem): boolean => (i.ItemId === id), items), head.SourceItem);
410
+ if (matchValue_1 == null) {
411
+ throw new Error(toText(interpolate("CoreMRPathwayMapper: trigger %P() reads item %A%P(), not on this form — refused first", [trigger.TriggerId, head.SourceItem])));
412
+ }
413
+ else {
414
+ fieldLabel = (isNullOrEmpty(value(matchValue_1).Text) ? ((item_1 = value(matchValue_1), "(no text)")) : ((item_2 = value(matchValue_1), (item_2.Text.length > 50) ? (substring(item_2.Text, 0, 47) + "...") : item_2.Text)));
415
+ }
416
+ }
417
+ else {
418
+ throw new Error(`CoreMRPathwayMapper: trigger ${trigger.TriggerId} states no condition — \`liveTriggers\` keeps none such`);
419
+ }
420
+ const matchValue_2: FSharpList<StatedCondition> = trigger.Conditions;
421
+ if (!isEmpty(matchValue_2)) {
422
+ if (isEmpty(tail(matchValue_2))) {
423
+ const matchValue_3: [string, FSharpList<string>] = textsOf(items, head_1(matchValue_2));
424
+ let matchResult: int32, v: string, vals_2: FSharpList<string>, vals_3: FSharpList<string>, v_1: string, v_2: string, v_3: string, v_4: string, v_5: string, v_6: string, vals_4: FSharpList<string>, op: string;
425
+ switch (matchValue_3[0]) {
426
+ case "any": {
427
+ if (!isEmpty(matchValue_3[1])) {
428
+ if (isEmpty(tail(matchValue_3[1]))) {
429
+ matchResult = 0;
430
+ v = head_1(matchValue_3[1]);
431
+ }
432
+ else if (length(matchValue_3[1]) <= 3) {
433
+ matchResult = 1;
434
+ vals_2 = matchValue_3[1];
435
+ }
436
+ else {
437
+ matchResult = 2;
438
+ vals_3 = matchValue_3[1];
439
+ }
440
+ }
441
+ else if (length(matchValue_3[1]) <= 3) {
442
+ matchResult = 1;
443
+ vals_2 = matchValue_3[1];
444
+ }
445
+ else {
446
+ matchResult = 2;
447
+ vals_3 = matchValue_3[1];
448
+ }
449
+ break;
450
+ }
451
+ case "equals": {
452
+ if (!isEmpty(matchValue_3[1])) {
453
+ if (isEmpty(tail(matchValue_3[1]))) {
454
+ matchResult = 3;
455
+ v_1 = head_1(matchValue_3[1]);
456
+ }
457
+ else {
458
+ matchResult = 10;
459
+ op = matchValue_3[0];
460
+ }
461
+ }
462
+ else {
463
+ matchResult = 10;
464
+ op = matchValue_3[0];
465
+ }
466
+ break;
467
+ }
468
+ case "not_equals": {
469
+ if (!isEmpty(matchValue_3[1])) {
470
+ if (isEmpty(tail(matchValue_3[1]))) {
471
+ matchResult = 4;
472
+ v_2 = head_1(matchValue_3[1]);
473
+ }
474
+ else {
475
+ matchResult = 10;
476
+ op = matchValue_3[0];
477
+ }
478
+ }
479
+ else {
480
+ matchResult = 10;
481
+ op = matchValue_3[0];
482
+ }
483
+ break;
484
+ }
485
+ case "greater_equals": {
486
+ if (!isEmpty(matchValue_3[1])) {
487
+ if (isEmpty(tail(matchValue_3[1]))) {
488
+ matchResult = 5;
489
+ v_3 = head_1(matchValue_3[1]);
490
+ }
491
+ else {
492
+ matchResult = 10;
493
+ op = matchValue_3[0];
494
+ }
495
+ }
496
+ else {
497
+ matchResult = 10;
498
+ op = matchValue_3[0];
499
+ }
500
+ break;
501
+ }
502
+ case "greater": {
503
+ if (!isEmpty(matchValue_3[1])) {
504
+ if (isEmpty(tail(matchValue_3[1]))) {
505
+ matchResult = 6;
506
+ v_4 = head_1(matchValue_3[1]);
507
+ }
508
+ else {
509
+ matchResult = 10;
510
+ op = matchValue_3[0];
511
+ }
512
+ }
513
+ else {
514
+ matchResult = 10;
515
+ op = matchValue_3[0];
516
+ }
517
+ break;
518
+ }
519
+ case "less_equals": {
520
+ if (!isEmpty(matchValue_3[1])) {
521
+ if (isEmpty(tail(matchValue_3[1]))) {
522
+ matchResult = 7;
523
+ v_5 = head_1(matchValue_3[1]);
524
+ }
525
+ else {
526
+ matchResult = 10;
527
+ op = matchValue_3[0];
528
+ }
529
+ }
530
+ else {
531
+ matchResult = 10;
532
+ op = matchValue_3[0];
533
+ }
534
+ break;
535
+ }
536
+ case "less": {
537
+ if (!isEmpty(matchValue_3[1])) {
538
+ if (isEmpty(tail(matchValue_3[1]))) {
539
+ matchResult = 8;
540
+ v_6 = head_1(matchValue_3[1]);
541
+ }
542
+ else {
543
+ matchResult = 10;
544
+ op = matchValue_3[0];
545
+ }
546
+ }
547
+ else {
548
+ matchResult = 10;
549
+ op = matchValue_3[0];
550
+ }
551
+ break;
552
+ }
553
+ case "all": {
554
+ matchResult = 9;
555
+ vals_4 = matchValue_3[1];
556
+ break;
557
+ }
558
+ default: {
559
+ matchResult = 10;
560
+ op = matchValue_3[0];
561
+ }
562
+ }
563
+ switch (matchResult) {
564
+ case 0:
565
+ return `When ${fieldLabel} = ${v!}`;
566
+ case 1:
567
+ return `When ${fieldLabel} is ${join(" or ", vals_2!)}`;
568
+ case 2:
569
+ return `When ${fieldLabel} is any of ${length(vals_3!)} values`;
570
+ case 3:
571
+ return `When ${fieldLabel} = ${v_1!}`;
572
+ case 4:
573
+ return `When ${fieldLabel} ≠ ${v_2!}`;
574
+ case 5:
575
+ return `When ${fieldLabel} ≥ ${v_3!}`;
576
+ case 6:
577
+ return `When ${fieldLabel} > ${v_4!}`;
578
+ case 7:
579
+ return `When ${fieldLabel} ≤ ${v_5!}`;
580
+ case 8:
581
+ return `When ${fieldLabel} < ${v_6!}`;
582
+ case 9:
583
+ return `When ${fieldLabel} has all of: ${join(", ", vals_4!)}`;
584
+ default:
585
+ return `When ${fieldLabel} ${op!}`;
586
+ }
587
+ }
588
+ else {
589
+ return `When ${fieldLabel} (${length(matchValue_2)} conditions)`;
590
+ }
591
+ }
592
+ else {
593
+ throw new Error(`CoreMRPathwayMapper: trigger ${trigger.TriggerId} states no condition`);
594
+ }
595
+ }
596
+
597
+ export function generateActionLabel(trigger: Trigger): string {
598
+ let matchValue_1: Priority;
599
+ const matchValue: FSharpList<Action_$union> = modelledActions(trigger);
600
+ if (!isEmpty(matchValue)) {
601
+ if (isEmpty(tail(matchValue))) {
602
+ let matchResult: int32, category: Ref, task: TaskOrder, medset: MedsetOrder, task_1: TaskOrder, other: Action_$union;
603
+ switch (head_1(matchValue).tag) {
604
+ case /* Alert */ 2: {
605
+ matchResult = 0;
606
+ category = (head_1(matchValue) as Action<2>).fields[0];
607
+ break;
608
+ }
609
+ case /* OneOffTask */ 0: {
610
+ matchResult = 1;
611
+ task = (head_1(matchValue) as Action<0>).fields[0];
612
+ break;
613
+ }
614
+ case /* Medset */ 4: {
615
+ matchResult = 2;
616
+ medset = (head_1(matchValue) as Action<4>).fields[0];
617
+ break;
618
+ }
619
+ case /* Problem */ 3: {
620
+ matchResult = 3;
621
+ break;
622
+ }
623
+ case /* StandingOrder */ 1: {
624
+ if ((head_1(matchValue) as Action<1>).fields[1].tag === /* RecurringTask */ 0) {
625
+ matchResult = 4;
626
+ task_1 = ((head_1(matchValue) as Action<1>).fields[1] as Standing<0>).fields[0];
627
+ }
628
+ else {
629
+ matchResult = 5;
630
+ other = head_1(matchValue);
631
+ }
632
+ break;
633
+ }
634
+ default: {
635
+ matchResult = 5;
636
+ other = head_1(matchValue);
637
+ }
638
+ }
639
+ switch (matchResult) {
640
+ case 0:
641
+ return `Create Alert: ${nameOf(category!)}`;
642
+ case 1:
643
+ return `Create ${(matchValue_1 = task!.Priority, (matchValue_1.fields[0] === 1) ? "High " : ((matchValue_1.fields[0] === 3) ? "Low " : ""))}Task: ${nameOf(task!.Category)}`;
644
+ case 2:
645
+ return `Order Medset: ${nameOf(medset!.Medset)}`;
646
+ case 3:
647
+ return "Add to Problem List";
648
+ case 4:
649
+ return `Schedule: ${nameOf(task_1!.Category)}`;
650
+ default:
651
+ return `Execute: ${kindWord(other!)}`;
652
+ }
653
+ }
654
+ else {
655
+ const joined: string = join(", ", List_distinct<string>(map_1<Action_$union, string>(kindWord, matchValue), {
656
+ Equals: (x: string, y: string): boolean => (x === y),
657
+ GetHashCode: stringHash,
658
+ }));
659
+ return `Execute ${length(matchValue)} actions: ${joined}`;
660
+ }
661
+ }
662
+ else {
663
+ return "No actions";
664
+ }
665
+ }
666
+
667
+ function pathwayActions(t: Trigger): FSharpList<ClinicalPathway_PathwayAction> {
668
+ let sourceItem: int32;
669
+ const matchValue: FSharpList<StatedCondition> = t.Conditions;
670
+ if (isEmpty(matchValue)) {
671
+ throw new Error(`CoreMRPathwayMapper: trigger ${t.TriggerId} states no condition — \`liveTriggers\` keeps none such`);
672
+ }
673
+ else if (head_1(matchValue).SourceItem == null) {
674
+ throw new Error(`CoreMRPathwayMapper: trigger ${t.TriggerId}'s head condition reads no item — \`refusalFor\` refuses it first`);
675
+ }
676
+ else {
677
+ const item: int32 = value(head_1(matchValue).SourceItem) | 0;
678
+ sourceItem = item;
679
+ }
680
+ return map_1<StatedAction, ClinicalPathway_PathwayAction>((a: StatedAction): ClinicalPathway_PathwayAction => {
681
+ const matchValue_1: ActionRead_$union = a.Read;
682
+ if (matchValue_1.tag === /* Unmodelled */ 1) {
683
+ throw new Error(`CoreMRPathwayMapper: action ${a.ActionId} (\`${matchValue_1.fields[0]}\`) is unmodelled (${matchValue_1.fields[1]}) — \`refusalFor\` refuses it first`);
684
+ }
685
+ else {
686
+ return new ClinicalPathway_PathwayAction(convertAction(matchValue_1.fields[0]), ClinicalPathway_ActionOrigin_CoreMRTrigger(new ClinicalPathway_CoreMRTriggerRef(t.TriggerId, a.ActionId, sourceItem)));
687
+ }
688
+ }, t.Actions);
689
+ }
690
+
691
+ function actionStateType(t: Trigger): ClinicalPathway_StateType_$union {
692
+ const matchValue: FSharpList<ClinicalPathway_PathwayAction> = pathwayActions(t);
693
+ if (!isEmpty(matchValue)) {
694
+ if (isEmpty(tail(matchValue))) {
695
+ return ClinicalPathway_StateType_Action(head_1(matchValue));
696
+ }
697
+ else {
698
+ return ClinicalPathway_StateType_CompoundAction(matchValue);
699
+ }
700
+ }
701
+ else {
702
+ throw new Error(`CoreMRPathwayMapper: trigger ${t.TriggerId} states no action — \`liveTriggers\` keeps none such`);
703
+ }
704
+ }
705
+
706
+ /**
707
+ * ⭐ `importedAt` is the import's ONE clock read, taken at the edge (f1-api's batch, Studio's tab) and passed IN
708
+ * (CTA-013): the mapper reads no clock, so the same input gives the same pathway, and a test can pin the instant.
709
+ */
710
+ export function convertTriggerToPathway(importedAt: Date, trigger: Trigger, items: FSharpList<TemplateItem>, itemFieldKeyMap: FSharpMap<int32, Shared_FieldKey>): ClinicalPathway_ClinicalPathwaySpec {
711
+ const tid: int32 = trigger.TriggerId | 0;
712
+ const startKey: Shared_StateKey = new Shared_StateKey(stableGuid(`t${tid}_start`));
713
+ const evalKey: Shared_StateKey = new Shared_StateKey(stableGuid(`t${tid}_eval`));
714
+ const actionKey: Shared_StateKey = new Shared_StateKey(stableGuid(`t${tid}_action`));
715
+ const endKey: Shared_StateKey = new Shared_StateKey(stableGuid(`t${tid}_end`));
716
+ const evalLabel: string = generateEvaluationLabel(trigger, items);
717
+ const actionLabel: string = generateActionLabel(trigger);
718
+ const startState: ClinicalPathway_StateDefinition = new ClinicalPathway_StateDefinition(startKey, "Start", 0, ClinicalPathway_StateType_Evaluation(new ClinicalPathway_EvaluationInfo("", undefined)), undefined);
719
+ const evalState: ClinicalPathway_StateDefinition = new ClinicalPathway_StateDefinition(evalKey, evalLabel, 1, ClinicalPathway_StateType_Evaluation(new ClinicalPathway_EvaluationInfo("", undefined)), undefined);
720
+ const actionState: ClinicalPathway_StateDefinition = new ClinicalPathway_StateDefinition(actionKey, actionLabel, 2, actionStateType(trigger), undefined);
721
+ const endState: ClinicalPathway_StateDefinition = new ClinicalPathway_StateDefinition(endKey, "Complete", 3, ClinicalPathway_StateType_Terminal(new ClinicalPathway_TerminalInfo("Complete", "Trigger evaluation complete", undefined)), undefined);
722
+ const condition: ClinicalPathway_TransitionCondition_$union = combineConditions(items, trigger.Conditions, itemFieldKeyMap);
723
+ const transitions: FSharpList<ClinicalPathway_TransitionDefinition> = ofArray([new ClinicalPathway_TransitionDefinition(new Shared_TransitionKey(stableGuid(`t${tid}_start_to_eval`)), startKey, evalKey, ClinicalPathway_TransitionCondition_Always(), undefined), new ClinicalPathway_TransitionDefinition(new Shared_TransitionKey(stableGuid(`t${tid}_eval_to_action`)), evalKey, actionKey, condition, 0), new ClinicalPathway_TransitionDefinition(new Shared_TransitionKey(stableGuid(`t${tid}_action_to_end`)), actionKey, endKey, ClinicalPathway_TransitionCondition_Always(), undefined)]);
724
+ return new ClinicalPathway_ClinicalPathwaySpec(`item_trigger_${tid}`, `Trigger ${tid}: ${actionLabel}`, "1.0.0", "CoreMR Conduit - Item Trigger", ClinicalPathway_PathwayExecutionMode_TriggerBased(new ClinicalPathway_TriggerBasedConfig(convertTiming(trigger.Timing), true)), startKey, ofArray([startState, evalState, actionState, endState]), transitions, empty<ClinicalPathway_ConstraintDefinition>(), empty<ClinicalPathway_PathRequirement>(), importedAt, undefined, undefined, 1);
725
+ }
726
+
727
+ /**
728
+ * The triggers a pathway is built from, in pathway order: each attached to the form items its conditions read
729
+ * (a source item id > 0 the form carries), in ITEM order then the order conduit states the triggers (by id) —
730
+ * first attachment wins — keeping only ENABLED triggers that state at least one action.
731
+ * ⭐ This is the attachment conduit made for the raw rows (`templateOf` → `items[].triggers`), recomputed from
732
+ * the DOMAIN's own facts. ⚠️ A trigger whose conditions read no item of the form attaches nowhere and fires
733
+ * nothing, exactly as before.
734
+ */
735
+ export function liveTriggers(form: TemplateForm, reads: ReleaseAvailability$1_$union<FSharpList<Trigger>>): FSharpList<Trigger> {
736
+ switch (reads.tag) {
737
+ case /* Stated */ 0: {
738
+ const byId: FSharpList<Trigger> = sortBy<Trigger, int32>((t: Trigger): int32 => t.TriggerId, reads.fields[0], {
739
+ Compare: comparePrimitives,
740
+ });
741
+ return filter<Trigger>((t_3: Trigger): boolean => {
742
+ if (t_3.Enabled) {
743
+ return !isEmpty(t_3.Actions);
744
+ }
745
+ else {
746
+ return false;
747
+ }
748
+ }, List_distinctBy<Trigger, int32>((t_2: Trigger): int32 => t_2.TriggerId, collect<TemplateItem, Trigger>((item: TemplateItem): FSharpList<Trigger> => filter<Trigger>((t_1: Trigger): boolean => exists<StatedCondition>((c: StatedCondition): boolean => equals(c.SourceItem, item.ItemId), t_1.Conditions), byId), form.Items), {
749
+ Equals: (x_1: int32, y_1: int32): boolean => (x_1 === y_1),
750
+ GetHashCode: numberHash,
751
+ }));
752
+ }
753
+ default:
754
+ return empty<Trigger>();
755
+ }
756
+ }
757
+
758
+ /**
759
+ * `Some sentence` when `form` must be refused — the sentence names every refused kind it uses, sorted.
760
+ * ⭐ The refusal is CONDUIT's supply's now (an action it serves `Unmodelled`, CTA-031); this only reads it.
761
+ * ⚠️ LIVE triggers only, exactly as the pathway reads them: St Johns form 130 carries a `recurring_task` on a
762
+ * DISABLED trigger and is not refused (CTA-003).
763
+ * ⚠️ The sentence still names "the 5.5.0+10245 converter" because the storage golden's report freezes it;
764
+ * rewording it is an intended diff (CTA-033).
765
+ * ⭐ ENFORCED BY: `VendorScoreTests`/`FormTemplateDomainTests` (FormSpec.FS.Tests) and the golden's 11 refusals.
766
+ */
767
+ export function refusalFor(form: TemplateForm, reads: ReleaseAvailability$1_$union<FSharpList<Trigger>>): Option<string> {
768
+ let arg: string, arg_1: string;
769
+ const live: FSharpList<Trigger> = liveTriggers(form, reads);
770
+ const kinds: FSharpList<string> = sort<string>(List_distinct<string>(collect<Trigger, string>((t: Trigger): FSharpList<string> => choose<StatedAction, string>((a: StatedAction): Option<string> => {
771
+ const matchValue: ActionRead_$union = a.Read;
772
+ if (matchValue.tag === /* Modelled */ 0) {
773
+ return undefined;
774
+ }
775
+ else {
776
+ const kind: string = matchValue.fields[0];
777
+ return kind.toLowerCase();
778
+ }
779
+ }, t.Actions), live), {
780
+ Equals: (x: string, y: string): boolean => (x === y),
781
+ GetHashCode: stringHash,
782
+ }), {
783
+ Compare: comparePrimitives,
784
+ });
785
+ const conditions: FSharpList<string> = sort<string>(List_distinct<string>(append<string>((reads.tag === /* NotInRelease */ 1) ? empty<string>() : ((reads.tag === /* NotReadYet */ 2) ? empty<string>() : map_1<Trigger, string>((t_3: Trigger): string => (`trigger ${t_3.TriggerId} reads no item`), filter<Trigger>((t_2: Trigger): boolean => exists<StatedCondition>((c: StatedCondition): boolean => (c.SourceItem == null), t_2.Conditions), filter<Trigger>((t_1: Trigger): boolean => {
786
+ if (t_1.Enabled) {
787
+ return !isEmpty(t_1.Actions);
788
+ }
789
+ else {
790
+ return false;
791
+ }
792
+ }, reads.fields[0])))), collect<Trigger, string>((t_4: Trigger): FSharpList<string> => toList<string>(delay<string>((): Iterable<string> => append_1<string>(collect_1<StatedCondition, Iterable<string>, string>((c_1: StatedCondition): Iterable<string> => {
793
+ let matchValue_1: Condition_$union;
794
+ return append_1<string>((matchValue_1 = c_1.Test, (matchValue_1.tag === /* UnmodelledCondition */ 6) ? singleton_1<string>(`${matchValue_1.fields[0]} ${matchValue_1.fields[1]}`) : (empty_1<string>())), delay<string>((): Iterable<string> => {
795
+ const matchValue_2: Option<Join_$union> = c_1.Join;
796
+ let matchResult: int32, j: string;
797
+ if (matchValue_2 != null) {
798
+ if (value(matchValue_2).tag === /* UnrecognisedJoin */ 2) {
799
+ matchResult = 0;
800
+ j = (value(matchValue_2) as Join<2>).fields[0];
801
+ }
802
+ else {
803
+ matchResult = 1;
804
+ }
805
+ }
806
+ else {
807
+ matchResult = 1;
808
+ }
809
+ switch (matchResult) {
810
+ case 0:
811
+ return singleton_1<string>(`join ${j!}`);
812
+ default: {
813
+ return empty_1<string>();
814
+ }
815
+ }
816
+ }));
817
+ }, t_4.Conditions), delay<string>((): Iterable<string> => {
818
+ const matchValue_3: Timing_$union = t_4.Timing;
819
+ if (matchValue_3.tag === /* UnrecognisedTiming */ 3) {
820
+ return singleton_1<string>(`event ${matchValue_3.fields[0]}`);
821
+ }
822
+ else {
823
+ return empty_1<string>();
824
+ }
825
+ })))), live)), {
826
+ Equals: (x_2: string, y_2: string): boolean => (x_2 === y_2),
827
+ GetHashCode: stringHash,
828
+ }), {
829
+ Compare: comparePrimitives,
830
+ });
831
+ if (isEmpty(kinds)) {
832
+ if (isEmpty(conditions)) {
833
+ return undefined;
834
+ }
835
+ else {
836
+ return (arg = join(", ", conditions), toText(printf("refused — its triggers state what the CoreMR trigger domain cannot evaluate yet: %s. Nothing is imported rather than a pathway that cannot be evaluated."))(arg));
837
+ }
838
+ }
839
+ else {
840
+ return (arg_1 = join(", ", kinds), toText(printf("refused — its triggers use action kinds the 5.5.0+10245 converter does not model faithfully yet: %s. Nothing is imported rather than a pathway with invented actions."))(arg_1));
841
+ }
842
+ }
843
+
844
+ /**
845
+ * ⛔ THROWS the `refusalFor` sentence for a form it must refuse. Its one caller (`CoreMRImportPipeline.runPipeline`)
846
+ * turns any throw into the import's *not converted* reason, so the sentence is what a clinician reads.
847
+ */
848
+ export function convertFormTriggersToPathway(importedAt: Date, form: TemplateForm, reads: ReleaseAvailability$1_$union<FSharpList<Trigger>>, itemFieldKeyMap: FSharpMap<int32, Shared_FieldKey>): Option<ClinicalPathway_ClinicalPathwaySpec> {
849
+ let arg: string;
850
+ const matchValue: Option<string> = refusalFor(form, reads);
851
+ if (matchValue == null) {
852
+ }
853
+ else {
854
+ throw new Error(value(matchValue));
855
+ }
856
+ const nonField: FSharpList<string> = List_distinct<string>(collect<Trigger, string>((t: Trigger): FSharpList<string> => choose<StatedCondition, string>((c: StatedCondition): Option<string> => {
857
+ const matchValue_1: Option<int32> = c.SourceItem;
858
+ let matchResult: int32, item_1: int32;
859
+ if (matchValue_1 != null) {
860
+ if (!FSharpMap__ContainsKey(itemFieldKeyMap, value(matchValue_1))) {
861
+ matchResult = 0;
862
+ item_1 = value(matchValue_1);
863
+ }
864
+ else {
865
+ matchResult = 1;
866
+ }
867
+ }
868
+ else {
869
+ matchResult = 1;
870
+ }
871
+ switch (matchResult) {
872
+ case 0:
873
+ return `trigger ${t.TriggerId} reads item ${item_1!}`;
874
+ default:
875
+ return undefined;
876
+ }
877
+ }, t.Conditions), liveTriggers(form, reads)), {
878
+ Equals: (x: string, y: string): boolean => (x === y),
879
+ GetHashCode: stringHash,
880
+ });
881
+ if (isEmpty(nonField)) {
882
+ }
883
+ else {
884
+ throw new Error((arg = join(", ", nonField), toText(printf("refused — its triggers read items that are not fields of this blueprint, so their branches could never fire: %s. Nothing is imported rather than a pathway with branches that can never fire."))(arg)));
885
+ }
886
+ const matchValue_2: FSharpList<Trigger> = liveTriggers(form, reads);
887
+ if (!isEmpty(matchValue_2)) {
888
+ if (isEmpty(tail(matchValue_2))) {
889
+ return convertTriggerToPathway(importedAt, head_1(matchValue_2), form.Items, itemFieldKeyMap);
890
+ }
891
+ else {
892
+ const pathwayId = `form_${form.FormId}_pathway`;
893
+ const startKey: Shared_StateKey = new Shared_StateKey(stableGuid(`${pathwayId}_start`));
894
+ let allStates: FSharpList<ClinicalPathway_StateDefinition> = singleton(new ClinicalPathway_StateDefinition(startKey, "Start", 0, ClinicalPathway_StateType_Evaluation(new ClinicalPathway_EvaluationInfo("", undefined)), undefined));
895
+ let allTransitions: FSharpList<ClinicalPathway_TransitionDefinition> = empty<ClinicalPathway_TransitionDefinition>();
896
+ const enumerator: IEnumerator<[int32, Trigger]> = getEnumerator(indexed<Trigger>(matchValue_2));
897
+ try {
898
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
899
+ const forLoopVar: [int32, Trigger] = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
900
+ const trigger: Trigger = forLoopVar[1];
901
+ const idx: int32 = forLoopVar[0] | 0;
902
+ const tid: int32 = trigger.TriggerId | 0;
903
+ const evalKey: Shared_StateKey = new Shared_StateKey(stableGuid(`${pathwayId}_eval_${tid}`));
904
+ const actionKey: Shared_StateKey = new Shared_StateKey(stableGuid(`${pathwayId}_action_${tid}`));
905
+ const endKey: Shared_StateKey = new Shared_StateKey(stableGuid(`${pathwayId}_end_${tid}`));
906
+ const evalState: ClinicalPathway_StateDefinition = new ClinicalPathway_StateDefinition(evalKey, generateEvaluationLabel(trigger, form.Items), (idx * 3) + 1, ClinicalPathway_StateType_Evaluation(new ClinicalPathway_EvaluationInfo("", undefined)), undefined);
907
+ const actionState: ClinicalPathway_StateDefinition = new ClinicalPathway_StateDefinition(actionKey, generateActionLabel(trigger), (idx * 3) + 2, actionStateType(trigger), undefined);
908
+ const endState: ClinicalPathway_StateDefinition = new ClinicalPathway_StateDefinition(endKey, "Complete", (idx * 3) + 3, ClinicalPathway_StateType_Terminal(new ClinicalPathway_TerminalInfo("Complete", `Trigger ${tid} complete`, undefined)), undefined);
909
+ const condition: ClinicalPathway_TransitionCondition_$union = combineConditions(form.Items, trigger.Conditions, itemFieldKeyMap);
910
+ const transitions: FSharpList<ClinicalPathway_TransitionDefinition> = ofArray([new ClinicalPathway_TransitionDefinition(new Shared_TransitionKey(stableGuid(`${pathwayId}_start_to_eval_${tid}`)), startKey, evalKey, ClinicalPathway_TransitionCondition_Always(), idx), new ClinicalPathway_TransitionDefinition(new Shared_TransitionKey(stableGuid(`${pathwayId}_eval_to_action_${tid}`)), evalKey, actionKey, condition, idx), new ClinicalPathway_TransitionDefinition(new Shared_TransitionKey(stableGuid(`${pathwayId}_action_to_end_${tid}`)), actionKey, endKey, ClinicalPathway_TransitionCondition_Always(), undefined)]);
911
+ allStates = append(allStates, ofArray([evalState, actionState, endState]));
912
+ allTransitions = append(allTransitions, transitions);
913
+ }
914
+ }
915
+ finally {
916
+ disposeSafe(enumerator as IDisposable);
917
+ }
918
+ return new ClinicalPathway_ClinicalPathwaySpec(pathwayId, `${form.Name} - Clinical Pathway`, "1.0.0", "CoreMR Conduit - Unified Item Triggers", ClinicalPathway_PathwayExecutionMode_MultiPathway(new ClinicalPathway_MultiPathwayConfig(ClinicalPathway_CombinationStrategy_AllMatching(), ClinicalPathway_ConflictResolution_CombineActions(), undefined)), startKey, allStates, allTransitions, empty<ClinicalPathway_ConstraintDefinition>(), empty<ClinicalPathway_PathRequirement>(), importedAt, undefined, undefined, 1);
919
+ }
920
+ }
921
+ else {
922
+ return undefined;
923
+ }
924
+ }
925
+
926
+ //# sourceMappingURL=CoreMRPathwayMapper.ts.map