72. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 8/14/2018 11:32:41 AM 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.

72.1 Files compared

# Location File Last Modified
1 cbs-2018-06-18.zip\cbs\src\main\java\gov\va\cpss\service CbsService.java Tue Jun 19 13:45:30 2018 UTC
2 cbs-2018-06-18.zip\cbs\src\main\java\gov\va\cpss\service CbsService.java Tue Aug 14 13:52:32 2018 UTC

72.2 Comparison summary

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

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

72.4 Active regular expressions

No regular expressions were active.

72.5 Comparison detail

  1   package go v.va.cpss. service;
  2  
  3   import jav a.sql.Time stamp;
  4   import jav a.util.Arr ayList;
  5   import jav a.util.Cal endar;
  6   import jav a.util.Col lections;
  7   import jav a.util.Com parator;
  8   import jav a.util.Dat e;
  9   import jav a.util.Lis t;
  10   import jav a.util.Map ;
  11   import jav a.util.Map .Entry;
  12   import jav a.util.str eam.Collec tors;
  13  
  14   import org .apache.lo g4j.Logger ;
  15   import org .springfra mework.ste reotype.Se rvice;
  16  
  17   import gov .va.cpss.c obol.Money ;
  18   import gov .va.cpss.d ao.CBSAcco untDAO;
  19   import gov .va.cpss.d ao.CBSSite PatientDAO ;
  20   import gov .va.cpss.d ao.CBSSite StmtDAO;
  21   import gov .va.cpss.d ao.CBSSite TransDAO;
  22   import gov .va.cpss.d ao.CBSStmt DAO;
  23   import gov .va.cpss.d ao.Process StatusDAO;
  24   import gov .va.cpss.m odel.Boole anChar;
  25   import gov .va.cpss.m odel.cbs.C BSSitePati ent;
  26   import gov .va.cpss.m odel.cbs.C BSSiteStmt ;
  27   import gov .va.cpss.m odel.cbs.C BSSiteTran s;
  28   import gov .va.cpss.m odel.cbs.C BSStmt;
  29   import gov .va.cpss.m odel.Proce ssStatus;
  30   import gov .va.cpss.m odel.fps.P SDetails;
  31   import gov .va.cpss.m odel.fps.P SPatient;
  32  
  33   /**
  34    * Service  class for  handling  activities  relating  to consoli dating a p atient
  35    * stateme nt.
  36    * 
  37    * @author   D N   
  38    */
  39   @Service
  40   @SuppressW arnings("n ls")
  41   public cla ss CbsServ ice {
  42  
  43           pr ivate stat ic final L ogger logg er = Logge r.getLogge r(CbsServi ce.class.g etCanonica lName());
  44  
  45           pr ivate stat ic final i nt MAX_COB OL_FIELD_L ENGTH = 9;
  46  
  47           pr ivate bool ean lateSt atementMes sage;
  48  
  49           pr ivate Proc essStatusD AO process StatusDAO;
  50  
  51           pr ivate CBSA ccountDAO  cbsAccount DAO;
  52  
  53           pr ivate CBSS tmtDAO cbs StmtDAO;
  54  
  55           pr ivate CBSS iteStmtDAO  cbsSiteSt mtDAO;
  56  
  57           pr ivate CBSS itePatient DAO cbsSit ePatientDA O;
  58  
  59           pr ivate CBSS iteTransDA O cbsSiteT ransDAO;
  60  
  61           pu blic CbsSe rvice() {
  62           }
  63  
  64           pu blic boole an getLate StatementM essage() {
  65                    retu rn lateSta tementMess age;
  66           }
  67  
  68           pu blic void  setLateSta tementMess age(boolea n lateStat ementMessa ge) {
  69                    this .lateState mentMessag e = lateSt atementMes sage;
  70           }
  71  
  72           pu blic Proce ssStatusDA O getProce ssStatusDA O() {
  73                    retu rn process StatusDAO;
  74           }
  75  
  76           pu blic void  setProcess StatusDAO( ProcessSta tusDAO pro cessStatus DAO) {
  77                    this .processSt atusDAO =  processSta tusDAO;
  78           }
  79  
  80           pu blic CBSAc countDAO g etCbsAccou ntDAO() {
  81                    retu rn cbsAcco untDAO;
  82           }
  83  
  84           pu blic void  setCbsAcco untDAO(CBS AccountDAO  cbsAccoun tDAO) {
  85                    this .cbsAccoun tDAO = cbs AccountDAO ;
  86           }
  87  
  88           pu blic CBSSt mtDAO getC bsStmtDAO( ) {
  89                    retu rn cbsStmt DAO;
  90           }
  91  
  92           pu blic void  setCbsStmt DAO(CBSStm tDAO cbsSt mtDAO) {
  93                    this .cbsStmtDA O = cbsStm tDAO;
  94           }
  95  
  96           pu blic CBSSi tePatientD AO getCbsS itePatient DAO() {
  97                    retu rn cbsSite PatientDAO ;
  98           }
  99  
  100           pu blic void  setCbsSite PatientDAO (CBSSitePa tientDAO c bsSitePati entDAO) {
  101                    this .cbsSitePa tientDAO =  cbsSitePa tientDAO;
  102           }
  103  
  104           pu blic CBSSi teStmtDAO  getCbsSite StmtDAO()  {
  105                    retu rn cbsSite StmtDAO;
  106           }
  107  
  108           pu blic void  setCbsSite StmtDAO(CB SSiteStmtD AO cbsSite StmtDAO) {
  109                    this .cbsSiteSt mtDAO = cb sSiteStmtD AO;
  110           }
  111  
  112           pu blic CBSSi teTransDAO  getCbsSit eTransDAO( ) {
  113                    retu rn cbsSite TransDAO;
  114           }
  115  
  116           pu blic void  setCbsSite TransDAO(C BSSiteTran sDAO cbsSi teTransDAO ) {
  117                    this .cbsSiteTr ansDAO = c bsSiteTran sDAO;
  118           }
  119  
  120           /* *
  121            *  Build a c onsolidate d statemen t for the  CBS Accoun t to list  of PSPatie nt
  122            *  records m ap.
  123            *  
  124            *  @param ba tchRunId
  125            *              The batc h run ID.
  126            *  @param pa tientMap
  127            *              The map  of records  to consol idate.
  128            *  @return A  consolida ted statem ent.
  129            * /
  130           pu blic CBSSt mt buildSt atementFor PatientMap (final lon g batchRun Id, Entry< Long, List <PSPatient >> patient Map)
  131                             throws  RuntimeEx ception {
  132  
  133                    // F irst, crea te an init ial statem ent for th e records  in the map .
  134                    CBSS tmt statem ent = crea teInitialS tatement(b atchRunId,  patientMa p.getKey() );
  135  
  136                    // T hen proces s the list  of PSPati ent record s.
  137                    if ( processPat ientList(s tatement,  patientMap .getValue( )) > 0) {
  138  
  139                             // Now  check if  this shoul d be a lat e statemen t or if a  new
  140                             // sta tement alr eady exist s for this  patient.
  141                             // If  an unrecov erable err or occurs  false will  be return ed.
  142                             if (!c heckForExi stingState ment(state ment)) {
  143  
  144                                      // An un recoverabl e error ha s occurred  indicatin g the data base
  145                                      // is co rrupted.
  146                                      throw ne w RuntimeE xception(" Unrecovera ble data e rror check ing for ex isting sta tement");
  147                             }
  148  
  149                    } el se {
  150  
  151                             // If  unexpected  data erro r occurs ( patient li st is empt y or no
  152                             // pat ients proc essed) the n log an e rror messa ge and
  153                             // ski p the stat ement.
  154                             logger .error("No  patients  processed  for CBS Ac count: " +  patientMa p.getKey() );
  155  
  156                             // Ret urn null w hich will  skip state ment.
  157                             statem ent = null ;
  158                    }
  159  
  160                    // S et accntNu mDisp afte r site pat ients have  been proc essed and
  161                    // s tatement m erged with  existing  statement
  162                    setA cntNumDisp (statement );
  163  
  164                    retu rn stateme nt;
  165           }
  166  
  167           /* *
  168            *  Check and  handle ex isting sta tement.
  169            *  
  170            *  @param st atement
  171            *              The cons olidated s tatement.
  172            *  @return F lag indica ting if su ccessfully  checked o r if an un recoverabl e
  173            *          e rror occur red.
  174            * /
  175           pu blic boole an checkFo rExistingS tatement(C BSStmt sta tement) {
  176  
  177                    bool ean succes sful = fal se;
  178  
  179                    // C heck if th is should  be a late  statement  (a stateme nt for thi s month
  180                    // a lready) or  if a new  statement
  181                    // a lready exi sts that n eeds to be  merged.
  182                    fina l Date sta tementDate  = stateme nt.getSite StmtL().ge t(0).getSt atementDat e();
  183  
  184                    // U nrecoverab le error i f statemen t date hap pens to be  null.
  185                    if ( statementD ate != nul l) {
  186  
  187                             Intege r statusId  = cbsStmt DAO.getSta tusIdForEx istingStat ementByAcc ountAndMon th(stateme nt.getAcco untId(),
  188                                               statementD ate);
  189  
  190                             // If  an existin g statemen t exists ( !null) the n process  accordingl y.
  191                             if (st atusId !=  null) {
  192  
  193                                      // Handl e existing  statement  different ly dependi ng on its
  194                                      // statu s.
  195                                      switch ( processSta tusDAO.get StatusType (statusId) .getStatus ()) {
  196  
  197                                      case NEW :
  198                                               // Query f or existin g statemen t.
  199                                               CBSStmt ex istingStat ement = ge tExistingS tatementFo rAccount(s tatement.g etAccountI d(), state mentDate);
  200  
  201                                               combineWit hExistingS tatement(s tatement,  existingSt atement);
  202                                               successful  = true;
  203                                               break;
  204                                      case ACK :
  205                                      case ERR OR:
  206                                      case SEN T:
  207                                               setAsLateS tatement(s tatement);
  208                                               successful  = true;
  209                                               break;
  210                                      case INI TIAL:
  211                                      case REP LACED:
  212                                      case UND EFINED:
  213                                      default:
  214                                               logger.err or("Existi ng stateme nt detecte d of inval id status  at time of  query");
  215                                               break;
  216                                      }
  217                             } else  {
  218  
  219                                      // There  is no exi sting stat ement foun d.
  220                                      successf ul = true;
  221                             }
  222                    } el se {
  223  
  224                             logger .error("Un able to ch eck for ex isting sta tement bec ause date  check was  unexpected ly null");
  225                    }
  226  
  227                    retu rn success ful;
  228           }
  229  
  230           /* *
  231            *  Create a  consolidat ed stateme nt object  for the sp ecified ac count numb er.
  232            *  
  233            *  @param ac countNumbe r
  234            *              The acco unt number  to associ ate with t he consoli dated
  235            *              statemen t.
  236            *  @return T he initial ized conso lidated st atement.
  237            * /
  238           pr ivate CBSS tmt create InitialSta tement(fin al long ba tchRunId,  final long  accountNu mber) {
  239  
  240                    // C reate a st atement fo r the acco unt.
  241                    CBSS tmt statem ent = new  CBSStmt(ba tchRunId,  accountNum ber,
  242                                      processS tatusDAO.g etStatusFr omEnum(Pro cessStatus .Status.IN ITIAL));
  243  
  244                    init ializeStat ement(stat ement);
  245  
  246                    retu rn stateme nt;
  247           }
  248  
  249           /* *
  250            *  Combine t he consoli dated stat ement with  the speci fied exist ing statem ent.
  251            *  
  252            *  @param st atement
  253            *              The cons olidated s tatement.
  254            *  @param ex istingStat ement
  255            *              The exis ting conso lidated st atement.
  256            * /
  257           pu blic void  combineWit hExistingS tatement(C BSStmt sta tement, fi nal CBSStm t existing Statement)  {
  258  
  259                    // S ave the re places id.
  260                    stat ement.setR eplacedStm tId(existi ngStatemen t.getId()) ;
  261  
  262                    // I nitialize  the runnin g totals w ith the va lues alrea dy in the
  263                    // s tatement.
  264                    doub le amountD ue = state ment.getAm ountDue(). getDouble( );
  265                    doub le previou sBalance =  statement .getPrevBa lance().ge tDouble();
  266                    doub le totalCh arges = st atement.ge tTotalChar ges().getD ouble();
  267                    doub le totalCr edits = st atement.ge tTotalCred its().getD ouble();
  268                    doub le newBala nce = stat ement.getN ewBalance( ).getDoubl e();
  269  
  270                    // A dd the exi sting stat ement valu es.
  271                    amou ntDue += e xistingSta tement.get AmountDue( ).getDoubl e();
  272                    prev iousBalanc e += exist ingStateme nt.getPrev Balance(). getDouble( );
  273                    tota lCharges + = existing Statement. getTotalCh arges().ge tDouble();
  274                    tota lCredits + = existing Statement. getTotalCr edits().ge tDouble();
  275                    newB alance +=  existingSt atement.ge tNewBalanc e().getDou ble();
  276  
  277                    // S ave the va lues.
  278                    setA mountDue(s tatement,  amountDue) ;
  279                    setP revBalance (statement , previous Balance);
  280                    setT otalCharge s(statemen t, totalCh arges);
  281                    setT otalCredit s(statemen t, totalCr edits);
  282                    setN ewBalance( statement,  newBalanc e);
  283  
  284                    // A ppend the  existing l ist of sit e statemen ts to the  new statem ent.
  285                    List <CBSSiteSt mt> siteSt atementL =  statement .getSiteSt mtL();
  286                    site StatementL .addAll(ex istingStat ement.getS iteStmtL() );
  287                    setP rimarySite Flags(stat ement, sit eStatement L);
  288                    stat ement.setS iteStmtL(s iteStateme ntL);
  289  
  290                    // T ake the va lue of the  existing  statement  late state ment messa ge.
  291                    stat ement.setL ateStmtMsg (existingS tatement.g etLateStmt Msg());
  292           }
  293  
  294           /* *
  295            *  Set the l ate messag e in the s tatement.
  296            *  
  297            *  @param st atement
  298            *              The stat ement that  is late.
  299            * /
  300           pr ivate void  setAsLate Statement( CBSStmt st atement) {
  301                    stat ement.setL ateStmtMsg (lateState mentMessag e);
  302           }
  303  
  304           /* *
  305            *  Initializ e a consol idated sta tement val ues.
  306            *  
  307            *  @param st atement
  308            * /
  309           pr ivate void  initializ eStatement (CBSStmt s tatement)  {
  310  
  311                    fina l Timestam p currentT ime = new  Timestamp( Calendar.g etInstance ().getTime ().getTime ());
  312  
  313                    stat ement.setS iteStmtL(n ew ArrayLi st<>());
  314  
  315                    setA mountDue(s tatement,  0);
  316                    setP revBalance (statement , 0);
  317                    setT otalCharge s(statemen t, 0);
  318                    setT otalCredit s(statemen t, 0);
  319                    setN ewBalance( statement,  0);
  320  
  321                    stat ement.setC reatedDate (currentTi me);
  322                    stat ement.setM odifiedDat e(currentT ime);
  323  
  324                    stat ement.setL ateStmtMsg (false);
  325           }
  326  
  327           pu blic void  setAmountD ue(CBSStmt  statement , final do uble value ) {
  328                    stat ement.setA mountDue(n ew Money(v alue, MAX_ COBOL_FIEL D_LENGTH)) ;
  329           }
  330  
  331           pu blic void  setPrevBal ance(CBSSt mt stateme nt, final  double val ue) {
  332                    stat ement.setP revBalance (new Money (value, MA X_COBOL_FI ELD_LENGTH ));
  333           }
  334  
  335           pu blic void  setTotalCh arges(CBSS tmt statem ent, final  double va lue) {
  336                    stat ement.setT otalCharge s(new Mone y(value, M AX_COBOL_F IELD_LENGT H));
  337           }
  338  
  339           pu blic void  setTotalCr edits(CBSS tmt statem ent, final  double va lue) {
  340                    stat ement.setT otalCredit s(new Mone y(value, M AX_COBOL_F IELD_LENGT H));
  341           }
  342  
  343           pu blic void  setNewBala nce(CBSStm t statemen t, final d ouble valu e) {
  344                    stat ement.setN ewBalance( new Money( value, MAX _COBOL_FIE LD_LENGTH) );
  345           }
  346  
  347           pu blic void  setAcntNum Disp(CBSSt mt stateme nt) {
  348                    stat ement.setA cntNumDisp (CBSStmt.c reateAcntN umDisp(sta tement));
  349           }
  350  
  351           /* *
  352            *  Identify  the approp riate site  statement s for prim ary patien t data and
  353            *  primary p atient add ress.
  354            *  
  355            *  @param si teStatemen tL
  356            *              The list  of site s tatements  for which  to calcula te primary
  357            *              flags.
  358            * /
  359           pu blic void  setPrimary SiteFlags( CBSStmt st atement, L ist<CBSSit eStmt> sit eStatement L) {
  360  
  361                    // I f there is  only one  site state ment then  this is ea sy.
  362                    if ( siteStatem entL.size( ) == 1) {
  363  
  364                             siteSt atementL.g et(0).setI sPrimary(B ooleanChar .Y);
  365                             siteSt atementL.g et(0).setI sPrimaryAd dress(Bool eanChar.Y) ;
  366  
  367                             // Set  the state ment dates  to the da tes of the  primary s ite
  368                             // sta tement.
  369                             setSta tementDate s(statemen t, siteSta tementL.ge t(0));
  370  
  371                    } el se {
  372  
  373                             // If  there are  multiple s ite statem ents then  it is more
  374                             // com plicated.
  375  
  376                             // Fir st, initia lize all t he sites t o not prim ary.
  377                             // Whi le doing s o, count t he number  of AR flag s.
  378                             int ar FlagCount  = 0;
  379                             for (C BSSiteStmt  siteState ment : sit eStatement L) {
  380  
  381                                      siteStat ement.setI sPrimary(B ooleanChar .N);
  382                                      siteStat ement.setI sPrimaryAd dress(Bool eanChar.N) ;
  383  
  384                                      // Count  how many  sites have  the AR fl ag set.
  385                                      if (site Statement. getArAddre ssFlag().i sTrue()) {
  386                                               arFlagCoun t++;
  387                                      }
  388                             }
  389  
  390                             // Sor t statemen ts by most  recent la stBillPrep Date to id entify
  391                             // isP rimary
  392                             Collec tions.sort (siteState mentL, new  Comparato r<CBSSiteS tmt>() {
  393                                      public i nt compare (CBSSiteSt mt o1, CBS SiteStmt o 2) {
  394                                               if (o1.get LastBillPr epDate() = = null) {
  395                                                       //  If o1 nul l, then as sume older .
  396                                                       re turn 1;
  397                                               } else if  (o2.getLas tBillPrepD ate() == n ull) {
  398                                                       //  If o2 is  then assum e o1 is ne wer.
  399                                                       re turn -1;
  400                                               } else {
  401                                                       //  Desire mo st recent  date, so c ompare o2  to o1.
  402                                                       re turn o2.ge tLastBillP repDate(). compareTo( o1.getLast BillPrepDa te());
  403                                               }
  404                                      }
  405                             });
  406  
  407                             // The  most rece nt will be  sorted fi rst.
  408                             // It  will be us ed for Pat ient Detai ls.
  409                             // Set  the first  in the co llection t o isPrimar y for Pati ent Detail s.
  410                             siteSt atementL.g et(0).setI sPrimary(B ooleanChar .Y);
  411  
  412                             // Set  the state ment dates  to the da tes of the  primary s ite
  413                             // sta tement.
  414                             setSta tementDate s(statemen t, siteSta tementL.ge t(0));
  415  
  416                             // Use  different  logic to  identify t he primary  site stat ement to u se
  417                             // for  the Patie nt
  418                             // Add ress
  419  
  420                             if (ar FlagCount  == 1) {
  421  
  422                                      // If ex actly one  AR flag fo und then u se that si te stateme nt as
  423                                      // the P rimary Add ress.
  424                                      for (CBS SiteStmt s iteStateme nt : siteS tatementL)  {
  425                                               if (siteSt atement.ge tArAddress Flag().isT rue()) {
  426                                                       si teStatemen t.setIsPri maryAddres s(BooleanC har.Y);
  427                                                       br eak;
  428                                               }
  429                                      }
  430  
  431                             } else  {
  432  
  433                                      // If th ere is mor e than one  AR flag o r if there  are no AR  flags
  434                                      // then  use the fi rst in the  sorted co llection j ust like h ow
  435                                      // Patie nt
  436                                      // Detai ls is dete rmined.
  437                                      siteStat ementL.get (0).setIsP rimaryAddr ess(Boolea nChar.Y);
  438                             }
  439                    }
  440           }
  441  
  442           /* *
  443            *  Set the s tatement d ates using  the prima ry site st atement da te values.
  444            *  
  445            *  @param st atement
  446            *              The stat ement to u pdate.
  447            *  @param si teStatemen t
  448            *              The site  statement  as refere nce.
  449            * /
  450           pr ivate void  setStatem entDates(C BSStmt sta tement, fi nal CBSSit eStmt site Statement)  {
  451                    // S et the sta tement val ues to poi nt to the  primary da tes.
  452                    stat ement.setS tatementDa te(siteSta tement.get StatementD ate());
  453                    stat ement.setP rocessDate (siteState ment.getPr ocessDate( ));
  454           }
  455  
  456           /* *
  457            *  Process t he list of  raw PSPat ient recor ds and rol l processe d data int o
  458            *  the conso lidated st atement.
  459            *  
  460            *  @param st atement
  461            *              The cons olidated s tatement t o update.
  462            *  @param ps PatientL
  463            *              The list  of PSPati ent record s.
  464            *  @return N umber of p atients pr ocessed.
  465            * /
  466           pu blic int p rocessPati entList(CB SStmt stat ement, fin al List<PS Patient> p sPatientL)  {
  467  
  468                    int  processedC ount = 0;
  469  
  470                    if ( (psPatient L == null)  || psPati entL.isEmp ty()) {
  471  
  472                             // Une xpected er ror that s hould neve r happen.
  473                             logger .error("Pa tient list  was unexp ectedly em pty!");
  474  
  475                    } el se {
  476  
  477                             // Get  the site  statement  list.
  478                             List<C BSSiteStmt > siteStat ementL = s tatement.g etSiteStmt L();
  479  
  480                             // Ini tialize th e running  totals wit h the valu es already  in the
  481                             // sta tement.
  482                             double  amountDue  = stateme nt.getAmou ntDue().ge tDouble();
  483                             double  previousB alance = s tatement.g etPrevBala nce().getD ouble();
  484                             double  totalChar ges = stat ement.getT otalCharge s().getDou ble();
  485                             double  totalCred its = stat ement.getT otalCredit s().getDou ble();
  486                             double  newBalanc e = statem ent.getNew Balance(). getDouble( );
  487  
  488                             for (P SPatient p sPatient :  psPatient L) {
  489                                      logger.d ebug("Proc essing Pat ient: " +  psPatient. getIcnNumb er());
  490  
  491                                      // Creat e CBSSiteS tmt associ ated with  the PSPati ent record .
  492                                      CBSSiteS tmt siteSt atement =  getSiteSta tementForP atient(psP atient);
  493  
  494                                      // Calcu late Total s for Cons olidated S tatement
  495                                      amountDu e += siteS tatement.g etAmountDu e().getDou ble();
  496                                      previous Balance +=  siteState ment.getPr evBalance( ).getDoubl e();
  497                                      totalCha rges += si teStatemen t.getTotal Charges(). getDouble( );
  498                                      totalCre dits += si teStatemen t.getTotal Credits(). getDouble( );
  499                                      newBalan ce += site Statement. getNewBala nce().getD ouble();
  500  
  501                                      // Appen d the site  statement  to the li st.
  502                                      siteStat ementL.add (siteState ment);
  503  
  504                                      // Incre ment the n umber of p atients pr ocessed.
  505                                      processe dCount++;
  506                             }
  507  
  508                             if (!s iteStateme ntL.isEmpt y()) {
  509                                      // Ident ify Primar y Site (Pa tient Deta ils) and P rimary Sit e
  510                                      // (Addr ess)
  511                                      setPrima rySiteFlag s(statemen t, siteSta tementL);
  512  
  513                                      // Set t he site st atement li st in the  Consolidat ed Stateme nt
  514                                      statemen t.setSiteS tmtL(siteS tatementL) ;
  515  
  516                                      // Set t he calcula ted totals .
  517                                      setAmoun tDue(state ment, amou ntDue);
  518                                      setPrevB alance(sta tement, pr eviousBala nce);
  519                                      setTotal Charges(st atement, t otalCharge s);
  520                                      setTotal Credits(st atement, t otalCredit s);
  521                                      setNewBa lance(stat ement, new Balance);
  522                             }
  523                    }
  524  
  525                    retu rn process edCount;
  526           }
  527  
  528           /* *
  529            *  Build a s ite statem ent associ ated with  the patien t record.
  530            *  
  531            *  @param ps Patient
  532            *              The pati ent record .
  533            *  @return A  site stat ement asso ciated wit h the spec ified pati ent record .
  534            * /
  535           pr ivate CBSS iteStmt ge tSiteState mentForPat ient(final  PSPatient  psPatient ) {
  536  
  537                    fina l Timestam p currentT ime = new  Timestamp( Calendar.g etInstance ().getTime ().getTime ());
  538  
  539                    CBSS iteStmt si teStatemen t = new CB SSiteStmt( );
  540                    site Statement. setStation Num(psPati ent.getPsS ite().getF acilityNum ());
  541                    site Statement. setStation PhoneNum(p sPatient.g etPsSite() .getFacili tyPhoneNum ());
  542                    site Statement. setProcess Date(psPat ient.getPs Site().get ProcessDat e());
  543                    site Statement. setStateme ntDate(psP atient.get PsSite().g etStatemen tDate());
  544                    site Statement. setAmountD ue(psPatie nt.getAmou ntDue());
  545                    site Statement. setPrevBal ance(psPat ient.getPr evBalance( ));
  546                    site Statement. setTotalCh arges(psPa tient.getT otalCharge s());
  547                    site Statement. setTotalCr edits(psPa tient.getT otalCredit s());
  548                    site Statement. setNewBala nce(psPati ent.getNew Balance()) ;
  549                    site Statement. setSpecial Notes(psPa tient.getS pecialNote s());
  550                    site Statement. setNoParaC des(psPati ent.getRig htsObligat ionParagra phCodes()) ;
  551                    site Statement. setLargeFo ntInd(psPa tient.getL argeFontIn d());
  552                    site Statement. setArAddre ssFlag(psP atient.get AddressFla g());
  553                    site Statement. setLastBil lPrepDate( psPatient. getLastBil lPrepDate( ));
  554                    site Statement. setIsPrima ry(Boolean Char.N);
  555                    site Statement. setIsPrima ryAddress( BooleanCha r.N);
  556                    site Statement. setCreated Date(curre ntTime);
  557                    site Statement. setModifie dDate(curr entTime);
  558  
  559                    CBSS itePatient  sitePatie nt = new C BSSitePati ent();
  560                    site Patient.se tIcn(psPat ient.getIc nNumber()) ;
  561                    site Patient.se tDfn(psPat ient.getDf nNumber()) ;
  562                    site Patient.se tOldAcntNu m(psPatien t.getPatie ntAccount( ));
  563                    site Patient.se tFirstName (psPatient .getPatien tFirstName ());
  564                    site Patient.se tLastName( psPatient. getPatient LastName() );
  565                    site Patient.se tMiddleNam e(psPatien t.getPatie ntMiddleNa me());
  566                    site Patient.se tAddress1( psPatient. getAddress 1());
  567                    site Patient.se tAddress2( psPatient. getAddress 2());
  568                    site Patient.se tAddress3( psPatient. getAddress 3());
  569                    site Patient.se tCity(psPa tient.getC ity());
  570                    site Patient.se tState(psP atient.get State());
  571                    site Patient.se tZipCode(p sPatient.g etZipCode( ));
  572                    site Patient.se tCountry(p sPatient.g etCountryN ame());
  573                    site Patient.se tCreatedDa te(current Time);
  574                    site Patient.se tModifiedD ate(curren tTime);
  575                    site Statement. setSitePat ient(siteP atient);
  576  
  577                    List <CBSSiteTr ans> siteT ransL = ne w ArrayLis t<>();
  578                    for  (PSDetails  details :  psPatient .getPsDeta ilsL()) {
  579  
  580                             CBSSit eTrans sit eTrans = n ew CBSSite Trans();
  581                             siteTr ans.setDat ePosted(de tails.getD atePosted( ));
  582                             siteTr ans.setTra nsDesc(det ails.getTr ansDesc()) ;
  583                             siteTr ans.setTra nsAmount(d etails.get TransAmoun t());
  584                             siteTr ans.setRef erenceNum( details.ge tReference Num());
  585                             siteTr ans.setOrd erNum(deta ils.getSeq Num());
  586                             siteTr ans.setCre atedDate(c urrentTime );
  587                             siteTr ans.setMod ifiedDate( currentTim e);
  588                             siteTr ansL.add(s iteTrans);
  589                    }
  590                    site Statement. setSiteTra nsL(siteTr ansL);
  591  
  592                    retu rn siteSta tement;
  593           }
  594  
  595           /* *
  596            *  Save an s tatement a nd update  the databa se auto ge nerated ID .
  597            *  
  598            *  @param st atement
  599            *              The cons olidated s tatement.
  600            *  @return T he updated  statement  populated  with the  auto gener ated ID.
  601            * /
  602           pu blic void  saveStatem ent(CBSStm t statemen t) {
  603  
  604                    stat ement.setI d(cbsStmtD AO.save(st atement));
  605           }
  606  
  607           /* *
  608            *  Save an s ite patien t and upda te the dat abase auto  generated  ID.
  609            *  
  610            *  @param si tePatient
  611            *              The site  patient.
  612            *  @return T he updated  site pati ent popula ted with t he auto ge nerated ID .
  613            * /
  614           pu blic void  savePatien t(CBSSiteP atient sit ePatient)  {
  615  
  616                    site Patient.se tId(cbsSit ePatientDA O.save(sit ePatient)) ;
  617           }
  618  
  619           /* *
  620            *  Save an s ite statem ent and up date the d atabase au to generat ed ID.
  621            *  
  622            *  @param si teStatemen t
  623            *              The site  statement .
  624            *  @return T he updated  site stat ement popu lated with  the auto  generated  ID.
  625            * /
  626           pu blic void  saveSiteSt atement(CB SSiteStmt  siteStatem ent) {
  627  
  628                    site Statement. setId(cbsS iteStmtDAO .save(site Statement,  true));
  629           }
  630  
  631           /* *
  632            *  Save the  List of CB SStmts. Th e nested C BSSiteStmt s CBSSiteP atients an d
  633            *  CBSSiteTr ans object s will als o be saved  (deep sav e). The au to generat ed
  634            *  IDs will  NOT be upd ated in th e objects.  If the id s are requ ired, then  use
  635            *  the other  individua l saveXXX( ) methods.
  636            *  
  637            *  @param st atementL
  638            *              List of  CBSStmts t o save
  639            * /
  640           pu blic void  batchSaveS tatements( List<CBSSt mt> statem entL) {
  641                    cbsS tmtDAO.sav eBatch(sta tementL);
  642  
  643                    // c bsSiteStmt DAO.saveBa tch(statem entL);
  644                    for  (CBSStmt c bsStmt : s tatementL)  {
  645                             List<C BSSiteStmt > cbsSiteS tmtL = cbs Stmt.getSi teStmtL();
  646                             
  647                             cbsStm t.setId(cb sStmtDAO.g etCBSStmtI d(cbsStmt. getBatchRu nId(), cbs Stmt.getAc countId()) );;
  648  
  649                             if (cb sSiteStmtL  != null)  {
  650                                      for (CBS SiteStmt c bsSiteStmt  : cbsSite StmtL) {
  651                                               cbsSiteStm t.setStmtI d(cbsStmt. getId());
  652                                               cbsSiteStm tDAO.save( cbsSiteStm t, false);
  653                                      }
  654                             }
  655                    }
  656  
  657                    cbsS itePatient DAO.saveBa tch(statem entL);
  658                    cbsS iteTransDA O.saveBatc h(statemen tL);
  659           }
  660  
  661           /* *
  662            *  Query the  database  for an exi sting stat ement for  this accou nt for the
  663            *  same mont h as the s pecified d ate.
  664            *  
  665            *  @param ac countNumbe r
  666            *              The acco unt number  for the s tatement.
  667            *  @param st atementDat e
  668            *              The date  for this  month.
  669            *  @return T he existin g statemen t or null  if does no t exist.
  670            * /
  671           pr ivate CBSS tmt getExi stingState mentForAcc ount(final  long acco untNumber,  final Dat e statemen tDate) {
  672  
  673                    CBSS tmt statem ent = cbsS tmtDAO.get ExistingSt atementByA ccountAndM onth(accou ntNumber,  statementD ate);
  674  
  675                    if ( statement  != null) {
  676  
  677                             // The n get all  CBSSiteStm t from dat abase.
  678                             List<C BSSiteStmt > siteStat ementL = c bsSiteStmt DAO.getAll ByCBSStmtI D(statemen t.getId(),  true);
  679  
  680                             // The n get all  CBSSiteTra ns from da tabase.
  681                             if ((s iteStateme ntL != nul l) && !sit eStatement L.isEmpty( )) {
  682  
  683                                      List<CBS SiteTrans>  siteTrans L = cbsSit eTransDAO. getAllByCB SSiteStmtI D(statemen t.getId()) ;
  684  
  685                                      // Sort  into a map  (CBSSiteS tmt.ID to  List<CBSSi teTrans>)  for
  686                                      // the
  687                                      // list  of CBSSite Trans.
  688                                      Map<Long , List<CBS SiteTrans> > transQue ryM = site TransL.str eam()
  689                                                       .c ollect(Col lectors.gr oupingBy(w  -> w.getS iteStmtId( )));
  690  
  691                                      // Set t he appropr iate trans  list in t he CBSSite Stmt.
  692                                      for (CBS SiteStmt s iteStmt :  siteStatem entL) {
  693  
  694                                               logger.deb ug("SITEST MT.ID: " +  siteStmt. getId());
  695  
  696                                               List<CBSSi teTrans> s iteTransMa pEntry = t ransQueryM .get(siteS tmt.getId( ));
  697                                               // If no l ist then a n unrecove rable data  error.
  698                                               if (siteTr ansMapEntr y != null)  {
  699  
  700                                                       si teStmt.set SiteTransL (siteTrans MapEntry);
  701                                               } else {
  702                                                       fi nal String  error = " Unrecovera ble data e rror, site  trans map  is null f or site";
  703                                                       lo gger.error (error);
  704                                                       th row new Ru ntimeExcep tion(error );
  705                                               }
  706                                      }
  707  
  708                                      // Add t he site st atement li st to the  statement.
  709                                      statemen t.setSiteS tmtL(siteS tatementL) ;
  710                             } else  {
  711                                      final St ring error  = "Unreco verable da ta error,  site state ment list  is null or  empty";
  712                                      logger.e rror(error );
  713                                      throw ne w RuntimeE xception(e rror);
  714                             }
  715                    }
  716  
  717                    retu rn stateme nt;
  718           }
  719  
  720           /* *
  721            *  Publish t he INITIAL  statement s to NEW s tatus.
  722            *  
  723            *  @return T he number  of stateme nts that w ere update d.
  724            * /
  725           pu blic int p ublishAllN ewStatemen ts() {
  726  
  727                    Inte ger initia lStatus =  processSta tusDAO.get StatusFrom Enum(Proce ssStatus.S tatus.INIT IAL);
  728                    Inte ger newSta tus = proc essStatusD AO.getStat usFromEnum (ProcessSt atus.Statu s.NEW);
  729  
  730                    if ( (initialSt atus != nu ll) && (ne wStatus !=  null)) {
  731  
  732                             return  cbsStmtDA O.updateAl lStatusFro mTo(initia lStatus, n ewStatus);
  733                    } el se {
  734  
  735                             logger .error("Un able to ob tain statu s mapping  for: " + P rocessStat us.Status. INITIAL +  " or "
  736                                               + ProcessS tatus.Stat us.NEW);
  737                    }
  738  
  739                    retu rn 0;
  740           }
  741  
  742           /* *
  743            *  Revert th e REPLACED  statement s to NEW s tatus that  are assoc iated with
  744            *  INITIAL s tatements.
  745            *  
  746            *  @return T he number  of stateme nts that w ere update d.
  747            * /
  748           pu blic int r evertRepla cedStateme ntsAssocia tedWithIni tialStatem ents() {
  749  
  750                    int  revertedCo unt = -1;
  751  
  752                    Inte ger initia lStatus =  processSta tusDAO.get StatusFrom Enum(Proce ssStatus.S tatus.INIT IAL);
  753                    Inte ger replac edStatus =  processSt atusDAO.ge tStatusFro mEnum(Proc essStatus. Status.REP LACED);
  754                    Inte ger newSta tus = proc essStatusD AO.getStat usFromEnum (ProcessSt atus.Statu s.NEW);
  755  
  756                    if ( (initialSt atus != nu ll) && (re placedStat us != null ) && (newS tatus != n ull)) {
  757  
  758                             revert edCount =  cbsStmtDAO .updateSta tusFromToF orInitial( replacedSt atus, newS tatus, ini tialStatus );
  759                    } el se {
  760  
  761                             logger .error("Un able to ob tain statu s mapping  for: " + P rocessStat us.Status. INITIAL +  " or "
  762                                               + ProcessS tatus.Stat us.REPLACE D + " or "  + Process Status.Sta tus.NEW);
  763                    }
  764  
  765                    retu rn reverte dCount;
  766           }
  767  
  768           /* *
  769            *  Remove st atements t hat have I NITIAL sta tus.
  770            *  
  771            *  @return T he number  of stateme nts that w ere update d.
  772            * /
  773           pu blic int r emoveIniti alStatemen ts() {
  774  
  775                    int  removedCou nt = -1;
  776  
  777                    Inte ger initia lStatus =  processSta tusDAO.get StatusFrom Enum(Proce ssStatus.S tatus.INIT IAL);
  778  
  779                    if ( initialSta tus != nul l) {
  780  
  781                             remove dCount = c bsStmtDAO. deleteBySt atusId(ini tialStatus );
  782                    } el se {
  783  
  784                             logger .error("Un able to ob tain statu s mapping  for: " + P rocessStat us.Status. INITIAL);
  785                    }
  786  
  787                    retu rn removed Count;
  788           }
  789  
  790           /* *
  791            *  Query the  number of  consolida ted statem ents in th e NEW stat e.
  792            *  
  793            *  @return T he number  of consoli dated stat ements in  the NEW st ate or nul l if
  794            *          e rror.
  795            * /
  796           pu blic Long  getCountOf Statements InState(fi nal Proces sStatus.St atus state ) {
  797  
  798                    Long  available Count = nu ll;
  799  
  800                    Inte ger status  = process StatusDAO. getStatusF romEnum(st ate);
  801  
  802                    if ( status !=  null) {
  803  
  804                             availa bleCount =  cbsStmtDA O.getState mentCountW ithStatus( status);
  805  
  806                             if (av ailableCou nt == null ) {
  807  
  808                                      logger.e rror("Inva lid count  when check ing for co unt of sta tements");
  809                             }
  810  
  811                    } el se {
  812  
  813                             logger .error("Un able to ob tain statu s mapping  for: " + s tate);
  814                    }
  815  
  816                    retu rn availab leCount;
  817           }
  818  
  819           //
  820           //  Fix for D efect 6164 40
  821           //  Yiping Ya o - 01/03/ 2018
  822           //
  823           //  Return a  list of CB SStmt for  a CBS ID w ithin the  statement  date range  and print  date.
  824           //
  825           pu blic List< CBSStmt> g etStatemen ts(long cb sId)
  826           {
  827                    // P rint Delay  Days = 3
  828                    // S tart Date  is 5/1/Pre viousYear  to End Dat e 4/30/Cur rentYear
  829                    int  delayDays  = 3;
  830  
  831                    //Da te startDa te = null;
  832                    //Da te endDate  = null;
  833                    //Li st<CBSStmt > cbsStmtL  = getCbsS tmtDAO().g etListOfSt mntsById(c bsId, dela yDays, sta rtDate, en dDate);
  834  
  835                    int  startMonth  = 4; // A pril
  836                    int  totalMonth s = 12;
  837  
  838                    retu rn getCbsS tmtDAO().g etListOfSt mntsById(c bsId, dela yDays, sta rtMonth, t otalMonths );
  839           }
  840   }