oro-sdk 6.0.1 → 6.1.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.
@@ -67,3 +67,11 @@ export declare function flattenSelectedAnswers(answers: SelectedAnswersData): st
67
67
  */
68
68
  export declare function getInitialisedSelectedAnswers(workflow: WorkflowData, useDefault?: boolean): any[];
69
69
  export declare function fillWorkflowFromPopulatedWorkflow(workflow: WorkflowData, populatedWorkflow: PopulatedWorkflowData): any;
70
+ /**
71
+ * Checks and toggles the changed status for every answer in the workflow
72
+ * by comparing the previous answer with the selected answer of the same question
73
+ *
74
+ * @param workflow
75
+ * @returns the workflow with the updated `changed` statuses
76
+ */
77
+ export declare function detectChangesInWorkflowAnswers(workflow: WorkflowData): WorkflowData;
@@ -744,8 +744,8 @@ function _filterTriggeredAnsweredWithKind() {
744
744
  // Flattens the list of answered questions
745
745
  flattenedAnswers = flattenSelectedAnswers(workflowData.selectedAnswers); // Generates a list of applicable questions
746
746
  triggeredQuestionsWithKind = Object.fromEntries(workflowData.pages.map(function (a) {
747
- return Object.entries(a.questions).filter(function (_ref) {
748
- var question = _ref[1];
747
+ return Object.entries(a.questions).filter(function (_ref2) {
748
+ var question = _ref2[1];
749
749
  return isTriggered(question.triggers || [], flattenedAnswers) && question.kind === kind;
750
750
  });
751
751
  }).flat());
@@ -769,7 +769,8 @@ function getWorkflowDataByCategory(_x3, _x4) {
769
769
  }
770
770
  function _getWorkflowDataByCategory() {
771
771
  _getWorkflowDataByCategory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(workflowData, category) {
772
- var flattenedAnswers, triggeredQuestions, fields;
772
+ var _workflowData$selecte;
773
+ var flattenedAnswers, triggeredQuestions, fields, answersPerPage;
773
774
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
774
775
  while (1) switch (_context2.prev = _context2.next) {
775
776
  case 0:
@@ -782,21 +783,41 @@ function _getWorkflowDataByCategory() {
782
783
  // Flattens the list of answered questions
783
784
  flattenedAnswers = flattenSelectedAnswers(workflowData.selectedAnswers); // Generates a list of applicable questions
784
785
  triggeredQuestions = Object.fromEntries(workflowData.pages.map(function (a) {
785
- return Object.entries(a.questions).filter(function (_ref2) {
786
- var question = _ref2[1];
786
+ return Object.entries(a.questions).filter(function (_ref3) {
787
+ var question = _ref3[1];
787
788
  return isTriggered(question.triggers || [], flattenedAnswers);
788
789
  });
789
790
  }).flat());
790
- fields = {}; // Generates the answers of the specified category and adds the appropriate values if any are missing
791
- return _context2.abrupt("return", Promise.all(workflowData.selectedAnswers.map(function (e) {
792
- return Object.entries(e);
793
- }).flat().filter(function (_ref3) {
794
- var k = _ref3[0];
791
+ fields = {};
792
+ answersPerPage = ((_workflowData$selecte = workflowData.selectedAnswers) != null ? _workflowData$selecte : []).map(function (pageAnswers, _) {
793
+ return Object.entries(pageAnswers).map(function (_ref4) {
794
+ var k = _ref4[0],
795
+ v = _ref4[1];
796
+ return [k, v, undefined];
797
+ });
798
+ });
799
+ if (workflowData.previousAnswers) {
800
+ // Since the selectedAnswers and previousAnswers should be a 1-1, we can map them together
801
+ answersPerPage = answersPerPage.map(function (pageAnswers, pageIndex) {
802
+ return pageAnswers.map(function (_ref5) {
803
+ var questionId = _ref5[0],
804
+ v = _ref5[1];
805
+ var previousAnswer = undefined;
806
+ if (workflowData.previousAnswers && workflowData.previousAnswers[pageIndex][questionId]) previousAnswer = workflowData.previousAnswers[pageIndex][questionId];
807
+ return [questionId, v, previousAnswer];
808
+ });
809
+ });
810
+ }
811
+ // Generates the answers of the specified category and adds the appropriate values if any are missing
812
+ return _context2.abrupt("return", Promise.all(answersPerPage.flat(1) // remove the pages, we want the answers all together
813
+ .filter(function (_ref6) {
814
+ var k = _ref6[0];
795
815
  return triggeredQuestions[k] && triggeredQuestions[k]['metaCategory'] === category;
796
- }).map(function (_ref4) {
797
- var k = _ref4[0],
798
- v = _ref4[1];
799
- return populateWorkflowField(triggeredQuestions[k], v).then(function (populatedValue) {
816
+ }).map(function (_ref7) {
817
+ var k = _ref7[0],
818
+ v = _ref7[1],
819
+ p = _ref7[2];
820
+ return populateWorkflowField(triggeredQuestions[k], v, p).then(function (populatedValue) {
800
821
  fields[k] = populatedValue;
801
822
  });
802
823
  })).then(function () {
@@ -811,7 +832,7 @@ function _getWorkflowDataByCategory() {
811
832
  console.error("Error while extracting " + category + " data from workflow", err);
812
833
  throw err;
813
834
  }));
814
- case 6:
835
+ case 8:
815
836
  case "end":
816
837
  return _context2.stop();
817
838
  }
@@ -851,7 +872,7 @@ function _getImagesFromIndexDb() {
851
872
  }));
852
873
  return _getImagesFromIndexDb.apply(this, arguments);
853
874
  }
854
- function populateWorkflowField(_x6, _x7) {
875
+ function populateWorkflowField(_x6, _x7, _x8) {
855
876
  return _populateWorkflowField.apply(this, arguments);
856
877
  }
857
878
  /**
@@ -901,7 +922,7 @@ function populateWorkflowField(_x6, _x7) {
901
922
  * @throws an Error if triggers typing is wrong
902
923
  */
903
924
  function _populateWorkflowField() {
904
- _populateWorkflowField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(question, answerValue) {
925
+ _populateWorkflowField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(question, answerValue, previousAnswer) {
905
926
  var answer, displayedAnswer;
906
927
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
907
928
  while (1) switch (_context4.prev = _context4.next) {
@@ -952,6 +973,7 @@ function _populateWorkflowField() {
952
973
  return _context4.abrupt("return", Promise.resolve({
953
974
  answer: answer,
954
975
  displayedAnswer: displayedAnswer,
976
+ previousAnswer: previousAnswer,
955
977
  kind: question.kind
956
978
  }));
957
979
  case 19:
@@ -1033,6 +1055,28 @@ function fillWorkflowFromPopulatedWorkflow(workflow, populatedWorkflow) {
1033
1055
  });
1034
1056
  return filledWorkflow;
1035
1057
  }
1058
+ /**
1059
+ * Checks and toggles the changed status for every answer in the workflow
1060
+ * by comparing the previous answer with the selected answer of the same question
1061
+ *
1062
+ * @param workflow
1063
+ * @returns the workflow with the updated `changed` statuses
1064
+ */
1065
+ function detectChangesInWorkflowAnswers(workflow) {
1066
+ return _extends({}, workflow, {
1067
+ previousAnswers: workflow.previousAnswers ? Object.fromEntries(workflow.previousAnswers.map(function (pageAnswers, pageId) {
1068
+ return Object.entries(pageAnswers).map(function (_ref) {
1069
+ var question = _ref[0],
1070
+ answer = _ref[1];
1071
+ var selectedAnswer = undefined;
1072
+ if (workflow.selectedAnswers && workflow.selectedAnswers[pageId][question]) selectedAnswer = workflow.selectedAnswers[pageId][question];
1073
+ return [question, _extends({}, answer, {
1074
+ changed: selectedAnswer === answer.previousAnswer
1075
+ })];
1076
+ });
1077
+ })) : undefined
1078
+ });
1079
+ }
1036
1080
 
1037
1081
  /**
1038
1082
  * Creates a consultation if one has not been created and fails to be retrieved by the payment intent
@@ -1125,6 +1169,8 @@ function _registerPatient() {
1125
1169
  identity = undefined;
1126
1170
  errorsThrown = [];
1127
1171
  stepsTotalNum = 9;
1172
+ // toggle all changed statuses if this workflow has previous/revision data
1173
+ workflow = detectChangesInWorkflowAnswers(workflow);
1128
1174
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1129
1175
  var _consultIndex, _identity, _identity2, practitioners, grantPromises, consultIndex, consultIndexPromises;
1130
1176
  return _regeneratorRuntime().wrap(function _loop$(_context3) {
@@ -1347,47 +1393,47 @@ function _registerPatient() {
1347
1393
  }
1348
1394
  }, _loop, null, [[0, 66]]);
1349
1395
  });
1350
- case 9:
1396
+ case 10:
1351
1397
  if (!(retry > 0)) {
1352
- _context4.next = 19;
1398
+ _context4.next = 20;
1353
1399
  break;
1354
1400
  }
1355
- return _context4.delegateYield(_loop(), "t0", 11);
1356
- case 11:
1401
+ return _context4.delegateYield(_loop(), "t0", 12);
1402
+ case 12:
1357
1403
  _ret = _context4.t0;
1358
1404
  if (!(_ret === "break")) {
1359
- _context4.next = 14;
1405
+ _context4.next = 15;
1360
1406
  break;
1361
1407
  }
1362
- return _context4.abrupt("break", 19);
1363
- case 14:
1408
+ return _context4.abrupt("break", 20);
1409
+ case 15:
1364
1410
  if (!(_ret === "continue")) {
1365
- _context4.next = 16;
1411
+ _context4.next = 17;
1366
1412
  break;
1367
1413
  }
1368
- return _context4.abrupt("continue", 16);
1369
- case 16:
1414
+ return _context4.abrupt("continue", 17);
1415
+ case 17:
1370
1416
  retry--;
1371
- _context4.next = 9;
1417
+ _context4.next = 10;
1372
1418
  break;
1373
- case 19:
1419
+ case 20:
1374
1420
  if (!(retry <= 0)) {
1375
- _context4.next = 22;
1421
+ _context4.next = 23;
1376
1422
  break;
1377
1423
  }
1378
1424
  console.error('[SDK] registration failed: MAX_RETRIES reached');
1379
1425
  throw 'RegistrationFailed';
1380
- case 22:
1426
+ case 23:
1381
1427
  console.log('Successfully Registered');
1382
- _context4.next = 25;
1428
+ _context4.next = 26;
1383
1429
  return oroClient.cleanIndex();
1384
- case 25:
1430
+ case 26:
1385
1431
  return _context4.abrupt("return", {
1386
1432
  masterKey: masterKey,
1387
1433
  consultationId: consult.uuid,
1388
1434
  lockboxUuid: lockboxUuid
1389
1435
  });
1390
- case 26:
1436
+ case 27:
1391
1437
  case "end":
1392
1438
  return _context4.stop();
1393
1439
  }
@@ -4777,6 +4823,7 @@ exports.createRefill = createRefill;
4777
4823
  exports.decryptConsultLockboxGrants = decryptConsultLockboxGrants;
4778
4824
  exports.decryptGrants = decryptGrants;
4779
4825
  exports.default = init;
4826
+ exports.detectChangesInWorkflowAnswers = detectChangesInWorkflowAnswers;
4780
4827
  exports.extractAndStorePersonalWorkflowData = extractAndStorePersonalWorkflowData;
4781
4828
  exports.extractISOLocalityForConsult = extractISOLocalityForConsult;
4782
4829
  exports.extractPersonalInfoFromWorkflowData = extractPersonalInfoFromWorkflowData;