@icure/api 7.1.14 → 8.0.0-RC.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/icc-api/api/IccAccesslogApi.d.ts +12 -1
  2. package/icc-api/api/IccAccesslogApi.js +142 -98
  3. package/icc-api/api/IccAccesslogApi.js.map +1 -1
  4. package/icc-api/api/IccBemikronoApi.d.ts +81 -0
  5. package/icc-api/api/IccBemikronoApi.js +163 -0
  6. package/icc-api/api/IccBemikronoApi.js.map +1 -0
  7. package/icc-api/api/IccCalendarItemApi.d.ts +21 -1
  8. package/icc-api/api/IccCalendarItemApi.js +183 -117
  9. package/icc-api/api/IccCalendarItemApi.js.map +1 -1
  10. package/icc-api/api/IccClassificationApi.d.ts +21 -1
  11. package/icc-api/api/IccClassificationApi.js +119 -63
  12. package/icc-api/api/IccClassificationApi.js.map +1 -1
  13. package/icc-api/api/IccContactApi.d.ts +21 -1
  14. package/icc-api/api/IccContactApi.js +385 -294
  15. package/icc-api/api/IccContactApi.js.map +1 -1
  16. package/icc-api/api/IccDocumentApi.d.ts +32 -25
  17. package/icc-api/api/IccDocumentApi.js +264 -212
  18. package/icc-api/api/IccDocumentApi.js.map +1 -1
  19. package/icc-api/api/IccExchangeDataApi.d.ts +19 -0
  20. package/icc-api/api/IccExchangeDataApi.js +85 -0
  21. package/icc-api/api/IccExchangeDataApi.js.map +1 -0
  22. package/icc-api/api/IccExchangeDataMapApi.d.ts +18 -0
  23. package/icc-api/api/IccExchangeDataMapApi.js +65 -0
  24. package/icc-api/api/IccExchangeDataMapApi.js.map +1 -0
  25. package/icc-api/api/IccFormApi.d.ts +21 -1
  26. package/icc-api/api/IccFormApi.js +321 -229
  27. package/icc-api/api/IccFormApi.js.map +1 -1
  28. package/icc-api/api/IccHelementApi.d.ts +21 -1
  29. package/icc-api/api/IccHelementApi.js +207 -137
  30. package/icc-api/api/IccHelementApi.js.map +1 -1
  31. package/icc-api/api/IccInvoiceApi.d.ts +21 -1
  32. package/icc-api/api/IccInvoiceApi.js +404 -298
  33. package/icc-api/api/IccInvoiceApi.js.map +1 -1
  34. package/icc-api/api/IccMaintenanceTaskApi.d.ts +12 -1
  35. package/icc-api/api/IccMaintenanceTaskApi.js +79 -43
  36. package/icc-api/api/IccMaintenanceTaskApi.js.map +1 -1
  37. package/icc-api/api/IccMessageApi.d.ts +12 -1
  38. package/icc-api/api/IccMessageApi.js +257 -191
  39. package/icc-api/api/IccMessageApi.js.map +1 -1
  40. package/icc-api/api/IccPatientApi.d.ts +12 -1
  41. package/icc-api/api/IccPatientApi.js +447 -351
  42. package/icc-api/api/IccPatientApi.js.map +1 -1
  43. package/icc-api/api/IccReceiptApi.d.ts +22 -8
  44. package/icc-api/api/IccReceiptApi.js +121 -64
  45. package/icc-api/api/IccReceiptApi.js.map +1 -1
  46. package/icc-api/api/IccRestApiPath.js +1 -1
  47. package/icc-api/api/IccRestApiPath.js.map +1 -1
  48. package/icc-api/api/IccTimeTableApi.d.ts +12 -1
  49. package/icc-api/api/IccTimeTableApi.js +86 -48
  50. package/icc-api/api/IccTimeTableApi.js.map +1 -1
  51. package/icc-api/index.d.ts +1 -0
  52. package/icc-api/index.js +1 -0
  53. package/icc-api/index.js.map +1 -1
  54. package/icc-api/model/AccessLog.d.ts +4 -0
  55. package/icc-api/model/AccessLog.js +1 -0
  56. package/icc-api/model/AccessLog.js.map +1 -1
  57. package/icc-api/model/Article.d.ts +4 -0
  58. package/icc-api/model/Article.js +1 -0
  59. package/icc-api/model/Article.js.map +1 -1
  60. package/icc-api/model/CalendarItem.d.ts +4 -0
  61. package/icc-api/model/CalendarItem.js +1 -0
  62. package/icc-api/model/CalendarItem.js.map +1 -1
  63. package/icc-api/model/Classification.d.ts +4 -0
  64. package/icc-api/model/Classification.js +1 -0
  65. package/icc-api/model/Classification.js.map +1 -1
  66. package/icc-api/model/ClassificationTemplate.d.ts +2 -0
  67. package/icc-api/model/ClassificationTemplate.js.map +1 -1
  68. package/icc-api/model/Contact.d.ts +4 -0
  69. package/icc-api/model/Contact.js +1 -0
  70. package/icc-api/model/Contact.js.map +1 -1
  71. package/icc-api/model/Device.d.ts +4 -4
  72. package/icc-api/model/Device.js.map +1 -1
  73. package/icc-api/model/Document.d.ts +4 -0
  74. package/icc-api/model/Document.js +1 -0
  75. package/icc-api/model/Document.js.map +1 -1
  76. package/icc-api/model/ExchangeData.d.ts +61 -0
  77. package/icc-api/model/ExchangeData.js +12 -0
  78. package/icc-api/model/ExchangeData.js.map +1 -0
  79. package/icc-api/model/ExchangeDataMap.d.ts +21 -0
  80. package/icc-api/model/ExchangeDataMap.js +10 -0
  81. package/icc-api/model/ExchangeDataMap.js.map +1 -0
  82. package/icc-api/model/ExchangeDataMapCreationBatch.d.ts +13 -0
  83. package/icc-api/model/ExchangeDataMapCreationBatch.js +10 -0
  84. package/icc-api/model/ExchangeDataMapCreationBatch.js.map +1 -0
  85. package/icc-api/model/Form.d.ts +4 -0
  86. package/icc-api/model/Form.js +1 -0
  87. package/icc-api/model/Form.js.map +1 -1
  88. package/icc-api/model/HealthElement.d.ts +4 -0
  89. package/icc-api/model/HealthElement.js +1 -0
  90. package/icc-api/model/HealthElement.js.map +1 -1
  91. package/icc-api/model/HealthcareParty.d.ts +2 -2
  92. package/icc-api/model/HealthcareParty.js.map +1 -1
  93. package/icc-api/model/IcureStub.d.ts +2 -0
  94. package/icc-api/model/IcureStub.js.map +1 -1
  95. package/icc-api/model/Invoice.d.ts +4 -0
  96. package/icc-api/model/Invoice.js +1 -0
  97. package/icc-api/model/Invoice.js.map +1 -1
  98. package/icc-api/model/MaintenanceTask.d.ts +4 -0
  99. package/icc-api/model/MaintenanceTask.js +1 -0
  100. package/icc-api/model/MaintenanceTask.js.map +1 -1
  101. package/icc-api/model/Message.d.ts +4 -0
  102. package/icc-api/model/Message.js +1 -0
  103. package/icc-api/model/Message.js.map +1 -1
  104. package/icc-api/model/PaginatedListExchangeData.d.ts +9 -0
  105. package/icc-api/model/PaginatedListExchangeData.js +10 -0
  106. package/icc-api/model/PaginatedListExchangeData.js.map +1 -0
  107. package/icc-api/model/Patient.d.ts +6 -2
  108. package/icc-api/model/Patient.js +1 -0
  109. package/icc-api/model/Patient.js.map +1 -1
  110. package/icc-api/model/PatientByHcPartyGenderEducationProfession.d.ts +31 -0
  111. package/icc-api/model/PatientByHcPartyGenderEducationProfession.js +32 -0
  112. package/icc-api/model/PatientByHcPartyGenderEducationProfession.js.map +1 -0
  113. package/icc-api/model/Receipt.d.ts +4 -0
  114. package/icc-api/model/Receipt.js +1 -0
  115. package/icc-api/model/Receipt.js.map +1 -1
  116. package/icc-api/model/SecureDelegation.d.ts +52 -0
  117. package/icc-api/model/SecureDelegation.js +16 -0
  118. package/icc-api/model/SecureDelegation.js.map +1 -0
  119. package/icc-api/model/SecurityMetadata.d.ts +33 -0
  120. package/icc-api/model/SecurityMetadata.js +13 -0
  121. package/icc-api/model/SecurityMetadata.js.map +1 -0
  122. package/icc-api/model/Service.d.ts +2 -0
  123. package/icc-api/model/Service.js.map +1 -1
  124. package/icc-api/model/TimeTable.d.ts +4 -0
  125. package/icc-api/model/TimeTable.js +1 -0
  126. package/icc-api/model/TimeTable.js.map +1 -1
  127. package/icc-api/model/models.d.ts +20 -39
  128. package/icc-api/model/models.js +15 -37
  129. package/icc-api/model/models.js.map +1 -1
  130. package/icc-api/model/requests/EntityBulkShareResult.d.ts +28 -0
  131. package/icc-api/model/requests/EntityBulkShareResult.js +16 -0
  132. package/icc-api/model/requests/EntityBulkShareResult.js.map +1 -0
  133. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.d.ts +10 -0
  134. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.js +17 -0
  135. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.js.map +1 -0
  136. package/icc-api/model/requests/EntityShareRequest.d.ts +110 -0
  137. package/icc-api/model/requests/EntityShareRequest.js +63 -0
  138. package/icc-api/model/requests/EntityShareRequest.js.map +1 -0
  139. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.d.ts +54 -0
  140. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.js +24 -0
  141. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.js.map +1 -0
  142. package/icc-api/model/requests/MinimalEntityBulkShareResult.d.ts +23 -0
  143. package/icc-api/model/requests/MinimalEntityBulkShareResult.js +13 -0
  144. package/icc-api/model/requests/MinimalEntityBulkShareResult.js.map +1 -0
  145. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.d.ts +21 -0
  146. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.js +14 -0
  147. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.js.map +1 -0
  148. package/icc-x-api/basexapi/EncryptedEntityXApi.d.ts +3 -2
  149. package/icc-x-api/basexapi/EncryptedEntityXApi.js.map +1 -1
  150. package/icc-x-api/crypto/AES.js +1 -1
  151. package/icc-x-api/crypto/AES.js.map +1 -1
  152. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.d.ts +16 -0
  153. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.js +41 -0
  154. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.js.map +1 -0
  155. package/icc-x-api/crypto/AccessControlSecretUtils.d.ts +42 -0
  156. package/icc-x-api/crypto/AccessControlSecretUtils.js +86 -0
  157. package/icc-x-api/crypto/AccessControlSecretUtils.js.map +1 -0
  158. package/icc-x-api/crypto/BaseExchangeDataManager.d.ts +146 -0
  159. package/icc-x-api/crypto/BaseExchangeDataManager.js +342 -0
  160. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -0
  161. package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +0 -18
  162. package/icc-x-api/crypto/BaseExchangeKeysManager.js +11 -85
  163. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
  164. package/icc-x-api/crypto/ConfidentialEntities.d.ts +26 -16
  165. package/icc-x-api/crypto/ConfidentialEntities.js +30 -17
  166. package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -1
  167. package/icc-x-api/crypto/CryptoStrategies.d.ts +8 -1
  168. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -1
  169. package/icc-x-api/crypto/ExchangeDataManager.d.ts +95 -0
  170. package/icc-x-api/crypto/ExchangeDataManager.js +493 -0
  171. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -0
  172. package/icc-x-api/crypto/ExchangeDataMapManager.d.ts +32 -0
  173. package/icc-x-api/crypto/ExchangeDataMapManager.js +70 -0
  174. package/icc-x-api/crypto/ExchangeDataMapManager.js.map +1 -0
  175. package/icc-x-api/crypto/ExchangeKeysManager.d.ts +4 -16
  176. package/icc-x-api/crypto/ExchangeKeysManager.js +4 -62
  177. package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -1
  178. package/icc-x-api/crypto/ExtendedApisUtils.d.ts +336 -0
  179. package/icc-x-api/crypto/ExtendedApisUtils.js +3 -0
  180. package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -0
  181. package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +181 -0
  182. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +562 -0
  183. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -0
  184. package/icc-x-api/crypto/KeyRecovery.d.ts +5 -2
  185. package/icc-x-api/crypto/KeyRecovery.js +59 -29
  186. package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
  187. package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +7 -2
  188. package/icc-x-api/crypto/LegacyCryptoStrategies.js +8 -1
  189. package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -1
  190. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.d.ts +39 -0
  191. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js +150 -0
  192. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js.map +1 -0
  193. package/icc-x-api/crypto/RSA.d.ts +34 -8
  194. package/icc-x-api/crypto/RSA.js +80 -13
  195. package/icc-x-api/crypto/RSA.js.map +1 -1
  196. package/icc-x-api/crypto/SecureDelegationsEncryption.d.ts +54 -0
  197. package/icc-x-api/crypto/SecureDelegationsEncryption.js +178 -0
  198. package/icc-x-api/crypto/SecureDelegationsEncryption.js.map +1 -0
  199. package/icc-x-api/crypto/SecureDelegationsManager.d.ts +66 -0
  200. package/icc-x-api/crypto/SecureDelegationsManager.js +261 -0
  201. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -0
  202. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.d.ts +37 -0
  203. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js +294 -0
  204. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js.map +1 -0
  205. package/icc-x-api/crypto/SecurityMetadataDecryptor.d.ts +114 -0
  206. package/icc-x-api/crypto/SecurityMetadataDecryptor.js +98 -0
  207. package/icc-x-api/crypto/SecurityMetadataDecryptor.js.map +1 -0
  208. package/icc-x-api/crypto/ShamirKeysManager.d.ts +5 -5
  209. package/icc-x-api/crypto/ShamirKeysManager.js +6 -9
  210. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
  211. package/icc-x-api/crypto/TransferKeysManager.d.ts +8 -6
  212. package/icc-x-api/crypto/TransferKeysManager.js +75 -52
  213. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
  214. package/icc-x-api/crypto/{KeyManager.d.ts → UserEncryptionKeysManager.d.ts} +4 -6
  215. package/icc-x-api/crypto/{KeyManager.js → UserEncryptionKeysManager.js} +43 -23
  216. package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -0
  217. package/icc-x-api/crypto/UserSignatureKeysManager.d.ts +26 -0
  218. package/icc-x-api/crypto/UserSignatureKeysManager.js +74 -0
  219. package/icc-x-api/crypto/UserSignatureKeysManager.js.map +1 -0
  220. package/icc-x-api/crypto/utils.d.ts +61 -11
  221. package/icc-x-api/crypto/utils.js +113 -44
  222. package/icc-x-api/crypto/utils.js.map +1 -1
  223. package/icc-x-api/filters/filters.js.map +1 -1
  224. package/icc-x-api/icc-accesslog-x-api.d.ts +46 -11
  225. package/icc-x-api/icc-accesslog-x-api.js +75 -42
  226. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  227. package/icc-x-api/icc-calendar-item-x-api.d.ts +50 -14
  228. package/icc-x-api/icc-calendar-item-x-api.js +99 -49
  229. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  230. package/icc-x-api/icc-classification-x-api.d.ts +44 -9
  231. package/icc-x-api/icc-classification-x-api.js +56 -31
  232. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  233. package/icc-x-api/icc-contact-x-api.d.ts +56 -32
  234. package/icc-x-api/icc-contact-x-api.js +95 -64
  235. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  236. package/icc-x-api/icc-crypto-x-api.d.ts +28 -334
  237. package/icc-x-api/icc-crypto-x-api.js +41 -765
  238. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  239. package/icc-x-api/icc-data-owner-x-api.d.ts +20 -8
  240. package/icc-x-api/icc-data-owner-x-api.js +31 -10
  241. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  242. package/icc-x-api/icc-document-x-api.d.ts +48 -11
  243. package/icc-x-api/icc-document-x-api.js +111 -64
  244. package/icc-x-api/icc-document-x-api.js.map +1 -1
  245. package/icc-x-api/icc-form-x-api.d.ts +45 -10
  246. package/icc-x-api/icc-form-x-api.js +65 -35
  247. package/icc-x-api/icc-form-x-api.js.map +1 -1
  248. package/icc-x-api/icc-hcparty-x-api.d.ts +2 -2
  249. package/icc-x-api/icc-hcparty-x-api.js +3 -3
  250. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  251. package/icc-x-api/icc-helement-x-api.d.ts +55 -18
  252. package/icc-x-api/icc-helement-x-api.js +76 -41
  253. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  254. package/icc-x-api/icc-icure-maintenance-x-api.d.ts +7 -2
  255. package/icc-x-api/icc-icure-maintenance-x-api.js +38 -27
  256. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
  257. package/icc-x-api/icc-invoice-x-api.d.ts +50 -15
  258. package/icc-x-api/icc-invoice-x-api.js +63 -33
  259. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  260. package/icc-x-api/icc-maintenance-task-x-api.d.ts +53 -21
  261. package/icc-x-api/icc-maintenance-task-x-api.js +72 -35
  262. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  263. package/icc-x-api/icc-message-x-api.d.ts +53 -15
  264. package/icc-x-api/icc-message-x-api.js +65 -36
  265. package/icc-x-api/icc-message-x-api.js.map +1 -1
  266. package/icc-x-api/icc-patient-x-api.d.ts +84 -29
  267. package/icc-x-api/icc-patient-x-api.js +313 -378
  268. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  269. package/icc-x-api/icc-receipt-x-api.d.ts +44 -12
  270. package/icc-x-api/icc-receipt-x-api.js +67 -35
  271. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  272. package/icc-x-api/icc-time-table-x-api.d.ts +43 -12
  273. package/icc-x-api/icc-time-table-x-api.js +56 -26
  274. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  275. package/icc-x-api/icc-user-x-api.d.ts +2 -2
  276. package/icc-x-api/icc-user-x-api.js +3 -3
  277. package/icc-x-api/icc-user-x-api.js.map +1 -1
  278. package/icc-x-api/index.d.ts +4 -2
  279. package/icc-x-api/index.js +154 -135
  280. package/icc-x-api/index.js.map +1 -1
  281. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +2 -0
  282. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +9 -2
  283. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -1
  284. package/icc-x-api/storage/IcureStorageFacade.d.ts +23 -2
  285. package/icc-x-api/storage/IcureStorageFacade.js +36 -2
  286. package/icc-x-api/storage/IcureStorageFacade.js.map +1 -1
  287. package/icc-x-api/storage/KeyStorageFacade.d.ts +12 -0
  288. package/icc-x-api/storage/KeyStorageFacade.js.map +1 -1
  289. package/icc-x-api/storage/KeyStorageImpl.d.ts +2 -0
  290. package/icc-x-api/storage/KeyStorageImpl.js +10 -0
  291. package/icc-x-api/storage/KeyStorageImpl.js.map +1 -1
  292. package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +14 -1
  293. package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -1
  294. package/icc-x-api/utils/EntityWithDelegationTypeName.d.ts +32 -0
  295. package/icc-x-api/utils/EntityWithDelegationTypeName.js +75 -0
  296. package/icc-x-api/utils/EntityWithDelegationTypeName.js.map +1 -0
  297. package/icc-x-api/utils/ShareResult.d.ts +74 -0
  298. package/icc-x-api/utils/ShareResult.js +61 -0
  299. package/icc-x-api/utils/ShareResult.js.map +1 -0
  300. package/icc-x-api/utils/binary-utils.d.ts +1 -0
  301. package/icc-x-api/utils/binary-utils.js +8 -1
  302. package/icc-x-api/utils/binary-utils.js.map +1 -1
  303. package/icc-x-api/utils/collection-utils.d.ts +5 -0
  304. package/icc-x-api/utils/collection-utils.js +26 -1
  305. package/icc-x-api/utils/collection-utils.js.map +1 -1
  306. package/icc-x-api/utils/crypto-utils.d.ts +4 -3
  307. package/icc-x-api/utils/crypto-utils.js +5 -4
  308. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  309. package/icc-x-api/utils/lru-temporised-async-cache.d.ts +26 -3
  310. package/icc-x-api/utils/lru-temporised-async-cache.js +75 -15
  311. package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -1
  312. package/icc-x-api/utils/websocket.d.ts +10 -10
  313. package/icc-x-api/utils/websocket.js +18 -9
  314. package/icc-x-api/utils/websocket.js.map +1 -1
  315. package/index.d.ts +1 -1
  316. package/index.js +3 -1
  317. package/index.js.map +1 -1
  318. package/package.json +2 -3
  319. package/icc-x-api/crypto/EntitiesEncryption.d.ts +0 -275
  320. package/icc-x-api/crypto/EntitiesEncryption.js +0 -734
  321. package/icc-x-api/crypto/EntitiesEncryption.js.map +0 -1
  322. package/icc-x-api/crypto/KeyManager.js.map +0 -1
@@ -18,11 +18,18 @@ const ModelHelper_1 = require("../icc-api/model/ModelHelper");
18
18
  const person_util_1 = require("./utils/person-util");
19
19
  const utils_1 = require("./utils");
20
20
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
21
+ const SecureDelegation_1 = require("../icc-api/model/SecureDelegation");
22
+ const EntityShareRequest_1 = require("../icc-api/model/requests/EntityShareRequest");
23
+ const ShareMetadataBehaviour_1 = require("./crypto/ShareMetadataBehaviour");
24
+ var AccessLevelEnum = SecureDelegation_1.SecureDelegation.AccessLevelEnum;
25
+ var RequestedPermissionEnum = EntityShareRequest_1.EntityShareRequest.RequestedPermissionEnum;
21
26
  const Connection_1 = require("../icc-api/model/Connection");
22
- const websocket_1 = require("./utils/websocket");
23
27
  // noinspection JSUnusedGlobalSymbols
24
28
  class IccPatientXApi extends icc_api_1.IccPatientApi {
25
- constructor(host, headers, crypto, contactApi, formApi, helementApi, invoiceApi, documentApi, hcpartyApi, classificationApi, dataOwnerApi, calendarItemaApi, userApi, authApi, encryptedKeys = ['note'], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
29
+ get headers() {
30
+ return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, 'Patient'));
31
+ }
32
+ constructor(host, headers, crypto, contactApi, formApi, helementApi, invoiceApi, documentApi, hcpartyApi, classificationApi, dataOwnerApi, calendarItemApi, userApi, authApi, encryptedKeys = ['note'], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
26
33
  ? window.fetch
27
34
  : typeof self !== 'undefined'
28
35
  ? self.fetch
@@ -33,11 +40,11 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
33
40
  this.formApi = formApi;
34
41
  this.helementApi = helementApi;
35
42
  this.invoiceApi = invoiceApi;
36
- this.hcpartyApi = hcpartyApi;
37
43
  this.documentApi = documentApi;
44
+ this.hcpartyApi = hcpartyApi;
38
45
  this.classificationApi = classificationApi;
39
- this.calendarItemApi = calendarItemaApi;
40
46
  this.dataOwnerApi = dataOwnerApi;
47
+ this.calendarItemApi = calendarItemApi;
41
48
  this.userApi = userApi;
42
49
  this.authApi = authApi;
43
50
  this.encryptedFields = (0, utils_1.parseEncryptedFields)(encryptedKeys, 'Patient.');
@@ -50,8 +57,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
50
57
  * @param options optional parameters:
51
58
  * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
52
59
  * 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
53
- * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
54
- * access will be possible.
60
+ * auto-delegations, in such case the access level specified here will be used.
55
61
  * @return a new instance of patient.
56
62
  */
57
63
  newInstance(user, p = {}, options = {}) {
@@ -61,12 +67,8 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
61
67
  const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
62
68
  if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
63
69
  throw new Error('Can only initialise entities as current data owner.');
64
- const extraDelegations = [
65
- ...Object.keys((_h = options.additionalDelegates) !== null && _h !== void 0 ? _h : {}),
66
- ...((_k = (_j = user.autoDelegations) === null || _j === void 0 ? void 0 : _j.all) !== null && _k !== void 0 ? _k : []),
67
- ...((_m = (_l = user.autoDelegations) === null || _l === void 0 ? void 0 : _l.medicalInformation) !== null && _m !== void 0 ? _m : []),
68
- ];
69
- const initialisationInfo = yield this.crypto.entities.entityWithInitialisedEncryptedMetadata(patient, undefined, undefined, true, extraDelegations);
70
+ const extraDelegations = Object.assign(Object.assign({}, Object.fromEntries([...((_j = (_h = user.autoDelegations) === null || _h === void 0 ? void 0 : _h.all) !== null && _j !== void 0 ? _j : []), ...((_l = (_k = user.autoDelegations) === null || _k === void 0 ? void 0 : _k.medicalInformation) !== null && _l !== void 0 ? _l : [])].map((d) => [d, AccessLevelEnum.WRITE]))), ((_m = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _m !== void 0 ? _m : {}));
71
+ const initialisationInfo = yield this.crypto.xapi.entityWithInitialisedEncryptedMetadata(patient, 'Patient', undefined, undefined, true, true, extraDelegations);
70
72
  return new models.Patient(initialisationInfo.updatedEntity);
71
73
  });
72
74
  }
@@ -92,7 +94,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
92
94
  if (!finalPatient.alias && !!(0, person_util_1.hasName)(finalPatient, models.PersonName.UseEnum.Nickname)) {
93
95
  finalPatient = Object.assign(Object.assign({}, finalPatient), { alias: (0, person_util_1.findName)(finalPatient, models.PersonName.UseEnum.Nickname).lastName });
94
96
  }
95
- return finalPatient;
97
+ return new models_1.Patient(finalPatient);
96
98
  }
97
99
  /**
98
100
  * @deprecated replace with {@link initConfidentialSecretId}
@@ -114,12 +116,18 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
114
116
  const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user);
115
117
  if (dataOwnerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
116
118
  throw new Error('You can initialise confidential delegations only for the current data owner');
117
- const initialised = yield this.crypto.confidential.entityWithInitialisedConfidentialSecretId(patient);
119
+ let updatedPatient = patient;
120
+ if (!patient.rev) {
121
+ updatedPatient = yield this.createPatientWithUser(user, patient);
122
+ if (!updatedPatient)
123
+ throw new Error('Could not create patient');
124
+ }
125
+ const initialised = yield this.crypto.confidential.initialiseConfidentialSecretId(updatedPatient, 'Patient', (x) => this.bulkSharePatients(x));
118
126
  if (initialised) {
119
- return initialised.rev ? this.modifyPatientWithUser(user, initialised) : this.createPatientWithUser(user, initialised);
127
+ return initialised;
120
128
  }
121
129
  else {
122
- return patient;
130
+ return updatedPatient;
123
131
  }
124
132
  });
125
133
  }
@@ -182,13 +190,13 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
182
190
  getPatientWithUser(user, patientId) {
183
191
  return super
184
192
  .getPatient(patientId)
185
- .then((p) => this.tryDecryptOrReturnOriginal(this.dataOwnerApi.getDataOwnerIdOf(user), [p]))
193
+ .then((p) => this.tryDecryptOrReturnOriginal([p]))
186
194
  .then((pats) => pats[0].entity);
187
195
  }
188
196
  getPotentiallyEncryptedPatientWithUser(user, patientId) {
189
197
  return super
190
198
  .getPatient(patientId)
191
- .then((p) => this.tryDecryptOrReturnOriginal(this.dataOwnerApi.getDataOwnerIdOf(user), [p]))
199
+ .then((p) => this.tryDecryptOrReturnOriginal([p]))
192
200
  .then((pats) => ({ patient: pats[0].entity, decrypted: pats[0].decrypted }));
193
201
  }
194
202
  getPatients(body) {
@@ -261,17 +269,20 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
261
269
  modifyPatient(body) {
262
270
  throw new Error('Cannot call a method that returns contacts without providing a user for de/encryption');
263
271
  }
272
+ /**
273
+ * @internal this method is for internal use only and may be changed without notice.
274
+ */
264
275
  modifyPatientRaw(body) {
265
276
  return super.modifyPatient(body);
266
277
  }
267
278
  modifyPatientWithUser(user, body) {
268
- return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null);
279
+ return body ? this.modifyPatientAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null);
269
280
  }
270
- modifyAs(dataOwner, body) {
281
+ modifyPatientAs(dataOwner, body) {
271
282
  return this.encryptAs(dataOwner, [_.cloneDeep(this.completeNames(body))])
272
283
  .then((pats) => super.modifyPatient(pats[0]))
273
- .then((p) => this.tryDecryptOrReturnOriginal(dataOwner, [p]))
274
- .then((pats) => pats[0].entity);
284
+ .then((p) => this.decryptAs(dataOwner, [p]))
285
+ .then((pats) => pats[0]);
275
286
  }
276
287
  modifyPatientReferral(patientId, referralId, start, end) {
277
288
  throw new Error('Cannot call a method that returns contacts without providing a user for de/encryption');
@@ -283,19 +294,23 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
283
294
  .then((pats) => pats[0]);
284
295
  }
285
296
  encrypt(user, pats) {
286
- return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), pats);
297
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user);
298
+ return this.encryptAs(dataOwnerId, pats);
287
299
  }
288
- encryptAs(dataOwnerId, pats) {
289
- return Promise.all(pats.map((p) => this.crypto.entities.tryEncryptEntity(p, dataOwnerId, this.encryptedFields, true, false, (x) => new models.Patient(x))));
300
+ encryptAs(dataOwner, pats) {
301
+ return Promise.all(pats.map((p) => this.crypto.xapi.tryEncryptEntity(p, 'Patient', this.encryptedFields, true, false, (x) => new models.Patient(x))));
290
302
  }
291
303
  // If patient can't be decrypted returns patient with encrypted data.
292
304
  decrypt(user, patients, fillDelegations = true) {
293
- return this.tryDecryptOrReturnOriginal(this.dataOwnerApi.getDataOwnerIdOf(user), patients).then((ps) => ps.map((p) => p.entity));
305
+ return this.decryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), patients, fillDelegations);
306
+ }
307
+ decryptAs(dataOwner, patients, fillDelegations = true) {
308
+ return this.tryDecryptOrReturnOriginal(patients).then((ps) => ps.map((p) => p.entity));
294
309
  }
295
- tryDecryptOrReturnOriginal(dataOwnerId, patients) {
310
+ tryDecryptOrReturnOriginal(patients) {
296
311
  return Promise.all(patients.map((p) => __awaiter(this, void 0, void 0, function* () {
297
- return yield this.crypto.entities
298
- .decryptEntity(p, dataOwnerId, (x) => new models.Patient(x))
312
+ return yield this.crypto.xapi
313
+ .decryptEntity(p, 'Patient', (x) => new models.Patient(x))
299
314
  .then((p) => {
300
315
  if (p.entity.picture && !(p.entity.picture instanceof ArrayBuffer)) {
301
316
  return {
@@ -308,34 +323,20 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
308
323
  });
309
324
  })));
310
325
  }
326
+ /**
327
+ * @deprecated replace with {@link shareAllDataOfPatient}
328
+ */
311
329
  share(user, patId, ownerId, delegateIds, delegationTags, usingPost = false) {
312
- const addDelegationsAndKeys = (dtos, markerPromise, delegateId, patient) => {
313
- return dtos.reduce((p, x) => p.then(() => __awaiter(this, void 0, void 0, function* () {
314
- const secretIds = yield this.crypto.entities.secretIdsOf(x, ownerId);
315
- const encryptionKeys = yield this.crypto.entities.encryptionKeysOf(x, ownerId);
316
- const parentIds = yield this.crypto.entities.owningEntityIdsOf(x, ownerId);
317
- const updatedX = yield this.crypto.entities
318
- .entityWithExtendedEncryptedMetadata(x, delegateId, secretIds, encryptionKeys, parentIds, [])
319
- .catch((e) => {
320
- console.log(e);
321
- return x;
322
- });
323
- _.assign(x, updatedX);
324
- return x;
325
- })), markerPromise);
326
- };
327
- const allTags = _.uniq(_.flatMap(Object.values(delegationTags)));
328
- // Determine which keys to share, depending on the delegation tag. For example, anonymousMedicalData only shares encryption keys and no delegations or secret foreign keys.
329
- const shareDelegations = allTags.some((tag) => tag != 'anonymousMedicalInformation');
330
- const shareEncryptionKeys = true;
331
- const shareCryptedForeignKeys = allTags.some((tag) => tag != 'anonymousMedicalInformation');
332
- // Anonymous sharing, will not change anything to the patient, only its contacts and health elements.
333
- const shareAnonymously = allTags.every((tag) => tag == 'anonymousMedicalInformation');
334
- return this.hcpartyApi.getHealthcareParty(ownerId).then((hcp) => {
335
- const parentId = hcp.parentId;
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ return this.shareAllDataOfPatient(user, patId, ownerId, delegateIds, delegationTags, usingPost);
332
+ });
333
+ }
334
+ shareAllDataOfPatient(user, patId, ownerId, delegateIds, delegationTags, usingPost = false) {
335
+ return __awaiter(this, void 0, void 0, function* () {
336
+ const allTags = _.uniq(_.flatMap(Object.values(delegationTags)));
336
337
  const status = {
337
338
  contacts: {
338
- success: allTags.includes('medicalInformation') || allTags.includes('anonymousMedicalInformation') || allTags.includes('all') ? false : null,
339
+ success: allTags.includes('medicalInformation') || allTags.includes('all') ? false : null,
339
340
  error: null,
340
341
  modified: 0,
341
342
  },
@@ -345,7 +346,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
345
346
  modified: 0,
346
347
  },
347
348
  healthElements: {
348
- success: allTags.includes('medicalInformation') || allTags.includes('anonymousMedicalInformation') || allTags.includes('all') ? false : null,
349
+ success: allTags.includes('medicalInformation') || allTags.includes('all') ? false : null,
349
350
  error: null,
350
351
  modified: 0,
351
352
  },
@@ -371,25 +372,169 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
371
372
  },
372
373
  patient: { success: false, error: null, modified: 0 },
373
374
  };
375
+ const hcp = yield this.hcpartyApi.getHealthcareParty(ownerId);
376
+ const parentId = hcp.parentId;
377
+ let patient = yield (0, utils_1.retry)(() => this.getPatientWithUser(user, patId));
378
+ const patientWithInitialisedEncryption = yield this.crypto.xapi.ensureEncryptionKeysInitialised(patient, 'Patient');
379
+ if (patientWithInitialisedEncryption) {
380
+ patient = yield this.modifyPatientWithUser(user, patientWithInitialisedEncryption);
381
+ }
382
+ if (!patient) {
383
+ status.patient = {
384
+ success: false,
385
+ error: new Error('Patient does not exist or cannot initialise encryption keys'),
386
+ };
387
+ return { patient: patient, statuses: status };
388
+ }
389
+ const delSfks = yield this.crypto.xapi.secretIdsOf({ entity: patient, type: 'Patient' }, ownerId);
390
+ const ecKeys = yield this.crypto.xapi.encryptionKeysOf({ entity: patient, type: 'Patient' }, ownerId);
391
+ if (delSfks.length) {
392
+ const retrievedHealthElements = yield (0, utils_1.retry)(() => (usingPost
393
+ ? this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(ownerId, _.uniq(delSfks))
394
+ : this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))).then((hes) => parentId
395
+ ? (usingPost
396
+ ? this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(parentId, _.uniq(delSfks))
397
+ : this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))).then((moreHes) => _.uniqBy(hes.concat(moreHes), 'id'))
398
+ : hes));
399
+ const retrievedForms = yield (0, utils_1.retry)(() => (usingPost
400
+ ? this.formApi.findFormsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(ownerId, _.uniq(delSfks))
401
+ : this.formApi.findFormsDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))).then((frms) => parentId
402
+ ? (usingPost
403
+ ? this.formApi.findFormsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(parentId, _.uniq(delSfks))
404
+ : this.formApi.findFormsDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))).then((moreFrms) => _.uniqBy(frms.concat(moreFrms), 'id'))
405
+ : frms));
406
+ const retrievedContacts = yield (0, utils_1.retry)(() => (usingPost
407
+ ? this.contactApi.findByHCPartyPatientSecretFKeysUsingPost(ownerId, undefined, undefined, _.uniq(delSfks))
408
+ : this.contactApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))).then((ctcs) => parentId
409
+ ? (usingPost
410
+ ? this.contactApi.findByHCPartyPatientSecretFKeysUsingPost(parentId, undefined, undefined, _.uniq(delSfks))
411
+ : this.contactApi.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))).then((moreCtcs) => _.uniqBy(ctcs.concat(moreCtcs), 'id'))
412
+ : ctcs));
413
+ const retrievedInvoices = yield (0, utils_1.retry)(() => (usingPost
414
+ ? this.invoiceApi.findInvoicesDelegationsStubsByHCPartyPatientForeignKeysUsingPost(ownerId, _.uniq(delSfks))
415
+ : this.invoiceApi.findInvoicesDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))).then((ivs) => parentId
416
+ ? this.invoiceApi
417
+ .findInvoicesDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
418
+ .then((moreIvs) => _.uniqBy(ivs.concat(moreIvs), 'id'))
419
+ : ivs));
420
+ const retrievedClassifications = yield (0, utils_1.retry)(() => this.classificationApi
421
+ .findClassificationsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
422
+ .then((cls) => parentId
423
+ ? this.classificationApi
424
+ .findClassificationsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
425
+ .then((moreCls) => _.uniqBy(cls.concat(moreCls), 'id'))
426
+ : cls));
427
+ const retrievedCalendarItems = yield (0, utils_1.retry)(() => (usingPost
428
+ ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(ownerId, _.uniq(delSfks))
429
+ : this.calendarItemApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))).then((cls) => parentId
430
+ ? (usingPost
431
+ ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(parentId, _.uniq(delSfks))
432
+ : this.calendarItemApi.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))).then((moreCls) => _.uniqBy(cls.concat(moreCls), 'id'))
433
+ : cls));
434
+ const isMedicalInfoTags = (tags) => tags.includes('medicalInformation') || tags.includes('all');
435
+ const isFinancialInfoTags = (tags) => tags.includes('financialInformation') || tags.includes('all');
436
+ const doShareEntitiesAndUpdateStatus = (entities, entitiesType, status, tagsCondition, doShareMinimal) => __awaiter(this, void 0, void 0, function* () {
437
+ const delegatesToApply = delegateIds.filter((delegateId) => tagsCondition(delegationTags[delegateId]));
438
+ if (entities.length && delegatesToApply.length) {
439
+ const requests = [];
440
+ for (const entity of entities) {
441
+ const currentEntityRequests = {};
442
+ const secretIds = yield this.crypto.xapi.secretIdsOf({ entity, type: entitiesType }, undefined);
443
+ const encryptionKeys = yield this.crypto.xapi.encryptionKeysOf({ entity, type: entitiesType }, undefined);
444
+ const request = {
445
+ shareSecretIds: secretIds,
446
+ shareEncryptionKeys: encryptionKeys,
447
+ shareOwningEntityIds: [patient.id],
448
+ requestedPermissions: RequestedPermissionEnum.MAX_WRITE,
449
+ };
450
+ for (const delegateId of delegatesToApply) {
451
+ currentEntityRequests[delegateId] = request;
452
+ }
453
+ requests.push({ dataForDelegates: currentEntityRequests, entity });
454
+ }
455
+ yield this.crypto.xapi
456
+ .bulkShareOrUpdateEncryptedEntityMetadataNoEntities(entitiesType, requests, (x) => doShareMinimal(x))
457
+ .then((shareResult) => {
458
+ status.modified = new Set(shareResult.successfulUpdates.map((x) => x.entityId)).size;
459
+ status.success = shareResult.updateErrors.length === 0;
460
+ if (!status.success) {
461
+ const errorMsg = `Error while sharing (some) entities of type ${entitiesType} for patient ${patient.id} : ${JSON.stringify(shareResult.updateErrors)}`;
462
+ console.error(errorMsg);
463
+ status.error = new Error(errorMsg);
464
+ }
465
+ })
466
+ .catch((e) => {
467
+ status.success = false;
468
+ status.error = e;
469
+ });
470
+ }
471
+ else {
472
+ status.success = true;
473
+ }
474
+ });
475
+ yield doShareEntitiesAndUpdateStatus(retrievedHealthElements, 'HealthElement', status.healthElements, isMedicalInfoTags, (x) => this.helementApi.bulkShareHealthElementsMinimal(x));
476
+ yield doShareEntitiesAndUpdateStatus(retrievedContacts, 'Contact', status.contacts, isMedicalInfoTags, (x) => this.contactApi.bulkShareContactsMinimal(x));
477
+ yield doShareEntitiesAndUpdateStatus(retrievedInvoices, 'Invoice', status.invoices, isFinancialInfoTags, (x) => this.invoiceApi.bulkShareInvoicesMinimal(x));
478
+ yield doShareEntitiesAndUpdateStatus(retrievedClassifications, 'Classification', status.classifications, isMedicalInfoTags, (x) => this.classificationApi.bulkShareClassificationsMinimal(x));
479
+ yield doShareEntitiesAndUpdateStatus(retrievedCalendarItems, 'CalendarItem', status.calendarItems, isMedicalInfoTags, (x) => this.calendarItemApi.bulkShareCalendarItemsMinimal(x));
480
+ yield doShareEntitiesAndUpdateStatus(retrievedForms, 'Form', status.forms, isMedicalInfoTags, (x) => this.formApi.bulkShareFormsMinimal(x));
481
+ }
482
+ const sharePatientDataRequest = {
483
+ shareSecretIds: delSfks,
484
+ shareEncryptionKeys: ecKeys,
485
+ shareOwningEntityIds: [],
486
+ requestedPermissions: RequestedPermissionEnum.MAX_WRITE,
487
+ };
488
+ const sharePatientRequest = {
489
+ entity: patient,
490
+ dataForDelegates: Object.fromEntries(delegateIds.map((delegateId) => [delegateId, sharePatientDataRequest])),
491
+ };
492
+ return yield this.crypto.xapi
493
+ .bulkShareOrUpdateEncryptedEntityMetadata('Patient', [sharePatientRequest], (x) => this.bulkSharePatients(x))
494
+ .then((shareResult) => {
495
+ var _a;
496
+ if (shareResult.updatedEntities.length && !shareResult.updateErrors.length) {
497
+ status.patient.success = true;
498
+ return { patient: shareResult.updatedEntities[0], statuses: status };
499
+ }
500
+ else {
501
+ const errorMsg = `Error while sharing patient with id ${patient.id} : ${JSON.stringify(shareResult.updateErrors)}`;
502
+ console.error(errorMsg);
503
+ status.patient.error = new Error(errorMsg);
504
+ status.patient.success = false;
505
+ return { patient: (_a = shareResult.updatedEntities[0]) !== null && _a !== void 0 ? _a : patient, statuses: status };
506
+ }
507
+ })
508
+ .catch((e) => {
509
+ status.patient.error = e;
510
+ status.patient.success = false;
511
+ return { patient, statuses: status };
512
+ });
513
+ });
514
+ }
515
+ export(user, patId, ownerId, usingPost = false) {
516
+ return this.hcpartyApi.getHealthcareParty(ownerId).then((hcp) => {
517
+ const parentId = hcp.parentId;
374
518
  return (0, utils_1.retry)(() => this.getPatientWithUser(user, patId))
375
- .then((patient) => patient.encryptionKeys && Object.keys(patient.encryptionKeys || {}).length
376
- ? Promise.resolve(patient)
377
- : this.crypto.entities.ensureEncryptionKeysInitialised(patient).then((p) => (!!p ? this.modifyPatientWithUser(user, p) : patient)))
519
+ .then((patient) => __awaiter(this, void 0, void 0, function* () {
520
+ const initialised = yield this.crypto.xapi.ensureEncryptionKeysInitialised(patient, 'Patient');
521
+ if (!initialised) {
522
+ return patient;
523
+ }
524
+ else {
525
+ return yield this.modifyPatientWithUser(user, initialised);
526
+ }
527
+ }))
378
528
  .then((patient) => __awaiter(this, void 0, void 0, function* () {
379
529
  if (!patient) {
380
- status.patient = {
381
- success: false,
382
- error: new Error('Patient does not exist or cannot initialise encryption keys'),
383
- };
384
- return Promise.resolve({ patient: patient, statuses: status });
530
+ return Promise.resolve({ id: patId });
385
531
  }
386
- const delSfks = yield this.crypto.entities.secretIdsOf(patient, ownerId);
387
- const ecKeys = yield this.crypto.entities.encryptionKeysOf(patient, ownerId);
532
+ const delSfks = yield this.crypto.xapi.secretIdsOf({ entity: patient, type: 'Patient' }, ownerId);
388
533
  return delSfks.length
389
534
  ? Promise.all([
390
535
  (0, utils_1.retry)(() => (usingPost
391
- ? this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(ownerId, _.uniq(delSfks))
392
- : this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))).then((hes) => parentId
536
+ ? this.helementApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))
537
+ : this.helementApi.findByHCPartyPatientSecretFKeysArray(ownerId, delSfks)).then((hes) => parentId
393
538
  ? (usingPost
394
539
  ? this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(parentId, _.uniq(delSfks))
395
540
  : this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))).then((moreHes) => _.uniqBy(hes.concat(moreHes), 'id'))
@@ -422,300 +567,57 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
422
567
  .findClassificationsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
423
568
  .then((moreCls) => _.uniqBy(cls.concat(moreCls), 'id'))
424
569
  : cls)),
425
- (0, utils_1.retry)(() => (usingPost
426
- ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(ownerId, _.uniq(delSfks))
427
- : this.calendarItemApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))).then((cls) => parentId
428
- ? (usingPost
429
- ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(parentId, _.uniq(delSfks))
430
- : this.calendarItemApi.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))).then((moreCls) => _.uniqBy(cls.concat(moreCls), 'id'))
431
- : cls)),
570
+ (0, utils_1.retry)(() => __awaiter(this, void 0, void 0, function* () {
571
+ const delegationSFKs = _.uniq(delSfks).join(',');
572
+ try {
573
+ let calendarItems = yield (usingPost
574
+ ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(ownerId, _.uniq(delSfks))
575
+ : this.calendarItemApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(',')));
576
+ if (parentId) {
577
+ const moreCalendarItems = yield (usingPost
578
+ ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(parentId, _.uniq(delSfks))
579
+ : this.calendarItemApi.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(',')));
580
+ calendarItems = _.uniqBy(calendarItems.concat(moreCalendarItems), 'id');
581
+ }
582
+ return calendarItems;
583
+ }
584
+ catch (ex) {
585
+ console.log(`exception occured exporting calendarItem for ownerId: ${ownerId} - ${ex}`);
586
+ //throw ex
587
+ }
588
+ })),
432
589
  ]).then(([hes, frms, ctcs, ivs, cls, cis]) => {
433
- const cloneKeysAndDelegations = function (x) {
434
- return {
435
- delegations: shareDelegations ? _.clone(x.delegations) : undefined,
436
- cryptedForeignKeys: shareCryptedForeignKeys ? _.clone(x.cryptedForeignKeys) : undefined,
437
- encryptionKeys: shareEncryptionKeys ? _.clone(x.encryptionKeys) : undefined,
438
- };
439
- };
440
- const ctcsStubs = ctcs.map((c) => (Object.assign({ id: c.id, rev: c.rev }, cloneKeysAndDelegations(c))));
441
- const oHes = hes.map((x) => _.assign(new models_1.IcureStub({}), x, cloneKeysAndDelegations(x)));
442
- const oFrms = frms.map((x) => _.assign(new models_1.IcureStub({}), x, cloneKeysAndDelegations(x)));
443
- const oCtcsStubs = ctcsStubs.map((x) => _.assign({}, x, cloneKeysAndDelegations(x)));
444
- const oIvs = ivs.map((x) => _.assign(new models_1.Invoice({}), x, cloneKeysAndDelegations(x)));
445
- const oCls = cls.map((x) => _.assign(new models_1.Classification({}), x, cloneKeysAndDelegations(x)));
446
- const oCis = cis.map((x) => _.assign(new models_1.CalendarItem({}), x, cloneKeysAndDelegations(x)));
447
590
  const docIds = {};
448
591
  ctcs.forEach((c) => c.services &&
449
592
  c.services.forEach((s) => s.content && Object.values(s.content).forEach((c) => c && c.documentId && (docIds[c.documentId] = 1))));
450
593
  return (0, utils_1.retry)(() => this.documentApi.getDocuments(new models_1.ListOfIds({ ids: Object.keys(docIds) }))).then((docs) => {
451
- const oDocs = docs.map((x) => _.assign({}, x, cloneKeysAndDelegations(x)));
452
- let markerPromise = Promise.resolve(null);
453
- delegateIds.forEach((delegateId) => {
454
- const tags = delegationTags[delegateId];
455
- markerPromise = markerPromise.then(() => __awaiter(this, void 0, void 0, function* () {
456
- //Share patient
457
- const updatedPatient = yield this.crypto.entities
458
- .entityWithExtendedEncryptedMetadata(patient, delegateId, delSfks, ecKeys, [], [])
459
- .catch((e) => {
460
- console.log(e);
461
- return patient;
462
- });
463
- return _.assign(patient, updatedPatient);
464
- }));
465
- (tags.includes('medicalInformation') || tags.includes('anonymousMedicalInformation') || tags.includes('all')) &&
466
- (markerPromise = addDelegationsAndKeys(hes, markerPromise, delegateId, patient));
467
- (tags.includes('medicalInformation') || tags.includes('all')) &&
468
- (markerPromise = addDelegationsAndKeys(frms, markerPromise, delegateId, patient));
469
- (tags.includes('medicalInformation') || tags.includes('anonymousMedicalInformation') || tags.includes('all')) &&
470
- (markerPromise = addDelegationsAndKeys(ctcsStubs, markerPromise, delegateId, patient));
471
- (tags.includes('medicalInformation') || tags.includes('all')) &&
472
- (markerPromise = addDelegationsAndKeys(cls, markerPromise, delegateId, patient));
473
- (tags.includes('medicalInformation') || tags.includes('all')) &&
474
- (markerPromise = addDelegationsAndKeys(cis, markerPromise, delegateId, patient));
475
- (tags.includes('financialInformation') || tags.includes('all')) &&
476
- (markerPromise = addDelegationsAndKeys(ivs, markerPromise, delegateId, patient));
477
- (tags.includes('medicalInformation') || tags.includes('all')) &&
478
- (markerPromise = addDelegationsAndKeys(docs, markerPromise, delegateId, null));
479
- });
480
- return markerPromise
481
- .then(() => {
482
- //console.log("scd")
483
- return (((allTags.includes('medicalInformation') || allTags.includes('anonymousMedicalInformation') || allTags.includes('all')) &&
484
- ctcsStubs &&
485
- ctcsStubs.length &&
486
- !_.isEqual(oCtcsStubs, ctcsStubs) &&
487
- this.contactApi
488
- .setContactsDelegations(ctcsStubs)
489
- .then(() => {
490
- status.contacts.success = true;
491
- status.contacts.modified += ctcsStubs.length;
492
- })
493
- .catch((e) => (status.contacts.error = e))) ||
494
- Promise.resolve((status.contacts.success = true)));
495
- })
496
- .then(() => {
497
- //console.log("shed")
498
- return (((allTags.includes('medicalInformation') || allTags.includes('anonymousMedicalInformation') || allTags.includes('all')) &&
499
- hes &&
500
- hes.length &&
501
- !_.isEqual(oHes, hes) &&
502
- this.helementApi
503
- .setHealthElementsDelegations(hes)
504
- .then(() => {
505
- status.healthElements.success = true;
506
- status.healthElements.modified += hes.length;
507
- })
508
- .catch((e) => (status.healthElements.error = e))) ||
509
- Promise.resolve((status.healthElements.success = true)));
510
- })
511
- .then(() => {
512
- //console.log("sfd")
513
- return (((allTags.includes('medicalInformation') || allTags.includes('all')) &&
514
- frms &&
515
- frms.length &&
516
- !_.isEqual(oFrms, frms) &&
517
- this.formApi
518
- .setFormsDelegations(frms)
519
- .then(() => {
520
- status.forms.success = true;
521
- status.forms.modified += frms.length;
522
- })
523
- .catch((e) => (status.forms.error = e))) ||
524
- Promise.resolve((status.forms.success = true)));
525
- })
526
- .then(() => {
527
- //console.log("sid")
528
- return (((allTags.includes('financialInformation') || allTags.includes('all')) &&
529
- ivs &&
530
- ivs.length &&
531
- !_.isEqual(oIvs, ivs) &&
532
- this.invoiceApi
533
- .setInvoicesDelegations(ivs)
534
- .then(() => {
535
- status.invoices.success = true;
536
- status.invoices.modified += ivs.length;
537
- })
538
- .catch((e) => (status.invoices.error = e))) ||
539
- Promise.resolve((status.invoices.success = true)));
540
- })
541
- .then(() => {
542
- //console.log("sdd")
543
- return (((allTags.includes('medicalInformation') || allTags.includes('all')) &&
544
- docs &&
545
- docs.length &&
546
- !_.isEqual(oDocs, docs) &&
547
- this.documentApi
548
- .setDocumentsDelegations(docs)
549
- .then(() => {
550
- status.documents.success = true;
551
- status.documents.modified += docs.length;
552
- })
553
- .catch((e) => (status.documents.error = e))) ||
554
- Promise.resolve((status.documents.success = true)));
555
- })
556
- .then(() => {
557
- //console.log("scld")
558
- return (((allTags.includes('medicalInformation') || allTags.includes('all')) &&
559
- cls &&
560
- cls.length &&
561
- !_.isEqual(oCls, cls) &&
562
- this.classificationApi
563
- .setClassificationsDelegations(cls)
564
- .then(() => {
565
- status.classifications.success = true;
566
- status.classifications.modified += cls.length;
567
- })
568
- .catch((e) => (status.classifications.error = e))) ||
569
- Promise.resolve((status.classifications.success = true)));
570
- })
571
- .then(() => {
572
- //console.log("scid")
573
- return (((allTags.includes('medicalInformation') || allTags.includes('all')) &&
574
- cis &&
575
- cis.length &&
576
- !_.isEqual(oCis, cis) &&
577
- this.calendarItemApi
578
- .setCalendarItemsDelegations(cis)
579
- .then(() => {
580
- status.calendarItems.success = true;
581
- status.calendarItems.modified += cis.length;
582
- })
583
- .catch((e) => (status.calendarItems.error = e))) ||
584
- Promise.resolve((status.calendarItems.success = true)));
585
- })
586
- .then(() => this.modifyPatientWithUser(user, patient))
587
- .then((p) => {
588
- status.patient.success = true;
589
- console.log(`c: ${status.contacts.modified}, he: ${status.healthElements.modified}, docs: ${status.documents.modified}, frms: ${status.forms.modified}, ivs: ${status.invoices.modified}, cis: ${status.calendarItems.modified}, cls: ${status.classifications.modified}`);
590
- return { patient: p, statuses: status };
591
- })
592
- .catch((e) => {
593
- status.patient.error = e;
594
- return { patient: patient, statuses: status };
595
- });
594
+ return {
595
+ id: patId,
596
+ patient: patient,
597
+ contacts: ctcs,
598
+ forms: frms,
599
+ healthElements: hes,
600
+ invoices: ivs,
601
+ classifications: cls,
602
+ calItems: cis,
603
+ documents: docs,
604
+ };
596
605
  });
597
606
  })
598
- : (allTags.includes('anonymousMedicalInformation')
599
- ? // TODO check also in v8 how patient is shared with anonymousMedicalInformation tag
600
- Promise.resolve(patient)
601
- : this.modifyPatientWithUser(user, _.assign(patient, {
602
- delegations: _.assign(patient.delegations, delegateIds
603
- .filter((id) => !patient.delegations || !patient.delegations[id]) //If there are delegations do not modify
604
- .reduce((acc, del) => Object.assign(acc, _.fromPairs([[del, []]])), patient.delegations || {})),
605
- })))
606
- .then((p) => {
607
- status.patient.success = true;
608
- return { patient: p, statuses: status };
609
- })
610
- .catch((e) => {
611
- status.patient.error = e;
612
- return { patient: patient, statuses: status };
607
+ : Promise.resolve({
608
+ id: patId,
609
+ patient: patient,
610
+ contacts: [],
611
+ forms: [],
612
+ healthElements: [],
613
+ invoices: [],
614
+ classifications: [],
615
+ calItems: [],
616
+ documents: [],
613
617
  });
614
618
  }));
615
619
  });
616
620
  }
617
- export(user, patId, ownerId, usingPost = false) {
618
- return this.hcpartyApi.getHealthcareParty(ownerId).then((hcp) => {
619
- const parentId = hcp.parentId;
620
- return (0, utils_1.retry)(() => this.getPatientWithUser(user, patId))
621
- .then((patient) => patient.encryptionKeys && Object.keys(patient.encryptionKeys || {}).length
622
- ? Promise.resolve(patient)
623
- : this.crypto.entities.ensureEncryptionKeysInitialised(patient).then((p) => (!!p ? this.modifyPatientWithUser(user, p) : patient)))
624
- .then((patient) => __awaiter(this, void 0, void 0, function* () {
625
- if (!patient) {
626
- return Promise.resolve({ id: patId });
627
- }
628
- const delSfks = yield this.crypto.entities.secretIdsOf(patient, ownerId);
629
- return Promise.resolve().then(() => {
630
- return delSfks.length
631
- ? Promise.all([
632
- (0, utils_1.retry)(() => (usingPost
633
- ? this.helementApi.findByHCPartyPatientSecretFKeysArray(ownerId, _.uniq(delSfks))
634
- : this.helementApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))).then((hes) => parentId
635
- ? this.helementApi
636
- .findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))
637
- .then((moreHes) => _.uniqBy(hes.concat(moreHes), 'id'))
638
- : hes)),
639
- (0, utils_1.retry)(() => (usingPost
640
- ? this.formApi.findFormsByHCPartyPatientForeignKeysUsingPost(ownerId, undefined, undefined, undefined, _.uniq(delSfks))
641
- : this.formApi.findFormsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))).then((frms) => parentId
642
- ? (usingPost
643
- ? this.formApi.findFormsByHCPartyPatientForeignKeysUsingPost(parentId, undefined, undefined, undefined, _.uniq(delSfks))
644
- : this.formApi.findFormsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))).then((moreFrms) => _.uniqBy(frms.concat(moreFrms), 'id'))
645
- : frms)),
646
- (0, utils_1.retry)(() => (usingPost
647
- ? this.contactApi.findByHCPartyPatientSecretFKeysArray(ownerId, _.uniq(delSfks))
648
- : this.contactApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))).then((ctcs) => parentId
649
- ? (usingPost
650
- ? this.contactApi.findByHCPartyPatientSecretFKeysArray(parentId, _.uniq(delSfks))
651
- : this.contactApi.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))).then((moreCtcs) => _.uniqBy(ctcs.concat(moreCtcs), 'id'))
652
- : ctcs)),
653
- (0, utils_1.retry)(() => (usingPost
654
- ? this.invoiceApi.findInvoicesByHCPartyPatientForeignKeysUsingPost(ownerId, _.uniq(delSfks))
655
- : this.invoiceApi.findInvoicesByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))).then((ivs) => parentId
656
- ? (usingPost
657
- ? this.invoiceApi.findInvoicesByHCPartyPatientForeignKeysUsingPost(parentId, _.uniq(delSfks))
658
- : this.invoiceApi.findInvoicesByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))).then((moreIvs) => _.uniqBy(ivs.concat(moreIvs), 'id'))
659
- : ivs)),
660
- (0, utils_1.retry)(() => this.classificationApi
661
- .findClassificationsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
662
- .then((cls) => parentId
663
- ? this.classificationApi
664
- .findClassificationsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
665
- .then((moreCls) => _.uniqBy(cls.concat(moreCls), 'id'))
666
- : cls)),
667
- (0, utils_1.retry)(() => __awaiter(this, void 0, void 0, function* () {
668
- const delegationSFKs = _.uniq(delSfks).join(',');
669
- try {
670
- let calendarItems = yield (usingPost
671
- ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(ownerId, _.uniq(delSfks))
672
- : this.calendarItemApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(',')));
673
- if (parentId) {
674
- const moreCalendarItems = yield (usingPost
675
- ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(parentId, _.uniq(delSfks))
676
- : this.calendarItemApi.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(',')));
677
- calendarItems = _.uniqBy(calendarItems.concat(moreCalendarItems), 'id');
678
- }
679
- return calendarItems;
680
- }
681
- catch (ex) {
682
- console.log(`exception occured exporting calendarItem for ownerId: ${ownerId} - ${ex}`);
683
- //throw ex
684
- }
685
- })),
686
- ]).then(([hes, frms, ctcs, ivs, cls, cis]) => {
687
- const docIds = {};
688
- ctcs.forEach((c) => c.services &&
689
- c.services.forEach((s) => s.content && Object.values(s.content).forEach((c) => c && c.documentId && (docIds[c.documentId] = 1))));
690
- return (0, utils_1.retry)(() => this.documentApi.getDocuments(new models_1.ListOfIds({ ids: Object.keys(docIds) }))).then((docs) => {
691
- return {
692
- id: patId,
693
- patient: patient,
694
- contacts: ctcs,
695
- forms: frms,
696
- healthElements: hes,
697
- invoices: ivs,
698
- classifications: cls,
699
- calItems: cis,
700
- documents: docs,
701
- };
702
- });
703
- })
704
- : Promise.resolve({
705
- id: patId,
706
- patient: patient,
707
- contacts: [],
708
- forms: [],
709
- healthElements: [],
710
- invoices: [],
711
- classifications: [],
712
- calItems: [],
713
- documents: [],
714
- });
715
- });
716
- }));
717
- });
718
- }
719
621
  checkInami(inami) {
720
622
  const num_inami = inami.replace(new RegExp('[^(0-9)]', 'g'), '');
721
623
  const checkDigit = num_inami.substring(6, 2);
@@ -744,12 +646,12 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
744
646
  }
745
647
  return isValidNiss;
746
648
  }
747
- getPatientIdOfChildDocumentForHcpAndHcpParents(childDocument, hcpId) {
649
+ getPatientIdOfChildDocumentForHcpAndHcpParents(childDocument, hcpId, childDocumentType) {
748
650
  const _super = Object.create(null, {
749
651
  getPatient: { get: () => super.getPatient }
750
652
  });
751
653
  return __awaiter(this, void 0, void 0, function* () {
752
- const parentIdsArray = yield this.crypto.entities.owningEntityIdsOf(childDocument, hcpId);
654
+ const parentIdsArray = yield this.crypto.xapi.owningEntityIdsOf({ entity: childDocument, type: childDocumentType }, hcpId);
753
655
  const multipleParentIds = _.uniq(parentIdsArray).length > 1;
754
656
  if (multipleParentIds) {
755
657
  throw 'Child document with id ' + childDocument.id + ' contains multiple parent ids in its CFKs for hcpId: ' + hcpId;
@@ -771,9 +673,17 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
771
673
  return patient.id;
772
674
  });
773
675
  }
676
+ /**
677
+ * @return if the logged data owner has write access to the content of the given patient
678
+ */
679
+ hasWriteAccess(patient) {
680
+ return __awaiter(this, void 0, void 0, function* () {
681
+ return this.crypto.xapi.hasWriteAccess({ entity: patient, type: 'Patient' });
682
+ });
683
+ }
774
684
  /**
775
685
  * Share an existing patient with other data owners, allowing them to access the non-encrypted data of the patient and optionally also
776
- * the encrypted content.
686
+ * the encrypted content, with read-only or read-write permissions.
777
687
  * @param delegateId the id of the data owner which will be granted access to the patient.
778
688
  * @param patient the patient to share.
779
689
  * @param shareSecretIds the secret ids of the Patient that the delegate will be given access to. Allows the delegate to search for data where the
@@ -783,35 +693,65 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
783
693
  * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
784
694
  * patient does not have encrypted content.
785
695
  * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
786
- * @return a promise which will contain the updated patient.
696
+ * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.
697
+ * @return the updated entity
787
698
  */
788
699
  shareWith(delegateId, patient, shareSecretIds, options = {}) {
789
700
  return __awaiter(this, void 0, void 0, function* () {
790
- return this.shareWithMany(patient, { [delegateId]: Object.assign({ shareSecretIds }, options) });
701
+ return this.shareWithMany(patient, { [delegateId]: Object.assign(Object.assign({}, options), { shareSecretIds: shareSecretIds }) });
791
702
  });
792
703
  }
793
704
  /**
794
705
  * Share an existing patient with other data owners, allowing them to access the non-encrypted data of the patient and optionally also
795
- * the encrypted content.
706
+ * the encrypted content, with read-only or read-write permissions.
796
707
  * @param patient the patient to share.
797
- * @param delegates sharing options for each delegate.
708
+ * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:
709
+ * - shareSecretIds the secret ids of the Patient that the delegate will be given access to. Allows the delegate to search for data where the
710
+ * shared Patient is the owning entity id.
798
711
  * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
799
712
  * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
800
713
  * patient does not have encrypted content.
714
+ * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
715
+ * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.
716
+ * @return the updated entity
717
+ */
718
+ shareWithMany(patient, delegates) {
719
+ return __awaiter(this, void 0, void 0, function* () {
720
+ return (yield this.tryShareWithMany(patient, delegates)).updatedEntityOrThrow;
721
+ });
722
+ }
723
+ /**
724
+ * Share an existing patient with other data owners, allowing them to access the non-encrypted data of the patient and optionally also
725
+ * the encrypted content, with read-only or read-write permissions.
726
+ * @param patient the patient to share.
727
+ * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:
801
728
  * - shareSecretIds the secret ids of the Patient that the delegate will be given access to. Allows the delegate to search for data where the
802
729
  * shared Patient is the owning entity id.
730
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
731
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
732
+ * patient does not have encrypted content.
803
733
  * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
804
- * @return a promise which will contain the updated patient.
734
+ * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.
735
+ * @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
736
+ * the operation failed.
805
737
  */
806
- shareWithMany(patient, delegates) {
738
+ tryShareWithMany(patient, delegates) {
807
739
  return __awaiter(this, void 0, void 0, function* () {
808
740
  const self = yield this.dataOwnerApi.getCurrentDataOwnerId();
809
- const extended = yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(patient, false, delegates);
810
- if (!!extended) {
811
- return yield this.modifyAs(self, extended);
812
- }
813
- else
814
- return patient;
741
+ // All entities should have an encryption key.
742
+ const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(patient, 'Patient');
743
+ const updatedEntity = entityWithEncryptionKey ? yield this.modifyPatientAs(self, entityWithEncryptionKey) : patient;
744
+ return this.crypto.xapi
745
+ .simpleShareOrUpdateEncryptedEntityMetadata({ entity: updatedEntity, type: 'Patient' }, false, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
746
+ delegateId,
747
+ {
748
+ requestedPermissions: options.requestedPermissions,
749
+ shareEncryptionKeys: options.shareEncryptionKey,
750
+ shareOwningEntityIds: ShareMetadataBehaviour_1.ShareMetadataBehaviour.NEVER,
751
+ shareSecretIds: options.shareSecretIds,
752
+ },
753
+ ])), (x) => this.bulkSharePatients(x))
754
+ .then((r) => r.mapSuccessAsync((e) => this.decryptAs(self, [e]).then((es) => es[0])));
815
755
  });
816
756
  }
817
757
  /**
@@ -820,7 +760,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
820
760
  * patient is the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.
821
761
  */
822
762
  decryptSecretIdsOf(patient) {
823
- return this.crypto.entities.secretIdsOf(patient, undefined);
763
+ return this.crypto.xapi.secretIdsOf({ entity: patient, type: 'Patient' }, undefined);
824
764
  }
825
765
  /**
826
766
  * @param patient a patient
@@ -828,7 +768,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
828
768
  * patient is the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.
829
769
  */
830
770
  decryptConfidentialSecretIdsOf(patient) {
831
- return this.crypto.confidential.getConfidentialSecretIds(patient, undefined);
771
+ return this.crypto.confidential.getConfidentialSecretIds({ entity: patient, type: 'Patient' }, undefined);
832
772
  }
833
773
  /**
834
774
  * @param patient a patient
@@ -836,17 +776,13 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
836
776
  * patient is the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.
837
777
  */
838
778
  decryptNonConfidentialSecretIdsOf(patient) {
839
- return this.crypto.confidential.getSecretIdsSharedWithParents(patient);
779
+ return this.crypto.confidential.getSecretIdsSharedWithParents({ entity: patient, type: 'Patient' });
840
780
  }
841
781
  getDataOwnersWithAccessTo(entity) {
842
- return __awaiter(this, void 0, void 0, function* () {
843
- return yield this.crypto.entities.getDataOwnersWithAccessTo(entity);
844
- });
782
+ return this.crypto.xapi.getDataOwnersWithAccessTo({ entity, type: 'Patient' });
845
783
  }
846
784
  getEncryptionKeysOf(entity) {
847
- return __awaiter(this, void 0, void 0, function* () {
848
- return yield this.crypto.entities.encryptionKeysOf(entity);
849
- });
785
+ return this.crypto.xapi.encryptionKeysOf({ entity, type: 'Patient' }, undefined);
850
786
  }
851
787
  /**
852
788
  * Merge two patients into one. This method performs the following operations:
@@ -890,16 +826,15 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
890
826
  baseMergePatients: { get: () => super.baseMergePatients }
891
827
  });
892
828
  return __awaiter(this, void 0, void 0, function* () {
893
- const encryptedMerged = (yield this.encryptAs(undefined, [mergedInto]))[0];
829
+ const encryptedMerged = (yield this.encryptAs(yield this.dataOwnerApi.getCurrentDataOwnerId(), [mergedInto]))[0];
894
830
  const merged = yield _super.baseMergePatients.call(this, from.id, from.rev, encryptedMerged);
895
- return (yield this.tryDecryptOrReturnOriginal(undefined, [merged]))[0].entity;
831
+ return (yield this.tryDecryptOrReturnOriginal([merged]))[0].entity;
896
832
  });
897
833
  }
898
834
  subscribeToPatientEvents(eventTypes, filter, eventFired, options = {}) {
899
835
  return __awaiter(this, void 0, void 0, function* () {
900
836
  const currentUser = yield this.userApi.getCurrentUser();
901
- return (0, websocket_1.subscribeToEntityEvents)(this.host, this.authApi, 'Patient', eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt(currentUser, [encrypted]))[0]; }))
902
- .then((rs) => new Connection_1.ConnectionImpl(rs));
837
+ return (0, utils_1.subscribeToEntityEvents)(this.host, this.authApi, 'Patient', eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt(currentUser, [encrypted]))[0]; })).then((rs) => new Connection_1.ConnectionImpl(rs));
903
838
  });
904
839
  }
905
840
  }