Produced by Araxis Merge on 10/4/2017 8:04:34 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | rdk.zip\rdk\product\production\rdk\src\resources\activitymanagement\tasks | task-operations-resource.js | Mon Aug 28 19:41:48 2017 UTC |
| 2 | rdk.zip\rdk\product\production\rdk\src\resources\activitymanagement\tasks | task-operations-resource.js | Tue Oct 3 17:16:15 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 2874 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | 'use stric t'; | |
| 2 | ||
| 3 | var rdk = require('. ./../../co re/rdk'); | |
| 4 | var uriBui lder = rdk .utils.uri Builder; | |
| 5 | var httpUt il = rdk.u tils.http; | |
| 6 | var pidVal idator = r dk.utils.p idValidato r; | |
| 7 | var nullch ecker = rd k.utils.nu llchecker; | |
| 8 | var RdkErr or = rdk.u tils.RdkEr ror; | |
| 9 | var _ = re quire('lod ash'); | |
| 10 | var async = require( 'async'); | |
| 11 | var parseS tring = re quire('xml 2js').pars eString; | |
| 12 | var activi tyUtils = require('. ./activity -utils'); | |
| 13 | var getGen ericJbpmCo nfig = act ivityUtils .getGeneri cJbpmConfi g; | |
| 14 | var proces sJsonObjec t = activi tyUtils.pr ocessJsonO bject; | |
| 15 | var proces sValue = a ctivityUti ls.process Value; | |
| 16 | var wrapVa lueInCData = activit yUtils.wra pValueInCD ata; | |
| 17 | var getJbp mUser = ac tivityUtil s.getJbpmU ser; | |
| 18 | var getFor mattedRout esString = activityU tils.getFo rmattedRou tesString; | |
| 19 | var parseA ssignedTo = activity Utils.pars eAssignedT o; | |
| 20 | var filter Identifier s = activi tyUtils.fi lterIdenti fiers; | |
| 21 | var getDat abaseConfi gFromReque st = activ ityUtils.g etDatabase ConfigFrom Request; | |
| 22 | var activi tyDb = req uire('../. ./../subsy stems/jbpm /jbpm-subs ystem'); | |
| 23 | var navMap ping = req uire('./na vigation-m apping'); | |
| 24 | var patien tRelatedTe ams = requ ire('../.. /../write/ pick-list/ team-manag ement/team s-for-user -patient-r elated-fet ch-list'); | |
| 25 | var moment = require ('moment') ; | |
| 26 | var oracle db = requi re('oracle db'); | |
| 27 | var facili tiesList = require(' ../../faci lity-monik er/vha-sit es').data. items; | |
| 28 | var result Utils = rd k.utils.re sults; | |
| 29 | var xmlTem plates = a ctivityUti ls.xmlTemp lates; | |
| 30 | var pepSub system = r equire('.. /../../sub systems/pe p/pep-subs ystem'); | |
| 31 | ||
| 32 | var dbSche ma = 'acti vitydb'; | |
| 33 | module.exp orts.dbSch ema = dbSc hema; | |
| 34 | ||
| 35 | module.exp orts.callJ pid = func tion(req, pid, callb ack) { | |
| 36 | if (!p id) { | |
| 37 | re turn callb ack('No pi d provided to callJp id'); | |
| 38 | } | |
| 39 | var jd sPath = '/ vpr/jpid/' + pid; | |
| 40 | var op tions = _. extend({}, req.app.c onfig.jdsS erver, { | |
| 41 | ur l: jdsPath , | |
| 42 | lo gger: req. logger, | |
| 43 | js on: true | |
| 44 | }); | |
| 45 | httpUt il.get(opt ions, call back); | |
| 46 | }; | |
| 47 | ||
| 48 | module.exp orts.getIc n = functi on(req, pi d, patient Identifier s, next) { | |
| 49 | patien tIdentifie rs = patie ntIdentifi ers || []; | |
| 50 | ||
| 51 | var ev aluateIcn = function (ids, next ) { | |
| 52 | va r icn = _. find(ids, pidValidat or.isIcn); | |
| 53 | ||
| 54 | if (!icn) { | |
| 55 | next('jp id did not find an i cn'); | |
| 56 | return; | |
| 57 | } | |
| 58 | ||
| 59 | ne xt(null, i cn); | |
| 60 | }; | |
| 61 | ||
| 62 | if (pa tientIdent ifiers.len gth > 1) { | |
| 63 | // if more th an 1 pid w e have alr eady done lookup in tasks quer y | |
| 64 | ev aluateIcn( patientIde ntifiers, next); | |
| 65 | } else { | |
| 66 | // patientide ntifiers i s null or was defaul ted to the passed-in pid value | |
| 67 | // so do a j pid lookup | |
| 68 | va r cb = fun ction(erro r, respons e, result) { | |
| 69 | if (erro r) { | |
| 70 | next (error); | |
| 71 | retu rn; | |
| 72 | } | |
| 73 | ||
| 74 | evaluate Icn(result .patientId entifiers, next); | |
| 75 | }; | |
| 76 | ||
| 77 | ex ports.call Jpid(req, pid, cb); | |
| 78 | } | |
| 79 | }; | |
| 80 | ||
| 81 | module.exp orts.getTe ams = func tion(req, staffIEN, patientID, next) { | |
| 82 | var db Config = g etDatabase ConfigFrom Request(re q); | |
| 83 | if (!d bConfig) { | |
| 84 | re turn next( new RdkErr or({ | |
| 85 | code: 'o racledb.50 3.1001', | |
| 86 | logger: req.logger | |
| 87 | }) ); | |
| 88 | } | |
| 89 | ||
| 90 | var pa tientRelat edTeamsCal lback = fu nction(err or, result ) { | |
| 91 | if (error) { | |
| 92 | next(err or); | |
| 93 | return; | |
| 94 | } | |
| 95 | ne xt(null, n ullchecker .isNullish (result)); | |
| 96 | }; | |
| 97 | ||
| 98 | patien tRelatedTe ams.fetch( req.logger , dbConfig , patientR elatedTeam sCallback, { | |
| 99 | st affIEN: st affIEN, | |
| 100 | pa tientID: p atientID, | |
| 101 | si te: _.get( req, 'sess ion.user.s ite'), | |
| 102 | pc mmDbConfig : dbConfig , | |
| 103 | fu llConfig: req.app.co nfig.pickL istServer | |
| 104 | }); | |
| 105 | }; | |
| 106 | ||
| 107 | function g etFacility Correspond ingToTeam( req, teamI D, next) { | |
| 108 | var db Config = g etDatabase ConfigFrom Request(re q); | |
| 109 | if (!d bConfig) { | |
| 110 | re turn next( new RdkErr or({ | |
| 111 | code: 'o racledb.50 3.1001', | |
| 112 | logger: req.logger | |
| 113 | }) ); | |
| 114 | } | |
| 115 | ||
| 116 | var pr ocParams = { | |
| 117 | p_ team_id: t eamID | |
| 118 | }; | |
| 119 | ||
| 120 | var pr ocQuery = 'BEGIN act ivitydb.pc mmdata.get FacilityCo rrespondin gToTeam(:p _team_id, :recordset ); END;'; | |
| 121 | ||
| 122 | return activityD b.doExecut eProcWithP arams(req, dbConfig, procQuery , procPara ms, next); | |
| 123 | } | |
| 124 | ||
| 125 | module.exp orts.build TasksRespo nse = func tion(tasks , tasksRou tesList, r eq, parame ters, pati entIdentif iers, task sCallback, next) { | |
| 126 | var ta skInstance IdsToRemov e = []; | |
| 127 | var fo rmattedRes ponse = { | |
| 128 | da ta: { | |
| 129 | items: [ ] | |
| 130 | } | |
| 131 | }; | |
| 132 | async. waterfall( [ | |
| 133 | ||
| 134 | fu nction(cal lback) { | |
| 135 | if (!tas ksRoutesLi st) { | |
| 136 | call back(); | |
| 137 | retu rn; | |
| 138 | } | |
| 139 | ||
| 140 | async.ea ch(tasksRo utesList, function(p o, callbac k) { | |
| 141 | var taskInstan ceId = po. TASKINSTAN CEID; | |
| 142 | if ( nullchecke r.isNotNul lish(po.US ERID)) { | |
| 143 | setImmedia te(callbac k); | |
| 144 | return; | |
| 145 | } el se { | |
| 146 | async.wate rfall([ | |
| 147 | ||
| 148 | functi on(callbac k) { | |
| 149 | if (po.PATIE NTASSIGNME NT === 1) { | |
| 150 | //if pat ient is on the team then dont delete the task | |
| 151 | var this Task = _.f ind(tasks, { | |
| 152 | 'TAS KID': task InstanceId | |
| 153 | }); | |
| 154 | if (null checker.is NotNullish (thisTask) && req && req.sessi on && req. session.us er && req. session.us er.site && req.sessi on.user.du z && (_.is Undefined( parameters .removeTas k) || para meters.rem oveTask)) { | |
| 155 | var staffIEN = req.sessi on.user.du z[req.sess ion.user.s ite]; | |
| 156 | asyn c.waterfal l([ | |
| 157 | exports.ge tIcn.bind( null, req, thisTask. PATIENTICN , patientI dentifiers ), | |
| 158 | exports.ge tTeams.bin d(null, re q, staffIE N) | |
| 159 | ], f unction(er r, removeT ask) { | |
| 160 | if (err) { | |
| 161 | if (re q.logger & & req.logg er.error) { | |
| 162 | re q.logger.e rror(err); | |
| 163 | } | |
| 164 | } | |
| 165 | if (remove Task) { | |
| 166 | taskIn stanceIdsT oRemove.pu sh(taskIns tanceId); | |
| 167 | } | |
| 168 | ||
| 169 | callback() ; | |
| 170 | }); | |
| 171 | } else { | |
| 172 | //Is this an e rror/excep tion condi tion? | |
| 173 | call back(); | |
| 174 | retu rn; | |
| 175 | } | |
| 176 | } else { | |
| 177 | callback (); | |
| 178 | return; | |
| 179 | } | |
| 180 | }, | |
| 181 | functi on(callbac k) { | |
| 182 | if (nullchec ker.isNotN ullish(po. TEAM)) { | |
| 183 | async.wa terfall([ | |
| 184 | getF acilityCor responding ToTeam.bin d(null, re q, po.TEAM ), | |
| 185 | func tion(resul t, callbac k) { | |
| 186 | if (_.isAr ray(result ) && (resu lt.length > 0) && (_ .isUndefin ed(paramet ers.remove Task) || p arameters. removeTask )) { | |
| 187 | var st ationNumbe rResult = _.get(resu lt, '[0].S TATIONNUMB ER'); | |
| 188 | ||
| 189 | var fa cilityEntr y = _.find (facilitie sList, { | |
| 190 | 'f acilityCod e': statio nNumberRes ult | |
| 191 | }); | |
| 192 | ||
| 193 | if (!f acilityEnt ry) { | |
| 194 | re turn callb ack('Facil ity code m atching th e station number ' + stationNu mberResult + ' canno t be found .'); | |
| 195 | } | |
| 196 | ||
| 197 | var fa cilityName = _.get(f acilityEnt ry, 'facil ityName'); | |
| 198 | if (fa cilityName ) { | |
| 199 | ta sks = _.ma p(tasks, f unction(ta sk) { | |
| 200 | if (task .TASKID == = taskInst anceId) { | |
| 201 | task .assignedF acilityNam e = facili tyName; | |
| 202 | } | |
| 203 | return t ask; | |
| 204 | }) ; | |
| 205 | } | |
| 206 | ||
| 207 | callba ck(null, f alse); | |
| 208 | return ; | |
| 209 | } | |
| 210 | callback(n ull, false ); | |
| 211 | } | |
| 212 | ], funct ion(err, r emoveTask) { | |
| 213 | if ( err) { | |
| 214 | if (req.lo gger && re q.logger.e rror) { | |
| 215 | req.lo gger.error (err); | |
| 216 | } | |
| 217 | } | |
| 218 | if ( removeTask && req.bo dy.context === 'user ') { | |
| 219 | taskInstan ceIdsToRem ove.push(t askInstanc eId); | |
| 220 | } | |
| 221 | ||
| 222 | call back(); | |
| 223 | }); | |
| 224 | } else { | |
| 225 | callback (); | |
| 226 | } | |
| 227 | } | |
| 228 | ], functio n(err) { | |
| 229 | if (er r) { | |
| 230 | if (req.logg er && req. logger.err or) { | |
| 231 | req.logg er.error(e rr); | |
| 232 | } | |
| 233 | } | |
| 234 | ||
| 235 | setImm ediate(cal lback); | |
| 236 | }); | |
| 237 | } | |
| 238 | }, funct ion(err) { | |
| 239 | if ( err) { | |
| 240 | callback(e rr); | |
| 241 | return; | |
| 242 | } | |
| 243 | ||
| 244 | call back(); | |
| 245 | }); | |
| 246 | }, | |
| 247 | fu nction(cal lback) { | |
| 248 | if (!tas ks) { | |
| 249 | call back(); | |
| 250 | retu rn; | |
| 251 | } | |
| 252 | if (!_.i sEmpty(tas kInstanceI dsToRemove )) { | |
| 253 | _.ea ch(_.uniqu e(taskInst anceIdsToR emove), fu nction(rem oveTaskIns tanceId) { | |
| 254 | tasks = _. reject(tas ks, { | |
| 255 | 'TASKI D': remove TaskInstan ceId | |
| 256 | }); | |
| 257 | }); | |
| 258 | } | |
| 259 | var icnT oNameMap = []; | |
| 260 | var crea torOwnerId s = []; | |
| 261 | ||
| 262 | var addD ataToTasks = functio n(callback ) { | |
| 263 | asyn c.each(tas ks, functi on process Task(row, callback) { | |
| 264 | if (row.ha sOwnProper ty('PATIEN TICN')) { | |
| 265 | if (!_ .any(icnTo NameMap, ' PATIENTICN ', row.PAT IENTICN)) { | |
| 266 | ic nToNameMap .push({ | |
| 267 | 'PATIENT ICN': row. PATIENTICN , | |
| 268 | 'PATIENT NAME': '', | |
| 269 | 'LAST4': '' | |
| 270 | }) ; | |
| 271 | } | |
| 272 | } | |
| 273 | ||
| 274 | if (row.ha sOwnProper ty('CREATE DBYID')) { | |
| 275 | if (!_ .any(creat orOwnerIds , 'ID', ro w.CREATEDB YID)) { | |
| 276 | cr eatorOwner Ids.push({ | |
| 277 | 'ID': ro w.CREATEDB YID, | |
| 278 | 'NAME': '' | |
| 279 | }) ; | |
| 280 | } | |
| 281 | } | |
| 282 | ||
| 283 | if (row.ha sOwnProper ty('ACTUAL OWNERID')) { | |
| 284 | if (!_ .any(creat orOwnerIds , 'ID', ro w.ACTUALOW NERID)) { | |
| 285 | cr eatorOwner Ids.push({ | |
| 286 | 'ID': ro w.ACTUALOW NERID, | |
| 287 | 'NAME': '' | |
| 288 | }) ; | |
| 289 | } | |
| 290 | } | |
| 291 | ||
| 292 | if (row.ha sOwnProper ty('ASSIGN EDTO') && nullchecke r.isNotNul lish(row.A SSIGNEDTO) ) { | |
| 293 | row.as signedToRo utes = par seAssigned To(row.ASS IGNEDTO); | |
| 294 | _.each (row.assig nedToRoute s, functio n(parsedRo ute) { | |
| 295 | if (!_.isUnd efined(par sedRoute.u ser) && !_ .any(creat orOwnerIds , 'ID', pa rsedRoute. user)) { | |
| 296 | creatorO wnerIds.pu sh({ | |
| 297 | 'ID' : parsedRo ute.user, | |
| 298 | 'NAM E': '' | |
| 299 | }); | |
| 300 | } | |
| 301 | }); | |
| 302 | } | |
| 303 | ||
| 304 | if (row.ha sOwnProper ty('NAVIGA TION') && nullchecke r.isNotNul lish(row.N AVIGATION) ) { | |
| 305 | //pars e navigati on to a va lid JSON | |
| 306 | try { | |
| 307 | ro w.NAVIGATI ON = JSON. parse(row. NAVIGATION ); | |
| 308 | // add parame ters | |
| 309 | if (_.isObje ct(row.NAV IGATION)) { | |
| 310 | if (row. NAVIGATION .hasOwnPro perty('cha nnel') && row.NAVIGA TION.hasOw nProperty( 'event')) { | |
| 311 | row. NAVIGATION .parameter s = navMap ping.getPa rameters(r ow); | |
| 312 | } | |
| 313 | } | |
| 314 | } catc h (e) { | |
| 315 | re q.logger.e rror('Unab le to pars e task nav igation da ta from ta sk: ' + ro w); | |
| 316 | } | |
| 317 | } else { | |
| 318 | req.lo gger.info( 'Missing n avigation informatio n for task : ' + row) ; | |
| 319 | } | |
| 320 | ||
| 321 | row.TASKTY PE = 'Huma n'; | |
| 322 | if (row.ha sOwnProper ty('DEPLOY MENTID')) { | |
| 323 | var se rvice = ro w.DEPLOYME NTID.split (':', 2); | |
| 324 | if (se rvice.leng th > 1) { | |
| 325 | ro w.SERVICE = service[ 1].replace ('_', ' ') ; | |
| 326 | } | |
| 327 | } | |
| 328 | ||
| 329 | if (row.ha sOwnProper ty('PERMIS SION') && nullchecke r.isNotNul lish(row.P ERMISSION) ) { | |
| 330 | row.PE RMISSION = parsePerm issions(ro w, req); | |
| 331 | //Chec k if the u ser has th e permissi ons requir ed by the task | |
| 332 | hasPer missions(r ow, req, f unction() { | |
| 333 | re turn callb ack(); | |
| 334 | }); | |
| 335 | } else { | |
| 336 | req.lo gger.info( 'Missing p ermission informatio n for task : ' + row) ; | |
| 337 | callba ck(); | |
| 338 | } | |
| 339 | ||
| 340 | row.BEFORE EARLIESTDA TE = Boole an(_.get(r ow, 'BEFOR EEARLIESTD ATE')); | |
| 341 | ||
| 342 | }, f unction ea chComplete (row, err) { | |
| 343 | if (err) { | |
| 344 | req.lo gger.debug ('addDataT oTasks: ', err); | |
| 345 | return callback( ); | |
| 346 | } | |
| 347 | ||
| 348 | // Unescap e special characters for DESCR IPTION and INSTANCEN AME fields | |
| 349 | if (_.size (tasks) > 0) { | |
| 350 | _.set( formattedR esponse, ' data.items ', resultU tils.unesc apeSpecial Characters (tasks, [' DESCRIPTIO N', 'INSTA NCENAME']) ); | |
| 351 | } | |
| 352 | ||
| 353 | return cal lback(null ); | |
| 354 | }); | |
| 355 | }; | |
| 356 | ||
| 357 | var getN amesAndPro viders = f unction(ca llback) { | |
| 358 | asyn c.parallel ([ | |
| 359 | function(p arallelCb) { | |
| 360 | export s.getNames FromIcns(i cnToNameMa p, req, fu nction(res ultedMap) { | |
| 361 | _. each(tasks , function (row) { | |
| 362 | if (row. hasOwnProp erty('PATI ENTICN')) { | |
| 363 | var name = _.p luck(_.whe re(resulte dMap, { | |
| 364 | 'PATIENTIC N': row.PA TIENTICN | |
| 365 | }), 'PATIENTNA ME'); | |
| 366 | ||
| 367 | var last4 = _. pluck(_.wh ere(result edMap, { | |
| 368 | 'PATIENTIC N': row.PA TIENTICN | |
| 369 | }), 'LAST4'); | |
| 370 | ||
| 371 | if ( Array.isAr ray(name) && name.le ngth > 0) { | |
| 372 | row.PATIEN TNAME = na me[0]; | |
| 373 | } el se { | |
| 374 | row.PATIEN TNAME = '' ; | |
| 375 | } | |
| 376 | ||
| 377 | if ( Array.isAr ray(last4) && last4. length > 0 ) { | |
| 378 | row.LAST4 = last4[0] ; | |
| 379 | } el se { | |
| 380 | row.LAST4 = ''; | |
| 381 | } | |
| 382 | } | |
| 383 | }) ; | |
| 384 | // getNamesFr omIcns doe s not retu rn an erro r - it wil l either f ill in val ues | |
| 385 | // into the resultant map or not - proceed in either case | |
| 386 | pa rallelCb(n ull); | |
| 387 | }); | |
| 388 | }, | |
| 389 | function(p arallelCb) { | |
| 390 | getPro vidersFrom Ids(creato rOwnerIds, req, func tion(provi derMap) { | |
| 391 | _. each(tasks , function (row) { | |
| 392 | var name ; | |
| 393 | if (row. hasOwnProp erty('CREA TEDBYID')) { | |
| 394 | name = _.pluck (_.where(p roviderMap , { | |
| 395 | 'ID': row. CREATEDBYI D | |
| 396 | }), 'NAME'); | |
| 397 | if ( Array.isAr ray(name) && name.le ngth > 0) { | |
| 398 | row.CREATE DBYNAME = name[0]; | |
| 399 | } el se { | |
| 400 | row.CREATE DBYNAME = ''; | |
| 401 | } | |
| 402 | } | |
| 403 | if (row. hasOwnProp erty('ACTU ALOWNERID' )) { | |
| 404 | name = _.pluck (_.where(p roviderMap , { | |
| 405 | 'ID': row. ACTUALOWNE RID | |
| 406 | }), 'NAME'); | |
| 407 | ||
| 408 | if ( Array.isAr ray(name) && name.le ngth > 0) { | |
| 409 | row.ACTUAL OWNERNAME = name[0]; | |
| 410 | } el se { | |
| 411 | row.ACTUAL OWNERNAME = ''; | |
| 412 | } | |
| 413 | } | |
| 414 | if (row. hasOwnProp erty('assi gnedToRout es') && nu llchecker. isNotNulli sh(row.ass ignedToRou tes)) { | |
| 415 | var userList = _.pluck(r ow.assigne dToRoutes, 'user'); | |
| 416 | var users = {} ; | |
| 417 | _.ea ch(userLis t, functio n(user) { | |
| 418 | name = _.p luck(_.whe re(provide rMap, { | |
| 419 | 'ID': user | |
| 420 | }), 'NAME' ); | |
| 421 | if (Array. isArray(na me) && nam e.length > 0) { | |
| 422 | users[ user] = na me[0]; | |
| 423 | } else { | |
| 424 | users[ user] = us er; // if name not f ound , dis play the u ser id | |
| 425 | } | |
| 426 | }); | |
| 427 | ||
| 428 | row. INTENDEDFO R = getFor mattedRout esString(r ow.assigne dToRoutes, users, tr ue); | |
| 429 | dele te row.ass ignedToRou tes; | |
| 430 | ||
| 431 | if ( row.hasOwn Property(' assignedFa cilityName ') && null checker.is NotNullish (row.assig nedFacilit yName)) { | |
| 432 | row.INTEND EDFOR = ro w.assigned FacilityNa me + ' - ' + row.INT ENDEDFOR; | |
| 433 | delete row .assignedF acilityNam e; | |
| 434 | } | |
| 435 | } else { | |
| 436 | row. INTENDEDFO R = ''; | |
| 437 | } | |
| 438 | }) ; | |
| 439 | // getProvide rsFromIds does not r eturn an e rror - it will eithe r fill in values | |
| 440 | // into the resultant map or not - proceed in either case | |
| 441 | pa rallelCb(n ull); | |
| 442 | }); | |
| 443 | } | |
| 444 | ], f unction(er r, results ) { | |
| 445 | if (err) { | |
| 446 | req.lo gger.debug ('getNames AndProvide rs: ', err ); | |
| 447 | return callback( ); | |
| 448 | } | |
| 449 | ||
| 450 | tasksCallb ack(format tedRespons e); | |
| 451 | return cal lback(null ); | |
| 452 | }); | |
| 453 | }; | |
| 454 | ||
| 455 | async.se ries([ | |
| 456 | addD ataToTasks , | |
| 457 | getN amesAndPro viders | |
| 458 | ], funct ion(err) { | |
| 459 | if ( err) { | |
| 460 | req.logger .error(err ); | |
| 461 | return cal lback(err) ; | |
| 462 | } | |
| 463 | call back(); | |
| 464 | }); | |
| 465 | } | |
| 466 | ], fun ction(err) { | |
| 467 | if (err) { | |
| 468 | if (next ) { | |
| 469 | next (err); | |
| 470 | } else { | |
| 471 | req. logger.err or('Error building t ask respon se: ' + er r); | |
| 472 | } | |
| 473 | } else { | |
| 474 | if (next ) { | |
| 475 | next (); | |
| 476 | } | |
| 477 | } | |
| 478 | }); | |
| 479 | }; | |
| 480 | ||
| 481 | function g etProvider sFromIds(c reatorOwne rIds, req, cb) { | |
| 482 | // /da ta/index/u ser-uid?ra nge=urn:va :user:9E7A :100000002 72,urn:va: user:9E7A: 1000000027 0 | |
| 483 | var jd sUrlString Limit = _. get(req, ' app.config .jdsServer .urlLength Limit', 12 0); | |
| 484 | var jd sServer = req.app.co nfig.jdsSe rver; | |
| 485 | var pr eSegmentUr l = '/data /index/use r-uid?rang e='; | |
| 486 | var ma xSegmentLe ngth = jds UrlStringL imit - (jd sServer.ba seUrl.leng th + preSe gmentUrl.l ength); | |
| 487 | ||
| 488 | var ur lSegments = []; | |
| 489 | var cu rUrlSegmen t = ''; | |
| 490 | ||
| 491 | //brea k the UIDs into appr opriately sized, com ma-delimit ed chunks for JDS qu erying | |
| 492 | _.each (creatorOw nerIds, fu nction(cre atorOwner) { | |
| 493 | if (_.get(cr eatorOwner , 'ID.leng th', 0) > 0) { | |
| 494 | //transl ate from s ite;duz fo rmat to JD S UID form at | |
| 495 | var crea torOwnerSe gments = c reatorOwne r.ID.split (';'); | |
| 496 | if (crea torOwnerSe gments.len gth >= 2) { | |
| 497 | var creatorOwn erSite = c reatorOwne rSegments[ 0]; | |
| 498 | var creatorOwn erDUZ = cr eatorOwner Segments[1 ]; | |
| 499 | ||
| 500 | var uidString = 'urn:va: user:'; | |
| 501 | uidS tring += c reatorOwne rSite + ': ' + creato rOwnerDUZ; | |
| 502 | ||
| 503 | if ( nullchecke r.isNotNul lish(uidSt ring)) { | |
| 504 | var segmen tLength = uidString. length; | |
| 505 | ||
| 506 | if ((curUr lSegment.l ength + se gmentLengt h + 1) > m axSegmentL ength) { | |
| 507 | urlSeg ments.push (curUrlSeg ment); | |
| 508 | curUrl Segment = uidString; | |
| 509 | ||
| 510 | } else { | |
| 511 | if (cu rUrlSegmen t.length = == 0) { | |
| 512 | cu rUrlSegmen t = uidStr ing; | |
| 513 | } else { | |
| 514 | cu rUrlSegmen t += ',' + uidString ; | |
| 515 | } | |
| 516 | } | |
| 517 | } | |
| 518 | } | |
| 519 | } | |
| 520 | }); | |
| 521 | ||
| 522 | if (cu rUrlSegmen t.length ! == 0) { | |
| 523 | ur lSegments. push(curUr lSegment); | |
| 524 | } | |
| 525 | ||
| 526 | var as yncJobs = []; | |
| 527 | ||
| 528 | _.forE ach(urlSeg ments, fun ction(segm ent, index ) { | |
| 529 | as yncJobs.pu sh(functio n(callback ) { | |
| 530 | //do jds call | |
| 531 | var jdsP ath = preS egmentUrl + segment; | |
| 532 | ||
| 533 | var opti ons = _.ex tend({}, j dsServer, { | |
| 534 | url: jdsPath, | |
| 535 | logg er: req.lo gger, | |
| 536 | json : true | |
| 537 | }); | |
| 538 | ||
| 539 | httpUtil .get(optio ns, | |
| 540 | func tion(err, response, data) { | |
| 541 | if (!nullc hecker.isN ullish(err )) { | |
| 542 | return callback( err); | |
| 543 | } | |
| 544 | ||
| 545 | return cal lback(null , data); | |
| 546 | } | |
| 547 | ); | |
| 548 | }) ; | |
| 549 | }); | |
| 550 | ||
| 551 | async. parallelLi mit(asyncJ obs, 5, fu nction(err , results) { | |
| 552 | if (err) { | |
| 553 | return c b(creatorO wnerIds); | |
| 554 | } else { | |
| 555 | // smash results b ack into a map | |
| 556 | var newM ap = []; | |
| 557 | _.forEac h(results, function( result) { | |
| 558 | if ( result.has OwnPropert y('data') && result. data.hasOw nProperty( 'items')) { | |
| 559 | _.forEach( result.dat a.items, f unction(it em) { | |
| 560 | //tran slate back from uid to site;du z format | |
| 561 | if (it em && item .uid && it em.uid.ind exOf(':')) { | |
| 562 | va r uidSegme nts = item .uid.split (':'); | |
| 563 | if (uidSegme nts.length >= 2) { | |
| 564 | var crea torOwnerDU Z = uidSeg ments[uidS egments.le ngth - 1]; | |
| 565 | var crea torOwnerSi te = uidSe gments[uid Segments.l ength - 2] ; | |
| 566 | newMap.p ush({ | |
| 567 | 'ID' : creatorO wnerSite + ';' + cre atorOwnerD UZ, | |
| 568 | 'NAM E': item.n ame | |
| 569 | }); | |
| 570 | } | |
| 571 | } | |
| 572 | }); | |
| 573 | } | |
| 574 | }); | |
| 575 | return c b(newMap); | |
| 576 | } | |
| 577 | }); | |
| 578 | } | |
| 579 | ||
| 580 | module.exp orts.getNa mesFromIcn s = functi on(icnToNa meMap, req , cb) { | |
| 581 | //http:// IP /data/inde x/pt-selec t-pid?rang e=9E7A;3,9 E7A;8 | |
| 582 | var jd sUrlString Limit = _. get(req, ' app.config .jdsServer .urlLength Limit') || 120; | |
| 583 | var jd sServer = req.app.co nfig.jdsSe rver; | |
| 584 | var pr eSegmentUr l = '/data /index/pt- select-pid ?range='; | |
| 585 | var ma xSegmentLe ngth = jds UrlStringL imit - (jd sServer.ba seUrl.leng th + preSe gmentUrl.l ength); | |
| 586 | ||
| 587 | var ur lSegments = []; | |
| 588 | var cu rUrlSegmen t = ''; | |
| 589 | ||
| 590 | //brea k the ICNs into appr opriately sized, com ma-delimit ed chunks for JDS qu erying | |
| 591 | _.each (icnToName Map, funct ion(map) { | |
| 592 | va r icn = ma p.PATIENTI CN; | |
| 593 | if (nullchec ker.isNotN ullish(icn )) { | |
| 594 | var segm entLength = icn.leng th; | |
| 595 | ||
| 596 | if ((cur UrlSegment .length + segmentLen gth + 1) > maxSegmen tLength) { | |
| 597 | urlS egments.pu sh(curUrlS egment); | |
| 598 | curU rlSegment = icn; | |
| 599 | ||
| 600 | } else { | |
| 601 | if ( curUrlSegm ent.length === 0) { | |
| 602 | curUrlSegm ent = icn; | |
| 603 | } el se { | |
| 604 | curUrlSegm ent += ',' + icn; | |
| 605 | } | |
| 606 | } | |
| 607 | } | |
| 608 | }); | |
| 609 | ||
| 610 | if (cu rUrlSegmen t.length ! == 0) { | |
| 611 | ur lSegments. push(curUr lSegment); | |
| 612 | } | |
| 613 | ||
| 614 | var as yncJobs = []; | |
| 615 | ||
| 616 | _.forE ach(urlSeg ments, fun ction(segm ent, index ) { | |
| 617 | as yncJobs.pu sh(functio n(callback ) { | |
| 618 | //do jds call | |
| 619 | var jdsP ath = preS egmentUrl + segment; | |
| 620 | ||
| 621 | var opti ons = _.ex tend({}, j dsServer, { | |
| 622 | url: jdsPath, | |
| 623 | logg er: req.lo gger, | |
| 624 | json : true | |
| 625 | }); | |
| 626 | ||
| 627 | httpUtil .get(optio ns, | |
| 628 | func tion(err, response, data) { | |
| 629 | if (!nullc hecker.isN ullish(err )) { | |
| 630 | return callback( err); | |
| 631 | } | |
| 632 | ||
| 633 | return cal lback(null , data); | |
| 634 | } | |
| 635 | ); | |
| 636 | }) ; | |
| 637 | }); | |
| 638 | ||
| 639 | async. parallelLi mit(asyncJ obs, 5, fu nction(err , results) { | |
| 640 | // results i s now equa l to: [{ic nToNameMap Chunk}, {i cnToNameMa pChunk} .. .] | |
| 641 | if (err) { | |
| 642 | return c b(icnToNam eMap); | |
| 643 | } else { | |
| 644 | // smash results b ack into a map | |
| 645 | var newM ap = []; | |
| 646 | _.forEac h(results, function( result) { | |
| 647 | if ( result.has OwnPropert y('data') && result. data.hasOw nProperty( 'items')) { | |
| 648 | _.forEach( result.dat a.items, f unction(it em) { | |
| 649 | if (it em.hasOwnP roperty('p id') && it em.hasOwnP roperty('d isplayName ')) { | |
| 650 | ne wMap.push( { | |
| 651 | 'PATIENT ICN': item .pid, | |
| 652 | 'PATIENT NAME': ite m.displayN ame, | |
| 653 | 'LAST4': item.last 4 | |
| 654 | }) ; | |
| 655 | } | |
| 656 | }); | |
| 657 | } | |
| 658 | }); | |
| 659 | return c b(newMap); | |
| 660 | } | |
| 661 | }); | |
| 662 | }; | |
| 663 | ||
| 664 | module.exp orts.query TasksRoute s = functi on(req, re s, tasks, parameters , patientI dentifiers ) { | |
| 665 | ||
| 666 | var cb = functio n(err, pot entialOwne rs) { | |
| 667 | if (err) { | |
| 668 | req.logg er.error(e rr); | |
| 669 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend(err) ; | |
| 670 | } | |
| 671 | ||
| 672 | ex ports.buil dTasksResp onse(tasks , potentia lOwners, r eq, parame ters, pati entIdentif iers, func tion(tasks ) { | |
| 673 | // !!Onl y for demo purposes - US13978 - return a ssignedTo (now subCo ntext) par ameter if provided | |
| 674 | if (null checker.is NotNullish (req.body) && nullch ecker.isNo tNullish(r eq.body.su bContext)) { | |
| 675 | if ( nullchecke r.isNotNul lish(tasks .data)) { | |
| 676 | tasks.data .subContex t = req.bo dy.subCont ext; | |
| 677 | } el se { | |
| 678 | tasks.subC ontext = r eq.body.su bContext; | |
| 679 | } | |
| 680 | } | |
| 681 | res.rdkS end(tasks) ; | |
| 682 | }) ; | |
| 683 | }; | |
| 684 | ||
| 685 | var ta skInstance Ids = _.pl uck(tasks, 'TASKID') ; | |
| 686 | if (_. isEmpty(ta skInstance Ids)) { | |
| 687 | ex ports.buil dTasksResp onse(tasks , [], req, parameter s, patient Identifier s, functio n(tasks) { | |
| 688 | res.rdkS end(tasks) ; | |
| 689 | }) ; | |
| 690 | } else { | |
| 691 | ex ports.getT asksRoutes (req, task InstanceId s, cb); | |
| 692 | } | |
| 693 | }; | |
| 694 | ||
| 695 | module.exp orts.getTa sksRoutes = function (req, task InstanceId s, routesC allback) { | |
| 696 | var su bQueryMax = 990; | |
| 697 | var da ta = []; | |
| 698 | var ro uteQuery = 'BEGIN ac tivitydb.t asks.getTa skRoutes(: p_task_ins tance_ids, :recordse t); END;'; | |
| 699 | ||
| 700 | var db Config = g etDatabase ConfigFrom Request(re q); | |
| 701 | ||
| 702 | async. whilst( | |
| 703 | fu nction() { | |
| 704 | return t askInstanc eIds.lengt h > 0; | |
| 705 | }, | |
| 706 | fu nction(cal lback) { | |
| 707 | if (!dbC onfig) { | |
| 708 | retu rn callbac k(new RdkE rror({ | |
| 709 | code: 'ora cledb.503. 1001', | |
| 710 | logger: re q.logger | |
| 711 | })); | |
| 712 | } | |
| 713 | ||
| 714 | var inQu eryArr = t askInstanc eIds.splic e(0, subQu eryMax); | |
| 715 | var proc Params = { | |
| 716 | p_ta sk_instanc e_ids: inQ ueryArr.jo in() | |
| 717 | }; | |
| 718 | ||
| 719 | var cb = function( err, rows) { | |
| 720 | if ( err) { | |
| 721 | return cal lback(err) ; | |
| 722 | } | |
| 723 | ||
| 724 | data = _.union (data, row s); | |
| 725 | retu rn callbac k(null); | |
| 726 | }; | |
| 727 | return a ctivityDb. doExecuteP rocWithPar ams(req, d bConfig, r outeQuery, procParam s, cb); | |
| 728 | }, | |
| 729 | fu nction(err ) { | |
| 730 | if (err) { | |
| 731 | req. logger.err or(err); | |
| 732 | retu rn routesC allback(er r); | |
| 733 | } | |
| 734 | ||
| 735 | return r outesCallb ack(null, data); | |
| 736 | } | |
| 737 | ); | |
| 738 | }; | |
| 739 | ||
| 740 | module.exp orts.query TasksbyId = function (req, res) { | |
| 741 | var pa rameters = { | |
| 742 | su bContext: 'all', | |
| 743 | st atus: 'All ', | |
| 744 | ta skId: req. param('tas kid'), | |
| 745 | re moveTask: false | |
| 746 | }; | |
| 747 | if (!p arameters. taskId) { | |
| 748 | va r idError = new Erro r('Unable to retriev e Task ID parameter' ); | |
| 749 | re q.logger.e rror(idErr or); | |
| 750 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message); | |
| 751 | } | |
| 752 | export s.buildTas kQuery(req , res, par ameters); | |
| 753 | }; | |
| 754 | ||
| 755 | module.exp orts.query Tasks = fu nction(req , res) { | |
| 756 | var co ntext = re q.body.con text; | |
| 757 | var id Error; | |
| 758 | ||
| 759 | if (nu llchecker. isNullish( context)) { | |
| 760 | id Error = ne w Error('M issing con text prope rty/value in input J SON.'); | |
| 761 | re q.logger.e rror(idErr or); | |
| 762 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message); | |
| 763 | } | |
| 764 | ||
| 765 | if (co ntext !== 'user' && context != = 'patient ') { | |
| 766 | id Error = ne w Error('I nvalid con text prope rty value in input J SON.'); | |
| 767 | re q.logger.e rror(idErr or); | |
| 768 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message); | |
| 769 | } | |
| 770 | ||
| 771 | var pi d = _.get( req, 'body .pid', nul l); | |
| 772 | if (co ntext === 'patient' && nullche cker.isNul lish(pid)) { | |
| 773 | id Error = ne w Error('M issing pid property/ value in i nput JSON. '); | |
| 774 | re q.logger.e rror(idErr or); | |
| 775 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message); | |
| 776 | } | |
| 777 | ||
| 778 | if (co ntext === 'user') { | |
| 779 | // req.sessio n.facility is eg. PA NORAMA | |
| 780 | va r facility = req.ses sion.user. site; //eg 9E7A | |
| 781 | if (nullchec ker.isNull ish(facili ty)) { | |
| 782 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend('Mis sing requi red parame ter: facil ity'); | |
| 783 | } | |
| 784 | ||
| 785 | va r user = g etJbpmUser (req); | |
| 786 | if (nullchec ker.isNull ish(user)) { | |
| 787 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend('Mis sing requi red parame ter: user' ); | |
| 788 | } | |
| 789 | ||
| 790 | ex ports.buil dTaskQuery (req, res, buildQuer yParameter ObjectFrom Request(re q, null, f acility)); | |
| 791 | ||
| 792 | } else { | |
| 793 | ex ports.buil dTaskQuery (req, res, buildQuer yParameter ObjectFrom Request(re q, null, n ull)); | |
| 794 | } | |
| 795 | req.lo gger.debug ('queryTas ks: Finsih ed queryin g tasks'); | |
| 796 | }; | |
| 797 | ||
| 798 | function b uildQueryP arameterOb jectFromRe quest(req, userTeams , facility ) { | |
| 799 | var pa rameters = {}; | |
| 800 | parame ters.subCo ntext = 'a ll'; | |
| 801 | ||
| 802 | if (nu llchecker. isNotNulli sh(req) && nullcheck er.isNotNu llish(req. body)) { | |
| 803 | if (nullchec ker.isNotN ullish(use rTeams)) { | |
| 804 | paramete rs.userTea ms = userT eams; | |
| 805 | } | |
| 806 | ||
| 807 | if (nullchec ker.isNotN ullish(fac ility)) { | |
| 808 | paramete rs.facilit y = facili ty; | |
| 809 | } | |
| 810 | ||
| 811 | if (nullchec ker.isNotN ullish(req .body.pid) ) { | |
| 812 | paramete rs.patient ICN = req. body.pid; | |
| 813 | } | |
| 814 | ||
| 815 | if (nullchec ker.isNotN ullish(req .body.stat us)) { | |
| 816 | paramete rs.status = req.body .status; | |
| 817 | } | |
| 818 | ||
| 819 | if (nullchec ker.isNotN ullish(req .body.subC ontext)) { | |
| 820 | paramete rs.subCont ext = req. body.subCo ntext.toLo werCase(); | |
| 821 | } | |
| 822 | ||
| 823 | if (nullchec ker.isNotN ullish(req .body.star tDate)) { | |
| 824 | paramete rs.startDa te = momen t(req.body .startDate , 'YYYYMMD DHHmmss'). toDate(); | |
| 825 | } | |
| 826 | ||
| 827 | if (nullchec ker.isNotN ullish(req .body.endD ate)) { | |
| 828 | paramete rs.endDate = moment( req.body.e ndDate, 'Y YYYMMDDHHm mss').toDa te(); | |
| 829 | } | |
| 830 | ||
| 831 | ||
| 832 | va r pii = re q.body.pro cessInstan ceId; | |
| 833 | if (nullchec ker.isNotN ullish(pii ) && | |
| 834 | typeof p ii === 'nu mber' && | |
| 835 | isFinite (pii) && | |
| 836 | pii === Math.floor (pii)) { | |
| 837 | paramete rs.process InstanceId = pii; | |
| 838 | } | |
| 839 | ||
| 840 | if (nullchec ker.isNotN ullish(req .body.prio rity)) { | |
| 841 | paramete rs.priorit y = req.bo dy.priorit y; | |
| 842 | } | |
| 843 | } | |
| 844 | ||
| 845 | return parameter s; | |
| 846 | } | |
| 847 | ||
| 848 | module.exp orts.build TaskQuery = function (req, res, parameter s) { | |
| 849 | var db Config = g etDatabase ConfigFrom Request(re q); | |
| 850 | if (!d bConfig) { | |
| 851 | va r configEr ror = new RdkError({ | |
| 852 | code: 'o racledb.50 3.1001', | |
| 853 | logger: req.logger | |
| 854 | }) ; | |
| 855 | re turn res.s tatus(conf igError.st atus).rdkS end(config Error); | |
| 856 | } | |
| 857 | ||
| 858 | var pa tientIdent ifiers = n ull; | |
| 859 | var pr epFunction s = []; | |
| 860 | ||
| 861 | var cb = functio n(err, row s) { | |
| 862 | if (err) { | |
| 863 | req.logg er.error(e rr); | |
| 864 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend(err) ; | |
| 865 | } | |
| 866 | va r tasks = rows[0]; | |
| 867 | va r potentia lOwners = rows[1]; | |
| 868 | ex ports.buil dTasksResp onse(tasks , potentia lOwners, r eq, parame ters, pati entIdentif iers, func tion(tasks ) { | |
| 869 | if (null checker.is NotNullish (req.body) && nullch ecker.isNo tNullish(r eq.body.su bContext)) { | |
| 870 | if ( nullchecke r.isNotNul lish(tasks .data)) { | |
| 871 | tasks.data .subContex t = req.bo dy.subCont ext; | |
| 872 | } el se { | |
| 873 | tasks.subC ontext = r eq.body.su bContext; | |
| 874 | } | |
| 875 | } | |
| 876 | res.rdkS end(tasks) ; | |
| 877 | }) ; | |
| 878 | }; | |
| 879 | ||
| 880 | var pa tientICN = parameter s.patientI CN; | |
| 881 | ||
| 882 | if (nu llchecker. isNotNulli sh(patient ICN) && re q.body.con text === ' patient') { | |
| 883 | ||
| 884 | va r prepareP atientIden tifiers = function(c allback) { | |
| 885 | //gather all avail able User IDs for th is patient | |
| 886 | exports. callJpid(r eq, patien tICN, func tion(err, response, results) { | |
| 887 | if ( err) { | |
| 888 | req.logger .error(err ); | |
| 889 | patientIde ntifiers = [patientI CN]; | |
| 890 | } el se { | |
| 891 | patientIde ntifiers = _.get(res ults, 'pat ientIdenti fiers') || null; | |
| 892 | patientIde ntifiers = filterIde ntifiers(p atientIden tifiers); | |
| 893 | if (!patie ntIdentifi ers || !Ar ray.isArra y(patientI dentifiers ) || patie ntIdentifi ers.length < 1) { | |
| 894 | patien tIdentifie rs = [pati entICN]; | |
| 895 | } | |
| 896 | } | |
| 897 | retu rn callbac k(null, pa tientIdent ifiers); | |
| 898 | }); | |
| 899 | }; | |
| 900 | ||
| 901 | pr epFunction s.push(pre parePatien tIdentifie rs); | |
| 902 | } | |
| 903 | ||
| 904 | async. series(pre pFunctions , function (err, resu lts) { | |
| 905 | va r stationN umber = re q.session. user.divis ion; | |
| 906 | va r user_id = getJbpmU ser(req); | |
| 907 | va r staff_id = user_id ; | |
| 908 | if (staff_id .indexOf(' ;') !== -1 ) { | |
| 909 | staff_id = staff_i d.substrin g(staff_id .indexOf(' ;') + 1); | |
| 910 | } | |
| 911 | ||
| 912 | va r procPara ms = { | |
| 913 | p_task_s tatuses: p arameters. status, | |
| 914 | p_proces s_instance _id: param eters.proc essInstanc eId || nul l, | |
| 915 | p_priori ty: parame ters.prior ity || nul l, | |
| 916 | p_task_i nstance_id : paramete rs.taskId || null, | |
| 917 | p_start_ date: para meters.sta rtDate ? { | |
| 918 | val: parameter s.startDat e, | |
| 919 | dir: oracledb. BIND_IN, | |
| 920 | type : oracledb .DATE | |
| 921 | } : null , | |
| 922 | p_end_da te: parame ters.endDa te ? { | |
| 923 | val: parameter s.endDate, | |
| 924 | dir: oracledb. BIND_IN, | |
| 925 | type : oracledb .DATE | |
| 926 | } : null , | |
| 927 | p_patien t_identifi ers: null, | |
| 928 | p_resolu tion_state : 0, | |
| 929 | p_max_sa lience: 4, | |
| 930 | p_ntf_us er_id: nul l | |
| 931 | ||
| 932 | ||
| 933 | }; | |
| 934 | ||
| 935 | va r taskQuer y = 'BEGIN activityd b.tasks.ge tAllTasks( :p_task_st atuses, :p _process_i nstance_id , :p_prior ity, :p_ta sk_instanc e_id, :p_s tart_date, :p_end_da te, :p_pat ient_ident ifiers, :p _resolutio n_state, : p_max_sali ence, :p_n tf_user_id , :records et, :recor dset2); EN D;'; | |
| 936 | ||
| 937 | if (paramete rs.subCont ext === 't eams' || p arameters. subContext === 'team roles') { | |
| 938 | procPara ms.p_staff _id = staf f_id; | |
| 939 | procPara ms.p_stati on_number = stationN umber; | |
| 940 | if (para meters.sub Context == = 'teams') { | |
| 941 | task Query = 'B EGIN activ itydb.task s.getTasks ForTeams(: p_staff_id , :p_stati on_number, :p_task_s tatuses, : p_process_ instance_i d, :p_prio rity, :p_t ask_instan ce_id, :p_ start_date , :p_end_d ate, :p_pa tient_iden tifiers, : p_resoluti on_state, :p_max_sal ience, :p_ ntf_user_i d, :record set, :reco rdset2); E ND;'; | |
| 942 | //pa tient:team s -- Show me tasks t hat are ro uted to my teams | |
| 943 | } else i f (paramet ers.subCon text === ' teamroles' ) { | |
| 944 | //pa tient:me - - Show me tasks that are route d to me (e ither dire ctly to me or via te am/role ro uting) | |
| 945 | proc Params.p_u ser_id = u ser_id; | |
| 946 | proc Params.p_f acility = null; | |
| 947 | task Query = 'B EGIN activ itydb.task s.getTasks ForTeamRol es(:p_user _id, :p_st aff_id, :p _station_n umber, :p_ facility, :p_task_st atuses, :p _process_i nstance_id , :p_prior ity, :p_ta sk_instanc e_id, :p_s tart_date, :p_end_da te, :p_pat ient_ident ifiers, :p _resolutio n_state, : p_max_sali ence, :p_n tf_user_id , :records et, :recor dset2); EN D;'; | |
| 948 | } | |
| 949 | } | |
| 950 | ||
| 951 | if (req.body .context = == 'user') { | |
| 952 | if (para meters.sub Context == = 'teamrol es') { | |
| 953 | //fa cility-bro adcast mes sages - sh ow only in staff vie w | |
| 954 | proc Params.p_f acility = parameters .facility || null; | |
| 955 | } | |
| 956 | } else if (r eq.body.co ntext === 'patient') { | |
| 957 | if (null checker.is NotNullish (patientId entifiers) ) { | |
| 958 | proc Params.p_p atient_ide ntifiers = patientId entifiers. join(','); | |
| 959 | } | |
| 960 | } | |
| 961 | ||
| 962 | re q.logger.d ebug('task -operation -resource: buildTaskQ uery taskQ uery %s', taskQuery) ; | |
| 963 | re q.logger.d ebug('task -operation -resource: buildTaskQ uery proc parameters :', procPa rams); | |
| 964 | ||
| 965 | // notificati ons | |
| 966 | pr ocParams.p _ntf_user_ id = null; | |
| 967 | if (req.sess ion.user & & req.sess ion.user.s ite && req .session.u ser.duz) { | |
| 968 | var user = req.ses sion.user; | |
| 969 | var user Id = user. duz[user.s ite]; | |
| 970 | if (!nul lchecker.i sNullish(u ser.site) || !nullch ecker.isNu llish(user Id)) { | |
| 971 | proc Params.p_n tf_user_id = user.si te + ';' + userId; | |
| 972 | } | |
| 973 | } | |
| 974 | re turn activ ityDb.doEx ecuteProcM ultipleRec ordSets(re q, dbConfi g, taskQue ry, procPa rams, cb); | |
| 975 | ||
| 976 | }); | |
| 977 | }; | |
| 978 | ||
| 979 | function b uildChange TaskStateR esponse(re q, res, er r, result) { | |
| 980 | if (er r) { | |
| 981 | re q.logger.e rror(err); | |
| 982 | re s.status(r dk.httpsta tus.bad_re quest).rdk Send(err); | |
| 983 | } | |
| 984 | ||
| 985 | var re sultJson; | |
| 986 | try { | |
| 987 | re sultJson = JSON.pars e(result); | |
| 988 | } catc h (e) { | |
| 989 | // ignore | |
| 990 | } | |
| 991 | ||
| 992 | if (re sultJson) { | |
| 993 | re turn res.r dkSend('Su ccess'); | |
| 994 | } | |
| 995 | ||
| 996 | parseS tring(resu lt, functi on(err, re sultJson) { | |
| 997 | if (err) { | |
| 998 | req.logg er.error(r esult); | |
| 999 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend('Inv alid error XML recei ved(' + er r + ')'); | |
| 1000 | } | |
| 1001 | ||
| 1002 | va r exceptio n; | |
| 1003 | if (resultJs on['comman d-response ']) { | |
| 1004 | if (resu ltJson['co mmand-resp onse'].exc eption) { | |
| 1005 | exce ption = re sultJson[' command-re sponse'].e xception[0 ]; | |
| 1006 | } | |
| 1007 | } else { | |
| 1008 | exceptio n = result Json.excep tion; | |
| 1009 | } | |
| 1010 | ||
| 1011 | if (exceptio n) { | |
| 1012 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend(exce ption.mess age[0]); | |
| 1013 | } | |
| 1014 | ||
| 1015 | re turn res.r dkSend('Su ccess'); | |
| 1016 | }); | |
| 1017 | } | |
| 1018 | ||
| 1019 | function h andleCompl ete(req, r es) { | |
| 1020 | ||
| 1021 | var de ploymentId = req.par am('deploy mentId') | | null; | |
| 1022 | var id Error; | |
| 1023 | if (!d eploymentI d) { | |
| 1024 | id Error = ne w Error('M issing dep loymentId property/v alue in in put JSON.' ); | |
| 1025 | re q.logger.e rror(idErr or); | |
| 1026 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message); | |
| 1027 | } | |
| 1028 | ||
| 1029 | var ta skId = req .param('ta skid'); | |
| 1030 | ||
| 1031 | var co nfig = get GenericJbp mConfig(re q); | |
| 1032 | ||
| 1033 | var ur i = uriBui lder.fromU ri(config. url) | |
| 1034 | .p ath('/exec ute') | |
| 1035 | .b uild(); | |
| 1036 | ||
| 1037 | config .url = uri ; | |
| 1038 | config .json = fa lse; | |
| 1039 | if (!c onfig.head ers) { | |
| 1040 | co nfig.heade rs = {}; | |
| 1041 | } | |
| 1042 | ||
| 1043 | config .headers[' Content-Ty pe'] = 'ap plication/ xml'; | |
| 1044 | config .headers.A ccept = 'a pplication /xml'; | |
| 1045 | config .headers[' Kie-Deploy ment-Id'] = deployme ntId; | |
| 1046 | ||
| 1047 | ||
| 1048 | async. parallel([ | |
| 1049 | ||
| 1050 | fu nction(cal lback) { | |
| 1051 | var comp leteTaskCo mmandXml; | |
| 1052 | var comp leteTaskCo mmandTempl ateXml = x mlTemplate s.complete TaskComman dTemplate; | |
| 1053 | var user = getJbpm User(req); | |
| 1054 | ||
| 1055 | complete TaskComman dXml = com pleteTaskC ommandTemp lateXml.re place('{De ploymentId }', deploy mentId).re place('{Ta skId}', ta skId).repl ace('{User }', user); | |
| 1056 | callback (null, com pleteTaskC ommandXml) ; | |
| 1057 | }, | |
| 1058 | fu nction(cal lback) { | |
| 1059 | var task Parameters XML = ''; | |
| 1060 | var item sList = '' ; | |
| 1061 | if (req. body.param eter) { | |
| 1062 | var primitiveT ypeXML = x mlTemplate s.paramete rTemplate; | |
| 1063 | var complexObj ectXML = x mlTemplate s.complexO bjectTempl ate; | |
| 1064 | var complexObj ectPropert iesXML = x mlTemplate s.complexO bjectPrope rtiesXML; | |
| 1065 | var complexArr ayedObject Properties XML = xmlT emplates.c omplexArra yedObjectP ropertiesX ML; | |
| 1066 | ||
| 1067 | _.ea ch(req.bod y.paramete r, functio n(value, k ey) { | |
| 1068 | var type = typeof va lue; | |
| 1069 | //**** Par ent Contai ner Object | |
| 1070 | if (type = == 'object ') { | |
| 1071 | var ob jectItems = value; | |
| 1072 | taskPa rametersXM L = taskPa rametersXM L + comple xObjectXML .replace(' {Key}', ke y); | |
| 1073 | _.each (objectIte ms, functi on(value, key) { | |
| 1074 | ty pe = typeo f value; | |
| 1075 | if (key === 'objectTyp e') { | |
| 1076 | taskPara metersXML = taskPara metersXML. replace('{ Type}', va lue); | |
| 1077 | } else { | |
| 1078 | if (type === 'obje ct') { | |
| 1079 | var objectItem sXML = ''; | |
| 1080 | var id = 0; | |
| 1081 | if ( value !== null && va lue.constr uctor === Array) { | |
| 1082 | for (var i = 0; i < value.leng th; i++) { | |
| 1083 | id = i + 1; | |
| 1084 | itemsL ist = item sList + co mplexArray edObjectPr opertiesXM L.replace( /{Key}/g, key).repla ce(/{ID}/, id).repla ce('{Value }', proces sValue(val ue[i], obj ectItemsXM L)); | |
| 1085 | } | |
| 1086 | } el se { | |
| 1087 | itemsList = itemsLis t + comple xObjectPro pertiesXML .replace(/ {Key}/g, k ey).replac e('{Value} ', process JsonObject (value, ob jectItemsX ML)); | |
| 1088 | } | |
| 1089 | } else { | |
| 1090 | item sList = it emsList + complexObj ectPropert iesXML.rep lace(/{Key }/g, key). replace('{ Value}', w rapValueIn CData(valu e)); | |
| 1091 | } | |
| 1092 | } | |
| 1093 | }); | |
| 1094 | taskPa rametersXM L = taskPa rametersXM L.replace( '{Value}', itemsList ); | |
| 1095 | } else { | |
| 1096 | taskPa rametersXM L = taskPa rametersXM L + primit iveTypeXML .replace(' {Key}', ke y).replace ('{Type}', type).rep lace('{Val ue}', wrap ValueInCDa ta(value)) ; | |
| 1097 | } | |
| 1098 | }); | |
| 1099 | } | |
| 1100 | callback (null, tas kParameter sXML); | |
| 1101 | } | |
| 1102 | ], fun ction(err, results) { | |
| 1103 | ||
| 1104 | if (err) { | |
| 1105 | req.logg er.error(e rr); | |
| 1106 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend(err) ; | |
| 1107 | } | |
| 1108 | ||
| 1109 | va r complete TaskComman dXml = res ults[0].re place('{Pa rameters}' , results[ 1]); | |
| 1110 | co nfig.body = complete TaskComman dXml; | |
| 1111 | ht tpUtil.pos t(config, function(e rr, respon se, result ) { | |
| 1112 | return b uildChange TaskStateR esponse(re q, res, er r, result) ; | |
| 1113 | }) ; | |
| 1114 | }); | |
| 1115 | } | |
| 1116 | ||
| 1117 | function c hangeTaskS tate(req, res) { | |
| 1118 | req.au dit.dataDo main = 'Ta sks'; | |
| 1119 | req.au dit.logCat egory = 'C HANGE_TASK _STATE'; | |
| 1120 | ||
| 1121 | // JBP M endpoint : /task/{t askID}/{st ate} | |
| 1122 | //stat e: | |
| 1123 | // ac tivate | |
| 1124 | // cl aim | |
| 1125 | // cl aimnextava ilable | |
| 1126 | // co mplete | |
| 1127 | // de legate | |
| 1128 | // ex it | |
| 1129 | // fa il | |
| 1130 | // fo rward | |
| 1131 | // no minate | |
| 1132 | // re lease | |
| 1133 | // re sume | |
| 1134 | // sk ip | |
| 1135 | // st art | |
| 1136 | // st op | |
| 1137 | // su spend | |
| 1138 | // par ameters: | |
| 1139 | // pa rameters m ay be need ed to comp lete task | |
| 1140 | ||
| 1141 | var ta skId = req .param('ta skid'); | |
| 1142 | var ne wState = r eq.param(' state'); | |
| 1143 | ||
| 1144 | var id Error; | |
| 1145 | ||
| 1146 | if (!t askId) { | |
| 1147 | id Error = ne w Error('U nable to r etrieve Ta sk ID para meter'); | |
| 1148 | re q.logger.e rror(idErr or); | |
| 1149 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message); | |
| 1150 | } | |
| 1151 | ||
| 1152 | if (!n ewState) { | |
| 1153 | id Error = ne w Error('U nable to r etrieve Ta sk New Sta te paramet er'); | |
| 1154 | re q.logger.e rror(idErr or); | |
| 1155 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message); | |
| 1156 | } | |
| 1157 | ||
| 1158 | //fetc h task by taskId and validate the attemp ted state change | |
| 1159 | return validateC hangeState Attempt(re q, taskId, function( err, isVal id) { | |
| 1160 | if (err) { | |
| 1161 | req.logg er.error({ | |
| 1162 | erro r: err | |
| 1163 | }, 'task -operation s-resource :changeTas kState err or executi ng validat eChangeSta teAttempt' ); | |
| 1164 | var chan geError = new RdkErr or({ | |
| 1165 | code : 'oracled b.400.1001 ', | |
| 1166 | logg er: req.lo gger | |
| 1167 | }); | |
| 1168 | return r es.status( changeErro r.status). rdkSend(ch angeError) ; | |
| 1169 | } | |
| 1170 | ||
| 1171 | if (!isValid ) { | |
| 1172 | var vali dationErro r = new Rd kError({ | |
| 1173 | code : 'jbpm.40 3.1001', | |
| 1174 | logg er: req.lo gger | |
| 1175 | }); | |
| 1176 | return r es.status( validation Error.stat us).rdkSen d(validati onError); | |
| 1177 | } | |
| 1178 | ||
| 1179 | if (newState .toLowerCa se() === ' complete') { | |
| 1180 | return h andleCompl ete(req, r es); | |
| 1181 | } | |
| 1182 | ||
| 1183 | va r config = getGeneri cJbpmConfi g(req); | |
| 1184 | ||
| 1185 | va r builder = uriBuild er.fromUri (config.ur l) | |
| 1186 | .path('/ task/' + t askId + '/ ' + newSta te); | |
| 1187 | ||
| 1188 | va r uri = bu ilder.buil d(); | |
| 1189 | co nfig.url = uri; | |
| 1190 | co nfig.json = false; | |
| 1191 | ||
| 1192 | ht tpUtil.pos t(config, function(e rr, respon se, result ) { | |
| 1193 | return b uildChange TaskStateR esponse(re q, res, er r, result) ; | |
| 1194 | }) ; | |
| 1195 | }); | |
| 1196 | } | |
| 1197 | ||
| 1198 | /** | |
| 1199 | * Perform logic to validate a task stat e change | |
| 1200 | * | |
| 1201 | * @param {any} req The reques t object | |
| 1202 | * @param {number} t askId The ID of the task attem pting to c hange stat e | |
| 1203 | * @param {function} callback Returns er ror or boo lean value indicatin g whether task can c hange stat e | |
| 1204 | */ | |
| 1205 | function v alidateCha ngeStateAt tempt(req, taskId, c allback) { | |
| 1206 | var db Config = g etDatabase ConfigFrom Request(re q); | |
| 1207 | if (!d bConfig) { | |
| 1208 | re turn callb ack(new Rd kError({ | |
| 1209 | code: 'o racledb.50 3.1001', | |
| 1210 | logger: req.logger | |
| 1211 | }) ); | |
| 1212 | } | |
| 1213 | ||
| 1214 | var pr ocParams = { | |
| 1215 | p_ task_defin ition_id: null, | |
| 1216 | p_ task_insta nce_id: ta skId, | |
| 1217 | p_ patient_id entifiers: null, | |
| 1218 | p_ task_statu ses: null | |
| 1219 | }; | |
| 1220 | ||
| 1221 | var qu ery = 'BEG IN activit ydb.tasks. getTasksBy Ids(:p_tas k_definiti on_id, :p_ task_insta nce_id, :p _patient_i dentifiers , :p_task_ statuses, :recordset ); END;'; | |
| 1222 | req.lo gger.trace ({ | |
| 1223 | qu ery: query , | |
| 1224 | pa rams: proc Params | |
| 1225 | }, 'ta sk-operati ons-resour ce:validat eChangeSta teAttempt querying f or task'); | |
| 1226 | activi tyDb.doExe cuteProcWi thParams(r eq, dbConf ig, query, procParam s, functio n(err, res ults) { | |
| 1227 | if (err) { | |
| 1228 | return c allback(er r); | |
| 1229 | } | |
| 1230 | ||
| 1231 | va r beforeEa rliestDate = _.get(r esults, '[ 0].BEFOREE ARLIESTDAT E', undefi ned); | |
| 1232 | va r earliest Date = _.g et(results , '[0].DUE ', undefin ed); | |
| 1233 | ||
| 1234 | if (_.isUnde fined(befo reEarliest Date) || ! (earliestD ate instan ceof Date) ) { | |
| 1235 | var defi nitionErro r = Error( 'Unable to retrieve required v alues to e xecute val idateChang eStateAtte mpt'); | |
| 1236 | return c allback(de finitionEr ror); | |
| 1237 | } | |
| 1238 | ||
| 1239 | va r isValid = checkEar liestDate( Boolean(be foreEarlie stDate), e arliestDat e); | |
| 1240 | if (!isValid ) { | |
| 1241 | req.logg er.warn({ | |
| 1242 | earl iestDate: earliestDa te, | |
| 1243 | befo reEarliest Date: befo reEarliest Date | |
| 1244 | }, 'task -operation s-resource :validateC hangeState Attempt di sallowing task state change du e to befor eEarliestD ate'); | |
| 1245 | } | |
| 1246 | ||
| 1247 | re turn callb ack(null, isValid); | |
| 1248 | }); | |
| 1249 | } | |
| 1250 | ||
| 1251 | function c heckEarlie stDate(bef oreEarlies tDate, ear liestDate) { | |
| 1252 | if (be foreEarlie stDate) { | |
| 1253 | re turn true; | |
| 1254 | } | |
| 1255 | ||
| 1256 | //task should no t be chang ed before earliestDa te | |
| 1257 | var to day = new Date(); | |
| 1258 | var im preciseTod ay = new D ate(today. getFullYea r(), today .getMonth( ), today.g etDate(), 23, 59, 59 , 999); | |
| 1259 | if (ea rliestDate .getTime() > impreci seToday.ge tTime()) { | |
| 1260 | re turn false ; | |
| 1261 | } | |
| 1262 | ||
| 1263 | return true; | |
| 1264 | } | |
| 1265 | ||
| 1266 | module.exp orts.getCu rrentTask = function (req, res) { | |
| 1267 | // Tak es an proc ess Instan ce ID | |
| 1268 | // Ret urns the c urrent tas k for that process/a ctivity, i ncluding: taskID, ta skType (Hu man or Sys tem), and task state . | |
| 1269 | req.au dit.dataDo main = 'Ta sks'; | |
| 1270 | req.au dit.logCat egory = 'G ET_CURRENT _TASK'; | |
| 1271 | ||
| 1272 | var pa rameters = buildQuer yParameter ObjectFrom Request(re q, null); | |
| 1273 | var pr ocessInsta nceIdError ; | |
| 1274 | if (nu llchecker. isNullish( parameters .processIn stanceId)) { | |
| 1275 | pr ocessInsta nceIdError = new Err or('Missin g processI nstanceId value in i nput JSON. '); | |
| 1276 | re q.logger.e rror(proce ssInstance IdError); | |
| 1277 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(processI nstanceIdE rror.messa ge); | |
| 1278 | } | |
| 1279 | ||
| 1280 | parame ters.statu s = 'Ready ,Reserved, InProgress '; | |
| 1281 | ||
| 1282 | export s.buildTas kQuery(req , res, par ameters); | |
| 1283 | }; | |
| 1284 | ||
| 1285 | function g etTask(req , res) { | |
| 1286 | // Tak es an Task ID | |
| 1287 | // Ret urns the d etails of the task w ith that i d, includi ng: taskID , taskType (Human or System), and task s tate etc. | |
| 1288 | req.au dit.dataDo main = 'Ta sks'; | |
| 1289 | req.au dit.logCat egory = 'G ET_TASK'; | |
| 1290 | ||
| 1291 | var ta skId = req .param('ta skid'); | |
| 1292 | var id Error; | |
| 1293 | ||
| 1294 | if (!t askId) { | |
| 1295 | id Error = ne w Error('U nable to r etrieve \' taskid\' p arameter') ; | |
| 1296 | re q.logger.e rror(idErr or); | |
| 1297 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message); | |
| 1298 | } | |
| 1299 | ||
| 1300 | var db Config = g etDatabase ConfigFrom Request(re q); | |
| 1301 | if (!d bConfig) { | |
| 1302 | va r configEr ror = new RdkError({ | |
| 1303 | code: 'o racledb.50 3.1001', | |
| 1304 | logger: req.logger | |
| 1305 | }) ; | |
| 1306 | re turn res.s tatus(conf igError.st atus).rdkS end(config Error); | |
| 1307 | } | |
| 1308 | ||
| 1309 | var co nfig = get GenericJbp mConfig(re q); | |
| 1310 | ||
| 1311 | var ur i = uriBui lder.fromU ri('/tasks service'). path('/tas k/' + task Id); | |
| 1312 | ||
| 1313 | config .url = uri .build(); | |
| 1314 | async. parallel({ | |
| 1315 | jb pmTask: fu nction(cal lback) { | |
| 1316 | httpUtil .get(confi g, functio n(err, res ponse, ret urnedData) { | |
| 1317 | if ( err) { | |
| 1318 | return cal lback(err) ; | |
| 1319 | } | |
| 1320 | if ( returnedDa ta && retu rnedData.d ata && ret urnedData. data.items && return edData.dat a.items.le ngth > 0 & & returned Data.data. items[0].h asOwnPrope rty('actua l-owner') && !nullch ecker.isNu llish(retu rnedData.d ata.items[ 0]['actual -owner'])) { | |
| 1321 | returnedDa ta.data.it ems[0].act ualOwnerNa me = undef ined; | |
| 1322 | var jdsPat h = '/data /urn:va:us er:'; | |
| 1323 | jdsPath += returnedD ata.data.i tems[0]['a ctual-owne r'].replac e(';', ':' ); | |
| 1324 | ||
| 1325 | var option s = _.exte nd({}, req .app.confi g.jdsServe r, { | |
| 1326 | url: j dsPath, | |
| 1327 | logger : req.logg er, | |
| 1328 | json: true | |
| 1329 | }); | |
| 1330 | ||
| 1331 | httpUtil.g et(options , function (err, resp onse, data ) { | |
| 1332 | if (er r) { | |
| 1333 | re turn callb ack(err); | |
| 1334 | } | |
| 1335 | if (!n ullchecker .isNullish (_.get(dat a, 'data.i tems[0].na me'))) { | |
| 1336 | re turnedData .data.item s[0].actua lOwnerName = data.da ta.items[0 ].name; | |
| 1337 | } | |
| 1338 | return callback( null, retu rnedData); | |
| 1339 | }); | |
| 1340 | } el se { | |
| 1341 | return cal lback(null , returned Data); | |
| 1342 | } | |
| 1343 | }); | |
| 1344 | }, | |
| 1345 | db Task: func tion(callb ack) { | |
| 1346 | var proc Params = { | |
| 1347 | p_ta sk_definit ion_id: nu ll, | |
| 1348 | p_ta sk_instanc e_id: task Id, | |
| 1349 | p_pa tient_iden tifiers: n ull, | |
| 1350 | p_ta sk_statuse s: null | |
| 1351 | }; | |
| 1352 | ||
| 1353 | var quer y = 'BEGIN activityd b.tasks.ge tTasksById s(:p_task_ definition _id, :p_ta sk_instanc e_id, :p_p atient_ide ntifiers, :p_task_st atuses, :r ecordset); END;'; | |
| 1354 | activity Db.doExecu teProcWith Params(req , dbConfig , query, p rocParams, callback) ; | |
| 1355 | } | |
| 1356 | }, fun ction(err, results) { | |
| 1357 | if (err) { | |
| 1358 | req.logg er.error(e rr); | |
| 1359 | return r es.status( rdk.httpst atus.not_f ound).rdkS end(err); | |
| 1360 | } | |
| 1361 | ||
| 1362 | if (_.size(_ .get(resul ts, 'jbpmT ask.data.i tems')) < 1 || _.siz e(_.get(re sults, 'db Task')) < 1 || | |
| 1363 | _.isUnde fined(resu lts.dbTask [0].STATUS TIMESTAMP) || _.isNu ll(results .dbTask[0] .STATUSTIM ESTAMP)) { | |
| 1364 | return r es.status( rdk.httpst atus.not_f ound).rdkS end(err); | |
| 1365 | } | |
| 1366 | ||
| 1367 | if (_.size(_ .get(resul ts, 'jbpmT ask.data.i tems')) > 0 && _.siz e(_.get(re sults, 'db Task')) > 0 && | |
| 1368 | nullchec ker.isNotN ullish(res ults.dbTas k[0].STATU STIMESTAMP )) { | |
| 1369 | var task = results .dbTask[0] ; | |
| 1370 | task.PER MISSION = parsePermi ssions(tas k, req) || {}; | |
| 1371 | ||
| 1372 | //Check if the use r has the permission s required by the ta sk | |
| 1373 | return h asPermissi ons(task, req, funct ion taskOp Callback(t ask) { | |
| 1374 | resu lts.jbpmTa sk.data.it ems[0].has Permission s = task.h asPermissi ons; | |
| 1375 | resu lts.jbpmTa sk.data.it ems[0].sta tusTimeSta mp = resul ts.dbTask[ 0].STATUST IMESTAMP.g etTime(); | |
| 1376 | resu lts.jbpmTa sk.data.it ems[0].bef oreEarlies tDate = Bo olean(_.ge t(results, 'dbTask[0 ].BEFOREEA RLIESTDATE ')); | |
| 1377 | ||
| 1378 | //th e followin g mappings were adde d to keep the UI bac kward comp atible | |
| 1379 | var extraAttri butes = { | |
| 1380 | 'actual-ow ner': 'act ualOwnerId ', | |
| 1381 | 'created-b y': 'creat edById', | |
| 1382 | 'created-o n': 'creat edOn', | |
| 1383 | 'activatio n-time': ' activation Time', | |
| 1384 | 'expiratio n-time': ' expiration Time', | |
| 1385 | 'process-i nstance-id ': 'proces sInstanceI d', | |
| 1386 | 'process-i d': 'proce ssId', | |
| 1387 | 'process-s ession-id' : 'process SessionId' , | |
| 1388 | 'deploymen t-id': 'de ploymentId ', | |
| 1389 | 'quick-tas k-summary' : 'quickTa skSummary' , | |
| 1390 | 'parentId' : 'parent- id' | |
| 1391 | }; | |
| 1392 | var items = _. get(result s, 'jbpmTa sk.data.it ems[0]'); | |
| 1393 | _.ea ch(extraAt tributes, function(v alue, key) { | |
| 1394 | if (_.has( items, key )) { | |
| 1395 | items[ value] = i tems[key]; | |
| 1396 | } | |
| 1397 | }); | |
| 1398 | ||
| 1399 | retu rn res.rdk Send(resul ts.jbpmTas k.data); | |
| 1400 | }); | |
| 1401 | } | |
| 1402 | ||
| 1403 | re turn res.s tatus(rdk. httpstatus .not_found ).rdkSend( err); | |
| 1404 | }); | |
| 1405 | } | |
| 1406 | ||
| 1407 | function p arsePermis sions(task , req) { | |
| 1408 | try { | |
| 1409 | re turn JSON. parse(task .PERMISSIO N); | |
| 1410 | } catc h (e) { | |
| 1411 | re q.logger.e rror('Erro r while pa rsing the permission s for a ta sk: ' + e + '\n' + t ask); | |
| 1412 | re turn false ; | |
| 1413 | } | |
| 1414 | } | |
| 1415 | ||
| 1416 | function h asPermissi ons(task, req, callb ack) { | |
| 1417 | task.h asPermissi ons = fals e; | |
| 1418 | ||
| 1419 | var mo ckRequest = { | |
| 1420 | _r esourceCon figItem: { | |
| 1421 | required Permission s: _.get(t ask, 'PERM ISSION.ehm p') | |
| 1422 | }, | |
| 1423 | lo gger: _.ge t(req, 'lo gger'), | |
| 1424 | se ssion: { | |
| 1425 | user: _. get(req, ' session.us er') | |
| 1426 | } | |
| 1427 | }; | |
| 1428 | ||
| 1429 | pepSub system.exe cute(mockR equest, {} , function taskOpCal lback(err) { | |
| 1430 | ta sk.hasPerm issions = !err; | |
| 1431 | re turn callb ack(task); | |
| 1432 | }); | |
| 1433 | } | |
| 1434 | ||
| 1435 | module.exp orts.hasPe rmissions = hasPermi ssions; | |
| 1436 | module.exp orts.chang eTaskState = changeT askState; | |
| 1437 | module.exp orts.getTa sk = getTa sk; | |
| 1438 | module.exp orts.check EarliestDa te = check EarliestDa te; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.