@icure/api 8.3.5 → 8.4.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 (44) hide show
  1. package/icc-api/api/IccAuthApi.d.ts +10 -1
  2. package/icc-api/api/IccAuthApi.js +20 -3
  3. package/icc-api/api/IccAuthApi.js.map +1 -1
  4. package/icc-api/api/IccClassificationApi.d.ts +1 -0
  5. package/icc-api/api/IccClassificationApi.js +12 -0
  6. package/icc-api/api/IccClassificationApi.js.map +1 -1
  7. package/icc-api/api/IccMessageApi.d.ts +0 -6
  8. package/icc-api/api/IccMessageApi.js +0 -15
  9. package/icc-api/api/IccMessageApi.js.map +1 -1
  10. package/icc-x-api/auth/SmartAuthProvider.d.ts +37 -13
  11. package/icc-x-api/auth/SmartAuthProvider.js +105 -29
  12. package/icc-x-api/auth/SmartAuthProvider.js.map +1 -1
  13. package/icc-x-api/icc-bekmehr-x-api.js +2 -1
  14. package/icc-x-api/icc-bekmehr-x-api.js.map +1 -1
  15. package/icc-x-api/icc-document-x-api.d.ts +51 -6
  16. package/icc-x-api/icc-document-x-api.js +231 -69
  17. package/icc-x-api/icc-document-x-api.js.map +1 -1
  18. package/icc-x-api/icc-message-x-api.d.ts +45 -6
  19. package/icc-x-api/icc-message-x-api.js +202 -30
  20. package/icc-x-api/icc-message-x-api.js.map +1 -1
  21. package/icc-x-api/icc-patient-x-api.d.ts +9 -1
  22. package/icc-x-api/icc-patient-x-api.js +92 -100
  23. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  24. package/icc-x-api/index.d.ts +14 -14
  25. package/icc-x-api/index.js +5 -4
  26. package/icc-x-api/index.js.map +1 -1
  27. package/package.json +1 -1
  28. package/test/icc-api/api/IccDocumentApi.js +27 -35
  29. package/test/icc-api/api/IccDocumentApi.js.map +1 -1
  30. package/test/icc-x-api/auth/group-switch-test.js +5 -5
  31. package/test/icc-x-api/auth/group-switch-test.js.map +1 -1
  32. package/test/icc-x-api/auth/jwt-provider-test.js +1 -1
  33. package/test/icc-x-api/auth/jwt-provider-test.js.map +1 -1
  34. package/test/icc-x-api/auth/smart-auth-provider-test.js +5 -5
  35. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -1
  36. package/test/icc-x-api/icc-document-x-api.js +28 -4
  37. package/test/icc-x-api/icc-document-x-api.js.map +1 -1
  38. package/test/icc-x-api/icc-message-x-api.js +19 -293
  39. package/test/icc-x-api/icc-message-x-api.js.map +1 -1
  40. package/test/icc-x-api/icc-user-x-api-test.js +1 -1
  41. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -1
  42. package/test/utils/test_utils.d.ts +4 -2
  43. package/test/utils/test_utils.js +4 -3
  44. package/test/utils/test_utils.js.map +1 -1
@@ -530,110 +530,102 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
530
530
  });
531
531
  });
532
532
  }
533
- export(user, patId, ownerId, usingPost = false) {
534
- return this.hcpartyApi.getHealthcareParty(ownerId).then((hcp) => {
535
- const parentId = hcp.parentId;
536
- return (0, utils_1.retry)(() => this.getPatientWithUser(user, patId))
537
- .then((patient) => __awaiter(this, void 0, void 0, function* () {
538
- const initialised = yield this.crypto.xapi.ensureEncryptionKeysInitialised(patient, EntityWithDelegationTypeName_1.EntityWithDelegationTypeName.Patient);
539
- if (!initialised) {
540
- return patient;
533
+ export(user, patId, ownerId) {
534
+ return __awaiter(this, void 0, void 0, function* () {
535
+ const parentId = yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds().then((h) => (h.length - 2 >= 0 ? h[h.length - 2] : h[0]));
536
+ const patient = yield (0, utils_1.retry)(() => __awaiter(this, void 0, void 0, function* () {
537
+ const retrieved = yield this.getPatientWithUser(user, patId);
538
+ if (retrieved != undefined) {
539
+ const initialised = yield this.crypto.xapi.ensureEncryptionKeysInitialised(retrieved, EntityWithDelegationTypeName_1.EntityWithDelegationTypeName.Patient);
540
+ if (!initialised) {
541
+ return retrieved;
542
+ }
543
+ else {
544
+ return yield this.modifyPatientWithUser(user, initialised);
545
+ }
541
546
  }
542
547
  else {
543
- return yield this.modifyPatientWithUser(user, initialised);
548
+ return null;
544
549
  }
545
- }))
546
- .then((patient) => __awaiter(this, void 0, void 0, function* () {
547
- if (!patient) {
548
- return Promise.resolve({ id: patId });
549
- }
550
- const delSfks = yield this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName_1.EntityWithDelegationTypeName.Patient }, ownerId);
551
- return delSfks.length
552
- ? Promise.all([
553
- (0, utils_1.retry)(() => (usingPost
554
- ? this.helementApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))
555
- : this.helementApi.findByHCPartyPatientSecretFKeysArray(ownerId, delSfks)).then((hes) => parentId
556
- ? (usingPost
557
- ? this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(parentId, _.uniq(delSfks))
558
- : this.helementApi.findHealthElementsDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))).then((moreHes) => _.uniqBy(hes.concat(moreHes), 'id'))
559
- : hes)),
560
- (0, utils_1.retry)(() => (usingPost
561
- ? this.formApi.findFormsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(ownerId, _.uniq(delSfks))
562
- : this.formApi.findFormsDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))).then((frms) => parentId
563
- ? (usingPost
564
- ? this.formApi.findFormsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(parentId, _.uniq(delSfks))
565
- : this.formApi.findFormsDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))).then((moreFrms) => _.uniqBy(frms.concat(moreFrms), 'id'))
566
- : frms)),
567
- (0, utils_1.retry)(() => (usingPost
568
- ? this.contactApi.findByHCPartyPatientSecretFKeysUsingPost(ownerId, undefined, undefined, _.uniq(delSfks))
569
- : this.contactApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(','))).then((ctcs) => parentId
570
- ? (usingPost
571
- ? this.contactApi.findByHCPartyPatientSecretFKeysUsingPost(parentId, undefined, undefined, _.uniq(delSfks))
572
- : this.contactApi.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(','))).then((moreCtcs) => _.uniqBy(ctcs.concat(moreCtcs), 'id'))
573
- : ctcs)),
574
- (0, utils_1.retry)(() => (usingPost
575
- ? this.invoiceApi.findInvoicesDelegationsStubsByHCPartyPatientForeignKeysUsingPost(ownerId, _.uniq(delSfks))
576
- : this.invoiceApi.findInvoicesDelegationsStubsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))).then((ivs) => parentId
577
- ? this.invoiceApi
578
- .findInvoicesDelegationsStubsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
579
- .then((moreIvs) => _.uniqBy(ivs.concat(moreIvs), 'id'))
580
- : ivs)),
581
- (0, utils_1.retry)(() => this.classificationApi
582
- .findClassificationsByHCPartyPatientForeignKeys(ownerId, _.uniq(delSfks).join(','))
583
- .then((cls) => parentId
584
- ? this.classificationApi
585
- .findClassificationsByHCPartyPatientForeignKeys(parentId, _.uniq(delSfks).join(','))
586
- .then((moreCls) => _.uniqBy(cls.concat(moreCls), 'id'))
587
- : cls)),
588
- (0, utils_1.retry)(() => __awaiter(this, void 0, void 0, function* () {
589
- const delegationSFKs = _.uniq(delSfks).join(',');
590
- try {
591
- let calendarItems = yield (usingPost
592
- ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(ownerId, _.uniq(delSfks))
593
- : this.calendarItemApi.findByHCPartyPatientSecretFKeys(ownerId, _.uniq(delSfks).join(',')));
594
- if (parentId) {
595
- const moreCalendarItems = yield (usingPost
596
- ? this.calendarItemApi.findByHCPartyPatientSecretFKeysArray(parentId, _.uniq(delSfks))
597
- : this.calendarItemApi.findByHCPartyPatientSecretFKeys(parentId, _.uniq(delSfks).join(',')));
598
- calendarItems = _.uniqBy(calendarItems.concat(moreCalendarItems), 'id');
599
- }
600
- return calendarItems;
601
- }
602
- catch (ex) {
603
- console.log(`exception occured exporting calendarItem for ownerId: ${ownerId} - ${ex}`);
604
- //throw ex
605
- }
606
- })),
607
- ]).then(([hes, frms, ctcs, ivs, cls, cis]) => {
608
- const docIds = {};
609
- ctcs.forEach((c) => c.services &&
610
- c.services.forEach((s) => s.content && Object.values(s.content).forEach((c) => c && c.documentId && (docIds[c.documentId] = 1))));
611
- return (0, utils_1.retry)(() => this.documentApi.getDocuments(new models_1.ListOfIds({ ids: Object.keys(docIds) }))).then((docs) => {
612
- return {
613
- id: patId,
614
- patient: patient,
615
- contacts: ctcs,
616
- forms: frms,
617
- healthElements: hes,
618
- invoices: ivs,
619
- classifications: cls,
620
- calItems: cis,
621
- documents: docs,
622
- };
623
- });
624
- })
625
- : Promise.resolve({
626
- id: patId,
627
- patient: patient,
628
- contacts: [],
629
- forms: [],
630
- healthElements: [],
631
- invoices: [],
632
- classifications: [],
633
- calItems: [],
634
- documents: [],
635
- });
636
550
  }));
551
+ const delSfks = patient != null ? yield this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName_1.EntityWithDelegationTypeName.Patient }, ownerId) : [];
552
+ if (delSfks.length <= 0) {
553
+ return {
554
+ id: patId,
555
+ patient,
556
+ contacts: [],
557
+ forms: [],
558
+ healthElements: [],
559
+ invoices: [],
560
+ classifications: [],
561
+ calItems: [],
562
+ documents: [],
563
+ };
564
+ }
565
+ const contactIds = new Set([
566
+ ...(yield (0, utils_1.retry)(() => this.contactApi.findContactIdsByDataOwnerPatientOpeningDate(ownerId, delSfks))),
567
+ ...(yield (0, utils_1.retry)(() => this.contactApi.findContactIdsByDataOwnerPatientOpeningDate(parentId, delSfks))),
568
+ ]);
569
+ const formIds = new Set([
570
+ ...(yield (0, utils_1.retry)(() => this.formApi.findFormIdsByDataOwnerPatientOpeningDate(ownerId, delSfks))),
571
+ ...(yield (0, utils_1.retry)(() => this.formApi.findFormIdsByDataOwnerPatientOpeningDate(parentId, delSfks))),
572
+ ]);
573
+ const healthElementIds = new Set([
574
+ ...(yield (0, utils_1.retry)(() => this.helementApi.findHealthElementIdsByDataOwnerPatientOpeningDate(ownerId, delSfks))),
575
+ ...(yield (0, utils_1.retry)(() => this.helementApi.findHealthElementIdsByDataOwnerPatientOpeningDate(parentId, delSfks))),
576
+ ]);
577
+ const invoiceIds = new Set([
578
+ ...(yield (0, utils_1.retry)(() => this.invoiceApi.findInvoiceIdsByDataOwnerPatientInvoiceDate(ownerId, delSfks))),
579
+ ...(yield (0, utils_1.retry)(() => this.invoiceApi.findInvoiceIdsByDataOwnerPatientInvoiceDate(parentId, delSfks))),
580
+ ]);
581
+ const classificationIds = new Set([
582
+ ...(yield (0, utils_1.retry)(() => this.classificationApi.findClassificationIdsByDataOwnerPatientCreated(ownerId, delSfks))),
583
+ ...(yield (0, utils_1.retry)(() => this.classificationApi.findClassificationIdsByDataOwnerPatientCreated(parentId, delSfks))),
584
+ ]);
585
+ const calendarItemIds = new Set([
586
+ ...(yield (0, utils_1.retry)(() => this.calendarItemApi.findCalendarItemIdsByDataOwnerPatientStartTime(ownerId, delSfks))),
587
+ ...(yield (0, utils_1.retry)(() => this.calendarItemApi.findCalendarItemIdsByDataOwnerPatientStartTime(parentId, delSfks))),
588
+ ]);
589
+ function batchGet(items_1, get_1) {
590
+ return __awaiter(this, arguments, void 0, function* (items, get, batchSize = 1000) {
591
+ const results = [];
592
+ for (let i = 0; i < items.length; i += batchSize) {
593
+ const batch = items.slice(i, i + batchSize);
594
+ const res = yield (0, utils_1.retry)(() => get(batch));
595
+ results.push(...res);
596
+ }
597
+ return results;
598
+ });
599
+ }
600
+ const contacts = yield batchGet([...contactIds], (x) => this.contactApi.getContactsWithUser(user, { ids: x }));
601
+ const forms = yield batchGet([...formIds], (x) => this.formApi.getForms({ ids: x }));
602
+ const healthElements = yield batchGet([...healthElementIds], (x) => this.helementApi.getHealthElementsWithUser(user, { ids: x }));
603
+ const invoices = yield batchGet([...invoiceIds], (x) => this.invoiceApi.getInvoices({ ids: x }));
604
+ const classifications = yield batchGet([...classificationIds], (x) => this.classificationApi.getClassifications({ ids: x }));
605
+ const calItems = yield batchGet([...calendarItemIds], (x) => this.calendarItemApi.getCalendarItemsWithIdsWithUser(user, { ids: x }));
606
+ const documentIds = new Set();
607
+ contacts.forEach((contact) => {
608
+ var _a;
609
+ (_a = contact.services) === null || _a === void 0 ? void 0 : _a.forEach((service) => {
610
+ var _a;
611
+ Object.values((_a = service.content) !== null && _a !== void 0 ? _a : {}).forEach((content) => {
612
+ if (!!content.documentId)
613
+ documentIds.add(content.documentId);
614
+ });
615
+ });
616
+ });
617
+ const documents = yield batchGet([...documentIds], (x) => this.documentApi.getDocumentsWithUser(user, { ids: x }));
618
+ return {
619
+ id: patId,
620
+ patient,
621
+ calItems,
622
+ classifications,
623
+ contacts,
624
+ documents,
625
+ forms,
626
+ healthElements,
627
+ invoices,
628
+ };
637
629
  });
638
630
  }
639
631
  checkInami(inami) {