909. EPMO Open Source Coordination Office Redaction File Detail Report

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

909.1 Files compared

# Location File Last Modified
1 ehmp.zip\ehmp\ehmp\product\production\vx-sync\tests\unittests\utils ptdemographics-utils-spec.js Tue Jan 10 16:20:50 2017 UTC
2 ehmp.zip\ehmp\ehmp\product\production\vx-sync\tests\unittests\utils ptdemographics-utils-spec.js Tue Oct 3 13:33:56 2017 UTC

909.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 7 4636
Changed 6 40
Inserted 0 0
Removed 0 0

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

909.4 Active regular expressions

No regular expressions were active.

909.5 Comparison detail

  1   'use stric t';
  2  
  3   //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
  4   // This fi le contain s unit tes ts for ptd emographic s-utils.js .
  5   //
  6   // Author:  Les Westb erg
  7   //-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
  8  
  9   require('. ./../../en v-setup');
  10   var _ = re quire('und erscore');
  11  
  12   var PtDemo graphicsUt il = requi re(global. VX_UTILS +  '/ptdemog raphics-ut ils');
  13   var metast ampUtil =  require(gl obal.VX_UT ILS + 'met astamp-uti ls');
  14   var JdsCli entDummy =  require(g lobal.VX_D UMMIES + ' jds-client -dummy');
  15   var log =  require(gl obal.VX_DU MMIES + 'd ummy-logge r');
  16   //-------- ---------- ---------- ---------- ---------- ---------- ----
  17   // Uncomme nt the fol lowing to  see the lo gging out  on the scr een.
  18   //-------- ---------- ---------- ---------- ---------- ---------- ----
  19   // var log Util = req uire(globa l.VX_UTILS  + 'log');
  20   // logUtil .initializ e([{
  21   //     nam e: 'root',
  22   //     str eam: proce ss.stdout,
  23   //     lev el: 'debug '
  24   // }]);
  25   // log = l ogUtil.get ('test', ' debug');
  26   //-------- ---------- ---------- ---------- ----
  27   // End of  logging st uff to com ment out.. ..
  28   //-------- ---------- ---------- ---------- ----
  29   // log = r equire('bu nyan').cre ateLogger( {
  30   //      na me: 'vista -record-po ller-spec' ,
  31   //      le vel: 'debu g'
  32   // });
  33  
  34   var hmpSer ver = 'The HmpServer' ;
  35  
  36  
  37   var config  = {
  38           jd s: {
  39                    prot ocol: 'htt p',
  40                     host: ' IP          ',
  41                     port:  PORT
  42           },
  43           'v istaSites' : {
  44                    '9E7 A': {
  45                             'name' : 'panoram a',
  46                              'host': ' IP          ',
  47                              'port':  PORT ,
  48                              'accessCod e': ' REDACT ',
  49                              'verifyCod e': ' REDACTED ',
  50                             'local IP': '127. 0.0.1',
  51                             'local Address':  'localhost ',
  52                             'conne ctTimeout' : 3000,
  53                             'sendT imeout': 1 0000
  54                    },
  55                    'C87 7': {
  56                             'name' : 'kodak',
  57                              'host': ' IP          ',
  58                              'port':  PORT ,
  59                              'accessCod e': ' REDACT ',
  60                              'verifyCod e': ' REDACTED ',
  61                             'local IP': '127. 0.0.1',
  62                             'local Address':  'localhost ',
  63                             'conne ctTimeout' : 3000,
  64                             'sendT imeout': 1 0000
  65                    }
  66           },
  67           'h mp.server. id': hmpSe rver,
  68           'h mp.version ': '0.7-S6 5',
  69           'h mp.batch.s ize': '100 0',
  70           'h mp.extract .schema':  '3.001',
  71           'h dr': {
  72                    'ope rationMode ': 'REQ/RE S'
  73           }
  74   };
  75  
  76   var vistaH drConfig =  {
  77           jd s: {
  78                    prot ocol: 'htt p',
  79                     host: ' IP          ',
  80                     port:  PORT
  81           },
  82           'v istaSites' : {
  83                    '9E7 A': {
  84                             'name' : 'panoram a',
  85                              'host': ' IP          ',
  86                              'port':  PORT ,
  87                              'accessCod e': ' REDACT ',
  88                              'verifyCod e': ' REDACTED ',
  89                             'local IP': '127. 0.0.1',
  90                             'local Address':  'localhost ',
  91                             'conne ctTimeout' : 3000,
  92                             'sendT imeout': 1 0000
  93                    },
  94                    'C87 7': {
  95                             'name' : 'kodak',
  96                              'host': ' IP          ',
  97                              'port':  PORT ,
  98                              'accessCod e': ' REDACT ',
  99                              'verifyCod e': ' REDACTED ',
  100                             'local IP': '127. 0.0.1',
  101                             'local Address':  'localhost ',
  102                             'conne ctTimeout' : 3000,
  103                             'sendT imeout': 1 0000
  104                    }
  105           },
  106           'h mp.server. id': hmpSe rver,
  107           'h mp.version ': '0.7-S6 5',
  108           'h mp.batch.s ize': '100 0',
  109           'h mp.extract .schema':  '3.001',
  110       'hdr':  {
  111           'o perationMo de' : 'PUB /SUB',
  112           'h drSites' :  {
  113                '3A8B':  {
  114                    'sta tionNumber ': 42
  115                },
  116                'CF2A':  {
  117                    'sta tionNumber ': 101
  118                },
  119                '72A0':  {
  120                    'sta tionNumber ': 13
  121                },
  122                '8211':  {
  123                    'sta tionNumber ': 1337
  124                },
  125                '84F0':  {
  126                    'sta tionNumber ': 578
  127                }
  128           }
  129       }
  130   };
  131  
  132   var demogr aphicsFrom Vista = {
  133           'p id': '9E7A ;3',
  134           'b irthDate':  '19350407 ',
  135           'l ast4': '00 08',
  136           'l ast5': 'E0 008',
  137           'i cn': '1010 8V420871',
  138           'f amilyName' : 'EIGHT',
  139           'g ivenNames' : 'PATIENT ',
  140           'f ullName':  'EIGHT,PAT IENT',
  141           'd isplayName ': 'Eight, Patient',
  142           'g enderCode' : 'urn:va: pat-gender :M',
  143           'g enderName' : 'Male',
  144           's ensitive':  false,
  145           'u id': 'urn: va:patient :9E7A:3:3' ,
  146           's ummary': ' Eight,Pati ent',
  147           's sn': '6660 00008',
  148           'l ocalId': ' 3'
  149   };
  150  
  151   var pidDod  = 'DOD;11 1';
  152   var uidDod  = 'urn:va :patient:D OD:111:111 ';
  153   var demogr aphicsDod  = _.clone( demographi csFromVist a);
  154   demographi csDod.pid  = pidDod;
  155   demographi csDod.uid  = uidDod;
  156  
  157   var pidHdr Secondary  = 'HDR;123 ';
  158   var uidHdr Secondary  = 'urn:va: patient:HD R:123:123' ;
  159   var demogr aphicsHdrS econdary =  _.clone(d emographic sFromVista );
  160   demographi csHdrSecon dary.pid =  pidHdrSec ondary;
  161   demographi csHdrSecon dary.uid =  uidHdrSec ondary;
  162  
  163   var pidVis taHdr = '8 211;456';
  164   var uidVis taHdr = 'u rn:va:pati ent:8211:4 56:456';
  165   var demogr aphicsVist aHdr = _.c lone(demog raphicsFro mVista);
  166   demographi csVistaHdr .pid = pid VistaHdr;
  167   demographi csVistaHdr .uid = uid VistaHdr;
  168  
  169   //-------- ---------- ---------- ---------- ---------- ---------- ---------- -
  170   // Create  an instanc e of the e nvironment  variable.
  171   //-------- ---------- ---------- ---------- ---------- ---------- ---------- -
  172   function c reateEnvir onment(vis taClient,  the_config ) {
  173           va r environm ent = {
  174                    jds:  new JdsCl ientDummy( log, the_c onfig),
  175                    vist aClient: { }
  176           };
  177  
  178           if  (vistaCli ent) {
  179                    envi ronment.vi staClient  = vistaCli ent;
  180           }
  181  
  182           sp yOn(enviro nment.jds,  'getOpera tionalData PtSelectBy Icn').andC allThrough ();
  183           sp yOn(enviro nment.jds,  'getOpera tionalData PtSelectBy Pid').andC allThrough ();
  184           sp yOn(enviro nment.jds,  'storePat ientData') .andCallTh rough();
  185       spyOn( environmen t.jds, 'sa veSyncStat us').andCa llThrough( );
  186           sp yOn(enviro nment.jds,  'getPtDem ographicsB yPid').and CallThroug h();
  187  
  188           re turn envir onment;
  189   }
  190  
  191   describe(' ptdemograp hics-utils .js', func tion() {
  192           de scribe('cr eatePtDemo graphics() ', functio n() {
  193                    it(' Happy Path  with pid' , function () {
  194                             var fi nished = f alse;
  195                             var vi staClient  = {
  196                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  197                                               return cal lback(null , demograp hicsFromVi sta);
  198                                      }
  199                             };
  200                             var en vironment  = createEn vironment( vistaClien t, config) ;
  201                             var ex pectedJdsE rror = [nu ll, null,  null];
  202                             var ex pectedJdsR esponse =  [{
  203                                      statusCo de: 404
  204                             }, {
  205                    stat usCode: 20 0
  206                }, {
  207                                      statusCo de: 201
  208                             }];
  209                             var ex pectedJdsR esult = [n ull, null,  null];
  210                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  211  
  212                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  213                             var or iginalSync Job = {
  214                                      patientI dentifier:  {
  215                                               type: 'pid ',
  216                                               value: '9E 7A;3'
  217                                      }
  218                             };
  219                             var sy ncJobsToPu blish = [] ;
  220                             runs(f unction()  {
  221                                      ptDemogr aphicsUtil .createPtD emographic s(original SyncJob, s yncJobsToP ublish, fu nction(err or, respon se) {
  222                                               expect(err or).toBeFa lsy();
  223                                               expect(res ponse).toE qual(syncJ obsToPubli sh);
  224                                               finished =  true;
  225                                      });
  226                             });
  227  
  228                             waitsF or(functio n() {
  229                                      return f inished;
  230                             });
  231                    });
  232                    it(' Happy Path  with icn' , function () {
  233                             var fi nished = f alse;
  234                             var vi staClient  = {
  235                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  236                                               return cal lback(null , demograp hicsFromVi sta);
  237                                      }
  238                             };
  239                             var en vironment  = createEn vironment( vistaClien t, config) ;
  240                             var ex pectedJdsE rror = [nu ll, null,  null, null ];
  241                             var ex pectedJdsR esponse =  [{
  242                                      statusCo de: 200
  243                             }, {
  244                                      statusCo de: 404
  245                             }, {
  246                    stat usCode: 20 0
  247                }, {
  248                                      statusCo de: 201
  249                             }];
  250                             var ex pectedJdsR esult = [{
  251                                      data: {
  252                                               items: [{
  253                                                       pi d: '9E7A;3 '
  254                                               }]
  255                                      }
  256                             },
  257                             null,  null, null ];
  258                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  259                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  260                             var ic n = '100';
  261                             var or iginalSync Job = {
  262                                      patientI dentifier:  {
  263                                               type: 'icn ',
  264                                               value: icn
  265                                      }
  266                             };
  267                             var sy ncJobsToPu blish = [] ;
  268                             runs(f unction()  {
  269                                      ptDemogr aphicsUtil .createPtD emographic s(original SyncJob, s yncJobsToP ublish, fu nction(err or, respon se) {
  270                                               expect(err or).toBeFa lsy();
  271                                               expect(res ponse).toE qual(syncJ obsToPubli sh);
  272                                               finished =  true;
  273                                      });
  274                             });
  275  
  276                             waitsF or(functio n() {
  277                                      return f inished;
  278                             });
  279                    });
  280                    it(' Happy Path  with icn  plus demog raphics',  function()  {
  281                             // log .debug('** ********** ********** *****  sta rt of test  ********* ********** ********** *****');
  282                             var fi nished = f alse;
  283                             var vi staClient  = {
  284                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  285                                               return cal lback(null , demograp hicsFromVi sta);
  286                                      }
  287                             };
  288                             var en vironment  = createEn vironment( vistaClien t, config) ;
  289                             var ex pectedJdsE rror = [nu ll];
  290                             var ex pectedJdsR esponse =  [{
  291                                      statusCo de: 200
  292                             }];
  293                             var ex pectedJdsR esult = [{
  294                                               'data' : {
  295                                                       it ems: [demo graphicsFr omVista]}
  296                                      }];
  297                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  298                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  299                             var ic n = '100';
  300                             var or iginalSync Job = {
  301                                      patientI dentifier:  {
  302                                               type: 'icn ',
  303                                               value: icn
  304                                      },
  305                                      demograp hics : dem ographicsF romVista
  306                             };
  307                             var sy ncJobsToPu blish = [{  type: 'jm eadows-syn c-request' ,
  308                    pati entIdentif ier: { typ e: 'pid',  value: 'DO D;1234567'  },
  309                    jpid : '21EC202 0-3AEA-406 9-A2DD-CCC CCCCCCCCC' ,
  310                    root JobId: '5' ,
  311                    jobI d: '0f2579 95-777f-4b b0-91f0-1e 3f86792a38 ' }];
  312  
  313                             runs(f unction()  {
  314                                      ptDemogr aphicsUtil .createPtD emographic s(original SyncJob, s yncJobsToP ublish, fu nction(err or, respon se) {
  315                                               expect(err or).toBeFa lsy();
  316                                               expect(res ponse).toE qual(syncJ obsToPubli sh);
  317                                               finished =  true;
  318                                      });
  319                             });
  320  
  321                             waitsF or(functio n() {
  322                                      return f inished;
  323                             });
  324  
  325                             // run s(function  () {
  326                             //       log.debu g('******* ********** **********   end of t est ****** ********** ********** ********') ;
  327                             // });
  328                    });
  329                    it(' Happy Path  with DOD; 1234567 pl us demogra phics', fu nction() {
  330                             log.de bug('***** ********** ********** **  start  of test ** ********** ********** ********** **');
  331                             var fi nished = f alse;
  332                             var vi staClient  = {
  333                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  334                                               return cal lback(null , demograp hicsFromVi sta);
  335                                      }
  336                             };
  337                             var en vironment  = createEn vironment( vistaClien t, config) ;
  338                             var ex pectedJdsE rror = [nu ll];
  339                             var ex pectedJdsR esponse =  [{
  340                                      statusCo de: 200
  341                             }];
  342                             var ex pectedJdsR esult = [{
  343                                      'data' :  {
  344                                               items: [de mographics FromVista]
  345                         }
  346                    }];
  347                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  348                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  349                             var ic n = '100';
  350                             var or iginalSync Job = {
  351                                      patientI dentifier:  {
  352                                               type: 'pid ',
  353                                               value: 'DO D;1234567'
  354                                      },
  355                                      demograp hics : dem ographicsF romVista
  356                             };
  357                             var sy ncJobsToPu blish = [{  type: 'jm eadows-syn c-request' ,
  358                    pati entIdentif ier: { typ e: 'pid',  value: 'DO D;1234567'  },
  359                    jpid : '21EC202 0-3AEA-406 9-A2DD-CCC CCCCCCCCC' ,
  360                    root JobId: '5' ,
  361                    jobI d: '0f2579 95-777f-4b b0-91f0-1e 3f86792a38 ' }];
  362  
  363                             runs(f unction()  {
  364                                      ptDemogr aphicsUtil .createPtD emographic s(original SyncJob, s yncJobsToP ublish, fu nction(err or, respon se) {
  365                                               expect(err or).toBeFa lsy();
  366                                               expect(res ponse).toE qual(syncJ obsToPubli sh);
  367                                               finished =  true;
  368                                      });
  369                             });
  370  
  371                             waitsF or(functio n() {
  372                                      return f inished;
  373                             });
  374  
  375                             runs(f unction ()  {
  376                                      log.debu g('******* ********** **********   end of t est ****** ********** ********** ********') ;
  377                             });
  378                    });
  379                    it(' No origina lSyncJob',  function( ) {
  380                             var fi nished = f alse;
  381                             var en vironment  = createEn vironment( null, conf ig);
  382                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  383                             var sy ncJobsToPu blish = {} ;
  384                             runs(f unction()  {
  385                                      ptDemogr aphicsUtil .createPtD emographic s(null, sy ncJobsToPu blish, fun ction(erro r, respons e) {
  386                                               expect(err or).toBeTr uthy();
  387                                               expect(res ponse).toB e(syncJobs ToPublish) ;
  388                                               finished =  true;
  389                                      });
  390                             });
  391  
  392                             waitsF or(functio n() {
  393                                      return f inished;
  394                             });
  395                    });
  396                    it(' No patient Identifier ', functio n() {
  397                             var fi nished = f alse;
  398                             var en vironment  = createEn vironment( null, conf ig);
  399                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  400                             var or iginalSync Job = {};
  401                             var sy ncJobsToPu blish = {} ;
  402                             runs(f unction()  {
  403                                      ptDemogr aphicsUtil .createPtD emographic s(original SyncJob, s yncJobsToP ublish, fu nction(err or, respon se) {
  404                                               expect(err or).toBeTr uthy();
  405                                               expect(res ponse).toB e(syncJobs ToPublish) ;
  406                                               finished =  true;
  407                                      });
  408                             });
  409  
  410                             waitsF or(functio n() {
  411                                      return f inished;
  412                             });
  413                    });
  414                    it(' patientIde ntifier no t icn or p id.', func tion() {
  415                             var fi nished = f alse;
  416                             var en vironment  = createEn vironment( null, conf ig);
  417                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  418                             var or iginalSync Job = {
  419                                      patientI dentifier:  {
  420                                               type: 'edi pi',
  421                                               value: '11 11'
  422                                      }
  423                             };
  424                             var sy ncJobsToPu blish = {} ;
  425                             runs(f unction()  {
  426                                      ptDemogr aphicsUtil .createPtD emographic s(original SyncJob, s yncJobsToP ublish, fu nction(err or, respon se) {
  427                                               expect(err or).toBeTr uthy();
  428                                               expect(res ponse).toB e(syncJobs ToPublish) ;
  429                                               finished =  true;
  430                                      });
  431                             });
  432  
  433                             waitsF or(functio n() {
  434                                      return f inished;
  435                             });
  436                    });
  437                    it(' patientIde ntifier wi th pid but  not a pri mary site. ', functio n() {
  438                             var fi nished = f alse;
  439                             var en vironment  = createEn vironment( null, conf ig);
  440                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  441                             var or iginalSync Job = {
  442                                      patientI dentifier:  {
  443                                               type: 'pid ',
  444                                               value: '4E 44;100'
  445                                      }
  446                             };
  447                             var sy ncJobsToPu blish = {} ;
  448                             runs(f unction()  {
  449                                      ptDemogr aphicsUtil .createPtD emographic s(original SyncJob, s yncJobsToP ublish, fu nction(err or, respon se) {
  450                                               expect(err or).toBeTr uthy();
  451                                               expect(res ponse).toB e(syncJobs ToPublish) ;
  452                                               finished =  true;
  453                                      });
  454                             });
  455  
  456                             waitsF or(functio n() {
  457                                      return f inished;
  458                             });
  459                    });
  460  
  461           }) ;
  462           de scribe('re trievePrim aryPidFrom SyncJobs() ', functio n() {
  463                    it(' Happy Path ', functio n() {
  464                             var fi nished = f alse;
  465                             var en vironment  = createEn vironment( null, conf ig);
  466                             var ex pectedJdsE rror = nul l;
  467                             var ex pectedJdsR esponse =  {
  468                                      statusCo de: 200
  469                             };
  470                             var ex pectedJdsR esult = {
  471                                      data: {
  472                                               items: [{
  473                                                       pi d: '9E7A;3 '
  474                                               }]
  475                                      }
  476                             };
  477                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  478                             var ic n = '100';
  479                var sync JobsToPubl ish = [ {  type: 'vis ta-9E7A-su bscribe-re quest',
  480                    pati entIdentif ier: { typ e: 'pid',  value: '9E 7A;3' },
  481                    jpid : '21EC202 0-3AEA-406 9-A2DD-CCC CCCCCCCCC' ,
  482                    root JobId: '5' ,
  483                    jobI d: '8d3805 3f-cfae-44 c0-8d02-d4 50b118a31a ' },
  484                  { type : 'vista-C 877-subscr ibe-reques t',
  485                    pati entIdentif ier: { typ e: 'pid',  value: 'C8 77;12' },
  486                    jpid : '21EC202 0-3AEA-406 9-A2DD-CCC CCCCCCCCC' ,
  487                    root JobId: '5' ,
  488                    jobI d: '48d652 7b-75b1-4d f8-9dd1-5f 70a5e3a6bc ' },
  489                  { type : 'jmeadow s-sync-req uest',
  490                    pati entIdentif ier: { typ e: 'pid',  value: 'DO D;1234567'  },
  491                    jpid : '21EC202 0-3AEA-406 9-A2DD-CCC CCCCCCCCC' ,
  492                    root JobId: '5' ,
  493                    jobI d: '0f2579 95-777f-4b b0-91f0-1e 3f86792a38 ' },
  494                  { type : 'hdr-syn c-request' ,
  495                    pati entIdentif ier: { typ e: 'pid',  value: 'HD R;111111'  },
  496                    jpid : '21EC202 0-3AEA-406 9-A2DD-CCC CCCCCCCCC' ,
  497                    root JobId: '5' ,
  498                    jobI d: '7f534d a6-be97-4a 05-a270-22 ca710f3c82 ' },
  499                  { type : 'vler-sy nc-request ',
  500                    pati entIdentif ier: { typ e: 'pid',  value: 'VL ER;222222'  },
  501                    jpid : '21EC202 0-3AEA-406 9-A2DD-CCC CCCCCCCCC' ,
  502                    root JobId: '5' ,
  503                    jobI d: '80806d a9-363d-4a 82-aefb-29 96a5a2e212 ' } ];
  504  
  505                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  506                runs(fun ction() {
  507                    ptDe mographics Util.retri evePrimary PidFromSyn cJobs(sync JobsToPubl ish, funct ion(error,  response)  {
  508                                               expect(err or).toBeFa lsy();
  509                                               expect(res ponse).toE qual('9E7A ;3');
  510                                               finished =  true;
  511                                      });
  512                             });
  513  
  514                             waitsF or(functio n() {
  515                                      return f inished;
  516                             });
  517                    });
  518                    it(' No result  returned',  function( ) {
  519                             var fi nished = f alse;
  520                             var en vironment  = createEn vironment( null, conf ig);
  521                             var ex pectedJdsE rror = nul l;
  522                             var ex pectedJdsR esponse =  {
  523                                      statusCo de: 200
  524                             };
  525                             var ex pectedJdsR esult = nu ll;
  526                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  527                var sync JobsToPubl ish = {};
  528  
  529                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  530                runs(fun ction() {
  531                    ptDe mographics Util.retri evePrimary PidFromSyn cJobs(sync JobsToPubl ish, funct ion(error,  response)  {
  532                                               expect(err or).toBeFa lsy();
  533                                               expect(res ponse).toB eNull();
  534                                               finished =  true;
  535                                      });
  536                             });
  537  
  538                             waitsF or(functio n() {
  539                                      return f inished;
  540                             });
  541                    });
  542                    it(' No result. data retur ned', func tion() {
  543                             var fi nished = f alse;
  544                             var en vironment  = createEn vironment( null, conf ig);
  545                             var ex pectedJdsE rror = nul l;
  546                             var ex pectedJdsR esponse =  {
  547                                      statusCo de: 200
  548                             };
  549                             var ex pectedJdsR esult = {} ;
  550                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  551                var sync JobsToPubl ish = {};
  552  
  553                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  554                runs(fun ction() {
  555                    ptDe mographics Util.retri evePrimary PidFromSyn cJobs(sync JobsToPubl ish, funct ion(error,  response)  {
  556                                               expect(err or).toBeFa lsy();
  557                                               expect(res ponse).toB eNull();
  558                                               finished =  true;
  559                                      });
  560                             });
  561  
  562                             waitsF or(functio n() {
  563                                      return f inished;
  564                             });
  565                    });
  566                    it(' No result. data.items  returned' , function () {
  567                             var fi nished = f alse;
  568                             var en vironment  = createEn vironment( null, conf ig);
  569                             var ex pectedJdsE rror = nul l;
  570                             var ex pectedJdsR esponse =  {
  571                                      statusCo de: 200
  572                             };
  573                             var ex pectedJdsR esult = {
  574                                      data: {}
  575                             };
  576                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  577                var sync JobsToPubl ish = {};
  578  
  579                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  580                runs(fun ction() {
  581                    ptDe mographics Util.retri evePrimary PidFromSyn cJobs(sync JobsToPubl ish, funct ion(error,  response)  {
  582                                               expect(err or).toBeFa lsy();
  583                                               expect(res ponse).toB eNull();
  584                                               finished =  true;
  585                                      });
  586                             });
  587  
  588                             waitsF or(functio n() {
  589                                      return f inished;
  590                             });
  591                    });
  592                    it(' No result. data.items [0] return ed', funct ion() {
  593                             var fi nished = f alse;
  594                             var en vironment  = createEn vironment( null, conf ig);
  595                             var ex pectedJdsE rror = nul l;
  596                             var ex pectedJdsR esponse =  {
  597                                      statusCo de: 200
  598                             };
  599                             var ex pectedJdsR esult = {
  600                                      data: {
  601                                               items: []
  602                                      }
  603                             };
  604                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  605                var sync JobsToPubl ish = {};
  606  
  607                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  608                             runs(f unction()  {
  609                                      ptDemogr aphicsUtil .retrieveP rimaryPidF romSyncJob s(syncJobs ToPublish,  function( error, res ponse) {
  610                                               expect(err or).toBeFa lsy();
  611                                               expect(res ponse).toB eNull();
  612                                               finished =  true;
  613                                      });
  614                             });
  615  
  616                             waitsF or(functio n() {
  617                                      return f inished;
  618                             });
  619                    });
  620           }) ;
  621           de scribe('re trieveDemo graphicsFr omVistAand StoreInJds ()', funct ion() {
  622                    it(' Happy Path ', functio n() {
  623                             var fi nished = f alse;
  624                             var vi staClient  = {
  625                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  626                                               return cal lback(null , demograp hicsFromVi sta);
  627                                      }
  628                             };
  629                             var en vironment  = createEn vironment( vistaClien t, config) ;
  630                             var ex pectedJdsE rror = [nu ll, null];
  631                             var ex pectedJdsR esponse =  [{
  632                    stat usCode: 20 0
  633                }, {
  634                                      statusCo de: 201
  635                             }];
  636                             var ex pectedJdsR esult = [n ull, null] ;
  637                var reco rd = {
  638                    'dat a': {
  639                         'items': [ demographi csFromVist a]
  640                    }
  641                };
  642                var meta stamp = me tastampUti l.metastam pDomain(re cord, demo graphicsFr omVista.st ampTime,'' );
  643  
  644                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  645  
  646                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  647                             runs(f unction()  {
  648                                      ptDemogr aphicsUtil .retrieveD emographic sFromVistA andStoreIn Jds(demogr aphicsFrom Vista.pid,  function( error, ptD emographic s) {
  649                                               expect(err or).toBeFa lsy();
  650                                               expect(ptD emographic s).toBeTru thy();
  651                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsFr omVista));  // toEqua l because  we should  get our or iginal ite m plus an  additional  attribute .
  652                                               expect(ptD emographic s.stampTim e).toBeTru thy();
  653                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  654                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csFromVist a.pid}), j asmine.any (Function) );
  655                             expect (environme nt.jds.sto rePatientD ata.calls. length).to Equal(1);
  656                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsF romVista),  jasmine.a ny(Functio n));
  657                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  658                             stampT ime: jasmi ne.any(Str ing)
  659                         }), jasmin e.any(Func tion));
  660                                               finished =  true;
  661                                      });
  662                             });
  663  
  664                             waitsF or(functio n() {
  665                                      return f inished;
  666                             });
  667                    });
  668                    it(' Pid was nu ll', funct ion() {
  669                             var fi nished = f alse;
  670                             var vi staClient  = {
  671                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  672                                               return cal lback(null , demograp hicsFromVi sta);
  673                                      }
  674                             };
  675                             var en vironment  = createEn vironment( vistaClien t, config) ;
  676                             var ex pectedJdsE rror = nul l;
  677                             var ex pectedJdsR esponse =  {
  678                                      statusCo de: 200
  679                             };
  680                             var ex pectedJdsR esult = nu ll;
  681                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  682  
  683                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  684                             runs(f unction()  {
  685                                      ptDemogr aphicsUtil .retrieveD emographic sFromVistA andStoreIn Jds(null,  function(e rror, ptDe mographics ) {
  686                                               expect(err or).toEqua l('FailedN oPid');
  687                                               expect(ptD emographic s).toBeNul l();
  688                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  689                                               finished =  true;
  690                                      });
  691                             });
  692  
  693                             waitsF or(functio n() {
  694                                      return f inished;
  695                             });
  696                    });
  697                    it(' Pid was in valid', fu nction() {
  698                             var fi nished = f alse;
  699                             var vi staClient  = {
  700                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  701                                               return cal lback(null , demograp hicsFromVi sta);
  702                                      }
  703                             };
  704                             var en vironment  = createEn vironment( vistaClien t, config) ;
  705                             var ex pectedJdsE rror = nul l;
  706                             var ex pectedJdsR esponse =  {
  707                                      statusCo de: 200
  708                             };
  709                             var ex pectedJdsR esult = nu ll;
  710                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  711  
  712                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  713                             runs(f unction()  {
  714                                      ptDemogr aphicsUtil .retrieveD emographic sFromVistA andStoreIn Jds('9E7A' , function (error, pt Demographi cs) {
  715                                               expect(err or).toEqua l('FailedP idInvalid' );
  716                                               expect(ptD emographic s).toBeNul l();
  717                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  718                                               finished =  true;
  719                                      });
  720                             });
  721  
  722                             waitsF or(functio n() {
  723                                      return f inished;
  724                             });
  725                    });
  726                    it(' VistA RPC  call retur ned error' , function () {
  727                             var fi nished = f alse;
  728                             var vi staClient  = {
  729                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  730                                               return cal lback('Err orFromVist a', null);
  731                                      }
  732                             };
  733                             var en vironment  = createEn vironment( vistaClien t, config) ;
  734                             var ex pectedJdsE rror = nul l;
  735                             var ex pectedJdsR esponse =  {
  736                                      statusCo de: 200
  737                             };
  738                             var ex pectedJdsR esult = nu ll;
  739                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  740  
  741                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  742                             runs(f unction()  {
  743                                      ptDemogr aphicsUtil .retrieveD emographic sFromVistA andStoreIn Jds(demogr aphicsFrom Vista.pid,  function( error, ptD emographic s) {
  744                                               expect(err or).toEqua l('ErrorFr omVista');
  745                                               expect(ptD emographic s).toBeNul l();
  746                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  747                                               finished =  true;
  748                                      });
  749                             });
  750  
  751                             waitsF or(functio n() {
  752                                      return f inished;
  753                             });
  754                    });
  755                    it(' VistA RPC  call retur ned no err or and no  demographi cs', funct ion() {
  756                             var fi nished = f alse;
  757                             var vi staClient  = {
  758                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  759                                               return cal lback(null , null);
  760                                      }
  761                             };
  762                             var en vironment  = createEn vironment( vistaClien t, config) ;
  763                             var ex pectedJdsE rror = nul l;
  764                             var ex pectedJdsR esponse =  {
  765                                      statusCo de: 200
  766                             };
  767                             var ex pectedJdsR esult = nu ll;
  768                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  769  
  770                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  771                             runs(f unction()  {
  772                                      ptDemogr aphicsUtil .retrieveD emographic sFromVistA andStoreIn Jds(demogr aphicsFrom Vista.pid,  function( error, ptD emographic s) {
  773                                               expect(err or).toBeNu ll();
  774                                               expect(ptD emographic s).toBeNul l();
  775                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  776                                               finished =  true;
  777                                      });
  778                             });
  779  
  780                             waitsF or(functio n() {
  781                                      return f inished;
  782                             });
  783                    });
  784  
  785           it ('Error wh en creatin g metastam p for pati ent demogr aphics', f unction()  {
  786                var fini shed = fal se;
  787  
  788                var demo graphicsFr omVistaWit hBadTimeSt amp = _.cl one(demogr aphicsFrom Vista);
  789                demograp hicsFromVi staWithBad TimeStamp. stampTime  = 20151230 1451;
  790  
  791                var vist aClient =  {
  792                    getD emographic s: functio n(vistaId,  dfn, call back) {
  793                         return cal lback(null , demograp hicsFromVi staWithBad TimeStamp) ;
  794                    }
  795                };
  796                var envi ronment =  createEnvi ronment(vi staClient,  config);
  797                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  798                runs(fun ction() {
  799                    ptDe mographics Util.retri eveDemogra phicsFromV istAandSto reInJds(de mographics FromVistaW ithBadTime Stamp.pid,  function( error, ptD emographic s) {
  800                         expect(err or).toEqua l('FailedM etastampEr ror');
  801                         expect(ptD emographic s).toBeNul l();
  802                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 0);
  803                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  804                         finished =  true;
  805                    });
  806                });
  807  
  808                waitsFor (function( ) {
  809                    retu rn finishe d;
  810                });
  811           }) ;
  812  
  813           it ('JDS retu rned error  on storag e of metas tamp for d emographic s', functi on() {
  814                var fini shed = fal se;
  815                var vist aClient =  {
  816                    getD emographic s: functio n(vistaId,  dfn, call back) {
  817                         return cal lback(null , demograp hicsFromVi sta);
  818                    }
  819                };
  820                var envi ronment =  createEnvi ronment(vi staClient,  config);
  821                var expe ctedJdsErr or = 'Some Error1';
  822                var expe ctedJdsRes ponse = {
  823                    stat usCode: 20 0
  824                };
  825                var expe ctedJdsRes ult = null ;
  826                var reco rd = {
  827                    'dat a': {
  828                         'items': [ demographi csFromVist a]
  829                    }
  830                };
  831                var meta stamp = me tastampUti l.metastam pDomain(re cord, demo graphicsFr omVista.st ampTime,'' );
  832                environm ent.jds._s etResponse Data(expec tedJdsErro r, expecte dJdsRespon se, expect edJdsResul t);
  833  
  834                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  835                runs(fun ction() {
  836                    ptDe mographics Util.retri eveDemogra phicsFromV istAandSto reInJds(de mographics FromVista. pid, funct ion(error,  ptDemogra phics) {
  837                         expect(err or).toEqua l('FailedJ dsError');
  838                         expect(ptD emographic s).toBeNul l();
  839                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  840                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csFromVist a.pid}), j asmine.any (Function) );
  841                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  842                         finished =  true;
  843                    });
  844                });
  845  
  846                waitsFor (function( ) {
  847                    retu rn finishe d;
  848                });
  849           }) ;
  850  
  851                    it(' JDS return ed error o n storage  of demogra phics', fu nction() {
  852                             var fi nished = f alse;
  853                             var vi staClient  = {
  854                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  855                                               return cal lback(null , demograp hicsFromVi sta);
  856                                      }
  857                             };
  858                             var en vironment  = createEn vironment( vistaClien t, config) ;
  859                             var ex pectedJdsE rror = [nu ll, 'SomeE rror'];
  860                             var ex pectedJdsR esponse =  [{
  861                    stat usCode: 20 0
  862                }, {
  863                                      statusCo de: 404
  864                             }];
  865                var expe ctedJdsRes ult = [nul l, null];
  866                var reco rd = {
  867                    'dat a': {
  868                         'items': [ demographi csFromVist a]
  869                    }
  870                };
  871                var meta stamp = me tastampUti l.metastam pDomain(re cord, demo graphicsFr omVista.st ampTime,'' );
  872  
  873                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  874  
  875                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  876                             runs(f unction()  {
  877                                      ptDemogr aphicsUtil .retrieveD emographic sFromVistA andStoreIn Jds(demogr aphicsFrom Vista.pid,  function( error, ptD emographic s) {
  878                                               expect(err or).toEqua l('FailedJ dsError');
  879                                               expect(ptD emographic s).toBeNul l();
  880                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  881                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csFromVist a.pid}), j asmine.any (Function) );
  882                             expect (environme nt.jds.sto rePatientD ata.calls. length).to Equal(1);
  883                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsF romVista),  jasmine.a ny(Functio n));
  884                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  885                             stampT ime: jasmi ne.any(Str ing)
  886                         }), jasmin e.any(Func tion));
  887                                               finished =  true;
  888                                      });
  889                             });
  890  
  891                             waitsF or(functio n() {
  892                                      return f inished;
  893                             });
  894                    });
  895           it ('JDS retu rned no re sponse on  storge of  metastamp  for demogr aphics', f unction()  {
  896                var fini shed = fal se;
  897                var vist aClient =  {
  898                    getD emographic s: functio n(vistaId,  dfn, call back) {
  899                         return cal lback(null , demograp hicsFromVi sta);
  900                    }
  901                };
  902                var envi ronment =  createEnvi ronment(vi staClient,  config);
  903                var expe ctedJdsErr or = null;
  904                var expe ctedJdsRes ponse = nu ll;
  905                var expe ctedJdsRes ult = null ;
  906                var reco rd = {
  907                    'dat a': {
  908                         'items': [ demographi csFromVist a]
  909                    }
  910                };
  911                var meta stamp = me tastampUti l.metastam pDomain(re cord, demo graphicsFr omVista.st ampTime,'' );
  912  
  913                environm ent.jds._s etResponse Data(expec tedJdsErro r, expecte dJdsRespon se, expect edJdsResul t);
  914  
  915                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  916                runs(fun ction() {
  917                    ptDe mographics Util.retri eveDemogra phicsFromV istAandSto reInJds(de mographics FromVista. pid, funct ion(error,  ptDemogra phics) {
  918                         expect(err or).toEqua l('FailedJ dsNoRespon se');
  919                         expect(ptD emographic s).toBeNul l();
  920                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  921                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csFromVist a.pid}), j asmine.any (Function) );
  922                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  923                         finished =  true;
  924                    });
  925                });
  926  
  927                waitsFor (function( ) {
  928                    retu rn finishe d;
  929                });
  930           }) ;
  931                    it(' JDS return ed no resp onse on st orge of de mographics ', functio n() {
  932                             var fi nished = f alse;
  933                             var vi staClient  = {
  934                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  935                                               return cal lback(null , demograp hicsFromVi sta);
  936                                      }
  937                             };
  938                             var en vironment  = createEn vironment( vistaClien t, config) ;
  939                var expe ctedJdsErr or = [null , null];
  940                var expe ctedJdsRes ponse = [{
  941                    stat usCode: 20 0
  942                }, null] ;
  943                var expe ctedJdsRes ult = [nul l, null];
  944                var reco rd = {
  945                    'dat a': {
  946                         'items': [ demographi csFromVist a]
  947                    }
  948                };
  949                var meta stamp = me tastampUti l.metastam pDomain(re cord, demo graphicsFr omVista.st ampTime,'' );
  950  
  951                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  952  
  953                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  954                             runs(f unction()  {
  955                                      ptDemogr aphicsUtil .retrieveD emographic sFromVistA andStoreIn Jds(demogr aphicsFrom Vista.pid,  function( error, ptD emographic s) {
  956                                               expect(err or).toEqua l('FailedJ dsNoRespon se');
  957                                               expect(ptD emographic s).toBeNul l();
  958                         expect(env ironment.j ds.saveSyn cStatus.ca ll.length) .toEqual(1 );
  959                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csFromVist a.pid}), j asmine.any (Function) );
  960                             expect (environme nt.jds.sto rePatientD ata.calls. length).to Equal(1);
  961                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsF romVista),  jasmine.a ny(Functio n));
  962                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  963                             stampT ime: jasmi ne.any(Str ing)
  964                         }), jasmin e.any(Func tion));
  965                                               finished =  true;
  966                                      });
  967                             });
  968  
  969                             waitsF or(functio n() {
  970                                      return f inished;
  971                             });
  972                    });
  973           it ('JDS retu rned inval id status  code on st orage of m etastamp f or demogra phics', fu nction() {
  974                var fini shed = fal se;
  975                var vist aClient =  {
  976                    getD emographic s: functio n(vistaId,  dfn, call back) {
  977                         return cal lback(null , demograp hicsFromVi sta);
  978                    }
  979                };
  980                var envi ronment =  createEnvi ronment(vi staClient,  config);
  981                var expe ctedJdsErr or = null;
  982                var expe ctedJdsRes ponse = {
  983                    stat usCode: 50 0
  984                };
  985                var expe ctedJdsRes ult = null ;
  986                var reco rd = {
  987                    'dat a': {
  988                         'items': [ demographi csFromVist a]
  989                    }
  990                };
  991                var meta stamp = me tastampUti l.metastam pDomain(re cord, demo graphicsFr omVista.st ampTime,'' );
  992  
  993                environm ent.jds._s etResponse Data(expec tedJdsErro r, expecte dJdsRespon se, expect edJdsResul t);
  994  
  995                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  996                runs(fun ction() {
  997                    ptDe mographics Util.retri eveDemogra phicsFromV istAandSto reInJds(de mographics FromVista. pid, funct ion(error,  ptDemogra phics) {
  998                         expect(err or).toEqua l('FailedJ dsWrongSta tusCode');
  999                         expect(ptD emographic s).toBeNul l();
  1000                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1001                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csFromVist a.pid}), j asmine.any (Function) );
  1002                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  1003                         finished =  true;
  1004                    });
  1005                });
  1006                waitsFor (function( ) {
  1007                    retu rn finishe d;
  1008                });
  1009           }) ;
  1010                    it(' JDS return ed invalid  status co de on stor age of dem ographics' , function () {
  1011                             var fi nished = f alse;
  1012                             var vi staClient  = {
  1013                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1014                                               return cal lback(null , demograp hicsFromVi sta);
  1015                                      }
  1016                             };
  1017                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1018                var expe ctedJdsErr or = [null , null];
  1019                var expe ctedJdsRes ponse = [{
  1020                    stat usCode: 20 0
  1021                }, {
  1022                                      statusCo de: 404
  1023                }];
  1024                var expe ctedJdsRes ult = [nul l, null];
  1025                var reco rd = {
  1026                    'dat a': {
  1027                         'items': [ demographi csFromVist a]
  1028                    }
  1029                };
  1030                var meta stamp = me tastampUti l.metastam pDomain(re cord, demo graphicsFr omVista.st ampTime,'' );
  1031  
  1032                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1033  
  1034                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1035                             runs(f unction()  {
  1036                                      ptDemogr aphicsUtil .retrieveD emographic sFromVistA andStoreIn Jds(demogr aphicsFrom Vista.pid,  function( error, ptD emographic s) {
  1037                                               expect(err or).toEqua l('FailedJ dsWrongSta tusCode');
  1038                                               expect(ptD emographic s).toBeNul l();
  1039                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1040                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csFromVist a.pid}), j asmine.any (Function) );
  1041                             expect (environme nt.jds.sto rePatientD ata.calls. length).to Equal(1);
  1042                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsF romVista),  jasmine.a ny(Functio n));
  1043                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  1044                             stampT ime: jasmi ne.any(Str ing)
  1045                         }), jasmin e.any(Func tion));
  1046                                               finished =  true;
  1047                                      });
  1048                             });
  1049  
  1050                             waitsF or(functio n() {
  1051                                      return f inished;
  1052                             });
  1053                    });
  1054           }) ;
  1055           de scribe('re trieveOrCr eateDemogr aphicsForP rimaryPid( )', functi on() {
  1056                    it(' Found demo graphics i n JDS', fu nction() {
  1057                             var fi nished = f alse;
  1058                             var vi staClient  = {
  1059                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1060                                               return cal lback(null , demograp hicsFromVi sta);
  1061                                      }
  1062                             };
  1063                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1064                             var ex pectedJdsE rror = nul l;
  1065                             var ex pectedJdsR esponse =  {
  1066                                      statusCo de: 200
  1067                             };
  1068                             var ex pectedJdsR esult = {
  1069                                      data: {
  1070                                               items: [de mographics FromVista]
  1071                                      }
  1072                             };
  1073                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1074  
  1075                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1076                             runs(f unction()  {
  1077                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orPrimaryP id(demogra phicsFromV ista.pid,  null, func tion(error , ptDemogr aphics) {
  1078                                               expect(err or).toBeFa lsy();
  1079                                               expect(ptD emographic s).toBeTru thy();
  1080                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsFr omVista));
  1081                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  1082                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1083                                               finished =  true;
  1084                                      });
  1085                             });
  1086  
  1087                             waitsF or(functio n() {
  1088                                      return f inished;
  1089                             });
  1090                    });
  1091                    it(' Did not fi nd demogra phics in J DS', funct ion() {
  1092                             var fi nished = f alse;
  1093                             var vi staClient  = {
  1094                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1095                                               return cal lback(null , demograp hicsFromVi sta);
  1096                                      }
  1097                             };
  1098                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1099                             var ex pectedJdsE rror = [nu ll, null,  null];
  1100                             var ex pectedJdsR esponse =  [{
  1101                                      statusCo de: 404
  1102                             }, {
  1103                    stat usCode: 20 0
  1104                }, {
  1105                                      statusCo de: 201
  1106                             }];
  1107                             var ex pectedJdsR esult = [n ull, null,  null];
  1108                var reco rd = {
  1109                    'dat a': {
  1110                         'items': [ demographi csFromVist a]
  1111                    }
  1112                };
  1113                var meta stamp = me tastampUti l.metastam pDomain(re cord, demo graphicsFr omVista.st ampTime,'' );
  1114  
  1115                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1116  
  1117                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1118                             runs(f unction()  {
  1119                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orPrimaryP id(demogra phicsFromV ista.pid,  null, func tion(error , ptDemogr aphics) {
  1120                                               expect(err or).toBeFa lsy();
  1121                                               expect(ptD emographic s).toBeTru thy();
  1122                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsFr omVista));  // toEqua l because  we should  get our or iginal ite m plus an  additional  attribute .
  1123                                               expect(ptD emographic s.stampTim e).toBeTru thy();
  1124                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  1125                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1126                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1127                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csFromVist a.pid}), j asmine.any (Function) );
  1128                             expect (environme nt.jds.sto rePatientD ata.calls. length).to Equal(1);
  1129                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsF romVista),  jasmine.a ny(Functio n));
  1130                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  1131                             stampT ime: jasmi ne.any(Str ing)
  1132                         }), jasmin e.any(Func tion));
  1133                                               finished =  true;
  1134                                      });
  1135                             });
  1136  
  1137                             waitsF or(functio n() {
  1138                                      return f inished;
  1139                             });
  1140                    });
  1141           }) ;
  1142           de scribe('_d emographic sCreationT askWrapper ()', funct ion() {
  1143                    it(' Happy Path ', functio n() {
  1144                             var fi nished = f alse;
  1145                             var de mographics CreationTa sk = funct ion(callba ck) {
  1146                                      return c allback(nu ll, demogr aphicsDod) ;
  1147                             };
  1148                             var en vironment  = createEn vironment( null, conf ig);
  1149                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1150                             var _d emographic sCreationT askWrapper  = PtDemog raphicsUti l._demogra phicsCreat ionTaskWra pper.bind( ptDemograp hicsUtil,  pidDod, de mographics CreationTa sk);
  1151                             runs(f unction()  {
  1152                                      _demogra phicsCreat ionTaskWra pper(funct ion(error,  response)  {
  1153                                               expect(err or).toBeNu ll();
  1154                                               expect(res ponse).toE qual(demog raphicsDod );
  1155                                               finished =  true;
  1156                                      });
  1157                             });
  1158  
  1159                             waitsF or(functio n() {
  1160                                      return f inished;
  1161                             });
  1162                    });
  1163                    it(' Happy Path ', functio n() {
  1164                             var fi nished = f alse;
  1165                             var de mographics CreationTa sk = funct ion(callba ck) {
  1166                                      return c allback('S omeError',  null);
  1167                             };
  1168                             var en vironment  = createEn vironment( null, conf ig);
  1169                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1170                             var _d emographic sCreationT askWrapper  = PtDemog raphicsUti l._demogra phicsCreat ionTaskWra pper.bind( ptDemograp hicsUtil,  pidDod, de mographics CreationTa sk);
  1171                             runs(f unction()  {
  1172                                      _demogra phicsCreat ionTaskWra pper(funct ion(error,  response)  {
  1173                                               expect(err or).toBeNu ll();
  1174                                               expect(res ponse).toE qual({
  1175                                                       er rorPid: pi dDod,
  1176                                                       er rorMessage : 'SomeErr or'
  1177                                               });
  1178                                               finished =  true;
  1179                                      });
  1180                             });
  1181  
  1182                             waitsF or(functio n() {
  1183                                      return f inished;
  1184                             });
  1185                    });
  1186           }) ;
  1187           de scribe('cr eatePtDemo graphicsFo rJobsUsing Pid()', fu nction() {
  1188                    it(' Happy Path  for DoD J ob', funct ion() {
  1189                             var fi nished = f alse;
  1190                             var vi staClient  = {
  1191                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1192                                               return cal lback(null , demograp hicsFromVi sta);
  1193                                      }
  1194                             };
  1195                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1196                             var ex pectedJdsE rror = [nu ll, null];
  1197                             var ex pectedJdsR esponse =  [{
  1198                                      statusCo de: 200
  1199                             }, {
  1200                                      statusCo de: 200
  1201                             }];
  1202                             var ex pectedJdsR esult = [{
  1203                                      data: {
  1204                                               items: [de mographics FromVista]
  1205                                      }
  1206                             }, {
  1207                                      data: {
  1208                                               items: [de mographics Dod]
  1209                                      }
  1210                             }];
  1211                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1212                             var sy ncJobsToPu blish = [{
  1213                                      type: 'j meadows-sy nc-request ',
  1214                                      patientI dentifier:  {
  1215                                               type: 'pid ',
  1216                                               value: pid Dod
  1217                                      }
  1218                             }];
  1219  
  1220                             // Not e we canno t test all  the jobs  at once -  because of  the paral lel nature  - we cann ot control  what orde r
  1221                             // JDS  will have  to give i ts respons es.
  1222                             //---- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
  1223                             // var  syncJobsT oPublish =  [{
  1224                             //       type: 'v ista-9E7A- subscribe- request',
  1225                             //       patientI dentifier:  {
  1226                             //                type: 'pid ',
  1227                             //                value: dem ographicsF romVista.p id
  1228                             //       }
  1229                             // },  {
  1230                             //       type: 'v ista-9E7A- subscribe- request',
  1231                             //       patientI dentifier:  {
  1232                             //                type: 'pid ',
  1233                             //                value: 'C8 77;3'
  1234                             //       }
  1235                             // },  {
  1236                             //       type: 'j meadows-sy nc-request ',
  1237                             //       patientI dentifier:  {
  1238                             //                type: 'pid ',
  1239                             //                value: pid Dod
  1240                             //       }
  1241                             // }];
  1242  
  1243                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1244                             runs(f unction()  {
  1245                                      ptDemogr aphicsUtil .createPtD emographic sForJobsUs ingPid(dem ographicsF romVista.p id, syncJo bsToPublis h, null, f unction(er ror, filte redSyncJob sToPublish ) {
  1246                                               expect(err or).toBeFa lsy();
  1247                                               expect(fil teredSyncJ obsToPubli sh).toEqua l(syncJobs ToPublish) ;
  1248                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(2) ;
  1249                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1250                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dDod, jasm ine.any(Fu nction));
  1251                                               finished =  true;
  1252                                      });
  1253                             });
  1254  
  1255                             waitsF or(functio n() {
  1256                                      return f inished;
  1257                             });
  1258                    });
  1259                    it(' Happy Path  for HDR J ob (HDR co nfigured a s secondar y)', funct ion() {
  1260                             var fi nished = f alse;
  1261                             var vi staClient  = {
  1262                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1263                                               return cal lback(null , demograp hicsFromVi sta);
  1264                                      }
  1265                             };
  1266                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1267                             var ex pectedJdsE rror = [nu ll, null];
  1268                             var ex pectedJdsR esponse =  [{
  1269                                      statusCo de: 200
  1270                             }, {
  1271                                      statusCo de: 200
  1272                             }];
  1273                             var ex pectedJdsR esult = [{
  1274                                      data: {
  1275                                               items: [de mographics FromVista]
  1276                                      }
  1277                             }, {
  1278                                      data: {
  1279                                               items: [de mographics HdrSeconda ry]
  1280                                      }
  1281                             }];
  1282                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1283                             var sy ncJobsToPu blish = [{
  1284                                      type: 'h dr-sync-re quest',
  1285                                      patientI dentifier:  {
  1286                                               type: 'pid ',
  1287                                               value: pid HdrSeconda ry
  1288                                      }
  1289                             }];
  1290  
  1291                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1292                             runs(f unction()  {
  1293                                      ptDemogr aphicsUtil .createPtD emographic sForJobsUs ingPid(dem ographicsF romVista.p id, syncJo bsToPublis h, null, f unction(er ror, filte redSyncJob sToPublish ) {
  1294                                               expect(err or).toBeFa lsy();
  1295                                               expect(fil teredSyncJ obsToPubli sh).toEqua l(syncJobs ToPublish) ;
  1296                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(2) ;
  1297                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1298                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dHdrSecond ary, jasmi ne.any(Fun ction));
  1299                                               finished =  true;
  1300                                      });
  1301                             });
  1302  
  1303                             waitsF or(functio n() {
  1304                                      return f inished;
  1305                             });
  1306                    });
  1307                    it(' Happy Path  for HDR J ob (HDR co nfigured a s PUB/SUB) ', functio n() {
  1308                             var fi nished = f alse;
  1309                             var vi staClient  = {
  1310                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1311                                               return cal lback(null , demograp hicsFromVi sta);
  1312                                      }
  1313                             };
  1314                             var en vironment  = createEn vironment( vistaClien t, vistaHd rConfig);
  1315                             var ex pectedJdsE rror = [nu ll, null];
  1316                             var ex pectedJdsR esponse =  [{
  1317                                      statusCo de: 200
  1318                             }, {
  1319                                      statusCo de: 200
  1320                             }];
  1321                             var ex pectedJdsR esult = [{
  1322                                      data: {
  1323                                               items: [de mographics FromVista]
  1324                                      }
  1325                             }, {
  1326                                      data: {
  1327                                               items: [de mographics VistaHdr]
  1328                                      }
  1329                             }];
  1330                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1331                             var sy ncJobsToPu blish = [{
  1332                                      type: 'v istahdr-82 11-subscri be-request ',
  1333                                      patientI dentifier:  {
  1334                                               type: 'pid ',
  1335                                               value: pid VistaHdr
  1336                                      }
  1337                             }];
  1338  
  1339                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, vis taHdrConfi g, environ ment);
  1340                             runs(f unction()  {
  1341                                      ptDemogr aphicsUtil .createPtD emographic sForJobsUs ingPid(dem ographicsF romVista.p id, syncJo bsToPublis h, null, f unction(er ror, filte redSyncJob sToPublish ) {
  1342                                               expect(err or).toBeFa lsy();
  1343                                               expect(fil teredSyncJ obsToPubli sh).toEqua l(syncJobs ToPublish) ;
  1344                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(2) ;
  1345                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1346                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dVistaHdr,  jasmine.a ny(Functio n));
  1347                                               finished =  true;
  1348                                      });
  1349                             });
  1350  
  1351                             waitsF or(functio n() {
  1352                                      return f inished;
  1353                             });
  1354                    });
  1355                    it(' Happy Path  for Prima ry Site Jo b - same a s original  primary s ite', func tion() {
  1356                             var fi nished = f alse;
  1357                             var vi staClient  = {
  1358                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1359                                               return cal lback(null , demograp hicsFromVi sta);
  1360                                      }
  1361                             };
  1362                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1363                             var ex pectedJdsE rror = [nu ll, null];
  1364                             var ex pectedJdsR esponse =  [{
  1365                                      statusCo de: 200
  1366                             }, {
  1367                                      statusCo de: 200
  1368                             }];
  1369                             var ex pectedJdsR esult = [{
  1370                                      data: {
  1371                                               items: [de mographics FromVista]
  1372                                      }
  1373                             }, {
  1374                                      data: {
  1375                                               items: [de mographics Dod]
  1376                                      }
  1377                             }];
  1378                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1379                             var sy ncJobsToPu blish = [{
  1380                                      type: 'v ista-9E7A- subscribe- request',
  1381                                      patientI dentifier:  {
  1382                                               type: 'pid ',
  1383                                               value: dem ographicsF romVista.p id
  1384                                      }
  1385                             }];
  1386  
  1387                             // Not e we canno t test all  the jobs  at once -  because of  the paral lel nature  - we cann ot control  what orde r
  1388                             // JDS  will have  to give i ts respons es.
  1389                             //---- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
  1390                             // var  syncJobsT oPublish =  [{
  1391                             //       type: 'v ista-9E7A- subscribe- request',
  1392                             //       patientI dentifier:  {
  1393                             //                type: 'pid ',
  1394                             //                value: dem ographicsF romVista.p id
  1395                             //       }
  1396                             // },  {
  1397                             //       type: 'v ista-9E7A- subscribe- request',
  1398                             //       patientI dentifier:  {
  1399                             //                type: 'pid ',
  1400                             //                value: 'C8 77;3'
  1401                             //       }
  1402                             // },  {
  1403                             //       type: 'j meadows-sy nc-request ',
  1404                             //       patientI dentifier:  {
  1405                             //                type: 'pid ',
  1406                             //                value: pid Dod
  1407                             //       }
  1408                             // }];
  1409  
  1410                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1411                             runs(f unction()  {
  1412                                      ptDemogr aphicsUtil .createPtD emographic sForJobsUs ingPid(dem ographicsF romVista.p id, syncJo bsToPublis h, null, f unction(er ror, filte redSyncJob sToPublish ) {
  1413                                               expect(err or).toBeFa lsy();
  1414                                               expect(fil teredSyncJ obsToPubli sh).toEqua l(syncJobs ToPublish) ;
  1415                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(2) ;
  1416                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1417                                               finished =  true;
  1418                                      });
  1419                             });
  1420  
  1421                             waitsF or(functio n() {
  1422                                      return f inished;
  1423                             });
  1424                    });
  1425                    it(' Happy Path  for Prima ry Site Jo b - differ ent than o riginal pr imary site ', functio n() {
  1426                             var fi nished = f alse;
  1427                             var vi staClient  = {
  1428                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1429                                               return cal lback(null , demograp hicsFromVi sta);
  1430                                      }
  1431                             };
  1432                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1433                             var ex pectedJdsE rror = [nu ll, null];
  1434                             var ex pectedJdsR esponse =  [{
  1435                                      statusCo de: 200
  1436                             }, {
  1437                                      statusCo de: 200
  1438                             }];
  1439                             var ex pectedJdsR esult = [{
  1440                                      data: {
  1441                                               items: [de mographics FromVista]
  1442                                      }
  1443                             }, {
  1444                                      data: {
  1445                                               items: [de mographics Dod]
  1446                                      }
  1447                             }];
  1448                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1449                             var sy ncJobsToPu blish = [{
  1450                                      type: 'v ista-9E7A- subscribe- request',
  1451                                      patientI dentifier:  {
  1452                                               type: 'pid ',
  1453                                               value: 'C8 77;3'
  1454                                      }
  1455                             }];
  1456  
  1457                             // Not e we canno t test all  the jobs  at once -  because of  the paral lel nature  - we cann ot control  what orde r
  1458                             // JDS  will have  to give i ts respons es.
  1459                             //---- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
  1460                             // var  syncJobsT oPublish =  [{
  1461                             //       type: 'v ista-9E7A- subscribe- request',
  1462                             //       patientI dentifier:  {
  1463                             //                type: 'pid ',
  1464                             //                value: dem ographicsF romVista.p id
  1465                             //       }
  1466                             // },  {
  1467                             //       type: 'v ista-9E7A- subscribe- request',
  1468                             //       patientI dentifier:  {
  1469                             //                type: 'pid ',
  1470                             //                value: 'C8 77;3'
  1471                             //       }
  1472                             // },  {
  1473                             //       type: 'j meadows-sy nc-request ',
  1474                             //       patientI dentifier:  {
  1475                             //                type: 'pid ',
  1476                             //                value: pid Dod
  1477                             //       }
  1478                             // }];
  1479  
  1480                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1481                             runs(f unction()  {
  1482                                      ptDemogr aphicsUtil .createPtD emographic sForJobsUs ingPid(dem ographicsF romVista.p id, syncJo bsToPublis h, null, f unction(er ror, filte redSyncJob sToPublish ) {
  1483                                               expect(err or).toBeFa lsy();
  1484                                               expect(fil teredSyncJ obsToPubli sh).toEqua l(syncJobs ToPublish) ;
  1485                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(2) ;
  1486                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1487                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith('9 E7A;3', ja smine.any( Function)) ;
  1488                                               finished =  true;
  1489                                      });
  1490                             });
  1491  
  1492                             waitsF or(functio n() {
  1493                                      return f inished;
  1494                             });
  1495                    });
  1496                    it(' DoD Job re ceived an  error', fu nction() {
  1497                             var fi nished = f alse;
  1498                             var vi staClient  = {
  1499                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1500                                               return cal lback(null , demograp hicsFromVi sta);
  1501                                      }
  1502                             };
  1503                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1504                             var ex pectedJdsE rror = [nu ll, null,  'SomeError '];
  1505                             var ex pectedJdsR esponse =  [{
  1506                                      statusCo de: 200
  1507                             }, {
  1508                                      statusCo de: 200
  1509                             }, {
  1510                                      statusCo de: 404
  1511                             }];
  1512                             var ex pectedJdsR esult = [{
  1513                                      data: {
  1514                                               items: [de mographics FromVista]
  1515                                      }
  1516                             }, nul l, null];
  1517                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1518                             var sy ncJobsToPu blish = [{
  1519                                      type: 'j meadows-sy nc-request ',
  1520                                      patientI dentifier:  {
  1521                                               type: 'pid ',
  1522                                               value: pid Dod
  1523                                      }
  1524                             }];
  1525  
  1526                             // Not e we canno t test all  the jobs  at once -  because of  the paral lel nature  - we cann ot control  what orde r
  1527                             // JDS  will have  to give i ts respons es.
  1528                             //---- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
  1529                             // var  syncJobsT oPublish =  [{
  1530                             //       type: 'v ista-9E7A- subscribe- request',
  1531                             //       patientI dentifier:  {
  1532                             //                type: 'pid ',
  1533                             //                value: dem ographicsF romVista.p id
  1534                             //       }
  1535                             // },  {
  1536                             //       type: 'v ista-9E7A- subscribe- request',
  1537                             //       patientI dentifier:  {
  1538                             //                type: 'pid ',
  1539                             //                value: 'C8 77;3'
  1540                             //       }
  1541                             // },  {
  1542                             //       type: 'j meadows-sy nc-request ',
  1543                             //       patientI dentifier:  {
  1544                             //                type: 'pid ',
  1545                             //                value: pid Dod
  1546                             //       }
  1547                             // }];
  1548  
  1549                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1550                             runs(f unction()  {
  1551                                      ptDemogr aphicsUtil .createPtD emographic sForJobsUs ingPid(dem ographicsF romVista.p id, syncJo bsToPublis h, null, f unction(er ror, filte redSyncJob sToPublish ) {
  1552                                               expect(err or).toBeFa lsy();
  1553                                               expect(fil teredSyncJ obsToPubli sh).toEqua l([]); //  Since ther e was an e rror - sho uld have b een remove d from the  list.
  1554                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(2) ;
  1555                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1556                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dDod, jasm ine.any(Fu nction));
  1557                                               finished =  true;
  1558                                      });
  1559                             });
  1560  
  1561                             waitsF or(functio n() {
  1562                                      return f inished;
  1563                             });
  1564                    });
  1565                    it(' retrieveOr CreateDemo graphicsFo rPrimaryPi d failed t o return p tDemograph ics.', fun ction() {
  1566                             var fi nished = f alse;
  1567                             var vi staClient  = {
  1568                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1569                                               return cal lback(null , demograp hicsFromVi sta);
  1570                                      }
  1571                             };
  1572                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1573                             var ex pectedJdsE rror = nul l;
  1574                             var ex pectedJdsR esponse =  {
  1575                                      statusCo de: 200
  1576                             };
  1577                             var ex pectedJdsR esult = nu ll;
  1578                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1579                             var sy ncJobsToPu blish = [] ;
  1580  
  1581                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1582                             runs(f unction()  {
  1583                                      ptDemogr aphicsUtil .createPtD emographic sForJobsUs ingPid(dem ographicsF romVista.p id, syncJo bsToPublis h, null, f unction(er ror) {
  1584                                               expect(err or).toEqua l('FailedJ dsNoRespon se');
  1585                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  1586                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(de mographics FromVista. pid, jasmi ne.any(Fun ction));
  1587                                               finished =  true;
  1588                                      });
  1589                             });
  1590  
  1591                             waitsF or(functio n() {
  1592                                      return f inished;
  1593                             });
  1594                    });
  1595                    it(' retrieveOr CreateDemo graphicsFo rPrimaryPi d failed t o return p tDemograph ics.', fun ction() {
  1596                             var fi nished = f alse;
  1597                             var vi staClient  = {
  1598                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1599                                               return cal lback(null , demograp hicsFromVi sta);
  1600                                      }
  1601                             };
  1602                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1603                             var ex pectedJdsE rror = nul l;
  1604                             var ex pectedJdsR esponse =  {
  1605                                      statusCo de: 200
  1606                             };
  1607                             var ex pectedJdsR esult = nu ll;
  1608                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1609                             var sy ncJobsToPu blish = [] ;
  1610  
  1611                             var de mographics  = {
  1612                                      name: 't est patien t'
  1613                             };
  1614                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1615                             runs(f unction()  {
  1616                                      ptDemogr aphicsUtil .createPtD emographic sForJobsUs ingPid('HD R;3', sync JobsToPubl ish, demog raphics, f unction(er ror) {
  1617                                               expect(err or).toBeFa lsy();
  1618                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  1619                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith('H DR;3', jas mine.any(F unction));
  1620                                               finished =  true;
  1621                                      });
  1622                             });
  1623  
  1624                             waitsF or(functio n() {
  1625                                      return f inished;
  1626                             });
  1627                    });
  1628           }) ;
  1629           de scribe('st oreDemogra phicsInJds UsingBasis Demographi cs()', fun ction() {
  1630                    it(' Happy Path ', functio n() {
  1631                             var fi nished = f alse;
  1632                             var vi staClient  = {
  1633                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1634                                               return cal lback(null , demograp hicsFromVi sta);
  1635                                      }
  1636                             };
  1637                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1638                var expe ctedJdsErr or = [null , null];
  1639                var expe ctedJdsRes ponse = [{
  1640                    stat usCode: 20 0
  1641                }, {
  1642                                      statusCo de: 201
  1643                             }];
  1644                             var ex pectedJdsR esult = [n ull, null] ;
  1645                var reco rd = {
  1646                    'dat a': {
  1647                         'items': [ demographi csDod]
  1648                    }
  1649                };
  1650                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  1651  
  1652                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1653  
  1654                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1655                             runs(f unction()  {
  1656                                      ptDemogr aphicsUtil .storeDemo graphicsIn JdsUsingBa sisDemogra phics(pidD od, demogr aphicsFrom Vista, fun ction(erro r, ptDemog raphics) {
  1657                                               expect(err or).toBeFa lsy();
  1658                                               expect(ptD emographic s).toBeTru thy();
  1659                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsDo d)); // to Equal beca use we sho uld get ou r original  item plus  an additi onal attri bute.
  1660                         expect(ptD emographic s).toEqual (jasmine.o bjectConta ining({
  1661                             stampT ime: jasmi ne.any(Str ing)
  1662                         }));
  1663                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1664                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csDod.pid} ), jasmine .any(Funct ion));
  1665                             expect (environme nt.jds.sto rePatientD ata.calls. length).to Equal(1);
  1666                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsD od), jasmi ne.any(Fun ction));
  1667                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  1668                             stampT ime: jasmi ne.any(Str ing)
  1669                         }), jasmin e.any(Func tion));
  1670                                               finished =  true;
  1671                                      });
  1672                             });
  1673  
  1674                             waitsF or(functio n() {
  1675                                      return f inished;
  1676                             });
  1677                    });
  1678                    it(' Missing pi d', functi on() {
  1679                             var fi nished = f alse;
  1680                             var vi staClient  = {
  1681                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1682                                               return cal lback(null , demograp hicsFromVi sta);
  1683                                      }
  1684                             };
  1685                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1686                             var ex pectedJdsE rror = nul l;
  1687                             var ex pectedJdsR esponse =  {
  1688                                      statusCo de: 201
  1689                             };
  1690                             var ex pectedJdsR esult = nu ll;
  1691                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1692  
  1693                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1694                             runs(f unction()  {
  1695                                      ptDemogr aphicsUtil .storeDemo graphicsIn JdsUsingBa sisDemogra phics(null , demograp hicsFromVi sta, funct ion(error,  ptDemogra phics) {
  1696                                               expect(err or).toEqua l('FailedN oPid');
  1697                                               expect(ptD emographic s).toBeNul l();
  1698                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 0);
  1699                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  1700                                               finished =  true;
  1701                                      });
  1702                             });
  1703  
  1704                             waitsF or(functio n() {
  1705                                      return f inished;
  1706                             });
  1707                    });
  1708                    it(' Missing pt Demographi csBasis',  function()  {
  1709                             var fi nished = f alse;
  1710                             var vi staClient  = {
  1711                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1712                                               return cal lback(null , demograp hicsFromVi sta);
  1713                                      }
  1714                             };
  1715                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1716                             var ex pectedJdsE rror = nul l;
  1717                             var ex pectedJdsR esponse =  {
  1718                                      statusCo de: 201
  1719                             };
  1720                             var ex pectedJdsR esult = nu ll;
  1721                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1722  
  1723                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1724                             runs(f unction()  {
  1725                                      ptDemogr aphicsUtil .storeDemo graphicsIn JdsUsingBa sisDemogra phics(pidD od, null,  function(e rror, ptDe mographics ) {
  1726                                               expect(err or).toEqua l('FailedN oPtDemogra phicsBasis ');
  1727                                               expect(ptD emographic s).toBeNul l();
  1728                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 0);
  1729                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  1730                                               finished =  true;
  1731                                      });
  1732                             });
  1733  
  1734                             waitsF or(functio n() {
  1735                                      return f inished;
  1736                             });
  1737                    });
  1738                    it(' PID not se condary si te.', func tion() {
  1739                             var fi nished = f alse;
  1740                             var vi staClient  = {
  1741                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1742                                               return cal lback(null , demograp hicsFromVi sta);
  1743                                      }
  1744                             };
  1745                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1746                             var ex pectedJdsE rror = nul l;
  1747                             var ex pectedJdsR esponse =  {
  1748                                      statusCo de: 201
  1749                             };
  1750                             var ex pectedJdsR esult = nu ll;
  1751                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1752  
  1753                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1754                             runs(f unction()  {
  1755                                      ptDemogr aphicsUtil .storeDemo graphicsIn JdsUsingBa sisDemogra phics('9E7 A;3', demo graphicsFr omVista, f unction(er ror, ptDem ographics)  {
  1756                                               expect(err or).toEqua l('FailedP idNotSecon darySite') ;
  1757                                               expect(ptD emographic s).toBeNul l();
  1758                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 0);
  1759                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  1760                                               finished =  true;
  1761                                      });
  1762                             });
  1763  
  1764                             waitsF or(functio n() {
  1765                                      return f inished;
  1766                             });
  1767                    });
  1768                    it(' PID second ary site -  but not v alid forma t.', funct ion() {
  1769                             var fi nished = f alse;
  1770                             var vi staClient  = {
  1771                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1772                                               return cal lback(null , demograp hicsFromVi sta);
  1773                                      }
  1774                             };
  1775                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1776                             var ex pectedJdsE rror = nul l;
  1777                             var ex pectedJdsR esponse =  {
  1778                                      statusCo de: 201
  1779                             };
  1780                             var ex pectedJdsR esult = nu ll;
  1781                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1782  
  1783                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1784                             runs(f unction()  {
  1785                                      ptDemogr aphicsUtil .storeDemo graphicsIn JdsUsingBa sisDemogra phics('DOD ;', demogr aphicsFrom Vista, fun ction(erro r, ptDemog raphics) {
  1786                                               expect(err or).toEqua l('FailedP idNotSecon darySite') ;
  1787                                               expect(ptD emographic s).toBeNul l();
  1788                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 0);
  1789                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  1790                                               finished =  true;
  1791                                      });
  1792                             });
  1793  
  1794                             waitsF or(functio n() {
  1795                                      return f inished;
  1796                             });
  1797                    });
  1798           it ('Store me tastamp fa iled with  JDS return ing error. ', functio n() {
  1799                var fini shed = fal se;
  1800                var vist aClient =  {
  1801                    getD emographic s: functio n(vistaId,  dfn, call back) {
  1802                         return cal lback(null , demograp hicsFromVi sta);
  1803                    }
  1804                };
  1805                var envi ronment =  createEnvi ronment(vi staClient,  config);
  1806                var expe ctedJdsErr or = 'Some Error';
  1807                var expe ctedJdsRes ponse = {
  1808                    stat usCode: 50 0
  1809                };
  1810                var expe ctedJdsRes ult = null ;
  1811                var reco rd = {
  1812                    'dat a': {
  1813                         'items': [ demographi csDod]
  1814                    }
  1815                };
  1816                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  1817  
  1818                environm ent.jds._s etResponse Data(expec tedJdsErro r, expecte dJdsRespon se, expect edJdsResul t);
  1819  
  1820                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  1821                runs(fun ction() {
  1822                    ptDe mographics Util.store Demographi csInJdsUsi ngBasisDem ographics( pidDod, de mographics FromVista,  function( error, ptD emographic s) {
  1823                         expect(err or).toEqua l('FailedJ dsError');
  1824                         expect(ptD emographic s).toBeNul l();
  1825                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1826                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csDod.pid} ), jasmine .any(Funct ion));
  1827                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  1828                         finished =  true;
  1829                    });
  1830                });
  1831  
  1832                waitsFor (function( ) {
  1833                    retu rn finishe d;
  1834                });
  1835           }) ;
  1836                    it(' Store fail ed with JD S returnin g error.',  function( ) {
  1837                             var fi nished = f alse;
  1838                             var vi staClient  = {
  1839                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1840                                               return cal lback(null , demograp hicsFromVi sta);
  1841                                      }
  1842                             };
  1843                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1844                var expe ctedJdsErr or = [null , 'SomeErr or'];
  1845                var expe ctedJdsRes ponse = [{
  1846                    stat usCode: 20 0
  1847                }, {
  1848                    stat usCode: 20 1
  1849                }];
  1850                var expe ctedJdsRes ult = [nul l, null];
  1851                var reco rd = {
  1852                    'dat a': {
  1853                         'items': [ demographi csDod]
  1854                    }
  1855                };
  1856                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  1857  
  1858                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1859  
  1860                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1861                             runs(f unction()  {
  1862                                      ptDemogr aphicsUtil .storeDemo graphicsIn JdsUsingBa sisDemogra phics(pidD od, demogr aphicsFrom Vista, fun ction(erro r, ptDemog raphics) {
  1863                                               expect(err or).toEqua l('FailedJ dsError');
  1864                                               expect(ptD emographic s).toBeNul l();
  1865                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1866                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csDod.pid} ), jasmine .any(Funct ion));
  1867                             expect (environme nt.jds.sto rePatientD ata.calls. length).to Equal(1);
  1868                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsD od), jasmi ne.any(Fun ction));
  1869                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  1870                             stampT ime: jasmi ne.any(Str ing)
  1871                         }), jasmin e.any(Func tion));
  1872                                               finished =  true;
  1873                                      });
  1874                             });
  1875  
  1876                             waitsF or(functio n() {
  1877                                      return f inished;
  1878                             });
  1879                    });
  1880           it ('Store me tastamp fa iled with  JDS return ing no res ponse.', f unction()  {
  1881                var fini shed = fal se;
  1882                var vist aClient =  {
  1883                    getD emographic s: functio n(vistaId,  dfn, call back) {
  1884                         return cal lback(null , demograp hicsFromVi sta);
  1885                    }
  1886                };
  1887                var envi ronment =  createEnvi ronment(vi staClient,  config);
  1888                var expe ctedJdsErr or = null;
  1889                var expe ctedJdsRes ponse = nu ll;
  1890                var expe ctedJdsRes ult = null ;
  1891                var reco rd = {
  1892                    'dat a': {
  1893                         'items': [ demographi csDod]
  1894                    }
  1895                };
  1896                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  1897  
  1898                environm ent.jds._s etResponse Data(expec tedJdsErro r, expecte dJdsRespon se, expect edJdsResul t);
  1899  
  1900                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  1901                runs(fun ction() {
  1902                    ptDe mographics Util.store Demographi csInJdsUsi ngBasisDem ographics( pidDod, de mographics FromVista,  function( error, ptD emographic s) {
  1903                         expect(err or).toEqua l('FailedJ dsNoRespon se');
  1904                         expect(ptD emographic s).toBeNul l();
  1905                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1906                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  1907                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csDod.pid} ), jasmine .any(Funct ion));
  1908                         finished =  true;
  1909                    });
  1910                });
  1911  
  1912                waitsFor (function( ) {
  1913                    retu rn finishe d;
  1914                });
  1915           }) ;
  1916                    it(' Store fail ed with JD S returnin g no respo nse.', fun ction() {
  1917                             var fi nished = f alse;
  1918                             var vi staClient  = {
  1919                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  1920                                               return cal lback(null , demograp hicsFromVi sta);
  1921                                      }
  1922                             };
  1923                             var en vironment  = createEn vironment( vistaClien t, config) ;
  1924                             var ex pectedJdsE rror = [nu ll, null];
  1925                var expe ctedJdsRes ponse = [{
  1926                    stat usCode: 20 0
  1927                }, null] ;
  1928                var expe ctedJdsRes ult = [nul l, null];
  1929                var reco rd = {
  1930                    'dat a': {
  1931                         'items': [ demographi csDod]
  1932                    }
  1933                };
  1934                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  1935  
  1936                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  1937  
  1938                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  1939                             runs(f unction()  {
  1940                                      ptDemogr aphicsUtil .storeDemo graphicsIn JdsUsingBa sisDemogra phics(pidD od, demogr aphicsFrom Vista, fun ction(erro r, ptDemog raphics) {
  1941                                               expect(err or).toEqua l('FailedJ dsNoRespon se');
  1942                                               expect(ptD emographic s).toBeNul l();
  1943                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1944                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csDod.pid} ), jasmine .any(Funct ion));
  1945                             expect (environme nt.jds.sto rePatientD ata.calls. length).to Equal(1);
  1946                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsD od), jasmi ne.any(Fun ction));
  1947                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  1948                             stampT ime: jasmi ne.any(Str ing)
  1949                         }), jasmin e.any(Func tion));
  1950                                               finished =  true;
  1951                                      });
  1952                             });
  1953  
  1954                             waitsF or(functio n() {
  1955                                      return f inished;
  1956                             });
  1957                    });
  1958           it ('Store me tastamp fa iled with  JDS return ing incorr ect respon se status  code.', fu nction() {
  1959                var fini shed = fal se;
  1960                var vist aClient =  {
  1961                    getD emographic s: functio n(vistaId,  dfn, call back) {
  1962                         return cal lback(null , demograp hicsFromVi sta);
  1963                    }
  1964                };
  1965                var envi ronment =  createEnvi ronment(vi staClient,  config);
  1966                var expe ctedJdsErr or = null;
  1967                var expe ctedJdsRes ponse = {
  1968                    stat usCode: 50 0
  1969                };
  1970                var expe ctedJdsRes ult = null ;
  1971                var reco rd = {
  1972                    'dat a': {
  1973                         'items': [ demographi csDod]
  1974                    }
  1975                };
  1976                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  1977  
  1978                environm ent.jds._s etResponse Data(expec tedJdsErro r, expecte dJdsRespon se, expect edJdsResul t);
  1979  
  1980                var ptDe mographics Util = new  PtDemogra phicsUtil( log, confi g, environ ment);
  1981                runs(fun ction() {
  1982                    ptDe mographics Util.store Demographi csInJdsUsi ngBasisDem ographics( pidDod, de mographics FromVista,  function( error, ptD emographic s) {
  1983                         expect(err or).toEqua l('FailedJ dsWrongSta tusCode');
  1984                         expect(ptD emographic s).toBeNul l();
  1985                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  1986                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csDod.pid} ), jasmine .any(Funct ion));
  1987                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  1988                         finished =  true;
  1989                    });
  1990                });
  1991  
  1992                waitsFor (function( ) {
  1993                    retu rn finishe d;
  1994                });
  1995           }) ;
  1996                    it(' Store fail ed with JD S returnin g incorrec t response  status co de.', func tion() {
  1997                             var fi nished = f alse;
  1998                             var vi staClient  = {
  1999                                      getDemog raphics: f unction(vi staId, dfn , callback ) {
  2000                                               return cal lback(null , demograp hicsFromVi sta);
  2001                                      }
  2002                             };
  2003                             var en vironment  = createEn vironment( vistaClien t, config) ;
  2004                var expe ctedJdsErr or = [null , null];
  2005                var expe ctedJdsRes ponse = [{
  2006                    stat usCode: 20 0
  2007                }, {
  2008                                      statusCo de: 404
  2009                }];
  2010                var expe ctedJdsRes ult = [nul l, null];
  2011                var reco rd = {
  2012                    'dat a': {
  2013                         'items': [ demographi csDod]
  2014                    }
  2015                };
  2016                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  2017  
  2018                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  2019  
  2020                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  2021                             runs(f unction()  {
  2022                                      ptDemogr aphicsUtil .storeDemo graphicsIn JdsUsingBa sisDemogra phics(pidD od, demogr aphicsFrom Vista, fun ction(erro r, ptDemog raphics) {
  2023                                               expect(err or).toEqua l('FailedJ dsWrongSta tusCode');
  2024                                               expect(ptD emographic s).toBeNul l();
  2025                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  2026                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({type: ' pid', valu e: demogra phicsDod.p id}), jasm ine.any(Fu nction));
  2027                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(1);
  2028                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsD od), jasmi ne.any(Fun ction));
  2029                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  2030                             stampT ime: jasmi ne.any(Str ing)
  2031                         }), jasmin e.any(Func tion));
  2032                                               finished =  true;
  2033                                      });
  2034                             });
  2035  
  2036                             waitsF or(functio n() {
  2037                                      return f inished;
  2038                             });
  2039                    });
  2040           }) ;
  2041           de scribe('re trieveOrCr eateDemogr aphicsForS econdaryOr VistaHdrPi d()', func tion() {
  2042                    it(' Found demo graphics i n JDS', fu nction() {
  2043                             var fi nished = f alse;
  2044                             var vi staClient  = {};
  2045                             var en vironment  = createEn vironment( vistaClien t, config) ;
  2046                             var ex pectedJdsE rror = nul l;
  2047                             var ex pectedJdsR esponse =  {
  2048                                      statusCo de: 200
  2049                             };
  2050                             var ex pectedJdsR esult = [{
  2051                                      data: {
  2052                                               items: [de mographics Dod]
  2053                                      }
  2054                             }];
  2055                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  2056  
  2057                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  2058                             runs(f unction()  {
  2059                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orSecondar yOrVistaHd rPid(pidDo d, demogra phicsFromV ista, func tion(error , ptDemogr aphics) {
  2060                                               expect(err or).toBeFa lsy();
  2061                                               expect(ptD emographic s).toBeTru thy();
  2062                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsDo d));
  2063                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  2064                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dDod, jasm ine.any(Fu nction));
  2065                                               finished =  true;
  2066                                      });
  2067                             });
  2068  
  2069                             waitsF or(functio n() {
  2070                                      return f inished;
  2071                             });
  2072                    });
  2073                    it(' Found demo graphics i n JDS (HDR  configure d as secon dary)', fu nction() {
  2074                             var fi nished = f alse;
  2075                             var vi staClient  = {};
  2076                             var en vironment  = createEn vironment( vistaClien t, config) ;
  2077                             var ex pectedJdsE rror = nul l;
  2078                             var ex pectedJdsR esponse =  {
  2079                                      statusCo de: 200
  2080                             };
  2081                             var ex pectedJdsR esult = [{
  2082                                      data: {
  2083                                               items: [de mographics HdrSeconda ry]
  2084                                      }
  2085                             }];
  2086                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  2087  
  2088                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  2089                             runs(f unction()  {
  2090                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orSecondar yOrVistaHd rPid(pidHd rSecondary , demograp hicsFromVi sta, funct ion(error,  ptDemogra phics) {
  2091                                               expect(err or).toBeFa lsy();
  2092                                               expect(ptD emographic s).toBeTru thy();
  2093                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsHd rSecondary ));
  2094                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  2095                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dHdrSecond ary, jasmi ne.any(Fun ction));
  2096                                               finished =  true;
  2097                                      });
  2098                             });
  2099  
  2100                             waitsF or(functio n() {
  2101                                      return f inished;
  2102                             });
  2103                    });
  2104                    it(' Found demo graphics i n JDS (HDR  configure d as PUB/S UB)', func tion() {
  2105                             var fi nished = f alse;
  2106                             var vi staClient  = {};
  2107                             var en vironment  = createEn vironment( vistaClien t, vistaHd rConfig);
  2108                             var ex pectedJdsE rror = nul l;
  2109                             var ex pectedJdsR esponse =  {
  2110                                      statusCo de: 200
  2111                             };
  2112                             var ex pectedJdsR esult = [{
  2113                                      data: {
  2114                                               items: [de mographics VistaHdr]
  2115                                      }
  2116                             }];
  2117                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  2118  
  2119                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, vis taHdrConfi g, environ ment);
  2120                             runs(f unction()  {
  2121                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orSecondar yOrVistaHd rPid(pidVi staHdr, de mographics FromVista,  function( error, ptD emographic s) {
  2122                                               expect(err or).toBeFa lsy();
  2123                                               expect(ptD emographic s).toBeTru thy();
  2124                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsVi staHdr));
  2125                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  2126                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dVistaHdr,  jasmine.a ny(Functio n));
  2127                                               finished =  true;
  2128                                      });
  2129                             });
  2130  
  2131                             waitsF or(functio n() {
  2132                                      return f inished;
  2133                             });
  2134                    });
  2135                    it(' Did not fi nd demogra phics in J DS', funct ion() {
  2136                             var fi nished = f alse;
  2137                             var vi staClient  = {};
  2138                             var en vironment  = createEn vironment( vistaClien t, config) ;
  2139                             var ex pectedJdsE rror = [nu ll, null,  null];
  2140                             var ex pectedJdsR esponse =  [{
  2141                                      statusCo de: 404
  2142                             }, {
  2143                    stat usCode: 20 0
  2144                }, {
  2145                                      statusCo de: 201
  2146                             }];
  2147                             var ex pectedJdsR esult = [n ull, null,  null];
  2148                var reco rd = {
  2149                    'dat a': {
  2150                         'items': [ demographi csDod]
  2151                    }
  2152                };
  2153                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  2154  
  2155                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  2156  
  2157                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  2158                             runs(f unction()  {
  2159                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orSecondar yOrVistaHd rPid(pidDo d, demogra phicsFromV ista, func tion(error , ptDemogr aphics) {
  2160                                               expect(err or).toBeFa lsy();
  2161                                               expect(ptD emographic s).toBeTru thy();
  2162                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsDo d)); // to Equal beca use we sho uld get ou r original  item plus  an additi onal attri bute.
  2163                                               expect(ptD emographic s.stampTim e).toBeTru thy();
  2164                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  2165                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dDod, jasm ine.any(Fu nction));
  2166                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  2167                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csDod.pid} ), jasmine .any(Funct ion));
  2168                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(1);
  2169                                               expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsD od), jasmi ne.any(Fun ction));
  2170                                               expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  2171                                                       st ampTime: j asmine.any (String)
  2172                                               }), jasmin e.any(Func tion));
  2173                                               finished =  true;
  2174                                      });
  2175                             });
  2176  
  2177                             waitsF or(functio n() {
  2178                                      return f inished;
  2179                             });
  2180                    });
  2181                    it(' Did not fi nd demogra phics in J DS (HDR co nfigured a s secondar y)', funct ion() {
  2182                             var fi nished = f alse;
  2183                             var vi staClient  = {};
  2184                             var en vironment  = createEn vironment( vistaClien t, config) ;
  2185                             var ex pectedJdsE rror = [nu ll, null,  null];
  2186                             var ex pectedJdsR esponse =  [{
  2187                                      statusCo de: 404
  2188                             }, {
  2189                    stat usCode: 20 0
  2190                }, {
  2191                                      statusCo de: 201
  2192                             }];
  2193                             var ex pectedJdsR esult = [n ull, null,  null];
  2194                var reco rd = {
  2195                    'dat a': {
  2196                         'items': [ demographi csHdrSecon dary]
  2197                    }
  2198                };
  2199                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  2200  
  2201                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  2202  
  2203                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  2204                             runs(f unction()  {
  2205                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orSecondar yOrVistaHd rPid(pidHd rSecondary , demograp hicsFromVi sta, funct ion(error,  ptDemogra phics) {
  2206                                               expect(err or).toBeFa lsy();
  2207                                               expect(ptD emographic s).toBeTru thy();
  2208                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsHd rSecondary )); // toE qual becau se we shou ld get our  original  item plus  an additio nal attrib ute.
  2209                                               expect(ptD emographic s.stampTim e).toBeTru thy();
  2210                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(1) ;
  2211                                               expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dHdrSecond ary, jasmi ne.any(Fun ction));
  2212                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  2213                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csHdrSecon dary.pid}) , jasmine. any(Functi on));
  2214                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(1);
  2215                                               expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsH drSecondar y), jasmin e.any(Func tion));
  2216                                               expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  2217                                                       st ampTime: j asmine.any (String)
  2218                                               }), jasmin e.any(Func tion));
  2219                                               finished =  true;
  2220                                      });
  2221                             });
  2222  
  2223                             waitsF or(functio n() {
  2224                                      return f inished;
  2225                             });
  2226                    });
  2227                    it(' Did not fi nd demogra phics in J DS (HDR co nfigured a s PUB/SUB) ', functio n() {
  2228                             var fi nished = f alse;
  2229                             var vi staClient  = {};
  2230                             var en vironment  = createEn vironment( vistaClien t, vistaHd rConfig);
  2231                var expe ctedJdsErr or = [null , null, nu ll];
  2232                             var ex pectedJdsR esponse =  [{
  2233                                      statusCo de: 404
  2234                             }, {
  2235                    stat usCode: 20 0
  2236                }, {
  2237                                      statusCo de: 201
  2238                             }];
  2239                             var ex pectedJdsR esult = [n ull, null,  null];
  2240                var reco rd = {
  2241                    'dat a': {
  2242                         'items': [ demographi csVistaHdr ]
  2243                    }
  2244                };
  2245                var meta stamp = me tastampUti l.metastam pDomain(re cord, PtDe mographics Util.BASIS _STAMPTIME ,'');
  2246  
  2247                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  2248  
  2249                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, vis taHdrConfi g, environ ment);
  2250                             runs(f unction()  {
  2251                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orSecondar yOrVistaHd rPid(pidVi staHdr, de mographics FromVista,  function( error, ptD emographic s) {
  2252                                               expect(err or).toBeFa lsy();
  2253                                               expect(ptD emographic s).toBeTru thy();
  2254                                               expect(ptD emographic s).toEqual (jasmine.o bjectConta ining(demo graphicsVi staHdr));  // toEqual  because w e should g et our ori ginal item  plus an a dditional  attribute.
  2255                                               expect(ptD emographic s.stampTim e).toBeTru thy();
  2256                             expect (environme nt.jds.get PtDemograp hicsByPid. calls.leng th).toEqua l(1);
  2257                         expect(env ironment.j ds.getPtDe mographics ByPid).toH aveBeenCal ledWith(pi dVistaHdr,  jasmine.a ny(Functio n));
  2258                         expect(env ironment.j ds.saveSyn cStatus.ca lls.length ).toEqual( 1);
  2259                         expect(env ironment.j ds.saveSyn cStatus).t oHaveBeenC alledWith( jasmine.ob jectContai ning(metas tamp), jas mine.objec tContainin g({value:  demographi csVistaHdr .pid}), ja smine.any( Function)) ;
  2260                         expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(1);
  2261                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining(dem ographicsV istaHdr),  jasmine.an y(Function ));
  2262                         expect(env ironment.j ds.storePa tientData) .toHaveBee nCalledWit h(jasmine. objectCont aining({
  2263                             stampT ime: jasmi ne.any(Str ing)
  2264                         }), jasmin e.any(Func tion));
  2265                                               finished =  true;
  2266                                      });
  2267                             });
  2268  
  2269                             waitsF or(functio n() {
  2270                                      return f inished;
  2271                             });
  2272                    });
  2273                    it(' Pid was no t for a se condary si te.', func tion() {
  2274                             var fi nished = f alse;
  2275                             var vi staClient  = {};
  2276                             var en vironment  = createEn vironment( vistaClien t, config) ;
  2277                             var ex pectedJdsE rror = [nu ll, null];
  2278                             var ex pectedJdsR esponse =  [{
  2279                                      statusCo de: 404
  2280                             }, {
  2281                                      statusCo de: 201
  2282                             }];
  2283                             var ex pectedJdsR esult = [n ull, null] ;
  2284                             enviro nment.jds. _setRespon seData(exp ectedJdsEr ror, expec tedJdsResp onse, expe ctedJdsRes ult);
  2285  
  2286                             var pt Demographi csUtil = n ew PtDemog raphicsUti l(log, con fig, envir onment);
  2287                             runs(f unction()  {
  2288                                      ptDemogr aphicsUtil .retrieveO rCreateDem ographicsF orSecondar yOrVistaHd rPid('9E7A ;111', dem ographicsF romVista,  function(e rror, ptDe mographics ) {
  2289                                               expect(err or).toEqua l('FailedP idNotSecon darySite') ;
  2290                                               expect(ptD emographic s).toBeNul l();
  2291                                               expect(env ironment.j ds.getPtDe mographics ByPid.call s.length). toEqual(0) ;
  2292                                               expect(env ironment.j ds.storePa tientData. calls.leng th).toEqua l(0);
  2293                                               finished =  true;
  2294                                      });
  2295                             });
  2296  
  2297                             waitsF or(functio n() {
  2298                                      return f inished;
  2299                             });
  2300                    });
  2301           }) ;
  2302  
  2303           de scribe('_m orphToSeco ndaryDemog raphics()' , function () {
  2304                    it(' Happy Path ', functio n() {
  2305                             var pr imaryDemog raphics =  {
  2306                                      'pid': ' 9E7A;3',
  2307                                      'birthDa te': '1935 0407',
  2308                                      'last4':  '0008',
  2309                                      'last5':  'E0008',
  2310                                      'icn': ' 10108V4208 71',
  2311                                      'familyN ame': 'EIG HT',
  2312                                      'givenNa mes': 'PAT IENT',
  2313                                      'fullNam e': 'EIGHT ,PATIENT',
  2314                                      'display Name': 'Ei ght,Patien t',
  2315                                      'genderC ode': 'urn :va:pat-ge nder:M',
  2316                                      'genderN ame': 'Mal e',
  2317                                      'sensiti ve': false ,
  2318                                      'uid': ' urn:va:pat ient:9E7A: 3:3',
  2319                                      'summary ': 'Eight, Patient',
  2320                                      'ssn': ' 666000008' ,
  2321                                      'localId ': '3',
  2322                                      'shortIn patientLoc ation': 's hortInpati entLocatio n',
  2323                                      'roomBed ': 'roomBe d',
  2324                                      'inpatie ntLocation ': 'inpati entLocatio n',
  2325                                      'admissi onUid': 'a dmissionUi d',
  2326                                      'cwadf':  'cwadf'
  2327                             };
  2328  
  2329                             var se condaryDem ographics  = PtDemogr aphicsUtil ._morphToS econdaryDe mographics (primaryDe mographics );
  2330                             expect (secondary Demographi cs.shortIn patientLoc ation).toB eUndefined ();
  2331                             expect (secondary Demographi cs.roomBed ).toBeUnde fined();
  2332                             expect (secondary Demographi cs.inpatie ntLocation ).toBeUnde fined();
  2333                             expect (secondary Demographi cs.admissi onUid).toB eUndefined ();
  2334                             expect (secondary Demographi cs.cwadf). toBeUndefi ned();
  2335                    });
  2336           }) ;
  2337  
  2338   });