@icure/api 7.0.0-beta.4 → 7.1.0

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 (93) hide show
  1. package/icc-api/api/IccDocumentApi.d.ts +6 -4
  2. package/icc-api/api/IccDocumentApi.js +8 -5
  3. package/icc-api/api/IccDocumentApi.js.map +1 -1
  4. package/icc-api/model/Address.d.ts +6 -0
  5. package/icc-api/model/Address.js.map +1 -1
  6. package/icc-api/model/Annotation.d.ts +18 -0
  7. package/icc-api/model/Annotation.js.map +1 -1
  8. package/icc-api/model/Connection.d.ts +16 -0
  9. package/icc-api/model/Connection.js +38 -0
  10. package/icc-api/model/Connection.js.map +1 -0
  11. package/icc-api/model/Content.js +1 -1
  12. package/icc-api/model/Content.js.map +1 -1
  13. package/icc-api/model/CryptoActorStub.d.ts +5 -0
  14. package/icc-api/model/CryptoActorStub.js +1 -0
  15. package/icc-api/model/CryptoActorStub.js.map +1 -1
  16. package/icc-api/model/Delegation.d.ts +3 -0
  17. package/icc-api/model/Delegation.js.map +1 -1
  18. package/icc-api/model/HealthElement.d.ts +6 -0
  19. package/icc-api/model/HealthElement.js.map +1 -1
  20. package/icc-api/model/HealthcareParty.js +1 -1
  21. package/icc-api/model/HealthcareParty.js.map +1 -1
  22. package/icc-api/model/ISO639_1.d.ts +8 -0
  23. package/icc-api/model/ISO639_1.js +3 -0
  24. package/icc-api/model/ISO639_1.js.map +1 -0
  25. package/icc-api/model/Patient.d.ts +7 -0
  26. package/icc-api/model/Patient.js +1 -1
  27. package/icc-api/model/Patient.js.map +1 -1
  28. package/icc-api/model/models.d.ts +2 -0
  29. package/icc-api/model/models.js +1 -0
  30. package/icc-api/model/models.js.map +1 -1
  31. package/icc-x-api/crypto/EntitiesEncryption.d.ts +2 -1
  32. package/icc-x-api/crypto/EntitiesEncryption.js +13 -11
  33. package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -1
  34. package/icc-x-api/filters/filters.d.ts +4 -0
  35. package/icc-x-api/filters/filters.js +4 -0
  36. package/icc-x-api/filters/filters.js.map +1 -1
  37. package/icc-x-api/icc-accesslog-x-api.d.ts +1 -1
  38. package/icc-x-api/icc-accesslog-x-api.js +9 -21
  39. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  40. package/icc-x-api/icc-calendar-item-x-api.d.ts +1 -1
  41. package/icc-x-api/icc-calendar-item-x-api.js +9 -18
  42. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  43. package/icc-x-api/icc-classification-x-api.js +6 -17
  44. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  45. package/icc-x-api/icc-contact-x-api.d.ts +30 -2
  46. package/icc-x-api/icc-contact-x-api.js +82 -96
  47. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  48. package/icc-x-api/icc-device-x-api.d.ts +17 -0
  49. package/icc-x-api/icc-device-x-api.js +35 -0
  50. package/icc-x-api/icc-device-x-api.js.map +1 -0
  51. package/icc-x-api/icc-doctemplate-x-api.js +2 -13
  52. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  53. package/icc-x-api/icc-document-x-api.d.ts +12 -4
  54. package/icc-x-api/icc-document-x-api.js +22 -23
  55. package/icc-x-api/icc-document-x-api.js.map +1 -1
  56. package/icc-x-api/icc-form-x-api.js +6 -15
  57. package/icc-x-api/icc-form-x-api.js.map +1 -1
  58. package/icc-x-api/icc-hcparty-x-api.d.ts +9 -2
  59. package/icc-x-api/icc-hcparty-x-api.js +9 -1
  60. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  61. package/icc-x-api/icc-helement-x-api.d.ts +12 -3
  62. package/icc-x-api/icc-helement-x-api.js +19 -19
  63. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  64. package/icc-x-api/icc-invoice-x-api.js +6 -17
  65. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  66. package/icc-x-api/icc-maintenance-task-x-api.d.ts +12 -2
  67. package/icc-x-api/icc-maintenance-task-x-api.js +17 -13
  68. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  69. package/icc-x-api/icc-message-x-api.js +6 -16
  70. package/icc-x-api/icc-message-x-api.js.map +1 -1
  71. package/icc-x-api/icc-patient-x-api.d.ts +12 -3
  72. package/icc-x-api/icc-patient-x-api.js +21 -18
  73. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  74. package/icc-x-api/icc-receipt-x-api.js +5 -15
  75. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  76. package/icc-x-api/icc-time-table-x-api.js +5 -15
  77. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  78. package/icc-x-api/icc-user-x-api.d.ts +10 -1
  79. package/icc-x-api/icc-user-x-api.js +8 -1
  80. package/icc-x-api/icc-user-x-api.js.map +1 -1
  81. package/icc-x-api/index.d.ts +110 -4
  82. package/icc-x-api/index.js +17 -15
  83. package/icc-x-api/index.js.map +1 -1
  84. package/icc-x-api/utils/crypto-utils.d.ts +140 -11
  85. package/icc-x-api/utils/crypto-utils.js +285 -36
  86. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  87. package/icc-x-api/utils/index.d.ts +1 -0
  88. package/icc-x-api/utils/index.js +1 -0
  89. package/icc-x-api/utils/index.js.map +1 -1
  90. package/icc-x-api/utils/websocket.d.ts +61 -0
  91. package/icc-x-api/utils/websocket.js +351 -0
  92. package/icc-x-api/utils/websocket.js.map +1 -0
  93. package/package.json +5 -2
@@ -15,8 +15,11 @@ const models = require("../icc-api/model/models");
15
15
  const models_1 = require("../icc-api/model/models");
16
16
  const _ = require("lodash");
17
17
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
18
+ const utils_1 = require("./utils");
19
+ const Connection_1 = require("../icc-api/model/Connection");
20
+ const websocket_1 = require("./utils/websocket");
18
21
  class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskApi {
19
- constructor(host, headers, crypto, hcPartyApi, dataOwnerApi, encryptedKeys = [], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
22
+ constructor(host, headers, crypto, hcPartyApi, dataOwnerApi, userApi, authApi, encryptedKeys = ['properties'], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
20
23
  ? window.fetch
21
24
  : typeof self !== 'undefined'
22
25
  ? self.fetch
@@ -25,7 +28,9 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
25
28
  this.crypto = crypto;
26
29
  this.hcPartyApi = hcPartyApi;
27
30
  this.dataOwnerApi = dataOwnerApi;
28
- this.encryptedKeys = encryptedKeys;
31
+ this.encryptedFields = (0, utils_1.parseEncryptedFields)(encryptedKeys, 'MaintenanceTask.');
32
+ this.userApi = userApi;
33
+ this.authApi = authApi;
29
34
  }
30
35
  /**
31
36
  * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).
@@ -40,18 +45,11 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
40
45
  * @return a new instance of maintenance task.
41
46
  */
42
47
  newInstance(user, m, options = {}) {
43
- var _a, _b, _c;
48
+ var _a, _b, _c, _d, _e, _f, _g, _h;
44
49
  return __awaiter(this, void 0, void 0, function* () {
45
50
  const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user);
46
- const maintenanceTask = _.assign({
47
- id: this.crypto.primitives.randomUuid(),
48
- _type: 'org.taktik.icure.entities.MaintenanceTask',
49
- created: new Date().getTime(),
50
- modified: new Date().getTime(),
51
- responsible: dataOwnerId,
52
- author: user.id,
53
- }, m || {});
54
- const extraDelegations = [...Object.keys((_a = options.additionalDelegates) !== null && _a !== void 0 ? _a : {}), ...((_c = (_b = user.autoDelegations) === null || _b === void 0 ? void 0 : _b.all) !== null && _c !== void 0 ? _c : [])];
51
+ const maintenanceTask = Object.assign(Object.assign({}, (m !== null && m !== void 0 ? m : {})), { _type: 'org.taktik.icure.entities.MaintenanceTask', id: (_a = m === null || m === void 0 ? void 0 : m.id) !== null && _a !== void 0 ? _a : this.crypto.primitives.randomUuid(), created: (_b = m === null || m === void 0 ? void 0 : m.created) !== null && _b !== void 0 ? _b : new Date().getTime(), modified: (_c = m === null || m === void 0 ? void 0 : m.modified) !== null && _c !== void 0 ? _c : new Date().getTime(), responsible: (_d = m === null || m === void 0 ? void 0 : m.responsible) !== null && _d !== void 0 ? _d : dataOwnerId, author: (_e = m === null || m === void 0 ? void 0 : m.author) !== null && _e !== void 0 ? _e : user.id });
52
+ const extraDelegations = [...Object.keys((_f = options.additionalDelegates) !== null && _f !== void 0 ? _f : {}), ...((_h = (_g = user.autoDelegations) === null || _g === void 0 ? void 0 : _g.all) !== null && _h !== void 0 ? _h : [])];
55
53
  return new models.MaintenanceTask(yield this.crypto.entities
56
54
  .entityWithInitialisedEncryptedMetadata(maintenanceTask, undefined, undefined, true, extraDelegations)
57
55
  .then((x) => x.updatedEntity));
@@ -107,7 +105,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
107
105
  return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks);
108
106
  }
109
107
  encryptAs(dataOwnerId, maintenanceTasks) {
110
- return Promise.all(maintenanceTasks.map((m) => this.crypto.entities.tryEncryptEntity(m, dataOwnerId, this.encryptedKeys, true, true, (x) => new models.MaintenanceTask(x))));
108
+ return Promise.all(maintenanceTasks.map((m) => this.crypto.entities.tryEncryptEntity(m, dataOwnerId, this.encryptedFields, true, true, (x) => new models.MaintenanceTask(x))));
111
109
  }
112
110
  decrypt(user, maintenanceTasks) {
113
111
  return this.decryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks);
@@ -162,6 +160,12 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
162
160
  return yield this.crypto.entities.encryptionKeysOf(entity);
163
161
  });
164
162
  }
163
+ subscribeToMaintenanceTaskEvents(eventTypes, filter, eventFired, options = {}) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const currentUser = yield this.userApi.getCurrentUser();
166
+ return (0, websocket_1.subscribeToEntityEvents)(this.host, this.authApi, 'MaintenanceTask', eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt(currentUser, [encrypted]))[0]; })).then((rs) => new Connection_1.ConnectionImpl(rs));
167
+ });
168
+ }
165
169
  }
166
170
  exports.IccMaintenanceTaskXApi = IccMaintenanceTaskXApi;
167
171
  //# sourceMappingURL=icc-maintenance-task-x-api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gFAA4E;AAE5E,kDAAiD;AACjD,oDAAwE;AACxE,4BAA2B;AAG3B,0EAAgG;AAIhG,MAAa,sBAAuB,SAAQ,6CAAqB;IAO/D,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,UAA0B,EAC1B,YAA8B,EAC9B,gBAA+B,EAAE,EACjC,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,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED;;;;;;;;;;;OAWG;IACG,WAAW,CACf,IAAiB,EACjB,CAAM,EACN,UA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AAQ,CAAC,uCAAuC,CAAC,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;YACrH,IAAI,CAAC,CAAC,QAAQ,EAAE;gBACd,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;aAC3C;;gBAAM,OAAO,eAAe,CAAA;QAC/B,CAAC;KAAA;IAEK,yBAAyB,CAC7B,MAAuB;;YAEvB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAA;QACrE,CAAC;KAAA;IAEK,mBAAmB,CAAC,MAAuB;;YAC/C,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC5D,CAAC;KAAA;CACF;AAjND,wDAiNC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport { DocIdentifier, MaintenanceTask } from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi implements EncryptedEntityXApi<models.MaintenanceTask> {\n crypto: IccCryptoXApi\n hcPartyApi: IccHcpartyXApi\n dataOwnerApi: IccDataOwnerXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n hcPartyApi: IccHcpartyXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = [],\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.hcPartyApi = hcPartyApi\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n /**\n * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param m initialised data for the maintenance task. 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 * @return a new instance of maintenance task.\n */\n async newInstance(\n user: models.User,\n m: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const maintenanceTask = _.assign(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n },\n m || {}\n )\n\n const extraDelegations = [...Object.keys(options.additionalDelegates ?? {}), ...(user.autoDelegations?.all ?? [])]\n return new models.MaintenanceTask(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(maintenanceTask, undefined, undefined, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskIds: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<Array<DocIdentifier>> | never {\n return super.deleteMaintenanceTask(maintenanceTaskId)\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n\n private modifyAs(dataOwner: string, body: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decryptAs(dataOwner, [mt]))\n .then((mts) => mts[0])\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks)\n }\n\n private encryptAs(dataOwnerId: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map((m) =>\n this.crypto.entities.tryEncryptEntity(m, dataOwnerId, this.encryptedKeys, true, true, (x) => new models.MaintenanceTask(x))\n )\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return this.decryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks)\n }\n\n private decryptAs(dataOwnerId: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map(async (mT) =>\n this.crypto.entities.decryptEntity(mT, dataOwnerId, (x) => new MaintenanceTask(x)).then(({ entity }) => entity)\n )\n )\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the maintenance task.\n * @param maintenanceTask the maintenance task 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 * maintenance task does not have encrypted content.\n * @return a promise which will contain the updated maintenance task\n */\n async shareWith(\n delegateId: string,\n maintenanceTask: models.MaintenanceTask,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.MaintenanceTask> {\n return this.shareWithMany(maintenanceTask, { [delegateId]: options })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates sharing options for each delegate.\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 * maintenance task does not have encrypted content.\n * @return a promise which will contain the updated maintenance task\n */\n async shareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.MaintenanceTask> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const extended = await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(maintenanceTask, true, delegates)\n if (!!extended) {\n return await this.modifyAs(self, extended)\n } else return maintenanceTask\n }\n\n async getDataOwnersWithAccessTo(\n entity: MaintenanceTask\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: 'WRITE' }; hasUnknownAnonymousDataOwners: boolean }> {\n return await this.crypto.entities.getDataOwnersWithAccessTo(entity)\n }\n\n async getEncryptionKeysOf(entity: MaintenanceTask): Promise<string[]> {\n return await this.crypto.entities.encryptionKeysOf(entity)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gFAA4E;AAE5E,kDAAiD;AACjD,oDAAwE;AACxE,4BAA2B;AAG3B,0EAAgG;AAGhG,mCAAuE;AAEvE,4DAAsE;AACtE,iDAAyD;AAIzD,MAAa,sBAAuB,SAAQ,6CAAqB;IAS/D,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,UAA0B,EAC1B,YAA8B,EAC9B,OAAoB,EACpB,OAAmB,EACnB,gBAA+B,CAAC,YAAY,CAAC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CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAA;QACrE,CAAC;KAAA;IAEK,mBAAmB,CAAC,MAAuB;;YAC/C,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC5D,CAAC;KAAA;IAEK,gCAAgC,CACpC,UAA8C,EAC9C,MAAuC,EACvC,UAA0D,EAC1D,UAA+E,EAAE;;YAEjF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAA;YAEvD,OAAO,IAAA,mCAAuB,EAC5B,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,OAAO,EACZ,iBAAiB,EACjB,UAAU,EACV,MAAM,EACN,UAAU,EACV,OAAO,EACP,CAAO,SAAS,EAAE,EAAE,gDAAC,OAAA,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,GAAA,CACvE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;KAAA;CACF;AAzOD,wDAyOC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport { DocIdentifier, MaintenanceTask } from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { EncryptedFieldsManifest, parseEncryptedFields } from './utils'\nimport {AbstractFilter} from \"./filters/filters\"\nimport {Connection, ConnectionImpl} from \"../icc-api/model/Connection\"\nimport {subscribeToEntityEvents} from \"./utils/websocket\"\nimport {IccUserXApi} from \"./icc-user-x-api\"\nimport {IccAuthApi} from \"../icc-api\"\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi implements EncryptedEntityXApi<models.MaintenanceTask> {\n crypto: IccCryptoXApi\n hcPartyApi: IccHcpartyXApi\n dataOwnerApi: IccDataOwnerXApi\n private readonly userApi: IccUserXApi\n private readonly authApi: IccAuthApi\n\n private readonly encryptedFields: EncryptedFieldsManifest\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n hcPartyApi: IccHcpartyXApi,\n dataOwnerApi: IccDataOwnerXApi,\n userApi: IccUserXApi,\n authApi: IccAuthApi,\n encryptedKeys: Array<string> = ['properties'],\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.hcPartyApi = hcPartyApi\n this.dataOwnerApi = dataOwnerApi\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'MaintenanceTask.')\n this.userApi = userApi\n this.authApi = authApi\n }\n\n /**\n * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param m initialised data for the maintenance task. 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 * @return a new instance of maintenance task.\n */\n async newInstance(\n user: models.User,\n m: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const maintenanceTask = {\n ...(m ?? {}),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n id: m?.id ?? this.crypto.primitives.randomUuid(),\n created: m?.created ?? new Date().getTime(),\n modified: m?.modified ?? new Date().getTime(),\n responsible: m?.responsible ?? dataOwnerId,\n author: m?.author ?? user.id,\n }\n\n const extraDelegations = [...Object.keys(options.additionalDelegates ?? {}), ...(user.autoDelegations?.all ?? [])]\n return new models.MaintenanceTask(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(maintenanceTask, undefined, undefined, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskIds: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<Array<DocIdentifier>> | never {\n return super.deleteMaintenanceTask(maintenanceTaskId)\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n\n private modifyAs(dataOwner: string, body: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decryptAs(dataOwner, [mt]))\n .then((mts) => mts[0])\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks)\n }\n\n private encryptAs(dataOwnerId: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map((m) =>\n this.crypto.entities.tryEncryptEntity(m, dataOwnerId, this.encryptedFields, true, true, (x) => new models.MaintenanceTask(x))\n )\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return this.decryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks)\n }\n\n private decryptAs(dataOwnerId: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map(async (mT) =>\n this.crypto.entities.decryptEntity(mT, dataOwnerId, (x) => new MaintenanceTask(x)).then(({ entity }) => entity)\n )\n )\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the maintenance task.\n * @param maintenanceTask the maintenance task 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 * maintenance task does not have encrypted content.\n * @return a promise which will contain the updated maintenance task\n */\n async shareWith(\n delegateId: string,\n maintenanceTask: models.MaintenanceTask,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.MaintenanceTask> {\n return this.shareWithMany(maintenanceTask, { [delegateId]: options })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates sharing options for each delegate.\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 * maintenance task does not have encrypted content.\n * @return a promise which will contain the updated maintenance task\n */\n async shareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.MaintenanceTask> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const extended = await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(maintenanceTask, true, delegates)\n if (!!extended) {\n return await this.modifyAs(self, extended)\n } else return maintenanceTask\n }\n\n async getDataOwnersWithAccessTo(\n entity: MaintenanceTask\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: 'WRITE' }; hasUnknownAnonymousDataOwners: boolean }> {\n return await this.crypto.entities.getDataOwnersWithAccessTo(entity)\n }\n\n async getEncryptionKeysOf(entity: MaintenanceTask): Promise<string[]> {\n return await this.crypto.entities.encryptionKeysOf(entity)\n }\n\n async subscribeToMaintenanceTaskEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<MaintenanceTask>,\n eventFired: (dataSample: MaintenanceTask) => Promise<void>,\n options: { connectionMaxRetry?: number; connectionRetryIntervalMs?: number } = {}\n ): Promise<Connection> {\n const currentUser = await this.userApi.getCurrentUser()\n\n return subscribeToEntityEvents(\n this.host,\n this.authApi,\n 'MaintenanceTask',\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt(currentUser, [encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n}\n"]}
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.IccMessageXApi = void 0;
13
13
  const icc_api_1 = require("../icc-api");
14
- const _ = require("lodash");
15
14
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
16
15
  const models = require("../icc-api/model/models");
17
16
  class IccMessageXApi extends icc_api_1.IccMessageApi {
@@ -45,30 +44,21 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
45
44
  * @return a new instance of message.
46
45
  */
47
46
  newInstanceWithPatient(user, patient, m = {}, options = {}) {
48
- var _a, _b, _c, _d, _e, _f;
47
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
49
48
  return __awaiter(this, void 0, void 0, function* () {
50
49
  if (!patient && options.preferredSfk)
51
50
  throw new Error('You need to specify parent patient in order to use secret foreign keys.');
52
- const message = _.extend({
53
- id: this.crypto.primitives.randomUuid(),
54
- _type: 'org.taktik.icure.entities.Message',
55
- created: new Date().getTime(),
56
- modified: new Date().getTime(),
57
- responsible: this.dataOwnerApi.getDataOwnerIdOf(user),
58
- author: user.id,
59
- codes: [],
60
- tags: [],
61
- }, m || {});
51
+ const message = Object.assign(Object.assign({}, (m !== null && m !== void 0 ? m : {})), { _type: 'org.taktik.icure.entities.Message', id: (_a = m === null || m === void 0 ? void 0 : m.id) !== null && _a !== void 0 ? _a : this.crypto.primitives.randomUuid(), created: (_b = m === null || m === void 0 ? void 0 : m.created) !== null && _b !== void 0 ? _b : new Date().getTime(), modified: (_c = m === null || m === void 0 ? void 0 : m.modified) !== null && _c !== void 0 ? _c : new Date().getTime(), responsible: (_d = m === null || m === void 0 ? void 0 : m.responsible) !== null && _d !== void 0 ? _d : this.dataOwnerApi.getDataOwnerIdOf(user), author: (_e = m === null || m === void 0 ? void 0 : m.author) !== null && _e !== void 0 ? _e : user.id, codes: (_f = m === null || m === void 0 ? void 0 : m.codes) !== null && _f !== void 0 ? _f : [], tags: (_g = m === null || m === void 0 ? void 0 : m.tags) !== null && _g !== void 0 ? _g : [] });
62
52
  const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
63
53
  if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
64
54
  throw new Error('Can only initialise entities as current data owner.');
65
- const sfk = patient ? (_a = options === null || options === void 0 ? void 0 : options.preferredSfk) !== null && _a !== void 0 ? _a : (yield this.crypto.confidential.getAnySecretIdSharedWithParents(patient)) : undefined;
55
+ const sfk = patient ? (_h = options === null || options === void 0 ? void 0 : options.preferredSfk) !== null && _h !== void 0 ? _h : (yield this.crypto.confidential.getAnySecretIdSharedWithParents(patient)) : undefined;
66
56
  if (patient && !sfk)
67
57
  throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
68
58
  const extraDelegations = [
69
- ...Object.keys((_b = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _b !== void 0 ? _b : {}),
70
- ...((_d = (_c = user.autoDelegations) === null || _c === void 0 ? void 0 : _c.all) !== null && _d !== void 0 ? _d : []),
71
- ...((_f = (_e = user.autoDelegations) === null || _e === void 0 ? void 0 : _e.medicalInformation) !== null && _f !== void 0 ? _f : []),
59
+ ...Object.keys((_j = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _j !== void 0 ? _j : {}),
60
+ ...((_l = (_k = user.autoDelegations) === null || _k === void 0 ? void 0 : _k.all) !== null && _l !== void 0 ? _l : []),
61
+ ...((_o = (_m = user.autoDelegations) === null || _m === void 0 ? void 0 : _m.medicalInformation) !== null && _o !== void 0 ? _o : []),
72
62
  ];
73
63
  return new models.Message(yield this.crypto.entities
74
64
  .entityWithInitialisedEncryptedMetadata(message, patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, extraDelegations)
@@ -1 +1 @@
1
- {"version":3,"file":"icc-message-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-message-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA0C;AAG1C,4BAA2B;AAI3B,0EAAgG;AAChG,kDAAiD;AAIjD,MAAa,cAAe,SAAQ,uBAAa;IAG/C,YACE,IAAY,EACZ,OAAkC,EAC1B,MAAqB,EAC7B,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;QAT/C,WAAM,GAAN,MAAM,CAAe;QAU7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,qCAAqC;IACrC,WAAW,CAAC,IAAU,EAAE,CAAM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AC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;gBACvD,UAAU;gBACV;oBACE,cAAc,EAAE,OAAO,CAAC,cAAc;oBACtC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;oBAC9C,oBAAoB,EAAE,OAAO,CAAC,cAAc;iBAC7C;aACF,CAAC,CACH,CACF,CAAA;YACD,IAAI,CAAC,CAAC,QAAQ,EAAE;gBACd,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;aAC1C;;gBAAM,OAAO,OAAO,CAAA;QACvB,CAAC;KAAA;IAED;;;;OAIG;IACH,kBAAkB,CAAC,OAAuB;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAC7D,CAAC;IAEK,yBAAyB,CAC7B,MAAsB;;YAEtB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAA;QACrE,CAAC;KAAA;IAEK,mBAAmB,CAAC,MAAsB;;YAC9C,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC5D,CAAC;KAAA;CACF;AAjLD,wCAiLC","sourcesContent":["import { IccMessageApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\n\nimport { Patient, User } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport * as models from '../icc-api/model/models'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\n\nexport class IccMessageXApi extends IccMessageApi implements EncryptedEntityXApi<models.Message> {\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private 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 // noinspection JSUnusedGlobalSymbols\n newInstance(user: User, m: any) {\n return this.newInstanceWithPatient(user, null, m)\n }\n\n /**\n * Creates a new instance of message with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this message refers to.\n * @param m initialised data for the message. 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 message.\n */\n async newInstanceWithPatient(\n user: User,\n patient: Patient | null,\n m: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ) {\n if (!patient && options.preferredSfk) throw new Error('You need to specify parent patient in order to use secret foreign keys.')\n const message = _.extend(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.Message',\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 m || {}\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 models.Message(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(message, patient?.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * @param message a message\n * @return the id of the patient that the message 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(message: models.Message): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(message, undefined)\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the message.\n * @param message the message to share.\n * @param shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id.\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 * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated message\n */\n async shareWith(\n delegateId: string,\n message: models.Message,\n shareSecretIds: string[],\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Message> {\n return this.shareWithMany(message, { [delegateId]: { shareSecretIds, ...options } })\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content.\n * @param message the message to share.\n * @param delegates sharing options for each delegate.\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 * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id.\n * @return a promise which will contain the updated message\n */\n async shareWithMany(\n message: models.Message,\n delegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n } = {}\n ): Promise<models.Message> {\n const extended = await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n message,\n false,\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n shareSecretIds: options.shareSecretIds,\n shareEncryptionKey: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n },\n ])\n )\n )\n if (!!extended) {\n return await this.modifyMessage(extended)\n } else return message\n }\n\n /**\n * @param message a message\n * @return the secret ids of the message, retrieved from the encrypted metadata. The result may be used to find entities where the message is\n * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.\n */\n decryptSecretIdsOf(message: models.Message): Promise<string[]> {\n return this.crypto.entities.secretIdsOf(message, undefined)\n }\n\n async getDataOwnersWithAccessTo(\n entity: models.Message\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: 'WRITE' }; hasUnknownAnonymousDataOwners: boolean }> {\n return await this.crypto.entities.getDataOwnersWithAccessTo(entity)\n }\n\n async getEncryptionKeysOf(entity: models.Message): Promise<string[]> {\n return await this.crypto.entities.encryptionKeysOf(entity)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-message-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-message-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA0C;AAO1C,0EAAgG;AAChG,kDAAiD;AAIjD,MAAa,cAAe,SAAQ,uBAAa;IAG/C,YACE,IAAY,EACZ,OAAkC,EAC1B,MAAqB,EAC7B,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;QAT/C,WAAM,GAAN,MAAM,CAAe;QAU7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,qCAAqC;IACrC,WAAW,CAAC,IAAU,EAAE,CAAM;QAC5B,OAAO,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACnD,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACG,sBAAsB,CAC1B,IAAU,EACV,OAAuB,EACvB,IAAS,EAAE,EACX,UAGI,EAAE;;;YAEN,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,YAAY;gBAAE,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAA;YAChI,MAAM,OAAO,mCACR,CAAC,CAAC,aAAD,CAAC,cAAD,CAAC,GAAI,EAAE,CAAC,KACZ,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,EACL,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;gBACvD,UAAU;gBACV;oBACE,cAAc,EAAE,OAAO,CAAC,cAAc;oBACtC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;oBAC9C,oBAAoB,EAAE,OAAO,CAAC,cAAc;iBAC7C;aACF,CAAC,CACH,CACF,CAAA;YACD,IAAI,CAAC,CAAC,QAAQ,EAAE;gBACd,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;aAC1C;;gBAAM,OAAO,OAAO,CAAA;QACvB,CAAC;KAAA;IAED;;;;OAIG;IACH,kBAAkB,CAAC,OAAuB;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAC7D,CAAC;IAEK,yBAAyB,CAC7B,MAAsB;;YAEtB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAA;QACrE,CAAC;KAAA;IAEK,mBAAmB,CAAC,MAAsB;;YAC9C,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC5D,CAAC;KAAA;CACF;AA/KD,wCA+KC","sourcesContent":["import { IccMessageApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\n\nimport { Patient, User } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport * as models from '../icc-api/model/models'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\n\nexport class IccMessageXApi extends IccMessageApi implements EncryptedEntityXApi<models.Message> {\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private 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 // noinspection JSUnusedGlobalSymbols\n newInstance(user: User, m: any) {\n return this.newInstanceWithPatient(user, null, m)\n }\n\n /**\n * Creates a new instance of message with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this message refers to.\n * @param m initialised data for the message. 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 message.\n */\n async newInstanceWithPatient(\n user: User,\n patient: Patient | null,\n m: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ) {\n if (!patient && options.preferredSfk) throw new Error('You need to specify parent patient in order to use secret foreign keys.')\n const message = {\n ...(m ?? {}),\n _type: 'org.taktik.icure.entities.Message',\n id: m?.id ?? this.crypto.primitives.randomUuid(),\n created: m?.created ?? new Date().getTime(),\n modified: m?.modified ?? new Date().getTime(),\n responsible: m?.responsible ?? this.dataOwnerApi.getDataOwnerIdOf(user),\n author: m?.author ?? user.id,\n codes: m?.codes ?? [],\n tags: m?.tags ?? [],\n }\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk = 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 models.Message(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(message, patient?.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * @param message a message\n * @return the id of the patient that the message 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(message: models.Message): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(message, undefined)\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the message.\n * @param message the message to share.\n * @param shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id.\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 * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated message\n */\n async shareWith(\n delegateId: string,\n message: models.Message,\n shareSecretIds: string[],\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Message> {\n return this.shareWithMany(message, { [delegateId]: { shareSecretIds, ...options } })\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content.\n * @param message the message to share.\n * @param delegates sharing options for each delegate.\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 * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id.\n * @return a promise which will contain the updated message\n */\n async shareWithMany(\n message: models.Message,\n delegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n } = {}\n ): Promise<models.Message> {\n const extended = await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n message,\n false,\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n shareSecretIds: options.shareSecretIds,\n shareEncryptionKey: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n },\n ])\n )\n )\n if (!!extended) {\n return await this.modifyMessage(extended)\n } else return message\n }\n\n /**\n * @param message a message\n * @return the secret ids of the message, retrieved from the encrypted metadata. The result may be used to find entities where the message is\n * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.\n */\n decryptSecretIdsOf(message: models.Message): Promise<string[]> {\n return this.crypto.entities.secretIdsOf(message, undefined)\n }\n\n async getDataOwnersWithAccessTo(\n entity: models.Message\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: 'WRITE' }; hasUnknownAnonymousDataOwners: boolean }> {\n return await this.crypto.entities.getDataOwnersWithAccessTo(entity)\n }\n\n async getEncryptionKeysOf(entity: models.Message): Promise<string[]> {\n return await this.crypto.entities.encryptionKeysOf(entity)\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { IccPatientApi } from '../icc-api';
1
+ import { IccAuthApi, IccPatientApi } from '../icc-api';
2
2
  import { IccCryptoXApi } from './icc-crypto-x-api';
3
3
  import { IccContactXApi } from './icc-contact-x-api';
4
4
  import { IccFormXApi } from './icc-form-x-api';
@@ -14,6 +14,9 @@ import { IccDataOwnerXApi } from './icc-data-owner-x-api';
14
14
  import { AuthenticationProvider } from './auth/AuthenticationProvider';
15
15
  import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour';
16
16
  import { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi';
17
+ import { AbstractFilter } from "./filters/filters";
18
+ import { Connection } from "../icc-api/model/Connection";
19
+ import { IccUserXApi } from "./icc-user-x-api";
17
20
  export declare class IccPatientXApi extends IccPatientApi implements EncryptedEntityXApi<models.Patient> {
18
21
  crypto: IccCryptoXApi;
19
22
  contactApi: IccContactXApi;
@@ -25,10 +28,12 @@ export declare class IccPatientXApi extends IccPatientApi implements EncryptedEn
25
28
  classificationApi: IccClassificationXApi;
26
29
  calendarItemApi: IccCalendarItemXApi;
27
30
  dataOwnerApi: IccDataOwnerXApi;
28
- private readonly encryptedKeys;
31
+ private readonly userApi;
32
+ private readonly authApi;
33
+ private readonly encryptedFields;
29
34
  constructor(host: string, headers: {
30
35
  [key: string]: string;
31
- }, crypto: IccCryptoXApi, contactApi: IccContactXApi, formApi: IccFormXApi, helementApi: IccHelementXApi, invoiceApi: IccInvoiceXApi, documentApi: IccDocumentXApi, hcpartyApi: IccHcpartyXApi, classificationApi: IccClassificationXApi, dataOwnerApi: IccDataOwnerXApi, calendarItemaApi: IccCalendarItemXApi, encryptedKeys?: Array<string>, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
36
+ }, crypto: IccCryptoXApi, contactApi: IccContactXApi, formApi: IccFormXApi, helementApi: IccHelementXApi, invoiceApi: IccInvoiceXApi, documentApi: IccDocumentXApi, hcpartyApi: IccHcpartyXApi, classificationApi: IccClassificationXApi, dataOwnerApi: IccDataOwnerXApi, calendarItemaApi: IccCalendarItemXApi, userApi: IccUserXApi, authApi: IccAuthApi, encryptedKeys?: Array<string>, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
32
37
  /**
33
38
  * Creates a new instance of patient with initialised encryption metadata (not in the database).
34
39
  * @param user the current user.
@@ -225,4 +230,8 @@ export declare class IccPatientXApi extends IccPatientApi implements EncryptedEn
225
230
  * @return the updated `into` patient.
226
231
  */
227
232
  mergePatients(from: Patient, mergedInto: Patient): Promise<Patient>;
233
+ subscribeToPatientEvents(eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[], filter: AbstractFilter<Patient> | undefined, eventFired: (patient: Patient) => Promise<void>, options?: {
234
+ connectionMaxRetry?: number;
235
+ connectionRetryIntervalMs?: number;
236
+ }): Promise<Connection>;
228
237
  }
@@ -18,9 +18,11 @@ const ModelHelper_1 = require("../icc-api/model/ModelHelper");
18
18
  const person_util_1 = require("./utils/person-util");
19
19
  const utils_1 = require("./utils");
20
20
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
21
+ const Connection_1 = require("../icc-api/model/Connection");
22
+ const websocket_1 = require("./utils/websocket");
21
23
  // noinspection JSUnusedGlobalSymbols
22
24
  class IccPatientXApi extends icc_api_1.IccPatientApi {
23
- constructor(host, headers, crypto, contactApi, formApi, helementApi, invoiceApi, documentApi, hcpartyApi, classificationApi, dataOwnerApi, calendarItemaApi, encryptedKeys = ['note'], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
25
+ constructor(host, headers, crypto, contactApi, formApi, helementApi, invoiceApi, documentApi, hcpartyApi, classificationApi, dataOwnerApi, calendarItemaApi, userApi, authApi, encryptedKeys = ['note'], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
24
26
  ? window.fetch
25
27
  : typeof self !== 'undefined'
26
28
  ? self.fetch
@@ -36,7 +38,9 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
36
38
  this.classificationApi = classificationApi;
37
39
  this.calendarItemApi = calendarItemaApi;
38
40
  this.dataOwnerApi = dataOwnerApi;
39
- this.encryptedKeys = encryptedKeys;
41
+ this.userApi = userApi;
42
+ this.authApi = authApi;
43
+ this.encryptedFields = (0, utils_1.parseEncryptedFields)(encryptedKeys, 'Patient.');
40
44
  }
41
45
  /**
42
46
  * Creates a new instance of patient with initialised encryption metadata (not in the database).
@@ -51,25 +55,16 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
51
55
  * @return a new instance of patient.
52
56
  */
53
57
  newInstance(user, p = {}, options = {}) {
54
- var _a, _b, _c, _d, _e;
58
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
55
59
  return __awaiter(this, void 0, void 0, function* () {
56
- const patient = _.extend({
57
- id: this.crypto.primitives.randomUuid(),
58
- _type: 'org.taktik.icure.entities.Patient',
59
- created: new Date().getTime(),
60
- modified: new Date().getTime(),
61
- responsible: this.dataOwnerApi.getDataOwnerIdOf(user),
62
- author: user.id,
63
- codes: [],
64
- tags: [],
65
- }, p || {});
60
+ const patient = Object.assign(Object.assign({}, (p !== null && p !== void 0 ? p : {})), { _type: 'org.taktik.icure.entities.Patient', id: (_a = p === null || p === void 0 ? void 0 : p.id) !== null && _a !== void 0 ? _a : this.crypto.primitives.randomUuid(), created: (_b = p === null || p === void 0 ? void 0 : p.created) !== null && _b !== void 0 ? _b : new Date().getTime(), modified: (_c = p === null || p === void 0 ? void 0 : p.modified) !== null && _c !== void 0 ? _c : new Date().getTime(), responsible: (_d = p === null || p === void 0 ? void 0 : p.responsible) !== null && _d !== void 0 ? _d : this.dataOwnerApi.getDataOwnerIdOf(user), author: (_e = p === null || p === void 0 ? void 0 : p.author) !== null && _e !== void 0 ? _e : user.id, codes: (_f = p === null || p === void 0 ? void 0 : p.codes) !== null && _f !== void 0 ? _f : [], tags: (_g = p === null || p === void 0 ? void 0 : p.tags) !== null && _g !== void 0 ? _g : [] });
66
61
  const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
67
62
  if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
68
63
  throw new Error('Can only initialise entities as current data owner.');
69
64
  const extraDelegations = [
70
- ...Object.keys((_a = options.additionalDelegates) !== null && _a !== void 0 ? _a : {}),
71
- ...((_c = (_b = user.autoDelegations) === null || _b === void 0 ? void 0 : _b.all) !== null && _c !== void 0 ? _c : []),
72
- ...((_e = (_d = user.autoDelegations) === null || _d === void 0 ? void 0 : _d.medicalInformation) !== null && _e !== void 0 ? _e : []),
65
+ ...Object.keys((_h = options.additionalDelegates) !== null && _h !== void 0 ? _h : {}),
66
+ ...((_k = (_j = user.autoDelegations) === null || _j === void 0 ? void 0 : _j.all) !== null && _k !== void 0 ? _k : []),
67
+ ...((_m = (_l = user.autoDelegations) === null || _l === void 0 ? void 0 : _l.medicalInformation) !== null && _m !== void 0 ? _m : []),
73
68
  ];
74
69
  const initialisationInfo = yield this.crypto.entities.entityWithInitialisedEncryptedMetadata(patient, undefined, undefined, true, extraDelegations);
75
70
  return new models.Patient(initialisationInfo.updatedEntity);
@@ -291,7 +286,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
291
286
  return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), pats);
292
287
  }
293
288
  encryptAs(dataOwnerId, pats) {
294
- return Promise.all(pats.map((p) => this.crypto.entities.tryEncryptEntity(p, dataOwnerId, this.encryptedKeys, true, false, (x) => new models.Patient(x))));
289
+ return Promise.all(pats.map((p) => this.crypto.entities.tryEncryptEntity(p, dataOwnerId, this.encryptedFields, true, false, (x) => new models.Patient(x))));
295
290
  }
296
291
  // If patient can't be decrypted returns patient with encrypted data.
297
292
  decrypt(user, patients, fillDelegations = true) {
@@ -601,7 +596,8 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
601
596
  });
602
597
  })
603
598
  : (allTags.includes('anonymousMedicalInformation')
604
- ? Promise.resolve(patient)
599
+ ? // TODO check also in v8 how patient is shared with anonymousMedicalInformation tag
600
+ Promise.resolve(patient)
605
601
  : this.modifyPatientWithUser(user, _.assign(patient, {
606
602
  delegations: _.assign(patient.delegations, delegateIds
607
603
  .filter((id) => !patient.delegations || !patient.delegations[id]) //If there are delegations do not modify
@@ -899,6 +895,13 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
899
895
  return (yield this.tryDecryptOrReturnOriginal(undefined, [merged]))[0].entity;
900
896
  });
901
897
  }
898
+ subscribeToPatientEvents(eventTypes, filter, eventFired, options = {}) {
899
+ return __awaiter(this, void 0, void 0, function* () {
900
+ const currentUser = yield this.userApi.getCurrentUser();
901
+ return (0, websocket_1.subscribeToEntityEvents)(this.host, this.authApi, 'Patient', eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt(currentUser, [encrypted]))[0]; }))
902
+ .then((rs) => new Connection_1.ConnectionImpl(rs));
903
+ });
904
+ }
902
905
  }
903
906
  exports.IccPatientXApi = IccPatientXApi;
904
907
  //# sourceMappingURL=icc-patient-x-api.js.map