@icure/api 5.0.14 → 5.0.17

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 (60) hide show
  1. package/icc-api/api/IccCodeApi.d.ts +14 -1
  2. package/icc-api/api/IccCodeApi.js +33 -1
  3. package/icc-api/api/IccCodeApi.js.map +1 -1
  4. package/icc-api/model/UserGroup.d.ts +3 -0
  5. package/icc-api/model/UserGroup.js.map +1 -1
  6. package/icc-x-api/crypto/utils.d.ts +0 -0
  7. package/icc-x-api/crypto/utils.js +2 -0
  8. package/icc-x-api/crypto/utils.js.map +1 -0
  9. package/icc-x-api/icc-accesslog-x-api.d.ts +3 -3
  10. package/icc-x-api/icc-accesslog-x-api.js +11 -11
  11. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  12. package/icc-x-api/icc-calendar-item-x-api.d.ts +3 -3
  13. package/icc-x-api/icc-calendar-item-x-api.js +13 -13
  14. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  15. package/icc-x-api/icc-classification-x-api.d.ts +3 -3
  16. package/icc-x-api/icc-classification-x-api.js +4 -4
  17. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  18. package/icc-x-api/icc-contact-x-api.d.ts +3 -3
  19. package/icc-x-api/icc-contact-x-api.js +16 -16
  20. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  21. package/icc-x-api/icc-crypto-x-api.d.ts +10 -3
  22. package/icc-x-api/icc-crypto-x-api.js +29 -17
  23. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  24. package/icc-x-api/icc-data-owner-x-api.d.ts +14 -0
  25. package/icc-x-api/icc-data-owner-x-api.js +44 -0
  26. package/icc-x-api/icc-data-owner-x-api.js.map +1 -0
  27. package/icc-x-api/icc-document-x-api.d.ts +3 -3
  28. package/icc-x-api/icc-document-x-api.js +5 -5
  29. package/icc-x-api/icc-document-x-api.js.map +1 -1
  30. package/icc-x-api/icc-form-x-api.d.ts +3 -3
  31. package/icc-x-api/icc-form-x-api.js +5 -5
  32. package/icc-x-api/icc-form-x-api.js.map +1 -1
  33. package/icc-x-api/icc-helement-x-api.d.ts +3 -3
  34. package/icc-x-api/icc-helement-x-api.js +10 -10
  35. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  36. package/icc-x-api/icc-invoice-x-api.d.ts +3 -3
  37. package/icc-x-api/icc-invoice-x-api.js +5 -5
  38. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  39. package/icc-x-api/icc-maintenance-task-x-api.d.ts +6 -3
  40. package/icc-x-api/icc-maintenance-task-x-api.js +21 -7
  41. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  42. package/icc-x-api/icc-message-x-api.d.ts +3 -3
  43. package/icc-x-api/icc-message-x-api.js +4 -4
  44. package/icc-x-api/icc-message-x-api.js.map +1 -1
  45. package/icc-x-api/icc-patient-x-api.d.ts +3 -3
  46. package/icc-x-api/icc-patient-x-api.js +9 -9
  47. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  48. package/icc-x-api/icc-receipt-x-api.d.ts +3 -3
  49. package/icc-x-api/icc-receipt-x-api.js +5 -5
  50. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  51. package/icc-x-api/icc-time-table-x-api.d.ts +3 -3
  52. package/icc-x-api/icc-time-table-x-api.js +5 -5
  53. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  54. package/icc-x-api/icc-user-x-api.d.ts +0 -2
  55. package/icc-x-api/icc-user-x-api.js +0 -8
  56. package/icc-x-api/icc-user-x-api.js.map +1 -1
  57. package/icc-x-api/index.d.ts +2 -0
  58. package/icc-x-api/index.js +24 -19
  59. package/icc-x-api/index.js.map +1 -1
  60. package/package.json +1 -1
@@ -26,7 +26,7 @@ const _ = require("lodash");
26
26
  const icc_api_1 = require("../icc-api");
27
27
  const utils_1 = require("./utils");
28
28
  class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
29
- constructor(host, headers, crypto, userApi, encryptedKeys = ['details', 'title', 'patientId'], fetchImpl = typeof window !== 'undefined'
29
+ constructor(host, headers, crypto, dataOwnerApi, encryptedKeys = ['details', 'title', 'patientId'], fetchImpl = typeof window !== 'undefined'
30
30
  ? window.fetch
31
31
  : typeof self !== 'undefined'
32
32
  ? self.fetch
@@ -35,7 +35,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
35
35
  this.i18n = i18n;
36
36
  this.encryptedKeys = ['details', 'title', 'patientId'];
37
37
  this.crypto = crypto;
38
- this.userApi = userApi;
38
+ this.dataOwnerApi = dataOwnerApi;
39
39
  this.encryptedKeys = encryptedKeys;
40
40
  }
41
41
  newInstance(user, ci, delegates = []) {
@@ -47,7 +47,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
47
47
  _type: 'org.taktik.icure.entities.CalendarItem',
48
48
  created: new Date().getTime(),
49
49
  modified: new Date().getTime(),
50
- responsible: this.userApi.getDataOwnerOf(user),
50
+ responsible: this.dataOwnerApi.getDataOwnerOf(user),
51
51
  author: user.id,
52
52
  codes: [],
53
53
  tags: [],
@@ -55,7 +55,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
55
55
  return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates);
56
56
  }
57
57
  initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates = []) {
58
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
58
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
59
59
  return this.crypto.extractDelegationsSFKs(patient, dataOwnerId).then((secretForeignKeys) => __awaiter(this, void 0, void 0, function* () {
60
60
  const dels = yield this.crypto.initObjectDelegations(calendarItem, patient, dataOwnerId, secretForeignKeys.extractedKeys[0]);
61
61
  const eks = yield this.crypto.initEncryptionKeys(calendarItem, dataOwnerId);
@@ -91,7 +91,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
91
91
  return body
92
92
  ? this.encrypt(user, [_.cloneDeep(body)])
93
93
  .then((items) => _super.createCalendarItem.call(this, items[0]))
94
- .then((ci) => this.decrypt(this.userApi.getDataOwnerOf(user), [ci]))
94
+ .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ci]))
95
95
  .then((cis) => cis[0])
96
96
  : null;
97
97
  });
@@ -99,20 +99,20 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
99
99
  getCalendarItemWithUser(user, calendarItemId) {
100
100
  return super
101
101
  .getCalendarItem(calendarItemId)
102
- .then((calendarItem) => this.decrypt(this.userApi.getDataOwnerOf(user), [calendarItem]))
102
+ .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [calendarItem]))
103
103
  .then((cis) => cis[0]);
104
104
  }
105
105
  getCalendarItem(calendarItemId) {
106
106
  throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
107
107
  }
108
108
  getCalendarItemsWithUser(user) {
109
- return super.getCalendarItems().then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user), calendarItems));
109
+ return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
110
110
  }
111
111
  getCalendarItems() {
112
112
  throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
113
113
  }
114
114
  getCalendarItemsWithIdsWithUser(user, body) {
115
- return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user), calendarItems));
115
+ return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
116
116
  }
117
117
  getCalendarItemsWithIds(body) {
118
118
  throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
@@ -120,7 +120,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
120
120
  getCalendarItemsByPeriodAndHcPartyIdWithUser(user, startDate, endDate, hcPartyId) {
121
121
  return super
122
122
  .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)
123
- .then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user), calendarItems));
123
+ .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
124
124
  }
125
125
  getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId) {
126
126
  throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
@@ -128,7 +128,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
128
128
  getCalendarsByPeriodAndAgendaIdWithUser(user, startDate, endDate, agendaId) {
129
129
  return super
130
130
  .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)
131
- .then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user), calendarItems));
131
+ .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
132
132
  }
133
133
  getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId) {
134
134
  throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
@@ -159,13 +159,13 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
159
159
  return body
160
160
  ? this.encrypt(user, [_.cloneDeep(body)])
161
161
  .then((items) => _super.modifyCalendarItem.call(this, items[0]))
162
- .then((ci) => this.decrypt(this.userApi.getDataOwnerOf(user), [ci]))
162
+ .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ci]))
163
163
  .then((cis) => cis[0])
164
164
  : null;
165
165
  });
166
166
  }
167
167
  initEncryptionKeys(user, calendarItem) {
168
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
168
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
169
169
  return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId).then((eks) => {
170
170
  let promise = Promise.resolve(_.extend(calendarItem, {
171
171
  encryptionKeys: eks.encryptionKeys,
@@ -182,7 +182,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
182
182
  return Promise.all(calendarItems.map((calendarItem) => (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length
183
183
  ? Promise.resolve(calendarItem)
184
184
  : this.initEncryptionKeys(user, calendarItem))
185
- .then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.userApi.getDataOwnerOf(user), calendarItem.id, calendarItem.encryptionKeys))
185
+ .then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user), calendarItem.id, calendarItem.encryptionKeys))
186
186
  .then((eks) => this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(eks.extractedKeys[0].replace(/-/g, ''))))
187
187
  .then((key) => (0, utils_1.crypt)(calendarItem, (obj) => this.crypto.AES.encrypt(key, (0, utils_1.utf8_2ua)(JSON.stringify(obj))), this.encryptedKeys))));
188
188
  }
@@ -1 +1 @@
1
- {"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAI3B,wCAA+C;AAC/C,mCAAmE;AAGnE,MAAa,mBAAoB,SAAQ,4BAAkB;IAMzD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,OAAoB,EACpB,gBAA+B,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,EAChE,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,SAAS,CAAC,CAAA;QAjBjC,SAAI,GAAQ,IAAI,CAAA;QAGhB,kBAAa,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,WAA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A;4BAC5F,OAAO,EAAE,CAAA;yBACV;oBACH,CAAC,CAAC;yBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;wBACb,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;wBAC/C,OAAO,EAAE,CAAA;oBACX,CAAC,CAAC,CACL,CACF,CAAA;gBACH,CAAC,CAAC;gBACN,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QACnC,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF;AA/QD,kDA+QC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { crypt, decrypt, hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { IccUserXApi } from './icc-user-x-api'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n userApi: IccUserXApi\n encryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n userApi: IccUserXApi,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\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, fetchImpl)\n this.crypto = crypto\n this.userApi = userApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: User, ci: CalendarItem, delegates: string[] = []) {\n return this.newInstancePatient(user, null, ci, delegates)\n }\n\n newInstancePatient(user: models.User, patient: models.Patient | null, ci: any, delegates: string[] = []): Promise<models.CalendarItem> {\n const calendarItem = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.CalendarItem',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.userApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n ci || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient | null,\n calendarItem: models.CalendarItem,\n delegates: string[] = []\n ): Promise<models.CalendarItem> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n\n return this.crypto.extractDelegationsSFKs(patient, dataOwnerId!).then(async (secretForeignKeys) => {\n const dels = await this.crypto.initObjectDelegations(calendarItem, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0])\n const eks = await this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!)\n\n _.extend(calendarItem, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(calendarItem)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((contact) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, contact, dataOwnerId!, delegateId, dels.secretId, eks.secretId)\n ))\n )\n return promise\n })\n }\n\n findBy(hcpartyId: string, patient: models.Patient) {\n return this.crypto.extractDelegationsSFKs(patient, hcpartyId).then((secretForeignKeys) => {\n return secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n : Promise.resolve([])\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem> | any> {\n return super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.userApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.userApi.getDataOwnerOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.modifyCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.userApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n initEncryptionKeys(user: models.User, calendarItem: models.CalendarItem): Promise<models.CalendarItem> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(calendarItem, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((item) =>\n this.crypto.appendEncryptionKeys(item, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(item, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((calendarItem) =>\n (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length\n ? Promise.resolve(calendarItem)\n : this.initEncryptionKeys(user, calendarItem)\n )\n .then((calendarItem: CalendarItem) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.userApi.getDataOwnerOf(user)!, calendarItem.id!, calendarItem.encryptionKeys!)\n )\n .then((eks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(eks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n crypt(calendarItem, (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))), this.encryptedKeys)\n )\n )\n )\n }\n\n decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n calendarItems.map((calendarItem) => {\n return calendarItem.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n calendarItem.id!,\n _.size(calendarItem.encryptionKeys) ? calendarItem.encryptionKeys! : calendarItem.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n return Promise.resolve(calendarItem)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then((key) =>\n decrypt(calendarItem, (ec) =>\n this.crypto.AES.decrypt(key, ec)\n .then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse calendar item', calendarItem.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n .catch((err) => {\n console.log('Error during AES decryption', err)\n return {}\n })\n )\n )\n })\n : Promise.resolve(calendarItem)\n })\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAI3B,wCAA+C;AAC/C,mCAAmE;AAGnE,MAAa,mBAAoB,SAAQ,4BAAkB;IAMzD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,gBAA+B,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,EAChE,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,SAAS,CAAC,CAAA;QAjBjC,SAAI,GAAQ,IAAI,CAAA;QAGhB,kBAAa,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QAe/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED,WAAW,CAAC,IAAU,EAAE,EAAgB,EAAE,YAAsB,EAAE;QAChE,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,CAAC,CAAA;IAC3D,CAAC;IAED,kBAAkB,CAAC,IAAiB,EAAE,OAA8B,EAAE,EAAO,EAAE,YAAsB,EAAE;QACrG,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAC3B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\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { crypt, decrypt, hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport {IccDataOwnerXApi} from \"./icc-data-owner-x-api\"\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n encryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\n 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, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: User, ci: CalendarItem, delegates: string[] = []) {\n return this.newInstancePatient(user, null, ci, delegates)\n }\n\n newInstancePatient(user: models.User, patient: models.Patient | null, ci: any, delegates: string[] = []): Promise<models.CalendarItem> {\n const calendarItem = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.CalendarItem',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n ci || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient | null,\n calendarItem: models.CalendarItem,\n delegates: string[] = []\n ): Promise<models.CalendarItem> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.extractDelegationsSFKs(patient, dataOwnerId!).then(async (secretForeignKeys) => {\n const dels = await this.crypto.initObjectDelegations(calendarItem, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0])\n const eks = await this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!)\n\n _.extend(calendarItem, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(calendarItem)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((contact) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, contact, dataOwnerId!, delegateId, dels.secretId, eks.secretId)\n ))\n )\n return promise\n })\n }\n\n findBy(hcpartyId: string, patient: models.Patient) {\n return this.crypto.extractDelegationsSFKs(patient, hcpartyId).then((secretForeignKeys) => {\n return secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n : Promise.resolve([])\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem> | any> {\n return super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.modifyCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n initEncryptionKeys(user: models.User, calendarItem: models.CalendarItem): Promise<models.CalendarItem> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(calendarItem, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((item) =>\n this.crypto.appendEncryptionKeys(item, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(item, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((calendarItem) =>\n (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length\n ? Promise.resolve(calendarItem)\n : this.initEncryptionKeys(user, calendarItem)\n )\n .then((calendarItem: CalendarItem) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItem.id!, calendarItem.encryptionKeys!)\n )\n .then((eks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(eks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n crypt(calendarItem, (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))), this.encryptedKeys)\n )\n )\n )\n }\n\n decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n calendarItems.map((calendarItem) => {\n return calendarItem.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n calendarItem.id!,\n _.size(calendarItem.encryptionKeys) ? calendarItem.encryptionKeys! : calendarItem.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n return Promise.resolve(calendarItem)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then((key) =>\n decrypt(calendarItem, (ec) =>\n this.crypto.AES.decrypt(key, ec)\n .then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse calendar item', calendarItem.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n .catch((err) => {\n console.log('Error during AES decryption', err)\n return {}\n })\n )\n )\n })\n : Promise.resolve(calendarItem)\n })\n )\n }\n}\n"]}
@@ -1,13 +1,13 @@
1
1
  import { IccClassificationApi } from '../icc-api';
2
2
  import { IccCryptoXApi } from './icc-crypto-x-api';
3
3
  import * as models from '../icc-api/model/models';
4
- import { IccUserXApi } from './icc-user-x-api';
4
+ import { IccDataOwnerXApi } from './icc-data-owner-x-api';
5
5
  export declare class IccClassificationXApi extends IccClassificationApi {
6
6
  crypto: IccCryptoXApi;
7
- userApi: IccUserXApi;
7
+ dataOwnerApi: IccDataOwnerXApi;
8
8
  constructor(host: string, headers: {
9
9
  [key: string]: string;
10
- }, crypto: IccCryptoXApi, userApi: IccUserXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
10
+ }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
11
11
  newInstance(user: models.User, patient: models.Patient, c?: any, delegates?: string[]): Promise<models.Classification>;
12
12
  initDelegationsAndEncryptionKeys(user: models.User, patient: models.Patient, classification: models.Classification, delegates?: string[]): Promise<models.Classification>;
13
13
  findBy(hcpartyId: string, patient: models.Patient): Promise<models.Classification[]>;
@@ -5,14 +5,14 @@ const icc_api_1 = require("../icc-api");
5
5
  const _ = require("lodash");
6
6
  const moment = require("moment");
7
7
  class IccClassificationXApi extends icc_api_1.IccClassificationApi {
8
- constructor(host, headers, crypto, userApi, fetchImpl = typeof window !== 'undefined'
8
+ constructor(host, headers, crypto, dataOwnerApi, fetchImpl = typeof window !== 'undefined'
9
9
  ? window.fetch
10
10
  : typeof self !== 'undefined'
11
11
  ? self.fetch
12
12
  : fetch) {
13
13
  super(host, headers, fetchImpl);
14
14
  this.crypto = crypto;
15
- this.userApi = userApi;
15
+ this.dataOwnerApi = dataOwnerApi;
16
16
  }
17
17
  newInstance(user, patient, c = {}, delegates = []) {
18
18
  const classification = _.assign({
@@ -20,7 +20,7 @@ class IccClassificationXApi extends icc_api_1.IccClassificationApi {
20
20
  _type: 'org.taktik.icure.entities.Classification',
21
21
  created: new Date().getTime(),
22
22
  modified: new Date().getTime(),
23
- responsible: this.userApi.getDataOwnerOf(user),
23
+ responsible: this.dataOwnerApi.getDataOwnerOf(user),
24
24
  author: user.id,
25
25
  codes: [],
26
26
  tags: [],
@@ -30,7 +30,7 @@ class IccClassificationXApi extends icc_api_1.IccClassificationApi {
30
30
  return this.initDelegationsAndEncryptionKeys(user, patient, classification, delegates);
31
31
  }
32
32
  initDelegationsAndEncryptionKeys(user, patient, classification, delegates = []) {
33
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
33
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
34
34
  return this.crypto
35
35
  .extractDelegationsSFKs(patient, dataOwnerId)
36
36
  .then((secretForeignKeys) => this.crypto.initObjectDelegations(classification, patient, dataOwnerId, secretForeignKeys.extractedKeys[0]))
@@ -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;AAGhC,MAAa,qBAAsB,SAAQ,8BAAoB;IAI7D,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,OAAoB,EACpB,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,SAAS,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,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,UAAU,EAAE;YAC5B,KAAK,EAAE,0CAA0C;YACjD,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC7B,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC9B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AAe,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CACrI,CAAC,OAAO,CACP,CAAC,UAAU,EAAE,EAAE,CACb,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,EAAE,CACzC,IAAI,CAAC,MAAM;iBACR,wCAAwC,CAAC,cAAc,EAAE,OAAO,EAAE,WAAY,EAAE,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC;iBAC9G,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAClB,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE;gBACvB,WAAW,EAAE,SAAS,CAAC,WAAW;gBAClC,kBAAkB,EAAE,SAAS,CAAC,kBAAkB;aACjD,CAAC,CACH;iBACA,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBACd,OAAO,cAAc,CAAA;YACvB,CAAC,CAAC,CACL,CAAC,CACL,CAAA;YAED,OAAO,OAAO,CAAA;QAChB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,SAAiB,EAAE,OAAuB;QAC/C,OAAO,IAAI,CAAC,MAAM;aACf,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC;aAC1C,IAAI,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAC1B,IAAI,CAAC,8CAA8C,CAAC,iBAAiB,CAAC,SAAU,EAAE,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CACrI,CAAA;IACL,CAAC;CACF;AAzFD,sDAyFC","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 { IccUserXApi } from './icc-user-x-api'\n\nexport class IccClassificationXApi extends IccClassificationApi {\n crypto: IccCryptoXApi\n userApi: IccUserXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n userApi: IccUserXApi,\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, fetchImpl)\n this.crypto = crypto\n this.userApi = userApi\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.userApi.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.userApi.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;AAKjD,4BAA2B;AAC3B,iCAAgC;AAGhC,MAAa,qBAAsB,SAAQ,8BAAoB;IAI7D,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,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,SAAS,CAAC,CAAA;QAC/B,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,UAAU,EAAE;YAC5B,KAAK,EAAE,0CAA0C;YACjD,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC7B,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC9B,WAAW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AAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CACrI,CAAC,OAAO,CACP,CAAC,UAAU,EAAE,EAAE,CACb,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,EAAE,CACzC,IAAI,CAAC,MAAM;iBACR,wCAAwC,CAAC,cAAc,EAAE,OAAO,EAAE,WAAY,EAAE,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC;iBAC9G,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAClB,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE;gBACvB,WAAW,EAAE,SAAS,CAAC,WAAW;gBAClC,kBAAkB,EAAE,SAAS,CAAC,kBAAkB;aACjD,CAAC,CACH;iBACA,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBACd,OAAO,cAAc,CAAA;YACvB,CAAC,CAAC,CACL,CAAC,CACL,CAAA;YAED,OAAO,OAAO,CAAA;QAChB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,SAAiB,EAAE,OAAuB;QAC/C,OAAO,IAAI,CAAC,MAAM;aACf,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC;aAC1C,IAAI,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAC1B,IAAI,CAAC,8CAA8C,CAAC,iBAAiB,CAAC,SAAU,EAAE,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CACrI,CAAA;IACL,CAAC;CACF;AAzFD,sDAyFC","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'\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 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, 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"]}
@@ -3,14 +3,14 @@ import { IccCryptoXApi } from './icc-crypto-x-api';
3
3
  import * as models from '../icc-api/model/models';
4
4
  import { Contact, ListOfIds, Service } from '../icc-api/model/models';
5
5
  import { PaginatedListContact } from '../icc-api/model/PaginatedListContact';
6
- import { IccUserXApi } from './icc-user-x-api';
6
+ import { IccDataOwnerXApi } from './icc-data-owner-x-api';
7
7
  export declare class IccContactXApi extends IccContactApi {
8
8
  i18n: any;
9
9
  crypto: IccCryptoXApi;
10
- userApi: IccUserXApi;
10
+ dataOwnerApi: IccDataOwnerXApi;
11
11
  constructor(host: string, headers: {
12
12
  [key: string]: string;
13
- }, crypto: IccCryptoXApi, userApi: IccUserXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
13
+ }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
14
14
  newInstance(user: models.User, patient: models.Patient, c: any, confidential?: boolean, delegates?: string[]): Promise<models.Contact>;
15
15
  /**
16
16
  * 1. Extract(decrypt) the patient's secretForeignKeys from the
@@ -20,7 +20,7 @@ const binary_utils_1 = require("./utils/binary-utils");
20
20
  const ServiceByIdsFilter_1 = require("./filters/ServiceByIdsFilter");
21
21
  const utils_1 = require("./utils");
22
22
  class IccContactXApi extends icc_api_1.IccContactApi {
23
- constructor(host, headers, crypto, userApi, fetchImpl = typeof window !== 'undefined'
23
+ constructor(host, headers, crypto, dataOwnerApi, fetchImpl = typeof window !== 'undefined'
24
24
  ? window.fetch
25
25
  : typeof self !== 'undefined'
26
26
  ? self.fetch
@@ -28,7 +28,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
28
28
  super(host, headers, fetchImpl);
29
29
  this.i18n = contact_i18n_1.default;
30
30
  this.crypto = crypto;
31
- this.userApi = userApi;
31
+ this.dataOwnerApi = dataOwnerApi;
32
32
  }
33
33
  newInstance(user, patient, c, confidential = false, delegates = []) {
34
34
  const contact = new models.Contact(_.extend({
@@ -36,7 +36,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
36
36
  _type: 'org.taktik.icure.entities.Contact',
37
37
  created: new Date().getTime(),
38
38
  modified: new Date().getTime(),
39
- responsible: this.userApi.getDataOwnerOf(user),
39
+ responsible: this.dataOwnerApi.getDataOwnerOf(user),
40
40
  author: user.id,
41
41
  codes: [],
42
42
  tags: [],
@@ -56,7 +56,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
56
56
  * & encryptionKeys.
57
57
  */
58
58
  initDelegationsAndEncryptionKeys(user, patient, contact, confidential = false, delegates = []) {
59
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
59
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
60
60
  return this.crypto.extractPreferredSfk(patient, dataOwnerId, confidential).then((key) => __awaiter(this, void 0, void 0, function* () {
61
61
  if (!key) {
62
62
  console.error(`SFK cannot be found for Contact ${key}. The contact will not be reachable from the patient side`);
@@ -82,7 +82,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
82
82
  }));
83
83
  }
84
84
  initEncryptionKeys(user, ctc) {
85
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
85
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
86
86
  return this.crypto.initEncryptionKeys(ctc, dataOwnerId).then((eks) => {
87
87
  let promise = Promise.resolve(_.extend(ctc, {
88
88
  encryptionKeys: eks.encryptionKeys,
@@ -212,19 +212,19 @@ class IccContactXApi extends icc_api_1.IccContactApi {
212
212
  .then((paginatedList) => { var _a; return this.decryptServices(user.healthcarePartyId || user.patientId, (_a = paginatedList.rows) !== null && _a !== void 0 ? _a : [], undefined, undefined); });
213
213
  }
214
214
  findByHCPartyFormIdWithUser(user, hcPartyId, formId) {
215
- return super.findByHCPartyFormId(hcPartyId, formId).then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs));
215
+ return super.findByHCPartyFormId(hcPartyId, formId).then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs));
216
216
  }
217
217
  findByHCPartyFormIdsWithUser(user, hcPartyId, body) {
218
- return super.findByHCPartyFormIds(hcPartyId, body).then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs));
218
+ return super.findByHCPartyFormIds(hcPartyId, body).then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs));
219
219
  }
220
220
  getContactWithUser(user, contactId) {
221
221
  return super
222
222
  .getContact(contactId)
223
- .then((ctc) => this.decrypt(this.userApi.getDataOwnerOf(user), [ctc]))
223
+ .then((ctc) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ctc]))
224
224
  .then((ctcs) => ctcs[0]);
225
225
  }
226
226
  getContactsWithUser(user, body) {
227
- return super.getContacts(body).then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs));
227
+ return super.getContacts(body).then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs));
228
228
  }
229
229
  modifyContactWithUser(user, body) {
230
230
  const _super = Object.create(null, {
@@ -234,7 +234,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
234
234
  return body
235
235
  ? this.encrypt(user, [_.cloneDeep(body)])
236
236
  .then((ctcs) => _super.modifyContact.call(this, ctcs[0]))
237
- .then((ctc) => this.decrypt(this.userApi.getDataOwnerOf(user), [ctc]))
237
+ .then((ctc) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ctc]))
238
238
  .then((ctcs) => ctcs[0])
239
239
  : null;
240
240
  });
@@ -247,7 +247,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
247
247
  return bodies
248
248
  ? this.encrypt(user, bodies.map((c) => _.cloneDeep(c)))
249
249
  .then((ctcs) => _super.modifyContacts.call(this, ctcs))
250
- .then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs))
250
+ .then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs))
251
251
  : null;
252
252
  });
253
253
  }
@@ -259,7 +259,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
259
259
  return body
260
260
  ? this.encrypt(user, [_.cloneDeep(body)])
261
261
  .then((ctcs) => _super.createContact.call(this, ctcs[0]))
262
- .then((ctc) => this.decrypt(this.userApi.getDataOwnerOf(user), [ctc]))
262
+ .then((ctc) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ctc]))
263
263
  .then((ctcs) => ctcs[0])
264
264
  : null;
265
265
  });
@@ -272,7 +272,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
272
272
  return bodies
273
273
  ? this.encrypt(user, bodies.map((c) => _.cloneDeep(c)))
274
274
  .then((ctcs) => _super.createContacts.call(this, ctcs))
275
- .then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs))
275
+ .then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs))
276
276
  : null;
277
277
  });
278
278
  }
@@ -307,7 +307,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
307
307
  })));
308
308
  }
309
309
  encrypt(user, ctcs) {
310
- const hcpartyId = this.userApi.getDataOwnerOf(user);
310
+ const hcpartyId = this.dataOwnerApi.getDataOwnerOf(user);
311
311
  const bypassEncryption = false; //Used for debug
312
312
  return Promise.all(ctcs.map((ctc) => __awaiter(this, void 0, void 0, function* () {
313
313
  const initialisedCtc = bypassEncryption //Prevent encryption for test ctc
@@ -500,7 +500,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
500
500
  const existing = ctc.services.find((s) => s.id === svc.id);
501
501
  const promoted = _.extend(_.extend(existing || {}, svc), {
502
502
  author: user.id,
503
- responsible: this.userApi.getDataOwnerOf(user),
503
+ responsible: this.dataOwnerApi.getDataOwnerOf(user),
504
504
  modified: new Date().getTime(),
505
505
  });
506
506
  if (!existing) {
@@ -592,7 +592,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
592
592
  _type: 'org.taktik.icure.entities.embed.Service',
593
593
  created: new Date().getTime(),
594
594
  modified: new Date().getTime(),
595
- responsible: this.userApi.getDataOwnerOf(user),
595
+ responsible: this.dataOwnerApi.getDataOwnerOf(user),
596
596
  author: user.id,
597
597
  codes: [],
598
598
  tags: [],