Produced by Araxis Merge on 10/3/2017 11:15:45 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 | ehmp.zip\ehmp\ehmp\product\production\vx-sync\subsystems\jds | jds-client.js | Mon Jul 10 17:46:22 2017 UTC |
| 2 | ehmp.zip\ehmp\ehmp\product\production\vx-sync\subsystems\jds | jds-client.js | Tue Oct 3 12:35:27 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 3016 |
| Changed | 1 | 4 |
| 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 | require('. ./../env-s etup'); | |
| 4 | ||
| 5 | var _ = re quire('und erscore'); | |
| 6 | var format = require ('util').f ormat; | |
| 7 | var reques t = requir e('request '); | |
| 8 | var inspec t = requir e(global.V X_UTILS + 'inspect') ; | |
| 9 | var errorU til = requ ire(global .VX_UTILS + 'error') ; | |
| 10 | var objUti l = requir e(global.V X_UTILS + 'object-ut ils'); | |
| 11 | var uuid = require(' node-uuid' ); | |
| 12 | var async = require( 'async'); | |
| 13 | var querys tring = re quire('que rystring') ; | |
| 14 | var sizeof = require ('object-s izeof'); | |
| 15 | ||
| 16 | /* | |
| 17 | config = { | |
| 18 | maxMet astampSize : 20000, | |
| 19 | handle rMaxSocket s: 5 | |
| 20 | jds: { | |
| 21 | pr otocol: 'h ttp' // JD S protocol https|htt p | |
| 22 | host: ' IP ' // JDS I P | |
| 23 | port: PORT // JDS po rt | |
| 24 | ti meout: 600 00 | |
| 25 | } | |
| 26 | } | |
| 27 | */ | |
| 28 | function J dsClient(l og, metric s, config) { | |
| 29 | if (!( this insta nceof JdsC lient)) { | |
| 30 | re turn new J dsClient(l og, metric s, config) ; | |
| 31 | } | |
| 32 | ||
| 33 | this.l og = log; | |
| 34 | this.m etrics = m etrics; | |
| 35 | this.c onfig = co nfig; | |
| 36 | } | |
| 37 | ||
| 38 | JdsClient. prototype. childInsta nce = func tion(child Log) { | |
| 39 | var se lf = this; | |
| 40 | var ne wInstance = new JdsC lient(chil dLog, self .metrics, self.confi g); | |
| 41 | ||
| 42 | return newInstan ce; | |
| 43 | }; | |
| 44 | ||
| 45 | // JdsClie nt.prototy pe.clearJd sData = fu nction(cal lback) { | |
| 46 | // thi s.clearPat ientIdenti fiers(this .clearSync Status(thi s.clearJob States(cal lback))); | |
| 47 | // }; | |
| 48 | ||
| 49 | JdsClient. prototype. saveSyncSt atus = fun ction(meta stamp, pat ientIdenti fier, call back) { | |
| 50 | this.l og.debug(' Jds-client .saveSyncS tatus()'); | |
| 51 | this.l og.debug(i nspect(met astamp)); | |
| 52 | var me tricsObj = { | |
| 53 | 's ubsystem': 'JDS', | |
| 54 | 'a ction': 's aveSyncSta tus', | |
| 55 | 'p id': patie ntIdentifi er.value, | |
| 56 | 'p rocess': u uid.v4(), | |
| 57 | 't imer': 'st art' | |
| 58 | }; | |
| 59 | this.m etrics.deb ug('JDS Sa ve Sync St atus', met ricsObj); | |
| 60 | var se lf = this; | |
| 61 | ||
| 62 | if (!p atientIden tifier) { | |
| 63 | me tricsObj.t imer = 'st op'; | |
| 64 | th is.metrics .debug('JD S Save Syn c Status i n Error', metricsObj ); | |
| 65 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No patie ntIdentifi er object passed in' )); | |
| 66 | } | |
| 67 | ||
| 68 | var id entifierVa lue = pati entIdentif ier.value; | |
| 69 | if (pa tientIdent ifier.type === 'edip i') { | |
| 70 | id entifierVa lue = 'DOD ;' + ident ifierValue ; | |
| 71 | } | |
| 72 | ||
| 73 | var pa th = '/sta tus/' + id entifierVa lue; | |
| 74 | var me tastampJob s = self._ ensureMeta stampSize( metastamp, self.conf ig.maxMeta stampSize || 20000); | |
| 75 | if (me tastampJob s.length > 1) { | |
| 76 | se lf.log.war n('JdsClie nt.saveSyn cStatus() metastamp broken int o %s parts ', metasta mpJobs.len gth); | |
| 77 | } | |
| 78 | async. each(metas tampJobs, function(s tamp, cb) { | |
| 79 | se lf.execute (path, sta mp, 'POST' , metricsO bj, cb); | |
| 80 | }, fun ction(err) { | |
| 81 | va r response = {}; //h ardcoded t o account for inabil ity to mer ge multipl e response s | |
| 82 | if (!err) { | |
| 83 | response .statusCod e = 200; | |
| 84 | } | |
| 85 | ca llback(err , response ); | |
| 86 | }); | |
| 87 | }; | |
| 88 | ||
| 89 | ||
| 90 | ||
| 91 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 92 | // Variadi c Function | |
| 93 | // getSync Status(pat ientIdenti fier, filt er, callba ck) | |
| 94 | // getSync Status(pat ientIdenti fier, call back) | |
| 95 | // | |
| 96 | // This me thod fetch es a sync status for a patient with the filter (if any) | |
| 97 | // appende d to the u rl. | |
| 98 | // | |
| 99 | // patient Identifier : A patien t identifi er in stan dard VxSyn c format. e.g.: | |
| 100 | // { | |
| 101 | // type : 'pid', | |
| 102 | // valu e: '9E7A;3 ' | |
| 103 | // } | |
| 104 | // | |
| 105 | // filter: An object containin g a 'filte r' propert y with the string to append | |
| 106 | // to the u rl of the sync statu s endpoint . Note tha t any esca ping, etc. | |
| 107 | // must be performed prior to p assing it to this me thod as th e value in | |
| 108 | // the 'fil ter' attri bute will be appende d as-is. A n example value for | |
| 109 | // this par ameter cou ld be: | |
| 110 | // { | |
| 111 | // filt er: '?deta iled=true& filter=lt( "stampTime ",20170101 000000)' | |
| 112 | // } | |
| 113 | // Alternat ively, the 'filter' parameter can be a s tring, whi ch will | |
| 114 | // used as the filter . e.g.: | |
| 115 | // '?detail ed=true&fi lter=lt("s tampTime", 2017010100 0000)' | |
| 116 | // | |
| 117 | // callbac k: The fun ction to i nvoke upon error or completion of the fe tch. | |
| 118 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 119 | JdsClient. prototype. getSyncSta tus = func tion(patie ntIdentifi er, filter , callback ) { | |
| 120 | this.l og.debug(' Jds-client .getSyncSt atus()'); | |
| 121 | this.l og.debug(i nspect(pat ientIdenti fier)); | |
| 122 | var me tricsObj = { | |
| 123 | 's ubsystem': 'JDS', | |
| 124 | 'a ction': 'g etSyncStat us', | |
| 125 | 'p id': patie ntIdentifi er.value, | |
| 126 | 'p rocess': u uid.v4(), | |
| 127 | 't imer': 'st art' | |
| 128 | }; | |
| 129 | this.m etrics.deb ug('JDS Ge t Sync Sta tus', metr icsObj); | |
| 130 | ||
| 131 | var ar gs = _.toA rray(argum ents); | |
| 132 | callba ck = args. pop(); | |
| 133 | filter = args.le ngth > 1 ? args.pop( ) : null; | |
| 134 | ||
| 135 | var pa th = '/sta tus/' + pa tientIdent ifier.valu e; | |
| 136 | ||
| 137 | if (!_ .isEmpty(f ilter)) { | |
| 138 | if (_.isStri ng(filter) ) { | |
| 139 | path += filter; | |
| 140 | } else if (! _.isEmpty( filter.fil ter)) { | |
| 141 | path += filter.fil ter; | |
| 142 | } | |
| 143 | } | |
| 144 | ||
| 145 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 146 | }; | |
| 147 | ||
| 148 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 149 | // Variadi c Function | |
| 150 | // getSimp leSyncStat us(patient Identifier , filter, callback) | |
| 151 | // getSimp leSyncStat us(patient Identifier , callback ) | |
| 152 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 153 | JdsClient. prototype. getSimpleS yncStatus = function (patientId entifier, callback) { | |
| 154 | this.l og.debug(' Jds-client .getSimple SyncStatus ()'); | |
| 155 | this.l og.debug(i nspect(pat ientIdenti fier)); | |
| 156 | var me tricsObj = { | |
| 157 | 's ubsystem': 'JDS', | |
| 158 | 'a ction': 'g etSimpleSy ncStatus', | |
| 159 | 'p id': patie ntIdentifi er.value, | |
| 160 | 'p rocess': u uid.v4(), | |
| 161 | 't imer': 'st art' | |
| 162 | }; | |
| 163 | this.m etrics.deb ug('JDS Ge t Simple S ync Status ', metrics Obj); | |
| 164 | ||
| 165 | var ar gs = _.toA rray(argum ents); | |
| 166 | callba ck = args. pop(); | |
| 167 | ||
| 168 | ||
| 169 | var pa th = '/syn c/combined stat/' + p atientIden tifier.val ue; | |
| 170 | ||
| 171 | if (ar guments.le ngth > 2) { | |
| 172 | pa th += argu ments[1].f ilter; | |
| 173 | } | |
| 174 | ||
| 175 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 176 | }; | |
| 177 | ||
| 178 | JdsClient. prototype. clearSyncS tatus = fu nction(cal lback) { | |
| 179 | this.l og.debug(' Jds-client .clearSync Status()') ; | |
| 180 | var me tricsObj = { | |
| 181 | 's ubsystem': 'JDS', | |
| 182 | 'a ction': 'c learSyncSt atus', | |
| 183 | 'p rocess': u uid.v4(), | |
| 184 | 't imer': 'st art' | |
| 185 | }; | |
| 186 | this.m etrics.deb ug('JDS Cl ear Sync S tatus', me tricsObj); | |
| 187 | ||
| 188 | var pa th = '/sta tus'; | |
| 189 | var me thod = 'DE LETE'; | |
| 190 | this.e xecute(pat h, null, m ethod, met ricsObj, c allback); | |
| 191 | }; | |
| 192 | ||
| 193 | JdsClient. prototype. saveJobSta te = funct ion(jobSta te, callba ck) { | |
| 194 | this.l og.debug(' Jds-client .saveJobSt ate()'); | |
| 195 | this.l og.debug(i nspect(job State)); | |
| 196 | var me tricsObj = { | |
| 197 | 's ubsystem': 'JDS', | |
| 198 | 'a ction': 's aveJobStat e', | |
| 199 | 'j pid': jobS tate.jpid, | |
| 200 | 'j obId': job State.jobI d, | |
| 201 | 'r ootJobId': jobState. rootJobId, | |
| 202 | 'j obType': j obState.ty pe, | |
| 203 | 'p rocess': u uid.v4(), | |
| 204 | 't imer': 'st art' | |
| 205 | }; | |
| 206 | if (jo bState.rec ord) { | |
| 207 | me tricsObj.p id = jobSt ate.record .pid; | |
| 208 | me tricsObj.u id = jobSt ate.record .uid; | |
| 209 | } | |
| 210 | this.m etrics.deb ug('JDS Sa ve Job Sta te', metri csObj); | |
| 211 | ||
| 212 | var pa th = '/job '; | |
| 213 | this.e xecute(pat h, jobStat e, 'POST', metricsOb j, callbac k); | |
| 214 | }; | |
| 215 | ||
| 216 | ||
| 217 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 218 | // Variadi c Function : | |
| 219 | // getJobS tatus(job, callback) | |
| 220 | // getJobS tatus(job, filter, c allback) | |
| 221 | // | |
| 222 | // job: An object wi th a "jpid " attribut e or a "pa tientIdent ifier" att ribute (se e below). | |
| 223 | // | |
| 224 | // filter: An object with a "f ilter" att ribute. If this valu e is empty , null, un defined, o r | |
| 225 | // does not have a "fi lter" attr ibute, the n it is ig nored and the call w ill be mad e | |
| 226 | // without a filter. T he filter attribute should be of the for m: '?filte r=<filter> ' | |
| 227 | // where <fi lter> is a filter fo r the JDS store: ?fi lter=eq(ty pe,"enterp rise-sync- request") | |
| 228 | // | |
| 229 | // The "jo b" paramet er can hav e two form ats: | |
| 230 | // { | |
| 231 | // jpi d: 6c2d958 9-7554-469 a-b480-d71 f9d2a5d64 | |
| 232 | // } | |
| 233 | // | |
| 234 | // or | |
| 235 | // | |
| 236 | // { | |
| 237 | // pat ientIdenti fier: { | |
| 238 | // value: '6 c2d9589-75 54-469a-b4 80-d71f9d2 a5d64' | |
| 239 | // } | |
| 240 | // } | |
| 241 | // | |
| 242 | // If the "job" para meter has both the " jpid" AND "patientId entifier" attributes , the "jpi d" | |
| 243 | // attribu te will ta ke precede nce. | |
| 244 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 245 | JdsClient. prototype. getJobStat us = funct ion(job, c allback) { | |
| 246 | this.l og.debug(' Jds-client .getJobSta tus() %j', job); | |
| 247 | this.l og.debug(i nspect(job )); | |
| 248 | var me tricsObj = { | |
| 249 | 's ubsystem': 'JDS', | |
| 250 | 'a ction': 'g etJobStatu s', | |
| 251 | 'j pid': job. jpid, | |
| 252 | 'p rocess': u uid.v4(), | |
| 253 | 't imer': 'st art' | |
| 254 | }; | |
| 255 | this.m etrics.deb ug('JDS Ge t Job Stat us', metri csObj); | |
| 256 | ||
| 257 | if (ar guments.le ngth < 2) { | |
| 258 | me tricsObj.t imer = 'st op'; | |
| 259 | th is.metrics .debug('JD S Get Job Status in Error', me tricsObj); | |
| 260 | re turn setTi meout(call back, 0, ' Invalid nu mber of ar guments'); | |
| 261 | } | |
| 262 | ||
| 263 | var ar gs = _.toA rray(argum ents); | |
| 264 | callba ck = args. pop(); | |
| 265 | ||
| 266 | // Fig ure out wh at identif ier we are going to use... jpi d or patie nt identif ier. | |
| 267 | //---- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----- | |
| 268 | var pa rams = obj Util.getPr operty(arg uments[0], 'jpid') | | objUtil. getPropert y(argument s[0], 'pat ientIdenti fier', 'va lue'); | |
| 269 | if (ar guments.le ngth > 2 & & _.has(ar guments[1] , 'filter' )) { | |
| 270 | pa rams += ar guments[1] .filter; | |
| 271 | } | |
| 272 | ||
| 273 | var pa th = '/job /' + param s; | |
| 274 | this.e xecute(pat h, job, 'G ET', metri csObj, cal lback); | |
| 275 | }; | |
| 276 | ||
| 277 | JdsClient. prototype. clearJobSt atesByPati entIdentif ier = func tion(patie ntIdentifi er, callba ck) { | |
| 278 | var me tricsObj = { | |
| 279 | 's ubsystem': 'JDS', | |
| 280 | 'a ction': 'c learJobSta tesByPatie ntIdentifi er', | |
| 281 | 'p id': patie ntIdentifi er.value, | |
| 282 | 'p rocess': u uid.v4(), | |
| 283 | 't imer': 'st art' | |
| 284 | }; | |
| 285 | this.m etrics.deb ug('JDS Cl ear Job St ates by PI D', metric sObj); | |
| 286 | var pa th = '/job /' + patie ntIdentifi er.value; | |
| 287 | var me thod = 'DE LETE'; | |
| 288 | this.e xecute(pat h, null, m ethod, met ricsObj, c allback); | |
| 289 | }; | |
| 290 | ||
| 291 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 292 | // This me thod retri eves the p atient Ide ntifier li st from JD S for the | |
| 293 | // patient Identifier in the gi ven job. | |
| 294 | // | |
| 295 | // job: T he job for the patie nt. | |
| 296 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 297 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 298 | JdsClient. prototype. getPatient Identifier = functio n(job, cal lback) { | |
| 299 | this.l og.debug(' jds-client .getPatien tIdentifie r() %j', j ob); | |
| 300 | ||
| 301 | this.g etPatientI dentifierB yPid(job.p atientIden tifier.val ue, callba ck); | |
| 302 | }; | |
| 303 | ||
| 304 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 305 | // This me thod retri eves the p atient Ide ntifier li st from JD S for the given | |
| 306 | // pid. | |
| 307 | // | |
| 308 | // pid: T he pid for the patie nt. | |
| 309 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 310 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 311 | JdsClient. prototype. getPatient Identifier ByPid = fu nction(pid , callback ) { | |
| 312 | this.l og.debug(' jds-client .getPatien tIdentifie rByPid() % j', pid); | |
| 313 | var me tricsObj = { | |
| 314 | 's ubsystem': 'JDS', | |
| 315 | 'a ction': 'g etPatientI dentifierB yPid', | |
| 316 | 'p id': pid, | |
| 317 | 'p rocess': u uid.v4(), | |
| 318 | 't imer': 'st art' | |
| 319 | }; | |
| 320 | this.m etrics.deb ug('JDS Ge t Correspo nding IDs by PID', m etricsObj) ; | |
| 321 | ||
| 322 | var pa th = '/vpr /jpid/' + pid; | |
| 323 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 324 | }; | |
| 325 | ||
| 326 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 327 | // This me thod retri eves the p atient Ide ntifier li st from JD S for the given | |
| 328 | // icn. | |
| 329 | // | |
| 330 | // icn: T he icn for the patie nt. | |
| 331 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 332 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- | |
| 333 | JdsClient. prototype. getPatient Identifier ByIcn = fu nction(icn , callback ) { | |
| 334 | this.l og.debug(' jds-client .getPatien tIdentifie rByIcn() % j', icn); | |
| 335 | var me tricsObj = { | |
| 336 | 's ubsystem': 'JDS', | |
| 337 | 'a ction': 'g etPatientI dentifierB yIcn', | |
| 338 | 'p id': icn, | |
| 339 | 'p rocess': u uid.v4(), | |
| 340 | 't imer': 'st art' | |
| 341 | }; | |
| 342 | this.m etrics.deb ug('JDS Ge t Correspo nding IDs by PID', m etricsObj) ; | |
| 343 | ||
| 344 | var pa th = '/vpr /jpid/' + icn; | |
| 345 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 346 | }; | |
| 347 | ||
| 348 | JdsClient. prototype. storePatie ntIdentifi er = funct ion(jdsPat ientIdenti ficationRe quest, cal lback) { | |
| 349 | this.l og.debug(' jds-client .storePati entIdentif ier() %j', jdsPatien tIdentific ationReque st); | |
| 350 | this.l og.debug(j dsPatientI dentificat ionRequest .jpid || ' No JPID pr ovided.'); | |
| 351 | var me tricsObj = { | |
| 352 | 's ubsystem': 'JDS', | |
| 353 | 'a ction': 's torePatien tIdentifie r', | |
| 354 | 'j pid': jdsP atientIden tification Request.jp id, | |
| 355 | 'p id': jdsPa tientIdent ificationR equest.pat ientIdenti fiers, | |
| 356 | 'p rocess': u uid.v4(), | |
| 357 | 't imer': 'st art' | |
| 358 | }; | |
| 359 | this.m etrics.deb ug('JDS St ore Patien t Identifi er', metri csObj); | |
| 360 | ||
| 361 | var pa th = '/vpr /jpid/'; | |
| 362 | if (ty peof jdsPa tientIdent ificationR equest.jpi d !== 'und efined') { | |
| 363 | pa th += jdsP atientIden tification Request.jp id; | |
| 364 | } | |
| 365 | ||
| 366 | this.e xecute(pat h, jdsPati entIdentif icationReq uest, 'POS T', metric sObj, call back); | |
| 367 | }; | |
| 368 | ||
| 369 | JdsClient. prototype. removePati entIdentif ier = func tion(jpid, callback) { | |
| 370 | this.l og.debug(' jds-client .removePat ientIdenti fier() %j' , jpid); | |
| 371 | var me tricsObj = { | |
| 372 | 's ubsystem': 'JDS', | |
| 373 | 'a ction': 'r emovePatie ntIdentifi er', | |
| 374 | 'j pid': jpid , | |
| 375 | 'p rocess': u uid.v4(), | |
| 376 | 't imer': 'st art' | |
| 377 | }; | |
| 378 | this.m etrics.deb ug('JDS Re move Patie nt Identif ier', metr icsObj); | |
| 379 | ||
| 380 | var pa th = '/vpr /jpid/' + jpid; | |
| 381 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 382 | }; | |
| 383 | ||
| 384 | JdsClient. prototype. clearPatie ntIdentifi ers = func tion(callb ack) { | |
| 385 | this.l og.debug(' jds-client .clearPati entIdentif iers()'); | |
| 386 | var me tricsObj = { | |
| 387 | 's ubsystem': 'JDS', | |
| 388 | 'a ction': 'c learPatien tIdentifie rs', | |
| 389 | 'p rocess': u uid.v4(), | |
| 390 | 't imer': 'st art' | |
| 391 | }; | |
| 392 | this.m etrics.deb ug('JDS Cl ear Patien t Identifi ers', metr icsObj); | |
| 393 | ||
| 394 | var pa th = '/vpr /jpid/clea r'; | |
| 395 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 396 | }; | |
| 397 | ||
| 398 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 399 | // Store t he object in the ope rational d ata store area of th e JDS. | |
| 400 | // | |
| 401 | // operati onalData: The object that repr esents the operation al data to be stored . | |
| 402 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 403 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 404 | JdsClient. prototype. storeOpera tionalData = functio n(operatio nalData, c allback) { | |
| 405 | this.l og.debug(' jds-client .storeOper ationalDat a()'); | |
| 406 | var me tricsObj = { | |
| 407 | 's ubsystem': 'JDS', | |
| 408 | 'a ction': 's toreOperat ionalData' , | |
| 409 | 's ite': oper ationalDat a.systemId , | |
| 410 | 'u id': opera tionalData .uid, | |
| 411 | 'p rocess': u uid.v4(), | |
| 412 | 't imer': 'st art' | |
| 413 | }; | |
| 414 | this.m etrics.deb ug('JDS St ore OPD', metricsObj ); | |
| 415 | ||
| 416 | if (_. isEmpty(op erationalD ata)) { | |
| 417 | me tricsObj.t imer = 'st op'; | |
| 418 | th is.metrics .debug('JD S Store OP D in Error ', metrics Obj); | |
| 419 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No recor d passed i n')); | |
| 420 | } | |
| 421 | ||
| 422 | var pa th = '/dat a'; | |
| 423 | this.e xecute(pat h, operati onalData, 'POST', me tricsObj, callback); | |
| 424 | }; | |
| 425 | ||
| 426 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -- | |
| 427 | // Retriev e pt-selec t data usi ng the pat ient's pid . | |
| 428 | // | |
| 429 | // pid: Th e pid to u se to retr ieve the p t-select d ata. | |
| 430 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 431 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --- | |
| 432 | JdsClient. prototype. getOperati onalDataPt SelectByPi d = functi on(pid, ca llback) { | |
| 433 | this.l og.debug(' jds-client .getOperat ionalDataP tSelectByP id() %j', pid); | |
| 434 | var me tricsObj = { | |
| 435 | 's ubsystem': 'JDS', | |
| 436 | 'a ction': 'g etOperatio nalDataPtS electByPid ', | |
| 437 | 'p id': pid, | |
| 438 | 'p rocess': u uid.v4(), | |
| 439 | 't imer': 'st art' | |
| 440 | }; | |
| 441 | this.m etrics.deb ug('JDS Ge t PT Selec t by PID', metricsOb j); | |
| 442 | ||
| 443 | if (_. isEmpty(pi d)) { | |
| 444 | me tricsObj.t imer = 'st op'; | |
| 445 | th is.metrics .debug('JD S Get PT S elect by P ID in Erro r', metric sObj); | |
| 446 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No pid p assed in') ); | |
| 447 | } | |
| 448 | ||
| 449 | var pa th = '/dat a/index/pt -select-pi d?range="' + pid + ' "'; | |
| 450 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 451 | }; | |
| 452 | ||
| 453 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -- | |
| 454 | // Retriev e pt-selec t data usi ng the pat ient's icn . | |
| 455 | // | |
| 456 | // icn: Th e icn to u se to retr ieve the p t-select d ata. | |
| 457 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 458 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --- | |
| 459 | JdsClient. prototype. getOperati onalDataPt SelectByIc n = functi on(icn, ca llback) { | |
| 460 | this.l og.debug(' jds-client .getOperat ionalDataP tSelectByI cn() %j', icn); | |
| 461 | var me tricsObj = { | |
| 462 | 's ubsystem': 'JDS', | |
| 463 | 'a ction': 'g etOperatio nalDataPtS electByIcn ', | |
| 464 | 'p id': icn, | |
| 465 | 'p rocess': u uid.v4(), | |
| 466 | 't imer': 'st art' | |
| 467 | }; | |
| 468 | this.m etrics.deb ug('JDS Ge t PT Selec t by ICN', metricsOb j); | |
| 469 | ||
| 470 | if (_. isEmpty(ic n)) { | |
| 471 | me tricsObj.t imer = 'st op'; | |
| 472 | th is.metrics .debug('JD S Get PT S elect by I CN in Erro r', metric sObj); | |
| 473 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No icn p assed in') ); | |
| 474 | } | |
| 475 | ||
| 476 | var pa th = '/dat a/index/pt -select-ic n?range="' + icn + ' "'; | |
| 477 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 478 | }; | |
| 479 | ||
| 480 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 481 | // Retriev e the oper ational da ta object by its UID . | |
| 482 | // | |
| 483 | // uid: Th e UID that identifie s the oper ational da ta item be ing retrie ved. | |
| 484 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 485 | // Returns (through call back ): the Ope rational d ata item. | |
| 486 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 487 | JdsClient. prototype. getOperati onalDataBy Uid = func tion(uid, callback) { | |
| 488 | this.l og.debug(' jds-client .getOperat ionalDataB yUid() %j' , uid); | |
| 489 | var me tricsObj = { | |
| 490 | 's ubsystem': 'JDS', | |
| 491 | 'a ction': 'g etOperatio nalDataByU id', | |
| 492 | 'u id': uid, | |
| 493 | 'p rocess': u uid.v4(), | |
| 494 | 't imer': 'st art' | |
| 495 | }; | |
| 496 | this.m etrics.deb ug('JDS Ge t PT Selec t by UID', metricsOb j); | |
| 497 | ||
| 498 | if (_. isEmpty(ui d)) { | |
| 499 | me tricsObj.t imer = 'st op'; | |
| 500 | th is.metrics .debug('JD S Get PT S elect by U ID in Erro r', metric sObj); | |
| 501 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No uid p assed in') ); | |
| 502 | } | |
| 503 | ||
| 504 | var pa th = '/dat a/' + uid; | |
| 505 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 506 | }; | |
| 507 | ||
| 508 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 509 | // Delete the operat ional data object by its UID. | |
| 510 | // | |
| 511 | // uid: Th e UID that identifie s the oper ational da ta item be ing delete d. | |
| 512 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 513 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 514 | JdsClient. prototype. deleteOper ationalDat aByUid = f unction(ui d, callbac k) { | |
| 515 | this.l og.debug(' jds-client .deleteOpe rationalDa taByUid() %j', uid); | |
| 516 | var me tricsObj = { | |
| 517 | 's ubsystem': 'JDS', | |
| 518 | 'a ction': 'd eleteOpera tionalData ByUid', | |
| 519 | 'u id': uid, | |
| 520 | 'p rocess': u uid.v4(), | |
| 521 | 't imer': 'st art' | |
| 522 | }; | |
| 523 | this.m etrics.deb ug('JDS De lete OPD b y UID', me tricsObj); | |
| 524 | ||
| 525 | if (_. isEmpty(ui d)) { | |
| 526 | me tricsObj.t imer = 'st op'; | |
| 527 | th is.metrics .debug('JD S Delete O PD by UID in Error', metricsOb j); | |
| 528 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No uid p assed in') ); | |
| 529 | } | |
| 530 | ||
| 531 | var pa th = '/dat a/' + uid; | |
| 532 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 533 | }; | |
| 534 | ||
| 535 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 536 | // Retriev e the oper ational da ta objects for clini cs by site from the location c ollection | |
| 537 | // | |
| 538 | // site: T he site th at filters the opera tional cli nic data i tem being retrieved. | |
| 539 | // clinic: The clini c that fur ther filte rs the ope rational c linic data being ret rieved. | |
| 540 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 541 | // Returns (through call back ): the Ope rational d ata item. | |
| 542 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 543 | JdsClient. prototype. getOperati onalDataBy SiteAndCli nic = func tion(site, clinic, c allback) { | |
| 544 | this.l og.debug(' jds-client .getOperat ionalDataB ySiteAndCl inic() %j: %j', site , clinic); | |
| 545 | ||
| 546 | var me tricsObj = { | |
| 547 | 's ubsystem': 'JDS', | |
| 548 | 'a ction': 'g etOperatio nalDataByS iteAndClin ic', | |
| 549 | 's ite': site , | |
| 550 | 'c linic': cl inic, | |
| 551 | 'p rocess': u uid.v4(), | |
| 552 | 't imer': 'st art' | |
| 553 | }; | |
| 554 | this.m etrics.deb ug('JDS Ge t OPD Data By Site a nd Clinic' , metricsO bj); | |
| 555 | ||
| 556 | if (!s ite) { | |
| 557 | me tricsObj.t imer = 'st op'; | |
| 558 | th is.metrics .debug('JD S Get OPD by site an d clinic i n Error', metricsObj ); | |
| 559 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No site passed in' )); | |
| 560 | } else if (!clin ic) { | |
| 561 | me tricsObj.t imer = 'st op'; | |
| 562 | th is.metrics .debug('JD S Get OPD by site an d clinic i n Error', metricsObj ); | |
| 563 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No clini c passed i n')); | |
| 564 | } | |
| 565 | ||
| 566 | var pa th = '/dat a/find/loc ation?filt er=ilike(" uid","%25: ' + site + ':%25"),i like("name ","' + cli nic + '")' ; | |
| 567 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 568 | }; | |
| 569 | ||
| 570 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 571 | // Store t he object in the mut able opera tional dat a store ar ea of the JDS. | |
| 572 | // | |
| 573 | // operati onalData: The object that repr esents the operation al data to be stored . | |
| 574 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 575 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 576 | JdsClient. prototype. storeOpera tionalData Mutable = function(o perational Data, call back) { | |
| 577 | this.l og.debug(' jds-client .storeOper ationalDat aMutable() '); | |
| 578 | var me tricsObj = { | |
| 579 | 's ubsystem': 'JDS', | |
| 580 | 'a ction': 's toreOperat ionalDataM utable', | |
| 581 | 'u id': opera tionalData .uid, | |
| 582 | 'p rocess': u uid.v4(), | |
| 583 | 't imer': 'st art' | |
| 584 | }; | |
| 585 | this.m etrics.deb ug('JDS St ore OPD Mu table', me tricsObj); | |
| 586 | ||
| 587 | if (_. isEmpty(op erationalD ata)) { | |
| 588 | me tricsObj.t imer = 'st op'; | |
| 589 | th is.metrics .debug('JD S Store OP D Mutable in Error', metricsOb j); | |
| 590 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No recor d passed i n')); | |
| 591 | } | |
| 592 | ||
| 593 | var pa th = '/odm utable/set /this'; | |
| 594 | this.e xecute(pat h, operati onalData, 'POST', me tricsObj, callback); | |
| 595 | }; | |
| 596 | ||
| 597 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 598 | // Retriev e mutable operationa l data obj ect by sit e id. | |
| 599 | // | |
| 600 | // siteId: The site id that id entifies t he operati onal data item being retrieved . | |
| 601 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 602 | // Returns (through call back ): the Ope rational d ata item. | |
| 603 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 604 | JdsClient. prototype. getOperati onalDataMu table = fu nction(sit eId, callb ack) { | |
| 605 | this.l og.debug(' jds-client .getOperat ionalDataM utable() % j', siteId ); | |
| 606 | var me tricsObj = { | |
| 607 | 's ubsystem': 'JDS', | |
| 608 | 'a ction': 'g etOperatio nalDataMut able', | |
| 609 | 's ite': site Id, | |
| 610 | 'p rocess': u uid.v4(), | |
| 611 | 't imer': 'st art' | |
| 612 | }; | |
| 613 | this.m etrics.deb ug('JDS Ge t OPD Muta ble', metr icsObj); | |
| 614 | ||
| 615 | if (_. isEmpty(si teId)) { | |
| 616 | me tricsObj.t imer = 'st op'; | |
| 617 | th is.metrics .debug('JD S Get OPD Mutable in Error', m etricsObj) ; | |
| 618 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No uid p assed in') ); | |
| 619 | } | |
| 620 | ||
| 621 | var pa th = '/odm utable/get /' + siteI d; | |
| 622 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 623 | }; | |
| 624 | ||
| 625 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 626 | // Retriev e multiple mutable o perational data obje cts by a f ilter | |
| 627 | // | |
| 628 | // filter: A JDS fil ter string (required !) | |
| 629 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 630 | // Returns (through call back ): an arra y of items . | |
| 631 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 632 | JdsClient. prototype. getOperati onalDataMu tableByFil ter = func tion(filte rString, c allback) { | |
| 633 | this.l og.debug(' jds-client .getOperat ionalDataM utableByFi lter'); | |
| 634 | var me tricsObj = { | |
| 635 | 's ubsystem': 'JDS', | |
| 636 | 'a ction': 'g etOperatio nalDataMut ableByFilt er', | |
| 637 | 'f ilterStrin g': filter String, | |
| 638 | 'p rocess': u uid.v4(), | |
| 639 | 't imer': 'st art' | |
| 640 | }; | |
| 641 | this.m etrics.deb ug('JDS Ge t All OPD Mutable', metricsObj ); | |
| 642 | ||
| 643 | if (_. isEmpty(fi lterString )) { | |
| 644 | me tricsObj.t imer = 'st op'; | |
| 645 | th is.metrics .debug('JD S Get OPD Mutable By Filter in Error', m etricsObj) ; | |
| 646 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No filte rString pa ssed in')) ; | |
| 647 | } | |
| 648 | ||
| 649 | var pa th = '/odm utable/get /' + filte rString; | |
| 650 | ||
| 651 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 652 | }; | |
| 653 | ||
| 654 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 655 | // Get the number of objects i n the muta ble operat ional data store | |
| 656 | // | |
| 657 | // Returns (through call back ): the Ope rational d ata item. | |
| 658 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 659 | JdsClient. prototype. getOperati onalDataMu tableCount = functio n(callback ) { | |
| 660 | this.l og.debug(' jds-client .getOperat ionalDataM utableCoun t()'); | |
| 661 | var me tricsObj = { | |
| 662 | 's ubsystem': 'JDS', | |
| 663 | 'a ction': 'g etOperatio nalDataMut ableCount' , | |
| 664 | 'p rocess': u uid.v4(), | |
| 665 | 't imer': 'st art' | |
| 666 | }; | |
| 667 | this.m etrics.deb ug('JDS Ge t OPD Muta ble Count' , metricsO bj); | |
| 668 | ||
| 669 | var pa th = '/odm utable/len gth/this'; | |
| 670 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 671 | }; | |
| 672 | ||
| 673 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 674 | // Delete the mutabl e operatio nal data o bject by t he site id . | |
| 675 | // | |
| 676 | // siteId: The site id that id entifies t he site fo r which si te specifi c operatio nal data s hould be d eleted. | |
| 677 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 678 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 679 | JdsClient. prototype. deleteOper ationalDat aMutable = function( siteId, ca llback) { | |
| 680 | this.l og.debug(' jds-client .deleteOpe rationalDa taMutable( ) %j', sit eId); | |
| 681 | var me tricsObj = { | |
| 682 | 's ubsystem': 'JDS', | |
| 683 | 'a ction': 'd eleteOpera tionalData Mutable', | |
| 684 | 's ite': site Id, | |
| 685 | 'p rocess': u uid.v4(), | |
| 686 | 't imer': 'st art' | |
| 687 | }; | |
| 688 | this.m etrics.deb ug('JDS Ge t OPD Muta ble Count' , metricsO bj); | |
| 689 | ||
| 690 | if (_. isEmpty(si teId)) { | |
| 691 | me tricsObj.t imer = 'st op'; | |
| 692 | th is.metrics .debug('JD S Get OPD Mutable Co unt in Err or', metri csObj); | |
| 693 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No site id passed in')); | |
| 694 | } | |
| 695 | ||
| 696 | var pa th = '/odm utable/des troy/' + s iteId; | |
| 697 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 698 | }; | |
| 699 | ||
| 700 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 701 | // Delete all mutabl e operatio nal data. | |
| 702 | // | |
| 703 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 704 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 705 | JdsClient. prototype. clearOpera tionalData MutableSto rage = fun ction(call back) { | |
| 706 | this.l og.debug(' jds-client .clearOper ationalDat aMutableSt orage()'); | |
| 707 | var me tricsObj = { | |
| 708 | 's ubsystem': 'JDS', | |
| 709 | 'a ction': 'c learOperat ionalDataM utableStor age', | |
| 710 | 'p rocess': u uid.v4(), | |
| 711 | 't imer': 'st art' | |
| 712 | }; | |
| 713 | this.m etrics.deb ug('JDS Cl ear OPD Mu table Stor age', metr icsObj); | |
| 714 | ||
| 715 | var pa th = '/odm utable/cle ar/this'; | |
| 716 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 717 | }; | |
| 718 | ||
| 719 | JdsClient. prototype. saveOperat ionalSyncS tatus = fu nction(met astamp, si teId, call back) { | |
| 720 | this.l og.debug(' JdsClient. saveOperat ionalSyncS tatus() %j ', siteId) ; | |
| 721 | this.l og.debug(i nspect(met astamp)); | |
| 722 | var me tricsObj = { | |
| 723 | 's ubsystem': 'JDS', | |
| 724 | 'a ction': 's aveOperati onalSyncSt atus', | |
| 725 | 's ite': site Id, | |
| 726 | 'p rocess': u uid.v4(), | |
| 727 | 't imer': 'st art' | |
| 728 | }; | |
| 729 | this.m etrics.deb ug('JDS Sa ve OPD Syn c Status', metricsOb j); | |
| 730 | var se lf = this; | |
| 731 | ||
| 732 | var pa th = '/sta tusod/' + siteId; | |
| 733 | // sel f.log.info ('JdsClien t.saveOper ationalSyn cStatus() %j',metast amp); | |
| 734 | var me tastampJob s = self._ ensureMeta stampSize( metastamp, self.conf ig.maxMeta stampSize || 20000); | |
| 735 | if (me tastampJob s.length > 1) { | |
| 736 | se lf.log.war n('JdsClie nt.saveOpe rationalSy ncStatus() metastamp broken in to %s part s', metast ampJobs.le ngth); | |
| 737 | // self.log. info('JdsC lient.save Operationa lSyncStatu s() %j',me tastampJob s[0]); | |
| 738 | } | |
| 739 | async. each(metas tampJobs, function(s tamp, cb) { | |
| 740 | se lf.log.inf o('JdsClie nt.saveOpe rationalSy ncStatus() %j', stam p); | |
| 741 | se lf.execute (path, sta mp, 'POST' , metricsO bj, cb); | |
| 742 | }, fun ction(err) { | |
| 743 | va r response = {}; //h ardcoded t o account for inabil ity to mer ge multipl e response s | |
| 744 | if (!err) { | |
| 745 | response .statusCod e = 200; | |
| 746 | } | |
| 747 | ca llback(err , response ); | |
| 748 | }); | |
| 749 | }; | |
| 750 | ||
| 751 | JdsClient. prototype. getOperati onalSyncSt atus = fun ction(site Id, callba ck) { | |
| 752 | this.l og.debug(' JdsClient. getOperati onalSyncSt atus() %j' , siteId); | |
| 753 | var me tricsObj = { | |
| 754 | 's ubsystem': 'JDS', | |
| 755 | 'a ction': 'g etOperatio nalSyncSta tus', | |
| 756 | 's ite': site Id, | |
| 757 | 'p rocess': u uid.v4(), | |
| 758 | 't imer': 'st art' | |
| 759 | }; | |
| 760 | this.m etrics.deb ug('JDS Ge t OPD Sync Status', metricsObj ); | |
| 761 | ||
| 762 | var pa th = '/sta tusod/' + siteId; | |
| 763 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 764 | }; | |
| 765 | ||
| 766 | JdsClient. prototype. getOperati onalSyncSt atusWithPa rams = fun ction(site Id, params , callback ) { | |
| 767 | this.l og.debug(' JdsClient. getOperati onalSyncSt atusWithPa rams() %j, %j', site Id, params ); | |
| 768 | var me tricsObj = { | |
| 769 | 's ubsystem': 'JDS', | |
| 770 | 'a ction': 'g etOperatio nalSyncSta tusWithPar ams', | |
| 771 | 's ite': site Id, | |
| 772 | 'p rocess': u uid.v4(), | |
| 773 | 'p arams': pa rams, | |
| 774 | 't imer': 'st art' | |
| 775 | }; | |
| 776 | this.m etrics.deb ug('JDS Ge t OPD Sync Status Wi th Params' , metricsO bj); | |
| 777 | ||
| 778 | if (_. isEmpty(pa rams)) { | |
| 779 | me tricsObj.t imer = 'st op'; | |
| 780 | th is.metrics .debug('JD S Get Oper ational Sy nc Status With Param s in Error ', metrics Obj); | |
| 781 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No param s passed i n')); | |
| 782 | } | |
| 783 | ||
| 784 | var pa th = '/sta tusod/' + siteId; | |
| 785 | if (_. isObject(p arams)) { | |
| 786 | pa th += '?' + querystr ing.string ify(params ); | |
| 787 | } | |
| 788 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 789 | }; | |
| 790 | ||
| 791 | JdsClient. prototype. deleteOper ationalSyn cStatus = function(s iteId, cal lback) { | |
| 792 | this.l og.debug(' JdsClient. deleteOper ationalSyn cStatus() %j', siteI d); | |
| 793 | var me tricsObj = { | |
| 794 | 's ubsystem': 'JDS', | |
| 795 | 'a ction': 'd eleteOpera tionalSync Status', | |
| 796 | 's ite': site Id, | |
| 797 | 'p rocess': u uid.v4(), | |
| 798 | 't imer': 'st art' | |
| 799 | }; | |
| 800 | this.m etrics.deb ug('JDS De lete OPD S ync Status ', metrics Obj); | |
| 801 | ||
| 802 | var pa th = '/sta tusod/' + siteId; | |
| 803 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 804 | }; | |
| 805 | ||
| 806 | JdsClient. prototype. clearAllOp erationalS yncStatus = function (callback) { | |
| 807 | this.l og.debug(' JdsClient. clearAllOp erationalS yncStatus( )'); | |
| 808 | var me tricsObj = { | |
| 809 | 's ubsystem': 'JDS', | |
| 810 | 'a ction': 'c learAllOpe rationalSy ncStatus', | |
| 811 | 'p rocess': u uid.v4(), | |
| 812 | 't imer': 'st art' | |
| 813 | }; | |
| 814 | this.m etrics.deb ug('JDS Cl ear All OP D Sync Sta tus', metr icsObj); | |
| 815 | ||
| 816 | var pa th = '/sta tusod/'; | |
| 817 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 818 | }; | |
| 819 | ||
| 820 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -- | |
| 821 | // Retriev e patientD emographic s data usi ng the pat ient's pid . Note th is is demo graphics | |
| 822 | // that co mes from p atient dom ain (NOT o perational pt-select data) | |
| 823 | // | |
| 824 | // pid: Th e pid to u se to retr ieve the d ata. | |
| 825 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 826 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --- | |
| 827 | JdsClient. prototype. getPtDemog raphicsByP id = funct ion(pid, c allback) { | |
| 828 | this.l og.debug(' jds-client .getPtDemo graphicsBy Pid() %j', pid); | |
| 829 | var me tricsObj = { | |
| 830 | 's ubsystem': 'JDS', | |
| 831 | 'a ction': 'g etPtDemogr aphicsByPi d', | |
| 832 | 'p id': pid, | |
| 833 | 'p rocess': u uid.v4(), | |
| 834 | 't imer': 'st art' | |
| 835 | }; | |
| 836 | this.m etrics.deb ug('JDS ge t PT Demog raphics by PID', met ricsObj); | |
| 837 | ||
| 838 | if (_. isEmpty(pi d)) { | |
| 839 | me tricsObj.t imer = 'st op'; | |
| 840 | th is.metrics .debug('JD S get PT D emographic s by PID i n Error', metricsObj ); | |
| 841 | th is.log.err or('jds-cl ient.getPt Demographi csByPid: N o pid pass ed in'); | |
| 842 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No pid p assed in') ); | |
| 843 | } | |
| 844 | ||
| 845 | var pa th = '/vpr /' + pid; | |
| 846 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 847 | }; | |
| 848 | ||
| 849 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -- | |
| 850 | // Retriev e patientD emographic s data usi ng the pat ient's icn . Note th is is demo graphics | |
| 851 | // that co mes from p atient dom ain (NOT o perational pt-select data) | |
| 852 | // | |
| 853 | // icn: Th e icn to u se to retr ieve the d ata. | |
| 854 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 855 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --- | |
| 856 | JdsClient. prototype. getPtDemog raphicsByI cn = funct ion(icn, c allback) { | |
| 857 | this.l og.debug(' jds-client .getPtDemo graphicsBy Icn: Enter ed method: icn: %s', icn); | |
| 858 | var me tricsObj = { | |
| 859 | 's ubsystem': 'JDS', | |
| 860 | 'a ction': 'g etPtDemogr aphicsByIc n', | |
| 861 | 'p id': icn, | |
| 862 | 'p rocess': u uid.v4(), | |
| 863 | 't imer': 'st art' | |
| 864 | }; | |
| 865 | this.m etrics.deb ug('JDS ge t PT Demog raphics by ICN', met ricsObj); | |
| 866 | ||
| 867 | if (_. isEmpty(ic n)) { | |
| 868 | me tricsObj.t imer = 'st op'; | |
| 869 | th is.metrics .debug('JD S get PT D emographic s by ICN i n Error', metricsObj ); | |
| 870 | th is.log.err or('jds-cl ient.getPt Demographi csByIcn: N o icn pass ed in'); | |
| 871 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No icn p assed in') ); | |
| 872 | } | |
| 873 | ||
| 874 | var pa th = '/vpr /' + icn; | |
| 875 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 876 | }; | |
| 877 | ||
| 878 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -- | |
| 879 | // This me thod marks an item o n an opera tional dat a sync sta tus as sto red. | |
| 880 | // It is o nly used f or integra tion testi ng. | |
| 881 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -- | |
| 882 | JdsClient. prototype. _markOpera tionalItem AsStored = function( metadata, callback) { | |
| 883 | this.l og.debug(' jds-client ._markOper ationalIte mAsStored( )'); | |
| 884 | var me tricsObj = { | |
| 885 | 's ubsystem': 'JDS', | |
| 886 | 'a ction': 'm arkOperati onalItemAs Stored', | |
| 887 | 'p rocess': u uid.v4(), | |
| 888 | 't imer': 'st art' | |
| 889 | }; | |
| 890 | this.m etrics.deb ug('JDS Ge t Patient Domain Dat a', metric sObj); | |
| 891 | ||
| 892 | var pa th = '/rec ordod'; | |
| 893 | this.e xecute(pat h, metadat a, 'POST', metricsOb j, callbac k); | |
| 894 | }; | |
| 895 | ||
| 896 | JdsClient. prototype. getPatient DomainData = functio n(identifi er, domain , callback ) { | |
| 897 | this.l og.debug(' jds-client .getPatien tDomainDat a() %j %j' , identifi er, domain ); | |
| 898 | var me tricsObj = { | |
| 899 | 's ubsystem': 'JDS', | |
| 900 | 'a ction': 'g etPatientD omainData' , | |
| 901 | 'd omain': do main, | |
| 902 | 'p id': ident ifier, | |
| 903 | 'p rocess': u uid.v4(), | |
| 904 | 't imer': 'st art' | |
| 905 | }; | |
| 906 | this.m etrics.deb ug('JDS Ge t Patient Domain Dat a', metric sObj); | |
| 907 | ||
| 908 | var pa th = '/vpr /' + ident ifier + '/ find/' + d omain; | |
| 909 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 910 | }; | |
| 911 | ||
| 912 | JdsClient. prototype. storePatie ntDataFrom Job = func tion(job, callback) { | |
| 913 | this.l og.debug(' jds-client .storePati entDataFro mJob() %j' , job); | |
| 914 | ||
| 915 | if (_. isEmpty(jo b.record)) { | |
| 916 | th is.log.deb ug('jds-cl ient.store PatientDat aFromJob: Failed to store pati ent data. job.recor d was empt y.'); | |
| 917 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No recor d passed i n job')); | |
| 918 | } | |
| 919 | ||
| 920 | // var path = '/ vpr/' + jo b.patientI dentifier. value; | |
| 921 | // thi s.execute( path, job. record, 'P OST', call back); | |
| 922 | ||
| 923 | return this.stor ePatientDa ta(job.rec ord, callb ack); | |
| 924 | ||
| 925 | }; | |
| 926 | ||
| 927 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
| 928 | // Store t he patient data even t to JDS. | |
| 929 | // | |
| 930 | // patient DataEvent: The patie nt data ev ent to be stored. | |
| 931 | // callbac k: The han dler to ca ll when th e data is stored. Signature is: | |
| 932 | // functio n(error, r esponse) w here: | |
| 933 | // err or: Is the error tha t occurs. | |
| 934 | // res ponse: Is the respon se from JD S. | |
| 935 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----- | |
| 936 | JdsClient. prototype. storePatie ntData = f unction(pa tientDataE vent, call back) { | |
| 937 | this.l og.debug(' jds-client .storePati entData() %j', patie ntDataEven t); | |
| 938 | var me tricsObj = { | |
| 939 | 's ubsystem': 'JDS', | |
| 940 | 'a ction': 's torePatien tData', | |
| 941 | 'p id': patie ntDataEven t.pid, | |
| 942 | 'u id': patie ntDataEven t.uid, | |
| 943 | 'p rocess': u uid.v4(), | |
| 944 | 't imer': 'st art' | |
| 945 | }; | |
| 946 | this.m etrics.deb ug('JDS St ore Patien t Data', m etricsObj) ; | |
| 947 | ||
| 948 | if (_. isEmpty(pa tientDataE vent)) { | |
| 949 | me tricsObj.t imer = 'st op'; | |
| 950 | th is.metrics .debug('JD S Store Pa tient Data in Error' , metricsO bj); | |
| 951 | th is.log.deb ug('jds-cl ient.store PatientDat a: Failed to store p atient dat a. patien tDataEvent was empty .'); | |
| 952 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No patie nt data ev ent passed in')); | |
| 953 | } | |
| 954 | ||
| 955 | var pa th = '/vpr '; | |
| 956 | this.e xecute(pat h, patient DataEvent, 'POST', m etricsObj, callback) ; | |
| 957 | }; | |
| 958 | ||
| 959 | JdsClient. prototype. getPatient DataByUid = function (uid, call back) { | |
| 960 | this.l og.debug(' jds-client .getPatien tDataByUid () %j', ui d); | |
| 961 | var me tricsObj = { | |
| 962 | 's ubsystem': 'JDS', | |
| 963 | 'a ction': 'g etPatientD ataByUid', | |
| 964 | 'u id': uid, | |
| 965 | 'p rocess': u uid.v4(), | |
| 966 | 't imer': 'st art' | |
| 967 | }; | |
| 968 | this.m etrics.deb ug('JDS Ge t Patient Data By UI D', metric sObj); | |
| 969 | ||
| 970 | if (_. isEmpty(ui d)) { | |
| 971 | me tricsObj.t imer = 'st op'; | |
| 972 | th is.metrics .debug('JD S Get Pati ent Data B y UID in E rror', met ricsObj); | |
| 973 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No uid p assed in') ); | |
| 974 | } | |
| 975 | ||
| 976 | var pa th = '/vpr /uid/' + u id; | |
| 977 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 978 | }; | |
| 979 | ||
| 980 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 981 | // Delete the patien t data obj ect by its UID. | |
| 982 | // | |
| 983 | // uid: Th e UID that identifie s the pati ent data i tem being deleted. | |
| 984 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 985 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 986 | JdsClient. prototype. deletePati entDataByU id = funct ion(uid, c allback) { | |
| 987 | this.l og.debug(' jds-client .deletePat ientDataBy Uid() %j', uid); | |
| 988 | var me tricsObj = { | |
| 989 | 's ubsystem': 'JDS', | |
| 990 | 'a ction': 'd eletePatie ntDataByUi d', | |
| 991 | 'u id': uid, | |
| 992 | 'p rocess': u uid.v4(), | |
| 993 | 't imer': 'st art' | |
| 994 | }; | |
| 995 | this.m etrics.deb ug('JDS De lete Patie nt Data By UID', met ricsObj); | |
| 996 | ||
| 997 | if (_. isEmpty(ui d)) { | |
| 998 | me tricsObj.t imer = 'st op'; | |
| 999 | th is.metrics .debug('JD S Delete P atient Dat a By UID i n Error', metricsObj ); | |
| 1000 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No uid p assed in') ); | |
| 1001 | } | |
| 1002 | ||
| 1003 | var pa th = '/vpr /uid/' + u id; | |
| 1004 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 1005 | }; | |
| 1006 | ||
| 1007 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 1008 | // Delete all patien t data for all ident ifiers tie d to this pid. | |
| 1009 | // | |
| 1010 | // pid: Th e pid that identifie s the pati ent. | |
| 1011 | // callbac k: The han dler to ca ll when th is request is comple ted. | |
| 1012 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - | |
| 1013 | JdsClient. prototype. deletePati entByPid = function( pid, callb ack) { | |
| 1014 | this.l og.debug(' jds-client .deletePat ientByPid( ) %j', pid ); | |
| 1015 | var me tricsObj = { | |
| 1016 | 's ubsystem': 'JDS', | |
| 1017 | 'a ction': 'd eletePatie ntByPid', | |
| 1018 | 'p id': pid, | |
| 1019 | 'p rocess': u uid.v4(), | |
| 1020 | 't imer': 'st art' | |
| 1021 | }; | |
| 1022 | this.m etrics.deb ug('JDS De lete Patie nt Data By PID', met ricsObj); | |
| 1023 | ||
| 1024 | if (_. isEmpty(pi d)) { | |
| 1025 | me tricsObj.t imer = 'st op'; | |
| 1026 | th is.metrics .debug('JD S Delete P atient Dat a By PID i n Error', metricsObj ); | |
| 1027 | th is.log.err or('jds-cl ient.delet ePatientBy Pid() No p id passed in'); | |
| 1028 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No pid p assed in') ); | |
| 1029 | } | |
| 1030 | ||
| 1031 | var pa th = '/vpr /' + pid; | |
| 1032 | this.e xecute(pat h, null, ' DELETE', m etricsObj, callback) ; | |
| 1033 | }; | |
| 1034 | ||
| 1035 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
| 1036 | // Store t he notific ation that an event was sent t o SOLR. | |
| 1037 | // | |
| 1038 | // pid: Th e pid for this patie nt. | |
| 1039 | // storeEv entInfo: T he require d event id entificati on to corr ectly noti fy JDS | |
| 1040 | // o f the even t status. The event should lo ok as foll ows: | |
| 1041 | // { | |
| 1042 | // "uid": "u rn:va:vita l:9E7A:3:2 3", | |
| 1043 | // "eventSta mp": 20040 330215452, | |
| 1044 | // "type": " solr" | |
| 1045 | // } | |
| 1046 | // callbac k: The han dler to ca ll when th e data is stored. Signature is: | |
| 1047 | // functio n(error, r esponse) w here: | |
| 1048 | // err or: Is the error tha t occurs. | |
| 1049 | // res ponse: Is the respon se from JD S. | |
| 1050 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----- | |
| 1051 | JdsClient. prototype. setEventSt oreStatus = function (pid, stor eEventInfo , callback ) { | |
| 1052 | this.l og.debug(' jds-client .setEventS toreStatus () pid: %s , storeEve ntInfo: %j ', pid, st oreEventIn fo); | |
| 1053 | var me tricsObj = { | |
| 1054 | 's ubsystem': 'JDS', | |
| 1055 | 'a ction': 's etEventSto reStatus', | |
| 1056 | 'p id': pid, | |
| 1057 | 'u id': (_.is Empty(stor eEventInfo )) ? null : storeEve ntInfo.uid , | |
| 1058 | 'p rocess': u uid.v4(), | |
| 1059 | 't imer': 'st art' | |
| 1060 | }; | |
| 1061 | this.m etrics.deb ug('JDS Ev ent Store Status', m etricsObj) ; | |
| 1062 | ||
| 1063 | if (_. isEmpty(st oreEventIn fo)) { | |
| 1064 | me tricsObj.t imer = 'st op'; | |
| 1065 | th is.metrics .debug('JD S Event St ore Status in Error' , metricsO bj); | |
| 1066 | th is.log.deb ug('jds-cl ient.setEv entStoreSt atus: Fail ed to stor e event st atus. sto reEventInf o was empt y.'); | |
| 1067 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No store event inf o passed i n')); | |
| 1068 | } | |
| 1069 | ||
| 1070 | var pa th = '/sta tus/' + pi d + '/stor e'; | |
| 1071 | this.e xecute(pat h, storeEv entInfo, ' POST', met ricsObj, c allback); | |
| 1072 | }; | |
| 1073 | ||
| 1074 | ||
| 1075 | ||
| 1076 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- | |
| 1077 | // This fu nction exe cutes the JDS comman d. | |
| 1078 | // | |
| 1079 | // path: T he JDS RES T URL (Wi thout that http://<i p>:port) | |
| 1080 | // dataToP ost: If t his is a p ut or post , then thi s is the d ata that i s going to be put or posted. | |
| 1081 | // method: The type of http me thod (i.e. GET, PUT, POST, etc ) | |
| 1082 | // callbac k: The cal l back fun ction that should be called wh en the exe cute is co mpleted. | |
| 1083 | //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- | |
| 1084 | JdsClient. prototype. execute = function(p ath, dataT oPost, met hod, metri csObj, cal lback) { | |
| 1085 | this.l og.debug(p ath); | |
| 1086 | this.l og.debug(i nspect(dat aToPost)); | |
| 1087 | metric sObj.timer = 'stop'; | |
| 1088 | if (_. isEmpty(th is.config. jds)) { | |
| 1089 | th is.metrics .debug('JD S Execute in Error', metricsOb j); | |
| 1090 | re turn setTi meout(call back, 0, e rrorUtil.c reateFatal ('No value passed fo r jds conf iguration' )); | |
| 1091 | } | |
| 1092 | ||
| 1093 | var ur l = format ('%s://%s: %s%s', thi s.config.j ds.protoco l, this.co nfig.jds.h ost, this. config.jds .port, pat h); | |
| 1094 | ||
| 1095 | if (me thod === ' POST' || m ethod === 'PUT') { | |
| 1096 | if (_.isEmpt y(dataToPo st)) { | |
| 1097 | this.log .debug('jd s-client.e xecute(): Sending a POST or PU T without dataToPost . url: %s' , url); | |
| 1098 | dataToPo st = undef ined; | |
| 1099 | } else { | |
| 1100 | var data ToPostWith outPwd = o bjUtil.rem ovePropert y(objUtil. removeProp erty(dataT oPost,'acc essCode'), 'verifyCod e'); | |
| 1101 | this.log .debug('jd s-client.e xecute(): Sending me ssage to J DS. %s -> dataToPost : %j', url , dataToPo stWithoutP wd); | |
| 1102 | } | |
| 1103 | } else { | |
| 1104 | th is.log.deb ug('jds-cl ient.execu te(): Send ing messag e to JDS. url: %s', url); | |
| 1105 | da taToPost = undefined ; | |
| 1106 | } | |
| 1107 | ||
| 1108 | var se lf = this; | |
| 1109 | reques t({ | |
| 1110 | ur l: url, | |
| 1111 | me thod: meth od || 'GET ', | |
| 1112 | js on: dataTo Post, | |
| 1113 | ti meout: thi s.config.j ds.timeout || 60000, | |
| 1114 | fo rever: tru e, | |
| 1115 | ag entOptions : {maxSock ets: self. config.han dlerMaxSoc kets || 5} | |
| 1116 | }, fun ction(erro r, respons e, body) { | |
| 1117 | se lf.log.deb ug('jds-cl ient.execu te(): post ed data to JDS %s', url); | |
| 1118 | ||
| 1119 | if (error || response. statusCode === 500) { | |
| 1120 | self.log .error('jd s-client.e xecute(): Unable to access JDS endpoint: %s %s', m ethod, url ); | |
| 1121 | self.log .error('%j %j', erro r, body); | |
| 1122 | ||
| 1123 | self.met rics.debug ('JDS Exec ute in Err or', metri csObj); | |
| 1124 | return c allback(er rorUtil.cr eateTransi ent((error || body | | 'Unknown Error')), response) ; | |
| 1125 | } | |
| 1126 | ||
| 1127 | va r json; | |
| 1128 | if (_.isEmpt y(body)) { | |
| 1129 | self.log .debug('jd s-client.e xecute(): Response b ody is emp ty. Statu s code:', response.s tatusCode) ; | |
| 1130 | self.met rics.debug ('JDS Exec ute comple te', metri csObj); | |
| 1131 | return c allback(nu ll, respon se); | |
| 1132 | } | |
| 1133 | ||
| 1134 | tr y { | |
| 1135 | json = _ .isObject( body) ? bo dy : JSON. parse(body ); | |
| 1136 | } catch (par seError) { | |
| 1137 | self.log .error('jd s-client.e xecute(): Unable to parse JSON response: ', body); | |
| 1138 | self.log .error('jd s-client.e xecute(): Unable to parse JSON response, and respo nse is def ined. thi s is actua lly bad'); | |
| 1139 | self.log .error(ins pect(parse Error)); | |
| 1140 | self.log .error(':: ' + body + '::'); | |
| 1141 | json = b ody; | |
| 1142 | } | |
| 1143 | ||
| 1144 | va r response WithoutPwd = objUtil .removePro perty(objU til.remove Property(j son, 'acce ssCode'), 'verifyCod e'); | |
| 1145 | se lf.log.deb ug('jds-cl ient.execu te(): JDS response i s for the caller to handle %j' , response WithoutPwd ); | |
| 1146 | se lf.metrics .debug('JD S Execute complete', metricsOb j); | |
| 1147 | ca llback(nul l, respons e, json); | |
| 1148 | }); | |
| 1149 | }; | |
| 1150 | ||
| 1151 | JdsClient. prototype. _validateM etastampSi ze = funct ion(metast amp, maxSi ze) { | |
| 1152 | var si ze = sizeo f(metastam p); | |
| 1153 | if (si ze > maxSi ze) { | |
| 1154 | re turn false ; | |
| 1155 | } else { | |
| 1156 | re turn true; | |
| 1157 | } | |
| 1158 | }; | |
| 1159 | ||
| 1160 | /** | |
| 1161 | Takes a me tastamp an d splits i t by data source. Th is is a fi rst attemp t | |
| 1162 | to break d own a meta stamp into a size th at can be processed by JDS. | |
| 1163 | **/ | |
| 1164 | JdsClient. prototype. _splitMeta stampBySou rce = func tion(metas tamp) { | |
| 1165 | var me tastampShe ll; | |
| 1166 | var so urces = me tastamp.so urceMetaSt amp; | |
| 1167 | var me tastampByS ource = [] ; | |
| 1168 | if (_. keys(sourc es).length <= 1) { / /This meta stamp only has one s ource alre ady | |
| 1169 | re turn [meta stamp]; | |
| 1170 | } | |
| 1171 | metast amp.source MetaStamp = {}; | |
| 1172 | metast ampShell = JSON.pars e(JSON.str ingify(met astamp)); | |
| 1173 | _.each (sources, function(v alue, key) { | |
| 1174 | va r siteStam p = JSON.p arse(JSON. stringify( metastampS hell)); | |
| 1175 | si teStamp.so urceMetaSt amp[key] = value; | |
| 1176 | me tastampByS ource.push (siteStamp ); | |
| 1177 | }); | |
| 1178 | return metastamp BySource; | |
| 1179 | }; | |
| 1180 | ||
| 1181 | /** | |
| 1182 | Breaks up a metastam p by domai n in hopes that sing le domains will be s mall enoug h | |
| 1183 | to store i n JDS. It assumes th at only on e source e xists in t his metast amp. | |
| 1184 | **/ | |
| 1185 | JdsClient. prototype. _splitMeta stampByDom ain = func tion(metas tamp) { | |
| 1186 | var me tastampShe ll; | |
| 1187 | var so urce = _.k eys(metast amp.source MetaStamp) [0]; | |
| 1188 | var do mains = me tastamp.so urceMetaSt amp[source ].domainMe taStamp; | |
| 1189 | var me tastampByD omain = [] ; | |
| 1190 | if (_. keys(domai ns).length <= 1) { / /this meta stamp only has one d omain alre ady | |
| 1191 | re turn [meta stamp]; | |
| 1192 | } | |
| 1193 | metast amp.source MetaStamp[ source].do mainMetaSt amp = {}; | |
| 1194 | metast ampShell = JSON.pars e(JSON.str ingify(met astamp)); | |
| 1195 | _.each (domains, function(v alue, key) { | |
| 1196 | va r domainSt amp = JSON .parse(JSO N.stringif y(metastam pShell)); | |
| 1197 | do mainStamp. sourceMeta Stamp[sour ce].domain MetaStamp[ key] = val ue; | |
| 1198 | me tastampByD omain.push (domainSta mp); | |
| 1199 | }); | |
| 1200 | return metastamp ByDomain; | |
| 1201 | }; | |
| 1202 | ||
| 1203 | /** | |
| 1204 | Breaks up a metastam p domain i nto approp riate size d metastam ps that ca n be store d in JDS. | |
| 1205 | This assum es that th e metastam p has alre ady been b roken up b y site and domain su ch that | |
| 1206 | this metas tamp only has one so urce with one domain . | |
| 1207 | **/ | |
| 1208 | JdsClient. prototype. _splitMeta stampDomai n = functi on(metasta mp, maxSiz e) { | |
| 1209 | var me tastampSiz e = sizeof (metastamp ); | |
| 1210 | var so urce = _.k eys(metast amp.source MetaStamp) [0]; | |
| 1211 | var do main = _.k eys(metast amp.source MetaStamp[ source].do mainMetaSt amp)[0]; | |
| 1212 | var ev entListNam e; | |
| 1213 | if (me tastamp.so urceMetaSt amp[source ].domainMe taStamp[do main].even tMetaStamp ) { | |
| 1214 | ev entListNam e = 'event MetaStamp' ; | |
| 1215 | } else { | |
| 1216 | ev entListNam e = 'itemM etaStamp'; | |
| 1217 | } | |
| 1218 | var ui ds = metas tamp.sourc eMetaStamp [source].d omainMetaS tamp[domai n][eventLi stName]; | |
| 1219 | metast amp.source MetaStamp[ source].do mainMetaSt amp[domain ][eventLis tName] = { }; | |
| 1220 | var me tastampShe ll = JSON. parse(JSON .stringify (metastamp )); | |
| 1221 | var nu mberOfEven ts = _.siz e(uids); | |
| 1222 | var di visor = ma xSize * nu mberOfEven ts; | |
| 1223 | var qu otient = d ivisor / m etastampSi ze; | |
| 1224 | var ev entsPerSta mp = Math. floor(quot ient); | |
| 1225 | if (ev entsPerSta mp < 1) { | |
| 1226 | ev entsPerSta mp = 1; | |
| 1227 | } | |
| 1228 | var me tastampByE vent = []; | |
| 1229 | var in dex = 0; | |
| 1230 | _.each (uids, fun ction(valu e, key) { | |
| 1231 | va r metastam pIndex = M ath.floor( index / ev entsPerSta mp); | |
| 1232 | if (!metasta mpByEvent[ metastampI ndex]) { | |
| 1233 | metastam pByEvent[m etastampIn dex] = JSO N.parse(JS ON.stringi fy(metasta mpShell)); | |
| 1234 | } | |
| 1235 | me tastampByE vent[metas tampIndex] .sourceMet aStamp[sou rce].domai nMetaStamp [domain][e ventListNa me][key] = value; | |
| 1236 | in dex++; | |
| 1237 | }); | |
| 1238 | return metastamp ByEvent; | |
| 1239 | }; | |
| 1240 | ||
| 1241 | /** | |
| 1242 | Ensures th at a metas tamp isn't so large that JDS c annot stor e it in me mory. | |
| 1243 | **/ | |
| 1244 | JdsClient. prototype. _ensureMet astampSize = functio n(metastam p, size) { | |
| 1245 | var se lf = this; | |
| 1246 | if (se lf._valida teMetastam pSize(meta stamp, siz e)) { | |
| 1247 | re turn [meta stamp]; | |
| 1248 | } | |
| 1249 | var me tastampJob s = []; | |
| 1250 | var so urceJobs = self._spl itMetastam pBySource( metastamp) ; | |
| 1251 | _.each (sourceJob s, functio n(sourceMe tastamp) { | |
| 1252 | if (self._va lidateMeta stampSize( sourceMeta stamp, siz e)) { | |
| 1253 | metastam pJobs.push (sourceMet astamp); | |
| 1254 | } else { | |
| 1255 | var doma inJobs = s elf._split MetastampB yDomain(so urceMetast amp); | |
| 1256 | _.each(d omainJobs, function( domainMeta stamp) { | |
| 1257 | if ( self._vali dateMetast ampSize(do mainMetast amp, size) ) { | |
| 1258 | metastampJ obs.push(d omainMetas tamp); | |
| 1259 | } el se { | |
| 1260 | var eventJ obs = self ._splitMet astampDoma in(domainM etastamp, size); | |
| 1261 | metastampJ obs = meta stampJobs. concat(eve ntJobs); | |
| 1262 | } | |
| 1263 | }); | |
| 1264 | } | |
| 1265 | }); | |
| 1266 | return metastamp Jobs; | |
| 1267 | }; | |
| 1268 | ||
| 1269 | ||
| 1270 | JdsClient. prototype. addErrorRe cord = fun ction(erro rRecord, c allback) { | |
| 1271 | this.l og.debug(' jds-client .addErrorR ecord() %j ', errorRe cord); | |
| 1272 | var me tricsObj = { | |
| 1273 | su bsystem: ' JDS', | |
| 1274 | ac tion: 'add ErrorRecor d', | |
| 1275 | pr ocess: uui d.v4(), | |
| 1276 | ti mer: 'star t' | |
| 1277 | }; | |
| 1278 | this.m etrics.deb ug('JDS ad dErrorReco rd %j', me tricsObj); | |
| 1279 | this.e xecute('/v xsyncerr/' , errorRec ord, 'PUT' , metricsO bj, callba ck); | |
| 1280 | }; | |
| 1281 | ||
| 1282 | JdsClient. prototype. findErrorR ecordByUid = functio n(uid, cal lback) { | |
| 1283 | this.l og.debug(' jds-client .findError RecordByUi d(%s)', ui d); | |
| 1284 | var me tricsObj = { | |
| 1285 | su bsystem: ' JDS', | |
| 1286 | ac tion: 'fin dErrorReco rdByUid', | |
| 1287 | ui d: uid, | |
| 1288 | pr ocess: uui d.v4(), | |
| 1289 | ti mer: 'star t' | |
| 1290 | }; | |
| 1291 | this.m etrics.deb ug('JDS fi ndErrorRec ordByUid % j', metric sObj); | |
| 1292 | this.e xecute('/v xsyncerr/' + uid, nu ll, 'GET', metricsOb j, callbac k); | |
| 1293 | }; | |
| 1294 | ||
| 1295 | JdsClient. prototype. findErrorR ecordsByFi lter = fun ction(filt er, callba ck) { | |
| 1296 | this.l og.debug(' jds-client .findError RecordsByF ilter() %s ', filter) ; | |
| 1297 | this.f indErrorRe cords({fil ter: filte r}, callba ck); | |
| 1298 | }; | |
| 1299 | ||
| 1300 | JdsClient. prototype. findErrorR ecords = f unction(qu ery, callb ack) { | |
| 1301 | this.l og.debug(' jds-client .findError Records() query: %s' , query); | |
| 1302 | var me tricsObj = { | |
| 1303 | su bsystem: ' JDS', | |
| 1304 | ac tion: 'fin dErrorReco rds', | |
| 1305 | qu ery: query , | |
| 1306 | pr ocess: uui d.v4(), | |
| 1307 | ti mer: 'star t' | |
| 1308 | }; | |
| 1309 | this.m etrics.deb ug('JDS fi ndErrorRec ords %j', metricsObj ); | |
| 1310 | ||
| 1311 | var pa th = '/vxs yncerr/'; | |
| 1312 | ||
| 1313 | if(_.h as(query,' index')){ | |
| 1314 | pa th += (que ry.index)? 'index/'+q uery.index :''; | |
| 1315 | qu ery = _.om it(query, 'index'); | |
| 1316 | } | |
| 1317 | ||
| 1318 | var qu eryString = querystr ing.string ify(query) ; | |
| 1319 | if(que ryString){ | |
| 1320 | pa th += '?' + queryStr ing; | |
| 1321 | } | |
| 1322 | ||
| 1323 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 1324 | }; | |
| 1325 | ||
| 1326 | JdsClient. prototype. findErrorR ecordsByRa nge = func tion(index , range, c allback){ | |
| 1327 | this.l og.debug(' jds-client .findError RecordsByR ange() ind ex: %s, ra nge: %s', index, ran ge); | |
| 1328 | this.f indErrorRe cords({ind ex: index, range: ra nge}, call back); | |
| 1329 | }; | |
| 1330 | ||
| 1331 | JdsClient. prototype. getErrorRe cordCount = function (callback) { | |
| 1332 | this.l og.debug(' jds-client .getErrorR ecordCount ()'); | |
| 1333 | var me tricsObj = { | |
| 1334 | su bsystem: ' JDS', | |
| 1335 | ac tion: 'get ErrorRecor dCount', | |
| 1336 | pr ocess: uui d.v4(), | |
| 1337 | ti mer: 'star t' | |
| 1338 | }; | |
| 1339 | this.m etrics.deb ug('JDS ge tErrorReco rdCount %j ', metrics Obj); | |
| 1340 | this.e xecute('/v xsyncerr', null, 'GE T', metric sObj, func tion(error , response , result) { | |
| 1341 | va r doc_coun t = (resul t && resul t.doc_coun t)?(result .doc_count ):null; | |
| 1342 | re turn callb ack(null, response, doc_count) ; | |
| 1343 | }); | |
| 1344 | }; | |
| 1345 | ||
| 1346 | JdsClient. prototype. deleteErro rRecordByU id = funct ion(uid, c allback) { | |
| 1347 | this.l og.debug(' jds-client .deleteErr orRecordBy Uid(%s)', uid); | |
| 1348 | var me tricsObj = { | |
| 1349 | su bsystem: ' JDS', | |
| 1350 | ac tion: 'del eteErrorRe cordByUid' , | |
| 1351 | ui d: uid, | |
| 1352 | pr ocess: uui d.v4(), | |
| 1353 | ti mer: 'star t' | |
| 1354 | }; | |
| 1355 | this.m etrics.deb ug('JDS de leteErrorR ecordByUid %j', metr icsObj); | |
| 1356 | this.e xecute('/v xsyncerr/' + uid, nu ll, 'DELET E', metric sObj, call back); | |
| 1357 | }; | |
| 1358 | ||
| 1359 | JdsClient. prototype. deleteAllE rrorRecord s = functi on(callbac k) { | |
| 1360 | this.l og.debug(' jds-client .deleteAll ErrorRecor ds()'); | |
| 1361 | var me tricsObj = { | |
| 1362 | su bsystem: ' JDS', | |
| 1363 | ac tion: 'del eteAllErro rRecords', | |
| 1364 | pr ocess: uui d.v4(), | |
| 1365 | ti mer: 'star t' | |
| 1366 | }; | |
| 1367 | this.m etrics.deb ug('JDS de leteAllErr orRecords %j', metri csObj); | |
| 1368 | this.e xecute('/v xsyncerr/? confirm=tr ue', null, 'DELETE', metricsOb j, callbac k); | |
| 1369 | }; | |
| 1370 | ||
| 1371 | JdsClient. prototype. deleteErro rRecordsBy Filter = f unction(fi lter, call back){ | |
| 1372 | this.l og.debug(' jds-client .deleteErr orRecordsB yFilter() %s', filte r); | |
| 1373 | var me tricsObj = { | |
| 1374 | su bsystem: ' JDS', | |
| 1375 | ac tion: 'del eteErrorRe cordsByFil ter', | |
| 1376 | fi lter: filt er, | |
| 1377 | pr ocess: uui d.v4(), | |
| 1378 | ti mer: 'star t' | |
| 1379 | }; | |
| 1380 | this.m etrics.deb ug('JDS de leteErrorR ecordsByFi lter %j', metricsObj ); | |
| 1381 | this.e xecute('/v xsyncerr/? filter=' + filter, n ull, 'DELE TE', metri csObj, cal lback); | |
| 1382 | }; | |
| 1383 | ||
| 1384 | JdsClient. prototype. getLockOnE rrorRecord = functio n(uid, cal lback) { | |
| 1385 | this.l og.debug(' jds-client .getLockOn ErrorRecor d(%s)', ui d); | |
| 1386 | var me tricsObj = { | |
| 1387 | su bsystem: ' JDS', | |
| 1388 | ac tion: 'get LockOnErro rRecord', | |
| 1389 | ui d: uid, | |
| 1390 | pr ocess: uui d.v4(), | |
| 1391 | ti mer: 'star t' | |
| 1392 | }; | |
| 1393 | this.m etrics.deb ug('JDS ge tLockOnErr orRecord % j', metric sObj); | |
| 1394 | this.e xecute('/v xsyncerr/l ock/' + ui d, null, ' GET', metr icsObj, ca llback); | |
| 1395 | }; | |
| 1396 | ||
| 1397 | JdsClient. prototype. lockErrorR ecord = fu nction(uid , callback ) { | |
| 1398 | this.l og.debug(' jds-client .lockError Record(%s) ', uid); | |
| 1399 | var me tricsObj = { | |
| 1400 | su bsystem: ' JDS', | |
| 1401 | ac tion: 'loc kErrorReco rd', | |
| 1402 | ui d: uid, | |
| 1403 | pr ocess: uui d.v4(), | |
| 1404 | ti mer: 'star t' | |
| 1405 | }; | |
| 1406 | this.m etrics.deb ug('JDS lo ckErrorRec ord %j', m etricsObj) ; | |
| 1407 | this.e xecute('/v xsyncerr/l ock/' + ui d, null, ' PUT', metr icsObj, ca llback); | |
| 1408 | }; | |
| 1409 | ||
| 1410 | JdsClient. prototype. unlockErro rRecord = function(u id, callba ck){ | |
| 1411 | this.l og.debug(' jds-client .unlockErr orRecord() %s', uid) ; | |
| 1412 | var me tricsObj = { | |
| 1413 | su bsystem: ' JDS', | |
| 1414 | ac tion: 'unl ockErrorRe cord', | |
| 1415 | ui d: uid, | |
| 1416 | pr ocess: uui d.v4(), | |
| 1417 | ti mer: 'star t' | |
| 1418 | }; | |
| 1419 | this.m etrics.deb ug('JDS un lockErrorR ecord %j', metricsOb j); | |
| 1420 | this.e xecute('/v xsyncerr/l ock/' + ui d, null, ' DELETE', m etricsObj, callback) ; | |
| 1421 | }; | |
| 1422 | ||
| 1423 | JdsClient. prototype. getPatient List = fun ction(last AccessTime , callback ) { | |
| 1424 | this.l og.debug(' jds-client .getPatien tList() %j ', lastAcc essTime); | |
| 1425 | var me tricsObj = { | |
| 1426 | 's ubsystem': 'JDS', | |
| 1427 | 'a ction': 'g etPatientL ist', | |
| 1428 | 'l astAccessT ime': last AccessTime , | |
| 1429 | 'p rocess': u uid.v4(), | |
| 1430 | 't imer': 'st art' | |
| 1431 | }; | |
| 1432 | this.m etrics.deb ug('JDS Ge t Patient Data By la stAccessTi me', metri csObj); | |
| 1433 | ||
| 1434 | var pa th = '/vpr /all/patie ntlist'; | |
| 1435 | ||
| 1436 | if (!_ .isEmpty(l astAccessT ime)) { | |
| 1437 | pa th = '/vpr /all/patie ntlist?fil ter=lt(las tAccessTim e,' + last AccessTime + ')'; | |
| 1438 | } | |
| 1439 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 1440 | }; | |
| 1441 | ||
| 1442 | JdsClient. prototype. getPatient ListBySite = functio n(site, ca llback) { | |
| 1443 | this.l og.debug(' jds-client .getPatien tListBySit e() %j', s ite); | |
| 1444 | var me tricsObj = { | |
| 1445 | 's ubsystem': 'JDS', | |
| 1446 | 'a ction': 'g etPatientL ist', | |
| 1447 | 's ite': site , | |
| 1448 | 'p rocess': u uid.v4(), | |
| 1449 | 't imer': 'st art' | |
| 1450 | }; | |
| 1451 | this.m etrics.deb ug('JDS Ge t Patient List By Si te', metri csObj); | |
| 1452 | ||
| 1453 | var pa th = '/vpr /all/pid/p id'; | |
| 1454 | ||
| 1455 | if (!_ .isEmpty(s ite)) { | |
| 1456 | pa th = '/vpr /all/index /pid/pid?f ilter=eq(s ite,' + si te + ')'; | |
| 1457 | } | |
| 1458 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 1459 | }; | |
| 1460 | ||
| 1461 | JdsClient. prototype. getJpidFro mQuery = f unction(pa tientIdent ifiers, ca llback) { | |
| 1462 | this.l og.debug(' jds-client .getJpidFr omQuery() %j', patie ntIdentifi ers); | |
| 1463 | var me tricsObj = { | |
| 1464 | 's ubsystem': 'JDS', | |
| 1465 | 'a ction': 'g etJpidFrom Query', | |
| 1466 | 'p atientIden tifiers': patientIde ntifiers, | |
| 1467 | 'p rocess': u uid.v4(), | |
| 1468 | 't imer': 'st art' | |
| 1469 | }; | |
| 1470 | this.m etrics.deb ug('JDS Ge t Jpid via query', m etricsObj) ; | |
| 1471 | ||
| 1472 | var po stBody = { | |
| 1473 | 'p atientIden tifiers': patientIde ntifiers | |
| 1474 | }; | |
| 1475 | ||
| 1476 | var pa th = '/vpr /jpid/quer y/'; | |
| 1477 | this.e xecute(pat h, postBod y, 'POST', metricsOb j, callbac k); | |
| 1478 | }; | |
| 1479 | ||
| 1480 | JdsClient. prototype. saveActive Users = fu nction(act iveUsers, callback) { | |
| 1481 | this.l og.debug(' jds-client .saveActiv eUsers()') ; | |
| 1482 | var me tricsObj = { | |
| 1483 | 's ubsystem': 'JDS', | |
| 1484 | 'a ction': 's aveActiveU sers', | |
| 1485 | 'p rocess': u uid.v4(), | |
| 1486 | 't imer': 'st art' | |
| 1487 | }; | |
| 1488 | this.m etrics.deb ug('JDS Sa ve Active Users', me tricsObj); | |
| 1489 | ||
| 1490 | var po stBody = { _id: 'osyn cusers', u sers : act iveUsers}; | |
| 1491 | ||
| 1492 | var pa th = '/use r/set/this '; | |
| 1493 | this.e xecute(pat h, postBod y, 'POST', metricsOb j, callbac k); | |
| 1494 | }; | |
| 1495 | ||
| 1496 | JdsClient. prototype. getActiveU sers = fun ction(call back) { | |
| 1497 | this.l og.debug(' jds-client .getActive Users()'); | |
| 1498 | var me tricsObj = { | |
| 1499 | 's ubsystem': 'JDS', | |
| 1500 | 'a ction': 'g etActiveUs ers', | |
| 1501 | 'p rocess': u uid.v4(), | |
| 1502 | 't imer': 'st art' | |
| 1503 | }; | |
| 1504 | this.m etrics.deb ug('JDS Ge t Active U sers', met ricsObj); | |
| 1505 | ||
| 1506 | var pa th = '/use r/get/osyn cusers'; | |
| 1507 | this.e xecute(pat h, null, ' GET', metr icsObj, ca llback); | |
| 1508 | }; | |
| 1509 | ||
| 1510 | module.exp orts = Jds Client; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.