@icure/form 1.1.14 → 1.1.16

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 (195) hide show
  1. package/.yarn/cache/@lit-labs-ssr-dom-shim-npm-1.2.0-6bda8c35cb-704621c28d.zip +0 -0
  2. package/.yarn/cache/@lit-reactive-element-npm-1.6.3-4828441e51-79b58631c3.zip +0 -0
  3. package/.yarn/cache/@lit-reactive-element-npm-2.0.4-4836436301-368d788d9e.zip +0 -0
  4. package/.yarn/cache/@material-animation-npm-14.0.0-canary.53b3cad2f.0-06a813cdea-9b5190654c.zip +0 -0
  5. package/.yarn/cache/@material-base-npm-14.0.0-canary.53b3cad2f.0-d195c1fdc4-9f4928d115.zip +0 -0
  6. package/.yarn/cache/@material-button-npm-14.0.0-canary.53b3cad2f.0-d4b070f508-873295c56a.zip +0 -0
  7. package/.yarn/cache/@material-density-npm-14.0.0-canary.53b3cad2f.0-48c1f65059-a23f00edfe.zip +0 -0
  8. package/.yarn/cache/@material-dialog-npm-14.0.0-canary.53b3cad2f.0-96168fa294-c1a498b81a.zip +0 -0
  9. package/.yarn/cache/@material-dom-npm-14.0.0-canary.53b3cad2f.0-ac009dc871-f5817f76dd.zip +0 -0
  10. package/.yarn/cache/@material-elevation-npm-14.0.0-canary.53b3cad2f.0-3312f06793-2f8945c7b6.zip +0 -0
  11. package/.yarn/cache/@material-feature-targeting-npm-14.0.0-canary.53b3cad2f.0-a919042d50-e7a1ed68f9.zip +0 -0
  12. package/.yarn/cache/@material-floating-label-npm-14.0.0-canary.53b3cad2f.0-eb8f330f2f-5295dc481d.zip +0 -0
  13. package/.yarn/cache/@material-focus-ring-npm-14.0.0-canary.53b3cad2f.0-b22f851a2e-92273b1247.zip +0 -0
  14. package/.yarn/cache/@material-icon-button-npm-14.0.0-canary.53b3cad2f.0-e158d26048-19b51665f2.zip +0 -0
  15. package/.yarn/cache/@material-line-ripple-npm-14.0.0-canary.53b3cad2f.0-d089468db9-6518961487.zip +0 -0
  16. package/.yarn/cache/@material-list-npm-14.0.0-canary.53b3cad2f.0-df9ce05084-6c977f518d.zip +0 -0
  17. package/.yarn/cache/@material-menu-npm-14.0.0-canary.53b3cad2f.0-9489b592c8-71b6a1f4dd.zip +0 -0
  18. package/.yarn/cache/@material-menu-surface-npm-14.0.0-canary.53b3cad2f.0-52212f38f4-ad48e168ca.zip +0 -0
  19. package/.yarn/cache/@material-mwc-base-npm-0.27.0-79caf3ef2b-07af17edfc.zip +0 -0
  20. package/.yarn/cache/@material-mwc-button-npm-0.27.0-4b85f2b26f-2ef5cc0951.zip +0 -0
  21. package/.yarn/cache/@material-mwc-checkbox-npm-0.27.0-e837031d8e-ba53a6ea8c.zip +0 -0
  22. package/.yarn/cache/@material-mwc-dialog-npm-0.27.0-77c6071543-ffab528e8e.zip +0 -0
  23. package/.yarn/cache/@material-mwc-floating-label-npm-0.27.0-80e62b22c0-fbbf4f2e42.zip +0 -0
  24. package/.yarn/cache/@material-mwc-icon-button-npm-0.27.0-41f82f135b-7315c0735b.zip +0 -0
  25. package/.yarn/cache/@material-mwc-icon-npm-0.27.0-98c9e8509f-6dfa5115d5.zip +0 -0
  26. package/.yarn/cache/@material-mwc-line-ripple-npm-0.27.0-e6704221e0-6862ede0f4.zip +0 -0
  27. package/.yarn/cache/@material-mwc-list-npm-0.27.0-5344fc9de4-6c2ae4f1c6.zip +0 -0
  28. package/.yarn/cache/@material-mwc-menu-npm-0.27.0-7c2bb47797-126f733659.zip +0 -0
  29. package/.yarn/cache/@material-mwc-notched-outline-npm-0.27.0-0e0d1c4d5f-2739032f76.zip +0 -0
  30. package/.yarn/cache/@material-mwc-radio-npm-0.27.0-aa2098a280-0b0a0a6b99.zip +0 -0
  31. package/.yarn/cache/@material-mwc-ripple-npm-0.27.0-ed37672f08-9cd73fdfe4.zip +0 -0
  32. package/.yarn/cache/@material-mwc-textfield-npm-0.27.0-dabd704f55-978c893aca.zip +0 -0
  33. package/.yarn/cache/@material-notched-outline-npm-14.0.0-canary.53b3cad2f.0-ecacde98db-1a9f8db4d8.zip +0 -0
  34. package/.yarn/cache/@material-radio-npm-14.0.0-canary.53b3cad2f.0-c50de64d41-898554f2b3.zip +0 -0
  35. package/.yarn/cache/@material-ripple-npm-14.0.0-canary.53b3cad2f.0-49060bfe7e-08b71917e2.zip +0 -0
  36. package/.yarn/cache/@material-rtl-npm-14.0.0-canary.53b3cad2f.0-daca794b76-3c1b8b48c6.zip +0 -0
  37. package/.yarn/cache/@material-shape-npm-14.0.0-canary.53b3cad2f.0-5bcff722a6-6ad9b020c0.zip +0 -0
  38. package/.yarn/cache/@material-textfield-npm-14.0.0-canary.53b3cad2f.0-4414808dda-7072e3c9df.zip +0 -0
  39. package/.yarn/cache/@material-theme-npm-14.0.0-canary.53b3cad2f.0-9a24e7b046-fd44e92917.zip +0 -0
  40. package/.yarn/cache/@material-tokens-npm-14.0.0-canary.53b3cad2f.0-f1c87523da-efa909f861.zip +0 -0
  41. package/.yarn/cache/@material-touch-target-npm-14.0.0-canary.53b3cad2f.0-fa6a2d0875-dbc13cbe7a.zip +0 -0
  42. package/.yarn/cache/@material-typography-npm-14.0.0-canary.53b3cad2f.0-f4a58946f1-fa2671df40.zip +0 -0
  43. package/.yarn/cache/@types-trusted-types-npm-2.0.7-a07fc44f59-8e4202766a.zip +0 -0
  44. package/.yarn/cache/@webcomponents-webcomponentsjs-npm-2.8.0-36c07db4d2-186373c030.zip +0 -0
  45. package/.yarn/cache/app-datepicker-npm-6.0.0-rc.33-f74d593ddf-6490949c45.zip +0 -0
  46. package/.yarn/cache/argparse-npm-2.0.1-faff7999e6-83644b5649.zip +0 -0
  47. package/.yarn/cache/blocking-elements-npm-0.1.1-423f51c76e-9a34084405.zip +0 -0
  48. package/.yarn/cache/entities-npm-4.5.0-7cdb83b832-853f8ebd5b.zip +0 -0
  49. package/.yarn/cache/fast-deep-equal-npm-3.1.3-790edcfcf5-e21a9d8d84.zip +0 -0
  50. package/.yarn/cache/linkify-it-npm-5.0.0-adb5f9c96f-b0b86cadaf.zip +0 -0
  51. package/.yarn/cache/lit-element-npm-3.3.3-2f9f9e38c0-29a596fa55.zip +0 -0
  52. package/.yarn/cache/lit-element-npm-4.0.6-bfca4f9870-4f73cd1c0d.zip +0 -0
  53. package/.yarn/cache/lit-html-npm-2.8.0-82f88d6ebf-2d70df0724.zip +0 -0
  54. package/.yarn/cache/lit-html-npm-3.1.4-58e56c5010-428593679c.zip +0 -0
  55. package/.yarn/cache/lit-npm-2.8.0-92bb1333a4-2480e733f7.zip +0 -0
  56. package/.yarn/cache/lit-npm-3.1.4-b7dcc2d5a3-c6ffa5580f.zip +0 -0
  57. package/.yarn/cache/lit-ntml-npm-3.0.6-98ebc6c1ac-2917c778d9.zip +0 -0
  58. package/.yarn/cache/lodash-es-npm-4.17.21-b45832dfce-05cbffad6e.zip +0 -0
  59. package/.yarn/cache/markdown-it-npm-14.1.0-e337d75bfe-07296b45eb.zip +0 -0
  60. package/.yarn/cache/mdurl-npm-2.0.0-3259713daf-880bc289ef.zip +0 -0
  61. package/.yarn/cache/nodemod-npm-3.0.6-844d650911-47ffe619b3.zip +0 -0
  62. package/.yarn/cache/normalize-diacritics-npm-3.0.12-93e2346015-5ddc2cfaf8.zip +0 -0
  63. package/.yarn/cache/orderedmap-npm-2.1.1-64b8a0684f-082cf970b0.zip +0 -0
  64. package/.yarn/cache/parse5-npm-6.0.1-70a35a494a-7d569a176c.zip +0 -0
  65. package/.yarn/cache/prosemirror-commands-npm-1.5.2-27f8f3fee9-ff65063a8c.zip +0 -0
  66. package/.yarn/cache/prosemirror-history-npm-1.3.2-cc128c8ee6-b85fe6378a.zip +0 -0
  67. package/.yarn/cache/prosemirror-keymap-npm-1.2.2-efb8276b00-85fe4fc303.zip +0 -0
  68. package/.yarn/cache/prosemirror-markdown-npm-1.12.0-28e990f443-d7607ee1a6.zip +0 -0
  69. package/.yarn/cache/prosemirror-model-npm-1.19.4-4fd32211c8-12c277ed30.zip +0 -0
  70. package/.yarn/cache/prosemirror-model-npm-1.22.2-9238026de4-f4004a4ebe.zip +0 -0
  71. package/.yarn/cache/prosemirror-schema-basic-npm-1.2.2-def7bf2ec7-1f93f8678c.zip +0 -0
  72. package/.yarn/cache/prosemirror-schema-list-npm-1.3.0-23c1830a7e-03654e37c8.zip +0 -0
  73. package/.yarn/cache/prosemirror-state-npm-1.4.3-d6540e44ad-28857d935c.zip +0 -0
  74. package/.yarn/cache/prosemirror-transform-npm-1.8.0-ea3ca0411f-6d16ca4f95.zip +0 -0
  75. package/.yarn/cache/prosemirror-transform-npm-1.9.0-fd256f82f0-c2d63c1fb0.zip +0 -0
  76. package/.yarn/cache/prosemirror-view-npm-1.32.7-63c3e4b182-40c9038a52.zip +0 -0
  77. package/.yarn/cache/prosemirror-view-npm-1.33.9-dd77e3e48f-d3bd6cef56.zip +0 -0
  78. package/.yarn/cache/punycode.js-npm-2.3.1-9084ecbbf5-13466d7ed5.zip +0 -0
  79. package/.yarn/cache/rope-sequence-npm-1.3.4-3b09587e5f-95cca2f99a.zip +0 -0
  80. package/.yarn/cache/tslib-npm-2.6.3-0fd136b3be-74fce0e100.zip +0 -0
  81. package/.yarn/cache/uc.micro-npm-2.1.0-c45282c865-3719735824.zip +0 -0
  82. package/.yarn/cache/uuid-npm-9.0.1-39a8442bc6-39931f6da7.zip +0 -0
  83. package/.yarn/cache/w3c-keyname-npm-2.2.8-66d7d5317a-95bafa4c04.zip +0 -0
  84. package/.yarn/cache/wicg-inert-npm-3.1.2-786d525c4e-538c5cb7f2.zip +0 -0
  85. package/.yarn/install-state.gz +0 -0
  86. package/components/common/field-with-options.d.ts +1 -1
  87. package/components/common/field-with-options.js.map +1 -1
  88. package/components/common/field.d.ts +3 -1
  89. package/components/common/field.js +18 -8
  90. package/components/common/field.js.map +1 -1
  91. package/components/common/utils.js.map +1 -1
  92. package/components/icure-button-group/index.js +8 -2
  93. package/components/icure-button-group/index.js.map +1 -1
  94. package/components/icure-date-picker/index.js +11 -4
  95. package/components/icure-date-picker/index.js.map +1 -1
  96. package/components/icure-dropdown-field/index.d.ts +3 -1
  97. package/components/icure-dropdown-field/index.js +42 -9
  98. package/components/icure-dropdown-field/index.js.map +1 -1
  99. package/components/icure-form/fields/button-group/checkbox.js +4 -3
  100. package/components/icure-form/fields/button-group/checkbox.js.map +1 -1
  101. package/components/icure-form/fields/button-group/radio-button.js +5 -4
  102. package/components/icure-form/fields/button-group/radio-button.js.map +1 -1
  103. package/components/icure-form/fields/date-picker/date-picker.js +4 -3
  104. package/components/icure-form/fields/date-picker/date-picker.js.map +1 -1
  105. package/components/icure-form/fields/date-picker/date-time-picker.js +4 -3
  106. package/components/icure-form/fields/date-picker/date-time-picker.js.map +1 -1
  107. package/components/icure-form/fields/date-picker/time-picker.js +4 -3
  108. package/components/icure-form/fields/date-picker/time-picker.js.map +1 -1
  109. package/components/icure-form/fields/dropdown/dropdown-field.d.ts +2 -4
  110. package/components/icure-form/fields/dropdown/dropdown-field.js +6 -5
  111. package/components/icure-form/fields/dropdown/dropdown-field.js.map +1 -1
  112. package/components/icure-form/fields/items-list-field/items-list-field.js +4 -4
  113. package/components/icure-form/fields/items-list-field/items-list-field.js.map +1 -1
  114. package/components/icure-form/fields/label/label.js +1 -1
  115. package/components/icure-form/fields/label/label.js.map +1 -1
  116. package/components/icure-form/fields/measure-field/measure-field.js +4 -3
  117. package/components/icure-form/fields/measure-field/measure-field.js.map +1 -1
  118. package/components/icure-form/fields/number-field/number-field.js +4 -3
  119. package/components/icure-form/fields/number-field/number-field.js.map +1 -1
  120. package/components/icure-form/fields/text-field/text-field.d.ts +1 -1
  121. package/components/icure-form/fields/text-field/text-field.js +5 -4
  122. package/components/icure-form/fields/text-field/text-field.js.map +1 -1
  123. package/components/icure-form/fields/token-field/token-field.js +4 -4
  124. package/components/icure-form/fields/token-field/token-field.js.map +1 -1
  125. package/components/icure-form/fields/utils/index.d.ts +4 -6
  126. package/components/icure-form/fields/utils/index.js +1 -1
  127. package/components/icure-form/fields/utils/index.js.map +1 -1
  128. package/components/icure-form/index.d.ts +8 -8
  129. package/components/icure-form/index.js +17 -13
  130. package/components/icure-form/index.js.map +1 -1
  131. package/components/icure-form/renderer/form/form-selection-button.js +1 -1
  132. package/components/icure-form/renderer/form/form-selection-button.js.map +1 -1
  133. package/components/icure-form/renderer/form/form.js +67 -58
  134. package/components/icure-form/renderer/form/form.js.map +1 -1
  135. package/components/icure-form/renderer/index.d.ts +4 -6
  136. package/components/icure-form/renderer/index.js.map +1 -1
  137. package/components/icure-label/index.js +6 -1
  138. package/components/icure-label/index.js.map +1 -1
  139. package/components/icure-text-field/index.d.ts +7 -9
  140. package/components/icure-text-field/index.js +118 -51
  141. package/components/icure-text-field/index.js.map +1 -1
  142. package/components/icure-text-field/plugin/caret-fix-plugin.js.map +1 -1
  143. package/components/icure-text-field/plugin/mask-plugin.js.map +1 -1
  144. package/components/icure-text-field/plugin/regexp-plugin.js.map +1 -1
  145. package/components/icure-text-field/prosemirror-commands.d.ts +2 -2
  146. package/components/icure-text-field/prosemirror-commands.js.map +1 -1
  147. package/components/icure-text-field/prosemirror-utils.js.map +1 -1
  148. package/components/icure-text-field/schema/common-marks.js.map +1 -1
  149. package/components/icure-text-field/schema/measure-schema.js.map +1 -1
  150. package/components/icure-text-field/selection-companion.js.map +1 -1
  151. package/components/icure-text-field/suggestion-palette.js.map +1 -1
  152. package/components/model/index.d.ts +69 -137
  153. package/components/model/index.js +30 -103
  154. package/components/model/index.js.map +1 -1
  155. package/components/themes/icure-blue/index.d.ts +1 -0
  156. package/components/themes/icure-blue/index.js +321 -0
  157. package/components/themes/icure-blue/index.js.map +1 -0
  158. package/conversion/ckmeans-grouping.js.map +1 -1
  159. package/conversion/ckmeans.js.map +1 -1
  160. package/conversion/icure-convert.js.map +1 -1
  161. package/generic/model.d.ts +45 -1
  162. package/generic/model.js.map +1 -1
  163. package/icure/form-values-container.d.ts +42 -8
  164. package/icure/form-values-container.js +99 -52
  165. package/icure/form-values-container.js.map +1 -1
  166. package/icure/icure-utils.d.ts +19 -0
  167. package/icure/icure-utils.js +117 -0
  168. package/icure/icure-utils.js.map +1 -0
  169. package/icure/model.d.ts +1 -1
  170. package/icure/model.js.map +1 -1
  171. package/package.json +5 -7
  172. package/utils/code-utils.d.ts +3 -10
  173. package/utils/code-utils.js +3 -9
  174. package/utils/code-utils.js.map +1 -1
  175. package/utils/dates.d.ts +6 -0
  176. package/utils/dates.js +58 -0
  177. package/utils/dates.js.map +1 -0
  178. package/utils/fields-values-provider.d.ts +2 -1
  179. package/utils/fields-values-provider.js +11 -6
  180. package/utils/fields-values-provider.js.map +1 -1
  181. package/utils/form-value-container.js.map +1 -1
  182. package/utils/icure-utils.js.map +1 -1
  183. package/utils/interpreter.js +1 -2
  184. package/utils/interpreter.js.map +1 -1
  185. package/utils/languages.d.ts +1 -5
  186. package/utils/languages.js.map +1 -1
  187. package/utils/markdown.d.ts +2 -1
  188. package/utils/markdown.js +5 -1
  189. package/utils/markdown.js.map +1 -1
  190. package/utils/no-lodash.d.ts +3 -1
  191. package/utils/no-lodash.js +3 -1
  192. package/utils/no-lodash.js.map +1 -1
  193. package/utils/primitive.d.ts +0 -3
  194. package/utils/primitive.js +4 -59
  195. package/utils/primitive.js.map +1 -1
@@ -1,6 +1,13 @@
1
+ import { FieldMetadata } from '../components/model';
2
+ /**
3
+ * VersionedData is a structure that contains the values of a form, organized by id and version.
4
+ */
1
5
  export interface VersionedData<T> {
2
6
  [id: string]: Version<T>[];
3
7
  }
8
+ /**
9
+ * Version is a structure that contains a value, a revision number and a modification timestamp used to sort the versions.
10
+ */
4
11
  export interface Version<T> {
5
12
  revision: string | null;
6
13
  modified?: number;
@@ -9,6 +16,36 @@ export interface Version<T> {
9
16
  export type ID = string;
10
17
  /**
11
18
  * FormValuesContainer is a readonly structure that provides and handle the values of a form.
19
+ * It is a tree structure where each node is a FormValuesContainer with the same Value and Metadata types.
20
+ *
21
+ * The following methods are provided and must be implemented by the concrete class:
22
+ * - `compute(formula: string, sandbox?: S): T?` : computes a formula based on the values of the form, inside a provided sandbox. If no sandbox is provided, the default sandbox is used.
23
+ * - `getLabel(): string` : returns the label of the form values container (used to display the title of the form in hierarchical contexts)
24
+ * - `getFormId(): string?` : returns the id of the form values container
25
+ * - `getValues(revisionsFilter: Lambda): VersionedData<Value>` : obtains the values to be displayed in the form, using a filter
26
+ * to select the desired versioned data that are to be displayed in a specific field.
27
+ * - `getMetadata(id: string, revisions: (string | null)[]): VersionedData<Metadata>` : obtains the metadata of a specific value, for the specified revisions.
28
+ * - `getValidationErrors(): [FieldMetadata, string][]`: returns the validation errors of the form values container for the values that are currently stored in it.
29
+ * - `getChildren(): FormValuesContainer<Value, Metadata>[]` : returns the children of the form values container
30
+ * - `setValue(label: string, language: string, data?: Value, id?: string, metadata?: Metadata): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>` :
31
+ * modifies the value associated to a field in the form values container. As a form values container is immutable, this method returns a mutation wrapping
32
+ * a new form values container along with the modified value.
33
+ * - `setMetadata(label: string, metadata: Metadata, id?: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>` :
34
+ * modifies the metadata associated to a value in the form values container. As a form values container is immutable, this method returns a mutation wrapping
35
+ * a new form values container along with the modified metadata.
36
+ * - `delete(valueId: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>` :
37
+ * deletes a value from the form values container. As a form values container is immutable, this method returns a mutation wrapping
38
+ * a new form values container without the deleted value.
39
+ * - `addChild(anchorId: string, templateId: string, label: string): Promise<FormValuesContainerMutation<...>, FormValuesContainer<...>>>`:
40
+ * adds a child to the form values container. As a form values container is immutable, this method returns a mutation wrapping
41
+ * a new form values container with the added child.
42
+ * - `removeChild(container: FormValuesContainer<Value, Metadata>): Promise<FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>>` :
43
+ * removes a child from the form values container. As a form values container is immutable, this method returns a mutation wrapping
44
+ * a new form values container without the removed child.
45
+ * - `registerChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void` :
46
+ * registers a listener that will be called whenever the form values container is modified.
47
+ * - `unregisterChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void` : unregisters a listener that was previously registered.
48
+ *
12
49
  */
13
50
  export interface FormValuesContainer<Value, Metadata> {
14
51
  compute<T, S extends {
@@ -19,6 +56,7 @@ export interface FormValuesContainer<Value, Metadata> {
19
56
  getValues(revisionsFilter: (id: string, history: Version<Metadata>[]) => (string | null)[]): VersionedData<Value>;
20
57
  getMetadata(id: string, revisions: (string | null)[]): VersionedData<Metadata>;
21
58
  getChildren(): FormValuesContainer<Value, Metadata>[];
59
+ getValidationErrors(): [FieldMetadata, string][];
22
60
  setValue(label: string, language: string, data?: Value, id?: string, metadata?: Metadata): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>;
23
61
  setMetadata(label: string, metadata: Metadata, id?: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>;
24
62
  delete(serviceId: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>;
@@ -27,13 +65,19 @@ export interface FormValuesContainer<Value, Metadata> {
27
65
  registerChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void;
28
66
  unregisterChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void;
29
67
  }
68
+ /**
69
+ * FormValuesContainerMutation is a structure that wraps a new form values container along with the modified value.
70
+ */
30
71
  export interface FormValuesContainerMutation<Value, Metadata, FVC extends FormValuesContainer<Value, Metadata>, Result> {
31
72
  result: Result;
32
73
  formValuesContainer: FVC;
33
74
  }
34
75
  export type Suggestion = {
35
76
  id: string;
36
- code: string;
77
+ code?: string;
37
78
  text: string;
38
79
  terms: string[];
80
+ label: {
81
+ [lng: string]: string;
82
+ };
39
83
  };
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../../tmp/generic/model.ts"],"names":[],"mappings":"","sourcesContent":["export interface VersionedData<T> {\n\t[id: string]: Version<T>[]\n}\n\nexport interface Version<T> {\n\trevision: string | null //null means that the version is not saved yet\n\tmodified?: number\n\tvalue: T\n}\n\nexport type ID = string\n/**\n * FormValuesContainer is a readonly structure that provides and handle the values of a form.\n */\nexport interface FormValuesContainer<Value, Metadata> {\n\t//information retrieval\n\tcompute<T, S extends { [key: string | symbol]: unknown }>(formula: string, sandbox?: S): T | undefined\n\tgetLabel(): string\n\tgetFormId(): string | undefined\n\tgetValues(revisionsFilter: (id: string, history: Version<Metadata>[]) => (string | null)[]): VersionedData<Value>\n\tgetMetadata(id: string, revisions: (string | null)[]): VersionedData<Metadata>\n\tgetChildren(): FormValuesContainer<Value, Metadata>[]\n\t//modification\n\tsetValue(label: string, language: string, data?: Value, id?: string, metadata?: Metadata): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>\n\tsetMetadata(label: string, metadata: Metadata, id?: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>\n\tdelete(serviceId: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>\n\t//hierarchy\n\taddChild(\n\t\tanchorId: string,\n\t\ttemplateId: string,\n\t\tlabel: string,\n\t): Promise<FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, FormValuesContainer<Value, Metadata>>>\n\tremoveChild(container: FormValuesContainer<Value, Metadata>): Promise<FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>>\n\t//listeners\n\tregisterChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void\n\tunregisterChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void\n}\n\nexport interface FormValuesContainerMutation<Value, Metadata, FVC extends FormValuesContainer<Value, Metadata>, Result> {\n\tresult: Result\n\tformValuesContainer: FVC\n}\n\nexport type Suggestion = { id: string; code: string; text: string; terms: string[] }\n"]}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../tmp/generic/model.ts"],"names":[],"mappings":"","sourcesContent":["import { FieldMetadata } from '../components/model'\n\n/**\n * VersionedData is a structure that contains the values of a form, organized by id and version.\n */\nexport interface VersionedData<T> {\n\t[id: string]: Version<T>[]\n}\n\n/**\n * Version is a structure that contains a value, a revision number and a modification timestamp used to sort the versions.\n */\nexport interface Version<T> {\n\trevision: string | null //null means that the version is not saved yet\n\tmodified?: number\n\tvalue: T\n}\n\nexport type ID = string\n/**\n * FormValuesContainer is a readonly structure that provides and handle the values of a form.\n * It is a tree structure where each node is a FormValuesContainer with the same Value and Metadata types.\n *\n * The following methods are provided and must be implemented by the concrete class:\n * - `compute(formula: string, sandbox?: S): T?` : computes a formula based on the values of the form, inside a provided sandbox. If no sandbox is provided, the default sandbox is used.\n * - `getLabel(): string` : returns the label of the form values container (used to display the title of the form in hierarchical contexts)\n * - `getFormId(): string?` : returns the id of the form values container\n * - `getValues(revisionsFilter: Lambda): VersionedData<Value>` : obtains the values to be displayed in the form, using a filter\n * \t\t\tto select the desired versioned data that are to be displayed in a specific field.\n * - `getMetadata(id: string, revisions: (string | null)[]): VersionedData<Metadata>` : obtains the metadata of a specific value, for the specified revisions.\n * - `getValidationErrors(): [FieldMetadata, string][]`: returns the validation errors of the form values container for the values that are currently stored in it.\n * - `getChildren(): FormValuesContainer<Value, Metadata>[]` : returns the children of the form values container\n * - `setValue(label: string, language: string, data?: Value, id?: string, metadata?: Metadata): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>` :\n * \t\t\tmodifies the value associated to a field in the form values container. As a form values container is immutable, this method returns a mutation wrapping\n * \t\t\ta new form values container along with the modified value.\n * - `setMetadata(label: string, metadata: Metadata, id?: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>` :\n * \t\t\tmodifies the metadata associated to a value in the form values container. As a form values container is immutable, this method returns a mutation wrapping\n * \t\t\ta new form values container along with the modified metadata.\n * - `delete(valueId: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>` :\n * \t\t\tdeletes a value from the form values container. As a form values container is immutable, this method returns a mutation wrapping\n * \t\t\ta new form values container without the deleted value.\n * - `addChild(anchorId: string, templateId: string, label: string): Promise<FormValuesContainerMutation<...>, FormValuesContainer<...>>>`:\n * \t\t\tadds a child to the form values container. As a form values container is immutable, this method returns a mutation wrapping\n * \t\t\ta new form values container with the added child.\n * - `removeChild(container: FormValuesContainer<Value, Metadata>): Promise<FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>>` :\n * \t\t\tremoves a child from the form values container. As a form values container is immutable, this method returns a mutation wrapping\n * \t\t\ta new form values container without the removed child.\n * - `registerChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void` :\n * \t\t\tregisters a listener that will be called whenever the form values container is modified.\n * - `unregisterChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void` : unregisters a listener that was previously registered.\n *\n */\nexport interface FormValuesContainer<Value, Metadata> {\n\t//information retrieval\n\tcompute<T, S extends { [key: string | symbol]: unknown }>(formula: string, sandbox?: S): T | undefined\n\tgetLabel(): string\n\tgetFormId(): string | undefined\n\tgetValues(revisionsFilter: (id: string, history: Version<Metadata>[]) => (string | null)[]): VersionedData<Value>\n\tgetMetadata(id: string, revisions: (string | null)[]): VersionedData<Metadata>\n\tgetChildren(): FormValuesContainer<Value, Metadata>[]\n\tgetValidationErrors(): [FieldMetadata, string][]\n\t//modification\n\tsetValue(label: string, language: string, data?: Value, id?: string, metadata?: Metadata): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>\n\tsetMetadata(label: string, metadata: Metadata, id?: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, ID>\n\tdelete(serviceId: string): FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>\n\t//hierarchy\n\taddChild(\n\t\tanchorId: string,\n\t\ttemplateId: string,\n\t\tlabel: string,\n\t): Promise<FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, FormValuesContainer<Value, Metadata>>>\n\tremoveChild(container: FormValuesContainer<Value, Metadata>): Promise<FormValuesContainerMutation<Value, Metadata, FormValuesContainer<Value, Metadata>, void>>\n\t//listeners\n\tregisterChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void\n\tunregisterChangeListener(listener: (newValue: FormValuesContainer<Value, Metadata>) => void): void\n}\n\n/**\n * FormValuesContainerMutation is a structure that wraps a new form values container along with the modified value.\n */\nexport interface FormValuesContainerMutation<Value, Metadata, FVC extends FormValuesContainer<Value, Metadata>, Result> {\n\tresult: Result\n\tformValuesContainer: FVC\n}\n\nexport type Suggestion = { id: string; code?: string; text: string; terms: string[]; label: { [lng: string]: string } }\n"]}
@@ -1,11 +1,31 @@
1
1
  import { Contact, Form as ICureForm, Service } from '@icure/api';
2
2
  import { FormValuesContainer, FormValuesContainerMutation, ID, Version, VersionedData } from '../generic';
3
- import { ServiceMetadata } from '../icure';
4
- import { FieldMetadata, FieldValue } from '../components/model';
3
+ import { ServiceMetadata } from './model';
4
+ import { FieldMetadata, FieldValue, Validator } from '../components/model';
5
+ /** This class is a bridge between the ICure API and the generic FormValuesContainer interface.
6
+ * It wraps around a ContactFormValuesContainer and provides a series of services:
7
+ * - It computes dependent values when the form is created
8
+ * - It broadcasts changes from the wrapped ContactFormValuesContainer to its listeners
9
+ * - It provides a way to compute formulas in a sandboxed environment
10
+ * - It bridges the setValues and setMetadata methods with the wrapped ContactFormValuesContainer by
11
+ * - converting the FieldValue to a Service
12
+ * - converting the FieldMetadata to a ServiceMetadata
13
+ * - It bridges the getValues and getMetadata methods with the wrapped ContactFormValuesContainer by
14
+ * - converting the Service to a FieldValue
15
+ * - converting the ServiceMetadata to a FieldMetadata
16
+ * - It lazily creates bridges the children by
17
+ * - lazily creating BridgedFormValuesContainer when the children of the wrapped ContactFormValuesContainer are accessed
18
+ * - creating a new ContactFormValuesContainer and wrapping it in a BridgedFormValuesContainer when a child is added
19
+ *
20
+ * The icure-form typically accepts a BridgedFormValuesContainer as a prop and uses it to interact with the form.
21
+ *
22
+ * This class is fairly generic and can be used as an inspiration or subclassed for other bridges
23
+ */
5
24
  export declare class BridgedFormValuesContainer implements FormValuesContainer<FieldValue, FieldMetadata> {
6
25
  private responsible;
7
26
  private interpreter?;
8
27
  private dependentValuesProvider;
28
+ private validatorsProvider;
9
29
  private language;
10
30
  private changeListeners;
11
31
  private contact;
@@ -14,13 +34,14 @@ export declare class BridgedFormValuesContainer implements FormValuesContainer<F
14
34
  get children(): BridgedFormValuesContainer[];
15
35
  /**
16
36
  * Creates an instance of BridgedFormValuesContainer.
17
- * @param responsible
37
+ * @param responsible The id of the data owner responsible for the creation of the values
18
38
  * @param contact The displayed contact (may be in the past). === to currentContact if the contact is the contact of the day
19
- * @param contactFormValuesContainer
20
- * @param interpreter
21
- * @param dependentValuesProvider
22
- * @param language
23
- * @param changeListeners
39
+ * @param contactFormValuesContainer The wrapped ContactFormValuesContainer
40
+ * @param interpreter A function that can interpret formulas
41
+ * @param dependentValuesProvider A function that provides the dependent values (computed on the basis of other values) for a given anchorId and templateId
42
+ * @param validatorsProvider A function that provides the validators for a given anchorId and templateId
43
+ * @param language The language in which the values are displayed
44
+ * @param changeListeners The listeners that will be notified when the values change
24
45
  */
25
46
  constructor(responsible: string, contactFormValuesContainer: ContactFormValuesContainer, interpreter?: (<T, S extends {
26
47
  [key: string]: unknown;
@@ -28,6 +49,9 @@ export declare class BridgedFormValuesContainer implements FormValuesContainer<F
28
49
  }>(formula: string, sandbox: S) => T | undefined) | undefined, contact?: Contact, dependentValuesProvider?: (anchorId: string | undefined, templateId: string) => {
29
50
  metadata: FieldMetadata;
30
51
  formula: string;
52
+ }[], validatorsProvider?: (anchorId: string | undefined, templateId: string) => {
53
+ metadata: FieldMetadata;
54
+ validators: Validator[];
31
55
  }[], language?: string, changeListeners?: ((newValue: BridgedFormValuesContainer) => void)[]);
32
56
  getLabel(): string;
33
57
  getFormId(): string | undefined;
@@ -46,9 +70,18 @@ export declare class BridgedFormValuesContainer implements FormValuesContainer<F
46
70
  [key: string | symbol]: unknown;
47
71
  }>(formula: string, sandbox?: S): T | undefined;
48
72
  getChildren(): FormValuesContainer<FieldValue, FieldMetadata>[];
73
+ getValidationErrors(): [FieldMetadata, string][];
49
74
  addChild(anchorId: string, templateId: string, label: string): Promise<FormValuesContainerMutation<FieldValue, FieldMetadata, BridgedFormValuesContainer, BridgedFormValuesContainer>>;
50
75
  removeChild(container: BridgedFormValuesContainer): Promise<FormValuesContainerMutation<FieldValue, FieldMetadata, BridgedFormValuesContainer, void>>;
51
76
  }
77
+ /**
78
+ * This class is a form values container that uses a hierarchy of forms as a data source. The actual values are extracted from the services of the contacts.
79
+ * The `currentContact` is the contact that has been selected by the user, any later contact should be ignored.
80
+ * The `contactsHistory` is used to provide the full history of the services.
81
+ * The hierarchy of ContactFormValuesContainer has to be maintained by the manager of the instances of this class (typically the BridgedFormValuesContainer).
82
+ * Each ContactFormValuesContainer has a reference to its `rootForm`.
83
+ * The `serviceFactory` and `formFactory` are used to create new services and add sub-forms.
84
+ */
52
85
  export declare class ContactFormValuesContainer implements FormValuesContainer<Service, ServiceMetadata> {
53
86
  rootForm: ICureForm;
54
87
  currentContact: Contact;
@@ -65,6 +98,7 @@ export declare class ContactFormValuesContainer implements FormValuesContainer<S
65
98
  registerChangeListener(listener: (newValue: ContactFormValuesContainer) => void): void;
66
99
  unregisterChangeListener(listener: (newValue: ContactFormValuesContainer) => void): void;
67
100
  getChildren(): ContactFormValuesContainer[];
101
+ getValidationErrors(): [FieldMetadata, string][];
68
102
  getValues(revisionsFilter: (id: string, history: Version<ServiceMetadata>[]) => (string | null)[]): VersionedData<Service>;
69
103
  getMetadata(id: string, revisions: (string | null)[]): VersionedData<ServiceMetadata>;
70
104
  setMetadata(label: string, meta: ServiceMetadata, id?: string): FormValuesContainerMutation<Service, ServiceMetadata, ContactFormValuesContainer, ID>;
@@ -12,30 +12,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ContactFormValuesContainer = exports.BridgedFormValuesContainer = void 0;
13
13
  const api_1 = require("@icure/api");
14
14
  const no_lodash_1 = require("../utils/no-lodash");
15
- const icure_utils_1 = require("../utils/icure-utils");
16
- const code_utils_1 = require("../utils/code-utils");
15
+ const icure_utils_1 = require("./icure-utils");
17
16
  const primitive_1 = require("../utils/primitive");
17
+ /** This class is a bridge between the ICure API and the generic FormValuesContainer interface.
18
+ * It wraps around a ContactFormValuesContainer and provides a series of services:
19
+ * - It computes dependent values when the form is created
20
+ * - It broadcasts changes from the wrapped ContactFormValuesContainer to its listeners
21
+ * - It provides a way to compute formulas in a sandboxed environment
22
+ * - It bridges the setValues and setMetadata methods with the wrapped ContactFormValuesContainer by
23
+ * - converting the FieldValue to a Service
24
+ * - converting the FieldMetadata to a ServiceMetadata
25
+ * - It bridges the getValues and getMetadata methods with the wrapped ContactFormValuesContainer by
26
+ * - converting the Service to a FieldValue
27
+ * - converting the ServiceMetadata to a FieldMetadata
28
+ * - It lazily creates bridges the children by
29
+ * - lazily creating BridgedFormValuesContainer when the children of the wrapped ContactFormValuesContainer are accessed
30
+ * - creating a new ContactFormValuesContainer and wrapping it in a BridgedFormValuesContainer when a child is added
31
+ *
32
+ * The icure-form typically accepts a BridgedFormValuesContainer as a prop and uses it to interact with the form.
33
+ *
34
+ * This class is fairly generic and can be used as an inspiration or subclassed for other bridges
35
+ */
18
36
  class BridgedFormValuesContainer {
19
37
  get children() {
20
38
  var _a;
21
39
  return ((_a = this._children) !== null && _a !== void 0 ? _a : (this._children = this.contactFormValuesContainer
22
40
  .getChildren()
23
- .map((fvc) => new BridgedFormValuesContainer(this.responsible, fvc, this.interpreter, this.contact, this.dependentValuesProvider, this.language, this.changeListeners))));
41
+ .map((fvc) => new BridgedFormValuesContainer(this.responsible, fvc, this.interpreter, this.contact, this.dependentValuesProvider, this.validatorsProvider, this.language, this.changeListeners))));
24
42
  }
25
43
  /**
26
44
  * Creates an instance of BridgedFormValuesContainer.
27
- * @param responsible
45
+ * @param responsible The id of the data owner responsible for the creation of the values
28
46
  * @param contact The displayed contact (may be in the past). === to currentContact if the contact is the contact of the day
29
- * @param contactFormValuesContainer
30
- * @param interpreter
31
- * @param dependentValuesProvider
32
- * @param language
33
- * @param changeListeners
47
+ * @param contactFormValuesContainer The wrapped ContactFormValuesContainer
48
+ * @param interpreter A function that can interpret formulas
49
+ * @param dependentValuesProvider A function that provides the dependent values (computed on the basis of other values) for a given anchorId and templateId
50
+ * @param validatorsProvider A function that provides the validators for a given anchorId and templateId
51
+ * @param language The language in which the values are displayed
52
+ * @param changeListeners The listeners that will be notified when the values change
34
53
  */
35
- constructor(responsible, contactFormValuesContainer, interpreter, contact, dependentValuesProvider = () => [], language = 'en', changeListeners = []) {
54
+ constructor(responsible, contactFormValuesContainer, interpreter, contact, dependentValuesProvider = () => [], validatorsProvider = () => [], language = 'en', changeListeners = []) {
36
55
  this.responsible = responsible;
37
56
  this.interpreter = interpreter;
38
57
  this.dependentValuesProvider = dependentValuesProvider;
58
+ this.validatorsProvider = validatorsProvider;
39
59
  this.language = language;
40
60
  this.changeListeners = changeListeners;
41
61
  //Before start to broadcast changes, we need to fill in the contactFormValuesContainer with the dependent values
@@ -59,23 +79,21 @@ class BridgedFormValuesContainer {
59
79
  this.changeListeners = this.changeListeners.filter((l) => l !== listener);
60
80
  }
61
81
  getValues(revisionsFilter) {
62
- return Object.entries(this.contactFormValuesContainer.getValues((id, history) => {
63
- return revisionsFilter(id, history
64
- .filter(({ modified }) => !this.contact.created || !modified || modified <= this.contact.created)
65
- .map(({ revision, modified, value: sm }) => {
66
- var _a;
67
- return ({
68
- revision,
69
- modified,
70
- value: {
71
- label: sm.label,
72
- owner: sm.owner,
73
- tags: (_a = sm.tags) === null || _a === void 0 ? void 0 : _a.map(code_utils_1.codeStubToCode),
74
- valueDate: sm.valueDate,
75
- },
76
- });
77
- }));
78
- })).reduce((acc, [id, history]) => {
82
+ return Object.entries(this.contactFormValuesContainer.getValues((id, history) => revisionsFilter(id, history
83
+ .filter(({ modified }) => !this.contact.created || !modified || modified <= this.contact.created)
84
+ .map(({ revision, modified, value: sm }) => {
85
+ var _a;
86
+ return ({
87
+ revision,
88
+ modified,
89
+ value: {
90
+ label: sm.label,
91
+ owner: sm.responsible,
92
+ tags: (_a = sm.tags) === null || _a === void 0 ? void 0 : _a.map(icure_utils_1.codeStubToCode),
93
+ valueDate: sm.valueDate,
94
+ },
95
+ });
96
+ })))).reduce((acc, [id, history]) => {
79
97
  return Object.assign(Object.assign({}, acc), { [id]: history.map(({ revision, modified, value: s }) => {
80
98
  var _a, _b;
81
99
  return ({
@@ -83,10 +101,10 @@ class BridgedFormValuesContainer {
83
101
  modified,
84
102
  value: {
85
103
  content: Object.entries((_a = s.content) !== null && _a !== void 0 ? _a : {}).reduce((acc, [lng, cnt]) => {
86
- const converted = (0, primitive_1.contentToPrimitiveType)(lng, cnt);
104
+ const converted = (0, icure_utils_1.contentToPrimitiveType)(lng, cnt);
87
105
  return converted ? Object.assign(Object.assign({}, acc), { [lng]: converted }) : acc;
88
106
  }, {}),
89
- codes: (_b = s.codes) === null || _b === void 0 ? void 0 : _b.map(code_utils_1.codeStubToCode),
107
+ codes: (_b = s.codes) === null || _b === void 0 ? void 0 : _b.map(icure_utils_1.codeStubToCode),
90
108
  },
91
109
  });
92
110
  }) });
@@ -98,14 +116,14 @@ class BridgedFormValuesContainer {
98
116
  modified,
99
117
  value: {
100
118
  label: s.label,
101
- owner: s.owner,
119
+ owner: s.responsible,
102
120
  valueDate: s.valueDate,
103
121
  tags: s.tags,
104
122
  },
105
123
  })) })), {});
106
124
  }
107
125
  mutateAndNotify(newContactFormValuesContainer) {
108
- const newBridgedFormValueContainer = new BridgedFormValuesContainer(this.responsible, newContactFormValuesContainer, this.interpreter, this.contact === this.contactFormValuesContainer.currentContact ? newContactFormValuesContainer.currentContact : this.contact, this.dependentValuesProvider, this.language, this.changeListeners);
126
+ const newBridgedFormValueContainer = new BridgedFormValuesContainer(this.responsible, newContactFormValuesContainer, this.interpreter, this.contact === this.contactFormValuesContainer.currentContact ? newContactFormValuesContainer.currentContact : this.contact, this.dependentValuesProvider, this.validatorsProvider, this.language, this.changeListeners);
109
127
  this.changeListeners.forEach((l) => l(newBridgedFormValueContainer));
110
128
  return newBridgedFormValueContainer;
111
129
  }
@@ -145,8 +163,7 @@ class BridgedFormValuesContainer {
145
163
  setMetadata(label, meta, id) {
146
164
  const mutation = this.contactFormValuesContainer.setMetadata(label, {
147
165
  label: meta.label,
148
- responsible: this.responsible,
149
- owner: meta.owner,
166
+ responsible: meta.owner,
150
167
  valueDate: meta.valueDate,
151
168
  tags: meta.tags,
152
169
  }, id);
@@ -180,6 +197,7 @@ class BridgedFormValuesContainer {
180
197
  const primitive = (_b = (_a = content[this.language]) !== null && _a !== void 0 ? _a : content['*']) !== null && _b !== void 0 ? _b : content[Object.keys(content)[0]];
181
198
  return primitive && (0, primitive_1.parsePrimitive)(primitive);
182
199
  },
200
+ log: console.log,
183
201
  };
184
202
  const proxy = new Proxy({}, {
185
203
  has: (target, key) => { var _a; return !!native[key] || key === 'self' || Object.keys((_a = this.getVersionedValuesForKey(key)) !== null && _a !== void 0 ? _a : {}).length > 0; },
@@ -199,6 +217,24 @@ class BridgedFormValuesContainer {
199
217
  getChildren() {
200
218
  return this.contactFormValuesContainer.getChildren().map((fvc) => new BridgedFormValuesContainer(this.responsible, fvc, this.interpreter, this.contact));
201
219
  }
220
+ getValidationErrors() {
221
+ if (this.contactFormValuesContainer.rootForm.formTemplateId) {
222
+ return this.validatorsProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).flatMap(({ metadata, validators }) => validators
223
+ .map(({ validation, message }) => {
224
+ try {
225
+ return this.compute(validation) ? undefined : [metadata, message];
226
+ }
227
+ catch (e) {
228
+ console.log(`Error while computing validation : ${validation}`, e);
229
+ return undefined;
230
+ }
231
+ })
232
+ .filter((x) => !!x));
233
+ }
234
+ else {
235
+ return [];
236
+ }
237
+ }
202
238
  addChild(anchorId, templateId, label) {
203
239
  return __awaiter(this, void 0, void 0, function* () {
204
240
  const mutation = yield this.contactFormValuesContainer.addChild(anchorId, templateId, label);
@@ -218,6 +254,14 @@ class BridgedFormValuesContainer {
218
254
  }
219
255
  }
220
256
  exports.BridgedFormValuesContainer = BridgedFormValuesContainer;
257
+ /**
258
+ * This class is a form values container that uses a hierarchy of forms as a data source. The actual values are extracted from the services of the contacts.
259
+ * The `currentContact` is the contact that has been selected by the user, any later contact should be ignored.
260
+ * The `contactsHistory` is used to provide the full history of the services.
261
+ * The hierarchy of ContactFormValuesContainer has to be maintained by the manager of the instances of this class (typically the BridgedFormValuesContainer).
262
+ * Each ContactFormValuesContainer has a reference to its `rootForm`.
263
+ * The `serviceFactory` and `formFactory` are used to create new services and add sub-forms.
264
+ */
221
265
  class ContactFormValuesContainer {
222
266
  constructor(rootForm, currentContact, contactsHistory, serviceFactory, children, formFactory, changeListeners = []) {
223
267
  if (contactsHistory.includes(currentContact)) {
@@ -237,8 +281,8 @@ class ContactFormValuesContainer {
237
281
  this.changeListeners.forEach((l) => l(newContactFormValuesContainer));
238
282
  });
239
283
  }
240
- static fromFormsHierarchy(rootForm, currentContact, contactsHistory, serviceFactory, formChildrenProvider, formFactory, changeListeners = []) {
241
- return __awaiter(this, void 0, void 0, function* () {
284
+ static fromFormsHierarchy(rootForm_1, currentContact_1, contactsHistory_1, serviceFactory_1, formChildrenProvider_1, formFactory_1) {
285
+ return __awaiter(this, arguments, void 0, function* (rootForm, currentContact, contactsHistory, serviceFactory, formChildrenProvider, formFactory, changeListeners = []) {
242
286
  const contactFormValuesContainer = new ContactFormValuesContainer(rootForm, currentContact, contactsHistory, serviceFactory, rootForm.id
243
287
  ? yield Promise.all((yield formChildrenProvider(rootForm.id)).map((f) => __awaiter(this, void 0, void 0, function* () {
244
288
  // eslint-disable-next-line max-len
@@ -265,6 +309,9 @@ class ContactFormValuesContainer {
265
309
  getChildren() {
266
310
  return this.children;
267
311
  }
312
+ getValidationErrors() {
313
+ throw new Error('Validation not supported at contact level');
314
+ }
268
315
  getValues(revisionsFilter) {
269
316
  return Object.entries(this.getServicesInHistory(revisionsFilter)).reduce((acc, [id, history]) => history.length
270
317
  ? Object.assign(Object.assign({}, acc), { [id]: [...history].sort((a, b) => ((b === null || b === void 0 ? void 0 : b.modified) || +new Date()) - ((a === null || a === void 0 ? void 0 : a.modified) || +new Date())) }) : acc, {});
@@ -285,7 +332,6 @@ class ContactFormValuesContainer {
285
332
  modified: s.modified,
286
333
  value: {
287
334
  label: (_c = s.label) !== null && _c !== void 0 ? _c : s.id,
288
- owner: s.author,
289
335
  responsible: s.responsible,
290
336
  valueDate: s.valueDate,
291
337
  tags: s.tags,
@@ -301,13 +347,11 @@ class ContactFormValuesContainer {
301
347
  throw new Error('Service id must be defined');
302
348
  }
303
349
  if ((meta.responsible && service.responsible !== meta.responsible) ||
304
- (meta.owner && service.author !== meta.owner) ||
305
350
  (meta.valueDate && service.valueDate !== meta.valueDate) ||
306
351
  (meta.codes && service.codes !== meta.codes) ||
307
352
  (meta.tags && service.tags !== meta.tags)) {
308
353
  const newService = new api_1.Service(Object.assign(Object.assign({}, service), { modified: Date.now() }));
309
354
  meta.responsible && (newService.responsible = meta.responsible);
310
- meta.owner && (newService.author = meta.owner);
311
355
  meta.valueDate && (newService.valueDate = meta.valueDate);
312
356
  meta.codes && (newService.codes = meta.codes);
313
357
  meta.tags && (newService.tags = meta.tags);
@@ -318,7 +362,7 @@ class ContactFormValuesContainer {
318
362
  return { result: service.id, formValuesContainer: this };
319
363
  }
320
364
  setValue(label, language, value, id, metadata) {
321
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
365
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
322
366
  const service = (id && this.getServiceInCurrentContact(id)) || this.serviceFactory(label, id);
323
367
  if (!service.id) {
324
368
  throw new Error('Service id must be defined');
@@ -333,7 +377,7 @@ class ContactFormValuesContainer {
333
377
  delete newContents[language];
334
378
  }
335
379
  let newCurrentContact;
336
- if (!Object.entries(newContents).filter(([_, cnt]) => cnt !== undefined).length) {
380
+ if (!Object.entries(newContents).filter(([, cnt]) => cnt !== undefined).length) {
337
381
  newCurrentContact = Object.assign(Object.assign({}, this.currentContact), { services: ((_e = this.currentContact.services) !== null && _e !== void 0 ? _e : []).some((s) => s.id === service.id)
338
382
  ? ((_f = this.currentContact.services) !== null && _f !== void 0 ? _f : []).filter((s) => s.id !== service.id)
339
383
  : [...((_g = this.currentContact.services) !== null && _g !== void 0 ? _g : [])] });
@@ -343,14 +387,13 @@ class ContactFormValuesContainer {
343
387
  newService.codes = newCodes;
344
388
  if (metadata) {
345
389
  newService.responsible = (_h = metadata.responsible) !== null && _h !== void 0 ? _h : newService.responsible;
346
- newService.author = (_j = metadata.owner) !== null && _j !== void 0 ? _j : newService.author;
347
- newService.valueDate = (_k = metadata.valueDate) !== null && _k !== void 0 ? _k : newService.valueDate;
348
- newService.tags = (_l = metadata.tags) !== null && _l !== void 0 ? _l : newService.tags;
349
- newService.label = (_m = metadata.label) !== null && _m !== void 0 ? _m : newService.label;
390
+ newService.valueDate = (_j = metadata.valueDate) !== null && _j !== void 0 ? _j : newService.valueDate;
391
+ newService.tags = (_k = metadata.tags) !== null && _k !== void 0 ? _k : newService.tags;
392
+ newService.label = (_l = metadata.label) !== null && _l !== void 0 ? _l : newService.label;
350
393
  }
351
- newCurrentContact = Object.assign(Object.assign({}, this.currentContact), { services: ((_o = this.currentContact.services) !== null && _o !== void 0 ? _o : []).some((s) => s.id === service.id)
352
- ? ((_p = this.currentContact.services) !== null && _p !== void 0 ? _p : []).map((s) => (s.id === service.id ? newService : s))
353
- : [...((_q = this.currentContact.services) !== null && _q !== void 0 ? _q : []), newService] });
394
+ newCurrentContact = Object.assign(Object.assign({}, this.currentContact), { services: ((_m = this.currentContact.services) !== null && _m !== void 0 ? _m : []).some((s) => s.id === service.id)
395
+ ? ((_o = this.currentContact.services) !== null && _o !== void 0 ? _o : []).map((s) => (s.id === service.id ? newService : s))
396
+ : [...((_p = this.currentContact.services) !== null && _p !== void 0 ? _p : []), newService] });
354
397
  }
355
398
  const newFormValuesContainer = new ContactFormValuesContainer(this.rootForm, newCurrentContact, this.contactsHistory.map((c) => (c === this.currentContact ? newCurrentContact : c)), this.serviceFactory, this.children, this.formFactory, this.changeListeners);
356
399
  this.changeListeners.forEach((l) => l(newFormValuesContainer));
@@ -392,8 +435,7 @@ class ContactFormValuesContainer {
392
435
  modified,
393
436
  value: {
394
437
  label: (_b = (_a = s.label) !== null && _a !== void 0 ? _a : s.id) !== null && _b !== void 0 ? _b : '',
395
- owner: s.author,
396
- responsible: s.responsible,
438
+ owner: s.responsible,
397
439
  valueDate: s.valueDate,
398
440
  codes: s.codes,
399
441
  tags: s.tags,
@@ -429,17 +471,22 @@ class ContactFormValuesContainer {
429
471
  }
430
472
  exports.ContactFormValuesContainer = ContactFormValuesContainer;
431
473
  const setValueOnContactFormValuesContainer = (cfvc, label, language, fv, id, metadata) => {
432
- var _a;
474
+ var _a, _b;
433
475
  const value = fv === null || fv === void 0 ? void 0 : fv.content[language];
434
476
  const mutation = cfvc.setValue(label, language, {
435
477
  id: id,
436
478
  codes: (_a = fv === null || fv === void 0 ? void 0 : fv.codes) !== null && _a !== void 0 ? _a : [],
437
479
  content: value
438
480
  ? {
439
- [language]: (0, primitive_1.primitiveTypeToContent)(language, value),
481
+ [language]: (0, icure_utils_1.primitiveTypeToContent)(language, value),
440
482
  }
441
483
  : undefined,
442
- }, id, metadata);
484
+ }, id, {
485
+ label: (_b = metadata === null || metadata === void 0 ? void 0 : metadata.label) !== null && _b !== void 0 ? _b : '',
486
+ responsible: metadata === null || metadata === void 0 ? void 0 : metadata.owner,
487
+ valueDate: metadata === null || metadata === void 0 ? void 0 : metadata.valueDate,
488
+ tags: metadata === null || metadata === void 0 ? void 0 : metadata.tags,
489
+ });
443
490
  return mutation;
444
491
  };
445
492
  //# sourceMappingURL=form-values-container.js.map