48. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/4/2017 8:04:34 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

48.1 Files compared

# Location File Last Modified
1 rdk.zip\rdk\product\production\rdk\src\resources\cds-patient-list definition.js Fri Aug 25 15:36:55 2017 UTC
2 rdk.zip\rdk\product\production\rdk\src\resources\cds-patient-list definition.js Tue Oct 3 17:16:29 2017 UTC

48.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 4 804
Changed 3 6
Inserted 0 0
Removed 0 0

48.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

48.4 Active regular expressions

No regular expressions were active.

48.5 Comparison detail

  1   'use stric t';
  2  
  3   // set up  the packag es we need
  4   var rdk =  require('. ./../core/ rdk');
  5   var _ = re quire('lod ash');
  6   var utils  = require( './utils.j s');
  7   var Object Id = requi re('mongod b').Object ID;
  8   var testId  = require ('../../ut ils/mongo- utils').va lidateMong oDBId;
  9  
  10   // Databas e
  11   var dbName  = 'patien tlist';
  12   var defCol lection =  'definitio ns';
  13  
  14  
  15   // /////// ////////// ///
  16   // Definit ion Templa te
  17   // /////// ////////// ///
  18  
  19   /**
  20    * Retriev e Definiti on(s) used  in the se lection of  patients
  21    *
  22    * @api {g et} /resou rce/cds/pa tient/defi nition[?id =id|name=n ame] Reque st
  23    *      De finition
  24    *
  25    * @apiNam e getDefin ition
  26    * @apiGro up Patient  Definitio n
  27    *
  28    * @apiPar am {String } [id] Def inition id  (24 digit  HEX numbe r), id has
  29    *            precede nce over n ame
  30    * @apiPar am {String } [name] D efinition  name (if i d not used )
  31    *
  32    * @apiSuc cess (Succ ess 200) { json[]} da ta Array o f one or m ore defini tions
  33    * @apiSuc cessExampl e Success- Response:  HTTP/1.1 2 00 OK { "d ata": [ {  "name":
  34    *                      "def one ", "descri ption": "u ser define d descript ion of
  35    *                      this def inition te mplate", " expression ": "{and:  [ {or:
  36    *                      ['A.A',' B.B'], {'A .A'} ]}",  "date":
  37    *                      "2015-03 -10T12:54: 54.035Z",  "scope": " private",  "owner":
  38    *                       " PW           ", "_id":  "54fee99e1 e3bdef2115 34bbb" } ]  }
  39    * @apiErr or (Error  404) . Def inition no t found
  40    * @apiErr orExample  Error-Resp onse: HTTP /1.1 404 N ot Found {  status: 4 04
  41    *                    message: D efinition  not found  }
  42    *
  43    */
  44   function g etDefiniti on(req, re s) {
  45       req.lo gger.debug ('definiti on.getDefi nition()') ;
  46  
  47       if (_. isUndefine d(req.app. subsystems .cds)) {
  48           re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS defin ition reso urce is un available. ');
  49       }
  50  
  51       req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) {
  52           if  (error) {
  53                return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence  store is  unavailabl e.');
  54           }
  55           va r status =  rdk.https tatus.ok;
  56           va r message  = '';
  57           va r match =  utils.comp uteMatch(r eq);
  58  
  59           if  (match.sc ope && (ma tch.scope  !== 'priva te' && mat ch.scope ! == 'site'  && match.s cope !== ' enterprise ')) {
  60                status =  rdk.https tatus.bad_ request; / / 400
  61                message  = 'Scope m ust be spe cified usi ng private  (default) , site or  enterprise ';
  62                return r es.status( status).rd kSend(mess age);
  63           }
  64  
  65           if  (match._i d) {
  66                message  = testId(m atch._id);
  67                if (mess age) {
  68                    retu rn res.sta tus(rdk.ht tpstatus.b ad_request ).rdkSend( message);
  69                }
  70                match._i d = new Ob jectId(mat ch._id);
  71           }
  72           if  (match.na me || matc h._id) {
  73                dbConnec tion.colle ction(defC ollection) .findOne(m atch, func tion(err,  result) {
  74                    mess age = (err  === null)  ? {
  75                         data: resu lt
  76                    } :  {
  77                         error: err
  78                    };
  79                    if ( err === nu ll && _.is Empty(resu lt)) {
  80                         status = r dk.httpsta tus.not_fo und;
  81                         message =  'Definitio n not foun d';
  82                    }
  83                    retu rn res.sta tus(status ).rdkSend( message);
  84                });
  85           }  else { //  return mul tiple
  86                dbConnec tion.colle ction(defC ollection) .find(matc h).toArray (function( err, resul t) {
  87                    mess age = (err  === null)  ? result  : err;
  88                    if ( err === nu ll && _.is Empty(resu lt)) {
  89                         status = r dk.httpsta tus.not_fo und;
  90                         message =  'Definitio n(s) not f ound';
  91                    }
  92                    res. status(sta tus).rdkSe nd(message );
  93                });
  94           }
  95       });
  96   }
  97  
  98  
  99   /**
  100    * Create  a Definiti on to be u sed in the  selection  of patien ts
  101    *
  102    * @api {p ost} /reso urce/cds/p atient/def inition Cr eate Defin ition
  103    *
  104    * @apiNam e postDefi nition
  105    * @apiGro up Patient  Definitio n
  106    *
  107    * @apiHea der {appli cation/jso n} Content -Type
  108    * @apiHea der {json}  content D efinition  object
  109    *
  110    * @apiSuc cess (Succ ess 201) { json} data  Definitio n JSON doc ument
  111    * @apiSuc cessExampl e Success- Response:  HTTP/1.1 2 01 Created  { "data":  { "name":
  112    *                      "def one ", "descri ption": "u ser define d descript ion of
  113    *                      this def inition te mplate", " expression ": "{and:  [ {or:
  114    *                      ['A.A',' B.B'], {'A .A'} ]}",  "date":
  115    *                      "2015-03 -10T12:54: 54.035Z",  "scope": " private",  "owner":
  116    *                       " PW           ", "_id":  "54fee99e1 e3bdef2115 34bbb" } }
  117    *
  118    * @apiErr or (Error  400) {json } error De finition d ocument (r equest bod y) must be
  119    *            defined
  120    * @apiErr orExample  Error-Resp onse: HTTP /1.1 400 B ad Request  { status:  400
  121    *                    message: D efinition  document ( request bo dy) must b e defined  }
  122    * @apiErr or (Error  400) {json } error Sc ope must b e specifie d using pr ivate
  123    *            (defaul t), site o r enterpri se
  124    * @apiErr orExample  Error-Resp onse: HTTP /1.1 400 B ad Request  { status:  400
  125    *                    message: S cope must  be specifi ed using p rivate (de fault),
  126    *                    site or en terprise }
  127    * @apiErr or (Error  400) {json } error De finition d ocument ca n not have  _id
  128    *            defined
  129    * @apiErr orExample  Error-Resp onse: HTTP /1.1 400 B ad Request  { status:  400
  130    *                    message: D efinition  document c an not hav e _id defi ned }
  131    * @apiErr or (Error  400) {json } error De finition n ame must b e defined
  132    * @apiErr orExample  Error-Resp onse: HTTP /1.1 400 B ad Request  { status:  400
  133    *                    message: D efinition  name must  be defined  }
  134    * @apiErr or (Error  409) {json } error De finition ' name' exis ts, can no t be
  135    *            created
  136    * @apiErr orExample  Error-Resp onse: HTTP /1.1 409 C onflict {  status: 40 9 message:
  137    *                    Definition  'name' ex ists, can  not be cre ated }
  138    * @apiErr or (Error  500) {json } error A  system or  database e rror messa ge was
  139    *            returne d
  140    * @apiErr orExample  Error-Resp onse: HTTP /1.1 500 I nternal Se rver Error  { status:
  141    *                    500 messag e: system  or databas e error me ssage }
  142    *
  143    */
  144   function p ostDefinit ion(req, r es) {
  145       req.lo gger.debug ('definiti on.postDef inition');
  146  
  147       if (_. isUndefine d(req.app. subsystems .cds)) {
  148           re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS defin ition reso urce is un available. ');
  149       }
  150  
  151       req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) {
  152           if  (error) {
  153                return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence  store is  unavailabl e.');
  154           }
  155           va r status =  rdk.https tatus.crea ted;
  156           va r message  = '';
  157           va r doc = re q.body;
  158  
  159           if  (!doc) {
  160                status =  rdk.https tatus.bad_ request;
  161                message  = 'Definit ion docume nt (reques t body) mu st be defi ned';
  162                return r es.status( status).rd kSend(mess age);
  163           }
  164           if  (doc.scop e && (doc. scope !==  'private'  && doc.sco pe !== 'si te' && doc .scope !==  'enterpri se')) {
  165                status =  rdk.https tatus.bad_ request; / / 400
  166                message  = 'Scope m ust be spe cified usi ng private  (default) , site or  enterprise ';
  167                return r es.status( status).rd kSend(mess age);
  168           }
  169           de lete doc._ id;
  170  
  171           if  (!doc.nam e) {
  172                status =  rdk.https tatus.bad_ request;
  173                message  = 'Definit ion name m ust be def ined';
  174                return r es.status( status).rd kSend(mess age);
  175           }
  176           do c.date = n ew Date();
  177           if  (!doc.sco pe) {
  178                // defau lt to priv ate scope
  179                doc.scop e = 'priva te';
  180           }
  181           sw itch (doc. scope) {
  182                case 'pr ivate':
  183                    doc. owner = re q.session. user.usern ame;
  184                    brea k;
  185                case 'si te':
  186                    doc. owner = re q.session. user.site;
  187                    brea k;
  188                default:
  189                    dele te doc.own er;
  190           }
  191           va r match =  {
  192                name: do c.name,
  193                scope: d oc.scope,
  194                owner: d oc.owner
  195           };
  196           //  Verify th e definiti on does no t already  exist
  197           db Connection .collectio n(defColle ction).fin dOne(match , function (err, resu lt) {
  198                if (!_.i sEmpty(res ult)) {
  199                    mess age = 'Def inition \' ' + doc.na me + '\' e xists, can  not be cr eated';
  200                    retu rn res.sta tus(rdk.ht tpstatus.c onflict).r dkSend(mes sage);
  201                }
  202                if (!_.i sEmpty(err )) {
  203                    retu rn res.sta tus(rdk.ht tpstatus.i nternal_se rver_error ).rdkSend( err);
  204                }
  205                dbConnec tion.colle ction(defC ollection) .insert(do c, functio n(err, res ult) {
  206                    var  message =  (err === n ull) ? res ult.ops :  err;
  207                    if ( !_.isEmpty (err)) {
  208                         status = r dk.httpsta tus.intern al_server_ error;
  209                    }
  210                    retu rn res.sta tus(status ).rdkSend( message);
  211                });
  212           }) ;
  213       });
  214   }
  215  
  216  
  217   /**
  218    * Delete  Definition  used in t he selecti on of pati ents
  219    *
  220    * Delete  a definiti on documen t
  221    *
  222    * @api {d elete} /re source/cds /patient/d efinition? [?id=id|na me=name] D elete
  223    *      De finition ( name or id )
  224    *
  225    * @apiNam e deleteDe finition
  226    * @apiGro up Patient  Definitio n
  227    *
  228    * @apiPar am {String } [id] 24  digit HEX  number doc  id
  229    * @apiPar am {String } [name] D efinition  name (if i d not used )
  230    *
  231    * @apiSuc cess (Succ ess 200) { Number} da ta Delete  count
  232    * @apiSuc cessExampl e Success- Response:  HTTP/1.1 2 00 OK
  233    * { "data ": 1 }
  234    *
  235    * @apiErr or (Error  404) {Numb er} data T he specifi ed definit ion was no t found
  236    * @apiErr orExample  Error-Resp onse: HTTP /1.1 404 N ot Found {  status: 4 04
  237    *                    message: n ull }
  238    * @apiErr or (Error  400) {json } error Na me or Id r equired
  239    * @apiErr orExample  Error-Resp onse: HTTP /1.1 400 B ad Request  { status:  400
  240    *                    message: N ame or Id  required }
  241    *
  242    */
  243   function d eleteDefin ition(req,  res) {
  244       req.lo gger.debug ('definiti on.deleteD efinition( )');
  245  
  246       if (_. isUndefine d(req.app. subsystems .cds)) {
  247           re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS defin ition reso urce is un available. ');
  248       }
  249  
  250       req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) {
  251           if  (error) {
  252                return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence  store is  unavailabl e.');
  253           }
  254           va r status =  rdk.https tatus.ok;
  255           va r message  = '';
  256  
  257           va r match =  utils.comp uteMatch(r eq);
  258           if  (match._i d) {
  259                message  = testId(m atch._id);
  260                if (!mes sage) {
  261                    matc h._id = ne w ObjectId (match._id );
  262                } else {
  263                    retu rn res.sta tus(rdk.ht tpstatus.b ad_request ).rdkSend( message);
  264                }
  265           }
  266  
  267           if  (match.na me || matc h._id) {
  268                dbConnec tion.colle ction(defC ollection) .remove(ma tch, funct ion(err, r esult) {
  269                    var  message =  (err === n ull) ? res ult : err;
  270                    if ( err !== nu ll || resu lt.result. n !== 1) {
  271                         status = r dk.httpsta tus.not_fo und;
  272                         message =  'Definitio n not foun d';
  273                    }
  274                    if ( !_.isEmpty (err)) {
  275                         status = r dk.httpsta tus.bad_re quest;
  276                    }
  277                    retu rn res.sta tus(status ).rdkSend( message);
  278                });
  279           }  else {
  280                message  = 'Name or  Id requir ed';
  281                return r es.status( rdk.httpst atus.bad_r equest).rd kSend(mess age);
  282           }
  283       });
  284   }
  285  
  286  
  287   /**
  288    * Copy a  Definition  used in t he selecti on of pati ents
  289    *
  290    * @api {p ost} /reso urce/cds/p atient/def inition/co py?id=123& newname=so mename
  291    *      Co py Definit ion
  292    *
  293    * @apiNam e copyDefi nition
  294    * @apiGro up Patient  Definitio n
  295    *
  296    * @apiPar am {String } [id] 24  digit HEX  number doc  id
  297    * @apiPar am {String } [name] D efinition  name (if i d not used )
  298    * @apiPar am {String } newname  new defini tion name
  299    *
  300    * @apiSuc cess (Succ ess 201) { json} data  update co unt
  301    * @apiSuc cessExampl e Success- Response:  HTTP/1.1 2 01 Created
  302    * { "data ": {
  303    *    "nam e":"def on e A",
  304    *    "des cription":  "user def ined descr iption of  this defin ition temp late",
  305    *    "exp ression":  "{and: [ { or: ['A.A' ,'B.B'], { 'A.A'} ]}" ,
  306    *    "dat e":"2015-0 3-10T12:54 :54.035Z",
  307    *    "sco pe": "priv ate",
  308    *      "owner": " PW           ",
  309    *    "_id ": "54fee9 9e1e3bdef2 11534bbb"  }
  310    * }
  311    *
  312    * @apiErr or (Error  400) {json } error Na me or Id r equired
  313    * @apiErr orExample  Error-Resp onse: HTTP /1.1 400 B ad Request
  314    * { statu s: 400 mes sage: Name  or Id req uired }
  315    * @apiErr or (Error  404) data  Source Def inition no t found
  316    * @apiErr orExample  Error-Resp onse: HTTP /1.1 404 N ot Found
  317    *  { stat us: 404 me ssage: Sou rce Defini tion not f ound }
  318    * @apiErr or (Error  409) {json } error De finition ' name' exis ts, can no t be
  319    *            created
  320    * @apiErr orExample  Error-Resp onse: HTTP /1.1 409 C onflict
  321    *  { stat us: 409 me ssage: Def inition 'n ame' exist s, can not  be create d }
  322    * @apiErr or (Error  500) {json } error A  system or  database e rror messa ge was
  323    *            returne d
  324    * @apiErr orExample  Error-Resp onse: HTTP /1.1 500 I nternal Se rver Error
  325    *  { stat us:500 mes sage: syst em or data base error  message }
  326    *
  327    */
  328   function c opyDefinit ion(req, r es) {
  329       req.lo gger.debug ('definiti on.copyDef inition()' );
  330  
  331       if (_. isUndefine d(req.app. subsystems .cds)) {
  332           re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS defin ition reso urce is un available. ');
  333       }
  334  
  335       req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) {
  336           if  (error) {
  337                return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence  store is  unavailabl e.');
  338           }
  339           va r status =  rdk.https tatus.crea ted;
  340           va r message  = '';
  341           va r newname  = req.quer y.newname;
  342  
  343           va r match =  utils.comp uteMatch(r eq);
  344           if  ((!match. name && !m atch._id)  || !newnam e) {
  345                status =  rdk.https tatus.bad_ request;
  346                message  = 'Name or  Id and a  Newname re quired';
  347                return r es.status( status).rd kSend(mess age);
  348           }
  349           if  (match._i d) {
  350                message  = testId(m atch._id);
  351                if (!mes sage) {
  352                    matc h._id = ne w ObjectId (match._id );
  353                } else {
  354                    stat us = rdk.h ttpstatus. bad_reques t;
  355                    retu rn res.sta tus(status ).rdkSend( message);
  356                }
  357           }
  358  
  359           //  retrieve  source Def inition do cument
  360           db Connection .collectio n(defColle ction).fin dOne(match , function (err, patl st) {
  361                if (err  || _.isEmp ty(patlst) ) {
  362                    if ( err) {
  363                         status = r dk.httpsta tus.intern al_server_ error;
  364                    } el se {
  365                         status = r dk.httpsta tus.not_fo und;
  366                         message =  'Source De finition n ot found';
  367                    }
  368                    retu rn res.sta tus(status ).rdkSend( message);
  369                }
  370  
  371                // see i t destinat ion patien t list doc ument exis ts
  372                delete m atch._id;
  373                match.na me = newna me;
  374                dbConnec tion.colle ction(defC ollection) .findOne(m atch, func tion(err,  test) {
  375                    if ( err || !_. isEmpty(te st)) {
  376                         if (err) {
  377                             status  = rdk.htt pstatus.ba d_request;
  378                             messag e = err;
  379                         } else {
  380                             status  = rdk.htt pstatus.co nflict;
  381                             messag e = 'Defin ition docu ment with  name \'' +  newname +  '\' alrea dy exists' ;
  382                         }
  383                         return res .status(st atus).rdkS end(messag e);
  384                    }
  385  
  386                    // c reate a ne w Definiti on based o n result
  387                    patl st.name =  newname;
  388                    dele te patlst. _id;
  389                    dbCo nnection.c ollection( defCollect ion).inser t(patlst,  function(e rr, result ) {
  390                         message =  (err === n ull) ? res ult.ops :  err;
  391                         if (err) {
  392                             status  = rdk.htt pstatus.in ternal_ser ver_error;
  393                         }
  394                         return res .status(st atus).rdkS end(messag e);
  395                    });
  396                });
  397           }) ;
  398       });
  399   }
  400  
  401  
  402   module.exp orts.getDe finition =  getDefini tion;
  403   module.exp orts.postD efinition  = postDefi nition;
  404   module.exp orts.delet eDefinitio n = delete Definition ;
  405   module.exp orts.copyD efinition  = copyDefi nition;