@icure/api 4.2.24 → 4.2.27
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/IccBeresultimportApi.js +2 -2
- package/icc-api/api/IccBeresultimportApi.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 +12 -0
- package/icc-api/api/IccDeviceApi.js +13 -0
- package/icc-api/api/IccDeviceApi.js.map +1 -1
- package/icc-api/api/IccHcpartyApi.d.ts +13 -1
- package/icc-api/api/IccHcpartyApi.js +14 -1
- package/icc-api/api/IccHcpartyApi.js.map +1 -1
- package/icc-api/api/IccMaintenanceTaskApi.d.ts +56 -0
- package/icc-api/api/IccMaintenanceTaskApi.js +111 -0
- package/icc-api/api/IccMaintenanceTaskApi.js.map +1 -0
- package/icc-api/api/IccPatientApi.d.ts +12 -0
- package/icc-api/api/IccPatientApi.js +13 -0
- 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/api/XHR.d.ts +1 -1
- package/icc-api/api/XHR.js +10 -4
- package/icc-api/api/XHR.js.map +1 -1
- package/icc-api/iccApi.d.ts +1 -1
- package/icc-api/iccApi.js +1 -1
- package/icc-api/iccApi.js.map +1 -1
- package/icc-api/model/AbstractFilterMaintenanceTask.d.ts +15 -0
- package/icc-api/model/AbstractFilterMaintenanceTask.js +21 -0
- package/icc-api/model/AbstractFilterMaintenanceTask.js.map +1 -0
- package/icc-api/model/Device.d.ts +5 -7
- package/icc-api/model/Device.js.map +1 -1
- package/icc-api/model/FilterChainMaintenanceTask.d.ts +19 -0
- package/icc-api/model/FilterChainMaintenanceTask.js +11 -0
- package/icc-api/model/FilterChainMaintenanceTask.js.map +1 -0
- package/icc-api/model/FormTemplate.d.ts +1 -0
- package/icc-api/model/FormTemplate.js.map +1 -1
- package/icc-api/model/HealthcareParty.d.ts +18 -7
- package/icc-api/model/HealthcareParty.js.map +1 -1
- package/icc-api/model/MaintenanceTask.d.ts +95 -0
- package/icc-api/model/MaintenanceTask.js +18 -0
- package/icc-api/model/MaintenanceTask.js.map +1 -0
- 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-api/model/PaginatedListMaintenanceTask.d.ts +20 -0
- package/icc-api/model/PaginatedListMaintenanceTask.js +10 -0
- package/icc-api/model/PaginatedListMaintenanceTask.js.map +1 -0
- package/icc-api/model/Patient.d.ts +5 -7
- package/icc-api/model/Patient.js.map +1 -1
- package/icc-api/model/PermissionItem.d.ts +1 -0
- package/icc-api/model/PermissionItem.js.map +1 -1
- package/icc-api/model/models.d.ts +4 -7
- package/icc-api/model/models.js +4 -7
- package/icc-api/model/models.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-classification-x-api.d.ts +2 -2
- 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 +1 -1
- package/icc-x-api/icc-contact-x-api.js +5 -5
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +1 -1
- package/icc-x-api/icc-crypto-x-api.js +1 -1
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +1 -1
- package/icc-x-api/icc-form-x-api.js +4 -4
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-hcparty-x-api.d.ts +1 -0
- package/icc-x-api/icc-hcparty-x-api.js +20 -0
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +2 -2
- package/icc-x-api/icc-helement-x-api.js +4 -4
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.d.ts +1 -1
- package/icc-x-api/icc-invoice-x-api.js +4 -4
- package/icc-x-api/icc-invoice-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-message-x-api.d.ts +1 -1
- package/icc-x-api/icc-message-x-api.js +2 -2
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +2 -2
- package/icc-x-api/icc-patient-x-api.js +6 -6
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +2 -0
- package/icc-x-api/index.js +3 -0
- package/icc-x-api/index.js.map +1 -1
- package/package.json +2 -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.filterMaintenanceTasksBy(startDocumentId, limit, body)
|
|
84
|
+
.then((pl) => this.decrypt(user, pl.rows).then((dr) => Object.assign(pl, { rows: dr })));
|
|
85
|
+
}
|
|
86
|
+
getMaintenanceTask(maintenanceTaskId) {
|
|
87
|
+
throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
|
|
88
|
+
}
|
|
89
|
+
getMaintenanceTaskWithUser(user, maintenanceTaskId) {
|
|
90
|
+
return super.getMaintenanceTask(maintenanceTaskId)
|
|
91
|
+
.then((mt) => this.decrypt(user, [mt]))
|
|
92
|
+
.then((mts) => mts[0]);
|
|
93
|
+
}
|
|
94
|
+
modifyMaintenanceTask(body) {
|
|
95
|
+
throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
|
|
96
|
+
}
|
|
97
|
+
modifyMaintenanceTaskWithUser(user, body) {
|
|
98
|
+
return body
|
|
99
|
+
? this.encrypt(user, [_.cloneDeep(body)])
|
|
100
|
+
.then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))
|
|
101
|
+
.then((mt) => this.decrypt(user, [mt]))
|
|
102
|
+
.then((mts) => mts[0])
|
|
103
|
+
: Promise.resolve(null);
|
|
104
|
+
}
|
|
105
|
+
encrypt(user, maintenanceTasks) {
|
|
106
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
107
|
+
return Promise.all(maintenanceTasks.map((m) => (m.encryptionKeys && Object.keys(m.encryptionKeys).some((k) => !!m.encryptionKeys[k].length)
|
|
108
|
+
? Promise.resolve(m)
|
|
109
|
+
: this.initEncryptionKeys(user, m))
|
|
110
|
+
.then((m) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, m.id, m.encryptionKeys))
|
|
111
|
+
.then((sfks) => this.crypto.AES.importKey('raw', utils_1.hex2ua(sfks.extractedKeys[0].replace(/-/g, ''))))
|
|
112
|
+
.then((key) => utils_2.utils.crypt(m, (obj) => this.crypto.AES.encrypt(key, utils_1.utf8_2ua(JSON.stringify(obj, (k, v) => {
|
|
113
|
+
return v instanceof ArrayBuffer || v instanceof Uint8Array
|
|
114
|
+
? ModelHelper_1.b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
|
|
115
|
+
: v;
|
|
116
|
+
}))), this.encryptedKeys))));
|
|
117
|
+
}
|
|
118
|
+
decrypt(user, maintenanceTasks) {
|
|
119
|
+
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
120
|
+
return Promise.all(maintenanceTasks.map((mT) => {
|
|
121
|
+
var _a;
|
|
122
|
+
return this.crypto
|
|
123
|
+
.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id, (_a = mT.encryptionKeys) !== null && _a !== void 0 ? _a : {})
|
|
124
|
+
.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,gFAA0E;AAI1E,4BAA2B;AAC3B,8DAAgE;AAChE,mCAAiD;AACjD,0CAAoC;AAGpC,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;YAC3B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAEX,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB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"./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,\n m: any,\n taskDelegatedTo: string | undefined = undefined,\n 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(\n user: models.User,\n maintenanceTask: models.MaintenanceTask,\n delegates: string[] = []\n ): 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(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []) : [])\n ).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(user: models.User, startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): Promise<models.PaginatedListMaintenanceTask | any> {\n return super.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.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\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\n .extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id!, mT.encryptionKeys ?? {})\n .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"]}
|
|
@@ -9,5 +9,5 @@ export declare class IccMessageXApi extends IccMessageApi {
|
|
|
9
9
|
[key: string]: string;
|
|
10
10
|
}, crypto: IccCryptoXApi, userApi: IccUserXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
11
11
|
newInstance(user: User, m: any): Promise<any>;
|
|
12
|
-
newInstanceWithPatient(user: User, patient: Patient | null, m
|
|
12
|
+
newInstanceWithPatient(user: User, patient: Patient | null, m?: any, delegates?: string[]): Promise<any>;
|
|
13
13
|
}
|
|
@@ -18,7 +18,7 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
|
|
|
18
18
|
newInstance(user, m) {
|
|
19
19
|
return this.newInstanceWithPatient(user, null, m);
|
|
20
20
|
}
|
|
21
|
-
newInstanceWithPatient(user, patient, m) {
|
|
21
|
+
newInstanceWithPatient(user, patient, m = {}, delegates = []) {
|
|
22
22
|
const message = _.extend({
|
|
23
23
|
id: this.crypto.randomUuid(),
|
|
24
24
|
_type: 'org.taktik.icure.entities.Message',
|
|
@@ -40,7 +40,7 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
|
|
|
40
40
|
secretForeignKeys: initData.secretForeignKeys,
|
|
41
41
|
});
|
|
42
42
|
let promise = Promise.resolve(message);
|
|
43
|
-
(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach((delegateId) => (promise = promise.then((helement) => this.crypto
|
|
43
|
+
_.uniq(delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])).forEach((delegateId) => (promise = promise.then((helement) => this.crypto
|
|
44
44
|
.extendedDelegationsAndCryptedForeignKeys(helement, patient, dataOwnerId, delegateId, initData.secretId)
|
|
45
45
|
.then((extraData) => _.extend(helement, {
|
|
46
46
|
delegations: extraData.delegations,
|
|
@@ -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,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;QARvB,WAAM,GAAN,MAAM,CAAe;QAS7B,IAAI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C,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 { IccUserXApi } from './icc-user-x-api'\n\nexport class IccMessageXApi extends IccMessageApi {\n userApi: IccUserXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private 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 // 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.userApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n m || {}\n )\n\n const dataOwnerId = this.userApi.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"]}
|
|
@@ -25,9 +25,9 @@ export declare class IccPatientXApi extends IccPatientApi {
|
|
|
25
25
|
constructor(host: string, headers: {
|
|
26
26
|
[key: string]: string;
|
|
27
27
|
}, crypto: IccCryptoXApi, contactApi: IccContactXApi, formApi: IccFormXApi, helementApi: IccHelementXApi, invoiceApi: IccInvoiceXApi, documentApi: IccDocumentXApi, hcpartyApi: IccHcpartyXApi, classificationApi: IccClassificationXApi, userApi: IccUserXApi, calendarItemaApi: IccCalendarItemXApi, encryptedKeys?: Array<string>, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
28
|
-
newInstance(user: models.User, p
|
|
28
|
+
newInstance(user: models.User, p?: any, delegates?: string[]): Promise<models.Patient>;
|
|
29
29
|
completeNames(patient: models.Patient): models.Patient;
|
|
30
|
-
initDelegations(patient: models.Patient, user: models.User, secretForeignKey?: string): Promise<models.Patient>;
|
|
30
|
+
initDelegations(patient: models.Patient, user: models.User, secretForeignKey?: string | undefined, delegates?: string[]): Promise<models.Patient>;
|
|
31
31
|
initConfidentialDelegation(patient: models.Patient, user: models.User): Promise<models.Patient | null>;
|
|
32
32
|
createPatient(body?: models.Patient): never;
|
|
33
33
|
createPatientWithUser(user: models.User, body?: models.Patient): Promise<models.Patient | any>;
|
|
@@ -40,7 +40,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
40
40
|
this.encryptedKeys = encryptedKeys;
|
|
41
41
|
}
|
|
42
42
|
// noinspection JSUnusedGlobalSymbols
|
|
43
|
-
newInstance(user, p) {
|
|
43
|
+
newInstance(user, p = {}, delegates = []) {
|
|
44
44
|
const patient = _.extend({
|
|
45
45
|
id: this.crypto.randomUuid(),
|
|
46
46
|
_type: 'org.taktik.icure.entities.Patient',
|
|
@@ -51,7 +51,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
51
51
|
codes: [],
|
|
52
52
|
tags: [],
|
|
53
53
|
}, p || {});
|
|
54
|
-
return this.initDelegations(patient, user);
|
|
54
|
+
return this.initDelegations(patient, user, undefined, delegates);
|
|
55
55
|
}
|
|
56
56
|
completeNames(patient) {
|
|
57
57
|
var _a;
|
|
@@ -77,12 +77,12 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
77
77
|
}
|
|
78
78
|
return finalPatient;
|
|
79
79
|
}
|
|
80
|
-
initDelegations(patient, user, secretForeignKey) {
|
|
80
|
+
initDelegations(patient, user, secretForeignKey = undefined, delegates = []) {
|
|
81
81
|
const dataOwnerId = this.userApi.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);
|
|
85
|
-
(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach((delegateId) => (promise = promise
|
|
85
|
+
_.uniq(delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])).forEach((delegateId) => (promise = promise
|
|
86
86
|
.then((patient) => this.crypto.extendedDelegationsAndCryptedForeignKeys(patient, null, dataOwnerId, delegateId, initData.secretId))
|
|
87
87
|
.then((extraData) => _.extend(patient, { delegations: extraData.delegations }))
|
|
88
88
|
.catch((e) => {
|
|
@@ -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
|
|
@@ -286,7 +286,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
|
|
|
286
286
|
decrypt(user, pats, fillDelegations = true) {
|
|
287
287
|
const dataOwnerId = this.userApi.getDataOwnerOf(user);
|
|
288
288
|
return (user.healthcarePartyId
|
|
289
|
-
? this.hcpartyApi.
|
|
289
|
+
? this.hcpartyApi.getHealthcarePartyHierarchyIds(user.healthcarePartyId)
|
|
290
290
|
: Promise.resolve([dataOwnerId])).then((ids) => {
|
|
291
291
|
const hcpId = ids[0];
|
|
292
292
|
//First check that we have no dangling delegation
|