@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.
Files changed (154) hide show
  1. package/icc-api/api/IccDeviceApi.d.ts +1 -1
  2. package/icc-api/api/IccDeviceApi.js.map +1 -1
  3. package/icc-api/api/IccDoctemplateApi.js.map +1 -1
  4. package/icc-api/api/IccDocumentTemplateApi.js.map +1 -1
  5. package/icc-api/api/IccHcpartyApi.d.ts +1 -1
  6. package/icc-api/api/IccHcpartyApi.js.map +1 -1
  7. package/icc-api/api/IccPatientApi.d.ts +1 -1
  8. package/icc-api/api/IccPatientApi.js.map +1 -1
  9. package/icc-api/model/MaintenanceTask.d.ts +6 -5
  10. package/icc-api/model/MaintenanceTask.js +5 -0
  11. package/icc-api/model/MaintenanceTask.js.map +1 -1
  12. package/icc-api/model/User.d.ts +23 -1
  13. package/icc-api/model/User.js +21 -0
  14. package/icc-api/model/User.js.map +1 -1
  15. package/icc-api/model/models.d.ts +14 -0
  16. package/icc-api/model/models.js.map +1 -1
  17. package/icc-x-api/crypto/AES.d.ts +2 -0
  18. package/icc-x-api/crypto/AES.js +12 -0
  19. package/icc-x-api/crypto/AES.js.map +1 -1
  20. package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +122 -0
  21. package/icc-x-api/crypto/BaseExchangeKeysManager.js +356 -0
  22. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -0
  23. package/icc-x-api/crypto/ConfidentialEntities.d.ts +58 -0
  24. package/icc-x-api/crypto/ConfidentialEntities.js +99 -0
  25. package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -0
  26. package/icc-x-api/crypto/CryptoPrimitives.d.ts +31 -0
  27. package/icc-x-api/crypto/CryptoPrimitives.js +55 -0
  28. package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -0
  29. package/icc-x-api/crypto/CryptoStrategies.d.ts +82 -0
  30. package/icc-x-api/crypto/CryptoStrategies.js +3 -0
  31. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -0
  32. package/icc-x-api/crypto/EntitiesEncryption.d.ts +254 -0
  33. package/icc-x-api/crypto/EntitiesEncryption.js +700 -0
  34. package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -0
  35. package/icc-x-api/crypto/ExchangeKeysManager.d.ts +56 -0
  36. package/icc-x-api/crypto/ExchangeKeysManager.js +147 -0
  37. package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -0
  38. package/icc-x-api/crypto/KeyManager.d.ts +103 -0
  39. package/icc-x-api/crypto/KeyManager.js +288 -0
  40. package/icc-x-api/crypto/KeyManager.js.map +1 -0
  41. package/icc-x-api/crypto/KeyRecovery.d.ts +34 -0
  42. package/icc-x-api/crypto/KeyRecovery.js +253 -0
  43. package/icc-x-api/crypto/KeyRecovery.js.map +1 -0
  44. package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +28 -0
  45. package/icc-x-api/crypto/LegacyCryptoStrategies.js +22 -0
  46. package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -0
  47. package/icc-x-api/crypto/RSA.d.ts +19 -20
  48. package/icc-x-api/crypto/RSA.js +30 -1
  49. package/icc-x-api/crypto/RSA.js.map +1 -1
  50. package/icc-x-api/crypto/ShamirKeysManager.d.ts +43 -0
  51. package/icc-x-api/crypto/ShamirKeysManager.js +150 -0
  52. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -0
  53. package/icc-x-api/crypto/ShareMetadataBehaviour.d.ts +19 -0
  54. package/icc-x-api/crypto/ShareMetadataBehaviour.js +24 -0
  55. package/icc-x-api/crypto/ShareMetadataBehaviour.js.map +1 -0
  56. package/icc-x-api/crypto/TransferKeysManager.d.ts +29 -0
  57. package/icc-x-api/crypto/TransferKeysManager.js +121 -0
  58. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -0
  59. package/icc-x-api/crypto/utils.d.ts +46 -0
  60. package/icc-x-api/crypto/utils.js +128 -0
  61. package/icc-x-api/crypto/utils.js.map +1 -1
  62. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.d.ts +11 -0
  63. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js +11 -0
  64. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js.map +1 -1
  65. package/icc-x-api/filters/DeviceByHcPartyFilter.d.ts +11 -0
  66. package/icc-x-api/filters/DeviceByHcPartyFilter.js +11 -0
  67. package/icc-x-api/filters/DeviceByHcPartyFilter.js.map +1 -1
  68. package/icc-x-api/filters/DeviceByIdsFilter.d.ts +11 -0
  69. package/icc-x-api/filters/DeviceByIdsFilter.js +11 -0
  70. package/icc-x-api/filters/DeviceByIdsFilter.js.map +1 -1
  71. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.d.ts +11 -0
  72. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js +11 -0
  73. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js.map +1 -1
  74. package/icc-x-api/icc-accesslog-x-api.d.ts +49 -4
  75. package/icc-x-api/icc-accesslog-x-api.js +112 -102
  76. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  77. package/icc-x-api/icc-calendar-item-x-api.d.ts +53 -5
  78. package/icc-x-api/icc-calendar-item-x-api.js +112 -100
  79. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  80. package/icc-x-api/icc-classification-x-api.d.ts +45 -2
  81. package/icc-x-api/icc-classification-x-api.js +89 -41
  82. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  83. package/icc-x-api/icc-contact-x-api.d.ts +57 -19
  84. package/icc-x-api/icc-contact-x-api.js +149 -154
  85. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  86. package/icc-x-api/icc-crypto-x-api.d.ts +266 -366
  87. package/icc-x-api/icc-crypto-x-api.js +416 -1327
  88. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  89. package/icc-x-api/icc-data-owner-x-api.d.ts +110 -11
  90. package/icc-x-api/icc-data-owner-x-api.js +188 -14
  91. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  92. package/icc-x-api/icc-doctemplate-x-api.js +3 -3
  93. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  94. package/icc-x-api/icc-document-x-api.d.ts +76 -5
  95. package/icc-x-api/icc-document-x-api.js +137 -59
  96. package/icc-x-api/icc-document-x-api.js.map +1 -1
  97. package/icc-x-api/icc-form-x-api.d.ts +47 -7
  98. package/icc-x-api/icc-form-x-api.js +85 -86
  99. package/icc-x-api/icc-form-x-api.js.map +1 -1
  100. package/icc-x-api/icc-hcparty-x-api.d.ts +1 -1
  101. package/icc-x-api/icc-hcparty-x-api.js +1 -1
  102. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  103. package/icc-x-api/icc-helement-x-api.d.ts +50 -3
  104. package/icc-x-api/icc-helement-x-api.js +101 -118
  105. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  106. package/icc-x-api/icc-icure-maintenance-x-api.d.ts +31 -0
  107. package/icc-x-api/icc-icure-maintenance-x-api.js +124 -0
  108. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -0
  109. package/icc-x-api/icc-invoice-x-api.d.ts +45 -5
  110. package/icc-x-api/icc-invoice-x-api.js +89 -64
  111. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  112. package/icc-x-api/icc-maintenance-task-x-api.d.ts +38 -6
  113. package/icc-x-api/icc-maintenance-task-x-api.js +73 -102
  114. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  115. package/icc-x-api/icc-message-x-api.d.ts +55 -2
  116. package/icc-x-api/icc-message-x-api.js +92 -33
  117. package/icc-x-api/icc-message-x-api.js.map +1 -1
  118. package/icc-x-api/icc-patient-x-api.d.ts +67 -7
  119. package/icc-x-api/icc-patient-x-api.js +409 -473
  120. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  121. package/icc-x-api/icc-receipt-x-api.d.ts +49 -5
  122. package/icc-x-api/icc-receipt-x-api.js +85 -47
  123. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  124. package/icc-x-api/icc-time-table-x-api.d.ts +34 -10
  125. package/icc-x-api/icc-time-table-x-api.js +61 -18
  126. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  127. package/icc-x-api/index.d.ts +30 -1
  128. package/icc-x-api/index.js +112 -49
  129. package/icc-x-api/index.js.map +1 -1
  130. package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +35 -0
  131. package/icc-x-api/maintenance/KeyPairUpdateRequest.js +54 -0
  132. package/icc-x-api/maintenance/KeyPairUpdateRequest.js.map +1 -0
  133. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +9 -0
  134. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +23 -0
  135. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -0
  136. package/icc-x-api/storage/IcureStorageFacade.d.ts +55 -0
  137. package/icc-x-api/storage/IcureStorageFacade.js +95 -0
  138. package/icc-x-api/storage/IcureStorageFacade.js.map +1 -0
  139. package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +31 -0
  140. package/icc-x-api/storage/StorageEntryKeysFactory.js +3 -0
  141. package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -0
  142. package/icc-x-api/utils/collection-utils.d.ts +8 -0
  143. package/icc-x-api/utils/collection-utils.js +26 -0
  144. package/icc-x-api/utils/collection-utils.js.map +1 -0
  145. package/icc-x-api/utils/crypto-utils.d.ts +8 -1
  146. package/icc-x-api/utils/crypto-utils.js +19 -3
  147. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  148. package/icc-x-api/utils/graph-utils.d.ts +45 -0
  149. package/icc-x-api/utils/graph-utils.js +203 -0
  150. package/icc-x-api/utils/graph-utils.js.map +1 -0
  151. package/icc-x-api/utils/lru-temporised-async-cache.d.ts +27 -0
  152. package/icc-x-api/utils/lru-temporised-async-cache.js +120 -0
  153. package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -0
  154. package/package.json +1 -1
@@ -3,13 +3,56 @@ import { IccCryptoXApi } from './icc-crypto-x-api';
3
3
  import * as models from '../icc-api/model/models';
4
4
  import { IccDataOwnerXApi } from './icc-data-owner-x-api';
5
5
  import { AuthenticationProvider } from './auth/AuthenticationProvider';
6
+ import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour';
6
7
  export declare class IccClassificationXApi extends IccClassificationApi {
7
8
  crypto: IccCryptoXApi;
8
9
  dataOwnerApi: IccDataOwnerXApi;
9
10
  constructor(host: string, headers: {
10
11
  [key: string]: string;
11
12
  }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
12
- newInstance(user: models.User, patient: models.Patient, c?: any, delegates?: string[]): Promise<models.Classification>;
13
- initDelegationsAndEncryptionKeys(user: models.User, patient: models.Patient, classification: models.Classification, delegates?: string[]): Promise<models.Classification>;
13
+ /**
14
+ * Creates a new instance of classification with initialised encryption metadata (not in the database).
15
+ * @param user the current user.
16
+ * @param patient the patient this classification refers to.
17
+ * @param c initialised data for the classification. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
18
+ * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
19
+ * @param options optional parameters:
20
+ * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
21
+ * 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
22
+ * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
23
+ * access will be possible.
24
+ * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
25
+ * secret id of patient known by the topmost parent in the current data owner hierarchy.
26
+ * @return a new instance of classification.
27
+ */
28
+ newInstance(user: models.User, patient: models.Patient, c?: any, options?: {
29
+ additionalDelegates?: {
30
+ [dataOwnerId: string]: 'WRITE';
31
+ };
32
+ preferredSfk?: string;
33
+ }): Promise<models.Classification>;
14
34
  findBy(hcpartyId: string, patient: models.Patient): Promise<models.Classification[]>;
35
+ /**
36
+ * @param classification a classification
37
+ * @return the id of the patient that the classification refers to, retrieved from the encrypted metadata. Normally there should only be one element
38
+ * in the returned array, but in case of entity merges there could be multiple values.
39
+ */
40
+ decryptPatientIdOf(classification: models.Classification): Promise<string[]>;
41
+ /**
42
+ * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also
43
+ * the encrypted content.
44
+ * @param delegateId the id of the data owner which will be granted access to the classification.
45
+ * @param classification the classification to share.
46
+ * @param options optional parameters to customize the sharing behaviour:
47
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
48
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
49
+ * classification does not have encrypted content.
50
+ * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to
51
+ * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
52
+ * @return a promise which will contain the updated classification.
53
+ */
54
+ shareWith(delegateId: string, classification: models.Classification, options?: {
55
+ shareEncryptionKey?: ShareMetadataBehaviour;
56
+ sharePatientId?: ShareMetadataBehaviour;
57
+ }): Promise<models.Classification>;
15
58
  }
@@ -1,7 +1,17 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.IccClassificationXApi = void 0;
4
13
  const icc_api_1 = require("../icc-api");
14
+ const models = require("../icc-api/model/models");
5
15
  const _ = require("lodash");
6
16
  const moment = require("moment");
7
17
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
@@ -15,50 +25,88 @@ class IccClassificationXApi extends icc_api_1.IccClassificationApi {
15
25
  this.crypto = crypto;
16
26
  this.dataOwnerApi = dataOwnerApi;
17
27
  }
18
- newInstance(user, patient, c = {}, delegates = []) {
19
- const classification = _.assign({
20
- id: this.crypto.randomUuid(),
21
- _type: 'org.taktik.icure.entities.Classification',
22
- created: new Date().getTime(),
23
- modified: new Date().getTime(),
24
- responsible: this.dataOwnerApi.getDataOwnerOf(user),
25
- author: user.id,
26
- codes: [],
27
- tags: [],
28
- healthElementId: this.crypto.randomUuid(),
29
- openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),
30
- }, c || {});
31
- return this.initDelegationsAndEncryptionKeys(user, patient, classification, delegates);
32
- }
33
- initDelegationsAndEncryptionKeys(user, patient, classification, delegates = []) {
34
- const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
35
- return this.crypto
36
- .extractDelegationsSFKs(patient, dataOwnerId)
37
- .then((secretForeignKeys) => this.crypto.initObjectDelegations(classification, patient, dataOwnerId, secretForeignKeys.extractedKeys[0]))
38
- .then((initData) => {
39
- _.extend(classification, {
40
- delegations: initData.delegations,
41
- cryptedForeignKeys: initData.cryptedForeignKeys,
42
- secretForeignKeys: initData.secretForeignKeys,
43
- });
44
- let promise = Promise.resolve(classification);
45
- _.uniq(delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])).forEach((delegateId) => (promise = promise.then((classification) => this.crypto
46
- .extendedDelegationsAndCryptedForeignKeys(classification, patient, dataOwnerId, delegateId, initData.secretId)
47
- .then((extraData) => _.extend(classification, {
48
- delegations: extraData.delegations,
49
- cryptedForeignKeys: extraData.cryptedForeignKeys,
50
- }))
51
- .catch((e) => {
52
- console.log(e);
53
- return classification;
54
- }))));
55
- return promise;
28
+ /**
29
+ * Creates a new instance of classification with initialised encryption metadata (not in the database).
30
+ * @param user the current user.
31
+ * @param patient the patient this classification refers to.
32
+ * @param c initialised data for the classification. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
33
+ * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
34
+ * @param options optional parameters:
35
+ * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
36
+ * 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
37
+ * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
38
+ * access will be possible.
39
+ * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
40
+ * secret id of patient known by the topmost parent in the current data owner hierarchy.
41
+ * @return a new instance of classification.
42
+ */
43
+ newInstance(user, patient, c = {}, options = {}) {
44
+ var _a, _b, _c, _d, _e, _f;
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const classification = _.assign({
47
+ id: this.crypto.primitives.randomUuid(),
48
+ _type: 'org.taktik.icure.entities.Classification',
49
+ created: new Date().getTime(),
50
+ modified: new Date().getTime(),
51
+ responsible: this.dataOwnerApi.getDataOwnerIdOf(user),
52
+ author: user.id,
53
+ codes: [],
54
+ tags: [],
55
+ healthElementId: this.crypto.primitives.randomUuid(),
56
+ openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),
57
+ }, c || {});
58
+ const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
59
+ if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
60
+ throw new Error('Can only initialise entities as current data owner.');
61
+ const sfk = (_a = options.preferredSfk) !== null && _a !== void 0 ? _a : (yield this.crypto.confidential.getAnySecretIdSharedWithParents(patient));
62
+ if (!sfk)
63
+ throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
64
+ const extraDelegations = [
65
+ ...Object.keys((_b = options.additionalDelegates) !== null && _b !== void 0 ? _b : {}),
66
+ ...((_d = (_c = user.autoDelegations) === null || _c === void 0 ? void 0 : _c.all) !== null && _d !== void 0 ? _d : []),
67
+ ...((_f = (_e = user.autoDelegations) === null || _e === void 0 ? void 0 : _e.medicalInformation) !== null && _f !== void 0 ? _f : []),
68
+ ];
69
+ return new models.Classification(yield this.crypto.entities
70
+ .entityWithInitialisedEncryptedMetadata(classification, patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, extraDelegations)
71
+ .then((x) => x.updatedEntity));
56
72
  });
57
73
  }
58
74
  findBy(hcpartyId, patient) {
59
- return this.crypto
60
- .extractDelegationsSFKs(patient, hcpartyId)
61
- .then((secretForeignKeys) => this.findClassificationsByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys).join(',')));
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const extractedKeys = yield this.crypto.entities.secretIdsOf(patient, hcpartyId);
77
+ const topmostParentId = (yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0];
78
+ return extractedKeys && extractedKeys.length > 0
79
+ ? this.findClassificationsByHCPartyPatientForeignKeys(topmostParentId, _.uniq(extractedKeys).join(','))
80
+ : Promise.resolve([]);
81
+ });
82
+ }
83
+ /**
84
+ * @param classification a classification
85
+ * @return the id of the patient that the classification refers to, retrieved from the encrypted metadata. Normally there should only be one element
86
+ * in the returned array, but in case of entity merges there could be multiple values.
87
+ */
88
+ decryptPatientIdOf(classification) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ return this.crypto.entities.owningEntityIdsOf(classification, undefined);
91
+ });
92
+ }
93
+ /**
94
+ * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also
95
+ * the encrypted content.
96
+ * @param delegateId the id of the data owner which will be granted access to the classification.
97
+ * @param classification the classification to share.
98
+ * @param options optional parameters to customize the sharing behaviour:
99
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
100
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
101
+ * classification does not have encrypted content.
102
+ * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to
103
+ * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
104
+ * @return a promise which will contain the updated classification.
105
+ */
106
+ shareWith(delegateId, classification, options = {}) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ return yield this.modifyClassification(yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(classification, delegateId, undefined, options.shareEncryptionKey, options.sharePatientId));
109
+ });
62
110
  }
63
111
  }
64
112
  exports.IccClassificationXApi = IccClassificationXApi;
@@ -1 +1 @@
1
- {"version":3,"file":"icc-classification-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-classification-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAAiD;AAKjD,4BAA2B;AAC3B,iCAAgC;AAEhC,0EAAgG;AAEhG,MAAa,qBAAsB,SAAQ,8BAAoB;IAI7D,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,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;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,WAAW,CAAC,IAAiB,EAAE,OAAuB,EAAE,IAAS,EAAE,EAAE,YAAsB,EAAE;QAC3F,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAC7B;YACE,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC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,CAAA;IACL,CAAC;CACF;AA1FD,sDA0FC","sourcesContent":["import { IccClassificationApi } 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 { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccClassificationXApi extends IccClassificationApi {\n crypto: IccCryptoXApi\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, c: any = {}, delegates: string[] = []): Promise<models.Classification> {\n const classification = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Classification',\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 healthElementId: this.crypto.randomUuid(),\n openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),\n },\n c || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, classification, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n classification: models.Classification,\n delegates: string[] = []\n ): Promise<models.Classification> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId!)\n .then((secretForeignKeys) => this.crypto.initObjectDelegations(classification, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]))\n .then((initData) => {\n _.extend(classification, {\n delegations: initData.delegations,\n cryptedForeignKeys: initData.cryptedForeignKeys,\n secretForeignKeys: initData.secretForeignKeys,\n })\n\n let promise = Promise.resolve(classification)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((classification) =>\n this.crypto\n .extendedDelegationsAndCryptedForeignKeys(classification, patient, dataOwnerId!, delegateId, initData.secretId)\n .then((extraData) =>\n _.extend(classification, {\n delegations: extraData.delegations,\n cryptedForeignKeys: extraData.cryptedForeignKeys,\n })\n )\n .catch((e) => {\n console.log(e)\n return classification\n })\n ))\n )\n\n return promise\n })\n }\n\n findBy(hcpartyId: string, patient: models.Patient) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n this.findClassificationsByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-classification-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-classification-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAiD;AAGjD,kDAAiD;AAEjD,4BAA2B;AAC3B,iCAAgC;AAEhC,0EAAgG;AAGhG,MAAa,qBAAsB,SAAQ,8BAAoB;IAI7D,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,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;QACvD,IAAI,CAAC,MA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AA;QAC1E,CAAC;KAAA;IAED;;;;;;;;;;;;OAYG;IACG,SAAS,CACb,UAAkB,EAClB,cAAqC,EACrC,UAGI,EAAE;;YAEN,OAAO,MAAM,IAAI,CAAC,oBAAoB,CACpC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAChE,cAAc,EACd,UAAU,EACV,SAAS,EACT,OAAO,CAAC,kBAAkB,EAC1B,OAAO,CAAC,cAAc,CACvB,CACF,CAAA;QACH,CAAC;KAAA;CACF;AA5HD,sDA4HC","sourcesContent":["import { IccClassificationApi } 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 { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\n\nexport class IccClassificationXApi extends IccClassificationApi {\n crypto: IccCryptoXApi\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 classification with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this classification refers to.\n * @param c initialised data for the classification. 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 classification. 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 classification.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n c: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ): Promise<models.Classification> {\n const classification = _.assign(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.Classification',\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 healthElementId: this.crypto.primitives.randomUuid(),\n openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),\n },\n c || {}\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?.medicalInformation ?? []),\n ]\n return new models.Classification(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(classification, patient?.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n async findBy(hcpartyId: string, patient: models.Patient) {\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 ? this.findClassificationsByHCPartyPatientForeignKeys(topmostParentId, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n /**\n * @param classification a classification\n * @return the id of the patient that the classification 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(classification: models.Classification): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(classification, undefined)\n }\n\n /**\n * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the classification.\n * @param classification the classification 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 * classification does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated classification.\n */\n async shareWith(\n delegateId: string,\n classification: models.Classification,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Classification> {\n return await this.modifyClassification(\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n classification,\n delegateId,\n undefined,\n options.shareEncryptionKey,\n options.sharePatientId\n )\n )\n }\n}\n"]}
@@ -5,6 +5,7 @@ import { Contact, ListOfIds, Service } from '../icc-api/model/models';
5
5
  import { PaginatedListContact } from '../icc-api/model/PaginatedListContact';
6
6
  import { IccDataOwnerXApi } from './icc-data-owner-x-api';
7
7
  import { AuthenticationProvider } from './auth/AuthenticationProvider';
8
+ import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour';
8
9
  export declare class IccContactXApi extends IccContactApi {
9
10
  i18n: any;
10
11
  crypto: IccCryptoXApi;
@@ -12,19 +13,30 @@ export declare class IccContactXApi extends IccContactApi {
12
13
  constructor(host: string, headers: {
13
14
  [key: string]: string;
14
15
  }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
15
- newInstance(user: models.User, patient: models.Patient, c: any, confidential?: boolean, delegates?: string[]): Promise<models.Contact>;
16
16
  /**
17
- * 1. Extract(decrypt) the patient's secretForeignKeys from the
18
- * "delegations" object.
19
- * 2. Initialize & encrypt the Contact's delegations & cryptedForeignKeys.
20
- * 3. Initialize & encrypt the Contact's encryptionKeys.
21
- * 4. Return the contact with the extended delegations, cryptedForeignKeys
22
- * & encryptionKeys.
17
+ * Creates a new instance of contact with initialised encryption metadata (not in the database).
18
+ * @param user the current user.
19
+ * @param patient the patient this contact refers to.
20
+ * @param c initialised data for the contact. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify other
21
+ * kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
22
+ * @param options optional parameters:
23
+ * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
24
+ * 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
25
+ * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
26
+ * access will be possible.
27
+ * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
28
+ * secret id of patient known by the topmost parent in the current data owner hierarchy.
29
+ * - confidential: if true, the entity will be created as confidential. Confidential entities are not shared with auto-delegations, and the default
30
+ * 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.
31
+ * @return a new instance of contact.
23
32
  */
24
- private initDelegationsAndEncryptionKeys;
25
- initEncryptionKeys(user: models.User, ctc: models.Contact): Promise<models.Contact & {
26
- encryptionKeys: any;
27
- }>;
33
+ newInstance(user: models.User, patient: models.Patient, c: any, options?: {
34
+ additionalDelegates?: {
35
+ [dataOwnerId: string]: 'WRITE';
36
+ };
37
+ preferredSfk?: string;
38
+ confidential?: boolean;
39
+ }): Promise<models.Contact>;
28
40
  /**
29
41
  * 1. Check whether there is a delegation with 'hcpartyId' or not.
30
42
  * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.
@@ -53,25 +65,28 @@ export declare class IccContactXApi extends IccContactApi {
53
65
  modifyContact(body?: Contact): never;
54
66
  modifyContacts(body?: Array<Contact>): never;
55
67
  createContact(body?: Contact): never;
56
- findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string, planOfActionIds?: string, skipClosedContacts?: boolean): Promise<Array<models.Contact> | any>;
68
+ findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string, planOfActionIds?: string, skipClosedContacts?: boolean): Promise<Array<models.Contact>>;
57
69
  findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[], planOfActionIds?: string, skipClosedContacts?: boolean): Promise<Array<models.Contact> | any>;
58
70
  filterByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: models.FilterChainContact): Promise<PaginatedListContact | any>;
59
71
  listContactsByOpeningDateWithUser(user: models.User, startKey: number, endKey: number, hcpartyid: string, startDocumentId?: string, limit?: number): Promise<PaginatedListContact | any>;
60
72
  listServicesWithUser(user: models.User, serviceIds: ListOfIds): Promise<Array<Service> | any>;
61
73
  findByHCPartyFormIdWithUser(user: models.User, hcPartyId: string, formId: string): Promise<Array<models.Contact> | any>;
62
74
  findByHCPartyFormIdsWithUser(user: models.User, hcPartyId: string, body: models.ListOfIds): Promise<Array<models.Contact> | any>;
63
- getContactWithUser(user: models.User, contactId: string): Promise<models.Contact | any>;
75
+ getContactWithUser(user: models.User, contactId: string): Promise<models.Contact>;
64
76
  getContactsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<models.Contact> | any>;
65
77
  modifyContactWithUser(user: models.User, body?: models.Contact): Promise<models.Contact | any>;
78
+ private modifyAs;
66
79
  modifyContactsWithUser(user: models.User, bodies?: Array<models.Contact>): Promise<models.Contact[] | any>;
67
- createContactWithUser(user: models.User, body?: models.Contact): Promise<models.Contact | any>;
68
- createContactsWithUser(user: models.User, bodies?: Array<models.Contact>): Promise<models.Contact[] | any>;
80
+ createContactWithUser(user: models.User, body?: models.Contact): Promise<models.Contact | null>;
81
+ createContactsWithUser(user: models.User, bodies?: Array<models.Contact>): Promise<models.Contact[] | null>;
69
82
  encryptServices(key: CryptoKey, rawKey: string, services: Service[]): PromiseLike<Service[]>;
70
- encrypt(user: models.User, ctcs: Array<models.Contact>): Promise<(models.Contact | (models.Contact & {
71
- encryptionKeys: any;
72
- }))[]>;
83
+ encrypt(user: models.User, ctcs: Array<models.Contact>): Promise<models.Contact[]>;
84
+ private encryptAs;
73
85
  decrypt(hcpartyId: string, ctcs: Array<models.Contact>): Promise<Array<models.Contact>>;
74
- decryptServices(hcpartyId: string, svcs: Array<models.Service>, key?: CryptoKey, rawKey?: string): Promise<Array<models.Service>>;
86
+ decryptServices(hcpartyId: string, svcs: Array<models.Service>, keys?: {
87
+ key: CryptoKey;
88
+ raw: string;
89
+ }[]): Promise<Array<models.Service>>;
75
90
  contactOfService(ctcs: Array<models.Contact>, svcId: string): models.Contact | undefined;
76
91
  filteredServices(ctcs: Array<models.Contact>, filter: any): Array<models.Service>;
77
92
  filterServices(ctcs: Array<models.Contact>, filter: any): Promise<Array<models.Service>>;
@@ -126,4 +141,27 @@ export declare class IccContactXApi extends IccContactApi {
126
141
  regimenToString: (r: models.RegimenItem, lang: string) => string | null;
127
142
  localize: (s: any, lang: string) => any;
128
143
  };
144
+ /**
145
+ * @param contact a contact
146
+ * @return the id of the patient that the contact refers to, retrieved from the encrypted metadata. Normally there should only be one element
147
+ * in the returned array, but in case of entity merges there could be multiple values.
148
+ */
149
+ decryptPatientIdOf(contact: models.Contact): Promise<string[]>;
150
+ /**
151
+ * Share an existing contact with other data owners, allowing them to access the non-encrypted data of the contact and optionally also
152
+ * the encrypted content.
153
+ * @param delegateId the id of the data owner which will be granted access to the contact.
154
+ * @param contact the contact to share.
155
+ * @param options optional parameters to customize the sharing behaviour:
156
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
157
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
158
+ * contact does not have encrypted content.
159
+ * - sharePatientId: specifies if the id of the patient that this contact refers to should be shared with the delegate (defaults to
160
+ * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
161
+ * @return a promise which will contain the updated contact.
162
+ */
163
+ shareWith(delegateId: string, contact: models.Contact, options?: {
164
+ shareEncryptionKey?: ShareMetadataBehaviour;
165
+ sharePatientId?: ShareMetadataBehaviour;
166
+ }): Promise<models.Contact>;
129
167
  }