@icure/api 8.6.4 → 8.6.6

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.
Files changed (61) hide show
  1. package/icc-api/api/IccFormApi.d.ts +81 -0
  2. package/icc-api/api/IccFormApi.js +213 -0
  3. package/icc-api/api/IccFormApi.js.map +1 -1
  4. package/icc-x-api/icc-accesslog-x-api.d.ts +93 -0
  5. package/icc-x-api/icc-accesslog-x-api.js +93 -0
  6. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  7. package/icc-x-api/icc-calendar-item-x-api.d.ts +122 -0
  8. package/icc-x-api/icc-calendar-item-x-api.js +122 -0
  9. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  10. package/icc-x-api/icc-classification-x-api.d.ts +20 -0
  11. package/icc-x-api/icc-classification-x-api.js +20 -0
  12. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  13. package/icc-x-api/icc-code-x-api.d.ts +23 -0
  14. package/icc-x-api/icc-code-x-api.js +23 -0
  15. package/icc-x-api/icc-code-x-api.js.map +1 -1
  16. package/icc-x-api/icc-contact-x-api.d.ts +219 -1
  17. package/icc-x-api/icc-contact-x-api.js +219 -2
  18. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  19. package/icc-x-api/icc-data-owner-x-api.d.ts +14 -3
  20. package/icc-x-api/icc-data-owner-x-api.js +14 -3
  21. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  22. package/icc-x-api/icc-device-x-api.d.ts +8 -0
  23. package/icc-x-api/icc-device-x-api.js +8 -0
  24. package/icc-x-api/icc-device-x-api.js.map +1 -1
  25. package/icc-x-api/icc-doctemplate-x-api.d.ts +26 -0
  26. package/icc-x-api/icc-doctemplate-x-api.js +26 -0
  27. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  28. package/icc-x-api/icc-document-x-api.d.ts +114 -1
  29. package/icc-x-api/icc-document-x-api.js +127 -1
  30. package/icc-x-api/icc-document-x-api.js.map +1 -1
  31. package/icc-x-api/icc-form-x-api.d.ts +34 -4
  32. package/icc-x-api/icc-form-x-api.js +34 -4
  33. package/icc-x-api/icc-form-x-api.js.map +1 -1
  34. package/icc-x-api/icc-hcparty-x-api.d.ts +67 -0
  35. package/icc-x-api/icc-hcparty-x-api.js +67 -0
  36. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  37. package/icc-x-api/icc-helement-x-api.d.ts +141 -0
  38. package/icc-x-api/icc-helement-x-api.js +141 -0
  39. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  40. package/icc-x-api/icc-invoice-x-api.d.ts +54 -0
  41. package/icc-x-api/icc-invoice-x-api.js +54 -0
  42. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  43. package/icc-x-api/icc-message-x-api.d.ts +162 -0
  44. package/icc-x-api/icc-message-x-api.js +162 -0
  45. package/icc-x-api/icc-message-x-api.js.map +1 -1
  46. package/icc-x-api/icc-patient-x-api.d.ts +245 -0
  47. package/icc-x-api/icc-patient-x-api.js +245 -1
  48. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  49. package/icc-x-api/icc-receipt-x-api.d.ts +25 -0
  50. package/icc-x-api/icc-receipt-x-api.js +25 -0
  51. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  52. package/icc-x-api/icc-user-x-api.d.ts +25 -0
  53. package/icc-x-api/icc-user-x-api.js +25 -0
  54. package/icc-x-api/icc-user-x-api.js.map +1 -1
  55. package/package.json +1 -1
  56. package/test/icc-x-api/icc-form-x-api.js +265 -1
  57. package/test/icc-x-api/icc-form-x-api.js.map +1 -1
  58. package/test/utils/roles.js +5 -0
  59. package/test/utils/roles.js.map +1 -1
  60. package/test/utils/test_utils.js +1 -21
  61. package/test/utils/test_utils.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;A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C;QACH,CAAC;KAAA;IAED;;;;;;;;OAQG;IACH,kBAAkB,CAAC,YAA0B;;QAC3C,OAAO,CAAC,MAAA,YAAY,CAAC,iBAAiB,mCAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;IAC1D,CAAC;IAED;;;;;;;;OAQG;IACG,kBAAkB,CAAC,YAA0B,EAAE,OAAuB,EAAE,SAA6B;;YACzG,IAAI,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,YAAY,CAAC,EAAE,iCAAiC,CAAC,CAAA;YAC7H,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAA;YAC5D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAC1D,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,oCAA4B,CAAC,OAAO,EAAE,EAC/D,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,qCAAiB,CAAC,sBAAsB,CACtD,CAAA;YACD,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnB,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,kCAAO,YAAY,KAAE,iBAAiB,EAAE,GAAG,IAAG,CAAA;YAC/E,CAAC;iBAAM,CAAC;gBACN,OAAO,YAAY,CAAA;YACrB,CAAC;QACH,CAAC;KAAA;IAED,uCAAuC,CAAC,MAAoB,EAAE,SAAmB;QAC/E,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAC7E,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,YAAY,EAAE,EAC3D,SAAS,CACV,CAAA;IACH,CAAC;CACF;AA9iBD,kDA8iBC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields } from './utils'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { PaginatedListCalendarItem } from '../icc-api/model/PaginatedListCalendarItem'\nimport { SecretIdUseOption } from './crypto/SecretIdUseOption'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi implements EncryptedEntityXApi<models.CalendarItem> {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.CalendarItem))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n private readonly autofillAuthor: boolean,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\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 this.encryptedFields = parseEncryptedFields(encryptedKeys, 'CalendarItem.')\n }\n\n newInstance(\n user: User,\n ci: any | CalendarItem,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n alternateRootDelegation?: string\n } = {}\n ) {\n return this.newInstancePatient(user, null, ci, options)\n }\n\n /**\n * Creates a new instance of calendar item with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this calendar item refers to.\n * @param ci initialised data for the calendar item. 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.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classcalendar itemification. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of calendar item.\n */\n async newInstancePatient(\n user: models.User,\n patient: models.Patient | null,\n ci: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n sfkOption?: SecretIdUseOption\n alternateRootDelegation?: string\n } = {}\n ): Promise<models.CalendarItem> {\n const calendarItem = {\n ...(ci ?? {}),\n _type: 'org.taktik.icure.entities.CalendarItem',\n id: ci?.id ?? this.crypto.primitives.randomUuid(),\n created: ci?.created ?? new Date().getTime(),\n modified: ci?.modified ?? new Date().getTime(),\n responsible: ci?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: ci?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: ci?.codes ?? [],\n tags: ci?.tags ?? [],\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 =\n patient != undefined\n ? await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n options.sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n : undefined\n const extraDelegations = {\n ...Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n ),\n ...(options?.additionalDelegates ?? {}),\n }\n return new CalendarItem(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n calendarItem,\n EntityWithDelegationTypeName.CalendarItem,\n patient?.id,\n sfk,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * @deprecated use {@link findIdsBy} instead.\n */\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? usingPost\n ? this.findByHCPartyPatientSecretFKeysArray(hcpartyId!, _.uniq(extractedKeys))\n : this.findByHCPartyPatientSecretFKeys(hcpartyId!, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n\n /**\n * Same as `findBy` but it will only return the ids of the calendar items. It can also filter the access logs where CalendarItem.date is between\n * startDate and endDate in ascending or descending order by that field. (default: ascending).\n */\n async findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean): Promise<string[]> {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n return extractedKeys && extractedKeys.length > 0\n ? this.findCalendarItemIdsByDataOwnerPatientStartTime(hcpartyId, _.uniq(extractedKeys), startDate, endDate, descending)\n : Promise.resolve([])\n }\n\n /**\n * @deprecated use {@link findCalendarItemIdsByDataOwnerPatientStartTime} instead.\n */\n async findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem>> {\n const calendarItems = await super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys)\n return await this.decrypt(hcPartyId, calendarItems)\n }\n\n /**\n * @deprecated use {@link findCalendarItemIdsByDataOwnerPatientStartTime} instead.\n */\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any> {\n return super\n .findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * @deprecated use {@link getCalendarItemsWithPaginationWithUser} instead.\n */\n async getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n async getCalendarItemsWithPaginationWithUser(user: models.User, startDocumentId?: string, limit?: number): Promise<PaginatedListCalendarItem> {\n return super.getCalendarItemsWithPagination(startDocumentId, limit).then((calendarItems) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems.rows ?? []).then(\n (decryptedItems) =>\n new PaginatedListCalendarItem({\n rows: decryptedItems,\n nextKeyPair: calendarItems.nextKeyPair,\n })\n )\n )\n }\n\n getCalendarItemsWithPagination(startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * @deprecated use {@link findCalendarItemsByRecurrenceIdWithPaginationWithUser} instead.\n */\n async findCalendarItemsByRecurrenceIdWithUser(user: models.User, recurrenceId: string): Promise<Array<CalendarItem> | any> {\n return super\n .findCalendarItemsByRecurrenceId(recurrenceId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n findCalendarItemsByRecurrenceId(recurrenceId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n async findCalendarItemsByRecurrenceIdWithPaginationWithUser(\n user: models.User,\n recurrenceId: string,\n startKey?: string,\n startDocumentId?: string,\n limit?: number\n ): Promise<PaginatedListCalendarItem> {\n return super.findCalendarItemsByRecurrenceIdWithPagination(recurrenceId, startKey, startDocumentId, limit).then((calendarItems) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems.rows ?? []).then(\n (decryptedItems) =>\n new PaginatedListCalendarItem({\n rows: decryptedItems,\n nextKeyPair: calendarItems.nextKeyPair,\n })\n )\n )\n }\n\n findCalendarItemsByRecurrenceIdWithPagination(recurrenceId: string, startKey?: string, startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, _.cloneDeep(body)) : null\n }\n\n private modifyAs(dataOwner: string, body: models.CalendarItem): Promise<models.CalendarItem> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((items) => super.modifyCalendarItem(items[0]))\n .then((ci) => this.decrypt(dataOwner, [ci]))\n .then((cis) => cis[0])\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems)\n }\n\n private encryptAs(dataOwner: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return this.crypto.xapi.tryEncryptEntities(\n calendarItems,\n EntityWithDelegationTypeName.CalendarItem,\n this.encryptedFields,\n false,\n false,\n (json) => new CalendarItem(json)\n )\n }\n\n async decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return (\n await this.crypto.xapi.tryDecryptEntities(calendarItems, EntityWithDelegationTypeName.CalendarItem, (json) => new CalendarItem(json))\n ).map(({ entity }) => entity)\n }\n\n /**\n * @param calendarItem a calendar item\n * @return the id of the patient that the calendar item 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(calendarItem: models.CalendarItem): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: calendarItem, type: EntityWithDelegationTypeName.CalendarItem }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given calendar item\n */\n async hasWriteAccess(calendarItem: models.CalendarItem): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: calendarItem, type: EntityWithDelegationTypeName.CalendarItem })\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the calendar item.\n * @param calendarItem item the calendar item to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - 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\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @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\n * the operation failed.\n */\n async shareWith(\n delegateId: string,\n calendarItem: models.CalendarItem,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.CalendarItem> {\n return this.shareWithMany(calendarItem, { [delegateId]: options })\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param calendarItem item the calendar item to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - 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\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n calendarItem: models.CalendarItem,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.CalendarItem> {\n return (await this.tryShareWithMany(calendarItem, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param calendarItem item the calendar item to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - 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\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async tryShareWithMany(\n calendarItem: models.CalendarItem,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.CalendarItem>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(calendarItem, EntityWithDelegationTypeName.CalendarItem)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyAs(self, entityWithEncryptionKey) : calendarItem\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.CalendarItem,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareCalendarItems(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: CalendarItem\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.CalendarItem })\n }\n\n getEncryptionKeysOf(entity: CalendarItem): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.CalendarItem }, undefined)\n }\n\n /**\n * Adds a bidirectional link between a calendar item with a patient.\n * Note that this operation is not reversible: it is not possible to change the patient linked to a calendar\n * item.\n * @param calendarItem a calendar item\n * @param patient the patient which will be linked to the calendar item.\n * @param shareLinkWithDelegates data owners other than the current data owner which will also be able to decrypt the id of the newly linked\n * patient. If any of these data owners do not already have access to the calendar item, they will be granted read access (no write).\n * @param sfkOption specify how to create the link from the patient\n * @return the updated calendar item\n */\n async linkWithPatient(\n calendarItem: models.CalendarItem,\n patient: models.Patient,\n shareLinkWithDelegates: string[],\n sfkOption?: SecretIdUseOption\n ): Promise<models.CalendarItem> {\n if (this.hasLinkFromPatient(calendarItem)) throw new Error(`Calendar item ${calendarItem.id} is already linked to a patient`)\n const delegates = [...new Set([await this.dataOwnerApi.getCurrentDataOwnerId(), ...shareLinkWithDelegates])]\n const sfk = await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n const individualShareData = {\n shareSecretIds: [] as string[],\n shareEncryptionKeys: [] as string[],\n shareOwningEntityIds: [patient.id!],\n requestedPermissions: RequestedPermissionEnum.FULL_READ,\n }\n const shared = await this.crypto.xapi.bulkShareOrUpdateEncryptedEntityMetadata(\n EntityWithDelegationTypeName.CalendarItem,\n [\n {\n entity: calendarItem,\n dataForDelegates: Object.fromEntries(delegates.map((d) => [d, individualShareData])),\n },\n ],\n (x) => this.bulkShareCalendarItems(x)\n )\n if (!shared.updatedEntities.length || shared.updatedEntities[0].id !== calendarItem.id) {\n const errorsForEntity = shared.updateErrors.filter((e) => e.entityId === calendarItem.id)\n if (!errorsForEntity.length || !errorsForEntity.find((x) => x.code === 409)) {\n throw new Error(`Unexpected error while linking calendar item ${calendarItem.id}`)\n } else {\n throw new Error(`Outdated calendar item revision ${calendarItem.id}-${calendarItem.rev}`)\n }\n }\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const sharedDecrypted = (await this.decrypt(self, [shared.updatedEntities[0]]))[0]\n if (sfk.length > 0) {\n return await this.modifyAs(self, { ...sharedDecrypted, secretForeignKeys: sfk })\n } else {\n return sharedDecrypted\n }\n }\n\n /**\n * Checks if a calendar item has an (encrypted) link from a patient.\n * Calendar item where this method returns false won't be findable when searching for them by patient.\n * If this method returns false there may still be a link to the patient; you can check for it by using the method\n * {@link decryptPatientIdOf}.\n *\n * Note: this method only checks the presence of a link, it doesn't verify that it is valid (for example, this method\n * doesn't check if the link from the patient matches the link to the patient).\n */\n hasLinkFromPatient(calendarItem: CalendarItem): boolean {\n return (calendarItem.secretForeignKeys ?? []).length > 0\n }\n\n /**\n * Adds a link to a calendar item allowing it to be found from the patient.\n * This method only adds a partial link; if the calendar item is not already linked to the patient you should\n * instead use the {@link linkWithPatient}\n * @param calendarItem the calendar item to update.\n * @param patient the patient to link with the calendar item.\n * @param sfkOption customize how to create the link.\n * @return the updated calendar item\n */\n async addLinkFromPatient(calendarItem: CalendarItem, patient: models.Patient, sfkOption?: SecretIdUseOption): Promise<CalendarItem> {\n if (this.hasLinkFromPatient(calendarItem)) throw new Error(`Calendar item ${calendarItem.id} is already linked to a patient`)\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const sfk = await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n if (sfk.length > 0) {\n return await this.modifyAs(self, { ...calendarItem, secretForeignKeys: sfk })\n } else {\n return calendarItem\n }\n }\n\n createDelegationDeAnonymizationMetadata(entity: CalendarItem, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.CalendarItem },\n delegates\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAE3B,oDAA4D;AAE5D,wCAA+C;AAE/C,0EAAgG;AAGhG,qFAAiF;AACjF,wEAAoE;AAEpE,mCAAqG;AAErG,IAAO,uBAAuB,GAAG,uCAAkB,CAAC,uBAAuB,CAAA;AAC3E,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AACzD,0FAAsF;AACtF,kEAA8D;AAE9D,MAAa,mBAAoB,SAAQ,4BAAkB;IAMzD,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAA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;OAQG;IACH,kBAAkB,CAAC,YAA0B;;QAC3C,OAAO,CAAC,MAAA,YAAY,CAAC,iBAAiB,mCAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;IAC1D,CAAC;IAED;;;;;;;;OAQG;IACG,kBAAkB,CAAC,YAA0B,EAAE,OAAuB,EAAE,SAA6B;;YACzG,IAAI,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,YAAY,CAAC,EAAE,iCAAiC,CAAC,CAAA;YAC7H,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAA;YAC5D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAC1D,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,oCAA4B,CAAC,OAAO,EAAE,EAC/D,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,qCAAiB,CAAC,sBAAsB,CACtD,CAAA;YACD,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnB,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,kCAAO,YAAY,KAAE,iBAAiB,EAAE,GAAG,IAAG,CAAA;YAC/E,CAAC;iBAAM,CAAC;gBACN,OAAO,YAAY,CAAA;YACrB,CAAC;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACH,uCAAuC,CAAC,MAAoB,EAAE,SAAmB;QAC/E,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAC7E,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,YAAY,EAAE,EAC3D,SAAS,CACV,CAAA;IACH,CAAC;CACF;AAxqBD,kDAwqBC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields } from './utils'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { PaginatedListCalendarItem } from '../icc-api/model/PaginatedListCalendarItem'\nimport { SecretIdUseOption } from './crypto/SecretIdUseOption'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi implements EncryptedEntityXApi<models.CalendarItem> {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.CalendarItem))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n private readonly autofillAuthor: boolean,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\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 this.encryptedFields = parseEncryptedFields(encryptedKeys, 'CalendarItem.')\n }\n\n /**\n * Creates a new instance of calendar item with initialised encryption metadata (not in the database), without\n * linking it to a patient. Use {@link newInstancePatient} to create a calendar item linked to a patient.\n * @param user the current user.\n * @param ci initialised data for the calendar item.\n * @param options optional parameters for delegates and root delegation.\n * @return a new instance of calendar item.\n */\n newInstance(\n user: User,\n ci: any | CalendarItem,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n alternateRootDelegation?: string\n } = {}\n ) {\n return this.newInstancePatient(user, null, ci, options)\n }\n\n /**\n * Creates a new instance of calendar item with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this calendar item refers to.\n * @param ci initialised data for the calendar item. 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.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classcalendar itemification. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of calendar item.\n */\n async newInstancePatient(\n user: models.User,\n patient: models.Patient | null,\n ci: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n sfkOption?: SecretIdUseOption\n alternateRootDelegation?: string\n } = {}\n ): Promise<models.CalendarItem> {\n const calendarItem = {\n ...(ci ?? {}),\n _type: 'org.taktik.icure.entities.CalendarItem',\n id: ci?.id ?? this.crypto.primitives.randomUuid(),\n created: ci?.created ?? new Date().getTime(),\n modified: ci?.modified ?? new Date().getTime(),\n responsible: ci?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: ci?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: ci?.codes ?? [],\n tags: ci?.tags ?? [],\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 =\n patient != undefined\n ? await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n options.sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n : undefined\n const extraDelegations = {\n ...Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n ),\n ...(options?.additionalDelegates ?? {}),\n }\n return new CalendarItem(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n calendarItem,\n EntityWithDelegationTypeName.CalendarItem,\n patient?.id,\n sfk,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * @deprecated use {@link findIdsBy} instead.\n */\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? usingPost\n ? this.findByHCPartyPatientSecretFKeysArray(hcpartyId!, _.uniq(extractedKeys))\n : this.findByHCPartyPatientSecretFKeys(hcpartyId!, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n\n /**\n * Same as `findBy` but it will only return the ids of the calendar items. It can also filter the access logs where CalendarItem.date is between\n * startDate and endDate in ascending or descending order by that field. (default: ascending).\n */\n async findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean): Promise<string[]> {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n return extractedKeys && extractedKeys.length > 0\n ? this.findCalendarItemIdsByDataOwnerPatientStartTime(hcpartyId, _.uniq(extractedKeys), startDate, endDate, descending)\n : Promise.resolve([])\n }\n\n /**\n * @deprecated use {@link findCalendarItemIdsByDataOwnerPatientStartTime} instead.\n */\n async findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem>> {\n const calendarItems = await super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys)\n return await this.decrypt(hcPartyId, calendarItems)\n }\n\n /**\n * @deprecated use {@link findCalendarItemIdsByDataOwnerPatientStartTime} instead.\n */\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any> {\n return super\n .findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n /**\n * @throws always. Use {@link createCalendarItemWithHcParty} instead.\n */\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Creates a calendar item after encrypting its content.\n * @param user the current user, used for encryption.\n * @param body the calendar item to create.\n * @return the created and decrypted calendar item.\n */\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n /**\n * Retrieves a calendar item by id and decrypts it.\n * @param user the current user, used for decryption.\n * @param calendarItemId the id of the calendar item to retrieve.\n * @return the decrypted calendar item.\n */\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n /**\n * @throws always. Use {@link getCalendarItemWithUser} instead.\n */\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * @deprecated use {@link getCalendarItemsWithPaginationWithUser} instead.\n */\n async getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n /**\n * @throws always. Use {@link getCalendarItemsWithPaginationWithUser} instead.\n */\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Retrieves calendar items with pagination and decrypts them.\n * @param user the current user, used for decryption.\n * @param startDocumentId the pagination start document id.\n * @param limit the maximum number of results to return.\n * @return a paginated list of decrypted calendar items.\n */\n async getCalendarItemsWithPaginationWithUser(user: models.User, startDocumentId?: string, limit?: number): Promise<PaginatedListCalendarItem> {\n return super.getCalendarItemsWithPagination(startDocumentId, limit).then((calendarItems) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems.rows ?? []).then(\n (decryptedItems) =>\n new PaginatedListCalendarItem({\n rows: decryptedItems,\n nextKeyPair: calendarItems.nextKeyPair,\n })\n )\n )\n }\n\n /**\n * @throws always. Use {@link getCalendarItemsWithPaginationWithUser} instead.\n */\n getCalendarItemsWithPagination(startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * @deprecated use {@link findCalendarItemsByRecurrenceIdWithPaginationWithUser} instead.\n */\n async findCalendarItemsByRecurrenceIdWithUser(user: models.User, recurrenceId: string): Promise<Array<CalendarItem> | any> {\n return super\n .findCalendarItemsByRecurrenceId(recurrenceId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n /**\n * @throws always. Use {@link findCalendarItemsByRecurrenceIdWithPaginationWithUser} instead.\n */\n findCalendarItemsByRecurrenceId(recurrenceId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Finds calendar items by recurrence id with pagination and decrypts them.\n * @param user the current user, used for decryption.\n * @param recurrenceId the recurrence id to search for.\n * @param startKey the pagination start key.\n * @param startDocumentId the pagination start document id.\n * @param limit the maximum number of results to return.\n * @return a paginated list of decrypted calendar items matching the recurrence id.\n */\n async findCalendarItemsByRecurrenceIdWithPaginationWithUser(\n user: models.User,\n recurrenceId: string,\n startKey?: string,\n startDocumentId?: string,\n limit?: number\n ): Promise<PaginatedListCalendarItem> {\n return super.findCalendarItemsByRecurrenceIdWithPagination(recurrenceId, startKey, startDocumentId, limit).then((calendarItems) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems.rows ?? []).then(\n (decryptedItems) =>\n new PaginatedListCalendarItem({\n rows: decryptedItems,\n nextKeyPair: calendarItems.nextKeyPair,\n })\n )\n )\n }\n\n /**\n * @throws always. Use {@link findCalendarItemsByRecurrenceIdWithPaginationWithUser} instead.\n */\n findCalendarItemsByRecurrenceIdWithPagination(recurrenceId: string, startKey?: string, startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Retrieves multiple calendar items by their ids and decrypts them.\n * @param user the current user, used for decryption.\n * @param body the list of calendar item ids to retrieve.\n * @return the decrypted calendar items.\n */\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n /**\n * @throws always. Use {@link getCalendarItemsWithIdsWithUser} instead.\n */\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Retrieves calendar items for a given healthcare party within a date range and decrypts them.\n * @param user the current user, used for decryption.\n * @param startDate the start of the date range.\n * @param endDate the end of the date range.\n * @param hcPartyId the id of the healthcare party.\n * @return the decrypted calendar items.\n */\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n /**\n * @throws always. Use {@link getCalendarItemsByPeriodAndHcPartyIdWithUser} instead.\n */\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Retrieves calendar items for a given agenda within a date range and decrypts them.\n * @param user the current user, used for decryption.\n * @param startDate the start of the date range.\n * @param endDate the end of the date range.\n * @param agendaId the id of the agenda.\n * @return the decrypted calendar items.\n */\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n /**\n * @throws always. Use {@link getCalendarsByPeriodAndAgendaIdWithUser} instead.\n */\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * @throws always. Use {@link modifyCalendarItemWithHcParty} instead.\n */\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n /**\n * Modifies a calendar item after encrypting its content.\n * @param user the current user, used for encryption/decryption.\n * @param body the calendar item with updated fields.\n * @return the modified and decrypted calendar item, or null if body was not provided.\n */\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, _.cloneDeep(body)) : null\n }\n\n private modifyAs(dataOwner: string, body: models.CalendarItem): Promise<models.CalendarItem> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((items) => super.modifyCalendarItem(items[0]))\n .then((ci) => this.decrypt(dataOwner, [ci]))\n .then((cis) => cis[0])\n }\n\n /**\n * Encrypts the encrypted fields of a list of calendar items.\n * @param user the current user, used to determine the data owner for encryption.\n * @param calendarItems the calendar items to encrypt.\n * @return the encrypted calendar items.\n */\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems)\n }\n\n private encryptAs(dataOwner: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return this.crypto.xapi.tryEncryptEntities(\n calendarItems,\n EntityWithDelegationTypeName.CalendarItem,\n this.encryptedFields,\n false,\n false,\n (json) => new CalendarItem(json)\n )\n }\n\n /**\n * Decrypts a list of calendar items using the current data owner's keys.\n * @param hcpId the id of the healthcare party performing the decryption.\n * @param calendarItems the calendar items to decrypt.\n * @return the decrypted calendar items.\n */\n async decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return (\n await this.crypto.xapi.tryDecryptEntities(calendarItems, EntityWithDelegationTypeName.CalendarItem, (json) => new CalendarItem(json))\n ).map(({ entity }) => entity)\n }\n\n /**\n * @param calendarItem a calendar item\n * @return the id of the patient that the calendar item 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(calendarItem: models.CalendarItem): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: calendarItem, type: EntityWithDelegationTypeName.CalendarItem }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given calendar item\n */\n async hasWriteAccess(calendarItem: models.CalendarItem): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: calendarItem, type: EntityWithDelegationTypeName.CalendarItem })\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the calendar item.\n * @param calendarItem item the calendar item to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - 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\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @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\n * the operation failed.\n */\n async shareWith(\n delegateId: string,\n calendarItem: models.CalendarItem,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.CalendarItem> {\n return this.shareWithMany(calendarItem, { [delegateId]: options })\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param calendarItem item the calendar item to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - 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\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n calendarItem: models.CalendarItem,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.CalendarItem> {\n return (await this.tryShareWithMany(calendarItem, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param calendarItem item the calendar item to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - 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\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async tryShareWithMany(\n calendarItem: models.CalendarItem,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.CalendarItem>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(calendarItem, EntityWithDelegationTypeName.CalendarItem)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyAs(self, entityWithEncryptionKey) : calendarItem\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.CalendarItem,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareCalendarItems(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt(self, [e]).then((es) => es[0])))\n }\n\n /**\n * Retrieves the data owners that have access to the given calendar item, along with their access levels.\n * @param entity the calendar item.\n * @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.\n */\n getDataOwnersWithAccessTo(\n entity: CalendarItem\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.CalendarItem })\n }\n\n /**\n * Retrieves the encryption keys of the given calendar item.\n * @param entity the calendar item.\n * @return the encryption key ids.\n */\n getEncryptionKeysOf(entity: CalendarItem): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.CalendarItem }, undefined)\n }\n\n /**\n * Adds a bidirectional link between a calendar item with a patient.\n * Note that this operation is not reversible: it is not possible to change the patient linked to a calendar\n * item.\n * @param calendarItem a calendar item\n * @param patient the patient which will be linked to the calendar item.\n * @param shareLinkWithDelegates data owners other than the current data owner which will also be able to decrypt the id of the newly linked\n * patient. If any of these data owners do not already have access to the calendar item, they will be granted read access (no write).\n * @param sfkOption specify how to create the link from the patient\n * @return the updated calendar item\n */\n async linkWithPatient(\n calendarItem: models.CalendarItem,\n patient: models.Patient,\n shareLinkWithDelegates: string[],\n sfkOption?: SecretIdUseOption\n ): Promise<models.CalendarItem> {\n if (this.hasLinkFromPatient(calendarItem)) throw new Error(`Calendar item ${calendarItem.id} is already linked to a patient`)\n const delegates = [...new Set([await this.dataOwnerApi.getCurrentDataOwnerId(), ...shareLinkWithDelegates])]\n const sfk = await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n const individualShareData = {\n shareSecretIds: [] as string[],\n shareEncryptionKeys: [] as string[],\n shareOwningEntityIds: [patient.id!],\n requestedPermissions: RequestedPermissionEnum.FULL_READ,\n }\n const shared = await this.crypto.xapi.bulkShareOrUpdateEncryptedEntityMetadata(\n EntityWithDelegationTypeName.CalendarItem,\n [\n {\n entity: calendarItem,\n dataForDelegates: Object.fromEntries(delegates.map((d) => [d, individualShareData])),\n },\n ],\n (x) => this.bulkShareCalendarItems(x)\n )\n if (!shared.updatedEntities.length || shared.updatedEntities[0].id !== calendarItem.id) {\n const errorsForEntity = shared.updateErrors.filter((e) => e.entityId === calendarItem.id)\n if (!errorsForEntity.length || !errorsForEntity.find((x) => x.code === 409)) {\n throw new Error(`Unexpected error while linking calendar item ${calendarItem.id}`)\n } else {\n throw new Error(`Outdated calendar item revision ${calendarItem.id}-${calendarItem.rev}`)\n }\n }\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const sharedDecrypted = (await this.decrypt(self, [shared.updatedEntities[0]]))[0]\n if (sfk.length > 0) {\n return await this.modifyAs(self, { ...sharedDecrypted, secretForeignKeys: sfk })\n } else {\n return sharedDecrypted\n }\n }\n\n /**\n * Checks if a calendar item has an (encrypted) link from a patient.\n * Calendar item where this method returns false won't be findable when searching for them by patient.\n * If this method returns false there may still be a link to the patient; you can check for it by using the method\n * {@link decryptPatientIdOf}.\n *\n * Note: this method only checks the presence of a link, it doesn't verify that it is valid (for example, this method\n * doesn't check if the link from the patient matches the link to the patient).\n */\n hasLinkFromPatient(calendarItem: CalendarItem): boolean {\n return (calendarItem.secretForeignKeys ?? []).length > 0\n }\n\n /**\n * Adds a link to a calendar item allowing it to be found from the patient.\n * This method only adds a partial link; if the calendar item is not already linked to the patient you should\n * instead use the {@link linkWithPatient}\n * @param calendarItem the calendar item to update.\n * @param patient the patient to link with the calendar item.\n * @param sfkOption customize how to create the link.\n * @return the updated calendar item\n */\n async addLinkFromPatient(calendarItem: CalendarItem, patient: models.Patient, sfkOption?: SecretIdUseOption): Promise<CalendarItem> {\n if (this.hasLinkFromPatient(calendarItem)) throw new Error(`Calendar item ${calendarItem.id} is already linked to a patient`)\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const sfk = await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n if (sfk.length > 0) {\n return await this.modifyAs(self, { ...calendarItem, secretForeignKeys: sfk })\n } else {\n return calendarItem\n }\n }\n\n /**\n * Creates or updates de-anonymization metadata for the given calendar item, allowing the specified delegates to\n * identify the data owners that have access to it.\n * @param entity the calendar item.\n * @param delegates the data owner ids for which to create de-anonymization metadata.\n */\n createDelegationDeAnonymizationMetadata(entity: CalendarItem, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.CalendarItem },\n delegates\n )\n }\n}\n"]}
@@ -48,6 +48,10 @@ export declare class IccClassificationXApi extends IccClassificationApi implemen
48
48
  * @deprecated use {@link findIdsBy} instead.
49
49
  */
50
50
  findBy(hcpartyId: string, patient: models.Patient): Promise<models.Classification[]>;
51
+ /**
52
+ * Same as {@link findBy} but it will only return the ids of the classifications. It can also filter the classifications where
53
+ * Classification.created is between startDate and endDate in ascending or descending order by that field (default: ascending).
54
+ */
51
55
  findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean): Promise<string[]>;
52
56
  /**
53
57
  * @param classification a classification
@@ -125,12 +129,28 @@ export declare class IccClassificationXApi extends IccClassificationApi implemen
125
129
  sharePatientId?: ShareMetadataBehaviour;
126
130
  };
127
131
  }): Promise<ShareResult<models.Classification>>;
132
+ /**
133
+ * Retrieves the data owners that have access to the given classification, along with their access levels.
134
+ * @param entity the classification.
135
+ * @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.
136
+ */
128
137
  getDataOwnersWithAccessTo(entity: models.Classification): Promise<{
129
138
  permissionsByDataOwnerId: {
130
139
  [p: string]: AccessLevelEnum;
131
140
  };
132
141
  hasUnknownAnonymousDataOwners: boolean;
133
142
  }>;
143
+ /**
144
+ * Retrieves the encryption keys of the given classification.
145
+ * @param entity the classification.
146
+ * @return the encryption key ids.
147
+ */
134
148
  getEncryptionKeysOf(entity: models.Classification): Promise<string[]>;
149
+ /**
150
+ * Creates or updates de-anonymization metadata for the given classification, allowing the specified delegates to
151
+ * identify the data owners that have access to it.
152
+ * @param entity the classification.
153
+ * @param delegates the data owner ids for which to create de-anonymization metadata.
154
+ */
135
155
  createDelegationDeAnonymizationMetadata(entity: models.Classification, delegates: string[]): Promise<void>;
136
156
  }
@@ -77,6 +77,10 @@ class IccClassificationXApi extends icc_api_1.IccClassificationApi {
77
77
  : Promise.resolve([]);
78
78
  });
79
79
  }
80
+ /**
81
+ * Same as {@link findBy} but it will only return the ids of the classifications. It can also filter the classifications where
82
+ * Classification.created is between startDate and endDate in ascending or descending order by that field (default: ascending).
83
+ */
80
84
  findIdsBy(hcpartyId, patient, startDate, endDate, descending) {
81
85
  return __awaiter(this, void 0, void 0, function* () {
82
86
  const extractedKeys = yield this.crypto.xapi.secretIdsOf({ entity: patient, type: utils_1.EntityWithDelegationTypeName.Patient }, hcpartyId);
@@ -177,12 +181,28 @@ class IccClassificationXApi extends icc_api_1.IccClassificationApi {
177
181
  ])), (x) => this.bulkShareClassifications(x));
178
182
  });
179
183
  }
184
+ /**
185
+ * Retrieves the data owners that have access to the given classification, along with their access levels.
186
+ * @param entity the classification.
187
+ * @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.
188
+ */
180
189
  getDataOwnersWithAccessTo(entity) {
181
190
  return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: utils_1.EntityWithDelegationTypeName.Classification });
182
191
  }
192
+ /**
193
+ * Retrieves the encryption keys of the given classification.
194
+ * @param entity the classification.
195
+ * @return the encryption key ids.
196
+ */
183
197
  getEncryptionKeysOf(entity) {
184
198
  return this.crypto.xapi.encryptionKeysOf({ entity, type: utils_1.EntityWithDelegationTypeName.Classification }, undefined);
185
199
  }
200
+ /**
201
+ * Creates or updates de-anonymization metadata for the given classification, allowing the specified delegates to
202
+ * identify the data owners that have access to it.
203
+ * @param entity the classification.
204
+ * @param delegates the data owner ids for which to create de-anonymization metadata.
205
+ */
186
206
  createDelegationDeAnonymizationMetadata(entity, delegates) {
187
207
  return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: utils_1.EntityWithDelegationTypeName.Classification }, delegates);
188
208
  }
@@ -1 +1 @@
1
- {"version":3,"file":"icc-classification-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-classification-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAiD;AAGjD,kDAAiD;AAEjD,4BAA2B;AAC3B,iCAAgC;AAEhC,0EAAgG;AAChG,wEAAoE;AAIpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAIzD,mCAAsD;AACtD,kEAA8D;AAE9D,MAAa,qBAAsB,SAAQ,8BAAoB;IAI7D,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,cAAc,CAAC,CAAC,CAAA;IACpJ,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EACb,cAAuB,EACxC,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;QARtC,mBAAc,GAAd,cAAc,CAAS;QASxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,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,CAAC;CACF;AA/PD,sDA+PC","sourcesContent":["import { IccClassificationApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport * as moment from 'moment'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { EntityWithDelegationTypeName } from './utils'\nimport { SecretIdUseOption } from './crypto/SecretIdUseOption'\n\nexport class IccClassificationXApi extends IccClassificationApi implements EncryptedEntityXApi<models.Classification> {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Classification))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n private readonly autofillAuthor: boolean,\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 classification with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this classification refers to.\n * @param c initialised data for the classification. 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.\n * - sfkOption: specifies which sfk of the owning entity to use.\n * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of classification.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n c: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n sfkOption?: SecretIdUseOption\n ignoreAutoDelegations?: boolean\n alternateRootDelegation?: string\n } = {}\n ): Promise<models.Classification> {\n const classification = {\n ...(c ?? {}),\n _type: 'org.taktik.icure.entities.Classification',\n id: c?.id ?? this.crypto.primitives.randomUuid(),\n created: c?.created ?? new Date().getTime(),\n modified: c?.modified ?? new Date().getTime(),\n responsible: c?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: c?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: c?.codes ?? [],\n tags: c?.tags ?? [],\n healthElementId: c?.healthElementId ?? this.crypto.primitives.randomUuid(),\n openingDate: c?.openingDate ?? parseInt(moment().format('YYYYMMDDHHmmss')),\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 = await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n options.sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n const extraDelegations = {\n ...(options.ignoreAutoDelegations == true\n ? {}\n : Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n )),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Classification(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n classification,\n EntityWithDelegationTypeName.Classification,\n patient?.id,\n sfk,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * @deprecated use {@link findIdsBy} instead.\n */\n async findBy(hcpartyId: string, patient: models.Patient) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? this.findClassificationsByHCPartyPatientForeignKeys(topmostParentId, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n\n async findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? this.findClassificationIdsByDataOwnerPatientCreated(topmostParentId, _.uniq(extractedKeys), startDate, endDate, descending)\n : Promise.resolve([])\n }\n\n /**\n * @param classification a classification\n * @return the id of the patient that the classification 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(classification: models.Classification): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: classification, type: EntityWithDelegationTypeName.Classification }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given classification\n */\n async hasWriteAccess(classification: models.Classification): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: classification, type: EntityWithDelegationTypeName.Classification })\n }\n\n /**\n * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the classification.\n * @param classification the classification to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - 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\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 * classification does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n classification: models.Classification,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Classification> {\n return this.shareWithMany(classification, { [delegateId]: options })\n }\n\n /**\n * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param classification the classification to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - 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\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 * classification does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n classification: models.Classification,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Classification> {\n return (await this.tryShareWithMany(classification, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param classification the classification to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - 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\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 * classification does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @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\n * the operation failed.\n */\n async tryShareWithMany(\n classification: models.Classification,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Classification>> {\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(\n classification,\n EntityWithDelegationTypeName.Classification\n )\n const updatedEntity = entityWithEncryptionKey ? await this.modifyClassification(entityWithEncryptionKey) : classification\n return this.crypto.xapi.simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Classification,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareClassifications(x)\n )\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Classification\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Classification })\n }\n\n getEncryptionKeysOf(entity: models.Classification): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Classification }, undefined)\n }\n\n createDelegationDeAnonymizationMetadata(entity: models.Classification, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.Classification },\n delegates\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-classification-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-classification-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAiD;AAGjD,kDAAiD;AAEjD,4BAA2B;AAC3B,iCAAgC;AAEhC,0EAAgG;AAChG,wEAAoE;AAIpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAIzD,mCAAsD;AACtD,kEAA8D;AAE9D,MAAa,qBAAsB,SAAQ,8BAAoB;IAI7D,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OA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AAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,CACxC,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACH,yBAAyB,CACvB,MAA6B;QAE7B,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,cAAc,EAAE,CAAC,CAAA;IACxI,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,MAA6B;QAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,cAAc,EAAE,EAAE,SAAS,CAAC,CAAA;IACpH,CAAC;IAED;;;;;OAKG;IACH,uCAAuC,CAAC,MAA6B,EAAE,SAAmB;QACxF,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAC7E,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,cAAc,EAAE,EAC7D,SAAS,CACV,CAAA;IACH,CAAC;CACF;AAnRD,sDAmRC","sourcesContent":["import { IccClassificationApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport * as moment from 'moment'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { EntityWithDelegationTypeName } from './utils'\nimport { SecretIdUseOption } from './crypto/SecretIdUseOption'\n\nexport class IccClassificationXApi extends IccClassificationApi implements EncryptedEntityXApi<models.Classification> {\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Classification))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n private readonly autofillAuthor: boolean,\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 classification with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this classification refers to.\n * @param c initialised data for the classification. 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.\n * - sfkOption: specifies which sfk of the owning entity to use.\n * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of classification.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n c: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n sfkOption?: SecretIdUseOption\n ignoreAutoDelegations?: boolean\n alternateRootDelegation?: string\n } = {}\n ): Promise<models.Classification> {\n const classification = {\n ...(c ?? {}),\n _type: 'org.taktik.icure.entities.Classification',\n id: c?.id ?? this.crypto.primitives.randomUuid(),\n created: c?.created ?? new Date().getTime(),\n modified: c?.modified ?? new Date().getTime(),\n responsible: c?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: c?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: c?.codes ?? [],\n tags: c?.tags ?? [],\n healthElementId: c?.healthElementId ?? this.crypto.primitives.randomUuid(),\n openingDate: c?.openingDate ?? parseInt(moment().format('YYYYMMDDHHmmss')),\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 = await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n options.sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n const extraDelegations = {\n ...(options.ignoreAutoDelegations == true\n ? {}\n : Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n )),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Classification(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n classification,\n EntityWithDelegationTypeName.Classification,\n patient?.id,\n sfk,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * @deprecated use {@link findIdsBy} instead.\n */\n async findBy(hcpartyId: string, patient: models.Patient) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? this.findClassificationsByHCPartyPatientForeignKeys(topmostParentId, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n\n /**\n * Same as {@link findBy} but it will only return the ids of the classifications. It can also filter the classifications where\n * Classification.created is between startDate and endDate in ascending or descending order by that field (default: ascending).\n */\n async findIdsBy(hcpartyId: string, patient: models.Patient, startDate?: number, endDate?: number, descending?: boolean) {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? this.findClassificationIdsByDataOwnerPatientCreated(topmostParentId, _.uniq(extractedKeys), startDate, endDate, descending)\n : Promise.resolve([])\n }\n\n /**\n * @param classification a classification\n * @return the id of the patient that the classification 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(classification: models.Classification): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: classification, type: EntityWithDelegationTypeName.Classification }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given classification\n */\n async hasWriteAccess(classification: models.Classification): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: classification, type: EntityWithDelegationTypeName.Classification })\n }\n\n /**\n * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the classification.\n * @param classification the classification to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - 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\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 * classification does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n classification: models.Classification,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Classification> {\n return this.shareWithMany(classification, { [delegateId]: options })\n }\n\n /**\n * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param classification the classification to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - 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\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 * classification does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n classification: models.Classification,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Classification> {\n return (await this.tryShareWithMany(classification, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing classification with other data owners, allowing them to access the non-encrypted data of the classification and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param classification the classification to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - 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\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 * classification does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this classification refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @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\n * the operation failed.\n */\n async tryShareWithMany(\n classification: models.Classification,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Classification>> {\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(\n classification,\n EntityWithDelegationTypeName.Classification\n )\n const updatedEntity = entityWithEncryptionKey ? await this.modifyClassification(entityWithEncryptionKey) : classification\n return this.crypto.xapi.simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Classification,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareClassifications(x)\n )\n }\n\n /**\n * Retrieves the data owners that have access to the given classification, along with their access levels.\n * @param entity the classification.\n * @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.\n */\n getDataOwnersWithAccessTo(\n entity: models.Classification\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Classification })\n }\n\n /**\n * Retrieves the encryption keys of the given classification.\n * @param entity the classification.\n * @return the encryption key ids.\n */\n getEncryptionKeysOf(entity: models.Classification): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Classification }, undefined)\n }\n\n /**\n * Creates or updates de-anonymization metadata for the given classification, allowing the specified delegates to\n * identify the data owners that have access to it.\n * @param entity the classification.\n * @param delegates the data owner ids for which to create de-anonymization metadata.\n */\n createDelegationDeAnonymizationMetadata(entity: models.Classification, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.Classification },\n delegates\n )\n }\n}\n"]}
@@ -8,9 +8,32 @@ export declare class IccCodeXApi extends IccCodeApi {
8
8
  constructor(host: string, headers: {
9
9
  [key: string]: string;
10
10
  }, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
11
+ /**
12
+ * Groups a list of ICD-10 codes by their corresponding ICD-10 chapter.
13
+ * @param listOfCodes an array of ICD-10 code strings to classify into chapters.
14
+ * @return a sorted array of chapter objects, each containing a code, description, and list of matching sub-codes.
15
+ */
11
16
  icdChapters(listOfCodes: Array<string>): Promise<any[]>;
17
+ /**
18
+ * Groups a list of ICPC-2 codes by their corresponding ICPC-2 chapter.
19
+ * @param listOfCodes an array of ICPC-2 code strings to classify into chapters.
20
+ * @return a sorted array of chapter objects, each containing a code, description, and list of matching sub-codes.
21
+ */
12
22
  icpcChapters(listOfCodes: Array<string>): Promise<any[]>;
23
+ /**
24
+ * Returns the appropriate language code for a given code type. Falls back to French ('fr') if the
25
+ * requested language is not available for the specified type.
26
+ * @param type the code type to look up available languages for.
27
+ * @param lng the desired language code.
28
+ * @return the requested language code if available, or 'fr' as a fallback.
29
+ */
13
30
  languageForType(type: string, lng: string): string;
31
+ /**
32
+ * Normalizes a code, ensuring it has a consistent structure with id, type, code, and version fields.
33
+ * Accepts either a pipe-delimited string (e.g. "type|code|version") or a Code object.
34
+ * @param c a code represented as a pipe-delimited string or a Code object.
35
+ * @return an object with id, type, code, and version fields fully populated.
36
+ */
14
37
  normalize(c: Code | string): {
15
38
  id: string;
16
39
  type: string | undefined;
@@ -18,6 +18,11 @@ class IccCodeXApi extends icc_api_1.IccCodeApi {
18
18
  this.icpc2 = icpc2_1.default;
19
19
  this.codeLanguages = codelng_1.default;
20
20
  }
21
+ /**
22
+ * Groups a list of ICD-10 codes by their corresponding ICD-10 chapter.
23
+ * @param listOfCodes an array of ICD-10 code strings to classify into chapters.
24
+ * @return a sorted array of chapter objects, each containing a code, description, and list of matching sub-codes.
25
+ */
21
26
  // noinspection JSUnusedGlobalSymbols
22
27
  icdChapters(listOfCodes) {
23
28
  return Promise.resolve(_.sortBy(_.values(_.reduce(_.fromPairs(listOfCodes.map((code) => [
@@ -40,6 +45,11 @@ class IccCodeXApi extends icc_api_1.IccCodeApi {
40
45
  return acc;
41
46
  }, {})), (c) => c.shortKey));
42
47
  }
48
+ /**
49
+ * Groups a list of ICPC-2 codes by their corresponding ICPC-2 chapter.
50
+ * @param listOfCodes an array of ICPC-2 code strings to classify into chapters.
51
+ * @return a sorted array of chapter objects, each containing a code, description, and list of matching sub-codes.
52
+ */
43
53
  // noinspection JSUnusedGlobalSymbols
44
54
  icpcChapters(listOfCodes) {
45
55
  return Promise.resolve(_.sortBy(_.values(_.reduce(_.fromPairs(listOfCodes.map((code) => [code, _.toPairs(this.icpc2).find(([k]) => k === code.substr(0, 1).toUpperCase())])), (acc, pairOfRangeAndIcdInfo, code) => {
@@ -56,11 +66,24 @@ class IccCodeXApi extends icc_api_1.IccCodeApi {
56
66
  return acc;
57
67
  }, {})), (c) => c.shortKey));
58
68
  }
69
+ /**
70
+ * Returns the appropriate language code for a given code type. Falls back to French ('fr') if the
71
+ * requested language is not available for the specified type.
72
+ * @param type the code type to look up available languages for.
73
+ * @param lng the desired language code.
74
+ * @return the requested language code if available, or 'fr' as a fallback.
75
+ */
59
76
  // noinspection JSUnusedGlobalSymbols
60
77
  languageForType(type, lng) {
61
78
  const availableLanguages = this.codeLanguages[type];
62
79
  return availableLanguages && availableLanguages.indexOf(lng) >= 0 ? lng : 'fr';
63
80
  }
81
+ /**
82
+ * Normalizes a code, ensuring it has a consistent structure with id, type, code, and version fields.
83
+ * Accepts either a pipe-delimited string (e.g. "type|code|version") or a Code object.
84
+ * @param c a code represented as a pipe-delimited string or a Code object.
85
+ * @return an object with id, type, code, and version fields fully populated.
86
+ */
64
87
  // noinspection JSMethodCanBeStatic, JSUnusedGlobalSymbols
65
88
  normalize(c) {
66
89
  return typeof c === 'string'
@@ -1 +1 @@
1
- {"version":3,"file":"icc-code-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-code-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AAEvC,4CAA0C;AAC1C,wCAAgC;AAChC,wCAAgC;AAEhC,4BAA2B;AAE3B,0EAAgG;AAEhG,MAAa,WAAY,SAAQ,oBAAU;IAKzC,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,UAAK,GAAQ,eAAK,CAAA;QAClB,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CAAU,CAAC,EAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;qBACxC;oBACH,CAAC,CAAC;wBACE,EAAE,EAAG,CAAU,CAAC,EAAG;wBACnB,IAAI,EAAG,CAAU,CAAC,IAAI;wBACtB,IAAI,EAAG,CAAU,CAAC,IAAI;wBACtB,OAAO,EAAG,CAAU,CAAC,OAAO,IAAI,GAAG;qBACpC,CAAA;IACP,CAAC;CACF;AA1HD,kCA0HC","sourcesContent":["import { IccCodeApi } from '../icc-api'\n\nimport codeLanguages from './rsrc/codelng'\nimport icd10 from './rsrc/icd10'\nimport icpc2 from './rsrc/icpc2'\n\nimport * as _ from 'lodash'\nimport { Code } from '../icc-api/model/Code'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccCodeXApi extends IccCodeApi {\n icd10: any = icd10\n icpc2: any = icpc2\n codeLanguages: any = codeLanguages\n\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 // noinspection JSUnusedGlobalSymbols\n icdChapters(listOfCodes: Array<string>) {\n return Promise.resolve(\n _.sortBy(\n _.values(\n _.reduce(\n _.fromPairs(\n listOfCodes.map((code) => [\n code,\n _.toPairs(this.icd10).find(([k]) => {\n const parts = k.split(/-/)\n return code.substr(0, 3) >= parts[0] && code.substr(0, 3) <= parts[1]\n }),\n ])\n ),\n (acc: any, pairOfRangeAndIcdInfo, code) => {\n if (!pairOfRangeAndIcdInfo) {\n return acc\n }\n const shortKey = pairOfRangeAndIcdInfo[0].substr(0, 2)\n ;(\n acc[shortKey] ||\n (acc[shortKey] = {\n code: shortKey,\n descr: pairOfRangeAndIcdInfo[1],\n subCodes: [],\n })\n ).subCodes.push(code)\n return acc\n },\n {}\n )\n ),\n (c: any) => c.shortKey\n )\n )\n }\n\n // noinspection JSUnusedGlobalSymbols\n icpcChapters(listOfCodes: Array<string>) {\n return Promise.resolve(\n _.sortBy(\n _.values(\n _.reduce(\n _.fromPairs(listOfCodes.map((code) => [code, _.toPairs(this.icpc2).find(([k]) => k === code.substr(0, 1).toUpperCase())])),\n (acc: any, pairOfRangeAndIcdInfo, code) => {\n if (!pairOfRangeAndIcdInfo) {\n return acc\n }\n const shortKey = pairOfRangeAndIcdInfo[0]\n ;(\n acc[shortKey] ||\n (acc[shortKey] = {\n code: shortKey,\n descr: pairOfRangeAndIcdInfo[1],\n subCodes: [],\n })\n ).subCodes.push(code)\n return acc\n },\n {}\n )\n ),\n (c: any) => c.shortKey\n )\n )\n }\n\n // noinspection JSUnusedGlobalSymbols\n languageForType(type: string, lng: string) {\n const availableLanguages = this.codeLanguages[type]\n return availableLanguages && availableLanguages.indexOf(lng) >= 0 ? lng : 'fr'\n }\n\n // noinspection JSMethodCanBeStatic, JSUnusedGlobalSymbols\n normalize(c: Code | string) {\n return typeof c === 'string'\n ? {\n id: c,\n type: c.split(/\\|/)[0],\n code: c.split(/\\|/)[1],\n version: c.split(/\\|/)[2],\n }\n : (c as Code).type && (c as Code).code && !(c as Code).id\n ? {\n id: (c as Code).type + '|' + (c as Code).code + '|' + ((c as Code).version || '1'),\n type: (c as Code).type,\n code: (c as Code).code,\n version: (c as Code).version || '1',\n }\n : (c as Code).id && (!(c as Code).code || !(c as Code).type || !(c as Code).version)\n ? {\n id: (c as Code).id,\n type: (c as Code).id!.split(/\\|/)[0],\n code: (c as Code).id!.split(/\\|/)[1],\n version: (c as Code).id!.split(/\\|/)[2],\n }\n : {\n id: (c as Code).id!,\n type: (c as Code).type,\n code: (c as Code).code,\n version: (c as Code).version || '1',\n }\n }\n}\n"]}
1
+ {"version":3,"file":"icc-code-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-code-x-api.ts"],"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AAE,CAAU,CAAC,OAAO,IAAI,GAAG,CAAC;oBAClF,IAAI,EAAG,CAAU,CAAC,IAAI;oBACtB,IAAI,EAAG,CAAU,CAAC,IAAI;oBACtB,OAAO,EAAG,CAAU,CAAC,OAAO,IAAI,GAAG;iBACpC;gBACH,CAAC,CAAE,CAAU,CAAC,EAAE,IAAI,CAAC,CAAE,CAAU,CAAC,IAAI,IAAI,CAAE,CAAU,CAAC,IAAI,IAAI,CAAE,CAAU,CAAC,OAAO,CAAC;oBACpF,CAAC,CAAC;wBACE,EAAE,EAAG,CAAU,CAAC,EAAE;wBAClB,IAAI,EAAG,CAAU,CAAC,EAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;wBACpC,IAAI,EAAG,CAAU,CAAC,EAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;wBACpC,OAAO,EAAG,CAAU,CAAC,EAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;qBACxC;oBACH,CAAC,CAAC;wBACE,EAAE,EAAG,CAAU,CAAC,EAAG;wBACnB,IAAI,EAAG,CAAU,CAAC,IAAI;wBACtB,IAAI,EAAG,CAAU,CAAC,IAAI;wBACtB,OAAO,EAAG,CAAU,CAAC,OAAO,IAAI,GAAG;qBACpC,CAAA;IACP,CAAC;CACF;AAjJD,kCAiJC","sourcesContent":["import { IccCodeApi } from '../icc-api'\n\nimport codeLanguages from './rsrc/codelng'\nimport icd10 from './rsrc/icd10'\nimport icpc2 from './rsrc/icpc2'\n\nimport * as _ from 'lodash'\nimport { Code } from '../icc-api/model/Code'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccCodeXApi extends IccCodeApi {\n icd10: any = icd10\n icpc2: any = icpc2\n codeLanguages: any = codeLanguages\n\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 /**\n * Groups a list of ICD-10 codes by their corresponding ICD-10 chapter.\n * @param listOfCodes an array of ICD-10 code strings to classify into chapters.\n * @return a sorted array of chapter objects, each containing a code, description, and list of matching sub-codes.\n */\n // noinspection JSUnusedGlobalSymbols\n icdChapters(listOfCodes: Array<string>) {\n return Promise.resolve(\n _.sortBy(\n _.values(\n _.reduce(\n _.fromPairs(\n listOfCodes.map((code) => [\n code,\n _.toPairs(this.icd10).find(([k]) => {\n const parts = k.split(/-/)\n return code.substr(0, 3) >= parts[0] && code.substr(0, 3) <= parts[1]\n }),\n ])\n ),\n (acc: any, pairOfRangeAndIcdInfo, code) => {\n if (!pairOfRangeAndIcdInfo) {\n return acc\n }\n const shortKey = pairOfRangeAndIcdInfo[0].substr(0, 2)\n ;(\n acc[shortKey] ||\n (acc[shortKey] = {\n code: shortKey,\n descr: pairOfRangeAndIcdInfo[1],\n subCodes: [],\n })\n ).subCodes.push(code)\n return acc\n },\n {}\n )\n ),\n (c: any) => c.shortKey\n )\n )\n }\n\n /**\n * Groups a list of ICPC-2 codes by their corresponding ICPC-2 chapter.\n * @param listOfCodes an array of ICPC-2 code strings to classify into chapters.\n * @return a sorted array of chapter objects, each containing a code, description, and list of matching sub-codes.\n */\n // noinspection JSUnusedGlobalSymbols\n icpcChapters(listOfCodes: Array<string>) {\n return Promise.resolve(\n _.sortBy(\n _.values(\n _.reduce(\n _.fromPairs(listOfCodes.map((code) => [code, _.toPairs(this.icpc2).find(([k]) => k === code.substr(0, 1).toUpperCase())])),\n (acc: any, pairOfRangeAndIcdInfo, code) => {\n if (!pairOfRangeAndIcdInfo) {\n return acc\n }\n const shortKey = pairOfRangeAndIcdInfo[0]\n ;(\n acc[shortKey] ||\n (acc[shortKey] = {\n code: shortKey,\n descr: pairOfRangeAndIcdInfo[1],\n subCodes: [],\n })\n ).subCodes.push(code)\n return acc\n },\n {}\n )\n ),\n (c: any) => c.shortKey\n )\n )\n }\n\n /**\n * Returns the appropriate language code for a given code type. Falls back to French ('fr') if the\n * requested language is not available for the specified type.\n * @param type the code type to look up available languages for.\n * @param lng the desired language code.\n * @return the requested language code if available, or 'fr' as a fallback.\n */\n // noinspection JSUnusedGlobalSymbols\n languageForType(type: string, lng: string) {\n const availableLanguages = this.codeLanguages[type]\n return availableLanguages && availableLanguages.indexOf(lng) >= 0 ? lng : 'fr'\n }\n\n /**\n * Normalizes a code, ensuring it has a consistent structure with id, type, code, and version fields.\n * Accepts either a pipe-delimited string (e.g. \"type|code|version\") or a Code object.\n * @param c a code represented as a pipe-delimited string or a Code object.\n * @return an object with id, type, code, and version fields fully populated.\n */\n // noinspection JSMethodCanBeStatic, JSUnusedGlobalSymbols\n normalize(c: Code | string) {\n return typeof c === 'string'\n ? {\n id: c,\n type: c.split(/\\|/)[0],\n code: c.split(/\\|/)[1],\n version: c.split(/\\|/)[2],\n }\n : (c as Code).type && (c as Code).code && !(c as Code).id\n ? {\n id: (c as Code).type + '|' + (c as Code).code + '|' + ((c as Code).version || '1'),\n type: (c as Code).type,\n code: (c as Code).code,\n version: (c as Code).version || '1',\n }\n : (c as Code).id && (!(c as Code).code || !(c as Code).type || !(c as Code).version)\n ? {\n id: (c as Code).id,\n type: (c as Code).id!.split(/\\|/)[0],\n code: (c as Code).id!.split(/\\|/)[1],\n version: (c as Code).id!.split(/\\|/)[2],\n }\n : {\n id: (c as Code).id!,\n type: (c as Code).type,\n code: (c as Code).code,\n version: (c as Code).version || '1',\n }\n }\n}\n"]}