192. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/3/2017 11:15:28 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.

192.1 Files compared

# Location File Last Modified
1 ehmp.zip\ehmp\ehmp\product\production\NodeMockServices mockMviProcess.js Wed Jul 20 16:08:24 2016 UTC
2 ehmp.zip\ehmp\ehmp\product\production\NodeMockServices mockMviProcess.js Mon Oct 2 19:36:07 2017 UTC

192.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 438
Changed 1 2
Inserted 0 0
Removed 0 0

192.3 Comparison options

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

192.4 Active regular expressions

No regular expressions were active.

192.5 Comparison detail

  1   /*jslint n ode: true  */
  2   'use stric t';
  3  
  4   var config  = require ('./config .js');
  5   var bunyan  = require ('bunyan') ;
  6   var path =  require(' path');
  7   var logger  = bunyan. createLogg er(config. logger);
  8   var _ = re quire('lod ash');
  9   var async  = require( 'async');
  10   var mockMv i1305 = re quire('./m ockMvi1305 .js');
  11   var mockMv i1309 = re quire('./m ockMvi1309 .js');
  12   var libxml js = requi re("libxml js");
  13   var fs = r equire('fs ');
  14  
  15   var data_p ath = '/da ta/';
  16   var data_f ile_extens ion = '.xm l';
  17  
  18   var USE_XM L_IDS = fa lse;
  19  
  20   function g etElement( xmlDoc, pa th, namesp ace) {
  21       try {
  22           re turn xmlDo c.get(path , namespac e).text();
  23       }
  24       catch  (err) {
  25           re turn "";
  26       }
  27   }
  28  
  29   function g etAttribut e(xmlDoc,  path, name space) {
  30       try {
  31           re turn xmlDo c.get(path , namespac e).value() ;
  32       }
  33       catch  (err) {
  34           re turn "";
  35       }
  36   }
  37  
  38   function m akeFancyMv iIdXml(jso n) {
  39       var IC N_TEMPLATE  = '<id ro ot="2.16.8 40.1.11388 3.4.349" e xtension=" ID^NI^200M ^USVHA^P"/ >';
  40       var VH IC_TEMPLAT E = '<id r oot="2.16. 840.1.1138 83.4.349"  extension= "ID^PI^742 V1^USVHA^A "/>';
  41       var DF N_TEMPLATE  = '<id ro ot="2.16.8 40.1.11388 3.4.349" e xtension=" ID^PI^STAT ION^USVHA^ A"/>';
  42       var ED IPI_TEMPLA TE = '<id  root="2.16 .840.1.113 883.4.349"  extension ="ID^NI^20 0DOD^USDOD ^P"/>';
  43  
  44       var xm l = '';
  45       var cr lf = '\n\t \t\t\t';
  46  
  47       _.map( json, func tion(id, s tation) {
  48           if  (station  === 'icn')  {
  49                xml += I CN_TEMPLAT E.replace( 'ID', id);
  50           }  else if (s tation ===  'VHIC') {
  51                xml += V HIC_TEMPLA TE.replace ('ID', id) ;
  52           }  else if (s tation ===  'EDIPI')  {
  53                xml += E DIPI_TEMPL ATE.replac e('ID', id );
  54           }  else {
  55                xml += D FN_TEMPLAT E.replace( 'ID', id). replace('S TATION', s tation);
  56           }
  57           xm l += crlf;
  58       });
  59  
  60       return  xml.slice (0, -crlf. length);
  61   }
  62  
  63   function s uperLegitM viSoapRequ estProcess or(request Xml) {
  64       var th eOnlyPartO fTheSOAPMe ssageWeRea d = reques tXml.get(' //patientI dentifier/ value').at tr('extens ion').valu e();
  65       return  theOnlyPa rtOfTheSOA PMessageWe Read;
  66   }
  67  
  68   function f etchMviDat a(req, res ) {
  69       logger .debug('mo ckMviProce ss.fetchMv iData(): e ntered met hod.');
  70       var fi lePath = " mvi/";
  71  
  72       // BH:  Should th ese really  be initia lized to d efault val ues like t his?
  73       var la stName = ' EIGHT';
  74       var fi rstName =  'PATIENT';
  75       var do b = '19350 407';
  76       var ss n = '';
  77       var pa tientId =  '10108V420 871^NI^200 M^USVHA';
  78  
  79       var bo dy = "";
  80       req.on ('data', f unction(da ta) {
  81           lo gger.debug ('fetchMvi Data: rece ived soap  message co ntent: ' +  data.toSt ring());
  82           bo dy = body  + data.toS tring();
  83       });
  84  
  85       //Once  the data  has finish ed uploadi ng to the  server...
  86       req.on ('end', fu nction(dat a) {
  87           lo gger.debug ('fetchMvi Data: ente red req.on (end metho d...');
  88           // Check to s ee if they  sent us a  POST with out any bo dy.
  89           if  (body ===  null || b ody === ''  || body = == undefin ed) {
  90                res.stat us(404).en d("Did you  forget to  send a PR PA_IN20130 5UV02 or P RPA_IN2013 09UV02 mes sage, the  body was e mpty");
  91                return;
  92           }
  93  
  94           lo gger.debug ('fetchMvi Data: req. body: %j',  req.body) ;
  95  
  96           // Parse that  data into  an XML ob ject.
  97           va r xmlDoc =  null;
  98           tr y {
  99                xmlDoc =  libxmljs. parseXmlSt ring(body) ;
  100           }
  101           ca tch (err)  {
  102                var s =  'Problem p arsing XML  Soap Mess age: ' + e rr;
  103                logger.w arn(s);
  104                res.stat us(404).en d(s);
  105                return;
  106           }
  107  
  108             var namesp ace = { so apenv: 'ht tp://schem as.xmlsoap .org/soap/ envelope/' , vaww: 'h ttp:// URL           . DNS     ' };
  109           va r path1305  = '//soap env:Envelo pe/soapenv :Body/vaww :PRPA_IN20 1305UV02';
  110           va r path1309  = '//soap env:Envelo pe/soapenv :Body/vaww :PRPA_IN20 1309UV02';
  111  
  112           // Determine  whether we  are a 130 5 message  or a 1309  message
  113           va r message1 305 = xmlD oc.get(pat h1305, nam espace); / /If not un defined, w e are a "S earch Pers on (Attend ed)" messa ge
  114           va r message1 309 = xmlD oc.get(pat h1309, nam espace); / /If not un defined, w e are a "G et Corresp onding IDs " message
  115  
  116           if  (message1 305 !== un defined) {
  117                //Since  we are a 1 305 messag e, retriev e the last Name, firs tName, dob , and ssn  from the m essage sen t to us.
  118                lastName  = getElem ent(xmlDoc , '//livin gSubjectNa me/value/f amily');
  119                firstNam e = getEle ment(xmlDo c, '//livi ngSubjectN ame/value/ given');
  120                dob = ge tAttribute (xmlDoc, ' //livingSu bjectBirth Time/value /@value');
  121                ssn = ge tAttribute (xmlDoc, ' //livingSu bjectId/va lue/@exten sion');
  122  
  123                //Now, s ee which m essage fil e to retur n based of f of our c riteria.
  124                filePath  += "1305/ " + mockMv i1305.fetc hMvi1305Fi leName(las tName, fir stName, do b, ssn);
  125           }
  126           el se if (USE _XML_IDS & & message1 309 !== un defined) {  // the FA KE 1309!
  127                patientI d = xmlDoc .get('//pa tientIdent ifier/valu e').attr(' extension' ).value();
  128  
  129                //Now, s ee which m essage fil e to retur n based of f of our c riteria.
  130                logger.d ebug('fetc hMviData:  looking up  patient i d: ' + pat ientId);
  131                filePath  += "1309/ " + mockMv i1309.fetc hMvi1309Fi leName(pat ientId);
  132           }
  133           el se if (USE _XML_IDS | | message1 309 !== un defined) {  // the 'r eal' 1309!
  134                logger.d ebug('fetc hMviData:  1309 messa ge receive d');
  135  
  136                var json Path = './ data/mvi/1 309/correl atedIds.js on';
  137                var theR ealJson =  { 'no one  is real':  true };
  138                patientI d = 'no, b h, they sh ould not'  && null;
  139  
  140                try {
  141                    theR ealJson =  require(js onPath) ||  'failed t o return d ata/1309';
  142                } catch  (e) {
  143                    json Path = '/o pt/mocks_d ata/correl atedIds.js on';
  144                    theR ealJson =  require(js onPath) ||  'failed t o return m ocks_data' ;
  145                }
  146  
  147                if (theR ealJson['n o one is r eal']) {
  148                    res. status(500 ).end("Cou ld not loa d the corr elatedIds. json file.   Blame De vOps.  See  chef-repo  PR #113." );
  149                } else {
  150                    logg er.debug(' fetchMviDa ta: found  correlatio ns file');
  151  
  152                    pati entId = su perLegitMv iSoapReque stProcesso r(xmlDoc);
  153  
  154                    logg er.debug(' fetchMviDa ta: lookin g up patie nt id: ' +  patientId );
  155  
  156                    var  fancyXML =  '<legitMV Ierror>we  got nothin g and the  real error  failed to  load</leg itMVIerror >';
  157                    var  utf8 = { ' encoding':  'UTF-8' } ;
  158                    try  {
  159                         fancyXML =  fs.readFi leSync(__d irname+dat a_path+fil ePath+'130 9/0 Result s.xml', ut f8);
  160                    } ca tch (e) {
  161                         logger.err or('fetchM viData: co uld not lo ad 0 Resul ts.xml fil e: ' + e);
  162                    }
  163                    var  mviRespons eTemplate  = '<legitM viResponse >INSERTLEG ITRESPONSE HERE<theRe alResponse FailedToLo ad/></legi tMviRespon se>';
  164                    try  {
  165                         mviRespons eTemplate  = fs.readF ileSync(__ dirname+da ta_path+fi lePath+'13 09/respons eTemplate. xml', utf8 );
  166                    } ca tch (e) {
  167                         logger.err or('fetchM viData: co uld not lo ad respons eTemplate. xml file:  ' + e);
  168                    }
  169  
  170                    logg er.debug(' fetchMviDa ta: saved  templates' );
  171  
  172                    theR ealJson.fo rEach(func tion(corre latedIds)  {
  173                         if (correl atedIds.ic n === pati entId.spli t('^')[0]  || correla tedIds.EDI PI === pat ientId.spl it('^')[0] ) {
  174                             var re asons = pa tientId.sp lit('^')[3 ] === 'USD OD' || _.k eys(correl atedIds).l ength > 3;
  175                             logger .debug('fe tchMviData : found pa tient id:  %j', corre latedIds);
  176                             fancyX ML = mviRe sponseTemp late.repla ce('INSERT LEGITRESPO NSEHERE',  makeFancyM viIdXml(co rrelatedId s));
  177                             fancyX ML = fancy XML.replac e('MVI_TOK EN', patie ntId);
  178                             fancyX ML = fancy XML.replac e('D_OR_P_ CUZ_REASON S', (reaso ns?'D':'P' ));
  179                         }
  180                    });
  181  
  182                    logg er.debug(' fetchMviDa ta: sendin g response : %s', fan cyXML);
  183  
  184                    res. header('x- timestamp' , Date.now ()).header ('Content- Type', 'te xt/xml').s end(fancyX ML);
  185                    retu rn;
  186                }
  187           }
  188           el se {
  189                //We wer en't a 130 5 or a 130 9 message,  let them  know.
  190                res.stat us(404).en d("You did  not send  a PRPA_IN2 01305UV02  or PRPA_IN 201309UV02  message,  you sent s omething e lse");
  191                return;
  192           }
  193  
  194           // We have th e full pat h and name  of the fi le, add th e extensio n to it so  we can se nd it.
  195           fi lePath +=  data_file_ extension;
  196           lo gger.debug ('fetchMvi Data: send ing file '  + filePat h);
  197  
  198           // Add a time stamp to t he header  and set th e root dir ectory to  find the f ile from.
  199           va r options  = {
  200                root: pa th.join(__ dirname ,  data_path) ,
  201                headers:  {
  202                    'x-t imestamp':  Date.now( ),
  203                    'Con tent-Type' : 'text/xm l'
  204                }
  205           };
  206  
  207           // Send the f ile back t o them.
  208           re s.sendFile (filePath,  options,  function ( err) {
  209                if (err)  {
  210                    logg er.error(e rr);
  211                    res. status(404 ).end("Pro blem sendi ng file: "  + err);
  212                } else {
  213                    logg er.debug(f ilePath +  ' sent');
  214                }
  215           }) ;
  216       });
  217  
  218   }
  219  
  220   module.exp orts.fetch MviData =  fetchMviDa ta;