@icure/api 7.1.34 → 7.1.35

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 (148) hide show
  1. package/icc-api/api/IccAuthApi.d.ts +1 -0
  2. package/icc-api/api/IccAuthApi.js +1 -0
  3. package/icc-api/api/IccAuthApi.js.map +1 -1
  4. package/icc-x-api/index.d.ts +22 -29
  5. package/icc-x-api/index.js +60 -38
  6. package/icc-x-api/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/test/icc-api/api/IccDocumentApi.d.ts +1 -0
  9. package/test/icc-api/api/IccDocumentApi.js +200 -0
  10. package/test/icc-api/api/IccDocumentApi.js.map +1 -0
  11. package/test/icc-api/api/IccGroupApi.d.ts +1 -0
  12. package/test/icc-api/api/IccGroupApi.js +50 -0
  13. package/test/icc-api/api/IccGroupApi.js.map +1 -0
  14. package/test/icc-api/api/IccRoleApi.d.ts +1 -0
  15. package/test/icc-api/api/IccRoleApi.js +34 -0
  16. package/test/icc-api/api/IccRoleApi.js.map +1 -0
  17. package/test/icc-api/api/IccUserApi.d.ts +1 -0
  18. package/test/icc-api/api/IccUserApi.js +80 -0
  19. package/test/icc-api/api/IccUserApi.js.map +1 -0
  20. package/test/icc-api/e2e/IccCalendarItemApi.d.ts +1 -0
  21. package/test/icc-api/e2e/IccCalendarItemApi.js +45 -0
  22. package/test/icc-api/e2e/IccCalendarItemApi.js.map +1 -0
  23. package/test/icc-api/model/modelHelpersTest.d.ts +1 -0
  24. package/test/icc-api/model/modelHelpersTest.js +45 -0
  25. package/test/icc-api/model/modelHelpersTest.js.map +1 -0
  26. package/test/icc-x-api/auth/group-switch-test.d.ts +1 -0
  27. package/test/icc-x-api/auth/group-switch-test.js +81 -0
  28. package/test/icc-x-api/auth/group-switch-test.js.map +1 -0
  29. package/test/icc-x-api/auth/jwt-concurrency-test.d.ts +2 -0
  30. package/test/icc-x-api/auth/jwt-concurrency-test.js +113 -0
  31. package/test/icc-x-api/auth/jwt-concurrency-test.js.map +1 -0
  32. package/test/icc-x-api/auth/smart-auth-provider-test.d.ts +1 -0
  33. package/test/icc-x-api/auth/smart-auth-provider-test.js +222 -0
  34. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -0
  35. package/test/icc-x-api/crypto/KeyManager-test.d.ts +1 -0
  36. package/test/icc-x-api/crypto/KeyManager-test.js +225 -0
  37. package/test/icc-x-api/crypto/KeyManager-test.js.map +1 -0
  38. package/test/icc-x-api/crypto/concurrency.d.ts +1 -0
  39. package/test/icc-x-api/crypto/concurrency.js +35 -0
  40. package/test/icc-x-api/crypto/concurrency.js.map +1 -0
  41. package/test/icc-x-api/crypto/crypto-utils.d.ts +1 -0
  42. package/test/icc-x-api/crypto/crypto-utils.js +80 -0
  43. package/test/icc-x-api/crypto/crypto-utils.js.map +1 -0
  44. package/test/icc-x-api/crypto/cryptoTest.d.ts +2 -0
  45. package/test/icc-x-api/crypto/cryptoTest.js +275 -0
  46. package/test/icc-x-api/crypto/cryptoTest.js.map +1 -0
  47. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.d.ts +1 -0
  48. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js +132 -0
  49. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js.map +1 -0
  50. package/test/icc-x-api/crypto/full-crypto-test.d.ts +1 -0
  51. package/test/icc-x-api/crypto/full-crypto-test.js +458 -0
  52. package/test/icc-x-api/crypto/full-crypto-test.js.map +1 -0
  53. package/test/icc-x-api/crypto/shamir.d.ts +2 -0
  54. package/test/icc-x-api/crypto/shamir.js +156 -0
  55. package/test/icc-x-api/crypto/shamir.js.map +1 -0
  56. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.d.ts +1 -0
  57. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js +75 -0
  58. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +1 -0
  59. package/test/icc-x-api/data-compatibility-test-7to6.d.ts +1 -0
  60. package/test/icc-x-api/data-compatibility-test-7to6.js +343 -0
  61. package/test/icc-x-api/data-compatibility-test-7to6.js.map +1 -0
  62. package/test/icc-x-api/entity-with-attachments-api-test.d.ts +1 -0
  63. package/test/icc-x-api/entity-with-attachments-api-test.js +142 -0
  64. package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -0
  65. package/test/icc-x-api/filters/filters.d.ts +1 -0
  66. package/test/icc-x-api/filters/filters.js +49 -0
  67. package/test/icc-x-api/filters/filters.js.map +1 -0
  68. package/test/icc-x-api/icc-accesslog-x-api.d.ts +1 -0
  69. package/test/icc-x-api/icc-accesslog-x-api.js +121 -0
  70. package/test/icc-x-api/icc-accesslog-x-api.js.map +1 -0
  71. package/test/icc-x-api/icc-auth-api.d.ts +1 -0
  72. package/test/icc-x-api/icc-auth-api.js +46 -0
  73. package/test/icc-x-api/icc-auth-api.js.map +1 -0
  74. package/test/icc-x-api/icc-calendar-item-x-api.d.ts +1 -0
  75. package/test/icc-x-api/icc-calendar-item-x-api.js +146 -0
  76. package/test/icc-x-api/icc-calendar-item-x-api.js.map +1 -0
  77. package/test/icc-x-api/icc-contact-x-api.d.ts +1 -0
  78. package/test/icc-x-api/icc-contact-x-api.js +311 -0
  79. package/test/icc-x-api/icc-contact-x-api.js.map +1 -0
  80. package/test/icc-x-api/icc-form-x-api.d.ts +1 -0
  81. package/test/icc-x-api/icc-form-x-api.js +331 -0
  82. package/test/icc-x-api/icc-form-x-api.js.map +1 -0
  83. package/test/icc-x-api/icc-helement-x-api-test.d.ts +1 -0
  84. package/test/icc-x-api/icc-helement-x-api-test.js +158 -0
  85. package/test/icc-x-api/icc-helement-x-api-test.js.map +1 -0
  86. package/test/icc-x-api/icc-invoice-x-api.d.ts +1 -0
  87. package/test/icc-x-api/icc-invoice-x-api.js +115 -0
  88. package/test/icc-x-api/icc-invoice-x-api.js.map +1 -0
  89. package/test/icc-x-api/icc-maintenance-task-x-api-test.d.ts +1 -0
  90. package/test/icc-x-api/icc-maintenance-task-x-api-test.js +230 -0
  91. package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +1 -0
  92. package/test/icc-x-api/icc-patient-x-api-test.d.ts +1 -0
  93. package/test/icc-x-api/icc-patient-x-api-test.js +169 -0
  94. package/test/icc-x-api/icc-patient-x-api-test.js.map +1 -0
  95. package/test/icc-x-api/icc-time-table-x-api.d.ts +1 -0
  96. package/test/icc-x-api/icc-time-table-x-api.js +110 -0
  97. package/test/icc-x-api/icc-time-table-x-api.js.map +1 -0
  98. package/test/icc-x-api/icc-user-x-api-test.d.ts +1 -0
  99. package/test/icc-x-api/icc-user-x-api-test.js +108 -0
  100. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -0
  101. package/test/icc-x-api/icureapi-group-test.d.ts +1 -0
  102. package/test/icc-x-api/icureapi-group-test.js +130 -0
  103. package/test/icc-x-api/icureapi-group-test.js.map +1 -0
  104. package/test/icc-x-api/patient-user.d.ts +2 -0
  105. package/test/icc-x-api/patient-user.js +117 -0
  106. package/test/icc-x-api/patient-user.js.map +1 -0
  107. package/test/icc-x-api/storage/storage.d.ts +1 -0
  108. package/test/icc-x-api/storage/storage.js +50 -0
  109. package/test/icc-x-api/storage/storage.js.map +1 -0
  110. package/test/icc-x-api/subscription-apis.d.ts +2 -0
  111. package/test/icc-x-api/subscription-apis.js +498 -0
  112. package/test/icc-x-api/subscription-apis.js.map +1 -0
  113. package/test/icc-x-api/test-api-no-parent.d.ts +1 -0
  114. package/test/icc-x-api/test-api-no-parent.js +79 -0
  115. package/test/icc-x-api/test-api-no-parent.js.map +1 -0
  116. package/test/icc-x-api/test-legacy-data-support.d.ts +1 -0
  117. package/test/icc-x-api/test-legacy-data-support.js +231 -0
  118. package/test/icc-x-api/test-legacy-data-support.js.map +1 -0
  119. package/test/icc-x-api/utils/crypto-utils-test.d.ts +1 -0
  120. package/test/icc-x-api/utils/crypto-utils-test.js +586 -0
  121. package/test/icc-x-api/utils/crypto-utils-test.js.map +1 -0
  122. package/test/icc-x-api/utils/graph-test.d.ts +1 -0
  123. package/test/icc-x-api/utils/graph-test.js +54 -0
  124. package/test/icc-x-api/utils/graph-test.js.map +1 -0
  125. package/test/support/CSM-185.d.ts +1 -0
  126. package/test/support/CSM-185.js +120 -0
  127. package/test/support/CSM-185.js.map +1 -0
  128. package/test/support/CSM-87.d.ts +0 -0
  129. package/test/support/CSM-87.js +21 -0
  130. package/test/support/CSM-87.js.map +1 -0
  131. package/test/support/CSM-93.d.ts +1 -0
  132. package/test/support/CSM-93.js +111 -0
  133. package/test/support/CSM-93.js.map +1 -0
  134. package/test/utils/TestApi.d.ts +3 -0
  135. package/test/utils/TestApi.js +27 -0
  136. package/test/utils/TestApi.js.map +1 -0
  137. package/test/utils/TestCollectionUtils.d.ts +1 -0
  138. package/test/utils/TestCollectionUtils.js +109 -0
  139. package/test/utils/TestCollectionUtils.js.map +1 -0
  140. package/test/utils/TestCryptoStrategies.d.ts +37 -0
  141. package/test/utils/TestCryptoStrategies.js +72 -0
  142. package/test/utils/TestCryptoStrategies.js.map +1 -0
  143. package/test/utils/TestStorage.d.ts +31 -0
  144. package/test/utils/TestStorage.js +88 -0
  145. package/test/utils/TestStorage.js.map +1 -0
  146. package/test/utils/test_utils.d.ts +60 -0
  147. package/test/utils/test_utils.js +313 -0
  148. package/test/utils/test_utils.js.map +1 -0
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ require("isomorphic-fetch");
13
+ const test_utils_1 = require("../utils/test_utils");
14
+ const mocha_1 = require("mocha");
15
+ const icc_x_api_1 = require("../../icc-x-api");
16
+ const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
17
+ const icc_api_1 = require("../../icc-api");
18
+ const Patient_1 = require("../../icc-api/model/Patient");
19
+ const crypto_1 = require("crypto");
20
+ const Invoice_1 = require("../../icc-api/model/Invoice");
21
+ const chai_1 = require("chai");
22
+ var initApi = test_utils_1.TestUtils.initApi;
23
+ const types_1 = require("@icure/test-setup/types");
24
+ (0, test_utils_1.setLocalStorage)(fetch);
25
+ let env;
26
+ describe('icc-calendar-item-x-api Tests', () => {
27
+ (0, mocha_1.before)(function () {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ this.timeout(600000);
30
+ const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
31
+ env = yield initializer.execute((0, types_1.getEnvVariables)());
32
+ });
33
+ });
34
+ function createPatient(patientApiForHcp, hcpUser) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ return patientApiForHcp.createPatientWithUser(hcpUser, yield patientApiForHcp.newInstance(hcpUser, new Patient_1.Patient({
37
+ id: (0, crypto_1.randomUUID)(),
38
+ firstName: 'John',
39
+ lastName: 'Snow',
40
+ note: 'Winter is coming',
41
+ })));
42
+ });
43
+ }
44
+ it('Test', () => __awaiter(void 0, void 0, void 0, function* () {
45
+ // Given
46
+ const username = env.dataOwnerDetails[test_utils_1.hcp1Username].user;
47
+ const password = env.dataOwnerDetails[test_utils_1.hcp1Username].password;
48
+ const authProvider = new AuthenticationProvider_1.BasicAuthenticationProvider(username, password);
49
+ const userApi = new icc_x_api_1.IccUserXApi(env.iCureUrl, {}, authProvider, null, fetch);
50
+ const invoiceApi = new icc_api_1.IccInvoiceApi(env.iCureUrl, {}, authProvider, fetch);
51
+ const currentUser = yield userApi.getCurrentUser();
52
+ }));
53
+ it('Test findBy not usingPost', () => __awaiter(void 0, void 0, void 0, function* () {
54
+ // Given
55
+ const { userApi: userApiForHcp, dataOwnerApi: dataOwnerApiForHcp, patientApi: patientApiForHcp, cryptoApi: cryptoApiForHcp, dataOwnerApi: dateOwnerApiForHcp, entityReferenceApi: entityReferenceApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
56
+ const hcpUser = yield userApiForHcp.getCurrentUser();
57
+ const username = env.dataOwnerDetails[test_utils_1.hcp1Username].user;
58
+ const password = env.dataOwnerDetails[test_utils_1.hcp1Username].password;
59
+ const authProvider = new AuthenticationProvider_1.BasicAuthenticationProvider(username, password);
60
+ const invoiceXApi = new icc_x_api_1.IccInvoiceXApi(env.iCureUrl, {}, cryptoApiForHcp, entityReferenceApiForHcp, dateOwnerApiForHcp, authProvider, fetch);
61
+ const patient = (yield createPatient(patientApiForHcp, hcpUser));
62
+ const invoice = new Invoice_1.Invoice({
63
+ id: (0, crypto_1.randomUUID)(),
64
+ created: new Date().getTime(),
65
+ modified: new Date().getTime(),
66
+ date: +new Date(),
67
+ responsible: hcpUser.healthcarePartyId,
68
+ author: hcpUser.id,
69
+ codes: [],
70
+ tags: [],
71
+ user: hcpUser.id,
72
+ patient: patient.id,
73
+ });
74
+ const invoiceToCreate = yield invoiceXApi.newInstance(hcpUser, patient, invoice);
75
+ const createdInvoice = yield invoiceXApi.createInvoice(invoiceToCreate);
76
+ const foundItems = yield invoiceXApi.findBy(hcpUser.healthcarePartyId, patient, false);
77
+ const foundItemsUsingPost = yield invoiceXApi.findBy(hcpUser.healthcarePartyId, patient, true);
78
+ (0, chai_1.assert)(foundItems.length == 1, 'Found items should be 1');
79
+ (0, chai_1.assert)(foundItems[0].id == createdInvoice.id, 'Found item should be the created invoice');
80
+ (0, chai_1.assert)(foundItemsUsingPost.length == 1, 'Found items using post should be 1');
81
+ (0, chai_1.assert)(foundItemsUsingPost[0].id == createdInvoice.id, 'Found item using post should be the created invoice');
82
+ }));
83
+ it('Share with should work as expected', () => __awaiter(void 0, void 0, void 0, function* () {
84
+ const api1 = yield initApi(env, test_utils_1.hcp1Username);
85
+ const user1 = yield api1.userApi.getCurrentUser();
86
+ const api2 = yield initApi(env, test_utils_1.hcp2Username);
87
+ const user2 = yield api2.userApi.getCurrentUser();
88
+ const samplePatient = yield api1.patientApi.createPatientWithUser(user1, yield api1.patientApi.newInstance(user1, { firstName: 'Gigio', lastName: 'Bagigio' }));
89
+ const entity = yield api1.invoiceApi.createInvoice(yield api1.invoiceApi.newInstance(user1, samplePatient));
90
+ yield api2.invoiceApi
91
+ .getInvoice(entity.id)
92
+ .then(() => {
93
+ throw new Error('Should not be able to get the entity');
94
+ })
95
+ .catch(() => {
96
+ /* expected */
97
+ });
98
+ yield api1.invoiceApi.shareWith(user2.healthcarePartyId, entity);
99
+ const retrieved = yield api2.invoiceApi.getInvoice(entity.id);
100
+ (0, chai_1.expect)((yield api2.invoiceApi.decryptPatientIdOf(retrieved))[0]).to.equal(samplePatient.id);
101
+ }));
102
+ it('newInstance should honor non-default values unless they are undefined', () => __awaiter(void 0, void 0, void 0, function* () {
103
+ const api = yield initApi(env, test_utils_1.hcp1Username);
104
+ const user = yield api.userApi.getCurrentUser();
105
+ const patient = yield api.patientApi.createPatientWithUser(user, yield api.patientApi.newInstance(user, { firstName: 'Gigio', lastName: 'Bagigio' }));
106
+ const invoiceUndefinedId = yield api.invoiceApi.newInstance(user, patient, { id: undefined });
107
+ const customId = 'customId';
108
+ const invoiceCustomId = yield api.invoiceApi.newInstance(user, patient, { id: customId });
109
+ const invoiceWithUndefinedInit = yield api.invoiceApi.newInstance(user, patient, undefined);
110
+ (0, chai_1.expect)(invoiceUndefinedId.id).to.not.be.undefined;
111
+ (0, chai_1.expect)(invoiceWithUndefinedInit.id).to.not.be.undefined;
112
+ (0, chai_1.expect)(invoiceCustomId.id).to.equal(customId);
113
+ }));
114
+ });
115
+ //# sourceMappingURL=icc-invoice-x-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icc-inv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AAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\nimport { getEnvironmentInitializer, hcp1Username, hcp2Username, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { before } from 'mocha'\nimport { IccInvoiceXApi, IccPatientXApi, IccUserXApi } from '../../icc-x-api'\nimport { BasicAuthenticationProvider } from '../../icc-x-api/auth/AuthenticationProvider'\nimport { IccInvoiceApi } from '../../icc-api'\nimport { Patient } from '../../icc-api/model/Patient'\nimport { User } from '../../icc-api/model/User'\nimport { randomUUID } from 'crypto'\nimport { Invoice } from '../../icc-api/model/Invoice'\nimport { assert, expect } from 'chai'\nimport initApi = TestUtils.initApi\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nsetLocalStorage(fetch)\nlet env: TestVars\n\ndescribe('icc-calendar-item-x-api Tests', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n async function createPatient(patientApiForHcp: IccPatientXApi, hcpUser: User) {\n return patientApiForHcp.createPatientWithUser(\n hcpUser,\n await patientApiForHcp.newInstance(\n hcpUser,\n new Patient({\n id: randomUUID(),\n firstName: 'John',\n lastName: 'Snow',\n note: 'Winter is coming',\n })\n )\n )\n }\n\n it('Test', async () => {\n // Given\n const username = env.dataOwnerDetails[hcp1Username].user\n const password = env.dataOwnerDetails[hcp1Username].password\n\n const authProvider = new BasicAuthenticationProvider(username, password)\n\n const userApi = new IccUserXApi(env.iCureUrl, {}, authProvider, null as any, fetch)\n const invoiceApi = new IccInvoiceApi(env.iCureUrl, {}, authProvider, fetch)\n\n const currentUser = await userApi.getCurrentUser()\n })\n\n it('Test findBy not usingPost', async () => {\n // Given\n const {\n userApi: userApiForHcp,\n dataOwnerApi: dataOwnerApiForHcp,\n patientApi: patientApiForHcp,\n cryptoApi: cryptoApiForHcp,\n dataOwnerApi: dateOwnerApiForHcp,\n entityReferenceApi: entityReferenceApiForHcp,\n } = await initApi(env!, hcp1Username)\n const hcpUser = await userApiForHcp.getCurrentUser()\n\n const username = env.dataOwnerDetails[hcp1Username].user\n const password = env.dataOwnerDetails[hcp1Username].password\n\n const authProvider = new BasicAuthenticationProvider(username, password)\n const invoiceXApi = new IccInvoiceXApi(env.iCureUrl, {}, cryptoApiForHcp, entityReferenceApiForHcp, dateOwnerApiForHcp, authProvider, fetch)\n const patient = (await createPatient(patientApiForHcp, hcpUser)) as Patient\n\n const invoice = new Invoice({\n id: randomUUID(),\n created: new Date().getTime(),\n modified: new Date().getTime(),\n date: +new Date(),\n responsible: hcpUser.healthcarePartyId!,\n author: hcpUser.id,\n codes: [],\n tags: [],\n user: hcpUser.id,\n patient: patient.id,\n })\n\n const invoiceToCreate = await invoiceXApi.newInstance(hcpUser, patient, invoice)\n const createdInvoice = await invoiceXApi.createInvoice(invoiceToCreate)\n\n const foundItems = await invoiceXApi.findBy(hcpUser.healthcarePartyId!, patient, false)\n const foundItemsUsingPost = await invoiceXApi.findBy(hcpUser.healthcarePartyId!, patient, true)\n\n assert(foundItems.length == 1, 'Found items should be 1')\n assert(foundItems[0].id == createdInvoice.id, 'Found item should be the created invoice')\n\n assert(foundItemsUsingPost.length == 1, 'Found items using post should be 1')\n assert(foundItemsUsingPost[0].id == createdInvoice.id, 'Found item using post should be the created invoice')\n })\n\n it('Share with should work as expected', async () => {\n const api1 = await initApi(env!, hcp1Username)\n const user1 = await api1.userApi.getCurrentUser()\n const api2 = await initApi(env!, hcp2Username)\n const user2 = await api2.userApi.getCurrentUser()\n const samplePatient = await api1.patientApi.createPatientWithUser(\n user1,\n await api1.patientApi.newInstance(user1, { firstName: 'Gigio', lastName: 'Bagigio' })\n )\n const entity = await api1.invoiceApi.createInvoice(await api1.invoiceApi.newInstance(user1, samplePatient))\n await api2.invoiceApi\n .getInvoice(entity.id!)\n .then(() => {\n throw new Error('Should not be able to get the entity')\n })\n .catch(() => {\n /* expected */\n })\n await api1.invoiceApi.shareWith(user2.healthcarePartyId!, entity)\n const retrieved = await api2.invoiceApi.getInvoice(entity.id!)\n expect((await api2.invoiceApi.decryptPatientIdOf(retrieved))[0]).to.equal(samplePatient.id)\n })\n\n it('newInstance should honor non-default values unless they are undefined', async () => {\n const api = await initApi(env!, hcp1Username)\n const user = await api.userApi.getCurrentUser()\n const patient = await api.patientApi.createPatientWithUser(\n user,\n await api.patientApi.newInstance(user, { firstName: 'Gigio', lastName: 'Bagigio' })\n )\n const invoiceUndefinedId = await api.invoiceApi.newInstance(user, patient, { id: undefined })\n const customId = 'customId'\n const invoiceCustomId = await api.invoiceApi.newInstance(user, patient, { id: customId })\n const invoiceWithUndefinedInit = await api.invoiceApi.newInstance(user, patient, undefined)\n expect(invoiceUndefinedId.id).to.not.be.undefined\n expect(invoiceWithUndefinedInit.id).to.not.be.undefined\n expect(invoiceCustomId.id).to.equal(customId)\n })\n})\n"]}
@@ -0,0 +1 @@
1
+ import 'isomorphic-fetch';
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const mocha_1 = require("mocha");
13
+ require("isomorphic-fetch");
14
+ const chai_1 = require("chai");
15
+ const crypto_1 = require("crypto");
16
+ const test_utils_1 = require("../utils/test_utils");
17
+ const MaintenanceTask_1 = require("../../icc-api/model/MaintenanceTask");
18
+ const PropertyStub_1 = require("../../icc-api/model/PropertyStub");
19
+ const PropertyTypeStub_1 = require("../../icc-api/model/PropertyTypeStub");
20
+ const TypedValueObject_1 = require("../../icc-api/model/TypedValueObject");
21
+ const Identifier_1 = require("../../icc-api/model/Identifier");
22
+ const FilterChainMaintenanceTask_1 = require("../../icc-api/model/FilterChainMaintenanceTask");
23
+ const MaintenanceTaskByIdsFilter_1 = require("../../icc-x-api/filters/MaintenanceTaskByIdsFilter");
24
+ const MaintenanceTaskByHcPartyAndTypeFilter_1 = require("../../icc-x-api/filters/MaintenanceTaskByHcPartyAndTypeFilter");
25
+ var initApi = test_utils_1.TestUtils.initApi;
26
+ const MaintenanceTaskAfterDateFilter_1 = require("../../icc-x-api/filters/MaintenanceTaskAfterDateFilter");
27
+ const types_1 = require("@icure/test-setup/types");
28
+ (0, test_utils_1.setLocalStorage)(fetch);
29
+ let env;
30
+ function maintenanceTaskToCreate(mTaskApiForHcp, hcpUser, delegatedTo) {
31
+ return mTaskApiForHcp.newInstance(hcpUser, new MaintenanceTask_1.MaintenanceTask({
32
+ id: (0, crypto_1.randomUUID)(),
33
+ taskType: (0, crypto_1.randomUUID)(),
34
+ status: MaintenanceTask_1.MaintenanceTask.StatusEnum.Pending,
35
+ properties: [
36
+ new PropertyStub_1.PropertyStub({
37
+ id: 'dataOwnerConcernedId',
38
+ type: new PropertyTypeStub_1.PropertyTypeStub({ type: PropertyTypeStub_1.PropertyTypeStub.TypeEnum.STRING }),
39
+ typedValue: new TypedValueObject_1.TypedValueObject({
40
+ type: TypedValueObject_1.TypedValueObject.TypeEnum.STRING,
41
+ stringValue: delegatedTo.id,
42
+ }),
43
+ }),
44
+ new PropertyStub_1.PropertyStub({
45
+ id: 'dataOwnerConcernedPubKey',
46
+ type: new PropertyTypeStub_1.PropertyTypeStub({ type: PropertyTypeStub_1.PropertyTypeStub.TypeEnum.STRING }),
47
+ typedValue: new TypedValueObject_1.TypedValueObject({
48
+ type: TypedValueObject_1.TypedValueObject.TypeEnum.STRING,
49
+ stringValue: delegatedTo.publicKey,
50
+ }),
51
+ }),
52
+ ],
53
+ }), { additionalDelegates: { [delegatedTo.id]: 'WRITE' } });
54
+ }
55
+ let apiForHcp1;
56
+ let hcp1User;
57
+ let hcp1;
58
+ let apiForHcp2;
59
+ let hcp2User;
60
+ let hcp2;
61
+ describe('icc-x-maintenance-task-api Tests', () => {
62
+ (0, mocha_1.before)(function () {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ this.timeout(600000);
65
+ const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
66
+ env = yield initializer.execute((0, types_1.getEnvVariables)());
67
+ apiForHcp1 = yield initApi(env, test_utils_1.hcp1Username);
68
+ hcp1User = yield apiForHcp1.userApi.getCurrentUser();
69
+ hcp1 = yield apiForHcp1.healthcarePartyApi.getCurrentHealthcareParty();
70
+ apiForHcp2 = yield initApi(env, test_utils_1.hcp2Username);
71
+ hcp2User = yield apiForHcp2.userApi.getCurrentUser();
72
+ hcp2 = yield apiForHcp2.healthcarePartyApi.getCurrentHealthcareParty();
73
+ });
74
+ });
75
+ it('CreateMaintenanceTaskWithUser Success for HCP', () => __awaiter(void 0, void 0, void 0, function* () {
76
+ var _a, _b;
77
+ // Given
78
+ const taskToCreate = yield maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp2);
79
+ // When
80
+ const createdTask = yield apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, taskToCreate);
81
+ // Then
82
+ (0, chai_1.assert)(createdTask != null);
83
+ (0, chai_1.assert)(createdTask.id == taskToCreate.id);
84
+ (0, chai_1.assert)(createdTask.delegations[hcp1User.healthcarePartyId] != undefined);
85
+ (0, chai_1.assert)(createdTask.delegations[hcp2User.healthcarePartyId] != undefined);
86
+ (0, chai_1.assert)(createdTask.encryptionKeys[hcp1User.healthcarePartyId] != undefined);
87
+ (0, chai_1.assert)(createdTask.encryptionKeys[hcp2User.healthcarePartyId] != undefined);
88
+ const foundTask = yield apiForHcp2.maintenanceTaskApi.getMaintenanceTaskWithUser(hcp2User, createdTask.id);
89
+ (0, chai_1.assert)(foundTask.id == createdTask.id);
90
+ (0, chai_1.assert)(((_a = foundTask.properties) === null || _a === void 0 ? void 0 : _a.find((prop) => { var _a; return ((_a = prop.typedValue) === null || _a === void 0 ? void 0 : _a.stringValue) == hcp2.id; })) != undefined);
91
+ (0, chai_1.assert)(((_b = foundTask.properties) === null || _b === void 0 ? void 0 : _b.find((prop) => { var _a; return ((_a = prop.typedValue) === null || _a === void 0 ? void 0 : _a.stringValue) == hcp2.publicKey; })) != undefined);
92
+ })).timeout(30000);
93
+ it('ModifyMaintenanceTaskWithUser Success for HCP', () => __awaiter(void 0, void 0, void 0, function* () {
94
+ var _c, _d, _e;
95
+ // Given
96
+ const createdTask = (yield apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, yield maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)));
97
+ const identifierToAdd = new Identifier_1.Identifier({ id: 'SYSTEM-TEST|VALUE-TEST', system: 'SYSTEM-TEST', value: 'VALUE-TEST' });
98
+ // When
99
+ const updatedTask = yield apiForHcp1.maintenanceTaskApi.modifyMaintenanceTaskWithUser(hcp1User, new MaintenanceTask_1.MaintenanceTask(Object.assign(Object.assign({}, createdTask), { identifier: [identifierToAdd], status: MaintenanceTask_1.MaintenanceTask.StatusEnum.Ongoing })));
100
+ // Then
101
+ (0, chai_1.assert)(updatedTask.id == createdTask.id);
102
+ (0, chai_1.assert)(((_c = updatedTask.identifier) === null || _c === void 0 ? void 0 : _c[0].system) == identifierToAdd.system);
103
+ (0, chai_1.assert)(((_d = updatedTask.identifier) === null || _d === void 0 ? void 0 : _d[0].value) == identifierToAdd.value);
104
+ (0, chai_1.assert)(((_e = updatedTask.identifier) === null || _e === void 0 ? void 0 : _e[0].id) == identifierToAdd.id);
105
+ (0, chai_1.assert)(updatedTask.status == MaintenanceTask_1.MaintenanceTask.StatusEnum.Ongoing);
106
+ }));
107
+ it('DeleteMaintenanceTaskWithUser Success for delegated HCP', () => __awaiter(void 0, void 0, void 0, function* () {
108
+ // Given
109
+ const createdTask = (yield apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, yield maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)));
110
+ (0, chai_1.assert)(!!createdTask.id);
111
+ // When
112
+ const deletedTask = yield apiForHcp1.maintenanceTaskApi.deleteMaintenanceTaskWithUser(hcp1User, createdTask.id);
113
+ // Then
114
+ (0, chai_1.assert)(!!deletedTask);
115
+ (0, chai_1.assert)(deletedTask.length == 1);
116
+ (0, chai_1.assert)(deletedTask[0].id === createdTask.id);
117
+ }));
118
+ it('DeleteMaintenanceTaskWithUser Success for HCP that which parent has delegation', () => __awaiter(void 0, void 0, void 0, function* () {
119
+ // Given
120
+ const createdTask = (yield apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, yield maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)));
121
+ (0, chai_1.assert)(!!createdTask.id);
122
+ // When
123
+ const deletedTask = yield apiForHcp2.maintenanceTaskApi.deleteMaintenanceTaskWithUser(hcp1User, createdTask.id);
124
+ // Then
125
+ (0, chai_1.assert)(!!deletedTask);
126
+ (0, chai_1.assert)(deletedTask.length == 1);
127
+ (0, chai_1.assert)(deletedTask[0].id === createdTask.id);
128
+ }));
129
+ it('DeleteMaintenanceTaskWithUser Fails for non-delegated HCP', () => __awaiter(void 0, void 0, void 0, function* () {
130
+ const apiForHcp3 = yield initApi(env, test_utils_1.hcp2Username);
131
+ const hcp3User = yield apiForHcp3.userApi.getCurrentUser();
132
+ // Given
133
+ const createdTask = (yield apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, yield maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)));
134
+ (0, chai_1.assert)(!!createdTask.id);
135
+ // When
136
+ apiForHcp3.maintenanceTaskApi.deleteMaintenanceTaskWithUser(hcp3User, createdTask.id).then(() => {
137
+ throw new Error('You should not be here');
138
+ }, (e) => {
139
+ (0, chai_1.assert)(!!e);
140
+ });
141
+ // Then
142
+ const actualTask = yield apiForHcp1.maintenanceTaskApi.getMaintenanceTaskWithUser(hcp1User, createdTask.id);
143
+ (0, chai_1.assert)(!!actualTask);
144
+ (0, chai_1.assert)(!actualTask.deletionDate);
145
+ }));
146
+ it('FilterMaintenanceTaskByWithUser By Ids Success for HCP', () => __awaiter(void 0, void 0, void 0, function* () {
147
+ // Given
148
+ const createdTask = (yield apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, yield maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)));
149
+ // When
150
+ const foundTask = (yield apiForHcp1.maintenanceTaskApi.filterMaintenanceTasksByWithUser(hcp1User, undefined, undefined, new FilterChainMaintenanceTask_1.FilterChainMaintenanceTask({
151
+ filter: new MaintenanceTaskByIdsFilter_1.MaintenanceTaskByIdsFilter({
152
+ ids: [createdTask.id],
153
+ }),
154
+ }))).rows[0];
155
+ // Then
156
+ (0, chai_1.assert)(foundTask.id == createdTask.id);
157
+ }));
158
+ it('FilterMaintenanceTaskByWithUser By Type Success for HCP', () => __awaiter(void 0, void 0, void 0, function* () {
159
+ // Given
160
+ const createdTask = (yield apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, yield maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)));
161
+ // When
162
+ const foundTask = (yield apiForHcp1.maintenanceTaskApi.filterMaintenanceTasksByWithUser(hcp1User, undefined, undefined, new FilterChainMaintenanceTask_1.FilterChainMaintenanceTask({
163
+ filter: new MaintenanceTaskByHcPartyAndTypeFilter_1.MaintenanceTaskByHcPartyAndTypeFilter({
164
+ healthcarePartyId: hcp1.id,
165
+ type: createdTask.taskType,
166
+ }),
167
+ }))).rows[0];
168
+ // Then
169
+ (0, chai_1.assert)(foundTask.id == createdTask.id);
170
+ }));
171
+ it('FilterMaintenanceTaskByWithUser After Date Success for HCP', () => __awaiter(void 0, void 0, void 0, function* () {
172
+ // Given
173
+ const startTimestamp = new Date().getTime() + 1000;
174
+ const taskToCreate = Object.assign(Object.assign({}, (yield maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1))), { created: startTimestamp });
175
+ const createdTask = (yield apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, taskToCreate));
176
+ // When
177
+ const foundTask = (yield apiForHcp1.maintenanceTaskApi.filterMaintenanceTasksByWithUser(hcp1User, undefined, undefined, new FilterChainMaintenanceTask_1.FilterChainMaintenanceTask({
178
+ filter: new MaintenanceTaskAfterDateFilter_1.MaintenanceTaskAfterDateFilter({
179
+ healthcarePartyId: hcp1.id,
180
+ date: startTimestamp - 1000,
181
+ }),
182
+ }))).rows[0];
183
+ // Then
184
+ (0, chai_1.assert)(foundTask.id == createdTask.id);
185
+ }));
186
+ it('Share with should work as expected', () => __awaiter(void 0, void 0, void 0, function* () {
187
+ const api1 = yield initApi(env, test_utils_1.hcp1Username);
188
+ const user1 = yield api1.userApi.getCurrentUser();
189
+ const api2 = yield initApi(env, test_utils_1.hcp2Username);
190
+ const user2 = yield api2.userApi.getCurrentUser();
191
+ const samplePatient = yield api1.patientApi.createPatientWithUser(user1, yield api1.patientApi.newInstance(user1, { firstName: 'Gigio', lastName: 'Bagigio' }));
192
+ const encryptedField = 'Something encrypted';
193
+ const entity = (yield api1.maintenanceTaskApi.createMaintenanceTaskWithUser(user1, yield api1.maintenanceTaskApi.newInstance(user1, {
194
+ properties: [
195
+ new PropertyStub_1.PropertyStub({
196
+ id: 'someProp',
197
+ type: new PropertyTypeStub_1.PropertyTypeStub({ type: PropertyTypeStub_1.PropertyTypeStub.TypeEnum.STRING }),
198
+ typedValue: new TypedValueObject_1.TypedValueObject({
199
+ type: TypedValueObject_1.TypedValueObject.TypeEnum.STRING,
200
+ stringValue: encryptedField,
201
+ }),
202
+ }),
203
+ ],
204
+ })));
205
+ (0, chai_1.expect)(entity.properties[0].typedValue.stringValue).to.be.equal(encryptedField);
206
+ yield api2.maintenanceTaskApi
207
+ .getMaintenanceTaskWithUser(user2, entity.id)
208
+ .then(() => {
209
+ throw new Error('Should not be able to get the entity');
210
+ })
211
+ .catch(() => {
212
+ /* expected */
213
+ });
214
+ yield api1.maintenanceTaskApi.shareWith(user2.healthcarePartyId, entity);
215
+ const retrieved = yield api2.maintenanceTaskApi.getMaintenanceTaskWithUser(user2, entity.id);
216
+ (0, chai_1.expect)(retrieved.properties[0].typedValue.stringValue).to.be.equal(encryptedField);
217
+ }));
218
+ it('newInstance should honor non-default values unless they are undefined', () => __awaiter(void 0, void 0, void 0, function* () {
219
+ const api = yield initApi(env, test_utils_1.hcp1Username);
220
+ const user = yield api.userApi.getCurrentUser();
221
+ const maintenanceTaskUndefinedId = yield api.maintenanceTaskApi.newInstance(user, { id: undefined });
222
+ const customId = 'customId';
223
+ const maintenanceTaskCustomId = yield api.maintenanceTaskApi.newInstance(user, { id: customId });
224
+ const maintenanceTaskWithUndefinedInit = yield api.maintenanceTaskApi.newInstance(user, undefined);
225
+ (0, chai_1.expect)(maintenanceTaskUndefinedId.id).to.not.be.undefined;
226
+ (0, chai_1.expect)(maintenanceTaskWithUndefinedInit.id).to.not.be.undefined;
227
+ (0, chai_1.expect)(maintenanceTaskCustomId.id).to.equal(customId);
228
+ }));
229
+ });
230
+ //# sourceMappingURL=icc-maintenance-task-x-api-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icc-maintenance-task-x-api-test.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-maintenance-task-x-api-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAA8B;AAE9B,4BAAyB;AAGzB,+BAAqC;AACrC,mCAAmC;AACnC,oDAAuH;AAGvH,yEAAqE;AACrE,mEAA+D;AAC/D,2EAAuE;AACvE,2EAAuE;AAEvE,+DAA2D;AAC3D,+FAA2F;AAC3F,mGAA+F;AAC/F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CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IACtF,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,uEAAuE,EAAE,GAAS,EAAE;QACrF,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAI,EAAE,yBAAY,CAAC,CAAA;QAC7C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,CAAA;QAC/C,MAAM,0BAA0B,GAAG,MAAM,GAAG,CAAC,kBAAkB,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAA;QACpG,MAAM,QAAQ,GAAG,UAAU,CAAA;QAC3B,MAAM,uBAAuB,GAAG,MAAM,GAAG,CAAC,kBAAkB,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;QAChG,MAAM,gCAAgC,GAAG,MAAM,GAAG,CAAC,kBAAkB,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QAClG,IAAA,aAAM,EAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAA;QACzD,IAAA,aAAM,EAAC,gCAAgC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAA;QAC/D,IAAA,aAAM,EAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACvD,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { before } from 'mocha'\n\nimport 'isomorphic-fetch'\n\nimport { Apis } from '../../icc-x-api'\nimport { assert, expect } from 'chai'\nimport { randomUUID } from 'crypto'\nimport { getEnvironmentInitializer, hcp1Username, hcp2Username, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { User } from '../../icc-api/model/User'\nimport { IccMaintenanceTaskXApi } from '../../icc-x-api/icc-maintenance-task-x-api'\nimport { MaintenanceTask } from '../../icc-api/model/MaintenanceTask'\nimport { PropertyStub } from '../../icc-api/model/PropertyStub'\nimport { PropertyTypeStub } from '../../icc-api/model/PropertyTypeStub'\nimport { TypedValueObject } from '../../icc-api/model/TypedValueObject'\nimport { HealthcareParty } from '../../icc-api/model/HealthcareParty'\nimport { Identifier } from '../../icc-api/model/Identifier'\nimport { FilterChainMaintenanceTask } from '../../icc-api/model/FilterChainMaintenanceTask'\nimport { MaintenanceTaskByIdsFilter } from '../../icc-x-api/filters/MaintenanceTaskByIdsFilter'\nimport { MaintenanceTaskByHcPartyAndTypeFilter } from '../../icc-x-api/filters/MaintenanceTaskByHcPartyAndTypeFilter'\nimport { DocIdentifier } from '../../icc-api/model/DocIdentifier'\nimport initApi = TestUtils.initApi\nimport { MaintenanceTaskAfterDateFilter } from '../../icc-x-api/filters/MaintenanceTaskAfterDateFilter'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nsetLocalStorage(fetch)\nlet env: TestVars\n\nfunction maintenanceTaskToCreate(mTaskApiForHcp: IccMaintenanceTaskXApi, hcpUser: User, delegatedTo: HealthcareParty) {\n return mTaskApiForHcp.newInstance(\n hcpUser,\n new MaintenanceTask({\n id: randomUUID(),\n taskType: randomUUID(),\n status: MaintenanceTask.StatusEnum.Pending,\n properties: [\n new PropertyStub({\n id: 'dataOwnerConcernedId',\n type: new PropertyTypeStub({ type: PropertyTypeStub.TypeEnum.STRING }),\n typedValue: new TypedValueObject({\n type: TypedValueObject.TypeEnum.STRING,\n stringValue: delegatedTo.id,\n }),\n }),\n new PropertyStub({\n id: 'dataOwnerConcernedPubKey',\n type: new PropertyTypeStub({ type: PropertyTypeStub.TypeEnum.STRING }),\n typedValue: new TypedValueObject({\n type: TypedValueObject.TypeEnum.STRING,\n stringValue: delegatedTo.publicKey,\n }),\n }),\n ],\n }),\n { additionalDelegates: { [delegatedTo.id!]: 'WRITE' } }\n )\n}\n\nlet apiForHcp1: Apis\nlet hcp1User: User\nlet hcp1: HealthcareParty\n\nlet apiForHcp2: Apis\nlet hcp2User: User\nlet hcp2: HealthcareParty\n\ndescribe('icc-x-maintenance-task-api Tests', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n\n apiForHcp1 = await initApi(env, hcp1Username)\n hcp1User = await apiForHcp1.userApi.getCurrentUser()\n hcp1 = await apiForHcp1.healthcarePartyApi.getCurrentHealthcareParty()\n\n apiForHcp2 = await initApi(env, hcp2Username)\n hcp2User = await apiForHcp2.userApi.getCurrentUser()\n hcp2 = await apiForHcp2.healthcarePartyApi.getCurrentHealthcareParty()\n })\n\n it('CreateMaintenanceTaskWithUser Success for HCP', async () => {\n // Given\n const taskToCreate = await maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp2)\n\n // When\n const createdTask = await apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, taskToCreate)\n\n // Then\n assert(createdTask != null)\n assert(createdTask.id == taskToCreate.id)\n assert(createdTask.delegations![hcp1User.healthcarePartyId!] != undefined)\n assert(createdTask.delegations![hcp2User.healthcarePartyId!] != undefined)\n assert(createdTask.encryptionKeys![hcp1User.healthcarePartyId!] != undefined)\n assert(createdTask.encryptionKeys![hcp2User.healthcarePartyId!] != undefined)\n\n const foundTask: MaintenanceTask = await apiForHcp2.maintenanceTaskApi.getMaintenanceTaskWithUser(hcp2User, createdTask.id!)\n\n assert(foundTask.id == createdTask.id)\n assert(foundTask.properties?.find((prop: PropertyStub) => prop.typedValue?.stringValue == hcp2.id) != undefined)\n assert(foundTask.properties?.find((prop: PropertyStub) => prop.typedValue?.stringValue == hcp2.publicKey) != undefined)\n }).timeout(30000)\n\n it('ModifyMaintenanceTaskWithUser Success for HCP', async () => {\n // Given\n const createdTask: MaintenanceTask = (await apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(\n hcp1User,\n await maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)\n ))!\n const identifierToAdd = new Identifier({ id: 'SYSTEM-TEST|VALUE-TEST', system: 'SYSTEM-TEST', value: 'VALUE-TEST' })\n\n // When\n const updatedTask: MaintenanceTask = await apiForHcp1.maintenanceTaskApi.modifyMaintenanceTaskWithUser(\n hcp1User,\n new MaintenanceTask({ ...createdTask, identifier: [identifierToAdd], status: MaintenanceTask.StatusEnum.Ongoing })\n )\n\n // Then\n assert(updatedTask.id == createdTask.id)\n assert(updatedTask.identifier?.[0].system == identifierToAdd.system)\n assert(updatedTask.identifier?.[0].value == identifierToAdd.value)\n assert(updatedTask.identifier?.[0].id == identifierToAdd.id)\n assert(updatedTask.status == MaintenanceTask.StatusEnum.Ongoing)\n })\n\n it('DeleteMaintenanceTaskWithUser Success for delegated HCP', async () => {\n // Given\n const createdTask: MaintenanceTask = (await apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(\n hcp1User,\n await maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)\n ))!\n assert(!!createdTask.id)\n\n // When\n const deletedTask: DocIdentifier[] = await apiForHcp1.maintenanceTaskApi.deleteMaintenanceTaskWithUser(hcp1User, createdTask.id!)\n\n // Then\n assert(!!deletedTask)\n assert(deletedTask.length == 1)\n assert(deletedTask[0].id === createdTask.id)\n })\n\n it('DeleteMaintenanceTaskWithUser Success for HCP that which parent has delegation', async () => {\n // Given\n const createdTask: MaintenanceTask = (await apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(\n hcp1User,\n await maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)\n ))!\n assert(!!createdTask.id)\n\n // When\n const deletedTask: DocIdentifier[] = await apiForHcp2.maintenanceTaskApi.deleteMaintenanceTaskWithUser(hcp1User, createdTask.id!)\n\n // Then\n assert(!!deletedTask)\n assert(deletedTask.length == 1)\n assert(deletedTask[0].id === createdTask.id)\n })\n\n it('DeleteMaintenanceTaskWithUser Fails for non-delegated HCP', async () => {\n const apiForHcp3 = await initApi(env, hcp2Username)\n const hcp3User = await apiForHcp3.userApi.getCurrentUser()\n\n // Given\n const createdTask: MaintenanceTask = (await apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(\n hcp1User,\n await maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)\n ))!\n assert(!!createdTask.id)\n\n // When\n apiForHcp3.maintenanceTaskApi.deleteMaintenanceTaskWithUser(hcp3User, createdTask.id!).then(\n () => {\n throw new Error('You should not be here')\n },\n (e) => {\n assert(!!e)\n }\n )\n\n // Then\n const actualTask: MaintenanceTask = await apiForHcp1.maintenanceTaskApi.getMaintenanceTaskWithUser(hcp1User, createdTask.id!)\n assert(!!actualTask)\n assert(!actualTask.deletionDate)\n })\n\n it('FilterMaintenanceTaskByWithUser By Ids Success for HCP', async () => {\n // Given\n const createdTask: MaintenanceTask = (await apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(\n hcp1User,\n await maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)\n ))!\n\n // When\n const foundTask = (\n await apiForHcp1.maintenanceTaskApi.filterMaintenanceTasksByWithUser(\n hcp1User,\n undefined,\n undefined,\n new FilterChainMaintenanceTask({\n filter: new MaintenanceTaskByIdsFilter({\n ids: [createdTask.id!],\n }),\n })\n )\n ).rows![0] as MaintenanceTask\n\n // Then\n assert(foundTask.id == createdTask.id)\n })\n\n it('FilterMaintenanceTaskByWithUser By Type Success for HCP', async () => {\n // Given\n const createdTask: MaintenanceTask = (await apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(\n hcp1User,\n await maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)\n ))!\n\n // When\n const foundTask = (\n await apiForHcp1.maintenanceTaskApi.filterMaintenanceTasksByWithUser(\n hcp1User,\n undefined,\n undefined,\n new FilterChainMaintenanceTask({\n filter: new MaintenanceTaskByHcPartyAndTypeFilter({\n healthcarePartyId: hcp1.id!,\n type: createdTask.taskType!,\n }),\n })\n )\n ).rows![0]\n\n // Then\n assert(foundTask.id == createdTask.id)\n })\n\n it('FilterMaintenanceTaskByWithUser After Date Success for HCP', async () => {\n // Given\n const startTimestamp = new Date().getTime() + 1000\n const taskToCreate = { ...(await maintenanceTaskToCreate(apiForHcp1.maintenanceTaskApi, hcp1User, hcp1)), created: startTimestamp }\n\n const createdTask: MaintenanceTask = (await apiForHcp1.maintenanceTaskApi.createMaintenanceTaskWithUser(hcp1User, taskToCreate))!\n\n // When\n const foundTask = (\n await apiForHcp1.maintenanceTaskApi.filterMaintenanceTasksByWithUser(\n hcp1User,\n undefined,\n undefined,\n new FilterChainMaintenanceTask({\n filter: new MaintenanceTaskAfterDateFilter({\n healthcarePartyId: hcp1.id!,\n date: startTimestamp - 1000,\n }),\n })\n )\n ).rows![0]\n\n // Then\n assert(foundTask.id == createdTask.id)\n })\n\n it('Share with should work as expected', async () => {\n const api1 = await initApi(env!, hcp1Username)\n const user1 = await api1.userApi.getCurrentUser()\n const api2 = await initApi(env!, hcp2Username)\n const user2 = await api2.userApi.getCurrentUser()\n const samplePatient = await api1.patientApi.createPatientWithUser(\n user1,\n await api1.patientApi.newInstance(user1, { firstName: 'Gigio', lastName: 'Bagigio' })\n )\n const encryptedField = 'Something encrypted'\n const entity = (await api1.maintenanceTaskApi.createMaintenanceTaskWithUser(\n user1,\n await api1.maintenanceTaskApi.newInstance(user1, {\n properties: [\n new PropertyStub({\n id: 'someProp',\n type: new PropertyTypeStub({ type: PropertyTypeStub.TypeEnum.STRING }),\n typedValue: new TypedValueObject({\n type: TypedValueObject.TypeEnum.STRING,\n stringValue: encryptedField,\n }),\n }),\n ],\n })\n ))!\n expect(entity.properties![0].typedValue!.stringValue).to.be.equal(encryptedField)\n await api2.maintenanceTaskApi\n .getMaintenanceTaskWithUser(user2, entity.id!)\n .then(() => {\n throw new Error('Should not be able to get the entity')\n })\n .catch(() => {\n /* expected */\n })\n await api1.maintenanceTaskApi.shareWith(user2.healthcarePartyId!, entity)\n const retrieved = await api2.maintenanceTaskApi.getMaintenanceTaskWithUser(user2, entity.id!)\n expect(retrieved.properties![0].typedValue!.stringValue).to.be.equal(encryptedField)\n })\n\n it('newInstance should honor non-default values unless they are undefined', async () => {\n const api = await initApi(env!, hcp1Username)\n const user = await api.userApi.getCurrentUser()\n const maintenanceTaskUndefinedId = await api.maintenanceTaskApi.newInstance(user, { id: undefined })\n const customId = 'customId'\n const maintenanceTaskCustomId = await api.maintenanceTaskApi.newInstance(user, { id: customId })\n const maintenanceTaskWithUndefinedInit = await api.maintenanceTaskApi.newInstance(user, undefined)\n expect(maintenanceTaskUndefinedId.id).to.not.be.undefined\n expect(maintenanceTaskWithUndefinedInit.id).to.not.be.undefined\n expect(maintenanceTaskCustomId.id).to.equal(customId)\n })\n})\n"]}
@@ -0,0 +1 @@
1
+ import 'isomorphic-fetch';
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const mocha_1 = require("mocha");
13
+ require("isomorphic-fetch");
14
+ const Patient_1 = require("../../icc-api/model/Patient");
15
+ const chai_1 = require("chai");
16
+ const crypto_1 = require("crypto");
17
+ const test_utils_1 = require("../utils/test_utils");
18
+ var initApi = test_utils_1.TestUtils.initApi;
19
+ const types_1 = require("@icure/test-setup/types");
20
+ const icc_x_api_1 = require("../../icc-x-api");
21
+ (0, test_utils_1.setLocalStorage)(fetch);
22
+ let env;
23
+ describe('icc-x-patient-api Tests', () => {
24
+ (0, mocha_1.before)(function () {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ this.timeout(600000);
27
+ const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
28
+ env = yield initializer.execute((0, types_1.getEnvVariables)());
29
+ });
30
+ });
31
+ it('CreatePatientWithUser Success for HCP', () => __awaiter(void 0, void 0, void 0, function* () {
32
+ // Given
33
+ const { userApi: userApiForHcp, dataOwnerApi: dataOwnerApiForHcp, patientApi: patientApiForHcp, cryptoApi: cryptoApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
34
+ const hcpUser = yield userApiForHcp.getCurrentUser();
35
+ const patientToCreate = yield patientApiForHcp.newInstance(hcpUser, new Patient_1.Patient({
36
+ id: (0, crypto_1.randomUUID)(),
37
+ firstName: 'John',
38
+ lastName: 'Snow',
39
+ note: 'Winter is coming',
40
+ }));
41
+ // When
42
+ const createdPatient = yield patientApiForHcp.createPatientWithUser(hcpUser, patientToCreate);
43
+ // Then
44
+ const readPatient = yield patientApiForHcp.getPatientWithUser(hcpUser, createdPatient.id);
45
+ (0, chai_1.assert)(readPatient != null);
46
+ (0, chai_1.assert)(readPatient.id != null);
47
+ (0, chai_1.assert)(readPatient.note == patientToCreate.note);
48
+ (0, chai_1.assert)(readPatient.firstName == patientToCreate.firstName);
49
+ (0, chai_1.assert)(readPatient.lastName == patientToCreate.lastName);
50
+ (0, chai_1.assert)(readPatient.delegations[hcpUser.healthcarePartyId].length > 0);
51
+ (0, chai_1.assert)(readPatient.encryptionKeys[hcpUser.healthcarePartyId].length > 0);
52
+ }));
53
+ it('Merge patients should work as expected', () => __awaiter(void 0, void 0, void 0, function* () {
54
+ const api1 = yield initApi(env, test_utils_1.hcp1Username);
55
+ const user1 = yield api1.userApi.getCurrentUser();
56
+ const api2 = yield initApi(env, test_utils_1.hcp2Username);
57
+ const user2 = yield api2.userApi.getCurrentUser();
58
+ const api3 = yield initApi(env, test_utils_1.hcp3Username);
59
+ const user3 = yield api3.userApi.getCurrentUser();
60
+ const mergedFirstName = 'Gigio';
61
+ const mergedLastName = 'Bagigio';
62
+ const mergedAlias = 'Luigio';
63
+ const mergedNote = 'A secret note';
64
+ const patientFrom = yield api1.patientApi.createPatientWithUser(user1, yield api1.patientApi.newInstance(user1, {
65
+ firstName: mergedFirstName,
66
+ lastName: 'From',
67
+ note: 'A',
68
+ }, { additionalDelegates: { [user2.healthcarePartyId]: 'WRITE' } }));
69
+ const patientFromSecretIds = yield api1.patientApi.decryptSecretIdsOf(patientFrom);
70
+ (0, chai_1.expect)(patientFromSecretIds).to.have.lengthOf(1);
71
+ const patientInto = yield api1.patientApi.createPatientWithUser(user1, yield api1.patientApi.newInstance(user1, {
72
+ firstName: 'Into',
73
+ lastName: mergedLastName,
74
+ note: 'B',
75
+ }, { additionalDelegates: { [user3.healthcarePartyId]: 'WRITE' } }));
76
+ const patientIntoSecretIds = yield api1.patientApi.decryptSecretIdsOf(patientInto);
77
+ (0, chai_1.expect)(patientFromSecretIds).to.have.lengthOf(1);
78
+ (0, chai_1.expect)(patientIntoSecretIds[0]).to.not.equal(patientFromSecretIds[0]);
79
+ const mergedInto = Object.assign(Object.assign({}, patientInto), { firstName: mergedFirstName, lastName: mergedLastName, alias: mergedAlias, note: mergedNote });
80
+ const mergedPatient = yield api1.patientApi.mergePatients(patientFrom, mergedInto);
81
+ (0, chai_1.expect)(mergedPatient.firstName).to.equal(mergedFirstName);
82
+ (0, chai_1.expect)(mergedPatient.lastName).to.equal(mergedLastName);
83
+ (0, chai_1.expect)(mergedPatient.alias).to.equal(mergedAlias);
84
+ (0, chai_1.expect)(mergedPatient.note).to.equal(mergedNote);
85
+ (0, chai_1.expect)(yield api1.patientApi.decryptSecretIdsOf(mergedPatient)).to.have.members([...patientFromSecretIds, ...patientIntoSecretIds]);
86
+ const retrievedByDelegateWithAccessToInto = yield api3.patientApi.getPatientWithUser(user3, patientInto.id);
87
+ (0, chai_1.expect)(retrievedByDelegateWithAccessToInto.firstName).to.equal(mergedFirstName);
88
+ (0, chai_1.expect)(retrievedByDelegateWithAccessToInto.lastName).to.equal(mergedLastName);
89
+ (0, chai_1.expect)(retrievedByDelegateWithAccessToInto.alias).to.equal(mergedAlias);
90
+ (0, chai_1.expect)(retrievedByDelegateWithAccessToInto.note).to.equal(mergedNote);
91
+ (0, chai_1.expect)(yield api3.patientApi.decryptSecretIdsOf(retrievedByDelegateWithAccessToInto)).to.have.members(patientIntoSecretIds);
92
+ const retrievedByDelegateWithAccessToFrom = yield api2.patientApi.getPatientWithUser(user2, patientInto.id);
93
+ (0, chai_1.expect)(retrievedByDelegateWithAccessToFrom.firstName).to.equal(mergedFirstName);
94
+ (0, chai_1.expect)(retrievedByDelegateWithAccessToFrom.lastName).to.equal(mergedLastName);
95
+ (0, chai_1.expect)(retrievedByDelegateWithAccessToFrom.alias).to.equal(mergedAlias);
96
+ (0, chai_1.expect)(retrievedByDelegateWithAccessToFrom.note).to.be.undefined; // No access to new encryption key yet
97
+ (0, chai_1.expect)(yield api2.patientApi.decryptSecretIdsOf(retrievedByDelegateWithAccessToFrom)).to.have.members(patientFromSecretIds);
98
+ }));
99
+ it('Share with should work as expected', () => __awaiter(void 0, void 0, void 0, function* () {
100
+ const api1 = yield initApi(env, test_utils_1.hcp1Username);
101
+ const user1 = yield api1.userApi.getCurrentUser();
102
+ const api2 = yield initApi(env, test_utils_1.hcp2Username);
103
+ const user2 = yield api2.userApi.getCurrentUser();
104
+ const encryptedField = 'Something encrypted';
105
+ const entity = yield api1.patientApi.createPatientWithUser(user1, yield api1.patientApi.newInstance(user1, { firstName: 'Gigio', lastName: 'Bagigio', note: encryptedField }));
106
+ (0, chai_1.expect)(entity.note).to.be.equal(encryptedField);
107
+ const secretIds = yield api1.patientApi.decryptSecretIdsOf(entity);
108
+ yield api2.patientApi
109
+ .getPatientWithUser(user2, entity.id)
110
+ .then(() => {
111
+ throw new Error('Should not be able to get the entity');
112
+ })
113
+ .catch(() => {
114
+ /* expected */
115
+ });
116
+ yield api1.patientApi.shareWith(user2.healthcarePartyId, entity, secretIds);
117
+ const retrieved = yield api2.patientApi.getPatientWithUser(user2, entity.id);
118
+ (0, chai_1.expect)(retrieved.note).to.be.equal(encryptedField);
119
+ (0, chai_1.expect)(yield api2.patientApi.decryptSecretIdsOf(retrieved)).to.have.members(secretIds);
120
+ }));
121
+ it('newInstance should honor non-default values unless they are undefined', () => __awaiter(void 0, void 0, void 0, function* () {
122
+ const api = yield initApi(env, test_utils_1.hcp1Username);
123
+ const user = yield api.userApi.getCurrentUser();
124
+ const patientUndefinedId = yield api.patientApi.newInstance(user, { id: undefined });
125
+ const customId = 'customId';
126
+ const patientCustomId = yield api.patientApi.newInstance(user, { id: customId });
127
+ const patientWithUndefinedId = yield api.patientApi.newInstance(user, undefined);
128
+ (0, chai_1.expect)(patientUndefinedId.id).to.not.be.undefined;
129
+ (0, chai_1.expect)(patientWithUndefinedId.id).to.not.be.undefined;
130
+ (0, chai_1.expect)(patientCustomId.id).to.equal(customId);
131
+ }));
132
+ it('Patient picture should be automatically decoded from base64 on initialisation.', () => __awaiter(void 0, void 0, void 0, function* () {
133
+ const pictureAB = (0, crypto_1.randomBytes)(100);
134
+ const pictureBase64 = (0, icc_x_api_1.ua2b64)(pictureAB);
135
+ const patient = new Patient_1.Patient({ picture: pictureBase64 });
136
+ (0, chai_1.expect)(patient.picture).to.not.be.undefined;
137
+ (0, chai_1.expect)(patient.picture instanceof ArrayBuffer || ArrayBuffer.isView(patient.picture)).to.be.true;
138
+ const decodedPicture = new Uint8Array(patient.picture);
139
+ (0, chai_1.expect)(decodedPicture).to.have.length(pictureAB.length);
140
+ for (let i = 0; i < pictureAB.length; i++) {
141
+ (0, chai_1.expect)(decodedPicture[i]).to.equal(pictureAB[i]);
142
+ }
143
+ }));
144
+ it('Creating a new Patient instance using a patient with decoded picture should not lose the picture data', () => __awaiter(void 0, void 0, void 0, function* () {
145
+ const pictureAB = (0, crypto_1.randomBytes)(100);
146
+ const patient = new Patient_1.Patient({ picture: new Uint8Array(pictureAB) });
147
+ (0, chai_1.expect)(patient.picture).to.not.be.undefined;
148
+ (0, chai_1.expect)(patient.picture instanceof ArrayBuffer || ArrayBuffer.isView(patient.picture)).to.be.true;
149
+ const decodedPicture = new Uint8Array(patient.picture);
150
+ (0, chai_1.expect)(decodedPicture).to.have.length(pictureAB.length);
151
+ for (let i = 0; i < pictureAB.length; i++) {
152
+ (0, chai_1.expect)(decodedPicture[i]).to.equal(pictureAB[i]);
153
+ }
154
+ }));
155
+ it('A Patient with picture data should be created and retrieved correctly', () => __awaiter(void 0, void 0, void 0, function* () {
156
+ const pictureAB = (0, crypto_1.randomBytes)(100);
157
+ const api = yield initApi(env, test_utils_1.hcp1Username);
158
+ const user = yield api.userApi.getCurrentUser();
159
+ const patient = yield api.patientApi.createPatientWithUser(user, yield api.patientApi.newInstance(user, { firstName: 'Giovanni', lastName: 'Giorgio', picture: new Uint8Array(pictureAB) }));
160
+ (0, chai_1.expect)(patient.picture).to.not.be.undefined;
161
+ (0, chai_1.expect)(patient.picture instanceof ArrayBuffer || ArrayBuffer.isView(patient.picture)).to.be.true;
162
+ const decodedPicture = new Uint8Array(patient.picture);
163
+ (0, chai_1.expect)(decodedPicture).to.have.length(pictureAB.length);
164
+ for (let i = 0; i < pictureAB.length; i++) {
165
+ (0, chai_1.expect)(decodedPicture[i]).to.equal(pictureAB[i]);
166
+ }
167
+ }));
168
+ });
169
+ //# sourceMappingURL=icc-patient-x-api-test.js.map