import { IccAuthApi, IccContactApi } from '../icc-api'; import { IccCryptoXApi } from './icc-crypto-x-api'; import * as models from '../icc-api/model/models'; import { Contact, ListOfIds, Service, TimingInfo } from '../icc-api/model/models'; import { PaginatedListContact } from '../icc-api/model/PaginatedListContact'; import { IccDataOwnerXApi } from './icc-data-owner-x-api'; import { SubscriptionOptions } from './utils'; import { AuthenticationProvider } from './auth/AuthenticationProvider'; import { SecureDelegation } from '../icc-api/model/SecureDelegation'; import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'; import { ShareResult } from './utils/ShareResult'; import { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'; import { XHR } from '../icc-api/api/XHR'; import { IccUserXApi } from './icc-user-x-api'; import { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'; import { AbstractFilter } from './filters/filters'; import { Connection } from '../icc-api/model/Connection'; import AccessLevelEnum = SecureDelegation.AccessLevelEnum; import RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum; import { SecretIdUseOption } from './crypto/SecretIdUseOption'; export declare class IccContactXApi extends IccContactApi implements EncryptedEntityXApi { private readonly crypto; private readonly dataOwnerApi; private readonly userApi; private readonly authApi; private readonly autofillAuthor; i18n: any; private readonly contactEncryptedFields; private readonly serviceEncryptedFieldsNoContent; private readonly serviceEncryptedFieldsWithContent; get headers(): Promise>; constructor(host: string, headers: { [key: string]: string; }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, userApi: IccUserXApi, authApi: IccAuthApi, autofillAuthor: boolean, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise, contactEncryptedKeys?: string[], serviceEncryptedKeys?: string[]); /** * Creates a new instance of contact with initialised encryption metadata (not in the database). * @param user the current user. * @param patient the patient this contact refers to. * @param c initialised data for the contact. 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 contact. */ newInstance(user: models.User, patient: models.Patient, c: any, options?: { additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum; }; sfkOption?: SecretIdUseOption; ignoreAutoDelegations?: boolean; alternateRootDelegation?: string; }): 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 contacts with (allSecretForeignKeysDelimitedByComa, hcpartyId) * * After these painful steps, you have the contacts of the patient. * * @deprecated use {@link findIdsBy} instead. * @param hcpartyId * @param patient (Promise) * @param usingPost */ findBy(hcpartyId: string, patient: models.Patient, usingPost?: boolean): Promise; /** * Same as {@link findBy} but it will only return the ids of the contacts. It can also filter the contacts where Contact.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 Unused method, bugged: won't work if `hcpartyId` is not the parent hcp and doesn't decrypt contacts. * Will be permanently removed in version 8.2.0 */ findByPatientSFKs(hcpartyId: string, patients: Array): Promise>; filterBy(startKey?: string, startDocumentId?: string, limit?: number, body?: models.FilterChainContact): never; listContactsByOpeningDate(startDate: number, endDate: number, hcpartyid: string, startKey?: string, startDocumentId?: string, limit?: number): never; listServices(body?: ListOfIds): Promise>; findByHCPartyFormId(hcPartyId?: string, formId?: string): never; findByHCPartyFormIds(hcPartyId?: string, body?: models.ListOfIds): never; getContact(contactId: string): never; getContacts(body?: models.ListOfIds): never; modifyContact(body?: Contact): never; modifyContacts(body?: Array): never; createContact(body?: Contact): never; /** * @deprecated use {@link findContactIdsByDataOwnerPatientOpeningDate} instead. */ findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string, planOfActionIds?: string, skipClosedContacts?: boolean): Promise>; /** * @deprecated use {@link findContactIdsByDataOwnerPatientOpeningDate} instead. */ findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[], planOfActionIds?: string, skipClosedContacts?: boolean): Promise | any>; /** * Filters contacts using a filter chain and decrypts the results for the given user. * @param user the user for decryption * @param startDocumentId optional document id to start pagination from * @param limit 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 contacts */ filterByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: models.FilterChainContact, collectTiming?: false): Promise; filterByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: models.FilterChainContact, collectTiming?: true): Promise<(PaginatedListContact & TimingInfo) | any>; /** * Filters services using a filter chain and decrypts the results for the given user. * @param user the user for decryption * @param startDocumentId optional document id to start pagination from * @param limit 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 services */ filterServicesByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: models.FilterChainService, collectTiming?: false): Promise; filterServicesByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: models.FilterChainService, collectTiming?: true): Promise<(PaginatedListContact & TimingInfo) | any>; /** * Lists contacts by opening date within a date range and decrypts the results for the given user. * @param user the user for decryption * @param startDate start of the date range (format: YYYYMMDDHHmmss) * @param endDate end of the date range (format: YYYYMMDDHHmmss) * @param hcpartyid the healthcare party id * @param startKey optional start key for pagination * @param startDocumentId optional document id to start pagination from * @param limit maximum number of results to return * @return a paginated list of decrypted contacts */ listContactsByOpeningDateWithUser(user: models.User, startDate: number, endDate: number, hcpartyid: string, startKey?: string, startDocumentId?: string, limit?: number): Promise; /** * Gets a service by id and decrypts it for the given user. * @param user the user for decryption * @param serviceId the service id * @return the decrypted service */ getServiceWithUser(user: models.User, serviceId: string): Promise; /** * Lists services by their ids and decrypts them for the given user. * @param user the user for decryption * @param serviceIds the list of service ids to retrieve * @return an array of decrypted services */ listServicesWithUser(user: models.User, serviceIds: ListOfIds): Promise | any>; /** * Finds contacts by healthcare party and form id and decrypts them for the given user. * @param user the user for decryption * @param hcPartyId the healthcare party id * @param formId the form id * @return an array of decrypted contacts */ findByHCPartyFormIdWithUser(user: models.User, hcPartyId: string, formId: string): Promise | any>; /** * Finds contacts by healthcare party and multiple form ids and decrypts them for the given user. * @param user the user for decryption * @param hcPartyId the healthcare party id * @param body the list of form ids * @return an array of decrypted contacts */ findByHCPartyFormIdsWithUser(user: models.User, hcPartyId: string, body: models.ListOfIds): Promise | any>; /** * Gets a contact by id and decrypts it for the given user. * @param user the user for decryption * @param contactId the contact id * @return the decrypted contact */ getContactWithUser(user: models.User, contactId: string): Promise; /** * Gets multiple contacts by their ids and decrypts them for the given user. * @param user the user for decryption * @param body the list of contact ids * @return an array of decrypted contacts */ getContactsWithUser(user: models.User, body?: models.ListOfIds): Promise | any>; /** * Modifies an existing contact by encrypting it and saving it to the database. * @param user the user for encryption * @param body the contact to modify * @return the modified and decrypted contact */ modifyContactWithUser(user: models.User, body?: models.Contact): Promise; private modifyContactAs; /** * Modifies multiple existing contacts by encrypting them and saving them to the database. * @param user the user for encryption * @param bodies the array of contacts to modify * @return an array of modified and decrypted contacts */ modifyContactsWithUser(user: models.User, bodies?: Array): Promise; /** * Creates a new contact by encrypting it and saving it to the database. * @param user the user for encryption * @param body the contact to create * @return the created and decrypted contact */ createContactWithUser(user: models.User, body?: models.Contact): Promise; /** * Creates multiple new contacts by encrypting them and saving them to the database. * @param user the user for encryption * @param bodies the array of contacts to create * @return an array of created and decrypted contacts */ createContactsWithUser(user: models.User, bodies?: Array): Promise; /** * Encrypts the content and custom encrypted fields of services. * Services with compound values are recursively encrypted. * @param key the encryption key * @param rawKey the raw encryption key as a string * @param services the array of services to encrypt * @return a promise containing the encrypted services */ encryptServices(key: CryptoKey, rawKey: string, services: Service[]): PromiseLike; /** * Encrypts contacts for the given user including all services within the contacts. * @param user the user for encryption * @param ctcs the array of contacts to encrypt * @return a promise containing the encrypted contacts */ encrypt(user: models.User, ctcs: Array): Promise; private encryptAs; /** * Decrypts contacts and all their encrypted content. * @param hcpartyId the healthcare party id (deprecated parameter, kept for compatibility) * @param ctcs the array of encrypted contacts * @return a promise containing the decrypted contacts */ decrypt(hcpartyId: string, ctcs: Array): Promise>; /** * Decrypts services and all their encrypted content. * @param hcpartyId the healthcare party id (deprecated parameter, kept for compatibility) * @param svcs the array of encrypted services * @return a promise containing the decrypted services */ decryptServices(hcpartyId: string, svcs: Array): Promise>; /** * Finds the contact containing the given service id, prioritizing the latest version by valueDate. * @param ctcs the array of contacts to search * @param svcId the service id to find * @return the contact containing the service or undefined if not found */ contactOfService(ctcs: Array, svcId: string): models.Contact | undefined; /** * Extracts and filters services from contacts, keeping only the latest version of each service and excluding deleted services. * @param ctcs the array of contacts containing services * @param filter a predicate function to filter services: (service, contact) => boolean * @return an array of filtered services with contactId set */ filteredServices(ctcs: Array, filter: any): Array; /** * Extracts and filters services from contacts, returning a promise. Same as filteredServices but wrapped in a promise. * @param ctcs the array of contacts containing services * @param filter a predicate function to filter services: (service, contact) => boolean * @return a promise containing an array of filtered services */ filterServices(ctcs: Array, filter: any): Promise>; /** * Gets all services from a contact that have the specified label. * @param ctc the contact * @param label the service label to filter by * @return an array of services with the given label */ services(ctc: models.Contact, label: string): models.Service[]; /** * Gets the preferred content for a service based on language preference, falling back to French then first available language. * @param svc the service * @param lng the preferred language code * @return the content in the preferred language or null if no content exists */ preferredContent(svc: models.Service, lng: string): models.Content | undefined; /** * Extracts the value from content, prioritizing string, number, measure, medication, and boolean values in that order. * @param c the content * @return the extracted value or undefined if no value is present */ contentValue(c: models.Content): string | number | boolean | models.Measure | models.Medication | undefined; /** * Gets a short human-readable description of a service in the preferred language. * @param svc the service * @param lng the preferred language code * @return a short description of the service content or empty string */ shortServiceDescription(svc: models.Service, lng: string): string | number; /** * Gets a short human-readable description of content, formatted appropriately for the content type. * @param c the content * @param lng the language code for medication formatting * @param label optional label used for boolean content display * @return a short description of the content */ shortContentDescription(c: models.Content, lng: string, label?: string): string | number; /** * Extracts the medication value from a service's content in the preferred language. * @param svc the service * @param lng the preferred language code * @return the medication value or undefined if not present */ medicationValue(svc: models.Service, lng: string): models.Medication | undefined; /** * Checks if content has any data value set (string, number, measure, boolean, medication, or document). * @param c the content to check * @return true if content has data, false otherwise */ contentHasData(c: any): boolean; /** * Localizes a value by selecting the appropriate language from an object, falling back through FR, EN, and NL. * @param e the object with language-keyed values or a simple value * @param lng the preferred language code * @return the localized value or null if e is null/undefined */ localize(e: any, lng: string): any; /** * Modifies the subcontacts this svc belongs to while minimizing the number of references to the svcs inside the subcontacts * After the invocation, there is at least one subcontact with provided poaId and heId that contains the svc * The svc is not removed from a previous subcontact it would belong to except if the new conditions are compatible * Note that undefined and null do not have the same meaning for formId * If formId is null: the subcontact which refers svc must have a null formId * If formId is undefined, the subcontact can have any value for formId * * When a svc does not exist yet in the current contact but exists in a previous contact, all the scs it was belonging to are * copied in the current contact * * the svc returned is the one that's inside the ctc * * @param ctc * @param user * @param ctcs * @param svc * @param formId * @param poaId aMap {heId2: [poaId11, poaId12], heId2: [poaId21] } * @param heId an Array of heIds, equivalent to poaIds = {heId: [], ...} * @param init * @returns {*} */ promoteServiceInContact(ctc: models.Contact, user: models.User, ctcs: Array, svc: models.Service, formId: string, poaIds?: { [key: string]: string[]; }, heIds?: Array, init?: any): any; /** * Checks if a service has numeric content (measure or number value) in the preferred language. * @param svc the service * @param lng the preferred language code * @return true if the service has numeric content, false otherwise */ isNumeric(svc: models.Service, lng: string): number | boolean | models.Measure | undefined; /** * Returns utility functions for working with services. * @return an object with helper methods for creating and manipulating services */ service(): { newInstance: (user: models.User, s: any) => any; }; /** * Returns utility functions for working with medication content. * @return an object with helper methods for formatting and displaying medication information */ medication(): { regimenScores: () => any; medicationNameToString: (m: any) => string; reimbursementReasonToString: (m: any, lang: string) => any; medicationToString: (m: any, lang: string) => string; productToString: (m: any) => string; posologyToString: (m: any, lang: string) => any; frequencyToString: (m: any, lang: string) => any; durationToString: (d: models.Duration, lang: string) => string; regimenToExtString: (r: models.RegimenItem, lang: string) => string; regimenToString: (r: models.RegimenItem, lang: string) => string | null; localize: (s: any, lang: string) => any; }; /** * @param contact a contact * @return the id of the patient that the contact 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(contact: models.Contact): Promise; /** * @param service a service * @return the id of the patient that the service 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. */ decryptPatientIdOfService(service: models.Service): Promise; /** * @return if the logged data owner has write access to the content of the given contact */ hasWriteAccess(contact: models.Contact): Promise; /** * Share an existing contact with other data owners, allowing them to access the non-encrypted data of the contact 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 contact. * @param contact the contact 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 * contact does not have encrypted content. * - sharePatientId: specifies if the id of the patient that this contact 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, contact: models.Contact, options?: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; sharePatientId?: ShareMetadataBehaviour; }): Promise; /** * Share an existing contact with other data owners, allowing them to access the non-encrypted data of the contact and optionally also * the encrypted content, with read-only or read-write permissions. * @param contact the contact 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 * contact does not have encrypted content. * - sharePatientId: specifies if the id of the patient that this contact 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(contact: models.Contact, delegates: { [delegateId: string]: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; sharePatientId?: ShareMetadataBehaviour; }; }): Promise; /** * Share an existing contact with other data owners, allowing them to access the non-encrypted data of the contact and optionally also * the encrypted content, with read-only or read-write permissions. * @param contact the contact 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 * contact does not have encrypted content. * - sharePatientId: specifies if the id of the patient that this contact 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(contact: models.Contact, delegates: { [delegateId: string]: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; sharePatientId?: ShareMetadataBehaviour; }; }): Promise>; /** * Gets the data owners that have access to the contact and their permission levels. * @param entity the contact * @return a promise containing the permissions by data owner id and whether there are unknown anonymous data owners */ getDataOwnersWithAccessTo(entity: models.Contact): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum; }; hasUnknownAnonymousDataOwners: boolean; }>; /** * Gets all encryption keys available for the contact. * @param entity the contact * @return a promise containing an array of encryption key hex strings */ getEncryptionKeysOf(entity: models.Contact): Promise; /** * Subscribes to service events (create, update, delete) and receives decrypted services. * @param eventTypes the types of events to subscribe to * @param filter optional filter to apply to services * @param eventFired callback function invoked when an event occurs, receives the decrypted service * @param options optional subscription options * @return a connection that can be closed to unsubscribe */ subscribeToServiceEvents(eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[], filter: AbstractFilter | undefined, eventFired: (dataSample: Service) => Promise, options?: SubscriptionOptions): Promise; /** * Subscribes to contact events (create, update, delete) and receives decrypted contacts. * @param eventTypes the types of events to subscribe to * @param filter optional filter to apply to contacts * @param eventFired callback function invoked when an event occurs, receives the decrypted contact * @param options optional subscription options * @return a connection that can be closed to unsubscribe */ subscribeToContactEvents(eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[], filter: AbstractFilter | undefined, eventFired: (dataSample: Contact) => Promise, options?: SubscriptionOptions): Promise; /** * Creates or updates de-anonymization metadata for delegations in a contact. * @param entity the contact * @param delegates the array of delegate ids to create de-anonymization metadata for * @return a promise that completes when the metadata is created/updated */ createDelegationDeAnonymizationMetadata(entity: Contact, 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 contact to retrieve the conflicts for. * @return the decrypted conflicting revisions of the contact. */ 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 contact belongs to. * @param entityId the id of the contact to retrieve the conflicts for. * @return the decrypted conflicting revisions of the contact. */ 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 contact 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>; }