@icure/api 4.2.33 → 4.2.36
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/IccAuthApi.d.ts +6 -0
- package/icc-api/api/IccAuthApi.js +15 -0
- package/icc-api/api/IccAuthApi.js.map +1 -1
- package/icc-api/api/XHR.js +1 -1
- package/icc-api/api/XHR.js.map +1 -1
- package/icc-api/iccApi.js +5 -1
- package/icc-api/iccApi.js.map +1 -1
- package/icc-api/index.js +5 -1
- package/icc-api/index.js.map +1 -1
- package/icc-api/model/Body.js +1 -1
- package/icc-api/model/Body.js.map +1 -1
- package/icc-api/model/Body1.js +1 -1
- package/icc-api/model/Body1.js.map +1 -1
- package/icc-api/model/Body2.js +1 -1
- package/icc-api/model/Body2.js.map +1 -1
- package/icc-api/model/Body3.js +1 -1
- package/icc-api/model/Body3.js.map +1 -1
- package/icc-api/model/ByteArray.js +1 -1
- package/icc-api/model/ByteArray.js.map +1 -1
- package/icc-api/model/Content.js +1 -1
- package/icc-api/model/Content.js.map +1 -1
- package/icc-api/model/Device.js +1 -1
- package/icc-api/model/Device.js.map +1 -1
- package/icc-api/model/Document.js +1 -1
- package/icc-api/model/Document.js.map +1 -1
- package/icc-api/model/DocumentTemplate.js +1 -1
- package/icc-api/model/DocumentTemplate.js.map +1 -1
- package/icc-api/model/HealthcareParty.js +1 -1
- package/icc-api/model/HealthcareParty.js.map +1 -1
- package/icc-api/model/MimeAttachment.js +1 -1
- package/icc-api/model/MimeAttachment.js.map +1 -1
- package/icc-api/model/Patient.js +1 -1
- package/icc-api/model/Patient.js.map +1 -1
- package/icc-api/model/models.js +5 -1
- package/icc-api/model/models.js.map +1 -1
- package/icc-x-api/crypto/AES.js +1 -1
- package/icc-x-api/crypto/AES.js.map +1 -1
- package/icc-x-api/crypto/utils.js +37 -36
- package/icc-x-api/crypto/utils.js.map +1 -1
- package/icc-x-api/filters/filters.js +7 -3
- package/icc-x-api/filters/filters.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.d.ts +3 -3
- package/icc-x-api/icc-accesslog-x-api.js +15 -15
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-bekmehr-x-api.js +2 -2
- package/icc-x-api/icc-bekmehr-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +3 -3
- package/icc-x-api/icc-calendar-item-x-api.js +17 -17
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +3 -3
- package/icc-x-api/icc-classification-x-api.js +4 -4
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +3 -3
- package/icc-x-api/icc-contact-x-api.js +27 -27
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +4 -2
- package/icc-x-api/icc-crypto-x-api.js +50 -48
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-data-owner-x-api.d.ts +14 -0
- package/icc-x-api/icc-data-owner-x-api.js +44 -0
- package/icc-x-api/icc-data-owner-x-api.js.map +1 -0
- package/icc-x-api/icc-doctemplate-x-api.js +2 -2
- package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +3 -3
- package/icc-x-api/icc-document-x-api.js +8 -8
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +3 -3
- package/icc-x-api/icc-form-x-api.js +8 -8
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-hcparty-x-api.js +4 -4
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +3 -3
- package/icc-x-api/icc-helement-x-api.js +15 -15
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.d.ts +3 -3
- package/icc-x-api/icc-invoice-x-api.js +5 -5
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +6 -3
- package/icc-x-api/icc-maintenance-task-x-api.js +26 -12
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +3 -3
- package/icc-x-api/icc-message-x-api.js +4 -4
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +3 -3
- package/icc-x-api/icc-patient-x-api.js +44 -44
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +3 -3
- package/icc-x-api/icc-receipt-x-api.js +5 -5
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +3 -3
- package/icc-x-api/icc-time-table-x-api.js +5 -5
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/icc-user-x-api.d.ts +0 -2
- package/icc-x-api/icc-user-x-api.js +0 -8
- package/icc-x-api/icc-user-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +3 -1
- package/icc-x-api/index.js +29 -20
- package/icc-x-api/index.js.map +1 -1
- package/icc-x-api/utils/binary-utils.js +5 -5
- package/icc-x-api/utils/binary-utils.js.map +1 -1
- package/icc-x-api/utils/formatting-util.js +3 -3
- package/icc-x-api/utils/formatting-util.js.map +1 -1
- package/icc-x-api/utils/index.js +5 -1
- package/icc-x-api/utils/index.js.map +1 -1
- package/icc-x-api/utils/uuid-encoder.js +2 -0
- package/icc-x-api/utils/uuid-encoder.js.map +1 -1
- package/index.js +5 -1
- package/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,
|
|
21
|
+
constructor(host, headers, crypto, dataOwnerApi, fetchImpl = typeof window !== 'undefined'
|
|
22
22
|
? window.fetch
|
|
23
23
|
: typeof self !== 'undefined'
|
|
24
24
|
? self.fetch
|
|
@@ -27,7 +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.
|
|
30
|
+
this.dataOwnerApi = dataOwnerApi;
|
|
31
31
|
}
|
|
32
32
|
newInstance(user, ci, delegates = []) {
|
|
33
33
|
return this.newInstancePatient(user, null, ci, delegates);
|
|
@@ -38,7 +38,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
38
38
|
_type: 'org.taktik.icure.entities.CalendarItem',
|
|
39
39
|
created: new Date().getTime(),
|
|
40
40
|
modified: new Date().getTime(),
|
|
41
|
-
responsible: this.
|
|
41
|
+
responsible: this.dataOwnerApi.getDataOwnerOf(user),
|
|
42
42
|
author: user.id,
|
|
43
43
|
codes: [],
|
|
44
44
|
tags: [],
|
|
@@ -46,7 +46,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
46
46
|
return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates);
|
|
47
47
|
}
|
|
48
48
|
initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates = []) {
|
|
49
|
-
const dataOwnerId = this.
|
|
49
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
50
50
|
return this.crypto
|
|
51
51
|
.extractDelegationsSFKs(patient, dataOwnerId)
|
|
52
52
|
.then((secretForeignKeys) => Promise.all([
|
|
@@ -84,27 +84,27 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
84
84
|
return body
|
|
85
85
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
86
86
|
.then((items) => super.createCalendarItem(items[0]))
|
|
87
|
-
.then((ci) => this.decrypt(this.
|
|
87
|
+
.then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ci]))
|
|
88
88
|
.then((cis) => cis[0])
|
|
89
89
|
: Promise.resolve(null);
|
|
90
90
|
}
|
|
91
91
|
getCalendarItemWithUser(user, calendarItemId) {
|
|
92
92
|
return super
|
|
93
93
|
.getCalendarItem(calendarItemId)
|
|
94
|
-
.then((calendarItem) => this.decrypt(this.
|
|
94
|
+
.then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [calendarItem]))
|
|
95
95
|
.then((cis) => cis[0]);
|
|
96
96
|
}
|
|
97
97
|
getCalendarItem(calendarItemId) {
|
|
98
98
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
99
99
|
}
|
|
100
100
|
getCalendarItemsWithUser(user) {
|
|
101
|
-
return super.getCalendarItems().then((calendarItems) => this.decrypt(this.
|
|
101
|
+
return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
|
|
102
102
|
}
|
|
103
103
|
getCalendarItems() {
|
|
104
104
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
105
105
|
}
|
|
106
106
|
getCalendarItemsWithIdsWithUser(user, body) {
|
|
107
|
-
return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.
|
|
107
|
+
return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
|
|
108
108
|
}
|
|
109
109
|
getCalendarItemsWithIds(body) {
|
|
110
110
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -112,7 +112,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
112
112
|
getCalendarItemsByPeriodAndHcPartyIdWithUser(user, startDate, endDate, hcPartyId) {
|
|
113
113
|
return super
|
|
114
114
|
.getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)
|
|
115
|
-
.then((calendarItems) => this.decrypt(this.
|
|
115
|
+
.then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
|
|
116
116
|
}
|
|
117
117
|
getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId) {
|
|
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
|
getCalendarsByPeriodAndAgendaIdWithUser(user, startDate, endDate, agendaId) {
|
|
121
121
|
return super
|
|
122
122
|
.getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)
|
|
123
|
-
.then((calendarItems) => this.decrypt(this.
|
|
123
|
+
.then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
|
|
124
124
|
}
|
|
125
125
|
getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId) {
|
|
126
126
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -147,12 +147,12 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
147
147
|
return body
|
|
148
148
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
149
149
|
.then((items) => super.modifyCalendarItem(items[0]))
|
|
150
|
-
.then((ci) => this.decrypt(this.
|
|
150
|
+
.then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ci]))
|
|
151
151
|
.then((cis) => cis[0])
|
|
152
152
|
: Promise.resolve(null);
|
|
153
153
|
}
|
|
154
154
|
initEncryptionKeys(user, calendarItem) {
|
|
155
|
-
const dataOwnerId = this.
|
|
155
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
156
156
|
return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId).then((eks) => {
|
|
157
157
|
let promise = Promise.resolve(_.extend(calendarItem, {
|
|
158
158
|
encryptionKeys: eks.encryptionKeys,
|
|
@@ -169,9 +169,9 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
169
169
|
return Promise.all(calendarItems.map((calendarItem) => (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length
|
|
170
170
|
? Promise.resolve(calendarItem)
|
|
171
171
|
: this.initEncryptionKeys(user, calendarItem))
|
|
172
|
-
.then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.
|
|
173
|
-
.then((eks) => this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(eks.extractedKeys[0].replace(/-/g, ''))))
|
|
174
|
-
.then((key) => utils_1.utils.crypt(calendarItem, (obj) => this.crypto.AES.encrypt(key, binary_utils_1.utf8_2ua(JSON.stringify(obj))), this.cryptedKeys))));
|
|
172
|
+
.then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user), calendarItem.id, calendarItem.encryptionKeys))
|
|
173
|
+
.then((eks) => this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(eks.extractedKeys[0].replace(/-/g, ''))))
|
|
174
|
+
.then((key) => utils_1.utils.crypt(calendarItem, (obj) => this.crypto.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify(obj))), this.cryptedKeys))));
|
|
175
175
|
}
|
|
176
176
|
decrypt(hcpId, calendarItems) {
|
|
177
177
|
//First check that we have no dangling delegation
|
|
@@ -183,9 +183,9 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
183
183
|
if (!sfks || !sfks.length) {
|
|
184
184
|
return Promise.resolve(calendarItem);
|
|
185
185
|
}
|
|
186
|
-
return this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(sfks[0].replace(/-/g, ''))).then((key) => utils_1.utils.decrypt(calendarItem, (ec) => this.crypto.AES.decrypt(key, ec)
|
|
186
|
+
return this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(sfks[0].replace(/-/g, ''))).then((key) => utils_1.utils.decrypt(calendarItem, (ec) => this.crypto.AES.decrypt(key, ec)
|
|
187
187
|
.then((dec) => {
|
|
188
|
-
const jsonContent = dec && binary_utils_1.ua2utf8(dec);
|
|
188
|
+
const jsonContent = dec && (0, binary_utils_1.ua2utf8)(dec);
|
|
189
189
|
try {
|
|
190
190
|
return JSON.parse(jsonContent);
|
|
191
191
|
}
|
|
@@ -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;AAG3B,0CAAsC;AAEtC,wCAA+C;AAC/C,uDAAgE;AAGhE,MAAa,mBAAoB,SAAQ,4BAAkB;IAMzD,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;QAhBjC,SAAI,GAAQ,IAAI,CAAA;QAGhB,gBAAW,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QAc7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,WAAW,CAAC,IAAU,EAAE,EAAgB,EAAE,YAAsB,EAAE;QAChE,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,SA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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
|
+
{"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,SAAQ,4BAAkB;IAMzD,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;QAhBjC,SAAI,GAAQ,IAAI,CAAA;QAGhB,gBAAW,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QAc7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,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,EAAE,wCAAwC;YAC/C,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC7B,QAAQ,EAAE,IAAI,IA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ash'\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 { IccDataOwnerXApi } from './icc-data-owner-x-api'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n cryptedKeys = ['details', 'title', 'patientId']\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: 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\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.dataOwnerApi.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.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 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 : Promise.resolve(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 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,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 {
|
|
4
|
+
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
5
5
|
export declare class IccClassificationXApi extends IccClassificationApi {
|
|
6
6
|
crypto: IccCryptoXApi;
|
|
7
|
-
|
|
7
|
+
dataOwnerApi: IccDataOwnerXApi;
|
|
8
8
|
constructor(host: string, headers: {
|
|
9
9
|
[key: string]: string;
|
|
10
|
-
}, crypto: IccCryptoXApi,
|
|
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,
|
|
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.
|
|
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.
|
|
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.
|
|
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,
|
|
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;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;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 {
|
|
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
|
-
|
|
10
|
+
dataOwnerApi: IccDataOwnerXApi;
|
|
11
11
|
constructor(host: string, headers: {
|
|
12
12
|
[key: string]: string;
|
|
13
|
-
}, crypto: IccCryptoXApi,
|
|
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 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,
|
|
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.
|
|
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.
|
|
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.
|
|
59
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
60
60
|
return this.crypto
|
|
61
61
|
.extractPreferredSfk(patient, dataOwnerId, confidential)
|
|
62
62
|
.then((key) => {
|
|
@@ -88,7 +88,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
initEncryptionKeys(user, ctc) {
|
|
91
|
-
const dataOwnerId = this.
|
|
91
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
92
92
|
return this.crypto.initEncryptionKeys(ctc, dataOwnerId).then((eks) => {
|
|
93
93
|
let promise = Promise.resolve(_.extend(ctc, {
|
|
94
94
|
encryptionKeys: eks.encryptionKeys,
|
|
@@ -218,25 +218,25 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
218
218
|
.then((paginatedList) => { var _a; return this.decryptServices(user.healthcarePartyId || user.patientId, (_a = paginatedList.rows) !== null && _a !== void 0 ? _a : [], undefined, undefined); });
|
|
219
219
|
}
|
|
220
220
|
findByHCPartyFormIdWithUser(user, hcPartyId, formId) {
|
|
221
|
-
return super.findByHCPartyFormId(hcPartyId, formId).then((ctcs) => this.decrypt(this.
|
|
221
|
+
return super.findByHCPartyFormId(hcPartyId, formId).then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs));
|
|
222
222
|
}
|
|
223
223
|
findByHCPartyFormIdsWithUser(user, hcPartyId, body) {
|
|
224
|
-
return super.findByHCPartyFormIds(hcPartyId, body).then((ctcs) => this.decrypt(this.
|
|
224
|
+
return super.findByHCPartyFormIds(hcPartyId, body).then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs));
|
|
225
225
|
}
|
|
226
226
|
getContactWithUser(user, contactId) {
|
|
227
227
|
return super
|
|
228
228
|
.getContact(contactId)
|
|
229
|
-
.then((ctc) => this.decrypt(this.
|
|
229
|
+
.then((ctc) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ctc]))
|
|
230
230
|
.then((ctcs) => ctcs[0]);
|
|
231
231
|
}
|
|
232
232
|
getContactsWithUser(user, body) {
|
|
233
|
-
return super.getContacts(body).then((ctcs) => this.decrypt(this.
|
|
233
|
+
return super.getContacts(body).then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs));
|
|
234
234
|
}
|
|
235
235
|
modifyContactWithUser(user, body) {
|
|
236
236
|
return body
|
|
237
237
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
238
238
|
.then((ctcs) => super.modifyContact(ctcs[0]))
|
|
239
|
-
.then((ctc) => this.decrypt(this.
|
|
239
|
+
.then((ctc) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ctc]))
|
|
240
240
|
.then((ctcs) => ctcs[0])
|
|
241
241
|
: Promise.resolve(null);
|
|
242
242
|
}
|
|
@@ -244,14 +244,14 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
244
244
|
return bodies
|
|
245
245
|
? this.encrypt(user, bodies.map((c) => _.cloneDeep(c)))
|
|
246
246
|
.then((ctcs) => super.modifyContacts(ctcs))
|
|
247
|
-
.then((ctcs) => this.decrypt(this.
|
|
247
|
+
.then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs))
|
|
248
248
|
: Promise.resolve(null);
|
|
249
249
|
}
|
|
250
250
|
createContactWithUser(user, body) {
|
|
251
251
|
return body
|
|
252
252
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
253
253
|
.then((ctcs) => super.createContact(ctcs[0]))
|
|
254
|
-
.then((ctc) => this.decrypt(this.
|
|
254
|
+
.then((ctc) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ctc]))
|
|
255
255
|
.then((ctcs) => ctcs[0])
|
|
256
256
|
: Promise.resolve(null);
|
|
257
257
|
}
|
|
@@ -259,7 +259,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
259
259
|
return bodies
|
|
260
260
|
? this.encrypt(user, bodies.map((c) => _.cloneDeep(c)))
|
|
261
261
|
.then((ctcs) => super.createContacts(ctcs))
|
|
262
|
-
.then((ctcs) => this.decrypt(this.
|
|
262
|
+
.then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), ctcs))
|
|
263
263
|
: Promise.resolve(null);
|
|
264
264
|
}
|
|
265
265
|
encryptServices(key, rawKey, services) {
|
|
@@ -286,14 +286,14 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
286
286
|
}))));
|
|
287
287
|
}
|
|
288
288
|
else {
|
|
289
|
-
svc.encryptedSelf = binary_utils_1.b2a(binary_utils_1.ua2string(yield this.crypto.AES.encrypt(key, binary_utils_1.utf8_2ua(JSON.stringify({ content: svc.content })), rawKey)));
|
|
289
|
+
svc.encryptedSelf = (0, binary_utils_1.b2a)((0, binary_utils_1.ua2string)(yield this.crypto.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify({ content: svc.content })), rawKey)));
|
|
290
290
|
delete svc.content;
|
|
291
291
|
}
|
|
292
292
|
return svc;
|
|
293
293
|
})));
|
|
294
294
|
}
|
|
295
295
|
encrypt(user, ctcs) {
|
|
296
|
-
const hcpartyId = this.
|
|
296
|
+
const hcpartyId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
297
297
|
const bypassEncryption = false; //Used for debug
|
|
298
298
|
return Promise.all(ctcs.map((ctc) => __awaiter(this, void 0, void 0, function* () {
|
|
299
299
|
const initialisedCtc = bypassEncryption //Prevent encryption for test ctc
|
|
@@ -301,9 +301,9 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
301
301
|
: yield (ctc.encryptionKeys && Object.keys(ctc.encryptionKeys || {}).length ? Promise.resolve(ctc) : this.initEncryptionKeys(user, ctc));
|
|
302
302
|
const sfks = yield this.crypto.extractKeysFromDelegationsForHcpHierarchy(hcpartyId, initialisedCtc.id, initialisedCtc.encryptionKeys);
|
|
303
303
|
const rawKey = sfks.extractedKeys[0].replace(/-/g, '');
|
|
304
|
-
const key = yield this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(rawKey));
|
|
304
|
+
const key = yield this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(rawKey));
|
|
305
305
|
initialisedCtc.services = yield this.encryptServices(key, rawKey, ctc.services || []);
|
|
306
|
-
initialisedCtc.encryptedSelf = binary_utils_1.b2a(binary_utils_1.ua2string(yield this.crypto.AES.encrypt(key, binary_utils_1.utf8_2ua(JSON.stringify({ descr: ctc.descr })), rawKey)));
|
|
306
|
+
initialisedCtc.encryptedSelf = (0, binary_utils_1.b2a)((0, binary_utils_1.ua2string)(yield this.crypto.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify({ descr: ctc.descr })), rawKey)));
|
|
307
307
|
delete initialisedCtc.descr;
|
|
308
308
|
return initialisedCtc;
|
|
309
309
|
})));
|
|
@@ -316,14 +316,14 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
316
316
|
return ctc;
|
|
317
317
|
}
|
|
318
318
|
const rawKey = sfks[0].replace(/-/g, '');
|
|
319
|
-
const key = yield this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(rawKey));
|
|
319
|
+
const key = yield this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(rawKey));
|
|
320
320
|
ctc.services = yield this.decryptServices(hcpartyId, ctc.services || [], key, rawKey);
|
|
321
321
|
if (ctc.encryptedSelf) {
|
|
322
322
|
try {
|
|
323
|
-
const dec = yield this.crypto.AES.decrypt(key, binary_utils_1.string2ua(binary_utils_1.a2b(ctc.encryptedSelf)), rawKey);
|
|
323
|
+
const dec = yield this.crypto.AES.decrypt(key, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(ctc.encryptedSelf)), rawKey);
|
|
324
324
|
let jsonContent;
|
|
325
325
|
try {
|
|
326
|
-
jsonContent = dec && binary_utils_1.ua2utf8(dec);
|
|
326
|
+
jsonContent = dec && (0, binary_utils_1.ua2utf8)(dec);
|
|
327
327
|
jsonContent && _.assign(ctc, JSON.parse(jsonContent));
|
|
328
328
|
}
|
|
329
329
|
catch (e) {
|
|
@@ -341,14 +341,14 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
341
341
|
return Promise.all(svcs.map((svc) => __awaiter(this, void 0, void 0, function* () {
|
|
342
342
|
if (!key) {
|
|
343
343
|
const { extractedKeys: sfks } = yield this.crypto.extractKeysFromDelegationsForHcpHierarchy(hcpartyId, svc.id, _.size(svc.encryptionKeys) ? svc.encryptionKeys : svc.delegations);
|
|
344
|
-
key = yield this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(sfks[0].replace(/-/g, '')));
|
|
344
|
+
key = yield this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(sfks[0].replace(/-/g, '')));
|
|
345
345
|
}
|
|
346
346
|
if (svc.encryptedContent) {
|
|
347
347
|
try {
|
|
348
|
-
const dec = yield this.crypto.AES.decrypt(key, binary_utils_1.string2ua(binary_utils_1.a2b(svc.encryptedContent)));
|
|
348
|
+
const dec = yield this.crypto.AES.decrypt(key, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(svc.encryptedContent)));
|
|
349
349
|
let jsonContent;
|
|
350
350
|
try {
|
|
351
|
-
jsonContent = binary_utils_1.ua2utf8(utils_1.utils.truncateTrailingNulls(new Uint8Array(dec)));
|
|
351
|
+
jsonContent = (0, binary_utils_1.ua2utf8)(utils_1.utils.truncateTrailingNulls(new Uint8Array(dec)));
|
|
352
352
|
Object.assign(svc, { content: JSON.parse(jsonContent) });
|
|
353
353
|
}
|
|
354
354
|
catch (e) {
|
|
@@ -361,10 +361,10 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
361
361
|
}
|
|
362
362
|
else if (svc.encryptedSelf) {
|
|
363
363
|
try {
|
|
364
|
-
const dec = yield this.crypto.AES.decrypt(key, binary_utils_1.string2ua(binary_utils_1.a2b(svc.encryptedSelf)));
|
|
364
|
+
const dec = yield this.crypto.AES.decrypt(key, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(svc.encryptedSelf)));
|
|
365
365
|
let jsonContent;
|
|
366
366
|
try {
|
|
367
|
-
jsonContent = binary_utils_1.ua2utf8(utils_1.utils.truncateTrailingNulls(new Uint8Array(dec)));
|
|
367
|
+
jsonContent = (0, binary_utils_1.ua2utf8)(utils_1.utils.truncateTrailingNulls(new Uint8Array(dec)));
|
|
368
368
|
Object.assign(svc, JSON.parse(jsonContent));
|
|
369
369
|
}
|
|
370
370
|
catch (e) {
|
|
@@ -486,7 +486,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
486
486
|
const existing = ctc.services.find((s) => s.id === svc.id);
|
|
487
487
|
const promoted = _.extend(_.extend(existing || {}, svc), {
|
|
488
488
|
author: user.id,
|
|
489
|
-
responsible: this.
|
|
489
|
+
responsible: this.dataOwnerApi.getDataOwnerOf(user),
|
|
490
490
|
modified: new Date().getTime(),
|
|
491
491
|
});
|
|
492
492
|
if (!existing) {
|
|
@@ -578,7 +578,7 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
578
578
|
_type: 'org.taktik.icure.entities.embed.Service',
|
|
579
579
|
created: new Date().getTime(),
|
|
580
580
|
modified: new Date().getTime(),
|
|
581
|
-
responsible: this.
|
|
581
|
+
responsible: this.dataOwnerApi.getDataOwnerOf(user),
|
|
582
582
|
author: user.id,
|
|
583
583
|
codes: [],
|
|
584
584
|
tags: [],
|