@icure/api 7.1.16 → 8.0.0-RC.2

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