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.
@@ -740,8 +740,8 @@ function _filterTriggeredAnsweredWithKind() {
740
740
  // Flattens the list of answered questions
741
741
  flattenedAnswers = flattenSelectedAnswers(workflowData.selectedAnswers); // Generates a list of applicable questions
742
742
  triggeredQuestionsWithKind = Object.fromEntries(workflowData.pages.map(function (a) {
743
- return Object.entries(a.questions).filter(function (_ref) {
744
- var question = _ref[1];
743
+ return Object.entries(a.questions).filter(function (_ref2) {
744
+ var question = _ref2[1];
745
745
  return isTriggered(question.triggers || [], flattenedAnswers) && question.kind === kind;
746
746
  });
747
747
  }).flat());
@@ -765,7 +765,8 @@ function getWorkflowDataByCategory(_x3, _x4) {
765
765
  }
766
766
  function _getWorkflowDataByCategory() {
767
767
  _getWorkflowDataByCategory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(workflowData, category) {
768
- var flattenedAnswers, triggeredQuestions, fields;
768
+ var _workflowData$selecte;
769
+ var flattenedAnswers, triggeredQuestions, fields, answersPerPage;
769
770
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
770
771
  while (1) switch (_context2.prev = _context2.next) {
771
772
  case 0:
@@ -778,21 +779,41 @@ function _getWorkflowDataByCategory() {
778
779
  // Flattens the list of answered questions
779
780
  flattenedAnswers = flattenSelectedAnswers(workflowData.selectedAnswers); // Generates a list of applicable questions
780
781
  triggeredQuestions = Object.fromEntries(workflowData.pages.map(function (a) {
781
- return Object.entries(a.questions).filter(function (_ref2) {
782
- var question = _ref2[1];
782
+ return Object.entries(a.questions).filter(function (_ref3) {
783
+ var question = _ref3[1];
783
784
  return isTriggered(question.triggers || [], flattenedAnswers);
784
785
  });
785
786
  }).flat());
786
- fields = {}; // Generates the answers of the specified category and adds the appropriate values if any are missing
787
- return _context2.abrupt("return", Promise.all(workflowData.selectedAnswers.map(function (e) {
788
- return Object.entries(e);
789
- }).flat().filter(function (_ref3) {
790
- var k = _ref3[0];
787
+ fields = {};
788
+ answersPerPage = ((_workflowData$selecte = workflowData.selectedAnswers) != null ? _workflowData$selecte : []).map(function (pageAnswers, _) {
789
+ return Object.entries(pageAnswers).map(function (_ref4) {
790
+ var k = _ref4[0],
791
+ v = _ref4[1];
792
+ return [k, v, undefined];
793
+ });
794
+ });
795
+ if (workflowData.previousAnswers) {
796
+ // Since the selectedAnswers and previousAnswers should be a 1-1, we can map them together
797
+ answersPerPage = answersPerPage.map(function (pageAnswers, pageIndex) {
798
+ return pageAnswers.map(function (_ref5) {
799
+ var questionId = _ref5[0],
800
+ v = _ref5[1];
801
+ var previousAnswer = undefined;
802
+ if (workflowData.previousAnswers && workflowData.previousAnswers[pageIndex][questionId]) previousAnswer = workflowData.previousAnswers[pageIndex][questionId];
803
+ return [questionId, v, previousAnswer];
804
+ });
805
+ });
806
+ }
807
+ // Generates the answers of the specified category and adds the appropriate values if any are missing
808
+ return _context2.abrupt("return", Promise.all(answersPerPage.flat(1) // remove the pages, we want the answers all together
809
+ .filter(function (_ref6) {
810
+ var k = _ref6[0];
791
811
  return triggeredQuestions[k] && triggeredQuestions[k]['metaCategory'] === category;
792
- }).map(function (_ref4) {
793
- var k = _ref4[0],
794
- v = _ref4[1];
795
- return populateWorkflowField(triggeredQuestions[k], v).then(function (populatedValue) {
812
+ }).map(function (_ref7) {
813
+ var k = _ref7[0],
814
+ v = _ref7[1],
815
+ p = _ref7[2];
816
+ return populateWorkflowField(triggeredQuestions[k], v, p).then(function (populatedValue) {
796
817
  fields[k] = populatedValue;
797
818
  });
798
819
  })).then(function () {
@@ -807,7 +828,7 @@ function _getWorkflowDataByCategory() {
807
828
  console.error("Error while extracting " + category + " data from workflow", err);
808
829
  throw err;
809
830
  }));
810
- case 6:
831
+ case 8:
811
832
  case "end":
812
833
  return _context2.stop();
813
834
  }
@@ -847,7 +868,7 @@ function _getImagesFromIndexDb() {
847
868
  }));
848
869
  return _getImagesFromIndexDb.apply(this, arguments);
849
870
  }
850
- function populateWorkflowField(_x6, _x7) {
871
+ function populateWorkflowField(_x6, _x7, _x8) {
851
872
  return _populateWorkflowField.apply(this, arguments);
852
873
  }
853
874
  /**
@@ -897,7 +918,7 @@ function populateWorkflowField(_x6, _x7) {
897
918
  * @throws an Error if triggers typing is wrong
898
919
  */
899
920
  function _populateWorkflowField() {
900
- _populateWorkflowField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(question, answerValue) {
921
+ _populateWorkflowField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(question, answerValue, previousAnswer) {
901
922
  var answer, displayedAnswer;
902
923
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
903
924
  while (1) switch (_context4.prev = _context4.next) {
@@ -948,6 +969,7 @@ function _populateWorkflowField() {
948
969
  return _context4.abrupt("return", Promise.resolve({
949
970
  answer: answer,
950
971
  displayedAnswer: displayedAnswer,
972
+ previousAnswer: previousAnswer,
951
973
  kind: question.kind
952
974
  }));
953
975
  case 19:
@@ -1029,6 +1051,28 @@ function fillWorkflowFromPopulatedWorkflow(workflow, populatedWorkflow) {
1029
1051
  });
1030
1052
  return filledWorkflow;
1031
1053
  }
1054
+ /**
1055
+ * Checks and toggles the changed status for every answer in the workflow
1056
+ * by comparing the previous answer with the selected answer of the same question
1057
+ *
1058
+ * @param workflow
1059
+ * @returns the workflow with the updated `changed` statuses
1060
+ */
1061
+ function detectChangesInWorkflowAnswers(workflow) {
1062
+ return _extends({}, workflow, {
1063
+ previousAnswers: workflow.previousAnswers ? Object.fromEntries(workflow.previousAnswers.map(function (pageAnswers, pageId) {
1064
+ return Object.entries(pageAnswers).map(function (_ref) {
1065
+ var question = _ref[0],
1066
+ answer = _ref[1];
1067
+ var selectedAnswer = undefined;
1068
+ if (workflow.selectedAnswers && workflow.selectedAnswers[pageId][question]) selectedAnswer = workflow.selectedAnswers[pageId][question];
1069
+ return [question, _extends({}, answer, {
1070
+ changed: selectedAnswer === answer.previousAnswer
1071
+ })];
1072
+ });
1073
+ })) : undefined
1074
+ });
1075
+ }
1032
1076
 
1033
1077
  /**
1034
1078
  * Creates a consultation if one has not been created and fails to be retrieved by the payment intent
@@ -1121,6 +1165,8 @@ function _registerPatient() {
1121
1165
  identity = undefined;
1122
1166
  errorsThrown = [];
1123
1167
  stepsTotalNum = 9;
1168
+ // toggle all changed statuses if this workflow has previous/revision data
1169
+ workflow = detectChangesInWorkflowAnswers(workflow);
1124
1170
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1125
1171
  var _consultIndex, _identity, _identity2, practitioners, grantPromises, consultIndex, consultIndexPromises;
1126
1172
  return _regeneratorRuntime().wrap(function _loop$(_context3) {
@@ -1343,47 +1389,47 @@ function _registerPatient() {
1343
1389
  }
1344
1390
  }, _loop, null, [[0, 66]]);
1345
1391
  });
1346
- case 9:
1392
+ case 10:
1347
1393
  if (!(retry > 0)) {
1348
- _context4.next = 19;
1394
+ _context4.next = 20;
1349
1395
  break;
1350
1396
  }
1351
- return _context4.delegateYield(_loop(), "t0", 11);
1352
- case 11:
1397
+ return _context4.delegateYield(_loop(), "t0", 12);
1398
+ case 12:
1353
1399
  _ret = _context4.t0;
1354
1400
  if (!(_ret === "break")) {
1355
- _context4.next = 14;
1401
+ _context4.next = 15;
1356
1402
  break;
1357
1403
  }
1358
- return _context4.abrupt("break", 19);
1359
- case 14:
1404
+ return _context4.abrupt("break", 20);
1405
+ case 15:
1360
1406
  if (!(_ret === "continue")) {
1361
- _context4.next = 16;
1407
+ _context4.next = 17;
1362
1408
  break;
1363
1409
  }
1364
- return _context4.abrupt("continue", 16);
1365
- case 16:
1410
+ return _context4.abrupt("continue", 17);
1411
+ case 17:
1366
1412
  retry--;
1367
- _context4.next = 9;
1413
+ _context4.next = 10;
1368
1414
  break;
1369
- case 19:
1415
+ case 20:
1370
1416
  if (!(retry <= 0)) {
1371
- _context4.next = 22;
1417
+ _context4.next = 23;
1372
1418
  break;
1373
1419
  }
1374
1420
  console.error('[SDK] registration failed: MAX_RETRIES reached');
1375
1421
  throw 'RegistrationFailed';
1376
- case 22:
1422
+ case 23:
1377
1423
  console.log('Successfully Registered');
1378
- _context4.next = 25;
1424
+ _context4.next = 26;
1379
1425
  return oroClient.cleanIndex();
1380
- case 25:
1426
+ case 26:
1381
1427
  return _context4.abrupt("return", {
1382
1428
  masterKey: masterKey,
1383
1429
  consultationId: consult.uuid,
1384
1430
  lockboxUuid: lockboxUuid
1385
1431
  });
1386
- case 26:
1432
+ case 27:
1387
1433
  case "end":
1388
1434
  return _context4.stop();
1389
1435
  }
@@ -4751,5 +4797,5 @@ var init = function init(toolbox, tellerBaseURL, vaultBaseURL, guardBaseURL, sea
4751
4797
  };
4752
4798
 
4753
4799
  export default init;
4754
- export { AssociatedLockboxNotFound, CliniaService, IncompleteAuthentication, MissingGrant, MissingGrantFilter, MissingLockbox, MissingLockboxOwner, OroClient, WorkflowAnswersMissingError, buildConsultSearchIndex, createRefill, decryptConsultLockboxGrants, decryptGrants, extractAndStorePersonalWorkflowData, extractISOLocalityForConsult, extractPersonalInfoFromWorkflowData, fillWorkflowFromPopulatedWorkflow, filterTriggeredAnsweredWithKind, flattenSelectedAnswers, getImagesFromIndexDb, getInitialisedSelectedAnswers, getRefillAnswersAsWorkflow, getWorkflowDataByCategory, identificationToPersonalInformations, isTriggered, registerPatient, sessionStorePrivateKeyName, toActualObject, updatePersonalIntoPopulatedWorkflowData, wasmPath };
4800
+ export { AssociatedLockboxNotFound, CliniaService, IncompleteAuthentication, MissingGrant, MissingGrantFilter, MissingLockbox, MissingLockboxOwner, OroClient, WorkflowAnswersMissingError, buildConsultSearchIndex, createRefill, decryptConsultLockboxGrants, decryptGrants, detectChangesInWorkflowAnswers, extractAndStorePersonalWorkflowData, extractISOLocalityForConsult, extractPersonalInfoFromWorkflowData, fillWorkflowFromPopulatedWorkflow, filterTriggeredAnsweredWithKind, flattenSelectedAnswers, getImagesFromIndexDb, getInitialisedSelectedAnswers, getRefillAnswersAsWorkflow, getWorkflowDataByCategory, identificationToPersonalInformations, isTriggered, registerPatient, sessionStorePrivateKeyName, toActualObject, updatePersonalIntoPopulatedWorkflowData, wasmPath };
4755
4801
  //# sourceMappingURL=oro-sdk.esm.js.map