@icure/api 8.0.63 → 8.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/icc-api/api/internal/IccExchangeDataApi.d.ts +2 -0
  2. package/icc-api/api/internal/IccExchangeDataApi.js +10 -0
  3. package/icc-api/api/internal/IccExchangeDataApi.js.map +1 -1
  4. package/icc-api/iccApi.d.ts +0 -1
  5. package/icc-api/iccApi.js +0 -1
  6. package/icc-api/iccApi.js.map +1 -1
  7. package/icc-api/index.d.ts +0 -1
  8. package/icc-api/index.js +0 -1
  9. package/icc-api/index.js.map +1 -1
  10. package/icc-x-api/crypto/AccessControlSecretUtils.d.ts +4 -13
  11. package/icc-x-api/crypto/AccessControlSecretUtils.js +19 -29
  12. package/icc-x-api/crypto/AccessControlSecretUtils.js.map +1 -1
  13. package/icc-x-api/crypto/BaseExchangeDataManager.d.ts +6 -2
  14. package/icc-x-api/crypto/BaseExchangeDataManager.js +26 -9
  15. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
  16. package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +2 -3
  17. package/icc-x-api/crypto/BaseExchangeKeysManager.js +8 -16
  18. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
  19. package/icc-x-api/crypto/CryptoPrimitives.d.ts +2 -0
  20. package/icc-x-api/crypto/CryptoPrimitives.js +3 -0
  21. package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -1
  22. package/icc-x-api/crypto/DelegationsDeAnonymization.d.ts +3 -3
  23. package/icc-x-api/crypto/DelegationsDeAnonymization.js +7 -7
  24. package/icc-x-api/crypto/DelegationsDeAnonymization.js.map +1 -1
  25. package/icc-x-api/crypto/ExchangeDataManager.d.ts +19 -29
  26. package/icc-x-api/crypto/ExchangeDataManager.js +200 -225
  27. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  28. package/icc-x-api/crypto/ExchangeDataMapManager.js +6 -4
  29. package/icc-x-api/crypto/ExchangeDataMapManager.js.map +1 -1
  30. package/icc-x-api/crypto/ExchangeKeysManager.d.ts +4 -16
  31. package/icc-x-api/crypto/ExchangeKeysManager.js +44 -41
  32. package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -1
  33. package/icc-x-api/crypto/ExtendedApisUtils.d.ts +47 -25
  34. package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -1
  35. package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +19 -18
  36. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +213 -134
  37. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
  38. package/icc-x-api/crypto/HMACUtils.d.ts +2 -2
  39. package/icc-x-api/crypto/HMACUtils.js +3 -4
  40. package/icc-x-api/crypto/HMACUtils.js.map +1 -1
  41. package/icc-x-api/crypto/NativeCryptoPrimitivesBridge.d.ts +1 -0
  42. package/icc-x-api/crypto/NativeCryptoPrimitivesBridge.js +5 -0
  43. package/icc-x-api/crypto/NativeCryptoPrimitivesBridge.js.map +1 -1
  44. package/icc-x-api/crypto/SecureDelegationsManager.d.ts +0 -1
  45. package/icc-x-api/crypto/SecureDelegationsManager.js +17 -49
  46. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
  47. package/icc-x-api/crypto/SecurityMetadataDecryptor.d.ts +59 -90
  48. package/icc-x-api/crypto/SecurityMetadataDecryptor.js +470 -56
  49. package/icc-x-api/crypto/SecurityMetadataDecryptor.js.map +1 -1
  50. package/icc-x-api/crypto/ShamirKeysManager.js +1 -1
  51. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
  52. package/icc-x-api/crypto/TransferKeysManager.d.ts +1 -3
  53. package/icc-x-api/crypto/TransferKeysManager.js +2 -4
  54. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
  55. package/icc-x-api/icc-accesslog-x-api.d.ts +2 -2
  56. package/icc-x-api/icc-accesslog-x-api.js +7 -3
  57. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  58. package/icc-x-api/icc-calendar-item-x-api.js +4 -2
  59. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  60. package/icc-x-api/icc-contact-x-api.d.ts +0 -1
  61. package/icc-x-api/icc-contact-x-api.js +33 -48
  62. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  63. package/icc-x-api/icc-crypto-x-api.js +1 -1
  64. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  65. package/icc-x-api/icc-document-x-api.d.ts +2 -2
  66. package/icc-x-api/icc-document-x-api.js +45 -42
  67. package/icc-x-api/icc-document-x-api.js.map +1 -1
  68. package/icc-x-api/icc-form-x-api.js +3 -1
  69. package/icc-x-api/icc-form-x-api.js.map +1 -1
  70. package/icc-x-api/icc-hcparty-x-api.d.ts +1 -1
  71. package/icc-x-api/icc-hcparty-x-api.js +62 -25
  72. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  73. package/icc-x-api/icc-helement-x-api.js +4 -4
  74. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  75. package/icc-x-api/icc-maintenance-task-x-api.js +4 -2
  76. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  77. package/icc-x-api/icc-message-x-api.js +4 -2
  78. package/icc-x-api/icc-message-x-api.js.map +1 -1
  79. package/icc-x-api/icc-patient-x-api.js +5 -7
  80. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  81. package/icc-x-api/icc-topic-x-api.js +2 -2
  82. package/icc-x-api/icc-topic-x-api.js.map +1 -1
  83. package/icc-x-api/index.d.ts +1 -2
  84. package/icc-x-api/index.js +7 -13
  85. package/icc-x-api/index.js.map +1 -1
  86. package/icc-x-api/utils/crypto-utils.d.ts +6 -4
  87. package/icc-x-api/utils/crypto-utils.js +27 -6
  88. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  89. package/icc-x-api/utils/simple-lru-cache.d.ts +19 -0
  90. package/icc-x-api/utils/simple-lru-cache.js +90 -0
  91. package/icc-x-api/utils/simple-lru-cache.js.map +1 -0
  92. package/package.json +4 -2
  93. package/test/icc-x-api/crud/entities-crud-test-interface.js +0 -8
  94. package/test/icc-x-api/crud/entities-crud-test-interface.js.map +1 -1
  95. package/test/icc-x-api/crypto/exchange-data-manager-test.js +74 -92
  96. package/test/icc-x-api/crypto/exchange-data-manager-test.js.map +1 -1
  97. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js.map +1 -1
  98. package/test/icc-x-api/crypto/secure-delegations-manager-test.js +27 -15
  99. package/test/icc-x-api/crypto/secure-delegations-manager-test.js.map +1 -1
  100. package/test/icc-x-api/icc-hcparty-x-api-test.d.ts +1 -0
  101. package/test/icc-x-api/icc-hcparty-x-api-test.js +55 -0
  102. package/test/icc-x-api/icc-hcparty-x-api-test.js.map +1 -0
  103. package/test/utils/FakeEncryptionKeysManager.d.ts +1 -0
  104. package/test/utils/FakeEncryptionKeysManager.js +11 -0
  105. package/test/utils/FakeEncryptionKeysManager.js.map +1 -1
  106. package/test/utils/FakeExchangeDataApi.d.ts +4 -2
  107. package/test/utils/FakeExchangeDataApi.js +24 -6
  108. package/test/utils/FakeExchangeDataApi.js.map +1 -1
  109. package/test/utils/FakeExchangeDataManager.d.ts +10 -10
  110. package/test/utils/FakeExchangeDataManager.js +12 -22
  111. package/test/utils/FakeExchangeDataManager.js.map +1 -1
  112. package/icc-api/api/IccArticleApi.d.ts +0 -72
  113. package/icc-api/api/IccArticleApi.js +0 -149
  114. package/icc-api/api/IccArticleApi.js.map +0 -1
  115. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.d.ts +0 -33
  116. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js +0 -141
  117. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js.map +0 -1
  118. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.d.ts +0 -46
  119. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js +0 -312
  120. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js.map +0 -1
  121. package/icc-x-api/crypto/UserSignatureKeysManager.d.ts +0 -26
  122. package/icc-x-api/crypto/UserSignatureKeysManager.js +0 -78
  123. package/icc-x-api/crypto/UserSignatureKeysManager.js.map +0 -1
  124. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.d.ts +0 -1
  125. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.js +0 -393
  126. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.js.map +0 -1
  127. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.d.ts +0 -1
  128. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.js +0 -213
  129. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.js.map +0 -1
  130. package/test/icc-x-api/crypto/signature-keys-manager-test.d.ts +0 -1
  131. package/test/icc-x-api/crypto/signature-keys-manager-test.js +0 -44
  132. package/test/icc-x-api/crypto/signature-keys-manager-test.js.map +0 -1
  133. package/test/utils/FakeSignatureKeysManager.d.ts +0 -16
  134. package/test/utils/FakeSignatureKeysManager.js +0 -54
  135. package/test/utils/FakeSignatureKeysManager.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"icc-form-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-form-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAuC;AAGvC,4BAA2B;AAC3B,kDAAiD;AAGjD,0EAAgG;AAChG,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAOzD,mCAAsD;AAEtD,qCAAqC;AACrC,MAAa,WAAY,SAAQ,oBAAU;IAIzC,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,IAAI,CAA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AAC,CAAC,CAC9B;iBACA,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACvF,CAAC;KAAA;IAED,yBAAyB,CACvB,MAAmB;QAEnB,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,IAAI,EAAE,CAAC,CAAA;IAC9H,CAAC;IAED,mBAAmB,CAAC,MAAmB;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAA;IAC1G,CAAC;IAED,uCAAuC,CAAC,MAAmB,EAAE,SAAmB;QAC9E,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAA;IACjJ,CAAC;CACF;AApQD,kCAoQC","sourcesContent":["import { IccFormApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\n\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { EntityWithDelegationTypeName } from './utils'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccFormXApi extends IccFormApi implements EncryptedEntityXApi<models.Form> {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Form))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n private readonly autofillAuthor: boolean,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of form with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this form refers to.\n * @param c initialised data for the form. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the form. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * @return a new instance of form.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n c: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n preferredSfk?: string\n } = {}\n ) {\n const form = {\n ...(c ?? {}),\n _type: 'org.taktik.icure.entities.Form',\n id: c?.id ?? this.crypto.primitives.randomUuid(),\n created: c?.created ?? new Date().getTime(),\n modified: c?.modified ?? new Date().getTime(),\n responsible: c?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: c?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: c?.codes ?? [],\n tags: c?.tags ?? [],\n }\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk =\n options.preferredSfk ??\n (await this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: EntityWithDelegationTypeName.Patient }))\n if (!sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = {\n ...Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n ),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Form(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(form, EntityWithDelegationTypeName.Form, patient.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all contacts with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the contacts of the patient.\n * @deprecated use {@link findIdsBy} instead.\n * @param hcpartyId\n * @param patient\n * @param usingPost (Promise)\n */\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n let forms: Array<models.Form> = await (usingPost\n ? this.findFormsByHCPartyPatientForeignKeysUsingPost(hcpartyId!, undefined, undefined, undefined, _.uniq(extractedKeys))\n : this.findFormsByHCPartyPatientForeignKeys(hcpartyId!, _.uniq(extractedKeys).join(',')))\n return await this.decrypt(hcpartyId, forms)\n }\n\n /**\n * Same as {@link findBy} but it will only return the ids of the forms. It can also filter the forms where Form.openingDate is between\n * startDate and endDate in ascending or descending order by that field. (default: ascending).\n */\n async findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n return this.findFormIdsByDataOwnerPatientOpeningDate(hcpartyId, _.uniq(extractedKeys), startDate, endDate, descending)\n }\n\n decrypt(hcpartyId: string, forms: Array<models.Form>) {\n return Promise.all(\n forms.map((form) =>\n this.crypto.xapi.decryptEntity(form, EntityWithDelegationTypeName.Form, (x) => new models.Form(x)).then(({ entity }) => entity)\n )\n )\n }\n\n /**\n * @param form a form\n * @return the id of the patient that the form refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(form: models.Form): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: form, type: EntityWithDelegationTypeName.Form }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given form\n */\n async hasWriteAccess(form: models.Form): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: form, type: EntityWithDelegationTypeName.Form })\n }\n\n /**\n * Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the form.\n * @param form the form to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * form does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n form: models.Form,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Form> {\n return this.shareWithMany(form, { [delegateId]: options })\n }\n\n /**\n * Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param form the form to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * form does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n form: models.Form,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Form> {\n return (await this.tryShareWithMany(form, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param form the form to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * form does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async tryShareWithMany(\n form: models.Form,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Form>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(form, EntityWithDelegationTypeName.Form)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyForm(entityWithEncryptionKey) : form\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Form,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareForms(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Form\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Form })\n }\n\n getEncryptionKeysOf(entity: models.Form): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Form }, undefined)\n }\n\n createDelegationDeAnonymizationMetadata(entity: models.Form, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Form }, delegates)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-form-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-form-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAuC;AAGvC,4BAA2B;AAC3B,kDAAiD;AAGjD,0EAAgG;AAChG,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAOzD,mCAAsD;AAEtD,qCAAqC;AACrC,MAAa,WAAY,SAAQ,oBAAU;IAIzC,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CA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H,EACD,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAC9B;iBACA,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACvF,CAAC;KAAA;IAED,yBAAyB,CACvB,MAAmB;QAEnB,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,IAAI,EAAE,CAAC,CAAA;IAC9H,CAAC;IAED,mBAAmB,CAAC,MAAmB;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAA;IAC1G,CAAC;IAED,uCAAuC,CAAC,MAAmB,EAAE,SAAmB;QAC9E,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAA;IACjJ,CAAC;CACF;AAlQD,kCAkQC","sourcesContent":["import { IccFormApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\n\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { EntityWithDelegationTypeName } from './utils'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccFormXApi extends IccFormApi implements EncryptedEntityXApi<models.Form> {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Form))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n private readonly autofillAuthor: boolean,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of form with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this form refers to.\n * @param c initialised data for the form. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the form. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * @return a new instance of form.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n c: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n preferredSfk?: string\n } = {}\n ) {\n const form = {\n ...(c ?? {}),\n _type: 'org.taktik.icure.entities.Form',\n id: c?.id ?? this.crypto.primitives.randomUuid(),\n created: c?.created ?? new Date().getTime(),\n modified: c?.modified ?? new Date().getTime(),\n responsible: c?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: c?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: c?.codes ?? [],\n tags: c?.tags ?? [],\n }\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk =\n options.preferredSfk ??\n (await this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: EntityWithDelegationTypeName.Patient }))\n if (!sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = {\n ...Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n ),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Form(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(form, EntityWithDelegationTypeName.Form, patient.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all contacts with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the contacts of the patient.\n * @deprecated use {@link findIdsBy} instead.\n * @param hcpartyId\n * @param patient\n * @param usingPost (Promise)\n */\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n let forms: Array<models.Form> = await (usingPost\n ? this.findFormsByHCPartyPatientForeignKeysUsingPost(hcpartyId!, undefined, undefined, undefined, _.uniq(extractedKeys))\n : this.findFormsByHCPartyPatientForeignKeys(hcpartyId!, _.uniq(extractedKeys).join(',')))\n return await this.decrypt(hcpartyId, forms)\n }\n\n /**\n * Same as {@link findBy} but it will only return the ids of the forms. It can also filter the forms where Form.openingDate is between\n * startDate and endDate in ascending or descending order by that field. (default: ascending).\n */\n async findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n return this.findFormIdsByDataOwnerPatientOpeningDate(hcpartyId, _.uniq(extractedKeys), startDate, endDate, descending)\n }\n\n async decrypt(hcpartyId: string, forms: Array<models.Form>) {\n return (await this.crypto.xapi.tryDecryptEntities(forms, EntityWithDelegationTypeName.Form, (x) => new models.Form(x))).map(\n ({ entity }) => entity\n )\n }\n\n /**\n * @param form a form\n * @return the id of the patient that the form refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(form: models.Form): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: form, type: EntityWithDelegationTypeName.Form }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given form\n */\n async hasWriteAccess(form: models.Form): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: form, type: EntityWithDelegationTypeName.Form })\n }\n\n /**\n * Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the form.\n * @param form the form to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * form does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n form: models.Form,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Form> {\n return this.shareWithMany(form, { [delegateId]: options })\n }\n\n /**\n * Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param form the form to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * form does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n form: models.Form,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Form> {\n return (await this.tryShareWithMany(form, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param form the form to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * form does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async tryShareWithMany(\n form: models.Form,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Form>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(form, EntityWithDelegationTypeName.Form)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyForm(entityWithEncryptionKey) : form\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Form,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareForms(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Form\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Form })\n }\n\n getEncryptionKeysOf(entity: models.Form): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Form }, undefined)\n }\n\n createDelegationDeAnonymizationMetadata(entity: models.Form, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Form }, delegates)\n }\n}\n"]}
@@ -22,7 +22,7 @@ export declare class IccHcpartyXApi extends IccHcpartyApi {
22
22
  }, authenticationProvider: AuthenticationProvider | undefined, authApi: IccAuthApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
23
23
  private getHcPartyFromCache;
24
24
  completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined;
25
- putHcPartyInCache(key: string, value?: Promise<HealthcareParty> | null): Promise<HealthcareParty>;
25
+ putHcPartyInCache(key: string, hcpPromise: Promise<HealthcareParty>): Promise<HealthcareParty>;
26
26
  createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty>;
27
27
  createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty>;
28
28
  modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any>;
@@ -58,15 +58,9 @@ class IccHcpartyXApi extends icc_api_1.IccHcpartyApi {
58
58
  }
59
59
  return finalHcParty;
60
60
  }
61
- putHcPartyInCache(key, value = null) {
62
- const hcp = value ||
63
- super.getHealthcareParty(key).catch((e) => {
64
- console.log(`Evict key ${key} because of error`);
65
- delete this.hcPartyCache[key];
66
- throw e;
67
- });
68
- this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcp];
69
- return hcp;
61
+ putHcPartyInCache(key, hcpPromise) {
62
+ this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcpPromise];
63
+ return hcpPromise;
70
64
  }
71
65
  createHealthcareParty(body) {
72
66
  return super.createHealthcareParty(this.completeNames(body));
@@ -82,28 +76,71 @@ class IccHcpartyXApi extends icc_api_1.IccHcpartyApi {
82
76
  return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id, Promise.resolve(hcp)));
83
77
  }
84
78
  getHealthcareParty(healthcarePartyId, bypassCache = false) {
85
- const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId);
86
- return fromCache || this.putHcPartyInCache(healthcarePartyId);
79
+ const _super = Object.create(null, {
80
+ getHealthcareParty: { get: () => super.getHealthcareParty }
81
+ });
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId);
84
+ if (fromCache) {
85
+ try {
86
+ return yield fromCache;
87
+ }
88
+ catch (_a) {
89
+ if (this.hcPartyCache[healthcarePartyId][1] === fromCache) {
90
+ delete this.hcPartyCache[healthcarePartyId];
91
+ }
92
+ return this.getHealthcareParty(healthcarePartyId, bypassCache);
93
+ }
94
+ }
95
+ else {
96
+ return yield this.putHcPartyInCache(healthcarePartyId, _super.getHealthcareParty.call(this, healthcarePartyId));
97
+ }
98
+ });
87
99
  }
88
100
  getHealthcarePartyHierarchyIds(healthcarePartyId, bypassCache = false) {
89
- const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId);
90
- return (fromCache || this.putHcPartyInCache(healthcarePartyId)).then((hcp) => __awaiter(this, void 0, void 0, function* () {
101
+ return this.getHealthcareParty(healthcarePartyId, bypassCache).then((hcp) => __awaiter(this, void 0, void 0, function* () {
91
102
  return hcp ? (hcp.parentId ? (yield this.getHealthcarePartyHierarchyIds(hcp.parentId, bypassCache)).concat([hcp.id]) : [hcp.id]) : [];
92
103
  }));
93
104
  }
94
105
  getHealthcareParties(healthcarePartyIds) {
95
- const ids = healthcarePartyIds.ids;
96
- if (!ids || !ids.length) {
97
- return Promise.resolve([]);
98
- }
99
- const cached = ids.map((id) => [id, this.getHcPartyFromCache(id)]);
100
- const toFetch = cached.filter((x) => !x[1]).map((x) => x[0]);
101
- if (!toFetch.length) {
102
- return Promise.all(cached.map((x) => x[1]));
103
- }
104
- const prom = super.getHealthcareParties(new models_1.ListOfIds({ ids: toFetch }));
105
- return Promise.all(cached.map((x) => x[1] ||
106
- this.putHcPartyInCache(x[0], prom.then((hcps) => hcps.find((h) => h.id === x[0])))));
106
+ const _super = Object.create(null, {
107
+ getHealthcareParties: { get: () => super.getHealthcareParties }
108
+ });
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const ids = healthcarePartyIds.ids;
111
+ if (!ids || !ids.length) {
112
+ return Promise.resolve([]);
113
+ }
114
+ const cached = [];
115
+ for (const id of ids) {
116
+ let hcp;
117
+ try {
118
+ hcp = yield this.getHcPartyFromCache(id);
119
+ }
120
+ catch (_a) {
121
+ hcp = null;
122
+ delete this.hcPartyCache[id];
123
+ }
124
+ cached.push([id, hcp]);
125
+ }
126
+ const toFetch = cached.filter((x) => !x[1]).map((x) => x[0]);
127
+ if (!toFetch.length) {
128
+ return Promise.all(cached.map((x) => x[1]));
129
+ }
130
+ const prom = _super.getHealthcareParties.call(this, new models_1.ListOfIds({ ids: toFetch }));
131
+ return Promise.all(cached.map((x) => {
132
+ var _a;
133
+ return (_a = x[1]) !== null && _a !== void 0 ? _a : this.putHcPartyInCache(x[0], prom.then((hcps) => {
134
+ const hcp = hcps.find((h) => h.id === x[0]);
135
+ if (!!hcp) {
136
+ return hcp;
137
+ }
138
+ else {
139
+ throw new Error(`Hcp with id ${x[0]} not found`);
140
+ }
141
+ }));
142
+ }));
143
+ });
107
144
  }
108
145
  getCurrentHealthcareParty() {
109
146
  return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id, Promise.resolve(hcp)));
@@ -1 +1 @@
1
- {"version":3,"file":"icc-hcparty-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-hcparty-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAsD;AAEtD,kDAAiD;AACjD,qDAA8E;AAC9E,0EAAgG;AAEhG,mCAAsE;AACtE,4DAAwE;AACxE,oDAAmD;AAEnD,qCAAqC;AACrC,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,yBAAiD,IAAI,iDAAwB,EAAE,EAC9D,OAAmB,EACpC,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAPtC,YAAO,GAAP,OAAO,CAAY;QARtC,qBAAgB,GAAiD,EAAE,CAAA;QACnE,iBAAY,GAA0D,EAAE,CAAA;QAEhE,0BAAqB,GAAG,MAAO,CAAA;I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H,CAAC;IAED,yBAAyB;QACvB,OAAO,KAAK,CAAC,yBAAyB,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAG,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC/G,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;QAClD,GAAG,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAEvC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAChF,CAAC;IAEK,gCAAgC,CACpC,UAA8C,EAC9C,MAAmD,EACnD,UAA0D,EAC1D,UAA+B,EAAE;;YAEjC,OAAO,IAAA,+BAAuB,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CACtH,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAC/B,CAAA;QACH,CAAC;KAAA;CACF;AAtJD,wCAsJC","sourcesContent":["import { IccAuthApi, IccHcpartyApi } from '../icc-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport * as models from '../icc-api/model/models'\nimport { findName, garnishPersonWithName, hasName } from './utils/person-util'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { AbstractFilter } from './filters/filters'\nimport { subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { ListOfIds } from '../icc-api/model/models'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccHcpartyXApi extends IccHcpartyApi {\n hcPartyKeysCache: { [key: string]: { [key: string]: string } } = {}\n hcPartyCache: { [key: string]: [number, Promise<HealthcareParty>] } = {}\n\n private CACHE_RETENTION_IN_MS = 300_000\n constructor(\n host: string,\n headers: { [key: string]: string },\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n private readonly authApi: IccAuthApi,\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n }\n\n private getHcPartyFromCache(key: string) {\n const hcpInCache = this.hcPartyCache[key]\n const now = Date.now()\n if (hcpInCache && hcpInCache[0] > now) {\n return hcpInCache[1]\n }\n if (!hcpInCache) {\n console.log(`Cache miss for key ${key} because not in cache`)\n } else {\n console.log(`Cache miss for key ${key} because ${hcpInCache[0]} > ${now}`)\n }\n return null\n }\n\n completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined {\n if (!hcParty) {\n return hcParty\n }\n\n let finalHcParty = hcParty\n\n if ((!!finalHcParty.lastName || !!finalHcParty.name) && !hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n finalHcParty = garnishPersonWithName(\n finalHcParty,\n models.PersonName.UseEnum.Official,\n finalHcParty.lastName,\n finalHcParty.firstName,\n finalHcParty.name\n )\n }\n\n if ((!finalHcParty.lastName || !finalHcParty.name) && !!hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n let officialName = findName(finalHcParty, models.PersonName.UseEnum.Official)\n finalHcParty = {\n ...finalHcParty,\n lastName: officialName!.lastName,\n firstName: officialName!.firstNames ? officialName!.firstNames[0] : undefined,\n name: officialName!.text,\n }\n }\n\n return finalHcParty\n }\n\n putHcPartyInCache(key: string, value: Promise<HealthcareParty> | null = null): Promise<HealthcareParty> {\n const hcp =\n value ||\n super.getHealthcareParty(key).catch((e) => {\n console.log(`Evict key ${key} because of error`)\n delete this.hcPartyCache[key]\n throw e\n })\n this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcp]\n return hcp\n }\n\n createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcareParty(this.completeNames(body))\n }\n\n createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcarePartyInGroup(groupId, this.completeNames(body))\n }\n\n modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any> {\n if (body && body.id) {\n console.log(`Evict key ${body.id} because of modification`)\n delete this.hcPartyCache[body.id]\n }\n\n return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n getHealthcareParty(healthcarePartyId: string, bypassCache = false): Promise<HealthcareParty | any> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n return fromCache || this.putHcPartyInCache(healthcarePartyId)\n }\n\n getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache = false): Promise<string[]> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n return (fromCache || this.putHcPartyInCache(healthcarePartyId)).then(async (hcp: HealthcareParty) => {\n return hcp ? (hcp.parentId ? (await this.getHealthcarePartyHierarchyIds(hcp.parentId!, bypassCache)).concat([hcp.id!]) : [hcp.id!]) : []\n })\n }\n\n getHealthcareParties(healthcarePartyIds: ListOfIds): Promise<Array<HealthcareParty> | any> {\n const ids = healthcarePartyIds.ids\n if (!ids || !ids.length) {\n return Promise.resolve([])\n }\n const cached: Array<[string, Promise<HealthcareParty> | null]> = ids.map((id) => [id, this.getHcPartyFromCache(id)])\n const toFetch = cached.filter((x) => !x[1]).map((x) => x[0])\n\n if (!toFetch.length) {\n return Promise.all(cached.map((x) => x[1]!))\n }\n\n const prom: Promise<HealthcareParty[]> = super.getHealthcareParties(new ListOfIds({ ids: toFetch }))\n return Promise.all(\n cached.map(\n (x) =>\n x[1] ||\n this.putHcPartyInCache(\n x[0],\n prom.then((hcps) => hcps.find((h) => h.id === x[0])!)\n )\n )\n )\n }\n\n getCurrentHealthcareParty(): Promise<HealthcareParty> {\n return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n isValidCbe(cbe: string) {\n cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '')\n cbe = cbe.length == 9 ? '0' + cbe : cbe\n\n return 97 - (Number(cbe.substring(0, 8)) % 97) === Number(cbe.substring(8, 2))\n }\n\n async subscribeToHealthcarePartyEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<HealthcareParty> | undefined,\n eventFired: (dataSample: HealthcareParty) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return subscribeToEntityEvents(this.host, this.authApi, 'HealthcareParty', eventTypes, filter, eventFired, options).then(\n (rs) => new ConnectionImpl(rs)\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-hcparty-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-hcparty-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAsD;AAEtD,kDAAiD;AACjD,qDAA8E;AAC9E,0EAAgG;AAEhG,mCAAsE;AACtE,4DAAwE;AACxE,oDAAmD;AAEnD,qCAAqC;AACrC,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,yBAAiD,IAAI,iDAAwB,EAAE,EAC9D,OAAmB,EACpC,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,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C,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAChF,CAAC;IAEK,gCAAgC,CACpC,UAA8C,EAC9C,MAAmD,EACnD,UAA0D,EAC1D,UAA+B,EAAE;;YAEjC,OAAO,IAAA,+BAAuB,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CACtH,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAC/B,CAAA;QACH,CAAC;KAAA;CACF;AA1KD,wCA0KC","sourcesContent":["import { IccAuthApi, IccHcpartyApi } from '../icc-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport * as models from '../icc-api/model/models'\nimport { findName, garnishPersonWithName, hasName } from './utils/person-util'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { AbstractFilter } from './filters/filters'\nimport { subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { ListOfIds } from '../icc-api/model/models'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccHcpartyXApi extends IccHcpartyApi {\n hcPartyKeysCache: { [key: string]: { [key: string]: string } } = {}\n hcPartyCache: { [key: string]: [number, Promise<HealthcareParty>] } = {}\n\n private CACHE_RETENTION_IN_MS = 300_000\n constructor(\n host: string,\n headers: { [key: string]: string },\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n private readonly authApi: IccAuthApi,\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n }\n\n private getHcPartyFromCache(key: string) {\n const hcpInCache = this.hcPartyCache[key]\n const now = Date.now()\n if (hcpInCache && hcpInCache[0] > now) {\n return hcpInCache[1]\n }\n if (!hcpInCache) {\n console.log(`Cache miss for key ${key} because not in cache`)\n } else {\n console.log(`Cache miss for key ${key} because ${hcpInCache[0]} > ${now}`)\n }\n return null\n }\n\n completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined {\n if (!hcParty) {\n return hcParty\n }\n\n let finalHcParty = hcParty\n\n if ((!!finalHcParty.lastName || !!finalHcParty.name) && !hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n finalHcParty = garnishPersonWithName(\n finalHcParty,\n models.PersonName.UseEnum.Official,\n finalHcParty.lastName,\n finalHcParty.firstName,\n finalHcParty.name\n )\n }\n\n if ((!finalHcParty.lastName || !finalHcParty.name) && !!hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n let officialName = findName(finalHcParty, models.PersonName.UseEnum.Official)\n finalHcParty = {\n ...finalHcParty,\n lastName: officialName!.lastName,\n firstName: officialName!.firstNames ? officialName!.firstNames[0] : undefined,\n name: officialName!.text,\n }\n }\n\n return finalHcParty\n }\n\n putHcPartyInCache(key: string, hcpPromise: Promise<HealthcareParty>): Promise<HealthcareParty> {\n this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcpPromise]\n return hcpPromise\n }\n\n createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcareParty(this.completeNames(body))\n }\n\n createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcarePartyInGroup(groupId, this.completeNames(body))\n }\n\n modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any> {\n if (body && body.id) {\n console.log(`Evict key ${body.id} because of modification`)\n delete this.hcPartyCache[body.id]\n }\n\n return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n async getHealthcareParty(healthcarePartyId: string, bypassCache = false): Promise<HealthcareParty | any> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n if (fromCache) {\n try {\n return await fromCache\n } catch {\n if (this.hcPartyCache[healthcarePartyId][1] === fromCache) {\n delete this.hcPartyCache[healthcarePartyId]\n }\n return this.getHealthcareParty(healthcarePartyId, bypassCache)\n }\n } else {\n return await this.putHcPartyInCache(healthcarePartyId, super.getHealthcareParty(healthcarePartyId))\n }\n }\n\n getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache = false): Promise<string[]> {\n return this.getHealthcareParty(healthcarePartyId, bypassCache).then(async (hcp: HealthcareParty) => {\n return hcp ? (hcp.parentId ? (await this.getHealthcarePartyHierarchyIds(hcp.parentId!, bypassCache)).concat([hcp.id!]) : [hcp.id!]) : []\n })\n }\n\n async getHealthcareParties(healthcarePartyIds: ListOfIds): Promise<Array<HealthcareParty> | any> {\n const ids = healthcarePartyIds.ids\n if (!ids || !ids.length) {\n return Promise.resolve([])\n }\n const cached: Array<[string, HealthcareParty | null]> = []\n for (const id of ids) {\n let hcp\n try {\n hcp = await this.getHcPartyFromCache(id)\n } catch {\n hcp = null\n delete this.hcPartyCache[id]\n }\n cached.push([id, hcp])\n }\n const toFetch = cached.filter((x) => !x[1]).map((x) => x[0])\n\n if (!toFetch.length) {\n return Promise.all(cached.map((x) => x[1]!))\n }\n\n const prom: Promise<HealthcareParty[]> = super.getHealthcareParties(new ListOfIds({ ids: toFetch }))\n return Promise.all(\n cached.map(\n (x) =>\n x[1] ??\n this.putHcPartyInCache(\n x[0],\n prom.then((hcps) => {\n const hcp = hcps.find((h) => h.id === x[0])\n if (!!hcp) {\n return hcp\n } else {\n throw new Error(`Hcp with id ${x[0]} not found`)\n }\n })\n )\n )\n )\n }\n\n getCurrentHealthcareParty(): Promise<HealthcareParty> {\n return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n isValidCbe(cbe: string) {\n cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '')\n cbe = cbe.length == 9 ? '0' + cbe : cbe\n\n return 97 - (Number(cbe.substring(0, 8)) % 97) === Number(cbe.substring(8, 2))\n }\n\n async subscribeToHealthcarePartyEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<HealthcareParty> | undefined,\n eventFired: (dataSample: HealthcareParty) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return subscribeToEntityEvents(this.host, this.authApi, 'HealthcareParty', eventTypes, filter, eventFired, options).then(\n (rs) => new ConnectionImpl(rs)\n )\n }\n}\n"]}
@@ -250,15 +250,15 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
250
250
  return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), healthElements);
251
251
  }
252
252
  encryptAs(owner, healthElements) {
253
- return Promise.all(healthElements.map((he) => this.crypto.xapi.tryEncryptEntity(he, utils_1.EntityWithDelegationTypeName.HealthElement, this.encryptedFields, false, false, (x) => new models.HealthElement(x))));
253
+ return this.crypto.xapi.tryEncryptEntities(healthElements, utils_1.EntityWithDelegationTypeName.HealthElement, this.encryptedFields, false, false, (x) => new models.HealthElement(x));
254
254
  }
255
255
  decryptWithUser(user, hes) {
256
256
  return this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes);
257
257
  }
258
258
  decrypt(dataOwnerId, hes) {
259
- return Promise.all(hes.map((he) => this.crypto.xapi
260
- .decryptEntity(he, utils_1.EntityWithDelegationTypeName.HealthElement, (x) => new models.HealthElement(x))
261
- .then(({ entity }) => entity)));
259
+ return __awaiter(this, void 0, void 0, function* () {
260
+ return (yield this.crypto.xapi.tryDecryptEntities(hes, utils_1.EntityWithDelegationTypeName.HealthElement, (x) => new models.HealthElement(x))).map(({ entity }) => entity);
261
+ });
262
262
  }
263
263
  filterHealthElementsBy(startDocumentId, limit, body) {
264
264
  throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption');
@@ -1 +1 @@
1
- {"version":3,"file":"icc-helement-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-helement-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAuD;AAGvD,kDAAiD;AAEjD,4BAA2B;AAC3B,iCAAgC;AAGhC,0EAAgG;AAChG,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAOzD,mCAAmJ;AAGnJ,4DAAwE;AAExE,MAAa,eAAgB,SAAQ,wBAAc;IAGjD,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,aAAa,CAAC,CAAC,CAAA;IACnJ,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,YAA8B,EAC9B,OAAoB,EACpB,OAAmB,EACnB,cAAuB,EACxC,gBAA+B,CAAC,OAAO,EAAE,MAAM,CAAC,EAChD,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAbtC,WAAM,GAAN,MAAM,CAAe;QACrB,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,YAAO,GAAP,OAAO,CAAa;QACpB,YAAO,GAAP,OAAO,CAAY;QACnB,mBAAc,GAAd,cAAc,CAAS;QAUxC,IAAI,CAAC,eAAe,GAAG,IAAA,4BAAoB,EAAC,aAAa,EAAE,gBAAgB,CAAC,CAAA;IAC9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AAC,CAAC,CAAA;QACxC,CAAC;KAAA;IAED,uCAAuC,CAAC,MAAqB,EAAE,SAAmB;QAChF,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAC7E,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,aAAa,EAAE,EAC5D,SAAS,CACV,CAAA;IACH,CAAC;CACF;AAhiBD,0CAgiBC","sourcesContent":["import { IccAuthApi, IccHelementApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport * as moment from 'moment'\nimport { FilterChainHealthElement, HealthElement, PaginatedListHealthElement } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { IccUserXApi } from './icc-user-x-api'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { AbstractFilter } from './filters/filters'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\n\nexport class IccHelementXApi extends IccHelementApi implements EncryptedEntityXApi<models.HealthElement> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.HealthElement))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly userApi: IccUserXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n encryptedKeys: Array<string> = ['descr', 'note'],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'HealthElement.')\n }\n\n /**\n * Creates a new instance of health element with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this health element refers to.\n * @param h initialised data for the health element. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the health element. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy if the confidential is set to false, else a secret id that\n * the data owner did not share with any of his parents.\n * - confidential: if true, the entity will be created as confidential. Confidential entities are not shared with auto-delegations, and the default\n * foreign key used is any key that is not shared with any of the data owner parents. By default entities are created as non-confidential.\n * @return a new instance of health element.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n h: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n preferredSfk?: string\n confidential?: boolean\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const helement = {\n ...(h ?? {}),\n _type: 'org.taktik.icure.entities.HealthElement',\n id: h?.id ?? this.crypto.primitives.randomUuid(),\n created: h?.created ?? new Date().getTime(),\n modified: h?.modified ?? new Date().getTime(),\n responsible: h?.responsible ?? (this.autofillAuthor ? dataOwnerId : undefined),\n author: h?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: h?.codes ?? [],\n tags: h?.tags ?? [],\n healthElementId: h?.healthElementId ?? this.crypto.primitives.randomUuid(),\n openingDate: h?.openingDate ?? parseInt(moment().format('YYYYMMDDHHmmss')),\n }\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk =\n options.preferredSfk ??\n (options?.confidential\n ? await this.crypto.confidential.getConfidentialSecretId({ entity: patient, type: EntityWithDelegationTypeName.Patient })\n : await this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: EntityWithDelegationTypeName.Patient }))\n if (!sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id} for confidential=${options?.confidential ?? false}`)\n const extraDelegations = {\n ...(options.confidential\n ? {}\n : Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n )),\n ...(options?.additionalDelegates ?? {}),\n }\n const initialisationInfo = await this.crypto.xapi.entityWithInitialisedEncryptedMetadata(\n helement,\n EntityWithDelegationTypeName.HealthElement,\n patient.id,\n sfk,\n true,\n extraDelegations\n )\n return new models.HealthElement(initialisationInfo.updatedEntity)\n }\n\n createHealthElement(body?: models.HealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementWithUser(user: models.User, body?: models.HealthElement): Promise<models.HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.createHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n createHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementsWithUser(user: models.User, bodies?: models.HealthElement[]): Promise<models.HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.createHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes))\n : Promise.resolve(null)\n }\n\n getHealthElement(healthElementId: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n getHealthElementWithUser(user: models.User, healthElementId: string): Promise<models.HealthElement> {\n return super\n .getHealthElement(healthElementId)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n }\n\n getHealthElements(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n getHealthElementsWithUser(user: models.User, body?: models.ListOfIds): Promise<models.HealthElement[]> {\n return super.getHealthElements(body).then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes))\n }\n\n newHealthElementDelegations(healthElementId: string, body?: Array<models.Delegation>): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n findHealthElementsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n findHealthElementsByHCPartyPatientForeignKeysWithUser(user: models.User, hcPartyId: string, secretFKeys: string): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user: models.User, hcPartyId: string, secretFKeys: string[]): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n async findHealthElementsByHCPartyAndPatientWithUser(\n user: models.User,\n hcPartyId: string,\n patient: models.Patient,\n usingPost: boolean = false\n ): Promise<models.HealthElement[]> {\n let keysAndHcPartyId = await this.crypto.xapi.secretIdsForHcpHierarchyOf({ entity: patient, type: EntityWithDelegationTypeName.Patient })\n const keys = keysAndHcPartyId.find((secretForeignKeys) => secretForeignKeys.ownerId == hcPartyId)?.extracted\n if (keys == undefined) {\n throw Error('No delegation for user')\n }\n return usingPost\n ? this.findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user, hcPartyId, keys)\n : this.findHealthElementsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, keys.join(','))\n }\n\n modifyHealthElement(body?: HealthElement): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise<HealthElement | any> {\n return body ? this.modifyHealthElementAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n private modifyHealthElementAs(dataOwner: string, body: HealthElement): Promise<HealthElement> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((hes) => super.modifyHealthElement(hes[0]))\n .then((he) => this.decrypt(dataOwner, [he]))\n .then((hes) => hes[0])\n }\n\n modifyHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n modifyHealthElementsWithUser(user: models.User, bodies?: HealthElement[]): Promise<HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.modifyHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes))\n : Promise.resolve(null)\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @deprecated use {@link findIdsBy}.\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n * @param usingPost\n */\n findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions = false, usingPost = false) {\n return this.crypto.xapi\n .secretIdsForHcpHierarchyOf({ entity: patient, type: EntityWithDelegationTypeName.Patient })\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.length > 0\n ? Promise.all(\n secretForeignKeys\n .reduce((acc, level) => {\n return acc.concat([\n {\n hcpartyId: level.ownerId,\n extractedKeys: level.extracted.filter((key) => !acc.some((previousLevel) => previousLevel.extractedKeys.includes(key))),\n },\n ])\n }, [] as Array<{ hcpartyId: string; extractedKeys: Array<string> }>)\n .filter((l) => l.extractedKeys.length > 0)\n .map(({ hcpartyId, extractedKeys }) =>\n usingPost\n ? this.findByHCPartyPatientSecretFKeysArray(hcpartyId, _.uniq(extractedKeys))\n : this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(','))\n )\n ).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))\n : Promise.resolve([])\n )\n .then((decryptedHelements: Array<models.HealthElement>) => {\n const byIds: { [key: string]: models.HealthElement } = {}\n\n if (keepObsoleteVersions) {\n return decryptedHelements\n } else {\n decryptedHelements.forEach((he) => {\n if (he.healthElementId) {\n const phe = byIds[he.healthElementId]\n if (!phe || !phe.modified || (he.modified && phe.modified < he.modified)) {\n byIds[he.healthElementId] = he\n }\n }\n })\n return _.values(byIds).filter((s: any) => !s.endOfLife)\n }\n })\n }\n\n /**\n * Same as {@link findBy} but it will only return the ids of the health elements. It can also filter the health elements where HealthElement.openingDate is between\n * startDate and endDate in ascending or descending order by that field. (default: ascending).\n */\n async findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean) {\n return this.crypto.xapi.secretIdsForHcpHierarchyOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }).then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.length > 0\n ? Promise.all(\n secretForeignKeys\n .reduce((acc, level) => {\n return acc.concat([\n {\n hcpartyId: level.ownerId,\n extractedKeys: level.extracted.filter((key) => !acc.some((previousLevel) => previousLevel.extractedKeys.includes(key))),\n },\n ])\n }, [] as Array<{ hcpartyId: string; extractedKeys: Array<string> }>)\n .filter((l) => l.extractedKeys.length > 0)\n .map(({ hcpartyId, extractedKeys }) =>\n this.findHealthElementIdsByDataOwnerPatientOpeningDate(hcpartyId, extractedKeys, startDate, endDate, descending)\n )\n ).then((results) => _.uniq(_.flatMap(results)))\n : Promise.resolve([])\n )\n }\n\n /**\n * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead.\n */\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.HealthElement> | any> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n /**\n * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead.\n */\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.Contact> | any> {\n return super\n .findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n encrypt(user: models.User, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), healthElements)\n }\n\n private encryptAs(owner: string, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return Promise.all(\n healthElements.map((he) =>\n this.crypto.xapi.tryEncryptEntity(\n he,\n EntityWithDelegationTypeName.HealthElement,\n this.encryptedFields,\n false,\n false,\n (x) => new models.HealthElement(x)\n )\n )\n )\n }\n\n decryptWithUser(user: models.User, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes)\n }\n\n decrypt(dataOwnerId: string, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return Promise.all(\n hes.map((he) =>\n this.crypto.xapi\n .decryptEntity(he, EntityWithDelegationTypeName.HealthElement, (x) => new models.HealthElement(x))\n .then(({ entity }) => entity)\n )\n )\n }\n\n filterHealthElementsBy(startDocumentId?: string, limit?: number, body?: FilterChainHealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n filterByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: FilterChainHealthElement\n ): Promise<PaginatedListHealthElement> {\n return super\n .filterHealthElementsBy(startDocumentId, limit, body)\n .then((pl) => this.decryptWithUser(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n // noinspection JSUnusedGlobalSymbols\n serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string) {\n return this.newInstance(user, patient, {\n idService: heSvc.id,\n author: heSvc.author,\n responsible: heSvc.responsible,\n openingDate: heSvc.valueDate || heSvc.openingDate,\n descr: descr,\n idOpeningContact: heSvc.contactId,\n modified: heSvc.modified,\n created: heSvc.created,\n codes: heSvc.codes,\n tags: heSvc.tags,\n }).then((he) => {\n return this.createHealthElement(he)\n })\n }\n\n // noinspection JSUnusedGlobalSymbols, JSMethodCanBeStatic\n stringToCode(code: string) {\n const c = code.split('|')\n return new models.Code({\n type: c[0],\n code: c[1],\n version: c[2],\n id: code,\n })\n }\n\n /**\n * @param healthElement a health element\n * @return the id of the patient that the health element refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(healthElement: models.HealthElement): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: healthElement, type: EntityWithDelegationTypeName.HealthElement }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given health element\n */\n async hasWriteAccess(healthElement: models.HealthElement): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: healthElement, type: EntityWithDelegationTypeName.HealthElement })\n }\n\n /**\n * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the health element.\n * @param healthElement the health element to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * health element does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n healthElement: models.HealthElement,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.HealthElement> {\n return this.shareWithMany(healthElement, { [delegateId]: options })\n }\n /**\n * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the health element.\n * @param healthElement the health element to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * health element does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n healthElement: models.HealthElement,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.HealthElement> {\n return (await this.tryShareWithMany(healthElement, delegates)).updatedEntityOrThrow\n }\n /**\n * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param healthElement the health element to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * health element does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async tryShareWithMany(\n healthElement: models.HealthElement,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.HealthElement>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(healthElement, EntityWithDelegationTypeName.HealthElement)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyHealthElementAs(self, entityWithEncryptionKey) : healthElement\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.HealthElement,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareHealthElements(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.HealthElement\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.HealthElement })\n }\n\n getEncryptionKeysOf(entity: models.HealthElement): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.HealthElement }, undefined)\n }\n\n async subscribeToHealthElementEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<HealthElement> | undefined,\n eventFired: (healthElement: HealthElement) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n const currentUser = await this.userApi.getCurrentUser()\n\n return await subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.HealthElement,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(currentUser), [encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: HealthElement, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.HealthElement },\n delegates\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-helement-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-helement-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAuD;AAGvD,kDAAiD;AAEjD,4BAA2B;AAC3B,iCAAgC;AAGhC,0EAAgG;AAChG,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAOzD,mCAAmJ;AAGnJ,4DAAwE;AAExE,MAAa,eAAgB,SAAQ,wBAAc;IAGjD,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,aAAa,CAAC,CAAC,CAAA;IACnJ,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,YAA8B,EAC9B,OAAoB,EACpB,OAAmB,EACnB,cAAuB,EACxC,gBAA+B,CAAC,OAAO,EAAE,MAAM,CAAC,EAChD,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,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AI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,GAAA,CAC3G,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;KAAA;IAED,uCAAuC,CAAC,MAAqB,EAAE,SAAmB;QAChF,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAC7E,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,aAAa,EAAE,EAC5D,SAAS,CACV,CAAA;IACH,CAAC;CACF;AAxhBD,0CAwhBC","sourcesContent":["import { IccAuthApi, IccHelementApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport * as moment from 'moment'\nimport { FilterChainHealthElement, HealthElement, PaginatedListHealthElement } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { IccUserXApi } from './icc-user-x-api'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { AbstractFilter } from './filters/filters'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\n\nexport class IccHelementXApi extends IccHelementApi implements EncryptedEntityXApi<models.HealthElement> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.HealthElement))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly userApi: IccUserXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n encryptedKeys: Array<string> = ['descr', 'note'],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'HealthElement.')\n }\n\n /**\n * Creates a new instance of health element with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this health element refers to.\n * @param h initialised data for the health element. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the health element. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy if the confidential is set to false, else a secret id that\n * the data owner did not share with any of his parents.\n * - confidential: if true, the entity will be created as confidential. Confidential entities are not shared with auto-delegations, and the default\n * foreign key used is any key that is not shared with any of the data owner parents. By default entities are created as non-confidential.\n * @return a new instance of health element.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n h: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n preferredSfk?: string\n confidential?: boolean\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const helement = {\n ...(h ?? {}),\n _type: 'org.taktik.icure.entities.HealthElement',\n id: h?.id ?? this.crypto.primitives.randomUuid(),\n created: h?.created ?? new Date().getTime(),\n modified: h?.modified ?? new Date().getTime(),\n responsible: h?.responsible ?? (this.autofillAuthor ? dataOwnerId : undefined),\n author: h?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: h?.codes ?? [],\n tags: h?.tags ?? [],\n healthElementId: h?.healthElementId ?? this.crypto.primitives.randomUuid(),\n openingDate: h?.openingDate ?? parseInt(moment().format('YYYYMMDDHHmmss')),\n }\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk =\n options.preferredSfk ??\n (options?.confidential\n ? await this.crypto.confidential.getConfidentialSecretId({ entity: patient, type: EntityWithDelegationTypeName.Patient })\n : await this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: EntityWithDelegationTypeName.Patient }))\n if (!sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id} for confidential=${options?.confidential ?? false}`)\n const extraDelegations = {\n ...(options.confidential\n ? {}\n : Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n )),\n ...(options?.additionalDelegates ?? {}),\n }\n const initialisationInfo = await this.crypto.xapi.entityWithInitialisedEncryptedMetadata(\n helement,\n EntityWithDelegationTypeName.HealthElement,\n patient.id,\n sfk,\n true,\n extraDelegations\n )\n return new models.HealthElement(initialisationInfo.updatedEntity)\n }\n\n createHealthElement(body?: models.HealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementWithUser(user: models.User, body?: models.HealthElement): Promise<models.HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.createHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n createHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementsWithUser(user: models.User, bodies?: models.HealthElement[]): Promise<models.HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.createHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes))\n : Promise.resolve(null)\n }\n\n getHealthElement(healthElementId: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n getHealthElementWithUser(user: models.User, healthElementId: string): Promise<models.HealthElement> {\n return super\n .getHealthElement(healthElementId)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n }\n\n getHealthElements(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n getHealthElementsWithUser(user: models.User, body?: models.ListOfIds): Promise<models.HealthElement[]> {\n return super.getHealthElements(body).then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes))\n }\n\n newHealthElementDelegations(healthElementId: string, body?: Array<models.Delegation>): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n findHealthElementsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n findHealthElementsByHCPartyPatientForeignKeysWithUser(user: models.User, hcPartyId: string, secretFKeys: string): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user: models.User, hcPartyId: string, secretFKeys: string[]): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n async findHealthElementsByHCPartyAndPatientWithUser(\n user: models.User,\n hcPartyId: string,\n patient: models.Patient,\n usingPost: boolean = false\n ): Promise<models.HealthElement[]> {\n let keysAndHcPartyId = await this.crypto.xapi.secretIdsForHcpHierarchyOf({ entity: patient, type: EntityWithDelegationTypeName.Patient })\n const keys = keysAndHcPartyId.find((secretForeignKeys) => secretForeignKeys.ownerId == hcPartyId)?.extracted\n if (keys == undefined) {\n throw Error('No delegation for user')\n }\n return usingPost\n ? this.findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user, hcPartyId, keys)\n : this.findHealthElementsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, keys.join(','))\n }\n\n modifyHealthElement(body?: HealthElement): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise<HealthElement | any> {\n return body ? this.modifyHealthElementAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n private modifyHealthElementAs(dataOwner: string, body: HealthElement): Promise<HealthElement> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((hes) => super.modifyHealthElement(hes[0]))\n .then((he) => this.decrypt(dataOwner, [he]))\n .then((hes) => hes[0])\n }\n\n modifyHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n modifyHealthElementsWithUser(user: models.User, bodies?: HealthElement[]): Promise<HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.modifyHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes))\n : Promise.resolve(null)\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @deprecated use {@link findIdsBy}.\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n * @param usingPost\n */\n findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions = false, usingPost = false) {\n return this.crypto.xapi\n .secretIdsForHcpHierarchyOf({ entity: patient, type: EntityWithDelegationTypeName.Patient })\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.length > 0\n ? Promise.all(\n secretForeignKeys\n .reduce((acc, level) => {\n return acc.concat([\n {\n hcpartyId: level.ownerId,\n extractedKeys: level.extracted.filter((key) => !acc.some((previousLevel) => previousLevel.extractedKeys.includes(key))),\n },\n ])\n }, [] as Array<{ hcpartyId: string; extractedKeys: Array<string> }>)\n .filter((l) => l.extractedKeys.length > 0)\n .map(({ hcpartyId, extractedKeys }) =>\n usingPost\n ? this.findByHCPartyPatientSecretFKeysArray(hcpartyId, _.uniq(extractedKeys))\n : this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(','))\n )\n ).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))\n : Promise.resolve([])\n )\n .then((decryptedHelements: Array<models.HealthElement>) => {\n const byIds: { [key: string]: models.HealthElement } = {}\n\n if (keepObsoleteVersions) {\n return decryptedHelements\n } else {\n decryptedHelements.forEach((he) => {\n if (he.healthElementId) {\n const phe = byIds[he.healthElementId]\n if (!phe || !phe.modified || (he.modified && phe.modified < he.modified)) {\n byIds[he.healthElementId] = he\n }\n }\n })\n return _.values(byIds).filter((s: any) => !s.endOfLife)\n }\n })\n }\n\n /**\n * Same as {@link findBy} but it will only return the ids of the health elements. It can also filter the health elements where HealthElement.openingDate is between\n * startDate and endDate in ascending or descending order by that field. (default: ascending).\n */\n async findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean) {\n return this.crypto.xapi.secretIdsForHcpHierarchyOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }).then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.length > 0\n ? Promise.all(\n secretForeignKeys\n .reduce((acc, level) => {\n return acc.concat([\n {\n hcpartyId: level.ownerId,\n extractedKeys: level.extracted.filter((key) => !acc.some((previousLevel) => previousLevel.extractedKeys.includes(key))),\n },\n ])\n }, [] as Array<{ hcpartyId: string; extractedKeys: Array<string> }>)\n .filter((l) => l.extractedKeys.length > 0)\n .map(({ hcpartyId, extractedKeys }) =>\n this.findHealthElementIdsByDataOwnerPatientOpeningDate(hcpartyId, extractedKeys, startDate, endDate, descending)\n )\n ).then((results) => _.uniq(_.flatMap(results)))\n : Promise.resolve([])\n )\n }\n\n /**\n * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead.\n */\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.HealthElement> | any> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n /**\n * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead.\n */\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.Contact> | any> {\n return super\n .findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n encrypt(user: models.User, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), healthElements)\n }\n\n private encryptAs(owner: string, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.crypto.xapi.tryEncryptEntities(\n healthElements,\n EntityWithDelegationTypeName.HealthElement,\n this.encryptedFields,\n false,\n false,\n (x) => new models.HealthElement(x)\n )\n }\n\n decryptWithUser(user: models.User, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), hes)\n }\n\n async decrypt(dataOwnerId: string, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return (await this.crypto.xapi.tryDecryptEntities(hes, EntityWithDelegationTypeName.HealthElement, (x) => new models.HealthElement(x))).map(\n ({ entity }) => entity\n )\n }\n\n filterHealthElementsBy(startDocumentId?: string, limit?: number, body?: FilterChainHealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n filterByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: FilterChainHealthElement\n ): Promise<PaginatedListHealthElement> {\n return super\n .filterHealthElementsBy(startDocumentId, limit, body)\n .then((pl) => this.decryptWithUser(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n // noinspection JSUnusedGlobalSymbols\n serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string) {\n return this.newInstance(user, patient, {\n idService: heSvc.id,\n author: heSvc.author,\n responsible: heSvc.responsible,\n openingDate: heSvc.valueDate || heSvc.openingDate,\n descr: descr,\n idOpeningContact: heSvc.contactId,\n modified: heSvc.modified,\n created: heSvc.created,\n codes: heSvc.codes,\n tags: heSvc.tags,\n }).then((he) => {\n return this.createHealthElement(he)\n })\n }\n\n // noinspection JSUnusedGlobalSymbols, JSMethodCanBeStatic\n stringToCode(code: string) {\n const c = code.split('|')\n return new models.Code({\n type: c[0],\n code: c[1],\n version: c[2],\n id: code,\n })\n }\n\n /**\n * @param healthElement a health element\n * @return the id of the patient that the health element refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(healthElement: models.HealthElement): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: healthElement, type: EntityWithDelegationTypeName.HealthElement }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given health element\n */\n async hasWriteAccess(healthElement: models.HealthElement): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: healthElement, type: EntityWithDelegationTypeName.HealthElement })\n }\n\n /**\n * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the health element.\n * @param healthElement the health element to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * health element does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n healthElement: models.HealthElement,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.HealthElement> {\n return this.shareWithMany(healthElement, { [delegateId]: options })\n }\n /**\n * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the health element.\n * @param healthElement the health element to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * health element does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n healthElement: models.HealthElement,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.HealthElement> {\n return (await this.tryShareWithMany(healthElement, delegates)).updatedEntityOrThrow\n }\n /**\n * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param healthElement the health element to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * health element does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async tryShareWithMany(\n healthElement: models.HealthElement,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.HealthElement>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(healthElement, EntityWithDelegationTypeName.HealthElement)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyHealthElementAs(self, entityWithEncryptionKey) : healthElement\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.HealthElement,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareHealthElements(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.HealthElement\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.HealthElement })\n }\n\n getEncryptionKeysOf(entity: models.HealthElement): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.HealthElement }, undefined)\n }\n\n async subscribeToHealthElementEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<HealthElement> | undefined,\n eventFired: (healthElement: HealthElement) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n const currentUser = await this.userApi.getCurrentUser()\n\n return await subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.HealthElement,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(currentUser), [encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: HealthElement, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.HealthElement },\n delegates\n )\n }\n}\n"]}
@@ -117,14 +117,16 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
117
117
  return this.encryptAs(dataOwnerId, maintenanceTasks);
118
118
  }
119
119
  encryptAs(dataOwner, maintenanceTasks) {
120
- return Promise.all(maintenanceTasks.map((m) => this.crypto.xapi.tryEncryptEntity(m, utils_1.EntityWithDelegationTypeName.MaintenanceTask, this.encryptedFields, true, false, (x) => new models.MaintenanceTask(x))));
120
+ return this.crypto.xapi.tryEncryptEntities(maintenanceTasks, utils_1.EntityWithDelegationTypeName.MaintenanceTask, this.encryptedFields, true, false, (x) => new models.MaintenanceTask(x));
121
121
  }
122
122
  decrypt(user, maintenanceTasks) {
123
123
  const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user);
124
124
  return this.decryptAs(dataOwnerId, maintenanceTasks);
125
125
  }
126
126
  decryptAs(dataOwner, maintenanceTasks) {
127
- return Promise.all(maintenanceTasks.map((mT) => __awaiter(this, void 0, void 0, function* () { return this.crypto.xapi.decryptEntity(mT, utils_1.EntityWithDelegationTypeName.MaintenanceTask, (x) => new models_1.MaintenanceTask(x)).then(({ entity }) => entity); })));
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ return (yield this.crypto.xapi.tryDecryptEntities(maintenanceTasks, utils_1.EntityWithDelegationTypeName.MaintenanceTask, (x) => new models_1.MaintenanceTask(x))).map(({ entity }) => entity);
129
+ });
128
130
  }
129
131
  /**
130
132
  * @return if the logged data owner has write access to the content of the given maintenance task