34. EPMO Open Source Coordination Office Redaction File Detail Report

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

34.1 Files compared

# Location File Last Modified
1 rdk.zip\rdk\product\production\rdk\src\handler\activity activity-management-event-handler-spec.js Mon Aug 28 19:41:48 2017 UTC
2 rdk.zip\rdk\product\production\rdk\src\handler\activity activity-management-event-handler-spec.js Tue Oct 3 18:06:23 2017 UTC

34.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 9 1622
Changed 8 26
Inserted 0 0
Removed 0 0

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

34.4 Active regular expressions

No regular expressions were active.

34.5 Comparison detail

  1   'use stric t';
  2   var _ = re quire('lod ash');
  3   var activi tyHelper =  require(' ./activity -managemen t-event-ha ndler-help er');
  4   var clinci alObjectsS ubsystem =  require(' ../../subs ystems/cli nical-obje cts/clinic al-objects -subsystem ');
  5   var activi tyEventPro cess = req uire('../. ./resource s/activity management /activitie s/eventpro cessor/act ivity-even t-process- resource') ;
  6   var rdk =  require('. ./../core/ rdk');
  7   var pidVal idator = r dk.utils.p idValidato r;
  8  
  9   var bunyan  = require ('bunyan') ;
  10   var logger  = sinon.s tub(bunyan .createLog ger({
  11       name:  'test-logg er'
  12   }));
  13   logger.chi ld.returns This();
  14  
  15   var handle r = requir e('./activ ity-manage ment-event -handler') ;
  16  
  17   var env =  {};
  18  
  19   var config  = {
  20       'rdk':  {
  21           pr otocol: 'h ttp',
  22             host: ' IP          ',
  23             activityPo rt:  PORT ,
  24             writePort:   PORT ,
  25           ti meout: 600 00,
  26             accessCode : ' REDACT ',
  27             verifyCode : ' REDACTED ',
  28           ac tivityURI:  '/resourc e/activiti es/startac tivityeven t',
  29           wr iteURI: '/ resource/w rite-healt h-data/pat ient'
  30       },
  31       'jdsSe rver': {
  32             'baseUrl':  'http:// IP                ',
  33           't imeout': 1 20000
  34       },
  35       'gener alPurposeJ dsServer':  {
  36             'baseUrl':  'http:// IP                ',
  37           'u rlLengthLi mit': 120
  38       },
  39       'jbpm' : {
  40             'baseUrl':  'http:// IP                ',
  41           'a piPath': ' /business- central/re st',
  42           'a dminUser':  {
  43                  'username' : ' RED A CTED ',
  44                  'password' : ' REDACTED '
  45           },
  46           'n urseUser':  {
  47                  'username' : ' REDACTED ',
  48                  'password' : ' REDACTED '
  49           },
  50           'h ealthcheck Endpoint':  '/history /instances '
  51       },
  52       'oracl edb': {
  53           'a ctivityDat abase': {
  54                'user':  'activityd buser',
  55                'passwor d': 'activ itydb$11',
  56                  'connectSt ring': ' IP                /xe'
  57           }
  58       },
  59       'activ ityManagem entJobRetr yLimit': 5 ,
  60   };
  61  
  62   var activi tyEventPro cessResour ceRepsonse  = {
  63       'name' : 'host-lo gger',
  64       'hostn ame': 'rdk -system-ma ster',
  65       'pid':  7919,
  66       'level ': 50,
  67       'messa ge': 'No m atches',
  68       'statu s': 200,
  69       'msg':  '',
  70       'time' : '2016-05 -16T13:44: 19.270Z',
  71       'v': 0
  72   };
  73  
  74   var mockVp rObject =  {
  75       'type' : 'activit y-manageme nt-event',
  76       'times tamp': '14 6549998687 8',
  77       'patie ntIdentifi er': {
  78           't ype': 'pid ',
  79           'v alue': 'C8 77;3'
  80       },
  81       'dataD omain': 'o rder',
  82       'recor d': {
  83           'c ontent': ' HEMOGLOBIN  A1C BLOOD    SP *UNS IGNED*\r\n ',
  84           'd isplayGrou p': 'CH',
  85           'e ntered': ' 2016060915 1900',
  86           'f acilityCod e': '507',
  87           'f acilityNam e': 'CAMP  BEE',
  88           'l astUpdateT ime': '201 6060915194 7',
  89           'l ocalId': ' 44243',
  90           'n ame': 'HEM OGLOBIN A1 C',
  91           'o iCode': 'u rn:va:oi:2 13',
  92           'o iName': 'H EMOGLOBIN  A1C',
  93           'o iPackageRe f': '97;99 LRT',
  94           'p roviderNam e': 'USER, PANORAMA',
  95           'p roviderUid ': 'urn:va :user:C877 :100000002 70',
  96           'l ocationUid ': 'urn:va :location: C877:158',
  97           's ervice': ' LR',
  98           's tampTime':  '20160609 151947',
  99           's tart': '',
  100           's tatusCode' : 'urn:va: order-stat us:unr',
  101           's tatusName' : 'UNRELEA SED',
  102           's tatusVuid' : 'urn:va: vuid:45011 24',
  103           's top': '',
  104           'u id': 'urn: va:order:C 877:3:4424 3',
  105           'p id': 'C877 ;3',
  106           'k ind': 'Lab oratory',
  107           'p roviderDis playName':  'User,Pan orama',
  108           's ummary': ' HEMOGLOBIN  A1C BLOOD    SP *UNS IGNED*\r\n '
  109       },
  110       'jobId ': '546c6e b0-b95c-4c 51-b999-e1 d62e432f3a '
  111   };
  112  
  113   var mockVp rObjectWit hClinicalO bject = {
  114       'autho rUid': 'ur n:va:user: C877:10000 000270',
  115       'creat ionDateTim e': '20160 614191226+ 0000',
  116       'data' : {
  117           'c ontent': ' HEMOGLOBIN  A1C BLOOD    SP *UNS IGNED*\r\n ',
  118           'd isplayGrou p': 'CH',
  119           'e ntered': ' 2016060915 1900',
  120           'f acilityCod e': '507',
  121           'f acilityNam e': 'CAMP  BEE',
  122           'k ind': 'Lab oratory',
  123           'l astUpdateT ime': '201 6060915194 7',
  124           'l ocalId': ' 44243',
  125           'n ame': 'HEM OGLOBIN A1 C',
  126           'o iCode': 'u rn:va:oi:2 13',
  127           'o iName': 'H EMOGLOBIN  A1C',
  128           'o iPackageRe f': '97;99 LRT',
  129           'p id': 'C877 ;3',
  130           'p roviderDis playName':  'User,Pan orama',
  131           'p roviderNam e': 'USER, PANORAMA',
  132           'p roviderUid ': 'urn:va :user:C877 :100000002 70',
  133           'l ocationUid ': 'urn:va :location: C877:158',
  134           's ervice': ' LR',
  135           's tampTime':  '20160609 151947',
  136           's tart': '',
  137           's tatusCode' : 'urn:va: order-stat us:unr',
  138           's tatusName' : 'UNRELEA SED',
  139           's tatusVuid' : 'urn:va: vuid:45011 24',
  140           's top': '',
  141           's ummary': ' HEMOGLOBIN  A1C BLOOD    SP *UNS IGNED*\r\n ',
  142           'u id': 'urn: va:order:C 877:3:4424 3'
  143       },
  144       'displ ayName': ' HEMOGLOBIN  A1C - ROU TINE',
  145       'domai n': 'ehmp- activity',
  146       'ehmpS tate': 'ac tive',
  147       'patie ntUid': 'u rn:va:pati ent:C877:3 :3',
  148       'refer enceId': ' urn:va:ord er:C877:3: 44243',
  149       'subDo main': 'la boratory',
  150       'uid':  'urn:va:e hmp-order: C877:3:0c9 0c33b-6d28 -4113-8f9d -598e392e6 e82',
  151       'visit ': {
  152           'd ateTime':  '201408141 30730',
  153           'l ocation':  'urn:va:lo cation:C87 7:158',
  154           's erviceCate gory': 'X'
  155       }
  156   };
  157  
  158   var mockVp rObjectWit hFakeClini calObject  = {
  159       'patie ntUid': 'u rn:va:pati ent:C877:3 :3',
  160       'autho rUid': 'ur n:va:user: C877:10000 000270',
  161       'domai n': 'ehmp- activity',
  162       'subDo main': 'la boratory',
  163       'refer enceId': ' urn:va:ord er:C877:3: 44243',
  164       'pid':  'C877;3',
  165       'ehmpS tate': 'ac tive',
  166       'visit ': {
  167           's erviceCate gory': 'LR ',
  168           'd ateTime':  '201606091 51900',
  169           'l ocation':  'urn:va:lo cation:C87 7:158'
  170       },
  171       'creat edDateTime ': '201606 09151947',
  172       'data' : {
  173           'c ontent': ' HEMOGLOBIN  A1C BLOOD    SP *UNS IGNED*\r\n ',
  174           'd isplayGrou p': 'CH',
  175           'e ntered': ' 2016060915 1900',
  176           'f acilityCod e': '507',
  177           'f acilityNam e': 'CAMP  BEE',
  178           'l astUpdateT ime': '201 6060915194 7',
  179           'l ocalId': ' 44243',
  180           'n ame': 'HEM OGLOBIN A1 C',
  181           'o iCode': 'u rn:va:oi:2 13',
  182           'o iName': 'H EMOGLOBIN  A1C',
  183           'o iPackageRe f': '97;99 LRT',
  184           'p roviderNam e': 'USER, PANORAMA',
  185           'p roviderUid ': 'urn:va :user:C877 :100000002 70',
  186           'l ocationUid ': 'urn:va :location: C877:158',
  187           's ervice': ' LR',
  188           's tampTime':  '20160609 151947',
  189           's tart': '',
  190           's tatusCode' : 'urn:va: order-stat us:unr',
  191           's tatusName' : 'UNRELEA SED',
  192           's tatusVuid' : 'urn:va: vuid:45011 24',
  193           's top': '',
  194           'u id': 'urn: va:order:C 877:3:4424 3',
  195           'p id': 'C877 ;3',
  196           'k ind': 'Lab oratory',
  197           'p roviderDis playName':  'User,Pan orama',
  198           's ummary': ' HEMOGLOBIN  A1C BLOOD    SP *UNS IGNED*\r\n '
  199       }
  200   };
  201  
  202   var mockNo nVprObject  = {
  203       'type' : 'activit y-manageme nt-event',
  204       'times tamp': '14 6550011005 8',
  205       'patie ntIdentifi er': {
  206           't ype': 'pid ',
  207           'v alue': 'C8 77;3'
  208       },
  209       'rootJ obId': '3f 580ed5-af3 3-4e67-832 6-7f5dee39 9987',
  210       'dataD omain': 'e hmp-order' ,
  211       'recor d': {
  212           'a uthorUid':  'urn:va:u ser:C877:1 0000000270 ',
  213           'p atientUid' : 'urn:va: patient:C8 77:3:3',
  214           'd omain': 'e hmp-order' ,
  215           's ubDomain':  'laborato ry',
  216           'v isit': {
  217                'service Category':  'X',
  218                'dateTim e': '20140 814130730' ,
  219                'locatio n': 'urn:v a:location :C877:158'
  220           },
  221           'r eferenceId ': 'urn:va :order:C87 7:3:44243' ,
  222           'd ata': {
  223                'availab leLabTests ': '213',
  224                'labTest Text': 'HE MOGLOBIN A 1C',
  225                'collect ionDate':  '06/09/201 6',
  226                'collect ionType':  'SP',
  227                'collect ionSample' : '3',
  228                'specime n': '70',
  229                'urgency ': '9',
  230                'urgency Text': 'RO UTINE',
  231                'notific ationDate' : '',
  232                'pastDue Date': '',
  233                'collect ionTime':  '',
  234                'otherCo llectionSa mple': '',
  235                'immedia teCollecti onDate': ' ',
  236                'immedia teCollecti onTime': ' ',
  237                'collect ionDateTim ePicklist' : '',
  238                'howOfte n': '',
  239                'howLong ': '',
  240                'otherSp ecimen': ' ',
  241                'forTest ': '',
  242                'doseDat e': '',
  243                'doseTim e': '',
  244                'drawDat e': '',
  245                'drawTim e': '',
  246                'orderCo mment': '' ,
  247                'anticoa gulant': ' ',
  248                'sampleD rawnAt': ' ',
  249                'urineVo lume': '',
  250                'additio nalComment s': '',
  251                'annotat ion': '',
  252                'problem Relationsh ip': '',
  253                'activit y': '',
  254                'isActiv ityEnabled ': ''
  255           },
  256           'e hmpState':  'active',
  257           'd isplayName ': 'HEMOGL OBIN A1C -  ROUTINE',
  258           'c reationDat eTime': '2 0160609192 149+0000',
  259           'u id': 'urn: va:ehmp-or der:C877:3 :0c1cd1e6- 9e24-4825- b020-703f4 85eedce'
  260       },
  261       'jobId ': '015ac5 da-4d6c-4f ba-8cfa-81 8c5c721bec '
  262   };
  263  
  264   var mockRe sponse = [ {
  265       'autho rUid': 'ur n:va:user: C877:10000 000270',
  266       'creat ionDateTim e': '20160 614191226+ 0000',
  267       'data' : {
  268           'c ontent': ' HEMOGLOBIN  A1C BLOOD    SP *UNS IGNED*\r\n ',
  269           'd isplayGrou p': 'CH',
  270           'e ntered': ' 2016060915 1900',
  271           'f acilityCod e': '507',
  272           'f acilityNam e': 'CAMP  BEE',
  273           'k ind': 'Lab oratory',
  274           'l astUpdateT ime': '201 6060915194 7',
  275           'l ocalId': ' 44243',
  276           'n ame': 'HEM OGLOBIN A1 C',
  277           'o iCode': 'u rn:va:oi:2 13',
  278           'o iName': 'H EMOGLOBIN  A1C',
  279           'o iPackageRe f': '97;99 LRT',
  280           'p id': 'C877 ;3',
  281           'p roviderDis playName':  'User,Pan orama',
  282           'p roviderNam e': 'USER, PANORAMA',
  283           'p roviderUid ': 'urn:va :user:C877 :100000002 70',
  284           'l ocationUid ': 'urn:va :location: C877:158',
  285           's ervice': ' LR',
  286           's tampTime':  '20160609 151947',
  287           's tart': '',
  288           's tatusCode' : 'urn:va: order-stat us:unr',
  289           's tatusName' : 'UNRELEA SED',
  290           's tatusVuid' : 'urn:va: vuid:45011 24',
  291           's top': '',
  292           's ummary': ' HEMOGLOBIN  A1C BLOOD    SP *UNS IGNED*\r\n ',
  293           'u id': 'urn: va:order:C 877:3:4424 3'
  294       },
  295       'displ ayName': ' HEMOGLOBIN  A1C - ROU TINE',
  296       'domai n': 'ehmp- order',
  297       'ehmpS tate': 'ac tive',
  298       'patie ntUid': 'u rn:va:pati ent:C877:3 :3',
  299       'refer enceId': ' urn:va:ord er:C877:3: 44243',
  300       'subDo main': 'la boratory',
  301       'uid':  'urn:va:e hmp-order: C877:3:0c9 0c33b-6d28 -4113-8f9d -598e392e6 e82',
  302       'visit ': {
  303           'd ateTime':  '201408141 30730',
  304           'l ocation':  'urn:va:lo cation:C87 7:158',
  305           's erviceCate gory': 'X'
  306       }
  307   }];
  308  
  309   function v alidateJob Object(key , job) {
  310       descri be('valida teJobObjec t for ' +  key, funct ion() {
  311           va r isVpr =  _.isUndefi ned(job.re cord);
  312           it (key + ' s hould retu rn an erro r because  the visit  key is mis sing', fun ction() {
  313                var miss ingVisit =  isVpr ? _ .omit(job,  'visit')  : _.omit(j ob.record,  'visit');
  314                activity Helper.val idateJobOb ject(missi ngVisit, l ogger, fun ction(resu lt) {
  315                    expe ct(result) .to.eql('j ob does no t have a v isit key') ;
  316                });
  317           }) ;
  318  
  319           it (key + ' s hould retu rn an erro r because  the data i s empty a  value for  a required  data fiel d', functi on() {
  320                var miss ingData =  isVpr ? _. cloneDeep( job) : _.c loneDeep(j ob.record) ;
  321                missingD ata.ehmpSt ate = '';
  322  
  323                activity Helper.val idateJobOb ject(missi ngData, lo gger, func tion(resul t) {
  324                    expe ct(result) .to.eql('m odel is mi ssing a va lue for th e ehmpStat e field');
  325                });
  326           }) ;
  327  
  328           it (key + ' s hould retu rn an erro r because  the data i s empty a  value for  a required  visit fie ld', funct ion() {
  329                var miss ingVisitDa ta = isVpr  ? _.clone Deep(job)  : _.cloneD eep(job.re cord);
  330                missingV isitData.v isit.dateT ime = '';
  331  
  332                activity Helper.val idateJobOb ject(missi ngVisitDat a, logger,  function( result) {
  333                    expe ct(result) .to.eql('m odel is mi ssing a va lue for th e dateTime  field');
  334                });
  335           }) ;
  336  
  337           it (key + ' s hould retu rn an erro r because  the data i s null a v alue for a  required  data field ', functio n() {
  338                var miss ingData =  isVpr ? _. cloneDeep( job) : _.c loneDeep(j ob.record) ;
  339                missingD ata.ehmpSt ate = null ;
  340  
  341                activity Helper.val idateJobOb ject(missi ngData, lo gger, func tion(resul t) {
  342                    expe ct(result) .to.eql('m odel is mi ssing a va lue for th e ehmpStat e field');
  343                });
  344           }) ;
  345  
  346           it (key + ' s hould retu rn an erro r because  the data i s null a v alue for a  required  visit fiel d', functi on() {
  347                var miss ingVisitDa ta = isVpr  ? _.clone Deep(job)  : _.cloneD eep(job.re cord);
  348                missingV isitData.v isit.dateT ime = null ;
  349  
  350                activity Helper.val idateJobOb ject(missi ngVisitDat a, logger,  function( result) {
  351                    expe ct(result) .to.eql('m odel is mi ssing a va lue for th e dateTime  field');
  352                });
  353           }) ;
  354  
  355           it (key + ' s hould retu rn no erro r', functi on() {
  356                var jobO bject = is Vpr ? job  : job.reco rd;
  357                activity Helper.val idateJobOb ject(jobOb ject, logg er, functi on(result)  {
  358                    expe ct(result) .to.eql(nu ll);
  359                });
  360           }) ;
  361       });
  362   }
  363  
  364   describe(' activity-m anagement- event-hand ler-spec.j s', functi on() {
  365  
  366       var mo ckActivity EventProce ss;
  367       var mo ckIsSecond arySite;
  368       var mo ckClincial ObjectsSub system;
  369       var mo ckPidValid ator;
  370       before Each(funct ion() {
  371           lo gger._leve l = 50;
  372           mo ckActivity EventProce ss = sinon .stub(acti vityEventP rocess, 's tartActivi tyEvent',  function(r eq, res) {
  373                return r es.status( 200).rdkSe nd(activit yEventProc essResourc eRepsonse) ;
  374           }) ;
  375           mo ckIsSecond arySite =  sinon.stub (pidValida tor, 'isSe condarySit e');
  376           mo ckIsSecond arySite.re turns(fals e);
  377           va r clonedMo ckResponse  = _.clone Deep(mockR esponse);
  378           mo ckClincial ObjectsSub system = s inon.stub( clincialOb jectsSubsy stem, 'fin d', functi on(logger,  appConfig , model, l oadReferen ce, callba ck) {
  379                return c allback(nu ll, {
  380                    'ite ms': clone dMockRespo nse
  381                });
  382           }) ;
  383           mo ckPidValid ator = sin on.stub(pi dValidator , 'isPrima rySite');
  384           mo ckPidValid ator.retur ns(true);
  385       });
  386  
  387       afterE ach(functi on() {
  388           mo ckActivity EventProce ss.restore ();
  389           mo ckIsSecond arySite.re store();
  390           mo ckClincial ObjectsSub system.res tore();
  391           mo ckPidValid ator.resto re();
  392           lo gger._leve l = 40;
  393       });
  394  
  395       descri be('valida teJobObjec t', functi on() {
  396           va r testable Objects =  {
  397                'mockVpr ObjectWith ClinicalOb ject': moc kVprObject WithClinic alObject,
  398                'mockVpr ObjectWith FakeClinic alObject':  mockVprOb jectWithFa keClinical Object,
  399                'mockNon VprObject' : mockNonV prObject
  400           };
  401           va r testable ObjectsKey s = Object .keys(test ableObject s);
  402           fo r (var i =  0; i < te stableObje ctsKeys.le ngth; i++)  {
  403                var key  = testable ObjectsKey s[i];
  404                validate JobObject( key, testa bleObjects [key]);
  405           }
  406       });
  407  
  408       descri be('handle ', functio n() {
  409           it ('Should e rror becau se of an e mpty job',  function( ) {
  410                handler( logger, co nfig, env,  null, fun ction(erro r, result)  {
  411                    expe ct(error). to.eql('Jo b was empt y, null, o r undefine d');
  412                });
  413           }) ;
  414  
  415           it ('Should e rror becau se the sit e is not p rimary', f unction()  {
  416                mockIsSe condarySit e.restore( );
  417                mockIsSe condarySit e = sinon. stub(pidVa lidator, ' isSecondar ySite');
  418                mockIsSe condarySit e.returns( true);
  419                handler( logger, co nfig, env,  mockVprOb ject, func tion(error , result)  {
  420                    expe ct(error). to.eql(nul l);
  421                    expe ct(result) .to.eql(nu ll);
  422                });
  423           }) ;
  424  
  425           it ('Should n ot error b ecause the  site is p rimary', f unction()  {
  426                handler( logger, co nfig, env,  mockNonVp rObject, f unction(er ror, resul t) {
  427                    expe ct(false). to.eql(moc kIsSeconda rySite.ret urnValues[ 0]);
  428                });
  429           }) ;
  430  
  431           it ('Should e rror becau se the Non -VPR Objec t referenc eId is emp ty', funct ion() {
  432                var nonV prEmptyRef erenceId =  _.cloneDe ep(mockNon VprObject) ;
  433                nonVprEm ptyReferen ceId.recor d.referenc eId = '';
  434                handler( logger, co nfig, env,  nonVprEmp tyReferenc eId, funct ion(error,  result) {
  435                    expe ct(error). to.eql(nul l);
  436                    expe ct(result) .to.eql(nu ll);
  437                });
  438           }) ;
  439  
  440           it ('Should e rror becau se the Non -VPR Objec t referenc eId is und efined', f unction()  {
  441                var nonV prRecordNo ReferenceI d = _.omit (mockNonVp rObject.re cord, 'ref erenceId') ;
  442                var nonV prNoRefere nceId = _. cloneDeep( mockNonVpr Object);
  443                nonVprNo ReferenceI d.record =  nonVprRec ordNoRefer enceId;
  444                handler( logger, co nfig, env,  nonVprNoR eferenceId , function (error, re sult) {
  445                    expe ct(error). to.eql(nul l);
  446                    expe ct(result) .to.eql(nu ll);
  447                });
  448           }) ;
  449  
  450           it ('Should e rror becau se findCli nicalObjec t returned  an error' , function () {
  451                mockClin cialObject sSubsystem .restore() ;
  452                mockClin cialObject sSubsystem  = sinon.s tub(clinci alObjectsS ubsystem,  'find', fu nction(log ger, appCo nfig, mode l, loadRef erence, ca llback) {
  453                    retu rn callbac k('Failed  to read th e notes fr om pJDS.') ;
  454                });
  455                handler( logger, co nfig, env,  mockNonVp rObject, f unction(er ror, resul t) {
  456                    expe ct(error). to.eql('Fa iled to re ad the not es from pJ DS.');
  457                });
  458           }) ;
  459  
  460           it ('Should b e a genera ted clinic alObject',  function( ) {
  461                mockActi vityEventP rocess.res tore();
  462                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  463                    retu rn res.sta tus(200).r dkSend(req .body);
  464                });
  465                mockClin cialObject sSubsystem .restore() ;
  466                mockClin cialObject sSubsystem  = sinon.s tub(clinci alObjectsS ubsystem,  'find', fu nction(log ger, appCo nfig, mode l, loadRef erence, ca llback) {
  467                    retu rn callbac k(['Clinic al object  not found' ]);
  468                });
  469                handler( logger, co nfig, env,  mockVprOb ject, func tion(error , result)  {
  470                    dele te result. data.activ ityRetry;
  471                    expe ct(error). to.eql(nul l);
  472                    expe ct(_.omit( result, 's tatus')).t o.eql(mock VprObjectW ithFakeCli nicalObjec t);
  473                });
  474           }) ;
  475  
  476           it ('Should c hange a VP R object d omain to e hmp-activi ty', funct ion() {
  477                mockActi vityEventP rocess.res tore();
  478                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  479                    retu rn res.sta tus(200).r dkSend(req .body);
  480                });
  481                handler( logger, co nfig, env,  mockVprOb ject, func tion(error , result)  {
  482                    dele te result. data.activ ityRetry;
  483                    expe ct(error). to.eql(nul l);
  484                    expe ct(_.omit( result, 's tatus')).t o.eql(mock VprObjectW ithClinica lObject);
  485                });
  486           }) ;
  487  
  488           it ('Should r eturn null  because t he respons e was empt y and it g ot a Non-V PR object' , function () {
  489                mockClin cialObject sSubsystem .restore() ;
  490                mockClin cialObject sSubsystem  = sinon.s tub(clinci alObjectsS ubsystem,  'find', fu nction(log ger, appCo nfig, mode l, loadRef erence, ca llback) {
  491                    retu rn callbac k(['Clinic al object  not found' ]);
  492                });
  493                handler( logger, co nfig, env,  mockNonVp rObject, f unction(er ror, resul t) {
  494                    expe ct(error). to.eql(nul l);
  495                    expe ct(result) .to.eql(nu ll);
  496                });
  497           }) ;
  498  
  499           it ('Should h ave the re sponse (VP R) data in  the newre cord.data  key', func tion() {
  500                mockActi vityEventP rocess.res tore();
  501                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  502                    retu rn res.sta tus(200).r dkSend(req .body);
  503                });
  504                handler( logger, co nfig, env,  mockVprOb ject, func tion(error , result)  {
  505                    expe ct(error). to.eql(nul l);
  506                    expe ct(result. data).to.e ql(mockVpr Object.rec ord);
  507                });
  508           }) ;
  509  
  510           it ('Should h ave the re cord (Non- VPR) data  in the new record.dat a key', fu nction() {
  511                mockActi vityEventP rocess.res tore();
  512                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  513                    retu rn res.sta tus(200).r dkSend(req .body);
  514                });
  515                handler( logger, co nfig, env,  mockNonVp rObject, f unction(er ror, resul t) {
  516                    expe ct(error). to.eql(nul l);
  517                    expe ct(result. data).to.e ql(mockRes ponse[0].d ata);
  518                });
  519           }) ;
  520  
  521           it ('Should r eturn call back', fun ction() {
  522                handler( logger, co nfig, env,  mockVprOb ject, func tion(error , result)  {
  523                    expe ct(error). to.eql(nul l);
  524                    expe ct(result. message).t o.eql('No  matches');
  525                });
  526           }) ;
  527       });
  528  
  529       descri be('cleanC linicalObj ectRespons eArray', f unction()  {
  530           va r clonedRe sponse = _ .cloneDeep (mockRespo nse[0]);
  531           cl onedRespon se.domain  = 'ehmp-ac tivity';
  532  
  533           it ('Should o nly return  one objec t with dom ain of ehm p-order; s ingle resp onse', fun ction() {
  534                var resp onse = act ivityHelpe r.cleanCli nicalObjec tResponseA rray(mockR esponse, l ogger, {}) ;
  535                expect(r esponse).t o.eql(mock Response[0 ]);
  536           }) ;
  537  
  538           it ('Should o nly return  one objec t with dom ain of ehm p-order; m ultiple re sponse onl y one ehmp -order', f unction()  {
  539                var resp onse = act ivityHelpe r.cleanCli nicalObjec tResponseA rray(mockR esponse, l ogger, {}) ;
  540                expect(r esponse).t o.eql(mock Response[0 ]);
  541           }) ;
  542  
  543           it ('Should e rror out b ecause no  ehmp-order  domain fo und in res ponses; si ngle respo nses', fun ction() {
  544                activity Helper.cle anClinical ObjectResp onseArray( clonedResp onse, logg er, functi on(error,  response)  {
  545                    expe ct(respons e).to.eql( null);
  546                    expe ct(respons e).to.eql( null);
  547                });
  548           }) ;
  549  
  550           it ('Should e rror out b ecause no  ehmp-order  domain fo und in res ponses; mu ltiple res ponses', f unction()  {
  551                activity Helper.cle anClinical ObjectResp onseArray( mockRespon se, logger , function (error, re sponse) {
  552                    expe ct(respons e).to.eql( null);
  553                    expe ct(respons e).to.eql( null);
  554                });
  555           }) ;
  556       });
  557  
  558       descri be('create RequestObj ect', func tion() {
  559           va r body = {
  560                'data':  {
  561                    'a':  'b',
  562                    'x':  'y'
  563                },
  564                'group':  ['one', 2 , '3'],
  565                'id': 'x xx:xx:xxxx -xxx'
  566           };
  567           va r config =  {
  568                'databas e': {
  569                    'use r': 'abcd' ,
  570                    'pas s': '1234'
  571                },
  572                'log': ' warn'
  573           };
  574           va r req = ac tivityHelp er.createR equestObje ct(body, c onfig, log ger);
  575           it ('Should h ave 3 keys , the firs t key is a n object a nd the sec ond key is  an array,  and the t hird is a  string', f unction()  {
  576                expect(O bject.keys (req.body) .length).t o.eql(3);
  577                expect(t ypeof req. body.data) .to.eql('o bject');
  578                expect(r eq.body.da ta.a).to.e ql('b');
  579                expect(_ .isArray(r eq.body.gr oup)).to.e ql(true);
  580                expect(r eq.body.gr oup[1]).to .eql(2);
  581                expect(t ypeof req. body.id).t o.eql('str ing');
  582                expect(r eq.body.id ).to.eql(' xxx:xx:xxx x-xxx');
  583           }) ;
  584  
  585           it ('Should h ave 2 keys , the firs t is an ob ject and t he second  is a strin g', functi on() {
  586                expect(O bject.keys (req.app.c onfig).len gth).to.eq l(2);
  587                expect(t ypeof req. app.config .database) .to.eql('o bject');
  588                expect(r eq.app.con fig.databa se.user).t o.eql('abc d');
  589                expect(t ypeof req. app.config .log).to.e ql('string ');
  590                expect(r eq.app.con fig.log).t o.eql('war n');
  591           }) ;
  592       });
  593  
  594       descri be('create ResponseOb ject', fun ction() {
  595           va r error, r esponse;
  596           va r res = ac tivityHelp er.createR esponseObj ect(logger , function (err, data ) {
  597                error =  err;
  598                response  = data;
  599           }) ;
  600           it ('Should s et status  to 800 and  return th at with th e callback ', functio n() {
  601                res.stat us(800).se nd(res.sta tusCode);
  602                expect(e rror).to.e ql(800);
  603           }) ;
  604  
  605           it ('Should r eturn the  callback w hen res.se nd() is ca lled', fun ction() {
  606                res.stat us(200).se nd(null, ' Testing ca llback');
  607                expect(r esponse).t o.eql('Tes ting callb ack');
  608           }) ;
  609  
  610           it ('Should s end back t he message  as an err or', funct ion() {
  611                res.stat us(204).rd kSend('Thi s should c ome back u ndefined') ;
  612                expect(e rror.messa ge).to.eql ('This sho uld come b ack undefi ned');
  613           }) ;
  614  
  615           it ('Should s end an err or that th e body is  null but t he status  is 200.',  function()  {
  616                res.stat us(200).rd kSend(null , null);
  617                expect(e rror.messa ge).to.eql ('Error -  Activity E vent Proce ssor retur n an empty  or null b ody.');
  618           }) ;
  619  
  620           it ('Should s end an err or that th e body is  undefined  but the st atus is 20 0.', funct ion() {
  621                res.stat us(200).rd kSend(null , undefine d);
  622                expect(e rror.messa ge).to.eql ('Error -  Activity E vent Proce ssor retur n an empty  or null b ody.');
  623           }) ;
  624  
  625           it ('Should h ave the co ntent in t he data ke y', functi on() {
  626                res.stat us(200).rd kSend({
  627                    'use r': 'pass'
  628                });
  629                expect(r esponse).t o.eql({
  630                    'dat a': {
  631                         'user': 'p ass'
  632                    }
  633                });
  634           }) ;
  635  
  636           it ('Should g et process ed into JS ON and hav e the cont ent in the  data key' , function () {
  637                res.stat us(200).se t('Content -Type', 'a pplication /json').rd kSend('{"u serString" : "passStr ing"}');
  638                expect(r esponse).t o.eql({
  639                    'dat a': {
  640                         'userStrin g': 'passS tring'
  641                    }
  642                });
  643           }) ;
  644  
  645           it ('Should g et passed  back as a  string bec ause the J SON is inv alid', fun ction() {
  646                res.stat us(200).se t('Content -Type', 'a pplication /json').rd kSend('{\' userString \': \'pass String\'}' );
  647                expect(r esponse).t o.eql({
  648                    'mes sage': '{\ 'userStrin g\': \'pas sString\'} '
  649                });
  650           }) ;
  651  
  652           it ('Should c ome back i n {message : body} fo rmat where  body is a  string',  function()  {
  653                res.stat us(200).rd kSend('Thi s should c ome back i n the mess age key');
  654                expect(r esponse).t o.eql({
  655                    mess age: 'This  should co me back in  the messa ge key'
  656                });
  657           }) ;
  658       });
  659  
  660       descri be('passOr derToProce ssor', fun ction() {
  661           it ('Should p ass into r eq creatio n as an ob ject', fun ction() {
  662                mockActi vityEventP rocess.res tore();
  663                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  664                    retu rn res.sta tus(200).r dkSend(req .body);
  665                });
  666                activity Helper.pas sOrderToPr ocessor({
  667                    data : {
  668                         user: 'pas s'
  669                    }
  670                }, mockV prObject,  config, lo gger, env,  function( ) {
  671                    retu rn;
  672                }, funct ion(error,  result) {
  673                    expe ct(error). to.eql(nul l);
  674                    expe ct(result) .to.eql({
  675                         data: {
  676                             user:  'pass'
  677                         }
  678                    });
  679                });
  680           }) ;
  681  
  682           it ('Should c onvert the  string to  a JSON ob ject', fun ction() {
  683                mockActi vityEventP rocess.res tore();
  684                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  685                    retu rn res.sta tus(200).r dkSend(req .body);
  686                });
  687                activity Helper.pas sOrderToPr ocessor('{ "data": {" user": "pa ss"}}', mo ckVprObjec t, config,  logger, e nv, functi on() {
  688                    retu rn;
  689                }, funct ion(error,  result) {
  690                    expe ct(error). to.eql(nul l);
  691                    expe ct(result) .to.eql({
  692                         data: {
  693                             user:  'pass'
  694                         }
  695                    });
  696                });
  697           }) ;
  698  
  699           it ('Should e rror becau se of bad  string JSO N', functi on() {
  700                mockActi vityEventP rocess.res tore();
  701                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  702                    retu rn res.sta tus(200).r dkSend('ig nored for  this test' );
  703                });
  704                activity Helper.pas sOrderToPr ocessor('{ \'data\':  {\'user\':  \'pass\'} }', mockVp rObject, c onfig, log ger, env,  function()  {
  705                    retu rn;
  706                }, funct ion(error,  result) {
  707                    expe ct(error.m essage).to .match(/Un expected t oken/);
  708                    expe ct(result) .to.eql(nu ll);
  709                });
  710           }) ;
  711  
  712           it ('Should r eturn a wo rking requ est object ', functio n() {
  713                mockActi vityEventP rocess.res tore();
  714                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  715                    retu rn res.sta tus(200).r dkSend(req );
  716                });
  717                activity Helper.pas sOrderToPr ocessor({
  718                    data : {
  719                         user: 'pas s'
  720                    }
  721                }, mockV prObject,  config, lo gger, env,  function( ) {
  722                    retu rn;
  723                }, funct ion(error,  result) {
  724                    expe ct(error). to.eql(nul l);
  725                    expe ct(Object. keys(resul t)).to.eql (['data']) ;
  726                });
  727           }) ;
  728  
  729           it ('Should r eturn the  input beca use it is  an object' , function () {
  730                mockActi vityEventP rocess.res tore();
  731                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  732                    retu rn res.sen d(null, {
  733                         data: {
  734                             user:  'pass'
  735                         }
  736                    });
  737                });
  738                activity Helper.pas sOrderToPr ocessor({
  739                    'thi s': 'is ig nored'
  740                }, mockV prObject,  config, lo gger, env,  function( ) {
  741                    retu rn;
  742                }, funct ion(error,  result) {
  743                    expe ct(error). to.eql(nul l);
  744                    expe ct(result) .to.eql({
  745                         data: {
  746                             user:  'pass'
  747                         }
  748                    });
  749                });
  750           }) ;
  751  
  752           it ('Should t ry to JSON ify the re sponse', f unction()  {
  753                mockActi vityEventP rocess.res tore();
  754                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  755                    retu rn res.sen d(null, '{ "data": {" user": "pa ss"}}');
  756                });
  757                activity Helper.pas sOrderToPr ocessor({
  758                    'thi s': 'is ig nored'
  759                }, mockV prObject,  config, lo gger, env,  function( ) {
  760                    retu rn;
  761                }, funct ion(error,  result) {
  762                    expe ct(error). to.eql(nul l);
  763                    expe ct(result) .to.eql({
  764                         data: {
  765                             user:  'pass'
  766                         }
  767                    });
  768                });
  769           }) ;
  770  
  771           it ('Should c atch the b ad JSON an d return a n error',  function()  {
  772                mockActi vityEventP rocess.res tore();
  773                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  774                    retu rn res.sen d(null, '{ \'data\':  {\'user\':  \'pass\'} }');
  775                });
  776                activity Helper.pas sOrderToPr ocessor({
  777                    'thi s': 'is ig nored'
  778                }, mockV prObject,  config, lo gger, env,  function( ) {
  779                    retu rn;
  780                }, funct ion(error,  result) {
  781                    expe ct(error.m essage).to .match(/Un expected t oken/);
  782                    expe ct(result) .to.eql(nu ll);
  783                });
  784           }) ;
  785  
  786           it ('Should r eturn the  body.messa ge if stat us is not  200', func tion() {
  787                mockActi vityEventP rocess.res tore();
  788                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  789                    retu rn res.sta tus(204).r dkSend({
  790                         message: ' 245 - Bad  response'
  791                    });
  792                });
  793                activity Helper.pas sOrderToPr ocessor({
  794                    'thi s': 'is ig nored'
  795                }, mockV prObject,  config, lo gger, env,  function( ) {
  796                    retu rn;
  797                }, funct ion(error,  result) {
  798                    expe ct(error.m essage).to .eql('245  - Bad resp onse');
  799                    expe ct(result) .to.eql(nu ll);
  800                });
  801           }) ;
  802  
  803           it ('Should r eturn succ ess', func tion() {
  804                mockActi vityEventP rocess.res tore();
  805                mockActi vityEventP rocess = s inon.stub( activityEv entProcess , 'startAc tivityEven t', functi on(req, re s) {
  806                    retu rn res.sta tus(200).r dkSend(req .body);
  807                });
  808                activity Helper.pas sOrderToPr ocessor({
  809                    'dat a': {
  810                         'this': 'P assed thro ugh mockAE P'
  811                    }
  812                }, mockV prObject,  config, lo gger, env,  function( ) {
  813                    retu rn;
  814                }, funct ion(error,  result) {
  815                    expe ct(error). to.eql(nul l);
  816                    expe ct(result) .to.eql({
  817                         'data': {
  818                             'this' : 'Passed  through mo ckAEP'
  819                         }
  820                    });
  821                });
  822           }) ;
  823       });
  824   });