@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
|
@@ -7,19 +7,19 @@ const ModelHelper_1 = require("../icc-api/model/ModelHelper");
|
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const utils_2 = require("./crypto/utils");
|
|
9
9
|
class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskApi {
|
|
10
|
-
constructor(host, headers, crypto,
|
|
10
|
+
constructor(host, headers, crypto, hcPartyApi, dataOwnerApi, encryptedKeys = [], fetchImpl = typeof window !== 'undefined'
|
|
11
11
|
? window.fetch
|
|
12
12
|
: typeof self !== 'undefined'
|
|
13
13
|
? self.fetch
|
|
14
14
|
: fetch) {
|
|
15
15
|
super(host, headers, fetchImpl);
|
|
16
16
|
this.crypto = crypto;
|
|
17
|
-
this.userApi = userApi;
|
|
18
17
|
this.hcPartyApi = hcPartyApi;
|
|
18
|
+
this.dataOwnerApi = dataOwnerApi;
|
|
19
19
|
this.encryptedKeys = encryptedKeys;
|
|
20
20
|
}
|
|
21
21
|
newInstance(user, m, delegates = []) {
|
|
22
|
-
const dataOwnerId = this.
|
|
22
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
23
23
|
const maintenanceTask = _.assign({
|
|
24
24
|
id: this.crypto.randomUuid(),
|
|
25
25
|
_type: 'org.taktik.icure.entities.MaintenanceTask',
|
|
@@ -31,7 +31,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
|
|
|
31
31
|
return this.initDelegations(user, maintenanceTask, delegates).then((task) => this.initEncryptionKeys(user, task, delegates));
|
|
32
32
|
}
|
|
33
33
|
initDelegations(user, maintenanceTask, delegates = []) {
|
|
34
|
-
const dataOwnerId = this.
|
|
34
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
35
35
|
return this.crypto.initObjectDelegations(maintenanceTask, null, dataOwnerId, null).then((initData) => {
|
|
36
36
|
_.extend(maintenanceTask, { delegations: initData.delegations });
|
|
37
37
|
let promise = Promise.resolve(maintenanceTask);
|
|
@@ -46,7 +46,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
initEncryptionKeys(user, maintenanceTask, delegates = []) {
|
|
49
|
-
const dataOwnerId = this.
|
|
49
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
50
50
|
return this.crypto.initEncryptionKeys(maintenanceTask, dataOwnerId).then((eks) => {
|
|
51
51
|
let promise = Promise.resolve(_.extend(maintenanceTask, {
|
|
52
52
|
encryptionKeys: eks.encryptionKeys,
|
|
@@ -79,6 +79,20 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
|
|
|
79
79
|
filterMaintenanceTasksBy(startDocumentId, limit, body) {
|
|
80
80
|
throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
|
|
81
81
|
}
|
|
82
|
+
deleteMaintenanceTask(_maintenanceTaskIds) {
|
|
83
|
+
throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
|
|
84
|
+
}
|
|
85
|
+
deleteMaintenanceTaskWithUser(user, maintenanceTaskId) {
|
|
86
|
+
return super.getMaintenanceTask(maintenanceTaskId).then((mt) => {
|
|
87
|
+
var _a;
|
|
88
|
+
return this.dataOwnerApi.hasAccessTo(user, (_a = mt.delegations) !== null && _a !== void 0 ? _a : {}).then((hasAccess) => {
|
|
89
|
+
if (hasAccess)
|
|
90
|
+
return super.deleteMaintenanceTask(maintenanceTaskId);
|
|
91
|
+
else
|
|
92
|
+
throw new Error('User does not have a delegation for this maintenanceTask');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
82
96
|
filterMaintenanceTasksByWithUser(user, startDocumentId, limit, body) {
|
|
83
97
|
return super
|
|
84
98
|
.filterMaintenanceTasksBy(startDocumentId, limit, body)
|
|
@@ -105,20 +119,20 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
|
|
|
105
119
|
: Promise.resolve(null);
|
|
106
120
|
}
|
|
107
121
|
encrypt(user, maintenanceTasks) {
|
|
108
|
-
const dataOwnerId = this.
|
|
122
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
109
123
|
return Promise.all(maintenanceTasks.map((m) => (m.encryptionKeys && Object.keys(m.encryptionKeys).some((k) => !!m.encryptionKeys[k].length)
|
|
110
124
|
? Promise.resolve(m)
|
|
111
125
|
: this.initEncryptionKeys(user, m))
|
|
112
126
|
.then((m) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, m.id, m.encryptionKeys))
|
|
113
|
-
.then((sfks) => this.crypto.AES.importKey('raw', utils_1.hex2ua(sfks.extractedKeys[0].replace(/-/g, ''))))
|
|
114
|
-
.then((key) => utils_2.utils.crypt(m, (obj) => this.crypto.AES.encrypt(key, utils_1.utf8_2ua(JSON.stringify(obj, (k, v) => {
|
|
127
|
+
.then((sfks) => this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks.extractedKeys[0].replace(/-/g, ''))))
|
|
128
|
+
.then((key) => utils_2.utils.crypt(m, (obj) => this.crypto.AES.encrypt(key, (0, utils_1.utf8_2ua)(JSON.stringify(obj, (k, v) => {
|
|
115
129
|
return v instanceof ArrayBuffer || v instanceof Uint8Array
|
|
116
|
-
? ModelHelper_1.b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
|
|
130
|
+
? (0, ModelHelper_1.b2a)(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
|
|
117
131
|
: v;
|
|
118
132
|
}))), this.encryptedKeys))));
|
|
119
133
|
}
|
|
120
134
|
decrypt(user, maintenanceTasks) {
|
|
121
|
-
const dataOwnerId = this.
|
|
135
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
122
136
|
return Promise.all(maintenanceTasks.map((mT) => {
|
|
123
137
|
var _a;
|
|
124
138
|
return this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id, (_a = mT.encryptionKeys) !== null && _a !== void 0 ? _a : {}).then(({ extractedKeys: sfks }) => {
|
|
@@ -127,10 +141,10 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
|
|
|
127
141
|
return Promise.resolve(mT);
|
|
128
142
|
}
|
|
129
143
|
if (mT.encryptedSelf) {
|
|
130
|
-
return this.crypto.AES.importKey('raw', utils_1.hex2ua(sfks[0].replace(/-/g, ''))).then((key) => new Promise((resolve) => this.crypto.AES.decrypt(key, ModelHelper_1.string2ua(ModelHelper_1.a2b(mT.encryptedSelf))).then((dec) => {
|
|
144
|
+
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks[0].replace(/-/g, ''))).then((key) => new Promise((resolve) => this.crypto.AES.decrypt(key, (0, ModelHelper_1.string2ua)((0, ModelHelper_1.a2b)(mT.encryptedSelf))).then((dec) => {
|
|
131
145
|
let jsonContent;
|
|
132
146
|
try {
|
|
133
|
-
jsonContent = dec && utils_1.ua2utf8(dec);
|
|
147
|
+
jsonContent = dec && (0, utils_1.ua2utf8)(dec);
|
|
134
148
|
jsonContent && _.assign(mT, JSON.parse(jsonContent));
|
|
135
149
|
}
|
|
136
150
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;AAAA,gFAA4E;AAI5E,4BAA2B;AAC3B,8DAAkE;AAClE,mCAAmD;AACnD,0CAAsC;AAGtC,MAAa,sBAAuB,SAAQ,6CAAqB;IAO/D,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,OAAoB,EACpB,UAA0B,EAC1B,gBAA+B,EAAE,EACjC,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;QAC/B,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AAE,CAAC,CAAA;iBAC3B;YACH,CAAC,CAAC,CAAA;SAAA,CACH,CACF,CAAA;IACH,CAAC;CACF;AAzND,wDAyNC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccUserXApi } from './icc-user-x-api'\nimport * as models from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { a2b, b2a, string2ua } from '../icc-api/model/ModelHelper'\nimport { hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { utils } from './crypto/utils'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi {\n crypto: IccCryptoXApi\n userApi: IccUserXApi\n hcPartyApi: IccHcpartyXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n userApi: IccUserXApi,\n hcPartyApi: IccHcpartyXApi,\n encryptedKeys: Array<string> = [],\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, fetchImpl)\n this.crypto = crypto\n this.userApi = userApi\n this.hcPartyApi = hcPartyApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: models.User, m: any, delegates: string[] = []) {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n const maintenanceTask = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n },\n m || {}\n )\n\n return this.initDelegations(user, maintenanceTask, delegates).then((task) => this.initEncryptionKeys(user, task, delegates))\n }\n\n initDelegations(user: models.User, maintenanceTask: models.MaintenanceTask, delegates: string[] = []): Promise<models.MaintenanceTask> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n return this.crypto.initObjectDelegations(maintenanceTask, null, dataOwnerId!, null).then((initData) => {\n _.extend(maintenanceTask, { delegations: initData.delegations })\n\n let promise = Promise.resolve(maintenanceTask)\n _.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach(\n (delegateId) =>\n (promise = promise\n .then((patient) => this.crypto.extendedDelegationsAndCryptedForeignKeys(patient, null, dataOwnerId!, delegateId, initData.secretId))\n .then((extraData) => _.extend(maintenanceTask, { delegations: extraData.delegations }))\n .catch((e) => {\n console.log(e)\n return maintenanceTask\n }))\n )\n return promise\n })\n }\n\n initEncryptionKeys(user: models.User, maintenanceTask: models.MaintenanceTask, delegates: string[] = []): Promise<models.MaintenanceTask> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(maintenanceTask, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(maintenanceTask, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n _.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach(\n (delegateId) =>\n (promise = promise.then((patient) =>\n this.crypto\n .appendEncryptionKeys(patient, dataOwnerId!, delegateId, eks.secretId)\n .then((extraEks) => {\n return _.extend(patient, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n .catch((e) => {\n console.log(e.message)\n return patient\n })\n ))\n )\n return promise\n })\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask | any> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n : Promise.resolve(null)\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n\n return Promise.all(\n maintenanceTasks.map((m) =>\n (m.encryptionKeys && Object.keys(m.encryptionKeys).some((k) => !!m.encryptionKeys![k].length)\n ? Promise.resolve(m)\n : this.initEncryptionKeys(user, m)\n )\n .then((m: models.MaintenanceTask) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId!, m.id!, m.encryptionKeys!))\n .then((sfks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(sfks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n utils.crypt(\n m,\n (obj: { [key: string]: string }) =>\n this.crypto.AES.encrypt(\n key,\n utf8_2ua(\n JSON.stringify(obj, (k, v) => {\n return v instanceof ArrayBuffer || v instanceof Uint8Array\n ? b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))\n : v\n })\n )\n ),\n this.encryptedKeys\n )\n )\n )\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n\n return Promise.all(\n maintenanceTasks.map((mT) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id!, mT.encryptionKeys ?? {}).then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n console.log('Cannot decrypt maintenanceTask', mT.id)\n return Promise.resolve(mT)\n }\n if (mT.encryptedSelf) {\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then(\n (key) =>\n new Promise((resolve: (value: any) => any) =>\n this.crypto.AES.decrypt(key, string2ua(a2b(mT.encryptedSelf!))).then(\n (dec) => {\n let jsonContent\n try {\n jsonContent = dec && ua2utf8(dec)\n jsonContent && _.assign(mT, JSON.parse(jsonContent))\n } catch (e) {\n console.log('Cannot parse mTask', mT.id, jsonContent || '<- Invalid encoding')\n }\n resolve(mT)\n },\n () => {\n console.log('Cannot decrypt mTask', mT.id)\n resolve(mT)\n }\n )\n )\n )\n } else {\n return Promise.resolve(mT)\n }\n })\n )\n )\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;AAAA,gFAA4E;AAG5E,4BAA2B;AAC3B,8DAAkE;AAClE,mCAAmD;AACnD,0CAAsC;AAKtC,MAAa,sBAAuB,SAAQ,6CAAqB;IAO/D,YACE,IAAY,EACZ,OAAkC,EAClC,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EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAC7E,CAAC,GAAG,EAAE,EAAE,CACN,IAAI,OAAO,CAAC,CAAC,OAA4B,EAAE,EAAE,CAC3C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,IAAA,uBAAS,EAAC,IAAA,iBAAG,EAAC,EAAE,CAAC,aAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAClE,CAAC,GAAG,EAAE,EAAE;wBACN,IAAI,WAAW,CAAA;wBACf,IAAI;4BACF,WAAW,GAAG,GAAG,IAAI,IAAA,eAAO,EAAC,GAAG,CAAC,CAAA;4BACjC,WAAW,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;yBACrD;wBAAC,OAAO,CAAC,EAAE;4BACV,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,IAAI,qBAAqB,CAAC,CAAA;yBAC/E;wBACD,OAAO,CAAC,EAAE,CAAC,CAAA;oBACb,CAAC,EACD,GAAG,EAAE;wBACH,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;wBAC1C,OAAO,CAAC,EAAE,CAAC,CAAA;oBACb,CAAC,CACF,CACF,CACJ,CAAA;iBACF;qBAAM;oBACL,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;iBAC3B;YACH,CAAC,CAAC,CAAA;SAAA,CACH,CACF,CAAA;IACH,CAAC;CACF;AAtOD,wDAsOC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { a2b, b2a, string2ua } from '../icc-api/model/ModelHelper'\nimport { hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { utils } from './crypto/utils'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { DocIdentifier } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi {\n crypto: IccCryptoXApi\n hcPartyApi: IccHcpartyXApi\n dataOwnerApi: IccDataOwnerXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n hcPartyApi: IccHcpartyXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = [],\n 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.hcPartyApi = hcPartyApi\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: models.User, m: any, delegates: string[] = []) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n const maintenanceTask = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n },\n m || {}\n )\n\n return this.initDelegations(user, maintenanceTask, delegates).then((task) => this.initEncryptionKeys(user, task, delegates))\n }\n\n initDelegations(user: models.User, maintenanceTask: models.MaintenanceTask, delegates: string[] = []): Promise<models.MaintenanceTask> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initObjectDelegations(maintenanceTask, null, dataOwnerId!, null).then((initData) => {\n _.extend(maintenanceTask, { delegations: initData.delegations })\n\n let promise = Promise.resolve(maintenanceTask)\n _.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach(\n (delegateId) =>\n (promise = promise\n .then((patient) => this.crypto.extendedDelegationsAndCryptedForeignKeys(patient, null, dataOwnerId!, delegateId, initData.secretId))\n .then((extraData) => _.extend(maintenanceTask, { delegations: extraData.delegations }))\n .catch((e) => {\n console.log(e)\n return maintenanceTask\n }))\n )\n return promise\n })\n }\n\n initEncryptionKeys(user: models.User, maintenanceTask: models.MaintenanceTask, delegates: string[] = []): Promise<models.MaintenanceTask> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(maintenanceTask, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(maintenanceTask, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n _.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach(\n (delegateId) =>\n (promise = promise.then((patient) =>\n this.crypto\n .appendEncryptionKeys(patient, dataOwnerId!, delegateId, eks.secretId)\n .then((extraEks) => {\n return _.extend(patient, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n .catch((e) => {\n console.log(e.message)\n return patient\n })\n ))\n )\n return promise\n })\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskIds: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<Array<DocIdentifier>> | never {\n return super.getMaintenanceTask(maintenanceTaskId).then((mt) => {\n return this.dataOwnerApi.hasAccessTo(user, mt.delegations ?? {}).then((hasAccess) => {\n if (hasAccess) return super.deleteMaintenanceTask(maintenanceTaskId)\n else throw new Error('User does not have a delegation for this maintenanceTask')\n })\n })\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask | any> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n : Promise.resolve(null)\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return Promise.all(\n maintenanceTasks.map((m) =>\n (m.encryptionKeys && Object.keys(m.encryptionKeys).some((k) => !!m.encryptionKeys![k].length)\n ? Promise.resolve(m)\n : this.initEncryptionKeys(user, m)\n )\n .then((m: models.MaintenanceTask) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId!, m.id!, m.encryptionKeys!))\n .then((sfks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(sfks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n utils.crypt(\n m,\n (obj: { [key: string]: string }) =>\n this.crypto.AES.encrypt(\n key,\n utf8_2ua(\n JSON.stringify(obj, (k, v) => {\n return v instanceof ArrayBuffer || v instanceof Uint8Array\n ? b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))\n : v\n })\n )\n ),\n this.encryptedKeys\n )\n )\n )\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return Promise.all(\n maintenanceTasks.map((mT) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id!, mT.encryptionKeys ?? {}).then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n console.log('Cannot decrypt maintenanceTask', mT.id)\n return Promise.resolve(mT)\n }\n if (mT.encryptedSelf) {\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then(\n (key) =>\n new Promise((resolve: (value: any) => any) =>\n this.crypto.AES.decrypt(key, string2ua(a2b(mT.encryptedSelf!))).then(\n (dec) => {\n let jsonContent\n try {\n jsonContent = dec && ua2utf8(dec)\n jsonContent && _.assign(mT, JSON.parse(jsonContent))\n } catch (e) {\n console.log('Cannot parse mTask', mT.id, jsonContent || '<- Invalid encoding')\n }\n resolve(mT)\n },\n () => {\n console.log('Cannot decrypt mTask', mT.id)\n resolve(mT)\n }\n )\n )\n )\n } else {\n return Promise.resolve(mT)\n }\n })\n )\n )\n }\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IccMessageApi } from '../icc-api';
|
|
2
2
|
import { IccCryptoXApi } from './icc-crypto-x-api';
|
|
3
3
|
import { Patient, User } from '../icc-api/model/models';
|
|
4
|
-
import {
|
|
4
|
+
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
5
5
|
export declare class IccMessageXApi extends IccMessageApi {
|
|
6
6
|
private crypto;
|
|
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: User, m: any): Promise<any>;
|
|
12
12
|
newInstanceWithPatient(user: User, patient: Patient | null, m?: any, delegates?: string[]): Promise<any>;
|
|
13
13
|
}
|
|
@@ -4,7 +4,7 @@ exports.IccMessageXApi = void 0;
|
|
|
4
4
|
const icc_api_1 = require("../icc-api");
|
|
5
5
|
const _ = require("lodash");
|
|
6
6
|
class IccMessageXApi extends icc_api_1.IccMessageApi {
|
|
7
|
-
constructor(host, headers, crypto,
|
|
7
|
+
constructor(host, headers, crypto, dataOwnerApi, fetchImpl = typeof window !== 'undefined'
|
|
8
8
|
? window.fetch
|
|
9
9
|
: typeof self !== 'undefined'
|
|
10
10
|
? self.fetch
|
|
@@ -12,7 +12,7 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
|
|
|
12
12
|
super(host, headers, fetchImpl);
|
|
13
13
|
this.crypto = crypto;
|
|
14
14
|
this.crypto = crypto;
|
|
15
|
-
this.
|
|
15
|
+
this.dataOwnerApi = dataOwnerApi;
|
|
16
16
|
}
|
|
17
17
|
// noinspection JSUnusedGlobalSymbols
|
|
18
18
|
newInstance(user, m) {
|
|
@@ -24,12 +24,12 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
|
|
|
24
24
|
_type: 'org.taktik.icure.entities.Message',
|
|
25
25
|
created: new Date().getTime(),
|
|
26
26
|
modified: new Date().getTime(),
|
|
27
|
-
responsible: this.
|
|
27
|
+
responsible: this.dataOwnerApi.getDataOwnerOf(user),
|
|
28
28
|
author: user.id,
|
|
29
29
|
codes: [],
|
|
30
30
|
tags: [],
|
|
31
31
|
}, m || {});
|
|
32
|
-
const dataOwnerId = this.
|
|
32
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
33
33
|
return this.crypto
|
|
34
34
|
.extractDelegationsSFKs(patient, dataOwnerId)
|
|
35
35
|
.then((secretForeignKeys) => this.crypto.initObjectDelegations(message, patient, dataOwnerId, secretForeignKeys.extractedKeys[0]))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-message-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-message-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAA0C;AAG1C,4BAA2B;AAK3B,MAAa,cAAe,SAAQ,uBAAa;IAG/C,YACE,IAAY,EACZ,OAAkC,EAC1B,MAAqB,EAC7B,
|
|
1
|
+
{"version":3,"file":"icc-message-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-message-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAA0C;AAG1C,4BAA2B;AAK3B,MAAa,cAAe,SAAQ,uBAAa;IAG/C,YACE,IAAY,EACZ,OAAkC,EAC1B,MAAqB,EAC7B,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;QARvB,WAAM,GAAN,MAAM,CAAe;QAS7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,qCAAqC;IACrC,WAAW,CAAC,IAAU,EAAE,CAAM;QAC5B,OAAO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AAI,CACJ,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CACrI,CAAC,OAAO,CACP,CAAC,UAAU,EAAE,EAAE,CACb,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CACnC,IAAI,CAAC,MAAM;iBACR,wCAAwC,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAY,EAAE,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC;iBACxG,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAClB,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;gBACjB,WAAW,EAAE,SAAS,CAAC,WAAW;gBAClC,kBAAkB,EAAE,SAAS,CAAC,kBAAkB;aACjD,CAAC,CACH;iBACA,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBACd,OAAO,QAAQ,CAAA;YACjB,CAAC,CAAC,CACL,CAAC,CACL,CAAA;YACD,OAAO,OAAO,CAAA;QAChB,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AA1ED,wCA0EC","sourcesContent":["import { IccMessageApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\n\nimport { Patient, User } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\n\nexport class IccMessageXApi extends IccMessageApi {\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private 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 // noinspection JSUnusedGlobalSymbols\n newInstance(user: User, m: any) {\n return this.newInstanceWithPatient(user, null, m)\n }\n\n newInstanceWithPatient(user: User, patient: Patient | null, m: any = {}, delegates: string[] = []) {\n const message = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Message',\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 m || {}\n )\n\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId)\n .then((secretForeignKeys) => this.crypto.initObjectDelegations(message, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]))\n .then((initData) => {\n _.extend(message, {\n delegations: initData.delegations,\n cryptedForeignKeys: initData.cryptedForeignKeys,\n secretForeignKeys: initData.secretForeignKeys,\n })\n\n let promise = Promise.resolve(message)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((helement) =>\n this.crypto\n .extendedDelegationsAndCryptedForeignKeys(helement, patient, dataOwnerId!, delegateId, initData.secretId)\n .then((extraData) =>\n _.extend(helement, {\n delegations: extraData.delegations,\n cryptedForeignKeys: extraData.cryptedForeignKeys,\n })\n )\n .catch((e) => {\n console.log(e)\n return helement\n })\n ))\n )\n return promise\n })\n }\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import { IccHelementXApi } from './icc-helement-x-api';
|
|
|
9
9
|
import { IccClassificationXApi } from './icc-classification-x-api';
|
|
10
10
|
import * as models from '../icc-api/model/models';
|
|
11
11
|
import { IccCalendarItemXApi } from './icc-calendar-item-x-api';
|
|
12
|
-
import {
|
|
12
|
+
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
13
13
|
export declare class IccPatientXApi extends IccPatientApi {
|
|
14
14
|
crypto: IccCryptoXApi;
|
|
15
15
|
contactApi: IccContactXApi;
|
|
@@ -20,11 +20,11 @@ export declare class IccPatientXApi extends IccPatientApi {
|
|
|
20
20
|
documentApi: IccDocumentXApi;
|
|
21
21
|
classificationApi: IccClassificationXApi;
|
|
22
22
|
calendarItemApi: IccCalendarItemXApi;
|
|
23
|
-
|
|
23
|
+
dataOwnerApi: IccDataOwnerXApi;
|
|
24
24
|
private readonly encryptedKeys;
|
|
25
25
|
constructor(host: string, headers: {
|
|
26
26
|
[key: string]: string;
|
|
27
|
-
}, crypto: IccCryptoXApi, contactApi: IccContactXApi, formApi: IccFormXApi, helementApi: IccHelementXApi, invoiceApi: IccInvoiceXApi, documentApi: IccDocumentXApi, hcpartyApi: IccHcpartyXApi, classificationApi: IccClassificationXApi,
|
|
27
|
+
}, crypto: IccCryptoXApi, contactApi: IccContactXApi, formApi: IccFormXApi, helementApi: IccHelementXApi, invoiceApi: IccInvoiceXApi, documentApi: IccDocumentXApi, hcpartyApi: IccHcpartyXApi, classificationApi: IccClassificationXApi, dataOwnerApi: IccDataOwnerXApi, calendarItemaApi: IccCalendarItemXApi, encryptedKeys?: Array<string>, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
28
28
|
newInstance(user: models.User, p?: any, delegates?: string[]): Promise<models.Patient>;
|
|
29
29
|
completeNames(patient: models.Patient): models.Patient;
|
|
30
30
|
initDelegations(patient: models.Patient, user: models.User, secretForeignKey?: string | undefined, delegates?: string[]): Promise<models.Patient>;
|
|
@@ -21,7 +21,7 @@ const person_util_1 = require("./utils/person-util");
|
|
|
21
21
|
const net_utils_1 = require("./utils/net-utils");
|
|
22
22
|
// noinspection JSUnusedGlobalSymbols
|
|
23
23
|
class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
24
|
-
constructor(host, headers, crypto, contactApi, formApi, helementApi, invoiceApi, documentApi, hcpartyApi, classificationApi,
|
|
24
|
+
constructor(host, headers, crypto, contactApi, formApi, helementApi, invoiceApi, documentApi, hcpartyApi, classificationApi, dataOwnerApi, calendarItemaApi, encryptedKeys = ['note'], fetchImpl = typeof window !== 'undefined'
|
|
25
25
|
? window.fetch
|
|
26
26
|
: typeof self !== 'undefined'
|
|
27
27
|
? self.fetch
|
|
@@ -36,7 +36,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
36
36
|
this.documentApi = documentApi;
|
|
37
37
|
this.classificationApi = classificationApi;
|
|
38
38
|
this.calendarItemApi = calendarItemaApi;
|
|
39
|
-
this.
|
|
39
|
+
this.dataOwnerApi = dataOwnerApi;
|
|
40
40
|
this.encryptedKeys = encryptedKeys;
|
|
41
41
|
}
|
|
42
42
|
// noinspection JSUnusedGlobalSymbols
|
|
@@ -46,7 +46,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
46
46
|
_type: 'org.taktik.icure.entities.Patient',
|
|
47
47
|
created: new Date().getTime(),
|
|
48
48
|
modified: new Date().getTime(),
|
|
49
|
-
responsible: this.
|
|
49
|
+
responsible: this.dataOwnerApi.getDataOwnerOf(user),
|
|
50
50
|
author: user.id,
|
|
51
51
|
codes: [],
|
|
52
52
|
tags: [],
|
|
@@ -56,29 +56,29 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
56
56
|
completeNames(patient) {
|
|
57
57
|
var _a;
|
|
58
58
|
let finalPatient = patient;
|
|
59
|
-
if (!!finalPatient.lastName && !person_util_1.hasName(finalPatient, models.PersonName.UseEnum.Official)) {
|
|
60
|
-
finalPatient = person_util_1.garnishPersonWithName(finalPatient, models.PersonName.UseEnum.Official, finalPatient.lastName, finalPatient.firstName);
|
|
59
|
+
if (!!finalPatient.lastName && !(0, person_util_1.hasName)(finalPatient, models.PersonName.UseEnum.Official)) {
|
|
60
|
+
finalPatient = (0, person_util_1.garnishPersonWithName)(finalPatient, models.PersonName.UseEnum.Official, finalPatient.lastName, finalPatient.firstName);
|
|
61
61
|
}
|
|
62
|
-
if (!!finalPatient.maidenName && !person_util_1.hasName(finalPatient, models.PersonName.UseEnum.Maiden)) {
|
|
63
|
-
finalPatient = person_util_1.garnishPersonWithName(finalPatient, models.PersonName.UseEnum.Maiden, finalPatient.maidenName, finalPatient.firstName);
|
|
62
|
+
if (!!finalPatient.maidenName && !(0, person_util_1.hasName)(finalPatient, models.PersonName.UseEnum.Maiden)) {
|
|
63
|
+
finalPatient = (0, person_util_1.garnishPersonWithName)(finalPatient, models.PersonName.UseEnum.Maiden, finalPatient.maidenName, finalPatient.firstName);
|
|
64
64
|
}
|
|
65
|
-
if (!!finalPatient.alias && !person_util_1.hasName(finalPatient, models.PersonName.UseEnum.Nickname)) {
|
|
66
|
-
finalPatient = person_util_1.garnishPersonWithName(finalPatient, models.PersonName.UseEnum.Nickname, finalPatient.alias, finalPatient.firstName);
|
|
65
|
+
if (!!finalPatient.alias && !(0, person_util_1.hasName)(finalPatient, models.PersonName.UseEnum.Nickname)) {
|
|
66
|
+
finalPatient = (0, person_util_1.garnishPersonWithName)(finalPatient, models.PersonName.UseEnum.Nickname, finalPatient.alias, finalPatient.firstName);
|
|
67
67
|
}
|
|
68
|
-
if (!finalPatient.lastName && !!person_util_1.hasName(finalPatient, models.PersonName.UseEnum.Official)) {
|
|
69
|
-
|
|
68
|
+
if (!finalPatient.lastName && !!(0, person_util_1.hasName)(finalPatient, models.PersonName.UseEnum.Official)) {
|
|
69
|
+
const officialName = (0, person_util_1.findName)(finalPatient, models.PersonName.UseEnum.Official);
|
|
70
70
|
finalPatient = Object.assign(Object.assign({}, finalPatient), { lastName: officialName.lastName, firstName: (_a = officialName.firstNames) === null || _a === void 0 ? void 0 : _a[0] });
|
|
71
71
|
}
|
|
72
|
-
if (!finalPatient.maidenName && !!person_util_1.hasName(finalPatient, models.PersonName.UseEnum.Maiden)) {
|
|
73
|
-
finalPatient = Object.assign(Object.assign({}, finalPatient), { maidenName: person_util_1.findName(finalPatient, models.PersonName.UseEnum.Maiden).lastName });
|
|
72
|
+
if (!finalPatient.maidenName && !!(0, person_util_1.hasName)(finalPatient, models.PersonName.UseEnum.Maiden)) {
|
|
73
|
+
finalPatient = Object.assign(Object.assign({}, finalPatient), { maidenName: (0, person_util_1.findName)(finalPatient, models.PersonName.UseEnum.Maiden).lastName });
|
|
74
74
|
}
|
|
75
|
-
if (!finalPatient.alias && !!person_util_1.hasName(finalPatient, models.PersonName.UseEnum.Nickname)) {
|
|
76
|
-
finalPatient = Object.assign(Object.assign({}, finalPatient), { alias: person_util_1.findName(finalPatient, models.PersonName.UseEnum.Nickname).lastName });
|
|
75
|
+
if (!finalPatient.alias && !!(0, person_util_1.hasName)(finalPatient, models.PersonName.UseEnum.Nickname)) {
|
|
76
|
+
finalPatient = Object.assign(Object.assign({}, finalPatient), { alias: (0, person_util_1.findName)(finalPatient, models.PersonName.UseEnum.Nickname).lastName });
|
|
77
77
|
}
|
|
78
78
|
return finalPatient;
|
|
79
79
|
}
|
|
80
80
|
initDelegations(patient, user, secretForeignKey = undefined, delegates = []) {
|
|
81
|
-
const dataOwnerId = this.
|
|
81
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
82
82
|
return this.crypto.initObjectDelegations(patient, null, dataOwnerId, secretForeignKey || null).then((initData) => {
|
|
83
83
|
_.extend(patient, { delegations: initData.delegations });
|
|
84
84
|
let promise = Promise.resolve(patient);
|
|
@@ -93,14 +93,14 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
initConfidentialDelegation(patient, user) {
|
|
96
|
-
const dataOwnerId = this.
|
|
96
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
97
97
|
return this.crypto.extractPreferredSfk(patient, dataOwnerId, true).then((k) => {
|
|
98
98
|
if (!k) {
|
|
99
99
|
const secretId = this.crypto.randomUuid();
|
|
100
100
|
return this.crypto
|
|
101
101
|
.decryptAndImportAesHcPartyKeysForDelegators([dataOwnerId], dataOwnerId)
|
|
102
102
|
.then((hcPartyKeys) => {
|
|
103
|
-
return this.crypto.AES.encrypt(hcPartyKeys[0].key, binary_utils_1.string2ua(patient.id + ':' + secretId).buffer);
|
|
103
|
+
return this.crypto.AES.encrypt(hcPartyKeys[0].key, (0, binary_utils_1.string2ua)(patient.id + ':' + secretId).buffer);
|
|
104
104
|
})
|
|
105
105
|
.then((newDelegation) => {
|
|
106
106
|
;
|
|
@@ -108,7 +108,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
108
108
|
owner: dataOwnerId,
|
|
109
109
|
delegatedTo: dataOwnerId,
|
|
110
110
|
tag: 'confidential',
|
|
111
|
-
key: binary_utils_1.ua2hex(newDelegation),
|
|
111
|
+
key: (0, binary_utils_1.ua2hex)(newDelegation),
|
|
112
112
|
}));
|
|
113
113
|
return patient.rev ? this.modifyPatientWithUser(user, patient) : this.createPatientWithUser(user, patient);
|
|
114
114
|
});
|
|
@@ -271,7 +271,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
271
271
|
.then((pats) => pats[0]);
|
|
272
272
|
}
|
|
273
273
|
encrypt(user, pats) {
|
|
274
|
-
const dataOwnerId = this.
|
|
274
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
275
275
|
const fixEncryptionKeys = (p) => {
|
|
276
276
|
if (p.delegations && p.delegations[dataOwnerId])
|
|
277
277
|
return this.initEncryptionKeys(user, p, Object.keys(p.delegations));
|
|
@@ -282,16 +282,16 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
282
282
|
var _a;
|
|
283
283
|
return (p.encryptionKeys && ((_a = p.encryptionKeys[dataOwnerId]) === null || _a === void 0 ? void 0 : _a.length) ? Promise.resolve(p) : fixEncryptionKeys(p))
|
|
284
284
|
.then((p) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, p.id, p.encryptionKeys))
|
|
285
|
-
.then((sfks) => this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(sfks.extractedKeys[0].replace(/-/g, ''))))
|
|
286
|
-
.then((key) => utils_1.utils.crypt(p, (obj) => this.crypto.AES.encrypt(key, binary_utils_1.utf8_2ua(JSON.stringify(obj, (k, v) => {
|
|
285
|
+
.then((sfks) => this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(sfks.extractedKeys[0].replace(/-/g, ''))))
|
|
286
|
+
.then((key) => utils_1.utils.crypt(p, (obj) => this.crypto.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify(obj, (k, v) => {
|
|
287
287
|
return v instanceof ArrayBuffer || v instanceof Uint8Array
|
|
288
|
-
? binary_utils_1.b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
|
|
288
|
+
? (0, binary_utils_1.b2a)(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
|
|
289
289
|
: v;
|
|
290
290
|
}))), this.encryptedKeys));
|
|
291
291
|
}));
|
|
292
292
|
}
|
|
293
293
|
decrypt(user, pats, fillDelegations = true) {
|
|
294
|
-
const dataOwnerId = this.
|
|
294
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
295
295
|
return (user.healthcarePartyId ? this.hcpartyApi.getHealthcarePartyHierarchyIds(user.healthcarePartyId) : Promise.resolve([dataOwnerId])).then((ids) => {
|
|
296
296
|
const hcpId = ids[0];
|
|
297
297
|
//First check that we have no dangling delegation
|
|
@@ -321,10 +321,10 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
321
321
|
//console.log("Cannot decrypt contact", ctc.id)
|
|
322
322
|
return Promise.resolve(p);
|
|
323
323
|
}
|
|
324
|
-
return this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(sfks[0].replace(/-/g, ''))).then((key) => utils_1.utils
|
|
324
|
+
return this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(sfks[0].replace(/-/g, ''))).then((key) => utils_1.utils
|
|
325
325
|
.decrypt(p, (ec) => this.crypto.AES.decrypt(key, ec)
|
|
326
326
|
.then((dec) => {
|
|
327
|
-
const jsonContent = dec && binary_utils_1.ua2utf8(dec);
|
|
327
|
+
const jsonContent = dec && (0, binary_utils_1.ua2utf8)(dec);
|
|
328
328
|
try {
|
|
329
329
|
return JSON.parse(jsonContent);
|
|
330
330
|
}
|
|
@@ -339,7 +339,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
339
339
|
}))
|
|
340
340
|
.then((p) => {
|
|
341
341
|
if (p.picture && !(p.picture instanceof ArrayBuffer)) {
|
|
342
|
-
p.picture = ModelHelper_1.b64_2ab(p.picture);
|
|
342
|
+
p.picture = (0, ModelHelper_1.b64_2ab)(p.picture);
|
|
343
343
|
}
|
|
344
344
|
return p;
|
|
345
345
|
}));
|
|
@@ -352,7 +352,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
352
352
|
/** By default, an encryptionKey will be added for every hcp in the autoDelegations of the provided user.
|
|
353
353
|
* In optional field additionalDelegateIds, you can ask the method to create encryptionKeys for additional hcps */
|
|
354
354
|
initEncryptionKeys(user, pat, additionalDelegateIds) {
|
|
355
|
-
const dataOwnerId = this.
|
|
355
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
356
356
|
const userAutoDelegations = user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [];
|
|
357
357
|
return this.crypto.initEncryptionKeys(pat, dataOwnerId).then((eks) => {
|
|
358
358
|
let promise = Promise.resolve(_.extend(pat, {
|
|
@@ -431,7 +431,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
431
431
|
},
|
|
432
432
|
patient: { success: false, error: null, modified: 0 },
|
|
433
433
|
};
|
|
434
|
-
return net_utils_1.retry(() => this.getPatientWithUser(user, patId))
|
|
434
|
+
return (0, net_utils_1.retry)(() => this.getPatientWithUser(user, patId))
|
|
435
435
|
.then((patient) => patient.encryptionKeys && Object.keys(patient.encryptionKeys || {}).length
|
|
436
436
|
? Promise.resolve(patient)
|
|
437
437
|
: this.initEncryptionKeys(user, patient).then((patient) => this.modifyPatientWithUser(user, patient)))
|
|
@@ -446,42 +446,42 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
446
446
|
return this.crypto.extractDelegationsSFKsAndEncryptionSKs(patient, ownerId).then(([delSfks, ecKeys]) => {
|
|
447
447
|
return delSfks.length
|
|
448
448
|
? Promise.all([
|
|
449
|
-
net_utils_1.retry(() => this.helementApi
|
|
449
|
+
(0, net_utils_1.retry)(() => this.helementApi
|
|
450
450
|
.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
|
|
451
451
|
.then((hes) => parentId
|
|
452
452
|
? this.helementApi
|
|
453
453
|
.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
|
|
454
454
|
.then((moreHes) => _.uniqBy(hes.concat(moreHes), 'id'))
|
|
455
455
|
: hes)),
|
|
456
|
-
net_utils_1.retry(() => this.formApi
|
|
456
|
+
(0, net_utils_1.retry)(() => this.formApi
|
|
457
457
|
.findFormsDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
|
|
458
458
|
.then((frms) => parentId
|
|
459
459
|
? this.formApi
|
|
460
460
|
.findFormsDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
|
|
461
461
|
.then((moreFrms) => _.uniqBy(frms.concat(moreFrms), 'id'))
|
|
462
462
|
: frms)),
|
|
463
|
-
net_utils_1.retry(() => this.contactApi
|
|
463
|
+
(0, net_utils_1.retry)(() => this.contactApi
|
|
464
464
|
.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))
|
|
465
465
|
.then((ctcs) => parentId
|
|
466
466
|
? this.contactApi
|
|
467
467
|
.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))
|
|
468
468
|
.then((moreCtcs) => _.uniqBy(ctcs.concat(moreCtcs), 'id'))
|
|
469
469
|
: ctcs)),
|
|
470
|
-
net_utils_1.retry(() => this.invoiceApi
|
|
470
|
+
(0, net_utils_1.retry)(() => this.invoiceApi
|
|
471
471
|
.findInvoicesDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
|
|
472
472
|
.then((ivs) => parentId
|
|
473
473
|
? this.invoiceApi
|
|
474
474
|
.findInvoicesDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
|
|
475
475
|
.then((moreIvs) => _.uniqBy(ivs.concat(moreIvs), 'id'))
|
|
476
476
|
: ivs)),
|
|
477
|
-
net_utils_1.retry(() => this.classificationApi
|
|
477
|
+
(0, net_utils_1.retry)(() => this.classificationApi
|
|
478
478
|
.findClassificationsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
|
|
479
479
|
.then((cls) => parentId
|
|
480
480
|
? this.classificationApi
|
|
481
481
|
.findClassificationsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
|
|
482
482
|
.then((moreCls) => _.uniqBy(cls.concat(moreCls), 'id'))
|
|
483
483
|
: cls)),
|
|
484
|
-
net_utils_1.retry(() => this.calendarItemApi
|
|
484
|
+
(0, net_utils_1.retry)(() => this.calendarItemApi
|
|
485
485
|
.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))
|
|
486
486
|
.then((cls) => parentId
|
|
487
487
|
? this.calendarItemApi
|
|
@@ -506,7 +506,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
506
506
|
const docIds = {};
|
|
507
507
|
ctcs.forEach((c) => c.services &&
|
|
508
508
|
c.services.forEach((s) => s.content && Object.values(s.content).forEach((c) => c && c.documentId && (docIds[c.documentId] = 1))));
|
|
509
|
-
return net_utils_1.retry(() => this.documentApi.getDocuments(new models_1.ListOfIds({ ids: Object.keys(docIds) }))).then((docs) => {
|
|
509
|
+
return (0, net_utils_1.retry)(() => this.documentApi.getDocuments(new models_1.ListOfIds({ ids: Object.keys(docIds) }))).then((docs) => {
|
|
510
510
|
const oDocs = docs.map((x) => _.assign({}, x, cloneKeysAndDelegations(x)));
|
|
511
511
|
let markerPromise = Promise.resolve(null);
|
|
512
512
|
delegateIds.forEach((delegateId) => {
|
|
@@ -694,7 +694,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
694
694
|
export(user, patId, ownerId) {
|
|
695
695
|
return this.hcpartyApi.getHealthcareParty(ownerId).then((hcp) => {
|
|
696
696
|
const parentId = hcp.parentId;
|
|
697
|
-
return net_utils_1.retry(() => this.getPatientWithUser(user, patId))
|
|
697
|
+
return (0, net_utils_1.retry)(() => this.getPatientWithUser(user, patId))
|
|
698
698
|
.then((patient) => patient.encryptionKeys && Object.keys(patient.encryptionKeys || {}).length
|
|
699
699
|
? Promise.resolve(patient)
|
|
700
700
|
: this.initEncryptionKeys(user, patient).then((patient) => this.modifyPatientWithUser(user, patient)))
|
|
@@ -705,42 +705,42 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
705
705
|
return this.crypto.extractDelegationsSFKsAndEncryptionSKs(patient, ownerId).then(([delSfks, ecKeys]) => {
|
|
706
706
|
return delSfks.length
|
|
707
707
|
? Promise.all([
|
|
708
|
-
net_utils_1.retry(() => this.helementApi
|
|
708
|
+
(0, net_utils_1.retry)(() => this.helementApi
|
|
709
709
|
.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))
|
|
710
710
|
.then((hes) => parentId
|
|
711
711
|
? this.helementApi
|
|
712
712
|
.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))
|
|
713
713
|
.then((moreHes) => _.uniqBy(hes.concat(moreHes), 'id'))
|
|
714
714
|
: hes)),
|
|
715
|
-
net_utils_1.retry(() => this.formApi
|
|
715
|
+
(0, net_utils_1.retry)(() => this.formApi
|
|
716
716
|
.findFormsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
|
|
717
717
|
.then((frms) => parentId
|
|
718
718
|
? this.formApi
|
|
719
719
|
.findFormsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
|
|
720
720
|
.then((moreFrms) => _.uniqBy(frms.concat(moreFrms), 'id'))
|
|
721
721
|
: frms)),
|
|
722
|
-
net_utils_1.retry(() => this.contactApi
|
|
722
|
+
(0, net_utils_1.retry)(() => this.contactApi
|
|
723
723
|
.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))
|
|
724
724
|
.then((ctcs) => parentId
|
|
725
725
|
? this.contactApi
|
|
726
726
|
.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))
|
|
727
727
|
.then((moreCtcs) => _.uniqBy(ctcs.concat(moreCtcs), 'id'))
|
|
728
728
|
: ctcs)),
|
|
729
|
-
net_utils_1.retry(() => this.invoiceApi
|
|
729
|
+
(0, net_utils_1.retry)(() => this.invoiceApi
|
|
730
730
|
.findInvoicesByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
|
|
731
731
|
.then((ivs) => parentId
|
|
732
732
|
? this.invoiceApi
|
|
733
733
|
.findInvoicesByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
|
|
734
734
|
.then((moreIvs) => _.uniqBy(ivs.concat(moreIvs), 'id'))
|
|
735
735
|
: ivs)),
|
|
736
|
-
net_utils_1.retry(() => this.classificationApi
|
|
736
|
+
(0, net_utils_1.retry)(() => this.classificationApi
|
|
737
737
|
.findClassificationsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
|
|
738
738
|
.then((cls) => parentId
|
|
739
739
|
? this.classificationApi
|
|
740
740
|
.findClassificationsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
|
|
741
741
|
.then((moreCls) => _.uniqBy(cls.concat(moreCls), 'id'))
|
|
742
742
|
: cls)),
|
|
743
|
-
net_utils_1.retry(() => __awaiter(this, void 0, void 0, function* () {
|
|
743
|
+
(0, net_utils_1.retry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
744
744
|
const delegationSFKs = _.uniq(delSfks).join(',');
|
|
745
745
|
try {
|
|
746
746
|
let calendarItems = yield this.calendarItemApi.findByHCPartyPatientSecretFKeys(ownerId, delegationSFKs);
|
|
@@ -759,7 +759,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
759
759
|
const docIds = {};
|
|
760
760
|
ctcs.forEach((c) => c.services &&
|
|
761
761
|
c.services.forEach((s) => s.content && Object.values(s.content).forEach((c) => c && c.documentId && (docIds[c.documentId] = 1))));
|
|
762
|
-
return net_utils_1.retry(() => this.documentApi.getDocuments(new models_1.ListOfIds({ ids: Object.keys(docIds) }))).then((docs) => {
|
|
762
|
+
return (0, net_utils_1.retry)(() => this.documentApi.getDocuments(new models_1.ListOfIds({ ids: Object.keys(docIds) }))).then((docs) => {
|
|
763
763
|
return {
|
|
764
764
|
id: patId,
|
|
765
765
|
patient: patient,
|