@icure/api 4.1.18 → 4.2.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.
- package/icc-api/api/IccGroupApi.d.ts +12 -2
- package/icc-api/api/IccGroupApi.js +26 -2
- package/icc-api/api/IccGroupApi.js.map +1 -1
- package/icc-x-api/filters/UserByNameEmailPhoneFilter.d.ts +18 -0
- package/icc-x-api/filters/UserByNameEmailPhoneFilter.js +25 -0
- package/icc-x-api/filters/UserByNameEmailPhoneFilter.js.map +1 -0
- package/icc-x-api/icc-accesslog-x-api.d.ts +3 -1
- package/icc-x-api/icc-accesslog-x-api.js +18 -17
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +4 -2
- package/icc-x-api/icc-calendar-item-x-api.js +19 -18
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +3 -1
- package/icc-x-api/icc-classification-x-api.js +7 -6
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +3 -1
- package/icc-x-api/icc-contact-x-api.js +25 -21
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +10 -10
- package/icc-x-api/icc-crypto-x-api.js +21 -21
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +4 -2
- package/icc-x-api/icc-document-x-api.js +24 -21
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +4 -2
- package/icc-x-api/icc-form-x-api.js +22 -21
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +29 -4
- package/icc-x-api/icc-helement-x-api.js +136 -11
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.d.ts +5 -3
- package/icc-x-api/icc-invoice-x-api.js +22 -21
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +3 -1
- package/icc-x-api/icc-message-x-api.js +7 -6
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +3 -1
- package/icc-x-api/icc-patient-x-api.js +19 -17
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +4 -2
- package/icc-x-api/icc-receipt-x-api.js +21 -20
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +4 -2
- package/icc-x-api/icc-time-table-x-api.js +5 -4
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/icc-user-x-api.d.ts +2 -0
- package/icc-x-api/icc-user-x-api.js +8 -0
- package/icc-x-api/icc-user-x-api.js.map +1 -1
- package/icc-x-api/index.js +12 -12
- package/icc-x-api/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ const utils_1 = require("./crypto/utils");
|
|
|
18
18
|
const icc_api_1 = require("../icc-api");
|
|
19
19
|
const binary_utils_1 = require("./utils/binary-utils");
|
|
20
20
|
class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
21
|
-
constructor(host, headers, crypto, fetchImpl = typeof window !== 'undefined'
|
|
21
|
+
constructor(host, headers, crypto, userApi, fetchImpl = typeof window !== 'undefined'
|
|
22
22
|
? window.fetch
|
|
23
23
|
: typeof self !== 'undefined'
|
|
24
24
|
? self.fetch
|
|
@@ -27,6 +27,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
27
27
|
this.i18n = i18n;
|
|
28
28
|
this.cryptedKeys = ['details', 'title', 'patientId'];
|
|
29
29
|
this.crypto = crypto;
|
|
30
|
+
this.userApi = userApi;
|
|
30
31
|
}
|
|
31
32
|
newInstance(user, ci, delegates = []) {
|
|
32
33
|
return this.newInstancePatient(user, null, ci, delegates);
|
|
@@ -37,7 +38,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
37
38
|
_type: 'org.taktik.icure.entities.CalendarItem',
|
|
38
39
|
created: new Date().getTime(),
|
|
39
40
|
modified: new Date().getTime(),
|
|
40
|
-
responsible:
|
|
41
|
+
responsible: this.userApi.getDataOwnerOf(user),
|
|
41
42
|
author: user.id,
|
|
42
43
|
codes: [],
|
|
43
44
|
tags: [],
|
|
@@ -45,12 +46,12 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
45
46
|
return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates);
|
|
46
47
|
}
|
|
47
48
|
initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates = []) {
|
|
48
|
-
const
|
|
49
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
49
50
|
return this.crypto
|
|
50
|
-
.extractDelegationsSFKs(patient,
|
|
51
|
+
.extractDelegationsSFKs(patient, dataOwnerId)
|
|
51
52
|
.then((secretForeignKeys) => Promise.all([
|
|
52
|
-
this.crypto.initObjectDelegations(calendarItem, patient,
|
|
53
|
-
this.crypto.initEncryptionKeys(calendarItem,
|
|
53
|
+
this.crypto.initObjectDelegations(calendarItem, patient, dataOwnerId, secretForeignKeys.extractedKeys[0]),
|
|
54
|
+
this.crypto.initEncryptionKeys(calendarItem, dataOwnerId),
|
|
54
55
|
]))
|
|
55
56
|
.then((initData) => {
|
|
56
57
|
const dels = initData[0];
|
|
@@ -62,7 +63,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
62
63
|
encryptionKeys: eks.encryptionKeys,
|
|
63
64
|
});
|
|
64
65
|
let promise = Promise.resolve(calendarItem);
|
|
65
|
-
_.uniq(delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])).forEach((delegateId) => (promise = promise.then((contact) => this.crypto.addDelegationsAndEncryptionKeys(patient, contact,
|
|
66
|
+
_.uniq(delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])).forEach((delegateId) => (promise = promise.then((contact) => this.crypto.addDelegationsAndEncryptionKeys(patient, contact, dataOwnerId, delegateId, dels.secretId, eks.secretId))));
|
|
66
67
|
return promise;
|
|
67
68
|
});
|
|
68
69
|
}
|
|
@@ -83,27 +84,27 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
83
84
|
return body
|
|
84
85
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
85
86
|
.then((items) => super.createCalendarItem(items[0]))
|
|
86
|
-
.then((ci) => this.decrypt((user
|
|
87
|
+
.then((ci) => this.decrypt(this.userApi.getDataOwnerOf(user), [ci]))
|
|
87
88
|
.then((cis) => cis[0])
|
|
88
89
|
: Promise.resolve(null);
|
|
89
90
|
}
|
|
90
91
|
getCalendarItemWithUser(user, calendarItemId) {
|
|
91
92
|
return super
|
|
92
93
|
.getCalendarItem(calendarItemId)
|
|
93
|
-
.then((calendarItem) => this.decrypt((user
|
|
94
|
+
.then((calendarItem) => this.decrypt(this.userApi.getDataOwnerOf(user), [calendarItem]))
|
|
94
95
|
.then((cis) => cis[0]);
|
|
95
96
|
}
|
|
96
97
|
getCalendarItem(calendarItemId) {
|
|
97
98
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
98
99
|
}
|
|
99
100
|
getCalendarItemsWithUser(user) {
|
|
100
|
-
return super.getCalendarItems().then((calendarItems) => this.decrypt((user
|
|
101
|
+
return super.getCalendarItems().then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user), calendarItems));
|
|
101
102
|
}
|
|
102
103
|
getCalendarItems() {
|
|
103
104
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
104
105
|
}
|
|
105
106
|
getCalendarItemsWithIdsWithUser(user, body) {
|
|
106
|
-
return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt((user
|
|
107
|
+
return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user), calendarItems));
|
|
107
108
|
}
|
|
108
109
|
getCalendarItemsWithIds(body) {
|
|
109
110
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -111,7 +112,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
111
112
|
getCalendarItemsByPeriodAndHcPartyIdWithUser(user, startDate, endDate, hcPartyId) {
|
|
112
113
|
return super
|
|
113
114
|
.getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)
|
|
114
|
-
.then((calendarItems) => this.decrypt((user
|
|
115
|
+
.then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user), calendarItems));
|
|
115
116
|
}
|
|
116
117
|
getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId) {
|
|
117
118
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -119,7 +120,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
119
120
|
getCalendarsByPeriodAndAgendaIdWithUser(user, startDate, endDate, agendaId) {
|
|
120
121
|
return super
|
|
121
122
|
.getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)
|
|
122
|
-
.then((calendarItems) => this.decrypt((user
|
|
123
|
+
.then((calendarItems) => this.decrypt(this.userApi.getDataOwnerOf(user), calendarItems));
|
|
123
124
|
}
|
|
124
125
|
getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId) {
|
|
125
126
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -146,17 +147,17 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
146
147
|
return body
|
|
147
148
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
148
149
|
.then((items) => super.modifyCalendarItem(items[0]))
|
|
149
|
-
.then((ci) => this.decrypt((user
|
|
150
|
+
.then((ci) => this.decrypt(this.userApi.getDataOwnerOf(user), [ci]))
|
|
150
151
|
.then((cis) => cis[0])
|
|
151
152
|
: Promise.resolve(null);
|
|
152
153
|
}
|
|
153
154
|
initEncryptionKeys(user, calendarItem) {
|
|
154
|
-
const
|
|
155
|
-
return this.crypto.initEncryptionKeys(calendarItem,
|
|
155
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
156
|
+
return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId).then((eks) => {
|
|
156
157
|
let promise = Promise.resolve(_.extend(calendarItem, {
|
|
157
158
|
encryptionKeys: eks.encryptionKeys,
|
|
158
159
|
}));
|
|
159
|
-
(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach((delegateId) => (promise = promise.then((item) => this.crypto.appendEncryptionKeys(item,
|
|
160
|
+
(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach((delegateId) => (promise = promise.then((item) => this.crypto.appendEncryptionKeys(item, dataOwnerId, delegateId, eks.secretId).then((extraEks) => {
|
|
160
161
|
return _.extend(item, {
|
|
161
162
|
encryptionKeys: extraEks.encryptionKeys,
|
|
162
163
|
});
|
|
@@ -168,7 +169,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
168
169
|
return Promise.all(calendarItems.map((calendarItem) => (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length
|
|
169
170
|
? Promise.resolve(calendarItem)
|
|
170
171
|
: this.initEncryptionKeys(user, calendarItem))
|
|
171
|
-
.then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy((user
|
|
172
|
+
.then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.userApi.getDataOwnerOf(user), calendarItem.id, calendarItem.encryptionKeys))
|
|
172
173
|
.then((eks) => this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(eks.extractedKeys[0].replace(/-/g, ''))))
|
|
173
174
|
.then((key) => utils_1.utils.crypt(calendarItem, (obj) => this.crypto.AES.encrypt(key, binary_utils_1.utf8_2ua(JSON.stringify(obj))), this.cryptedKeys))));
|
|
174
175
|
}
|
|
@@ -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;AAE3B,0CAAsC;AAEtC,wCAA+C;AAE/C,uDAAgE;AAEhE,MAAa,mBAAoB,SAAQ,4BAAkB;IAKzD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,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;QAdjC,SAAI,GAAQ,IAAI,CAAA;QAEhB,gBAAW,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QAa7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,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;YACE,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YAC5B,KAAK,E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AAC,CAAA;QACnC,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF;AAvRD,kDAuRC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { utils } from './crypto/utils'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { hex2ua, ua2utf8, utf8_2ua } from './utils/binary-utils'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n cryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\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 }\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: user.healthcarePartyId || user.patientId,\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 hcpId = user.healthcarePartyId || user.patientId\n return this.crypto\n .extractDelegationsSFKs(patient, hcpId!)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(calendarItem, patient, hcpId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(calendarItem, hcpId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\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, hcpId!, 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 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((user.healthcarePartyId || user.patientId)!, [ci]))\n .then((cis) => cis[0])\n : Promise.resolve(null)\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt((user.healthcarePartyId || user.patientId)!, [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((user.healthcarePartyId || user.patientId)!, 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((user.healthcarePartyId || user.patientId)!, 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((user.healthcarePartyId || user.patientId)!, 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((user.healthcarePartyId || user.patientId)!, 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 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((user.healthcarePartyId || user.patientId)!, [ci]))\n .then((cis) => cis[0])\n : Promise.resolve(null)\n }\n\n initEncryptionKeys(user: models.User, calendarItem: models.CalendarItem): Promise<models.CalendarItem> {\n const hcpId = user.healthcarePartyId || user.patientId\n return this.crypto.initEncryptionKeys(calendarItem, hcpId!).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, hcpId!, 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(\n (user.healthcarePartyId || user.patientId)!,\n calendarItem.id!,\n calendarItem.encryptionKeys!\n )\n )\n .then((eks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(eks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n utils.crypt(\n calendarItem,\n (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))),\n this.cryptedKeys\n )\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 utils.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;AAG3B,0CAAsC;AAEtC,wCAA+C;AAC/C,uDAAgE;AAGhE,MAAa,mBAAoB,SA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,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CACtF,aAAK,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,CACjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;yBAC7B,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;wBACZ,MAAM,WAAW,GAAG,GAAG,IAAI,sBAAO,CAAC,GAAG,CAAC,CAAA;wBACvC,IAAI;4BACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;yBAC/B;wBAAC,OAAO,CAAC,EAAE;4BACV,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,YAAY,CAAC,EAAE,EAAE,WAAW,IAAI,iBAAiB,CAAC,CAAA;4BAC5F,OAAO,EAAE,CAAA;yBACV;oBACH,CAAC,CAAC;yBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;wBACb,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;wBAC/C,OAAO,EAAE,CAAA;oBACX,CAAC,CAAC,CACL,CACF,CAAA;gBACH,CAAC,CAAC;gBACN,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QACnC,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF;AAxRD,kDAwRC","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 { utils } from './crypto/utils'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { hex2ua, ua2utf8, utf8_2ua } from './utils/binary-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 cryptedKeys = ['details', 'title', 'patientId']\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: 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\n .extractDelegationsSFKs(patient, dataOwnerId!)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(calendarItem, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\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 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 : Promise.resolve(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 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 : Promise.resolve(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 utils.crypt(\n calendarItem,\n (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))),\n this.cryptedKeys\n )\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 utils.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,11 +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
5
|
export declare class IccClassificationXApi extends IccClassificationApi {
|
|
5
6
|
crypto: IccCryptoXApi;
|
|
7
|
+
userApi: IccUserXApi;
|
|
6
8
|
constructor(host: string, headers: {
|
|
7
9
|
[key: string]: string;
|
|
8
|
-
}, crypto: IccCryptoXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
10
|
+
}, crypto: IccCryptoXApi, userApi: IccUserXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
9
11
|
newInstance(user: models.User, patient: models.Patient, c: any): Promise<models.Classification>;
|
|
10
12
|
initDelegationsAndEncryptionKeys(user: models.User, patient: models.Patient, classification: models.Classification): Promise<models.Classification>;
|
|
11
13
|
findBy(hcpartyId: string, patient: models.Patient): Promise<models.Classification[]>;
|
|
@@ -5,13 +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, fetchImpl = typeof window !== 'undefined'
|
|
8
|
+
constructor(host, headers, crypto, userApi, 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
16
|
}
|
|
16
17
|
newInstance(user, patient, c) {
|
|
17
18
|
const classification = _.assign({
|
|
@@ -19,7 +20,7 @@ class IccClassificationXApi extends icc_api_1.IccClassificationApi {
|
|
|
19
20
|
_type: 'org.taktik.icure.entities.Classification',
|
|
20
21
|
created: new Date().getTime(),
|
|
21
22
|
modified: new Date().getTime(),
|
|
22
|
-
responsible:
|
|
23
|
+
responsible: this.userApi.getDataOwnerOf(user),
|
|
23
24
|
author: user.id,
|
|
24
25
|
codes: [],
|
|
25
26
|
tags: [],
|
|
@@ -29,10 +30,10 @@ class IccClassificationXApi extends icc_api_1.IccClassificationApi {
|
|
|
29
30
|
return this.initDelegationsAndEncryptionKeys(user, patient, classification);
|
|
30
31
|
}
|
|
31
32
|
initDelegationsAndEncryptionKeys(user, patient, classification) {
|
|
32
|
-
const
|
|
33
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
33
34
|
return this.crypto
|
|
34
|
-
.extractDelegationsSFKs(patient,
|
|
35
|
-
.then((secretForeignKeys) => this.crypto.initObjectDelegations(classification, patient,
|
|
35
|
+
.extractDelegationsSFKs(patient, dataOwnerId)
|
|
36
|
+
.then((secretForeignKeys) => this.crypto.initObjectDelegations(classification, patient, dataOwnerId, secretForeignKeys.extractedKeys[0]))
|
|
36
37
|
.then((initData) => {
|
|
37
38
|
_.extend(classification, {
|
|
38
39
|
delegations: initData.delegations,
|
|
@@ -41,7 +42,7 @@ class IccClassificationXApi extends icc_api_1.IccClassificationApi {
|
|
|
41
42
|
});
|
|
42
43
|
let promise = Promise.resolve(classification);
|
|
43
44
|
(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach((delegateId) => (promise = promise.then((classification) => this.crypto
|
|
44
|
-
.extendedDelegationsAndCryptedForeignKeys(classification, patient,
|
|
45
|
+
.extendedDelegationsAndCryptedForeignKeys(classification, patient, dataOwnerId, delegateId, initData.secretId)
|
|
45
46
|
.then((extraData) => _.extend(classification, {
|
|
46
47
|
delegations: extraData.delegations,
|
|
47
48
|
cryptedForeignKeys: extraData.cryptedForeignKeys,
|
|
@@ -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;
|
|
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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,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;AAtFD,sDAsFC","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): 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)\n }\n\n initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n classification: models.Classification\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 ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).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,12 +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
7
|
export declare class IccContactXApi extends IccContactApi {
|
|
7
8
|
i18n: any;
|
|
8
9
|
crypto: IccCryptoXApi;
|
|
10
|
+
userApi: IccUserXApi;
|
|
9
11
|
constructor(host: string, headers: {
|
|
10
12
|
[key: string]: string;
|
|
11
|
-
}, crypto: IccCryptoXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
13
|
+
}, crypto: IccCryptoXApi, userApi: IccUserXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
12
14
|
newInstance(user: models.User, patient: models.Patient, c: any, confidential?: boolean): Promise<models.Contact>;
|
|
13
15
|
/**
|
|
14
16
|
* 1. Extract(decrypt) the patient's secretForeignKeys from the
|
|
@@ -20,7 +20,7 @@ const models_1 = require("../icc-api/model/models");
|
|
|
20
20
|
const binary_utils_1 = require("./utils/binary-utils");
|
|
21
21
|
const ServiceByIdsFilter_1 = require("./filters/ServiceByIdsFilter");
|
|
22
22
|
class IccContactXApi extends icc_api_1.IccContactApi {
|
|
23
|
-
constructor(host, headers, crypto, fetchImpl = typeof window !== 'undefined'
|
|
23
|
+
constructor(host, headers, crypto, userApi, fetchImpl = typeof window !== 'undefined'
|
|
24
24
|
? window.fetch
|
|
25
25
|
: typeof self !== 'undefined'
|
|
26
26
|
? self.fetch
|
|
@@ -28,6 +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
32
|
}
|
|
32
33
|
newInstance(user, patient, c, confidential = false) {
|
|
33
34
|
const contact = new models.Contact(_.extend({
|
|
@@ -35,7 +36,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
35
36
|
_type: 'org.taktik.icure.entities.Contact',
|
|
36
37
|
created: new Date().getTime(),
|
|
37
38
|
modified: new Date().getTime(),
|
|
38
|
-
responsible:
|
|
39
|
+
responsible: this.userApi.getDataOwnerOf(user),
|
|
39
40
|
author: user.id,
|
|
40
41
|
codes: [],
|
|
41
42
|
tags: [],
|
|
@@ -55,14 +56,17 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
55
56
|
* & encryptionKeys.
|
|
56
57
|
*/
|
|
57
58
|
initDelegationsAndEncryptionKeys(user, patient, contact, confidential = false) {
|
|
58
|
-
const
|
|
59
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
59
60
|
return this.crypto
|
|
60
|
-
.extractPreferredSfk(patient,
|
|
61
|
+
.extractPreferredSfk(patient, dataOwnerId, confidential)
|
|
61
62
|
.then((key) => {
|
|
62
63
|
if (!key) {
|
|
63
64
|
console.error(`SFK cannot be found for HealthElement ${key}. The health element will not be reachable from the patient side`);
|
|
64
65
|
}
|
|
65
|
-
return Promise.all([
|
|
66
|
+
return Promise.all([
|
|
67
|
+
this.crypto.initObjectDelegations(contact, patient, dataOwnerId, key),
|
|
68
|
+
this.crypto.initEncryptionKeys(contact, dataOwnerId),
|
|
69
|
+
]);
|
|
66
70
|
})
|
|
67
71
|
.then(([dels, eks]) => {
|
|
68
72
|
_.extend(contact, {
|
|
@@ -72,11 +76,11 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
72
76
|
encryptionKeys: eks.encryptionKeys,
|
|
73
77
|
});
|
|
74
78
|
let promise = Promise.resolve(contact);
|
|
75
|
-
(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach((delegateId) => (promise = promise.then((contact) => this.crypto.addDelegationsAndEncryptionKeys(patient, contact,
|
|
79
|
+
(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach((delegateId) => (promise = promise.then((contact) => this.crypto.addDelegationsAndEncryptionKeys(patient, contact, dataOwnerId, delegateId, dels.secretId, eks.secretId).catch((e) => {
|
|
76
80
|
console.log(e);
|
|
77
81
|
return contact;
|
|
78
82
|
}))));
|
|
79
|
-
(user.autoDelegations && user.autoDelegations.anonymousMedicalInformation ? user.autoDelegations.anonymousMedicalInformation : []).forEach((delegateId) => (promise = promise.then((contact) => this.crypto.addDelegationsAndEncryptionKeys(patient, contact,
|
|
83
|
+
(user.autoDelegations && user.autoDelegations.anonymousMedicalInformation ? user.autoDelegations.anonymousMedicalInformation : []).forEach((delegateId) => (promise = promise.then((contact) => this.crypto.addDelegationsAndEncryptionKeys(patient, contact, dataOwnerId, delegateId, null, eks.secretId).catch((e) => {
|
|
80
84
|
console.log(e);
|
|
81
85
|
return contact;
|
|
82
86
|
}))));
|
|
@@ -84,8 +88,8 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
84
88
|
});
|
|
85
89
|
}
|
|
86
90
|
initEncryptionKeys(user, ctc) {
|
|
87
|
-
const
|
|
88
|
-
return this.crypto.initEncryptionKeys(ctc,
|
|
91
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
92
|
+
return this.crypto.initEncryptionKeys(ctc, dataOwnerId).then((eks) => {
|
|
89
93
|
let promise = Promise.resolve(_.extend(ctc, {
|
|
90
94
|
encryptionKeys: eks.encryptionKeys,
|
|
91
95
|
}));
|
|
@@ -94,7 +98,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
94
98
|
.concat(user.autoDelegations.medicalInformation || [])
|
|
95
99
|
.concat(user.autoDelegations.anonymousMedicalInformation || [])
|
|
96
100
|
: []).forEach((delegateId) => (promise = promise.then((contact) => this.crypto
|
|
97
|
-
.appendEncryptionKeys(contact,
|
|
101
|
+
.appendEncryptionKeys(contact, dataOwnerId, delegateId, eks.secretId)
|
|
98
102
|
.then((extraEks) => {
|
|
99
103
|
return _.extend(contact, {
|
|
100
104
|
encryptionKeys: extraEks.encryptionKeys,
|
|
@@ -214,25 +218,25 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
214
218
|
.then((paginatedList) => { var _a; return this.decryptServices(user.healthcarePartyId || user.patientId, (_a = paginatedList.rows) !== null && _a !== void 0 ? _a : [], undefined, undefined); });
|
|
215
219
|
}
|
|
216
220
|
findByHCPartyFormIdWithUser(user, hcPartyId, formId) {
|
|
217
|
-
return super.findByHCPartyFormId(hcPartyId, formId).then((ctcs) => this.decrypt((user
|
|
221
|
+
return super.findByHCPartyFormId(hcPartyId, formId).then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs));
|
|
218
222
|
}
|
|
219
223
|
findByHCPartyFormIdsWithUser(user, hcPartyId, body) {
|
|
220
|
-
return super.findByHCPartyFormIds(hcPartyId, body).then((ctcs) => this.decrypt((user
|
|
224
|
+
return super.findByHCPartyFormIds(hcPartyId, body).then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs));
|
|
221
225
|
}
|
|
222
226
|
getContactWithUser(user, contactId) {
|
|
223
227
|
return super
|
|
224
228
|
.getContact(contactId)
|
|
225
|
-
.then((ctc) => this.decrypt((user
|
|
229
|
+
.then((ctc) => this.decrypt(this.userApi.getDataOwnerOf(user), [ctc]))
|
|
226
230
|
.then((ctcs) => ctcs[0]);
|
|
227
231
|
}
|
|
228
232
|
getContactsWithUser(user, body) {
|
|
229
|
-
return super.getContacts(body).then((ctcs) => this.decrypt((user
|
|
233
|
+
return super.getContacts(body).then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs));
|
|
230
234
|
}
|
|
231
235
|
modifyContactWithUser(user, body) {
|
|
232
236
|
return body
|
|
233
237
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
234
238
|
.then((ctcs) => super.modifyContact(ctcs[0]))
|
|
235
|
-
.then((ctc) => this.decrypt((user
|
|
239
|
+
.then((ctc) => this.decrypt(this.userApi.getDataOwnerOf(user), [ctc]))
|
|
236
240
|
.then((ctcs) => ctcs[0])
|
|
237
241
|
: Promise.resolve(null);
|
|
238
242
|
}
|
|
@@ -240,14 +244,14 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
240
244
|
return bodies
|
|
241
245
|
? this.encrypt(user, bodies.map((c) => _.cloneDeep(c)))
|
|
242
246
|
.then((ctcs) => super.modifyContacts(ctcs))
|
|
243
|
-
.then((ctcs) => this.decrypt((user
|
|
247
|
+
.then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs))
|
|
244
248
|
: Promise.resolve(null);
|
|
245
249
|
}
|
|
246
250
|
createContactWithUser(user, body) {
|
|
247
251
|
return body
|
|
248
252
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
249
253
|
.then((ctcs) => super.createContact(ctcs[0]))
|
|
250
|
-
.then((ctc) => this.decrypt((user
|
|
254
|
+
.then((ctc) => this.decrypt(this.userApi.getDataOwnerOf(user), [ctc]))
|
|
251
255
|
.then((ctcs) => ctcs[0])
|
|
252
256
|
: Promise.resolve(null);
|
|
253
257
|
}
|
|
@@ -255,7 +259,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
255
259
|
return bodies
|
|
256
260
|
? this.encrypt(user, bodies.map((c) => _.cloneDeep(c)))
|
|
257
261
|
.then((ctcs) => super.createContacts(ctcs))
|
|
258
|
-
.then((ctcs) => this.decrypt((user
|
|
262
|
+
.then((ctcs) => this.decrypt(this.userApi.getDataOwnerOf(user), ctcs))
|
|
259
263
|
: Promise.resolve(null);
|
|
260
264
|
}
|
|
261
265
|
encryptServices(key, rawKey, services) {
|
|
@@ -289,7 +293,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
289
293
|
})));
|
|
290
294
|
}
|
|
291
295
|
encrypt(user, ctcs) {
|
|
292
|
-
const hcpartyId = (user
|
|
296
|
+
const hcpartyId = this.userApi.getDataOwnerOf(user);
|
|
293
297
|
const bypassEncryption = false; //Used for debug
|
|
294
298
|
return Promise.all(ctcs.map((ctc) => __awaiter(this, void 0, void 0, function* () {
|
|
295
299
|
const initialisedCtc = bypassEncryption //Prevent encryption for test ctc
|
|
@@ -482,7 +486,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
482
486
|
const existing = ctc.services.find((s) => s.id === svc.id);
|
|
483
487
|
const promoted = _.extend(_.extend(existing || {}, svc), {
|
|
484
488
|
author: user.id,
|
|
485
|
-
responsible:
|
|
489
|
+
responsible: this.userApi.getDataOwnerOf(user),
|
|
486
490
|
modified: new Date().getTime(),
|
|
487
491
|
});
|
|
488
492
|
if (!existing) {
|
|
@@ -574,7 +578,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
574
578
|
_type: 'org.taktik.icure.entities.embed.Service',
|
|
575
579
|
created: new Date().getTime(),
|
|
576
580
|
modified: new Date().getTime(),
|
|
577
|
-
responsible:
|
|
581
|
+
responsible: this.userApi.getDataOwnerOf(user),
|
|
578
582
|
author: user.id,
|
|
579
583
|
codes: [],
|
|
580
584
|
tags: [],
|