oro-sdk 3.1.2-dev2 → 3.2.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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.1.2-dev2",
2
+ "version": "3.2.0",
3
3
  "main": "dist/index.js",
4
4
  "typings": "dist/index.d.ts",
5
5
  "files": [
@@ -54,7 +54,7 @@
54
54
  "form-data": "^4.0.0",
55
55
  "formdata-node": "^4.3.1",
56
56
  "idb-keyval": "^5.0.6",
57
- "oro-sdk-apis": "1.38.2",
57
+ "oro-sdk-apis": "1.39.1",
58
58
  "oro-toolbox": "0.0.6",
59
59
  "uuid": "^8.3.2"
60
60
  }
@@ -5,14 +5,17 @@ import {
5
5
  ConsultRequest,
6
6
  DocumentType,
7
7
  IdentityResponse,
8
- IndexKey, LocalizedData,
8
+ IndexKey,
9
9
  MedicalMeta,
10
10
  MedicalStatus,
11
11
  MetadataCategory,
12
- PersonalMeta, PopulatedWorkflowData,
12
+ PersonalMeta,
13
+ PopulatedWorkflowData,
13
14
  Practitioner,
14
15
  PreferenceMeta,
15
- RawConsultationMeta, Term, Terms,
16
+ RawConsultationMeta,
17
+ Term,
18
+ Terms,
16
19
  Uuid,
17
20
  VaultIndex,
18
21
  WorkflowData,
@@ -20,9 +23,11 @@ import {
20
23
  import {
21
24
  filterTriggeredAnsweredWithKind,
22
25
  getImagesFromIndexDb,
23
- getWorkflowDataByCategory, identificationToPersonalInformations,
26
+ getWorkflowDataByCategory,
27
+ identificationToPersonalInformations,
24
28
  OroClient,
25
- RegisterPatientOutput, toActualObject,
29
+ RegisterPatientOutput,
30
+ toActualObject
26
31
  } from '..'
27
32
 
28
33
  const MAX_RETRIES = 15
@@ -179,6 +184,12 @@ export async function registerPatient(
179
184
 
180
185
  await Promise.all([...grantPromises, ...consultIndexPromises])
181
186
 
187
+ await buildConsultSearchIndex(consult.uuid, workflow, oroClient).catch((err) => {
188
+ console.error('[SDK: registration] personal information not found or another error occured during search indexing', err)
189
+ if(retry <= 1) return // this statement is to avoid failing the registration due to the failure in search indexing the consult, this practically implements a soft retry
190
+ errorsThrown.push(err)
191
+ })
192
+
182
193
  if (errorsThrown.length > 0)
183
194
  throw errorsThrown
184
195
 
@@ -187,11 +198,6 @@ export async function registerPatient(
187
198
  statusMedical: MedicalStatus.New,
188
199
  })
189
200
 
190
- await searchIndexConsultation(consult.uuid, oroClient).catch((err) => {
191
- console.error('[SDK: registration] personal information not found or another error occured during search indexing', err)
192
- errorsThrown.push(err)
193
- })
194
-
195
201
  // if we got through the complete flow, the registration succeeded
196
202
  break
197
203
  } catch (err) {
@@ -405,84 +411,56 @@ export async function extractAndStorePersonalWorkflowData(
405
411
  })
406
412
  }
407
413
 
408
- export async function extractPersonalInfoFromConsultId(consultUuid: string, oroClient: OroClient): Promise<{
409
- consultUuid: string,
410
- personalInformations: LocalizedData<PopulatedWorkflowData>,
411
- childPersonalInformations: LocalizedData<PopulatedWorkflowData>,
412
- otherPersonalInformations: LocalizedData<PopulatedWorkflowData>,
414
+ /**
415
+ * Given workflow data, it populates it with Personal, ChildPersonal, and OtherPersonal workflow data
416
+ * @param workflow
417
+ */
418
+ export async function extractPersonalInfoFromWorkflowData(workflow: WorkflowData): Promise<{
419
+ personalInfoPopulatedWfData: PopulatedWorkflowData,
420
+ childPersonalInfoPopulatedWfData: PopulatedWorkflowData,
421
+ otherPersonalInfoPopulatedWfData: PopulatedWorkflowData,
413
422
  }> {
414
423
  return Promise.all([
415
- // Retrieve MetadataCategory.Personal in any case
416
- oroClient
417
- .getPersonalInformationsFromConsultId(consultUuid, MetadataCategory.Personal, true)
418
- .then((personalInformations) => {
419
- if (!personalInformations[0]) {
420
- console.error(
421
- `${MetadataCategory.Personal} informations not found for consult:`,
422
- consultUuid
423
- )
424
-
425
- throw Error('No self personal information found')
426
- }
427
-
428
- return personalInformations[0]
429
- }),
430
- // Retrieve MetadataCategory.ChildPersonal in any case in parallel
431
- oroClient
432
- .getPersonalInformationsFromConsultId(consultUuid, MetadataCategory.ChildPersonal, true)
433
- .then((childInformations): any => {
434
- if (!childInformations[0]) {
435
- console.debug(
436
- `${MetadataCategory.ChildPersonal} informations not found for consult:`,
437
- consultUuid
438
- )
439
-
440
- // Retrieve MetadataCategory.OtherPersonal only if MetadataCategory.ChildPersonal does not exist
441
- return oroClient
442
- .getPersonalInformationsFromConsultId(
443
- consultUuid,
444
- MetadataCategory.OtherPersonal,
445
- true
446
- )
447
- .then((otherInformations) => {
448
- if (!otherInformations[0]) {
449
- console.debug(
450
- `${MetadataCategory.OtherPersonal} informations not found for consult:`,
451
- consultUuid
452
- )
453
-
454
- return {}
455
- }
456
-
457
- return { otherPersonalInformations: otherInformations[0] }
458
- })
459
- }
460
-
461
- return { childPersonalInformations: childInformations[0] }
462
- }),
463
- ]).then(([personalInformations, { childPersonalInformations, otherPersonalInformations }]) => {
424
+ getWorkflowDataByCategory(workflow, MetadataCategory.Personal),
425
+ getWorkflowDataByCategory(workflow, MetadataCategory.ChildPersonal),
426
+ getWorkflowDataByCategory(workflow, MetadataCategory.OtherPersonal)
427
+ ]).then(([personalInfoPopulatedWfData, childPersonalInfoPopulatedWfData, otherPersonalInfoPopulatedWfData]) => {
464
428
  return {
465
- consultUuid,
466
- personalInformations,
467
- childPersonalInformations,
468
- otherPersonalInformations,
429
+ personalInfoPopulatedWfData,
430
+ childPersonalInfoPopulatedWfData,
431
+ otherPersonalInfoPopulatedWfData,
469
432
  }
470
433
  })
471
434
  }
472
435
 
473
- export async function searchIndexConsultation(consultUuid: string, oroClient: OroClient) {
436
+ /**
437
+ * Creates the search index for the first and last name of the given consultation
438
+ * @param consultUuid the uuid of the consult to be search indexed
439
+ * @param workflow the workflow data
440
+ * @param oroClient
441
+ */
442
+ export async function buildConsultSearchIndex(consultUuid: string, workflow: WorkflowData, oroClient: OroClient) {
474
443
  let terms: Terms = []
475
444
 
476
445
  const {
477
- personalInformations,
478
- childPersonalInformations,
479
- otherPersonalInformations
480
- } = await extractPersonalInfoFromConsultId(consultUuid, oroClient)
446
+ personalInfoPopulatedWfData,
447
+ childPersonalInfoPopulatedWfData,
448
+ otherPersonalInfoPopulatedWfData
449
+ } = await extractPersonalInfoFromWorkflowData(workflow)
481
450
 
482
451
  const personalInfo = identificationToPersonalInformations(
483
- toActualObject(personalInformations.data),
452
+ toActualObject(personalInfoPopulatedWfData),
484
453
  MetadataCategory.Personal
485
454
  )
455
+ const childPersonalInfo = identificationToPersonalInformations(
456
+ toActualObject(childPersonalInfoPopulatedWfData),
457
+ MetadataCategory.ChildPersonal
458
+ )
459
+ const otherPersonalInfo = identificationToPersonalInformations(
460
+ toActualObject(otherPersonalInfoPopulatedWfData),
461
+ MetadataCategory.OtherPersonal
462
+ )
463
+
486
464
  terms.push(<Term>{
487
465
  kind: 'first-name',
488
466
  value: personalInfo.firstname,
@@ -491,11 +469,7 @@ export async function searchIndexConsultation(consultUuid: string, oroClient: Or
491
469
  value: personalInfo.name
492
470
  })
493
471
 
494
- if(childPersonalInformations) {
495
- const childPersonalInfo = identificationToPersonalInformations(
496
- toActualObject(childPersonalInformations.data),
497
- MetadataCategory.ChildPersonal
498
- )
472
+ if(childPersonalInfo.firstname && childPersonalInfo.name) {
499
473
  terms.push(<Term>{
500
474
  kind: 'first-name',
501
475
  value: childPersonalInfo.firstname,
@@ -505,11 +479,7 @@ export async function searchIndexConsultation(consultUuid: string, oroClient: Or
505
479
  })
506
480
  }
507
481
 
508
- if(otherPersonalInformations) {
509
- const otherPersonalInfo = identificationToPersonalInformations(
510
- toActualObject(otherPersonalInformations.data),
511
- MetadataCategory.OtherPersonal
512
- )
482
+ if(otherPersonalInfo.firstname && otherPersonalInfo.name) {
513
483
  terms.push(<Term>{
514
484
  kind: 'first-name',
515
485
  value: otherPersonalInfo.firstname,