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\cds-work-product | cds-work-product.js | Fri Aug 25 15:36:55 2017 UTC |
| 2 | rdk.zip\rdk\product\production\rdk\src\resources\cds-work-product | cds-work-product.js | Tue Oct 3 17:16:36 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 2332 |
| 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('. ./../core/ rdk'); | |
| 4 | var http = rdk.utils .http; | |
| 5 | var nullch ecker = rd k.utils.nu llchecker; | |
| 6 | var async = require( 'async'); | |
| 7 | var _ = re quire('lod ash'); | |
| 8 | var Object Id = requi re('mongod b').Object ID; | |
| 9 | var testId = require ('../../ut ils/mongo- utils').va lidateMong oDBId; | |
| 10 | ||
| 11 | var dbName = 'work'; | |
| 12 | var workCo llection = 'work'; | |
| 13 | var subscr iptionColl ection = ' subscripti ons'; | |
| 14 | ||
| 15 | ||
| 16 | /** | |
| 17 | * Special ty Codes ( snomed) | |
| 18 | */ | |
| 19 | var SPECIA LTY = { | |
| 20 | ALLERG Y: 4084390 02, | |
| 21 | CRITIC AL_CARE: 4 08478003, | |
| 22 | DERMAT OLOGY: 394 582007, | |
| 23 | ENDOCR INOLOGY: 3 94582007, | |
| 24 | FAMILY _MEDICINE: 419772000 , | |
| 25 | GASTRO ENTEROLOGY : 39458400 8, | |
| 26 | GENERA L_SURGERY: 394294004 , | |
| 27 | HEMATO LOGY_AND_O NCOLOGY: 3 94916005, | |
| 28 | INTERN AL_MEDCINE : 41919200 3, | |
| 29 | NEONAT OLOGY: 408 445005, | |
| 30 | NEUROL OGY: 56397 003, | |
| 31 | OBGYN: 309367003 , | |
| 32 | OPHTHA LMOLOGY: 3 94813003, | |
| 33 | RHEUMA TOLOGY: 39 4810000 | |
| 34 | }; | |
| 35 | ||
| 36 | var allSpe cialties = _.values( SPECIALTY) ; | |
| 37 | ||
| 38 | var defaul tSubscript ions = { | |
| 39 | specia lty: allSp ecialties, | |
| 40 | priori ty: 'ALL', // Values can be: A LL (all), CRI (criti cal), URG (urgent: c ritical + high prior ities) | |
| 41 | type: [ | |
| 42 | 'P ', // Prop osal | |
| 43 | 'A ' // Advic e | |
| 44 | ] | |
| 45 | }; | |
| 46 | ||
| 47 | ||
| 48 | // | |
| 49 | // Databas e Init - d bErrorCall back can b e null if an error m essage is to be retu rned on fa ilure. | |
| 50 | // Please see retrie veWorkProd uctsForPro vider for a custom e rror callb ack | |
| 51 | // | |
| 52 | function c reateInitD b(logger) { | |
| 53 | return function initWorkPr oduct(db) { | |
| 54 | db .collectio n(workColl ection).en sureIndex( { | |
| 55 | provider : 1, | |
| 56 | type: 1, | |
| 57 | priority : 1 | |
| 58 | }, {}, funct ion(error) { | |
| 59 | if (erro r) { | |
| 60 | logg er.error({ | |
| 61 | error: err or | |
| 62 | }, ' error ensu ring ' + w orkCollect ion + ' in dex'); | |
| 63 | } | |
| 64 | }) ; | |
| 65 | ||
| 66 | db .collectio n(subscrip tionCollec tion).ensu reIndex({ | |
| 67 | user: 1 | |
| 68 | }, { | |
| 69 | unique: true | |
| 70 | }, function( error) { | |
| 71 | if (erro r) { | |
| 72 | logg er.error({ | |
| 73 | error: err or | |
| 74 | }, ' error ensu ring ' + s ubscriptio nCollectio n + ' inde x'); | |
| 75 | retu rn; | |
| 76 | } | |
| 77 | }) ; | |
| 78 | }; | |
| 79 | } | |
| 80 | ||
| 81 | ||
| 82 | // | |
| 83 | // Utility Methods | |
| 84 | // | |
| 85 | ||
| 86 | function g etKeyValue (obj) { | |
| 87 | var pr operty; | |
| 88 | //null checker.is NotNullish (obj) ??? | |
| 89 | //add: if (obj.h asOwnPrope rty(proper ty)) ??? | |
| 90 | if (ob j !== null ) { | |
| 91 | fo r (propert y in obj) { | |
| 92 | if (prop erty !== u ndefined) { | |
| 93 | retu rn propert y + ':' + obj[proper ty]; | |
| 94 | } | |
| 95 | } | |
| 96 | } | |
| 97 | return 'BAD OBJE CT'; | |
| 98 | } | |
| 99 | ||
| 100 | ||
| 101 | function f etchNames( req, items , fetchcb) { | |
| 102 | async. each( | |
| 103 | it ems, | |
| 104 | fu nction(ite m, callbac k) { | |
| 105 | //http:// IP /vpr/9E7A; 237 | |
| 106 | ||
| 107 | var pid = item.pid ; | |
| 108 | var jdsR esource = '/vpr'; | |
| 109 | if (/^\d +$/.test(p id)) { | |
| 110 | retu rn callbac k('Numeric -only DFN found; a s ite is req uired.'); | |
| 111 | } | |
| 112 | req.logg er.info('v pr search using pid [%s]', pid ); | |
| 113 | ||
| 114 | var jdsP ath = jdsR esource + '/' + pid; | |
| 115 | var opti ons = _.ex tend({}, r eq.app.con fig.jdsSer ver, { | |
| 116 | url: jdsPath, | |
| 117 | logg er: req.lo gger, | |
| 118 | json : true | |
| 119 | }); | |
| 120 | http.get (options, function(e rror, resp onse, resu lt) { | |
| 121 | var err = null ; | |
| 122 | if ( error || r esult.erro r) { | |
| 123 | if (error) { | |
| 124 | err = error; | |
| 125 | } else { | |
| 126 | err = result.err or; | |
| 127 | } | |
| 128 | req.logger .error({ | |
| 129 | error: err | |
| 130 | }, 'cds-wo rk-product .fetchName s - Error fetching n ame'); | |
| 131 | ||
| 132 | return cal lback(err) ; | |
| 133 | } | |
| 134 | if ( nullchecke r.isNotNul lish(resul t) && null checker.is NotNullish (result.da ta) && nul lchecker.i sNotNullis h(result.d ata.items[ 0])) { | |
| 135 | item.displ ayName = r esult.data .items[0]. displayNam e; | |
| 136 | item.fullN ame = resu lt.data.it ems[0].ful lName; | |
| 137 | } | |
| 138 | retu rn callbac k(); | |
| 139 | }); | |
| 140 | }, | |
| 141 | // This func tion is ca lled if an item cann ot be succ essfully p rocessed o r if an er ror occurr ed during the proces sing | |
| 142 | fu nction(err ) { | |
| 143 | if (err) { | |
| 144 | req. logger.err or('Error fetching n ames:'); | |
| 145 | req. logger.err or(err); | |
| 146 | } | |
| 147 | return f etchcb(ite ms); | |
| 148 | }) ; | |
| 149 | } | |
| 150 | ||
| 151 | ||
| 152 | /* | |
| 153 | * Transf orm the da ta | |
| 154 | * | |
| 155 | * @param {object} L ist of wra pped work product js on objects . | |
| 156 | */ | |
| 157 | function f ormatForRD K(workProd uctWrapper ) { | |
| 158 | var it ems = []; | |
| 159 | ||
| 160 | if (nu llchecker. isNullish( workProduc tWrapper)) { | |
| 161 | re turn items ; | |
| 162 | } | |
| 163 | ||
| 164 | //resu lts here a re wrapped work prod uct object s from Mon goDB | |
| 165 | _.forE ach(workPr oductWrapp er, functi on(wrapper ) { | |
| 166 | ||
| 167 | if (nullchec ker.isNull ish(wrappe r._id)) { | |
| 168 | return; | |
| 169 | } | |
| 170 | ||
| 171 | va r type = w rapper.wor kproduct.t ype; | |
| 172 | if (nullchec ker.isNotN ullish(wra pper.workp roduct.pay load)) { | |
| 173 | _.forEac h(wrapper. workproduc t.payload, function( payload) { | |
| 174 | ||
| 175 | //we only goin g to retur n the type we're wor king with | |
| 176 | if ( type === p ayload.typ e) { | |
| 177 | ||
| 178 | //repurpos ing the id field to give us a work produ ct id. Th is is need ed | |
| 179 | //when the front end wants to request th at this be marked as 'read', e tc | |
| 180 | payload.da ta.id = wr apper._id; | |
| 181 | items.push (payload.d ata); | |
| 182 | } | |
| 183 | }); | |
| 184 | } | |
| 185 | }); | |
| 186 | return items; | |
| 187 | } | |
| 188 | ||
| 189 | ||
| 190 | //Gets the actual wo rk product (s) out of the wrapp er that is used to d enormalize the work product da ta for Mon goDB | |
| 191 | function w orkProduct ForClient( workProduc tWrapper) { | |
| 192 | //resu lts here a re wrapped work prod uct object s from Mon goDB | |
| 193 | if (nu llchecker. isNullish( workProduc tWrapper)) { | |
| 194 | re turn; | |
| 195 | } | |
| 196 | if (wo rkProductW rapper ins tanceof Ar ray) { | |
| 197 | va r workprod ucts = []; | |
| 198 | _. forEach(wo rkProductW rapper, fu nction(wra pper) { | |
| 199 | if (null checker.is NotNullish (wrapper._ id)) { | |
| 200 | wrap per.workpr oduct.id = wrapper._ id; | |
| 201 | work products.p ush(wrappe r.workprod uct); | |
| 202 | ||
| 203 | } | |
| 204 | }) ; | |
| 205 | re turn workp roducts; | |
| 206 | } | |
| 207 | ||
| 208 | //id i s overload ed here, s o that we can refer back to th e database id for th is work pr oduct. | |
| 209 | if (wo rkProductW rapper && workProduc tWrapper.w orkproduct && workPr oductWrapp er._id) { | |
| 210 | wo rkProductW rapper.wor kproduct.i d = workPr oductWrapp er._id; | |
| 211 | re turn workP roductWrap per.workpr oduct; | |
| 212 | } | |
| 213 | ||
| 214 | //if a ll else fa ils, retur n nothing. | |
| 215 | return ''; | |
| 216 | } | |
| 217 | ||
| 218 | ||
| 219 | // | |
| 220 | // API Cal ls | |
| 221 | // | |
| 222 | ||
| 223 | /** | |
| 224 | * @api {g et} /resou rce/cds/wo rk-product /inbox Ret rieves 'in box' for t he authent icated use r. | |
| 225 | * @apiNam e retrieve Inbox | |
| 226 | * @apiGro up CDSWork Product | |
| 227 | * | |
| 228 | * @apiDes cription T his method retrieves the 'inbo x' for the user that is curren tly authen ticated. | |
| 229 | * | |
| 230 | * @apiSuc cess (Succ ess 200) { json} json collectio n of objec ts contain ing the us ers inbox entries | |
| 231 | * @apiSuc cessExampl e Success- Response: | |
| 232 | * HTTP/1. 1 200 OK | |
| 233 | * { | |
| 234 | * "statu s": 200, | |
| 235 | * "data" : { | |
| 236 | * "i tems": [{ | |
| 237 | * "details ": { | |
| 238 | * "det ail": "Thi s is the B ody", | |
| 239 | * "pro venance": "Test Data " | |
| 240 | * }, | |
| 241 | * "doneDat e": null, | |
| 242 | * "dueDate ": 1443989 700000, | |
| 243 | * "generat edBy": "Ge neratedBYU nitTest", | |
| 244 | * "id": nu ll, | |
| 245 | * "pid": " PatientId" , | |
| 246 | * "priorit y": 50, | |
| 247 | * "provide r": "Provi derId", | |
| 248 | * "title": "A Test R esult", | |
| 249 | * "type": "advice", | |
| 250 | * "patient Name": "22 99:2222:Ju nk" | |
| 251 | * }] | |
| 252 | * } | |
| 253 | * } | |
| 254 | * | |
| 255 | * @apiErr or (Error 404) Not F ound. | |
| 256 | * @apiErr orExample Error-Resp onse: | |
| 257 | * HTTP/1. 1 404 Bad Request | |
| 258 | * { | |
| 259 | * "st atus": 404 , | |
| 260 | * "er ror": "" | |
| 261 | * } | |
| 262 | */ | |
| 263 | function r etrieveInb ox(req, re s) { | |
| 264 | req.lo gger.debug ('cds-work -product.r etrieveInb ox()'); | |
| 265 | ||
| 266 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 267 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS work- product is unavailab le.'); | |
| 268 | } | |
| 269 | ||
| 270 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 271 | if (error) { | |
| 272 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 273 | } | |
| 274 | re q.logger.d ebug('CDS Work Produ ct GET ret rieveInbox called'); | |
| 275 | ||
| 276 | va r userId = getKeyVal ue(req.ses sion.user. duz); | |
| 277 | va r query = {}; | |
| 278 | qu ery.assign ments = { | |
| 279 | $elemMat ch: { | |
| 280 | 'use r.id': use rId | |
| 281 | } | |
| 282 | }; | |
| 283 | va r projecti on = { | |
| 284 | 'workpro duct': 1 | |
| 285 | }; | |
| 286 | ||
| 287 | va r status = rdk.https tatus.ok; | |
| 288 | db Connection .collectio n(workColl ection).fi nd(query, projection ).toArray( function(e rr, result ) { | |
| 289 | if (null checker.is NotNullish (err)) { | |
| 290 | req. logger.deb ug({ | |
| 291 | error: err | |
| 292 | }); | |
| 293 | stat us = rdk.h ttpstatus. not_found; | |
| 294 | retu rn res.sta tus(status ).rdkSend( err); | |
| 295 | } | |
| 296 | ||
| 297 | req.logg er.debug(' results: ' + result) ; | |
| 298 | var item s = format ForRDK(res ult); | |
| 299 | return f etchNames( req, items , function (items) { | |
| 300 | var data = { | |
| 301 | items: ite ms | |
| 302 | }; | |
| 303 | retu rn res.sta tus(status ).rdkSend( data); | |
| 304 | }); | |
| 305 | }) ; | |
| 306 | }); | |
| 307 | } | |
| 308 | ||
| 309 | ||
| 310 | /** | |
| 311 | * @apiIgn ore This i s not used externall y. This m ethod is u sed by cds AdviceList . | |
| 312 | * | |
| 313 | * @apiDes cription R etrieves ' work produ cts' for t he given p rovider. In the eve nt of an e rror, an | |
| 314 | * empty r esult is r eturned. | |
| 315 | * | |
| 316 | * @apiSuc cess (Succ ess 200) { json} json workprodu cts for th e given pr ovider. | |
| 317 | * @apiSuc cessExampl e Success- Response: | |
| 318 | * HTTP/1. 1 200 OK | |
| 319 | * { | |
| 320 | * "statu s": 200, | |
| 321 | * "data" : { | |
| 322 | * "i tems": [{ | |
| 323 | * "details ": { | |
| 324 | * "det ail": "Thi s is the B ody", | |
| 325 | * "pro venance": "Test Data " | |
| 326 | * }, | |
| 327 | * "doneDat e": null, | |
| 328 | * "dueDate ": 1443989 700000, | |
| 329 | * "generat edBy": "Ge neratedBYU nitTest", | |
| 330 | * "id": nu ll, | |
| 331 | * "pid": " PatientId" , | |
| 332 | * "priorit y": 50, | |
| 333 | * "provide r": "Provi derId", | |
| 334 | * "title": "A Test R esult", | |
| 335 | * "type": "advice", | |
| 336 | * "patien tName": "2 299:2222:J unk" | |
| 337 | * }, | |
| 338 | * { | |
| 339 | * "details ": { | |
| 340 | * "det ail": "Thi s is the B ody", | |
| 341 | * "pro venance": "Test Data " | |
| 342 | * }, | |
| 343 | * "doneDat e": null, | |
| 344 | * "dueDate ": 1443989 700000, | |
| 345 | * "generat edBy": "Ge neratedBYU nitTest", | |
| 346 | * "id": nu ll, | |
| 347 | * "pid": " PatientId" , | |
| 348 | * "priorit y": 50, | |
| 349 | * "provide r": "Provi derId", | |
| 350 | * "title": "A Test R esult", | |
| 351 | * "type": "advice", | |
| 352 | * "patient Name": "22 99:2222:Ju nk" | |
| 353 | * }] | |
| 354 | * } | |
| 355 | * } | |
| 356 | * | |
| 357 | */ | |
| 358 | function r etrieveWor kProductsF orProvider (req, prov ider, pid, readStatu s, callbac k) { | |
| 359 | req.lo gger.debug ('cds-work -product.r etrieveWor kProductsF orProvider ()'); | |
| 360 | ||
| 361 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 362 | re turn callb ack(null, []); | |
| 363 | } | |
| 364 | ||
| 365 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 366 | if (error) { | |
| 367 | return c allback(nu ll, []); | |
| 368 | } | |
| 369 | if (nullchec ker.isNotN ullish(pid )) { | |
| 370 | fetchPid s(req, pid , function (error, pi ds) { | |
| 371 | if ( error) { | |
| 372 | req.logger .error('re trieveWork ProductsFo rProvider: jpid sear ch using p id [%s], e rror: %s', pid, erro r); | |
| 373 | // call ca llback wit h empty li st | |
| 374 | return cal lback(null , []); | |
| 375 | } | |
| 376 | // p roceed and fetch wor k products | |
| 377 | retu rn fetchWo rkProduct( dbConnecti on, req, p rovider, p ids, readS tatus, cal lback); | |
| 378 | }); | |
| 379 | } else { | |
| 380 | // fetch work prod ucts witho ut pid | |
| 381 | return f etchWorkPr oduct(dbCo nnection, req, provi der, null, readStatu s, callbac k); | |
| 382 | } | |
| 383 | }); | |
| 384 | } | |
| 385 | ||
| 386 | ||
| 387 | function f etchPids(r eq, pid, c allback) { | |
| 388 | var jd sResource = '/vpr/jp id'; | |
| 389 | req.lo gger.info( 'WorkProdu cts.fetchP ids: jpid search usi ng pid [%s ]', pid); | |
| 390 | ||
| 391 | var jd sPath = jd sResource + '/' + pi d; | |
| 392 | var op tions = _. extend({}, req.app.c onfig.jdsS erver, { | |
| 393 | ur l: jdsPath , | |
| 394 | lo gger: req. logger, | |
| 395 | js on: true | |
| 396 | }); | |
| 397 | ||
| 398 | http.g et(options , function (error, re sponse, re sult) { | |
| 399 | if (error) { | |
| 400 | return c allback(er ror, null) ; | |
| 401 | } | |
| 402 | pi d = result .patientId entifiers; | |
| 403 | re turn callb ack(null, pid); | |
| 404 | }); | |
| 405 | } | |
| 406 | ||
| 407 | ||
| 408 | function f etchWorkPr oduct(dbCo nnection, req, provi der, pid, readStatus , callback ) { | |
| 409 | var wo rkProductQ uery = {}; | |
| 410 | if (nu llchecker. isNotNulli sh(pid)) { | |
| 411 | wo rkProductQ uery['work product.co ntext.subj ect.id'] = { | |
| 412 | $in: pid | |
| 413 | }; | |
| 414 | } | |
| 415 | ||
| 416 | var re ad = readS tatus === 'true'; | |
| 417 | ||
| 418 | if (re adStatus | | provider ) { | |
| 419 | wo rkProductQ uery.assig nments = { | |
| 420 | $elemMat ch: {} | |
| 421 | }; | |
| 422 | if (readStat us) { | |
| 423 | workProd uctQuery.a ssignments .$elemMatc h.readStat us = read; | |
| 424 | } | |
| 425 | if (provider ) { | |
| 426 | workProd uctQuery.a ssignments .$elemMatc h['user.id '] = provi der; | |
| 427 | } | |
| 428 | } | |
| 429 | ||
| 430 | var pr ojection = { | |
| 431 | 'w orkproduct ': 1 | |
| 432 | }; | |
| 433 | ||
| 434 | dbConn ection.col lection(wo rkCollecti on).find(w orkProduct Query, pro jection) | |
| 435 | .s ort({ | |
| 436 | 'workpro duct.gener ationDate' : -1 | |
| 437 | }) | |
| 438 | .l imit(500). toArray(fu nction(err , result) { | |
| 439 | if (null checker.is NotNullish (err)) { | |
| 440 | req. logger.err or('fetchW orkProduct : jpid sea rch using pid [%s], error: %s' , pid, err ); | |
| 441 | //in these err ors, there is nothin g we can d o but retu rn no mess ages... | |
| 442 | retu rn callbac k(null, [] ); | |
| 443 | } | |
| 444 | //callba ck | |
| 445 | var item s = format ForRDK(res ult); | |
| 446 | fetchNam es(req, it ems, funct ion(items) { | |
| 447 | //va r data = { items: ite ms }; | |
| 448 | retu rn callbac k(null, it ems); | |
| 449 | }); | |
| 450 | }) ; | |
| 451 | } | |
| 452 | ||
| 453 | ||
| 454 | /** | |
| 455 | * @api {p ost} /reso urce/cds/w ork-produc t/product Creates a work produ ct. | |
| 456 | * @apiNam e createWo rkProduct | |
| 457 | * @apiGro up CDSWork Product | |
| 458 | * | |
| 459 | * @apiDes cription C reates a w ork produc t. | |
| 460 | * | |
| 461 | * @apiSuc cess (Succ ess 201) { json} json echo of t he created workprodu ct | |
| 462 | * @apiSuc cessExampl e Success- Response: | |
| 463 | * HTTP/1. 1 201 Crea ted | |
| 464 | * { | |
| 465 | * "statu s": 201, | |
| 466 | * "data" : [ | |
| 467 | * { | |
| 468 | * "c ategories" : [ | |
| 469 | * 41919200 3 | |
| 470 | * ], | |
| 471 | * "c ontext": { | |
| 472 | * "locatio n": { | |
| 473 | * "cod eSystem": "VA:Locati on", | |
| 474 | * "ent ityType": "Location" , | |
| 475 | * "id" : "2883", | |
| 476 | * "nam e": "Clini cOne", | |
| 477 | * "typ e": "Clini cName" | |
| 478 | * }, | |
| 479 | * "special ty": { | |
| 480 | * "cod eSystem": "VA:Specia lty", | |
| 481 | * "ent ityType": "Specialty ", | |
| 482 | * "id" : "FM", | |
| 483 | * "nam e": "Famil y Medicine ", | |
| 484 | * "typ e": "Speci ality" | |
| 485 | * }, | |
| 486 | * "subject ": { | |
| 487 | * "cod eSystem": "VA:Univer salId", | |
| 488 | * "ent ityType": "Subject", | |
| 489 | * "id" : "2299:22 22:Junk", | |
| 490 | * "nam e": null, | |
| 491 | * "typ e": "Patie nt" | |
| 492 | * }, | |
| 493 | * "user": { | |
| 494 | * "cod eSystem": "VA:Provid er", | |
| 495 | * "ent ityType": "User", | |
| 496 | * "id" : "unitTes tUserId", | |
| 497 | * "nam e": "TESR, USER", | |
| 498 | * "typ e": "Provi der" | |
| 499 | * } | |
| 500 | * }, | |
| 501 | * "d uplicateCh eckKey": { | |
| 502 | * "checkSu m": "", | |
| 503 | * "subject ": { | |
| 504 | * "cod eSystem": "VA:Univer salId", | |
| 505 | * "ent ityType": "Subject", | |
| 506 | * "id" : "2299:22 22:Junk", | |
| 507 | * "nam e": null, | |
| 508 | * "typ e": "Patie nt" | |
| 509 | * }, | |
| 510 | * "type": "advice" | |
| 511 | * }, | |
| 512 | * "e xpirationD ate": 1443 989700000, | |
| 513 | * "g enerationD ate": 1443 903300000, | |
| 514 | * "i d": "5550c d249e94e57 917716f5e" , | |
| 515 | * "i nvocationI nfo": { | |
| 516 | * "callId" : "UUID of CallId", | |
| 517 | * "generat edBy": "Un itTestRule sEngine", | |
| 518 | * "targetI nfo": { | |
| 519 | * "int entsSet": [ | |
| 520 | * "Invocatio nIntentA" | |
| 521 | * ], | |
| 522 | * "mod e": "Norma l", | |
| 523 | * "per ceivedExec utionTime" : null, | |
| 524 | * "sup plementalM appings": null, | |
| 525 | * "typ e": "Backg round" | |
| 526 | * } | |
| 527 | * }, | |
| 528 | * "p ayload": [ { | |
| 529 | * "data": { | |
| 530 | * "det ails": { | |
| 531 | * "detail": "This is t he Body", | |
| 532 | * "provenanc e": "Test Data" | |
| 533 | * }, | |
| 534 | * "don eDate": nu ll, | |
| 535 | * "due Date": 144 3989700000 , | |
| 536 | * "gen eratedBy": "Generate dBYUnitTes t", | |
| 537 | * "id" : null, | |
| 538 | * "pid ": "Patien tId", | |
| 539 | * "pri ority": 50 , | |
| 540 | * "pro vider": "P roviderId" , | |
| 541 | * "tit le": "A Te st Result" , | |
| 542 | * "typ e": "advic e" | |
| 543 | * }, | |
| 544 | * "type": "advice" | |
| 545 | * }] , | |
| 546 | * "p riority": 0, | |
| 547 | * "t ype": "adv ice" | |
| 548 | * }] | |
| 549 | * } | |
| 550 | * | |
| 551 | * @apiErr or (Error 400) Bad R equest. | |
| 552 | * @apiErr orExample Error-Resp onse: | |
| 553 | * HTTP/1. 1 400 Bad Request | |
| 554 | * { | |
| 555 | * "stat us": 400, | |
| 556 | * "mess age": "" | |
| 557 | * } | |
| 558 | */ | |
| 559 | function c reateWorkP roduct(req , res) { | |
| 560 | req.lo gger.debug ('cds-work -product.c reateWorkP roduct()') ; | |
| 561 | ||
| 562 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 563 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS work product is unavailab le.'); | |
| 564 | } | |
| 565 | ||
| 566 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 567 | if (error) { | |
| 568 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 569 | } | |
| 570 | re q.logger.d ebug('CDS Work Produ ct POST cr eateWorkPr oduct call ed'); | |
| 571 | ||
| 572 | va r product = req.body ; | |
| 573 | ||
| 574 | // putting th is into a wrapper ob ject for e asier acce ss, etc. | |
| 575 | va r wrapper = {}; | |
| 576 | wr apper.work product = product; | |
| 577 | wr apper.assi gnments = []; | |
| 578 | ||
| 579 | va r status = rdk.https tatus.crea ted; | |
| 580 | ||
| 581 | db Connection .collectio n(workColl ection).in sert(wrapp er, functi on(err, re sult) { | |
| 582 | status = rdk.https tatus.crea ted; | |
| 583 | if (null checker.is NotNullish (err)) { | |
| 584 | stat us = rdk.h ttpstatus. bad_reques t; | |
| 585 | retu rn res.sta tus(rdk.ht tpstatus.b ad_request ).rdkSend( err); | |
| 586 | } | |
| 587 | if (resu lt && resu lt.ops) { | |
| 588 | resu lt = resul t.ops; | |
| 589 | } | |
| 590 | return r es.status( status).rd kSend(work ProductFor Client(res ult)); | |
| 591 | }) ; | |
| 592 | }); | |
| 593 | } | |
| 594 | ||
| 595 | ||
| 596 | /** | |
| 597 | * @api {g et} /resou rce/cds/wo rk-product /product R etrieves w ork produc ts from th e database . | |
| 598 | * @apiNam e retrieve WorkProduc t | |
| 599 | * @apiGro up CDSWork Product | |
| 600 | * | |
| 601 | * @apiPar am {String } [id=*] W ork Produc t Id; defa ult is '*' which mea ns it retu rns first 500 work p roducts | |
| 602 | * | |
| 603 | * @apiDes cription R etrieves a work prod uct from t he databas e. | |
| 604 | * | |
| 605 | * @apiSuc cess (Succ ess 200) { json} json represent ation of t he workpro duct | |
| 606 | * @apiSuc cessExampl e Success- Response: | |
| 607 | * HTTP/1. 1 200 OK | |
| 608 | * { | |
| 609 | * "statu s": 200, | |
| 610 | * "data" : [ | |
| 611 | * { | |
| 612 | * "c ategories" : [ | |
| 613 | * 41919200 3 | |
| 614 | * ], | |
| 615 | * "c ontext": { | |
| 616 | * "locatio n": { | |
| 617 | * "cod eSystem": "VA:Locati on", | |
| 618 | * "ent ityType": "Location" , | |
| 619 | * "id" : "2883", | |
| 620 | * "nam e": "Clini cOne", | |
| 621 | * "typ e": "Clini cName" | |
| 622 | * }, | |
| 623 | * "special ty": { | |
| 624 | * "cod eSystem": "VA:Specia lty", | |
| 625 | * "ent ityType": "Specialty ", | |
| 626 | * "id" : "FM", | |
| 627 | * "nam e": "Famil y Medicine ", | |
| 628 | * "typ e": "Speci ality" | |
| 629 | * }, | |
| 630 | * "subject ": { | |
| 631 | * "cod eSystem": "VA:Univer salId", | |
| 632 | * "ent ityType": "Subject", | |
| 633 | * "id" : "2299:22 22:Junk", | |
| 634 | * "nam e": null, | |
| 635 | * "typ e": "Patie nt" | |
| 636 | * }, | |
| 637 | * "user": { | |
| 638 | * "cod eSystem": "VA:Provid er", | |
| 639 | * "ent ityType": "User", | |
| 640 | * "id" : "unitTes tUserId", | |
| 641 | * "nam e": "TESR, USER", | |
| 642 | * "typ e": "Provi der" | |
| 643 | * } | |
| 644 | * }, | |
| 645 | * "d uplicateCh eckKey": { | |
| 646 | * "checkSu m": "", | |
| 647 | * "subject ": { | |
| 648 | * "cod eSystem": "VA:Univer salId", | |
| 649 | * "ent ityType": "Subject", | |
| 650 | * "id" : "2299:22 22:Junk", | |
| 651 | * "nam e": null, | |
| 652 | * "typ e": "Patie nt" | |
| 653 | * }, | |
| 654 | * "type": "advice" | |
| 655 | * }, | |
| 656 | * "e xpirationD ate": 1443 989700000, | |
| 657 | * "g enerationD ate": 1443 903300000, | |
| 658 | * "i d": "5550c d249e94e57 917716f5e" , | |
| 659 | * "i nvocationI nfo": { | |
| 660 | * "callId" : "UUID of CallId", | |
| 661 | * "generat edBy": "Un itTestRule sEngine", | |
| 662 | * "targetI nfo": { | |
| 663 | * "int entsSet": [ | |
| 664 | * "Invocatio nIntentA" | |
| 665 | * ], | |
| 666 | * "mod e": "Norma l", | |
| 667 | * "per ceivedExec utionTime" : null, | |
| 668 | * "sup plementalM appings": null, | |
| 669 | * "typ e": "Backg round" | |
| 670 | * } | |
| 671 | * }, | |
| 672 | * "p ayload": [ { | |
| 673 | * "data": { | |
| 674 | * "det ails": { | |
| 675 | * "detail": "This is t he Body", | |
| 676 | * "provenanc e": "Test Data" | |
| 677 | * }, | |
| 678 | * "don eDate": nu ll, | |
| 679 | * "due Date": 144 3989700000 , | |
| 680 | * "gen eratedBy": "Generate dBYUnitTes t", | |
| 681 | * "id" : null, | |
| 682 | * "pid ": "Patien tId", | |
| 683 | * "pri ority": 50 , | |
| 684 | * "pro vider": "P roviderId" , | |
| 685 | * "tit le": "A Te st Result" , | |
| 686 | * "typ e": "advic e" | |
| 687 | * }, | |
| 688 | * "type": "advice" | |
| 689 | * }] , | |
| 690 | * "p riority": 0, | |
| 691 | * "t ype": "adv ice" | |
| 692 | * }] | |
| 693 | * } | |
| 694 | * | |
| 695 | * @apiErr or (Error 404) Work Product no t found. | |
| 696 | * @apiErr orExample Error-Resp onse: | |
| 697 | * HTTP/1. 1 404 Not Found Erro r | |
| 698 | * { | |
| 699 | * "stat us": 404, | |
| 700 | * "mess age": "Mis sing or in valid work product i d." | |
| 701 | * } | |
| 702 | */ | |
| 703 | function r etrieveWor kProduct(r eq, res) { | |
| 704 | req.lo gger.debug ('cds-work -product.r etrieveWor kProduct() '); | |
| 705 | ||
| 706 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 707 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS work product is unavailab le.'); | |
| 708 | } | |
| 709 | ||
| 710 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 711 | if (error) { | |
| 712 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 713 | } | |
| 714 | re q.logger.d ebug('CDS Work Produ ct GET ret rieveWorkP roduct cal led'); | |
| 715 | ||
| 716 | va r matchQue ry = {}; | |
| 717 | ||
| 718 | // first chec k that we have an id ... | |
| 719 | va r id = req .query.id; | |
| 720 | if (id === ' *') { | |
| 721 | id = nul l; | |
| 722 | } | |
| 723 | if (id) { | |
| 724 | //make s ure the id is in a v alid forma t, return the error if not... | |
| 725 | var idVa lidationEr ror = test Id(id); | |
| 726 | if (null checker.is NotNullish (idValidat ionError)) { | |
| 727 | retu rn res.sta tus(rdk.ht tpstatus.b ad_request ).rdkSend( idValidati onError); | |
| 728 | } | |
| 729 | matchQue ry._id = n ew ObjectI d(id); | |
| 730 | } | |
| 731 | ||
| 732 | db Connection .collectio n(workColl ection).fi nd(matchQu ery).limit (500).toAr ray(functi on(err, re sult) { | |
| 733 | if (null checker.is NotNullish (err)) { | |
| 734 | retu rn res.sta tus(rdk.ht tpstatus.i nternal_se rver_error ).rdkSend( err); | |
| 735 | } | |
| 736 | if (null checker.is Nullish(re sult)) { | |
| 737 | retu rn res.sta tus(rdk.ht tpstatus.n ot_found). rdkSend('W ork Produc t with id \'' + id + '\' was n ot found.' ); | |
| 738 | } | |
| 739 | //defaul t status i s 'ok' | |
| 740 | return r es.status( rdk.httpst atus.ok).r dkSend(wor kProductFo rClient(re sult)); | |
| 741 | }) ; | |
| 742 | }); | |
| 743 | } | |
| 744 | ||
| 745 | ||
| 746 | /** | |
| 747 | * @api {p ut} /resou rce/cds/wo rk-product /product U pdates a w ork produc t in the d atabase. | |
| 748 | * @apiNam e updateWo rkProduct | |
| 749 | * @apiGro up CDSWork Product | |
| 750 | * | |
| 751 | * @apiDes cription U pdates a w ork produc t in the d atabase. | |
| 752 | * | |
| 753 | * @apiPar am {string } id work product id | |
| 754 | * | |
| 755 | * @apiSuc cess (Succ ess 200) { json} data with a '1 ' for succ essful mat ch and upd ate, or a '0' for no match and update. | |
| 756 | * @apiSuc cessExampl e Success- Response: | |
| 757 | * HTTP/1. 1 200 OK | |
| 758 | * { | |
| 759 | * "statu s": 200, | |
| 760 | * "messa ge": 1 | |
| 761 | * } | |
| 762 | * | |
| 763 | * @apiErr or (Error 400) Work Product no t found. | |
| 764 | * @apiErr orExample Error-Resp onse: | |
| 765 | * HTTP/1. 1 400 Bad Request | |
| 766 | * { | |
| 767 | * "stat us": 400, | |
| 768 | * "mess age": "Mis sing or in valid work product i d." | |
| 769 | * } | |
| 770 | * | |
| 771 | * @apiErr or (Error 404) Work Product no t found. | |
| 772 | * @apiErr orExample Error-Resp onse: | |
| 773 | * HTTP/1. 1 404 Not Found Erro r | |
| 774 | * { | |
| 775 | * "stat us": 404, | |
| 776 | * "mess age": "Wor k Product with id <i d> was not found." | |
| 777 | * } | |
| 778 | */ | |
| 779 | function u pdateWorkP roduct(req , res) { | |
| 780 | req.lo gger.debug ('cds-work -product.u pdateWorkP roduct()') ; | |
| 781 | ||
| 782 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 783 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS work product is unavailab le.'); | |
| 784 | } | |
| 785 | ||
| 786 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 787 | if (error) { | |
| 788 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 789 | } | |
| 790 | re q.logger.d ebug('CDS Work Produ ct PUT upd ateWorkPro duct calle d'); | |
| 791 | ||
| 792 | va r id = req .query.id; | |
| 793 | va r product = req.body ; | |
| 794 | ||
| 795 | if (nullchec ker.isNull ish(id)) { | |
| 796 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend('Mis sing or in valid work product i d.'); | |
| 797 | } | |
| 798 | // make sure the id is in a valid format, r eturn the error if n ot... | |
| 799 | va r idValida tionError = testId(i d); | |
| 800 | if (nullchec ker.isNotN ullish(idV alidationE rror)) { | |
| 801 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend(idVa lidationEr ror); | |
| 802 | } | |
| 803 | ||
| 804 | db Connection .collectio n(workColl ection).up date({ | |
| 805 | _id: new ObjectId( id) | |
| 806 | }, { | |
| 807 | $set: { | |
| 808 | work product: p roduct | |
| 809 | } | |
| 810 | }, function( err, numUp dated) { | |
| 811 | if (null checker.is Nullish(er r)) { | |
| 812 | if ( numUpdated === 0) { | |
| 813 | // no reco rds update d, id not found | |
| 814 | return res .status(rd k.httpstat us.not_fou nd).rdkSen d('Work Pr oduct with id \'' + id + '\' w as not fou nd.'); | |
| 815 | } | |
| 816 | //st atus defau lt is 'ok' | |
| 817 | retu rn res.sta tus(rdk.ht tpstatus.o k).rdkSend (numUpdate d); | |
| 818 | } | |
| 819 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend(err) ; | |
| 820 | }) ; | |
| 821 | }); | |
| 822 | } | |
| 823 | ||
| 824 | ||
| 825 | /** | |
| 826 | * @apiIgn ore This i s not used externall y. This m ethod is u sed intern ally and n ot exposed via rest. | |
| 827 | * | |
| 828 | * @api {p ut} /resou rce/cds/wo rk-product /product S ets the 'r ead' statu s of an as signed wor k product in the dat abase. | |
| 829 | * @apiNam e patchWor kProduct | |
| 830 | * @apiGro up CDSWork Product | |
| 831 | * | |
| 832 | * @apiDes cription S ets the 'r ead' statu s of an as signed wor k product in the dat abase. | |
| 833 | * | |
| 834 | * @apiSuc cess {json } data Jso n object c ontaining a one for successful match and update, z ero if the re was no record to update. | |
| 835 | * | |
| 836 | */ | |
| 837 | function s etReadStat us(req, id , readStat us, provid er, callba ck) { | |
| 838 | req.lo gger.debug ('cds-work -product.s etReadStat us()'); | |
| 839 | ||
| 840 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 841 | re turn callb ack(null, []); | |
| 842 | } | |
| 843 | ||
| 844 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 845 | if (error) { | |
| 846 | return c allback(er ror, null) ; | |
| 847 | } | |
| 848 | va r read = r eadStatus === 'true' ; | |
| 849 | tr y { | |
| 850 | dbConnec tion.colle ction(work Collection ).update({ | |
| 851 | _id: new Objec tId(id), | |
| 852 | 'ass ignments.u ser.id': p rovider | |
| 853 | }, { | |
| 854 | $set : { | |
| 855 | 'assignmen ts.$.readS tatus': re ad | |
| 856 | } | |
| 857 | }, funct ion(err, r esult) { | |
| 858 | if ( err) { | |
| 859 | return cal lback(null , err); | |
| 860 | } | |
| 861 | if ( result) { | |
| 862 | return cal lback(resu lt, null); | |
| 863 | } | |
| 864 | retu rn callbac k(null, 'A dvice with id \'' + id + '\' n ot found.' ); | |
| 865 | }); | |
| 866 | } catch (err or) { | |
| 867 | return c allback(nu ll, error. message); | |
| 868 | } | |
| 869 | }); | |
| 870 | } | |
| 871 | ||
| 872 | ||
| 873 | /** | |
| 874 | * @api {d elete} /re source/cds /work-prod uct/produc t Delete a work prod uct in the database. | |
| 875 | * @apiNam e deleteWo rkProduct | |
| 876 | * @apiGro up CDSWork Product | |
| 877 | * | |
| 878 | * @apiDes cription D elete a wo rk product in the da tabase. | |
| 879 | * | |
| 880 | * @apiPar am {string } id work product id | |
| 881 | * | |
| 882 | * @apiSuc cess (Succ ess 201) { json} data with a '1 ' for succ essful mat ch and del ete, or a '0' for no match and delete. | |
| 883 | * @apiSuc cessExampl e Success- Response: | |
| 884 | * HTTP/1. 1 200 OK | |
| 885 | * { | |
| 886 | * "statu s": 200, | |
| 887 | * "messa ge": 1 | |
| 888 | * } | |
| 889 | * | |
| 890 | * @apiErr or (Error 404) Not F ound. | |
| 891 | * @apiErr orExample Error-Resp onse: | |
| 892 | * HTTP/1. 1 404 Inte rnal Serve r Error | |
| 893 | * { | |
| 894 | * "st atus": 404 , | |
| 895 | * "me ssage": "W ork Produc t with id <id> was n ot found." | |
| 896 | * } | |
| 897 | * | |
| 898 | * @apiErr or (Error 500) Inter nal Server Error. | |
| 899 | * @apiErr orExample Error-Resp onse: | |
| 900 | * HTTP/1. 1 500 Inte rnal Serve r Error | |
| 901 | * { | |
| 902 | * "st atus": 500 , | |
| 903 | * "me ssage": "" | |
| 904 | * } | |
| 905 | */ | |
| 906 | function d eleteWorkP roduct(req , res) { | |
| 907 | req.lo gger.debug ('cds-work -product.d eleteWorkP roduct()') ; | |
| 908 | ||
| 909 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 910 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS work product is unavailab le.'); | |
| 911 | } | |
| 912 | ||
| 913 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 914 | if (error) { | |
| 915 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 916 | } | |
| 917 | re q.logger.d ebug('CDS Work Produ ct DELETE deleteWork Product ca lled'); | |
| 918 | ||
| 919 | va r id = req .query.id; | |
| 920 | ||
| 921 | if (nullchec ker.isNull ish(id)) { | |
| 922 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend('Mis sing or in valid work product i d.'); | |
| 923 | } | |
| 924 | // make sure the id is in a valid format, r eturn the error if n ot... | |
| 925 | va r idValida tionError = testId(i d); | |
| 926 | if (nullchec ker.isNotN ullish(idV alidationE rror)) { | |
| 927 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend(idVa lidationEr ror); | |
| 928 | } | |
| 929 | ||
| 930 | db Connection .collectio n(workColl ection).re move({ | |
| 931 | _id: new ObjectId( id) | |
| 932 | }, function( err, numDe leted) { | |
| 933 | if (null checker.is Nullish(er r)) { | |
| 934 | if ( numDeleted === 0) { | |
| 935 | // no reco rd deleted , id not f ound | |
| 936 | return res .status(rd k.httpstat us.not_fou nd).rdkSen d('Work Pr oduct with id \'' + id + '\' w as not fou nd.'); | |
| 937 | } | |
| 938 | retu rn res.sta tus(rdk.ht tpstatus.o k).rdkSend (numDelete d); | |
| 939 | } | |
| 940 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend(err) ; | |
| 941 | }) ; | |
| 942 | }); | |
| 943 | } | |
| 944 | ||
| 945 | ||
| 946 | /** | |
| 947 | * @api {g et} /resou rce/cds/wo rk-product /subscript ions Retri eves user subscripti ons for th e authenti cated user . | |
| 948 | * @apiNam e retrieve Subscripti ons | |
| 949 | * @apiGro up CDSWork Product | |
| 950 | * | |
| 951 | * @apiDes cription R etrieves u ser subscr iptions fo r the auth enticated user. | |
| 952 | * | |
| 953 | * Priorit y values: ALL (All p riorities) , URG (Urg ent: high + critical priority) , CRIT (Cr itical pri ority) | |
| 954 | * | |
| 955 | * Type va lues: A (a dvice), P (proposal) | |
| 956 | * | |
| 957 | * Special ty values (snomed co des): | |
| 958 | * Allergy 408439002 | |
| 959 | * Critica l Care 408 478003 | |
| 960 | * Dermato logy 39458 2007 | |
| 961 | * Endocri nology 394 582007 | |
| 962 | * Family Medicine 4 19772000 | |
| 963 | * Gastroe nterology 394584008 | |
| 964 | * General Surgery 3 94294004 | |
| 965 | * Hematol ogy and On cology 394 916005 | |
| 966 | * Interna l Medicine 419192003 | |
| 967 | * Neonato logy 40844 5005 | |
| 968 | * Neurolo gy 5639700 3 | |
| 969 | * Obstetr ics and Gy necology 3 09367003 | |
| 970 | * Ophthal mology 394 813003 | |
| 971 | * Rheumat ology 3948 10000 | |
| 972 | * | |
| 973 | * @apiSuc cess {json } data A c ollection of string arrays con taining th e user's s ubscriptio ns. | |
| 974 | * | |
| 975 | * @apiSuc cessExampl e Success- Response: | |
| 976 | * { | |
| 977 | * "st atus": 200 , | |
| 978 | * "da ta": { | |
| 979 | * "specialt y": [ | |
| 980 | * 40843 9002, | |
| 981 | * 40847 8003 | |
| 982 | * ], | |
| 983 | * "priority ": "ALL", | |
| 984 | * "type": [ | |
| 985 | * "P", | |
| 986 | * "A" | |
| 987 | * ] | |
| 988 | * } | |
| 989 | * } | |
| 990 | * | |
| 991 | * @apiErr or (Error 404) Not F ound. | |
| 992 | * @apiErr orExample Error-Resp onse: | |
| 993 | * HTTP/1. 1 404 Inte rnal Serve r Error | |
| 994 | * { | |
| 995 | * "st atus": 404 , | |
| 996 | * "me ssage": "" | |
| 997 | * } | |
| 998 | */ | |
| 999 | function r etrieveSub scriptions (req, res) { | |
| 1000 | req.lo gger.debug ('cds-work -product.r etrieveSub scriptions ()'); | |
| 1001 | ||
| 1002 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 1003 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS work product is unavailab le.'); | |
| 1004 | } | |
| 1005 | ||
| 1006 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 1007 | if (error) { | |
| 1008 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 1009 | } | |
| 1010 | re q.logger.d ebug('CDS Work Produ ct GET ret rieveSubsc riptions c alled'); | |
| 1011 | ||
| 1012 | va r userId = getKeyVal ue(req.ses sion.user. duz); | |
| 1013 | db Connection .collectio n(subscrip tionCollec tion).find One({ | |
| 1014 | user: us erId | |
| 1015 | }, function( err, resul t) { | |
| 1016 | ||
| 1017 | req.logg er.debug(' error: ' + err); | |
| 1018 | req.logg er.debug(' result: ' + result); | |
| 1019 | ||
| 1020 | if (null checker.is Nullish(re sult)) { / / none fou nd - use d efaults. | |
| 1021 | resu lt = defau ltSubscrip tions; | |
| 1022 | } else i f (result && result. data) { // found som e, just pa ss the par t that mat ters. | |
| 1023 | resu lt = resul t.data; | |
| 1024 | } | |
| 1025 | ||
| 1026 | if (null checker.is Nullish(er r)) { | |
| 1027 | //de fault stat us is 'ok' | |
| 1028 | retu rn res.sta tus(rdk.ht tpstatus.o k).rdkSend (result); | |
| 1029 | } | |
| 1030 | //this s hould be u nreachable in practi ce, since we default the respo nse. | |
| 1031 | return r es.status( rdk.httpst atus.not_f ound).rdkS end(err); | |
| 1032 | }) ; | |
| 1033 | }); | |
| 1034 | } | |
| 1035 | ||
| 1036 | ||
| 1037 | /** | |
| 1038 | * @api {p ut} /resou rce/cds/wo rk-product /subscript ions Updat es user su bscription s for the authentica ted user. | |
| 1039 | * @apiNam e updateSu bscription s | |
| 1040 | * @apiGro up CDSWork Product | |
| 1041 | * | |
| 1042 | * @apiDes cription U pdates use r subscrip tions for the authen ticated us er. | |
| 1043 | * | |
| 1044 | * @apiPar amExample {json} Req uest-Examp le: | |
| 1045 | * { | |
| 1046 | * pri ority: "AL L", | |
| 1047 | * spe cialty: [ 408439002, 394582007 ], // spec ialty snom ed codes | |
| 1048 | * typ e: [ "A", "P" ] | |
| 1049 | * } | |
| 1050 | * | |
| 1051 | * @apiSuc cess (Succ ess 201) { json} data with a '1 ' for succ essful mat ch and upd ate, or a '0' for no match and update. | |
| 1052 | * @apiSuc cessExampl e Success- Response: | |
| 1053 | * HTTP/1. 1 200 OK | |
| 1054 | * { | |
| 1055 | * "statu s": 200, | |
| 1056 | * "messa ge": 1 | |
| 1057 | * } | |
| 1058 | * | |
| 1059 | * @apiErr or (Error 500) Inter nal Server Error. | |
| 1060 | * @apiErr orExample Error-Resp onse: | |
| 1061 | * HTTP/1. 1 500 Inte rnal Serve r Error | |
| 1062 | * { | |
| 1063 | * "st atus": 500 , | |
| 1064 | * "me ssage": "" | |
| 1065 | * } | |
| 1066 | */ | |
| 1067 | function u pdateSubsc riptions(r eq, res) { | |
| 1068 | req.lo gger.debug ('cds-work -product.u pdateSubsc riptions() '); | |
| 1069 | ||
| 1070 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 1071 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS work product is unavailab le.'); | |
| 1072 | } | |
| 1073 | ||
| 1074 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 1075 | if (error) { | |
| 1076 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 1077 | } | |
| 1078 | re q.logger.d ebug('CDS Work Produ ct PUT upd ateSubscri ptions cal led'); | |
| 1079 | ||
| 1080 | va r product = req.body ; | |
| 1081 | va r userId = getKeyVal ue(req.ses sion.user. duz); | |
| 1082 | pr oduct.user = userId; | |
| 1083 | ||
| 1084 | db Connection .collectio n(subscrip tionCollec tion).upda te({ | |
| 1085 | user: us erId | |
| 1086 | }, product, { | |
| 1087 | upsert: true | |
| 1088 | }, function( err, numUp dated) { | |
| 1089 | if (null checker.is NotNullish (err)) { | |
| 1090 | req. logger.deb ug('error: ' + err); | |
| 1091 | retu rn res.sta tus(rdk.ht tpstatus.i nternal_se rver_error ).rdkSend( err); | |
| 1092 | } | |
| 1093 | req.logg er.debug(' numUpdated : ' + numU pdated); | |
| 1094 | //this i s an 'upse rt' to no need to ch eck for nu mber of re cords upda ted. Ther e will alw ays be one . | |
| 1095 | //status default i s 'ok' | |
| 1096 | return r es.status( rdk.httpst atus.ok).r dkSend(num Updated); | |
| 1097 | }) ; | |
| 1098 | }); | |
| 1099 | } | |
| 1100 | ||
| 1101 | ||
| 1102 | /** | |
| 1103 | * @api {d elete} /re source/cds /work-prod uct/subscr iptions De letes user subscript ions for t he authent icated use r. | |
| 1104 | * @apiNam e deleteSu bscription s | |
| 1105 | * @apiGro up CDSWork Product | |
| 1106 | * | |
| 1107 | * @apiDes cription D eletes use r subscrip tions for the authen ticated us er. | |
| 1108 | * | |
| 1109 | * @apiSuc cess (Succ ess 201) { json} data with a '1 ' for succ essful mat ch and del ete, or a '0' for no match and delete. | |
| 1110 | * @apiSuc cessExampl e Success- Response: | |
| 1111 | * HTTP/1. 1 200 OK | |
| 1112 | * { | |
| 1113 | * "statu s": 200, | |
| 1114 | * "messa ge": 1 | |
| 1115 | * } | |
| 1116 | * | |
| 1117 | * @apiErr or (Error 404) Not F ound. | |
| 1118 | * @apiErr orExample Error-Resp onse: | |
| 1119 | * HTTP/1. 1 404 Not Found | |
| 1120 | * { | |
| 1121 | * "stat us": 404, | |
| 1122 | * "mess age": "Sub scriptions for user <userId> w as not fou nd." | |
| 1123 | * } | |
| 1124 | * | |
| 1125 | */ | |
| 1126 | function d eleteSubsc riptions(r eq, res) { | |
| 1127 | req.lo gger.debug ('cds-work -product.d eleteSubsc riptions() '); | |
| 1128 | ||
| 1129 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 1130 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS work product is unavailab le.'); | |
| 1131 | } | |
| 1132 | ||
| 1133 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 1134 | if (error) { | |
| 1135 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 1136 | } | |
| 1137 | re q.logger.d ebug('CDS Work Produ ct DELETE deleteSubs criptions called'); | |
| 1138 | ||
| 1139 | va r userId = getKeyVal ue(req.ses sion.user. duz); | |
| 1140 | ||
| 1141 | db Connection .collectio n(subscrip tionCollec tion).remo ve({ | |
| 1142 | user: us erId | |
| 1143 | }, function( err, numDe leted) { | |
| 1144 | if (null checker.is Nullish(er r)) { | |
| 1145 | if ( numDeleted === 0) { | |
| 1146 | // do we w ant to ret urn this e rror in th is case si nce they'd just get the defaul ts anyways ? | |
| 1147 | // no reco rd deleted , id not f ound | |
| 1148 | return res .status(rd k.httpstat us.not_fou nd).rdkSen d('Subscri ptions for user \'' + userId + '\' was n ot found.' ); | |
| 1149 | } | |
| 1150 | retu rn res.sta tus(rdk.ht tpstatus.o k).rdkSend (numDelete d); | |
| 1151 | } | |
| 1152 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend(err) ; | |
| 1153 | }) ; | |
| 1154 | }); | |
| 1155 | } | |
| 1156 | ||
| 1157 | ||
| 1158 | module.exp orts.retri eveInbox = retrieveI nbox; | |
| 1159 | module.exp orts.retri eveWorkPro ductsForPr ovider = r etrieveWor kProductsF orProvider ; | |
| 1160 | module.exp orts.creat eWorkProdu ct = creat eWorkProdu ct; | |
| 1161 | module.exp orts.retri eveWorkPro duct = ret rieveWorkP roduct; | |
| 1162 | module.exp orts.updat eWorkProdu ct = updat eWorkProdu ct; | |
| 1163 | module.exp orts.setRe adStatus = setReadSt atus; | |
| 1164 | module.exp orts.delet eWorkProdu ct = delet eWorkProdu ct; | |
| 1165 | module.exp orts.retri eveSubscri ptions = r etrieveSub scriptions ; | |
| 1166 | module.exp orts.updat eSubscript ions = upd ateSubscri ptions; | |
| 1167 | module.exp orts.delet eSubscript ions = del eteSubscri ptions; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.