@icure/api 7.0.0-beta.3 → 7.0.0

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 (207) hide show
  1. package/icc-api/api/IccAccesslogApi.js +2 -1
  2. package/icc-api/api/IccAccesslogApi.js.map +1 -1
  3. package/icc-api/api/IccAgendaApi.js +2 -1
  4. package/icc-api/api/IccAgendaApi.js.map +1 -1
  5. package/icc-api/api/IccAnonymousAccessApi.js +2 -1
  6. package/icc-api/api/IccAnonymousAccessApi.js.map +1 -1
  7. package/icc-api/api/IccApplicationsettingsApi.js +2 -1
  8. package/icc-api/api/IccApplicationsettingsApi.js.map +1 -1
  9. package/icc-api/api/IccArticleApi.js +2 -1
  10. package/icc-api/api/IccArticleApi.js.map +1 -1
  11. package/icc-api/api/IccAuthApi.d.ts +23 -0
  12. package/icc-api/api/IccAuthApi.js +59 -2
  13. package/icc-api/api/IccAuthApi.js.map +1 -1
  14. package/icc-api/api/IccBeefactApi.js +2 -1
  15. package/icc-api/api/IccBeefactApi.js.map +1 -1
  16. package/icc-api/api/IccBekmehrApi.js +2 -1
  17. package/icc-api/api/IccBekmehrApi.js.map +1 -1
  18. package/icc-api/api/IccBeresultexportApi.js +2 -1
  19. package/icc-api/api/IccBeresultexportApi.js.map +1 -1
  20. package/icc-api/api/IccBeresultimportApi.js +2 -1
  21. package/icc-api/api/IccBeresultimportApi.js.map +1 -1
  22. package/icc-api/api/IccBesamv2Api.d.ts +6 -0
  23. package/icc-api/api/IccBesamv2Api.js +15 -1
  24. package/icc-api/api/IccBesamv2Api.js.map +1 -1
  25. package/icc-api/api/IccCalendarItemApi.js +2 -1
  26. package/icc-api/api/IccCalendarItemApi.js.map +1 -1
  27. package/icc-api/api/IccCalendarItemTypeApi.js +2 -1
  28. package/icc-api/api/IccCalendarItemTypeApi.js.map +1 -1
  29. package/icc-api/api/IccClassificationApi.js +2 -1
  30. package/icc-api/api/IccClassificationApi.js.map +1 -1
  31. package/icc-api/api/IccClassificationTemplateApi.js +2 -1
  32. package/icc-api/api/IccClassificationTemplateApi.js.map +1 -1
  33. package/icc-api/api/IccCodeApi.js +2 -1
  34. package/icc-api/api/IccCodeApi.js.map +1 -1
  35. package/icc-api/api/IccContactApi.d.ts +6 -0
  36. package/icc-api/api/IccContactApi.js +26 -1
  37. package/icc-api/api/IccContactApi.js.map +1 -1
  38. package/icc-api/api/IccDataownerApi.js +2 -1
  39. package/icc-api/api/IccDataownerApi.js.map +1 -1
  40. package/icc-api/api/IccDeviceApi.js +2 -1
  41. package/icc-api/api/IccDeviceApi.js.map +1 -1
  42. package/icc-api/api/IccDoctemplateApi.js +2 -1
  43. package/icc-api/api/IccDoctemplateApi.js.map +1 -1
  44. package/icc-api/api/IccDocumentApi.d.ts +6 -4
  45. package/icc-api/api/IccDocumentApi.js +10 -6
  46. package/icc-api/api/IccDocumentApi.js.map +1 -1
  47. package/icc-api/api/IccDocumentTemplateApi.js +2 -1
  48. package/icc-api/api/IccDocumentTemplateApi.js.map +1 -1
  49. package/icc-api/api/IccEntityrefApi.js +2 -1
  50. package/icc-api/api/IccEntityrefApi.js.map +1 -1
  51. package/icc-api/api/IccEntitytemplateApi.js +2 -1
  52. package/icc-api/api/IccEntitytemplateApi.js.map +1 -1
  53. package/icc-api/api/IccFormApi.js +2 -1
  54. package/icc-api/api/IccFormApi.js.map +1 -1
  55. package/icc-api/api/IccFrontendmigrationApi.js +2 -1
  56. package/icc-api/api/IccFrontendmigrationApi.js.map +1 -1
  57. package/icc-api/api/IccGroupApi.d.ts +6 -0
  58. package/icc-api/api/IccGroupApi.js +15 -1
  59. package/icc-api/api/IccGroupApi.js.map +1 -1
  60. package/icc-api/api/IccHcpartyApi.js +2 -1
  61. package/icc-api/api/IccHcpartyApi.js.map +1 -1
  62. package/icc-api/api/IccHelementApi.js +2 -1
  63. package/icc-api/api/IccHelementApi.js.map +1 -1
  64. package/icc-api/api/IccIcureApi.js +2 -1
  65. package/icc-api/api/IccIcureApi.js.map +1 -1
  66. package/icc-api/api/IccInsuranceApi.js +2 -1
  67. package/icc-api/api/IccInsuranceApi.js.map +1 -1
  68. package/icc-api/api/IccInvoiceApi.js +2 -1
  69. package/icc-api/api/IccInvoiceApi.js.map +1 -1
  70. package/icc-api/api/IccKeywordApi.js +2 -1
  71. package/icc-api/api/IccKeywordApi.js.map +1 -1
  72. package/icc-api/api/IccMaintenanceTaskApi.js +2 -1
  73. package/icc-api/api/IccMaintenanceTaskApi.js.map +1 -1
  74. package/icc-api/api/IccMedexApi.js +2 -1
  75. package/icc-api/api/IccMedexApi.js.map +1 -1
  76. package/icc-api/api/IccMedicallocationApi.js +2 -1
  77. package/icc-api/api/IccMedicallocationApi.js.map +1 -1
  78. package/icc-api/api/IccMessageApi.js +2 -1
  79. package/icc-api/api/IccMessageApi.js.map +1 -1
  80. package/icc-api/api/IccPatientApi.js +2 -1
  81. package/icc-api/api/IccPatientApi.js.map +1 -1
  82. package/icc-api/api/IccPermissionApi.js +2 -1
  83. package/icc-api/api/IccPermissionApi.js.map +1 -1
  84. package/icc-api/api/IccPlaceApi.js +2 -1
  85. package/icc-api/api/IccPlaceApi.js.map +1 -1
  86. package/icc-api/api/IccPubsubApi.js +2 -1
  87. package/icc-api/api/IccPubsubApi.js.map +1 -1
  88. package/icc-api/api/IccReceiptApi.js +2 -1
  89. package/icc-api/api/IccReceiptApi.js.map +1 -1
  90. package/icc-api/api/IccReplicationApi.js +2 -1
  91. package/icc-api/api/IccReplicationApi.js.map +1 -1
  92. package/icc-api/api/IccRestApiPath.d.ts +1 -0
  93. package/icc-api/api/IccRestApiPath.js +10 -0
  94. package/icc-api/api/IccRestApiPath.js.map +1 -0
  95. package/icc-api/api/IccTarificationApi.js +2 -1
  96. package/icc-api/api/IccTarificationApi.js.map +1 -1
  97. package/icc-api/api/IccTimeTableApi.js +2 -1
  98. package/icc-api/api/IccTimeTableApi.js.map +1 -1
  99. package/icc-api/api/IccTmpApi.js +2 -1
  100. package/icc-api/api/IccTmpApi.js.map +1 -1
  101. package/icc-api/api/IccUserApi.js +2 -1
  102. package/icc-api/api/IccUserApi.js.map +1 -1
  103. package/icc-api/index.d.ts +0 -1
  104. package/icc-api/index.js +0 -1
  105. package/icc-api/index.js.map +1 -1
  106. package/icc-api/model/Address.d.ts +6 -0
  107. package/icc-api/model/Address.js.map +1 -1
  108. package/icc-api/model/Annotation.d.ts +18 -0
  109. package/icc-api/model/Annotation.js.map +1 -1
  110. package/icc-api/model/AuthenticationToken.d.ts +1 -0
  111. package/icc-api/model/AuthenticationToken.js.map +1 -1
  112. package/icc-api/model/Content.js +1 -1
  113. package/icc-api/model/Content.js.map +1 -1
  114. package/icc-api/model/CryptoActorStub.d.ts +5 -0
  115. package/icc-api/model/CryptoActorStub.js +1 -0
  116. package/icc-api/model/CryptoActorStub.js.map +1 -1
  117. package/icc-api/model/Delegation.d.ts +3 -0
  118. package/icc-api/model/Delegation.js.map +1 -1
  119. package/icc-api/model/FlatRateTarification.d.ts +4 -1
  120. package/icc-api/model/FlatRateTarification.js +3 -0
  121. package/icc-api/model/FlatRateTarification.js.map +1 -1
  122. package/icc-api/model/HealthElement.d.ts +6 -0
  123. package/icc-api/model/HealthElement.js.map +1 -1
  124. package/icc-api/model/HealthcareParty.js +1 -1
  125. package/icc-api/model/HealthcareParty.js.map +1 -1
  126. package/icc-api/model/ISO639_1.d.ts +8 -0
  127. package/icc-api/model/ISO639_1.js +3 -0
  128. package/icc-api/model/ISO639_1.js.map +1 -0
  129. package/icc-api/model/Patient.d.ts +7 -0
  130. package/icc-api/model/Patient.js +1 -1
  131. package/icc-api/model/Patient.js.map +1 -1
  132. package/icc-api/model/UserGroup.d.ts +1 -0
  133. package/icc-api/model/UserGroup.js.map +1 -1
  134. package/icc-api/model/models.d.ts +1 -0
  135. package/icc-api/model/models.js.map +1 -1
  136. package/icc-x-api/auth/AuthenticationProvider.d.ts +67 -6
  137. package/icc-x-api/auth/AuthenticationProvider.js +100 -7
  138. package/icc-x-api/auth/AuthenticationProvider.js.map +1 -1
  139. package/icc-x-api/auth/EnsembleAuthService.d.ts +7 -2
  140. package/icc-x-api/auth/EnsembleAuthService.js +9 -0
  141. package/icc-x-api/auth/EnsembleAuthService.js.map +1 -1
  142. package/icc-x-api/auth/JwtAuthService.d.ts +10 -5
  143. package/icc-x-api/auth/JwtAuthService.js +22 -26
  144. package/icc-x-api/auth/JwtAuthService.js.map +1 -1
  145. package/icc-x-api/auth/JwtBridgedAuthService.d.ts +27 -0
  146. package/icc-x-api/auth/JwtBridgedAuthService.js +131 -0
  147. package/icc-x-api/auth/JwtBridgedAuthService.js.map +1 -0
  148. package/icc-x-api/crypto/EntitiesEncryption.d.ts +5 -4
  149. package/icc-x-api/crypto/EntitiesEncryption.js +20 -16
  150. package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -1
  151. package/icc-x-api/filters/ServiceByHcPartyTagCodeDateFilter.d.ts +1 -0
  152. package/icc-x-api/filters/ServiceByHcPartyTagCodeDateFilter.js.map +1 -1
  153. package/icc-x-api/filters/filters.d.ts +4 -0
  154. package/icc-x-api/filters/filters.js +4 -0
  155. package/icc-x-api/filters/filters.js.map +1 -1
  156. package/icc-x-api/icc-accesslog-x-api.d.ts +2 -2
  157. package/icc-x-api/icc-accesslog-x-api.js +17 -24
  158. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  159. package/icc-x-api/icc-calendar-item-x-api.d.ts +1 -1
  160. package/icc-x-api/icc-calendar-item-x-api.js +18 -22
  161. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  162. package/icc-x-api/icc-classification-x-api.js +13 -19
  163. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  164. package/icc-x-api/icc-contact-x-api.d.ts +17 -1
  165. package/icc-x-api/icc-contact-x-api.js +81 -99
  166. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  167. package/icc-x-api/icc-data-owner-x-api.d.ts +1 -1
  168. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  169. package/icc-x-api/icc-doctemplate-x-api.js +2 -13
  170. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  171. package/icc-x-api/icc-document-x-api.d.ts +12 -4
  172. package/icc-x-api/icc-document-x-api.js +29 -25
  173. package/icc-x-api/icc-document-x-api.js.map +1 -1
  174. package/icc-x-api/icc-form-x-api.js +13 -17
  175. package/icc-x-api/icc-form-x-api.js.map +1 -1
  176. package/icc-x-api/icc-helement-x-api.d.ts +1 -1
  177. package/icc-x-api/icc-helement-x-api.js +15 -20
  178. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  179. package/icc-x-api/icc-icure-maintenance-x-api.js +4 -4
  180. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
  181. package/icc-x-api/icc-invoice-x-api.js +13 -19
  182. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  183. package/icc-x-api/icc-maintenance-task-x-api.d.ts +1 -1
  184. package/icc-x-api/icc-maintenance-task-x-api.js +13 -14
  185. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  186. package/icc-x-api/icc-message-x-api.js +13 -18
  187. package/icc-x-api/icc-message-x-api.js.map +1 -1
  188. package/icc-x-api/icc-patient-x-api.d.ts +5 -2
  189. package/icc-x-api/icc-patient-x-api.js +17 -24
  190. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  191. package/icc-x-api/icc-receipt-x-api.js +11 -16
  192. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  193. package/icc-x-api/icc-time-table-x-api.js +11 -16
  194. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  195. package/icc-x-api/index.d.ts +284 -35
  196. package/icc-x-api/index.js +303 -79
  197. package/icc-x-api/index.js.map +1 -1
  198. package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +12 -9
  199. package/icc-x-api/maintenance/KeyPairUpdateRequest.js +11 -17
  200. package/icc-x-api/maintenance/KeyPairUpdateRequest.js.map +1 -1
  201. package/icc-x-api/utils/crypto-utils.d.ts +140 -11
  202. package/icc-x-api/utils/crypto-utils.js +285 -36
  203. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  204. package/package.json +1 -1
  205. package/icc-api/api/IccBemikronoApi.d.ts +0 -81
  206. package/icc-api/api/IccBemikronoApi.js +0 -162
  207. package/icc-api/api/IccBemikronoApi.js.map +0 -1
@@ -11,9 +11,24 @@ export declare class IccContactXApi extends IccContactApi implements EncryptedEn
11
11
  i18n: any;
12
12
  crypto: IccCryptoXApi;
13
13
  dataOwnerApi: IccDataOwnerXApi;
14
+ private readonly contactEncryptedFields;
15
+ private readonly serviceEncryptedFieldsNoContent;
16
+ private readonly serviceEncryptedFieldsWithContent;
17
+ /**
18
+ *
19
+ * @param host
20
+ * @param headers
21
+ * @param crypto
22
+ * @param dataOwnerApi
23
+ * @param authenticationProvider
24
+ * @param fetchImpl
25
+ * @param contactEncryptedKeys custom encrypted fields for Contact. Note that to customise the encryption of contained services (`services` field),
26
+ * you need to use the serviceEncryptedKeys parameter.
27
+ * @param serviceEncryptedKeys custom encrypted fields for Service. Note that you can't customise encryption of the `content` field
28
+ */
14
29
  constructor(host: string, headers: {
15
30
  [key: string]: string;
16
- }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
31
+ }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>, contactEncryptedKeys?: string[], serviceEncryptedKeys?: string[]);
17
32
  /**
18
33
  * Creates a new instance of contact with initialised encryption metadata (not in the database).
19
34
  * @param user the current user.
@@ -70,6 +85,7 @@ export declare class IccContactXApi extends IccContactApi implements EncryptedEn
70
85
  findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[], planOfActionIds?: string, skipClosedContacts?: boolean): Promise<Array<models.Contact> | any>;
71
86
  filterByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: models.FilterChainContact): Promise<PaginatedListContact | any>;
72
87
  listContactsByOpeningDateWithUser(user: models.User, startKey: number, endKey: number, hcpartyid: string, startDocumentId?: string, limit?: number): Promise<PaginatedListContact | any>;
88
+ getServiceWithUser(user: models.User, serviceId: string): Promise<Service>;
73
89
  listServicesWithUser(user: models.User, serviceIds: ListOfIds): Promise<Array<Service> | any>;
74
90
  findByHCPartyFormIdWithUser(user: models.User, hcPartyId: string, formId: string): Promise<Array<models.Contact> | any>;
75
91
  findByHCPartyFormIdsWithUser(user: models.User, hcPartyId: string, body: models.ListOfIds): Promise<Array<models.Contact> | any>;
@@ -21,15 +21,39 @@ const ServiceByIdsFilter_1 = require("./filters/ServiceByIdsFilter");
21
21
  const utils_1 = require("./utils");
22
22
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
23
23
  class IccContactXApi extends icc_api_1.IccContactApi {
24
+ /**
25
+ *
26
+ * @param host
27
+ * @param headers
28
+ * @param crypto
29
+ * @param dataOwnerApi
30
+ * @param authenticationProvider
31
+ * @param fetchImpl
32
+ * @param contactEncryptedKeys custom encrypted fields for Contact. Note that to customise the encryption of contained services (`services` field),
33
+ * you need to use the serviceEncryptedKeys parameter.
34
+ * @param serviceEncryptedKeys custom encrypted fields for Service. Note that you can't customise encryption of the `content` field
35
+ */
24
36
  constructor(host, headers, crypto, dataOwnerApi, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
25
37
  ? window.fetch
26
38
  : typeof self !== 'undefined'
27
39
  ? self.fetch
28
- : fetch) {
40
+ : fetch, contactEncryptedKeys = ['descr'], serviceEncryptedKeys = []) {
29
41
  super(host, headers, authenticationProvider, fetchImpl);
30
42
  this.i18n = contact_i18n_1.default;
43
+ if (contactEncryptedKeys.some((key) => key.startsWith('services'))) {
44
+ throw new Error("You can't customise encryption of the `services` field of Contact. Use the serviceEncryptedKeys parameter instead.");
45
+ }
46
+ if (serviceEncryptedKeys.some((key) => key.startsWith('content'))) {
47
+ throw new Error("You can't customise encryption of the `content` of a Service. The content values for services is automatically encrypted.");
48
+ }
31
49
  this.crypto = crypto;
32
50
  this.dataOwnerApi = dataOwnerApi;
51
+ this.contactEncryptedFields = (0, utils_1.parseEncryptedFields)(contactEncryptedKeys, 'Contact.');
52
+ const customServiceEncryptedFields = (0, utils_1.parseEncryptedFields)(serviceEncryptedKeys, 'Service.');
53
+ if (serviceEncryptedKeys.length > 0) {
54
+ this.serviceEncryptedFieldsNoContent = customServiceEncryptedFields;
55
+ }
56
+ this.serviceEncryptedFieldsWithContent = Object.assign(Object.assign({}, customServiceEncryptedFields), { topLevelFields: [...customServiceEncryptedFields.topLevelFields, { fieldName: 'content', fieldPath: 'Service.content' }] });
33
57
  }
34
58
  /**
35
59
  * Creates a new instance of contact with initialised encryption metadata (not in the database).
@@ -49,33 +73,20 @@ class IccContactXApi extends icc_api_1.IccContactApi {
49
73
  * @return a new instance of contact.
50
74
  */
51
75
  newInstance(user, patient, c, options = {}) {
52
- var _a, _b, _c, _d, _e, _f;
76
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
53
77
  return __awaiter(this, void 0, void 0, function* () {
54
- const contact = new models.Contact(_.extend({
55
- id: this.crypto.primitives.randomUuid(),
56
- _type: 'org.taktik.icure.entities.Contact',
57
- created: new Date().getTime(),
58
- modified: new Date().getTime(),
59
- responsible: this.dataOwnerApi.getDataOwnerIdOf(user),
60
- author: user.id,
61
- codes: [],
62
- tags: [],
63
- groupId: this.crypto.primitives.randomUuid(),
64
- subContacts: [],
65
- services: [],
66
- openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),
67
- }, c || {}));
78
+ const contact = new models.Contact(Object.assign(Object.assign({}, (c !== null && c !== void 0 ? c : {})), { _type: 'org.taktik.icure.entities.Contact', id: (_a = c === null || c === void 0 ? void 0 : c.id) !== null && _a !== void 0 ? _a : this.crypto.primitives.randomUuid(), created: (_b = c === null || c === void 0 ? void 0 : c.created) !== null && _b !== void 0 ? _b : new Date().getTime(), modified: (_c = c === null || c === void 0 ? void 0 : c.modified) !== null && _c !== void 0 ? _c : new Date().getTime(), responsible: (_d = c === null || c === void 0 ? void 0 : c.responsible) !== null && _d !== void 0 ? _d : this.dataOwnerApi.getDataOwnerIdOf(user), author: (_e = c === null || c === void 0 ? void 0 : c.author) !== null && _e !== void 0 ? _e : user.id, codes: (_f = c === null || c === void 0 ? void 0 : c.codes) !== null && _f !== void 0 ? _f : [], tags: (_g = c === null || c === void 0 ? void 0 : c.tags) !== null && _g !== void 0 ? _g : [], groupId: (_h = c === null || c === void 0 ? void 0 : c.groupId) !== null && _h !== void 0 ? _h : this.crypto.primitives.randomUuid(), subContacts: (_j = c === null || c === void 0 ? void 0 : c.subContacts) !== null && _j !== void 0 ? _j : [], services: (_k = c === null || c === void 0 ? void 0 : c.services) !== null && _k !== void 0 ? _k : [], openingDate: (_l = c === null || c === void 0 ? void 0 : c.openingDate) !== null && _l !== void 0 ? _l : parseInt(moment().format('YYYYMMDDHHmmss')) }));
68
79
  const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
69
80
  if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
70
81
  throw new Error('Can only initialise entities as current data owner.');
71
- const sfk = (_a = options.preferredSfk) !== null && _a !== void 0 ? _a : (!!options.confidential
82
+ const sfk = (_m = options.preferredSfk) !== null && _m !== void 0 ? _m : (!!options.confidential
72
83
  ? yield this.crypto.confidential.getConfidentialSecretId(patient)
73
84
  : yield this.crypto.confidential.getAnySecretIdSharedWithParents(patient));
74
85
  if (!sfk)
75
86
  throw new Error(`Couldn't find any sfk of parent patient ${patient.id} for confidential=${!!options.confidential}`);
76
87
  const extraDelegations = [
77
- ...Object.keys((_b = options.additionalDelegates) !== null && _b !== void 0 ? _b : {}),
78
- ...(options.confidential ? [] : [...((_d = (_c = user.autoDelegations) === null || _c === void 0 ? void 0 : _c.all) !== null && _d !== void 0 ? _d : []), ...((_f = (_e = user.autoDelegations) === null || _e === void 0 ? void 0 : _e.medicalInformation) !== null && _f !== void 0 ? _f : [])]),
88
+ ...Object.keys((_o = options.additionalDelegates) !== null && _o !== void 0 ? _o : {}),
89
+ ...(options.confidential ? [] : [...((_q = (_p = user.autoDelegations) === null || _p === void 0 ? void 0 : _p.all) !== null && _q !== void 0 ? _q : []), ...((_s = (_r = user.autoDelegations) === null || _r === void 0 ? void 0 : _r.medicalInformation) !== null && _s !== void 0 ? _s : [])]),
79
90
  ];
80
91
  const initialisationInfo = yield this.crypto.entities.entityWithInitialisedEncryptedMetadata(contact, patient.id, sfk, true, extraDelegations);
81
92
  return new models.Contact(initialisationInfo.updatedEntity);
@@ -191,11 +202,17 @@ class IccContactXApi extends icc_api_1.IccContactApi {
191
202
  .listContactsByOpeningDate(startKey, endKey, hcpartyid, startDocumentId, limit)
192
203
  .then((ctcs) => this.decrypt(user.healthcarePartyId || user.patientId, ctcs.rows).then((decryptedRows) => Object.assign(ctcs, { rows: decryptedRows })));
193
204
  }
205
+ getServiceWithUser(user, serviceId) {
206
+ return super
207
+ .getService(serviceId)
208
+ .then((service) => { var _a, _b; return this.decryptServices((_b = (_a = user.healthcarePartyId) !== null && _a !== void 0 ? _a : user.patientId) !== null && _b !== void 0 ? _b : user.deviceId, [service]); })
209
+ .then((decrypted) => decrypted[0]);
210
+ }
194
211
  listServicesWithUser(user, serviceIds) {
195
212
  var _a;
196
213
  return super
197
214
  .filterServicesBy(undefined, (_a = serviceIds.ids) === null || _a === void 0 ? void 0 : _a.length, new models_1.FilterChainService({ filter: new ServiceByIdsFilter_1.ServiceByIdsFilter({ ids: serviceIds.ids }) }))
198
- .then((paginatedList) => { var _a; return this.decryptServices(user.healthcarePartyId || user.patientId, (_a = paginatedList.rows) !== null && _a !== void 0 ? _a : []); });
215
+ .then((paginatedList) => { var _a, _b, _c; return this.decryptServices((_b = (_a = user.healthcarePartyId) !== null && _a !== void 0 ? _a : user.patientId) !== null && _b !== void 0 ? _b : user.deviceId, (_c = paginatedList.rows) !== null && _c !== void 0 ? _c : []); });
199
216
  }
200
217
  findByHCPartyFormIdWithUser(user, hcPartyId, formId) {
201
218
  return super.findByHCPartyFormId(hcPartyId, formId).then((ctcs) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user), ctcs));
@@ -262,32 +279,37 @@ class IccContactXApi extends icc_api_1.IccContactApi {
262
279
  }
263
280
  encryptServices(key, rawKey, services) {
264
281
  return Promise.all(services.map((svc) => __awaiter(this, void 0, void 0, function* () {
265
- if (!svc.content) {
266
- return svc;
267
- }
268
- if (Object.values(svc.content).every((c) => c.compoundValue &&
269
- !c.stringValue &&
270
- !c.documentId &&
271
- !c.measureValue &&
272
- !c.medicationValue &&
273
- (c.booleanValue === null || c.booleanValue === undefined) &&
274
- (c.numberValue === null || c.numberValue === undefined) &&
275
- !c.instantValue &&
276
- !c.fuzzyDateValue &&
277
- !c.binaryValue)) {
278
- svc.content = _.fromPairs(yield Promise.all(_.toPairs(svc.content).map((p) => __awaiter(this, void 0, void 0, function* () {
282
+ if (svc.content &&
283
+ Object.values(svc.content).every((c) => c.compoundValue &&
284
+ !c.stringValue &&
285
+ !c.documentId &&
286
+ !c.measureValue &&
287
+ !c.medicationValue &&
288
+ (c.booleanValue === null || c.booleanValue === undefined) &&
289
+ (c.numberValue === null || c.numberValue === undefined) &&
290
+ !c.instantValue &&
291
+ !c.fuzzyDateValue &&
292
+ !c.binaryValue)) {
293
+ const recursivelyEncryptedContent = Object.fromEntries(yield Promise.all(Object.entries(svc.content).map((p) => __awaiter(this, void 0, void 0, function* () {
279
294
  var _a;
280
295
  if ((_a = p[1].compoundValue) === null || _a === void 0 ? void 0 : _a.length) {
281
- p[1].compoundValue = yield this.encryptServices(key, rawKey, p[1].compoundValue);
296
+ return [p[0], Object.assign(Object.assign({}, p[1]), { compoundValue: yield this.encryptServices(key, rawKey, p[1].compoundValue) })];
282
297
  }
283
- return p;
298
+ else
299
+ return p;
284
300
  }))));
301
+ const copyWithEncryptedContent = Object.assign(Object.assign({}, svc), { content: recursivelyEncryptedContent });
302
+ return this.serviceEncryptedFieldsNoContent
303
+ ? (0, utils_1.encryptObject)(copyWithEncryptedContent, (obj) => {
304
+ return this.crypto.primitives.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify(obj)), rawKey);
305
+ }, this.serviceEncryptedFieldsNoContent, 'service')
306
+ : copyWithEncryptedContent;
285
307
  }
286
308
  else {
287
- svc.encryptedSelf = (0, binary_utils_1.b2a)((0, binary_utils_1.ua2string)(yield this.crypto.primitives.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify({ content: svc.content })), rawKey)));
288
- delete svc.content;
309
+ return (0, utils_1.encryptObject)(svc, (obj) => {
310
+ return this.crypto.primitives.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify(obj)), rawKey);
311
+ }, this.serviceEncryptedFieldsWithContent, 'service');
289
312
  }
290
- return svc;
291
313
  })));
292
314
  }
293
315
  encrypt(user, ctcs) {
@@ -296,14 +318,14 @@ class IccContactXApi extends icc_api_1.IccContactApi {
296
318
  encryptAs(hcpartyId, ctcs) {
297
319
  const bypassEncryption = false; //Used for debug
298
320
  return Promise.all(ctcs.map((ctc) => __awaiter(this, void 0, void 0, function* () {
321
+ var _a;
299
322
  const initialisedCtc = bypassEncryption //Prevent encryption for test ctc
300
323
  ? ctc
301
- : yield this.crypto.entities.ensureEncryptionKeysInitialised(ctc);
324
+ : (_a = (yield this.crypto.entities.ensureEncryptionKeysInitialised(ctc))) !== null && _a !== void 0 ? _a : ctc;
302
325
  const encryptionKey = yield this.crypto.entities.importFirstValidKey(yield this.crypto.entities.encryptionKeysOf(ctc, hcpartyId), ctc.id);
303
- initialisedCtc.services = yield this.encryptServices(encryptionKey.key, encryptionKey.raw, ctc.services || []);
304
- initialisedCtc.encryptedSelf = (0, binary_utils_1.b2a)((0, binary_utils_1.ua2string)(yield this.crypto.primitives.AES.encrypt(encryptionKey.key, (0, binary_utils_1.utf8_2ua)(JSON.stringify({ descr: ctc.descr })), encryptionKey.raw)));
305
- delete initialisedCtc.descr;
306
- return initialisedCtc;
326
+ return new models_1.Contact(yield (0, utils_1.encryptObject)(Object.assign(Object.assign({}, initialisedCtc), { services: initialisedCtc.services ? yield this.encryptServices(encryptionKey.key, encryptionKey.raw, initialisedCtc.services) : [] }), (obj) => {
327
+ return this.crypto.primitives.AES.encrypt(encryptionKey.key, (0, binary_utils_1.utf8_2ua)(JSON.stringify(obj)), encryptionKey.raw);
328
+ }, this.contactEncryptedFields, 'contact'));
307
329
  })));
308
330
  }
309
331
  decrypt(hcpartyId, ctcs) {
@@ -313,22 +335,10 @@ class IccContactXApi extends icc_api_1.IccContactApi {
313
335
  console.log('Cannot decrypt contact', ctc.id);
314
336
  return ctc;
315
337
  }
316
- ctc.services = yield this.decryptServices(hcpartyId, ctc.services || [], keys);
317
- if (ctc.encryptedSelf) {
318
- try {
319
- const json = yield this.crypto.entities.tryDecryptJson(keys, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(ctc.encryptedSelf)), false);
320
- if (json) {
321
- _.assign(ctc, json);
322
- }
323
- else {
324
- console.log('Cannot decrypt ctc: no valid key could produce valid json', ctc.id);
325
- }
326
- }
327
- catch (e) {
328
- console.log('Failed to decrypt ctc', ctc.id, e);
329
- }
330
- }
331
- return ctc;
338
+ return new models_1.Contact(yield (0, utils_1.decryptObject)(ctc, (encrypted) => __awaiter(this, void 0, void 0, function* () {
339
+ var _a;
340
+ return (_a = (yield this.crypto.entities.tryDecryptJson(keys, encrypted, false))) !== null && _a !== void 0 ? _a : {};
341
+ })));
332
342
  })));
333
343
  }
334
344
  decryptServices(hcpartyId, svcs, keys) {
@@ -336,43 +346,10 @@ class IccContactXApi extends icc_api_1.IccContactApi {
336
346
  if (!keys) {
337
347
  keys = yield this.crypto.entities.importAllValidKeys(yield this.crypto.entities.encryptionKeysOf(svc, hcpartyId));
338
348
  }
339
- if (svc.encryptedContent) {
340
- try {
341
- const json = yield this.crypto.entities.tryDecryptJson(keys, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(svc.encryptedContent)), true);
342
- if (json) {
343
- Object.assign(svc, { content: json });
344
- }
345
- else {
346
- console.log('Cannot decrypt service: no valid key could produce valid json', svc.id);
347
- }
348
- }
349
- catch (e) {
350
- console.log('Cannot decrypt service', svc.id, e);
351
- }
352
- }
353
- else if (svc.encryptedSelf) {
354
- try {
355
- const json = yield this.crypto.entities.tryDecryptJson(keys, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(svc.encryptedSelf)), true);
356
- if (json) {
357
- Object.assign(svc, json);
358
- }
359
- else {
360
- console.log('Cannot decrypt service: no valid key could produce valid json', svc.id);
361
- }
362
- }
363
- catch (e) {
364
- console.log('Cannot decrypt service', svc.id, e);
365
- }
366
- }
367
- else {
368
- svc.content = _.fromPairs(yield Promise.all(_.toPairs(svc.content).map((p) => __awaiter(this, void 0, void 0, function* () {
369
- if (p[1].compoundValue) {
370
- p[1].compoundValue = yield this.decryptServices(hcpartyId, p[1].compoundValue, keys);
371
- }
372
- return p;
373
- }))));
374
- }
375
- return svc;
349
+ return new models_1.Contact(yield (0, utils_1.decryptObject)(svc, (encrypted) => __awaiter(this, void 0, void 0, function* () {
350
+ var _a;
351
+ return (_a = (yield this.crypto.entities.tryDecryptJson(keys, encrypted, false))) !== null && _a !== void 0 ? _a : {};
352
+ })));
376
353
  })));
377
354
  }
378
355
  contactOfService(ctcs, svcId) {
@@ -773,13 +750,18 @@ class IccContactXApi extends icc_api_1.IccContactApi {
773
750
  shareWithMany(contact, delegates) {
774
751
  return __awaiter(this, void 0, void 0, function* () {
775
752
  const self = yield this.dataOwnerApi.getCurrentDataOwnerId();
776
- return yield this.modifyAs(self, yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(contact, true, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
753
+ const extended = yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(contact, true, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
777
754
  delegateId,
778
755
  {
779
756
  shareEncryptionKey: options.shareEncryptionKey,
780
757
  shareOwningEntityIds: options.sharePatientId,
781
758
  },
782
- ]))));
759
+ ])));
760
+ if (!!extended) {
761
+ return yield this.modifyAs(self, extended);
762
+ }
763
+ else
764
+ return contact;
783
765
  });
784
766
  }
785
767
  getDataOwnersWithAccessTo(entity) {