@icure/form 2.1.4 → 2.1.5

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.
Binary file
@@ -155,6 +155,7 @@ export declare class ContactFormValuesContainer implements FormValuesContainer<S
155
155
  private getServicesInHistory;
156
156
  addChild(anchorId: string, templateId: string, label: string): Promise<void>;
157
157
  private getServiceInCurrentContact;
158
+ private static collectFormIds;
158
159
  removeChild(container: ContactFormValuesContainer): Promise<void>;
159
160
  }
160
161
  export {};
@@ -489,12 +489,19 @@ class ContactFormValuesContainer {
489
489
  * Returns a contact that combines the content of the contact in this form with the content of all contents stored in the children
490
490
  */
491
491
  coordinatedContact() {
492
- var _a, _b, _c;
492
+ var _a, _b, _c, _d, _e;
493
493
  const childrenContacts = this.children.map((c) => c.coordinatedContact());
494
- const thisKeptServiceIds = ((_a = this.currentContact.subContacts) !== null && _a !== void 0 ? _a : []).filter((sc) => sc.formId === this.rootForm.id).flatMap((sc) => { var _a; return ((_a = sc.services) !== null && _a !== void 0 ? _a : []).map((s) => s.serviceId); });
495
- return Object.assign(Object.assign({}, this.currentContact), { services: childrenContacts.reduce((acc, c) => { var _a; return acc.concat((_a = c.services) !== null && _a !== void 0 ? _a : []); }, []).concat(((_b = this.currentContact.services) !== null && _b !== void 0 ? _b : []).filter((s) => thisKeptServiceIds.includes(s.id))), subContacts: childrenContacts
494
+ const thisKeptServiceIds = new Set(((_a = this.currentContact.subContacts) !== null && _a !== void 0 ? _a : []).filter((sc) => sc.formId === this.rootForm.id).flatMap((sc) => { var _a; return ((_a = sc.services) !== null && _a !== void 0 ? _a : []).map((s) => s.serviceId); }));
495
+ const thisFormServices = ((_b = this.currentContact.services) !== null && _b !== void 0 ? _b : []).filter((s) => thisKeptServiceIds.has(s.id));
496
+ // Include endOfLife services not linked to any subcontact (from deleted subforms)
497
+ const allSubContactServiceIds = new Set(((_c = this.currentContact.subContacts) !== null && _c !== void 0 ? _c : []).flatMap((sc) => { var _a; return ((_a = sc.services) !== null && _a !== void 0 ? _a : []).map((s) => s.serviceId); }));
498
+ const endOfLifeServices = ((_d = this.currentContact.services) !== null && _d !== void 0 ? _d : []).filter((s) => s.endOfLife && s.id && !allSubContactServiceIds.has(s.id));
499
+ return Object.assign(Object.assign({}, this.currentContact), { services: childrenContacts
500
+ .reduce((acc, c) => { var _a; return acc.concat((_a = c.services) !== null && _a !== void 0 ? _a : []); }, [])
501
+ .concat(thisFormServices)
502
+ .concat(endOfLifeServices), subContacts: childrenContacts
496
503
  .reduce((acc, c) => { var _a; return acc.concat((_a = c.subContacts) !== null && _a !== void 0 ? _a : []); }, [])
497
- .concat(((_c = this.currentContact.subContacts) !== null && _c !== void 0 ? _c : []).filter((s) => s.formId === this.rootForm.id)) });
504
+ .concat(((_e = this.currentContact.subContacts) !== null && _e !== void 0 ? _e : []).filter((s) => s.formId === this.rootForm.id)) });
498
505
  }
499
506
  /**
500
507
  * Returns a contact that combines the content of the contact in this form with the content of all contents stored in the children
@@ -503,7 +510,7 @@ class ContactFormValuesContainer {
503
510
  return [this.rootForm].concat(this.children.flatMap((c) => c.allForms()));
504
511
  }
505
512
  constructor(rootForm, currentContact, contactsHistory, serviceFactory, children, formFactory, formRecycler, changeListeners = [], anchorId, initialised = true) {
506
- var _a;
513
+ var _a, _b;
507
514
  this._id = '';
508
515
  this._initialised = false;
509
516
  this.rootForm = rootForm;
@@ -521,9 +528,16 @@ class ContactFormValuesContainer {
521
528
  this.formRecycler = formRecycler;
522
529
  this.changeListeners = changeListeners;
523
530
  this._initialised = initialised;
531
+ // Collect IDs of services that have been marked with endOfLife in the most recent contact
532
+ const endOfLifeServiceIds = new Set();
533
+ const mostRecentContact = this.currentContact;
534
+ for (const s of (_b = mostRecentContact.services) !== null && _b !== void 0 ? _b : []) {
535
+ if (s.id && s.endOfLife)
536
+ endOfLifeServiceIds.add(s.id);
537
+ }
524
538
  this.indexedServices = [this.currentContact].concat(this.contactsHistory).reduce((acc, ctc) => {
525
539
  var _a, _b, _c;
526
- return ((_c = (_b = (_a = ctc.services) === null || _a === void 0 ? void 0 : _a.filter((s) => { var _a; return (_a = ctc.subContacts) === null || _a === void 0 ? void 0 : _a.some((sc) => { var _a; return sc.formId === this.rootForm.id && ((_a = sc.services) === null || _a === void 0 ? void 0 : _a.some((sss) => sss.serviceId === s.id)); }); })) === null || _b === void 0 ? void 0 : _b.reduce((acc, s) => {
540
+ return ((_c = (_b = (_a = ctc.services) === null || _a === void 0 ? void 0 : _a.filter((s) => { var _a; return !endOfLifeServiceIds.has(s.id) && ((_a = ctc.subContacts) === null || _a === void 0 ? void 0 : _a.some((sc) => { var _a; return sc.formId === this.rootForm.id && ((_a = sc.services) === null || _a === void 0 ? void 0 : _a.some((sss) => sss.serviceId === s.id)); })); })) === null || _b === void 0 ? void 0 : _b.reduce((acc, s) => {
527
541
  var _a, _b;
528
542
  return s.id
529
543
  ? Object.assign(Object.assign({}, acc), { [s.id]: ((_a = acc[s.id]) !== null && _a !== void 0 ? _a : (acc[s.id] = [])).concat({
@@ -785,9 +799,77 @@ class ContactFormValuesContainer {
785
799
  const service = (_a = (this.currentContact.services || [])) === null || _a === void 0 ? void 0 : _a.find((s) => s.id === id);
786
800
  return service !== null && service !== void 0 ? service : undefined;
787
801
  }
802
+ static collectFormIds(container) {
803
+ const ids = new Set();
804
+ if (container.rootForm.id)
805
+ ids.add(container.rootForm.id);
806
+ for (const child of container.children) {
807
+ for (const id of ContactFormValuesContainer.collectFormIds(child)) {
808
+ ids.add(id);
809
+ }
810
+ }
811
+ return ids;
812
+ }
788
813
  removeChild(container) {
789
814
  return __awaiter(this, void 0, void 0, function* () {
790
- const newContactFormValuesContainer = new ContactFormValuesContainer(this.rootForm, this.currentContact, this.contactsHistory, this.serviceFactory, this.children.filter((c) => c.rootForm.id !== container.rootForm.id), this.formFactory, this.formRecycler, this.changeListeners, this.anchorId, true);
815
+ var _a, _b, _c, _d, _e, _f, _g, _h;
816
+ // Collect all form IDs in the subtree being removed (child + its descendants)
817
+ const removedFormIds = ContactFormValuesContainer.collectFormIds(container);
818
+ // Collect service IDs linked to any removed form across current contact and history
819
+ const allContacts = [this.currentContact, ...this.contactsHistory];
820
+ const childServiceIds = new Set();
821
+ for (const ctc of allContacts) {
822
+ for (const sc of (_a = ctc.subContacts) !== null && _a !== void 0 ? _a : []) {
823
+ if (sc.formId && removedFormIds.has(sc.formId)) {
824
+ for (const sRef of (_b = sc.services) !== null && _b !== void 0 ? _b : []) {
825
+ if (sRef.serviceId)
826
+ childServiceIds.add(sRef.serviceId);
827
+ }
828
+ }
829
+ }
830
+ }
831
+ // Build the updated current contact:
832
+ // - Services that exist in history must be marked with endOfLife (not removed)
833
+ // - Services that only exist in the current contact can be simply removed
834
+ // - Remove subContact entries for all removed forms
835
+ const now = Date.now();
836
+ // Determine which child services exist in history
837
+ const childServiceIdsInHistory = new Set();
838
+ for (const ctc of this.contactsHistory) {
839
+ for (const sc of (_c = ctc.subContacts) !== null && _c !== void 0 ? _c : []) {
840
+ if (sc.formId && removedFormIds.has(sc.formId)) {
841
+ for (const sRef of (_d = sc.services) !== null && _d !== void 0 ? _d : []) {
842
+ if (sRef.serviceId && childServiceIds.has(sRef.serviceId))
843
+ childServiceIdsInHistory.add(sRef.serviceId);
844
+ }
845
+ }
846
+ }
847
+ }
848
+ const existingServiceIds = new Set(((_e = this.currentContact.services) !== null && _e !== void 0 ? _e : []).map((s) => s.id));
849
+ // Services in current contact: mark with endOfLife if in history, remove otherwise
850
+ const updatedServices = ((_f = this.currentContact.services) !== null && _f !== void 0 ? _f : [])
851
+ .filter((s) => !(s.id && childServiceIds.has(s.id) && !childServiceIdsInHistory.has(s.id)))
852
+ .map((s) => (s.id && childServiceIdsInHistory.has(s.id) ? new api_1.Service({ id: s.id, created: s.created, modified: now, endOfLife: now }) : s));
853
+ // Services only in history (not in current contact): add with endOfLife
854
+ for (const serviceId of childServiceIdsInHistory) {
855
+ if (!existingServiceIds.has(serviceId)) {
856
+ for (const ctc of this.contactsHistory) {
857
+ const historyService = (_g = ctc.services) === null || _g === void 0 ? void 0 : _g.find((s) => s.id === serviceId);
858
+ if (historyService) {
859
+ updatedServices.push(new api_1.Service({ id: historyService.id, created: historyService.created, modified: now, endOfLife: now }));
860
+ break;
861
+ }
862
+ }
863
+ }
864
+ }
865
+ // Remove subContact entries for all removed forms
866
+ const updatedSubContacts = ((_h = this.currentContact.subContacts) !== null && _h !== void 0 ? _h : []).filter((sc) => !sc.formId || !removedFormIds.has(sc.formId));
867
+ const updatedContact = Object.assign(Object.assign({}, this.currentContact), { services: updatedServices, subContacts: updatedSubContacts });
868
+ // Recycle all removed forms
869
+ for (const formId of removedFormIds) {
870
+ yield this.formRecycler(formId);
871
+ }
872
+ const newContactFormValuesContainer = new ContactFormValuesContainer(this.rootForm, updatedContact, this.contactsHistory, this.serviceFactory, this.children.filter((c) => c.rootForm.id !== container.rootForm.id), this.formFactory, this.formRecycler, this.changeListeners, this.anchorId, true);
791
873
  this.changeListeners.forEach((l) => { var _a; return notify(l, newContactFormValuesContainer, [`subForms_${(_a = container.anchorId) !== null && _a !== void 0 ? _a : 'all'}`]); });
792
874
  });
793
875
  }
@@ -1 +1 @@
1
- {"version":3,"file":"form-values-container.js","sourceRoot":"","sources":["../../tmp/icure/form-values-container.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAgF;AAChF,kDAA6C;AAI7C,+CAA6H;AAC7H,kDAAmD;AACnD,0CAA+D;AAC/D,oDAAoD;AASpD,IAAI,QAAQ,GAAG,CAAC,CAAA;AAEhB,SAAS,MAAM,CACd,CAAoG,EACpG,GAAyC,EACzC,WAA4B,EAC5B,KAAK,GAAG,KAAK;IAEb,CAAC,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,CAAC,CAAA;AAC3B,CAAC;AAED,SAAS,qBAAqB,CAAC,EAAiB;IAC/C,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,QAAQ;YACZ,OAAO,EAAE,CAAC,KAAK,CAAA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D,MAAM,KAAK,GAAG,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IACnC,IAAI,CAAC,QAAQ,CACZ,KAAK,EACL,QAAQ,EACR;QACC,EAAE,EAAE,EAAE;QACN,KAAK,EAAE,MAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,KAAK,mCAAI,EAAE;QACtB,OAAO,EAAE,KAAK;YACb,CAAC,CAAC;gBACA,CAAC,QAAQ,CAAC,EAAE,IAAA,oCAAsB,EAAC,QAAQ,EAAE,KAAK,CAAC;aAClD;YACH,CAAC,CAAC,SAAS;KACZ,EACD,EAAE,EACF,QAAQ;QACP,CAAC,CAAC;YACA,KAAK,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK,mCAAI,KAAK;YAC/B,WAAW,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK;YAC5B,SAAS,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,SAAS;YAC9B,IAAI,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI;SACnB;QACH,CAAC,CAAC,SAAS,EACZ,wBAAwB,CACxB,CAAA;AACF,CAAC,CAAA","sourcesContent":["import { Contact, Form, Form as ICureForm, Service, CodeStub } from '@icure/api'\nimport { sortedBy } from '../utils/no-lodash'\nimport { ComputationResult, FormValuesContainer, Version, VersionedData } from '../generic'\nimport { ServiceMetadata } from './model'\nimport { FieldMetadata, FieldValue, PrimitiveType, Validator } from '../components/model'\nimport { areCodesEqual, codeStubToCode, contentToPrimitiveType, isContentEqual, primitiveTypeToContent } from './icure-utils'\nimport { parsePrimitive } from '../utils/primitive'\nimport { anyDateToDate, dateToFuzzyDate } from '../utils/dates'\nimport { normalizeCodes } from '../utils/code-utils'\n\ninterface ComputedValueChange {\n\tserviceId: string | undefined\n\tmetadata: FieldMetadata\n\tlanguage: string\n\tvalue: FieldValue | undefined\n}\n\nlet _ordinal = 0\n\nfunction notify<Value, Metadata>(\n\tl: (fvc: FormValuesContainer<Value, Metadata>, changedKeys: string[] | null, force: boolean) => void,\n\tfvc: FormValuesContainer<Value, Metadata>,\n\tchangedKeys: string[] | null,\n\tforce = false,\n) {\n\tl(fvc, changedKeys, force)\n}\n\nfunction primitiveTypeToString(pt: PrimitiveType): string {\n\tswitch (pt.type) {\n\t\tcase 'string':\n\t\t\treturn pt.value\n\t\tcase 'number':\n\t\t\treturn pt.value.toString()\n\t\tcase 'boolean':\n\t\t\treturn pt.value.toString()\n\t\tcase 'measure':\n\t\t\treturn pt.value !== undefined ? `${pt.value}${pt.unit ? ' ' + pt.unit : ''}` : ''\n\t\tcase 'timestamp':\n\t\t\treturn new Date(pt.value).toISOString()\n\t\tcase 'datetime':\n\t\t\treturn pt.value.toString()\n\t\tcase 'compound':\n\t\t\treturn Object.entries(pt.value)\n\t\t\t\t.map(([k, v]) => `${k}: ${primitiveTypeToString(v)}`)\n\t\t\t\t.join(', ')\n\t}\n}\n\n/** This class is a bridge between the ICure API and the generic FormValuesContainer interface.\n * It wraps around a ContactFormValuesContainer and provides a series of services:\n * - It computes dependent values when the form is created\n * - It broadcasts changes from the wrapped ContactFormValuesContainer to its listeners\n * - It provides a way to compute formulas in a sandboxed environment\n * - It bridges the setValues and setMetadata methods with the wrapped ContactFormValuesContainer by\n * \t\t- converting the FieldValue to a Service\n * \t\t- converting the FieldMetadata to a ServiceMetadata\n * - It bridges the getValues and getMetadata methods with the wrapped ContactFormValuesContainer by\n * \t\t- converting the Service to a FieldValue\n * \t\t- converting the ServiceMetadata to a FieldMetadata\n * - It lazily creates bridges the children by\n * - lazily creating BridgedFormValuesContainer when the children of the wrapped ContactFormValuesContainer are accessed\n * - creating a new ContactFormValuesContainer and wrapping it in a BridgedFormValuesContainer when a child is added\n *\n * The icure-form typically accepts a BridgedFormValuesContainer as a prop and uses it to interact with the form.\n *\n * This class is fairly generic and can be used as an inspiration or subclassed for other bridges\n */\nexport class BridgedFormValuesContainer implements FormValuesContainer<FieldValue, FieldMetadata> {\n\tprivate contact: Contact\n\tprivate contactFormValuesContainer: ContactFormValuesContainer\n\tprivate _id = ''\n\tprivate readonly mutateAndNotify: (newContactFormValuesContainer: ContactFormValuesContainer, changedKeys: string[] | null) => void\n\tprivate dependentValuesComputationIteration?: Promise<ComputedValueChange[]> = undefined\n\n\ttoString(): string {\n\t\treturn `Bridged(${this.contactFormValuesContainer.rootForm.formTemplateId}[${this.contactFormValuesContainer.rootForm.id}]) - ${this._id}`\n\t}\n\n\t/**\n\t * Creates an instance of BridgedFormValuesContainer.\n\t * @param responsible The id of the data owner responsible for the creation of the values\n\t * @param contactFormValuesContainer The wrapped ContactFormValuesContainer\n\t * @param interpreter A function that can interpret formulas\n\t * @param contact The displayed contact (may be in the past). === to currentContact if the contact is the contact of the day\n\t * @param initialValuesProvider A lambda that provides the initial values of the form\n\t * @param dependentValuesProvider A function that provides the dependent values (computed on the basis of other values) for a given anchorId and templateId\n\t * @param validatorsProvider A function that provides the validators for a given anchorId and templateId\n\t * @param language The language in which the values are displayed\n\t * @param changeListeners The listeners that will be notified when the values change\n\t * @param interpreterContext A map with keys that are the names of the variables and values that are the functions that return the values of the variables\n\t * @param dependenciesCache\n\t */\n\tconstructor(\n\t\tprivate responsible: string,\n\t\tcontactFormValuesContainer: ContactFormValuesContainer,\n\t\tprivate interpreter?: <\n\t\t\tT,\n\t\t\tS extends {\n\t\t\t\t[key: string | symbol]: unknown\n\t\t\t},\n\t\t>(\n\t\t\tformula: string,\n\t\t\tsandbox: S,\n\t\t) => Promise<T | undefined>,\n\t\tcontact?: Contact,\n\t\tprivate initialValuesProvider: (\n\t\t\tanchorId?: string,\n\t\t\ttemplateId?: string,\n\t\t) => {\n\t\t\tmetadata: FieldMetadata\n\t\t\trevisionsFilter: (id: string, history: Version<FieldMetadata>[]) => (string | null)[]\n\t\t\tformula: string\n\t\t}[] = () => [],\n\t\tprivate dependentValuesProvider: (\n\t\t\tanchorId: string | undefined,\n\t\t\ttemplateId: string | undefined,\n\t\t) => {\n\t\t\tmetadata: FieldMetadata\n\t\t\trevisionsFilter: (id: string, history: Version<FieldMetadata>[]) => (string | null)[]\n\t\t\tformula: string\n\t\t}[] = () => [],\n\t\tprivate validatorsProvider: (\n\t\t\tanchorId: string | undefined,\n\t\t\ttemplateId: string,\n\t\t) => {\n\t\t\tmetadata: FieldMetadata\n\t\t\tvalidators: Validator[]\n\t\t}[] = () => [],\n\t\tprivate language = 'en',\n\t\tprivate changeListeners: ((newValue: BridgedFormValuesContainer, changedKeys: string[] | null, force: boolean) => void)[] = [],\n\t\tprivate interpreterContext: { [variable: string]: () => unknown } = {},\n\t\tprivate dependenciesCache: { [formula: string]: string[] } = {},\n\t) {\n\t\t//Before start to broadcast changes, we need to fill in the contactFormValuesContainer with the dependent values\n\t\tthis.contactFormValuesContainer = contactFormValuesContainer\n\t\tthis._id = `[${contactFormValuesContainer._id}]`\n\t\tconsole.log(`+ BFVC ${this._id} created`)\n\t\tthis.mutateAndNotify = (newContactFormValuesContainer: ContactFormValuesContainer, changedKeys: string[] | null, force = false) => {\n\t\t\tif (this.changeListeners.length === 0) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (!force && this.contactFormValuesContainer === newContactFormValuesContainer) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.contactFormValuesContainer.unregisterChangeListener(this.mutateAndNotify)\n\t\t\tnewContactFormValuesContainer.unregisterChangeListener(this.mutateAndNotify)\n\n\t\t\tconst newBridgedFormValueContainer = new BridgedFormValuesContainer(\n\t\t\t\tthis.responsible,\n\t\t\t\tnewContactFormValuesContainer,\n\t\t\t\tthis.interpreter,\n\t\t\t\tthis.contact === this.contactFormValuesContainer.currentContact ? newContactFormValuesContainer.currentContact : this.contact,\n\t\t\t\tthis.initialValuesProvider,\n\t\t\t\tthis.dependentValuesProvider,\n\t\t\t\tthis.validatorsProvider,\n\t\t\t\tthis.language,\n\t\t\t\tthis.changeListeners,\n\t\t\t\tthis.interpreterContext,\n\t\t\t\tthis.dependenciesCache,\n\t\t\t)\n\n\t\t\tconsole.log(`- init started ${newBridgedFormValueContainer._id} with changed keys: ${changedKeys ? changedKeys.join(', ') : 'all'}`)\n\t\t\tconst initPromise = newBridgedFormValueContainer.init(changedKeys, this.dependentValuesComputationIteration)\n\t\t\tthis.changeListeners.forEach((l) => notify(l, newBridgedFormValueContainer, changedKeys))\n\n\t\t\tinitPromise\n\t\t\t\t.catch((e) => {\n\t\t\t\t\tconsole.log('Error while initializing new BridgedFormValuesContainer', e)\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tconsole.log(`- init finished ${newBridgedFormValueContainer._id}`)\n\t\t\t\t})\n\t\t}\n\t\tthis.contactFormValuesContainer.registerChangeListener(this.mutateAndNotify)\n\t\tthis.contact = contact ?? contactFormValuesContainer.currentContact\n\t}\n\n\t/* init can be called several times on the same instance but the initialisation will only be done once */\n\tasync init(changedKeys: string[] | null = null, pendingComputationIteration?: Promise<ComputedValueChange[]>): Promise<BridgedFormValuesContainer> {\n\t\tlet changedKeysByInit: string[] = []\n\t\tif (pendingComputationIteration) {\n\t\t\tconst changes = await pendingComputationIteration\n\n\t\t\tif (changes.length > 0) {\n\t\t\t\tthis.quietlyApplyChangesOnContactFormValueContainer(changes)\n\t\t\t\tchangedKeysByInit = await this.computeDependentValues([...(changedKeys ?? []), ...changes.map(({ metadata }) => metadata.label)], this.contactFormValuesContainer.mustBeInitialised())\n\t\t\t} else {\n\t\t\t\tchangedKeysByInit = await this.computeDependentValues(changedKeys, this.contactFormValuesContainer.mustBeInitialised())\n\t\t\t}\n\t\t} else {\n\t\t\tconsole.log('Start compute')\n\t\t\tchangedKeysByInit = await this.computeDependentValues(changedKeys, this.contactFormValuesContainer.mustBeInitialised())\n\t\t\tconsole.log('Finish compute')\n\t\t}\n\n\t\t//After all the silent updates, we need a last one that causes a new BridgedFormValuesContainer to be created and broadcasted to the listeners, so that they get the final values with all the dependencies computed\n\t\tconsole.log('Launch refresh')\n\t\tthis.contactFormValuesContainer.changeListeners.forEach((l) => notify(l, this.contactFormValuesContainer, changedKeysByInit, changedKeysByInit.length > 0))\n\n\t\treturn this\n\t}\n\n\tgetLabel(): string {\n\t\treturn this.contactFormValuesContainer.getLabel()\n\t}\n\n\tgetFormId(): string | undefined {\n\t\treturn this.contactFormValuesContainer.getFormId()\n\t}\n\n\tgetContactFormValuesContainer() {\n\t\treturn this.contactFormValuesContainer\n\t}\n\n\tregisterChangeListener(listener: (newValue: BridgedFormValuesContainer, changedKeys: string[] | null, force: boolean) => void): void {\n\t\tthis.changeListeners.push(listener)\n\t}\n\n\tunregisterChangeListener(listener: (newValue: BridgedFormValuesContainer, changedKeys: string[] | null, force: boolean) => void): void {\n\t\tthis.changeListeners = this.changeListeners.filter((l) => l !== listener)\n\t}\n\n\tgetDefaultValueProvider(label: string): (() => Promise<FieldValue | undefined>) | undefined {\n\t\tconst formula = this.initialValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).find(\n\t\t\t({ metadata }) => metadata.label === label,\n\t\t)?.formula\n\t\treturn formula ? async () => this.convertRawValue(await this.compute(formula)) : undefined\n\t}\n\n\tgetValues(revisionsFilter: (id: string, history: Version<FieldMetadata>[]) => (string | null)[]): VersionedData<FieldValue> {\n\t\treturn Object.entries(\n\t\t\tthis.contactFormValuesContainer.getValues((id, history) =>\n\t\t\t\trevisionsFilter(\n\t\t\t\t\tid,\n\t\t\t\t\thistory\n\t\t\t\t\t\t.filter(({ modified }) => !this.contact.created || !modified || modified <= this.contact.created)\n\t\t\t\t\t\t.map(({ revision, modified, value: sm }) => ({\n\t\t\t\t\t\t\trevision,\n\t\t\t\t\t\t\tmodified,\n\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\tlabel: sm.label,\n\t\t\t\t\t\t\t\towner: sm.responsible,\n\t\t\t\t\t\t\t\ttags: sm.tags?.map(codeStubToCode),\n\t\t\t\t\t\t\t\tvalueDate: sm.valueDate,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t),\n\t\t).reduce((acc, [id, history]) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t[id]: history.map(({ revision, modified, value: s }) => ({\n\t\t\t\t\trevision,\n\t\t\t\t\tmodified,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontent: Object.entries(s.content ?? {}).reduce((acc, [lng, cnt]) => {\n\t\t\t\t\t\t\tconst converted = contentToPrimitiveType(lng, cnt)\n\t\t\t\t\t\t\treturn converted ? { ...acc, [lng]: converted } : acc\n\t\t\t\t\t\t}, {}),\n\t\t\t\t\t\tcodes: s.codes?.map(codeStubToCode),\n\t\t\t\t\t},\n\t\t\t\t})),\n\t\t\t}\n\t\t}, {} as VersionedData<FieldValue>)\n\t}\n\n\tgetMetadata(id: string, revisions: (string | null)[]): VersionedData<FieldMetadata> {\n\t\treturn Object.entries(this.contactFormValuesContainer.getMetadata(id, revisions)).reduce(\n\t\t\t(acc, [id, history]) => ({\n\t\t\t\t...acc,\n\t\t\t\t[id]: history.map(({ revision, modified, value: s }) => ({\n\t\t\t\t\trevision,\n\t\t\t\t\tmodified,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tlabel: s.label,\n\t\t\t\t\t\towner: s.responsible,\n\t\t\t\t\t\tvalueDate: s.valueDate,\n\t\t\t\t\t\ttags: s.tags,\n\t\t\t\t\t\tdiscordantMetadata: () => ({\n\t\t\t\t\t\t\t...(s.responsible !== this.responsible ? { owner: this.responsible } : {}),\n\t\t\t\t\t\t\t...(Math.abs(+(anyDateToDate(s.valueDate) ?? 0) - +(anyDateToDate(this.contact.created) ?? 0)) > 24 * 3600000 ? { valueDate: s.valueDate } : {}),\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t})),\n\t\t\t}),\n\t\t\t{},\n\t\t)\n\t}\n\n\tprivate convertRawValue(rawValue: unknown): FieldValue | undefined {\n\t\tif (rawValue && typeof rawValue === 'object' && 'content' in rawValue) {\n\t\t\treturn rawValue as FieldValue\n\t\t}\n\n\t\tif (Array.isArray(rawValue)) {\n\t\t\treturn rawValue.reduce(\n\t\t\t\t(acc: FieldValue, it, idx) => {\n\t\t\t\t\tconst fv = this.convertRawValue(it)\n\t\t\t\t\tif (fv === undefined) {\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t}\n\t\t\t\t\tacc.codes = [...(fv.codes ?? []), ...(acc.codes ?? [])]\n\t\t\t\t\tacc.content['*'] = fv.content['*']?.value\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t...acc.content['*'],\n\t\t\t\t\t\t\t\t[(fv.codes ?? [])[0].id ?? idx.toString()]: fv.content['*'].value,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: acc.content['*']\n\t\t\t\t\treturn acc\n\t\t\t\t},\n\t\t\t\t{ content: { '*': { type: 'compound', value: {} } } },\n\t\t\t)\n\t\t}\n\n\t\tif (typeof rawValue === 'number') {\n\t\t\treturn { content: { '*': { type: 'number', value: rawValue } } }\n\t\t}\n\n\t\tif (typeof rawValue === 'string') {\n\t\t\treturn { content: { '*': { type: 'string', value: rawValue } } }\n\t\t}\n\n\t\tif (typeof rawValue === 'boolean') {\n\t\t\treturn { content: { '*': { type: 'boolean', value: rawValue } } }\n\t\t}\n\n\t\tif (rawValue instanceof Date) {\n\t\t\treturn { content: { '*': { type: 'timestamp', value: dateToFuzzyDate(rawValue) } } }\n\t\t}\n\n\t\tif (rawValue && typeof rawValue === 'object' && 'unit' in rawValue && 'value' in rawValue && typeof rawValue.value === 'number') {\n\t\t\treturn { content: { '*': { type: 'measure', value: rawValue.value, unit: rawValue.unit?.toString() ?? '' } } }\n\t\t}\n\n\t\treturn undefined\n\t}\n\n\t//This method mutates the BridgedFormValuesContainer but can only be called from the constructor\n\tprivate async computeDependentValues(changedKeys: string[] | null, computeInitialValues: boolean): Promise<string[]> {\n\t\tconst initialValues = (computeInitialValues ? this.initialValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId) : []).filter(\n\t\t\t({ revisionsFilter }) => {\n\t\t\t\tconst currentValue = this.getValues(revisionsFilter)\n\t\t\t\treturn !currentValue || !Object.keys(currentValue).length\n\t\t\t},\n\t\t)\n\n\t\tconst dependentValues = this.dependentValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId)\n\n\t\tconst iterate = async (changedKeys: string[] | null, iterationCount: number): Promise<ComputedValueChange[]> => {\n\t\t\tif (this.contactFormValuesContainer.rootForm.formTemplateId) {\n\t\t\t\tconsole.log(`% ${iterationCount}, keys: ${changedKeys ? changedKeys.join(', ') : 'all'}`)\n\n\t\t\t\treturn await Promise.all(\n\t\t\t\t\tdependentValues.concat(initialValues).map(async ({ metadata, revisionsFilter, formula }) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (!changedKeys || !this.dependenciesCache[formula] || this.dependenciesCache[formula].some((d) => changedKeys.includes(d))) {\n\t\t\t\t\t\t\t\tconst currentValue = this.getValues(revisionsFilter)\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst computationResult = await this.compute(formula)\n\t\t\t\t\t\t\t\t\tthis.dependenciesCache[formula] = [...(this.dependenciesCache[formula] ?? []), ...computationResult.dependencies].filter((d, idx, array) => array.indexOf(d) === idx)\n\t\t\t\t\t\t\t\t\tconst newValue = computationResult.value ? this.convertRawValue(computationResult.value) : undefined\n\n\t\t\t\t\t\t\t\t\tif (newValue !== undefined || (currentValue != undefined && Object.keys(currentValue).length > 0 && currentValue[Object.keys(currentValue)[0]][0].value)) {\n\t\t\t\t\t\t\t\t\t\tconst lng = this.language ?? 'en'\n\t\t\t\t\t\t\t\t\t\tif (newValue && !newValue.content[lng] && newValue.content['*']) {\n\t\t\t\t\t\t\t\t\t\t\tnewValue.content[lng] = newValue.content['*']\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (newValue) {\n\t\t\t\t\t\t\t\t\t\t\tdelete newValue.content['*']\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn { serviceId: Object.keys(currentValue ?? {})[0], metadata, language: lng, value: newValue } as ComputedValueChange\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\t\tconsole.log(`Error while computing formula : ${formula}`, e)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\tconsole.log(`Error while computing formula : ${formula}`, e)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}),\n\t\t\t\t).then((results) => {\n\t\t\t\t\treturn results.filter((r) => !!r)\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\treturn []\n\t\t\t}\n\t\t}\n\n\t\tlet latestKeys = changedKeys\n\t\tconst iterationCount = 0\n\t\tconst allChangedKeys: string[] = []\n\t\twhile (true) {\n\t\t\tif (latestKeys != null && latestKeys.length === 0) {\n\t\t\t\tthis.dependentValuesComputationIteration = undefined\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tconst changesPromise = iterate(latestKeys, iterationCount)\n\t\t\tthis.dependentValuesComputationIteration = changesPromise\n\t\t\tconst changesResult = await changesPromise\n\t\t\tlatestKeys = this.quietlyApplyChangesOnContactFormValueContainer(changesResult)\n\t\t\tallChangedKeys.push(...latestKeys)\n\t\t}\n\n\t\treturn allChangedKeys\n\t}\n\n\tprivate quietlyApplyChangesOnContactFormValueContainer(changes: ComputedValueChange[]): string[] {\n\t\tconst allChangedKeys: string[] = []\n\t\tconst interceptor = (fvc: ContactFormValuesContainer, changedKeys: string[] | null) => {\n\t\t\tconst currentContact = this.contactFormValuesContainer.currentContact\n\t\t\tthis.contactFormValuesContainer = fvc\n\t\t\tif (this.contact === currentContact) {\n\t\t\t\tthis.contact = fvc.currentContact\n\t\t\t}\n\t\t\tallChangedKeys.push(...(changedKeys ?? []))\n\t\t}\n\n\t\tchanges.forEach(({ serviceId, metadata, language, value }) => {\n\t\t\ttry {\n\t\t\t\tsetValueOnContactFormValuesContainer(this.contactFormValuesContainer, metadata.label, language, value ?? undefined, serviceId, metadata, interceptor)\n\t\t\t} catch (e) {\n\t\t\t\tconsole.log(`Error while applying dependent value change for ${metadata.label} (${serviceId})`, e)\n\t\t\t}\n\t\t})\n\n\t\treturn allChangedKeys\n\t}\n\n\tsetValue(label: string, language: string, fv?: FieldValue, id?: string, metadata?: FieldMetadata): void {\n\t\tsetValueOnContactFormValuesContainer(this.contactFormValuesContainer, label, language, fv, id, metadata)\n\t}\n\n\tsetMetadata(meta: FieldMetadata, id?: string | undefined): void {\n\t\tthis.contactFormValuesContainer.setMetadata(\n\t\t\t{\n\t\t\t\tlabel: meta.label,\n\t\t\t\tresponsible: meta.owner,\n\t\t\t\tvalueDate: meta.valueDate,\n\t\t\t\ttags: meta.tags,\n\t\t\t},\n\t\t\tid,\n\t\t)\n\t}\n\n\tdelete(serviceId: string): void {\n\t\tthis.contactFormValuesContainer.delete(serviceId)\n\t}\n\n\tprivate getVersionedValuesForKey(key: string | symbol) {\n\t\treturn this.getValues((id, history) => (history?.[0]?.value?.label && key === history[0].value.label ? [history?.[0]?.revision] : []))\n\t}\n\n\tasync compute<T>(formula: string): Promise<ComputationResult<T>> {\n\t\tconst dependencies = new Set<string>()\n\t\t// noinspection JSUnusedGlobalSymbols\n\t\tconst parseContent = (content?: { [key: string]: PrimitiveType }, toString = false) => {\n\t\t\tif (!content) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tconst primitive = content[this.language] ?? content['*'] ?? content[Object.keys(content)[0]]\n\t\t\treturn primitive && parsePrimitive(primitive, toString)\n\t\t}\n\t\tconst text = (item?: { content: { [key: string]: PrimitiveType } } | { content: { [key: string]: PrimitiveType } }[]) => {\n\t\t\tif (!item) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tconst items: { content: { [key: string]: PrimitiveType } }[] = Array.isArray(item) ? item : [item]\n\t\t\treturn items\n\t\t\t\t.map((it) => parseContent(it.content, true)?.toString())\n\t\t\t\t.filter((it) => !!it)\n\t\t\t\t.join(', ')\n\t\t}\n\t\tconst log = console.log\n\t\t// noinspection JSUnusedGlobalSymbols\n\t\tconst native = {\n\t\t\tparseInt: parseInt,\n\t\t\tparseFloat: parseFloat,\n\t\t\tDate: Date,\n\t\t\tMath: Math,\n\t\t\tNumber: Number,\n\t\t\tString: String,\n\t\t\tBoolean: Boolean,\n\t\t\tArray: Array,\n\t\t\tObject: Object,\n\t\t\thasOption: (\n\t\t\t\tit: {\n\t\t\t\t\tcodes: CodeStub[]\n\t\t\t\t},\n\t\t\t\toption: string,\n\t\t\t) => it && it.codes?.some((c) => c.id === option || c.id?.split('|')?.[1] === option),\n\t\t\tscore: (it: { codes: CodeStub[] }) => {\n\t\t\t\treturn it\n\t\t\t\t\t? (it.codes ?? []).reduce((acc, c) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\treturn acc + parseInt(c.id?.split('|')?.[1] ?? '0')\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\treturn acc\n\t\t\t\t\t\t\t}\n\t\t\t\t\t }, 0)\n\t\t\t\t\t: 0\n\t\t\t},\n\t\t\tparseContent,\n\t\t\tvalidate: {\n\t\t\t\tnotBlank: (self: any, label: string) => {\n\t\t\t\t\tconst value = parseContent((self[label as any] as any)?.[0]?.content)\n\t\t\t\t\treturn !!(value as any)?.trim()?.length\n\t\t\t\t},\n\t\t\t},\n\t\t\ttext,\n\t\t\tlog,\n\t\t\tPromise,\n\t\t} as { [key: string]: any }\n\t\tconst proxy: { [key: string]: string | symbol } = new Proxy({} as { [key: string]: string | symbol }, {\n\t\t\thas: (target: { [key: string]: string | symbol }, key: string | symbol) =>\n\t\t\t\t!!native[key as string] || key === 'self' || !!this.interpreterContext[key as string] || Object.keys(this.getVersionedValuesForKey(key) ?? {}).length > 0,\n\t\t\tget: (target: { [key: string]: string | symbol }, key: string | symbol) => {\n\t\t\t\tif (key === 'undefined') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst nativeValue = native[key as string]\n\t\t\t\tif (!!nativeValue) {\n\t\t\t\t\treturn nativeValue\n\t\t\t\t}\n\t\t\t\tif (key === 'self') {\n\t\t\t\t\treturn proxy\n\t\t\t\t} else {\n\t\t\t\t\tdependencies.add(key.toString())\n\t\t\t\t\treturn this.interpreterContext[key as string] ? this.interpreterContext[key as string]() : Object.values(this.getVersionedValuesForKey(key)).map((v) => v[0]?.value)\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t\treturn { value: await this.interpreter?.(formula, proxy), dependencies: Array.from(dependencies) }\n\t}\n\n\tasync getChildren(): Promise<FormValuesContainer<FieldValue, FieldMetadata>[]> {\n\t\treturn await Promise.all(\n\t\t\t(\n\t\t\t\tawait this.contactFormValuesContainer.getChildren()\n\t\t\t).map((fvc) =>\n\t\t\t\tnew BridgedFormValuesContainer(\n\t\t\t\t\tthis.responsible,\n\t\t\t\t\tfvc,\n\t\t\t\t\tthis.interpreter,\n\t\t\t\t\tthis.contact,\n\t\t\t\t\tthis.initialValuesProvider,\n\t\t\t\t\tthis.dependentValuesProvider,\n\t\t\t\t\tthis.validatorsProvider,\n\t\t\t\t\tthis.language,\n\t\t\t\t\t[],\n\t\t\t\t\tthis.interpreterContext,\n\t\t\t\t).init(),\n\t\t\t),\n\t\t)\n\t}\n\n\tgetValidationErrors(): Promise<[FieldMetadata, string] | null>[] {\n\t\tif (this.contactFormValuesContainer.rootForm.formTemplateId) {\n\t\t\treturn this.validatorsProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).flatMap(({ metadata, validators }) =>\n\t\t\t\tvalidators.map(async ({ validation, message }): Promise<[FieldMetadata, string] | null> => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (!(await this.compute(validation))) {\n\t\t\t\t\t\t\treturn [metadata, message]\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tconsole.log(`Error while computing validation : ${validation}`, e)\n\t\t\t\t\t}\n\t\t\t\t\treturn null\n\t\t\t\t}),\n\t\t\t)\n\t\t} else {\n\t\t\treturn []\n\t\t}\n\t}\n\n\tasync addChild(anchorId: string, templateId: string, label: string): Promise<void> {\n\t\tawait this.contactFormValuesContainer.addChild(anchorId, templateId, label)\n\t}\n\n\tasync removeChild(container: BridgedFormValuesContainer): Promise<void> {\n\t\tawait this.contactFormValuesContainer.removeChild(container.contactFormValuesContainer)\n\t}\n\n\tsynchronise() {\n\t\tthis.contactFormValuesContainer.synchronise()\n\t\treturn this\n\t}\n}\n\n/**\n * 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.\n * The `currentContact` is the contact that has been selected by the user, any later contact should be ignored.\n * The `contactsHistory` is used to provide the full history of the services.\n * The hierarchy of ContactFormValuesContainer has to be maintained by the manager of the instances of this class (typically the BridgedFormValuesContainer).\n * Each ContactFormValuesContainer has a reference to its `rootForm`.\n * The `serviceFactory` and `formFactory` are used to create new services and add sub-forms.\n */\nexport class ContactFormValuesContainer implements FormValuesContainer<Service, ServiceMetadata> {\n\trootForm: ICureForm\n\tcurrentContact: Contact //The contact of the moment, used to record new modifications\n\tcontactsHistory: Contact[] //Must be sorted (most recent first), contains all the contacts linked to this form\n\tchildren: ContactFormValuesContainer[] //Direct children of the ContactFormValuesContainer\n\tanchorId?: string //The anchorId in the parent form\n\tserviceFactory: (label: string, serviceId?: string) => Service\n\tformFactory: (parentId: string, anchorId: string, formTemplateId: string, label: string) => Promise<ICureForm>\n\tformRecycler: (formId: string) => Promise<void>\n\n\tchangeListeners: ((newValue: ContactFormValuesContainer, changedKeys: string[] | null, force: boolean) => void)[]\n\n\t_id = ''\n\tprivate _initialised = false\n\tprivate indexedServices: { [id: string]: Version<Service>[] }\n\n\ttoString(): string {\n\t\treturn `Contact(${this.rootForm.formTemplateId}[${this.rootForm.id}]) - ${this._id}`\n\t}\n\n\tmustBeInitialised() {\n\t\treturn !this._initialised\n\t}\n\n\t/**\n\t * Returns a contact that combines the content of the contact in this form with the content of all contents stored in the children\n\t */\n\tcoordinatedContact(): Contact {\n\t\tconst childrenContacts = this.children.map((c) => c.coordinatedContact())\n\t\tconst thisKeptServiceIds = (this.currentContact.subContacts ?? []).filter((sc) => sc.formId === this.rootForm.id).flatMap((sc) => (sc.services ?? []).map((s) => s.serviceId))\n\t\treturn {\n\t\t\t...this.currentContact,\n\t\t\tservices: childrenContacts.reduce((acc: Service[], c: Contact) => acc.concat(c.services ?? []), []).concat((this.currentContact.services ?? []).filter((s) => thisKeptServiceIds.includes(s.id))),\n\t\t\tsubContacts: childrenContacts\n\t\t\t\t.reduce((acc: Service[], c: Contact) => acc.concat(c.subContacts ?? []), [])\n\t\t\t\t.concat((this.currentContact.subContacts ?? []).filter((s) => s.formId === this.rootForm.id)),\n\t\t}\n\t}\n\n\t/**\n\t * Returns a contact that combines the content of the contact in this form with the content of all contents stored in the children\n\t */\n\tallForms(): Form[] {\n\t\treturn [this.rootForm].concat(this.children.flatMap((c) => c.allForms()))\n\t}\n\n\tconstructor(\n\t\trootForm: ICureForm,\n\t\tcurrentContact: Contact,\n\t\tcontactsHistory: Contact[],\n\t\tserviceFactory: (label: string, serviceId?: string) => Service,\n\t\tchildren: ContactFormValuesContainer[],\n\t\tformFactory: (parentId: string, anchorId: string, formTemplateId: string, label: string) => Promise<ICureForm>,\n\t\tformRecycler: (formId: string) => Promise<void>,\n\t\tchangeListeners: ((newValue: ContactFormValuesContainer, changedKeys: string[] | null, force: boolean) => void)[] = [],\n\t\tanchorId?: string,\n\t\tinitialised = true,\n\t) {\n\t\tthis.rootForm = rootForm\n\t\tthis._id = `${(rootForm.formTemplateId ?? '').substring(0, 4)}.${++_ordinal}`\n\t\tconsole.log(`+ CFVC: ${this._id} with children { ${children.map((c) => c._id).join(', ')} }`)\n\n\t\tif (contactsHistory.includes(currentContact)) {\n\t\t\tthrow new Error('Illegal argument, the history must not contain the currentContact')\n\t\t}\n\t\tthis.currentContact = currentContact\n\t\tthis.contactsHistory = sortedBy(contactsHistory, 'created', 'desc')\n\t\tthis.children = children\n\t\tthis.anchorId = anchorId\n\t\tthis.serviceFactory = serviceFactory\n\t\tthis.formFactory = formFactory\n\t\tthis.formRecycler = formRecycler\n\t\tthis.changeListeners = changeListeners\n\t\tthis._initialised = initialised\n\n\t\tthis.indexedServices = [this.currentContact].concat(this.contactsHistory).reduce((acc, ctc) => {\n\t\t\treturn (\n\t\t\t\tctc.services\n\t\t\t\t\t?.filter((s) => ctc.subContacts?.some((sc) => sc.formId === this.rootForm.id && sc.services?.some((sss) => sss.serviceId === s.id)))\n\t\t\t\t\t?.reduce(\n\t\t\t\t\t\t(acc, s) =>\n\t\t\t\t\t\t\ts.id\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t\t[s.id]: (acc[s.id] ?? (acc[s.id] = [])).concat({\n\t\t\t\t\t\t\t\t\t\t\trevision: ctc.rev ?? null,\n\t\t\t\t\t\t\t\t\t\t\tmodified: ctc.created,\n\t\t\t\t\t\t\t\t\t\t\tvalue: s,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t: acc,\n\t\t\t\t\t\tacc,\n\t\t\t\t\t) ?? acc\n\t\t\t)\n\t\t}, {} as VersionedData<Service>)\n\n\t\tthis.synchronise()\n\t}\n\n\tsynchronise() {\n\t\tthis.children.forEach((childFVC) => {\n\t\t\tthis.registerChildFormValuesContainer(childFVC.synchronise(), childFVC.anchorId ?? '')\n\t\t})\n\t\treturn this\n\t}\n\n\t//Make sure that when a child is changed, a new version of this is created with the updated child\n\tregisterChildFormValuesContainer(childFormValueContainer: ContactFormValuesContainer, anchorId: string) {\n\t\tchildFormValueContainer.changeListeners = [\n\t\t\t(newValue, changedKeys, force) => {\n\t\t\t\tif (changedKeys?.length === 0 && !force) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconsole.log(`Child ${newValue._id} ${childFormValueContainer.rootForm.formTemplateId} changed, updating parent ${this._id} ${this.rootForm.formTemplateId}`)\n\t\t\t\tconst newContactFormValuesContainer = new ContactFormValuesContainer(\n\t\t\t\t\tthis.rootForm,\n\t\t\t\t\tthis.currentContact,\n\t\t\t\t\tthis.contactsHistory,\n\t\t\t\t\tthis.serviceFactory,\n\t\t\t\t\tthis.children.map((c) => {\n\t\t\t\t\t\treturn c.rootForm.id === childFormValueContainer.rootForm.id ? newValue : c\n\t\t\t\t\t}),\n\t\t\t\t\tthis.formFactory,\n\t\t\t\t\tthis.formRecycler,\n\t\t\t\t\t[],\n\t\t\t\t\tthis.anchorId,\n\t\t\t\t\ttrue,\n\t\t\t\t)\n\t\t\t\tthis.changeListeners.forEach((l) => notify(l, newContactFormValuesContainer, null))\n\t\t\t},\n\t\t]\n\t}\n\n\tstatic async fromFormsHierarchy(\n\t\trootForm: ICureForm,\n\t\tcurrentContact: Contact,\n\t\tcontactsHistory: Contact[],\n\t\tserviceFactory: (label: string, serviceId?: string) => Service,\n\t\tformChildrenProvider: (parentId: string | undefined) => Promise<ICureForm[]>,\n\t\tformFactory: (parentId: string, anchorId: string, formTemplateId: string, label: string) => Promise<ICureForm>,\n\t\tformRecycler: (formId: string) => Promise<void>,\n\t\tchangeListeners: ((newValue: ContactFormValuesContainer) => void)[] = [],\n\t): Promise<ContactFormValuesContainer> {\n\t\tconst contactFormValuesContainer = new ContactFormValuesContainer(\n\t\t\trootForm,\n\t\t\tcurrentContact,\n\t\t\tcontactsHistory,\n\t\t\tserviceFactory,\n\t\t\trootForm.id\n\t\t\t\t? await Promise.all(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tawait formChildrenProvider(rootForm.id)\n\t\t\t\t\t\t).map(\n\t\t\t\t\t\t\tasync (f) =>\n\t\t\t\t\t\t\t\t// eslint-disable-next-line max-len\n\t\t\t\t\t\t\t\tawait ContactFormValuesContainer.fromFormsHierarchy(f, currentContact, contactsHistory, serviceFactory, formChildrenProvider, formFactory, formRecycler),\n\t\t\t\t\t\t),\n\t\t\t\t )\n\t\t\t\t: [],\n\t\t\tformFactory,\n\t\t\tformRecycler,\n\t\t\tchangeListeners,\n\t\t\trootForm.descr,\n\t\t\tfalse,\n\t\t)\n\t\tcontactFormValuesContainer.children.forEach((childFVC) => contactFormValuesContainer.registerChildFormValuesContainer(childFVC, childFVC.anchorId ?? 'all'))\n\n\t\treturn contactFormValuesContainer\n\t}\n\n\tgetLabel(): string {\n\t\treturn this.rootForm.descr ?? ''\n\t}\n\n\tgetFormId(): string | undefined {\n\t\treturn this.rootForm?.formTemplateId\n\t}\n\n\tregisterChangeListener(listener: (newValue: ContactFormValuesContainer, changedKeys: string[] | null, force: boolean) => void): void {\n\t\tthis.changeListeners.push(listener)\n\t}\n\n\tunregisterChangeListener(listener: (newValue: ContactFormValuesContainer, changedKeys: string[] | null, force: boolean) => void): void {\n\t\tthis.changeListeners = this.changeListeners.filter((l) => l !== listener)\n\t}\n\n\tasync getChildren(): Promise<ContactFormValuesContainer[]> {\n\t\treturn this.children\n\t}\n\n\tgetValidationErrors(): Promise<[FieldMetadata, string] | null>[] {\n\t\tthrow new Error('Validation not supported at contact level')\n\t}\n\n\tgetDefaultValueProvider(): (() => Promise<FieldValue | undefined>) | undefined {\n\t\treturn undefined\n\t}\n\n\tgetValues(revisionsFilter: (id: string, history: Version<ServiceMetadata>[]) => (string | null)[]): VersionedData<Service> {\n\t\treturn Object.entries(this.getServicesInHistory(revisionsFilter)).reduce(\n\t\t\t(acc, [id, history]) =>\n\t\t\t\thistory.length\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t[id]: [...history].sort((a, b) => (b?.modified || +new Date()) - (a?.modified || +new Date())),\n\t\t\t\t\t }\n\t\t\t\t\t: acc,\n\t\t\t{},\n\t\t)\n\t}\n\n\tgetMetadata(id: string, revisions: (string | null)[]): VersionedData<ServiceMetadata> {\n\t\treturn [this.currentContact]\n\t\t\t.concat(this.contactsHistory)\n\t\t\t.filter((ctc) => ctc.rev !== undefined && revisions.includes(ctc.rev))\n\t\t\t.reduce(\n\t\t\t\t(acc, ctc) =>\n\t\t\t\t\t(ctc.services ?? [])\n\t\t\t\t\t\t.filter((s) => s.id === id)\n\t\t\t\t\t\t.reduce(\n\t\t\t\t\t\t\t(acc, s) =>\n\t\t\t\t\t\t\t\ts.id\n\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t\t\t[s.id]: (acc[s.id] ?? (acc[s.id] = [])).concat({\n\t\t\t\t\t\t\t\t\t\t\t\trevision: ctc.rev ?? null,\n\t\t\t\t\t\t\t\t\t\t\t\tmodified: s.modified,\n\t\t\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlabel: s.label ?? s.id,\n\t\t\t\t\t\t\t\t\t\t\t\t\tresponsible: s.responsible,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalueDate: s.valueDate,\n\t\t\t\t\t\t\t\t\t\t\t\t\ttags: s.tags,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t\t: acc,\n\t\t\t\t\t\t\tacc,\n\t\t\t\t\t\t) ?? acc,\n\t\t\t\t{} as { [id: string]: Version<ServiceMetadata>[] },\n\t\t\t) //index services in history by id\n\t}\n\n\tsetMetadata(meta: ServiceMetadata, id?: string): void {\n\t\tconst service = (id && this.getServiceInCurrentContact(id)) || this.serviceFactory(meta.label, id)\n\t\tif (!service.id) {\n\t\t\tthrow new Error('Service id must be defined')\n\t\t}\n\t\tif (\n\t\t\t(meta.responsible && service.responsible !== meta.responsible) ||\n\t\t\t(meta.valueDate && service.valueDate !== meta.valueDate) ||\n\t\t\t(meta.codes && service.codes !== meta.codes) ||\n\t\t\t(meta.tags && service.tags !== meta.tags)\n\t\t) {\n\t\t\tconst newService = new Service({ ...service, modified: Date.now() })\n\t\t\tmeta.responsible && (newService.responsible = meta.responsible)\n\t\t\tmeta.valueDate && (newService.valueDate = meta.valueDate)\n\t\t\tmeta.codes && (newService.codes = normalizeCodes(meta.codes))\n\t\t\tmeta.tags && (newService.tags = normalizeCodes(meta.tags))\n\n\t\t\tconst newFormValuesContainer = new ContactFormValuesContainer(\n\t\t\t\tthis.rootForm,\n\t\t\t\t{\n\t\t\t\t\t...this.currentContact,\n\t\t\t\t\tservices: this.currentContact.services?.map((s) => (s.id === service.id ? newService : s)),\n\t\t\t\t},\n\t\t\t\tthis.contactsHistory,\n\t\t\t\tthis.serviceFactory,\n\t\t\t\tthis.children,\n\t\t\t\tthis.formFactory,\n\t\t\t\tthis.formRecycler,\n\t\t\t\tthis.changeListeners,\n\t\t\t\tthis.anchorId,\n\t\t\t\ttrue,\n\t\t\t)\n\n\t\t\tthis.changeListeners.forEach((l) => notify(l, newFormValuesContainer, [meta.label]))\n\t\t}\n\t}\n\n\tsetValue(\n\t\tlabel: string,\n\t\tlanguage: string,\n\t\tvalue?: Service,\n\t\tid?: string,\n\t\tmetadata?: ServiceMetadata,\n\t\tchangeListenersOverrider?: (fvc: ContactFormValuesContainer, changedKeys: string[] | null) => void,\n\t): void {\n\t\tconst service = (id && this.getServicesInHistory((sid: string, history) => (sid === id ? history.map((x) => x.revision) : []))[id]?.[0]?.value) || this.serviceFactory(label, id)\n\t\tif (!service.id) {\n\t\t\tthrow new Error('Service id must be defined')\n\t\t}\n\t\tconsole.log(\n\t\t\t`Setting value of service ${service.label} [${service.id}] to ${Object.entries(value?.content ?? {}).map(([k, c]) => `${k}: ${JSON.stringify(contentToPrimitiveType(k, c))}`)} and md`,\n\t\t\tmetadata,\n\t\t)\n\t\tconst newContent = value?.content?.[language]\n\n\t\tconst newCodes = value?.codes ? normalizeCodes(value.codes) : []\n\t\tif (!isContentEqual(service.content?.[language], newContent) || (newCodes && !areCodesEqual(newCodes, service.codes ?? []))) {\n\t\t\tconst newService = new Service({ ...service, modified: Date.now() })\n\t\t\tconst newContents = newContent\n\t\t\t\t? {\n\t\t\t\t\t\t...(service.content || {}),\n\t\t\t\t\t\t[language]: newContent,\n\t\t\t\t }\n\t\t\t\t: { ...(service.content || {}) }\n\t\t\tif (!newContent) {\n\t\t\t\tdelete newContents[language]\n\t\t\t}\n\n\t\t\tlet newCurrentContact: Contact\n\t\t\tif (!Object.entries(newContents).filter(([, cnt]) => cnt !== undefined).length) {\n\t\t\t\tnewCurrentContact = {\n\t\t\t\t\t...this.currentContact,\n\t\t\t\t\tsubContacts: (this.currentContact.subContacts ?? []).some((sc) => sc.formId === this.rootForm.id)\n\t\t\t\t\t\t? (this.currentContact.subContacts ?? []).map((sc) => {\n\t\t\t\t\t\t\t\tif (sc.formId === this.rootForm.id) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...sc,\n\t\t\t\t\t\t\t\t\t\tservices: (sc.services ?? []).filter((s) => s.serviceId !== service.id).concat([{ serviceId: service.id }]),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn sc\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t })\n\t\t\t\t\t\t: (this.currentContact.subContacts ?? []).concat({ formId: this.rootForm.id, services: [{ serviceId: service.id }] }),\n\t\t\t\t\tservices: (this.currentContact.services ?? []).some((s) => s.id === service.id)\n\t\t\t\t\t\t? (this.currentContact.services ?? []).filter((s) => s.id !== service.id)\n\t\t\t\t\t\t: [...(this.currentContact.services ?? [])],\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnewService.content = newContents\n\t\t\t\tnewService.codes = newCodes\n\n\t\t\t\tif (metadata) {\n\t\t\t\t\tnewService.responsible = metadata.responsible ?? newService.responsible\n\t\t\t\t\tnewService.valueDate = metadata.valueDate ?? newService.valueDate\n\t\t\t\t\tnewService.tags = metadata.tags ? normalizeCodes(metadata.tags) : newService.tags\n\t\t\t\t\tnewService.label = metadata.label ?? newService.label\n\t\t\t\t}\n\n\t\t\t\tnewCurrentContact = {\n\t\t\t\t\t...this.currentContact,\n\t\t\t\t\tsubContacts: (this.currentContact.subContacts ?? []).some((sc) => sc.formId === this.rootForm.id)\n\t\t\t\t\t\t? (this.currentContact.subContacts ?? []).map((sc) => {\n\t\t\t\t\t\t\t\tif (sc.formId === this.rootForm.id) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...sc,\n\t\t\t\t\t\t\t\t\t\tservices: (sc.services ?? []).filter((s) => s.serviceId !== service.id).concat([{ serviceId: service.id }]),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn sc\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t })\n\t\t\t\t\t\t: (this.currentContact.subContacts ?? []).concat({ formId: this.rootForm.id, services: [{ serviceId: service.id }] }),\n\t\t\t\t\tservices: (this.currentContact.services ?? []).some((s) => s.id === service.id)\n\t\t\t\t\t\t? (this.currentContact.services ?? []).map((s) => (s.id === service.id ? newService : s))\n\t\t\t\t\t\t: [...(this.currentContact.services ?? []), newService],\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst newFormValuesContainer = new ContactFormValuesContainer(\n\t\t\t\tthis.rootForm,\n\t\t\t\tnewCurrentContact,\n\t\t\t\tthis.contactsHistory.map((c) => (c === this.currentContact ? newCurrentContact : c)),\n\t\t\t\tthis.serviceFactory,\n\t\t\t\tthis.children,\n\t\t\t\tthis.formFactory,\n\t\t\t\tthis.formRecycler,\n\t\t\t\tthis.changeListeners,\n\t\t\t\tthis.anchorId,\n\t\t\t\ttrue,\n\t\t\t)\n\n\t\t\tchangeListenersOverrider ? changeListenersOverrider(newFormValuesContainer, [label]) : this.changeListeners.forEach((l) => notify(l, newFormValuesContainer, [label]))\n\t\t}\n\t}\n\n\tdelete(serviceId: string): void {\n\t\tconst service = this.getServiceInCurrentContact(serviceId)\n\t\tif (service) {\n\t\t\tconst newFormValuesContainer = new ContactFormValuesContainer(\n\t\t\t\tthis.rootForm,\n\t\t\t\t{\n\t\t\t\t\t...this.currentContact,\n\t\t\t\t\tservices: this.currentContact.services?.map((s) =>\n\t\t\t\t\t\ts.id === serviceId\n\t\t\t\t\t\t\t? new Service({\n\t\t\t\t\t\t\t\t\t...service,\n\t\t\t\t\t\t\t\t\tendOfLife: Date.now(),\n\t\t\t\t\t\t\t })\n\t\t\t\t\t\t\t: s,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\tthis.contactsHistory,\n\t\t\t\tthis.serviceFactory,\n\t\t\t\tthis.children,\n\t\t\t\tthis.formFactory,\n\t\t\t\tthis.formRecycler,\n\t\t\t\tthis.changeListeners,\n\t\t\t\tthis.anchorId,\n\t\t\t\ttrue,\n\t\t\t)\n\n\t\t\tthis.changeListeners.forEach((l) => notify(l, newFormValuesContainer, [service.label ?? service.id ?? ''] /* only the label is going to propagate the changes for the formulas */))\n\t\t}\n\t}\n\n\ttoMarkdownTable(): string {\n\t\tconst tableRows: [string, string, string][] = []\n\t\tfor (const [, versions] of Object.entries(this.indexedServices)) {\n\t\t\tif (!versions.length) continue\n\t\t\tconst service = versions[0].value\n\t\t\tconst label = service.label ?? service.id ?? ''\n\t\t\tconst modifiedStr = service.modified ? new Date(service.modified).toISOString() : ''\n\t\t\tconst contentParts: string[] = []\n\t\t\tfor (const [lng, cnt] of Object.entries(service.content ?? {})) {\n\t\t\t\tconst primitive = contentToPrimitiveType(lng, cnt)\n\t\t\t\tif (primitive) {\n\t\t\t\t\tcontentParts.push(primitiveTypeToString(primitive))\n\t\t\t\t}\n\t\t\t}\n\t\t\ttableRows.push([label, modifiedStr, contentParts.join(', ')])\n\t\t}\n\t\tconst headers: [string, string, string] = ['Label', 'Modified', 'Content']\n\t\tconst colWidths = headers.map((h, i) => Math.max(h.length, ...tableRows.map((r) => r[i].length)))\n\t\tconst pad = (s: string, w: number) => s + ' '.repeat(w - s.length)\n\t\tconst formatRow = (cells: [string, string, string]) => '| ' + cells.map((c, i) => pad(c, colWidths[i])).join(' | ') + ' |'\n\t\tconst separator = '|' + colWidths.map((w) => '-'.repeat(w + 2)).join('|') + '|'\n\t\treturn [formatRow(headers), separator, ...tableRows.map(formatRow)].join('\\n')\n\t}\n\n\tasync compute<T>(): Promise<ComputationResult<T>> {\n\t\tthrow new Error('Compute not supported at contact level')\n\t}\n\n\t/** returns all services in history that match a selector\n\t *\n\t * @private\n\t * @param revisionsFilter\n\t */\n\tprivate getServicesInHistory(revisionsFilter: (id: string, history: Version<ServiceMetadata>[]) => (string | null)[]): VersionedData<Service> {\n\t\t//index services in history by id\n\t\treturn Object.entries(this.indexedServices)\n\t\t\t.map(([id, history]) => {\n\t\t\t\tconst keptRevisions = revisionsFilter(\n\t\t\t\t\tid,\n\t\t\t\t\thistory.map(({ revision, modified, value: s }) => ({\n\t\t\t\t\t\trevision,\n\t\t\t\t\t\tmodified,\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\tlabel: s.label ?? s.id ?? '',\n\t\t\t\t\t\t\towner: s.responsible,\n\t\t\t\t\t\t\tvalueDate: s.valueDate,\n\t\t\t\t\t\t\tcodes: s.codes,\n\t\t\t\t\t\t\ttags: s.tags,\n\t\t\t\t\t\t},\n\t\t\t\t\t})),\n\t\t\t\t)\n\t\t\t\treturn [id, history.filter(({ revision }) => keptRevisions.includes(revision))] as [string, Version<Service>[]]\n\t\t\t})\n\t\t\t.reduce((acc, [id, history]) => ({ ...acc, [id]: history }), {})\n\t}\n\n\tasync addChild(anchorId: string, templateId: string, label: string): Promise<void> {\n\t\tconst parentId = this.rootForm.id\n\t\tif (!parentId) return\n\n\t\tconst newForm = await this.formFactory(parentId, anchorId, templateId, label)\n\t\tconst childFVC = new ContactFormValuesContainer(newForm, this.currentContact, this.contactsHistory, this.serviceFactory, [], this.formFactory, this.formRecycler, [], anchorId, false)\n\n\t\tconst newContactFormValuesContainer = new ContactFormValuesContainer(\n\t\t\tthis.rootForm,\n\t\t\tthis.currentContact,\n\t\t\tthis.contactsHistory,\n\t\t\tthis.serviceFactory,\n\t\t\t[...this.children, childFVC],\n\t\t\tthis.formFactory,\n\t\t\tthis.formRecycler,\n\t\t\tthis.changeListeners,\n\t\t\tthis.anchorId,\n\t\t\ttrue,\n\t\t)\n\t\tnewContactFormValuesContainer.registerChildFormValuesContainer(childFVC, anchorId)\n\t\tthis.changeListeners.forEach((l) => {\n\t\t\tnotify(l, newContactFormValuesContainer, null)\n\t\t})\n\t}\n\n\tprivate getServiceInCurrentContact(id: string): Service | undefined {\n\t\tconst service = (this.currentContact.services || [])?.find((s) => s.id === id)\n\t\treturn service ?? undefined\n\t}\n\n\tasync removeChild(container: ContactFormValuesContainer): Promise<void> {\n\t\tconst newContactFormValuesContainer = new ContactFormValuesContainer(\n\t\t\tthis.rootForm,\n\t\t\tthis.currentContact,\n\t\t\tthis.contactsHistory,\n\t\t\tthis.serviceFactory,\n\t\t\tthis.children.filter((c) => c.rootForm.id !== container.rootForm.id),\n\t\t\tthis.formFactory,\n\t\t\tthis.formRecycler,\n\t\t\tthis.changeListeners,\n\t\t\tthis.anchorId,\n\t\t\ttrue,\n\t\t)\n\t\tthis.changeListeners.forEach((l) => notify(l, newContactFormValuesContainer, [`subForms_${container.anchorId ?? 'all'}`]))\n\t}\n}\n\n// Runtime validation for FieldValue — guards against mistyped data coming from\n// external callers (formulas, SDK bridges, etc.) where the TypeScript types may\n// not match the actual runtime values.\nconst validatePrimitiveType = (pt: PrimitiveType, path: string): void => {\n\tconst v: any = pt.value\n\tswitch (pt.type) {\n\t\tcase 'string':\n\t\t\tif (typeof v !== 'string') {\n\t\t\t\tthrow new Error(`${path}: expected string value, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'number':\n\t\t\tif (typeof v !== 'number') {\n\t\t\t\tthrow new Error(`${path}: expected number value, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'boolean':\n\t\t\tif (typeof v !== 'boolean') {\n\t\t\t\tthrow new Error(`${path}: expected boolean value, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'timestamp':\n\t\t\tif (typeof v !== 'number') {\n\t\t\t\tthrow new Error(`${path}: expected number value for timestamp, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'datetime':\n\t\t\tif (typeof v !== 'number') {\n\t\t\t\tthrow new Error(`${path}: expected number value for datetime, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'measure': {\n\t\t\tconst m: any = pt\n\t\t\tif (m.value !== undefined && typeof m.value !== 'number') {\n\t\t\t\tthrow new Error(`${path}: expected number or undefined value for measure, got ${typeof m.value}`)\n\t\t\t}\n\t\t\tif (m.unit !== undefined && typeof m.unit !== 'string') {\n\t\t\t\tthrow new Error(`${path}: expected string or undefined unit for measure, got ${typeof m.unit}`)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'compound':\n\t\t\tif (typeof v !== 'object' || v === null || Array.isArray(v)) {\n\t\t\t\tthrow new Error(`${path}: expected object value for compound, got ${Array.isArray(v) ? 'array' : typeof v}`)\n\t\t\t}\n\t\t\tfor (const [key, subValue] of Object.entries(v as { [label: string]: PrimitiveType })) {\n\t\t\t\tvalidatePrimitiveType(subValue, `${path}.compound[${key}]`)\n\t\t\t}\n\t\t\tbreak\n\t\tdefault:\n\t\t\tthrow new Error(`${path}: unknown PrimitiveType type: ${(pt as any).type}`)\n\t}\n}\n\nconst validateCode = (code: { id: string; label?: { [key: string]: string } }, path: string): void => {\n\tconst id: any = code.id\n\tif (!id || typeof id !== 'string') {\n\t\tthrow new Error(`${path}: code must have a non-empty string id, got ${JSON.stringify(id)}`)\n\t}\n}\n\nconst validateFieldValue = (fv: FieldValue, language: string, label: string): void => {\n\tconst pt = fv.content[language]\n\tif (pt) {\n\t\tvalidatePrimitiveType(pt, `FieldValue[${label}].content[${language}]`)\n\t}\n\tif (fv.codes) {\n\t\tfv.codes.forEach((code, i) => validateCode(code, `FieldValue[${label}].codes[${i}]`))\n\t}\n}\n\nconst setValueOnContactFormValuesContainer = (\n\tcfvc: ContactFormValuesContainer,\n\tlabel: string,\n\tlanguage: string,\n\tfv?: FieldValue,\n\tid?: string,\n\tmetadata?: FieldMetadata,\n\tchangeListenersOverrider?: (fvc: ContactFormValuesContainer, changedKeys: string[] | null) => void,\n) => {\n\tif (fv) {\n\t\tvalidateFieldValue(fv, language, label)\n\t}\n\tconst value = fv?.content[language]\n\tcfvc.setValue(\n\t\tlabel,\n\t\tlanguage,\n\t\t{\n\t\t\tid: id,\n\t\t\tcodes: fv?.codes ?? [],\n\t\t\tcontent: value\n\t\t\t\t? {\n\t\t\t\t\t\t[language]: primitiveTypeToContent(language, value),\n\t\t\t\t }\n\t\t\t\t: undefined,\n\t\t},\n\t\tid,\n\t\tmetadata\n\t\t\t? {\n\t\t\t\t\tlabel: metadata?.label ?? label,\n\t\t\t\t\tresponsible: metadata?.owner,\n\t\t\t\t\tvalueDate: metadata?.valueDate,\n\t\t\t\t\ttags: metadata?.tags,\n\t\t\t }\n\t\t\t: undefined,\n\t\tchangeListenersOverrider,\n\t)\n}\n"]}
1
+ {"version":3,"file":"form-values-container.js","sourceRoot":"","sources":["../../tmp/icure/form-values-container.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAgF;AAChF,kDAA6C;AAI7C,+CAA6H;AAC7H,kDAAmD;AACnD,0CAA+D;AAC/D,oDAAoD;AASpD,IAAI,QAAQ,GAAG,CAAC,CAAA;AAEhB,SAAS,MAAM,CACd,CAAoG,EACpG,GAAyC,EACzC,WAA4B,EAC5B,KAAK,GAAG,KAAK;IAEb,CA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xB,wBAAkG,EACjG,EAAE;;IACH,IAAI,EAAE,EAAE,CAAC;QACR,kBAAkB,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;IACxC,CAAC;IACD,MAAM,KAAK,GAAG,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IACnC,IAAI,CAAC,QAAQ,CACZ,KAAK,EACL,QAAQ,EACR;QACC,EAAE,EAAE,EAAE;QACN,KAAK,EAAE,MAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,KAAK,mCAAI,EAAE;QACtB,OAAO,EAAE,KAAK;YACb,CAAC,CAAC;gBACA,CAAC,QAAQ,CAAC,EAAE,IAAA,oCAAsB,EAAC,QAAQ,EAAE,KAAK,CAAC;aAClD;YACH,CAAC,CAAC,SAAS;KACZ,EACD,EAAE,EACF,QAAQ;QACP,CAAC,CAAC;YACA,KAAK,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK,mCAAI,KAAK;YAC/B,WAAW,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK;YAC5B,SAAS,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,SAAS;YAC9B,IAAI,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI;SACnB;QACH,CAAC,CAAC,SAAS,EACZ,wBAAwB,CACxB,CAAA;AACF,CAAC,CAAA","sourcesContent":["import { Contact, Form, Form as ICureForm, Service, CodeStub } from '@icure/api'\nimport { sortedBy } from '../utils/no-lodash'\nimport { ComputationResult, FormValuesContainer, Version, VersionedData } from '../generic'\nimport { ServiceMetadata } from './model'\nimport { FieldMetadata, FieldValue, PrimitiveType, Validator } from '../components/model'\nimport { areCodesEqual, codeStubToCode, contentToPrimitiveType, isContentEqual, primitiveTypeToContent } from './icure-utils'\nimport { parsePrimitive } from '../utils/primitive'\nimport { anyDateToDate, dateToFuzzyDate } from '../utils/dates'\nimport { normalizeCodes } from '../utils/code-utils'\n\ninterface ComputedValueChange {\n\tserviceId: string | undefined\n\tmetadata: FieldMetadata\n\tlanguage: string\n\tvalue: FieldValue | undefined\n}\n\nlet _ordinal = 0\n\nfunction notify<Value, Metadata>(\n\tl: (fvc: FormValuesContainer<Value, Metadata>, changedKeys: string[] | null, force: boolean) => void,\n\tfvc: FormValuesContainer<Value, Metadata>,\n\tchangedKeys: string[] | null,\n\tforce = false,\n) {\n\tl(fvc, changedKeys, force)\n}\n\nfunction primitiveTypeToString(pt: PrimitiveType): string {\n\tswitch (pt.type) {\n\t\tcase 'string':\n\t\t\treturn pt.value\n\t\tcase 'number':\n\t\t\treturn pt.value.toString()\n\t\tcase 'boolean':\n\t\t\treturn pt.value.toString()\n\t\tcase 'measure':\n\t\t\treturn pt.value !== undefined ? `${pt.value}${pt.unit ? ' ' + pt.unit : ''}` : ''\n\t\tcase 'timestamp':\n\t\t\treturn new Date(pt.value).toISOString()\n\t\tcase 'datetime':\n\t\t\treturn pt.value.toString()\n\t\tcase 'compound':\n\t\t\treturn Object.entries(pt.value)\n\t\t\t\t.map(([k, v]) => `${k}: ${primitiveTypeToString(v)}`)\n\t\t\t\t.join(', ')\n\t}\n}\n\n/** This class is a bridge between the ICure API and the generic FormValuesContainer interface.\n * It wraps around a ContactFormValuesContainer and provides a series of services:\n * - It computes dependent values when the form is created\n * - It broadcasts changes from the wrapped ContactFormValuesContainer to its listeners\n * - It provides a way to compute formulas in a sandboxed environment\n * - It bridges the setValues and setMetadata methods with the wrapped ContactFormValuesContainer by\n * \t\t- converting the FieldValue to a Service\n * \t\t- converting the FieldMetadata to a ServiceMetadata\n * - It bridges the getValues and getMetadata methods with the wrapped ContactFormValuesContainer by\n * \t\t- converting the Service to a FieldValue\n * \t\t- converting the ServiceMetadata to a FieldMetadata\n * - It lazily creates bridges the children by\n * - lazily creating BridgedFormValuesContainer when the children of the wrapped ContactFormValuesContainer are accessed\n * - creating a new ContactFormValuesContainer and wrapping it in a BridgedFormValuesContainer when a child is added\n *\n * The icure-form typically accepts a BridgedFormValuesContainer as a prop and uses it to interact with the form.\n *\n * This class is fairly generic and can be used as an inspiration or subclassed for other bridges\n */\nexport class BridgedFormValuesContainer implements FormValuesContainer<FieldValue, FieldMetadata> {\n\tprivate contact: Contact\n\tprivate contactFormValuesContainer: ContactFormValuesContainer\n\tprivate _id = ''\n\tprivate readonly mutateAndNotify: (newContactFormValuesContainer: ContactFormValuesContainer, changedKeys: string[] | null) => void\n\tprivate dependentValuesComputationIteration?: Promise<ComputedValueChange[]> = undefined\n\n\ttoString(): string {\n\t\treturn `Bridged(${this.contactFormValuesContainer.rootForm.formTemplateId}[${this.contactFormValuesContainer.rootForm.id}]) - ${this._id}`\n\t}\n\n\t/**\n\t * Creates an instance of BridgedFormValuesContainer.\n\t * @param responsible The id of the data owner responsible for the creation of the values\n\t * @param contactFormValuesContainer The wrapped ContactFormValuesContainer\n\t * @param interpreter A function that can interpret formulas\n\t * @param contact The displayed contact (may be in the past). === to currentContact if the contact is the contact of the day\n\t * @param initialValuesProvider A lambda that provides the initial values of the form\n\t * @param dependentValuesProvider A function that provides the dependent values (computed on the basis of other values) for a given anchorId and templateId\n\t * @param validatorsProvider A function that provides the validators for a given anchorId and templateId\n\t * @param language The language in which the values are displayed\n\t * @param changeListeners The listeners that will be notified when the values change\n\t * @param interpreterContext A map with keys that are the names of the variables and values that are the functions that return the values of the variables\n\t * @param dependenciesCache\n\t */\n\tconstructor(\n\t\tprivate responsible: string,\n\t\tcontactFormValuesContainer: ContactFormValuesContainer,\n\t\tprivate interpreter?: <\n\t\t\tT,\n\t\t\tS extends {\n\t\t\t\t[key: string | symbol]: unknown\n\t\t\t},\n\t\t>(\n\t\t\tformula: string,\n\t\t\tsandbox: S,\n\t\t) => Promise<T | undefined>,\n\t\tcontact?: Contact,\n\t\tprivate initialValuesProvider: (\n\t\t\tanchorId?: string,\n\t\t\ttemplateId?: string,\n\t\t) => {\n\t\t\tmetadata: FieldMetadata\n\t\t\trevisionsFilter: (id: string, history: Version<FieldMetadata>[]) => (string | null)[]\n\t\t\tformula: string\n\t\t}[] = () => [],\n\t\tprivate dependentValuesProvider: (\n\t\t\tanchorId: string | undefined,\n\t\t\ttemplateId: string | undefined,\n\t\t) => {\n\t\t\tmetadata: FieldMetadata\n\t\t\trevisionsFilter: (id: string, history: Version<FieldMetadata>[]) => (string | null)[]\n\t\t\tformula: string\n\t\t}[] = () => [],\n\t\tprivate validatorsProvider: (\n\t\t\tanchorId: string | undefined,\n\t\t\ttemplateId: string,\n\t\t) => {\n\t\t\tmetadata: FieldMetadata\n\t\t\tvalidators: Validator[]\n\t\t}[] = () => [],\n\t\tprivate language = 'en',\n\t\tprivate changeListeners: ((newValue: BridgedFormValuesContainer, changedKeys: string[] | null, force: boolean) => void)[] = [],\n\t\tprivate interpreterContext: { [variable: string]: () => unknown } = {},\n\t\tprivate dependenciesCache: { [formula: string]: string[] } = {},\n\t) {\n\t\t//Before start to broadcast changes, we need to fill in the contactFormValuesContainer with the dependent values\n\t\tthis.contactFormValuesContainer = contactFormValuesContainer\n\t\tthis._id = `[${contactFormValuesContainer._id}]`\n\t\tconsole.log(`+ BFVC ${this._id} created`)\n\t\tthis.mutateAndNotify = (newContactFormValuesContainer: ContactFormValuesContainer, changedKeys: string[] | null, force = false) => {\n\t\t\tif (this.changeListeners.length === 0) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (!force && this.contactFormValuesContainer === newContactFormValuesContainer) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.contactFormValuesContainer.unregisterChangeListener(this.mutateAndNotify)\n\t\t\tnewContactFormValuesContainer.unregisterChangeListener(this.mutateAndNotify)\n\n\t\t\tconst newBridgedFormValueContainer = new BridgedFormValuesContainer(\n\t\t\t\tthis.responsible,\n\t\t\t\tnewContactFormValuesContainer,\n\t\t\t\tthis.interpreter,\n\t\t\t\tthis.contact === this.contactFormValuesContainer.currentContact ? newContactFormValuesContainer.currentContact : this.contact,\n\t\t\t\tthis.initialValuesProvider,\n\t\t\t\tthis.dependentValuesProvider,\n\t\t\t\tthis.validatorsProvider,\n\t\t\t\tthis.language,\n\t\t\t\tthis.changeListeners,\n\t\t\t\tthis.interpreterContext,\n\t\t\t\tthis.dependenciesCache,\n\t\t\t)\n\n\t\t\tconsole.log(`- init started ${newBridgedFormValueContainer._id} with changed keys: ${changedKeys ? changedKeys.join(', ') : 'all'}`)\n\t\t\tconst initPromise = newBridgedFormValueContainer.init(changedKeys, this.dependentValuesComputationIteration)\n\t\t\tthis.changeListeners.forEach((l) => notify(l, newBridgedFormValueContainer, changedKeys))\n\n\t\t\tinitPromise\n\t\t\t\t.catch((e) => {\n\t\t\t\t\tconsole.log('Error while initializing new BridgedFormValuesContainer', e)\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tconsole.log(`- init finished ${newBridgedFormValueContainer._id}`)\n\t\t\t\t})\n\t\t}\n\t\tthis.contactFormValuesContainer.registerChangeListener(this.mutateAndNotify)\n\t\tthis.contact = contact ?? contactFormValuesContainer.currentContact\n\t}\n\n\t/* init can be called several times on the same instance but the initialisation will only be done once */\n\tasync init(changedKeys: string[] | null = null, pendingComputationIteration?: Promise<ComputedValueChange[]>): Promise<BridgedFormValuesContainer> {\n\t\tlet changedKeysByInit: string[] = []\n\t\tif (pendingComputationIteration) {\n\t\t\tconst changes = await pendingComputationIteration\n\n\t\t\tif (changes.length > 0) {\n\t\t\t\tthis.quietlyApplyChangesOnContactFormValueContainer(changes)\n\t\t\t\tchangedKeysByInit = await this.computeDependentValues([...(changedKeys ?? []), ...changes.map(({ metadata }) => metadata.label)], this.contactFormValuesContainer.mustBeInitialised())\n\t\t\t} else {\n\t\t\t\tchangedKeysByInit = await this.computeDependentValues(changedKeys, this.contactFormValuesContainer.mustBeInitialised())\n\t\t\t}\n\t\t} else {\n\t\t\tconsole.log('Start compute')\n\t\t\tchangedKeysByInit = await this.computeDependentValues(changedKeys, this.contactFormValuesContainer.mustBeInitialised())\n\t\t\tconsole.log('Finish compute')\n\t\t}\n\n\t\t//After all the silent updates, we need a last one that causes a new BridgedFormValuesContainer to be created and broadcasted to the listeners, so that they get the final values with all the dependencies computed\n\t\tconsole.log('Launch refresh')\n\t\tthis.contactFormValuesContainer.changeListeners.forEach((l) => notify(l, this.contactFormValuesContainer, changedKeysByInit, changedKeysByInit.length > 0))\n\n\t\treturn this\n\t}\n\n\tgetLabel(): string {\n\t\treturn this.contactFormValuesContainer.getLabel()\n\t}\n\n\tgetFormId(): string | undefined {\n\t\treturn this.contactFormValuesContainer.getFormId()\n\t}\n\n\tgetContactFormValuesContainer() {\n\t\treturn this.contactFormValuesContainer\n\t}\n\n\tregisterChangeListener(listener: (newValue: BridgedFormValuesContainer, changedKeys: string[] | null, force: boolean) => void): void {\n\t\tthis.changeListeners.push(listener)\n\t}\n\n\tunregisterChangeListener(listener: (newValue: BridgedFormValuesContainer, changedKeys: string[] | null, force: boolean) => void): void {\n\t\tthis.changeListeners = this.changeListeners.filter((l) => l !== listener)\n\t}\n\n\tgetDefaultValueProvider(label: string): (() => Promise<FieldValue | undefined>) | undefined {\n\t\tconst formula = this.initialValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).find(\n\t\t\t({ metadata }) => metadata.label === label,\n\t\t)?.formula\n\t\treturn formula ? async () => this.convertRawValue(await this.compute(formula)) : undefined\n\t}\n\n\tgetValues(revisionsFilter: (id: string, history: Version<FieldMetadata>[]) => (string | null)[]): VersionedData<FieldValue> {\n\t\treturn Object.entries(\n\t\t\tthis.contactFormValuesContainer.getValues((id, history) =>\n\t\t\t\trevisionsFilter(\n\t\t\t\t\tid,\n\t\t\t\t\thistory\n\t\t\t\t\t\t.filter(({ modified }) => !this.contact.created || !modified || modified <= this.contact.created)\n\t\t\t\t\t\t.map(({ revision, modified, value: sm }) => ({\n\t\t\t\t\t\t\trevision,\n\t\t\t\t\t\t\tmodified,\n\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\tlabel: sm.label,\n\t\t\t\t\t\t\t\towner: sm.responsible,\n\t\t\t\t\t\t\t\ttags: sm.tags?.map(codeStubToCode),\n\t\t\t\t\t\t\t\tvalueDate: sm.valueDate,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t),\n\t\t).reduce((acc, [id, history]) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t[id]: history.map(({ revision, modified, value: s }) => ({\n\t\t\t\t\trevision,\n\t\t\t\t\tmodified,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontent: Object.entries(s.content ?? {}).reduce((acc, [lng, cnt]) => {\n\t\t\t\t\t\t\tconst converted = contentToPrimitiveType(lng, cnt)\n\t\t\t\t\t\t\treturn converted ? { ...acc, [lng]: converted } : acc\n\t\t\t\t\t\t}, {}),\n\t\t\t\t\t\tcodes: s.codes?.map(codeStubToCode),\n\t\t\t\t\t},\n\t\t\t\t})),\n\t\t\t}\n\t\t}, {} as VersionedData<FieldValue>)\n\t}\n\n\tgetMetadata(id: string, revisions: (string | null)[]): VersionedData<FieldMetadata> {\n\t\treturn Object.entries(this.contactFormValuesContainer.getMetadata(id, revisions)).reduce(\n\t\t\t(acc, [id, history]) => ({\n\t\t\t\t...acc,\n\t\t\t\t[id]: history.map(({ revision, modified, value: s }) => ({\n\t\t\t\t\trevision,\n\t\t\t\t\tmodified,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tlabel: s.label,\n\t\t\t\t\t\towner: s.responsible,\n\t\t\t\t\t\tvalueDate: s.valueDate,\n\t\t\t\t\t\ttags: s.tags,\n\t\t\t\t\t\tdiscordantMetadata: () => ({\n\t\t\t\t\t\t\t...(s.responsible !== this.responsible ? { owner: this.responsible } : {}),\n\t\t\t\t\t\t\t...(Math.abs(+(anyDateToDate(s.valueDate) ?? 0) - +(anyDateToDate(this.contact.created) ?? 0)) > 24 * 3600000 ? { valueDate: s.valueDate } : {}),\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t})),\n\t\t\t}),\n\t\t\t{},\n\t\t)\n\t}\n\n\tprivate convertRawValue(rawValue: unknown): FieldValue | undefined {\n\t\tif (rawValue && typeof rawValue === 'object' && 'content' in rawValue) {\n\t\t\treturn rawValue as FieldValue\n\t\t}\n\n\t\tif (Array.isArray(rawValue)) {\n\t\t\treturn rawValue.reduce(\n\t\t\t\t(acc: FieldValue, it, idx) => {\n\t\t\t\t\tconst fv = this.convertRawValue(it)\n\t\t\t\t\tif (fv === undefined) {\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t}\n\t\t\t\t\tacc.codes = [...(fv.codes ?? []), ...(acc.codes ?? [])]\n\t\t\t\t\tacc.content['*'] = fv.content['*']?.value\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t...acc.content['*'],\n\t\t\t\t\t\t\t\t[(fv.codes ?? [])[0].id ?? idx.toString()]: fv.content['*'].value,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: acc.content['*']\n\t\t\t\t\treturn acc\n\t\t\t\t},\n\t\t\t\t{ content: { '*': { type: 'compound', value: {} } } },\n\t\t\t)\n\t\t}\n\n\t\tif (typeof rawValue === 'number') {\n\t\t\treturn { content: { '*': { type: 'number', value: rawValue } } }\n\t\t}\n\n\t\tif (typeof rawValue === 'string') {\n\t\t\treturn { content: { '*': { type: 'string', value: rawValue } } }\n\t\t}\n\n\t\tif (typeof rawValue === 'boolean') {\n\t\t\treturn { content: { '*': { type: 'boolean', value: rawValue } } }\n\t\t}\n\n\t\tif (rawValue instanceof Date) {\n\t\t\treturn { content: { '*': { type: 'timestamp', value: dateToFuzzyDate(rawValue) } } }\n\t\t}\n\n\t\tif (rawValue && typeof rawValue === 'object' && 'unit' in rawValue && 'value' in rawValue && typeof rawValue.value === 'number') {\n\t\t\treturn { content: { '*': { type: 'measure', value: rawValue.value, unit: rawValue.unit?.toString() ?? '' } } }\n\t\t}\n\n\t\treturn undefined\n\t}\n\n\t//This method mutates the BridgedFormValuesContainer but can only be called from the constructor\n\tprivate async computeDependentValues(changedKeys: string[] | null, computeInitialValues: boolean): Promise<string[]> {\n\t\tconst initialValues = (computeInitialValues ? this.initialValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId) : []).filter(\n\t\t\t({ revisionsFilter }) => {\n\t\t\t\tconst currentValue = this.getValues(revisionsFilter)\n\t\t\t\treturn !currentValue || !Object.keys(currentValue).length\n\t\t\t},\n\t\t)\n\n\t\tconst dependentValues = this.dependentValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId)\n\n\t\tconst iterate = async (changedKeys: string[] | null, iterationCount: number): Promise<ComputedValueChange[]> => {\n\t\t\tif (this.contactFormValuesContainer.rootForm.formTemplateId) {\n\t\t\t\tconsole.log(`% ${iterationCount}, keys: ${changedKeys ? changedKeys.join(', ') : 'all'}`)\n\n\t\t\t\treturn await Promise.all(\n\t\t\t\t\tdependentValues.concat(initialValues).map(async ({ metadata, revisionsFilter, formula }) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (!changedKeys || !this.dependenciesCache[formula] || this.dependenciesCache[formula].some((d) => changedKeys.includes(d))) {\n\t\t\t\t\t\t\t\tconst currentValue = this.getValues(revisionsFilter)\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst computationResult = await this.compute(formula)\n\t\t\t\t\t\t\t\t\tthis.dependenciesCache[formula] = [...(this.dependenciesCache[formula] ?? []), ...computationResult.dependencies].filter((d, idx, array) => array.indexOf(d) === idx)\n\t\t\t\t\t\t\t\t\tconst newValue = computationResult.value ? this.convertRawValue(computationResult.value) : undefined\n\n\t\t\t\t\t\t\t\t\tif (newValue !== undefined || (currentValue != undefined && Object.keys(currentValue).length > 0 && currentValue[Object.keys(currentValue)[0]][0].value)) {\n\t\t\t\t\t\t\t\t\t\tconst lng = this.language ?? 'en'\n\t\t\t\t\t\t\t\t\t\tif (newValue && !newValue.content[lng] && newValue.content['*']) {\n\t\t\t\t\t\t\t\t\t\t\tnewValue.content[lng] = newValue.content['*']\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (newValue) {\n\t\t\t\t\t\t\t\t\t\t\tdelete newValue.content['*']\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn { serviceId: Object.keys(currentValue ?? {})[0], metadata, language: lng, value: newValue } as ComputedValueChange\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\t\tconsole.log(`Error while computing formula : ${formula}`, e)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\tconsole.log(`Error while computing formula : ${formula}`, e)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}),\n\t\t\t\t).then((results) => {\n\t\t\t\t\treturn results.filter((r) => !!r)\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\treturn []\n\t\t\t}\n\t\t}\n\n\t\tlet latestKeys = changedKeys\n\t\tconst iterationCount = 0\n\t\tconst allChangedKeys: string[] = []\n\t\twhile (true) {\n\t\t\tif (latestKeys != null && latestKeys.length === 0) {\n\t\t\t\tthis.dependentValuesComputationIteration = undefined\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tconst changesPromise = iterate(latestKeys, iterationCount)\n\t\t\tthis.dependentValuesComputationIteration = changesPromise\n\t\t\tconst changesResult = await changesPromise\n\t\t\tlatestKeys = this.quietlyApplyChangesOnContactFormValueContainer(changesResult)\n\t\t\tallChangedKeys.push(...latestKeys)\n\t\t}\n\n\t\treturn allChangedKeys\n\t}\n\n\tprivate quietlyApplyChangesOnContactFormValueContainer(changes: ComputedValueChange[]): string[] {\n\t\tconst allChangedKeys: string[] = []\n\t\tconst interceptor = (fvc: ContactFormValuesContainer, changedKeys: string[] | null) => {\n\t\t\tconst currentContact = this.contactFormValuesContainer.currentContact\n\t\t\tthis.contactFormValuesContainer = fvc\n\t\t\tif (this.contact === currentContact) {\n\t\t\t\tthis.contact = fvc.currentContact\n\t\t\t}\n\t\t\tallChangedKeys.push(...(changedKeys ?? []))\n\t\t}\n\n\t\tchanges.forEach(({ serviceId, metadata, language, value }) => {\n\t\t\ttry {\n\t\t\t\tsetValueOnContactFormValuesContainer(this.contactFormValuesContainer, metadata.label, language, value ?? undefined, serviceId, metadata, interceptor)\n\t\t\t} catch (e) {\n\t\t\t\tconsole.log(`Error while applying dependent value change for ${metadata.label} (${serviceId})`, e)\n\t\t\t}\n\t\t})\n\n\t\treturn allChangedKeys\n\t}\n\n\tsetValue(label: string, language: string, fv?: FieldValue, id?: string, metadata?: FieldMetadata): void {\n\t\tsetValueOnContactFormValuesContainer(this.contactFormValuesContainer, label, language, fv, id, metadata)\n\t}\n\n\tsetMetadata(meta: FieldMetadata, id?: string | undefined): void {\n\t\tthis.contactFormValuesContainer.setMetadata(\n\t\t\t{\n\t\t\t\tlabel: meta.label,\n\t\t\t\tresponsible: meta.owner,\n\t\t\t\tvalueDate: meta.valueDate,\n\t\t\t\ttags: meta.tags,\n\t\t\t},\n\t\t\tid,\n\t\t)\n\t}\n\n\tdelete(serviceId: string): void {\n\t\tthis.contactFormValuesContainer.delete(serviceId)\n\t}\n\n\tprivate getVersionedValuesForKey(key: string | symbol) {\n\t\treturn this.getValues((id, history) => (history?.[0]?.value?.label && key === history[0].value.label ? [history?.[0]?.revision] : []))\n\t}\n\n\tasync compute<T>(formula: string): Promise<ComputationResult<T>> {\n\t\tconst dependencies = new Set<string>()\n\t\t// noinspection JSUnusedGlobalSymbols\n\t\tconst parseContent = (content?: { [key: string]: PrimitiveType }, toString = false) => {\n\t\t\tif (!content) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tconst primitive = content[this.language] ?? content['*'] ?? content[Object.keys(content)[0]]\n\t\t\treturn primitive && parsePrimitive(primitive, toString)\n\t\t}\n\t\tconst text = (item?: { content: { [key: string]: PrimitiveType } } | { content: { [key: string]: PrimitiveType } }[]) => {\n\t\t\tif (!item) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tconst items: { content: { [key: string]: PrimitiveType } }[] = Array.isArray(item) ? item : [item]\n\t\t\treturn items\n\t\t\t\t.map((it) => parseContent(it.content, true)?.toString())\n\t\t\t\t.filter((it) => !!it)\n\t\t\t\t.join(', ')\n\t\t}\n\t\tconst log = console.log\n\t\t// noinspection JSUnusedGlobalSymbols\n\t\tconst native = {\n\t\t\tparseInt: parseInt,\n\t\t\tparseFloat: parseFloat,\n\t\t\tDate: Date,\n\t\t\tMath: Math,\n\t\t\tNumber: Number,\n\t\t\tString: String,\n\t\t\tBoolean: Boolean,\n\t\t\tArray: Array,\n\t\t\tObject: Object,\n\t\t\thasOption: (\n\t\t\t\tit: {\n\t\t\t\t\tcodes: CodeStub[]\n\t\t\t\t},\n\t\t\t\toption: string,\n\t\t\t) => it && it.codes?.some((c) => c.id === option || c.id?.split('|')?.[1] === option),\n\t\t\tscore: (it: { codes: CodeStub[] }) => {\n\t\t\t\treturn it\n\t\t\t\t\t? (it.codes ?? []).reduce((acc, c) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\treturn acc + parseInt(c.id?.split('|')?.[1] ?? '0')\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\treturn acc\n\t\t\t\t\t\t\t}\n\t\t\t\t\t }, 0)\n\t\t\t\t\t: 0\n\t\t\t},\n\t\t\tparseContent,\n\t\t\tvalidate: {\n\t\t\t\tnotBlank: (self: any, label: string) => {\n\t\t\t\t\tconst value = parseContent((self[label as any] as any)?.[0]?.content)\n\t\t\t\t\treturn !!(value as any)?.trim()?.length\n\t\t\t\t},\n\t\t\t},\n\t\t\ttext,\n\t\t\tlog,\n\t\t\tPromise,\n\t\t} as { [key: string]: any }\n\t\tconst proxy: { [key: string]: string | symbol } = new Proxy({} as { [key: string]: string | symbol }, {\n\t\t\thas: (target: { [key: string]: string | symbol }, key: string | symbol) =>\n\t\t\t\t!!native[key as string] || key === 'self' || !!this.interpreterContext[key as string] || Object.keys(this.getVersionedValuesForKey(key) ?? {}).length > 0,\n\t\t\tget: (target: { [key: string]: string | symbol }, key: string | symbol) => {\n\t\t\t\tif (key === 'undefined') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst nativeValue = native[key as string]\n\t\t\t\tif (!!nativeValue) {\n\t\t\t\t\treturn nativeValue\n\t\t\t\t}\n\t\t\t\tif (key === 'self') {\n\t\t\t\t\treturn proxy\n\t\t\t\t} else {\n\t\t\t\t\tdependencies.add(key.toString())\n\t\t\t\t\treturn this.interpreterContext[key as string] ? this.interpreterContext[key as string]() : Object.values(this.getVersionedValuesForKey(key)).map((v) => v[0]?.value)\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t\treturn { value: await this.interpreter?.(formula, proxy), dependencies: Array.from(dependencies) }\n\t}\n\n\tasync getChildren(): Promise<FormValuesContainer<FieldValue, FieldMetadata>[]> {\n\t\treturn await Promise.all(\n\t\t\t(\n\t\t\t\tawait this.contactFormValuesContainer.getChildren()\n\t\t\t).map((fvc) =>\n\t\t\t\tnew BridgedFormValuesContainer(\n\t\t\t\t\tthis.responsible,\n\t\t\t\t\tfvc,\n\t\t\t\t\tthis.interpreter,\n\t\t\t\t\tthis.contact,\n\t\t\t\t\tthis.initialValuesProvider,\n\t\t\t\t\tthis.dependentValuesProvider,\n\t\t\t\t\tthis.validatorsProvider,\n\t\t\t\t\tthis.language,\n\t\t\t\t\t[],\n\t\t\t\t\tthis.interpreterContext,\n\t\t\t\t).init(),\n\t\t\t),\n\t\t)\n\t}\n\n\tgetValidationErrors(): Promise<[FieldMetadata, string] | null>[] {\n\t\tif (this.contactFormValuesContainer.rootForm.formTemplateId) {\n\t\t\treturn this.validatorsProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).flatMap(({ metadata, validators }) =>\n\t\t\t\tvalidators.map(async ({ validation, message }): Promise<[FieldMetadata, string] | null> => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (!(await this.compute(validation))) {\n\t\t\t\t\t\t\treturn [metadata, message]\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tconsole.log(`Error while computing validation : ${validation}`, e)\n\t\t\t\t\t}\n\t\t\t\t\treturn null\n\t\t\t\t}),\n\t\t\t)\n\t\t} else {\n\t\t\treturn []\n\t\t}\n\t}\n\n\tasync addChild(anchorId: string, templateId: string, label: string): Promise<void> {\n\t\tawait this.contactFormValuesContainer.addChild(anchorId, templateId, label)\n\t}\n\n\tasync removeChild(container: BridgedFormValuesContainer): Promise<void> {\n\t\tawait this.contactFormValuesContainer.removeChild(container.contactFormValuesContainer)\n\t}\n\n\tsynchronise() {\n\t\tthis.contactFormValuesContainer.synchronise()\n\t\treturn this\n\t}\n}\n\n/**\n * 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.\n * The `currentContact` is the contact that has been selected by the user, any later contact should be ignored.\n * The `contactsHistory` is used to provide the full history of the services.\n * The hierarchy of ContactFormValuesContainer has to be maintained by the manager of the instances of this class (typically the BridgedFormValuesContainer).\n * Each ContactFormValuesContainer has a reference to its `rootForm`.\n * The `serviceFactory` and `formFactory` are used to create new services and add sub-forms.\n */\nexport class ContactFormValuesContainer implements FormValuesContainer<Service, ServiceMetadata> {\n\trootForm: ICureForm\n\tcurrentContact: Contact //The contact of the moment, used to record new modifications\n\tcontactsHistory: Contact[] //Must be sorted (most recent first), contains all the contacts linked to this form\n\tchildren: ContactFormValuesContainer[] //Direct children of the ContactFormValuesContainer\n\tanchorId?: string //The anchorId in the parent form\n\tserviceFactory: (label: string, serviceId?: string) => Service\n\tformFactory: (parentId: string, anchorId: string, formTemplateId: string, label: string) => Promise<ICureForm>\n\tformRecycler: (formId: string) => Promise<void>\n\n\tchangeListeners: ((newValue: ContactFormValuesContainer, changedKeys: string[] | null, force: boolean) => void)[]\n\n\t_id = ''\n\tprivate _initialised = false\n\tprivate indexedServices: { [id: string]: Version<Service>[] }\n\n\ttoString(): string {\n\t\treturn `Contact(${this.rootForm.formTemplateId}[${this.rootForm.id}]) - ${this._id}`\n\t}\n\n\tmustBeInitialised() {\n\t\treturn !this._initialised\n\t}\n\n\t/**\n\t * Returns a contact that combines the content of the contact in this form with the content of all contents stored in the children\n\t */\n\tcoordinatedContact(): Contact {\n\t\tconst childrenContacts = this.children.map((c) => c.coordinatedContact())\n\t\tconst thisKeptServiceIds = new Set((this.currentContact.subContacts ?? []).filter((sc) => sc.formId === this.rootForm.id).flatMap((sc) => (sc.services ?? []).map((s) => s.serviceId)))\n\t\tconst thisFormServices = (this.currentContact.services ?? []).filter((s) => thisKeptServiceIds.has(s.id))\n\t\t// Include endOfLife services not linked to any subcontact (from deleted subforms)\n\t\tconst allSubContactServiceIds = new Set((this.currentContact.subContacts ?? []).flatMap((sc) => (sc.services ?? []).map((s) => s.serviceId)))\n\t\tconst endOfLifeServices = (this.currentContact.services ?? []).filter((s) => s.endOfLife && s.id && !allSubContactServiceIds.has(s.id))\n\n\t\treturn {\n\t\t\t...this.currentContact,\n\t\t\tservices: childrenContacts\n\t\t\t\t.reduce((acc: Service[], c: Contact) => acc.concat(c.services ?? []), [])\n\t\t\t\t.concat(thisFormServices)\n\t\t\t\t.concat(endOfLifeServices),\n\t\t\tsubContacts: childrenContacts\n\t\t\t\t.reduce((acc: Service[], c: Contact) => acc.concat(c.subContacts ?? []), [])\n\t\t\t\t.concat((this.currentContact.subContacts ?? []).filter((s) => s.formId === this.rootForm.id)),\n\t\t}\n\t}\n\n\t/**\n\t * Returns a contact that combines the content of the contact in this form with the content of all contents stored in the children\n\t */\n\tallForms(): Form[] {\n\t\treturn [this.rootForm].concat(this.children.flatMap((c) => c.allForms()))\n\t}\n\n\tconstructor(\n\t\trootForm: ICureForm,\n\t\tcurrentContact: Contact,\n\t\tcontactsHistory: Contact[],\n\t\tserviceFactory: (label: string, serviceId?: string) => Service,\n\t\tchildren: ContactFormValuesContainer[],\n\t\tformFactory: (parentId: string, anchorId: string, formTemplateId: string, label: string) => Promise<ICureForm>,\n\t\tformRecycler: (formId: string) => Promise<void>,\n\t\tchangeListeners: ((newValue: ContactFormValuesContainer, changedKeys: string[] | null, force: boolean) => void)[] = [],\n\t\tanchorId?: string,\n\t\tinitialised = true,\n\t) {\n\t\tthis.rootForm = rootForm\n\t\tthis._id = `${(rootForm.formTemplateId ?? '').substring(0, 4)}.${++_ordinal}`\n\t\tconsole.log(`+ CFVC: ${this._id} with children { ${children.map((c) => c._id).join(', ')} }`)\n\n\t\tif (contactsHistory.includes(currentContact)) {\n\t\t\tthrow new Error('Illegal argument, the history must not contain the currentContact')\n\t\t}\n\t\tthis.currentContact = currentContact\n\t\tthis.contactsHistory = sortedBy(contactsHistory, 'created', 'desc')\n\t\tthis.children = children\n\t\tthis.anchorId = anchorId\n\t\tthis.serviceFactory = serviceFactory\n\t\tthis.formFactory = formFactory\n\t\tthis.formRecycler = formRecycler\n\t\tthis.changeListeners = changeListeners\n\t\tthis._initialised = initialised\n\n\t\t// Collect IDs of services that have been marked with endOfLife in the most recent contact\n\t\tconst endOfLifeServiceIds = new Set<string>()\n\t\tconst mostRecentContact = this.currentContact\n\t\tfor (const s of mostRecentContact.services ?? []) {\n\t\t\tif (s.id && s.endOfLife) endOfLifeServiceIds.add(s.id)\n\t\t}\n\n\t\tthis.indexedServices = [this.currentContact].concat(this.contactsHistory).reduce((acc, ctc) => {\n\t\t\treturn (\n\t\t\t\tctc.services\n\t\t\t\t\t?.filter((s) => !endOfLifeServiceIds.has(s.id!) && ctc.subContacts?.some((sc) => sc.formId === this.rootForm.id && sc.services?.some((sss) => sss.serviceId === s.id)))\n\t\t\t\t\t?.reduce(\n\t\t\t\t\t\t(acc, s) =>\n\t\t\t\t\t\t\ts.id\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t\t[s.id]: (acc[s.id] ?? (acc[s.id] = [])).concat({\n\t\t\t\t\t\t\t\t\t\t\trevision: ctc.rev ?? null,\n\t\t\t\t\t\t\t\t\t\t\tmodified: ctc.created,\n\t\t\t\t\t\t\t\t\t\t\tvalue: s,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t: acc,\n\t\t\t\t\t\tacc,\n\t\t\t\t\t) ?? acc\n\t\t\t)\n\t\t}, {} as VersionedData<Service>)\n\n\t\tthis.synchronise()\n\t}\n\n\tsynchronise() {\n\t\tthis.children.forEach((childFVC) => {\n\t\t\tthis.registerChildFormValuesContainer(childFVC.synchronise(), childFVC.anchorId ?? '')\n\t\t})\n\t\treturn this\n\t}\n\n\t//Make sure that when a child is changed, a new version of this is created with the updated child\n\tregisterChildFormValuesContainer(childFormValueContainer: ContactFormValuesContainer, anchorId: string) {\n\t\tchildFormValueContainer.changeListeners = [\n\t\t\t(newValue, changedKeys, force) => {\n\t\t\t\tif (changedKeys?.length === 0 && !force) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconsole.log(`Child ${newValue._id} ${childFormValueContainer.rootForm.formTemplateId} changed, updating parent ${this._id} ${this.rootForm.formTemplateId}`)\n\t\t\t\tconst newContactFormValuesContainer = new ContactFormValuesContainer(\n\t\t\t\t\tthis.rootForm,\n\t\t\t\t\tthis.currentContact,\n\t\t\t\t\tthis.contactsHistory,\n\t\t\t\t\tthis.serviceFactory,\n\t\t\t\t\tthis.children.map((c) => {\n\t\t\t\t\t\treturn c.rootForm.id === childFormValueContainer.rootForm.id ? newValue : c\n\t\t\t\t\t}),\n\t\t\t\t\tthis.formFactory,\n\t\t\t\t\tthis.formRecycler,\n\t\t\t\t\t[],\n\t\t\t\t\tthis.anchorId,\n\t\t\t\t\ttrue,\n\t\t\t\t)\n\t\t\t\tthis.changeListeners.forEach((l) => notify(l, newContactFormValuesContainer, null))\n\t\t\t},\n\t\t]\n\t}\n\n\tstatic async fromFormsHierarchy(\n\t\trootForm: ICureForm,\n\t\tcurrentContact: Contact,\n\t\tcontactsHistory: Contact[],\n\t\tserviceFactory: (label: string, serviceId?: string) => Service,\n\t\tformChildrenProvider: (parentId: string | undefined) => Promise<ICureForm[]>,\n\t\tformFactory: (parentId: string, anchorId: string, formTemplateId: string, label: string) => Promise<ICureForm>,\n\t\tformRecycler: (formId: string) => Promise<void>,\n\t\tchangeListeners: ((newValue: ContactFormValuesContainer) => void)[] = [],\n\t): Promise<ContactFormValuesContainer> {\n\t\tconst contactFormValuesContainer = new ContactFormValuesContainer(\n\t\t\trootForm,\n\t\t\tcurrentContact,\n\t\t\tcontactsHistory,\n\t\t\tserviceFactory,\n\t\t\trootForm.id\n\t\t\t\t? await Promise.all(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tawait formChildrenProvider(rootForm.id)\n\t\t\t\t\t\t).map(\n\t\t\t\t\t\t\tasync (f) =>\n\t\t\t\t\t\t\t\t// eslint-disable-next-line max-len\n\t\t\t\t\t\t\t\tawait ContactFormValuesContainer.fromFormsHierarchy(f, currentContact, contactsHistory, serviceFactory, formChildrenProvider, formFactory, formRecycler),\n\t\t\t\t\t\t),\n\t\t\t\t )\n\t\t\t\t: [],\n\t\t\tformFactory,\n\t\t\tformRecycler,\n\t\t\tchangeListeners,\n\t\t\trootForm.descr,\n\t\t\tfalse,\n\t\t)\n\t\tcontactFormValuesContainer.children.forEach((childFVC) => contactFormValuesContainer.registerChildFormValuesContainer(childFVC, childFVC.anchorId ?? 'all'))\n\n\t\treturn contactFormValuesContainer\n\t}\n\n\tgetLabel(): string {\n\t\treturn this.rootForm.descr ?? ''\n\t}\n\n\tgetFormId(): string | undefined {\n\t\treturn this.rootForm?.formTemplateId\n\t}\n\n\tregisterChangeListener(listener: (newValue: ContactFormValuesContainer, changedKeys: string[] | null, force: boolean) => void): void {\n\t\tthis.changeListeners.push(listener)\n\t}\n\n\tunregisterChangeListener(listener: (newValue: ContactFormValuesContainer, changedKeys: string[] | null, force: boolean) => void): void {\n\t\tthis.changeListeners = this.changeListeners.filter((l) => l !== listener)\n\t}\n\n\tasync getChildren(): Promise<ContactFormValuesContainer[]> {\n\t\treturn this.children\n\t}\n\n\tgetValidationErrors(): Promise<[FieldMetadata, string] | null>[] {\n\t\tthrow new Error('Validation not supported at contact level')\n\t}\n\n\tgetDefaultValueProvider(): (() => Promise<FieldValue | undefined>) | undefined {\n\t\treturn undefined\n\t}\n\n\tgetValues(revisionsFilter: (id: string, history: Version<ServiceMetadata>[]) => (string | null)[]): VersionedData<Service> {\n\t\treturn Object.entries(this.getServicesInHistory(revisionsFilter)).reduce(\n\t\t\t(acc, [id, history]) =>\n\t\t\t\thistory.length\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t[id]: [...history].sort((a, b) => (b?.modified || +new Date()) - (a?.modified || +new Date())),\n\t\t\t\t\t }\n\t\t\t\t\t: acc,\n\t\t\t{},\n\t\t)\n\t}\n\n\tgetMetadata(id: string, revisions: (string | null)[]): VersionedData<ServiceMetadata> {\n\t\treturn [this.currentContact]\n\t\t\t.concat(this.contactsHistory)\n\t\t\t.filter((ctc) => ctc.rev !== undefined && revisions.includes(ctc.rev))\n\t\t\t.reduce(\n\t\t\t\t(acc, ctc) =>\n\t\t\t\t\t(ctc.services ?? [])\n\t\t\t\t\t\t.filter((s) => s.id === id)\n\t\t\t\t\t\t.reduce(\n\t\t\t\t\t\t\t(acc, s) =>\n\t\t\t\t\t\t\t\ts.id\n\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t\t\t[s.id]: (acc[s.id] ?? (acc[s.id] = [])).concat({\n\t\t\t\t\t\t\t\t\t\t\t\trevision: ctc.rev ?? null,\n\t\t\t\t\t\t\t\t\t\t\t\tmodified: s.modified,\n\t\t\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlabel: s.label ?? s.id,\n\t\t\t\t\t\t\t\t\t\t\t\t\tresponsible: s.responsible,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalueDate: s.valueDate,\n\t\t\t\t\t\t\t\t\t\t\t\t\ttags: s.tags,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t\t: acc,\n\t\t\t\t\t\t\tacc,\n\t\t\t\t\t\t) ?? acc,\n\t\t\t\t{} as { [id: string]: Version<ServiceMetadata>[] },\n\t\t\t) //index services in history by id\n\t}\n\n\tsetMetadata(meta: ServiceMetadata, id?: string): void {\n\t\tconst service = (id && this.getServiceInCurrentContact(id)) || this.serviceFactory(meta.label, id)\n\t\tif (!service.id) {\n\t\t\tthrow new Error('Service id must be defined')\n\t\t}\n\t\tif (\n\t\t\t(meta.responsible && service.responsible !== meta.responsible) ||\n\t\t\t(meta.valueDate && service.valueDate !== meta.valueDate) ||\n\t\t\t(meta.codes && service.codes !== meta.codes) ||\n\t\t\t(meta.tags && service.tags !== meta.tags)\n\t\t) {\n\t\t\tconst newService = new Service({ ...service, modified: Date.now() })\n\t\t\tmeta.responsible && (newService.responsible = meta.responsible)\n\t\t\tmeta.valueDate && (newService.valueDate = meta.valueDate)\n\t\t\tmeta.codes && (newService.codes = normalizeCodes(meta.codes))\n\t\t\tmeta.tags && (newService.tags = normalizeCodes(meta.tags))\n\n\t\t\tconst newFormValuesContainer = new ContactFormValuesContainer(\n\t\t\t\tthis.rootForm,\n\t\t\t\t{\n\t\t\t\t\t...this.currentContact,\n\t\t\t\t\tservices: this.currentContact.services?.map((s) => (s.id === service.id ? newService : s)),\n\t\t\t\t},\n\t\t\t\tthis.contactsHistory,\n\t\t\t\tthis.serviceFactory,\n\t\t\t\tthis.children,\n\t\t\t\tthis.formFactory,\n\t\t\t\tthis.formRecycler,\n\t\t\t\tthis.changeListeners,\n\t\t\t\tthis.anchorId,\n\t\t\t\ttrue,\n\t\t\t)\n\n\t\t\tthis.changeListeners.forEach((l) => notify(l, newFormValuesContainer, [meta.label]))\n\t\t}\n\t}\n\n\tsetValue(\n\t\tlabel: string,\n\t\tlanguage: string,\n\t\tvalue?: Service,\n\t\tid?: string,\n\t\tmetadata?: ServiceMetadata,\n\t\tchangeListenersOverrider?: (fvc: ContactFormValuesContainer, changedKeys: string[] | null) => void,\n\t): void {\n\t\tconst service = (id && this.getServicesInHistory((sid: string, history) => (sid === id ? history.map((x) => x.revision) : []))[id]?.[0]?.value) || this.serviceFactory(label, id)\n\t\tif (!service.id) {\n\t\t\tthrow new Error('Service id must be defined')\n\t\t}\n\t\tconsole.log(\n\t\t\t`Setting value of service ${service.label} [${service.id}] to ${Object.entries(value?.content ?? {}).map(([k, c]) => `${k}: ${JSON.stringify(contentToPrimitiveType(k, c))}`)} and md`,\n\t\t\tmetadata,\n\t\t)\n\t\tconst newContent = value?.content?.[language]\n\n\t\tconst newCodes = value?.codes ? normalizeCodes(value.codes) : []\n\t\tif (!isContentEqual(service.content?.[language], newContent) || (newCodes && !areCodesEqual(newCodes, service.codes ?? []))) {\n\t\t\tconst newService = new Service({ ...service, modified: Date.now() })\n\t\t\tconst newContents = newContent\n\t\t\t\t? {\n\t\t\t\t\t\t...(service.content || {}),\n\t\t\t\t\t\t[language]: newContent,\n\t\t\t\t }\n\t\t\t\t: { ...(service.content || {}) }\n\t\t\tif (!newContent) {\n\t\t\t\tdelete newContents[language]\n\t\t\t}\n\n\t\t\tlet newCurrentContact: Contact\n\t\t\tif (!Object.entries(newContents).filter(([, cnt]) => cnt !== undefined).length) {\n\t\t\t\tnewCurrentContact = {\n\t\t\t\t\t...this.currentContact,\n\t\t\t\t\tsubContacts: (this.currentContact.subContacts ?? []).some((sc) => sc.formId === this.rootForm.id)\n\t\t\t\t\t\t? (this.currentContact.subContacts ?? []).map((sc) => {\n\t\t\t\t\t\t\t\tif (sc.formId === this.rootForm.id) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...sc,\n\t\t\t\t\t\t\t\t\t\tservices: (sc.services ?? []).filter((s) => s.serviceId !== service.id).concat([{ serviceId: service.id }]),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn sc\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t })\n\t\t\t\t\t\t: (this.currentContact.subContacts ?? []).concat({ formId: this.rootForm.id, services: [{ serviceId: service.id }] }),\n\t\t\t\t\tservices: (this.currentContact.services ?? []).some((s) => s.id === service.id)\n\t\t\t\t\t\t? (this.currentContact.services ?? []).filter((s) => s.id !== service.id)\n\t\t\t\t\t\t: [...(this.currentContact.services ?? [])],\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnewService.content = newContents\n\t\t\t\tnewService.codes = newCodes\n\n\t\t\t\tif (metadata) {\n\t\t\t\t\tnewService.responsible = metadata.responsible ?? newService.responsible\n\t\t\t\t\tnewService.valueDate = metadata.valueDate ?? newService.valueDate\n\t\t\t\t\tnewService.tags = metadata.tags ? normalizeCodes(metadata.tags) : newService.tags\n\t\t\t\t\tnewService.label = metadata.label ?? newService.label\n\t\t\t\t}\n\n\t\t\t\tnewCurrentContact = {\n\t\t\t\t\t...this.currentContact,\n\t\t\t\t\tsubContacts: (this.currentContact.subContacts ?? []).some((sc) => sc.formId === this.rootForm.id)\n\t\t\t\t\t\t? (this.currentContact.subContacts ?? []).map((sc) => {\n\t\t\t\t\t\t\t\tif (sc.formId === this.rootForm.id) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...sc,\n\t\t\t\t\t\t\t\t\t\tservices: (sc.services ?? []).filter((s) => s.serviceId !== service.id).concat([{ serviceId: service.id }]),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn sc\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t })\n\t\t\t\t\t\t: (this.currentContact.subContacts ?? []).concat({ formId: this.rootForm.id, services: [{ serviceId: service.id }] }),\n\t\t\t\t\tservices: (this.currentContact.services ?? []).some((s) => s.id === service.id)\n\t\t\t\t\t\t? (this.currentContact.services ?? []).map((s) => (s.id === service.id ? newService : s))\n\t\t\t\t\t\t: [...(this.currentContact.services ?? []), newService],\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst newFormValuesContainer = new ContactFormValuesContainer(\n\t\t\t\tthis.rootForm,\n\t\t\t\tnewCurrentContact,\n\t\t\t\tthis.contactsHistory.map((c) => (c === this.currentContact ? newCurrentContact : c)),\n\t\t\t\tthis.serviceFactory,\n\t\t\t\tthis.children,\n\t\t\t\tthis.formFactory,\n\t\t\t\tthis.formRecycler,\n\t\t\t\tthis.changeListeners,\n\t\t\t\tthis.anchorId,\n\t\t\t\ttrue,\n\t\t\t)\n\n\t\t\tchangeListenersOverrider ? changeListenersOverrider(newFormValuesContainer, [label]) : this.changeListeners.forEach((l) => notify(l, newFormValuesContainer, [label]))\n\t\t}\n\t}\n\n\tdelete(serviceId: string): void {\n\t\tconst service = this.getServiceInCurrentContact(serviceId)\n\t\tif (service) {\n\t\t\tconst newFormValuesContainer = new ContactFormValuesContainer(\n\t\t\t\tthis.rootForm,\n\t\t\t\t{\n\t\t\t\t\t...this.currentContact,\n\t\t\t\t\tservices: this.currentContact.services?.map((s) =>\n\t\t\t\t\t\ts.id === serviceId\n\t\t\t\t\t\t\t? new Service({\n\t\t\t\t\t\t\t\t\t...service,\n\t\t\t\t\t\t\t\t\tendOfLife: Date.now(),\n\t\t\t\t\t\t\t })\n\t\t\t\t\t\t\t: s,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\tthis.contactsHistory,\n\t\t\t\tthis.serviceFactory,\n\t\t\t\tthis.children,\n\t\t\t\tthis.formFactory,\n\t\t\t\tthis.formRecycler,\n\t\t\t\tthis.changeListeners,\n\t\t\t\tthis.anchorId,\n\t\t\t\ttrue,\n\t\t\t)\n\n\t\t\tthis.changeListeners.forEach((l) => notify(l, newFormValuesContainer, [service.label ?? service.id ?? ''] /* only the label is going to propagate the changes for the formulas */))\n\t\t}\n\t}\n\n\ttoMarkdownTable(): string {\n\t\tconst tableRows: [string, string, string][] = []\n\t\tfor (const [, versions] of Object.entries(this.indexedServices)) {\n\t\t\tif (!versions.length) continue\n\t\t\tconst service = versions[0].value\n\t\t\tconst label = service.label ?? service.id ?? ''\n\t\t\tconst modifiedStr = service.modified ? new Date(service.modified).toISOString() : ''\n\t\t\tconst contentParts: string[] = []\n\t\t\tfor (const [lng, cnt] of Object.entries(service.content ?? {})) {\n\t\t\t\tconst primitive = contentToPrimitiveType(lng, cnt)\n\t\t\t\tif (primitive) {\n\t\t\t\t\tcontentParts.push(primitiveTypeToString(primitive))\n\t\t\t\t}\n\t\t\t}\n\t\t\ttableRows.push([label, modifiedStr, contentParts.join(', ')])\n\t\t}\n\t\tconst headers: [string, string, string] = ['Label', 'Modified', 'Content']\n\t\tconst colWidths = headers.map((h, i) => Math.max(h.length, ...tableRows.map((r) => r[i].length)))\n\t\tconst pad = (s: string, w: number) => s + ' '.repeat(w - s.length)\n\t\tconst formatRow = (cells: [string, string, string]) => '| ' + cells.map((c, i) => pad(c, colWidths[i])).join(' | ') + ' |'\n\t\tconst separator = '|' + colWidths.map((w) => '-'.repeat(w + 2)).join('|') + '|'\n\t\treturn [formatRow(headers), separator, ...tableRows.map(formatRow)].join('\\n')\n\t}\n\n\tasync compute<T>(): Promise<ComputationResult<T>> {\n\t\tthrow new Error('Compute not supported at contact level')\n\t}\n\n\t/** returns all services in history that match a selector\n\t *\n\t * @private\n\t * @param revisionsFilter\n\t */\n\tprivate getServicesInHistory(revisionsFilter: (id: string, history: Version<ServiceMetadata>[]) => (string | null)[]): VersionedData<Service> {\n\t\t//index services in history by id\n\t\treturn Object.entries(this.indexedServices)\n\t\t\t.map(([id, history]) => {\n\t\t\t\tconst keptRevisions = revisionsFilter(\n\t\t\t\t\tid,\n\t\t\t\t\thistory.map(({ revision, modified, value: s }) => ({\n\t\t\t\t\t\trevision,\n\t\t\t\t\t\tmodified,\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\tlabel: s.label ?? s.id ?? '',\n\t\t\t\t\t\t\towner: s.responsible,\n\t\t\t\t\t\t\tvalueDate: s.valueDate,\n\t\t\t\t\t\t\tcodes: s.codes,\n\t\t\t\t\t\t\ttags: s.tags,\n\t\t\t\t\t\t},\n\t\t\t\t\t})),\n\t\t\t\t)\n\t\t\t\treturn [id, history.filter(({ revision }) => keptRevisions.includes(revision))] as [string, Version<Service>[]]\n\t\t\t})\n\t\t\t.reduce((acc, [id, history]) => ({ ...acc, [id]: history }), {})\n\t}\n\n\tasync addChild(anchorId: string, templateId: string, label: string): Promise<void> {\n\t\tconst parentId = this.rootForm.id\n\t\tif (!parentId) return\n\n\t\tconst newForm = await this.formFactory(parentId, anchorId, templateId, label)\n\t\tconst childFVC = new ContactFormValuesContainer(newForm, this.currentContact, this.contactsHistory, this.serviceFactory, [], this.formFactory, this.formRecycler, [], anchorId, false)\n\n\t\tconst newContactFormValuesContainer = new ContactFormValuesContainer(\n\t\t\tthis.rootForm,\n\t\t\tthis.currentContact,\n\t\t\tthis.contactsHistory,\n\t\t\tthis.serviceFactory,\n\t\t\t[...this.children, childFVC],\n\t\t\tthis.formFactory,\n\t\t\tthis.formRecycler,\n\t\t\tthis.changeListeners,\n\t\t\tthis.anchorId,\n\t\t\ttrue,\n\t\t)\n\t\tnewContactFormValuesContainer.registerChildFormValuesContainer(childFVC, anchorId)\n\t\tthis.changeListeners.forEach((l) => {\n\t\t\tnotify(l, newContactFormValuesContainer, null)\n\t\t})\n\t}\n\n\tprivate getServiceInCurrentContact(id: string): Service | undefined {\n\t\tconst service = (this.currentContact.services || [])?.find((s) => s.id === id)\n\t\treturn service ?? undefined\n\t}\n\n\tprivate static collectFormIds(container: ContactFormValuesContainer): Set<string> {\n\t\tconst ids = new Set<string>()\n\t\tif (container.rootForm.id) ids.add(container.rootForm.id)\n\t\tfor (const child of container.children) {\n\t\t\tfor (const id of ContactFormValuesContainer.collectFormIds(child)) {\n\t\t\t\tids.add(id)\n\t\t\t}\n\t\t}\n\t\treturn ids\n\t}\n\n\tasync removeChild(container: ContactFormValuesContainer): Promise<void> {\n\t\t// Collect all form IDs in the subtree being removed (child + its descendants)\n\t\tconst removedFormIds = ContactFormValuesContainer.collectFormIds(container)\n\n\t\t// Collect service IDs linked to any removed form across current contact and history\n\t\tconst allContacts = [this.currentContact, ...this.contactsHistory]\n\t\tconst childServiceIds = new Set<string>()\n\t\tfor (const ctc of allContacts) {\n\t\t\tfor (const sc of ctc.subContacts ?? []) {\n\t\t\t\tif (sc.formId && removedFormIds.has(sc.formId)) {\n\t\t\t\t\tfor (const sRef of sc.services ?? []) {\n\t\t\t\t\t\tif (sRef.serviceId) childServiceIds.add(sRef.serviceId)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Build the updated current contact:\n\t\t// - Services that exist in history must be marked with endOfLife (not removed)\n\t\t// - Services that only exist in the current contact can be simply removed\n\t\t// - Remove subContact entries for all removed forms\n\t\tconst now = Date.now()\n\n\t\t// Determine which child services exist in history\n\t\tconst childServiceIdsInHistory = new Set<string>()\n\t\tfor (const ctc of this.contactsHistory) {\n\t\t\tfor (const sc of ctc.subContacts ?? []) {\n\t\t\t\tif (sc.formId && removedFormIds.has(sc.formId)) {\n\t\t\t\t\tfor (const sRef of sc.services ?? []) {\n\t\t\t\t\t\tif (sRef.serviceId && childServiceIds.has(sRef.serviceId)) childServiceIdsInHistory.add(sRef.serviceId)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst existingServiceIds = new Set((this.currentContact.services ?? []).map((s) => s.id))\n\n\t\t// Services in current contact: mark with endOfLife if in history, remove otherwise\n\t\tconst updatedServices = (this.currentContact.services ?? [])\n\t\t\t.filter((s) => !(s.id && childServiceIds.has(s.id) && !childServiceIdsInHistory.has(s.id)))\n\t\t\t.map((s) => (s.id && childServiceIdsInHistory.has(s.id) ? new Service({ id: s.id, created: s.created, modified: now, endOfLife: now }) : s))\n\n\t\t// Services only in history (not in current contact): add with endOfLife\n\t\tfor (const serviceId of childServiceIdsInHistory) {\n\t\t\tif (!existingServiceIds.has(serviceId)) {\n\t\t\t\tfor (const ctc of this.contactsHistory) {\n\t\t\t\t\tconst historyService = ctc.services?.find((s) => s.id === serviceId)\n\t\t\t\t\tif (historyService) {\n\t\t\t\t\t\tupdatedServices.push(new Service({ id: historyService.id, created: historyService.created, modified: now, endOfLife: now }))\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Remove subContact entries for all removed forms\n\t\tconst updatedSubContacts = (this.currentContact.subContacts ?? []).filter((sc) => !sc.formId || !removedFormIds.has(sc.formId))\n\n\t\tconst updatedContact = {\n\t\t\t...this.currentContact,\n\t\t\tservices: updatedServices,\n\t\t\tsubContacts: updatedSubContacts,\n\t\t}\n\n\t\t// Recycle all removed forms\n\t\tfor (const formId of removedFormIds) {\n\t\t\tawait this.formRecycler(formId)\n\t\t}\n\n\t\tconst newContactFormValuesContainer = new ContactFormValuesContainer(\n\t\t\tthis.rootForm,\n\t\t\tupdatedContact,\n\t\t\tthis.contactsHistory,\n\t\t\tthis.serviceFactory,\n\t\t\tthis.children.filter((c) => c.rootForm.id !== container.rootForm.id),\n\t\t\tthis.formFactory,\n\t\t\tthis.formRecycler,\n\t\t\tthis.changeListeners,\n\t\t\tthis.anchorId,\n\t\t\ttrue,\n\t\t)\n\t\tthis.changeListeners.forEach((l) => notify(l, newContactFormValuesContainer, [`subForms_${container.anchorId ?? 'all'}`]))\n\t}\n}\n\n// Runtime validation for FieldValue — guards against mistyped data coming from\n// external callers (formulas, SDK bridges, etc.) where the TypeScript types may\n// not match the actual runtime values.\nconst validatePrimitiveType = (pt: PrimitiveType, path: string): void => {\n\tconst v: any = pt.value\n\tswitch (pt.type) {\n\t\tcase 'string':\n\t\t\tif (typeof v !== 'string') {\n\t\t\t\tthrow new Error(`${path}: expected string value, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'number':\n\t\t\tif (typeof v !== 'number') {\n\t\t\t\tthrow new Error(`${path}: expected number value, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'boolean':\n\t\t\tif (typeof v !== 'boolean') {\n\t\t\t\tthrow new Error(`${path}: expected boolean value, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'timestamp':\n\t\t\tif (typeof v !== 'number') {\n\t\t\t\tthrow new Error(`${path}: expected number value for timestamp, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'datetime':\n\t\t\tif (typeof v !== 'number') {\n\t\t\t\tthrow new Error(`${path}: expected number value for datetime, got ${typeof v}`)\n\t\t\t}\n\t\t\tbreak\n\t\tcase 'measure': {\n\t\t\tconst m: any = pt\n\t\t\tif (m.value !== undefined && typeof m.value !== 'number') {\n\t\t\t\tthrow new Error(`${path}: expected number or undefined value for measure, got ${typeof m.value}`)\n\t\t\t}\n\t\t\tif (m.unit !== undefined && typeof m.unit !== 'string') {\n\t\t\t\tthrow new Error(`${path}: expected string or undefined unit for measure, got ${typeof m.unit}`)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'compound':\n\t\t\tif (typeof v !== 'object' || v === null || Array.isArray(v)) {\n\t\t\t\tthrow new Error(`${path}: expected object value for compound, got ${Array.isArray(v) ? 'array' : typeof v}`)\n\t\t\t}\n\t\t\tfor (const [key, subValue] of Object.entries(v as { [label: string]: PrimitiveType })) {\n\t\t\t\tvalidatePrimitiveType(subValue, `${path}.compound[${key}]`)\n\t\t\t}\n\t\t\tbreak\n\t\tdefault:\n\t\t\tthrow new Error(`${path}: unknown PrimitiveType type: ${(pt as any).type}`)\n\t}\n}\n\nconst validateCode = (code: { id: string; label?: { [key: string]: string } }, path: string): void => {\n\tconst id: any = code.id\n\tif (!id || typeof id !== 'string') {\n\t\tthrow new Error(`${path}: code must have a non-empty string id, got ${JSON.stringify(id)}`)\n\t}\n}\n\nconst validateFieldValue = (fv: FieldValue, language: string, label: string): void => {\n\tconst pt = fv.content[language]\n\tif (pt) {\n\t\tvalidatePrimitiveType(pt, `FieldValue[${label}].content[${language}]`)\n\t}\n\tif (fv.codes) {\n\t\tfv.codes.forEach((code, i) => validateCode(code, `FieldValue[${label}].codes[${i}]`))\n\t}\n}\n\nconst setValueOnContactFormValuesContainer = (\n\tcfvc: ContactFormValuesContainer,\n\tlabel: string,\n\tlanguage: string,\n\tfv?: FieldValue,\n\tid?: string,\n\tmetadata?: FieldMetadata,\n\tchangeListenersOverrider?: (fvc: ContactFormValuesContainer, changedKeys: string[] | null) => void,\n) => {\n\tif (fv) {\n\t\tvalidateFieldValue(fv, language, label)\n\t}\n\tconst value = fv?.content[language]\n\tcfvc.setValue(\n\t\tlabel,\n\t\tlanguage,\n\t\t{\n\t\t\tid: id,\n\t\t\tcodes: fv?.codes ?? [],\n\t\t\tcontent: value\n\t\t\t\t? {\n\t\t\t\t\t\t[language]: primitiveTypeToContent(language, value),\n\t\t\t\t }\n\t\t\t\t: undefined,\n\t\t},\n\t\tid,\n\t\tmetadata\n\t\t\t? {\n\t\t\t\t\tlabel: metadata?.label ?? label,\n\t\t\t\t\tresponsible: metadata?.owner,\n\t\t\t\t\tvalueDate: metadata?.valueDate,\n\t\t\t\t\ttags: metadata?.tags,\n\t\t\t }\n\t\t\t: undefined,\n\t\tchangeListenersOverrider,\n\t)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icure/form",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",