@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
|
@@ -3,17 +3,34 @@ 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 IccFormXApi extends IccFormApi {
|
|
7
8
|
crypto: IccCryptoXApi;
|
|
8
9
|
dataOwnerApi: IccDataOwnerXApi;
|
|
9
10
|
constructor(host: string, headers: {
|
|
10
11
|
[key: string]: string;
|
|
11
12
|
}, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new instance of form with initialised encryption metadata (not in the database).
|
|
15
|
+
* @param user the current user.
|
|
16
|
+
* @param patient the patient this form refers to.
|
|
17
|
+
* @param c initialised data for the form. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
|
|
18
|
+
* other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
|
|
19
|
+
* @param options optional parameters:
|
|
20
|
+
* - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
|
|
21
|
+
* 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
|
|
22
|
+
* auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
|
|
23
|
+
* access will be possible.
|
|
24
|
+
* - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
|
|
25
|
+
* secret id of patient known by the topmost parent in the current data owner hierarchy.
|
|
26
|
+
* @return a new instance of form.
|
|
27
|
+
*/
|
|
28
|
+
newInstance(user: models.User, patient: models.Patient, c?: any, options?: {
|
|
29
|
+
additionalDelegates?: {
|
|
30
|
+
[dataOwnerId: string]: 'WRITE';
|
|
31
|
+
};
|
|
32
|
+
preferredSfk?: string;
|
|
33
|
+
}): Promise<models.Form>;
|
|
17
34
|
/**
|
|
18
35
|
* 1. Check whether there is a delegation with 'hcpartyId' or not.
|
|
19
36
|
* 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.
|
|
@@ -30,6 +47,29 @@ export declare class IccFormXApi extends IccFormApi {
|
|
|
30
47
|
* @param patient
|
|
31
48
|
* @param usingPost (Promise)
|
|
32
49
|
*/
|
|
33
|
-
findBy(hcpartyId: string, patient: models.Patient, usingPost?: boolean): Promise<
|
|
34
|
-
decrypt(hcpartyId: string, forms: Array<models.Form>): Promise<
|
|
50
|
+
findBy(hcpartyId: string, patient: models.Patient, usingPost?: boolean): Promise<models.Form[]>;
|
|
51
|
+
decrypt(hcpartyId: string, forms: Array<models.Form>): Promise<models.Form[]>;
|
|
52
|
+
/**
|
|
53
|
+
* @param form a form
|
|
54
|
+
* @return the id of the patient that the form refers to, retrieved from the encrypted metadata. Normally there should only be one element
|
|
55
|
+
* in the returned array, but in case of entity merges there could be multiple values.
|
|
56
|
+
*/
|
|
57
|
+
decryptPatientIdOf(form: models.Form): Promise<string[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also
|
|
60
|
+
* the encrypted content.
|
|
61
|
+
* @param delegateId the id of the data owner which will be granted access to the form.
|
|
62
|
+
* @param form the form to share.
|
|
63
|
+
* @param options optional parameters to customize the sharing behaviour:
|
|
64
|
+
* - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
|
|
65
|
+
* content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
|
|
66
|
+
* form does not have encrypted content.
|
|
67
|
+
* - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to
|
|
68
|
+
* {@link ShareMetadataBehaviour.IF_AVAILABLE}).
|
|
69
|
+
* @return a promise which will contain the updated form.
|
|
70
|
+
*/
|
|
71
|
+
shareWith(delegateId: string, form: models.Form, options?: {
|
|
72
|
+
shareEncryptionKey?: ShareMetadataBehaviour;
|
|
73
|
+
sharePatientId?: ShareMetadataBehaviour;
|
|
74
|
+
}): Promise<models.Form>;
|
|
35
75
|
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.IccFormXApi = void 0;
|
|
4
13
|
const icc_api_1 = require("../icc-api");
|
|
5
14
|
const _ = require("lodash");
|
|
6
|
-
const
|
|
15
|
+
const models = require("../icc-api/model/models");
|
|
7
16
|
const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
|
|
8
17
|
// noinspection JSUnusedGlobalSymbols
|
|
9
18
|
class IccFormXApi extends icc_api_1.IccFormApi {
|
|
@@ -16,57 +25,46 @@ class IccFormXApi extends icc_api_1.IccFormApi {
|
|
|
16
25
|
this.crypto = crypto;
|
|
17
26
|
this.dataOwnerApi = dataOwnerApi;
|
|
18
27
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
delegations: dels.delegations,
|
|
60
|
-
cryptedForeignKeys: dels.cryptedForeignKeys,
|
|
61
|
-
secretForeignKeys: dels.secretForeignKeys,
|
|
62
|
-
encryptionKeys: eks.encryptionKeys,
|
|
63
|
-
});
|
|
64
|
-
let promise = Promise.resolve(form);
|
|
65
|
-
_.uniq(delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])).forEach((delegateId) => (promise = promise.then((form) => this.crypto.addDelegationsAndEncryptionKeys(patient, form, dataOwnerId, delegateId, dels.secretId, eks.secretId).catch((e) => {
|
|
66
|
-
console.log(e);
|
|
67
|
-
return form;
|
|
68
|
-
}))));
|
|
69
|
-
return promise;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new instance of form with initialised encryption metadata (not in the database).
|
|
30
|
+
* @param user the current user.
|
|
31
|
+
* @param patient the patient this form refers to.
|
|
32
|
+
* @param c initialised data for the form. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
|
|
33
|
+
* other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
|
|
34
|
+
* @param options optional parameters:
|
|
35
|
+
* - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
|
|
36
|
+
* 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
|
|
37
|
+
* auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
|
|
38
|
+
* access will be possible.
|
|
39
|
+
* - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
|
|
40
|
+
* secret id of patient known by the topmost parent in the current data owner hierarchy.
|
|
41
|
+
* @return a new instance of form.
|
|
42
|
+
*/
|
|
43
|
+
newInstance(user, patient, c = {}, options = {}) {
|
|
44
|
+
var _a, _b, _c, _d, _e, _f;
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const form = _.extend({
|
|
47
|
+
id: this.crypto.randomUuid(),
|
|
48
|
+
_type: 'org.taktik.icure.entities.Form',
|
|
49
|
+
created: new Date().getTime(),
|
|
50
|
+
modified: new Date().getTime(),
|
|
51
|
+
responsible: this.dataOwnerApi.getDataOwnerIdOf(user),
|
|
52
|
+
author: user.id,
|
|
53
|
+
codes: [],
|
|
54
|
+
tags: [],
|
|
55
|
+
}, c || {});
|
|
56
|
+
const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
|
|
57
|
+
if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
|
|
58
|
+
throw new Error('Can only initialise entities as current data owner.');
|
|
59
|
+
const sfk = (_a = options.preferredSfk) !== null && _a !== void 0 ? _a : (yield this.crypto.confidential.getAnySecretIdSharedWithParents(patient));
|
|
60
|
+
if (!sfk)
|
|
61
|
+
throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
|
|
62
|
+
const extraDelegations = [
|
|
63
|
+
...Object.keys((_b = options.additionalDelegates) !== null && _b !== void 0 ? _b : {}),
|
|
64
|
+
...((_d = (_c = user.autoDelegations) === null || _c === void 0 ? void 0 : _c.all) !== null && _d !== void 0 ? _d : []),
|
|
65
|
+
...((_f = (_e = user.autoDelegations) === null || _e === void 0 ? void 0 : _e.medicalInformation) !== null && _f !== void 0 ? _f : []),
|
|
66
|
+
];
|
|
67
|
+
return new models.Form(yield this.crypto.entities.entityWithInitialisedEncryptedMetadata(form, patient.id, sfk, true, extraDelegations).then((x) => x.updatedEntity));
|
|
70
68
|
});
|
|
71
69
|
}
|
|
72
70
|
// noinspection JSUnusedGlobalSymbols
|
|
@@ -87,43 +85,44 @@ class IccFormXApi extends icc_api_1.IccFormApi {
|
|
|
87
85
|
* @param usingPost (Promise)
|
|
88
86
|
*/
|
|
89
87
|
findBy(hcpartyId, patient, usingPost = false) {
|
|
90
|
-
return this
|
|
91
|
-
.
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.
|
|
97
|
-
return decryptedForms;
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const extractedKeys = yield this.crypto.entities.secretIdsOf(patient, hcpartyId);
|
|
90
|
+
const topmostParentId = (yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0];
|
|
91
|
+
let forms = usingPost
|
|
92
|
+
? yield this.findFormsByHCPartyPatientForeignKeysUsingPost(topmostParentId, undefined, undefined, undefined, _.uniq(extractedKeys))
|
|
93
|
+
: yield this.findFormsByHCPartyPatientForeignKeys(topmostParentId, _.uniq(extractedKeys).join(','));
|
|
94
|
+
return yield this.decrypt(hcpartyId, forms);
|
|
98
95
|
});
|
|
99
96
|
}
|
|
100
97
|
decrypt(hcpartyId, forms) {
|
|
101
|
-
return Promise.all(forms.map((form) => this.crypto
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
98
|
+
return Promise.all(forms.map((form) => this.crypto.entities.decryptEntity(form, hcpartyId, (x) => new models.Form(x)).then(({ entity }) => entity)));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @param form a form
|
|
102
|
+
* @return the id of the patient that the form refers to, retrieved from the encrypted metadata. Normally there should only be one element
|
|
103
|
+
* in the returned array, but in case of entity merges there could be multiple values.
|
|
104
|
+
*/
|
|
105
|
+
decryptPatientIdOf(form) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
return this.crypto.entities.owningEntityIdsOf(form, undefined);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also
|
|
112
|
+
* the encrypted content.
|
|
113
|
+
* @param delegateId the id of the data owner which will be granted access to the form.
|
|
114
|
+
* @param form the form to share.
|
|
115
|
+
* @param options optional parameters to customize the sharing behaviour:
|
|
116
|
+
* - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
|
|
117
|
+
* content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
|
|
118
|
+
* form does not have encrypted content.
|
|
119
|
+
* - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to
|
|
120
|
+
* {@link ShareMetadataBehaviour.IF_AVAILABLE}).
|
|
121
|
+
* @return a promise which will contain the updated form.
|
|
122
|
+
*/
|
|
123
|
+
shareWith(delegateId, form, options = {}) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
return yield this.modifyForm(yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(form, delegateId, undefined, options.shareEncryptionKey, options.sharePatientId));
|
|
127
126
|
});
|
|
128
127
|
}
|
|
129
128
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-form-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-form-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AAGvC,4BAA2B;AAG3B,uDAAwE;AAExE,0EAAgG;AAEhG,qCAAqC;AACrC,MAAa,WAAY,SAAQ,oBAAU;IAIzC,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,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,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC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AAC,OAA4B,EAAE,EAAE;oBAC3C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,IAAA,wBAAS,EAAC,IAAA,kBAAG,EAAC,IAAI,CAAC,aAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;wBACnF,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;wBAC3C,OAAO,CAAC,IAAI,CAAC,CAAA;oBACf,CAAC,CAAC,CAAA;gBACJ,CAAC,CAAC,CACL;qBACA,IAAI,CAAC,CAAC,SAAsB,EAAE,EAAE;oBAC/B,IAAI,SAAS,EAAE;wBACb,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAA,wBAAS,EAAC,SAAS,CAAC,CAAC,CAAC,CAAA;qBACxD;oBACD,OAAO,IAAI,CAAA;gBACb,CAAC,CAAC,CAAA;aACL;iBAAM;gBACL,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;aAC7B;QACH,CAAC,CAAC;aACD,KAAK,CAAC,UAAU,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC,CAAC,CACL,CACF,CAAC,KAAK,CAAC,UAAU,CAAC;YACjB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAzKD,kCAyKC","sourcesContent":["import { IccFormApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\n\nimport { a2b, hex2ua, string2ua, ua2string } from './utils/binary-utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccFormXApi extends IccFormApi {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\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.dataOwnerApi = dataOwnerApi\n }\n\n // noinspection JSUnusedGlobalSymbols\n newInstance(user: models.User, patient: models.Patient, c: any = {}, delegates: string[] = []) {\n const form = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Form',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n c || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, form, delegates)\n }\n\n initEncryptionKeys(user: models.User, form: models.Form) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(form, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(form, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((contact) =>\n this.crypto.appendEncryptionKeys(contact, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n private initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n form: models.Form,\n delegates: string[] = []\n ): Promise<models.Form> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId!)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(form, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(form, dataOwnerId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\n _.extend(form, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(form)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((form) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, form, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return form\n })\n ))\n )\n return promise\n })\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all contacts with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the contacts of the patient.\n *\n * @param hcpartyId\n * @param patient\n * @param usingPost (Promise)\n */\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n usingPost ?\n this.findFormsByHCPartyPatientForeignKeysUsingPost(secretForeignKeys.hcpartyId!, undefined, undefined, undefined, _.uniq(secretForeignKeys.extractedKeys)) :\n this.findFormsByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n )\n .then((forms) => this.decrypt(hcpartyId, forms))\n .then(function (decryptedForms) {\n return decryptedForms\n })\n }\n\n decrypt(hcpartyId: string, forms: Array<models.Form>) {\n return Promise.all(\n forms.map((form) =>\n this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(hcpartyId, form.id!, _.size(form.encryptionKeys) ? form.encryptionKeys! : form.delegations!)\n .then(({ extractedKeys: sfks }) => {\n if (form.encryptedSelf) {\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, '')))\n .then(\n (key) =>\n new Promise((resolve: (value: any) => any) => {\n this.crypto.AES.decrypt(key, string2ua(a2b(form.encryptedSelf!))).then(resolve, () => {\n console.log('Cannot decrypt form', form.id)\n resolve(null)\n })\n })\n )\n .then((decrypted: ArrayBuffer) => {\n if (decrypted) {\n form = _.extend(form, JSON.parse(ua2string(decrypted)))\n }\n return form\n })\n } else {\n return Promise.resolve(form)\n }\n })\n .catch(function (e) {\n console.log(e)\n })\n )\n ).catch(function (e) {\n console.log(e)\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-form-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-form-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAuC;AAGvC,4BAA2B;AAC3B,kDAAiD;AAGjD,0EAAgG;AAGhG,qCAAqC;AACrC,MAAa,WAAY,SAAQ,oBAAU;IAIzC,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,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,IAAI,CAAC,KAAK;YACZ,CAA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AC,SAAiB,EAAE,KAAyB;QAClD,OAAO,OAAO,CAAC,GAAG,CAChB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CACjI,CAAA;IACH,CAAC;IAED;;;;OAIG;IACG,kBAAkB,CAAC,IAAiB;;YACxC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QAChE,CAAC;KAAA;IAED;;;;;;;;;;;;OAYG;IACG,SAAS,CACb,UAAkB,EAClB,IAAiB,EACjB,UAGI,EAAE;;YAEN,OAAO,MAAM,IAAI,CAAC,UAAU,CAC1B,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAChE,IAAI,EACJ,UAAU,EACV,SAAS,EACT,OAAO,CAAC,kBAAkB,EAC1B,OAAO,CAAC,cAAc,CACvB,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAjJD,kCAiJC","sourcesContent":["import { IccFormApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\n\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccFormXApi extends IccFormApi {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\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.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of form with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this form refers to.\n * @param c initialised data for the form. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * 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\n * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * @return a new instance of form.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n c: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ) {\n const form = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Form',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerIdOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n c || {}\n )\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk = options.preferredSfk ?? (await this.crypto.confidential.getAnySecretIdSharedWithParents(patient))\n if (!sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = [\n ...Object.keys(options.additionalDelegates ?? {}),\n ...(user.autoDelegations?.all ?? []),\n ...(user.autoDelegations?.medicalInformation ?? []),\n ]\n return new models.Form(\n await this.crypto.entities.entityWithInitialisedEncryptedMetadata(form, patient.id, sfk, true, extraDelegations).then((x) => x.updatedEntity)\n )\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all contacts with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the contacts of the patient.\n *\n * @param hcpartyId\n * @param patient\n * @param usingPost (Promise)\n */\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n const extractedKeys = await this.crypto.entities.secretIdsOf(patient, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n let forms: Array<models.Form> = usingPost\n ? await this.findFormsByHCPartyPatientForeignKeysUsingPost(topmostParentId, undefined, undefined, undefined, _.uniq(extractedKeys))\n : await this.findFormsByHCPartyPatientForeignKeys(topmostParentId, _.uniq(extractedKeys).join(','))\n return await this.decrypt(hcpartyId, forms)\n }\n\n decrypt(hcpartyId: string, forms: Array<models.Form>) {\n return Promise.all(\n forms.map((form) => this.crypto.entities.decryptEntity(form, hcpartyId, (x) => new models.Form(x)).then(({ entity }) => entity))\n )\n }\n\n /**\n * @param form a form\n * @return the id of the patient that the form refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(form: models.Form): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(form, undefined)\n }\n\n /**\n * Share an existing form with other data owners, allowing them to access the non-encrypted data of the form and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the form.\n * @param form the form to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * form does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this form refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated form.\n */\n async shareWith(\n delegateId: string,\n form: models.Form,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Form> {\n return await this.modifyForm(\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n form,\n delegateId,\n undefined,\n options.shareEncryptionKey,\n options.sharePatientId\n )\n )\n }\n}\n"]}
|
|
@@ -24,7 +24,7 @@ export declare class IccHcpartyXApi extends IccHcpartyApi {
|
|
|
24
24
|
getHealthcareParty(healthcarePartyId: string, bypassCache?: boolean): Promise<HealthcareParty | any>;
|
|
25
25
|
getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache?: boolean): Promise<string[]>;
|
|
26
26
|
getHealthcareParties(healthcarePartyIds: string): Promise<Array<HealthcareParty> | any>;
|
|
27
|
-
getCurrentHealthcareParty(): Promise<HealthcareParty
|
|
27
|
+
getCurrentHealthcareParty(): Promise<HealthcareParty>;
|
|
28
28
|
getHcPartyKeysForDelegate(healthcarePartyId: string, bypassCache?: boolean): Promise<{
|
|
29
29
|
[key: string]: string;
|
|
30
30
|
}>;
|
|
@@ -110,7 +110,7 @@ class IccHcpartyXApi extends icc_api_1.IccHcpartyApi {
|
|
|
110
110
|
isValidCbe(cbe) {
|
|
111
111
|
cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '');
|
|
112
112
|
cbe = cbe.length == 9 ? '0' + cbe : cbe;
|
|
113
|
-
return 97 - (Number(cbe.
|
|
113
|
+
return 97 - (Number(cbe.substring(0, 8)) % 97) === Number(cbe.substring(8, 2));
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
exports.IccHcpartyXApi = IccHcpartyXApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-hcparty-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-hcparty-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA0C;AAE1C,kDAAiD;AACjD,qDAA8E;AAC9E,0EAAgG;AAEhG,qCAAqC;AACrC,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,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,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAdzD,qBAAgB,GAAiD,EAAE,CAAA;QACnE,iBAAY,GAA0D,EAAE,CAAA;QAEhE,0BAAqB,GAAG,MAAO,CAAA;IAYvC,CAAC;IAEO,mBAAmB,CAAC,GAAW;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,UAAU,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE;YACrC,OAAO,UAAU,CAAC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M,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAA;QAC5E,OAAO,MAAM;YACX,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;YACzB,CAAC,CAAC,KAAK,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACpH,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;QAClD,GAAG,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAEvC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC1E,CAAC;CACF;AA9ID,wCA8IC","sourcesContent":["import { IccHcpartyApi } from '../icc-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport * as models from '../icc-api/model/models'\nimport { findName, garnishPersonWithName, hasName } from './utils/person-util'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccHcpartyXApi extends IccHcpartyApi {\n hcPartyKeysCache: { [key: string]: { [key: string]: string } } = {}\n hcPartyCache: { [key: string]: [number, Promise<HealthcareParty>] } = {}\n\n private CACHE_RETENTION_IN_MS = 300_000\n constructor(\n host: string,\n headers: { [key: string]: string },\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 }\n\n private getHcPartyFromCache(key: string) {\n const hcpInCache = this.hcPartyCache[key]\n const now = Date.now()\n if (hcpInCache && hcpInCache[0] > now) {\n return hcpInCache[1]\n }\n if (!hcpInCache) {\n console.log(`Cache miss for key ${key} because not in cache`)\n } else {\n console.log(`Cache miss for key ${key} because ${hcpInCache[0]} > ${now}`)\n }\n return null\n }\n\n completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined {\n if (!hcParty) {\n return hcParty\n }\n\n let finalHcParty = hcParty\n\n if ((!!finalHcParty.lastName || !!finalHcParty.name) && !hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n finalHcParty = garnishPersonWithName(\n finalHcParty,\n models.PersonName.UseEnum.Official,\n finalHcParty.lastName,\n finalHcParty.firstName,\n finalHcParty.name\n )\n }\n\n if ((!finalHcParty.lastName || !finalHcParty.name) && !!hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n let officialName = findName(finalHcParty, models.PersonName.UseEnum.Official)\n finalHcParty = {\n ...finalHcParty,\n lastName: officialName!.lastName,\n firstName: officialName!.firstNames ? officialName!.firstNames[0] : undefined,\n name: officialName!.text,\n }\n }\n\n return finalHcParty\n }\n\n putHcPartyInCache(key: string, value: Promise<HealthcareParty> | null = null): Promise<HealthcareParty> {\n const hcp =\n value ||\n super.getHealthcareParty(key).catch((e) => {\n console.log(`Evict key ${key} because of error`)\n delete this.hcPartyCache[key]\n throw e\n })\n this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcp]\n return hcp\n }\n\n createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcareParty(this.completeNames(body))\n }\n\n createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcarePartyInGroup(groupId, this.completeNames(body))\n }\n\n modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any> {\n if (body && body.id) {\n console.log(`Evict key ${body.id} because of modification`)\n delete this.hcPartyCache[body.id]\n }\n\n return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n getHealthcareParty(healthcarePartyId: string, bypassCache = false): Promise<HealthcareParty | any> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n return fromCache || this.putHcPartyInCache(healthcarePartyId)\n }\n\n getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache = false): Promise<string[]> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n return (fromCache || this.putHcPartyInCache(healthcarePartyId)).then(async (hcp: HealthcareParty) => {\n return hcp ? (hcp.parentId ? (await this.getHealthcarePartyHierarchyIds(hcp.parentId!, bypassCache)).concat([hcp.id!]) : [hcp.id!]) : []\n })\n }\n\n getHealthcareParties(healthcarePartyIds: string): Promise<Array<HealthcareParty> | any> {\n const ids = healthcarePartyIds.split(',').filter((x) => !!x)\n const cached: Array<[string, Promise<HealthcareParty> | null]> = ids.map((id) => [id, this.getHcPartyFromCache(id)])\n const toFetch = cached.filter((x) => !x[1]).map((x) => x[0])\n\n if (!toFetch.length) {\n return Promise.all(cached.map((x) => x[1]!))\n }\n\n const prom: Promise<HealthcareParty[]> = super.getHealthcareParties(toFetch.join(','))\n return Promise.all(\n cached.map(\n (x) =>\n x[1] ||\n this.putHcPartyInCache(\n x[0],\n prom.then((hcps) => hcps.find((h) => h.id === x[0])!)\n )\n )\n )\n }\n\n getCurrentHealthcareParty(): Promise<HealthcareParty | any> {\n return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n getHcPartyKeysForDelegate(healthcarePartyId: string, bypassCache = false): Promise<{ [key: string]: string }> {\n const cached = bypassCache ? null : this.hcPartyKeysCache[healthcarePartyId]\n return cached\n ? Promise.resolve(cached)\n : super.getHcPartyKeysForDelegate(healthcarePartyId).then((r) => (this.hcPartyKeysCache[healthcarePartyId] = r))\n }\n\n isValidCbe(cbe: string) {\n cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '')\n cbe = cbe.length == 9 ? '0' + cbe : cbe\n\n return 97 - (Number(cbe.substr(0, 8)) % 97) === Number(cbe.substr(8, 2))\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-hcparty-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-hcparty-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA0C;AAE1C,kDAAiD;AACjD,qDAA8E;AAC9E,0EAAgG;AAEhG,qCAAqC;AACrC,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,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,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAdzD,qBAAgB,GAAiD,EAAE,CAAA;QACnE,iBAAY,GAA0D,EAAE,CAAA;QAEhE,0BAAqB,GAAG,MAAO,CAAA;IAYvC,CAAC;IAEO,mBAAmB,CAAC,GAAW;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,UAAU,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE;YACrC,OAAO,U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MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAA;QAC5E,OAAO,MAAM;YACX,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;YACzB,CAAC,CAAC,KAAK,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACpH,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;QAClD,GAAG,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAEvC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAChF,CAAC;CACF;AA9ID,wCA8IC","sourcesContent":["import { IccHcpartyApi } from '../icc-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport * as models from '../icc-api/model/models'\nimport { findName, garnishPersonWithName, hasName } from './utils/person-util'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccHcpartyXApi extends IccHcpartyApi {\n hcPartyKeysCache: { [key: string]: { [key: string]: string } } = {}\n hcPartyCache: { [key: string]: [number, Promise<HealthcareParty>] } = {}\n\n private CACHE_RETENTION_IN_MS = 300_000\n constructor(\n host: string,\n headers: { [key: string]: string },\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 }\n\n private getHcPartyFromCache(key: string) {\n const hcpInCache = this.hcPartyCache[key]\n const now = Date.now()\n if (hcpInCache && hcpInCache[0] > now) {\n return hcpInCache[1]\n }\n if (!hcpInCache) {\n console.log(`Cache miss for key ${key} because not in cache`)\n } else {\n console.log(`Cache miss for key ${key} because ${hcpInCache[0]} > ${now}`)\n }\n return null\n }\n\n completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined {\n if (!hcParty) {\n return hcParty\n }\n\n let finalHcParty = hcParty\n\n if ((!!finalHcParty.lastName || !!finalHcParty.name) && !hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n finalHcParty = garnishPersonWithName(\n finalHcParty,\n models.PersonName.UseEnum.Official,\n finalHcParty.lastName,\n finalHcParty.firstName,\n finalHcParty.name\n )\n }\n\n if ((!finalHcParty.lastName || !finalHcParty.name) && !!hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n let officialName = findName(finalHcParty, models.PersonName.UseEnum.Official)\n finalHcParty = {\n ...finalHcParty,\n lastName: officialName!.lastName,\n firstName: officialName!.firstNames ? officialName!.firstNames[0] : undefined,\n name: officialName!.text,\n }\n }\n\n return finalHcParty\n }\n\n putHcPartyInCache(key: string, value: Promise<HealthcareParty> | null = null): Promise<HealthcareParty> {\n const hcp =\n value ||\n super.getHealthcareParty(key).catch((e) => {\n console.log(`Evict key ${key} because of error`)\n delete this.hcPartyCache[key]\n throw e\n })\n this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcp]\n return hcp\n }\n\n createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcareParty(this.completeNames(body))\n }\n\n createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcarePartyInGroup(groupId, this.completeNames(body))\n }\n\n modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any> {\n if (body && body.id) {\n console.log(`Evict key ${body.id} because of modification`)\n delete this.hcPartyCache[body.id]\n }\n\n return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n getHealthcareParty(healthcarePartyId: string, bypassCache = false): Promise<HealthcareParty | any> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n return fromCache || this.putHcPartyInCache(healthcarePartyId)\n }\n\n getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache = false): Promise<string[]> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n return (fromCache || this.putHcPartyInCache(healthcarePartyId)).then(async (hcp: HealthcareParty) => {\n return hcp ? (hcp.parentId ? (await this.getHealthcarePartyHierarchyIds(hcp.parentId!, bypassCache)).concat([hcp.id!]) : [hcp.id!]) : []\n })\n }\n\n getHealthcareParties(healthcarePartyIds: string): Promise<Array<HealthcareParty> | any> {\n const ids = healthcarePartyIds.split(',').filter((x) => !!x)\n const cached: Array<[string, Promise<HealthcareParty> | null]> = ids.map((id) => [id, this.getHcPartyFromCache(id)])\n const toFetch = cached.filter((x) => !x[1]).map((x) => x[0])\n\n if (!toFetch.length) {\n return Promise.all(cached.map((x) => x[1]!))\n }\n\n const prom: Promise<HealthcareParty[]> = super.getHealthcareParties(toFetch.join(','))\n return Promise.all(\n cached.map(\n (x) =>\n x[1] ||\n this.putHcPartyInCache(\n x[0],\n prom.then((hcps) => hcps.find((h) => h.id === x[0])!)\n )\n )\n )\n }\n\n getCurrentHealthcareParty(): Promise<HealthcareParty> {\n return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n getHcPartyKeysForDelegate(healthcarePartyId: string, bypassCache = false): Promise<{ [key: string]: string }> {\n const cached = bypassCache ? null : this.hcPartyKeysCache[healthcarePartyId]\n return cached\n ? Promise.resolve(cached)\n : super.getHcPartyKeysForDelegate(healthcarePartyId).then((r) => (this.hcPartyKeysCache[healthcarePartyId] = r))\n }\n\n isValidCbe(cbe: string) {\n cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '')\n cbe = cbe.length == 9 ? '0' + cbe : cbe\n\n return 97 - (Number(cbe.substring(0, 8)) % 97) === Number(cbe.substring(8, 2))\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import * as models from '../icc-api/model/models';
|
|
|
4
4
|
import { FilterChainHealthElement, HealthElement, PaginatedListHealthElement } from '../icc-api/model/models';
|
|
5
5
|
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
6
6
|
import { AuthenticationProvider } from './auth/AuthenticationProvider';
|
|
7
|
+
import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour';
|
|
7
8
|
export declare class IccHelementXApi extends IccHelementApi {
|
|
8
9
|
crypto: IccCryptoXApi;
|
|
9
10
|
dataOwnerApi: IccDataOwnerXApi;
|
|
@@ -11,8 +12,30 @@ export declare class IccHelementXApi extends IccHelementApi {
|
|
|
11
12
|
constructor(host: string, headers: {
|
|
12
13
|
[key: string]: string;
|
|
13
14
|
}, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, encryptedKeys?: Array<string>, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new instance of health element with initialised encryption metadata (not in the database).
|
|
17
|
+
* @param user the current user.
|
|
18
|
+
* @param patient the patient this health element refers to.
|
|
19
|
+
* @param h initialised data for the health element. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
|
|
20
|
+
* other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
|
|
21
|
+
* @param options optional parameters:
|
|
22
|
+
* - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
|
|
23
|
+
* 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
|
|
24
|
+
* auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
|
|
25
|
+
* access will be possible.
|
|
26
|
+
* - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
|
|
27
|
+
* secret id of patient known by the topmost parent in the current data owner hierarchy.
|
|
28
|
+
* - confidential: if true, the entity will be created as confidential. Confidential entities are not shared with auto-delegations, and the default
|
|
29
|
+
* foreign key used is any key that is not shared with any of the data owner parents. By default entities are created as non-confidential.
|
|
30
|
+
* @return a new instance of health element.
|
|
31
|
+
*/
|
|
32
|
+
newInstance(user: models.User, patient: models.Patient, h: any, options?: {
|
|
33
|
+
additionalDelegates?: {
|
|
34
|
+
[dataOwnerId: string]: 'WRITE';
|
|
35
|
+
};
|
|
36
|
+
preferredSfk?: string;
|
|
37
|
+
confidential?: boolean;
|
|
38
|
+
}): Promise<models.HealthElement>;
|
|
16
39
|
createHealthElement(body?: models.HealthElement): never;
|
|
17
40
|
createHealthElementWithUser(user: models.User, body?: models.HealthElement): Promise<models.HealthElement | any>;
|
|
18
41
|
createHealthElements(body?: Array<HealthElement>): never;
|
|
@@ -29,6 +52,7 @@ export declare class IccHelementXApi extends IccHelementApi {
|
|
|
29
52
|
findHealthElementsByHCPartyAndPatientWithUser(user: models.User, hcPartyId: string, patient: models.Patient, usingPost?: boolean): Promise<models.HealthElement[]>;
|
|
30
53
|
modifyHealthElement(body?: HealthElement): never;
|
|
31
54
|
modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise<HealthElement | any>;
|
|
55
|
+
private modifyAs;
|
|
32
56
|
modifyHealthElements(body?: Array<HealthElement>): never;
|
|
33
57
|
modifyHealthElementsWithUser(user: models.User, bodies?: HealthElement[]): Promise<HealthElement[] | any>;
|
|
34
58
|
/**
|
|
@@ -52,11 +76,34 @@ export declare class IccHelementXApi extends IccHelementApi {
|
|
|
52
76
|
findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.Contact> | any>;
|
|
53
77
|
findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.Contact> | any>;
|
|
54
78
|
encrypt(user: models.User, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>>;
|
|
55
|
-
|
|
79
|
+
private encryptAs;
|
|
56
80
|
decryptWithUser(user: models.User, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>>;
|
|
57
81
|
decrypt(dataOwnerId: string, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>>;
|
|
58
82
|
filterHealthElementsBy(startDocumentId?: string, limit?: number, body?: FilterChainHealthElement): never;
|
|
59
83
|
filterByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: FilterChainHealthElement): Promise<PaginatedListHealthElement>;
|
|
60
84
|
serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string): Promise<never>;
|
|
61
85
|
stringToCode(code: string): models.Code;
|
|
86
|
+
/**
|
|
87
|
+
* @param healthElement a health element
|
|
88
|
+
* @return the id of the patient that the health element refers to, retrieved from the encrypted metadata. Normally there should only be one element
|
|
89
|
+
* in the returned array, but in case of entity merges there could be multiple values.
|
|
90
|
+
*/
|
|
91
|
+
decryptPatientIdOf(healthElement: models.HealthElement): Promise<string[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also
|
|
94
|
+
* the encrypted content, with read-only or read-write permissions.
|
|
95
|
+
* @param delegateId the id of the data owner which will be granted access to the health element.
|
|
96
|
+
* @param healthElement the health element to share.
|
|
97
|
+
* @param options optional parameters to customize the sharing behaviour:
|
|
98
|
+
* - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
|
|
99
|
+
* content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
|
|
100
|
+
* health element does not have encrypted content.
|
|
101
|
+
* - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to
|
|
102
|
+
* {@link ShareMetadataBehaviour.IF_AVAILABLE}).
|
|
103
|
+
* @return a promise which will contain the updated health element.
|
|
104
|
+
*/
|
|
105
|
+
shareWith(delegateId: string, healthElement: models.HealthElement, options?: {
|
|
106
|
+
shareEncryptionKey?: ShareMetadataBehaviour;
|
|
107
|
+
sharePatientId?: ShareMetadataBehaviour;
|
|
108
|
+
}): Promise<models.HealthElement>;
|
|
62
109
|
}
|