oro-sdk 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.1.2",
2
+ "version": "3.2.0",
3
3
  "main": "dist/index.js",
4
4
  "typings": "dist/index.d.ts",
5
5
  "files": [
@@ -54,8 +54,8 @@
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
  }
61
- }
61
+ }
@@ -10,9 +10,12 @@ import {
10
10
  MedicalStatus,
11
11
  MetadataCategory,
12
12
  PersonalMeta,
13
+ PopulatedWorkflowData,
13
14
  Practitioner,
14
15
  PreferenceMeta,
15
16
  RawConsultationMeta,
17
+ Term,
18
+ Terms,
16
19
  Uuid,
17
20
  VaultIndex,
18
21
  WorkflowData,
@@ -21,8 +24,10 @@ import {
21
24
  filterTriggeredAnsweredWithKind,
22
25
  getImagesFromIndexDb,
23
26
  getWorkflowDataByCategory,
27
+ identificationToPersonalInformations,
24
28
  OroClient,
25
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
 
@@ -399,3 +410,84 @@ export async function extractAndStorePersonalWorkflowData(
399
410
  )
400
411
  })
401
412
  }
413
+
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,
422
+ }> {
423
+ return Promise.all([
424
+ getWorkflowDataByCategory(workflow, MetadataCategory.Personal),
425
+ getWorkflowDataByCategory(workflow, MetadataCategory.ChildPersonal),
426
+ getWorkflowDataByCategory(workflow, MetadataCategory.OtherPersonal)
427
+ ]).then(([personalInfoPopulatedWfData, childPersonalInfoPopulatedWfData, otherPersonalInfoPopulatedWfData]) => {
428
+ return {
429
+ personalInfoPopulatedWfData,
430
+ childPersonalInfoPopulatedWfData,
431
+ otherPersonalInfoPopulatedWfData,
432
+ }
433
+ })
434
+ }
435
+
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) {
443
+ let terms: Terms = []
444
+
445
+ const {
446
+ personalInfoPopulatedWfData,
447
+ childPersonalInfoPopulatedWfData,
448
+ otherPersonalInfoPopulatedWfData
449
+ } = await extractPersonalInfoFromWorkflowData(workflow)
450
+
451
+ const personalInfo = identificationToPersonalInformations(
452
+ toActualObject(personalInfoPopulatedWfData),
453
+ MetadataCategory.Personal
454
+ )
455
+ const childPersonalInfo = identificationToPersonalInformations(
456
+ toActualObject(childPersonalInfoPopulatedWfData),
457
+ MetadataCategory.ChildPersonal
458
+ )
459
+ const otherPersonalInfo = identificationToPersonalInformations(
460
+ toActualObject(otherPersonalInfoPopulatedWfData),
461
+ MetadataCategory.OtherPersonal
462
+ )
463
+
464
+ terms.push(<Term>{
465
+ kind: 'first-name',
466
+ value: personalInfo.firstname,
467
+ }, <Term> {
468
+ kind: 'last-name',
469
+ value: personalInfo.name
470
+ })
471
+
472
+ if(childPersonalInfo.firstname && childPersonalInfo.name) {
473
+ terms.push(<Term>{
474
+ kind: 'first-name',
475
+ value: childPersonalInfo.firstname,
476
+ }, <Term> {
477
+ kind: 'last-name',
478
+ value: childPersonalInfo.name
479
+ })
480
+ }
481
+
482
+ if(otherPersonalInfo.firstname && otherPersonalInfo.name) {
483
+ terms.push(<Term>{
484
+ kind: 'first-name',
485
+ value: otherPersonalInfo.firstname,
486
+ }, <Term> {
487
+ kind: 'last-name',
488
+ value: otherPersonalInfo.name
489
+ })
490
+ }
491
+
492
+ await oroClient.searchClient.index(consultUuid, terms)
493
+ }