94. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/4/2017 8:04:36 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.

94.1 Files compared

# Location File Last Modified
1 rdk.zip\rdk\product\production\rdk\src\subsystems\vix vix-subsystem-spec.js Mon Aug 21 12:51:07 2017 UTC
2 rdk.zip\rdk\product\production\rdk\src\subsystems\vix vix-subsystem-spec.js Tue Oct 3 18:42:57 2017 UTC

94.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 5 1548
Changed 4 12
Inserted 0 0
Removed 0 0

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

94.4 Active regular expressions

No regular expressions were active.

94.5 Comparison detail

  1   'use stric t';
  2  
  3   var _ = re quire('lod ash');
  4   var bunyan  = require ('bunyan') ;
  5   var moment  = require ('moment') ;
  6   var rdk =  require('. ./../core/ rdk');
  7   var http =  rdk.utils .http;
  8   var RpcCli ent = requ ire('vista -js').RpcC lient;
  9   var vixSub system = r equire('./ vix-subsys tem');
  10  
  11   var app =  {
  12       config : {
  13           rp cConfig: {
  14                context:  'HMP UI C ONTEXT'
  15           },
  16           vi x: {
  17                  baseUrl: ' http:// IP                ',
  18                api: {
  19                    stud yQuery:  ' /vix/viewe r/studyque ry',
  20                    stud yDetails:  '/vix/view er/studyde tails'
  21                },
  22                agentOpt ions: {
  23                    pfx:  null,
  24                    reje ctUnauthor ized: null ,
  25                    requ estCert: n ull,
  26                    pass phrase: nu ll
  27                }
  28           },
  29           vi staSites:  {
  30                '9E7A':  {
  31                    divi sion: [{id :'500',nam e:'PANORAM A'}],
  32                      host: ' IP          ',
  33                      localIP: ' IP        ',
  34                    loca lAddress:  'localhost ',
  35                      port:  PORT ,
  36                    prod uction: fa lse,
  37                      accessCode : ' PORT ',
  38                      verifyCode : ' PORT ',
  39                    info ButtonOid:  '1.3.6.1. 4.1.3768',
  40                    abbr eviation:  'PAN',
  41                    uatr acker: tru e
  42                }
  43           }
  44       }
  45   };
  46  
  47   var logger  = sinon.s tub(bunyan .createLog ger({
  48       name:  'vix-subsy stem-spec'
  49   }));
  50  
  51   var user =  {
  52       firstn ame: 'FIRS T',
  53       lastna me: 'LAST' ,
  54       ssn: ' 000000000' ,
  55       facili ty: '9E7A' ,
  56       site:  'PANORAMA' ,
  57       divisi on: '500',
  58       duz: {
  59           'P ANORAMA':  '500'
  60       },
  61       'vixBs eToken': ' ~1XWBAS121 0-215869_2 ',
  62       'vixBs eTokenExpi res': mome nt().add(2 2, 'hours' ).format(' X')
  63   };
  64  
  65   vixSubsyst em._init(a pp, logger );
  66  
  67   describe(' vix-subsys tem._init' , function  () {
  68       after( function ( ) {
  69           vi xSubsystem ._vixServe rConfigure d = true;
  70       });
  71  
  72       it('Sh ould be di sabled if  there is n o baseUrl  in the app  config',  function ( ) {
  73           vi xSubsystem ._init({},  logger);
  74           ex pect(vixSu bsystem._v ixServerCo nfigured). to.be(fals e);
  75       });
  76  
  77       it('Sh ould be en abled if t here is a  baseUrl in  the app c onfig', fu nction ()  {
  78           vi xSubsystem ._init(app , logger);
  79           ex pect(vixSu bsystem._v ixServerCo nfigured). to.be(true );
  80       });
  81   });
  82  
  83   describe(' vix-subsys tem\'s hea lthcheck',  function  () {
  84       it('Sh ould be sk ipped if t he vix-sub system is  disabled',  function  (done) {
  85           va r config =  vixSubsys tem.getSub systemConf ig(app, lo gger);
  86           vi xSubsystem ._vixServe rConfigure d = false;
  87           co nfig.healt hcheck.che ck(functio n (healthy ) {
  88                expect(h ealthy).to .be(false) ;
  89                done();
  90           }) ;
  91           vi xSubsystem ._vixServe rConfigure d = true;
  92       });
  93  
  94       it('Sh ould ping  vix if the  vix-subsy stem is en abled', fu nction (do ne) {
  95           si non.stub(h ttp, 'get' ).callsFak e(function (config, c allback) {
  96                callback (null);
  97           }) ;
  98           va r config =  vixSubsys tem.getSub systemConf ig(app, lo gger);
  99           co nfig.healt hcheck.che ck(functio n (healthy ) {
  100                expect(h ealthy).to .be(true);
  101                done();
  102           }) ;
  103       });
  104   });
  105  
  106   describe(' vix-subsys tem.addIma gesToDocum ent', func tion() {
  107       var re q, jdsResp onse;
  108  
  109       before Each(funct ion() {
  110           re q = {
  111                app: app ,
  112                body: {} ,
  113                intercep torResults : {
  114                    'pat ientIdenti fiers': {
  115                         'icn': '10 108V420871 ',
  116                         'dfn': '3' ,
  117                    },
  118                    'jds Filter': { }
  119                },
  120                logger:  logger,
  121                query: { },
  122           };
  123           _. set(req, ' session.us er', user) ;
  124           jd sResponse  = {
  125                patientI cn: '10108 V420871',
  126                data: {
  127                    item s: []
  128                }
  129           };
  130       });
  131  
  132       it('Ab orts when  vix-subsys tem is dis abled', fu nction (do ne) {
  133           vi xSubsystem ._vixServe rConfigure d = false;
  134           _. set(req, ' intercepto rResults.p atientIden tifiers.si teDfn', '9 E7A;3');
  135           vi xSubsystem .addImages ToDocument (req, jdsR esponse, f unction(er ror, inner JdsRespons e) {
  136                vixSubsy stem._vixS erverConfi gured = tr ue;
  137                expect(e rror).to.e ql({ error : 'vix is  not config ured' });
  138                done();
  139           }) ;
  140       });
  141  
  142       functi on tryWith PidInQuery AndBody(pi d, descrip tion, test , skipOrOn ly) {
  143           if  (skipOrOn ly) {
  144                describe ('(query p id)', func tion() {
  145                    befo reEach(fun ction() {
  146                         _.set(req,  'intercep torResults .patientId entifiers. siteDfn',  pid);
  147                    });
  148                    it[s kipOrOnly] (descripti on, test);
  149                });
  150                describe ('(body pi d)', funct ion() {
  151                    befo reEach(fun ction() {
  152                         _.set(req,  'intercep torResults .patientId entifiers. siteDfn',  pid);
  153                    });
  154                    it[s kipOrOnly] (descripti on, test);
  155                });
  156           }  else {
  157                describe ('(query p id)', func tion() {
  158                    befo reEach(fun ction() {
  159                         _.set(req,  'intercep torResults .patientId entifiers. siteDfn',  pid);
  160                    });
  161                    it(d escription , test);
  162                });
  163                describe ('(body pi d)', funct ion() {
  164                    befo reEach(fun ction() {
  165                         _.set(req,  'intercep torResults .patientId entifiers. siteDfn',  pid);
  166                    });
  167                    it(d escription , test);
  168                });
  169           }
  170       }
  171  
  172       tryWit hPidInQuer yAndBody.o nly = _.bi nd(tryWith PidInQuery AndBody, t his, _, _,  _, 'only' );
  173       tryWit hPidInQuer yAndBody.s kip = _.bi nd(tryWith PidInQuery AndBody, t his, _, _,  _, 'skip' );
  174  
  175       tryWit hPidInQuer yAndBody(' 1234', 'sk ips enrich ment with  invalid ic n/pid', fu nction() {
  176           _. set(req, ' intercepto rResults.p atientIden tifiers.ic n', '1234' );
  177           _. set(req, ' intercepto rResults.p atientIden tifiers.pi d', '1234' );
  178           vi xSubsystem .addImages ToDocument (req, jdsR esponse, f unction(er ror, inner JdsRespons e) {
  179                expect(e rror).to.e ql('icn an d site;dfn  are not v alid');
  180                expect(r eq.logger. info.calle dWithMatch ({error: ' icn and si te;dfn are  not valid  - returni ng error'} )).to.be.t rue();
  181           }) ;
  182       });
  183  
  184       tryWit hPidInQuer yAndBody(' 9E7A;3', ' does nothi ng with em pty respon se from VI X', functi on() {
  185           si non.stub(h ttp, 'post ').callsFa ke(functio n(config,  callback)  {
  186                callback (null, {bo dy: {studi es: []}});
  187           }) ;
  188           vi xSubsystem .addImages ToDocument (req, jdsR esponse, f unction(er ror, inner JdsRespons e) {
  189                expect(i nnerJdsRes ponse).to. eql(jdsRes ponse);
  190                expect(r eq.logger. error.call edWithMatc h({error:  'Empty res ponse from  VIX'})).t o.be.true( );
  191           }) ;
  192       });
  193  
  194       tryWit hPidInQuer yAndBody(' 9E7A;3', ' adds prope rties to r ecords tha t have ass ociated im ages', fun ction() {
  195           si non.stub(h ttp, 'post ').callsFa ke(functio n(config,  callback)  {
  196                callback (null, {bo dy: {studi es: [{
  197                         localId: 1
  198                    }, {
  199                         localId: 2 ,
  200                         category:  'RA',
  201                         hasImages:  true,
  202                         contextId:  'RPT^CPRS ^3^RA^2^^^ ^^^^^1'
  203                    }, {
  204                         localId: 3 ,
  205                         hasImages:  true,
  206                         contextId:  'RPT^CPRS ^3^TIU^3^^ ^^^^^^1'
  207                    }, {
  208                         localId: 4 ,
  209                         facilityNa me: 'DOD',
  210                         thumbnails : [],
  211                         viewerUrl:  '',
  212                         detailsUrl : '',
  213                         studyId: ' ',
  214                         contextId:  'RPT^CPRS ^3^TIU^4^^ DOD^^^^^^0 ',
  215                         imageCount : 2
  216                    }
  217                ]}});
  218           }) ;
  219           va r jdsData  = _.cloneD eep(jdsRes ponse);
  220           jd sData.data .items = [ {
  221                    loca lId: 1
  222                }, {
  223                    loca lId: 2,
  224                    cate gory: 'RA' ,
  225                    hasI mages: tru e
  226                }, {
  227                    loca lId: 3,
  228                    hasI mages: tru e
  229                }, {
  230                    loca lId: 4,
  231                    faci lityName:  'DOD'
  232                }];
  233           vi xSubsystem .addImages ToDocument (req, jdsD ata, funct ion(error,  innerJdsR esponse) {
  234                expect(i nnerJdsRes ponse.data .items).to .eql([{
  235                         localId: 1
  236                    }, {
  237                         localId: 2 ,
  238                         category:  'RA',
  239                         hasImages:  true,
  240                         contextId:  'RPT^CPRS ^3^RA^2^^^ ^^^^^1'
  241                    }, {
  242                         localId: 3 ,
  243                         hasImages:  true,
  244                         contextId:  'RPT^CPRS ^3^TIU^3^^ ^^^^^^1'
  245                    }, {
  246                         localId: 4 ,
  247                         facilityNa me: 'DOD',
  248                         thumbnails : [undefin ed],
  249                         viewerUrl:  '',
  250                         detailsUrl : '',
  251                         studyId: ' ',
  252                         contextId:  'RPT^CPRS ^3^TIU^4^^ DOD^^^^^^0 ',
  253                         hasImages:  true,
  254                         imageCount : 2
  255                    }
  256                ]);
  257                expect(r eq.logger. debug.call edWith({
  258                    post LoopVixBod y: {
  259                         studies: [ {
  260                             localI d: 1
  261                         }, {
  262                             localI d: 2,
  263                             catego ry: 'RA',
  264                             hasIma ges: true,
  265                             contex tId: 'RPT^ CPRS^3^RA^ 2^^^^^^^^1 '
  266                         }, {
  267                             localI d: 3,
  268                             hasIma ges: true,
  269                             contex tId: 'RPT^ CPRS^3^TIU ^3^^^^^^^^ 1'
  270                         }]
  271                    }
  272                })).to.b e.true();
  273           }) ;
  274       });
  275  
  276       tryWit hPidInQuer yAndBody(' 9E7A;3', ' does not a dd propert ies to rec ords that  have no as sociated i mages', fu nction() {
  277           va r jdsData  = _.cloneD eep(jdsRes ponse);
  278           jd sData.data .items = [ {
  279                    loca lId: 1,
  280                    cate gory: 'RA' ,
  281                    faci lityCode:  '500',
  282                    faci lityName:  'PANORAMA' ,
  283                    kind : 'Imaging ',
  284                    name : 'CT SCAN '
  285                }, {
  286                    loca lId: 2,
  287                    cate gory: 'RA' ,
  288                    faci lityCode:  '500',
  289                    faci lityName:  'PANORAMA' ,
  290                    kind : 'Imaging ',
  291                    name : 'CHEST S CAN'
  292                }, {
  293                    loca lId: 3,
  294                    faci lityCode:  '500',
  295                    faci lityName:  'PANORAMA' ,
  296                    kind : 'Advance  Directive ',
  297                    name : 'CT SCAN '
  298                }, {
  299                    loca lId: 4,
  300                    faci lityCode:  '507',
  301                    faci lityName:  'KODAK',
  302                    kind : 'Crisis  Note',
  303                    name : 'CRISIS  NOTE'
  304                }];
  305           vi xSubsystem .addImages ToDocument (req, jdsD ata, funct ion(error,  innerJdsR esponse) {
  306                expect(i nnerJdsRes ponse.data .items).to .eql([
  307                    {
  308                         localId: 1 ,
  309                         category:  'RA',
  310                         facilityCo de: '500',
  311                         facilityNa me: 'PANOR AMA',
  312                         kind: 'Ima ging',
  313                         name: 'CT  SCAN'
  314                    }, {  localId:  2,
  315                         category:  'RA',
  316                         facilityCo de: '500',
  317                         facilityNa me: 'PANOR AMA',
  318                         kind: 'Ima ging',
  319                         name: 'CHE ST SCAN'
  320                    }, {  localId:  3,
  321                         facilityCo de: '500',
  322                         facilityNa me: 'PANOR AMA',
  323                         kind: 'Adv ance Direc tive',
  324                         name: 'CT  SCAN'
  325                    }, {
  326                         localId: 4 ,
  327                         facilityCo de: '507',
  328                         facilityNa me: 'KODAK ',
  329                         kind: 'Cri sis Note',
  330                         name: 'CRI SIS NOTE'
  331                    }
  332                ]);
  333           }) ;
  334       });
  335  
  336       tryWit hPidInQuer yAndBody(' 9E7A;3', ' does nothi ng when vi x is unava ilable', f unction()  {
  337           si non.stub(v ixSubsyste m, '_getQu eryConfig' ).callsFak e(function (appConfig , logger,  query) {
  338                return n ull;
  339           }) ;
  340           vi xSubsystem .addImages ToDocument (req, jdsR esponse, f unction(er ror, inner JdsRespons e) {
  341                expect(r eq.logger. debug.call edWith({er ror: {erro r: 'vix is  not confi gured'}})) ;
  342                expect(i nnerJdsRes ponse).to. eql(jdsRes ponse);
  343           }) ;
  344       });
  345   });
  346  
  347   describe(' vix-subsys tem.getIma gesForDocu ment', fun ction() {
  348       var re q;
  349  
  350       var si ngleVixRes ponse = {
  351           bo dy: {
  352                studies:  [{
  353                    cont extId: 'RP T^CPRS^3^R A^6839398. 7969-1^86^ CAMP MASTE R^^^^^^1',
  354                    exte rnalContex tId: 'RA-6 61',
  355                    grou pIEN: '166 0',
  356                    pati entICN: '1 0108V42087 1',
  357                    site Number: '5 00',
  358                    deta ilsUrl: 'h ttp://54.2 35.252.102 :9911/vix/ viewer/stu dydetails? ContextId= RPT%5eCPRS %5e3%5eRA% 5e6839398. 7969-1%5e8 6%5eCAMP+M ASTER%5e%5 e%5e%5e%5e %5e1&SiteN umber=500& PatientICN =10108V420 871&Securi tyToken=Mj AxNy0wMi0x M1QwNTowMD owMC4wMDAw MDAwWnx0Rk M4SDRreHl0 d1FfTHgxZj JNOGZmQ2hH Y2pJUS1hTm Vmb0VrdlJT YlFPU1N0c2 1GZnpKXzlo ZWJzaTNIcD ZwbkF2MnZO R2VEYXlub3 VpemJUaVps NTNPUjMtaU 5ucXpKZDlh S2F5c3k2OD 18M2JjMmVh M2QtNjYyMC 00MWYzLWJk NjYtOTcwMD Y0NzFmZDMz fGhSdm14Qk tUeGlzWlVT WTBEblJpUW Zjb0lVNUpi UVhlSDRXRk EvK1RxSGkx SnQ3clFSZn E4Z3Y3bDEw VFk4V3FuOF N6VXJlYXU1 bXBoK3VPTk VXd3ZDWW4r RlpZSzNLTU dYdGRSNFlO ekpNPQ%3d% 3d&AuthSit eNumber=50 0',
  359                    view erUrl: 'ht tp://54.23 5.66.32:99 11/vix/vie wer/loader ?ContextId =RPT%5eCPR S%5e3%5eRA %5e6839398 .7969-1%5e 86%5eCAMP+ MASTER%5e% 5e%5e%5e%5 e%5e1&Site Number=500 &PatientIC N=10108V42 0871&Secur ityToken=M jAxNy0wMi0 xM1QwNTowM DowMC4wMDA wMDAwWnx0R kM4SDRreHl 0d1FfTHgxZ jJNOGZmQ2h HY2pJUS1hT mVmb0VrdlJ TYlFPU1N0c 21GZnpKXzl oZWJzaTNIc DZwbkF2MnZ OR2VEYXlub 3VpemJUaVp sNTNPUjMta U5ucXpKZDl hS2F5c3k2O D18M2JjMmV hM2QtNjYyM C00MWYzLWJ kNjYtOTcwM DY0NzFmZDM zfGhSdm14Q ktUeGlzWlV TWTBEblJpU WZjb0lVNUp iUVhlSDRXR kEvK1RxSGk xSnQ3clFSZ nE4Z3Y3bDE wVFk4V3FuO FN6VXJlYXU 1bXBoK3VPT kVXd3ZDWW4 rRlpZSzNLT UdYdGRSNFl OekpNPQ%3d %3d&AuthSi teNumber=5 00',
  360                    thum bnailUrl:  'http://54 .235.252.1 02:9911/vi x/viewer/t humbnails? ContextId= aW1hZ2VVUk 49dXJuOnZh aW1hZ2U6NT AwLTE2NjEt MTY2MC0xMD EwOFY0MjA4 NzEmaW1hZ2 VRdWFsaXR5 PTIwJmNvbn RlbnRUeXBl PWltYWdlL2 pwZWcsaW1h Z2UveC10YX JnYSxpbWFn ZS9ibXAsKi 8q&Securit yToken=MjA xNy0wMi0xM 1QwNTowMDo wMC4wMDAwM DAwWnx0RkM 4SDRreHl0d 1FfTHgxZjJ NOGZmQ2hHY 2pJUS1hTmV mb0VrdlJTY lFPU1N0c21 GZnpKXzloZ WJzaTNIcDZ wbkF2MnZOR 2VEYXlub3V pemJUaVpsN TNPUjMtaU5 ucXpKZDlhS 2F5c3k2OD1 8M2JjMmVhM 2QtNjYyMC0 0MWYzLWJkN jYtOTcwMDY 0NzFmZDMzf GhSdm14Qkt UeGlzWlVTW TBEblJpUWZ jb0lVNUpiU VhlSDRXRkE vK1RxSGkxS nQ3clFSZnE 4Z3Y3bDEwV Fk4V3FuOFN 6VXJlYXU1b XBoK3VPTkV Xd3ZDWW4rR lpZSzNLTUd YdGRSNFlOe kpNPQ%3d%3 d&AuthSite Number=500 ',
  361                    stat usCode: '2 00',
  362                    imag eCount: 6,
  363                    stud yDescripti on: 'ECHO  EXAM OF HE ART',
  364                    stud yDate: '20 16-06-01T2 0:30:00-04 :00',
  365                    acqu isitionDat e: '2016-0 6-13T20:16 :00-04:00' ,
  366                    stud yId: 'urn: vastudy:50 0-1660-101 08V420871' ,
  367                    site Name: 'CAM P MASTER',
  368                    even t: 'ULTRAS OUND',
  369                    pack age: 'RAD' ,
  370                    type : 'IMAGE',
  371                    orig in: 'VA',
  372                    stud yType: 'IM AGE',
  373                    proc edureDescr iption: 'R AD US',
  374                    spec ialtyDescr iption: 'R ADIOLOGY',
  375                    stud yClass: 'C LIN',
  376                    isSe nsitive: f alse
  377                }],
  378                patientI CN: '10108 V420871',
  379                siteNumb er: '500',
  380                authSite Number: '5 00'
  381           }
  382       };
  383  
  384       before Each(funct ion() {
  385           re q = {
  386                app: app ,
  387                body: {} ,
  388                intercep torResults : {
  389                    'pat ientIdenti fiers': {
  390                         'icn': '10 108V420871 ',
  391                         'dfn': '3' ,
  392                         'siteDfn':  '9E7A;3'
  393                    },
  394                    'jds Filter': { }
  395                },
  396                logger:  logger,
  397                query: {
  398                    site Number: '5 00',
  399                    cont extId: 'RP T^CPRS^3^R A^6839398. 7969-1^86^ CAMP MASTE R^^^^^^1'
  400                },
  401           };
  402           _. set(req, ' session.us er', user) ;
  403       });
  404  
  405       it('Ab orts when  vix-subsys tem is dis abled', fu nction (do ne) {
  406           vi xSubsystem ._vixServe rConfigure d = false;
  407           vi xSubsystem .getImages ForDocumen t(req, fun ction(erro r, respons e) {
  408                vixSubsy stem._vixS erverConfi gured = tr ue;
  409                expect(e rror).to.e ql({ error : 'vix is  not config ured' });
  410                done();
  411           }) ;
  412       });
  413  
  414       it('Sh ould retur n an error  with an i nvalid icn  or pid',  function()  {
  415           va r reqClone  = _.clone Deep(req);
  416           re qClone.int erceptorRe sults.pati entIdentif iers.icn =  'bad';
  417           re qClone.int erceptorRe sults.pati entIdentif iers.siteD fn = 'bad' ;
  418           vi xSubsystem .getImages ForDocumen t(reqClone , function (error, re sponse) {
  419                expect(e rror).to.e ql('icn an d site;dfn  are not v alid');
  420                expect(r eqClone.lo gger.info. calledWith Match({err or: 'icn a nd site;df n are not  valid - re turning er ror'})).to .be.true() ;
  421           }) ;
  422       });
  423  
  424       it('Sh ould retur n an error  with an e mpty siteN umber', fu nction() {
  425           va r reqClone  = _.clone Deep(req);
  426           re qClone.que ry.siteNum ber = '';
  427           vi xSubsystem .getImages ForDocumen t(reqClone , function (error, re sponse) {
  428                expect(e rror).to.e ql('siteNu mber is nu llish');
  429                expect(r eqClone.lo gger.info. calledWith Match({err or: 'siteN umber is n ullish - r eturning e rror'})).t o.be.true( );
  430           }) ;
  431       });
  432  
  433       it('Sh ould retur n an error  with an e mpty conte xtId', fun ction() {
  434           va r reqClone  = _.clone Deep(req);
  435           re qClone.que ry.context Id = '';
  436           vi xSubsystem .getImages ForDocumen t(reqClone , function (error, re sponse) {
  437                expect(e rror).to.e ql('contex tId is nul lish');
  438                expect(r eqClone.lo gger.info. calledWith Match({err or: 'conte xtId is nu llish - re turning er ror'})).to .be.true() ;
  439           }) ;
  440       });
  441  
  442       it('Sh ould retur n an error  because t he VIX is  not config ured', fun ction() {
  443           si non.stub(v ixSubsyste m, '_getQu eryConfig' ).callsFak e(function (appConfig , logger,  query) {
  444                return n ull;
  445           }) ;
  446           vi xSubsystem .getImages ForDocumen t(req, fun ction(erro r, respons e) {
  447                expect(r eq.logger. debug.call edWithMatc h({error:  {error: 'v ix is not  configured '}})).to.t rue();
  448           }) ;
  449       });
  450  
  451       it('Sh ould retur n an error  if the VI X Body is  empty', fu nction() {
  452           si non.stub(v ixSubsyste m, '_getSt udyQuery') .callsFake (function( req, bseTo ken, query , callback ) {
  453                return c allback(nu ll, {studi es: []});
  454           }) ;
  455           vi xSubsystem .getImages ForDocumen t(req, fun ction(erro r, respons e) {
  456                expect(r eq.logger. debug.call edWithMatc h({error:  'Empty res ponse from  VIX'})).t o.true();
  457           }) ;
  458       });
  459  
  460       it('Sh ould retur n the stud ies in the n items ar ray and no t have a s tudies arr ay', funct ion() {
  461           si non.stub(h ttp, 'post ').callsFa ke(functio n(config,  callback)  {
  462                return c allback(nu ll, single VixRespons e);
  463           }) ;
  464           vi xSubsystem .getImages ForDocumen t(req, fun ction(erro r, respons e) {
  465                expect(r esponse.it ems).to.no t.be.empty ();
  466                expect(r esponse.st udies).to. eql(undefi ned);
  467           }) ;
  468       });
  469   });
  470  
  471   describe(' vix-subsys tem._water fallGetTok en', funct ion() {
  472       var re q;
  473       req =  {
  474           lo gger: logg er
  475       };
  476       it('Sh ould error  if checkB seToken re turns an R PC error',  function( ) {
  477           si non.stub(v ixSubsyste m, '_check BseToken') .callsFake (function( req, callb ack) {
  478                return c allback('S imulated R PC Error') ;
  479           }) ;
  480           vi xSubsystem ._waterfal lGetToken( req, funct ion(error,  response)  {
  481                expect(r eq.logger. debug.call edWith({er ror: 'Simu lated RPC  Error'}));
  482                expect(e rror).to.e ql('Simula ted RPC Er ror');
  483           }) ;
  484       });
  485  
  486       it('Sh ould retur n a token  after _sav eBseToken  tries to s ave it', f unction()  {
  487           si non.stub(v ixSubsyste m, '_check BseToken') .callsFake (function( req, callb ack) {
  488                return c allback(nu ll, 'token ');
  489           }) ;
  490           vi xSubsystem ._waterfal lGetToken( req, funct ion(error,  response)  {
  491                expect(r esponse).t o.eql('tok en');
  492           }) ;
  493       });
  494   });
  495  
  496   describe(' vix-subsys tem._getSt udyQuery',  function( ) {
  497       var re q, bseToke n, query;
  498       req =  {
  499           lo gger: logg er,
  500           ap p: {
  501                config:  {}
  502           },
  503           se ssion: {
  504                user: {}
  505           }
  506       };
  507       it('Sh ould retur n an error  if the co nfig is no t setup fo r the VIX' , function () {
  508           si non.stub(v ixSubsyste m, '_getQu eryConfig' ).callsFak e(function (appConfig , logger,  query) {
  509                return n ull;
  510           }) ;
  511           vi xSubsystem ._getStudy Query(req,  bseToken,  query, fu nction(err or, respon se) {
  512                expect(e rror).to.e ql({error:  'vix is n ot configu red'});
  513           }) ;
  514       });
  515  
  516       it('Sh ould retur n the erro r sent bac k from the  VIX', fun ction() {
  517           si non.stub(v ixSubsyste m, '_getQu eryConfig' ).callsFak e(function (appConfig , logger,  query) {
  518                return { };
  519           }) ;
  520           si non.stub(h ttp, 'post ').callsFa ke(functio n(config,  callback)  {
  521                return c allback('S imulated V IX error') ;
  522           }) ;
  523           vi xSubsystem ._getStudy Query(req,  bseToken,  query, fu nction(err or, respon se) {
  524                expect(e rror).to.e ql('Simula ted VIX er ror');
  525           }) ;
  526       });
  527  
  528       it('Sh ould retur n the body  of the VI X response ', functio n() {
  529           si non.stub(v ixSubsyste m, '_getQu eryConfig' ).callsFak e(function (appConfig , logger,  query) {
  530                return { };
  531           }) ;
  532           si non.stub(h ttp, 'post ').callsFa ke(functio n(config,  callback)  {
  533                return c allback(nu ll, {body:  'Simulate d VIX body '});
  534           }) ;
  535           vi xSubsystem ._getStudy Query(req,  bseToken,  query, fu nction(err or, respon se) {
  536                expect(r esponse).t o.eql('Sim ulated VIX  body');
  537           }) ;
  538       });
  539   });
  540  
  541   describe(' vix-subsys tem._getQu eryConfig' , function () {
  542       var ap pConfig, q uery;
  543       appCon fig = {};
  544       appCon fig.vix =  app.config .vix;
  545       query  = 'studyQu ery';
  546       it('Sh ould retur n null if  the subsys tem is not  initializ ed', funct ion() {
  547           vi xSubsystem ._vixServe rConfigure d = false;
  548           va r response  = vixSubs ystem._get QueryConfi g(appConfi g, logger,  query);
  549           ex pect(respo nse).to.eq l(null);
  550           vi xSubsystem ._vixServe rConfigure d = true;
  551       });
  552  
  553       it('Sh ould retur n a query  config Nod e http can  use to ta lk to the  VIX', func tion() {
  554           va r response  = vixSubs ystem._get QueryConfi g(appConfi g, logger,  query);
  555           ex pect(respo nse.baseUr l).to.eql( app.config .vix.baseU rl);
  556       });
  557   });
  558  
  559   describe(' vix-subsys tem._conve rtCategory ', functio n() {
  560       it('Sh ould make  an empty c ategory a  TIU', func tion() {
  561           va r response  = vixSubs ystem._con vertCatego ry('');
  562           ex pect(respo nse).to.eq l('TIU');
  563       });
  564  
  565       it('Sh ould keep  a RA categ ory the sa me', funct ion() {
  566           va r response  = vixSubs ystem._con vertCatego ry('RA');
  567           ex pect(respo nse).to.eq l('RA');
  568       });
  569  
  570       //TODO  expand to  cover all  categorie s covered  by TIU
  571       it('Sh ould make  a LR categ ory a TIU' , function () {
  572           va r response  = vixSubs ystem._con vertCatego ry('LR');
  573           ex pect(respo nse).to.eq l('TIU');
  574       });
  575   });
  576  
  577   describe(' vix-subsys tem._build ContextId' , function () {
  578       var re q, record;
  579       //req. intercepto rResults.p atientIden tifiers.df n;
  580       req =  {
  581           in terceptorR esults: {
  582                patientI dentifiers : {
  583                    dfn:  '3'
  584                }
  585           }
  586       };
  587       it('Sh ould creat e a proper  RA contex tId', func tion() {
  588           re cord = {
  589                hasImage s: true,
  590                category : 'RA',
  591                localId:  '6839398. 7969-1',
  592                case: '8 6',
  593                facility Name: 'CAM P MASTERS'
  594           };
  595           va r response  = vixSubs ystem._bui ldContextI d(req, rec ord);
  596           ex pect(respo nse).to.eq l('RPT^CPR S^3^RA^683 9398.7969- 1^86^CAMP  MASTERS^^^ ^^^1');
  597       });
  598  
  599       it('Sh ould creat e a proper  TIU conte xtId', fun ction() {
  600           re cord = {
  601                hasImage s: true,
  602                category : 'TIU',
  603                localId:  '12349',
  604                case: '8 6',
  605                facility Name: 'CAM P MASTERS'
  606           };
  607           va r response  = vixSubs ystem._bui ldContextI d(req, rec ord);
  608           ex pect(respo nse).to.eq l('RPT^CPR S^3^TIU^12 349^86^CAM P MASTERS^ ^^^^^1');
  609       });
  610  
  611       it('Sh ould creat e a proper  DOD conte xtId', fun ction() {
  612           re cord = {
  613                hasImage s: false,
  614                category : 'DOD',
  615                localId:  '10000006 48',
  616                case: '' ,
  617                facility Name: 'DOD '
  618           };
  619           va r response  = vixSubs ystem._bui ldContextI d(req, rec ord);
  620           ex pect(respo nse).to.eq l('RPT^CPR S^3^DOD^10 00000648^^ DOD^^^^^^0 ');
  621       });
  622   });
  623  
  624   describe(' vix-subsys tem._check BseToken',  function( ) {
  625       var re q;
  626       req =  {
  627           lo gger: logg er,
  628           se ssion: {
  629                user: {
  630                    vixB seToken: ' ~1XWBAS121 0-215869_2 ',
  631                    vixB seTokenExp ires: mome nt().add(2 2, 'hours' ).format(' X')
  632                }
  633           }
  634       };
  635       it('Sh ould retur n an error  if the se ssion obje ct is empt y or malfo rmed.', fu nction() {
  636           va r regenStu b = sinon. stub(vixSu bsystem, ' _regenerat eBseToken' ).callsFak e(function (req, call back) {
  637                return;
  638           }) ;
  639           va r badReq =  {
  640                logger:  logger
  641           };
  642           vi xSubsystem ._checkBse Token(badR eq, functi on(error,  response)  {
  643                expect(r eq.logger. error.call edWithMatc h({locatio n: 'vix-su bsystem._s aveBseToke n', error:  'User obj ect is emp ty'}));
  644                expect(r egenStub). to.be.call ed();
  645                expect(e rror).to.e ql('User o bject is e mpty');
  646           }) ;
  647       });
  648  
  649       it('Sh ould try t o regenera te the tok en if ther e is a pro blem with  the token  or token e xpiration  keys', fun ction() {
  650           va r regenStu b = sinon. stub(vixSu bsystem, ' _regenerat eBseToken' ).callsFak e(function (req, call back) {
  651                return;
  652           }) ;
  653           va r modReq =  _.cloneDe ep(req);
  654           mo dReq.sessi on.user.vi xBseToken  = null;
  655           vi xSubsystem ._checkBse Token(modR eq, functi on(error,  response)  {
  656                expect(m odReq.logg er.debug.c alledWith( {location:  'vix-subs ystem._che ckBseToken ', error:  'There is  a problem  with token  or token  expiration '})).to.tr ue();
  657                expect(r egenStub). to.be.call ed();
  658           }) ;
  659       });
  660  
  661       it('Sh ould try t o regenera te the tok en if the  token is e xpired', f unction()  {
  662           va r regenStu b = sinon. stub(vixSu bsystem, ' _regenerat eBseToken' ).callsFak e(function (req, call back) {
  663                return;
  664           }) ;
  665           va r modReq =  _.cloneDe ep(req);
  666           mo dReq.sessi on.user.vi xBseTokenE xpires = m oment().su btract(1,  'hours').f ormat('X') ;
  667           vi xSubsystem ._checkBse Token(modR eq, functi on(error,  response)  {
  668                expect(m odReq.logg er.debug.c alledWith( {location:  'vix-subs ystem._che ckBseToken ', error:  'BSE token  has expir ed'})).to. true();
  669                expect(r egenStub). to.be.call ed();
  670           }) ;
  671       });
  672  
  673       it('Sh ould retur n the toke n', functi on() {
  674           vi xSubsystem ._checkBse Token(req,  function( error, res ponse) {
  675                expect(r esponse).t o.eql('~1X WBAS1210-2 15869_2');
  676           }) ;
  677       });
  678   });
  679  
  680   describe(' vix-subsys tem._regen erateBseTo ken', func tion() {
  681       var re q;
  682       req =  {
  683           lo gger: logg er
  684       };
  685       it('Sh ould retur n an error  if there  is an erro r with the  RPC call' , function () {
  686           si non.stub(v ixSubsyste m, '_getBs eToken').c allsFake(f unction(re q, callbac k) {
  687                return c allback('e rror');
  688           }) ;
  689           vi xSubsystem ._regenera teBseToken (req, func tion(error , response ) {
  690                expect(e rror).to.e ql('error' );
  691           }) ;
  692       });
  693  
  694       it('Sh ould retur n the toke n', functi on() {
  695           si non.stub(v ixSubsyste m, '_getBs eToken').c allsFake(f unction(re q, callbac k) {
  696                return c allback(nu ll, 'token ');
  697           }) ;
  698           si non.stub(v ixSubsyste m, '_saveB seToken'). callsFake( function(r eq, token,  callback)  {
  699                return c allback(nu ll, 'token ');
  700           }) ;
  701           vi xSubsystem ._regenera teBseToken (req, func tion(error , response ) {
  702                expect(r esponse).t o.eql('tok en');
  703           }) ;
  704       });
  705   });
  706  
  707   describe(' vix-subsys tem._getBs eToken', f unction()  {
  708       var re q = {
  709           ap p: app,
  710           lo gger: logg er,
  711           se ssion: {
  712                user: {
  713                    acce ssCode: ap p.config.v istaSites[ '9E7A'].ac cessCode,
  714                    veri fyCode: ap p.config.v istaSites[ '9E7A'].ve rifyCode,
  715                    divi sion: '500 ',
  716                    site : '9E7A'
  717                }
  718           }
  719       };
  720       it('Sh ould retur n an error  if the si te is not  set', func tion() {
  721           va r badReq =  _.cloneDe ep(req);
  722           ba dReq.sessi on.user.si te = 'bad' ;
  723           vi xSubsystem ._getBseTo ken(badReq , function (error, re sponse) {
  724                expect(e rror).to.e ql({error:  'user sit e not conf igured'});
  725           }) ;
  726       });
  727  
  728       it('Sh ould retur n an error  if the RP C returns  an error',  function( ) {
  729           si non.stub(R pcClient,  'callRpc') .callsFake (function( logger, co nfig, rpcN ame, param eters, cal lback) {
  730                return c allback('r pcError');
  731           }) ;
  732           vi xSubsystem ._getBseTo ken(req, f unction(er ror, respo nse) {
  733                expect(e rror).to.e ql('rpcErr or');
  734           }) ;
  735       });
  736  
  737       it('Sh ould retur n the toke n', functi on() {
  738           si non.stub(R pcClient,  'callRpc') .callsFake (function( logger, co nfig, rpcN ame, param eters, cal lback) {
  739                return c allback(nu ll, 'rpcDa ta');
  740           }) ;
  741           vi xSubsystem ._getBseTo ken(req, f unction(er ror, respo nse) {
  742                expect(r esponse).t o.eql('rpc Data');
  743           }) ;
  744       });
  745   });
  746  
  747   describe(' vix-subsys tem._saveB seToken',  function()  {
  748       var re q, token;
  749       req =  {
  750           lo gger: logg er,
  751           se ssion: {
  752                user: {
  753                    uid:  'urn:va:u ser:9E7A:1 0000000270 '
  754                }
  755           }
  756       };
  757       token  = '~1XWBAS 1210-21586 9_2';
  758  
  759       it('Sh ould retur n an error  if the to ken is nul l', functi on() {
  760           vi xSubsystem ._saveBseT oken(req,  '', functi on(error,  response)  {
  761                expect(e rror).to.e ql('Token  not provid ed from Vi stA');
  762           }) ;
  763       });
  764  
  765       it('Sh ould log a n error bu t return t he token i f the uid  is not set ', functio n() {
  766           va r badReq =  {
  767                logger:  logger
  768           };
  769           vi xSubsystem ._saveBseT oken(badRe q, token,  function(e rror, resp onse) {
  770                expect(e rror).to.e ql('User o bject is e mpty');
  771                expect(r eq.logger. error.call edWith({lo cation: 'v ix-subsyst em._saveBs eToken', e rror: 'Use r object i s empty'}) );
  772           }) ;
  773       });
  774  
  775       it('Sh ould retur n the toke n', functi on() {
  776           vi xSubsystem ._saveBseT oken(req,  token, fun ction(erro r, respons e) {
  777                expect(r esponse).t o.eql('~1X WBAS1210-2 15869_2');
  778           }) ;
  779       });
  780   });