remymumoh

Untitled

Mar 16th, 2020
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // SAMPLE STORED PROCEDURE
  2. function sample(projectId, linkageCode) {
  3.     var collection = getContext().getCollection();
  4.     var output = {
  5.         interviewDate: '',
  6.         birthDate: ''
  7.     };
  8.  
  9.         // this is not returning anything at the moment stuck here
  10.         var result = collection.chain()
  11.             .filter(function (doc) {
  12.                 return doc.projectId == projectId
  13.             })
  14.             .filter(function (doc) {
  15.                 return doc.CaseNumber == caseNumber
  16.             })
  17.             .unwind(doc => doc.ItemDetails, (doc, details) => { return { doc, dayName: details.Name, dayValue: details.ItemValue }; })
  18.             .unwind(doc => doc.doc.ItemDetails, (doc, details) => { return { doc, monthName: details.Name, monthValue: details.ItemValue }; })
  19.             .unwind(doc => doc.doc.ItemDetails, (doc, details) => { return { yearName: details.Name, yearValue: details.ItemValue }; })
  20.             .filter(doc => ( doc.dayName == dateFields['day'] ))
  21.             .filter(doc => ( doc.monthName == dateFields['month'] ))
  22.             .filter(doc => ( doc.yearName == dateFields['year'] ))
  23.             .map(doc => ( {day: doc.dayValue, month: doc.monthValue, year: doc.yearValue} ))
  24.             .value({}, function (error, resources, options) {
  25.                 console.log(JSON.stringify(resources));
  26.             });
  27.  
  28.         return result;
  29.     }
  30.  
  31.     // this part works as expected return the casenumber
  32.     var linkageCodeResult = collection.chain()
  33.         .filter(function (doc) {
  34.             return doc.projectId == projectId
  35.         })
  36.         .unwind(s => s.ItemDetails, (s, i) => { return { caseNumber: s.CaseNumber, itemName: i.Name, itemValue: i.ItemValue } })
  37.         .filter(function (si) {
  38.             return si.itemName == 'LINKAGE_CODE';
  39.         })
  40.         .filter(function (postCouns) {
  41.             return postCouns.itemValue == linkageCode
  42.         })
  43.         .pluck('caseNumber')
  44.         .value({}, function (error, resources, options) {
  45.             var caseNumber = resources[0];
  46.             console.log(caseNumber);
  47.            
  48.             //this part is not returning the dates
  49.             var interviewDateResult = dateResult(
  50.                 caseNumber,
  51.                 { 'day': 'IINTD', 'month': 'IINTM', 'year': 'IINTY' },
  52.                 'interviewDate'
  53.             );
  54.             var birthDateResult = dateResult(
  55.                 caseNumber,
  56.                 { 'day': 'I0102A', 'month': 'I0102M', 'year': 'I0102Y' },
  57.                 'birthDate'
  58.             );
  59.         });
  60. }
RAW Paste Data