73. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 4/18/2017 5:22:15 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.

73.1 Files compared

# Location File Last Modified
1 Caregivers-Title_1.zip\docroot\WEB-INF\src\gov\va\caret\portlet\action CaretActionCommand.java Mon Apr 17 14:03:14 2017 UTC
2 Caregivers-Title_1.zip\docroot\WEB-INF\src\gov\va\caret\portlet\action CaretActionCommand.java Tue Apr 18 16:34:19 2017 UTC

73.2 Comparison summary

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

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

73.4 Active regular expressions

No regular expressions were active.

73.5 Comparison detail

  1   package go v.va.caret .portlet.a ction;
  2  
  3   import com .liferay.c ounter.ser vice.Count erLocalSer viceUtil;
  4   import com .liferay.p ortal.NoSu chClassNam eException ;
  5   import com .liferay.p ortal.kern el.dao.jdb c.OutputBl ob;
  6   import com .liferay.p ortal.kern el.excepti on.PortalE xception;
  7   import com .liferay.p ortal.kern el.excepti on.SystemE xception;
  8   import com .liferay.p ortal.kern el.languag e.Language Util;
  9   import com .liferay.p ortal.kern el.log.Log ;
  10   import com .liferay.p ortal.kern el.log.Log FactoryUti l;
  11   import com .liferay.p ortal.kern el.upload. UploadPort letRequest ;
  12   import com .liferay.p ortal.kern el.util.Fi leUtil;
  13   import com .liferay.p ortal.kern el.util.Li stUtil;
  14   import com .liferay.p ortal.kern el.util.Pa ramUtil;
  15   import com .liferay.p ortal.kern el.util.Pr efsPropsUt il;
  16   import com .liferay.p ortal.kern el.util.Pr opsKeys;
  17   import com .liferay.p ortal.kern el.util.Pr opsUtil;
  18   import com .liferay.p ortal.kern el.util.St ringPool;
  19   import com .liferay.p ortal.kern el.util.St ringUtil;
  20   import com .liferay.p ortal.kern el.util.We bKeys;
  21   import com .liferay.p ortal.mode l.CountryC onstants;
  22   import com .liferay.p ortal.serv ice.Region ServiceUti l;
  23   import com .liferay.p ortal.serv ice.Servic eContext;
  24   import com .liferay.p ortal.them e.ThemeDis play;
  25   import com .liferay.p ortal.util .PortalUti l;
  26   import com .liferay.u til.portle t.PortletP rops;
  27  
  28   import gov .va.caret. Applicatio nWorkFlowE xception;
  29   import gov .va.caret. bean.Assmt Bean;
  30   import gov .va.caret. bean.Attac hmentBean;
  31   import gov .va.caret. bean.CespB ean;
  32   import gov .va.caret. bean.SocBe an;
  33   import gov .va.caret. controller .CaretView Controller ;
  34   import gov .va.caret. controller .dashboard .config.Cs lDashboard Config;
  35   import gov .va.caret. controller .dashboard .config.Da shboardCon fig;
  36   import gov .va.caret. controller .dashboard .config.Da shboardCon figFactory ;
  37   import gov .va.caret. controller .dashboard .config.Fa cilityDash boardConfi g;
  38   import gov .va.caret. model.Assm t;
  39   import gov .va.caret. model.BgAs n;
  40   import gov .va.caret. model.BoxG p;
  41   import gov .va.caret. model.CalE t;
  42   import gov .va.caret. model.Call ;
  43   import gov .va.caret. model.Cesp ;
  44   import gov .va.caret. model.ClSo c;
  45   import gov .va.caret. model.Docu m;
  46   import gov .va.caret. model.Note ;
  47   import gov .va.caret. model.Pers n;
  48   import gov .va.caret. model.Vcg;
  49   import gov .va.caret. model.VcgA n;
  50   import gov .va.caret. model.Waiv r;
  51   import gov .va.caret. model.WorI m;
  52   import gov .va.caret. model.impl .AssmtImpl ;
  53   import gov .va.caret. model.impl .BgAsnImpl ;
  54   import gov .va.caret. model.impl .CalEtImpl ;
  55   import gov .va.caret. model.impl .CallImpl;
  56   import gov .va.caret. model.impl .PersnImpl ;
  57   import gov .va.caret. model.impl .VcgAnImpl ;
  58   import gov .va.caret. model.impl .WaivrImpl ;
  59   import gov .va.caret. model.impl .WorImImpl ;
  60   import gov .va.caret. model.supp ort.Applic ationStatu s;
  61   import gov .va.caret. model.supp ort.BoxedG roupAssoci ation;
  62   import gov .va.caret. model.supp ort.Genera l;
  63   import gov .va.caret. model.supp ort.NoteSu pport;
  64   import gov .va.caret. model.supp ort.Person ;
  65   import gov .va.caret. model.supp ort.Primar y;
  66   import gov .va.caret. model.supp ort.Second ary;
  67   import gov .va.caret. model.supp ort.Second aryTwo;
  68   import gov .va.caret. model.supp ort.VcgApp lication;
  69   import gov .va.caret. model.supp ort.VcgSup port;
  70   import gov .va.caret. model.supp ort.Vetera n;
  71   import gov .va.caret. model.supp ort.WorkIt emSupport;
  72   import gov .va.caret. model.supp ort.WorkSt atus;
  73   import gov .va.caret. model.supp ort.WorkTy pe;
  74   import gov .va.caret. pdf.FileTy pe;
  75   import gov .va.caret. pm.portlet .PMPortlet ;
  76   import gov .va.caret. security.C Action;
  77   import gov .va.caret. security.C Action.Car etCan;
  78   import gov .va.caret. service.As smtLocalSe rviceUtil;
  79   import gov .va.caret. service.Bo xGpLocalSe rviceUtil;
  80   import gov .va.caret. service.Ca llLocalSer viceUtil;
  81   import gov .va.caret. service.Ca retLocalSe rviceUtil;
  82   import gov .va.caret. service.Ce spLocalSer viceUtil;
  83   import gov .va.caret. service.Cl SocLocalSe rviceUtil;
  84   import gov .va.caret. service.Do cumLocalSe rviceUtil;
  85   import gov .va.caret. service.Pe rsnLocalSe rviceUtil;
  86   import gov .va.caret. service.Vc gAnLocalSe rviceUtil;
  87   import gov .va.caret. service.Vc gLocalServ iceUtil;
  88   import gov .va.caret. service.Wa ivrLocalSe rviceUtil;
  89   import gov .va.caret. service.Wo rImLocalSe rviceUtil;
  90   import gov .va.caret. service.ct ssh.Servic eFacade;
  91   import gov .va.caret. util.Caret Map;
  92   import gov .va.caret. util.Caret StrPool;
  93   import gov .va.caret. util.Toolb ox;
  94   import gov .va.caret. view.Caret Param;
  95   import gov .va.caret. view.Resul tMap;
  96  
  97   import jav a.io.File;
  98   import jav a.io.FileI nputStream ;
  99   import jav a.io.FileN otFoundExc eption;
  100   import jav a.io.IOExc eption;
  101   import jav a.io.Input Stream;
  102   import jav a.io.Seria lizable;
  103   import jav a.text.Mes sageFormat ;
  104   import jav a.util.Arr ayList;
  105   import jav a.util.Arr ays;
  106   import jav a.util.Cal endar;
  107   import jav a.util.Col lection;
  108   import jav a.util.Col lections;
  109   import jav a.util.Dat e;
  110   import jav a.util.Has hMap;
  111   import jav a.util.Has hSet;
  112   import jav a.util.Lis t;
  113   import jav a.util.Loc ale;
  114   import jav a.util.Map ;
  115   import jav a.util.Set ;
  116  
  117   import jav ax.portlet .ActionReq uest;
  118   import jav ax.portlet .ActionRes ponse;
  119   import jav ax.portlet .PortletRe quest;
  120   import jav ax.portlet .PortletSe ssion;
  121   import jav ax.portlet .ProcessAc tion;
  122  
  123  
  124   public cla ss CaretAc tionComman d extends  ActionComm and implem ents Seria lizable {
  125           
  126   private st atic final  long seri alVersionU ID = 22515 0078003840 9153L;
  127           
  128  
  129   @ProcessAc tion (name ="loadVcgM anagement" )
  130   public voi d loadVcgM anagement(  ActionReq uest reque st, Action Response r esponse )  {
  131           lo ng worImId  = ParamUt il.getLong (request,  CaretStrPo ol.WORK_ID );
  132           lo ng vcgId =  ParamUtil .getLong(  request, C aretStrPoo l.VCGID );
  133           if  ( vcgId = = 0 ){
  134                    vcgI d = (Long)  request.g etAttribut e(CaretStr Pool.VCGID );
  135           }
  136           
  137           Ma p<String,  Object> fo rm = Resul tMap.getFo rm(request );
  138           fo rm.put(Car etStrPool. WORK_ID, w orImId);
  139           tr y {
  140                    VcgS upport vcg  = null;
  141                    VcgA n app = nu ll;
  142                    if (  vcgId !=  0 ){
  143                             long a ssociate =  ParamUtil .getLong(r equest, "a ssociate") ;
  144                             if ( a ssociate >  0 ) {
  145                                      associat eWorkItem  ( associat e, vcgId,  request );
  146                             }
  147                             vcg =  VcgSupport .getVcgSup port(vcgId );
  148                             app =   VcgAnLoca lServiceUt il.getRece nt(vcgId);
  149                             if ( a pp == null  ){
  150                                      app = ne w VcgAnImp l();
  151                             }
  152                             List<D ocum> supp ortDocs =  new ArrayL ist<Docum> ();
  153                             List<W orIm> work Items = Wo rImLocalSe rviceUtil. findByVcgI d(vcgId);
  154                             List<W orIm> open Referrals  = new Arra yList<WorI m>();
  155                             List<W orIm> clos edReferral s = new Ar rayList<Wo rIm>();
  156                             for (  WorIm work Item: work Items ){
  157                                      WorkType  type = Wo rkType.val ueOf( work Item.getTy pe() );
  158                                      switch (  type ){
  159                                      case REF ERRAL:
  160                                      case CAL L_REFERRAL :
  161                                      case CSL _REFERRAL:
  162                                      case HEC _REFERRAL:
  163                                      case HRC _REFERRAL:
  164                                               if ( Caret StrPool.CO MPLETE.equ als( workI tem.getSta tus() ) ){
  165                                                       cl osedReferr als.add(ne w WorkItem Support(wo rkItem));
  166                                               } else {
  167                                                       op enReferral s.add(new  WorkItemSu pport(work Item));
  168                                               }
  169                                      default:
  170                                      }
  171                             }
  172                             
  173                             Result Map.getRes ultTotalMa p( request  ).put( "v cgClosedRe fs", close dReferrals .size() );
  174                             Result Map.getRes ultTotalMa p( request  ).put( "v cgOpenRefs ", openRef errals.siz e() );
  175                             
  176                             Result Map.getRes ultListMap ( request  ).put("vcg ClosedRefs ", closedR eferrals);
  177                             Result Map.getRes ultListMap ( request  ).put("vcg OpenRefs",  openRefer rals);
  178                             
  179                             form.p ut("suppor tDocs", su pportDocs  );
  180                             //_log .info("num ber of sup porting do cs is : "+ supportDoc s.size());
  181                             
  182                    }
  183                    
  184                    form .put(Caret StrPool.VC GAN, app);
  185                    form .put("vcg" , vcg);
  186                    
  187                                                       
  188                    
  189                    //** *Start of  Supporting  Doc Code  ****           
  190                    VcgS upport vcg Support =  new VcgSup port(vcg);
  191                    vcgS upport.get Supporting DocData();
  192                                      
  193                    form .put("vcgD ocsCurrent ", vcgSupp ort.getVcg DocsCurren t());
  194                    form .put("vcgD ocsCurrent Size", vcg Support.ge tVcgDocsCu rrent().si ze());
  195  
  196                    
  197                    // P eriodic As sessments  code 
  198                    Stri ng section  = ParamUt il.getStri ng(request , "section ", "");
  199                    form .put("sect ion", sect ion);
  200                    
  201                    form .put("EaE" , Toolbox. isMviEnabl ed());
  202                    
  203                    //** *Start of  Assessment s Code***                 
  204                    form .put(Caret StrPool.VE TERAN_ID,  app.getVet eranId() ) ;
  205                    if (  vcgId > 0  ){
  206                             //get  all applic ations for  the vcg r ecord (vcg id) - then  check for  IN_PROCES S apps
  207                             List<V cgAn> vcgA nList= Vcg AnLocalSer viceUtil.g etByVcg(vc gId);                              
  208                             
  209                             for(Vc gAn vcgAn: vcgAnList)
  210                             {
  211                                      String d ateStr = T oolbox.for matDateCpr s(vcgAn.ge tReceivedD ate());
  212                                      if(vcg.g etPrimaryV cgAnId()== vcgAn.getV cgAnId()){
  213                                               form.put(" primaryVal idAppDate" , dateStr) ;
  214                                      }
  215                                      if(vcg.g etSecondar yVcgAnId() ==vcgAn.ge tVcgAnId() ){
  216                                               form.put(" secondaryV alidAppDat e", dateSt r);
  217                                      }                                   
  218                                      if(vcg.g etSecondar yTwoVcgAnI d()==vcgAn .getVcgAnI d()){
  219                                               form.put(" secondaryT woValidApp Date", dat eStr);
  220                                      }
  221                             }
  222                             
  223                             //for  periodic a ssessments
  224                             if(vcg .getPrimar yDispReaso n()!=null  && (vcg.is Approved(v cg.getPrim aryDispRea son())||(v cg.isReins tated(vcg. getPrimary DispReason ())))){
  225                                      String d ateStr = T oolbox.for matDateCpr s(vcg.getP rimaryDisp ositionDat e());
  226                                      form.put ("primaryA pprovalDat e", dateSt r);                                  
  227                             }
  228                    
  229                             loadAs sessments( request, f orm, vcg);
  230                             
  231                             String  showSecti on = Param Util.getSt ring(reque st, CaretS trPool.SHO W_SECTION,  "");
  232                             reques t.setAttri bute("show Section",  showSectio n);
  233                             if(sho wSection!= null && !s howSection .equals("" )){
  234                                      request. setAttribu te("showAs sessments" , true);                     
  235                             }
  236                    }
  237                    //** *End of As sessments  Code***
  238                    
  239           }  catch (Ill egalArgume ntExceptio n e) {
  240                    Appl icationWor kFlowExcep tion.handl eException (e);
  241           }  catch (Por talExcepti on e) {
  242                    Appl icationWor kFlowExcep tion.handl eException (e);
  243           }
  244           
  245   }
  246  
  247  
  248           @P rocessActi on (name=" loadProces sApplicati on")
  249           pu blic void  loadProces sApplicati on ( Actio nRequest r equest, Ac tionRespon se respons e ) {
  250                    Map< String, Ob ject> form  = ResultM ap.getForm (request);
  251                    requ est.setAtt ribute( Ca retStrPool .TRACKER,  CaretParam .trackNdx(  request )  );
  252                    long  worImId =  ParamUtil .getLong(r equest, Ca retStrPool .WORK_ID);
  253                    form .put(Caret StrPool.WO RK_ID, wor ImId);
  254                    try  {
  255                             if ( w orImId > 0  ){
  256                                      
  257                                      long vcg AnId = Par amUtil.get Long(reque st, CaretS trPool.PRI MARY_KEY);
  258                                      _log.inf o("primary  key is :  "+vcgAnId) ;
  259                                      VcgAn ap p = VcgAnL ocalServic eUtil.getV cgAn( vcgA nId );
  260                                      Veteran  veteran =  new Vetera n( PersnLo calService Util.getPe rsn( app.g etVeteranI d() ) );
  261                                      
  262                                      form.put ( CaretStr Pool.VETER AN_PERSN,  veteran );
  263                                      Boolean  verifiedVe teranOnly  = true; //  || String Pool.TRUE. equals( Po rtletProps .get("proc ess-app-ve teran.regi stered") ) ;
  264                                      form.put ( CaretStr Pool.REGIS TERED_ONLY , verified VeteranOnl y );
  265                                      
  266                                      if ( app .getPrimar yId() > 0  ){
  267                                               form.put(C aretStrPoo l.PRIMARY_ PERSN, new  Primary ( PersnLocal ServiceUti l.getPersn ( app.getP rimaryId()  ) ) );
  268                                      }
  269                                      if ( app .getSecond aryId() >  0 ){
  270                                               form.put(C aretStrPoo l.SECONDAR Y_PERSN, n ew Seconda ry (PersnL ocalServic eUtil.getP ersn( app. getSeconda ryId() ) )  );
  271                                      }
  272                                      if ( app .getSecond aryTwoId()  > 0 ){
  273                                               form.put(C aretStrPoo l.SECONDAR Y_TWO_PERS N, new Sec ondaryTwo  (PersnLoca lServiceUt il.getPers n( app.get SecondaryT woId() ) )  );
  274                                      }
  275                                      String a ctives = A rrays.deep ToString(  veteran.ge tVcgActive s() );
  276                                      form.put (CaretStrP ool.ACTIVE _VCG, acti ves.substr ing(1,acti ves.length ()-2) );
  277                                      form.put ("workType ", WorImLo calService Util.getWo rIm(worImI d).getType () );
  278                                      form.put (CaretStrP ool.VCGAN,  app);
  279                                      
  280                                      List<Doc um> suppor tDocs = Do cumLocalSe rviceUtil. getByPrima ryKey( vcg AnId );
  281                                      form.put ("supportD ocs", supp ortDocs );
  282                                      _log.inf o("number  of support ing docs i s : "+supp ortDocs.si ze());
  283                                      form.put ("veteranI d", app.ge tVeteranId () );
  284                                      response .setRender Parameter( CaretStrPo ol.MVC_PAT H, CaretSt rPool.VCG_ DISPOSITIO N_PAGE);
  285                             }
  286                    } ca tch (Illeg alArgument Exception  e) {
  287                             Applic ationWorkF lowExcepti on.handleE xception(e );
  288                    } ca tch (Porta lException  e) {
  289                             Applic ationWorkF lowExcepti on.handleE xception(e );
  290                    } ca tch (Syste mException  e) {
  291                             Applic ationWorkF lowExcepti on.handleE xception(e );
  292                    }
  293                    
  294           }
  295           
  296           
  297           pu blic void  loadAssess ments( Act ionRequest  request,  Map<String ,Object> f orm, Vcg v cg) 
  298           {
  299                    try 
  300                    {                         
  301                             AssmtB ean primar yClinical  = new Assm tBean(new  AssmtImpl( ), CaretSt rPool.PRIM ARY_CLINIC AL);                                 
  302                             AssmtB ean primar yAssessmen t = new As smtBean(ne w AssmtImp l(), Caret StrPool.PR IMARY_ASSE SSMENT);                    
  303                             AssmtB ean primar yTraining  = new Assm tBean(new  AssmtImpl( ), CaretSt rPool.PRIM ARY_TRAINI NG);                                 
  304                             AssmtB ean primar yInHome =  new AssmtB ean(new As smtImpl(),  CaretStrP ool.PRIMAR Y_IN_HOME) ;                                    
  305                             AssmtB ean second aryClinica l = new As smtBean(ne w AssmtImp l(), Caret StrPool.SE CONDARY_CL INICAL); 
  306                             AssmtB ean second aryAssessm ent = new  AssmtBean( new AssmtI mpl(), Car etStrPool. SECONDARY_ ASSESSMENT ); 
  307                             AssmtB ean second aryTrainin g = new As smtBean(ne w AssmtImp l(), Caret StrPool.SE CONDARY_TR AINING); 
  308                             AssmtB ean second aryTwoClin ical = new  AssmtBean (new Assmt Impl(), Ca retStrPool .SECONDARY _TWO_CLINI CAL); 
  309                             AssmtB ean second aryTwoAsse ssment = n ew AssmtBe an(new Ass mtImpl(),  CaretStrPo ol.SECONDA RY_TWO_ASS ESSMENT); 
  310                             AssmtB ean second aryTwoTrai ning = new  AssmtBean (new Assmt Impl(), Ca retStrPool .SECONDARY _TWO_TRAIN ING); 
  311                             
  312                             List<A ssmt> comp letedAsses smentList  = AssmtLoc alServiceU til.findBy VcgId(vcg. getVcgId() );
  313                             
  314                             long y ear=0;
  315                             for(As smt assess ment:compl etedAssess mentList)
  316                             {
  317                                      //get ac tive asses sments for  the careg iver
  318                                      if(asses sment.isAc tive())
  319                                      {
  320                                               String dat eStr = Too lbox.forma tDateCprs( assessment .getComple tionDate() );                                   
  321                                               if(assessm ent.getTyp e().equals (CaretStrP ool.PRIMAR Y_CLINICAL ) && asses sment.getC aregiverId ()==vcg.ge tPrimaryId ()){
  322                                                       pr imaryClini cal.setAss essment(as sessment);
  323                                                       pr imaryClini cal.setFor mattedcomp letionDate (dateStr);                                        
  324                                               }else if(a ssessment. getType(). equals(Car etStrPool. PRIMARY_AS SESSMENT)  && assessm ent.getCar egiverId() ==vcg.getP rimaryId() ){
  325                                                       pr imaryAsses sment.setA ssessment( assessment );
  326                                                       pr imaryAsses sment.setF ormattedco mpletionDa te(dateStr );
  327                                               }else if(a ssessment. getType(). equals(Car etStrPool. PRIMARY_TR AINING) &&  assessmen t.getCareg iverId()== vcg.getPri maryId()){
  328                                                       pr imaryTrain ing.setAss essment(as sessment);
  329                                                       pr imaryTrain ing.setFor mattedcomp letionDate (dateStr);
  330                                               }else if(a ssessment. getType(). equals(Car etStrPool. PRIMARY_IN _HOME) &&  assessment .getCaregi verId()==v cg.getPrim aryId()){
  331                                                       pr imaryInHom e.setAsses sment(asse ssment);
  332                                                       pr imaryInHom e.setForma ttedcomple tionDate(d ateStr);
  333                                               }else if(a ssessment. getType(). equals(Car etStrPool. SECONDARY_ CLINICAL)  && assessm ent.getCar egiverId() ==vcg.getS econdaryId ()){
  334                                                       se condaryCli nical.setA ssessment( assessment );
  335                                                       se condaryCli nical.setF ormattedco mpletionDa te(dateStr );
  336                                               }else if(a ssessment. getType(). equals(Car etStrPool. SECONDARY_ ASSESSMENT ) && asses sment.getC aregiverId ()==vcg.ge tSecondary Id()){
  337                                                       se condaryAss essment.se tAssessmen t(assessme nt);
  338                                                       se condaryAss essment.se tFormatted completion Date(dateS tr);
  339                                               }else if(a ssessment. getType(). equals(Car etStrPool. SECONDARY_ TRAINING)  && assessm ent.getCar egiverId() ==vcg.getS econdaryId ()){
  340                                                       se condaryTra ining.setA ssessment( assessment );
  341                                                       se condaryTra ining.setF ormattedco mpletionDa te(dateStr );
  342                                               }else if(a ssessment. getType(). equals(Car etStrPool. SECONDARY_ TWO_CLINIC AL) && ass essment.ge tCaregiver Id()==vcg. getSeconda ryTwoId()) {
  343                                                       se condaryTwo Clinical.s etAssessme nt(assessm ent);
  344                                                       se condaryTwo Clinical.s etFormatte dcompletio nDate(date Str);
  345                                               }else if(a ssessment. getType(). equals(Car etStrPool. SECONDARY_ TWO_ASSESS MENT) && a ssessment. getCaregiv erId()==vc g.getSecon daryTwoId( )){
  346                                                       se condaryTwo Assessment .setAssess ment(asses sment);
  347                                                       se condaryTwo Assessment .setFormat tedcomplet ionDate(da teStr);
  348                                               }else if(a ssessment. getType(). equals(Car etStrPool. SECONDARY_ TWO_TRAINI NG) && ass essment.ge tCaregiver Id()==vcg. getSeconda ryTwoId()) {
  349                                                       se condaryTwo Training.s etAssessme nt(assessm ent);
  350                                                       se condaryTwo Training.s etFormatte dcompletio nDate(date Str);
  351                                               }
  352                                              
  353                                               if(assessm ent.getYea r()>year){
  354                                                       ye ar = asses sment.getY ear();
  355                                               }
  356                                      }
  357                             }
  358                                              
  359                             
  360                             List<A ssmtBean>  primaryAss essmentLis t = new Ar rayList<As smtBean>() ;
  361                             primar yAssessmen tList.add( primaryCli nical);
  362                             primar yAssessmen tList.add( primaryAss essment);
  363                             primar yAssessmen tList.add( primaryTra ining);
  364                             primar yAssessmen tList.add( primaryInH ome);
  365                             
  366                             List<A ssmtBean>  secondaryA ssessmentL ist = new  ArrayList< AssmtBean> ();
  367                             second aryAssessm entList.ad d(secondar yClinical) ;
  368                             second aryAssessm entList.ad d(secondar yAssessmen t);
  369                             second aryAssessm entList.ad d(secondar yTraining) ;
  370  
  371                             List<A ssmtBean>  secondaryT woAssessme ntList = n ew ArrayLi st<AssmtBe an>();
  372                             second aryTwoAsse ssmentList .add(secon daryTwoCli nical);
  373                             second aryTwoAsse ssmentList .add(secon daryTwoAss essment);
  374                             second aryTwoAsse ssmentList .add(secon daryTwoTra ining);
  375  
  376                             form.p ut("primar yAssessmen tList", pr imaryAsses smentList) ;
  377                             form.p ut("second aryAssessm entList",  secondaryA ssessmentL ist);
  378                             form.p ut("second aryTwoAsse ssmentList ", seconda ryTwoAsses smentList) ;                               
  379                             
  380                             
  381                             //**** Start for  Periodic A ssessments *****
  382                             
  383                             //get  current se t of perio dic assess ments
  384                             List<A ssmtBean>  periodicAs sessmentLi st = new A rrayList<A ssmtBean>( );
  385                             for(As smt assess ment:compl etedAssess mentList)
  386                             {
  387                                      AssmtBea n assmtBea n = new As smtBean(ne w AssmtImp l(), "");
  388                                      //String  completio nDateStr =  Toolbox.f ormatDateC prs(assess ment.getCo mpletionDa te());
  389                                      String c ompletionD ateStr = " ";
  390                                      if(asses sment.isAc tive() &&  assessment .getYear() >0 && (yea r==assessm ent.getYea r() || (ye ar-1)==ass essment.ge tYear()))
  391                                      {
  392                                               String sch eduleDateS tr = Toolb ox.formatD ateCprs(as sessment.g etSchedule Date());
  393                                               if(assessm ent.getMod e().equals (CaretStrP ool.NOT_CO MPLETED) & & assessme nt.getComp letionDate ()==null){
  394                                                       co mpletionDa teStr = "" ;
  395                                               }else{
  396                                                       co mpletionDa teStr = To olbox.form atDateCprs (assessmen t.getCompl etionDate( ));
  397                                               }
  398                                                                                          
  399                                               assmtBean. setAssessm ent(assess ment);
  400                                               assmtBean. setFormatt edSchedule Date(sched uleDateStr );                                       
  401                                               assmtBean. setFormatt edcompleti onDate(com pletionDat eStr);                                            
  402                                               periodicAs sessmentLi st.add(ass mtBean);
  403                                      }
  404                                      //_log.i nfo("asses sment id i s : "+asse ssment.get AssmtId()) ;
  405                             }        
  406                             
  407                             //_log .info("per iodic assm t number i s : "+peri odicAssess mentList.s ize());
  408  
  409                             form.p ut("period icAssessme ntList", p eriodicAss essmentLis t);
  410                             form.p ut("period icAssessme ntSize", p eriodicAss essmentLis t.size());
  411                             
  412                    } ca tch (Appli cationWork FlowExcept ion e) {
  413                             Applic ationWorkF lowExcepti on.handleE xception(e );
  414                    }
  415           }
  416           
  417           
  418           
  419           @P rocessActi on (name=" workClose" )
  420           pu blic void  workClose  ( ActionRe quest requ est, Actio nResponse  response )  {
  421                    _log .info("wor kClose");
  422                    
  423                    long  worImId =  ParamUtil .getLong(r equest, Ca retStrPool .WORK_ID);
  424                    try  {
  425                             Servic eContext s c = CaretP aram.setCa retService Context(re quest);
  426                             WorIm  workItem =  WorImLoca lServiceUt il.getWorI m(worImId) ;
  427                             switch  ( WorkTyp e.valueOf(  workItem. getType()  ) ){
  428                             case C ALL_REFERR AL:
  429                             case R EFERRAL:
  430                             case H EC_REFERRA L:
  431                             case H RC_REFERRA L:
  432                             case C SL_REFERRA L:
  433                                      
  434                                      workItem .setStatus ( WorkStat us.COMPLET E.name() ) ;
  435                                      workItem .setComple tionBy( sc .getUserId () );
  436                                      workItem .setComple tionDate(  sc.getCrea teDate() ) ;
  437                                      
  438                                      CaretLoc alServiceU til.save(w orkItem);
  439                                      _log.inf o("adding  note " + L anguageUti l.get( Loc ale.getDef ault(), Pa ramUtil.ge t(request,  CaretStrP ool.WORK_C OMMENT, St ringPool.B LANK) ) );
  440                                      CaretLoc alServiceU til.addNot e(Toolbox. createNote (sc.getCre ateDate(),
  441                                                       wo rImId,
  442                                                       wo rkItem.get GroupId(),
  443                                                       sc .getUserId (),
  444                                                       Pa ramUtil.ge t(request,  CaretStrP ool.WORK_C OMMENT, St ringPool.B LANK)));
  445                             defaul t:
  446                                      break;
  447                             }
  448                    } ca tch (Porta lException  e) {
  449                             Applic ationWorkF lowExcepti on.handleE xception(e );
  450                    } ca tch (Syste mException  e) {
  451                             Applic ationWorkF lowExcepti on.handleE xception(e );
  452                    }
  453           }
  454  
  455           @P rocessActi on (name=" openReferr al")
  456           pu blic void  openReferr al ( Actio nRequest r equest, Ac tionRespon se respons e ) {
  457                    
  458                    try  {
  459                             WorkTy pe type =  WorkType.v alueOf( Pa ramUtil.ge tString(re quest, "ty pe", Strin gPool.BLAN K) );  
  460                             reques t.setAttri bute(Caret StrPool.WO RK_ID, Par amUtil.get Long(reque st, CaretS trPool.WOR K_ID ) );
  461                             switch  ( type ){
  462                             case C ALL_REFERR AL:
  463                                      loadCall (request);
  464                                      response .setRender Parameter( CaretStrPo ol.MVC_PAT H, CaretSt rPool.EDIT _CALL_PAGE );
  465                                      break;
  466                             case R EFERRAL:
  467                             case H EC_REFERRA L:
  468                             case H RC_REFERRA L:
  469                             case C SL_REFERRA L:
  470                                      loadRefe rral(reque st);
  471                                      response .setRender Parameter( CaretStrPo ol.MVC_PAT H, CaretSt rPool.EDIT _REFERRAL_ PAGE);
  472                                      break;
  473                             defaul t:
  474                                      break;
  475                             }
  476                             if ( " VCG_MANAGE MENT_PAGE" .equals( P aramUtil.g etString(r equest, "o nPageCompl ete", Stri ngPool.BLA NK) ) ){
  477                                      ResultMa p.getForm( request).p ut("onPage Complete",  "VCG_MANA GEMENT_PAG E" );
  478   //                                 response .setRender Parameter( CaretStrPo ol.MVC_PAT H, CaretSt rPool.VCG_ MANAGEMENT _PAGE);
  479                             }
  480                    } ca tch (Porta lException  e) {
  481                             Applic ationWorkF lowExcepti on.handleE xception(e );
  482                    } ca tch (Illeg alArgument Exception  e) {
  483                             Applic ationWorkF lowExcepti on.handleE xception(e );
  484                    } 
  485                    
  486           }
  487           
  488   //      
  489   //      @S uppressWar nings("unc hecked")
  490   //      @P rocessActi on (name=" approvePay mentMonth" )
  491   //      pu blic void  approvePay mentMonth(  ActionReq uest actio nRequest,  ActionResp onse actio nResponse  ) {
  492   //               _log .info("app rovePaymen tMonth..."  );
  493   //               int  m = ParamU til.get(ac tionReques t, "month" , 12);
  494   //               int  year = Par amUtil.get (actionReq uest, "yea r", 0);
  495   //               _log .info("mon th= " + m  + ", year= " + year ) ;
  496   //               if (  m < 12 &&  year > 0  ){
  497   //                        Calend ar calenda r = Calend ar.getInst ance();
  498   //                        calend ar.set(Cal endar.MONT H, m);
  499   //                        calend ar.set(Cal endar.YEAR , year);
  500   //                        calend ar.set(Cal endar.DAY_ OF_MONTH,  0);
  501   //                        calend ar.set(Cal endar.HOUR , 0);
  502   //                        Date d ate = cale ndar.getTi me();
  503   //                        _log.i nfo( "date =" + date  );
  504   //                        
  505   //                        Dynami cQuery dyn amicQuery  = DynamicQ ueryFactor yUtil.forC lass( StiP tImpl.clas s, PortalC lassLoader Util.getCl assLoader( ) )
  506   //                        .add (  PropertyF actoryUtil .forName ( "StipendSt artDate"). gt( date )  );
  507   //                        calend ar.roll(Ca lendar.MON TH, true);
  508   //                        Date d ate2 = cal endar.getT ime();
  509   //                        dynami cQuery.add  ( Propert yFactoryUt il.forName  ("Stipend StartDate" ).lt( date 2 ) )
  510   //                        .add (  PropertyF actoryUtil .forName ( "StipendSt atus").eq(  "PENDING  PAYMENT" )  );
  511   //                        List<S tiPt> list  = Collect ions.empty List();
  512   //                        try {
  513   //                                 list = S tiPtLocalS erviceUtil .dynamicQu ery(dynami cQuery);
  514   //                                 Date now  = new Dat e();
  515   //                                 for ( St iPt paymen t : list ) {
  516   //                                          PayLg payL og = new P ayLgImpl() ;
  517   //                                          Double pay mentAmt =  Double.val ueOf( paym ent.getTie rHours() )  * Double. valueOf( p ayment.get BlsRateHou rly() );
  518   //                                          payLog.set Amount( pa ymentAmt ) ;
  519   //                                          payLog.set PaymentDat e( payment .getStipen dStartDate () );
  520   //                                          payLog.set StiPtId( p ayment.get PrimaryKey () );
  521   //                                          PayLgLocal ServiceUti l.addPayLg (payLog);
  522   //                                         
  523   //                                          payment.se tStipendSt atus("PAYM ENT_FINANC ED");
  524   //                                          payment.se tStipendAp provedDate (now);
  525   //                                          payment.se tMonthlyPa yment( pay mentAmt.to String() ) ;
  526   //                                          StiPtLocal ServiceUti l.updateSt iPt(paymen t);
  527   //                                 }
  528   //                        } catc h (SystemE xception e ) {
  529   //                                 Applicat ionWorkFlo wException .handleExc eption(e);
  530   //                        }
  531   //                        action Request.se tAttribute ("monthYea r", Months .values()[ m] + ", "  + year );
  532   //               }
  533   //      }
  534   //      
  535           @P rocessActi on (name=" loadTen10A pp")
  536           pu blic void  loadVcgAnA pp ( Actio nRequest a ctionReque st, Action Response a ctionRespo nse ) {
  537                    _log .info("loa dTen10App. .." );
  538                    acti onResponse .setRender Parameter( CaretStrPo ol.MVC_PAT H, "/jsp/i nternal/cr eateTen10. jsp" );
  539                    load StatesAndF acilities(  actionReq uest );
  540           }
  541           
  542           pu blic void  loadStates AndFacilit ies ( Port letRequest  request )  {
  543                    try  {
  544                             Map<St ring,Objec t> caret =  ResultMap .getCaretM ap(request );
  545                             caret. put( Caret StrPool.VH A_SYSTEM,  Toolbox.ge tVhaOrgTre e( PortalU til.getCom panyId( re quest ), t rue ) );
  546                             try {
  547                                      caret.pu t(CaretStr Pool.STATE S, RegionS erviceUtil .getRegion s( Country Constants. DEFAULT_CO UNTRY_ID )  );
  548                             } catc h (SystemE xception e ) {
  549                                      Applicat ionWorkFlo wException .handleExc eption(e);
  550                             }
  551                             
  552                             
  553                    } ca tch (Porta lException  e) {
  554                             Applic ationWorkF lowExcepti on.handleE xception(e );
  555                    }
  556           }
  557           
  558           pr ivate void  saveBoxGr oups ( Por tletReques t request,  long prim aryKey ){
  559                    try  {
  560                             List<L ong> fmChe cks = Care tParam.loa dSelectedB oxModel(re quest, Car etStrPool. BOX_GROUP) ;
  561  
  562                             String [] radioNa mes = new  String[]{
  563                                               "boxRadioG rp_heardFr omUs", "bo xRadioGrp_ enrolledVa Health", 
  564                                               "boxRadioG rp_dischar gedAfter91 1", "boxRa dioGrp_vet eranScCond ition",
  565                                               "boxRadioG rp_prescre enPcafc"
  566                             };
  567                             for (  String rad io: radioN ames ){
  568                                      Long rad ioId = Par amUtil.get Long(reque st, radio,  0);
  569                                      if ( rad ioId > 0 ) {
  570                                               fmChecks.a dd(radioId );
  571                                      }
  572                             }
  573                             
  574                             if ( p rimaryKey  > 0 ){
  575                                      List<Lon g> updated  = new Arr ayList<Lon g>();
  576                                      List<BgA sn> bgAsnL ist = BoxG pLocalServ iceUtil.ge tBoxGroupA ssociation s( primary Key );
  577                                      for ( Bg Asn bgAsn:  bgAsnList  ){
  578                                               if ( fmChe cks.contai ns( bgAsn. getBoxGpId () ) ){
  579                                                       if  ( !bgAsn. isSelected () ){
  580                                                                bgAs n.setSelec ted( true  );
  581                                                                Care tLocalServ iceUtil.sa ve( new Bo xedGroupAs sociation( bgAsn) );
  582                                                                upda ted.add( b gAsn.getBo xGpId() );
  583                                                       }
  584                                                       fm Checks.rem ove( bgAsn .getBoxGpI d() );
  585                                               } else {
  586                                                       if  ( bgAsn.i sSelected( ) ){
  587                                                                bgAs n.setSelec ted( false  );
  588                                                                Care tLocalServ iceUtil.sa ve( new Bo xedGroupAs sociation( bgAsn) );
  589                                                       }
  590                                               }
  591                                      }
  592                                      for ( Lo ng boxGpId : fmChecks ){
  593                                               if ( ! upd ated.conta ins( boxGp Id ) ){
  594                                                       Bg Asn bgAsn  = new BgAs nImpl();
  595                                                       bg Asn.setBox GpId( boxG pId );
  596                                                       bg Asn.setOwn erId( prim aryKey );
  597                                                       bg Asn.setSel ected( tru e );
  598                                                       Ca retLocalSe rviceUtil. save( new  BoxedGroup Associatio n(bgAsn) ) ;
  599                                               }
  600                                      }
  601                             } else  {
  602                                      for ( Lo ng boxGpId : fmChecks  ){
  603                                               BgAsn bgAs n = new Bg AsnImpl();
  604                                               bgAsn.setB oxGpId(box GpId);
  605                                               bgAsn.setO wnerId( pr imaryKey ) ;
  606                                               bgAsn.setS elected( t rue );
  607                                               CaretLocal ServiceUti l.save( ne w BoxedGro upAssociat ion(bgAsn)  );
  608                                      }
  609                             }
  610                             
  611                             _log.i nfo(fmChec ks);
  612                    } ca tch (Appli cationWork FlowExcept ion e) {
  613                             Applic ationWorkF lowExcepti on.handleE xception(e );
  614                    }
  615           }
  616           
  617           pr ivate void  saveCall  ( ActionRe quest requ est ) thro ws Applica tionWorkFl owExceptio n{
  618                    _log .info("sav eCall..."  );
  619                    Call  call = nu ll;
  620                    Pers on caller  = null;
  621                    Vete ran vetera n = null;
  622                    
  623                    getO utput(requ est);
  624                    Long  callId =  ParamUtil. getLong(re quest, "ca ll_primary Key");
  625                    Long  veteranId  = ParamUt il.getLong (request,  "veteranPe rsn_primar yKey");
  626                    
  627                    Serv iceContext  sc = Care tParam.set CaretServi ceContext( request);
  628                    if (  callId >  0 ){
  629                             try {
  630                                      call = C allLocalSe rviceUtil. getCall(ca llId);
  631                             } catc h (PortalE xception e ) {
  632                                      Applicat ionWorkFlo wException .handleExc eption(e);
  633                             } catc h (SystemE xception e ) {
  634                                      Applicat ionWorkFlo wException .handleExc eption(e);
  635                             }
  636                    }
  637                    
  638                    if (  call == n ull) {
  639                             call =  new CallI mpl();
  640                    }
  641                             
  642                    Long  callerId  = ParamUti l.getLong( request, " callerPers n_primaryK ey");
  643                    if (  callerId  > 0 ){
  644                             try {
  645                                      caller =  new Perso n( PersnLo calService Util.getPe rsn( calle rId ) );
  646                             } catc h (PortalE xception e ) {
  647                                      Applicat ionWorkFlo wException .handleExc eption(e);
  648                             } catc h (SystemE xception e ) {
  649                                      Applicat ionWorkFlo wException .handleExc eption(e);
  650                             }
  651                    }
  652                    if (  caller ==  null ){
  653                             caller  = new Per son ( new  PersnImpl( ) );
  654                    }
  655                    //TO DO: pass l ist of par ameter nam es 
  656                    Care tParam.loa dModel( re quest, cal l, call.ge tModelAttr ibutes().k eySet(), " call_");
  657  
  658                    //TO DO: pass l ist of par ameter nam es 
  659                    Care tParam.loa dModel(req uest, call er, caller .getModelA ttributes( ).keySet() , "callerP ersn_");
  660                    
  661                    bool ean unknow n = ParamU til.getBoo lean(reque st,  "call erPersn_st atusLabel" );
  662                    if (  unknown ) {
  663                             caller .setStatus (CaretStrP ool.UNKNOW N_IDENTITY );
  664                             caller .setFirstN ame(String Pool.BLANK );
  665                             caller .setLastNa me(StringP ool.BLANK) ;
  666                    } el se if ( !T oolbox.isE mpty( call er.getFirs tName() )  ){
  667                             caller .setStatus (StringPoo l.BLANK);
  668                    } 
  669                    
  670                    if (  veteranId  > 0 ){
  671                             try {
  672                                      veteran  = new Vete ran ( Pers nLocalServ iceUtil.ge tPersn( ve teranId )  );
  673                             } catc h (Excepti on e) {
  674                                      throw ne w Applicat ionWorkFlo wException (e);
  675                             }
  676                    }
  677                    if (  veteran = = null ){
  678                             vetera n = new Ve teran ( ne w PersnImp l() );
  679                    }
  680                    //TO DO: pass l ist of par ameter nam es 
  681                    
  682                    Care tParam.loa dModel(req uest, vete ran, veter an.getMode lAttribute s().keySet (), "veter anPersn_") ;
  683                    
  684                    if (  veteran.i sForeigner () ){
  685                             CaretP aram.loadM odel( requ est, veter an, Toolbo x.getAddre ssCollecti on(), Care tStrPool.V ETERAN_PER SN + Caret StrPool.G_ UNDERLINE  );
  686                    } el se {
  687                             CaretP aram.loadM odel( requ est, veter an, Toolbo x.getAddre ssCollecti on(), Care tStrPool.V ETERAN_PER SN + Caret StrPool.U_ UNDERLINE  );
  688                    }
  689                    
  690                    if (  call.isSa meAddress( ) ){
  691                             caller .setAddres s(veteran. getAddress ());
  692                             caller .setAddres s2(veteran .getAddres s2());
  693                             caller .setZip(ve teran.getZ ip());
  694                             caller .setState( veteran.ge tState());
  695                             caller .setCity(v eteran.get City());
  696                             caller .setValidA ddress(vet eran.getVa lidAddress ());
  697                    } el se {
  698                             if ( c aller.isFo reigner()  ){
  699                                      CaretPar am.loadMod el( reques t, caller,  Toolbox.g etAddressC ollection( ), CaretSt rPool.CALL ER_PERSN +  CaretStrP ool.G_UNDE RLINE );
  700                             } else  {
  701                                      CaretPar am.loadMod el( reques t, caller,  Toolbox.g etAddressC ollection( ), CaretSt rPool.CALL ER_PERSN +  CaretStrP ool.U_UNDE RLINE );
  702                             }
  703                    }
  704                    Care tLocalServ iceUtil.sa ve( caller  );
  705                    Care tLocalServ iceUtil.sa ve( vetera n );
  706                    _log .info("vet eran is "  + veteran) ;
  707                    
  708                    long  roleId =  (Long)sc.g etAttribut e( CaretSt rPool.ROLE _ID );
  709                    Them eDisplay t hemeDispla y = (Theme Display) r equest.get Attribute(  WebKeys.T HEME_DISPL AY );
  710  
  711                    Stri ng message  = null;
  712                    if (  call.getP rimaryKey( ) == 0 ){
  713                             call.s etCreateGr oupId( rol eId );
  714                             call.s etUserId(  (Long) sc. getAttribu te( CaretS trPool.USE R_ID ) );
  715                             try {
  716                                      message  = PortalUt il.getUser (request). getFullNam e() + " cr eated " +
  717                                                                Lang uageUtil.g et(themeDi splay.getL ocale(), c all.getCal lType()) +  " as " +
  718                                                                Lang uageUtil.g et(themeDi splay.getL ocale(), c all.getCal lState() )  ; 
  719                             } catc h (Excepti on e) {
  720                                      throw ne w Applicat ionWorkFlo wException (e);
  721                             }
  722                    }
  723                    call .setVetera nPersnId(  veteran.ge tPersnId()  );
  724                    call .setCaller PersnId( c aller.getP ersnId() ) ;
  725                    if (  call.getC allId() >  0 ){
  726                             call.s etModifica tionDate(  sc.getCrea teDate() ) ;
  727                    }
  728                    if (  call.getC allState()  != null & &
  729                                      call.get CallState( ).toLowerC ase().cont ains(Caret StrPool.CA LL_STATE_C OMPLETE)
  730                                      && call. getComplet ionDate()  == null ){
  731                             call.s etCompleti onDate(sc. getCreateD ate());
  732                    }
  733                    call  = (Call)C aretLocalS erviceUtil .save( cal l );
  734                    if (  CaretStrP ool.CALL_S TATE_REFER RAL.equals ( call.get CallState( ) ) ){
  735                             WorIm  workItem =  null;
  736                             
  737                             if ( v eteran.get GroupId()  > 0  ){//t ype, persn Id
  738                                      if ( cal l.getWorkP rimaryKey( ) > 0 ){
  739                                               try {
  740                                                       wo rkItem = W orImLocalS erviceUtil .getWorIm(  call.getW orkPrimary Key() );
  741                                                       if  ( workIte m != null  ){
  742                                                                work Item.setGr oupId( vet eran.getGr oupId() );
  743                                                                Care tLocalServ iceUtil.sa ve( workIt em );
  744                                                       }
  745                                               } catch (P ortalExcep tion e) {
  746                                                       Ap plicationW orkFlowExc eption.han dleExcepti on(e);
  747                                               } catch (S ystemExcep tion e) {
  748                                                       Ap plicationW orkFlowExc eption.han dleExcepti on(e);
  749                                               }
  750                                      }
  751                                      if ( wor kItem == n ull ){
  752                                               workItem =  Toolbox.c reateWorkI tem(sc, ve teran.getG roupId(),  call, Work Type.CALL_ REFERRAL,  veteran.ge tPersnId() , caller.g etPersnId( )  );
  753   //                                          workItem.s etQueId(Ca retStrPool .REFERRAL_ QUE);
  754                                               CaretLocal ServiceUti l.save( wo rkItem );
  755                                               call.setWo rkPrimaryK ey(workIte m.getPrima ryKey());
  756                                               CaretLocal ServiceUti l.save( ca ll );
  757                                      }
  758                             } else  {
  759                                      throw ne w Applicat ionWorkFlo wException ( "NEED GR OUP ID" );
  760                             }
  761                             
  762                    } el se if ( !C aretStrPoo l.CALL_STA TE_COMPLET E.equals(   call.getC allState()  ) ){
  763                             CalEt  callEvent  = new CalE tImpl();
  764                             callEv ent.setCal lId(call.g etCallId() );
  765                             String Builder sb  = new Str ingBuilder ( call.get CallType()  );
  766                             sb.app end(CaretS trPool.COL ON_SPACE);
  767                             if ( c all.isHang Up() ){
  768                                      sb.appen d("Hang-up , ");
  769                             }
  770                             if ( c all.isWith outContact () ){
  771                                      sb.appen d("Without -contact,  ");
  772                             }
  773                             if ( c all.isWron gNumber()  ){
  774                                      sb.appen d("Wrong-n umber, ");
  775                             }
  776                             callEv ent.setCom ment( sb.s ubstring(0 ,sb.length ()-1) );
  777                             callEv ent.setEve nt( call.g etCallStat e() );
  778                             callEv ent.setCre ationDate(  sc.getCre ateDate()  );
  779                             CaretL ocalServic eUtil.save (callEvent );
  780                    }
  781                    
  782                    
  783                    save BoxGroups( request, c all.getPri maryKey()) ;
  784                    _log .info("add ing note "  + Languag eUtil.get(  Locale.ge tDefault() , message         ) ) ;
  785                    Care tLocalServ iceUtil.ad dNote( Too lbox.creat eNote(sc.g etCreateDa te(), call .getCallId (), roleId , sc.getUs erId(), me ssage) );
  786                    _log .info("cal l is " + c all);
  787           }
  788                    
  789           pu blic void  saveSoc (  ActionRequ est reques t ){
  790                    _log .info("sav eSoc..." ) ;
  791  
  792                    try  {                    
  793                             getOut put(reques t);
  794                             Servic eContext s c = CaretP aram.setCa retService Context(re quest);
  795  
  796                             String  threshold Met = Para mUtil.get( request, " soc_tresho ldMet", St ringPool.B LANK);                                                   
  797  
  798                             long s ocId = Cou nterLocalS erviceUtil .increment ( ClSoc.cl ass.getNam e() );
  799                             ClSoc  soc = ClSo cLocalServ iceUtil.cr eateClSoc( socId);
  800                             CaretP aram.loadM odel(reque st, soc,       soc.ge tModelAttr ibutes().k eySet(), " soc_");
  801                             
  802                             soc.se tClSocId(s ocId);
  803                             soc.se tCreationD ate(new Da te());
  804  
  805                             if(thr esholdMet. equals("No ")){
  806                                      String f ollowupCal l = ParamU til.get(re quest, "so c_followup Call_q14",  StringPoo l.BLANK);
  807                                      String f ollowupCal lTime = Pa ramUtil.ge t(request,  "soc_foll owupCallTi me_q14", S tringPool. BLANK);
  808                                      soc.setF ollowupCal l(followup Call);
  809                                      soc.setF ollowupCal lTime(foll owupCallTi me);
  810                             }
  811  
  812                             ClSocL ocalServic eUtil.addC lSoc(soc);
  813                             
  814                             //NOTE : TODO use  save() to  save soc
  815                             //Care tLocalServ iceUtil.sa ve( soc );
  816                             
  817                             //crea te work it em for fol low up cal l                    
  818                             if(soc .getFollow upCall() ! = null &&  soc.getFol lowupCall( ).equals(" Yes")){
  819                                      Call cal l = CallLo calService Util.getCa ll( Long.p arseLong(P aramUtil.g et(request , "soc_cal lId", Stri ngPool.BLA NK)) );
  820                                      long vet eranId = c all.getVet eranPersnI d();
  821                                      Person v eteran = n ew Person  ( PersnLoc alServiceU til.getPer sn( vetera nId ) );
  822                                      CaretLoc alServiceU til.save(  Toolbox.cr eateWorkIt em( sc, ve teran.getG roupId(),  soc, WorkT ype.SOC_FO LLOWUP, ve teranId, c all.getCal lerPersnId () ));
  823                             }
  824                             
  825                             CaretL ocalServic eUtil.addN ote( Toolb ox.createN ote(sc.get CreateDate (), soc.ge tCallId(),  (Long)sc. getAttribu te( CaretS trPool.ROL E_ID ), sc .getUserId (), "Compl eted SOC C all Attemp t - "+soc. getAttempt Num()) );                     
  826                    } ca tch (Excep tion e) {
  827                             Applic ationWorkF lowExcepti on.handleE xception(e );
  828                    }
  829           }
  830           
  831  
  832           pu blic void  saveCesp (  ActionReq uest reque st ){
  833                    _log .info("sav eCesp..."  );
  834  
  835                    try  {
  836                             getOut put(reques t);
  837                             
  838                             Servic eContext s c = CaretP aram.setCa retService Context(re quest);
  839  
  840                             int nu mOfCesp =  ParamUtil. getInteger (request,  "cesp_numO fCesp");
  841                             String  cespClose d = ParamU til.get(re quest, "ce sp_cespClo sed", Stri ngPool.BLA NK);
  842  
  843                             long c espId = Co unterLocal ServiceUti l.incremen t( Cesp.cl ass.getNam e() );
  844                             Cesp c esp = Cesp LocalServi ceUtil.cre ateCesp(ce spId);
  845                             CaretP aram.loadM odel(reque st, cesp,  cesp.getMo delAttribu tes().keyS et(), "ces p_");
  846                             
  847                             cesp.s etCespId(c espId);
  848                             cesp.s etCreation Date(new D ate());
  849  
  850                             String  notificat ion = "";
  851                             if(num OfCesp ==  0){
  852                                      cesp.set Status(Car etStrPool. CESP_STATU S_INITIAL) ;//initial       
  853                                      notifica tion = "CE SP - Initi al - Compl eted";
  854                             }else  if(cespClo sed.equals ("No")){
  855                                      cesp.set Status(Car etStrPool. CESP_STATU S_COMPLETE );//comple te - in st ep 2                                                                      
  856                                      notifica tion = "CE SP - Compl eted";
  857                             }else  if(cespClo sed.equals ("Yes")){
  858                                      cesp.set Status(Car etStrPool. CESP_STATU S_CLOSED); //complete  - cesp cl osed                                                                                        
  859                                      notifica tion = "CE SP - Close d";
  860                             }
  861  
  862                             CespLo calService Util.addCe sp(cesp);
  863                             //NOTE : TODO use  save() to  save cesp
  864                             //Care tLocalServ iceUtil.sa ve( cesp ) ;
  865  
  866                             
  867                             //crea te work it em for CSC                         
  868                             if(nul l!=cesp.ge tCespClose dReason() 
  869                                      && (cesp .getCespCl osedReason ().equals( "Goals Rea ched") ||  cesp.getCe spClosedRe ason().equ als("Parti cipation D iscontinue d - refer  to CSC"))) {
  870                                      Call cal l = CallLo calService Util.getCa ll( Long.p arseLong(P aramUtil.g et(request , "cesp_ca llId", Str ingPool.BL ANK)) );
  871                                      long vet eranId = c all.getVet eranPersnI d();
  872                                      Person v eteran = n ew Person  ( PersnLoc alServiceU til.getPer sn( vetera nId ) );
  873                                      CaretLoc alServiceU til.save(  Toolbox.cr eateWorkIt em( sc, ve teran.getG roupId(),  cesp, Work Type.CESP_ CSC, veter anId, call .getCaller PersnId()  ));
  874                             }
  875  
  876                             CaretL ocalServic eUtil.addN ote( Toolb ox.createN ote(sc.get CreateDate (), cesp.g etCallId() , (Long)sc .getAttrib ute( Caret StrPool.RO LE_ID ), s c.getUserI d(), notif ication) ) ;                  
  877                    } ca tch (Excep tion e) {
  878                             Applic ationWorkF lowExcepti on.handleE xception(e );
  879                    }
  880           }
  881  
  882           pr ivate void  saveRefer ral ( Acti onRequest  request )  throws App licationWo rkFlowExce ption{
  883                    Call  call = nu ll;
  884                    Pers on caller  = null;
  885                    WorI m workItem  = null;
  886  
  887                    getO utput(requ est);
  888                    Long  callId =  ParamUtil. getLong(re quest, "ca ll_primary Key");
  889  
  890                    Pers on veteran  = null;
  891                    Long  veteranId  = ParamUt il.getLong (request,  "veteranPe rsn_primar yKey");
  892                    if (  veteranId  > 0 ){
  893                             try {
  894                                      veteran  = new Pers on ( Persn LocalServi ceUtil.get Persn( vet eranId ) ) ;
  895                             } catc h (PortalE xception e ) {
  896                                      Applicat ionWorkFlo wException .handleExc eption(e);
  897                             } catc h (SystemE xception e ) {
  898                                      Applicat ionWorkFlo wException .handleExc eption(e);
  899                             }
  900                    }
  901                    if (  veteran = = null ){
  902                             vetera n = new Pe rson ( new  PersnImpl () );
  903                    }
  904                    
  905                    Care tParam.set CaretServi ceContext( request);
  906                    bool ean create WorkItem =  false;
  907                    if (  callId >  0 ){
  908                             try {
  909                                      call = C allLocalSe rviceUtil. getCall(ca llId);
  910                                      if ( cal l.getWorkP rimaryKey( ) > 0 ){
  911                                               workItem =  WorImLoca lServiceUt il.getWorI m( call.ge tWorkPrima ryKey() );
  912                                      } else {
  913                                               createWork Item = tru e;
  914                                               workItem =  new WorIm Impl();
  915                                      }
  916                             } catc h (Excepti on e) {
  917                                      throw ne w Applicat ionWorkFlo wException (e);
  918                             }
  919                             if ( w orkItem.ge tStatus(). equals( St ringPool.B LANK ) ){
  920                                      workItem .setStatus ( WorkStat us.NEW.nam e() );
  921                             }
  922                             
  923                             if ( ! workItem.g etStatus() .equals( W orkStatus. NEW.name()  ) ){
  924                                      throw ne w Applicat ionWorkFlo wException ( "WORK IT EM ALREADY  STARTED"  );
  925                             }
  926                    }
  927                    
  928                    
  929                             
  930                    Long  callerId  = ParamUti l.getLong( request, " callerPers n_primaryK ey");
  931                    if (  callerId  > 0 ){
  932                             try {
  933                                      caller =  new Perso n ( PersnL ocalServic eUtil.getP ersn( call erId ) );
  934                             } catc h (Excepti on e) {
  935                                      throw ne w Applicat ionWorkFlo wException (e);
  936                             }
  937                    }
  938                    if (  caller ==  null ){
  939                             caller  = new Per son ( new  PersnImpl( ) );
  940                    }
  941                    
  942                    //TO DO: pass l ist of par ameter nam es
  943                    Care tParam.loa dModel(req uest, call er, caller .getModelA ttributes( ).keySet() , "callerP ersn_");
  944                    
  945                    bool ean unknow n = ParamU til.getBoo lean(reque st,  "call erPersn_st atusLabel" );
  946                    if (  unknown ) {
  947                             caller .setStatus (CaretStrP ool.UNKNOW N_IDENTITY );
  948                             caller .setFirstN ame(String Pool.BLANK );
  949                             caller .setLastNa me(StringP ool.BLANK) ;
  950                    } el se if ( !T oolbox.isE mpty( call er.getFirs tName() )  ){
  951                             caller .setStatus (StringPoo l.BLANK);
  952                    }
  953                    Care tLocalServ iceUtil.sa ve( caller  );
  954                    _log .info("cal ler is " +  caller);
  955                    
  956  
  957                    //TO DO: pass l ist of par ameter nam es 
  958                    Care tParam.loa dModel(req uest, vete ran, veter an.getMode lAttribute s().keySet (), "veter anPersn_") ;
  959                    _log .info("vet eran is "  + veteran) ;
  960                    if (  veteran.i sForeigner () ){
  961                             CaretP aram.loadM odel( requ est, veter an, Toolbo x.getAddre ssCollecti on(), Care tStrPool.V ETERAN_PER SN + Caret StrPool.G_ UNDERLINE  );
  962                    } el se {
  963                             CaretP aram.loadM odel( requ est, veter an, Toolbo x.getAddre ssCollecti on(), Care tStrPool.V ETERAN_PER SN + Caret StrPool.U_ UNDERLINE  );
  964                    }
  965                    
  966                    if (  call == n ull) {
  967                             call =  new CallI mpl();
  968                    }
  969                    Care tParam.loa dModel( re quest, cal l, call.ge tModelAttr ibutes().k eySet(), " call_");
  970  
  971                    if (  call.isSa meAddress( ) ){
  972                             caller .setAddres s( veteran .getAddres s() );
  973                             caller .setAddres s2( vetera n.getAddre ss2() );
  974                             caller .setZip( v eteran.get Zip() );
  975                             caller .setState(  veteran.g etState()  );
  976                             caller .setCity(  veteran.ge tCity() );
  977                             caller .setValidA ddress( ve teran.getV alidAddres s() );
  978                    }
  979                    Care tLocalServ iceUtil.sa ve( vetera n );
  980                    
  981                    if (  ! CaretVi ewControll er.getView Controller ().validat eRequired( CaretStrPo ol.CALL, r equest) ){
  982                             throw  new Applic ationWorkF lowExcepti on( "VALID ATION" );
  983                    }
  984                    
  985  
  986                    Serv iceContext  sc = Care tParam.set CaretServi ceContext(  request ) ;
  987                    
  988                    call .setVetera nPersnId(  veteran.ge tPersnId()  );
  989                    call .setCaller PersnId( c aller.getP ersnId() ) ;
  990  
  991                    if (  call.getC allId() ==  0 || crea teWorkItem  ){
  992   //                        call.s etCallStat e(CaretStr Pool.CALL_ STATE_COMP LETE);
  993                             call.s etCallStat e(CaretStr Pool.CREAT E_REFERRAL );
  994                             Dashbo ardConfig  dashConfig  = ( Dashb oardConfig  ) request .getPortle tSession() .getAttrib ute( Caret StrPool.DA SHBOARD_CO NFIG );
  995                             call.s etCreateGr oupId( das hConfig.ge tRoleId()  );
  996                             call.s etUserId(  (Long) sc. getAttribu te( CaretS trPool.USE R_ID ) );
  997                             CaretL ocalServic eUtil.save ( call );
  998                             
  999                             WorkTy pe workTyp e;
  1000                             if ( d ashConfig  instanceof  CslDashbo ardConfig  ){
  1001                                      workType  = WorkTyp e.CSL_REFE RRAL;
  1002                             } else  {
  1003                                      try{
  1004                                               workType =  WorkType. valueOf( d ashConfig. getRole()  + "_REFERR AL");
  1005                                      } catch( Exception  e){
  1006                                               workType =  WorkType. REFERRAL;
  1007                                      }
  1008                             }
  1009                             
  1010                             workIt em = Toolb ox.createW orkItem(sc , veteran. getGroupId (), call,  workType,  veteran.ge tPersnId() , call.get CallerPers nId() );
  1011                    } el se {
  1012                             workIt em.setGrou pId( veter an.getGrou pId() );
  1013                    }
  1014                    Care tLocalServ iceUtil.sa ve( workIt em );
  1015                    call .setWorkPr imaryKey(  workItem.g etPrimaryK ey() );
  1016                    if (  call.getC allState()  != null & &
  1017                                      call.get CallState( ).toLowerC ase().cont ains(Caret StrPool.CA LL_STATE_C OMPLETE)
  1018                                      && call. getComplet ionDate()  == null ){
  1019                             call.s etCompleti onDate(sc. getCreateD ate());
  1020                    }
  1021                    call  = (Call)C aretLocalS erviceUtil .save( cal l );
  1022                    _log .info("cal l is " + c all);
  1023                    
  1024                    save ReferralQu estionaire  ( veteran .getPersnI d(), reque st );
  1025                             
  1026                    
  1027                    //Su pporting D ocs attach ment code
  1028                    try  {            
  1029                             if ( r equest.get PortletSes sion().get Attribute( CaretStrPo ol.FILE_PA TH) != nul l ){
  1030                                      for ( Do cum docume nt : Docum LocalServi ceUtil.get ByPrimaryK ey( call.g etCallId()  ) ){
  1031                                               DocumLocal ServiceUti l.deleteDo cument( do cument );
  1032                                      }
  1033                                      String p ath = (Str ing) reque st.getPort letSession ().getAttr ibute(Care tStrPool.F ILE_PATH);
  1034                                      String n ame = (Str ing) reque st.getPort letSession ().getAttr ibute(Care tStrPool.F ILE_NAME);
  1035                                      Attachme ntBean att achment =  new Attach mentBean() ;
  1036                                      attachme nt.setClas sId(Portal Util.getCl assNameId( Call.class ));
  1037                                      attachme nt.setClas sPk(call.g etCallId() );
  1038                                      attachme nt.setPath (path);
  1039                                      attachme nt.setName (name);
  1040                                      attachme nt.setType (FileType. REFERRAL_1 010.name() );
  1041                                      handleAp plicationD ocument( r equest, at tachment);
  1042                                      request. getPortlet Session(). removeAttr ibute(Care tStrPool.F ILE_PATH);
  1043                                      request. getPortlet Session(). removeAttr ibute(Care tStrPool.F ILE_NAME);
  1044                             }
  1045   //                        if ( r equest.get PortletSes sion().get Attribute( CaretStrPo ol.POA_FIL E_PATH) !=  null ){
  1046   //                                 String p ath = (Str ing) reque st.getPort letSession ().getAttr ibute(Care tStrPool.P OA_FILE_PA TH);
  1047   //                                 String n ame = (Str ing) reque st.getPort letSession ().getAttr ibute(Care tStrPool.P OA_FILE_NA ME);
  1048   //                                 Attachme ntBean att achment =  new Attach mentBean() ;
  1049   //                                 attachme nt.setClas sId(Portal Util.getCl assNameId( Call.class ));
  1050   //                                 attachme nt.setClas sPk(call.g etCallId() );
  1051   //                                 attachme nt.setPath (path);
  1052   //                                 attachme nt.setName (name);
  1053   //                                 attachme nt.setType (FileType. REFERRAL_P OA.name()) ;
  1054   //                                 handleAp plicationD ocument( r equest, at tachment);
  1055   //                                 request. getPortlet Session(). removeAttr ibute(Care tStrPool.P OA_FILE_PA TH);
  1056   //                                 request. getPortlet Session(). removeAttr ibute(Care tStrPool.P OA_FILE_NA ME);
  1057   //                        }
  1058                    } ca tch (FileN otFoundExc eption e)  {
  1059                             Applic ationWorkF lowExcepti on.handleE xception(e );
  1060                    } ca tch (Syste mException  e) {
  1061                             Applic ationWorkF lowExcepti on.handleE xception(e );
  1062                    }
  1063                    
  1064                    
  1065                    _log .info("sav eReferral. .." );
  1066           }
  1067           
  1068           pr ivate void  saveRefer ralQuestio naire(long  persnId,  PortletReq uest reque st) throws  Applicati onWorkFlow Exception  {
  1069                    
  1070                    List <Long> fmC hecks = Ca retParam.l oadSelecte dBoxModel( request, C aretStrPoo l.BOX_GROU P);
  1071  
  1072                    Stri ng[] radio Names = ne w String[] {
  1073                                      "boxRadi oGrp_enrol ledVaHealt h", "boxRa dioGrp_dis chargedAft er911", 
  1074                                      "boxRadi oGrp_veter anScCondit ion", "box RadioGrp_p rescreenPc afc"
  1075                    };
  1076                    for  ( String r adio: radi oNames ){
  1077                             Long r adioId = P aramUtil.g etLong(req uest, radi o, 0);
  1078                             if ( r adioId > 0  ){
  1079                                      fmChecks .add(radio Id);
  1080                             }
  1081                    }
  1082                    
  1083                    List <Long> upd ated = new  ArrayList <Long>();
  1084  
  1085                    Set< Long> priv ateSet = n ew HashSet <Long>();
  1086                    for  ( BoxGp it em: BoxGpL ocalServic eUtil.getB oxGroups(C aretStrPoo l.REFERRAL _QUESTIONA IRE_YN) ){
  1087                             privat eSet.add(  item.getBo xGpId() );
  1088                    }
  1089                    bool ean lodQa  = CAction. canDoCaret (request,  CaretCan.L OD_QA.name () );
  1090                    
  1091                    List <BgAsn> bg AsnList =  BoxGpLocal ServiceUti l.getBoxGr oupAssocia tions( per snId );
  1092                    
  1093                    for  ( BgAsn bg Asn: bgAsn List ){
  1094                             if ( ! lodQa && p rivateSet. contains(  bgAsn.getB oxGpId() )  ){
  1095                                      fmChecks .remove( b gAsn.getBo xGpId() );
  1096                                      continue ;
  1097                             }
  1098                             if ( f mChecks.co ntains( bg Asn.getBox GpId() ) ) {
  1099                                      if ( !bg Asn.isSele cted() ){
  1100                                               bgAsn.setS elected( t rue );
  1101                                               CaretLocal ServiceUti l.save( ne w BoxedGro upAssociat ion(bgAsn)  );
  1102                                               updated.ad d( bgAsn.g etBoxGpId( ) );
  1103                                      }
  1104                                      fmChecks .remove( b gAsn.getBo xGpId() );
  1105                             } else  {
  1106                                      if ( bgA sn.isSelec ted() ){
  1107                                               bgAsn.setS elected( f alse );
  1108                                               CaretLocal ServiceUti l.save( ne w BoxedGro upAssociat ion(bgAsn)  );
  1109                                      }
  1110                             }
  1111                    }
  1112                    for  ( Long box GpId: fmCh ecks){
  1113                             if ( !  updated.c ontains( b oxGpId ) ) {
  1114                                      BgAsn bg Asn = new  BgAsnImpl( );
  1115                                      bgAsn.se tBoxGpId(  boxGpId );
  1116                                      bgAsn.se tOwnerId(  persnId );
  1117                                      bgAsn.se tSelected(  true );
  1118                                      CaretLoc alServiceU til.save(  new BoxedG roupAssoci ation(bgAs n) );
  1119                             }
  1120                    }
  1121           }
  1122  
  1123           
  1124           pu blic void  getOutput(  PortletRe quest requ est ){
  1125                    Care tViewContr oller.getV iewControl ler().getO utput(requ est);
  1126           }
  1127           
  1128           pu blic void  writeTiuNo te ( Actio nRequest r equest, St ring noteB ody, Strin g noteTitl e, VcgSupp ort vcg, P erson.Role  caregiver Role ) thr ows Applic ationWorkF lowExcepti on{
  1129                    _log .info("wri te TIU Not e..." );
  1130                    
  1131                    try{
  1132                             Servic eFacade.Wr iteTIUNote (PersnLoca lServiceUt il.getPers n( CaretPa ram.getPer snId(reque st) ),
  1133                                               noteTitle,
  1134                                               noteBody,
  1135                                               vcg.getVet eran().get Icn());
  1136                    } ca tch ( Exce ption e ){
  1137                             Applic ationWorkF lowExcepti on.handleE xception(" Could not  not save T IU Note");
  1138                             e.prin tStackTrac e();
  1139                             Servic eContext s c = CaretP aram.setCa retService Context(re quest);
  1140                             CaretL ocalServic eUtil.save ( Toolbox. createWork Item( sc,  vcg.getGro upId(), vc g, WorkTyp e.TIU, vcg .getVetera nId(), vcg .getPerson Id(caregiv erRole) )  );
  1141                    }
  1142           }
  1143           
  1144           pu blic void  saveVcgTie r ( Action Request re quest, Act ionRespons e response  ) throws  Applicatio nWorkFlowE xception{
  1145                    // s ee saveVcg Entry
  1146                    _log .info("sav eVcgTier") ;
  1147           }
  1148           
  1149           pu blic void  createVcg(  ActionReq uest reque st, Action Response r esponse )  throws App licationWo rkFlowExce ption {
  1150                    Stri ng tracker  = ParamUt il.getStri ng(request , CaretStr Pool.TRACK ER, String Pool.BLANK  );
  1151                    if (  ! CaretPa ram.isTrac ked( reque st, tracke r, true )  ){
  1152                             _log.w arn("TRACK ER BLOCKIN G action.. . ");
  1153                             reques t.setAttri bute(Caret StrPool.IN VALID_REQU EST, true) ;
  1154                             return ;
  1155                    }
  1156                    if ( CAction.ca nDoCaret(r equest, CA ction.Care tCan.DISPO SITION_VCG .name()))  {
  1157                             _log.i nfo("creat eVcg... ") ;
  1158                             getOut put(reques t);
  1159                             long v eteranId =  ParamUtil .getLong(r equest, "v cg_veteran Id", 0);
  1160                             long v cgAnId = P aramUtil.g etLong(req uest, Care tStrPool.V CGANID);
  1161                             long w orImId = P aramUtil.g etLong(req uest, Care tStrPool.W ORK_ID);
  1162  
  1163                             Servic eContext s c = CaretP aram.setCa retService Context(re quest);
  1164                             String  applicati onStatus =  request.g etParamete r("applica tionStatus ");
  1165  
  1166                             VcgApp lication v cgAn = nul l;
  1167                             WorIm  worIm = nu ll;
  1168                             VcgSup port vcgSu pport = nu ll;
  1169                             Vetera n vcgVeter an = null;
  1170                             try {
  1171                                      worIm =  WorImLocal ServiceUti l.getWorIm (worImId);
  1172                                      vcgAn =  new VcgApp lication(V cgAnLocalS erviceUtil .getVcgAn( vcgAnId));
  1173                                      vcgAn.se tStatus(ap plicationS tatus);
  1174  
  1175                                      if (Care tStrPool.I NVALID.equ als(applic ationStatu s)) {
  1176                                               String com ment = "";
  1177                                               if (vetera nId > 0) {
  1178                                                       vc gVeteran =  new Veter an(PersnLo calService Util.getPe rsn(vetera nId));
  1179                                                       vc gVeteran.s etStatus(C aretStrPoo l.ACTIVE_V CG);
  1180                                                       
  1181                                                       vc gSupport =  VcgSuppor t.getVeter anVcg(vete ranId);
  1182                                                       vc gSupport.s etGroupId( vcgVeteran .getGroupI d());
  1183                                                       St ring noteS tr = reque st.getPara meter(Care tStrPool.D ISPOSITION _NOTE);
  1184                                                       vc gSupport.s etInvalidA pplication (vcgAnId,  noteStr);
  1185  
  1186                                                       Ca retLocalSe rviceUtil. save(vcgVe teran);
  1187                                                       No te note =  CaretLocal ServiceUti l.addNote( Toolbox.cr eateNote(s c.getCreat eDate(), v cgSupport. getVcgId() ,
  1188                                                                         0l, sc .getUserId (), noteSt r));
  1189                                                       vc gSupport.u seNote("In valid", no te);
  1190                                                       Ca retLocalSe rviceUtil. save(vcgSu pport);
  1191                                                       vc gAn.setVcg Id(vcgSupp ort.getVcg Id());
  1192                                                       
  1193                                                       wo rIm.setVcg Id(vcgSupp ort.getVcg Id());
  1194                                               }
  1195                                               vcgAn.setI nvalidPers on(1, requ est.getPar ameter(Car etStrPool. DISPOSITIO N_NOTE) );
  1196                                               vcgAn.setS tatus(appl icationSta tus);
  1197                                               CaretLocal ServiceUti l.save(vcg An);
  1198  
  1199                                               worIm.setS tatus(Work Status.COM PLETE.name ());
  1200                                               worIm.setC ompletionD ate( sc.ge tCreateDat e() );
  1201                                               worIm.setC ompletionB y( sc.getU serId() );
  1202                                               CaretLocal ServiceUti l.save(wor Im);
  1203                                              
  1204                                               //Note for  Online us ers
  1205   //                                          _log.info( "adding no te " + Lan guageUtil. get( Local e.getDefau lt(), Care tStrPool.D ISPOSITION ED_ONLINE_ MESSAGE) ) ;
  1206                                               if ( worIm .getType() .equals( W orkType.ON LINE_APP.n ame() ) ){
  1207                                                       Ca retLocalSe rviceUtil. addNote(To olbox.crea teNote(sc. getCreateD ate(), vcg An.getVcgA nId(),
  1208                                                                0, v cgAn.getVe teranId(),  LanguageU til.get( L ocale.getD efault(),  CaretStrPo ol.DISPOSI TIONED_ONL INE_MESSAG E) ) );
  1209                                               }
  1210                                               return;
  1211                                      } else i f (veteran Id == 0) {
  1212                                               Applicatio nWorkFlowE xception.h andleExcep tion("VCG  requires V eteranId") ;
  1213                                               return;
  1214                                      } 
  1215  
  1216                                      vcgVeter an = new V eteran(Per snLocalSer viceUtil.g etPersn(ve teranId));
  1217                                      vcgVeter an.setStat us(CaretSt rPool.ACTI VE_VCG);
  1218                                      vcgSuppo rt = VcgSu pport.getV eteranVcg( veteranId) ;
  1219                                      boolean  isNewVcg =  vcgSuppor t.getVcgId () > 0;
  1220                                      // group Id defect. ..
  1221                                      _log.inf o( "****** ********** ********** ********** ");
  1222                                      _log.inf o( "****** ********** ********** ********** ");
  1223                                      _log.inf o( "VCG=Ve teran=Appl ication...  groupId="  + vcgAn.g etGroupId( ) );
  1224                                      _log.inf o( "****** ********** ********** ********** ");
  1225                                      _log.inf o( "****** ********** ********** ********** ");
  1226                                      vcgSuppo rt.setGrou pId(vcgAn. getGroupId ());
  1227                                      vcgVeter an.setGrou pId(vcgAn. getGroupId ());
  1228  
  1229   //                                 String c omment = S tringPool. BLANK;
  1230  
  1231                                      Map<Pers on,boolean []> change Map = new  HashMap<Pe rson,boole an[]>();
  1232                                      List<Str ing> error s = new Ar rayList<St ring>();
  1233                                      
  1234                                      int inva lids = 0;
  1235                                      int care givers = 0 ;
  1236                                      int coun t = 0;
  1237                                      Set<Long > userSet  = new Hash Set<Long>( );
  1238                                      
  1239                                      if (Care tStrPool.D UPLICATE.e quals(appl icationSta tus)) {
  1240                                               worIm.setS tatus( Wor kStatus.CO MPLETE.nam e() );
  1241                                               worIm.setC ompletionD ate( sc.ge tCreateDat e() );
  1242                                               worIm.setC ompletionB y( sc.getU serId() );
  1243                                               vcgAn.setS tatus( Car etStrPool. DUPLICATE  );
  1244                                               vcgSupport .setDuplic ateApplica tion(vcgAn .getVcgAnI d(), reque st.getPara meter(Care tStrPool.D ISPOSITION _NOTE) );
  1245                                              
  1246                                               userSet.ad d(CaretStr Pool.ALL_P OS);
  1247                                      } else {
  1248                                               worIm.setS tatus(Work Status.IN_ PROCESS.na me());
  1249  
  1250                                               long prima ryId = Par amUtil.get Long(reque st, "vcg_p rimaryId",  0);
  1251                                               long secon daryId = P aramUtil.g etLong(req uest, "vcg _secondary Id", 0);
  1252                                               long secon daryTwoId  = ParamUti l.getLong( request, " vcg_second aryTwoId",  0);
  1253  
  1254                                               Person vcg Primary =  null, vcgS econdary =  null, vcg SecondaryT wo = null;
  1255  
  1256                                               if (vcgAn. getVeteran Id() != ve teranId) {
  1257                                                       bo olean[] ch anges = ne w boolean[ Person.Cha nges.value s().length ];
  1258                                                       Pe rsn merged  = PersnLo calService Util.getPe rsn(vcgAn. getVeteran Id());
  1259                                                       er rors.addAl l( CaretVi ewControll er.getView Controller ().setVcgP erson(requ est,
  1260                                                                         new Ve teran(merg ed), vcgVe teran, cha nges) );
  1261                                                       if  ( errors. isEmpty()  ){
  1262                                                                merg ed.setStat us(CaretSt rPool.REVI SION_MERGE D);
  1263                                                                Care tLocalServ iceUtil.sa ve(merged) ;
  1264                                                       }
  1265                                                       if  ( vcgSupp ort != nul l && ( vcg Support.is PrimaryApp roved() ||  vcgSuppor t.isSecond aryApprove d() || vcg Support.is SecondaryT woApproved () ) ){
  1266                                                                chan geMap.put( vcgVeteran , changes) ;
  1267                                                       }
  1268                                               }
  1269                                               vcgAn.setV eteranId(  veteranId  );
  1270                                               //init VCG  
  1271                                               CaretLocal ServiceUti l.save(vcg Support);
  1272                                              
  1273                                               if (vcgAn. getPrimary Id() > 0)  {
  1274                                                       Pr imary appP rimary = n ew Primary (PersnLoca lServiceUt il.getPers n(vcgAn.ge tPrimaryId ()));
  1275                                                       St ring prima ryStatus =  ParamUtil .get(reque st, "prima ryStatus",  StringPoo l.BLANK);
  1276                                                       ca regivers++ ;
  1277                                                       if  (CaretStr Pool.INVAL ID.equals( primarySta tus)) { // Decision M ade
  1278                                                                vcgA n.setInval idPerson(v cgAn.getPr imaryId(),  ParamUtil .get(reque st, "prima ryNote", " Missing IN VALID-App  reason"));
  1279                                                                
  1280                                                                inva lids++;
  1281                                                                user Set.add( a ppPrimary. getRootUse rId() ); / /Decision  Made
  1282                                                       }  else if (p rimaryId >  0) {
  1283                                                                vcgP rimary = n ew Primary (PersnLoca lServiceUt il.getPers n(primaryI d));
  1284                                                                if ( CaretStrPo ol.IN_PROC ESS.equals (primarySt atus)) {
  1285                                                                         if ( v cgSupport. getPrimary DispReason () != null  && VcgSup port.isAct ive( vcgSu pport.getP rimaryDisp Reason() )  ) {
  1286                                                                                  throw ne w Applicat ionWorkFlo wException ("VCG - Pr imary Slot  already r eserved!") ;
  1287                                                                         } else  if (vcgAn .getPrimar yId() != p rimaryId)  {
  1288                                                                                  boolean[ ] changes  = new bool ean[Person .Changes.v alues().le ngth];
  1289                                                                                  CaretVie wControlle r.getViewC ontroller( ).setVcgPe rson(reque st, appPri mary, vcgP rimary, ch anges);
  1290                                                                                  
  1291                                                                                  if ( vcg Support !=  null && v cgSupport. isPrimaryA pproved()  ){
  1292                                                                                           changeMap. put(vcgPri mary, chan ges);
  1293                                                                                  }
  1294                                                                                  
  1295                                                                         }
  1296                                                                         vcgPri mary.setSt atus(Caret StrPool.AC TIVE_VCG);
  1297                                                                         vcgSup port.setNe wPrimary(  primaryId,  vcgAn.get PrimaryRel ationship( ), vcgAnId  );
  1298                                                                         count+ +;
  1299                                                                }
  1300                                                       }
  1301                                               }
  1302                                               if (vcgAn. getSeconda ryId() > 0 ) {
  1303                                                       Se condary ap pSecondary  = new Sec ondary(Per snLocalSer viceUtil.g etPersn(vc gAn.getSec ondaryId() ));
  1304                                                       St ring secon daryStatus  = ParamUt il.get(req uest, "sec ondaryStat us", Strin gPool.BLAN K);
  1305                                                       ca regivers++ ;
  1306                                                       if  (CaretStr Pool.INVAL ID.equals( secondaryS tatus)) {
  1307                                                                vcgA n.setInval idPerson(v cgAn.getSe condaryId( ),
  1308                                                                                  ParamUti l.get(requ est, "seco ndaryNote" , "Missing  INVALID-A pp reason" ));
  1309                                                                inva lids++;
  1310                                                                user Set.add( a ppSecondar y.getRootU serId() );
  1311                                                       }  else if (s econdaryId  > 0) {
  1312                                                                vcgS econdary =  new Secon dary(Persn LocalServi ceUtil.get Persn(seco ndaryId));
  1313                                                                if ( CaretStrPo ol.IN_PROC ESS.equals (secondary Status)) {
  1314                                                                         if ( v cgSupport. getSeconda ryDispReas on() != nu ll && VcgS upport.isA ctive( vcg Support.ge tSecondary DispReason () ) ) {
  1315                                                                                  throw ne w Applicat ionWorkFlo wException ("VCG - Se condary Sl ot already  reserved! ");
  1316                                                                         } else  if (vcgAn .getSecond aryId() !=  secondary Id) {
  1317                                                                                  boolean[ ] changes  = new bool ean[Person .Changes.v alues().le ngth];
  1318                                                                                  CaretVie wControlle r.getViewC ontroller( ).setVcgPe rson(reque st, appSec ondary,
  1319                                                                                                   vc gSecondary , changes) ;
  1320                                                                                  if ( vcg Support !=  null && v cgSupport. isSecondar yApproved( ) ){
  1321                                                                                           changeMap. put(vcgSec ondary, ch anges);
  1322                                                                                  }
  1323                                                                         }
  1324                                                                         vcgSec ondary.set Status(Car etStrPool. ACTIVE_VCG );
  1325                                                                         vcgSup port.setNe wSecondary ( secondar yId, vcgAn .getSecond aryRelatio nship(), v cgAnId );
  1326                                                                         count+ +;
  1327                                                                }
  1328                                                       }
  1329                                               }
  1330                                               if (vcgAn. getSeconda ryTwoId()  > 0) {
  1331                                                       Se condaryTwo  appSecond aryTwo = n ew Seconda ryTwo(Pers nLocalServ iceUtil.ge tPersn(vcg An.getSeco ndaryTwoId ()));
  1332                                                       St ring secon daryTwoSta tus = Para mUtil.get( request, " secondaryT woStatus",  StringPoo l.BLANK);
  1333                                                       ca regivers++ ;
  1334                                                       
  1335                                                       if  (CaretStr Pool.INVAL ID.equals( secondaryT woStatus))  {
  1336                                                                vcgA n.setInval idPerson(v cgAn.getSe condaryTwo Id(),
  1337                                                                                  ParamUti l.get(requ est, "seco ndaryTwoNo te", "Miss ing INVALI D-App reas on"));
  1338                                                                inva lids++;
  1339                                                                user Set.add( a ppSecondar yTwo.getRo otUserId()  );
  1340                                                       }  else if (s econdaryTw oId > 0) {
  1341                                                                vcgS econdaryTw o = new Se condaryTwo (PersnLoca lServiceUt il.getPers n(secondar yTwoId));
  1342                                                                if ( CaretStrPo ol.IN_PROC ESS.equals (secondary TwoStatus) ) {
  1343                                                                         if ( v cgSupport. getSeconda ryTwoDispR eason() !=  null && V cgSupport. isActive(  vcgSupport .getSecond aryTwoDisp Reason() )  ) {
  1344                                                                                  throw ne w Applicat ionWorkFlo wException ("VCG - Se condary II  Slot alre ady reserv ed!");
  1345                                                                         } else  if (vcgAn .getSecond aryTwoId()  != second aryTwoId)  {
  1346                                                                                  boolean[ ] changes  = new bool ean[Person .Changes.v alues().le ngth];
  1347                                                                                  CaretVie wControlle r.getViewC ontroller( ).setVcgPe rson(reque st, appSec ondaryTwo,
  1348                                                                                                   vc gSecondary Two, chang es);
  1349                                                                                  if ( vcg Support !=  null && v cgSupport. isSecondar yTwoApprov ed() ){
  1350                                                                                           changeMap. put(vcgSec ondaryTwo,  changes);
  1351                                                                                  }
  1352                                                                         }
  1353                                                                         vcgSec ondaryTwo. setStatus( CaretStrPo ol.ACTIVE_ VCG);
  1354                                                                         vcgSup port.setNe wSecondary Two( secon daryTwoId,  vcgAn.get SecondaryT woRelation ship(), vc gAnId );
  1355                                                                         count+ +;
  1356                                                                }
  1357                                                       }
  1358                                               }
  1359                                      }
  1360                                      setOnlin eNotes(use rSet, vcgA n, vcgVete ran, sc);
  1361                                      
  1362                                      CaretLoc alServiceU til.save(v cgSupport) ;
  1363                                      CaretLoc alServiceU til.save(v cgVeteran) ;
  1364                                      
  1365                                      if ( inv alids == c aregivers  || count = = 0 ){
  1366                                               worIm.setS tatus(Work Status.COM PLETE.name ());
  1367                                               vcgAn.setS tatus( App licationSt atus.DECIS ION_MADE.n ame() );
  1368                                      } else {
  1369                                               vcgAn.setS tatus( App licationSt atus.IN_RE VIEW.name( ) );
  1370                                      }
  1371                                      vcgAn.se tVcgId( vc gSupport.g etVcgId()  );
  1372                                      CaretLoc alServiceU til.save(v cgAn);
  1373  
  1374                                      worIm.se tVcgId( vc gSupport.g etVcgId()  );
  1375                                      CaretLoc alServiceU til.save(w orIm);
  1376                                      
  1377                                      String c omment = i sNewVcg?
  1378                                                       "U pdated VCG  record wi th " + cou nt + " new  Caregiver  selection (s)"
  1379                                                       :  "Created n ew VCG rec ord with "  + count +  " Caregiv er selecti on(s)";
  1380                                      CaretLoc alServiceU til.addNot e(Toolbox. createNote (sc.getCre ateDate(),  vcgSuppor t.getVcgId (),
  1381                                                       No teSupport. NoteGroup. CREATE_VCG .groupId() , sc.getUs erId(), co mment));
  1382                                      
  1383                                      for ( Pe rson perso n: changeM ap.keySet( ) ){
  1384                                               CaretViewC ontroller. getViewCon troller(). applyWorkI tem( reque st, change Map.get(pe rson), per son, vcgSu pport, per son.getRol e() );
  1385                                               CaretLocal ServiceUti l.save(per son);
  1386                                      }
  1387                                      
  1388                                      if ( CAc tion.canDo Caret(requ est, CActi on.CaretCa n.MANAGE_V CG.name())  ) {
  1389                                               request.se tAttribute ( CaretStr Pool.VCGID , vcgSuppo rt.getVcgI d() );
  1390                                               loadVcgMan agement(re quest, res ponse);
  1391                                               response.s etRenderPa rameter(Ca retStrPool .MVC_PATH,  CaretStrP ool.VCG_MA NAGEMENT_P AGE);
  1392                                      }
  1393                             } catc h (PortalE xception e ) {
  1394                                      Applicat ionWorkFlo wException .handleExc eption(e);
  1395                             } catc h (SystemE xception e ) {
  1396                                      Applicat ionWorkFlo wException .handleExc eption(e);
  1397                             }
  1398                    }
  1399           }
  1400  
  1401           pr ivate void  setOnline Notes( Set <Long> use rSet, VcgA pplication  vcgAn, Ve teran vcgV eteran, Se rviceConte xt sc ) th rows Appli cationWork FlowExcept ion, Porta lException , SystemEx ception {
  1402                    if (  userSet.c ontains( C aretStrPoo l.ALL_POS  ) ){
  1403                             userSe t.remove(  CaretStrPo ol.ALL_POS  );
  1404                             if ( v cgAn.getPr imaryId()  > 0 ){
  1405                                      userSet. add(new Pr imary(Pers nLocalServ iceUtil.ge tPersn(vcg An.getPrim aryId())). getRootUse rId());
  1406                             }
  1407                             if ( v cgAn.getSe condaryId( ) > 0 ){
  1408                                      userSet. add(new Se condary(Pe rsnLocalSe rviceUtil. getPersn(v cgAn.getSe condaryId( ))).getRoo tUserId()) ;
  1409                             }
  1410                             if ( v cgAn.getSe condaryTwo Id() > 0 ) {
  1411                                      userSet. add(new Se condaryTwo (PersnLoca lServiceUt il.getPers n(vcgAn.ge tSecondary TwoId())). getRootUse rId());
  1412                             }
  1413                    }
  1414                    Stri ng onlineM essage = L anguageUti l.get( Loc ale.getDef ault(), Ca retStrPool .DISPOSITI ONED_ONLIN E_MESSAGE)  ;
  1415                    if (  !userSet. isEmpty()  ){
  1416                             userSe t.add(vcgV eteran.get RootUserId ());
  1417                    }
  1418                    for  ( Long id  : userSet  ){
  1419                             CaretL ocalServic eUtil.addN ote(Toolbo x.createNo te(sc.getC reateDate( ), vcgAn.g etVcgAnId( ), 0, id,  onlineMess age ) );
  1420                    }
  1421           }
  1422  
  1423  
  1424           pu blic void  saveVcgDis position (  ActionReq uest reque st, VcgSup port vcg,  Person per son ) thro ws Applica tionWorkFl owExceptio n{
  1425                             String  ndx = req uest.getPa rameter("v cg_ndx") +  StringPoo l.UNDERLIN E;
  1426                             Date d isposition Date = Too lbox.parse Date(reque st.getPara meter(ndx  + "disposi tionDate") );
  1427                             String  dispositi onChoice =  request.g etParamete r(ndx + "d isposition Choice");
  1428                             String  dispositi onReason =  Toolbox.n ullSafe( r equest.get Parameter( ndx + "dis positionRe ason") );
  1429                             String  oldDispos itionState  = null;
  1430                             long v cgAnId = 0 ;
  1431                             int[]  extensionD ays = new  int[1];
  1432                             Servic eContext s c = CaretP aram.setCa retService Context( r equest );
  1433                             boolea n generalU pdate = fa lse;
  1434                             Set<Lo ng> userId s = new Ha shSet<Long >();
  1435                             
  1436                             if ( p erson.getR ole() == P erson.Role .PRIMARY & & !vcg.get PrimaryDis pReason(). equals( di spositionC hoice )){
  1437                                      oldDispo sitionStat e = vcg.ge tPrimaryDi spReason() ;
  1438                                      vcg.setP rimaryDisp Reason( ex tDays(disp ositionCho ice, exten sionDays)  + disposit ionReason   );
  1439                                      userIds. add( vcg.g etPrimary( ).getRootU serId() );
  1440                                      vcgAnId  = vcg.getP rimaryVcgA nId();
  1441                                      if ( vcg .isRevoked ( vcg.getP rimaryDisp Reason() )  ){
  1442                                               vcg.setPri maryRevoca tionDate(d isposition Date);
  1443                                      } else {
  1444                                               if ( vcg.i sApproved( dispositio nChoice) | | vcg.isRe instated(d isposition Choice) ){
  1445                                                       Da te tierEff ectiveDate  = Toolbox .parseDate (request.g etParamete r(ndx + "t ierEffecti veDate"));
  1446                                                       vc g.setTierE ffectiveDa te(tierEff ectiveDate  );
  1447                                                       vc g.setTierL evel( Para mUtil.getI nteger(req uest, ndx  + "tier")  );
  1448  
  1449                                                       if  ( vcg.get PrimaryIni tDispDate( ) == null  ){
  1450                                                                if (  vcg.isVac oWaiverPri mary() ){
  1451                                                                         closeD elayWork (  request,  person, sc , vcg );
  1452                                                                } el se if ( vc g.isWaiver Primary()  ) {
  1453                                                                         saveCs cWaiver( r equest, pe rson, sc,  ndx, vcg,  CaretStrPo ol.ACCEPTE D );
  1454                                                                } 
  1455                                                       }
  1456                                                       
  1457                                                       wr iteTiuNote (request,  getNoteBod y(vcg, dis positionCh oice, pers on.getRole (), sc), g etNoteTitl e(vcg, dis positionCh oice, pers on.getRole ()), vcg,  person.get Role());
  1458                                               }
  1459                                               vcg.setPri maryDispos itionDate( dispositio nDate);
  1460                                      }
  1461                                      
  1462                                      //**** P eriodic As sessments
  1463                                      //if dis p == appro ved -> cre ate 4 peri odic asses sments sch eduled 90  days apart
  1464                                      if(vcg.i sApproved( dispositio nChoice)){
  1465                                               saveFirstP eriodicAss essments(r equest, vc g, person,  dispositi onDate);                               
  1466                                      }
  1467                                      //if pri mary was r evoked; in activate a ll periodi c assessme nts
  1468                                      if(vcg.i sRevoked(d isposition Choice)){
  1469                                               _log.info( "primary s tatus chan ged from a pproved... inactivati ng periodi c assmts.. .");
  1470                                               inactivate Assessment s(vcg.getV cgId(), vc g.getPrima ryId(), Ca retStrPool .ASSMT_PER IODIC);
  1471                                      }
  1472                                      
  1473                                      //if pri mary was r einstated;  activate  all period ic assessm ents
  1474                                      if(vcg.i sReinstate d(disposit ionChoice) ){
  1475                                               _log.info( "primary s tatus chan ged to rei nstated... activating  periodic  assmts..." );
  1476                                               activateAs sessments( vcg.getVcg Id(), vcg. getPrimary Id(), Care tStrPool.A SSMT_PERIO DIC);
  1477                                      }
  1478                                      
  1479                             } else  if ( pers on.getRole () == Pers on.Role.SE CONDARY &&  !vcg.getS econdaryDi spReason() .equals( d isposition Choice ) ) {
  1480                                      oldDispo sitionStat e = vcg.ge tSecondary DispReason ();
  1481                                      vcg.setS econdaryDi spReason(  extDays(di spositionC hoice, ext ensionDays ) + dispos itionReaso n  );
  1482                                      vcgAnId  = vcg.getS econdaryVc gAnId();
  1483                                      userIds. add( vcg.g etSecondar y().getRoo tUserId()  );
  1484                                      if ( vcg .isRevoked ( vcg.getS econdaryDi spReason()  ) ){
  1485                                               vcg.setSec ondaryRevo cationDate (dispositi onDate);
  1486                                      } else {
  1487                                               if ( vcg.i sApproved( dispositio nChoice) & & vcg.getS econdaryIn itDispDate ()== null  ){
  1488                                                       if  ( vcg.isV acoWaiverS econdary()  ){
  1489                                                                clos eDelayWork  ( request , person,  sc, vcg );
  1490                                                       }  else if (  vcg.isWaiv erSecondar y() ) {
  1491                                                                save CscWaiver(  request,  person, sc , ndx, vcg , CaretStr Pool.ACCEP TED);
  1492                                                       }
  1493                                               }
  1494                                               vcg.setSec ondaryDisp ositionDat e(disposit ionDate);
  1495                                      }
  1496                             } else  if ( pers on.getRole () == Pers on.Role.SE CONDARYTWO  && !vcg.g etSecondar yTwoDispRe ason().equ als( dispo sitionChoi ce )  ){
  1497                                      oldDispo sitionStat e = vcg.ge tSecondary TwoDispRea son();
  1498                                      vcg.setS econdaryTw oDispReaso n( extDays (dispositi onChoice,  extensionD ays)  + di spositionR eason );
  1499                                      vcgAnId  = vcg.getS econdaryTw oVcgAnId() ;
  1500                                      userIds. add( vcg.g etSecondar yTwo().get RootUserId () );
  1501                                      if ( vcg .isRevoked ( vcg.getS econdaryTw oDispReaso n() ) ){
  1502                                               vcg.setSec ondaryTwoR evocationD ate(dispos itionDate) ;
  1503                                      } else {
  1504                                               if ( vcg.i sApproved( dispositio nChoice) & & vcg.getS econdaryIn itDispDate () == null  ){
  1505                                                       if  ( vcg.isV acoWaiverS econdaryTw o() ){
  1506                                                                clos eDelayWork  ( request , person,  sc, vcg );
  1507                                                       }  else if (  vcg.isWaiv erSecondar yTwo() ){
  1508                                                                save CscWaiver(  request,  person, sc , ndx, vcg , CaretStr Pool.ACCEP TED);
  1509                                                       }
  1510                                               }
  1511                                               vcg.setSec ondaryTwoD isposition Date(dispo sitionDate );
  1512                                      }
  1513                                      if ( ext ensionDays [0] > 0 ){
  1514                                               _log.info( "Benefits  extended "  + extensi onDays[0]  + " days f rom revoca tion date" );
  1515                                      }
  1516                             } else  if ( pers on.getRole () == Pers on.Role.GE NERAL && ! vcg.getGen eralDispRe ason().equ als( dispo sitionChoi ce )  ){ / / General  Caregiver
  1517                                      _log.inf o( "Genera l Caregive r... updat e profile. .." );
  1518                                      generalU pdate = tr ue;
  1519    
  1520                                      vcg.setG eneralDisp Reason( ex tDays(disp ositionCho ice, exten sionDays)   + disposi tionReason   );
  1521                                      oldDispo sitionStat e = vcg.ge tGeneralDi spReason() ;
  1522                                      if ( vcg .isRevoked ( vcg.getG eneralDisp Reason() )  ){
  1523                                               vcg.setGen eralRevoca tionDate(d isposition Date);
  1524                                      } else {
  1525                                               vcg.setGen eralDispos itionDate( dispositio nDate);
  1526                                      }
  1527                             }
  1528                             
  1529                             String  note = re quest.getP arameter(n dx + "note ");
  1530                             if ( ! CaretStrPo ol.IN_PROC ESS.equals ( disposit ionChoice  )){
  1531                                      vcg.setN ote("dispo sitionNote ", note, s c.getUserI d(), sc.ge tCreateDat e(), NoteS upport.Not eGroup.DIS POSITION.g roupId() ) ;
  1532                             }
  1533                             
  1534                             
  1535   //                        WorkTy pe getDisp ositionWor k()
  1536                             
  1537                             WorkTy pe cbopcWo rk = vcg.g etDisposit ionWork(di spositionC hoice);
  1538                             if ( c bopcWork   != null ){
  1539                                      //CBOPC  Work Item
  1540                                      Map<Work Type,WorIm > workItem Map = (Map )request.g etAttribut e("workIte mMap");
  1541                                      if ( wor kItemMap = = null ){
  1542                                               workItemMa p = new Ha shMap<Work Type,WorIm >();
  1543                                               request.se tAttribute ("workItem Map", work ItemMap);
  1544                                      }
  1545                                      if ( !wo rkItemMap. containsKe y( cbopcWo rk ) ){
  1546                                               WorIm work Item = Too lbox.creat eWorkItem( sc, 0, vcg , cbopcWor k, vcg.get VeteranId( ), person. getPersnId () );
  1547                                               workItem.s etVcgId( v cg.getVcgI d() );
  1548                                               workItem.s etQueId( s c.getUserI d() );
  1549                                               CaretLocal ServiceUti l.save(wor kItem);
  1550                                               workItemMa p.put(cbop cWork, wor kItem);
  1551                                      }
  1552                             }
  1553           
  1554                             VcgApp lication v cgApp = nu ll;
  1555                             if ( ! generalUpd ate ){
  1556                                      //Update  active Wo rk Item
  1557                                      try {
  1558                                               vcgApp = n ew VcgAppl ication( V cgAnLocalS erviceUtil .getVcgAn(  vcgAnId )  );
  1559                                               if ( vcgAp p != null  ){
  1560                                                       Ap plicationS tatus appS tatus = nu ll;
  1561                                                       Li st<WorIm>  works = Wo rImLocalSe rviceUtil. findByClas sId(vcg.ge tVcgId(),  vcgAnId);
  1562                                                       if  ( !works. isEmpty()  ){
  1563                                                                Work ItemSuppor t vcgAppWo rk = new W orkItemSup port( work s.get(0) ) ;
  1564                                                                if (  vcgAppWor k.isComple table( vcg  ) ){
  1565                                                                         if ( ! WorkStatus .COMPLETE. name().equ als( vcgAp pWork.getS tatus() )  ){
  1566                                                                                  vcgAppWo rk.setStat us( CaretS trPool.COM PLETE );
  1567                                                                                  vcgAppWo rk.setComp letionBy(s c.getUserI d());
  1568                                                                                  vcgAppWo rk.setComp letionDate (sc.getCre ateDate()) ;
  1569                                                                                  CaretLoc alServiceU til.save(v cgAppWork) ;
  1570                                                                                  appStatu s = Applic ationStatu s.DECISION _MADE;
  1571                                                                         } else  if ( !App licationSt atus.DECIS ION_MADE.n ame().equa ls( vcgApp .getStatus () ) ){
  1572                                                                                  appStatu s = Applic ationStatu s.IN_REVIE W;
  1573                                                                         }
  1574                                                                } el se if ( !A pplication Status.DEC ISION_MADE .name().eq uals( vcgA pp.getStat us() ) ){
  1575                                                                         appSta tus = Appl icationSta tus.IN_REV IEW;
  1576                                                                }
  1577                                                       }
  1578                                                       if  ( appStat us != null  ){
  1579                                                                vcgA pp.setStat us( appSta tus.name()  );
  1580                                                                Care tLocalServ iceUtil.sa ve( vcgApp  );
  1581                                                       }
  1582                                               }
  1583                                      } catch  (NoSuchCla ssNameExce ption e) {
  1584                                               throw new  Applicatio nWorkFlowE xception(e );
  1585                                      } catch  (SystemExc eption e)  {
  1586                                               throw new  Applicatio nWorkFlowE xception(e );
  1587                                      } catch  (PortalExc eption e)  {
  1588                                               throw new  Applicatio nWorkFlowE xception(e );
  1589                                      }
  1590                             }
  1591                             
  1592                             if ( !  userIds.i sEmpty() & & vcgApp ! = null ) {
  1593                                      String m essage = L anguageUti l.get( Loc ale.getDef ault(), Ca retStrPool .DISPOSITI ONED_ONLIN E_MESSAGE) ;
  1594                                      userIds. add( vcg.g etVeteran( ).getRootU serId() );
  1595                                      for ( lo ng userId  : userIds  ){
  1596                                               if ( userI d > 0 ){
  1597                                                       Ca retLocalSe rviceUtil. addNote( T oolbox.cre ateNote( s c.getCreat eDate(), v cgApp.getV cgAnId(),  0, userId,  message )  );
  1598                                               }
  1599                                      }
  1600                             }
  1601                             CaretL ocalServic eUtil.save (vcg);
  1602                    }
  1603           
  1604           
  1605           pr ivate Stri ng getNote Body(VcgSu pport vcg,  String di spositionC hoice, Per son.Role r ole, Servi ceContext  sc ) {
  1606                    Stri ngBuilder  sb = new S tringBuild er();
  1607                    sb.a ppend("Vet eran’s Nam e - ").app end(vcg.ge tVeteranNa me()).appe nd("\n");
  1608                    sb.a ppend("Vet eran’s SSN  - ").appe nd(vcg.get Veteran(). getSsn()). append("\n ");
  1609                    
  1610                    VcgA n app = vc g.getPerso nVcgAn(rol e);
  1611                    sb.a ppend("For m 10-10CG  Valid Date  - ").appe nd(app.get ReceivedDa te()).appe nd("\n");
  1612                    
  1613                    try  {
  1614                             sb.app end("Veter an Assessm ent Comple ted - ").a ppend( Too lbox.forma tDateCprs( vcg.geVete ranAssessm entComplet ionDate()  ) ).append ("\n");
  1615                             sb.app end("Careg iver Asses sment Comp leted - ") .append( T oolbox.for matDateCpr s(vcg.getC aregiverAs sessmentCo mpletionDa te(role) )  ).append( "\n");
  1616                             sb.app end("Careg iver Train ing Verifi ed - ").ap pend( Tool box.format DateCprs(v cg.getCare giverTrain ingComplet ionDate(ro le) ) ).ap pend("\n") ;
  1617                             sb.app end("In-Ho me Visit C ompleted -  ").append ( Toolbox. formatDate Cprs(vcg.g etInHomeCo mpletionDa te(role) )  ).append( "\n");
  1618                    } ca tch (Appli cationWork FlowExcept ion e) {
  1619                             e.prin tStackTrac e();
  1620                    }
  1621                    
  1622                    sb.a ppend("App roval Date  - ").appe nd( Toolbo x.formatDa teCprs(sc. getCreateD ate()) ).a ppend("\n" );
  1623                    sb.a ppend("App roved Prim ary Family  Caregiver  Name - ") .append(vc g.getPrima ryName()). append("\n ");
  1624   //               (If  there is a  Secondary )
  1625                    if (  vcg.isSec ondaryAppr oved() ){
  1626                             sb.app end("Appro ved Second ary Family  Caregiver  Name - ") .append(vc g.getSecon daryName() ). append( "\n");
  1627                    }
  1628                    
  1629                    
  1630                    retu rn sb.toSt ring();
  1631           }
  1632  
  1633  
  1634           pr ivate Stri ng getNote Title(VcgS upport vcg , String d isposition Choice, Pe rson.Role  role ) {
  1635                    
  1636                    Stri ng title =  MessageFo rmat.forma t( Languag eUtil.get(  Locale.ge tDefault() , "nationa l-note-tit le-" + dis positionCh oice ), ro le.name()  );
  1637                    
  1638                    retu rn title;
  1639           }
  1640  
  1641  
  1642           pr ivate void  closeDela yWork(Acti onRequest  request, P erson pers on, Servic eContext s c, VcgSupp ort vcg) t hrows Appl icationWor kFlowExcep tion {
  1643                    
  1644                    WorI m workItem  = WorImLo calService Util.findB yCgWorkLas t( vcg.get VcgId(), p erson.getP ersnId(),  WorkType.A PP_DELAY.n ame() );
  1645                    
  1646                    if (  Toolbox.i sEmpty( wo rkItem.get Status() )  || CaretS trPool.IN_ PROCESS.eq uals( work Item.getSt atus() ) ) {
  1647                             throw  new Applic ationWorkF lowExcepti on( "INVAL ID WORK IT EM STATUS"  );
  1648                    } el se {
  1649                             workIt em = WorIm LocalServi ceUtil.fin dByCgWorkL ast( vcg.g etVcgId(),  person.ge tPersnId() , WorkType .DELAY_REV IEWED.name () );
  1650                             workIt em.setComp letionBy(P ortalUtil. getUserId( request) ) ;
  1651                             workIt em.setComp letionDate ( sc.getCr eateDate()  );
  1652                             workIt em.setStat us( WorkSt atus.COMPL ETE.name()  );
  1653                             
  1654   //                        workIt em.useNote (noteAtt,  vcg.getNot e(noteAtt) );
  1655                             CaretL ocalServic eUtil.save (workItem) ;
  1656                    }
  1657                    
  1658           }
  1659  
  1660  
  1661           pr ivate Waiv r saveCscW aiver(Acti onRequest  request, P erson pers on, Servic eContext s c, String  ndx, Vcg v cg, String  adjudicat ion) throw s Applicat ionWorkFlo wException  {
  1662                    Waiv r waiver =  new Waivr Impl();
  1663                    waiv er.setReas on( reques t.getParam eter(ndx +  "waiverRe ason") );
  1664                    waiv er.setNote ( request. getParamet er(ndx + " waiverNote ") );
  1665                    waiv er.setUser Id( sc.get UserId() ) ;
  1666                    waiv er.setCrea tionDate(  sc.getCrea teDate() ) ;
  1667                    waiv er.setClas sPk( vcg.g etVcgId()  );
  1668                    waiv er.setAdju dication(  adjudicati on );
  1669                    Care tLocalServ iceUtil.sa ve(waiver) ;
  1670                    retu rn waiver;
  1671           }
  1672  
  1673  
  1674           pr ivate void  saveFirst PeriodicAs sessments( ActionRequ est reques t, VcgSupp ort vcgSup port, Pers on person,  Date disp ositionDat e){
  1675                    
  1676                    Map< String, Ob ject> form  = ResultM ap.getForm (request);
  1677                    Serv iceContext  sc = Care tParam.set CaretServi ceContext( request);
  1678                    
  1679                    //As smtBean pe riodicAssm tOne = new  AssmtBean (new Assmt Impl(), Ca retStrPool .QUARTER1) ;                             
  1680                    //As smtBean pe riodicAssm tTwo = new  AssmtBean (new Assmt Impl(), Ca retStrPool .QUARTER2) ;                    
  1681                    //As smtBean pe riodicAssm tThree = n ew AssmtBe an(new Ass mtImpl(),  CaretStrPo ol.QUARTER 3);                                    
  1682                    //As smtBean pe riodicAssm tAnnual =  new AssmtB ean(new As smtImpl(),  CaretStrP ool.ANNUAL ); 
  1683  
  1684                    List <AssmtBean > periodic Assessment List = new  ArrayList <AssmtBean >();
  1685                    //pe riodicAsse ssmentList .add(perio dicAssmtOn e);
  1686                    //pe riodicAsse ssmentList .add(perio dicAssmtTw o);
  1687                    //pe riodicAsse ssmentList .add(perio dicAssmtTh ree);
  1688                    //pe riodicAsse ssmentList .add(perio dicAssmtAn nual);
  1689                    peri odicAssess mentList.a dd(new Ass mtBean(new  AssmtImpl (), CaretS trPool.QUA RTER1));
  1690                    peri odicAssess mentList.a dd(new Ass mtBean(new  AssmtImpl (), CaretS trPool.QUA RTER2));
  1691                    peri odicAssess mentList.a dd(new Ass mtBean(new  AssmtImpl (), CaretS trPool.QUA RTER3));
  1692                    peri odicAssess mentList.a dd(new Ass mtBean(new  AssmtImpl (), CaretS trPool.ANN UAL));
  1693  
  1694                    try  {
  1695                             Calend ar c = Cal endar.getI nstance();  
  1696                             c.setT ime(dispos itionDate) ;
  1697                             for(As smtBean on eAssmt:per iodicAsses smentList) {
  1698                                      oneAssmt .getAssess ment().set Year(1);
  1699                                      oneAssmt .getAssess ment().set VcgId(vcgS upport.get VcgId());
  1700                                      oneAssmt .getAssess ment().set Active(tru e);
  1701                                      oneAssmt .getAssess ment().set CaregiverI d(person.g etPersnId( ));
  1702                                      oneAssmt .getAssess ment().set UserId(sc. getUserId( ));
  1703                                      
  1704                                      c.add(Ca lendar.DAT E, 90);
  1705                                      oneAssmt .getAssess ment().set ScheduleDa te(c.getTi me());  
  1706                                      
  1707                                      CaretLoc alServiceU til.save(o neAssmt.ge tAssessmen t());
  1708                             }
  1709                    } ca tch (Appli cationWork FlowExcept ion e) {
  1710                             Applic ationWorkF lowExcepti on.handleE xception(e );
  1711                    }
  1712  
  1713                    form .put("peri odicAssess mentList",  periodicA ssessmentL ist);
  1714           }
  1715  
  1716           
  1717           pu blic void  inactivate Assessment s( long vc gId, long  caregiverI d, String  category) 
  1718           {
  1719                    Stri ng[] perio dicTypes =  {CaretStr Pool.QUART ER1, Caret StrPool.QU ARTER2, Ca retStrPool .QUARTER3,  CaretStrP ool.ANNUAL };
  1720                    Stri ng[] initi alTypes =  {CaretStrP ool.PRIMAR Y_ASSESSME NT, CaretS trPool.PRI MARY_CLINI CAL, Caret StrPool.PR IMARY_TRAI NING, Care tStrPool.P RIMARY_IN_ HOME, Care tStrPool.S ECONDARY_A SSESSMENT,  CaretStrP ool.SECOND ARY_CLINIC AL, CaretS trPool.SEC ONDARY_TRA INING, Car etStrPool. SECONDARY_ TWO_ASSESS MENT, Care tStrPool.S ECONDARY_T WO_CLINICA L, CaretSt rPool.SECO NDARY_TWO_ TRAINING};
  1721  
  1722                    try 
  1723                    {                                                    
  1724                             List<A ssmt> asse ssmentList ;
  1725                             if(cat egory.equa ls(CaretSt rPool.ASSM T_PERIODIC )){
  1726                                      assessme ntList = A ssmtLocalS erviceUtil .findByAss mtTypes(vc gId, perio dicTypes);
  1727                             }else  if(categor y.equals(C aretStrPoo l.ASSMT_IN ITIAL)){
  1728                                      assessme ntList = A ssmtLocalS erviceUtil .findByAss mtTypes(vc gId, initi alTypes);
  1729                             }else{
  1730                                      assessme ntList = A ssmtLocalS erviceUtil .findByVcg Id(vcgId);
  1731                             }
  1732                             
  1733                             for(As smt assess ment:asses smentList)
  1734                             {
  1735                                      if(asses sment.isAc tive() &&  assessment .getCaregi verId()==c aregiverId )
  1736                                      {
  1737                                               assessment .setActive (false);
  1738                                               CaretLocal ServiceUti l.save(ass essment);
  1739                                      }
  1740                             }                         
  1741                    } ca tch (Appli cationWork FlowExcept ion e) {
  1742                                      Applicat ionWorkFlo wException .handleExc eption(e);
  1743                    }
  1744           }
  1745  
  1746           
  1747           pu blic void  activateAs sessments(  long vcgI d, long ca regiverId,  String ca tegory) 
  1748           {
  1749                    Stri ng[] perio dicTypes =  {CaretStr Pool.QUART ER1, Caret StrPool.QU ARTER2, Ca retStrPool .QUARTER3,  CaretStrP ool.ANNUAL };
  1750                    Stri ng[] initi alTypes =  {CaretStrP ool.PRIMAR Y_ASSESSME NT, CaretS trPool.PRI MARY_CLINI CAL, Caret StrPool.PR IMARY_TRAI NING, Care tStrPool.P RIMARY_IN_ HOME, Care tStrPool.S ECONDARY_A SSESSMENT,  CaretStrP ool.SECOND ARY_CLINIC AL, CaretS trPool.SEC ONDARY_TRA INING, Car etStrPool. SECONDARY_ TWO_ASSESS MENT, Care tStrPool.S ECONDARY_T WO_CLINICA L, CaretSt rPool.SECO NDARY_TWO_ TRAINING};
  1751  
  1752                    try 
  1753                    {                                                    
  1754                             List<A ssmt> asse ssmentList ;
  1755                             if(cat egory.equa ls(CaretSt rPool.ASSM T_PERIODIC )){
  1756                                      assessme ntList = A ssmtLocalS erviceUtil .findByAss mtTypes(vc gId, perio dicTypes);
  1757                             }else  if(categor y.equals(C aretStrPoo l.ASSMT_IN ITIAL)){
  1758                                      assessme ntList = A ssmtLocalS erviceUtil .findByAss mtTypes(vc gId, initi alTypes);
  1759                             }else{
  1760                                      assessme ntList = A ssmtLocalS erviceUtil .findByVcg Id(vcgId);
  1761                             }
  1762                             
  1763                             for(As smt assess ment:asses smentList)
  1764                             {
  1765                                      if(!asse ssment.isA ctive() &&  assessmen t.getCareg iverId()== caregiverI d)
  1766                                      {
  1767                                               assessment .setActive (true);
  1768                                               CaretLocal ServiceUti l.save(ass essment);
  1769                                      }
  1770                             }                         
  1771                    } ca tch (Appli cationWork FlowExcept ion e) {
  1772                                      Applicat ionWorkFlo wException .handleExc eption(e);
  1773                    }
  1774           }
  1775  
  1776  
  1777  
  1778           pr ivate Stri ng extDays (String di spositionR eason, int [] extensi onDays) {
  1779                    int  ndx = disp ositionRea son.indexO f("[");
  1780                    Stri ng temp =  dispositio nReason;
  1781                    if (  ndx > 0 ) {
  1782                             temp =  dispositi onReason.s ubstring(0 ,ndx);
  1783                             extens ionDays[0]  = Integer .valueOf(  dispositio nReason.su bstring(nd x+1, dispo sitionReas on.indexOf ("]")) );
  1784                    }
  1785                    retu rn temp;
  1786           }
  1787  
  1788           
  1789           pu blic void  saveVcgEnt ry ( Actio nRequest r equest, Ac tionRespon se respons e ) throws  Applicati onWorkFlow Exception{
  1790                    getO utput(requ est);
  1791                    Stri ng ndx = T oolbox.nul lSafe(requ est.getPar ameter("nd x")) + Str ingPool.UN DERLINE;
  1792                    long  persnId =  ParamUtil .getLong(r equest, re quest.getP arameter(" vcg_ndx")  + "_primar yKey", Par amUtil.get Long(reque st, "_prim aryKey", P aramUtil.g etLong(req uest, ndx  + "primary Key") ) );
  1793                    long  vcgId = P aramUtil.g etLong(req uest, requ est.getPar ameter("nd x") + "vcg Id", Param Util.getLo ng(request , "vcgId")  );
  1794                    Stri ng icn = r equest.get Parameter( ndx + "iCN ");
  1795                    
  1796                    Serv iceContext  sc = Care tParam.set CaretServi ceContext(  request ) ;
  1797                    VcgS upport vcg  = null;
  1798                    if (  vcgId > 0  ){
  1799                             vcg =  VcgSupport .getVcgSup port( vcgI d );
  1800                             
  1801                             if ( C Action.can DoCaret( r equest, CA ction.Care tCan.MANAG E_VCG.name () ) ){
  1802                                      int mode  = ParamUt il.getInte ger(reques t, "MODE",  0);
  1803                                      
  1804                                      try {
  1805                                              
  1806                                               Person per son = null ;
  1807                                               Person for mPerson =  null;
  1808                                               boolean is Approved =  false;
  1809   //                                          boolean re lationship Empty = mo de == 1 ||  Toolbox.i sEmpty( re quest.getP arameter(  ndx + "rel ationship"  ) );
  1810                                               if ( persn Id > 0 ){
  1811                                                       if  ( persnId  == vcg.ge tVeteranId () ){
  1812                                                                if (  mode == 0  ){
  1813                                                                         formPe rson = (Ve teran) Car etParam.lo adModel( r equest, ne w Veteran(  new Persn Impl() ), 
  1814                                                                                  Toolbox. getCollect ion("first Name","las tName","mi ddleName",  "birthDat e", "gende r", "email ", "addres s", "phone ", "phone2 ", "ssn",  "country",  "validAdd ress",  "e xternalId" , "vaHealt hEnrolled" , "groupId " ),
  1815                                                                                  ndx ); / /TODO: cre ate transf er work-it em if faci lity is ch anged
  1816                                                                }
  1817                                                                pers on = new V eteran( Pe rsnLocalSe rviceUtil. getPersn(p ersnId) );
  1818                                                                isAp proved = v cg.isPrima ryApproved () || vcg. isSecondar yApproved( ) || vcg.i sSecondary TwoApprove d();
  1819                                                       }  else if (  persnId ==  vcg.getPr imaryId()  ){
  1820                                                                pers on = new P rimary( Pe rsnLocalSe rviceUtil. getPersn(p ersnId) );
  1821                                                                if (  mode == 0  ) {
  1822                                                                         formPe rson = (Pr imary) Car etParam.lo adModel( r equest, ne w Primary(  new Persn Impl() ), 
  1823                                                                                           Toolbox.ge tCollectio n("firstNa me","lastN ame","midd leName", " birthDate" , "gender" , "email",  "address" , "phone",  "phone2",  "ssn", "c ountry", " validAddre ss",  "ext ernalId",  "otherInsC hecked", " otherHealt hInsurance ", "mediEn rolled"),
  1824                                                                                           ndx );
  1825                                                                         vcg.se tPrimaryTy pe( reques t.getParam eter( ndx  + "relatio nship" ) ) ;
  1826                                                                }
  1827                                                                isAp proved = v cg.isPrima ryApproved ();
  1828                                                       }  else if (  persnId ==  vcg.getSe condaryId( ) ){
  1829                                                                pers on = new S econdary(  PersnLocal ServiceUti l.getPersn (persnId)  );
  1830                                                                if (  mode == 0  ) {
  1831                                                                         formPe rson = (Se condary) C aretParam. loadModel(  request,  new Second ary( new P ersnImpl()  ), 
  1832                                                                                           Toolbox.ge tCollectio n("firstNa me","lastN ame","midd leName", " birthDate" , "gender" , "email",  "address" , "phone",  "phone2",  "ssn", "c ountry", " validAddre ss",  "ext ernalId" ) ,
  1833                                                                                           ndx );
  1834                                                                         vcg.se tSecondary Type( requ est.getPar ameter( nd x + "relat ionship" )  );
  1835                                                                }
  1836                                                                isAp proved = v cg.isSecon daryApprov ed();
  1837                                                       }  else if (  persnId ==  vcg.getSe condaryTwo Id() ){
  1838                                                                pers on = new S econdaryTw o( PersnLo calService Util.getPe rsn(persnI d) );
  1839                                                                if (  mode == 0  ) {
  1840                                                                         formPe rson = (Se condaryTwo ) CaretPar am.loadMod el( reques t, new Sec ondaryTwo(  new Persn Impl() ), 
  1841                                                                                           Toolbox.ge tCollectio n("firstNa me","lastN ame","midd leName", " birthDate" , "gender" , "email",  "address" , "phone",  "phone2",  "ssn", "c ountry", " validAddre ss",  "ext ernalId" ) ,
  1842                                                                                           ndx );
  1843                                                                         vcg.se tSecondary TwoType( r equest.get Parameter(  ndx + "re lationship " ) );
  1844                                                                }
  1845                                                                isAp proved = v cg.isSecon daryTwoApp roved();
  1846                                                       }  else {
  1847                                                                pers on = new G eneral( Pe rsnLocalSe rviceUtil. getPersn(p ersnId) );
  1848                                                                if (  mode == 0   || mode  == 3 ) {
  1849                                                                         formPe rson = (Ge neral) Car etParam.lo adModel( r equest, ne w General(  new Persn Impl() ), 
  1850                                                                                           Toolbox.ge tCollectio n("firstNa me","lastN ame","midd leName", " birthDate" , "gender" , "email",  "address" , "phone",  "phone2",  "ssn", "c ountry", " validAddre ss",  "ext ernalId" ) ,
  1851                                                                                           ndx );
  1852                                                                         vcg.se tGeneralTy pe( reques t.getParam eter( ndx  + "relatio nship" ) ) ;
  1853                                                                }
  1854                                                       }
  1855                                               } else if  ( mode ==  3 ) {
  1856                                                       pe rson = new  General(  new PersnI mpl() );
  1857                                                       if  ( mode ==  0  || mod e == 3 ) {
  1858                                                                form Person = ( General) C aretParam. loadModel(  request,  new Genera l( new Per snImpl() )
  1859                                                                                  Toolbox. getCollect ion("first Name","las tName","mi ddleName",  "birthDat e", "gende r", "email ", "addres s", "phone ", "phone2 ", "ssn",  "country",  "validAdd ress",  "e xternalId"  ),
  1860                                                                                  ndx );
  1861                                                       }
  1862                                               }
  1863                                              
  1864                                              
  1865                                               if ( mode  == 0 || mo de == 3 ){
  1866                                                       if  ( formPer son.isFore igner() ){
  1867                                                                Care tParam.loa dModel( re quest, for mPerson, T oolbox.get AddressCol lection(),  Toolbox.n ullSafe(re quest.getP arameter(" ndx")) + C aretStrPoo l.G_UNDERL INE );
  1868                                                       }  else {
  1869                                                                Care tParam.loa dModel( re quest, for mPerson, T oolbox.get AddressCol lection(),  Toolbox.n ullSafe(re quest.getP arameter(" ndx")) + C aretStrPoo l.U_UNDERL INE );
  1870                                                       }
  1871                                               }
  1872                                              
  1873                                               switch ( m ode ){
  1874                                                       ca se 1:
  1875                                                                if (  CAction.c anDoCaret(  request,  CAction.Ca retCan.DIS POSITION_V CG.name()  ) ){
  1876                                                                         saveVc gDispositi on ( reque st, vcg, p erson );
  1877                                                                }
  1878                                                                brea k;
  1879                                                       ca se 2:
  1880                                                                
  1881                                                                if (  CAction.c anDoCaret(  request,  CAction.Ca retCan.UPD ATE_TIER_L EVEL.name( ) ) ){
  1882                                                                         String  tierEffec tiveDate =  request.g etParamete r(ndx + "t ierEffecti veDate");
  1883                                                                         String  tierLevel Str = requ est.getPar ameter(ndx  + "tier") ;
  1884                                                                         String  dispositi onDate = r equest.get Parameter( ndx + "dis positionDa te");
  1885                                                                         String  caretNote  = request .getParame ter("caret _note");
  1886                                                                         int ti erLevel =  Integer.va lueOf(Stri ng.valueOf (tierLevel Str.charAt (4)));
  1887                                                                         int ol dTier = vc g.getTierL evel();
  1888   //                                                                    VcgSup port vcgSu pport = ne w VcgSuppo rt(vcg);
  1889                                                                         if ( t ierEffecti veDate !=  null && !v cg.getTier EffectiveD ateStr().e quals( tie rEffective Date ) ||
  1890                                                                                           vcg.getTie rLevel() ! = tierLeve l ){
  1891                                                                                  vcg.setT ierEffecti veDateStr(  tierEffec tiveDate ) ;
  1892                                                                                  if ( dis positionDa te!= null  && !String Pool.BLANK .equals( d isposition Date ) ){
  1893                                                                                           vcg.setPri maryDispos itionDate(  Toolbox.p arseDate(d isposition Date) );
  1894                                                                                  }
  1895                                                                                  vcg.setT ierLevel(  tierLevel   );
  1896                                              
  1897                                                                                  vcg.setN ote("tierU pdateNote" , caretNot e, sc.getU serId(), s c.getCreat eDate(), N oteSupport .NoteGroup .TIER_UPDA TE.groupId () );
  1898                                                                                  CaretLoc alServiceU til.save(v cg);
  1899                                                                                  
  1900                                                                                  if ( tie rLevel !=  oldTier ){
  1901                                                                                           String mes sage = Lan guageUtil. get( Local e.getDefau lt(), Care tStrPool.D ISPOSITION ED_ONLINE_ MESSAGE);
  1902                                                                                           CaretLocal ServiceUti l.addNote(  Toolbox.c reateNote( sc.getCrea teDate(),  vcg.getPri maryVcgAnI d(), 0, pe rson.getRo otUserId() , message  ) );
  1903                                                                                           CaretLocal ServiceUti l.addNote(  Toolbox.c reateNote( sc.getCrea teDate(),  vcg.getPri maryVcgAnI d(), 0, vc g.getVeter an().getRo otUserId() , message  ) );
  1904                                                                                  }
  1905                                                                                  
  1906                                                                                  WorIm wo rkItem = T oolbox.cre ateWorkIte m(sc, 0, v cg, WorkTy pe.TIER_UP DATE, 
  1907                                                                                                   vc g.getVeter anId(), pe rson.getPe rsnId() ==  vcg.getVe teranId()?  vcg.getPr imaryId():  person.ge tPersnId()  );
  1908                                                                                  workItem .setQueId(  sc.getUse rId() );
  1909                                                                                  workItem .setVcgId( vcgId);
  1910                                                                                  CaretLoc alServiceU til.save(  workItem ) ;
  1911                                                                                  
  1912                                                                         } 
  1913                                                                }
  1914                                                                brea k;
  1915                                                       ca se 3: //as signing Ge neral CG
  1916                                                                
  1917                                                                if (  vcg.getGe neralId()  > 0 && ( v cg.isAppro ved( vcg.g etGeneralD ispReason( ) ) || vcg .isReinsta ted( vcg.g etGeneralD ispReason( ) ) ) ){
  1918                                                                         throw  new Applic ationWorkF lowExcepti on ( "Cann ot over-wr ite an app roved Gene ral Caregi ver for a  new Genera l Caregive r ");
  1919                                                                }
  1920                                                                
  1921                                                                if (  CaretView Controller .getViewCo ntroller() .setVcgPer son( reque st, formPe rson, pers on, new bo olean[5]). isEmpty()  ){
  1922                                                                         CaretL ocalServic eUtil.save (person);
  1923                                                                         vcg.se tNote("gen eralAssign mentNote",  ParamUtil .get(reque st, CaretS trPool.WOR K_COMMENT,  CaretStrP ool.ASSIGN ED_GENERAL _CG_MESSAG E ),
  1924                                                                                           sc.getUser Id(), sc.g etCreateDa te(), Note Support.No teGroup.AS SIGN_GENER AL.groupId () );
  1925                                                                         
  1926                                                                         vcg.se tNewGenera l(person.g etPersnId( ), request .getParame ter( ndx +  "relation ship" ) );
  1927                                                                         CaretL ocalServic eUtil.save (vcg);
  1928                                                                }
  1929                                                                
  1930                                                                brea k;
  1931                                                       ca se 4:
  1932   //                                                           Stri ng vcgNdx  = request. getParamet er("vcg_nd x") + Stri ngPool.UND ERLINE;
  1933                                                                Waiv r waiver =  saveCscWa iver( requ est, perso n, sc, ndx , vcg, nul l );
  1934                                                                VcgA n vcgAn =  vcg.getPer sonVcgAn(  persnId );
  1935                                                                Work ItemSuppor t workAppD elay =  ne w WorkItem Support(To olbox.crea teWorkItem (sc, vcg.g etGroupId( ), vcgAn,  WorkType.A PP_DELAY,  vcg.getVet eranId(),  persnId));
  1936                                                                work AppDelay.s etVcgId( v cg.getVcgI d() );
  1937                                                                work AppDelay.s etQueId( w aiver.getW aivrId() ) ;
  1938                                                                Care tLocalServ iceUtil.sa ve(workApp Delay);
  1939                                                                
  1940                                                                vcg. setNote("a ppDelayNot e",  reque st.getPara meter(ndx  + "waiverN ote"),
  1941                                                                                  sc.getUs erId(), sc .getCreate Date(), No teSupport. NoteGroup. APP_DELAY. groupId()  );
  1942                                                                Care tLocalServ iceUtil.sa ve(vcg);
  1943  
  1944                                                                work AppDelay.u seNote("ap pDelayNote ", vcg.get Note("appD elayNote") );
  1945                                                                Care tLocalServ iceUtil.sa ve(workApp Delay);
  1946                                                                brea k;
  1947                                                       de fault:
  1948                                              
  1949                                                                
  1950                                                       
  1951                                                       bo olean[] ch ange = new  boolean[5 ];
  1952                                                       
  1953                                                       Li st<String>  errors =  CaretViewC ontroller. getViewCon troller(). setVcgPers on( reques t, formPer son, perso n, change) ;
  1954                                                       
  1955                                                       if  ( ! error s.isEmpty( ) ){
  1956                                                                requ est.setAtt ribute("SA VE_FAILED" , errors.g et(0) );
  1957                                                                retu rn;
  1958                                                       }
  1959                                                       
  1960                                                       if  ( change[ Person.Cha nges.INSUR ANCE_CHANG E.ordinal( )] || 
  1961                                                                         change [Person.Ch anges.ADDR ESS_CHANGE .ordinal() ] || 
  1962                                                                         change [Person.Ch anges.PII_ CHANGE.ord inal()] ||  
  1963                                                                         change [Person.Ch anges.FACI LITY_CHANG E.ordinal( )] || 
  1964                                                                         change [Person.Ch anges.NAME _CHANGE.or dinal()] ) {
  1965                                                                if (  isApprove d ){
  1966                                                                         List < WorIm> wor kItems =   Toolbox.cr eateWorkIt ems(reques t, 0, pers on, change
  1967                                                                                           vcg.getVet eranId(),  person.get PersnId()  == vcg.get VeteranId( )? vcg.get PrimaryId( ): person. getPersnId () ) ;
  1968                                                                         
  1969                                                                         for (  WorIm work Item : wor kItems ){
  1970                                                                                  workItem .setQueId(  sc.getUse rId() );
  1971                                                                                  workItem .setVcgId( vcgId);
  1972                                                                                  CaretLoc alServiceU til.save(w orkItem);
  1973                                                                                  _log.inf o("adding  note " + P aramUtil.g et(request ,CaretStrP ool.WORK_C OMMENT, St ringPool.B LANK ) );
  1974                                                                         }
  1975   //                                                                    CaretL ocalServic eUtil.addN ote( Toolb ox.createN ote( 
  1976   //                                                                                      sc.getCrea teDate(),
  1977   //                                                                                      person.get PersnId(),
  1978   //                                                                                      vcg.getVcg Id(),
  1979   //                                                                                      sc.getUser Id(),
  1980   //                                                                                      ParamUtil. get(reques t, CaretSt rPool.WORK _COMMENT,  CaretStrPo ol.SYSTEM_ GENERATED_ WORK ) ) ) ;
  1981                                                                }
  1982                                                                Stri ng comment  = request .getParame ter(CaretS trPool.WOR K_COMMENT) ;
  1983                                                                if (  !Toolbox. isEmpty(co mment) ){
  1984                                                                         vcg.se tNote(pers on.getRole ().getLabe l()+"Note" , request. getParamet er(CaretSt rPool.WORK _COMMENT),  sc.getUse rId(), sc. getCreateD ate(), Not eSupport.N oteGroup.P ROFILE_UPD ATE.groupI d() );
  1985                                                                         CaretL ocalServic eUtil.save (vcg);
  1986                                                                }
  1987   //                                                           if (  change[Pe rson.Chang es.ADDRESS _CHANGE.or dinal()] ) {
  1988   //                                                                    String Builder sb  = new Str ingBuilder ().append( person.get Address())
  1989   //                                                                                      .append( p erson.getC ity() ).ap pend( pers on.getStat e()).appen d( person. getZip());
  1990   //                                                                    boolea n valid =  isValid(re quest, per son.getAdd ress(), pe rson.getCi ty(), pers on.getStat e(), perso n.getZip()  );
  1991   //                                                                    person .setValidA ddress( va lid );
  1992   //                                                           }
  1993                                                                Care tLocalServ iceUtil.sa ve(person) ;
  1994                                                       }  else {
  1995                                                                Stri ng comment  = request .getParame ter(CaretS trPool.WOR K_COMMENT) ;
  1996                                                                if (  !Toolbox. isEmpty(co mment) ){
  1997                                                                         vcg.se tNote(pers on.getRole ().getLabe l()+"Note" , request. getParamet er(CaretSt rPool.WORK _COMMENT),  sc.getUse rId(), sc. getCreateD ate(), Not eSupport.N oteGroup.C AREGIVER_I NFO.groupI d() );
  1998                                                                         CaretL ocalServic eUtil.save (vcg);
  1999                                                                }
  2000                                                       }
  2001                                               }
  2002  
  2003                                      } catch  (PortalExc eption e)  {
  2004                                               Applicatio nWorkFlowE xception.h andleExcep tion(e);
  2005                                      } catch  (SystemExc eption e)  {
  2006                                               Applicatio nWorkFlowE xception.h andleExcep tion(e);
  2007                                      }
  2008                                      
  2009                                      loadVcgM anagement  (request,  response);
  2010                                      response .setRender Parameter( CaretStrPo ol.MVC_PAT H, CaretSt rPool.VCG_ MANAGEMENT _PAGE);
  2011                             }
  2012                    } el se {
  2013                             _log.i nfo("vcgId  == 0");
  2014                             Vetera n vcgVeter an;
  2015                             try {
  2016                                      if ( per snId > 0 ) {
  2017                                               vcgVeteran  = new Vet eran(Persn LocalServi ceUtil.get Persn(pers nId));
  2018                                      } else i f ( !Toolb ox.isEmpty (icn) ){
  2019                                               vcgVeteran  = new Vet eran(new P ersnImpl() );
  2020                                               vcgVeteran .setICN(ic n);
  2021                                               vcgVeteran .setLastNa me(request .getParame ter("veter anPersonu_ lastName") );
  2022                                      } else {
  2023                                               throw new  Applicatio nWorkFlowE xception (  "NEED VER IFIED ID F OR VCG CRE ATION" );
  2024                                      }
  2025                                      CaretPar am.loadMod el(request , vcgVeter an, vcgVet eran.getMo delAttribu tes().keyS et(), ndx) ;
  2026                                      if ( vcg Veteran.is Foreigner( ) ){
  2027                                               CaretParam .loadModel ( request,  vcgVetera n, Toolbox .getAddres sCollectio n(), Caret StrPool.VE TERAN_PERS ON + Caret StrPool.G_ UNDERLINE  );
  2028                                      } else {
  2029                                               CaretParam .loadModel ( request,  vcgVetera n, Toolbox .getAddres sCollectio n(), Caret StrPool.VE TERAN_PERS ON + Caret StrPool.U_ UNDERLINE  );
  2030                                      }
  2031                             } catc h (PortalE xception e ) {
  2032                                      throw ne w Applicat ionWorkFlo wException (e);
  2033                             } catc h (SystemE xception e ) {
  2034                                      throw ne w Applicat ionWorkFlo wException (e);
  2035                             }
  2036                             vcgVet eran.setSt atus(Caret StrPool.AC TIVE_VCG);
  2037                             vcgVet eran.setVa HealthEnro lled(Param Util.get(r equest, nd x + "_vaHe althEnroll ed", false ));
  2038                             CaretL ocalServic eUtil.save (vcgVetera n);
  2039                             VcgSup port vcgSu pport = Vc gSupport.g etVeteranV cg( vcgVet eran.getPe rsnId() );
  2040                             vcgSup port.setGr oupId(vcgV eteran.get GroupId()) ;
  2041  
  2042                             CaretL ocalServic eUtil.save (vcgSuppor t);
  2043                             vcgSup port.setNo te("vcgCre ateNote",  ParamUtil. get(reques t, "vetera nPerson_co mments", " Created a  VCG Record "),
  2044                                               sc.getUser Id(), sc.g etCreateDa te(), Note Support.No teGroup.CR EATE_VCG.g roupId());
  2045                             CaretL ocalServic eUtil.save (vcgSuppor t);
  2046  
  2047                             Note n ote = vcgS upport.get Note("vcgC reateNote" );
  2048                             long w orImId = P aramUtil.g etLong(req uest, "wor ImId");
  2049                             if ( w orImId > 0  ){
  2050                                      try {
  2051                                               WorkItemSu pport work Item = new  WorkItemS upport ( W orImLocalS erviceUtil .getWorIm( worImId) ) ;
  2052                                               workItem.u seNote("vc gCreateNot e", note);
  2053                                               workItem.s etVcgId( v cgSupport. getVcgId()  );
  2054                                               CaretLocal ServiceUti l.save(wor kItem);
  2055                                      } catch  (PortalExc eption e)  {
  2056                                               throw new  Applicatio nWorkFlowE xception() ;
  2057                                      } catch  (SystemExc eption e)  {
  2058                                               throw new  Applicatio nWorkFlowE xception() ;
  2059                                      }
  2060                             }
  2061                             vcg =  vcgSupport ;
  2062                    }
  2063                    
  2064                    if (  vcg != nu ll ){
  2065                             reques t.setAttri bute(Caret StrPool.VC GID, vcg.g etVcgId()  );
  2066                    }
  2067                    load VcgManagem ent (reque st, respon se);
  2068                    requ est.setAtt ribute( Ca retStrPool .MVC_PATH,  CaretStrP ool.VCG_MA NAGEMENT_P AGE );
  2069           }
  2070           
  2071           pr ivate bool ean isVali d( Portlet Request re quest, Str ing addres s, String  city, Stri ng state,  String zip  ) {
  2072                    Port letSession  session =  request.g etPortletS ession();
  2073                    Stri ngBuilder  sb = new S tringBuild er().appen d(address) .append( c ity ).appe nd( state  ).append(  zip );
  2074                    Bool ean valid  = (Boolean )session.g etAttribut e( sb.toSt ring() );
  2075                    if (  valid ==  null ){
  2076                             valid  = Toolbox. isValidate UspsAddres s(address,  city, sta te, zip );
  2077                             sessio n.setAttri bute( sb.t oString()  , valid );
  2078                    }
  2079                    retu rn valid;
  2080           }
  2081  
  2082  
  2083           pu blic void  associateW orkItem (  long assoc iateId, lo ng vcgId,  PortletReq uest reque st ) throw s Applicat ionWorkFlo wException {
  2084                    if (  associate Id > 0 ){
  2085                             try {
  2086                                      ServiceC ontext sc  = CaretPar am.setCare tServiceCo ntext(requ est);
  2087                                      WorkItem Support as sociateWor Im = new W orkItemSup port ( Wor ImLocalSer viceUtil.g etWorIm(as sociateId)  );
  2088                                      associat eWorIm.set VcgId(vcgI d);
  2089                                      String n dx = reque st.getPara meter("ndx ");
  2090                                      String c omment = " Associated  " + assoc iateWorIm. getType()  + " to VCG  ";
  2091                                      if ( !To olbox.isEm pty(ndx) ) {
  2092                                               comment =  request.ge tParameter (ndx + "_c omments");
  2093                                      }
  2094                                      associat eWorIm.set Note("asso ciatedNote ", comment , sc.getUs erId(), sc .getCreate Date() );
  2095                                      if ( Car etStrPool. NEW.equals ( associat eWorIm.get Status() )  ){
  2096                                               associateW orIm.setSt atus( Care tStrPool.I N_PROCESS  );
  2097                                      }
  2098                                      CaretLoc alServiceU til.save(a ssociateWo rIm);
  2099                                      Note not e = associ ateWorIm.g etNote( "a ssociatedN ote" );
  2100                                      
  2101                                      VcgSuppo rt vcgSupp ort = VcgS upport.get VcgSupport (vcgId);
  2102                                      vcgSuppo rt.useNote ("workItem Associate" , note );
  2103                                      CaretLoc alServiceU til.save(  vcgSupport  );
  2104                             } catc h (PortalE xception e ) {
  2105                                      throw ne w Applicat ionWorkFlo wException ();
  2106                             } catc h (SystemE xception e ) {
  2107                                      throw ne w Applicat ionWorkFlo wException ();
  2108                             }
  2109                    }
  2110           }
  2111           
  2112           pu blic void  saveVcgAn  ( ActionRe quest acti onRequest  ){
  2113                    _log .info("sav eVcgAn..."  );
  2114                    getO utput(acti onRequest) ;
  2115                    
  2116                    try  {
  2117                             
  2118                             VcgApp lication v cgApplicat ion = new  VcgApplica tion( new  VcgAnImpl( ) );
  2119                             CaretP aram.loadM odel(actio nRequest,  vcgApplica tion, vcgA pplication .getModelA ttributes( ).keySet() , CaretStr Pool.VCGAN _UNDERLINE );
  2120                                                       
  2121                             //crea te new per son record s in db fo r veteran  and caregi vers
  2122                             Servic eContext s c = CaretP aram.setCa retService Context(ac tionReques t);
  2123                             vcgApp lication.s etCreation Date(sc.ge tCreateDat e());
  2124                             
  2125                             long c aregiverId  = 0;
  2126                             
  2127                             String  veteranFi rstName =  ParamUtil. get(action Request, " veteranPer son_firstN ame", "");
  2128                             if(!ve teranFirst Name.equal s("")){                         
  2129                                      Veteran  veteran =  new Vetera n( new Per snImpl() ) ;
  2130                                      CaretPar am.loadMod el(actionR equest, ve teran, vet eran.getMo delAttribu tes().keyS et(), Care tStrPool.V ETERAN_PER SON  + Str ingPool.UN DERLINE);
  2131                                      if( "fal se".equals (veteran.g etCountry( )) ){ //us a address
  2132                                               CaretParam .loadModel (actionReq uest, vete ran, Toolb ox.getAddr essCollect ion(), Car etStrPool. VETERAN_PE RSON + "u_ " );
  2133                                      }else if (!"false". equals(vet eran.getCo untry())){ //foreign  address
  2134                                               CaretParam .loadModel (actionReq uest, vete ran, Toolb ox.getAddr essCollect ion(), Car etStrPool. VETERAN_PE RSON + "g_ " );                                                                                      
  2135                                      }       
  2136                                      veteran. setVaHealt hEnrolled(  vcgApplic ation.getV aHealthEnr olled() );
  2137                                      CaretLoc alServiceU til.save(  veteran );
  2138                                      vcgAppli cation.set VeteranId( veteran.ge tPersnId() );
  2139                             }
  2140  
  2141                             String  primaryFi rstName =  ParamUtil. get(action Request, " primaryPer son_firstN ame", "");
  2142                             if(!pr imaryFirst Name.equal s("")){                         
  2143                                      Primary  primary =  new Primar y ( new Pe rsnImpl()  );
  2144                                      CaretPar am.loadMod el(actionR equest, pr imary, pri mary.getMo delAttribu tes().keyS et(), Care tStrPool.P RIMARY_PER SON  + Str ingPool.UN DERLINE);
  2145                                      if( "fal se".equals (primary.g etCountry( )) ){ //us a address
  2146                                               CaretParam .loadModel (actionReq uest, prim ary, Toolb ox.getAddr essCollect ion(), Car etStrPool. PRIMARY_PE RSON + "u_ " );
  2147                                               if ( Portl etProps.ge t("csc.req uired.prim ary.input" ).contains ("uspsVali dation") & & primary. isComplete DomesticAd dress() &&  !primary. isForeigne r() ){
  2148                                                       pr imary.setV alidAddres s(true);
  2149                                               }
  2150                                      } else i f (!"false ".equals(p rimary.get Country()) ){
  2151                                               CaretParam .loadModel (actionReq uest, prim ary, Toolb ox.getAddr essCollect ion(), Car etStrPool. PRIMARY_PE RSON + "g_ " );                                          
  2152                                      }
  2153                                      primary. setOtherIn sChecked(P aramUtil.g etBoolean( actionRequ est, "prim aryPerson_ otherHealt hInsurance YesNo"));
  2154                                      primary. setMediEnr olled(vcgA pplication .getMediEn rolled());
  2155                                      CaretLoc alServiceU til.save(  primary );
  2156                                      vcgAppli cation.set PrimaryId( primary.ge tPersnId() );
  2157                                      caregive rId = prim ary.getPer snId();
  2158                             }
  2159  
  2160                             String  secondary FirstName  = ParamUti l.get(acti onRequest,  "secondar yPerson_fi rstName",  "");
  2161                             if(!se condaryFir stName.equ als("")){                       
  2162                                      Person s econdary =  new Perso n ( new Pe rsnImpl()  );
  2163                                      CaretPar am.loadMod el(actionR equest, se condary, s econdary.g etModelAtt ributes(). keySet(),  CaretStrPo ol.SECONDA RY_PERSON   + StringP ool.UNDERL INE);
  2164                                      if( "fal se".equals (secondary .getCountr y()) ){ // usa addres s
  2165                                               CaretParam .loadModel (actionReq uest, seco ndary, Too lbox.getAd dressColle ction(), C aretStrPoo l.SECONDAR Y_PERSON +  "u_" );
  2166                                      }else if (!"false". equals(sec ondary.get Country())  ){
  2167                                               CaretParam .loadModel (actionReq uest, seco ndary, Too lbox.getAd dressColle ction(), C aretStrPoo l.SECONDAR Y_PERSON +  "g_" );                                      
  2168                                      }
  2169                                      CaretLoc alServiceU til.save(  secondary  );
  2170                                      vcgAppli cation.set SecondaryI d(secondar y.getPersn Id());
  2171                                      if ( car egiverId = = 0 ){
  2172                                               caregiverI d = second ary.getPer snId();
  2173                                      }
  2174                             }
  2175  
  2176                             String  secondary TwoFirstNa me = Param Util.get(a ctionReque st, "secon daryTwoPer son_firstN ame", "");
  2177                             if(!se condaryTwo FirstName. equals("") ){                   
  2178                                      Person s econdaryTw o = new Pe rson ( new  PersnImpl () );
  2179                                      CaretPar am.loadMod el(actionR equest, se condaryTwo , secondar yTwo.getMo delAttribu tes().keyS et(), Care tStrPool.S ECONDARY_T WO_PERSON   + StringP ool.UNDERL INE);
  2180                                      if( "fal se".equals (secondary Two.getCou ntry()) ){  //usa add ress
  2181                                               CaretParam .loadModel (actionReq uest, seco ndaryTwo,  Toolbox.ge tAddressCo llection() , CaretStr Pool.SECON DARY_TWO_P ERSON + "u _" );
  2182                                      }else if (!"false". equals(sec ondaryTwo. getCountry ()) ){
  2183                                               CaretParam .loadModel (actionReq uest, seco ndaryTwo,  Toolbox.ge tAddressCo llection() , CaretStr Pool.SECON DARY_TWO_P ERSON + "g _" );
  2184                                      }
  2185                                      CaretLoc alServiceU til.save(  secondaryT wo );
  2186                                      vcgAppli cation.set SecondaryT woId(secon daryTwo.ge tPersnId() );
  2187                                      if ( car egiverId = = 0 ){
  2188                                               caregiverI d = second aryTwo.get PersnId();
  2189                                      }
  2190                             }
  2191  
  2192                             boolea n foreignC ountry = P aramUtil.g etBoolean( actionRequ est, "vete ranPerson_ country");
  2193                             String  groupId =  "";
  2194                             if(for eignCountr y){
  2195                                      groupId  = ParamUti l.get(acti onRequest,  "veteranP ersong_gro upId", "") ;
  2196                             }else{
  2197                                      groupId  = ParamUti l.get(acti onRequest,  "veteranP erson_grou pId", "");
  2198                             }
  2199                             if(!gr oupId.equa ls("")){vc gApplicati on.setGrou pId(Long.p arseLong(g roupId));}
  2200  
  2201                             CaretL ocalServic eUtil.save ( vcgAppli cation );
  2202                             
  2203                             /*
  2204                             if ( a ctionReque st.getPort letSession ().getAttr ibute(Care tStrPool.F ILE_PATH)  != null ){
  2205                                      String p ath = (Str ing) actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.FILE_ PATH);
  2206                                      String n ame = (Str ing) actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.FILE_ NAME);
  2207                                      String t ype = File Type.CSC_1 010.name() ;
  2208                                      handleAp plicationD ocument( a ctionReque st, vcgApp lication,  path, name , type );                              
  2209                                      actionRe quest.getP ortletSess ion().remo veAttribut e(CaretStr Pool.FILE_ PATH);
  2210                                      actionRe quest.getP ortletSess ion().remo veAttribut e(CaretStr Pool.FILE_ NAME);
  2211                             }
  2212                             if ( a ctionReque st.getPort letSession ().getAttr ibute(Care tStrPool.P OA_FILE_PA TH) != nul l ){
  2213                                      String p ath = (Str ing) actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.POA_F ILE_PATH);
  2214                                      String n ame = (Str ing) actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.POA_F ILE_NAME);
  2215                                      String t ype = File Type.CSC_P OA.name();
  2216                                      handleAp plicationD ocument( a ctionReque st, vcgApp lication,  path, name , type );                              
  2217                                      actionRe quest.getP ortletSess ion().remo veAttribut e(CaretStr Pool.POA_F ILE_PATH);
  2218                                      actionRe quest.getP ortletSess ion().remo veAttribut e(CaretStr Pool.POA_F ILE_NAME);
  2219                             }
  2220                             */
  2221                             
  2222                             if ( a ctionReque st.getPort letSession ().getAttr ibute(Care tStrPool.F ILE_PATH)  != null ){
  2223                                      String p ath = (Str ing) actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.FILE_ PATH);
  2224                                      String n ame = (Str ing) actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.FILE_ NAME);
  2225                                      //String  type = Fi leType.CSC _1010.name ();
  2226                                      Attachme ntBean att achment =  new Attach mentBean() ;
  2227                                      attachme nt.setClas sPk(vcgApp lication.g etVcgAnId( ));
  2228                                      attachme nt.setClas sId(Portal Util.getCl assNameId( VcgAn.clas s));
  2229                                      attachme nt.setPath (path);
  2230                                      attachme nt.setName (name);
  2231                                      attachme nt.setType (FileType. CSC_1010.n ame());
  2232                                      //handle Applicatio nDocument(  actionReq uest, vcgA pplication , path, na me, type ) ;
  2233                                      handleAp plicationD ocument( a ctionReque st, attach ment);
  2234                                      actionRe quest.getP ortletSess ion().remo veAttribut e(CaretStr Pool.FILE_ PATH);
  2235                                      actionRe quest.getP ortletSess ion().remo veAttribut e(CaretStr Pool.FILE_ NAME);
  2236                             }
  2237                             if ( a ctionReque st.getPort letSession ().getAttr ibute(Care tStrPool.P OA_FILE_PA TH) != nul l ){
  2238                                      String p ath = (Str ing) actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.POA_F ILE_PATH);
  2239                                      String n ame = (Str ing) actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.POA_F ILE_NAME);
  2240                                      //String  type = Fi leType.CSC _POA.name( );
  2241                                      Attachme ntBean att achment =  new Attach mentBean() ;
  2242                                      attachme nt.setClas sPk(vcgApp lication.g etVcgAnId( ));
  2243                                      attachme nt.setClas sId(Portal Util.getCl assNameId( VcgAn.clas s));
  2244                                      attachme nt.setPath (path);
  2245                                      attachme nt.setName (name);
  2246                                      attachme nt.setType (FileType. CSC_POA.na me());
  2247                                      //handle Applicatio nDocument(  actionReq uest, vcgA pplication , path, na me, type ) ;
  2248                                      handleAp plicationD ocument( a ctionReque st, attach ment);
  2249                                      actionRe quest.getP ortletSess ion().remo veAttribut e(CaretStr Pool.POA_F ILE_PATH);
  2250                                      actionRe quest.getP ortletSess ion().remo veAttribut e(CaretStr Pool.POA_F ILE_NAME);
  2251                             }
  2252                             
  2253                             CaretL ocalServic eUtil.save ( Toolbox. createWork Item( sc,  vcgApplica tion.getGr oupId(), v cgApplicat ion, WorkT ype.CSC_AP P, vcgAppl ication.ge tVeteranId (), caregi verId ));
  2254                                                       
  2255                    } ca tch (Syste mException  e1) {
  2256                             Applic ationWorkF lowExcepti on.handleE xception(e 1);
  2257                    } ca tch (Appli cationWork FlowExcept ion e) {
  2258                             Applic ationWorkF lowExcepti on.handleE xception(e );
  2259                    } ca tch (FileN otFoundExc eption e)  {
  2260                             Applic ationWorkF lowExcepti on.handleE xception(e );
  2261                    } 
  2262           }
  2263           
  2264   //      pu blic void  handleAppl icationDoc ument ( Po rtletReque st request , VcgAn vc gApplicati on, String  path, Str ing name,  String typ e) throws  FileNotFou ndExceptio n, SystemE xception {
  2265           pu blic void  handleAppl icationDoc ument ( Po rtletReque st request , Attachme ntBean att achment) t hrows File NotFoundEx ception, S ystemExcep tion {
  2266                    
  2267                    //Fi le uploadF ile = new  File(path) ;
  2268                    File  uploadFil e = new Fi le(attachm ent.getPat h());
  2269                    Inpu tStream in putStream  = new File InputStrea m( uploadF ile );
  2270                    Outp utBlob out putBlob =  new Output Blob ( inp utStream,  uploadFile .length()  );
  2271                    
  2272                    long  documId =  CounterLo calService Util.incre ment( Docu m.class.ge tName() );
  2273                    Docu m document  = DocumLo calService Util.creat eDocum(doc umId);
  2274                    docu ment.setDo cument(out putBlob);
  2275                    docu ment.setDe leted(fals e);
  2276                    //do cument.set ClassPk( v cgApplicat ion.getVcg AnId() );
  2277                    //do cument.set ClassId( P ortalUtil. getClassNa meId(VcgAn .class) );
  2278                    docu ment.setCl assPk( att achment.ge tClassPk()  );
  2279                    docu ment.setCl assId( att achment.ge tClassId()  );
  2280                    docu ment.setTy pe(attachm ent.getTyp e());
  2281                    docu ment.setNa me(attachm ent.getNam e());
  2282                    try  {
  2283                             DocumL ocalServic eUtil.addD ocum( docu ment );
  2284                             reques t.getPortl etSession( ).removeAt tribute(Ca retStrPool .FILE_NAME );
  2285                             FileUt il.delete( uploadFile );
  2286                    }
  2287                    catc h (Excepti on e) {
  2288                             Applic ationWorkF lowExcepti on.handleE xception(e );
  2289                    }
  2290           }
  2291           
  2292           @P rocessActi on (name=" searchEntr y")
  2293           pu blic void  searchEntr y( ActionR equest act ionRequest , ActionRe sponse act ionRespons e ) {
  2294                    sear chEntry(ac tionReques t);
  2295           }
  2296  
  2297           pu blic void  loadCallTy pe(Portlet Request re quest) thr ows Applic ationWorkF lowExcepti on {
  2298                    
  2299                    Map< String,Obj ect> form  = ResultMa p.getForm  (request);
  2300                    
  2301                    Stri ng callTyp e = Portle tProps.get ("call.typ e");
  2302                    if (  !callType .isEmpty()  ){
  2303                             String [] array =  (callType  + StringP ool.COMMA  + "soc-cal l").split( StringPool .COMMA) ;
  2304                             List<S tring> c =  ListUtil. fromArray( array);
  2305                             Collec tions.sort (c);
  2306                             form.p ut( "stand ard-call-t ypes", c ) ;
  2307                    }
  2308                    form .put( Care tStrPool.C USTOM_CALL _TYPES, Bo xGpLocalSe rviceUtil. getBoxGrou ps(CaretSt rPool.CUST OM_CALL_TY PES) );
  2309                    Dash boardConfi gFactory.l oadInstanc e( request , null );
  2310           }
  2311           
  2312           pu blic void  loadCall(P ortletRequ est reques t) throws  Applicatio nWorkFlowE xception {
  2313                    requ est.setAtt ribute( Ca retStrPool .TRACKER,  CaretParam .trackNdx(  request )  );
  2314                    
  2315                    Stri ng service Status = P ortletProp s.get("vet eran.suppl emental.se rviceStatu ses");
  2316                    if (  !serviceS tatus.isEm pty() ){
  2317                             reques t.setAttri bute("serv iceStatus" , serviceS tatus.spli t(StringPo ol.COMMA)  );
  2318                    }
  2319                    
  2320                    Map< String,Obj ect> form  = ResultMa p.getForm  (request);
  2321                    Map< String,Obj ect> caret  = ResultM ap.getCare tMap(reque st);
  2322                    
  2323                    Map< String,Int eger> tota l = Result Map.getRes ultTotalMa p( request  );
  2324                    Map< String,Lis t<?>> resu lts = Resu ltMap.getR esultListM ap( reques t );
  2325                    bool ean newIns tance = Ca retStrPool .NEW.equal s( request .getParame ter(CaretS trPool.STA TUS) ) ;
  2326                    
  2327                    long  veteranId  = 0;
  2328                    
  2329                    try  {
  2330                             long c allId = Pa ramUtil.ge tLong(requ est, Caret StrPool.CA LL_ID, 0 ) ;
  2331                             CaretV iewControl ler contro ller = Car etViewCont roller.get ViewContro ller();
  2332                             if ( c allId > 0  ){
  2333                                      Call cal l = CallLo calService Util.getCa ll( callId  );
  2334                                      if ( new Instance )  {
  2335                                               call.setCa llId(0);
  2336                                               call.setWo rkPrimaryK ey(0);
  2337                                      }
  2338                                      form.put ( "call",  call );
  2339                                      
  2340                                      Person c aller = ne w Person(P ersnLocalS erviceUtil .getPersn(  call.getC allerPersn Id() ));
  2341                                      form.put (CaretStrP ool.CALLER _PERSN, ca ller );
  2342                                      controll er.loadAdd ress( care t, caller,  CaretStrP ool.CALLER _PERSN );
  2343                                      
  2344                                      if ( !ne wInstance  ){
  2345                                               //Start SO C
  2346                                               String cal lerName =  caller.get FirstName( ) +" "+cal ler.getLas tName();
  2347                                               form.put(" callerName ", callerN ame);
  2348           
  2349                                               loadSocAsp ects(reque st, form,  call, call Id);
  2350                                               //End SOC
  2351                                              
  2352                                               //Start CE SP
  2353                                               loadCespAs pects(requ est, form,  call, cal lId);
  2354                                               //End CESP
  2355                                      }
  2356                                      
  2357                                      veteranI d = call.g etVeteranP ersnId();
  2358                                      Person p erson = ne w Person(  PersnLocal ServiceUti l.getPersn ( veteranI d ) );
  2359                                      form.put (CaretStrP ool.VETERA N_PERSN, p erson );
  2360                                      controll er.loadAdd ress( care t, person,  CaretStrP ool.VETERA N_PERSN );
  2361                             
  2362                                      boolean  enableSoc  = !newInst ance && ca ll.getCrea tionDate() .before( C aretParam. getSocDueD ate() );
  2363                                      request. setAttribu te("enable Soc", enab leSoc );
  2364                                      //reques t.setAttri bute("expa nded", ena bleSoc? "c ollapsed":  "expanded " );
  2365                                      request. setAttribu te("expand ed", "expa nded");
  2366  
  2367                                      List<?>  l = CaretL ocalServic eUtil.getC allEvents(  callId );
  2368                                      results. put("callE vents", l) ;
  2369                                      total.pu t("callEve nts", l.si ze());
  2370  
  2371   //                                 request. setAttribu te("isDisa bled", cal l.getCallS tate() !=  null && ca ll.getCall State().to LowerCase( ).contains (CaretStrP ool.CALL_S TATE_COMPL ETE) );
  2372                                      request. setAttribu te("isDisa bled", cal l.getCallI d() > 0);
  2373                                      
  2374                                      if ( cal l.getWorkP rimaryKey( ) > 0 ){
  2375                                               WorIm work Item = Wor ImLocalSer viceUtil.g etWorIm( c all.getWor kPrimaryKe y() );
  2376                                               form.put(" workItem",  workItem  );
  2377                                               if ( workI tem != nul l && ( wor kItem.getU serId() >  0 || workI tem.getCom pletionBy( ) > 0 ) ){
  2378                                                       re quest.setA ttribute(" isDisabled ", true);
  2379                                                       if  ( workIte m.getStatu s() != nul l ){
  2380                                                                if (  ! workIte m.getStatu s().toLowe rCase().co ntains("co mpleted")  ){
  2381                                                                         reques t.setAttri bute("disp ositionCal l", CActio n.canDoCar et(request , CaretCan .DISPOSITI ON_CALLS.n ame() ) );
  2382                                                                }
  2383                                                       }  else {
  2384                                                                requ est.setAtt ribute("di spositionC all", CAct ion.canDoC aret(reque st, CaretC an.DISPOSI TION_CALLS .name() )  );
  2385                                                       }
  2386                                               }
  2387                                      }
  2388                             } else  {
  2389                                      request. setAttribu te("expand ed", "expa nded");
  2390                             }
  2391                             
  2392                             Result Map.getCar etMap(requ est).put(" genderType s", Portle tProps.get ("persn.ge nder.types ").split(S tringPool. COMMA) ) ;
  2393                             loadCa llSelects(  request ) ;
  2394                             loadMo reCallInfo  ( request  );
  2395   //                        loadMo reReferral Info ( req uest, vete ranId );
  2396                             loadSt atesAndFac ilities( r equest );
  2397                             contro ller.loadR equiredInp uts( Caret StrPool.CA LL, form ) ;
  2398                             
  2399                             reques t.setAttri bute(Caret StrPool.RO LE, ((Dash boardConfi g)request. getPortlet Session(). getAttribu te(CaretSt rPool.DASH BOARD_CONF IG)).getRo le() );
  2400                    } ca tch (Excep tion e) {
  2401                             Applic ationWorkF lowExcepti on.handleE xception(e );
  2402                    }
  2403                    
  2404           }
  2405  
  2406           pr ivate void  loadSocAs pects(Port letRequest  request,  Map<String ,Object> f orm, Call  call, long  callId) t hrows Port alExceptio n, SystemE xception {
  2407                    
  2408                    form .put("call Date", Too lbox.forma tDateCprs(  call.getC reationDat e() ) );
  2409                    long  loggedPer snId = Car etParam.ge tPersnId(r equest);
  2410                    Pers on loggedU ser = new  Person ( P ersnLocalS erviceUtil .getPersn(  loggedPer snId ) );
  2411                    form .put("logg edPersnId" , loggedPe rsnId );
  2412                    form .put("logg edUserName ", loggedU ser.getFir stName() + " "+ logge dUser.getL astName()  );
  2413                                      
  2414                    List <ClSoc> so cList = Cl SocLocalSe rviceUtil. findByCall Id(callId) ;
  2415  
  2416                    int  attemptNum  = socList .size()+1;
  2417                    form .put("atte mptNum", a ttemptNum) ;
  2418                    
  2419                    int  numOfSoc =  socList.s ize();
  2420                    form .put("numO fSoc", num OfSoc);
  2421                    
  2422                    
  2423                    if(n umOfSoc >  0){         
  2424                             List<S ocBean> so cHistory =  new Array List<SocBe an>();
  2425                             for(Cl Soc oneSoc  : socList ){
  2426                                      Person c reatedByPe rsn = new  Person ( P ersnLocalS erviceUtil .getPersn(  oneSoc.ge tPersnId()  ) );
  2427                                      String n ame = crea tedByPersn .getFirstN ame()+" "+ createdByP ersn.getLa stName();
  2428  
  2429                                      SocBean  oneBean =  new SocBea n();
  2430                                      oneBean. setSoc(one Soc);
  2431                                      oneBean. setFormatt edCreatedD ate(Toolbo x.formatDa teTimeMeta data(oneSo c.getCreat ionDate()) );
  2432                                      oneBean. setCreated ByName(nam e);
  2433                                      socHisto ry.add(one Bean);         
  2434                             }
  2435                             form.p ut("soc-hi story", so cHistory);
  2436                    }
  2437  
  2438           }
  2439           
  2440           pr ivate void  loadCespA spects(Por tletReques t request,  Map<Strin g,Object>  form, Call  call, lon g callId)  throws Por talExcepti on, System Exception  {
  2441                    
  2442                    long  loggedPer snId = Car etParam.ge tPersnId(r equest);
  2443                    form .put("logg edPersnId" , loggedPe rsnId );
  2444  
  2445                    //ch eck if the re are any  cesp for  the call
  2446                    List <Cesp> ces pList = Ce spLocalSer viceUtil.f indByCallI d(callId);         
  2447                    int  numOfCesp  = cespList .size();
  2448                    form .put("numO fCesp", nu mOfCesp);
  2449                    
  2450                    Stri ng cespSta tus = Stri ngPool.BLA NK;
  2451  
  2452                    if(n umOfCesp >  0){
  2453                             form.p ut("step",  CaretStrP ool.CESP_S TEP2);
  2454                                       
  2455                             List<C espBean> c espHistory  = new Arr ayList<Ces pBean>();
  2456                             for(Ce sp oneCesp  : cespLis t){
  2457                                      Person c reatedByPe rsn = new  Person ( P ersnLocalS erviceUtil .getPersn(  oneCesp.g etCreatedB yPersnId()  ) );
  2458                                      String n ame = crea tedByPersn .getFirstN ame()+" "+ createdByP ersn.getLa stName();
  2459  
  2460                                      CespBean  oneBean =  new CespB ean();
  2461                                      oneBean. setCesp(on eCesp);
  2462                                      oneBean. setFormatt edCreatedD ate(Toolbo x.formatDa teTimeMeta data(oneCe sp.getCrea tionDate() ));
  2463                                      oneBean. setCespCre atedByName (name);
  2464                                      cespHist ory.add(on eBean);        
  2465                                      
  2466                                      if(oneCe sp.getStat us().equal s(CaretStr Pool.CESP_ STATUS_CLO SED)){
  2467                                               cespStatus  = "closed ";
  2468                                      }
  2469                             }
  2470                             form.p ut("cesp-h istory", c espHistory );
  2471                    }els e{
  2472                             form.p ut("step",  CaretStrP ool.CESP_S TEP1);
  2473                    }
  2474  
  2475                    form .put("cesp Status", c espStatus) ;
  2476           }
  2477           
  2478           
  2479           @P rocessActi on (name=" loadEntry" )
  2480           pu blic void  loadEntry(  ActionReq uest actio nRequest,  ActionResp onse actio nResponse  ) {
  2481                    Stri ng entry =  ParamUtil .get(actio nRequest,  "entry", S tringPool. BLANK);
  2482                    _log .info("loa dEntry..."  +  entry  );
  2483   //               acti onResponse .setRender Parameter( CaretStrPo ol.MVC_PAT H, "/jsp/i nternal/"+  action +  ".jsp" );
  2484   //               _log .info("act ion..." +   entry );
  2485                    try{
  2486                             if ( C aretStrPoo l.CREATE_R EFERRAL.eq uals(entry ) ){
  2487                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_REF ERRAL.name () ) ){
  2488                                               loadReferr al(actionR equest);
  2489                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. EDIT_REFER RAL_PAGE);
  2490                                      }
  2491                             } else  if ( "MAN AGE_VCG".e quals(entr y) ){
  2492                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. MANAGE_VCG .name() )  ){
  2493                                               loadVcgMan agement (a ctionReque st, action Response);
  2494                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. VCG_MANAGE MENT_PAGE) ;
  2495                                      }
  2496                             } else  if ( Care tStrPool.C REATE_CALL S.equals(e ntry) ){
  2497                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_CAL LS.name()  ) ){
  2498                                               loadCall ( actionRequ est);
  2499                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. EDIT_CALL_ PAGE);
  2500                                      }
  2501                             } else  if ( "CRE ATE_CALL_T YPE".equal s(entry) ) {
  2502                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_CAL L_TYPE.nam e() ) ){
  2503                                               loadCallTy pe (action Request);
  2504                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. ADD_CALLTY PE_PAGE);
  2505                                      }
  2506                             } else  if ( "soc ".equals(e ntry) ){
  2507                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_SOC .name() )  ){
  2508                                               loadCall ( actionRequ est);
  2509                                               actionRequ est.setAtt ribute("en ableSoc",  true);
  2510                                               actionRequ est.setAtt ribute("is Disabled",  true);
  2511                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. EDIT_CALL_ PAGE);
  2512                                               //                        loadLe tter(actio nRequest);
  2513                                      }
  2514                             } else  if ( "ces p".equals( entry) ){
  2515                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_CES P.name() )  ){
  2516                                               loadCall ( actionRequ est);
  2517                                               actionRequ est.setAtt ribute("en ableCesp",  true);
  2518                                               actionRequ est.setAtt ribute("is Disabled",  true);
  2519                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. EDIT_CALL_ PAGE);
  2520                                               //                        loadLe tter(actio nRequest);
  2521                                      }
  2522                             } else  if ( "cbo pcWork".eq uals(entry ) ){
  2523                                      
  2524                             } else  if ( "CRE ATE_VCG".e quals(entr y) || "SET _GENERAL_C G".equals( entry) ){
  2525                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_VCG .name() )  ){
  2526                                               ResultMap. getForm(ac tionReques t).put("ve teranRequi red", Coll ections.si ngletonMap ("lastTrea tmentPlace ", "hidden -element") );
  2527                                               long veter anId = Par amUtil.get Long(actio nRequest,  CaretStrPo ol.VETERAN _ID );
  2528                                               if ( veter anId > 0 ) {
  2529                                                       Pe rsn person ;
  2530                                                       tr y {
  2531                                                                pers on = Persn LocalServi ceUtil.get Persn(vete ranId);
  2532                                                                Resu ltMap.getF orm(action Request).p ut(CaretSt rPool.LAST NAME, new  Person(per son));
  2533                                                       }  catch (Por talExcepti on e) {
  2534                                                                Appl icationWor kFlowExcep tion.handl eException (e);
  2535                                                       }  catch (Sys temExcepti on e) {
  2536                                                                Appl icationWor kFlowExcep tion.handl eException (e);
  2537                                                       }
  2538                                               }
  2539                                               ResultMap. getForm(ac tionReques t).put("as sociate",  ParamUtil. getBoolean (actionReq uest, "ass ociate"));
  2540                                               if ( Param Util.getLo ng(actionR equest, "w orImId") >  0 ){
  2541                                                       tr y {
  2542                                                                Resu ltMap.getF orm(action Request).p ut("workIt em", 
  2543                                                                                  new Work ItemSuppor t ( WorImL ocalServic eUtil.getW orIm( Para mUtil.getL ong(action Request, " worImId")  ) ) ); 
  2544                                                       }  catch (Por talExcepti on e1) {
  2545                                                                Appl icationWor kFlowExcep tion.handl eException (e1);
  2546                                                       }  catch (Sys temExcepti on e1) {
  2547                                                                Appl icationWor kFlowExcep tion.handl eException (e1);
  2548                                                       }
  2549                                               }
  2550                                               actionRequ est.setAtt ribute( Ca retStrPool .TRACKER,  CaretParam .trackNdx(  actionReq uest ) );
  2551  
  2552                                               Map caret  = ResultMa p.getCaret Map(action Request);
  2553                                               if ( actio nRequest.g etPortletS ession().g etAttribut e(CaretStr Pool.DASHB OARD_CONFI G) instanc eof Facili tyDashboar dConfig )  {
  2554                                                       ca ret.put( C aretStrPoo l.VHA_MEMB ER, Toolbo x.getVhaOr gList( act ionRequest  ) );
  2555                                                       tr y {
  2556                                                                care t.put(Care tStrPool.S TATES, Reg ionService Util.getRe gions( Cou ntryConsta nts.DEFAUL T_COUNTRY_ ID ) );
  2557                                                       }  catch (Sys temExcepti on e) {
  2558                                                                Appl icationWor kFlowExcep tion.handl eException (e);
  2559                                                       }
  2560                                                       ca ret.put( C aretStrPoo l.VHA_ORGT REE, false  );
  2561                                               } else {
  2562                                                       lo adStatesAn dFacilitie s( actionR equest );
  2563                                                       ca ret.put( C aretStrPoo l.VHA_ORGT REE , true  );
  2564                                               }
  2565                                               //TODO: re quired att ributes...
  2566                                              
  2567                                               CaretViewC ontroller. getViewCon troller(). loadRequir edInputs(  CaretStrPo ol.NEW_VCG _VETERAN_F ORM, Resul tMap.getFo rm(actionR equest) )  ;
  2568                                              
  2569                                               caret.put( "genderTyp es", Portl etProps.ge t("persn.g ender.type s").split( StringPool .COMMA) )  ;
  2570                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. CREATE_VCG _PAGE );
  2571                                               //                        loadLe tter(actio nRequest);
  2572                                      }
  2573           //                         loadCbop cWork(acti onRequest) ;
  2574                             } else  if ( "CRE ATE_APPLIC ATIONS".eq uals(entry ) ){
  2575                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_APP LICATIONS. name() ) ) {
  2576                    //                         loadStates AndFacilit ies( actio nRequest ) ;
  2577                                               createEntr y(actionRe quest, act ionRespons e);
  2578                                               long veter anId = Par amUtil.get Long(actio nRequest,  CaretStrPo ol.VETERAN _ID );
  2579                                               if ( veter anId > 0 ) {
  2580                                                       Pe rsn person ;
  2581                                                       tr y {
  2582                                                                pers on = Persn LocalServi ceUtil.get Persn(vete ranId);
  2583                                                                acti onRequest. setAttribu te("defaul tUser", ne w Person(p erson));
  2584                                                       }  catch (Por talExcepti on e) {
  2585                                                                Appl icationWor kFlowExcep tion.handl eException (e);
  2586                                                       }  catch (Sys temExcepti on e) {
  2587                                                                Appl icationWor kFlowExcep tion.handl eException (e);
  2588                                                       }
  2589                                               }
  2590                                      }
  2591                             } else  if ( "PRO CESS_APPLI CATIONS".e quals(entr y) ){
  2592                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. MANAGE_VCG .name() )  ){
  2593                                               loadProces sApplicati on(actionR equest, ac tionRespon se);
  2594                                              
  2595                                      }
  2596                             } else  if ( "INT ERNAL_MESS AGE".equal s(entry) ) {
  2597                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. INTERNAL_M ESSAGE.nam e() ) ){
  2598                                               PMPortlet. render(act ionRequest , actionRe sponse);
  2599                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. INTERNAL_M ESSAGES_PA GE+actionR equest.get Attribute( "targetPat h"));
  2600                                      }
  2601                             }
  2602                    } ca tch (Appli cationWork FlowExcept ion e) {
  2603                             Applic ationWorkF lowExcepti on.handleE xception (  e );
  2604                    }
  2605           }
  2606           
  2607  
  2608  
  2609           pr ivate void  searchEnt ry( Portle tRequest r equest ) {
  2610   //               Map< String, In teger> tot al = Resul tMap.getRe sultTotalM ap( reques t );
  2611   //               Map< String, Li st<?>> res ults = Res ultMap.get ResultList Map(reques t);
  2612                    _log .info("sea rchEntry") ;
  2613           }
  2614           
  2615           @P rocessActi on (name=" saveEntry" )
  2616           pu blic void  saveEntry(  ActionReq uest actio nRequest,  ActionResp onse actio nResponse  ) {
  2617                    Stri ng entry =  ParamUtil .get(actio nRequest,  "entry", S tringPool. BLANK);
  2618  
  2619                    _log .info("sav e entry... " +  entry  );
  2620                    
  2621   ///*             
  2622                    Stri ng tracker  = ParamUt il.getStri ng(actionR equest, Ca retStrPool .TRACKER,  StringPool .BLANK );
  2623                    if (  ! CaretPa ram.isTrac ked( actio nRequest,  tracker, t rue ) ){
  2624                             _log.w arn("TRACK ER BLOCKIN G action.. . ");
  2625                             action Request.se tAttribute (CaretStrP ool.INVALI D_REQUEST,  true);
  2626                             return ;
  2627                    }
  2628   //*/
  2629                    try  {
  2630                             if ( " vcg".equal s(entry) ) {
  2631                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. MANAGE_VCG .name() )  ){
  2632                                               saveVcgEnt ry(actionR equest, ac tionRespon se);
  2633                                      }
  2634                             } else  if ( "CRE ATE_REFERR AL".equals (entry) ){
  2635                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_REF ERRAL.name () ) ){
  2636                                               saveReferr al(actionR equest);
  2637                                      } else i f ( CActio n.canDoCar et(actionR equest, Ca retCan.DIS POSITION_C ALLS.name( ) ) ){
  2638                                               saveCallDi sposition(  actionReq uest, acti onResponse  );
  2639                                      }
  2640                             } else  if ( "CRE ATE_CALLS" .equals(en try) ){
  2641                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_CAL LS.name()  ) ){
  2642                                               saveCall(a ctionReque st);
  2643                                      }
  2644                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. DISPOSITIO N_CALLS.na me() ) ){
  2645                                               saveCallDi sposition(  actionReq uest, acti onResponse  );
  2646                                      }
  2647                             } else  if ( "soc ".equals(e ntry) ){
  2648                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_SOC .name() )  ){
  2649                                               saveSoc(ac tionReques t);
  2650                                      }
  2651                             }else  if("cesp". equals(ent ry)){
  2652                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_CES P.name() )  ){
  2653                                               saveCesp(a ctionReque st);
  2654                                      }
  2655                             }else  if ( "vcgA n".equals( entry) ){
  2656                                      if ( CAc tion.canDo Caret(acti onRequest,  CaretCan. CREATE_APP LICATIONS. name() ) ) {
  2657                                               saveVcgAn( actionRequ est);
  2658                                      }
  2659                             }else  if ( "cscW aiver".equ als(entry)  ){                           
  2660                                      saveCSCW aiver(acti onRequest) ;
  2661                             }
  2662                                                                                  
  2663                    } ca tch (Appli cationWork FlowExcept ion e) {
  2664                             Applic ationWorkF lowExcepti on.handleE xception (  e );
  2665                    }
  2666           }
  2667           
  2668           
  2669  
  2670  
  2671           pr ivate void  saveCallD isposition (ActionReq uest actio nRequest,  ActionResp onse actio nResponse)  {
  2672                    _log .info("sav eCallDispo sition..."   );
  2673                    long  callId =  ParamUtil. getLong(ac tionReques t, "call_p rimaryKey" );
  2674                    if (  callId >  0 ){
  2675                             try {
  2676                                      ServiceC ontext sc  = CaretPar am.setCare tServiceCo ntext(acti onRequest) ;
  2677                                      Call cal l = CallLo calService Util.getCa ll(callId) ;
  2678   //                                 call.set Summary(ac tionReques t.getParam eter(Caret StrPool.WO RK_COMMENT ));
  2679                                      call.set Modificati onDate( sc .getCreate Date() );
  2680                                      String c allState =  actionReq uest.getPa rameter("c all_callSt ate");
  2681                                      call.set CallState(  callState  );
  2682                                      if ( cal lState.con tains("com pleted") ) {
  2683                                               WorkItemSu pport work  = new Wor kItemSuppo rt( WorImL ocalServic eUtil.getW orIm( call .getWorkPr imaryKey()  ) );
  2684                                               if ( work. getVcgId()  > 0 ){
  2685                                                       Vc gSupport v cgSupport  = VcgSuppo rt.getVcgS upport( wo rk.getVcgI d() );
  2686                                                       vc gSupport.s etNote("ca llDisposit ion", acti onRequest. getParamet er(CaretSt rPool.WORK _COMMENT),
  2687                                                                         sc.get UserId(),  sc.getCrea teDate(),  NoteSuppor t.NoteGrou p.REFERRAL .groupId() );
  2688                                                       Ca retLocalSe rviceUtil. save(vcgSu pport);
  2689                                                       wo rk.useNote ("callDisp osition",  vcgSupport .getNote(" callDispos ition") );
  2690                                                       ac tionReques t.setAttri bute( Care tStrPool.V CGID, vcgS upport.get VcgId() );
  2691                                               }
  2692                                               work.setSt atus(WorkS tatus.COMP LETE.name( ));
  2693                                               work.setCo mpletionBy ( sc.getUs erId() );
  2694                                               work.setCo mpletionDa te( sc.get CreateDate () );
  2695                                               CaretLocal ServiceUti l.save(wor k);
  2696                                      }
  2697                                      CaretLoc alServiceU til.save(c all);
  2698                                      
  2699                                      if ( "VC G_MANAGEME NT_PAGE".e quals( Par amUtil.get String( ac tionReques t, "onPage Complete",  StringPoo l.BLANK) )  ){
  2700                                               actionResp onse.setRe nderParame ter(CaretS trPool.MVC _PATH, Car etStrPool. VCG_MANAGE MENT_PAGE) ;
  2701                                               loadVcgMan agement(ac tionReques t, actionR esponse);
  2702                                      }
  2703                                      
  2704                             } catc h (PortalE xception e ) {
  2705                                      Applicat ionWorkFlo wException .handleExc eption(e);
  2706                             } catc h (SystemE xception e ) {
  2707                                      Applicat ionWorkFlo wException .handleExc eption(e);
  2708                             }
  2709                    }
  2710                    
  2711           }
  2712  
  2713  
  2714           pr ivate void  loadCallS elects(Por tletReques t request  ) throws A pplication WorkFlowEx ception{
  2715                    Map< String,Obj ect> form  = ResultMa p.getForm  (request);
  2716                    
  2717                    Stri ng callTyp e = Portle tProps.get ("call.typ e");
  2718                    if (  !callType .isEmpty()  ){
  2719                             form.p ut( "stand ard-call-t ypes", cal lType.spli t(StringPo ol.COMMA)  );
  2720                    }
  2721                    form .put( "cus tom-call-t ypes", Box GpLocalSer viceUtil.g etBoxGroup s("custom- call-types ") );
  2722                    
  2723                    
  2724                    Stri ng callerL earnAbout  = PortletP rops.get(" call.calle rLearnAbou t");
  2725                    if (  !callerLe arnAbout.i sEmpty() ) {
  2726                             reques t.setAttri bute("call erLearnAbo ut", calle rLearnAbou t.split(St ringPool.C OMMA) );
  2727                    }
  2728                    Stri ng callerC aregiverTy pe = Portl etProps.ge t("call.ca llerCaregi verType");
  2729                    if (  !callerCa regiverTyp e.isEmpty( ) ){
  2730                             reques t.setAttri bute("call erCaregive rType", ca llerCaregi verType.sp lit(String Pool.COMMA ) );
  2731                    }
  2732                    
  2733                    load Relationsh ipLists(re quest);
  2734           }
  2735           
  2736           pr ivate void  loadMoreR eferralInf o ( Portle tRequest r equest, lo ng veteran Id ) throw s Applicat ionWorkFlo wException {
  2737                    
  2738                    List <BoxGp> gr oups = Box GpLocalSer viceUtil.g etBoxGroup s(CaretStr Pool.REFER RAL_QUESTI ONAIRE_YN) ;
  2739                    Map< String,Lis t<BoxGp>>  boxGpMap =  new HashM ap<String, List<BoxGp >>();
  2740                    int  i = 0;
  2741                    List <BoxGp> bo xGpList =  new ArrayL ist<BoxGp> (5);
  2742                    for  ( BoxGp bo xGp: group s ){
  2743                             boxGpL ist.add( b oxGp );
  2744                             if ( i  % 2 == 1  ){
  2745                                      boxGpMap .put( boxG p.getBoxSu bGroup(),  boxGpList  );
  2746                                      boxGpLis t = new Ar rayList<Bo xGp>(5);
  2747                             }
  2748                             i++;
  2749                    }
  2750                    
  2751                    Map< String, Ob ject> form  = ResultM ap.getForm (request);
  2752                    form .put( "pre screen-mee ts-pcafc",  Toolbox.l oadBoxGrou p ( "refer ral-questi onaire-yn" , "prescre en-meets-p cafc" ) );
  2753                    form .put( "enr olled-in-v a-health",  Toolbox.l oadBoxGrou p ( "refer ral-questi onaire-yn" , "enrolle d-in-va-he alth" ) );
  2754                    form .put( "dis charged-af ter-911",  Toolbox.lo adBoxGroup  ( "referr al-questio naire-yn",  "discharg ed-after-9 11" ) );
  2755                    form .put( "vet eran-has-s c-conditio n", Toolbo x.loadBoxG roup ( "re ferral-que stionaire- yn", "vete ran-has-sc -condition " ) );
  2756                    
  2757                    Map< Long,Boole an> enable dBxGps =   new CaretM ap<Long,Bo olean>( fa lse );
  2758                    form .put(Caret StrPool.BO X_GROUP, e nabledBxGp s);
  2759                    
  2760                    if (  veteranId  > 0 ){
  2761                             for (  BgAsn bgAs n0: BoxGpL ocalServic eUtil.getB oxGroupAss ociations(  veteranId , true ) )  {
  2762                                      enabledB xGps.put(  bgAsn0.get BoxGpId(),  true );
  2763                             }
  2764                    }                 
  2765                    
  2766                    if (  CAction.c anDoCaret( request, C aretCan.LO D_QA.name( ) ) ){
  2767                             form.p ut( CaretS trPool.HEC _QUESTIONA IRE, Toolb ox.loadBox Group ( Ca retStrPool .HEC_QUEST IONAIRE, C aretStrPoo l.HEC_QUES TIONAIRE )  );
  2768                    }
  2769           }
  2770           
  2771           pr ivate void  loadMoreC allInfo (  PortletReq uest reque st ) throw s Applicat ionWorkFlo wException {
  2772                    
  2773                    Stri ng service Branches =  PortletPr ops.get("c all.servic eBranches" );
  2774                    if (  !serviceB ranches.is Empty() ){
  2775                             reques t.setAttri bute("serv iceBranche s", servic eBranches. split(Stri ngPool.COM MA) );
  2776                    }
  2777                    
  2778                    Stri ng eraServ iceTypes =  PortletPr ops.get("c all.eraSer viceTypes" );
  2779                    if (  !eraServi ceTypes.is Empty() ){
  2780                             reques t.setAttri bute("eraS erviceType s", eraSer viceTypes. split(Stri ngPool.COM MA) );
  2781                    }
  2782                    
  2783                    long  callId =  ParamUtil. getLong(re quest, Car etStrPool. CALL_ID, 0  );
  2784   //               Set< Long> bgAs nSet = new  HashSet<L ong>();
  2785                    
  2786                    Map< Long,Boole an> boxGrp  =  new Ca retMap<Lon g,Boolean> ( false );
  2787                    
  2788                    Map< String, Ob ject> form  = ResultM ap.getForm (request);
  2789                    form .put(Caret StrPool.BO X_GROUP, b oxGrp);
  2790                    
  2791                    if (  callId >  0 ){
  2792                             for (  BgAsn bgAs n0: BoxGpL ocalServic eUtil.getB oxGroupAss ociations(  callId, t rue ) ) {
  2793                                      boxGrp.p ut( bgAsn0 .getBoxGpI d(), true  );
  2794                             }
  2795                    }
  2796                    Resu ltMap.getF orm(reques t);
  2797   //               form .put( subN ame, group s );
  2798                    form .put( "vet eran-prima ry-diagnos is", Toolb ox.loadBox Group ( "v eteran-pri mary-diagn osis", "ve teran-prim ary-diagno sis" ) );
  2799                    form .put( "oth er-primary -diagnosis ", Toolbox .loadBoxGr oup ( "oth er-primary -diagnosis ", "other- primary-di agnosis" )  );
  2800                    form .put( "pub lic-law-11 1-163-reas ons", Tool box.loadBo xGroup ( " public-law -111-163-r easons", " public-law -111-163-r easons") ) ;
  2801                    form .put( "hea rd-from-us ", Toolbox .loadBoxGr oup ( "hea rd-from-us ", "heard- from-us" )  );
  2802  
  2803                    form .put( "pre screen-mee ts-pcafc",  Toolbox.l oadBoxGrou p ( "refer ral-questi onaire-yn" , "prescre en-meets-p cafc" ) );
  2804                    form .put( "enr olled-in-v a-health",  Toolbox.l oadBoxGrou p ( "refer ral-questi onaire-yn" , "enrolle d-in-va-he alth" ) );
  2805                    form .put( "dis charged-af ter-911",  Toolbox.lo adBoxGroup  ( "referr al-questio naire-yn",  "discharg ed-after-9 11" ) );
  2806                    form .put( "vet eran-has-s c-conditio n", Toolbo x.loadBoxG roup ( "re ferral-que stionaire- yn", "vete ran-has-sc -condition " ) );
  2807                    
  2808                    form .put( "sup port-lines -transfer" , Toolbox. loadBoxGro up ( "supp ort-lines" , "support -lines-tra nsfer") );
  2809                    form .put( "sup port-lines -number-pr ovided", T oolbox.loa dBoxGroup  ( "support -lines", " support-li nes-number -provided" ) );
  2810                    form .put( "int erventions -applied-f amily", To olbox.load BoxGroup (  "interven tions-appl ied", "int erventions -applied-f amily") );
  2811                    form .put( "int erventions -applied-c are", Tool box.loadBo xGroup ( " interventi ons-applie d", "inter ventions-a pplied-car e") );
  2812                    form .put( "int erventions -applied-r espite", T oolbox.loa dBoxGroup  ( "interve ntions-app lied", "in tervention s-applied- respite")  );
  2813                    form .put( "int erventions -applied-c ounseling" , Toolbox. loadBoxGro up ( "inte rventions- applied",  "intervent ions-appli ed-counsel ing") );
  2814                    form .put( "int erventions -applied-d irectives" , Toolbox. loadBoxGro up ( "inte rventions- applied",  "intervent ions-appli ed-directi ves") );
  2815                    form .put( "int erventions -applied-o ther", Too lbox.loadB oxGroup (  "intervent ions-appli ed", "inte rventions- applied-ot her") );
  2816                    
  2817                    if (  CAction.c anDoCaret( request, C aretCan.LO D_QA.name( ) ) ){
  2818                             form.p ut( CaretS trPool.HEC _QUESTIONA IRE, Toolb ox.loadBox Group ( Ca retStrPool .HEC_QUEST IONAIRE, C aretStrPoo l.HEC_QUES TIONAIRE )  );
  2819                    }
  2820           }
  2821           
  2822           
  2823           
  2824           pu blic void  loadReferr al(Portlet Request re quest) thr ows Applic ationWorkF lowExcepti on {
  2825                    requ est.setAtt ribute( Ca retStrPool .TRACKER,  CaretParam .trackNdx(  request )  );
  2826  
  2827                    Stri ng service Status = P ortletProp s.get("vet eran.suppl emental.se rviceStatu ses");
  2828                    if (  !serviceS tatus.isEm pty() ){
  2829                             reques t.setAttri bute(Caret StrPool.SE RVICE_STAT US, servic eStatus.sp lit(String Pool.COMMA ) );
  2830                    }
  2831                    Map< String,Obj ect> form  = ResultMa p.getForm(  request ) ;
  2832                    bool ean newIns tance = Ca retStrPool .NEW.equal s( request .getParame ter(CaretS trPool.STA TUS) ) ;
  2833                    try  {
  2834                             CaretV iewControl ler contro ller = Car etViewCont roller.get ViewContro ller();
  2835                             long c allId = Pa ramUtil.ge tLong(requ est, Caret StrPool.CA LL_ID, 0 ) ;
  2836                             long v eteranId =  0;
  2837                             if ( c allId > 0  ){
  2838                                      Map<Stri ng,Object>  caret = R esultMap.g etCaretMap (request);
  2839                                      
  2840                                      Call cal l = CallLo calService Util.getCa ll( callId  );
  2841                                      if ( new Instance )  {
  2842                                               call.setCa llId(0);
  2843                                               call.setWo rkPrimaryK ey(0);
  2844                                      }
  2845                                      form.put ( CaretStr Pool.CALL,  call );
  2846                                      
  2847                                      if ( cal l.getWorkP rimaryKey( ) > 0 ){
  2848                                               WorIm work Item = Wor ImLocalSer viceUtil.g etWorIm( c all.getWor kPrimaryKe y() );
  2849                                               form.put(" workItem",  workItem  );
  2850                                               if ( workI tem != nul l && ( wor kItem.getU serId() >  0 || workI tem.getCom pletionBy( ) > 0 )  ) {
  2851                                                       re quest.setA ttribute(" isDisabled ", true);
  2852                                                       if  ( workIte m.getStatu s() != nul l ){
  2853                                                                if (  ! workIte m.getStatu s().toLowe rCase().co ntains("co mpleted")  ){
  2854                                                                         reques t.setAttri bute("disp ositionCal l", CActio n.canDoCar et(request , CaretCan .DISPOSITI ON_CALLS.n ame() ) );
  2855                                                                }
  2856                                                       }  else {
  2857                                                                requ est.setAtt ribute("di spositionC all", CAct ion.canDoC aret(reque st, CaretC an.DISPOSI TION_CALLS .name() )  );
  2858                                                       }
  2859                                               }
  2860                                      }
  2861                                      
  2862                                      Person p erson = ne w Person(  PersnLocal ServiceUti l.getPersn ( call.get CallerPers nId() ) );
  2863                                      form.put (CaretStrP ool.CALLER _PERSN, pe rson );
  2864                                      controll er.loadAdd ress( care t, person,  CaretStrP ool.CALLER _PERSN );
  2865                                      veteranI d = call.g etVeteranP ersnId();
  2866                                      person =  new Perso n ( PersnL ocalServic eUtil.getP ersn( vete ranId ) );
  2867                                      form.put (CaretStrP ool.VETERA N_PERSN, p erson );
  2868                                      controll er.loadAdd ress( care t, person,  CaretStrP ool.VETERA N_PERSN );
  2869  
  2870   //                                 if ( ( c all.getCal lState() ! = null &&
  2871   //                                                  ca ll.getCall State().to LowerCase( ).contains (CaretStrP ool.CALL_S TATE_COMPL ETE) ) ||                                           
  2872   //                                                  !  CAction.ca nDoCaret(r equest, CA ction.Care tCan.CREAT E_REFERRAL .name() )  ){
  2873   //                                          request.se tAttribute ("isDisabl ed", true) ;
  2874   //                                 }
  2875                                      request. setAttribu te("isDisa bled", !ne wInstance  && call.ge tCallId()  > 0);
  2876                                      
  2877                             }
  2878                             
  2879                             loadCa llSelects(  request ) ;
  2880                             loadMo reReferral Info(reque st, vetera nId );
  2881                             
  2882                             Result Map.getCar etMap(requ est).put(" genderType s", Portle tProps.get ("persn.ge nder.types ").split(S tringPool. COMMA) ) ;
  2883                             
  2884                             loadSt atesAndFac ilities( r equest );
  2885  
  2886                             Dashbo ardConfig  config = ( DashboardC onfig)requ est.getPor tletSessio n().getAtt ribute(Car etStrPool. DASHBOARD_ CONFIG);
  2887                             if ( c onfig != n ull ){
  2888                                      request. setAttribu te(CaretSt rPool.ROLE , config.g etRole() ) ;
  2889                             }
  2890                             contro ller.loadR equiredInp uts( Caret StrPool.RE FFERAL, fo rm );
  2891                             
  2892                             if ( C Action.can DoCaret(re quest, CAc tion.Caret Can.REFERR AL_ATTACHM ENT.name()  ) || CAct ion.canDoC aret(reque st, CActio n.CaretCan .MANAGE_VC G.name() )  ){
  2893                                      if ( !ne wInstance  ) {
  2894                                               List<Docum > supportD ocs = Docu mLocalServ iceUtil.ge tByPrimary Key( callI d );
  2895                                               form.put(" supportDoc s", suppor tDocs );
  2896                                      }
  2897                                      form.put ("hasDocum entAcess",  true);
  2898                             } else  {
  2899                                      form.put ("hasDocum entAcess",  false);
  2900                             }
  2901                             
  2902                    } ca tch (Excep tion e) {
  2903                             throw  new Applic ationWorkF lowExcepti on(e);
  2904                    }
  2905           }
  2906           
  2907           
  2908           pu blic void  takeOwners hip ( Acti onRequest  request, A ctionRespo nse action Response ) {
  2909                    _log .info("tak eOwnership ");
  2910                    
  2911                    long  worImId =  ParamUtil .getLong(r equest, Ca retStrPool .WORK_ID);
  2912                    try  {
  2913                             Servic eContext s c = CaretP aram.setCa retService Context(re quest);
  2914                             WorIm  workItem =  WorImLoca lServiceUt il.getWorI m(worImId) ;
  2915                             workIt em.setUser Id( sc.get UserId() ) ;
  2916   //                        workIt em.setStat us(WorkSta tus.IN_PRO CESS.name( ));
  2917                             CaretL ocalServic eUtil.save (workItem) ;
  2918                             
  2919   //                        update VcgAnStatu s(workItem );
  2920                             
  2921                    } ca tch (Porta lException  e) {
  2922                             Applic ationWorkF lowExcepti on.handleE xception(e );
  2923                    } ca tch (Syste mException  e) {
  2924                             Applic ationWorkF lowExcepti on.handleE xception(e );
  2925                    }
  2926                    
  2927           }
  2928  
  2929           pu blic void  assignTo (  ActionReq uest reque st, Action Response a ctionRespo nse ){
  2930                    
  2931                    long  primKey =  ParamUtil .getLong(r equest, Ca retStrPool .WORK_ID);
  2932                    long  userId =  ParamUtil. getLong(re quest, "fo rm_userNam e");
  2933                    if (  primKey >  0 && user Id > 0 ){
  2934                             try {
  2935                                      WorIm wo rkItem = W orImLocalS erviceUtil .getWorIm( primKey);
  2936                                      workItem .setUserId (userId);
  2937   //                                 workItem .setStatus (WorkStatu s.IN_PROCE SS.name()) ;
  2938                                      ServiceC ontext sc  = CaretPar am.setCare tServiceCo ntext(requ est);
  2939                                      CaretLoc alServiceU til.save(  workItem ) ;
  2940                                      CaretLoc alServiceU til.addNot e( 
  2941                                                       To olbox.crea teNote( 
  2942                                                                         sc.get CreateDate (),
  2943                                                                         workIt em.getWorI mId(),
  2944                                                                         workIt em.getGrou pId(),
  2945                                                                         sc.get UserId(),
  2946                                                                         ParamU til.get(re quest,
  2947                                                                                           CaretStrPo ol.WORK_CO MMENT, Str ingPool.BL ANK ) ) );
  2948  
  2949   //                                 updateVc gAnStatus( workItem);
  2950                                      
  2951                             } catc h (PortalE xception e ) {
  2952                                      Applicat ionWorkFlo wException .handleExc eption(e);
  2953                             } catc h (SystemE xception e ) {
  2954                                      Applicat ionWorkFlo wException .handleExc eption(e);
  2955                             } 
  2956                    }                 
  2957           }
  2958           
  2959           pu blic void  reviewAppD elay ( Act ionRequest  request,  ActionResp onse actio nResponse  ){
  2960                    
  2961                    long  primKey =  ParamUtil .getLong(r equest, Ca retStrPool .WORK_ID);
  2962                    Stri ng workImS tatus = Pa ramUtil.ge t(request,  "worIm_st atus", Str ingPool.BL ANK);
  2963                     if ( primK ey > 0 &&  ! Toolbox. isEmpty(wo rkImStatus ) && CActi on.canDoCa ret(reques t, CAction .CaretCan. CREATE_ DNS  _WAIVER) ) {
  2964                             try {
  2965                                      ServiceC ontext sc  = CaretPar am.setCare tServiceCo ntext(requ est);
  2966  
  2967                                      WorkItem Support wo rkItem = n ew WorkIte mSupport(  WorImLocal ServiceUti l.getWorIm (primKey)  );
  2968                                      workItem .setStatus ( workImSt atus );
  2969  
  2970                                      String n oteAtt = " ReviewNote ";
  2971                                      VcgSuppo rt vcg = V cgSupport. getVcgSupp ort( workI tem.getVcg Id() );
  2972                                      String c omment = P aramUtil.g et(request , CaretStr Pool.WORK_ COMMENT, S tringPool. BLANK );
  2973                                      vcg.setN ote(noteAt t, comment , sc.getUs erId(), sc .getCreate Date(), No teSupport. NoteGroup. APP_DELAY. groupId()) ;
  2974                                      CaretLoc alServiceU til.save(  vcg );
  2975                                      
  2976                                      if ( !wo rkImStatus .equals( C aretStrPoo l.IN_PROCE SS ) ){
  2977                                               workItem.s etCompleti onBy(Porta lUtil.getU serId(requ est) );
  2978                                               workItem.s etCompleti onDate( sc .getCreate Date() );
  2979                                               Waivr waiv er = Waivr LocalServi ceUtil.get Waivr( wor kItem.getQ ueId() );
  2980                                               waiver.set Completion Date( sc.g etCreateDa te() );
  2981                                               waiver.set Adjudicati on( workIm Status );
  2982                                               CaretLocal ServiceUti l.save( wa iver );
  2983                                              
  2984                                               VcgAn vcgA n = vcg.ge tPersonVcg An( workIt em.getCare giverId()  );
  2985                                               WorkItemSu pport work AppDelay =   new Work ItemSuppor t(Toolbox. createWork Item(sc, w orkItem.ge tGroupId() , vcgAn, W orkType.DE LAY_REVIEW ED, workIt em.getPers nId(), wor kItem.getC aregiverId ()));
  2986                                               workAppDel ay.setVcgI d( vcg.get VcgId() );
  2987                                               workAppDel ay.setQueI d( waiver. getUserId( ) );
  2988   //                                          CaretLocal ServiceUti l.save(wor kAppDelay) ;
  2989                                              
  2990                                               workAppDel ay.useNote (noteAtt,  vcg.getNot e(noteAtt) );
  2991                                               CaretLocal ServiceUti l.save(wor kAppDelay) ;
  2992                                      }
  2993                                      workItem .useNote(n oteAtt, vc g.getNote( noteAtt) ) ;
  2994                                      CaretLoc alServiceU til.save(  workItem ) ;
  2995  
  2996                             } catc h (PortalE xception e ) {
  2997                                      Applicat ionWorkFlo wException .handleExc eption(e);
  2998                             } catc h (SystemE xception e ) {
  2999                                      Applicat ionWorkFlo wException .handleExc eption(e);
  3000                             } 
  3001                    }                 
  3002           }
  3003           
  3004           
  3005           
  3006           pu blic void  updateVcgA nStatus (  WorIm work Item ){
  3007                    
  3008                    try{
  3009                             String [] types =  PortletPr ops.get(Ca retStrPool .APP_TYPES ).split(St ringPool.C OMMA);
  3010                             
  3011                             boolea n updateSt atus = fal se;
  3012                             for (S tring appT ype: types ) { 
  3013                                      if(workI tem.getTyp e().equals (appType))
  3014                                      {
  3015                                       updateS tatus = tr ue;
  3016                                 }
  3017                             }
  3018                             
  3019                             if(upd ateStatus)
  3020                             {        
  3021                                      long vcg AnId = wor kItem.getC lassPk();
  3022                                      VcgAn vc gAn = VcgA nLocalServ iceUtil.ge tVcgAn(vcg AnId);
  3023                                      vcgAn.se tStatus(Ap plicationS tatus.IN_R EVIEW.name ());
  3024                                      VcgAnLoc alServiceU til.update VcgAn(vcgA n);
  3025                             }
  3026                             
  3027                    } ca tch (Porta lException  e) {
  3028                             Applic ationWorkF lowExcepti on.handleE xception(e );
  3029                    } ca tch (Syste mException  e) {
  3030                             Applic ationWorkF lowExcepti on.handleE xception(e );
  3031                    }                 
  3032           }
  3033  
  3034           
  3035           pu blic void  facilTrans fer ( Acti onRequest  request, A ctionRespo nse action Response ) {
  3036                    
  3037                    long  primKey =  ParamUtil .getLong(r equest, Ca retStrPool .WORK_ID);
  3038                    long  groupId =  ParamUtil .getLong(r equest, "t ransfer_gr oupId");
  3039                    if (  primKey >  0 && grou pId > 0 ){
  3040                             try {
  3041                                      WorkItem Support wo rkItem = n ew WorkIte mSupport(  WorImLocal ServiceUti l.getWorIm (primKey)  );
  3042                                      workItem .setQueId( groupId);
  3043                                      workItem .setStatus (WorkStatu s.TRANSFER _REQUESTED .name());
  3044                                      ServiceC ontext sc  = CaretPar am.setCare tServiceCo ntext(requ est);
  3045                                      workItem .setNote(" transferRe ason", Par amUtil.get (request,  CaretStrPo ol.WORK_CO MMENT, Str ingPool.BL ANK ),
  3046                                                                                                            sc.g etUserId() , sc.getCr eateDate()  );
  3047                                      CaretLoc alServiceU til.save(  workItem ) ;
  3048                                      
  3049                             } catc h (PortalE xception e ) {
  3050                                      Applicat ionWorkFlo wException .handleExc eption(e);
  3051                             } catc h (SystemE xception e ) {
  3052                                      Applicat ionWorkFlo wException .handleExc eption(e);
  3053                             } 
  3054                    }//a udit log t o contain
  3055                    //re ason for t ransfer an d date tra nsfer acce pted
  3056           }
  3057           
  3058           pu blic void  acceptTran sfer ( Act ionRequest  request,  ActionResp onse actio nResponse  ) throws P ortalExcep tion, Syst emExceptio n{
  3059                    bool ean accept  = ParamUt il.getBool ean(reques t, "transf er");
  3060                    long  worImId =  ParamUtil .getLong(r equest, Ca retStrPool .WORK_ID);
  3061                    if (  worImId >  0 ){
  3062                             Servic eContext s c = CaretP aram.setCa retService Context(re quest);
  3063                             Dashbo ardConfig  config = ( DashboardC onfig) req uest.getPo rtletSessi on().getAt tribute( C aretStrPoo l.DASHBOAR D_CONFIG);
  3064                             WorkIt emSupport  workItem =  new WorkI temSupport ( WorImLoc alServiceU til.getWor Im(worImId ) );
  3065                             if ( a ccept ){
  3066                                      workItem .setGroupI d( workIte m.getQueId () );
  3067                             }
  3068                             if ( W orkType.VC G_TRANSFER .name().eq uals( work Item.getTy pe() ) ){
  3069                                      transfer VcgWorkIte ms( workIt em, accept , config.w orkItemTyp es() );
  3070                                      workItem .setStatus ( WorkStat us.COMPLET E.name() ) ;
  3071                             } else  {
  3072                                      if ( wor kItem.getV cgId() > 0  ){
  3073                                               transferVc gWorkItems ( workItem , accept,  config.wor kItemTypes () );
  3074                                      }
  3075                                      workItem .setStatus ( WorkStat us.IN_PROC ESS.name()  );
  3076                             }
  3077                             Persn  veteran =  PersnLocal ServiceUti l.getPersn ( workItem .getPersnI d() );
  3078                             if ( w orkItem.ge tQueId() ! = veteran. getGroupId () ){
  3079                                      veteran. setGroupId ( workItem .getQueId( ) );
  3080                                      CaretLoc alServiceU til.save(  veteran );
  3081                             }
  3082                             workIt em.setQueI d(0);
  3083                             workIt em.setNote ("transfer Response",  ParamUtil .get(reque st, CaretS trPool.WOR K_COMMENT,  StringPoo l.BLANK ),
  3084                                               sc.getUser Id(), sc.g etCreateDa te() );
  3085                             CaretL ocalServic eUtil.save ( workItem  );
  3086                    }
  3087           }
  3088  
  3089           
  3090           pr ivate void  transferV cgWorkItem s(WorIm wo rkItem, bo olean acce pt, Collec tion<Strin g> workTyp es ) throw s Applicat ionWorkFlo wException  {
  3091                    for  ( WorIm wo rIm : WorI mLocalServ iceUtil.fi ndByVcgId(  workItem. getVcgId()  ) ){
  3092                             if ( w orIm.getWo rImId() ==  workItem. getWorImId () ) conti nue;
  3093                             if ( w orkTypes.c ontains(wo rIm.getTyp e()) && (  worIm.getQ ueId() > 0  || (accep t && worIm .getGroupI d() != wor kItem.getG roupId() )  ) ){
  3094                                      if ( acc ept ){
  3095                                               worIm.setG roupId( wo rkItem.get GroupId()  );
  3096                                               worIm.setU serId(0);
  3097                                      }
  3098                                      worIm.se tQueId( 0  );
  3099                                      CaretLoc alServiceU til.save(  worIm );
  3100                             }
  3101                    }
  3102                    if (  accept &&  workItem. getVcgId()  > 0 ){
  3103                             try {
  3104                                      Vcg vcg  = VcgLocal ServiceUti l.getVcg(  workItem.g etVcgId()  );
  3105                                      vcg.setG roupId( wo rkItem.get GroupId()  );
  3106                                      CaretLoc alServiceU til.save(v cg);
  3107                             } catc h (PortalE xception |  SystemExc eption e)  {
  3108                                      throw ne w Applicat ionWorkFlo wException (e);
  3109                             }
  3110                    }
  3111                    
  3112           }
  3113           
  3114           
  3115  
  3116           @P rocessActi on (name=" createEntr y")
  3117           pu blic void  createEntr y( ActionR equest act ionRequest , ActionRe sponse act ionRespons e ) {
  3118                    Stri ng entry =  ParamUtil .get(actio nRequest,  "entry", S tringPool. BLANK);
  3119                    _log .info("cre ateEntry.. ." +  entr y );
  3120                    
  3121                    acti onRequest. setAttribu te( CaretS trPool.TRA CKER, Care tParam.tra ckNdx( act ionRequest  ) );
  3122                    Resu ltMap.getC aretMap(ac tionReques t).put("ge nderTypes" , PortletP rops.get(" persn.gend er.types") .split(Str ingPool.CO MMA) ) ;
  3123                    load StatesAndF acilities(  actionReq uest );
  3124                    load Relationsh ipLists( a ctionReque st );
  3125                    
  3126                    acti onRequest. setAttribu te("isDisa bled", tru e);
  3127                    
  3128                    Map< String,Obj ect> form  = ResultMa p.getForm  (actionReq uest);
  3129                    Care tViewContr oller cont roller = C aretViewCo ntroller.g etViewCont roller();
  3130                    cont roller.loa dRequiredI nputs( Car etStrPool. VETERAN_PE RSN, form  );
  3131                    cont roller.loa dRequiredI nputs( Car etStrPool. PRIMARY_PE RSN, form  );
  3132                    cont roller.loa dRequiredI nputs( Car etStrPool. SECONDARY_ PERSN, for m );
  3133                    cont roller.loa dRequiredI nputs( Car etStrPool. SECONDARY_ TWO_PERSN,  form );
  3134  
  3135                    try  {
  3136                             String   extensio ns = Strin gUtil.merg e(PrefsPro psUtil.get StringArra y(PropsKey s.DL_FILE_ EXTENSIONS , StringPo ol.COMMA)) ;
  3137                             long m axSize = L ong.parseL ong(PrefsP ropsUtil.g etString(P ropsKeys.D L_FILE_MAX _SIZE)) /  1024;
  3138                             //_log .info("ext ensions =  " + extens ions + ",  maxSize="  + maxSize  );
  3139                             form.p ut("extens ions",  ex tensions ) ;
  3140                             form.p ut("maxSiz e",  maxSi ze );
  3141                    } ca tch (Syste mException  e) {
  3142                             Applic ationWorkF lowExcepti on.handleE xception(e );
  3143                    }
  3144  
  3145                    acti onResponse .setRender Parameter( CaretStrPo ol.MVC_PAT H, CaretSt rPool.CREA TE_APPLICA TION_PAGE) ;
  3146           }
  3147           
  3148           
  3149           pu blic void  loadRelati onshipList s ( Portle tRequest r equest ) {
  3150                    Care tViewContr oller.getV iewControl ler().load Relationsh ipLists(re quest);
  3151           }
  3152           
  3153           @P rocessActi on (name=" uploadFile ")
  3154           pu blic void  uploadFile  ( ActionR equest req uest, Acti onResponse  actionRes ponse ) th rows FileN otFoundExc eption{
  3155                    Uplo adPortletR equest upl oadRequest  = PortalU til.getUpl oadPortlet Request(re quest);
  3156                    
  3157                    Stri ng type =  ParamUtil. get(reques t, "type",  StringPoo l.BLANK);
  3158                    //_l og.info("f ile type i s : "+type );
  3159  
  3160                    
  3161                    long  size = up loadReques t.getSize( "file");
  3162                    //_l og.info("s ize=" + si ze );
  3163                    if (  size == 0  ){
  3164                             _log.i nfo("retur ning since  size is 0 ...");
  3165                             return ;
  3166                    }
  3167  
  3168                    File  uploadFil e = upload Request.ge tFile("fil e");
  3169                    Stri ng tempLoc ation = Pr opsUtil.ge t(CaretStr Pool.FILE_ TEMP_STORE );
  3170                    Stri ng name =  uploadRequ est.getFil eName("fil e");
  3171                    
  3172                    File  file = ne w File(tem pLocation  + name);
  3173                    try  {
  3174                             FileUt il.copyFil e( uploadF ile, file  );
  3175                    } ca tch (IOExc eption e)  {
  3176                             Applic ationWorkF lowExcepti on.handleE xception(e );
  3177                    }
  3178                    
  3179                    //_l og.info("p ath is ...  " + uploa dFile.getP ath() + ",  name=" +  name );
  3180                    //St ring fileP ath = "";
  3181                    //St ring fileN ame = "";
  3182                    if(C aretStrPoo l.TEN_TEN_ CG.equals( type) ){
  3183                             //file Path = Car etStrPool. FILE_PATH;
  3184                             //file Name = Car etStrPool. FILE_NAME;
  3185                             reques t.getPortl etSession( ).setAttri bute(Caret StrPool.FI LE_PATH, f ile.getPat h() );
  3186                             reques t.getPortl etSession( ).setAttri bute(Caret StrPool.FI LE_NAME, n ame);
  3187                    } el se if( Car etStrPool. POA.equals (type) ){
  3188                             //file Path = Car etStrPool. POA_FILE_P ATH;
  3189                             //file Name = Car etStrPool. POA_FILE_N AME;                          
  3190                             reques t.getPortl etSession( ).setAttri bute(Caret StrPool.PO A_FILE_PAT H, file.ge tPath() );
  3191                             reques t.getPortl etSession( ).setAttri bute(Caret StrPool.PO A_FILE_NAM E, name);
  3192                    } el se {
  3193                             reques t.getPortl etSession( ).setAttri bute(Caret StrPool.FI LE_PATH, f ile.getPat h() );
  3194                             reques t.getPortl etSession( ).setAttri bute(Caret StrPool.FI LE_NAME, n ame);
  3195                    }
  3196                    _log .info("pat h is ... "  + file.ge tPath() +  ", name="  + name );
  3197           }
  3198  
  3199  
  3200           
  3201           @P rocessActi on (name=" cscWaiver" )
  3202           pu blic void  cscWaiver(  ActionReq uest actio nRequest,  ActionResp onse actio nResponse  ) {
  3203                    _log .info("csc Waiver.... ");
  3204                    acti onRequest. setAttribu te( CaretS trPool.TRA CKER, Care tParam.tra ckNdx( act ionRequest  ));
  3205                    
  3206                    Stri ng workIte mId = Para mUtil.get( actionRequ est, "work ItemId", S tringPool. BLANK);
  3207                    Stri ng vcgAnId  = ParamUt il.get(act ionRequest , "vcgAnId ", StringP ool.BLANK) ;
  3208                    Stri ng receive dDate = Pa ramUtil.ge t(actionRe quest, "re ceivedDate ", StringP ool.BLANK) ;
  3209                    Stri ng daysPas sed = Para mUtil.get( actionRequ est, "days Passed", S tringPool. BLANK);
  3210                                      
  3211                    Map< String,Obj ect> form  = ResultMa p.getForm  (actionReq uest);
  3212                    form .put("work ItemId", w orkItemId) ;
  3213                    form .put("vcgA nId", vcgA nId);
  3214                    form .put("rece ivedDate",  receivedD ate);
  3215                    form .put("days Passed", d aysPassed) ;
  3216                    
  3217                    try  {
  3218                             long l oggedPersn Id = Caret Param.getP ersnId(act ionRequest );
  3219                             form.p ut("logged PersnId",  loggedPers nId );
  3220                    } ca tch (Appli cationWork FlowExcept ion e) {
  3221                             Applic ationWorkF lowExcepti on.handleE xception(e );
  3222                    }
  3223  
  3224                    acti onResponse .setRender Parameter( CaretStrPo ol.MVC_PAT H, CaretSt rPool.CSC_ WAIVER_PAG E);
  3225           }
  3226  
  3227           
  3228           pu blic void  saveCSCWai ver( Actio nRequest a ctionReque st) throws  Applicati onWorkFlow Exception  {
  3229                    getO utput(acti onRequest) ;
  3230                    
  3231                    try  {
  3232                             Servic eContext s c = CaretP aram.setCa retService Context(ac tionReques t);
  3233                             Waivr  w = new Wa ivrImpl();
  3234                             Waivr  waiver = ( Waivr) Car etParam.lo adModel(ac tionReques t, new Wai vrImpl(),  w.getModel Attributes ().keySet( ), CaretSt rPool.WAIV ER_UNDERLI NE);
  3235                             waiver .setCreati onDate(new  Date());
  3236                             
  3237                             CaretL ocalServic eUtil.save ( waiver ) ;
  3238                                                                                  
  3239                    } ca tch (Appli cationWork FlowExcept ion e) {
  3240                             Applic ationWorkF lowExcepti on.handleE xception(e );
  3241                    } 
  3242           }
  3243  
  3244           @P rocessActi on (name=" messageAct ions")
  3245           pu blic void  messageAct ions( Acti onRequest  actionRequ est, Actio nResponse  actionResp onse ) {
  3246                    Stri ng message Action = P aramUtil.g et(actionR equest, "m essageActi on", Strin gPool.BLAN K);
  3247                    _log .info("mes sageAction s..." +  m essageActi on );
  3248                                      PMPortle t.render(a ctionReque st, action Response);
  3249                                      actionRe sponse.set RenderPara meter(Care tStrPool.M VC_PATH, C aretStrPoo l.INTERNAL _MESSAGES_ PAGE+actio nRequest.g etAttribut e("targetP ath"));
  3250           }
  3251           
  3252           pr ivate stat ic Log _lo g = LogFac toryUtil.g etLog( Car etActionCo mmand.clas s );
  3253   }