Produced by Araxis Merge on 10/3/2017 11:16:05 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\tools\chemlab-resync | chemlab-patient-util.js | Mon Jul 10 17:46:22 2017 UTC |
| 2 | ehmp.zip\ehmp\ehmp\product\production\vx-sync\tools\chemlab-resync | chemlab-patient-util.js | Tue Oct 3 13:35:45 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 556 |
| Changed | 2 | 8 |
| 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 fs = r equire('fs '); | |
| 4 | var util = require(' util'); | |
| 5 | var async = require( 'async'); | |
| 6 | var _ = re quire('und erscore'); | |
| 7 | var reques t = requir e('request '); | |
| 8 | ||
| 9 | ||
| 10 | /* | |
| 11 | Load and p arse patie ntFile or return an empty obje ct if 'out putFile' d oes not ex ist. | |
| 12 | ||
| 13 | logger: A bunyan-sty le logger | |
| 14 | ||
| 15 | outputFile : The name and path of the out putFile | |
| 16 | ||
| 17 | callback: A standard callback | |
| 18 | ||
| 19 | fileSystem : an optio nal overri de of the 'fs' file system. Fo r this fun ction, | |
| 20 | th e object m ust implem ent exists Sync(file) and readF ile(file, options, c allback) f unctions. | |
| 21 | */ | |
| 22 | function l oadPatient File(logge r, patient File, call back, file System) { | |
| 23 | fi leSystem = fileSyste m || fs; | |
| 24 | lo gger.debug ('fetch-sy nced-patie nt-list.lo adPatientF ile(): pat ientFile: %s', patie ntFile); | |
| 25 | ||
| 26 | if (!fileSys tem.exists Sync(patie ntFile)) { | |
| 27 | logg er.debug(' fetch-sync ed-patient -list.load PatientFil e(): retur n empty ob ject {}'); | |
| 28 | retu rn setTime out(callba ck, 0, nul l, {}); | |
| 29 | } | |
| 30 | ||
| 31 | fi leSystem.r eadFile(pa tientFile, 'utf8', f unction(er ror, data) { | |
| 32 | logg er.debug(' fetch-sync ed-patient -list.load PatientFil e(): fs.re adFile() c allback'); | |
| 33 | if ( error) { | |
| 34 | logger .error('Un able to lo ad patient file: %s' , patientF ile); | |
| 35 | logger .error(err or); | |
| 36 | return callback( error); | |
| 37 | } | |
| 38 | ||
| 39 | try { | |
| 40 | logger .debug('fe tch-synced -patient-l ist.loadPa tientFile( ): JSON.pa rse() file contents' ); | |
| 41 | return callback( null, JSON .parse(dat a)); | |
| 42 | } ca tch (parse Error) { | |
| 43 | logger .error('Un able to pa rse patien t file: %s ', patient File); | |
| 44 | logger .error(par seError); | |
| 45 | return callback( util.forma t('Unable to parse p atientFile : %s', pat ientFile)) ; | |
| 46 | } | |
| 47 | }) ; | |
| 48 | } | |
| 49 | ||
| 50 | /* | |
| 51 | Returns a list of UI Ds of Chem Labs to us e when del eting from JDS. | |
| 52 | ||
| 53 | logger: A bunyan-sty le logger | |
| 54 | ||
| 55 | jdsConfig: An object of the fo rm: | |
| 56 | { | |
| 57 | pr otocol: pr otocol, | |
| 58 | ho st: host, | |
| 59 | po rt: port | |
| 60 | } | |
| 61 | ||
| 62 | identifier : A string with a pa tient iden tifier val ue | |
| 63 | ||
| 64 | callback: A standard callback | |
| 65 | ||
| 66 | requestLib : An optio nal overri de of the 'request' library fu nction of the form: | |
| 67 | re questLib(o ptions, ca llback) | |
| 68 | */ | |
| 69 | function f etchPatien tDodChemLa bUidList(l ogger, jds Config, id entifier, callback, requestLib ) { | |
| 70 | re questLib = requestLi b || reque st; | |
| 71 | lo gger.debug ('fetch-sy nced-patie nt-list.fe tchPatient DodChemLab UidList() identifier : %s', ide ntifier); | |
| 72 | lo gger.debug ('fetch-sy nced-patie nt-list.fe tchPatient DodChemLab UidList() provided r equestLib? :', !!requ estLib); | |
| 73 | ||
| 74 | va r list; | |
| 75 | ||
| 76 | va r options = { | |
| 77 | url: util.form at('%s://% s:%s/vpr/% s/index/la boratory?f ilter=and( eq("facili tyCode","D OD"),eq("c ategoryCod e","urn:va :lab-categ ory:CH"))' , jdsConfi g.protocol , jdsConfi g.host, jd sConfig.po rt, identi fier), | |
| 78 | meth od: 'GET' | |
| 79 | }; | |
| 80 | ||
| 81 | re turn reque stLib(opti ons, funct ion(error, response, body) { | |
| 82 | if ( error || r esponse.st atusCode ! == 200) { | |
| 83 | logger .error('Un able to fe tch DOD Ch emLab UID list for p atient: %s ', identif ier); | |
| 84 | logger .error(err or || resp onse.statu sCode); | |
| 85 | return callback( error || r esponse.st atusCode); | |
| 86 | } | |
| 87 | ||
| 88 | try { | |
| 89 | body = JSON.pars e(body); | |
| 90 | list = _.map(bod y.data.ite ms, functi on(chemLab ) { | |
| 91 | return c hemLab.uid ; | |
| 92 | }); | |
| 93 | } ca tch (parse Error) { | |
| 94 | logger .error('Un able to pa rse JDS re sponse'); | |
| 95 | logger .error(par seError); | |
| 96 | return callback( parseError ); | |
| 97 | } | |
| 98 | ||
| 99 | retu rn callbac k(null, li st); | |
| 100 | }) ; | |
| 101 | } | |
| 102 | ||
| 103 | /* | |
| 104 | var config = { | |
| 105 | jds: { | |
| 106 | pr otocol: 'h ttp', | |
| 107 | host: ' IP ', | |
| 108 | port: PORT , | |
| 109 | ti meout: 300 000 | |
| 110 | } | |
| 111 | }; | |
| 112 | ||
| 113 | example of PatientLi st output: | |
| 114 | { | |
| 115 | items: [ | |
| 116 | { | |
| 117 | jpid: "0 003ee96-52 a3-47bc-87 7b-250cbda c703c", | |
| 118 | lastAcce ssTime: 20 1704280031 56, | |
| 119 | patientI dentifiers : [ | |
| 120 | "9E7 A;254", | |
| 121 | "JPI D;0003ee96 -52a3-47bc -877b-250c bdac703c" | |
| 122 | ] | |
| 123 | }, | |
| 124 | { | |
| 125 | jpid: "0 0133272-d5 58-457b-86 5b-4ee7b83 11c13", | |
| 126 | lastAcce ssTime: 20 1704280035 41, | |
| 127 | patientI dentifiers : [ | |
| 128 | "9E7 A;100065", | |
| 129 | "JPI D;00133272 -d558-457b -865b-4ee7 b8311c13" | |
| 130 | ] | |
| 131 | } | |
| 132 | ] | |
| 133 | } | |
| 134 | */ | |
| 135 | function f etchSynchr onizedPati entList(lo gger, jdsC onfig, all SyncedPati ents, call back, requ estLib) { | |
| 136 | re questLib = requestLi b || reque st; | |
| 137 | lo gger.debug ('fetch-sy nced-patie nt-list.fe tchSynchro nizedPatie ntList() a llSyncedPa tients?: % s', allSyn cedPatient s); | |
| 138 | lo gger.debug ('fetch-sy nced-patie nt-list.fe tchSynchro nizedPatie ntList() p rovided re questLib?: %s', !!re questLib); | |
| 139 | ||
| 140 | fu nction has DodChemLab s(identifi er, callba ck) { | |
| 141 | fetc hPatientDo dChemLabUi dList(logg er, jdsCon fig, ident ifier, fun ction(erro r, result) { | |
| 142 | if (er ror) { | |
| 143 | return c allback(er ror); | |
| 144 | } | |
| 145 | ||
| 146 | return callback( null, _.is Array(resu lt) && _.s ize(result ) > 0); | |
| 147 | }, r equestLib) ; | |
| 148 | } | |
| 149 | ||
| 150 | va r list; | |
| 151 | ||
| 152 | va r options = { | |
| 153 | url: util.form at('%s://% s:%s%s', j dsConfig.p rotocol, j dsConfig.h ost, jdsCo nfig.port, '/vpr/all /patientli st'), | |
| 154 | meth od: 'GET' | |
| 155 | }; | |
| 156 | ||
| 157 | // First fet ch all of the synced patient i dentifiers | |
| 158 | re turn reque stLib(opti ons, funct ion(error, response, body) { | |
| 159 | if ( error || r esponse.st atusCode ! == 200) { | |
| 160 | logger .error('fe tch-synced -patient-l ist.fetchS ynchronize dPatientLi st() Unabl e to fetch patient l ist'); | |
| 161 | logger .error(err or || resp onse.statu sCode !== 200); | |
| 162 | return callback( error || r esponse.st atusCode ! == 200); | |
| 163 | } | |
| 164 | ||
| 165 | try { | |
| 166 | logger .debug('fe tch-synced -patient-l ist.fetchS ynchronize dPatientLi st() full response: %s', body) ; | |
| 167 | body = JSON.pars e(body); | |
| 168 | list = _.map(bod y.items, f unction(pa tientInfo) { | |
| 169 | // Get t he first p atientIden tifier val ue since a ny will wo rk in foll owing step s. | |
| 170 | return _ .first(pat ientInfo.p atientIden tifiers); | |
| 171 | }); | |
| 172 | ||
| 173 | logger .debug('fe tch-synced -patient-l ist.fetchS ynchronize dPatientLi st() list of first i dentifiers : %s', lis t); | |
| 174 | } ca tch (parse Error) { | |
| 175 | logger .error('fe tch-synced -patient-l ist.fetchS ynchronize dPatientLi st() Unabl e to parse patient l ist'); | |
| 176 | logger .error(par seError); | |
| 177 | return callback( parseError ); | |
| 178 | } | |
| 179 | // i f allSynce dPatients === true t hen return all synce d patients | |
| 180 | if ( allSyncedP atients) { | |
| 181 | return callback( null, list ); | |
| 182 | } | |
| 183 | ||
| 184 | // f ilter sync ed patient s to only return tho se with DO D ChemLabs | |
| 185 | asyn c.filterLi mit(list, 5, hasDodC hemLabs, c allback); | |
| 186 | }) ; | |
| 187 | } | |
| 188 | ||
| 189 | ||
| 190 | /* | |
| 191 | Create a J SON file w ith the li st of pati ent identi fiers with a value | |
| 192 | of true or false, wh ere 'true' means the patient w as already processed . | |
| 193 | This value should be set by an other util ity when t he work on that part icular | |
| 194 | patient is complete. This is t o minimize reprocess ing patien ts. | |
| 195 | ||
| 196 | { | |
| 197 | "9 E7A;3": fa lse, | |
| 198 | "9 E7A;8": fa lse | |
| 199 | } | |
| 200 | ||
| 201 | ||
| 202 | jdsConfig: JDS conne ction info rmation. T his object should be of the fo rm: | |
| 203 | { | |
| 204 | "proto col": "htt p", | |
| 205 | "host": " IP ", | |
| 206 | "port": " PORT ", | |
| 207 | } | |
| 208 | ||
| 209 | outputFile : The path to the fi le contain ing all of the relev ant patien t data and | |
| 210 | the proces sing statu s for each . This fil e will be a JSON obj ect with t he same | |
| 211 | structure as the 'ex istingPati entData' o bject. | |
| 212 | ||
| 213 | allSyncedP atients: A boolean t o determin e whether or not to filter out patients | |
| 214 | that d o not have DOD ChemL ab data. I f 'true' A LL synced patients w ill be | |
| 215 | return ed regardl ess of whe ther of no t they hav e DOD Chem Labs. | |
| 216 | ||
| 217 | callback: A standard callback | |
| 218 | ||
| 219 | fileSystem : An optio nal overri de of the 'fs' file system. Fo r this fun ction, | |
| 220 | th e object m ust implem ent writeF ile(file, content, o ptions, ca llback) fu nction. | |
| 221 | ||
| 222 | loadFuncti on: An opt ional over ride of th e loadPati entFile() function d efined in this | |
| 223 | fi le to simp lify unit testing. | |
| 224 | ||
| 225 | fetchFunct ion: An op tional ove rride of t he fetchSy nchronized PatientLis t() functi on defined | |
| 226 | in this file to simpli fy unit te sting. | |
| 227 | */ | |
| 228 | function c reatePatie ntList(log ger, jdsCo nfig, outp utFile, ap pend, allS yncedPatie nts, callb ack, fileS ystem, loa dFunction, fetchFunc tion) { | |
| 229 | fi leSystem = fileSyste m || fs; | |
| 230 | lo adFunction = loadFun ction || l oadPatient File; | |
| 231 | fe tchFunctio n = fetchF unction || fetchSync hronizedPa tientList; | |
| 232 | lo gger.debug ('fetch-sy nced-patie nt-list.cr eatePatien tList() ap pend? %s jdsConfig: %j', appe nd, jdsCon fig); | |
| 233 | lo gger.debug ('fetch-sy nced-patie nt-list.cr eatePatien tList() pr ovided fil eSystem?: %s', !!fil eSystem); | |
| 234 | ||
| 235 | if (!append) { | |
| 236 | load Function = function( logger, pa tientFile, callback) { | |
| 237 | logger .debug('fe tch-synced -patient-l ist.create PatientLis t() append is false so return {}'); | |
| 238 | setTim eout(callb ack, 0, nu ll, {}); | |
| 239 | }; | |
| 240 | } | |
| 241 | ||
| 242 | lo adFunction (logger, o utputFile, function( error, exi stingPatie ntData) { | |
| 243 | if(e rror) { | |
| 244 | logger .error('fe tch-synced -patient-l ist.create PatientLis t() Unable to load f ile: %s', outputFile ); | |
| 245 | return callback( error); | |
| 246 | } | |
| 247 | ||
| 248 | fetc hFunction( logger, jd sConfig, a llSyncedPa tients, fu nction(err or, result ) { | |
| 249 | if (er ror) { | |
| 250 | logger.e rror('Unab le to fetc h patient list from %s://%s:%s ', jdsConf ig.protoco l, jdsConf ig.host, j dsConfig.p ort); | |
| 251 | logger.e rror(error ); | |
| 252 | return c allback(er ror); | |
| 253 | } | |
| 254 | ||
| 255 | var pa tients = { }; | |
| 256 | _.each (result, f unction(pi d) { | |
| 257 | patients [pid] = fa lse; | |
| 258 | }); | |
| 259 | ||
| 260 | patien ts = _.def aults(exis tingPatien tData, pat ients); | |
| 261 | var fi leOutput = JSON.stri ngify(pati ents); | |
| 262 | ||
| 263 | fileSy stem.write File(outpu tFile, fil eOutput, ' utf8', fun ction(erro r) { | |
| 264 | logger.d ebug('fetc h-synced-p atient-lis t.createPa tientList( ): fs.writ eFile() ca llback'); | |
| 265 | if (erro r) { | |
| 266 | logger.err or('Unable to write patient fi le: %s', o utputFile) ; | |
| 267 | logger.err or(error); | |
| 268 | return cal lback(erro r); | |
| 269 | } | |
| 270 | ||
| 271 | logger.d ebug('fetc h-synced-p atient-lis t.createPa tientList( ): patient s written to file: % s', output File); | |
| 272 | return c allback(); | |
| 273 | }); | |
| 274 | }); | |
| 275 | }) ; | |
| 276 | } | |
| 277 | ||
| 278 | ||
| 279 | module.exp orts.loadP atientFile = loadPat ientFile; | |
| 280 | module.exp orts.fetch PatientDod ChemLabUid List = fet chPatientD odChemLabU idList; | |
| 281 | module.exp orts.fetch Synchroniz edPatientL ist = fetc hSynchroni zedPatient List; | |
| 282 | module.exp orts.creat ePatientLi st = creat ePatientLi st; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.