3854. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/9/2017 3:50:56 PM Eastern 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.

3854.1 Files compared

# Location File Last Modified
1 Fri Jun 9 19:50:56 2017 UTC
2 eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\VAP_CIF_CODE0502.zip\VAP_CIF_CODE0502\VAP_CIF_CODE0502\nvap-server\src\main\java\gov\va\nvap\server\announce\jpa AnnouncementJpaController.java Fri Apr 21 20:03:28 2017 UTC

3854.2 Comparison summary

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

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

3854.4 Active regular expressions

No regular expressions were active.

3854.5 Comparison detail

        1   /*
        2    * To chan ge this te mplate, ch oose Tools  | Templat es
        3    * and ope n the temp late in th e editor.
        4    */
        5   package go v.va.nvap. server.ann ounce.jpa;
        6  
        7   import gov .va.nvap.c ommon.vali dation.Nul lChecker;
        8   import gov .va.nvap.p rivacy.Con sentType;
        9   import gov .va.nvap.s erver.anno unce.Annou ncerContro llerInterf ace;
        10   import gov .va.nvap.s vc.consent mgmt.PIPIn terface;
        11   import gov .va.nvap.s vc.consent mgmt.jpa.O rganizatio nsJpaContr oller;
        12   import gov .va.nvap.s vc.consent mgmt.jpa.e xceptions. Nonexisten tEntityExc eption;
        13   import gov .va.nvap.s vc.consent mgmt.stub. adapter.an nounce.dat a.Announce ment;
        14   import gov .va.nvap.s vc.consent mgmt.stub. adapter.an nounce.dat a.Announce mentBatchS ummary;
        15   import gov .va.nvap.s vc.consent mgmt.stub. data.Conse ntDirectiv e;
        16   import gov .va.nvap.s vc.consent mgmt.stub. data.Organ ization;
        17  
        18   import jav a.math.Big Decimal;
        19   import jav a.util.Arr ayList;
        20   import jav a.util.Col lection;
        21   import jav a.util.Dat e;
        22   import jav a.util.Has hMap;
        23   import jav a.util.Has hSet;
        24   import jav a.util.Lis t;
        25   import jav a.util.UUI D;
        26  
        27   import jav ax.persist ence.Entit yManager;
        28   import jav ax.persist ence.Entit yNotFoundE xception;
        29   import jav ax.persist ence.Persi stenceCont ext;
        30   import jav ax.persist ence.Query ;
        31  
        32   import org .springfra mework.bea ns.factory .annotatio n.Required ;
        33  
        34   /**
        35    * 
        36    * @author  vhaislegb erb
        37    * @author  Irakli Ka kushadze
        38    * @author  Zack Pete rson
        39    */
        40   public cla ss Announc ementJpaCo ntroller i mplements  AnnouncerC ontrollerI nterface {
        41  
        42           pr ivate stat ic final i nt MAX_RES ULTS = 100 00;
        43  
        44           @P ersistence Context(na me = "VapE ntityManag er")
        45           pr ivate Enti tyManager  em;
        46  
        47           /* *
        48            *  The polic y informat ion point.
        49            * /
        50           pr ivate PIPI nterface p ip;
        51           
        52           @R equired
        53           pu blic void  setPip(fin al PIPInte rface pip)  {
        54                    this .pip = pip ;
        55           }
        56           
        57           @O verride
        58           pu blic void  create(fin al Announc ement anno uncement)  {
        59                    this .em.persis t(announce ment);
        60           }
        61  
        62           @O verride
        63           pu blic Strin g createAn nounceBatc h(final Or ganization  targetOrg anization,
        64                             final  String use rId, final  Date date RangeStart ,
        65                             final  Date dateR angeStop,  final bool ean reanno unce) {
        66       
        67                    if ( targetOrga nization = = null) {
        68                             throw  new Illega lArgumentE xception(
        69                                               "Target or ganization  must not  be null wh en created  a announc ement batc h.");
        70                    }
        71  
        72                    // c reate a un ique ident ifier for  the batch
        73                    fina l String b atchId = U UID.random UUID().toS tring();
        74  
        75                    fina l StringBu ilder sbQu eryName =  new String Builder(
        76                                      "Consent Directive. active.not Excluded") ;
        77                    sbQu eryName
        78                                      .append( ((dateRang eStart !=  null) && ( dateRangeS top == nul l)) ? ".cr eatedAfter tDate"
        79                                                       :  "")
        80                                      .append( ((dateRang eStart ==  null) && ( dateRangeS top != nul l)) ? ".cr eatedBefor eDate"
        81                                                       :  "")
        82                                      .append( ((dateRang eStart !=  null) && ( dateRangeS top != nul l)) ? ".cr eatedBetwe enDates"
        83                                                       :  "");
        84  
        85                    if ( reannounce ) {
        86                             sbQuer yName.appe nd(".Reann ounce");
        87                    }
        88                    int  firstResul t = 0;
        89  
        90                    // S etting the  Consent T ypes here.  For now,  only non-c onsumer Nw Hin Organi zations ar e being us ed for bat ch announc ements.
        91                    // W hen we add  batch ann ouncements  for SSA,  additional  logic wil l need to  be added h ere.
        92                    fina l gov.va.n vap.svc.co nsentmgmt. stub.data. ConsentTyp e consentT ypeAuthori ze = this. pip.getCon sentTypeBy Name(Conse ntType.NW_ HIN_AUTHOR IZATION.va lue());
        93                    //fi nal gov.va .nvap.svc. consentmgm t.stub.dat a.ConsentT ype consen tTypeRestr ict = this .pip.getCo nsentTypeB yName(Cons entType.NW _HIN_ORGAN IZATION_RE STRICTION_ AUTHORIZAT ION.value( ));
        94  
        95                    List <ConsentDi rective> c onsentDire ctives = n ull;
        96                    fina l Date ann ounceCreat eDate = ne w Date();
        97  
        98                    //Sy stem.out.p rintln("** ********** ********** ********** ********** ********** *********" );
        99                    //Sy stem.out.p rintln("Da teTime bef ore starti ng do loop : " + new  Date());
        100                    //Sy stem.out.p rintln("** ********** ********** ********** ********** ********** *********" );
        101                    
        102                    do {                      
        103                             Query  q = this.e m.createNa medQuery(s bQueryName .toString( ));
        104                             q.setP arameter(" consentTyp eAuthorize ", consent TypeAuthor ize);                     
        105                             //q.se tParameter ("consentT ypeRestric t", consen tTypeRestr ict);
        106                             
        107                             if (da teRangeSta rt != null ) {
        108                                      q.setPar ameter("af terDate",  dateRangeS tart);                               
        109                             }
        110                             if (da teRangeSto p != null)  {
        111                                      q.setPar ameter("be foreDate",  dateRange Stop);
        112                             }
        113  
        114                             //Syst em.out.pri ntln("befo reDate Dat e: " + dat eRangeStop .toString( ));
        115                             //Syst em.out.pri ntln("firs tResult: "  + firstRe sult);
        116                             
        117                             if (!r eannounce)  {
        118                    //Lo ok up the  organizati on through  the DAO t o prevent  constructi on of quer y with use r-defined  data.
        119                    Orga nizationsJ paControll er orgJpaC ontroller  = new Orga nizationsJ paControll er();
        120                    Orga nization v alidatedOr g = orgJpa Controller .findOrgan izationByO id(targetO rganizatio n.getOrgOi d());
        121                    if ( !NullCheck er.isNullO rEmpty(val idatedOrg) ) {
        122                         q.setParam eter("targ etedOrgani zation", v alidatedOr g);
        123                    }
        124                    cons entDirecti ves = q.se tMaxResult s(Announce mentJpaCon troller.MA X_RESULTS) .getResult List();
        125                             }else{
        126                                      consentD irectives  = q.setFir stResult(f irstResult  * Announc ementJpaCo ntroller.M AX_RESULTS )
        127                                      .setMaxR esults(Ann ouncementJ paControll er.MAX_RES ULTS).getR esultList( );                            
        128                             }
        129                             
        130                             for (f inal Conse ntDirectiv e cd : con sentDirect ives) {
        131                                      /*if (!r eannounce)  {
        132                                               q = this.e m
        133                                               .createNam edQuery("A nnouncemen t.findByCo nsentDirec tiveAndTar getOrg");
        134                                               q.setParam eter("cons entDirecti ve", cd);
        135                                               q.setParam eter("orga nization",  targetOrg anization) ;
        136                                               try {
        137                                                       fi nal List r esults = q .getResult List();
        138                                                       if  (NullChec ker.isNotE mpty(resul ts)) {
        139                                                                cont inue;
        140                                                       }
        141                                               } catch (f inal NoRes ultExcepti on nre) {
        142                                                       //  this is i ndicative  of no anno uncement a lready exi ting
        143                                                       //  for conse nt directi ve at targ et organiz ation.
        144                                               }
        145                                      }*/
        146  
        147                                      // creat e a new an nouncement  and persi st it in t he table.
        148                                      final An nouncement  announcem ent = new  Announceme nt();
        149                                      announce ment.setBa tchId(batc hId);
        150                                      announce ment.setUs erId(userI d);
        151                                      announce ment.setPa tientConse ntDir(cd);
        152                                      announce ment.setTa rgetOrgani zation(tar getOrganiz ation);
        153                                      announce ment.setCr eatedTs(an nounceCrea teDate);
        154  
        155                                      //System .out.print ln("Consen t Directiv e ID: " +  cd.getCons entDirId() );
        156  
        157                                      this.em. persist(an nouncement );
        158                             }
        159                             firstR esult++;                    
        160                             
        161                             //Syst em.out.pri ntln("---- ---------- ---------- ---------- ---------- ---------- -------");
        162                             //Syst em.out.pri ntln("Date Time after  finishing  " + first Result + "  loop(s) o f while: "  + new Dat e());
        163                             //Syst em.out.pri ntln("---- ---------- ---------- ---------- ---------- ---------- -------");
        164  
        165                    } wh ile ((cons entDirecti ves != nul l)
        166                                      && (cons entDirecti ves.size()  == Announ cementJpaC ontroller. MAX_RESULT S));
        167  
        168                    //Sy stem.out.p rintln("** ********** ********** ********** ********** ********** *********" );
        169                    //Sy stem.out.p rintln("Da teTime aft er finishi ng do loop : " + new  Date());
        170                    //Sy stem.out.p rintln("** ********** ********** ********** ********** ********** *********" );
        171  
        172                    retu rn batchId ;
        173  
        174           }
        175  
        176           @O verride
        177           pu blic Strin g createAn nounceBatc h(final Or ganization  targetOrg anization,
        178                final St ring userI d, HashSet <String> i ens) {
        179   //         if (target Organizati on == null ) {
        180   //             throw  new Illega lArgumentE xception(" Target org anization  must not b e null whe n creating  an announ cement bat ch.");
        181   //         }
        182  
        183           //  create a  unique ide ntifier fo r the batc h
        184           fi nal String  batchId =  UUID.rand omUUID().t oString();
        185  
        186           //  Setting t he Consent  Types her e. For now , only non -consumer  NwHin Orga nizations  are being  used for b atch annou ncements.
        187           //  When we a dd batch a nnouncemen ts for SSA , addition al logic w ill need t o be added  here.
        188           fi nal gov.va .nvap.svc. consentmgm t.stub.dat a.ConsentT ype consen tTypeAutho rize = thi s.pip.getC onsentType ByName(Con sentType.N W_HIN_AUTH ORIZATION. value());
        189  
        190           fi nal Date a nnounceCre ateDate =  new Date() ;
        191  
        192           fo r (String  ien : iens ) {
        193                // creat e a new an nouncement  and persi st it in t he table.
        194                final An nouncement  announcem ent = new  Announceme nt();
        195                announce ment.setBa tchId(batc hId);
        196                announce ment.setUs erId(userI d);
        197                announce ment.setPa tientIen(i en);
        198                announce ment.setTa rgetOrgani zation(tar getOrganiz ation);
        199                announce ment.setCr eatedTs(an nounceCrea teDate);
        200                this.em. persist(an nouncement );
        201           }
        202  
        203           re turn batch Id;         
        204       }
        205       
        206       @Overr ide
        207           pu blic Strin g createAn nounceBatc h(final Co llection<O rganizatio n> targetO rganizatio ns,
        208                             final  String use rId, final  Date date RangeStart ,
        209                             final  Date dateR angeStop,  final bool ean reanno unce) {
        210       
        211                    if ( targetOrga nizations  == null) {
        212                             throw  new Illega lArgumentE xception(
        213                                               "Target or ganization s must not  be null w hen create d a announ cement bat ch.");
        214                    }
        215  
        216                    // c reate a un ique ident ifier for  the batch
        217                    fina l String b atchId = U UID.random UUID().toS tring();
        218  
        219                    fina l StringBu ilder sbQu eryName =  new String Builder(
        220                                      "Consent Directive. active.not Excluded") ;
        221           if  (!reannou nce) {
        222                             sbQuer yName.appe nd(".multO rgs");
        223                    }
        224                    sbQu eryName
        225                                      .append( ((dateRang eStart !=  null) && ( dateRangeS top == nul l)) ? ".cr eatedAfter tDate"
        226                                                       :  "")
        227                                      .append( ((dateRang eStart ==  null) && ( dateRangeS top != nul l)) ? ".cr eatedBefor eDate"
        228                                                       :  "")
        229                                      .append( ((dateRang eStart !=  null) && ( dateRangeS top != nul l)) ? ".cr eatedBetwe enDates"
        230                                                       :  "");
        231  
        232                    if ( reannounce ) {
        233                             sbQuer yName.appe nd(".Reann ounce");
        234                    }
        235                    int  firstResul t = 0;
        236  
        237                    // S etting the  Consent T ypes here.  For now,  only non-c onsumer Nw Hin Organi zations ar e being us ed for bat ch announc ements.
        238                    // W hen we add  batch ann ouncements  for SSA,  additional  logic wil l need to  be added h ere.
        239                    fina l gov.va.n vap.svc.co nsentmgmt. stub.data. ConsentTyp e consentT ypeAuthori ze = this. pip.getCon sentTypeBy Name(Conse ntType.NW_ HIN_AUTHOR IZATION.va lue());
        240  
        241                    List <ConsentDi rective> c onsentDire ctives = n ull;
        242                    fina l Date ann ounceCreat eDate = ne w Date();
        243  
        244                    do {                      
        245                             Query  q = this.e m.createNa medQuery(s bQueryName .toString( ));
        246                             q.setP arameter(" consentTyp eAuthorize ", consent TypeAuthor ize);
        247                             
        248                             if (da teRangeSta rt != null ) {
        249                                      q.setPar ameter("af terDate",  dateRangeS tart);                               
        250                             }
        251                             if (da teRangeSto p != null)  {
        252                                      q.setPar ameter("be foreDate",  dateRange Stop);
        253                             }
        254                             
        255                             if (!r eannounce)  {
        256                    q.se tParameter ("targeted Organizati ons", targ etOrganiza tions);
        257                    cons entDirecti ves = q.se tMaxResult s(Announce mentJpaCon troller.MA X_RESULTS) .getResult List();
        258                             }else{
        259                                      consentD irectives  = q.setFir stResult(f irstResult  * Announc ementJpaCo ntroller.M AX_RESULTS )
        260                                      .setMaxR esults(Ann ouncementJ paControll er.MAX_RES ULTS).getR esultList( );                            
        261                             }
        262                             
        263                             for (f inal Conse ntDirectiv e cd : con sentDirect ives) {
        264                                      // creat e a new an nouncement  and persi st it in t he table.
        265                                      final An nouncement  announcem ent = new  Announceme nt();
        266                                      announce ment.setBa tchId(batc hId);
        267                                      announce ment.setUs erId(userI d);
        268                                      announce ment.setPa tientConse ntDir(cd);
        269                                      announce ment.setTa rgetOrgani zation(nul l);
        270                                      announce ment.setCr eatedTs(an nounceCrea teDate);
        271  
        272                                      this.em. persist(an nouncement );
        273                             }
        274                             firstR esult++;                    
        275  
        276                    } wh ile ((cons entDirecti ves != nul l)
        277                                      && (cons entDirecti ves.size()  == Announ cementJpaC ontroller. MAX_RESULT S));
        278  
        279                    retu rn batchId ;
        280           }
        281       
        282           pu blic void  destroy(fi nal BigDec imal id) t hrows None xistentEnt ityExcepti on {
        283                    Anno uncement a nnouncemen t;
        284                    try  {
        285                             announ cement = t his.em.get Reference( Announceme nt.class,  id);
        286                             announ cement.get Announceme ntId();
        287                    } ca tch (final  EntityNot FoundExcep tion enfe)  {
        288                             throw  new Nonexi stentEntit yException ("The anno uncement w ith id "
        289                                               + id + " n o longer e xists.", e nfe);
        290                    }
        291                    this .em.remove (announcem ent);
        292           }
        293  
        294           @O verride
        295           pu blic void  edit(Annou ncement an nouncement )
        296                             throws  Nonexiste ntEntityEx ception, E xception {
        297                    try  {
        298                             announ cement = t his.em.mer ge(announc ement);
        299                    } ca tch (final  Exception  ex) {
        300                             final  String msg  = ex.getL ocalizedMe ssage();
        301                             if ((m sg == null ) || (msg. length() = = 0)) {
        302                                      final Lo ng id = an nouncement .getAnnoun cementId() ;
        303                                      if (this .findAnnou ncement(id ) == null)  {
        304                                               throw new  Nonexisten tEntityExc eption(
        305                                                                "The  announcem ent with i d " + id
        306                                                                                  + " no l onger exis ts.");
        307                                      }
        308                             }
        309                             throw  ex;
        310                    }
        311           }
        312  
        313           @O verride
        314           pu blic Annou ncement fi ndAnnounce ment(final  Long id)  {
        315                    retu rn this.em .find(Anno uncement.c lass, id);
        316           }
        317  
        318           @O verride
        319           pu blic List< Announceme nt> findAn nouncement Entities()  {
        320                    retu rn this.fi ndAnnounce mentEntiti es(true, - 1, -1);
        321           }
        322  
        323           pr ivate List <Announcem ent> findA nnouncemen tEntities( final bool ean all,
        324                             final  int maxRes ults, fina l int firs tResult) {
        325                    fina l Query q  = this.em
        326                                      .createQ uery("sele ct object( o) from An nouncement  as o");
        327                    if ( !all) {
        328                             q.setM axResults( maxResults );
        329                             q.setF irstResult (firstResu lt);
        330                    }
        331                    retu rn q.getRe sultList() ;
        332           }
        333  
        334           @O verride
        335           pu blic List< Announceme nt> findAn nouncement Entities(f inal int m axResults,
        336                             final  int firstR esult) {
        337                    retu rn this.fi ndAnnounce mentEntiti es(false,  maxResults , firstRes ult);
        338           }
        339  
        340       /**
        341        * Fin ds all ann ouncements  for a par ticular us er.
        342        * 
        343        * @pa ram userId  User ID
        344        * @re turn List  of objects  of type A nnouncemen t found fo r this use r
        345        */  
        346       @Overr ide
        347       public  List<Anno uncement>  findAnnoun cementsByU serId(fina l String u serId) {
        348           fi nal Query  q = this.e m.createNa medQuery(" Announceme nt.findByU serId");
        349           q. setParamet er("userId ", userId) ;
        350           re turn q.get ResultList ();
        351       }
        352       
        353       /**
        354        * Fin ds all ann ouncements  for a lis t of conse nt directi ve ID numb ers
        355        * 
        356        * @pa ram consen tDirective Ids list o f consent  directive  ID numbers
        357        * @re turn List  of objects  of type A nnouncemen t found fo r this pat ient
        358        */
        359       @Overr ide
        360       public  List<Anno uncement>  findAnnoun cementsByC onsentDire ctiveId(fi nal List<L ong> conse ntDirectiv eIds) {
        361           fi nal Query  q = this.e m.createNa medQuery(" Announceme nt.findByC onsentDire ctiveIdLis t");
        362           q. setParamet er("consen tDirective IdList", c onsentDire ctiveIds);
        363           re turn q.get ResultList ();
        364       }
        365       
        366           @O verride
        367           pu blic List< Announceme nt> findUn scheduledA nnouncemen tsByBatchI d(
        368                             final  String bat chId, fina l int maxA nnouncemen ts, final  int firstR esult) {
        369  
        370                    fina l Query q  = this.em. createName dQuery("An nouncement .findByBat chId");
        371                    q.se tParameter ("batchId" , batchId) ;
        372                    q.se tFirstResu lt(firstRe sult*maxAn nouncement s).setMaxR esults(max Announceme nts);
        373                    retu rn q.getRe sultList() ;
        374           }
        375       
        376       @Overr ide
        377           pu blic List< Announceme nt> findAl lAnnouncem entsByBatc hId(final  String bat chId) {
        378                    fina l Query q  = this.em. createName dQuery("An nouncement .findByBat chId");
        379           q. setParamet er("batchI d", batchI d);
        380                    retu rn q.getRe sultList() ;
        381           }
        382  
        383           @O verride
        384           pu blic int g etAnnounce mentCount( ) {
        385                    fina l Query q  = this.em
        386                                      .createQ uery("sele ct count(o ) from Ann ouncement  as o");
        387                    retu rn ((Long)  q.getSing leResult() ).intValue ();
        388           }
        389  
        390           @O verride
        391           pu blic void  removeByBa tchId(fina l Collecti on<String>  batchIds)  {
        392                    fina l Query q  = this.em
        393                                      .createN amedQuery( "Announcem ent.delete ByBatchIds ");
        394                    q.se tParameter ("batchIds ", batchId s);
        395                    q.ex ecuteUpdat e();
        396           }
        397  
        398       @Overr ide
        399           pu blic List< Announceme ntBatchSum mary> retr ieveBatchS ummaries(f inal Date  startDate,  final Dat e endDate,  final Str ing orgOid , final St ring userI d, final i nt firstRe sult, fina l int maxR esults) {
        400           St ring query  = "SELECT  NEW gov.v a.nvap.svc .consentmg mt.stub.ad apter.anno unce.data. Announceme ntBatchSum mary(a.bat chId, o.or gName, o.o rgId, COUN T(a.announ cementId),  MIN(a.cre atedTs), C OUNT(a.sch eduledTs),  COUNT(a.c ompletedTs )) FROM An nouncement Org j JOIN  j.announc ement a JO IN j.targe tOrganizat ion o WHER E a.batchI d is not n ull";
        401           St ring query Params = " ";
        402           Qu ery q = nu ll;
        403           
        404           // build the  query
        405           if (orgOid !=  null && o rgOid.leng th() > 0){
        406                queryPar ams = quer yParams +  " AND o.or gOid=:orgO id";
        407           }
        408           
        409           qu eryParams  = queryPar ams + " GR OUP BY a.b atchId, o. orgName, o .orgId";
        410           
        411           if (startDate  != null & & endDate  != null){
        412                queryPar ams = quer yParams +  " HAVING M IN(a.creat edTs) >= : startDate  and MIN(a. createdTs)  <= :endDa te";
        413           }  else {
        414                if(start Date != nu ll){
        415                    quer yParams =  queryParam s + " HAVI NG MIN(a.c reatedTs)  >= :startD ate";
        416                }
        417                if(endDa te != null ){
        418                    quer yParams =  queryParam s + " HAVI NG MIN(a.c reatedTs)  <= :endDat e";
        419                }
        420           }
        421           
        422           qu ery = quer y + queryP arams + "  ORDER BY M IN(a.creat edTs) DESC ";
        423           
        424           if  (maxResul ts <= 0) {
        425                q = this .em.create Query(quer y);
        426           }  else {
        427                q = this .em.create Query(quer y).setFirs tResult(fi rstResult) .setMaxRes ults(maxRe sults);
        428           }
        429           
        430           // add the pa rams
        431           if (orgOid !=  null && o rgOid.leng th() > 0){
        432                q.setPar ameter("or gOid", org Oid);
        433           }
        434           if (startDate  != null){
        435                q.setPar ameter("st artDate",  startDate) ;
        436           }
        437           if (endDate ! = null){
        438                q.setPar ameter("en dDate", en dDate);
        439           }
        440           
        441           Li st<Announc ementBatch Summary> r esults = q .getResult List();
        442           
        443           re turn resul ts;
        444       }
        445       
        446           /* @Override
        447           pu blic List< Announceme ntBatchSum mary> retr ieveBatchS ummaries(
        448                             final  Date start Date, fina l Date end Date, fina l String o rgOid,
        449                             final  String use rId, final  int first Result, fi nal int ma xResults)  {
        450                    Stri ng query =  null;
        451           St ring query 2 = null;
        452                    // T ODO: Refac tor - ther e must be  a better w ay to do t his, maybe  % like
        453                    // q ueries or  Hibernate  Criterias
        454                    if ( (null != u serId) &&  (userId.le ngth() > 0 )) {
        455                             if ((n ull != org Oid) && (o rgOid.leng th() > 0))  {
        456                                      query =  "Announcem ent.allBat chSummaryB yOrganizat ionAndUser Id";
        457                    quer y2 = "Anno uncement.a llBatchSum maryByOrga nizationAn dUserId2";
        458                                      if (null  != startD ate) {
        459                                               if (null ! = endDate)  {
        460                                                       qu ery = "Ann ouncement. batchSumma ryByDateAn dOrganizat ionAndUser Id";
        461                             query2  = "Announ cement.bat chSummaryB yDateAndOr ganization AndUserId2 ";
        462                                               } else {
        463                                                       qu ery = "Ann ouncement. batchSumma ryFromDate AndOrganiz ationAndUs erId";
        464                             query2  = "Announ cement.bat chSummaryF romDateAnd Organizati onAndUserI d2";
        465                                               }
        466                                      } else i f (null !=  endDate)  {
        467                                               query = "A nnouncemen t.batchSum maryToDate AndOrganiz ationAndUs erId";
        468                         query2 = " Announceme nt.batchSu mmaryToDat eAndOrgani zationAndU serId2";
        469                                      }
        470  
        471                             } else  {
        472                                      query =  "Announcem ent.allBat chSummaryB yUserId";
        473                    quer y2 = "Anno uncement.a llBatchSum maryByUser Id2";
        474                                      if (null  != startD ate) {
        475                                               if (null ! = endDate)  {
        476                                                       qu ery = "Ann ouncement. batchSumma ryByDateAn dUserId";
        477                             query2  = "Announ cement.bat chSummaryB yDateAndUs erId2";
        478                                               } else {
        479                                                       qu ery = "Ann ouncement. batchSumma ryFromDate AndUserId" ;
        480                             query2  = "Announ cement.bat chSummaryF romDateAnd UserId2";
        481                                               }
        482                                      } else i f (null !=  endDate)  {
        483                                               query = "A nnouncemen t.batchSum maryToDate AndUserId" ;
        484                         query2 = " Announceme nt.batchSu mmaryToDat eAndUserId 2";
        485                                      }
        486                             }
        487                    } el se {
        488                             if ((n ull != org Oid) && (o rgOid.leng th() > 0))  {
        489                                      query =  "Announcem ent.allBat chSummaryB yOrganizat ion";
        490                    quer y2 = "Anno uncement.a llBatchSum maryByOrga nization2" ;
        491                                      if (null  != startD ate) {
        492                                               if (null ! = endDate)  {
        493                                                       qu ery = "Ann ouncement. batchSumma ryByDateAn dOrganizat ion";
        494                             query2  = "Announ cement.bat chSummaryB yDateAndOr ganization 2";
        495                                               } else {
        496                                                       qu ery = "Ann ouncement. batchSumma ryFromDate AndOrganiz ation";
        497                             query2  = "Announ cement.bat chSummaryF romDateAnd Organizati on2";
        498                                               }
        499                                      } else i f (null !=  endDate)  {
        500                                               query = "A nnouncemen t.batchSum maryToDate AndOrganiz ation";
        501                         query2 = " Announceme nt.batchSu mmaryToDat eAndOrgani zation2";
        502                                      }
        503  
        504                             } else  {
        505                                      query =  "Announcem ent.allBat chSummary" ;
        506                    quer y2 = "Anno uncement.a llBatchSum mary2";
        507                                      if (null  != startD ate) {
        508                                               if (null ! = endDate)  {
        509                                                       qu ery = "Ann ouncement. batchSumma ryByDate";
        510                             query2  = "Announ cement.bat chSummaryB yDate2";
        511                                               } else {
        512                                                       qu ery = "Ann ouncement. batchSumma ryFromDate ";
        513                             query2  = "Announ cement.bat chSummaryF romDate2";
        514                                               }
        515                                      } else i f (null !=  endDate)  {
        516                                               query = "A nnouncemen t.batchSum maryToDate ";
        517                         query2 = " Announceme nt.batchSu mmaryToDat e2";
        518                                      }
        519                             }
        520                    }
        521  
        522                    fina l Query q  = this.em. createName dQuery(que ry);
        523           fi nal Query  q2 = this. em.createN amedQuery( query2);
        524                    if ( null != st artDate) {
        525                             q.setP arameter(" startDate" , startDat e);
        526                q2.setPa rameter("s tartDate",  startDate );
        527                    }
        528                    if ( null != en dDate) {
        529                             q.setP arameter(" endDate",  endDate);
        530                q2.setPa rameter("e ndDate", e ndDate);
        531                    }
        532                    if ( (null != o rgOid) &&  (orgOid.le ngth() > 0 )) {
        533                             q.setP arameter(" orgOid", o rgOid);
        534                q2.setPa rameter("o rgOid", or gOid);
        535                    }
        536                    if ( (null != u serId) &&  (userId.le ngth() > 0 )) {
        537                             q.setP arameter(" userId", u serId);
        538                q2.setPa rameter("u serId", us erId);
        539                    }
        540                    if ( maxResults  <= 0) {
        541                List<Ann ouncementB atchSummar y> results  = q.getRe sultList() ;
        542                results. addAll(q2. getResultL ist());
        543                             return  results;
        544                    } el se {
        545                List<Ann ouncementB atchSummar y> results  = q.getRe sultList() ;
        546                results. addAll(q2. getResultL ist());
        547                results  = results. subList(fi rstResult,  firstResu lt + maxRe sults > re sults.size () ? resul ts.size()  : firstRes ult + maxR esults);
        548                             return  results;
        549                    }
        550           }  */
        551  
        552           @O verride
        553           pu blic List< Announceme ntBatchSum mary> retr ieveBatchS ummaries(
        554                             final  List<Strin g> batchId s) {
        555                    fina l Query q  = this.em. createName dQuery("An nouncement .batchSumm ary");
        556                    q.se tParameter ("batchIds ", batchId s);
        557                    retu rn q.getRe sultList() ;
        558           }
        559  
        560           @O verride
        561           pu blic List< Announceme ntBatchSum mary> retr ieveBatchS ummariesBy DateRange(
        562                             final  Date start Date, fina l Date end Date) {
        563                    retu rn this.re trieveBatc hSummaries (startDate , endDate,  null, nul l, 0,
        564                                      -1);
        565           }
        566       
        567       /**
        568        * Fin ds all ann ouncements  created a fter input  date for  a particul ar patient .
        569        * 
        570        * @pa ram create dTs
        571        * @pa ram patien tIen
        572        * 
        573        * @re turn List  of objects  of type A nnouncemen t found fo r this pat ient
        574        */  
        575       @Overr ide
        576       public  List<Anno uncement>  findNonBat chAnnounce mentsByCre atedTs(fin al Date cr eatedTs, f inal Strin g patientI en) {
        577           fi nal Query  q = this.e m.createNa medQuery(" Announceme nt.findNon BatchAnnou ncementsBy CreatedTs" );
        578           q. setParamet er("create dTs", crea tedTs);
        579           q. setParamet er("patien tIen", pat ientIen);
        580           re turn q.get ResultList ();
        581       }
        582  
        583           @O verride
        584           pu blic void  setEntityM anager(fin al EntityM anager em)  {
        585                    this .em = em;
        586           }
        587       
        588       @Overr ide
        589           pu blic HashM ap findAll Announceme ntsByBatch IdWithPagi ng(final S tring batc hId, final  String or gId, final  Integer s tartRow, f inal Integ er maxRows ) {
        590           Ha shMap hm =  new HashM ap();
        591           
        592           fi nal Query  cq = this. em.createN amedQuery( "Announcem ent.findCo untByBatch IdAndOrgId ");
        593           cq .setParame ter("batch Id", batch Id);
        594           cq .setParame ter("orgId ", Long.pa rseLong(or gId));
        595           Lo ng c = Lon g.parseLon g(cq.getSi ngleResult ().toStrin g());
        596           
        597           hm .put("coun t", c);
        598           
        599           fi nal Query  q = this.e m.createNa medQuery(" Announceme nt.findByB atchIdAndO rgId").set FirstResul t(startRow ).setMaxRe sults(maxR ows);
        600           q. setParamet er("batchI d", batchI d);
        601           q. setParamet er("orgId" , Long.par seLong(org Id));
        602                    List <Announcem ent> resul ts = q.get ResultList (); 
        603           
        604           hm .put("resu lts", resu lts);
        605           
        606           re turn hm;
        607           }
        608   }