@icure/api 6.4.0 → 7.0.0-beta.1
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/IccDeviceApi.d.ts +1 -1
- package/icc-api/api/IccDeviceApi.js.map +1 -1
- package/icc-api/api/IccDoctemplateApi.js.map +1 -1
- package/icc-api/api/IccDocumentTemplateApi.js.map +1 -1
- package/icc-api/api/IccHcpartyApi.d.ts +1 -1
- package/icc-api/api/IccHcpartyApi.js.map +1 -1
- package/icc-api/api/IccPatientApi.d.ts +1 -1
- package/icc-api/api/IccPatientApi.js.map +1 -1
- package/icc-api/model/MaintenanceTask.d.ts +6 -5
- package/icc-api/model/MaintenanceTask.js +5 -0
- package/icc-api/model/MaintenanceTask.js.map +1 -1
- package/icc-api/model/User.d.ts +23 -1
- package/icc-api/model/User.js +21 -0
- package/icc-api/model/User.js.map +1 -1
- package/icc-api/model/models.d.ts +14 -0
- package/icc-api/model/models.js.map +1 -1
- package/icc-x-api/crypto/AES.d.ts +2 -0
- package/icc-x-api/crypto/AES.js +12 -0
- package/icc-x-api/crypto/AES.js.map +1 -1
- package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +122 -0
- package/icc-x-api/crypto/BaseExchangeKeysManager.js +356 -0
- package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -0
- package/icc-x-api/crypto/ConfidentialEntities.d.ts +58 -0
- package/icc-x-api/crypto/ConfidentialEntities.js +99 -0
- package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -0
- package/icc-x-api/crypto/CryptoPrimitives.d.ts +31 -0
- package/icc-x-api/crypto/CryptoPrimitives.js +55 -0
- package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -0
- package/icc-x-api/crypto/CryptoStrategies.d.ts +82 -0
- package/icc-x-api/crypto/CryptoStrategies.js +3 -0
- package/icc-x-api/crypto/CryptoStrategies.js.map +1 -0
- package/icc-x-api/crypto/EntitiesEncryption.d.ts +254 -0
- package/icc-x-api/crypto/EntitiesEncryption.js +700 -0
- package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -0
- package/icc-x-api/crypto/ExchangeKeysManager.d.ts +56 -0
- package/icc-x-api/crypto/ExchangeKeysManager.js +147 -0
- package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -0
- package/icc-x-api/crypto/KeyManager.d.ts +103 -0
- package/icc-x-api/crypto/KeyManager.js +288 -0
- package/icc-x-api/crypto/KeyManager.js.map +1 -0
- package/icc-x-api/crypto/KeyRecovery.d.ts +34 -0
- package/icc-x-api/crypto/KeyRecovery.js +253 -0
- package/icc-x-api/crypto/KeyRecovery.js.map +1 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +28 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.js +22 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -0
- package/icc-x-api/crypto/RSA.d.ts +19 -20
- package/icc-x-api/crypto/RSA.js +30 -1
- package/icc-x-api/crypto/RSA.js.map +1 -1
- package/icc-x-api/crypto/ShamirKeysManager.d.ts +43 -0
- package/icc-x-api/crypto/ShamirKeysManager.js +150 -0
- package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.d.ts +19 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.js +24 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.js.map +1 -0
- package/icc-x-api/crypto/TransferKeysManager.d.ts +29 -0
- package/icc-x-api/crypto/TransferKeysManager.js +121 -0
- package/icc-x-api/crypto/TransferKeysManager.js.map +1 -0
- package/icc-x-api/crypto/utils.d.ts +46 -0
- package/icc-x-api/crypto/utils.js +128 -0
- package/icc-x-api/crypto/utils.js.map +1 -1
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.d.ts +11 -0
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js +11 -0
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js.map +1 -1
- package/icc-x-api/filters/DeviceByHcPartyFilter.d.ts +11 -0
- package/icc-x-api/filters/DeviceByHcPartyFilter.js +11 -0
- package/icc-x-api/filters/DeviceByHcPartyFilter.js.map +1 -1
- package/icc-x-api/filters/DeviceByIdsFilter.d.ts +11 -0
- package/icc-x-api/filters/DeviceByIdsFilter.js +11 -0
- package/icc-x-api/filters/DeviceByIdsFilter.js.map +1 -1
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.d.ts +11 -0
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js +11 -0
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.d.ts +49 -4
- package/icc-x-api/icc-accesslog-x-api.js +112 -102
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +53 -5
- package/icc-x-api/icc-calendar-item-x-api.js +112 -100
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +45 -2
- package/icc-x-api/icc-classification-x-api.js +89 -41
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +57 -19
- package/icc-x-api/icc-contact-x-api.js +149 -154
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +266 -366
- package/icc-x-api/icc-crypto-x-api.js +416 -1327
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-data-owner-x-api.d.ts +110 -11
- package/icc-x-api/icc-data-owner-x-api.js +188 -14
- package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
- package/icc-x-api/icc-doctemplate-x-api.js +3 -3
- package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +76 -5
- package/icc-x-api/icc-document-x-api.js +137 -59
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +47 -7
- package/icc-x-api/icc-form-x-api.js +85 -86
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-hcparty-x-api.d.ts +1 -1
- package/icc-x-api/icc-hcparty-x-api.js +1 -1
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +50 -3
- package/icc-x-api/icc-helement-x-api.js +101 -118
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-icure-maintenance-x-api.d.ts +31 -0
- package/icc-x-api/icc-icure-maintenance-x-api.js +124 -0
- package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -0
- package/icc-x-api/icc-invoice-x-api.d.ts +45 -5
- package/icc-x-api/icc-invoice-x-api.js +89 -64
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +38 -6
- package/icc-x-api/icc-maintenance-task-x-api.js +73 -102
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +55 -2
- package/icc-x-api/icc-message-x-api.js +92 -33
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +67 -7
- package/icc-x-api/icc-patient-x-api.js +409 -473
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +49 -5
- package/icc-x-api/icc-receipt-x-api.js +85 -47
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +34 -10
- package/icc-x-api/icc-time-table-x-api.js +61 -18
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +30 -1
- package/icc-x-api/index.js +112 -49
- package/icc-x-api/index.js.map +1 -1
- package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +35 -0
- package/icc-x-api/maintenance/KeyPairUpdateRequest.js +54 -0
- package/icc-x-api/maintenance/KeyPairUpdateRequest.js.map +1 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +9 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +23 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -0
- package/icc-x-api/storage/IcureStorageFacade.d.ts +55 -0
- package/icc-x-api/storage/IcureStorageFacade.js +95 -0
- package/icc-x-api/storage/IcureStorageFacade.js.map +1 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +31 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.js +3 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -0
- package/icc-x-api/utils/collection-utils.d.ts +8 -0
- package/icc-x-api/utils/collection-utils.js +26 -0
- package/icc-x-api/utils/collection-utils.js.map +1 -0
- package/icc-x-api/utils/crypto-utils.d.ts +8 -1
- package/icc-x-api/utils/crypto-utils.js +19 -3
- package/icc-x-api/utils/crypto-utils.js.map +1 -1
- package/icc-x-api/utils/graph-utils.d.ts +45 -0
- package/icc-x-api/utils/graph-utils.js +203 -0
- package/icc-x-api/utils/graph-utils.js.map +1 -0
- package/icc-x-api/utils/lru-temporised-async-cache.d.ts +27 -0
- package/icc-x-api/utils/lru-temporised-async-cache.js +120 -0
- package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,14 +1,113 @@
|
|
|
1
1
|
import { User } from '../icc-api/model/User';
|
|
2
|
-
import { IccPatientApi } from '../icc-api';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { IccDeviceApi, IccPatientApi, IccUserApi } from '../icc-api';
|
|
3
|
+
import { HealthcareParty } from '../icc-api/model/HealthcareParty';
|
|
4
|
+
import { Patient } from '../icc-api/model/Patient';
|
|
5
|
+
import { Device } from '../icc-api/model/Device';
|
|
6
|
+
import { IccHcpartyXApi } from './icc-hcparty-x-api';
|
|
7
|
+
/**
|
|
8
|
+
* Represents a type of data owner.
|
|
9
|
+
*/
|
|
10
|
+
export type DataOwnerTypeEnum = 'patient' | 'device' | 'hcp';
|
|
11
|
+
export declare const DataOwnerTypeEnum: {
|
|
12
|
+
[key: string]: DataOwnerTypeEnum;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Represents any data owner.
|
|
16
|
+
*/
|
|
17
|
+
export type DataOwner = (Patient | Device | HealthcareParty) & {
|
|
18
|
+
id: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Represents any data owner enriched with type information.
|
|
22
|
+
*/
|
|
23
|
+
export type DataOwnerWithType = {
|
|
24
|
+
type: 'patient';
|
|
25
|
+
dataOwner: Patient & DataOwner;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'device';
|
|
28
|
+
dataOwner: Device & DataOwner;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'hcp';
|
|
31
|
+
dataOwner: HealthcareParty & DataOwner;
|
|
32
|
+
};
|
|
5
33
|
export declare class IccDataOwnerXApi {
|
|
6
|
-
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
34
|
+
private readonly userBaseApi;
|
|
35
|
+
private readonly hcpartyBaseApi;
|
|
36
|
+
private readonly patientBaseApi;
|
|
37
|
+
private readonly deviceBaseApi;
|
|
38
|
+
private currentDataOwnerType;
|
|
39
|
+
private currentDataOwnerHierarchyIds;
|
|
40
|
+
private get selfDataOwnerId();
|
|
41
|
+
constructor(userBaseApi: IccUserApi, hcpartyBaseApi: IccHcpartyXApi, //Init with a hcparty x api for better performances
|
|
42
|
+
patientBaseApi: IccPatientApi, deviceBaseApi: IccDeviceApi);
|
|
43
|
+
/**
|
|
44
|
+
* If the logged user is a data owner get the current data owner. This information is cached without expiration, and will only be updated in case
|
|
45
|
+
* of forced refresh.
|
|
46
|
+
* @throws if the current user is not a data owner.
|
|
47
|
+
*/
|
|
48
|
+
getCurrentDataOwnerId(): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* If the logged user is a data owner get its parent hierarchy. This information is cached without expiration, and will only be updated in case
|
|
51
|
+
* of forced refresh.
|
|
52
|
+
* The resulting array starts with the topmost parent (the only ancestor without a parent) and ends with the data owner itself.
|
|
53
|
+
* @throws if the current user is not a data owner.
|
|
54
|
+
*/
|
|
55
|
+
getCurrentDataOwnerHierarchyIds(): Promise<string[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Get the hierarchy for the current data owner starting from the specified parent.
|
|
58
|
+
* @throws an array starting at the topmost parent and ending at the provided parent id. If the provided id is not part of the hierarchy throws an
|
|
59
|
+
* error.
|
|
60
|
+
*/
|
|
61
|
+
getCurrentDataOwnerHierarchyIdsFrom(parentId: string): Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* If the logged user is a data owner get the current data owner.
|
|
64
|
+
* @throws if the current user is not a data owner.
|
|
65
|
+
*/
|
|
66
|
+
getCurrentDataOwner(): Promise<DataOwnerWithType>;
|
|
67
|
+
/**
|
|
68
|
+
* If the logged user is a data owner get the current data owner and all of his parents.
|
|
69
|
+
* @throws if the current user is not a data owner.
|
|
70
|
+
* @return the current data owner hierarchy, starting from the topmost parent to the current data owner.
|
|
71
|
+
*/
|
|
72
|
+
getCurrentDataOwnerHierarchy(): Promise<DataOwnerWithType[]>;
|
|
73
|
+
/**
|
|
74
|
+
* If the logged user is a data owner get the type of the current data owner. This information is cached.
|
|
75
|
+
* @throws if the current user is not a data owner
|
|
76
|
+
*/
|
|
77
|
+
getCurrentDataOwnerType(): Promise<DataOwnerTypeEnum>;
|
|
78
|
+
/**
|
|
79
|
+
* Get the id of the data owner entity for a user.
|
|
80
|
+
* @param user a user that is also a data owner.
|
|
81
|
+
* @return the id of the data owner corresponding to the provided user.
|
|
82
|
+
* @throws if the user is not a data owner.
|
|
83
|
+
*/
|
|
84
|
+
getDataOwnerIdOf(user: User): string;
|
|
85
|
+
/**
|
|
86
|
+
* Get a data owner. Uses a cache to improve performance.
|
|
87
|
+
* @param ownerId id of the data owner to retrieve (patient, medical device, hcp, ...)
|
|
88
|
+
* @return the data owner or undefined if loadIfMissingFromCache is false and there is no data owner with provided id in cache.
|
|
89
|
+
* @throws if no data owner with the provided id could be found on an error occurred while attempting to retrieve it.
|
|
90
|
+
*/
|
|
91
|
+
getDataOwner(ownerId: string): Promise<DataOwnerWithType>;
|
|
92
|
+
/**
|
|
93
|
+
* Gets the public keys of a data owner in hex format.
|
|
94
|
+
* @param dataOwner a data owner.
|
|
95
|
+
* @return the public keys for the data owner in hex format.
|
|
96
|
+
*/
|
|
97
|
+
getHexPublicKeysOf(dataOwner: DataOwner): Set<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Clears the cache of current data owner id and parent hierarchy ids. The hierarchy of a data owner should not normally change over time, so this
|
|
100
|
+
* method should be rarely needed.
|
|
101
|
+
*/
|
|
102
|
+
clearCurrentDataOwnerIdsCache(): void;
|
|
103
|
+
/**
|
|
104
|
+
* @internal This method is intended only for internal use and may be changed without notice.
|
|
105
|
+
* Updates a data owner and its cached value.
|
|
106
|
+
* @param dataOwner a data owner with updated value.
|
|
107
|
+
* @return the updated data owner, with updated revision.
|
|
108
|
+
*/
|
|
109
|
+
updateDataOwner(dataOwner: DataOwnerWithType): Promise<DataOwnerWithType>;
|
|
110
|
+
private checkDataOwnerIntegrity;
|
|
111
|
+
private forceLoadCurrentDataOwnerHierarchyAndCacheIds;
|
|
112
|
+
private handleError;
|
|
14
113
|
}
|
|
@@ -9,13 +9,120 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.IccDataOwnerXApi = void 0;
|
|
12
|
+
exports.IccDataOwnerXApi = exports.DataOwnerTypeEnum = void 0;
|
|
13
|
+
const utils_1 = require("./crypto/utils");
|
|
14
|
+
const XHR_1 = require("../icc-api/api/XHR");
|
|
15
|
+
exports.DataOwnerTypeEnum = {
|
|
16
|
+
Patient: 'patient',
|
|
17
|
+
Device: 'device',
|
|
18
|
+
Hcp: 'hcp',
|
|
19
|
+
};
|
|
13
20
|
class IccDataOwnerXApi {
|
|
14
|
-
|
|
15
|
-
this.
|
|
21
|
+
get selfDataOwnerId() {
|
|
22
|
+
if (!this.currentDataOwnerHierarchyIds)
|
|
23
|
+
return undefined;
|
|
24
|
+
return this.currentDataOwnerHierarchyIds[this.currentDataOwnerHierarchyIds.length - 1];
|
|
25
|
+
}
|
|
26
|
+
constructor(userBaseApi, hcpartyBaseApi, //Init with a hcparty x api for better performances
|
|
27
|
+
patientBaseApi, deviceBaseApi) {
|
|
28
|
+
this.userBaseApi = userBaseApi;
|
|
29
|
+
this.hcpartyBaseApi = hcpartyBaseApi;
|
|
16
30
|
this.patientBaseApi = patientBaseApi;
|
|
31
|
+
this.deviceBaseApi = deviceBaseApi;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* If the logged user is a data owner get the current data owner. This information is cached without expiration, and will only be updated in case
|
|
35
|
+
* of forced refresh.
|
|
36
|
+
* @throws if the current user is not a data owner.
|
|
37
|
+
*/
|
|
38
|
+
getCurrentDataOwnerId() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (!this.currentDataOwnerHierarchyIds) {
|
|
41
|
+
yield this.getCurrentDataOwnerHierarchyIds();
|
|
42
|
+
}
|
|
43
|
+
return this.currentDataOwnerHierarchyIds[this.currentDataOwnerHierarchyIds.length - 1];
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* If the logged user is a data owner get its parent hierarchy. This information is cached without expiration, and will only be updated in case
|
|
48
|
+
* of forced refresh.
|
|
49
|
+
* The resulting array starts with the topmost parent (the only ancestor without a parent) and ends with the data owner itself.
|
|
50
|
+
* @throws if the current user is not a data owner.
|
|
51
|
+
*/
|
|
52
|
+
getCurrentDataOwnerHierarchyIds() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (!this.currentDataOwnerHierarchyIds) {
|
|
55
|
+
yield this.forceLoadCurrentDataOwnerHierarchyAndCacheIds();
|
|
56
|
+
}
|
|
57
|
+
return [...this.currentDataOwnerHierarchyIds];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the hierarchy for the current data owner starting from the specified parent.
|
|
62
|
+
* @throws an array starting at the topmost parent and ending at the provided parent id. If the provided id is not part of the hierarchy throws an
|
|
63
|
+
* error.
|
|
64
|
+
*/
|
|
65
|
+
getCurrentDataOwnerHierarchyIdsFrom(parentId) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
if (!this.currentDataOwnerHierarchyIds) {
|
|
68
|
+
yield this.getCurrentDataOwnerHierarchyIds();
|
|
69
|
+
}
|
|
70
|
+
const res = [];
|
|
71
|
+
for (const dataOwnerId of this.currentDataOwnerHierarchyIds) {
|
|
72
|
+
res.push(dataOwnerId);
|
|
73
|
+
if (dataOwnerId === parentId)
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`${parentId} is not part of the data owner hierarchy for the current user`);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* If the logged user is a data owner get the current data owner.
|
|
81
|
+
* @throws if the current user is not a data owner.
|
|
82
|
+
*/
|
|
83
|
+
getCurrentDataOwner() {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
if (!this.currentDataOwnerHierarchyIds) {
|
|
86
|
+
const dataOwnerHierarchy = yield this.forceLoadCurrentDataOwnerHierarchyAndCacheIds();
|
|
87
|
+
return dataOwnerHierarchy[dataOwnerHierarchy.length - 1];
|
|
88
|
+
}
|
|
89
|
+
else
|
|
90
|
+
return this.getDataOwner(yield this.getCurrentDataOwnerId());
|
|
91
|
+
});
|
|
17
92
|
}
|
|
18
|
-
|
|
93
|
+
/**
|
|
94
|
+
* If the logged user is a data owner get the current data owner and all of his parents.
|
|
95
|
+
* @throws if the current user is not a data owner.
|
|
96
|
+
* @return the current data owner hierarchy, starting from the topmost parent to the current data owner.
|
|
97
|
+
*/
|
|
98
|
+
getCurrentDataOwnerHierarchy() {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
if (!this.currentDataOwnerHierarchyIds) {
|
|
101
|
+
return yield this.forceLoadCurrentDataOwnerHierarchyAndCacheIds();
|
|
102
|
+
}
|
|
103
|
+
else
|
|
104
|
+
return Promise.all(this.currentDataOwnerHierarchyIds.map((id) => this.getDataOwner(id)));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* If the logged user is a data owner get the type of the current data owner. This information is cached.
|
|
109
|
+
* @throws if the current user is not a data owner
|
|
110
|
+
*/
|
|
111
|
+
getCurrentDataOwnerType() {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
if (!this.currentDataOwnerHierarchyIds) {
|
|
114
|
+
yield this.forceLoadCurrentDataOwnerHierarchyAndCacheIds();
|
|
115
|
+
}
|
|
116
|
+
return this.currentDataOwnerType;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the id of the data owner entity for a user.
|
|
121
|
+
* @param user a user that is also a data owner.
|
|
122
|
+
* @return the id of the data owner corresponding to the provided user.
|
|
123
|
+
* @throws if the user is not a data owner.
|
|
124
|
+
*/
|
|
125
|
+
getDataOwnerIdOf(user) {
|
|
19
126
|
var _a, _b;
|
|
20
127
|
const dataOwnerId = (_b = (_a = user.healthcarePartyId) !== null && _a !== void 0 ? _a : user.patientId) !== null && _b !== void 0 ? _b : user.deviceId;
|
|
21
128
|
if (dataOwnerId == undefined) {
|
|
@@ -23,22 +130,89 @@ class IccDataOwnerXApi {
|
|
|
23
130
|
}
|
|
24
131
|
return dataOwnerId;
|
|
25
132
|
}
|
|
26
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Get a data owner. Uses a cache to improve performance.
|
|
135
|
+
* @param ownerId id of the data owner to retrieve (patient, medical device, hcp, ...)
|
|
136
|
+
* @return the data owner or undefined if loadIfMissingFromCache is false and there is no data owner with provided id in cache.
|
|
137
|
+
* @throws if no data owner with the provided id could be found on an error occurred while attempting to retrieve it.
|
|
138
|
+
*/
|
|
139
|
+
getDataOwner(ownerId) {
|
|
27
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
141
|
+
const _url = this.userBaseApi.host + `/dataowner/` + ownerId + '?ts=' + new Date().getTime();
|
|
142
|
+
let headers = this.userBaseApi.headers;
|
|
143
|
+
return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.userBaseApi.fetchImpl, undefined, this.userBaseApi.authenticationProvider.getAuthService())
|
|
144
|
+
.then((doc) => doc.body)
|
|
145
|
+
.then((dowt) => {
|
|
146
|
+
if (dowt.dataOwner.id === this.selfDataOwnerId)
|
|
147
|
+
this.checkDataOwnerIntegrity(dowt.dataOwner);
|
|
148
|
+
return dowt;
|
|
149
|
+
})
|
|
150
|
+
.catch((err) => this.handleError(err));
|
|
35
151
|
});
|
|
36
152
|
}
|
|
37
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Gets the public keys of a data owner in hex format.
|
|
155
|
+
* @param dataOwner a data owner.
|
|
156
|
+
* @return the public keys for the data owner in hex format.
|
|
157
|
+
*/
|
|
158
|
+
getHexPublicKeysOf(dataOwner) {
|
|
159
|
+
return (0, utils_1.hexPublicKeysOf)(dataOwner);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Clears the cache of current data owner id and parent hierarchy ids. The hierarchy of a data owner should not normally change over time, so this
|
|
163
|
+
* method should be rarely needed.
|
|
164
|
+
*/
|
|
165
|
+
clearCurrentDataOwnerIdsCache() {
|
|
166
|
+
this.currentDataOwnerHierarchyIds = undefined;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @internal This method is intended only for internal use and may be changed without notice.
|
|
170
|
+
* Updates a data owner and its cached value.
|
|
171
|
+
* @param dataOwner a data owner with updated value.
|
|
172
|
+
* @return the updated data owner, with updated revision.
|
|
173
|
+
*/
|
|
174
|
+
updateDataOwner(dataOwner) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const ownerType = dataOwner.type;
|
|
177
|
+
const ownerToUpdate = dataOwner.dataOwner;
|
|
178
|
+
if (ownerType === 'hcp') {
|
|
179
|
+
return yield this.hcpartyBaseApi
|
|
180
|
+
.modifyHealthcareParty(ownerToUpdate)
|
|
181
|
+
.then((x) => ({ type: 'hcp', dataOwner: x }));
|
|
182
|
+
}
|
|
183
|
+
else if (ownerType === 'patient') {
|
|
184
|
+
return yield this.patientBaseApi.modifyPatient(ownerToUpdate).then((x) => ({ type: 'patient', dataOwner: x }));
|
|
185
|
+
}
|
|
186
|
+
else if (ownerType === 'device') {
|
|
187
|
+
return yield this.deviceBaseApi.updateDevice(ownerToUpdate).then((x) => ({ type: 'device', dataOwner: x }));
|
|
188
|
+
}
|
|
189
|
+
else
|
|
190
|
+
throw new Error(`Unrecognised data owner type: ${ownerType}`);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
checkDataOwnerIntegrity(dataOwner) {
|
|
194
|
+
const keys = this.getHexPublicKeysOf(dataOwner);
|
|
195
|
+
if (new Set(Array.from(keys).map((x) => x.slice(-32))).size != keys.size)
|
|
196
|
+
throw new Error(`Different public keys for ${dataOwner.id} have the same fingerprint; this should not happen in normal circumstances. Please report this error to iCure.`);
|
|
197
|
+
}
|
|
198
|
+
forceLoadCurrentDataOwnerHierarchyAndCacheIds() {
|
|
38
199
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
|
|
200
|
+
const currentUser = yield this.userBaseApi.getCurrentUser();
|
|
201
|
+
let curr = yield this.getDataOwner(this.getDataOwnerIdOf(currentUser));
|
|
202
|
+
this.checkDataOwnerIntegrity(curr.dataOwner);
|
|
203
|
+
this.currentDataOwnerType = curr.type;
|
|
204
|
+
let res = [curr];
|
|
205
|
+
while (curr.dataOwner.parentId) {
|
|
206
|
+
curr = yield this.getDataOwner(curr.dataOwner.parentId);
|
|
207
|
+
res = [curr, ...res];
|
|
208
|
+
}
|
|
209
|
+
this.currentDataOwnerHierarchyIds = res.map((x) => x.dataOwner.id);
|
|
210
|
+
return res;
|
|
40
211
|
});
|
|
41
212
|
}
|
|
213
|
+
handleError(e) {
|
|
214
|
+
throw e;
|
|
215
|
+
}
|
|
42
216
|
}
|
|
43
217
|
exports.IccDataOwnerXApi = IccDataOwnerXApi;
|
|
44
218
|
//# sourceMappingURL=icc-data-owner-x-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-data-owner-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-data-owner-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,MAAa,gBAAgB;IAI3B,YAAY,MAAqB,EAAE,cAA6B;QAC9D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACtC,CAAC;IAED,cAAc,CAAC,IAAU;;QACvB,MAAM,WAAW,GAAG,MAAA,MAAA,IAAI,CAAC,iBAAiB,mCAAI,IAAI,CAAC,SAAS,mCAAI,IAAI,CAAC,QAAQ,CAAA;QAC7E,IAAI,WAAW,IAAI,SAAS,EAAE;YAC5B,MAAM,KAAK,CAAC,QAAQ,IAAI,CAAC,EAAE,sBAAsB,CAAC,CAAA;SACnD;QACD,OAAO,WAAW,CAAA;IACpB,CAAC;IAEa,YAAY,CAAC,WAAmB,EAAE,WAAiD;;YAC/F,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE;gBAC7E,MAAM,QAAQ,GAAI,SAA6B,CAAC,QAAQ,CAAA;gBACxD,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;oBACpF,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;iBACrE;gBACD,OAAO,IAAI,CAAA;YACb,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IAEK,WAAW,CAAC,SAAe,EAAE,WAAiD;;YAClF,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,WAAW,CAAC,CAAA;QACvE,CAAC;KAAA;CACF;AA9BD,4CA8BC","sourcesContent":["import { User } from '../icc-api/model/User'\nimport { IccPatientApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport { Delegation } from '../icc-api/model/Delegation'\n\nexport class IccDataOwnerXApi {\n crypto: IccCryptoXApi\n private patientBaseApi: IccPatientApi\n\n constructor(crypto: IccCryptoXApi, patientBaseApi: IccPatientApi) {\n this.crypto = crypto\n this.patientBaseApi = patientBaseApi\n }\n\n getDataOwnerOf(user: User): string {\n const dataOwnerId = user.healthcarePartyId ?? user.patientId ?? user.deviceId\n if (dataOwnerId == undefined) {\n throw Error(`User ${user.id} is not a data owner`)\n }\n return dataOwnerId\n }\n\n private async _hasAccessTo(dataOwnerId: string, delegations: { [key: string]: Array<Delegation> }): Promise<boolean> {\n return this.crypto.getDataOwner(dataOwnerId).then(({ dataOwner: dataOwner }) => {\n const parentId = (dataOwner as HealthcareParty).parentId\n if (!dataOwner.id || !delegations[dataOwner.id] || !delegations[dataOwner.id].length) {\n return !!parentId ? this._hasAccessTo(parentId, delegations) : false\n }\n return true\n })\n }\n\n async hasAccessTo(dataOwner: User, delegations: { [key: string]: Array<Delegation> }): Promise<boolean> {\n return this._hasAccessTo(this.getDataOwnerOf(dataOwner), delegations)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-data-owner-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-data-owner-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,0CAAgD;AAEhD,4CAAwC;AAM3B,QAAA,iBAAiB,GAAyC;IACrE,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;CACX,CAAA;AAgBD,MAAa,gBAAgB;IAQ3B,IAAY,eAAe;QACzB,IAAI,CAAC,IAAI,CAAC,4BAA4B;YAAE,OAAO,SAAS,CAAA;QACxD,OAAO,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,4BAA4B,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACxF,CAAC;IAED,YACE,WAAuB,EACvB,cAA8B,EAAE,mDAAmD;IACnF,cAA6B,EAC7B,aAA2B;QAE3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED;;;;OAIG;IACG,qBAAqB;;YACzB,IAAI,CAAC,IAAI,CAAC,4BAA4B,EAAE;gBACtC,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAA;aAC7C;YACD,OAAO,IAAI,CAAC,4BAA6B,CAAC,IAAI,CAAC,4BAA6B,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC1F,CAAC;KAAA;IAED;;;;;OAKG;IACG,+BAA+B;;YACnC,IAAI,CAAC,IAAI,CAAC,4BAA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c-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport { Patient } from '../icc-api/model/Patient'\nimport { Device } from '../icc-api/model/Device'\nimport { hexPublicKeysOf } from './crypto/utils'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { XHR } from '../icc-api/api/XHR'\n\n/**\n * Represents a type of data owner.\n */\nexport type DataOwnerTypeEnum = 'patient' | 'device' | 'hcp'\nexport const DataOwnerTypeEnum: { [key: string]: DataOwnerTypeEnum } = {\n Patient: 'patient',\n Device: 'device',\n Hcp: 'hcp',\n}\n\n/**\n * Represents any data owner.\n */\n// Trick to make typechecking work: without this you can pass anything to a data owner\nexport type DataOwner = (Patient | Device | HealthcareParty) & { id: string }\n\n/**\n * Represents any data owner enriched with type information.\n */\nexport type DataOwnerWithType =\n | { type: 'patient'; dataOwner: Patient & DataOwner }\n | { type: 'device'; dataOwner: Device & DataOwner }\n | { type: 'hcp'; dataOwner: HealthcareParty & DataOwner }\n\nexport class IccDataOwnerXApi {\n private readonly userBaseApi: IccUserApi\n private readonly hcpartyBaseApi: IccHcpartyXApi\n private readonly patientBaseApi: IccPatientApi\n private readonly deviceBaseApi: IccDeviceApi\n private currentDataOwnerType: DataOwnerTypeEnum | undefined\n private currentDataOwnerHierarchyIds: string[] | undefined\n\n private get selfDataOwnerId(): string | undefined {\n if (!this.currentDataOwnerHierarchyIds) return undefined\n return this.currentDataOwnerHierarchyIds[this.currentDataOwnerHierarchyIds.length - 1]\n }\n\n constructor(\n userBaseApi: IccUserApi,\n hcpartyBaseApi: IccHcpartyXApi, //Init with a hcparty x api for better performances\n patientBaseApi: IccPatientApi,\n deviceBaseApi: IccDeviceApi\n ) {\n this.userBaseApi = userBaseApi\n this.hcpartyBaseApi = hcpartyBaseApi\n this.patientBaseApi = patientBaseApi\n this.deviceBaseApi = deviceBaseApi\n }\n\n /**\n * If the logged user is a data owner get the current data owner. This information is cached without expiration, and will only be updated in case\n * of forced refresh.\n * @throws if the current user is not a data owner.\n */\n async getCurrentDataOwnerId(): Promise<string> {\n if (!this.currentDataOwnerHierarchyIds) {\n await this.getCurrentDataOwnerHierarchyIds()\n }\n return this.currentDataOwnerHierarchyIds![this.currentDataOwnerHierarchyIds!.length - 1]\n }\n\n /**\n * If the logged user is a data owner get its parent hierarchy. This information is cached without expiration, and will only be updated in case\n * of forced refresh.\n * The resulting array starts with the topmost parent (the only ancestor without a parent) and ends with the data owner itself.\n * @throws if the current user is not a data owner.\n */\n async getCurrentDataOwnerHierarchyIds(): Promise<string[]> {\n if (!this.currentDataOwnerHierarchyIds) {\n await this.forceLoadCurrentDataOwnerHierarchyAndCacheIds()\n }\n return [...this.currentDataOwnerHierarchyIds!]\n }\n\n /**\n * Get the hierarchy for the current data owner starting from the specified parent.\n * @throws an array starting at the topmost parent and ending at the provided parent id. If the provided id is not part of the hierarchy throws an\n * error.\n */\n async getCurrentDataOwnerHierarchyIdsFrom(parentId: string): Promise<string[]> {\n if (!this.currentDataOwnerHierarchyIds) {\n await this.getCurrentDataOwnerHierarchyIds()\n }\n const res = []\n for (const dataOwnerId of this.currentDataOwnerHierarchyIds!) {\n res.push(dataOwnerId)\n if (dataOwnerId === parentId) return res\n }\n throw new Error(`${parentId} is not part of the data owner hierarchy for the current user`)\n }\n\n /**\n * If the logged user is a data owner get the current data owner.\n * @throws if the current user is not a data owner.\n */\n async getCurrentDataOwner(): Promise<DataOwnerWithType> {\n if (!this.currentDataOwnerHierarchyIds) {\n const dataOwnerHierarchy = await this.forceLoadCurrentDataOwnerHierarchyAndCacheIds()\n return dataOwnerHierarchy[dataOwnerHierarchy.length - 1]\n } else return this.getDataOwner(await this.getCurrentDataOwnerId())\n }\n\n /**\n * If the logged user is a data owner get the current data owner and all of his parents.\n * @throws if the current user is not a data owner.\n * @return the current data owner hierarchy, starting from the topmost parent to the current data owner.\n */\n async getCurrentDataOwnerHierarchy(): Promise<DataOwnerWithType[]> {\n if (!this.currentDataOwnerHierarchyIds) {\n return await this.forceLoadCurrentDataOwnerHierarchyAndCacheIds()\n } else return Promise.all(this.currentDataOwnerHierarchyIds!.map((id) => this.getDataOwner(id)))\n }\n\n /**\n * If the logged user is a data owner get the type of the current data owner. This information is cached.\n * @throws if the current user is not a data owner\n */\n async getCurrentDataOwnerType(): Promise<DataOwnerTypeEnum> {\n if (!this.currentDataOwnerHierarchyIds) {\n await this.forceLoadCurrentDataOwnerHierarchyAndCacheIds()\n }\n return this.currentDataOwnerType!\n }\n\n /**\n * Get the id of the data owner entity for a user.\n * @param user a user that is also a data owner.\n * @return the id of the data owner corresponding to the provided user.\n * @throws if the user is not a data owner.\n */\n getDataOwnerIdOf(user: User): string {\n const dataOwnerId = user.healthcarePartyId ?? user.patientId ?? user.deviceId\n if (dataOwnerId == undefined) {\n throw Error(`User ${user.id} is not a data owner`)\n }\n return dataOwnerId\n }\n\n /**\n * Get a data owner. Uses a cache to improve performance.\n * @param ownerId id of the data owner to retrieve (patient, medical device, hcp, ...)\n * @return the data owner or undefined if loadIfMissingFromCache is false and there is no data owner with provided id in cache.\n * @throws if no data owner with the provided id could be found on an error occurred while attempting to retrieve it.\n */\n async getDataOwner(ownerId: string): Promise<DataOwnerWithType> {\n const _url = this.userBaseApi.host + `/dataowner/` + ownerId + '?ts=' + new Date().getTime()\n let headers = this.userBaseApi.headers\n return XHR.sendCommand(\n 'GET',\n _url,\n headers,\n null,\n this.userBaseApi.fetchImpl,\n undefined,\n this.userBaseApi.authenticationProvider.getAuthService()\n )\n .then((doc) => doc.body as DataOwnerWithType)\n .then((dowt) => {\n if (dowt.dataOwner.id === this.selfDataOwnerId) this.checkDataOwnerIntegrity(dowt.dataOwner)\n return dowt\n })\n .catch((err) => this.handleError(err))\n }\n\n /**\n * Gets the public keys of a data owner in hex format.\n * @param dataOwner a data owner.\n * @return the public keys for the data owner in hex format.\n */\n getHexPublicKeysOf(dataOwner: DataOwner): Set<string> {\n return hexPublicKeysOf(dataOwner)\n }\n\n /**\n * Clears the cache of current data owner id and parent hierarchy ids. The hierarchy of a data owner should not normally change over time, so this\n * method should be rarely needed.\n */\n clearCurrentDataOwnerIdsCache() {\n this.currentDataOwnerHierarchyIds = undefined\n }\n\n /**\n * @internal This method is intended only for internal use and may be changed without notice.\n * Updates a data owner and its cached value.\n * @param dataOwner a data owner with updated value.\n * @return the updated data owner, with updated revision.\n */\n async updateDataOwner(dataOwner: DataOwnerWithType): Promise<DataOwnerWithType> {\n const ownerType = dataOwner.type\n const ownerToUpdate = dataOwner.dataOwner\n if (ownerType === 'hcp') {\n return await this.hcpartyBaseApi\n .modifyHealthcareParty(ownerToUpdate as HealthcareParty)\n .then((x) => ({ type: 'hcp', dataOwner: x } as DataOwnerWithType))\n } else if (ownerType === 'patient') {\n return await this.patientBaseApi.modifyPatient(ownerToUpdate as Patient).then((x) => ({ type: 'patient', dataOwner: x } as DataOwnerWithType))\n } else if (ownerType === 'device') {\n return await this.deviceBaseApi.updateDevice(ownerToUpdate as Device).then((x) => ({ type: 'device', dataOwner: x } as DataOwnerWithType))\n } else throw new Error(`Unrecognised data owner type: ${ownerType}`)\n }\n\n private checkDataOwnerIntegrity(dataOwner: DataOwner) {\n const keys = this.getHexPublicKeysOf(dataOwner)\n if (new Set(Array.from(keys).map((x) => x.slice(-32))).size != keys.size)\n throw new Error(\n `Different public keys for ${dataOwner.id} have the same fingerprint; this should not happen in normal circumstances. Please report this error to iCure.`\n )\n }\n\n private async forceLoadCurrentDataOwnerHierarchyAndCacheIds(): Promise<DataOwnerWithType[]> {\n const currentUser = await this.userBaseApi.getCurrentUser()\n let curr = await this.getDataOwner(this.getDataOwnerIdOf(currentUser))\n this.checkDataOwnerIntegrity(curr.dataOwner)\n this.currentDataOwnerType = curr.type\n let res = [curr]\n while ((curr.dataOwner as HealthcareParty).parentId) {\n curr = await this.getDataOwner((curr.dataOwner as HealthcareParty).parentId!)\n res = [curr, ...res]\n }\n this.currentDataOwnerHierarchyIds = res.map((x) => x.dataOwner.id!)\n return res\n }\n\n private handleError(e: XHR.XHRError): never {\n throw e\n }\n}\n"]}
|
|
@@ -21,19 +21,19 @@ class IccDoctemplateXApi extends icc_api_1.IccDoctemplateApi {
|
|
|
21
21
|
newInstance(user, template, c) {
|
|
22
22
|
return new Promise((resolve, reject) => {
|
|
23
23
|
const documentTemplate = (0, lodash_1.extend)({
|
|
24
|
-
id: this.crypto.randomUuid(),
|
|
24
|
+
id: this.crypto.primitives.randomUuid(),
|
|
25
25
|
_type: 'org.taktik.icure.entities.DocumentTemplate',
|
|
26
26
|
owner: user.id,
|
|
27
27
|
created: new Date().getTime(),
|
|
28
28
|
modified: new Date().getTime(),
|
|
29
|
-
guid: this.crypto.randomUuid(),
|
|
29
|
+
guid: this.crypto.primitives.randomUuid(),
|
|
30
30
|
group: null,
|
|
31
31
|
specialty: null,
|
|
32
32
|
attachment: (0, binary_utils_1.string2ua)(template),
|
|
33
33
|
mainUti: 'public.plain-text',
|
|
34
34
|
}, c || {});
|
|
35
35
|
if (documentTemplate.group && documentTemplate.group.guid == null) {
|
|
36
|
-
documentTemplate.group.guid = this.crypto.randomUuid();
|
|
36
|
+
documentTemplate.group.guid = this.crypto.primitives.randomUuid();
|
|
37
37
|
}
|
|
38
38
|
//sauver l doctemplate vide
|
|
39
39
|
if (template) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-doctemplate-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-doctemplate-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAG9C,mCAA+B;AAG/B,uDAAgD;AAChD,4CAAwC;AACxC,0EAAgG;AAEhG,qCAAqC;AACrC,MAAa,kBAAmB,SAAQ,2BAAiB;IAKvD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAA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,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;IAC1C,CAAC;CACF;AA5FD,gDA4FC","sourcesContent":["import { IccDoctemplateApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport { extend } from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { DocumentTemplate } from '../icc-api/model/models'\nimport { string2ua } from './utils/binary-utils'\nimport { XHR } from '../icc-api/api/XHR'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccDoctemplateXApi extends IccDoctemplateApi {\n crypto: IccCryptoXApi\n authenticationProvider: AuthenticationProvider\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\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, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.authenticationProvider = authenticationProvider\n this.fetchImpl = fetchImpl\n }\n\n newInstance(user: models.User, template: string, c: any): Promise<DocumentTemplate> {\n return new Promise<DocumentTemplate>((resolve, reject) => {\n const documentTemplate: DocumentTemplate = extend(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.DocumentTemplate',\n owner: user.id,\n created: new Date().getTime(),\n modified: new Date().getTime(),\n guid: this.crypto.primitives.randomUuid(),\n group: null,\n specialty: null,\n attachment: string2ua(template),\n mainUti: 'public.plain-text',\n },\n c || {}\n )\n if (documentTemplate.group && documentTemplate.group.guid == null) {\n documentTemplate.group.guid = this.crypto.primitives.randomUuid()\n }\n\n //sauver l doctemplate vide\n\n if (template) {\n //save attachement\n }\n\n return resolve(documentTemplate)\n })\n }\n\n // noinspection JSUnusedLocalSymbols\n findAllByOwnerId(ownerId: string): Promise<Array<models.DocumentTemplate>> {\n return new Promise(function (resolve, reject) {\n reject(console.log('findByHCPartyPatientSecretFKeys not implemented in document API!'))\n })\n }\n\n // noinspection JSUnusedGlobalSymbols\n getAttachmentUrl(documentId: string, attachmentId: string) {\n return (\n this.host + '/doctemplate/{documentId}/attachment/{attachmentId}'.replace('{documentId}', documentId).replace('{attachmentId}', attachmentId)\n )\n }\n\n getAttachmentText(documentTemplateId: string, attachmentId: string): Promise<any | boolean> {\n const _body = null\n\n const _url =\n this.host +\n '/doctemplate/{documentTemplateId}/attachmentText/{attachmentId}'\n .replace('{documentTemplateId}', documentTemplateId + '')\n .replace('{attachmentId}', attachmentId + '') +\n '?ts=' +\n new Date().getTime()\n\n return XHR.sendCommand('GET', _url, this.headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())\n .then((doc) => {\n if (doc.contentType.startsWith('application/octet-stream')) {\n const enc = new TextDecoder('utf-8')\n const arr = new Uint8Array(doc.body)\n return enc.decode(arr)\n } else if (doc.contentType.startsWith('text/plain') || doc.contentType.startsWith('text/html') || doc.contentType.startsWith('text/xml')) {\n return doc.body\n } else {\n return false\n }\n })\n .catch((err) => this.handleError(err))\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { IccCryptoXApi } from './icc-crypto-x-api';
|
|
|
3
3
|
import * as models from '../icc-api/model/models';
|
|
4
4
|
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
5
5
|
import { AuthenticationProvider } from './auth/AuthenticationProvider';
|
|
6
|
+
import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour';
|
|
6
7
|
export declare class IccDocumentXApi extends IccDocumentApi {
|
|
7
8
|
private crypto;
|
|
8
9
|
private authApi;
|
|
@@ -25,11 +26,27 @@ export declare class IccDocumentXApi extends IccDocumentApi {
|
|
|
25
26
|
constructor(host: string, headers: {
|
|
26
27
|
[key: string]: string;
|
|
27
28
|
}, crypto: IccCryptoXApi, authApi: IccAuthApi, dataOwnerApi: IccDataOwnerXApi, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new instance of document with initialised encryption metadata (not in the database).
|
|
31
|
+
* @param user the current user.
|
|
32
|
+
* @param message the message this document refers to.
|
|
33
|
+
* @param c initialised data for the document. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
|
|
34
|
+
* other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
|
|
35
|
+
* @param options optional parameters:
|
|
36
|
+
* - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
|
|
37
|
+
* auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with
|
|
38
|
+
* auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
|
|
39
|
+
* access will be possible.
|
|
40
|
+
* - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
|
|
41
|
+
* secret id of patient known by the topmost parent in the current data owner hierarchy.
|
|
42
|
+
* @return a new instance of document.
|
|
43
|
+
*/
|
|
44
|
+
newInstance(user: models.User, message?: models.Message, c?: any, options?: {
|
|
45
|
+
additionalDelegates?: {
|
|
46
|
+
[dataOwnerId: string]: 'WRITE';
|
|
47
|
+
};
|
|
48
|
+
preferredSfk?: string;
|
|
49
|
+
}): Promise<models.Document>;
|
|
33
50
|
findByMessage(hcpartyId: string, message: models.Message): Promise<models.Document[]>;
|
|
34
51
|
decrypt(hcpartyId: string, documents: Array<models.Document>): Promise<Array<models.Document>>;
|
|
35
52
|
getAttachmentAs(documentId: string, attachmentId: string, returnType: "application/octet-stream", enckeys?: string, fileName?: string): Promise<ArrayBuffer>;
|
|
@@ -41,4 +58,58 @@ export declare class IccDocumentXApi extends IccDocumentApi {
|
|
|
41
58
|
}>, fileName?: string): Promise<string>;
|
|
42
59
|
uti(mimeType: string, extension: string): string;
|
|
43
60
|
mimeType(uti: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Adds an attachment to a document, encrypting it on client side using the encryption keys of the provided document.
|
|
63
|
+
* @param document a document.
|
|
64
|
+
* @param attachment a new main attachment for the document.
|
|
65
|
+
* @return the updated document.
|
|
66
|
+
*/
|
|
67
|
+
encryptAndSetDocumentAttachment(document: models.Document, attachment: ArrayBuffer | Uint8Array): Promise<models.Document>;
|
|
68
|
+
/**
|
|
69
|
+
* Adds a secondary attachment to a document, encrypting it on client side using the encryption keys of the provided document.
|
|
70
|
+
* @param document a document.
|
|
71
|
+
* @param secondaryAttachmentKey key for the secondary attachment.
|
|
72
|
+
* @param attachment a new secondary attachment for the document.
|
|
73
|
+
* @return the updated document.
|
|
74
|
+
*/
|
|
75
|
+
encryptAndSetSecondaryDocumentAttachment(document: models.Document, secondaryAttachmentKey: string, attachment: ArrayBuffer | Uint8Array): Promise<models.Document>;
|
|
76
|
+
/**
|
|
77
|
+
* Gets the main attachment of a document and tries to decrypt it using the encryption keys of the document.
|
|
78
|
+
* @param document a document.
|
|
79
|
+
* @param validator optionally a validator function which checks if the decryption was successful. In cases where the document has many encryption
|
|
80
|
+
* keys and it is unclear which one should be used this function can help to detect bad decryptions.
|
|
81
|
+
* @return the decrypted attachment, if it could be decrypted, else the encrypted attachment.
|
|
82
|
+
*/
|
|
83
|
+
getAndDecryptDocumentAttachment(document: models.Document, validator?: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer>;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the secondary attachment of a document and tries to decrypt it using the encryption keys of the document.
|
|
86
|
+
* @param document a document.
|
|
87
|
+
* @param secondaryAttachmentKey key of the secondary attachment.
|
|
88
|
+
* @param validator optionally a validator function which checks if the decryption was successful. In cases where the document has many encryption
|
|
89
|
+
* keys and it is unclear which one should be used this function can help to detect bad decryptions.
|
|
90
|
+
* @return the decrypted attachment, if it could be decrypted, else the encrypted attachment.
|
|
91
|
+
*/
|
|
92
|
+
getAndDecryptSecondaryDocumentAttachment(document: models.Document, secondaryAttachmentKey: string, validator?: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer>;
|
|
93
|
+
/**
|
|
94
|
+
* @param document a document
|
|
95
|
+
* @return the id of the message that the document refers to, retrieved from the encrypted metadata. Normally there should only be one element
|
|
96
|
+
* in the returned array, but in case of entity merges there could be multiple values.
|
|
97
|
+
*/
|
|
98
|
+
decryptMessageIdOf(document: models.Document): Promise<string[]>;
|
|
99
|
+
/**
|
|
100
|
+
* Share an existing document with other data owners, allowing them to access the non-encrypted data of the document and optionally also
|
|
101
|
+
* the encrypted content.
|
|
102
|
+
* @param delegateId the id of the data owner which will be granted access to the document.
|
|
103
|
+
* @param document the document to share.
|
|
104
|
+
* @param options optional parameters to customize the sharing behaviour:
|
|
105
|
+
* - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
|
|
106
|
+
* content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}).
|
|
107
|
+
* - shareMessageId: specifies if the id of the message that this document refers to should be shared with the delegate (defaults to
|
|
108
|
+
* {@link ShareMetadataBehaviour.IF_AVAILABLE}).
|
|
109
|
+
* @return a promise which will contain the updated document.
|
|
110
|
+
*/
|
|
111
|
+
shareWith(delegateId: string, document: models.Document, options?: {
|
|
112
|
+
shareEncryptionKey?: ShareMetadataBehaviour;
|
|
113
|
+
shareMessageId?: ShareMetadataBehaviour;
|
|
114
|
+
}): Promise<models.Document>;
|
|
44
115
|
}
|