@icure/api 4.2.26 → 4.2.31
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/IccApplicationsettingsApi.d.ts +6 -0
- package/icc-api/api/IccApplicationsettingsApi.js +15 -0
- package/icc-api/api/IccApplicationsettingsApi.js.map +1 -1
- package/icc-api/api/IccBesamv2Api.d.ts +9 -0
- package/icc-api/api/IccBesamv2Api.js +22 -0
- package/icc-api/api/IccBesamv2Api.js.map +1 -1
- package/icc-api/api/IccDeviceApi.d.ts +3 -1
- package/icc-api/api/IccDeviceApi.js.map +1 -1
- package/icc-api/api/IccHcpartyApi.d.ts +3 -1
- package/icc-api/api/IccHcpartyApi.js.map +1 -1
- package/icc-api/api/IccPatientApi.d.ts +3 -1
- package/icc-api/api/IccPatientApi.js.map +1 -1
- package/icc-api/api/IccUserApi.d.ts +8 -2
- package/icc-api/api/IccUserApi.js +17 -4
- package/icc-api/api/IccUserApi.js.map +1 -1
- package/icc-api/model/Measure.d.ts +1 -0
- package/icc-api/model/Measure.js.map +1 -1
- package/icc-api/model/Medication.d.ts +1 -0
- package/icc-api/model/Medication.js.map +1 -1
- package/icc-x-api/filters/MaintenanceTaskAfterDateFilter.d.ts +18 -0
- package/icc-x-api/filters/MaintenanceTaskAfterDateFilter.js +24 -0
- package/icc-x-api/filters/MaintenanceTaskAfterDateFilter.js.map +1 -0
- package/icc-x-api/filters/MaintenanceTaskByHcPartyAndIdentifiersFilter.d.ts +20 -0
- package/icc-x-api/filters/MaintenanceTaskByHcPartyAndIdentifiersFilter.js +13 -0
- package/icc-x-api/filters/MaintenanceTaskByHcPartyAndIdentifiersFilter.js.map +1 -0
- package/icc-x-api/filters/MaintenanceTaskByHcPartyAndTypeFilter.d.ts +19 -0
- package/icc-x-api/filters/MaintenanceTaskByHcPartyAndTypeFilter.js +24 -0
- package/icc-x-api/filters/MaintenanceTaskByHcPartyAndTypeFilter.js.map +1 -0
- package/icc-x-api/filters/MaintenanceTaskByIdsFilter.d.ts +18 -0
- package/icc-x-api/filters/MaintenanceTaskByIdsFilter.js +24 -0
- package/icc-x-api/filters/MaintenanceTaskByIdsFilter.js.map +1 -0
- package/icc-x-api/icc-hcparty-x-api.d.ts +1 -0
- package/icc-x-api/icc-hcparty-x-api.js +15 -0
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +27 -0
- package/icc-x-api/icc-maintenance-task-x-api.js +153 -0
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -0
- package/icc-x-api/icc-patient-x-api.js +2 -4
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +17 -13
- package/icc-x-api/index.js +72 -51
- package/icc-x-api/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IccMaintenanceTaskXApi = void 0;
|
|
4
|
+
const IccMaintenanceTaskApi_1 = require("../icc-api/api/IccMaintenanceTaskApi");
|
|
5
|
+
const _ = require("lodash");
|
|
6
|
+
const ModelHelper_1 = require("../icc-api/model/ModelHelper");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const utils_2 = require("./crypto/utils");
|
|
9
|
+
class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskApi {
|
|
10
|
+
constructor(host, headers, crypto, userApi, hcPartyApi, encryptedKeys = [], fetchImpl = typeof window !== 'undefined'
|
|
11
|
+
? window.fetch
|
|
12
|
+
: typeof self !== 'undefined'
|
|
13
|
+
? self.fetch
|
|
14
|
+
: fetch) {
|
|
15
|
+
super(host, headers, fetchImpl);
|
|
16
|
+
this.crypto = crypto;
|
|
17
|
+
this.userApi = userApi;
|
|
18
|
+
this.hcPartyApi = hcPartyApi;
|
|
19
|
+
this.encryptedKeys = encryptedKeys;
|
|
20
|
+
}
|
|
21
|
+
newInstance(user, m, taskDelegatedTo = undefined, delegates = []) {
|
|
22
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
23
|
+
const maintenanceTask = _.assign({
|
|
24
|
+
id: this.crypto.randomUuid(),
|
|
25
|
+
_type: 'org.taktik.icure.entities.MaintenanceTask',
|
|
26
|
+
created: new Date().getTime(),
|
|
27
|
+
modified: new Date().getTime(),
|
|
28
|
+
responsible: dataOwnerId,
|
|
29
|
+
author: user.id,
|
|
30
|
+
}, m || {});
|
|
31
|
+
return this.initDelegations(user, maintenanceTask, delegates);
|
|
32
|
+
}
|
|
33
|
+
initDelegations(user, maintenanceTask, delegates = []) {
|
|
34
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
35
|
+
return this.crypto.initObjectDelegations(maintenanceTask, null, dataOwnerId, null).then((initData) => {
|
|
36
|
+
_.extend(maintenanceTask, { delegations: initData.delegations });
|
|
37
|
+
let promise = Promise.resolve(maintenanceTask);
|
|
38
|
+
_.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach((delegateId) => (promise = promise
|
|
39
|
+
.then((patient) => this.crypto.extendedDelegationsAndCryptedForeignKeys(patient, null, dataOwnerId, delegateId, initData.secretId))
|
|
40
|
+
.then((extraData) => _.extend(maintenanceTask, { delegations: extraData.delegations }))
|
|
41
|
+
.catch((e) => {
|
|
42
|
+
console.log(e);
|
|
43
|
+
return maintenanceTask;
|
|
44
|
+
})));
|
|
45
|
+
return promise;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
initEncryptionKeys(user, maintenanceTask) {
|
|
49
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
50
|
+
return this.crypto.initEncryptionKeys(maintenanceTask, dataOwnerId).then((eks) => {
|
|
51
|
+
let promise = Promise.resolve(_.extend(maintenanceTask, {
|
|
52
|
+
encryptionKeys: eks.encryptionKeys,
|
|
53
|
+
}));
|
|
54
|
+
(user.autoDelegations ? user.autoDelegations.all || [] : []).forEach((delegateId) => (promise = promise.then((patient) => this.crypto
|
|
55
|
+
.appendEncryptionKeys(patient, dataOwnerId, delegateId, eks.secretId)
|
|
56
|
+
.then((extraEks) => {
|
|
57
|
+
return _.extend(patient, {
|
|
58
|
+
encryptionKeys: extraEks.encryptionKeys,
|
|
59
|
+
});
|
|
60
|
+
})
|
|
61
|
+
.catch((e) => {
|
|
62
|
+
console.log(e.message);
|
|
63
|
+
return patient;
|
|
64
|
+
}))));
|
|
65
|
+
return promise;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
createMaintenanceTask(body) {
|
|
69
|
+
throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
|
|
70
|
+
}
|
|
71
|
+
createMaintenanceTaskWithUser(user, body) {
|
|
72
|
+
return body
|
|
73
|
+
? this.encrypt(user, [_.cloneDeep(body)])
|
|
74
|
+
.then((tasks) => super.createMaintenanceTask(tasks[0]))
|
|
75
|
+
.then((mt) => this.decrypt(user, [mt]))
|
|
76
|
+
.then((tasks) => tasks[0])
|
|
77
|
+
: Promise.resolve(null);
|
|
78
|
+
}
|
|
79
|
+
filterMaintenanceTasksBy(startDocumentId, limit, body) {
|
|
80
|
+
throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
|
|
81
|
+
}
|
|
82
|
+
filterMaintenanceTasksByWithUser(user, startDocumentId, limit, body) {
|
|
83
|
+
return super
|
|
84
|
+
.filterMaintenanceTasksBy(startDocumentId, limit, body)
|
|
85
|
+
.then((pl) => this.decrypt(user, pl.rows).then((dr) => Object.assign(pl, { rows: dr })));
|
|
86
|
+
}
|
|
87
|
+
getMaintenanceTask(maintenanceTaskId) {
|
|
88
|
+
throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
|
|
89
|
+
}
|
|
90
|
+
getMaintenanceTaskWithUser(user, maintenanceTaskId) {
|
|
91
|
+
return super
|
|
92
|
+
.getMaintenanceTask(maintenanceTaskId)
|
|
93
|
+
.then((mt) => this.decrypt(user, [mt]))
|
|
94
|
+
.then((mts) => mts[0]);
|
|
95
|
+
}
|
|
96
|
+
modifyMaintenanceTask(body) {
|
|
97
|
+
throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
|
|
98
|
+
}
|
|
99
|
+
modifyMaintenanceTaskWithUser(user, body) {
|
|
100
|
+
return body
|
|
101
|
+
? this.encrypt(user, [_.cloneDeep(body)])
|
|
102
|
+
.then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))
|
|
103
|
+
.then((mt) => this.decrypt(user, [mt]))
|
|
104
|
+
.then((mts) => mts[0])
|
|
105
|
+
: Promise.resolve(null);
|
|
106
|
+
}
|
|
107
|
+
encrypt(user, maintenanceTasks) {
|
|
108
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
109
|
+
return Promise.all(maintenanceTasks.map((m) => (m.encryptionKeys && Object.keys(m.encryptionKeys).some((k) => !!m.encryptionKeys[k].length)
|
|
110
|
+
? Promise.resolve(m)
|
|
111
|
+
: this.initEncryptionKeys(user, m))
|
|
112
|
+
.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) => {
|
|
115
|
+
return v instanceof ArrayBuffer || v instanceof Uint8Array
|
|
116
|
+
? ModelHelper_1.b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
|
|
117
|
+
: v;
|
|
118
|
+
}))), this.encryptedKeys))));
|
|
119
|
+
}
|
|
120
|
+
decrypt(user, maintenanceTasks) {
|
|
121
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
122
|
+
return Promise.all(maintenanceTasks.map((mT) => {
|
|
123
|
+
var _a;
|
|
124
|
+
return this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id, (_a = mT.encryptionKeys) !== null && _a !== void 0 ? _a : {}).then(({ extractedKeys: sfks }) => {
|
|
125
|
+
if (!sfks || !sfks.length) {
|
|
126
|
+
console.log('Cannot decrypt maintenanceTask', mT.id);
|
|
127
|
+
return Promise.resolve(mT);
|
|
128
|
+
}
|
|
129
|
+
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) => {
|
|
131
|
+
let jsonContent;
|
|
132
|
+
try {
|
|
133
|
+
jsonContent = dec && utils_1.ua2utf8(dec);
|
|
134
|
+
jsonContent && _.assign(mT, JSON.parse(jsonContent));
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
console.log('Cannot parse mTask', mT.id, jsonContent || '<- Invalid encoding');
|
|
138
|
+
}
|
|
139
|
+
resolve(mT);
|
|
140
|
+
}, () => {
|
|
141
|
+
console.log('Cannot decrypt mTask', mT.id);
|
|
142
|
+
resolve(mT);
|
|
143
|
+
})));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return Promise.resolve(mT);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.IccMaintenanceTaskXApi = IccMaintenanceTaskXApi;
|
|
153
|
+
//# sourceMappingURL=icc-maintenance-task-x-api.js.map
|
|
@@ -0,0 +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,0CAA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D,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;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, taskDelegatedTo: string | undefined = undefined, 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)\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): 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 ;(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"]}
|
|
@@ -119,7 +119,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
createPatient(body) {
|
|
122
|
-
throw new Error('Cannot call a method that returns
|
|
122
|
+
throw new Error('Cannot call a method that returns patients without providing a user for de/encryption');
|
|
123
123
|
}
|
|
124
124
|
createPatientWithUser(user, body) {
|
|
125
125
|
return body
|
|
@@ -285,9 +285,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
285
285
|
}
|
|
286
286
|
decrypt(user, pats, fillDelegations = true) {
|
|
287
287
|
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
288
|
-
return (user.healthcarePartyId
|
|
289
|
-
? this.hcpartyApi.getHealthcareParty(user.healthcarePartyId).then((hcp) => [hcp.id, hcp.parentId])
|
|
290
|
-
: Promise.resolve([dataOwnerId])).then((ids) => {
|
|
288
|
+
return (user.healthcarePartyId ? this.hcpartyApi.getHealthcarePartyHierarchyIds(user.healthcarePartyId) : Promise.resolve([dataOwnerId])).then((ids) => {
|
|
291
289
|
const hcpId = ids[0];
|
|
292
290
|
//First check that we have no dangling delegation
|
|
293
291
|
const patsWithMissingDelegations = pats.filter((p) => p.delegations &&
|