@icure/api 6.4.0 → 7.0.0-beta.1
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.
- package/icc-api/api/IccDeviceApi.d.ts +1 -1
- package/icc-api/api/IccDeviceApi.js.map +1 -1
- package/icc-api/api/IccDoctemplateApi.js.map +1 -1
- package/icc-api/api/IccDocumentTemplateApi.js.map +1 -1
- package/icc-api/api/IccHcpartyApi.d.ts +1 -1
- package/icc-api/api/IccHcpartyApi.js.map +1 -1
- package/icc-api/api/IccPatientApi.d.ts +1 -1
- package/icc-api/api/IccPatientApi.js.map +1 -1
- package/icc-api/model/MaintenanceTask.d.ts +6 -5
- package/icc-api/model/MaintenanceTask.js +5 -0
- package/icc-api/model/MaintenanceTask.js.map +1 -1
- package/icc-api/model/User.d.ts +23 -1
- package/icc-api/model/User.js +21 -0
- package/icc-api/model/User.js.map +1 -1
- package/icc-api/model/models.d.ts +14 -0
- package/icc-api/model/models.js.map +1 -1
- package/icc-x-api/crypto/AES.d.ts +2 -0
- package/icc-x-api/crypto/AES.js +12 -0
- package/icc-x-api/crypto/AES.js.map +1 -1
- package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +122 -0
- package/icc-x-api/crypto/BaseExchangeKeysManager.js +356 -0
- package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -0
- package/icc-x-api/crypto/ConfidentialEntities.d.ts +58 -0
- package/icc-x-api/crypto/ConfidentialEntities.js +99 -0
- package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -0
- package/icc-x-api/crypto/CryptoPrimitives.d.ts +31 -0
- package/icc-x-api/crypto/CryptoPrimitives.js +55 -0
- package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -0
- package/icc-x-api/crypto/CryptoStrategies.d.ts +82 -0
- package/icc-x-api/crypto/CryptoStrategies.js +3 -0
- package/icc-x-api/crypto/CryptoStrategies.js.map +1 -0
- package/icc-x-api/crypto/EntitiesEncryption.d.ts +254 -0
- package/icc-x-api/crypto/EntitiesEncryption.js +700 -0
- package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -0
- package/icc-x-api/crypto/ExchangeKeysManager.d.ts +56 -0
- package/icc-x-api/crypto/ExchangeKeysManager.js +147 -0
- package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -0
- package/icc-x-api/crypto/KeyManager.d.ts +103 -0
- package/icc-x-api/crypto/KeyManager.js +288 -0
- package/icc-x-api/crypto/KeyManager.js.map +1 -0
- package/icc-x-api/crypto/KeyRecovery.d.ts +34 -0
- package/icc-x-api/crypto/KeyRecovery.js +253 -0
- package/icc-x-api/crypto/KeyRecovery.js.map +1 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +28 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.js +22 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -0
- package/icc-x-api/crypto/RSA.d.ts +19 -20
- package/icc-x-api/crypto/RSA.js +30 -1
- package/icc-x-api/crypto/RSA.js.map +1 -1
- package/icc-x-api/crypto/ShamirKeysManager.d.ts +43 -0
- package/icc-x-api/crypto/ShamirKeysManager.js +150 -0
- package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.d.ts +19 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.js +24 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.js.map +1 -0
- package/icc-x-api/crypto/TransferKeysManager.d.ts +29 -0
- package/icc-x-api/crypto/TransferKeysManager.js +121 -0
- package/icc-x-api/crypto/TransferKeysManager.js.map +1 -0
- package/icc-x-api/crypto/utils.d.ts +46 -0
- package/icc-x-api/crypto/utils.js +128 -0
- package/icc-x-api/crypto/utils.js.map +1 -1
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.d.ts +11 -0
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js +11 -0
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js.map +1 -1
- package/icc-x-api/filters/DeviceByHcPartyFilter.d.ts +11 -0
- package/icc-x-api/filters/DeviceByHcPartyFilter.js +11 -0
- package/icc-x-api/filters/DeviceByHcPartyFilter.js.map +1 -1
- package/icc-x-api/filters/DeviceByIdsFilter.d.ts +11 -0
- package/icc-x-api/filters/DeviceByIdsFilter.js +11 -0
- package/icc-x-api/filters/DeviceByIdsFilter.js.map +1 -1
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.d.ts +11 -0
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js +11 -0
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.d.ts +49 -4
- package/icc-x-api/icc-accesslog-x-api.js +112 -102
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +53 -5
- package/icc-x-api/icc-calendar-item-x-api.js +112 -100
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +45 -2
- package/icc-x-api/icc-classification-x-api.js +89 -41
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +57 -19
- package/icc-x-api/icc-contact-x-api.js +149 -154
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +266 -366
- package/icc-x-api/icc-crypto-x-api.js +416 -1327
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-data-owner-x-api.d.ts +110 -11
- package/icc-x-api/icc-data-owner-x-api.js +188 -14
- package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
- package/icc-x-api/icc-doctemplate-x-api.js +3 -3
- package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +76 -5
- package/icc-x-api/icc-document-x-api.js +137 -59
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +47 -7
- package/icc-x-api/icc-form-x-api.js +85 -86
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-hcparty-x-api.d.ts +1 -1
- package/icc-x-api/icc-hcparty-x-api.js +1 -1
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +50 -3
- package/icc-x-api/icc-helement-x-api.js +101 -118
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-icure-maintenance-x-api.d.ts +31 -0
- package/icc-x-api/icc-icure-maintenance-x-api.js +124 -0
- package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -0
- package/icc-x-api/icc-invoice-x-api.d.ts +45 -5
- package/icc-x-api/icc-invoice-x-api.js +89 -64
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +38 -6
- package/icc-x-api/icc-maintenance-task-x-api.js +73 -102
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +55 -2
- package/icc-x-api/icc-message-x-api.js +92 -33
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +67 -7
- package/icc-x-api/icc-patient-x-api.js +409 -473
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +49 -5
- package/icc-x-api/icc-receipt-x-api.js +85 -47
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +34 -10
- package/icc-x-api/icc-time-table-x-api.js +61 -18
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +30 -1
- package/icc-x-api/index.js +112 -49
- package/icc-x-api/index.js.map +1 -1
- package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +35 -0
- package/icc-x-api/maintenance/KeyPairUpdateRequest.js +54 -0
- package/icc-x-api/maintenance/KeyPairUpdateRequest.js.map +1 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +9 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +23 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -0
- package/icc-x-api/storage/IcureStorageFacade.d.ts +55 -0
- package/icc-x-api/storage/IcureStorageFacade.js +95 -0
- package/icc-x-api/storage/IcureStorageFacade.js.map +1 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +31 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.js +3 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -0
- package/icc-x-api/utils/collection-utils.d.ts +8 -0
- package/icc-x-api/utils/collection-utils.js +26 -0
- package/icc-x-api/utils/collection-utils.js.map +1 -0
- package/icc-x-api/utils/crypto-utils.d.ts +8 -1
- package/icc-x-api/utils/crypto-utils.js +19 -3
- package/icc-x-api/utils/crypto-utils.js.map +1 -1
- package/icc-x-api/utils/graph-utils.d.ts +45 -0
- package/icc-x-api/utils/graph-utils.js +203 -0
- package/icc-x-api/utils/graph-utils.js.map +1 -0
- package/icc-x-api/utils/lru-temporised-async-cache.d.ts +27 -0
- package/icc-x-api/utils/lru-temporised-async-cache.js +120 -0
- package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-accesslog-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-accesslog-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA4C;AAM5C,4BAA2B;AAC3B,mCAAmE;AAEnE,0EAAgG;AAMhG,MAAa,gBAAiB,SAAQ,yBAAe;IAKnD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MA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B,CAAC,CAAC,IAAI,CACvI,CAAC,aAAa,EAAE,EAAE,CAChB,OAAO,CAAC,GAAG,CACT,CAAC,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,YAAY,EAAE,EAAE;oBACpC,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,EAAE,IAAI,CAAC,iBAA2B,CAAC,CAAC,IAAI,CACvF,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,gCACI,YAAY,KACf,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GACX,CAAA,CAC/B,CAAA;gBACH,CAAC,CAAC,CACH,CACJ,CAAA;gBAED,MAAM,UAAU,GAA6B,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;qBACpE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC;qBACxF,MAAM,CAAC,CAAC,GAA2B,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;qBACtD,KAAK,EAAE;qBACP,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;gBAEzB,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,UAAU,CAAC,CAAA;gBAErD,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,yBAAyB,EAAE;oBACnD,MAAK;iBACN;qBAAM,IAAI,cAAc,EAAE;oBACzB,WAAW,GAAG,cAAc,CAAA;iBAC7B;qBAAM;oBACL,MAAK;iBACN;aACF;YAED,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;CACF;AAtUD,4CAsUC","sourcesContent":["import { IccAccesslogApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\nimport { AccessLog, PaginatedListAccessLog } from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport { crypt, decrypt, hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport interface AccessLogWithPatientId extends AccessLog {\n patientId: string\n}\n\nexport class IccAccesslogXApi extends IccAccesslogApi {\n crypto: IccCryptoXApi\n cryptedKeys = ['detail', 'objectId']\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\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 newInstance(user: models.User, patient: models.Patient, h: any) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n const accessslog = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.AccessLog',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n date: +new Date(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n user: user.id,\n patientId: patient.id,\n accessType: 'USER_ACCESS',\n },\n h || {}\n )\n\n return this.crypto.extractDelegationsSFKs(patient, dataOwnerId).then(async (secretForeignKeys) => {\n const dels = await this.crypto.initObjectDelegations(accessslog, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0])\n const eks = await this.crypto.initEncryptionKeys(accessslog, dataOwnerId!)\n\n _.extend(accessslog, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(accessslog)\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then(() =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, accessslog, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return accessslog\n })\n ))\n )\n return promise\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 helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n * @param usingPost\n */\n\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? (usingPost ?\n this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys)) :\n this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(',')))\n : Promise.resolve([])\n )\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n decrypt(hcpId: string, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n accessLogs.map((accessLog) => {\n return accessLog.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n accessLog.id!,\n _.size(accessLog.encryptionKeys) ? accessLog.encryptionKeys! : accessLog.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n //console.log(\"Cannot decrypt contact\", ctc.id)\n return Promise.resolve(accessLog)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then((key) =>\n decrypt(accessLog, (ec) =>\n this.crypto.AES.decrypt(key, ec).then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse access log', accessLog.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n )\n )\n })\n : Promise.resolve(accessLog)\n })\n )\n }\n\n initEncryptionKeys(user: models.User, accessLog: models.AccessLog): Promise<models.AccessLog> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(accessLog, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(accessLog, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((accessLog) =>\n this.crypto.appendEncryptionKeys(accessLog, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n return Promise.all(\n accessLogs.map((accessLog) =>\n (accessLog.encryptionKeys && Object.keys(accessLog.encryptionKeys).length\n ? Promise.resolve(accessLog)\n : this.initEncryptionKeys(user, accessLog)\n )\n .then((accessLog: AccessLog) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.id!, accessLog.encryptionKeys!)\n )\n .then(async (eks: { extractedKeys: Array<string>; hcpartyId: string }) => {\n const rawKey = eks.extractedKeys[0].replace(/-/g, '')\n const key = await this.crypto.AES.importKey('raw', hex2ua(rawKey))\n return crypt(\n accessLog,\n (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj)), rawKey),\n this.cryptedKeys\n )\n })\n )\n )\n }\n\n createAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n createAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.createAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : Promise.resolve()\n }\n\n getAccessLog(accessLogId: string): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n getAccessLogWithUser(user: models.User, accessLogId: string): Promise<models.AccessLog | any> {\n return super\n .getAccessLog(accessLogId)\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n }\n\n listAccessLogs(fromEpoch?: number, toEpoch?: number, startKey?: number, startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n listAccessLogsWithUser(\n user: models.User,\n fromEpoch?: number,\n toEpoch?: number,\n startKey?: number,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<PaginatedListAccessLog> {\n return super\n .listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n modifyAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n async modifyAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.modifyAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : null\n }\n\n findByUserAfterDate(\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n findByUserAfterDateWithUser(\n user: models.User,\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<models.AccessLog | any> {\n return super\n .findByUserAfterDate(userId, accessType, startDate, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n async findLatestAccessLogsOfPatientsWithUser(user: models.User, userId: string, limit = 100, startDate?: number): Promise<models.AccessLog[]> {\n let foundAccessLogs: AccessLogWithPatientId[] = [],\n nextKeyPair: models.PaginatedDocumentKeyIdPairObject | undefined = undefined\n const numberRequestedAccessLogs = 100\n const MAX_WHILE_ITERATIONS = 5\n\n for (let currentIteration = 0; foundAccessLogs.length < limit && currentIteration < MAX_WHILE_ITERATIONS; currentIteration++) {\n const currentLimit = limit - foundAccessLogs.length\n const { rows: logs, nextKeyPair: newNextKeyPair }: models.PaginatedListAccessLog = (await super.findByUserAfterDate(\n userId,\n 'USER_ACCESS',\n startDate,\n nextKeyPair && JSON.stringify(nextKeyPair.startKey!),\n nextKeyPair && nextKeyPair.startKeyDocId!,\n numberRequestedAccessLogs,\n true\n )) as models.PaginatedListAccessLog\n const logsWithPatientId: AccessLogWithPatientId[] = await this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, logs as AccessLog[]).then(\n (decryptedLogs) =>\n Promise.all(\n _.map(decryptedLogs, (decryptedLog) => {\n return this.crypto.extractCryptedFKs(decryptedLog, user.healthcarePartyId as string).then(\n (keys) =>\n ({\n ...decryptedLog,\n patientId: _.head(keys.extractedKeys),\n } as AccessLogWithPatientId)\n )\n })\n )\n )\n\n const uniqueLogs: AccessLogWithPatientId[] = _.chain(logsWithPatientId)\n .reject((log) => _.some(foundAccessLogs, ({ patientId }) => patientId === log.patientId))\n .uniqBy((log: AccessLogWithPatientId) => log.patientId)\n .value()\n .slice(0, currentLimit)\n\n foundAccessLogs = [...foundAccessLogs, ...uniqueLogs]\n\n if ((logs || []).length < numberRequestedAccessLogs) {\n break\n } else if (newNextKeyPair) {\n nextKeyPair = newNextKeyPair\n } else {\n break\n }\n }\n\n return foundAccessLogs\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-accesslog-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-accesslog-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA4C;AAG5C,oDAA2E;AAC3E,4BAA2B;AAE3B,0EAAgG;AAOhG,MAAa,gBAAiB,SAAQ,yBAAe;IAKnD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CA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i } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport { AccessLog, PaginatedListAccessLog } from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\n\nexport interface AccessLogWithPatientId extends AccessLog {\n patientId: string\n}\n\nexport class IccAccesslogXApi extends IccAccesslogApi {\n crypto: IccCryptoXApi\n cryptedKeys = ['detail', 'objectId']\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\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 access log with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this access log refers to.\n * @param h initialised data for the access log. 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. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the access log. 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 access log.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n h: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n\n const accessLog = _.assign(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.AccessLog',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n date: +new Date(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n user: user.id,\n patientId: patient.id,\n accessType: 'USER_ACCESS',\n },\n h || {}\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 = options.preferredSfk ?? (await this.crypto.confidential.getAnySecretIdSharedWithParents(patient))\n if (!sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = [\n ...Object.keys(options.additionalDelegates ?? {}),\n ...(user.autoDelegations?.all ?? []),\n ...(user.autoDelegations?.administrativeData ?? []),\n ]\n return new AccessLog(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(accessLog, 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 helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n * @param usingPost\n */\n\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false): Promise<models.AccessLog[]> {\n const extractedKeys = await this.crypto.entities.secretIdsOf(patient, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? usingPost\n ? this.findByHCPartyPatientSecretFKeysArray(topmostParentId!, _.uniq(extractedKeys))\n : this.findByHCPartyPatientSecretFKeys(topmostParentId!, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n\n async findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<AccessLog[]> {\n const accessLogs = await super.findAccessLogsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys)\n return await this.decrypt(hcPartyId, accessLogs)\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n decrypt(hcpId: string, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n return Promise.all(\n accessLogs.map((x) => this.crypto.entities.decryptEntity(x, hcpId, (json) => new AccessLog(json)).then(({ entity }) => entity))\n )\n }\n\n encrypt(user: models.User, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, accessLogs)\n }\n\n private encryptAs(dataOwner: string, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n return Promise.all(\n accessLogs.map((x) => this.crypto.entities.tryEncryptEntity(x, dataOwner, this.cryptedKeys, false, true, (json) => new AccessLog(json)))\n )\n }\n\n createAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n createAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.createAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [accessLog]))\n .then((als) => als[0])\n : Promise.resolve()\n }\n\n getAccessLog(accessLogId: string): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n getAccessLogWithUser(user: models.User, accessLogId: string): Promise<models.AccessLog | any> {\n return super\n .getAccessLog(accessLogId)\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [accessLog]))\n .then((als) => als[0])\n }\n\n listAccessLogs(fromEpoch?: number, toEpoch?: number, startKey?: number, startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n listAccessLogsWithUser(\n user: models.User,\n fromEpoch?: number,\n toEpoch?: number,\n startKey?: number,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<PaginatedListAccessLog> {\n return super\n .listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n modifyAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n async modifyAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | null> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, _.cloneDeep(body)) : null\n }\n\n private modifyAs(dataOwner: string, accessLog: models.AccessLog): Promise<models.AccessLog> {\n return this.encryptAs(dataOwner, [_.cloneDeep(accessLog)])\n .then((als) => super.modifyAccessLog(als[0]))\n .then((accessLog) => this.decrypt(dataOwner, [accessLog]))\n .then((als) => als[0])\n }\n\n findByUserAfterDate(\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n findByUserAfterDateWithUser(\n user: models.User,\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<models.AccessLog | any> {\n return super\n .findByUserAfterDate(userId, accessType, startDate, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n async findLatestAccessLogsOfPatientsWithUser(user: models.User, userId: string, limit = 100, startDate?: number): Promise<models.AccessLog[]> {\n let foundAccessLogs: AccessLogWithPatientId[] = [],\n nextKeyPair: models.PaginatedDocumentKeyIdPairObject | undefined = undefined\n const numberRequestedAccessLogs = 100\n const MAX_WHILE_ITERATIONS = 5\n\n for (let currentIteration = 0; foundAccessLogs.length < limit && currentIteration < MAX_WHILE_ITERATIONS; currentIteration++) {\n const currentLimit = limit - foundAccessLogs.length\n const { rows: logs, nextKeyPair: newNextKeyPair }: models.PaginatedListAccessLog = (await super.findByUserAfterDate(\n userId,\n 'USER_ACCESS',\n startDate,\n nextKeyPair && JSON.stringify(nextKeyPair.startKey!),\n nextKeyPair && nextKeyPair.startKeyDocId!,\n numberRequestedAccessLogs,\n true\n )) as models.PaginatedListAccessLog\n const logsWithPatientId: AccessLogWithPatientId[] = await this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, logs as AccessLog[]).then(\n (decryptedLogs) =>\n Promise.all(\n _.map(decryptedLogs, (decryptedLog) => {\n return this.crypto.entities.owningEntityIdsOf(decryptedLog, user.healthcarePartyId as string).then(\n (keys) =>\n ({\n ...decryptedLog,\n patientId: _.head(keys),\n } as AccessLogWithPatientId)\n )\n })\n )\n )\n\n const uniqueLogs: AccessLogWithPatientId[] = _.chain(logsWithPatientId)\n .reject((log) => _.some(foundAccessLogs, ({ patientId }) => patientId === log.patientId))\n .uniqBy((log: AccessLogWithPatientId) => log.patientId)\n .value()\n .slice(0, currentLimit)\n\n foundAccessLogs = [...foundAccessLogs, ...uniqueLogs]\n\n if ((logs || []).length < numberRequestedAccessLogs) {\n break\n } else if (newNextKeyPair) {\n nextKeyPair = newNextKeyPair\n } else {\n break\n }\n }\n\n return foundAccessLogs\n }\n\n /**\n * @param accessLog an access log\n * @return the id of the patient that the access log refers to, retrieved from the encrypted metadata (not from the decrypted entity body). Normally\n * there should only be one element in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(accessLog: AccessLog): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(accessLog, undefined)\n }\n\n /**\n * Share an existing access log with other data owners, allowing them to access the non-encrypted data of the access log and optionally also the\n * encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the access log.\n * @param accessLog the access log to share.\n * @param options optional parameters to customize the sharing behaviour:\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}).\n * - sharePatientId: specifies if the id of the patient that this access log refers to should be shared with the delegate. Normally this would\n * be the same as objectId, but it is encrypted separately from it allowing you to give access to the patient id without giving access to the other\n * encrypted data of the access log (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated entity.\n */\n async shareWith(\n delegateId: string,\n accessLog: AccessLog,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<AccessLog> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n return await this.modifyAs(\n self,\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n accessLog,\n delegateId,\n undefined,\n options.shareEncryptionKey,\n options.sharePatientId\n )\n )\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import { IccCryptoXApi } from './icc-crypto-x-api';
|
|
|
4
4
|
import { IccCalendarItemApi } from '../icc-api';
|
|
5
5
|
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
6
6
|
import { AuthenticationProvider } from './auth/AuthenticationProvider';
|
|
7
|
+
import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour';
|
|
7
8
|
export declare class IccCalendarItemXApi extends IccCalendarItemApi {
|
|
8
9
|
i18n: any;
|
|
9
10
|
crypto: IccCryptoXApi;
|
|
@@ -12,11 +13,34 @@ export declare class IccCalendarItemXApi extends IccCalendarItemApi {
|
|
|
12
13
|
constructor(host: string, headers: {
|
|
13
14
|
[key: string]: string;
|
|
14
15
|
}, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, encryptedKeys?: Array<string>, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
15
|
-
newInstance(user: User, ci: CalendarItem,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
newInstance(user: User, ci: CalendarItem, options?: {
|
|
17
|
+
additionalDelegates?: {
|
|
18
|
+
[dataOwnerId: string]: 'WRITE';
|
|
19
|
+
};
|
|
20
|
+
}): Promise<models.CalendarItem>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new instance of calendar item with initialised encryption metadata (not in the database).
|
|
23
|
+
* @param user the current user.
|
|
24
|
+
* @param patient the patient this calendar item refers to.
|
|
25
|
+
* @param ci initialised data for the calendar item. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
|
|
26
|
+
* other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
|
|
27
|
+
* @param options optional parameters:
|
|
28
|
+
* - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
|
|
29
|
+
* 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
|
|
30
|
+
* auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
|
|
31
|
+
* access will be possible.
|
|
32
|
+
* - preferredSfk: secret id of the patient to use as the secret foreign key to use for the access log. The default value will be a
|
|
33
|
+
* secret id of patient known by the topmost parent in the current data owner hierarchy.
|
|
34
|
+
* @return a new instance of calendar item.
|
|
35
|
+
*/
|
|
36
|
+
newInstancePatient(user: models.User, patient: models.Patient | null, ci: any, options?: {
|
|
37
|
+
additionalDelegates?: {
|
|
38
|
+
[dataOwnerId: string]: 'WRITE';
|
|
39
|
+
};
|
|
40
|
+
preferredSfk?: string;
|
|
41
|
+
}): Promise<models.CalendarItem>;
|
|
18
42
|
findBy(hcpartyId: string, patient: models.Patient, usingPost?: boolean): Promise<any>;
|
|
19
|
-
findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem
|
|
43
|
+
findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem>>;
|
|
20
44
|
findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any>;
|
|
21
45
|
createCalendarItem(body?: CalendarItem): never;
|
|
22
46
|
createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any>;
|
|
@@ -44,7 +68,31 @@ export declare class IccCalendarItemXApi extends IccCalendarItemApi {
|
|
|
44
68
|
*/
|
|
45
69
|
resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem;
|
|
46
70
|
modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any>;
|
|
47
|
-
|
|
71
|
+
private modifyAs;
|
|
48
72
|
encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>>;
|
|
73
|
+
private encryptAs;
|
|
49
74
|
decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>>;
|
|
75
|
+
/**
|
|
76
|
+
* @param calendarItem a calendar item
|
|
77
|
+
* @return the id of the patient that the calendar item refers to, retrieved from the encrypted metadata. Normally there should only be one element
|
|
78
|
+
* in the returned array, but in case of entity merges there could be multiple values.
|
|
79
|
+
*/
|
|
80
|
+
decryptPatientIdOf(calendarItem: models.CalendarItem): Promise<string[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also
|
|
83
|
+
* the encrypted content.
|
|
84
|
+
* @param delegateId the id of the data owner which will be granted access to the calendar item.
|
|
85
|
+
* @param calendarItem item the calendar item to share.
|
|
86
|
+
* @param options optional parameters to customize the sharing behaviour:
|
|
87
|
+
* - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
|
|
88
|
+
* content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
|
|
89
|
+
* calendar item does not have encrypted content.
|
|
90
|
+
* - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to
|
|
91
|
+
* {@link ShareMetadataBehaviour.IF_AVAILABLE}).
|
|
92
|
+
* @return a promise which will contain the updated entity.
|
|
93
|
+
*/
|
|
94
|
+
shareWith(delegateId: string, calendarItem: models.CalendarItem, options?: {
|
|
95
|
+
shareEncryptionKey?: ShareMetadataBehaviour;
|
|
96
|
+
sharePatientId?: ShareMetadataBehaviour;
|
|
97
|
+
}): Promise<models.CalendarItem>;
|
|
50
98
|
}
|
|
@@ -23,8 +23,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.IccCalendarItemXApi = void 0;
|
|
24
24
|
const i18n = require("./rsrc/contact.i18n");
|
|
25
25
|
const _ = require("lodash");
|
|
26
|
+
const models_1 = require("../icc-api/model/models");
|
|
26
27
|
const icc_api_1 = require("../icc-api");
|
|
27
|
-
const utils_1 = require("./utils");
|
|
28
28
|
const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
|
|
29
29
|
class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
30
30
|
constructor(host, headers, crypto, dataOwnerApi, encryptedKeys = ['details', 'title', 'patientId'], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
|
|
@@ -39,52 +39,79 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
39
39
|
this.dataOwnerApi = dataOwnerApi;
|
|
40
40
|
this.encryptedKeys = encryptedKeys;
|
|
41
41
|
}
|
|
42
|
-
newInstance(user, ci,
|
|
43
|
-
return this.newInstancePatient(user, null, ci,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
42
|
+
newInstance(user, ci, options = {}) {
|
|
43
|
+
return this.newInstancePatient(user, null, ci, options);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new instance of calendar item with initialised encryption metadata (not in the database).
|
|
47
|
+
* @param user the current user.
|
|
48
|
+
* @param patient the patient this calendar item refers to.
|
|
49
|
+
* @param ci initialised data for the calendar item. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
|
|
50
|
+
* other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
|
|
51
|
+
* @param options optional parameters:
|
|
52
|
+
* - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
|
|
53
|
+
* 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
|
|
54
|
+
* auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
|
|
55
|
+
* access will be possible.
|
|
56
|
+
* - preferredSfk: secret id of the patient to use as the secret foreign key to use for the access log. The default value will be a
|
|
57
|
+
* secret id of patient known by the topmost parent in the current data owner hierarchy.
|
|
58
|
+
* @return a new instance of calendar item.
|
|
59
|
+
*/
|
|
60
|
+
newInstancePatient(user, patient, ci, options = {}) {
|
|
61
|
+
var _a, _b, _c, _d, _e, _f;
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
if (!patient && options.preferredSfk)
|
|
64
|
+
throw new Error('You need to specify parent patient in order to use secret foreign keys.');
|
|
65
|
+
const calendarItem = _.extend({
|
|
66
|
+
id: this.crypto.primitives.randomUuid(),
|
|
67
|
+
_type: 'org.taktik.icure.entities.CalendarItem',
|
|
68
|
+
created: new Date().getTime(),
|
|
69
|
+
modified: new Date().getTime(),
|
|
70
|
+
responsible: this.dataOwnerApi.getDataOwnerIdOf(user),
|
|
71
|
+
author: user.id,
|
|
72
|
+
codes: [],
|
|
73
|
+
tags: [],
|
|
74
|
+
}, ci || {});
|
|
75
|
+
const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
|
|
76
|
+
if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
|
|
77
|
+
throw new Error('Can only initialise entities as current data owner.');
|
|
78
|
+
const sfk = patient ? (_a = options.preferredSfk) !== null && _a !== void 0 ? _a : (yield this.crypto.confidential.getAnySecretIdSharedWithParents(patient)) : undefined;
|
|
79
|
+
if (patient && !sfk)
|
|
80
|
+
throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
|
|
81
|
+
const extraDelegations = [
|
|
82
|
+
...Object.keys((_b = options.additionalDelegates) !== null && _b !== void 0 ? _b : {}),
|
|
83
|
+
...((_d = (_c = user.autoDelegations) === null || _c === void 0 ? void 0 : _c.all) !== null && _d !== void 0 ? _d : []),
|
|
84
|
+
...((_f = (_e = user.autoDelegations) === null || _e === void 0 ? void 0 : _e.medicalInformation) !== null && _f !== void 0 ? _f : []),
|
|
85
|
+
];
|
|
86
|
+
return new models_1.CalendarItem(yield this.crypto.entities
|
|
87
|
+
.entityWithInitialisedEncryptedMetadata(calendarItem, patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, extraDelegations)
|
|
88
|
+
.then((x) => x.updatedEntity));
|
|
89
|
+
});
|
|
73
90
|
}
|
|
74
91
|
findBy(hcpartyId, patient, usingPost = false) {
|
|
75
|
-
return this
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const extractedKeys = yield this.crypto.entities.secretIdsOf(patient, hcpartyId);
|
|
94
|
+
const topmostParentId = (yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0];
|
|
95
|
+
return extractedKeys && extractedKeys.length > 0
|
|
96
|
+
? usingPost
|
|
97
|
+
? yield this.findByHCPartyPatientSecretFKeysArray(topmostParentId, _.uniq(extractedKeys))
|
|
98
|
+
: yield this.findByHCPartyPatientSecretFKeys(topmostParentId, _.uniq(extractedKeys).join(','))
|
|
80
99
|
: Promise.resolve([]);
|
|
81
100
|
});
|
|
82
101
|
}
|
|
83
102
|
findByHCPartyPatientSecretFKeys(hcPartyId, secretFKeys) {
|
|
84
|
-
|
|
103
|
+
const _super = Object.create(null, {
|
|
104
|
+
findCalendarItemsByHCPartyPatientForeignKeys: { get: () => super.findCalendarItemsByHCPartyPatientForeignKeys }
|
|
105
|
+
});
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const calendarItems = yield _super.findCalendarItemsByHCPartyPatientForeignKeys.call(this, hcPartyId, secretFKeys);
|
|
108
|
+
return yield this.decrypt(hcPartyId, calendarItems);
|
|
109
|
+
});
|
|
85
110
|
}
|
|
86
111
|
findByHCPartyPatientSecretFKeysArray(hcPartyId, secretFKeys) {
|
|
87
|
-
return super
|
|
112
|
+
return super
|
|
113
|
+
.findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)
|
|
114
|
+
.then((calendarItems) => this.decrypt(hcPartyId, calendarItems));
|
|
88
115
|
}
|
|
89
116
|
createCalendarItem(body) {
|
|
90
117
|
throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption');
|
|
@@ -97,7 +124,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
97
124
|
return body
|
|
98
125
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
99
126
|
.then((items) => _super.createCalendarItem.call(this, items[0]))
|
|
100
|
-
.then((ci) => this.decrypt(this.dataOwnerApi.
|
|
127
|
+
.then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), [ci]))
|
|
101
128
|
.then((cis) => cis[0])
|
|
102
129
|
: null;
|
|
103
130
|
});
|
|
@@ -105,20 +132,20 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
105
132
|
getCalendarItemWithUser(user, calendarItemId) {
|
|
106
133
|
return super
|
|
107
134
|
.getCalendarItem(calendarItemId)
|
|
108
|
-
.then((calendarItem) => this.decrypt(this.dataOwnerApi.
|
|
135
|
+
.then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), [calendarItem]))
|
|
109
136
|
.then((cis) => cis[0]);
|
|
110
137
|
}
|
|
111
138
|
getCalendarItem(calendarItemId) {
|
|
112
139
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
113
140
|
}
|
|
114
141
|
getCalendarItemsWithUser(user) {
|
|
115
|
-
return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.
|
|
142
|
+
return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), calendarItems));
|
|
116
143
|
}
|
|
117
144
|
getCalendarItems() {
|
|
118
145
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
119
146
|
}
|
|
120
147
|
getCalendarItemsWithIdsWithUser(user, body) {
|
|
121
|
-
return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.
|
|
148
|
+
return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), calendarItems));
|
|
122
149
|
}
|
|
123
150
|
getCalendarItemsWithIds(body) {
|
|
124
151
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -126,7 +153,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
126
153
|
getCalendarItemsByPeriodAndHcPartyIdWithUser(user, startDate, endDate, hcPartyId) {
|
|
127
154
|
return super
|
|
128
155
|
.getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)
|
|
129
|
-
.then((calendarItems) => this.decrypt(this.dataOwnerApi.
|
|
156
|
+
.then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), calendarItems));
|
|
130
157
|
}
|
|
131
158
|
getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId) {
|
|
132
159
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -134,7 +161,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
134
161
|
getCalendarsByPeriodAndAgendaIdWithUser(user, startDate, endDate, agendaId) {
|
|
135
162
|
return super
|
|
136
163
|
.getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)
|
|
137
|
-
.then((calendarItems) => this.decrypt(this.dataOwnerApi.
|
|
164
|
+
.then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), calendarItems));
|
|
138
165
|
}
|
|
139
166
|
getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId) {
|
|
140
167
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -158,68 +185,53 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
158
185
|
return resetCalendarItem;
|
|
159
186
|
}
|
|
160
187
|
modifyCalendarItemWithHcParty(user, body) {
|
|
161
|
-
const _super = Object.create(null, {
|
|
162
|
-
modifyCalendarItem: { get: () => super.modifyCalendarItem }
|
|
163
|
-
});
|
|
164
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
return body
|
|
166
|
-
? this.encrypt(user, [_.cloneDeep(body)])
|
|
167
|
-
.then((items) => _super.modifyCalendarItem.call(this, items[0]))
|
|
168
|
-
.then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ci]))
|
|
169
|
-
.then((cis) => cis[0])
|
|
170
|
-
: null;
|
|
189
|
+
return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user), _.cloneDeep(body)) : null;
|
|
171
190
|
});
|
|
172
191
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}));
|
|
179
|
-
(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach((delegateId) => (promise = promise.then((item) => this.crypto.appendEncryptionKeys(item, dataOwnerId, delegateId, eks.secretId).then((extraEks) => {
|
|
180
|
-
return _.extend(extraEks.modifiedObject, {
|
|
181
|
-
encryptionKeys: extraEks.encryptionKeys,
|
|
182
|
-
});
|
|
183
|
-
}))));
|
|
184
|
-
return promise;
|
|
185
|
-
});
|
|
192
|
+
modifyAs(dataOwner, body) {
|
|
193
|
+
return this.encryptAs(dataOwner, [_.cloneDeep(body)])
|
|
194
|
+
.then((als) => super.modifyCalendarItem(als[0]))
|
|
195
|
+
.then((body) => this.decrypt(dataOwner, [body]))
|
|
196
|
+
.then((als) => als[0]);
|
|
186
197
|
}
|
|
187
198
|
encrypt(user, calendarItems) {
|
|
188
|
-
return
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
.then((eks) => this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(eks.extractedKeys[0].replace(/-/g, ''))))
|
|
193
|
-
.then((key) => (0, utils_1.crypt)(calendarItem, (obj) => this.crypto.AES.encrypt(key, (0, utils_1.utf8_2ua)(JSON.stringify(obj))), this.encryptedKeys))));
|
|
199
|
+
return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), calendarItems);
|
|
200
|
+
}
|
|
201
|
+
encryptAs(dataOwnerId, calendarItems) {
|
|
202
|
+
return Promise.all(calendarItems.map((x) => this.crypto.entities.tryEncryptEntity(x, dataOwnerId, this.encryptedKeys, false, true, (json) => new models_1.CalendarItem(json))));
|
|
194
203
|
}
|
|
195
204
|
decrypt(hcpId, calendarItems) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
205
|
+
return Promise.all(calendarItems.map((x) => this.crypto.entities.decryptEntity(x, hcpId, (json) => new models_1.CalendarItem(json)).then(({ entity }) => entity)));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @param calendarItem a calendar item
|
|
209
|
+
* @return the id of the patient that the calendar item refers to, retrieved from the encrypted metadata. Normally there should only be one element
|
|
210
|
+
* in the returned array, but in case of entity merges there could be multiple values.
|
|
211
|
+
*/
|
|
212
|
+
decryptPatientIdOf(calendarItem) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
return this.crypto.entities.owningEntityIdsOf(calendarItem, undefined);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also
|
|
219
|
+
* the encrypted content.
|
|
220
|
+
* @param delegateId the id of the data owner which will be granted access to the calendar item.
|
|
221
|
+
* @param calendarItem item the calendar item to share.
|
|
222
|
+
* @param options optional parameters to customize the sharing behaviour:
|
|
223
|
+
* - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
|
|
224
|
+
* content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
|
|
225
|
+
* calendar item does not have encrypted content.
|
|
226
|
+
* - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to
|
|
227
|
+
* {@link ShareMetadataBehaviour.IF_AVAILABLE}).
|
|
228
|
+
* @return a promise which will contain the updated entity.
|
|
229
|
+
*/
|
|
230
|
+
shareWith(delegateId, calendarItem, options = {}) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
const self = yield this.dataOwnerApi.getCurrentDataOwnerId();
|
|
233
|
+
return yield this.modifyAs(self, yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(calendarItem, delegateId, undefined, options.shareEncryptionKey, options.sharePatientId));
|
|
234
|
+
});
|
|
223
235
|
}
|
|
224
236
|
}
|
|
225
237
|
exports.IccCalendarItemXApi = IccCalendarItemXApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAI3B,wCAA+C;AAC/C,mCAAmE;AAEnE,0EAAgG;AAEhG,MAAa,mBAAoB,SAAQ,4BAAkB;IAMzD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,gBAA+B,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,EAChE,yBAAiD,IA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I,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;wBACzB,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;qBACrC;oBACD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,IAAA,cAAM,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CACtF,IAAA,eAAO,EAAC,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,CAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;yBAC7B,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;wBACZ,MAAM,WAAW,GAAG,GAAG,IAAI,IAAA,eAAO,EAAC,GAAG,CAAC,CAAA;wBACvC,IAAI;4BACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;yBAC/B;wBAAC,OAAO,CAAC,EAAE;4BACV,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,YAAY,CAAC,EAAE,EAAE,WAAW,IAAI,iBAAiB,CAAC,CAAA;4BAC5F,OAAO,EAAE,CAAA;yBACV;oBACH,CAAC,CAAC;yBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;wBACb,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;wBAC/C,OAAO,EAAE,CAAA;oBACX,CAAC,CAAC,CACL,CACF,CAAA;gBACH,CAAC,CAAC;gBACN,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QACnC,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF;AA1RD,kDA0RC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { crypt, decrypt, hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n encryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\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 this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: User, ci: CalendarItem, delegates: string[] = []) {\n return this.newInstancePatient(user, null, ci, delegates)\n }\n\n newInstancePatient(user: models.User, patient: models.Patient | null, ci: any, delegates: string[] = []): Promise<models.CalendarItem> {\n const calendarItem = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.CalendarItem',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n ci || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient | null,\n calendarItem: models.CalendarItem,\n delegates: string[] = []\n ): Promise<models.CalendarItem> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.extractDelegationsSFKs(patient, dataOwnerId!).then(async (secretForeignKeys) => {\n const dels = await this.crypto.initObjectDelegations(calendarItem, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0])\n const eks = await this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!)\n\n _.extend(calendarItem, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(calendarItem)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((contact) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, contact, dataOwnerId!, delegateId, dels.secretId, eks.secretId)\n ))\n )\n return promise\n })\n }\n\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n return this.crypto.extractDelegationsSFKs(patient, hcpartyId).then((secretForeignKeys) => {\n return secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? (usingPost ?\n this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys)) :\n this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(',')))\n : Promise.resolve([])\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem> | any> {\n return super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any> {\n return super.findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.modifyCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n initEncryptionKeys(user: models.User, calendarItem: models.CalendarItem): Promise<models.CalendarItem> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(calendarItem, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((item) =>\n this.crypto.appendEncryptionKeys(item, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((calendarItem) =>\n (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length\n ? Promise.resolve(calendarItem)\n : this.initEncryptionKeys(user, calendarItem)\n )\n .then((calendarItem: CalendarItem) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(\n this.dataOwnerApi.getDataOwnerOf(user)!,\n calendarItem.id!,\n calendarItem.encryptionKeys!\n )\n )\n .then((eks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(eks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n crypt(calendarItem, (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))), this.encryptedKeys)\n )\n )\n )\n }\n\n decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n calendarItems.map((calendarItem) => {\n return calendarItem.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n calendarItem.id!,\n _.size(calendarItem.encryptionKeys) ? calendarItem.encryptionKeys! : calendarItem.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n return Promise.resolve(calendarItem)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then((key) =>\n decrypt(calendarItem, (ec) =>\n this.crypto.AES.decrypt(key, ec)\n .then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse calendar item', calendarItem.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n .catch((err) => {\n console.log('Error during AES decryption', err)\n return {}\n })\n )\n )\n })\n : Promise.resolve(calendarItem)\n })\n )\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAE3B,oDAA4D;AAE5D,wCAA+C;AAE/C,0EAAgG;AAGhG,MAAa,mBAAoB,SAAQ,4BAAkB;IAMzD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,gBAA+B,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,EAChE,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;QAlBzD,SAAI,GAAQ,IAAI,CAAA;QAGhB,kBAAa,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QAgB/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED,WAAW,CAAC,IAAU,EAAE,EAAgB,EAAE,UAAwE,EAAE;QAClH,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;I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AAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;QACxE,CAAC;KAAA;IAED;;;;;;;;;;;;OAYG;IACG,SAAS,CACb,UAAkB,EAClB,YAAiC,EACjC,UAGI,EAAE;;YAEN,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAA;YAC5D,OAAO,MAAM,IAAI,CAAC,QAAQ,CACxB,IAAI,EACJ,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAChE,YAAY,EACZ,UAAU,EACV,SAAS,EACT,OAAO,CAAC,kBAAkB,EAC1B,OAAO,CAAC,cAAc,CACvB,CACF,CAAA;QACH,CAAC;KAAA;CACF;AA1QD,kDA0QC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n encryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\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 this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: User, ci: CalendarItem, options: { additionalDelegates?: { [dataOwnerId: string]: 'WRITE' } } = {}) {\n return this.newInstancePatient(user, null, ci, options)\n }\n\n /**\n * Creates a new instance of calendar item with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this calendar item refers to.\n * @param ci initialised data for the calendar item. 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. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the access log. 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 calendar item.\n */\n async newInstancePatient(\n user: models.User,\n patient: models.Patient | null,\n ci: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ): Promise<models.CalendarItem> {\n if (!patient && options.preferredSfk) throw new Error('You need to specify parent patient in order to use secret foreign keys.')\n const calendarItem = _.extend(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.CalendarItem',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerIdOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n ci || {}\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 = patient ? options.preferredSfk ?? (await this.crypto.confidential.getAnySecretIdSharedWithParents(patient)) : undefined\n if (patient && !sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = [\n ...Object.keys(options.additionalDelegates ?? {}),\n ...(user.autoDelegations?.all ?? []),\n ...(user.autoDelegations?.medicalInformation ?? []),\n ]\n return new CalendarItem(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(calendarItem, patient?.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n const extractedKeys = await this.crypto.entities.secretIdsOf(patient, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? usingPost\n ? await this.findByHCPartyPatientSecretFKeysArray(topmostParentId, _.uniq(extractedKeys))\n : await this.findByHCPartyPatientSecretFKeys(topmostParentId, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n\n async findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem>> {\n const calendarItems = await super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys)\n return await this.decrypt(hcPartyId, calendarItems)\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any> {\n return super\n .findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, _.cloneDeep(body)) : null\n }\n\n private modifyAs(dataOwner: string, body: models.CalendarItem): Promise<models.CalendarItem> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((als) => super.modifyCalendarItem(als[0]))\n .then((body) => this.decrypt(dataOwner, [body]))\n .then((als) => als[0])\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems)\n }\n\n private encryptAs(dataOwnerId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((x) =>\n this.crypto.entities.tryEncryptEntity(x, dataOwnerId, this.encryptedKeys, false, true, (json) => new CalendarItem(json))\n )\n )\n }\n\n decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((x) => this.crypto.entities.decryptEntity(x, hcpId, (json) => new CalendarItem(json)).then(({ entity }) => entity))\n )\n }\n\n /**\n * @param calendarItem a calendar item\n * @return the id of the patient that the calendar item 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(calendarItem: models.CalendarItem): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(calendarItem, undefined)\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the calendar item.\n * @param calendarItem item the calendar item to share.\n * @param options optional parameters to customize the sharing behaviour:\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated entity.\n */\n async shareWith(\n delegateId: string,\n calendarItem: models.CalendarItem,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.CalendarItem> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n return await this.modifyAs(\n self,\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n calendarItem,\n delegateId,\n undefined,\n options.shareEncryptionKey,\n options.sharePatientId\n )\n )\n }\n}\n"]}
|