import { IccAuthApi, IccHelementApi } from '../icc-api'; import { IccCryptoXApi } from './icc-crypto-x-api'; import * as models from '../icc-api/model/models'; import { FilterChainHealthElement, HealthElement, PaginatedListHealthElement, TimingInfo } from '../icc-api/model/models'; import { IccDataOwnerXApi } from './icc-data-owner-x-api'; import { AuthenticationProvider } from './auth/AuthenticationProvider'; import { SecureDelegation } from '../icc-api/model/SecureDelegation'; import AccessLevelEnum = SecureDelegation.AccessLevelEnum; import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'; import { ShareResult } from './utils/ShareResult'; import { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'; import RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum; import { XHR } from '../icc-api/api/XHR'; import { IccUserXApi } from './icc-user-x-api'; import { SubscriptionOptions } from './utils'; import { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'; import { AbstractFilter } from './filters/filters'; import { Connection } from '../icc-api/model/Connection'; import { SecretIdUseOption } from './crypto/SecretIdUseOption'; export declare class IccHelementXApi extends IccHelementApi implements EncryptedEntityXApi { private readonly crypto; private readonly dataOwnerApi; private readonly userApi; private readonly authApi; private readonly autofillAuthor; private readonly encryptedFields; get headers(): Promise>; constructor(host: string, headers: { [key: string]: string; }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, userApi: IccUserXApi, authApi: IccAuthApi, autofillAuthor: boolean, encryptedKeys?: Array, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise); /** * Creates a new instance of health element with initialised encryption metadata (not in the database). * @param user the current user. * @param patient the patient this health element refers to. * @param h initialised data for the health element. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata. * @param options optional parameters: * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the * 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 * auto-delegations, in such case the access level specified here will be used. * - sfkOption: specifies which sfk of the owning entity to use. * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible, * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation. * @return a new instance of health element. */ newInstance(user: models.User, patient: models.Patient, h: any, options?: { additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum; }; sfkOption?: SecretIdUseOption; ignoreAutoDelegations?: boolean; alternateRootDelegation?: string; }): Promise; /** * @throws always. Use {@link createHealthElementWithUser} instead. */ createHealthElement(body?: models.HealthElement): never; /** * Creates a health element after encrypting its content. * @param user the current user, used for encryption. * @param body the health element to create. * @return the created and decrypted health element. */ createHealthElementWithUser(user: models.User, body?: models.HealthElement): Promise; /** * @throws always. Use {@link createHealthElementsWithUser} instead. */ createHealthElements(body?: Array): never; /** * Creates multiple health elements after encrypting their content. * @param user the current user, used for encryption. * @param bodies the health elements to create. * @return the created and decrypted health elements. */ createHealthElementsWithUser(user: models.User, bodies?: models.HealthElement[]): Promise; /** * @throws always. Use {@link getHealthElementWithUser} instead. */ getHealthElement(healthElementId: string): never; /** * Retrieves a health element by id and decrypts it. * @param user the current user, used for decryption. * @param healthElementId the id of the health element to retrieve. * @return the decrypted health element. */ getHealthElementWithUser(user: models.User, healthElementId: string): Promise; /** * @throws always. Use {@link getHealthElementsWithUser} instead. */ getHealthElements(body?: models.ListOfIds): never; /** * Retrieves multiple health elements by their ids and decrypts them. * @param user the current user, used for decryption. * @param body the list of health element ids to retrieve. * @return the decrypted health elements. */ getHealthElementsWithUser(user: models.User, body?: models.ListOfIds): Promise; /** * @throws always. */ newHealthElementDelegations(healthElementId: string, body?: Array): never; /** * @throws always. Use {@link findHealthElementsByHCPartyPatientForeignKeysWithUser} instead. */ findHealthElementsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string): never; /** * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead. */ findHealthElementsByHCPartyPatientForeignKeysWithUser(user: models.User, hcPartyId: string, secretFKeys: string): Promise; /** * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead. */ findHealthElementsByHCPartyPatientForeignKeysArrayWithUser(user: models.User, hcPartyId: string, secretFKeys: string[]): Promise; /** * Finds all health elements for a given patient and healthcare party, and decrypts them. * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead. * @param user the current user, used for decryption. * @param hcPartyId the id of the healthcare party. * @param patient the patient whose health elements to find. * @param usingPost if true, uses POST instead of GET for the request. * @return the decrypted health elements. */ findHealthElementsByHCPartyAndPatientWithUser(user: models.User, hcPartyId: string, patient: models.Patient, usingPost?: boolean): Promise; /** * @throws always. Use {@link modifyHealthElementWithUser} instead. */ modifyHealthElement(body?: HealthElement): never; /** * Modifies a health element after encrypting its content. * @param user the current user, used for encryption/decryption. * @param body the health element with updated fields. * @return the modified and decrypted health element, or null if body was not provided. */ modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise; private modifyHealthElementAs; /** * @throws always. Use {@link modifyHealthElementsWithUser} instead. */ modifyHealthElements(body?: Array): never; /** * Modifies multiple health elements after encrypting their content. * @param user the current user, used for encryption/decryption. * @param bodies the health elements with updated fields. * @return the modified and decrypted health elements, or null if bodies was not provided. */ modifyHealthElementsWithUser(user: models.User, bodies?: HealthElement[]): Promise; /** * 1. Check whether there is a delegation with 'hcpartyId' or not. * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him. * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key * 3.1. KeyPair should be fetch from cache (in jwk) * 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 * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4) * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId) * * After these painful steps, you have the helements of the patient. * * @deprecated use {@link findIdsBy}. * @param hcpartyId * @param patient (Promise) * @param keepObsoleteVersions * @param usingPost */ findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions?: boolean, usingPost?: boolean): Promise; /** * Same as {@link findBy} but it will only return the ids of the health elements. It can also filter the health elements where HealthElement.openingDate is between * startDate and endDate in ascending or descending order by that field. (default: ascending). */ findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean): Promise; /** * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead. */ findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise | any>; /** * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead. */ findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise | any>; /** * Encrypts the encrypted fields of a list of health elements. * @param user the current user, used to determine the data owner for encryption. * @param healthElements the health elements to encrypt. * @return the encrypted health elements. */ encrypt(user: models.User, healthElements: Array): Promise>; private encryptAs; /** * Decrypts a list of health elements using the given user's data owner keys. * @param user the current user. * @param hes the health elements to decrypt. * @return the decrypted health elements. */ decryptWithUser(user: models.User, hes: Array): Promise>; /** * Decrypts a list of health elements using the current data owner's keys. * @param dataOwnerId the id of the data owner performing the decryption. * @param hes the health elements to decrypt. * @return the decrypted health elements. */ decrypt(dataOwnerId: string, hes: Array): Promise>; /** * @throws always. Use {@link filterByWithUser} instead. */ filterHealthElementsBy(startDocumentId?: string, limit?: number, body?: FilterChainHealthElement): never; /** * Filters health elements using the provided filter chain and decrypts the results. * @param user the current user, used for decryption. * @param startDocumentId the pagination start document id. * @param limit the maximum number of results to return. * @param body the filter chain to apply. * @param collectTiming add timing information to the response * @return a paginated list of decrypted health elements. */ filterByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: FilterChainHealthElement, collectTiming?: false): Promise; filterByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: FilterChainHealthElement, collectTiming?: true): Promise; /** * Converts a service into a new health element linked to the given patient. * @param user the current user. * @param patient the patient to link the health element to. * @param heSvc the service to convert. * @param descr the description for the new health element. * @return the created health element. */ serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string): Promise; /** * Parses a pipe-delimited code string into a Code object. * @param code the code string in format "type|code|version". * @return a Code object with the parsed fields. */ stringToCode(code: string): models.Code; /** * @param healthElement a health element * @return the id of the patient that the health element refers to, retrieved from the encrypted metadata. Normally there should only be one element * in the returned array, but in case of entity merges there could be multiple values. */ decryptPatientIdOf(healthElement: models.HealthElement): Promise; /** * @return if the logged data owner has write access to the content of the given health element */ hasWriteAccess(healthElement: models.HealthElement): Promise; /** * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also * the encrypted content, with read-only or read-write permissions. * @param delegateId the id of the data owner which will be granted access to the health element. * @param healthElement the health element to share. * @param options optional parameters to customize the sharing behaviour: * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a * health element does not have encrypted content. * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to * {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @return the updated entity */ shareWith(delegateId: string, healthElement: models.HealthElement, options?: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; sharePatientId?: ShareMetadataBehaviour; }): Promise; /** * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also * the encrypted content, with read-only or read-write permissions. * @param delegateId the id of the data owner which will be granted access to the health element. * @param healthElement the health element to share. * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options: * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a * health element does not have encrypted content. * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to * {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @return the updated entity */ shareWithMany(healthElement: models.HealthElement, delegates: { [delegateId: string]: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; sharePatientId?: ShareMetadataBehaviour; }; }): Promise; /** * Share an existing health element with other data owners, allowing them to access the non-encrypted data of the health element and optionally also * the encrypted content, with read-only or read-write permissions. * @param healthElement the health element to share. * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options: * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a * health element does not have encrypted content. * - sharePatientId: specifies if the id of the patient that this health element refers to should be shared with the delegate (defaults to * {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if * the operation failed. */ tryShareWithMany(healthElement: models.HealthElement, delegates: { [delegateId: string]: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; sharePatientId?: ShareMetadataBehaviour; }; }): Promise>; /** * Retrieves the data owners that have access to the given health element, along with their access levels. * @param entity the health element. * @return an object containing a map of data owner ids to their access levels, and a flag indicating if there are unknown anonymous data owners. */ getDataOwnersWithAccessTo(entity: models.HealthElement): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum; }; hasUnknownAnonymousDataOwners: boolean; }>; /** * Retrieves the encryption keys of the given health element. * @param entity the health element. * @return the encryption key ids. */ getEncryptionKeysOf(entity: models.HealthElement): Promise; /** * Subscribes to real-time health element events using a WebSocket connection. Received events are automatically decrypted. * @param eventTypes the types of events to listen for (e.g. 'CREATE', 'UPDATE', 'DELETE'). * @param filter an optional filter to restrict which health element events trigger the callback. * @param eventFired the callback function invoked when a matching health element event is received. * @param options optional subscription configuration such as connection parameters and retry behaviour. * @return a connection object that can be used to manage the WebSocket subscription lifecycle. */ subscribeToHealthElementEvents(eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[], filter: AbstractFilter | undefined, eventFired: (healthElement: HealthElement) => Promise, options?: SubscriptionOptions): Promise; /** * Creates or updates de-anonymization metadata for the given health element, allowing the specified delegates to * identify the data owners that have access to it. * @param entity the health element. * @param delegates the data owner ids for which to create de-anonymization metadata. */ createDelegationDeAnonymizationMetadata(entity: HealthElement, delegates: string[]): Promise; /** * Like {@link getConflictsForEntity} but additionally decrypts the conflicting revisions for the given user. * @param user the current user, used to determine the data owner that will decrypt the entities. * @param entityId the id of the health element to retrieve the conflicts for. * @return the decrypted conflicting revisions of the health element. */ getConflictsForEntityWithUser(user: models.User, entityId: string): Promise>; /** * Like {@link declareConflictWinner} but encrypts the winning revision before sending it and decrypts the saved * winner returned by the backend. * @param user the current user, used to determine the data owner that will encrypt/decrypt the entity. * @param request the {@link models.ConflictResolutionRequest} carrying the (decrypted) winning revision and the conflicts to purge. * @return the {@link models.ConflictResolutionResult} with the decrypted saved winner and the conflicts that are still unresolved. */ declareConflictWinnerWithUser(user: models.User, request: models.ConflictResolutionRequest): Promise>; /** * Like {@link getConflictsForEntityWithUser} but targets the entity of the group with the given id. * @param user the current user, used to determine the data owner that will decrypt the entities. * @param groupId the id of the group the health element belongs to. * @param entityId the id of the health element to retrieve the conflicts for. * @return the decrypted conflicting revisions of the health element. */ getConflictsForEntityInGroupWithUser(user: models.User, groupId: string, entityId: string): Promise>; /** * Like {@link declareConflictWinnerWithUser} but targets the entity of the group with the given id. * @param user the current user, used to determine the data owner that will encrypt/decrypt the entity. * @param groupId the id of the group the health element belongs to. * @param request the {@link models.ConflictResolutionRequest} carrying the (decrypted) winning revision and the conflicts to purge. * @return the {@link models.ConflictResolutionResult} with the decrypted saved winner and the conflicts that are still unresolved. */ declareConflictWinnerInGroupWithUser(user: models.User, groupId: string, request: models.ConflictResolutionRequest): Promise>; }