oro-sdk 3.1.2 → 3.3.1

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.3.1",
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.2",
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, 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,89 @@ 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 name, last name, and the short id of the given consultation
438
+ * @param consult the consultation to be search indexed
439
+ * @param workflow the workflow data
440
+ * @param oroClient
441
+ */
442
+ export async function buildConsultSearchIndex(consult: Consult, workflow: WorkflowData, oroClient: OroClient) {
443
+ let terms: Terms = [
444
+ <Term> {
445
+ kind: 'consult-shortid',
446
+ value: consult.shortId
447
+ }
448
+ ]
449
+
450
+ const {
451
+ personalInfoPopulatedWfData,
452
+ childPersonalInfoPopulatedWfData,
453
+ otherPersonalInfoPopulatedWfData
454
+ } = await extractPersonalInfoFromWorkflowData(workflow)
455
+
456
+ const personalInfo = identificationToPersonalInformations(
457
+ toActualObject(personalInfoPopulatedWfData),
458
+ MetadataCategory.Personal
459
+ )
460
+ const childPersonalInfo = identificationToPersonalInformations(
461
+ toActualObject(childPersonalInfoPopulatedWfData),
462
+ MetadataCategory.ChildPersonal
463
+ )
464
+ const otherPersonalInfo = identificationToPersonalInformations(
465
+ toActualObject(otherPersonalInfoPopulatedWfData),
466
+ MetadataCategory.OtherPersonal
467
+ )
468
+
469
+ terms.push(<Term>{
470
+ kind: 'first-name',
471
+ value: personalInfo.firstname,
472
+ }, <Term> {
473
+ kind: 'last-name',
474
+ value: personalInfo.name
475
+ })
476
+
477
+ if(childPersonalInfo.firstname && childPersonalInfo.name) {
478
+ terms.push(<Term>{
479
+ kind: 'first-name',
480
+ value: childPersonalInfo.firstname,
481
+ }, <Term> {
482
+ kind: 'last-name',
483
+ value: childPersonalInfo.name
484
+ })
485
+ }
486
+
487
+ if(otherPersonalInfo.firstname && otherPersonalInfo.name) {
488
+ terms.push(<Term>{
489
+ kind: 'first-name',
490
+ value: otherPersonalInfo.firstname,
491
+ }, <Term> {
492
+ kind: 'last-name',
493
+ value: otherPersonalInfo.name
494
+ })
495
+ }
496
+
497
+ await oroClient.searchClient.index(consult.uuid, terms)
498
+ }