Advertisement
dahomee_69

MaintainOHAllowanceSessionEJB

Dec 21st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 400.50 KB | None | 0 0
  1. // -- Java Code Generation Process --
  2. package gosi.business.socialinsurance.occupationalhazards.injury.session;
  3. // Import Statements
  4. import gosi.business.financialaccounting.common.beans.FAConstants;
  5. import gosi.core.util.ServiceLocator;
  6. import gosi.core.util.GOSIDebug;
  7. import javax.ejb.SessionBean;
  8. import java.util.ArrayList;
  9. import javax.ejb.SessionContext;
  10. import javax.ejb.EJBException;
  11. import java.rmi.RemoteException;
  12. import java.sql.Connection;
  13. import java.sql.PreparedStatement;
  14. import java.sql.ResultSet;
  15. import java.sql.Timestamp;
  16. import java.util.ArrayList;
  17. import java.util.Calendar;
  18. import java.util.GregorianCalendar;
  19. import java.util.Date;
  20. import java.util.HashMap;
  21. import java.util.Hashtable;
  22. import java.util.StringTokenizer;
  23. import javax.naming.Context;
  24. import javax.naming.InitialContext;
  25. import java.util.Properties;
  26. import javax.rmi.PortableRemoteObject;
  27. import java.lang.Math;
  28. import gosi.core.util.GOSIException;
  29. import gosi.core.util.GOSIConstants;
  30. import gosi.core.util.GOSIErrorMessages;
  31. import gosi.core.util.GOSIUtilities;
  32. import gosi.core.util.GOSIInstrumentationLog;
  33. import gosi.core.util.GOSIDateUtilities;
  34. import gosi.core.util.GOSIApplicationProperties;
  35. import gosi.core.util.beans.AuditBean;
  36. import gosi.core.workflow.beans.WorkflowParamBean;
  37. import gosi.business.interfaces.beans.OccupationalHazardsInterfaceConstants;
  38. import gosi.business.socialinsurance.common.beans.SITables;
  39. import gosi.rules.socialinsurance.occupationalhazards.beans.OHRuleBean;
  40. import gosi.business.socialinsurance.occupationalhazards.common.beans.OHUtilities;
  41. import gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails;
  42. import gosi.business.socialinsurance.occupationalhazards.injury.beans.VisitBean;
  43. import gosi.business.socialinsurance.occupationalhazards.injury.beans.OHAllowanceBean;
  44. import gosi.business.socialinsurance.occupationalhazards.injury.beans.TreatmentPeriodBean;
  45. import gosi.business.socialinsurance.occupationalhazards.injury.beans.RecEmployerBean;
  46. import gosi.business.socialinsurance.occupationalhazards.injury.beans.RecFromContributorHeaderBean;
  47. import gosi.business.socialinsurance.occupationalhazards.injury.beans.RecalculateBenefitInputBean;
  48. import gosi.business.socialinsurance.occupationalhazards.injury.beans.ResumeBean;
  49. import gosi.business.socialinsurance.occupationalhazards.common.beans.OHServices;
  50. import gosi.business.socialinsurance.occupationalhazards.common.beans.OHConstants;
  51. import gosi.business.socialinsurance.annuities.common.beans.PaymentBankAccountBean;
  52. import gosi.database.socialinsurance.annuities.entity.PaymentBankAccountEntity;
  53. import gosi.database.socialinsurance.annuities.entity.PaymentBankAccountEntityHome;
  54. import gosi.database.socialinsurance.occupationalhazards.injury.entity.OHAllowanceEntity;
  55. import gosi.database.socialinsurance.occupationalhazards.injury.entity.OHAllowanceEntityHome;
  56. import gosi.business.socialinsurance.registration.common.beans.RegistrationConstants;
  57. import gosi.business.socialinsurance.registration.establishment.beans.EstablishmentUtility;
  58. import gosi.business.socialinsurance.registration.establishment.beans.EstablishmentBean;
  59. import gosi.database.socialinsurance.occupationalhazards.injury.entity.RecEmployerEntity;
  60. import gosi.database.socialinsurance.occupationalhazards.injury.entity.RecEmployerEntityHome;
  61. import gosi.database.socialinsurance.occupationalhazards.injury.entity.RecFromContributorEntity;
  62. import gosi.database.socialinsurance.occupationalhazards.injury.entity.RecFromContributorEntityHome;
  63. import gosi.business.socialinsurance.occupationalhazards.injury.beans.CompanionBean;
  64. import gosi.business.socialinsurance.registration.engagement.beans.ContributorUtilities;
  65. import gosi.business.socialinsurance.registration.engagement.beans.ContributorBean;
  66. import gosi.business.socialinsurance.common.beans.PersonBean;
  67. import gosi.business.socialinsurance.common.beans.PersonUtilities;
  68. import gosi.core.util.beans.IndividualContactBean;
  69. import gosi.business.interfaces.beans.CNInterfaceBean;
  70. import gosi.business.interfaces.beans.CNInterfaceDetailBean;
  71. import gosi.business.interfaces.beans.FAInterfaceConstants;
  72. import gosi.business.interfaces.FinanceImplProxy;
  73. import gosi.business.interfaces.FinancialAccountingInterface;
  74. import gosi.business.interfaces.beans.PartyInterfaceBean;
  75. import gosi.database.socialinsurance.occupationalhazards.common.entity.MaintainOHServicesEntityHome;
  76. import gosi.database.socialinsurance.occupationalhazards.common.entity.MaintainOHServicesEntity;
  77. import gosi.database.socialinsurance.occupationalhazards.injury.entity.InjuryEntityHome;
  78. import gosi.database.socialinsurance.occupationalhazards.injury.entity.InjuryEntity;
  79. import gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryBean;
  80. import gosi.core.dms.beans.DMSRequestHeaderBean;
  81. import gosi.core.dms.beans.DMSConstants;
  82. import gosi.core.dms.util.DMSUtilities;
  83. import java.util.Iterator;
  84.  
  85.  
  86. /**
  87.  * @CLASS NAME          : MaintainOHAllowanceSessionEJB
  88.  * @TYPE                : SessionEJB
  89.  * @AUTHOR              : TCS
  90.  * @VERSION             : 1
  91.  * @EXTENDS             : Nil
  92.  * @INFORMATION         : Session EJB object is used to Maintain OH Allowance
  93.  * @IMPLEMENTS          : SessionBean
  94.  * @TABLES REFERRED     : T_ohbenefit, T_injury,T_contributor,T_person,T_establishemnt,
  95.                           T_engagement,T_engagementwagecoverage,T_treatment,T_hospital,
  96.                           T_stopresumeohallowance
  97.  * @LAST MODIFIED BY    :
  98.  * @LAST MODIFIED DATE  :
  99.  * @stereotype SessionBean
  100.  * @homeInterface gosi.business.socialinsurance.occupationalhazards.injury.session.MaintainOHAllowanceSessionHome
  101.  * @remoteInterface gosi.business.socialinsurance.occupationalhazards.injury.session.MaintainOHAllowanceSession
  102.  */
  103. public class MaintainOHAllowanceSessionEJB implements javax.ejb.SessionBean
  104. {
  105.  
  106.     private Connection con=null;
  107.     private SessionContext ctx=null;
  108.  
  109.     /**
  110.     * @METHOD NAME              :   searchInjuryList
  111.     * @INFORMATION              :   This method is to  search Injury List with sin and injurydate
  112.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  113.     * @RETURN                   :   class java.util.ArrayList
  114.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  115.     * @LAST MODIFIED BY         :
  116.     * @LAST MODIFIED DATE       :
  117.     **/
  118.    public ArrayList searchInjuryList(InjuryPopDetails searchBean)
  119.         throws GOSIException
  120.     {
  121.         // get injury with status other than cancelled
  122.         long startTime   = 0;
  123.         long endTime     = 0;
  124.         long elapsedTime = 0;
  125.         startTime = System.currentTimeMillis();
  126.  
  127.  
  128.         PreparedStatement ps = null;
  129.         ResultSet rs = null;
  130.         GOSIDebug.debugMessages("\t\t Start searchInjuryList - MaintainOHAllowanceSessionEJB");    
  131.         String message = "";
  132.         Long socInsNum = searchBean.getSocialInsuranceNumber();
  133.         Timestamp startDate = null;
  134.         Timestamp endDate = null;
  135.         String entFmt = searchBean.getBenefitStartDateEntFmt();
  136.         GOSIDebug.debugMessages("EntFmt:" + entFmt);
  137.         GOSIDebug.debugMessages("SIN:" + socInsNum + "\t startDate:" + startDate);
  138.         String sqlQuery = "";
  139.         ArrayList injuryList = new ArrayList();
  140.         //Query to get injurys which has treatment for the benefit period
  141.         sqlQuery= " select "+
  142.             " INJURYID,   "+
  143.             " SOCINSNUMBER,   "+
  144.             " CONTRIBUTORID,  "+
  145.             " ESTABLISHMENTID,  "+
  146.             " INJURYDATE, "+
  147.             " DATECOMPLICATION, "+
  148.             " INJURYNUMBER,   "+
  149.             " DESCRIPTION,    "+
  150.             " FIELDOFFICECODE, "+
  151.             " INJURYSTATUS, "+
  152.             " EMPLOYERNOTIFYDATE, "+
  153.             " WORKERINTIMATIONDATE, "+
  154.             " WAGESTOPDATE, "+
  155.             " (NVL(WORKDISABILITYDATE,INJURYDATE +1)) MINDISABLITYDATE, "+
  156.             " TREATMENTSTDATE, "+
  157.             " TREATMENTENDDATE " +
  158.             " from "+ SITables.T_INJURY +
  159.             " where SOCINSNUMBER = ? "+
  160.             " and TREATMENTSTDATE  <= ? "+
  161.             " and TREATMENTENDDATE >= ? "+
  162.             " and INJURYSTATUS != ? "+
  163.             " order by INJURYDATE ";
  164.  
  165.        
  166.         try
  167.         {
  168.            Timestamp currentDate = new Timestamp(System.currentTimeMillis());
  169.            startDate = OHUtilities.getGregDate
  170.                 (searchBean.getBenefitStartDateStr(),
  171.                     searchBean.getBenefitStartDateEntFmt());
  172.             GOSIDebug.debugMessages("startDate:" + startDate);
  173.             endDate =  OHUtilities.getGregDate
  174.                 (searchBean.getBenefitEndDateStr(),
  175.                     searchBean.getBenefitEndDateEntFmt());
  176.  
  177.             GOSIDebug.debugMessages("StartDate:" + startDate + " : EndDate:" + endDate + ":");
  178.             // comparing end date with current date
  179.             if(endDate.compareTo(currentDate) > 0)
  180.             {
  181.                 throw new GOSIException( GOSIConstants.SEVERITY_THREE,
  182.                                         GOSIConstants.OCCUPATIONAL_HAZARDS,
  183.                                         this.getClass().toString(),
  184.                                         "searchInjuryList()",null,
  185.                                         "SOI_ERR_4189");
  186.             }
  187.             //comparing startdate with current date
  188.             if(startDate.compareTo(endDate) > 0)
  189.             {
  190.                 throw new GOSIException( GOSIConstants.SEVERITY_THREE,
  191.                                         GOSIConstants.OCCUPATIONAL_HAZARDS,
  192.                                         this.getClass().toString(),
  193.                                         "searchInjuryList()",null,
  194.                                         "SOI_ERR_4190");
  195.             }          
  196.             con = GOSIUtilities.getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  197.             ps = con.prepareStatement(sqlQuery);
  198.             ps.setLong(1,socInsNum.longValue());
  199.             ps.setTimestamp(2,endDate);
  200.             ps.setTimestamp(3,startDate);
  201.             ps.setShort(4,OHConstants.INJ_STS_CANCELLED.shortValue());
  202.            
  203.             GOSIDebug.debugMessages("SqlQuery :"  + sqlQuery + ":");
  204.             GOSIDebug.debugMessages("\t\t Param 1 :" + socInsNum.longValue() + ":");
  205.             GOSIDebug.debugMessages("\t\t Param 2 :" + endDate + ":");
  206.             GOSIDebug.debugMessages("\t\t Param 3 :" + startDate + ":");
  207.             GOSIDebug.debugMessages("\t\t Param 4 :" + OHConstants.INJ_STS_CANCELLED.shortValue() + ":");
  208.             rs = ps.executeQuery();
  209.             while(rs.next())
  210.             {
  211.                 GOSIDebug.debugMessages("SearchInjuryList has records");
  212.                 InjuryPopDetails injuryDetails = new InjuryPopDetails();
  213.                 injuryDetails.setInjuryID(new Long(rs.getLong("INJURYID")));
  214.                 injuryDetails.setSocialInsuranceNumber
  215.                         (new Long(rs.getLong("SOCINSNUMBER")));
  216.                 injuryDetails.setEstablishmentId
  217.                         (new Long(rs.getLong("ESTABLISHMENTID")));
  218.                 injuryDetails.setContributorId
  219.                         (new Long(rs.getLong("CONTRIBUTORID")));
  220.                 injuryDetails.setInjuryDate(rs.getTimestamp("INJURYDATE"));
  221.                 if (OHConstants.HIJRAH.equals(entFmt))
  222.                 {
  223.                     injuryDetails.setInjuryDateStr
  224.                         (GOSIDateUtilities.convertToHijra(
  225.                                 GOSIUtilities.getDateFullString(
  226.                                 injuryDetails.getInjuryDate())));
  227.                 }
  228.                 else
  229.                 {
  230.                     injuryDetails.setInjuryDateStr
  231.                         (GOSIUtilities.getDateFullString(
  232.                             injuryDetails.getInjuryDate()));
  233.                 }
  234.                 if(rs.getObject("DATECOMPLICATION") != null)
  235.                 {
  236.                     injuryDetails.setComplicationDate
  237.                         (rs.getTimestamp("DATECOMPLICATION"));
  238.                 }
  239.                 injuryDetails.setInjuryNumber
  240.                         (new Long(rs.getLong("INJURYNUMBER")));
  241.  
  242.                 GOSIDebug.debugMessages("Injury Number:" + injuryDetails.getInjuryNumber() + ":");
  243.                 injuryDetails.setDescription(rs.getString("DESCRIPTION"));
  244.                 injuryDetails.setFieldOffice
  245.                         (new Short(rs.getShort("FIELDOFFICECODE")));
  246.                 injuryDetails.setInjuryStatus
  247.                     (new Short(rs.getString("INJURYSTATUS")));
  248.                 if(rs.getObject("EMPLOYERNOTIFYDATE")!= null)
  249.                 {
  250.                     injuryDetails.setEmployerNotifyDate
  251.                     (rs.getTimestamp("EMPLOYERNOTIFYDATE"));
  252.                 }
  253.                 if(rs.getObject("WORKERINTIMATIONDATE") != null)
  254.                 {
  255.                     injuryDetails.setWorkerIntimationDate
  256.                     (rs.getTimestamp("WORKERINTIMATIONDATE"));
  257.                 }
  258.                 if(rs.getObject("WAGESTOPDATE") != null)
  259.                 {
  260.                     injuryDetails.setWageStopDate
  261.                     (rs.getTimestamp("WAGESTOPDATE"));
  262.                 }
  263.  
  264.                 if(rs.getObject("TREATMENTSTDATE") != null)
  265.                 {
  266.                     injuryDetails.setTreatmentStartDate
  267.                     (rs.getTimestamp("TREATMENTSTDATE"));
  268.                 }
  269.                 if(rs.getObject("TREATMENTENDDATE") != null)
  270.                 {
  271.                     injuryDetails.setTreatmentEndDate
  272.                     (rs.getTimestamp("TREATMENTENDDATE"));
  273.                 }
  274.                 if(rs.getObject("MINDISABLITYDATE") !=null)
  275.                 {
  276.                     injuryDetails.setWorkDisabilityDate
  277.                         (rs.getTimestamp("MINDISABLITYDATE"));
  278.                 }
  279.                 // setting contributor details
  280.                 injuryDetails = setContributorDetails(injuryDetails);
  281.                 // setting establishment details
  282.                 injuryDetails = setEstablishmentDetails(injuryDetails);
  283.                 injuryDetails.setBenefitStartDateStr
  284.                     (searchBean.getBenefitStartDateStr());
  285.                 injuryDetails.setBenefitEndDateStr
  286.                     (searchBean.getBenefitEndDateStr());
  287.                 injuryDetails.setBenefitStartDate(startDate);
  288.                 injuryDetails.setBenefitEndDate(endDate);
  289.                 injuryDetails.setBenefitStartDateEntFmt(entFmt);
  290.                 injuryDetails.setBenefitEndDateEntFmt(entFmt);
  291.                 GOSIDebug.debugMessages("Pay to SI: " +
  292.                     injuryDetails.getBenefitPayableTo() + ":");
  293.                 injuryList.add(injuryDetails);
  294.                // adding injurydetails to list  for multiple injuryies
  295.             }
  296.             int injuryListSize = injuryList.size();
  297.             if(injuryListSize == 0)
  298.             {
  299.                 throw new GOSIException( GOSIConstants.SEVERITY_FOUR,
  300.                                         GOSIConstants.OCCUPATIONAL_HAZARDS,
  301.                                         this.getClass().toString(),
  302.                                         "searchInjuryList()",null,
  303.                                         "SOI_ERR_4762");
  304.             }
  305.             for(int i=0;i<injuryListSize;i++)
  306.             {
  307.                 InjuryPopDetails injuryDetails =
  308.                     (InjuryPopDetails)injuryList.get(i);
  309.                 GOSIDebug.debugMessages("InjuryNumber:" + injuryDetails.getInjuryNumber() +
  310.                         ": InjuryId:" + injuryDetails.getInjuryID() + ":");
  311.                 if(injuryDetails.getInjuryStatus().equals
  312.                     (OHConstants.INJ_STS_NOTIFIED))
  313.                 {
  314.                     // UnApproved Injury Details found for the
  315.                     // period entered, Please redefine your calculation period
  316.                     // or Approve the Injury record
  317.                     throw new GOSIException( GOSIConstants.SEVERITY_FOUR,
  318.                                         GOSIConstants.OCCUPATIONAL_HAZARDS,
  319.                                         this.getClass().toString(),
  320.                                         "searchInjuryList()",null,
  321.                                         "SOI_ERR_5189");
  322.                 }else
  323.                 {
  324.                     //setting injury date to complication date
  325.                     // if complication date is not null and
  326.                     // the person is having a valid engagement on complication date
  327.                     Timestamp injuryDate = injuryDetails.getInjuryDate();
  328.                     if(injuryDetails.getComplicationDate() != null)
  329.                     {
  330.                         if(injuryDetails.getIsEngagementPresentOnComplicationAndEligibleForOH())
  331.                         {
  332.                             injuryDate = injuryDetails.getComplicationDate();
  333.                         }
  334.                         //setting wage for the injured engagement
  335.                         injuryDetails = setTotalConWage(injuryDate,injuryDetails);
  336.  
  337.                     }else
  338.                     {
  339.                         //setting wage for the injured engagement
  340.                         injuryDetails = setTotalConWage(injuryDate,injuryDetails);
  341.                     }
  342.                 }
  343.             }
  344.             // calculating the total contributory wage
  345.             injuryList = getTotalContributorWage(injuryList);
  346.  
  347.             endTime = System.currentTimeMillis();
  348.             elapsedTime = endTime - startTime;
  349.             GOSIInstrumentationLog.writeInstrumentationToLog(
  350.                     this.getClass().toString(),
  351.                     "searchInjuryList()",
  352.                     elapsedTime);
  353.  
  354.         }
  355.         catch (GOSIException ge)
  356.         {
  357.             throw ge;
  358.         }
  359.         catch(Exception e)
  360.         {
  361.             GOSIDebug.debugMessages("session:searchInjuryList:e:" + e);
  362.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  363.                                         GOSIConstants.SOCIAL_INSURANCE,
  364.                                         this.getClass().toString(),
  365.                                         "searchInjuryList()",e,
  366.                                         "CMN_ERR_1000");
  367.  
  368.         }
  369.         finally
  370.         {
  371.              GOSIUtilities.cleanUp(con, ps, rs);
  372.         }
  373.         GOSIDebug.debugMessages("\t\t End searchInjuryList - MaintainOHAllowanceSessionEJB");
  374.         return injuryList ;
  375.     }
  376.     /**
  377.     * @METHOD NAME              :   setTotalConWage
  378.     * @INFORMATION              :   This method is to  calculate  wage at the time of injury
  379.     * @PARAM                    :   class Timestamp,gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  380.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  381.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  382.     * @LAST MODIFIED BY         :
  383.     * @LAST MODIFIED DATE       :
  384.     **/
  385.  
  386.     private InjuryPopDetails setTotalConWage
  387.         (Timestamp injuryDate,InjuryPopDetails injuryDetails)
  388.             throws GOSIException
  389.     {
  390.         GOSIDebug.debugMessages("\t\t Start setTotalConWage - MaintainOHAllowanceSessionEJB");
  391.         try
  392.         {
  393.             // wage of previous month of injured month or if not employed on the
  394.             // previous month wage as on injured month. Month should
  395.             // be based on employer calender type.
  396.             String calenderType = injuryDetails.getCalendarType();
  397.             String injuryDateStr = OHUtilities.getDateStr(injuryDate,calenderType); //OHConstants.HIJRAH
  398.             int month = OHUtilities.getMonth(injuryDateStr);
  399.             int year = OHUtilities.getYear(injuryDateStr);
  400.             int lastMonth =(month-1);
  401.             int lastYear = year;
  402.             if (lastMonth==0)
  403.             {
  404.                 lastMonth = 12;
  405.                 lastYear = year-1;
  406.             }
  407.             Double wage = new Double("0.00");
  408.             Long engagementId = injuryDetails.getEngagementId();
  409.             Timestamp firstDate = OHUtilities.getGregDate
  410.                 (OHUtilities.getMonthStartDate(lastMonth,lastYear),
  411.                     calenderType);
  412.                 //OHConstants.HIJRAH);
  413.             Timestamp lastDate   = OHUtilities.getGregDate
  414.                 (GOSIDateUtilities.getMonthEndDate(lastMonth,lastYear),
  415.                     calenderType);
  416.                 //OHConstants.HIJRAH);
  417.             GOSIDebug.debugMessages("LastDate:" + lastDate + ":");
  418.             wage = getWageforMonth(engagementId,lastDate);
  419.             if(wage == null)
  420.             {
  421.                 GOSIDebug.debugMessages("FirstWage is null");
  422.                 lastDate = OHUtilities.getGregDate
  423.                     (GOSIDateUtilities.getMonthEndDate(month,year), calenderType);
  424.                 //OHConstants.HIJRAH);
  425.                 GOSIDebug.debugMessages("LastDate:" + lastDate);
  426.                 wage = getWageforMonth(engagementId,lastDate);
  427.             }
  428.             injuryDetails.setTotalConWage(wage);           
  429.             injuryDetails.setInjuredEstablishmentWage(wage);
  430.         }
  431.         catch (GOSIException ge)
  432.         {
  433.             throw ge;
  434.         }
  435.         catch(Exception e)
  436.         {
  437.             GOSIDebug.debugMessages("session:setTotalConWage:e:"+e);
  438.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  439.                                         GOSIConstants.SOCIAL_INSURANCE,
  440.                                         this.getClass().toString(),
  441.                                         "setTotalConWage()",e,
  442.                                         "CMN_ERR_1000");
  443.         }
  444.         GOSIDebug.debugMessages("\t\t End setTotalConWage - MaintainOHAllowanceSessionEJB");
  445.         return injuryDetails;
  446.     }
  447.  
  448.  
  449.     /**
  450.     * @METHOD NAME              :   setContributorDetails
  451.     * @INFORMATION              :   This method is to  set Contributor Details
  452.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  453.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  454.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  455.     * @LAST MODIFIED BY         :
  456.     * @LAST MODIFIED DATE       :
  457.     **/
  458.     private InjuryPopDetails setContributorDetails(InjuryPopDetails injuryBean)
  459.     throws GOSIException
  460.     {
  461.         PreparedStatement ps =null;
  462.         ResultSet rs =null;
  463.         try
  464.         {
  465.             //Query to get the contirbutor details like nationality and name
  466.             //getting merged sin to check for other sin for the same person
  467.             String sqlQuery =" select "+
  468.                 " a.NATIONALITYCODE,b.MERGEDSOCIALINSURANCENUMBER, "+
  469.                 " a.FIRSTNAME, a.SECONDNAME, a.THIRDNAME, a.SURNAME, "+
  470.                 " a.NAMEENGLISH from "+
  471.                 SITables.T_PERSON +" a, "+
  472.                 SITables.T_CONTRIBUTOR +" b "+
  473.                 " where b.CONTRIBUTORID =? and b.PERSONID = a.PERSONID ";
  474.  
  475.             ps = con.prepareStatement(sqlQuery);
  476.             ps.setLong(1,injuryBean.getContributorId().longValue());
  477.             GOSIDebug.debugMessages("SqlQuery:" + sqlQuery + ":");
  478.             GOSIDebug.debugMessages("\t\t Param 1 :" + injuryBean.getContributorId() + ":");
  479.  
  480.             rs = ps.executeQuery();
  481.             if(rs.next())
  482.             {
  483.                 injuryBean.setNationality
  484.                     (new Short(rs.getShort("NATIONALITYCODE")));
  485.                 String name ="";
  486.                 if(rs.getObject("FIRSTNAME")!=null)
  487.                 {
  488.                     name =name+rs.getString("FIRSTNAME");
  489.                 }if(rs.getObject("SECONDNAME")!=null)
  490.                 {
  491.                     name =name+" "+rs.getString("SECONDNAME");
  492.                 }
  493.                 if(rs.getObject("THIRDNAME")!=null)
  494.                 {
  495.                     name =name+" "+rs.getString("THIRDNAME");
  496.                 }if(rs.getObject("SURNAME")!=null)
  497.                 {
  498.                     name =name+" "+rs.getString("SURNAME");
  499.                 }
  500.                 if(rs.getObject("MERGEDSOCIALINSURANCENUMBER")!= null)
  501.                 {
  502.                     injuryBean.setMergedSIN(new Long
  503.                         (rs.getLong("MERGEDSOCIALINSURANCENUMBER")));
  504.                 }
  505.                 injuryBean.setName(name);
  506.                 injuryBean.setContributorNameEnglish
  507.                     (rs.getString("NAMEENGLISH"));
  508.             }
  509.             return injuryBean;
  510.             //returning the injury bean set with the details of contributor
  511.         }
  512.         catch(Exception e)
  513.         {
  514.             GOSIDebug.debugMessages("session:setContributorDetails:e:"+e);
  515.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  516.                                         GOSIConstants.SOCIAL_INSURANCE,
  517.                                         this.getClass().toString(),
  518.                                         "setContributorDetails()",e,
  519.                                         "CMN_ERR_1000");
  520.  
  521.         }
  522.         finally
  523.         {
  524.              GOSIUtilities.cleanUp(ps, rs);
  525.         }
  526.     }
  527.  
  528.     /**
  529.     * @METHOD NAME              :   getWageforMonth
  530.     * @INFORMATION              :   This method is to  get contributor Wage for Month
  531.     * @PARAM                    :   class java.lang.Long,
  532.                                     class java.sql.Timestamp
  533.     * @RETURN                   :   class java.lang.Double
  534.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  535.     * @LAST MODIFIED BY         :
  536.     * @LAST MODIFIED DATE       :
  537.     **/
  538.     private Double getWageforMonth(Long engagementId,Timestamp endDate)
  539.         throws GOSIException
  540.     {
  541.         java.sql.ResultSet rs = null;
  542.         java.sql.PreparedStatement ps = null;
  543.         Double wage = null;
  544.         try
  545.         {
  546.             if(engagementId != null)
  547.             {
  548.                 //Query to get the wage of the contributor on the month
  549.                 // end date who is covered for oh (monthly contributory wage)
  550.                 String sqlQuery=""+
  551.                 " select MONTHLYCONTRIBUTORYWAGE from "+
  552.                 SITables.T_ENGAGEMENTWAGECOVERAGE +" where "+
  553.                 " ENGAGEMENTID = ? and "+
  554.                 " EFFECTIVESTARTDATE <= ? and "+
  555.                 " (EFFECTIVEENDDATE is null or EFFECTIVEENDDATE >= ? ) "+
  556.                 " and STATUS in(?,?,?) "+
  557.                 " and APPROVALSTATUS in(?,?) "+
  558.                 //" and ACTIVEIND = ? "+
  559.                 " and COVERAGE in (?,?,?)";
  560.                 int i = 0;
  561.                 ps = con.prepareStatement(sqlQuery);
  562.                 ps.setLong(++i,engagementId.longValue());
  563.                 ps.setTimestamp(++i,endDate);
  564.                 ps.setTimestamp(++i,endDate);
  565.                 ps.setShort(++i,RegistrationConstants.VALID);
  566.                 ps.setShort(++i,RegistrationConstants.TO_BE_MADE_VALID);
  567.                 ps.setShort(++i,RegistrationConstants.TO_BE_MADE_VALID_WGECHG);
  568.                 ps.setShort(++i,
  569.                     RegistrationConstants.DATA_FINALLY_APPROVED.shortValue());
  570.                 ps.setShort(++i,
  571.                     RegistrationConstants.OLD_UNAPP_STATUS.shortValue());
  572.                 //ps.setByte(7,RegistrationConstants.ACTIVE_WORKER.byteValue());
  573.                 ps.setShort(++i,RegistrationConstants.OH);
  574.                 ps.setShort(++i,RegistrationConstants.OH_ANNUITY);
  575.                 ps.setShort(++i,RegistrationConstants.OH_ANNUITY_UNEMPLOYMENT);
  576.                 //psReg.setShort(2,OHConstants.ENGAGEMENT_STS_ACTIVE);
  577.                 GOSIDebug.debugMessages("Sqlquery :" + sqlQuery + ":");
  578.                 GOSIDebug.debugMessages("\t\t Param 1 :" + engagementId.longValue() + ":");
  579.                 GOSIDebug.debugMessages("\t\t Param 2 :" + endDate + ":");
  580.                 GOSIDebug.debugMessages("\t\t Param 3 :" + endDate + ":");
  581.                 GOSIDebug.debugMessages("\t\t Param 4 :" + RegistrationConstants.VALID + ":");
  582.                 GOSIDebug.debugMessages("\t\t Param 5 :" + RegistrationConstants.TO_BE_MADE_VALID + ":");
  583.                 GOSIDebug.debugMessages("\t\t Param 6 :" + RegistrationConstants.TO_BE_MADE_VALID_WGECHG + ":");
  584.                 GOSIDebug.debugMessages("\t\t Param 7 :" + RegistrationConstants.DATA_FINALLY_APPROVED.shortValue() + ":");
  585.                 GOSIDebug.debugMessages("\t\t Param 8 :" + RegistrationConstants.OLD_UNAPP_STATUS.shortValue() + ":");
  586.                 GOSIDebug.debugMessages("\t\t Param 9 :" + RegistrationConstants.OH + ":");
  587.                 GOSIDebug.debugMessages("\t\t Param 10:" + RegistrationConstants.OH_ANNUITY + ":");
  588.                 GOSIDebug.debugMessages("\t\t Param 11:" + RegistrationConstants.OH_ANNUITY_UNEMPLOYMENT + ":");
  589.  
  590.                 rs = ps.executeQuery();
  591.                 while(rs.next())
  592.                 {
  593.                     if(rs.getObject("MONTHLYCONTRIBUTORYWAGE")!=null)
  594.                     {
  595.                         wage = new Double
  596.                             (rs.getDouble("MONTHLYCONTRIBUTORYWAGE"));
  597.                     }
  598.                 }
  599.                  GOSIDebug.debugMessages("Montyly Wage :" + wage + ":");
  600.             }
  601.             return wage;
  602.         }
  603.         catch(Exception e)
  604.         {
  605.             GOSIDebug.debugMessages("session:getWageforMonth:e:"+e);
  606.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  607.                 GOSIConstants.SOCIAL_INSURANCE,
  608.                 this.getClass().toString(),
  609.                 "getWageforMonth()",e,"CMN_ERR_1000");
  610.         }
  611.         finally
  612.         {
  613.             GOSIUtilities. cleanUp(ps,rs);
  614.         }
  615.     }
  616.  
  617.     /**
  618.     * @METHOD NAME              :   getTotalContributorWage
  619.     * @INFORMATION              :   This method is to  get Total Contributor Wage
  620.     * @PARAM                    :   class java.util.ArrayList
  621.     * @RETURN                   :   class java.util.ArrayList
  622.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  623.     * @LAST MODIFIED BY         :
  624.     * @LAST MODIFIED DATE       :
  625.     **/
  626.     private ArrayList getTotalContributorWage(ArrayList injuryList)
  627.     throws gosi.core.util.GOSIException
  628.     {
  629.         java.sql.ResultSet rs = null;
  630.         java.sql.PreparedStatement ps = null;
  631.         try
  632.         {
  633.             /*
  634.                 calculating total wage =
  635.                 wage of injured establishment +
  636.                 wage of other simultanious engagements (if he is saudi only).
  637.  
  638.                 For NON-Saudi there is no need to combine the wages from multiple
  639.                 engagements.
  640.             */
  641.             double wage = 0.00;
  642.             String calendarType = OHConstants.HIJRAH;
  643.             String sqlQuery =  "";
  644.            
  645.             ArrayList engagementList = new ArrayList();
  646.             for(int i=0;i<injuryList.size();i++)
  647.             {
  648.                 InjuryPopDetails injuryBean =(InjuryPopDetails)injuryList.get(i);
  649.  
  650.                 if(injuryBean.getMergedSIN() != null)
  651.                 {
  652.                     //Query to get list of engagements if the person has more
  653.                     // than one sin
  654.                     sqlQuery = " select eng.ENGAGEMENTID,eng.ESTABLISHMENTID from  T_CONTRIBUTOR con ,"+
  655.                         " T_ENGAGEMENT eng  where "+
  656.                         " eng.CONTRIBUTORID  = con.CONTRIBUTORID "+
  657.                         " and con.MERGEDSOCIALINSURANCENUMBER = ? "+
  658.                         " and eng.JOININGDATE <=? and "+
  659.                         " ( eng.LEAVINGDATE >=? or eng.LEAVINGDATE is null) and "+
  660.                         " eng.ENGAGEMENTSTATUS != ? ";
  661.                 }else
  662.                 {
  663.                     //Query to get list of engagements if the person has only one sin
  664.                     sqlQuery = "select ENGAGEMENTID,ESTABLISHMENTID from T_ENGAGEMENT "+
  665.                     " where CONTRIBUTORID =? and JOININGDATE <=? and "+
  666.                     " ( LEAVINGDATE >=? or LEAVINGDATE is null) and "+
  667.                     " ENGAGEMENTSTATUS != ? ";
  668.                 }
  669.                
  670.                 GOSIDebug.debugMessages("Injury number:" + injuryBean.getInjuryNumber());
  671.  
  672.                 //logic checks if the person has valid engagement on complication date
  673.                 Timestamp injuryDate = injuryBean.getInjuryDate();
  674.                 if(injuryBean.getComplicationDate()!=null)
  675.                 {
  676.                     if(injuryBean.getIsEngagementPresentOnComplicationAndEligibleForOH())
  677.                     {
  678.                         injuryDate = injuryBean.getComplicationDate();
  679.                     }
  680.                 }
  681.                 calendarType = injuryBean.getCalendarType();               
  682.                 ps = con.prepareStatement(sqlQuery);
  683.                 GOSIDebug.debugMessages("SqlQuery:" + sqlQuery + ":");
  684.                 if(injuryBean.getMergedSIN() != null)
  685.                 {
  686.                     ps.setLong(1,(injuryBean.getMergedSIN()).longValue());
  687.                     GOSIDebug.debugMessages("\t\t Param 1 :" + (injuryBean.getMergedSIN()).longValue() + ":");
  688.                 }else
  689.                 {
  690.                     ps.setLong(1,(injuryBean.getContributorId()).longValue());
  691.                     GOSIDebug.debugMessages("\t\t Param 1 :" + (injuryBean.getContributorId()).longValue() + ":");
  692.                 }
  693.                 ps.setTimestamp(2,injuryDate);
  694.                 ps.setTimestamp(3,injuryDate);
  695.                 ps.setShort(4,
  696.                     RegistrationConstants.ENG_JOIN_IN_PROGRESS.shortValue());
  697.                 //ps.setByte(5,RegistrationConstants.ACTIVE_WORKER.byteValue());
  698.                 GOSIDebug.debugMessages("\t\t Param 2 :" + injuryDate + ":");
  699.                 GOSIDebug.debugMessages("\t\t Param 3 :" + injuryDate + ":");
  700.                 GOSIDebug.debugMessages("\t\t Param 4 :" +
  701.                     RegistrationConstants.ENG_JOIN_IN_PROGRESS.shortValue() + ":");
  702.                 rs = ps.executeQuery();
  703.                 while(rs.next())
  704.                 {
  705.                     // this logic adds each unique engagement into the list
  706.                     Long engagementId = new Long(rs.getLong("ENGAGEMENTID"));
  707.                     Long establishmentId = new Long(rs.getLong("ESTABLISHMENTID"));
  708.                     int engagementListSize = engagementList.size();
  709.                     boolean flag = true;
  710.                     for(int j=0;j<engagementListSize;j=j+2)
  711.                     {
  712.                         Long engagementListId = (Long)engagementList.get(j);
  713.                         if(engagementId.equals(engagementListId))
  714.                         {
  715.                             flag = false;
  716.                             break;
  717.                         }
  718.                     }
  719.                     //Dont pay benefits to the Establishmetn that not paying contribution
  720.                     boolean isEstPaycontributions = OHUtilities.isEligibleforOHCoverage(establishmentId,injuryDate);
  721.                    
  722.                     if(flag /* && isEstPaycontributions*/)
  723.                     {
  724.                         GOSIDebug.debugMessages("ENGAGEMENTID:" + engagementId);
  725.                         engagementList.add(engagementId);
  726.                         engagementList.add(injuryDate);
  727.                     }
  728.                 }
  729.             }
  730.             // if the person has more than one injury pay to contriubtor
  731.             // else follow the rule as below
  732.             int injuryListSize = injuryList.size();
  733.             Short payableTo = OHConstants.OH_BNFT_PAY_TO_CON;
  734.             if(engagementList.size() > 2)
  735.             {
  736.                 payableTo = OHConstants.OH_BNFT_PAY_TO_CON;
  737.  
  738.             }else
  739.             {
  740.                 InjuryPopDetails injuryDetailsBean = (InjuryPopDetails)injuryList.get(0);
  741.                 if(OHConstants.OH_BNFT_PAY_TO_EMP.equals
  742.                     (injuryDetailsBean.getBenefitPayableTo())&&
  743.                         null == injuryDetailsBean.getWageStopDate())
  744.                 {
  745.                     payableTo = OHConstants.OH_BNFT_PAY_TO_EMP;
  746.                 }else
  747.                 {
  748.                     payableTo = OHConstants.OH_BNFT_PAY_TO_CON;
  749.                 }
  750.             }
  751.             boolean isContributorSaudi = false;
  752.             for(int j=0;j<injuryList.size();j++)
  753.             {
  754.                 InjuryPopDetails injuryDetailsBean =(InjuryPopDetails)injuryList.get(j);
  755.                 injuryDetailsBean.setBenefitPayableTo(payableTo);
  756.                 GOSIDebug.debugMessages("Injury number:" + injuryDetailsBean.getInjuryNumber());
  757.                 GOSIDebug.debugMessages("Nationality code:" + injuryDetailsBean.getNationality());
  758.                 if(OHConstants.NATIONALITY_CODE_SAUDI.equals(injuryDetailsBean.getNationality()))
  759.                 {
  760.                     isContributorSaudi = true;
  761.                 }
  762.             }
  763.             GOSIDebug.debugMessages("isContributorSaudi:" + isContributorSaudi);
  764.             // if contributor is non saudi calculate the wage only for the
  765.             // the injured engagement
  766.             for(int i=0;i<engagementList.size();i=i+2)
  767.             {
  768.                 Long engagementId =(Long)engagementList.get(i);
  769.                 boolean flag = true;
  770.                 Double tempWage = null;
  771.                 for(int j=0;j<injuryList.size();j++)
  772.                 {
  773.                     InjuryPopDetails injuryDetailsBean =(InjuryPopDetails)injuryList.get(j);
  774.                     if(engagementId.equals(injuryDetailsBean.getEngagementId()))
  775.                     {
  776.                         flag = false;
  777.                         tempWage = injuryDetailsBean.getTotalConWage();
  778.                         break;
  779.                     }
  780.                 }
  781.                 // logic for calculating the wage.
  782.                 if(flag && isContributorSaudi)
  783.                 {
  784.                     //Timestamp injuryDate = ((InjuryPopDetails)injuryList.get(injuryListSize-1)).getInjuryDate();\
  785.                     Timestamp injuryDate =(Timestamp)engagementList.get(i+1);
  786.                     String injuryDateStr = OHUtilities.getDateStr(injuryDate,calendarType);//OHConstants.HIJRAH
  787.                     int month =OHUtilities.getMonth(injuryDateStr);
  788.                     int year =OHUtilities.getYear(injuryDateStr);
  789.                     int lastMonth =(month-1);
  790.                     int lastYear = year;
  791.                     if (lastMonth==0)
  792.                     {
  793.                         lastMonth = 12;
  794.                         lastYear = year-1;
  795.                     }
  796.                     Timestamp endDate   = OHUtilities.getGregDate
  797.                         (GOSIDateUtilities.getMonthEndDate(lastMonth,lastYear),
  798.                             calendarType);//OHConstants.HIJRAH
  799.                     tempWage = getWageforMonth(engagementId,endDate);
  800.                     if(tempWage == null)
  801.                     {
  802.                         endDate   = OHUtilities.getGregDate(GOSIDateUtilities.getMonthEndDate(month,year),calendarType);//OHConstants.HIJRAH
  803.                         tempWage = getWageforMonth(engagementId,endDate);
  804.                     }
  805.                 }
  806.                 GOSIDebug.debugMessages("EstablishmentId:" + engagementId.longValue() + ":Wage:" + tempWage+ ":");
  807.                 if(tempWage != null)
  808.                 {
  809.                     wage = wage + tempWage.doubleValue();
  810.                 }
  811.             }
  812.             // setting the total contributor wage on all beans on list
  813.             for(int j=0;j<injuryList.size();j++)
  814.             {
  815.                 InjuryPopDetails injuryDetailsBean =(InjuryPopDetails)injuryList.get(j);
  816.                 injuryDetailsBean.setTotalConWage(new Double(wage));
  817.                 GOSIDebug.debugMessages("InjuryNumber:"+injuryDetailsBean.getInjuryNumber());
  818.  
  819.             }
  820.             return injuryList;
  821.             //returning the list
  822.         }
  823.         catch(GOSIException ge)
  824.         {
  825.             GOSIDebug.debugMessages("Session:getTotalContibutorWage :ge:"+ge);
  826.             throw ge;
  827.         }
  828.         catch(Exception e)
  829.         {
  830.             GOSIDebug.debugMessages("session:getTotalContibutorWage :e:"+e);
  831.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  832.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  833.                 "getTotalContibutorWage()",e,"CMN_ERR_1000");
  834.         }
  835.         finally
  836.         {
  837.             GOSIUtilities. cleanUp(ps,rs);
  838.         }
  839.     }
  840.     /**
  841.     * @METHOD NAME              :   checkBenefitPeriod
  842.     * @INFORMATION              :   This method is to  check whether benefit
  843.                                     calculated for the Benefit Period
  844.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  845.     * @RETURN                   :   void
  846.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  847.     * @LAST MODIFIED BY         :
  848.     * @LAST MODIFIED DATE       :
  849.     **/
  850.     public void checkBenefitPeriod(InjuryPopDetails injuryBean)
  851.         throws GOSIException
  852.     {
  853.         long startTime   = 0;
  854.         long endTime     = 0;
  855.         long elapsedTime = 0;
  856.         startTime = System.currentTimeMillis();
  857.  
  858.         PreparedStatement ps = null;
  859.         ResultSet rs = null;
  860.         try
  861.         {
  862.             // this query returns the list of benefits payed for
  863.             // the period, if benefits found throw error
  864.             con = GOSIUtilities.getConnection
  865.                 (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  866.             Timestamp benefitStartDate = injuryBean.getBenefitStartDate();
  867.             Timestamp benefitEndDate = injuryBean.getBenefitEndDate();
  868.             String sqlQuery ="select OHBENID from "+
  869.                             SITables.T_OHBENEFIT +
  870.                 " where BENSTATUS != ? and BENSTDATE <= ? and "+
  871.                 " BENENDDATE >= ? and "+
  872.                 " OHBENCODE in(?,?) and "+
  873.                 " CONTRIBUTORID =  "+
  874.                 " (select CONTRIBUTORID from "+SITables.T_CONTRIBUTOR +
  875.                 " where SOCIALINSURANCENUMBER = ?) ";
  876.             ps= con.prepareStatement(sqlQuery) ;
  877.             ps.setShort(1,OHConstants.OH_BNFT_STS_CANCELLED.shortValue());
  878.             ps.setTimestamp(2,benefitEndDate);
  879.             ps.setTimestamp(3,benefitStartDate);
  880.             ps.setShort(4,OHConstants.OH_ALWNC_DAIlY_INPATIENT.shortValue());
  881.             ps.setShort(5,OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.shortValue());
  882.             ps.setLong(6,injuryBean.getSocialInsuranceNumber().longValue());
  883.  
  884.             GOSIDebug.debugMessages("sqlQuery:" + sqlQuery + ":");
  885.             boolean flag = false;
  886.             rs = ps.executeQuery();
  887.             while (rs.next())
  888.             {
  889.                 flag = true;
  890.             }
  891.             if(flag)
  892.             {
  893.                 //Redefine your Benefit period as the period contains Periods
  894.                 //for which OH Allowance has already been calculated
  895.                 throw new GOSIException(GOSIConstants.SEVERITY_THREE,
  896.                                         GOSIConstants.SOCIAL_INSURANCE,
  897.                                         this.getClass().toString(),
  898.                                         "checkBenefitPeriod()",
  899.                                         null,
  900.                                         "SOI_ERR_5190");
  901.             }
  902.         endTime = System.currentTimeMillis();
  903.         elapsedTime = endTime - startTime;
  904.         GOSIInstrumentationLog.writeInstrumentationToLog(
  905.                 this.getClass().toString(),
  906.                 "checkBenefitPeriod()",
  907.                 elapsedTime);
  908.         }
  909.         catch (GOSIException ge)
  910.         {
  911.             throw ge;
  912.         }
  913.         catch (Exception e)
  914.         {
  915.             GOSIDebug.debugMessages("session:checkBenefitPeriod :e:"+e);
  916.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  917.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  918.                 "checkBenefitPeriod()",e,"CMN_ERR_1000");
  919.         }
  920.         finally
  921.         {
  922.             GOSIUtilities.cleanUp(con,ps,rs);
  923.         }
  924.     }
  925.  
  926.  
  927.     /**
  928.     * @METHOD NAME              :   saveOHAllowance
  929.     * @INFORMATION              :   This method is to  save OH Allowance into the T_ohbenefit table
  930.     * @PARAM                    :   class java.util.ArrayList,
  931.                                     class gosi.core.workflow.beans.WorkflowParamBean,
  932.                                     class java.lang.Long
  933.     * @RETURN                   :   class java.lang.String
  934.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  935.     * @LAST MODIFIED BY         :
  936.     * @LAST MODIFIED DATE       :
  937.     **/
  938.     public String saveOHAllowance(ArrayList benefitList,
  939.         WorkflowParamBean workflowParamBean,Long socInsNum,ArrayList contactList)
  940.             throws GOSIException
  941.     {
  942.         long startTime   = 0;
  943.         long endTime     = 0;
  944.         long elapsedTime = 0;
  945.         startTime = System.currentTimeMillis();
  946.  
  947.         String message = "";
  948.         try
  949.         {
  950.             GOSIDebug.debugMessages(""+OHConstants.OH_ALLOWANCE_ENTITY_JNDI);
  951.             OHAllowanceEntityHome home=(OHAllowanceEntityHome)
  952.                 ServiceLocator.getInstance().getRemoteHome(
  953.                 OHConstants.OH_ALLOWANCE_ENTITY_JNDI,
  954.                 OHAllowanceEntityHome.class);
  955.             Timestamp currentTime=new Timestamp (System.currentTimeMillis());
  956.             Long injuryId=((OHAllowanceBean)benefitList.get(0)).getInjuryId();
  957.             //checking bank details if payable to bank
  958.             boolean isBankDetailsPresent =
  959.                 isBankDetailsPresent(benefitList,socInsNum);
  960.             GOSIDebug.debugMessages("is bank details present:"+isBankDetailsPresent);
  961.             // checking if an autorized person is present
  962.             // if mode is OH_BNFT_PAY_TO_AUTH_PERSON
  963.             for(int i=0;i<benefitList.size();i++)
  964.             {
  965.                 OHAllowanceBean benefitBean=(OHAllowanceBean)benefitList.get(i);
  966.                 if(OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals(benefitBean.getBenefitPayableTo()))
  967.                 {
  968.                     isAuthPersonPresent(benefitBean.getContributorId());
  969.                     break;
  970.                 }
  971.             }
  972.             // validating the contact details of the contributor
  973.             validateContactDetails(contactList,benefitList);
  974.  
  975.             if(isBankDetailsPresent)
  976.             {
  977.                 //inserting benefit details into the T_ohbenefit table
  978.                 for(int i=0;i<benefitList.size();i++)
  979.                 {
  980.                     OHAllowanceBean benefitBean=(OHAllowanceBean)benefitList.get(i);
  981.                     benefitBean.setCreationTimestamp(currentTime);
  982.                     benefitBean.setOhBenId(GOSIUtilities.getPrimaryKey
  983.                         ("T_OHBENEFIT",benefitBean.getCreatedBy()));
  984.                     OHAllowanceEntity remoteEntity=(OHAllowanceEntity)home.create(benefitBean);
  985.                     GOSIDebug.debugMessages("After calling entity:"+remoteEntity);
  986.                 }
  987.                 //calling the workflow interface
  988.                 if(workflowParamBean!=null)
  989.                 {
  990.                     GOSIDebug.debugMessages("workflowParamBean :"+workflowParamBean);
  991.                     workflowParamBean.setrecordDescription(
  992.                         workflowParamBean.getrecordDescription()+" - "+socInsNum);
  993.                     String userName = GOSIUtilities.startWorkflow(workflowParamBean);
  994.                     GOSIDebug.debugMessages("user :"+userName);
  995.                     message = GOSIErrorMessages.getErrorDesc("SOI_ERR_5194")+
  996.                         " "+userName;
  997.                 }
  998.             }else
  999.             {
  1000.                 //Please enter contributor bank details before saving
  1001.                 throw new GOSIException(GOSIConstants.SEVERITY_THREE,
  1002.                     GOSIConstants.SOCIAL_INSURANCE,
  1003.                     this.getClass().toString(),
  1004.                     "saveOHAllowance()",null,"SOI_ERR_4541");
  1005.             }
  1006.             endTime = System.currentTimeMillis();
  1007.             elapsedTime = endTime - startTime;
  1008.             GOSIInstrumentationLog.writeInstrumentationToLog(
  1009.                 this.getClass().toString(),
  1010.                 "saveOHAllowance()",
  1011.                 elapsedTime);
  1012.  
  1013.             return message;
  1014.         }
  1015.         catch(GOSIException gosiException)
  1016.         {
  1017.                 GOSIDebug.debugMessages("session:save:ge:message:"+gosiException.getMessage());
  1018.                 ctx.setRollbackOnly();
  1019.                 throw gosiException;
  1020.         }
  1021.         catch(Exception e)
  1022.         {
  1023.             GOSIDebug.debugMessages("session:save: :The exception is "+e);
  1024.             ctx.setRollbackOnly();
  1025.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  1026.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  1027.                 "saveOHAllowance()",e,"CMN_ERR_1000");
  1028.         }
  1029.  
  1030.     }
  1031.  
  1032.     /**
  1033.     * @METHOD NAME              :   isAuthPersonPresent
  1034.     * @INFORMATION              :   This method is to  is check if Authorized Person Present or not
  1035.     * @PARAM                    :   class java.lang.Long
  1036.     * @RETURN                   :   boolean
  1037.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  1038.     * @LAST MODIFIED BY         :
  1039.     * @LAST MODIFIED DATE       :
  1040.     **/
  1041.     private boolean isAuthPersonPresent(Long contributorId)
  1042.         throws GOSIException
  1043.     {
  1044.  
  1045.         PreparedStatement ps = null;
  1046.         ResultSet rs = null;
  1047.         String payeeName = null;
  1048.         boolean isAuthPersonPresent = false;
  1049.         try
  1050.         {
  1051.             //Query to get the authorized person for a contributor
  1052.             String sqlQuery = " select AUTHORIZEDPERSONID from "+
  1053.                 SITables.T_OHAUTHORIZEDPERSON +
  1054.                 " where CONTRIBUTORID =? and STATUS = ? ";
  1055.             con = GOSIUtilities.getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  1056.             ps = con.prepareStatement(sqlQuery);
  1057.             ps.setLong(1,contributorId.longValue());
  1058.             ps.setShort(2,OHConstants.AUTHORIZED_PERSON_STATUS_ACTIVE.shortValue());
  1059.             rs = ps.executeQuery();
  1060.             if(rs.next())
  1061.             {
  1062.                 isAuthPersonPresent = true;
  1063.             }
  1064.             // if authorized person is present return true else
  1065.             // throw error
  1066.             if(!isAuthPersonPresent)
  1067.             {
  1068.                 throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  1069.                 GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  1070.                 "isAuthPersonPresent()",null,"SOI_ERR_5507");
  1071.             }
  1072.             return isAuthPersonPresent;
  1073.         }
  1074.         catch (GOSIException ge)
  1075.         {
  1076.             throw ge;
  1077.         }
  1078.         catch(Exception se)
  1079.         {
  1080.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  1081.             GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  1082.             "isAuthPersonPresent()",se,"CMN_ERR_1000");
  1083.         }
  1084.         finally
  1085.         {
  1086.             GOSIUtilities.cleanUp(con,ps,rs);
  1087.         }
  1088.     }
  1089.  
  1090.  
  1091.  
  1092.  
  1093.     /**
  1094.     * @METHOD NAME              :   modifyOHAllowance
  1095.     * @INFORMATION              :   This method is to  modify OH Allowance
  1096.     * @PARAM                    :   class java.util.ArrayList,
  1097.                                     class java.util.ArrayList,
  1098.                                     class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails,
  1099.                                     class gosi.core.workflow.beans.WorkflowParamBean,
  1100.                                     class java.lang.String,
  1101.                                     boolean,
  1102.                                     class gosi.core.dms.beans.DMSRequestHeaderBean
  1103.     * @RETURN                   :   class java.lang.String
  1104.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  1105.     * @LAST MODIFIED BY         :
  1106.     * @LAST MODIFIED DATE       :
  1107.     **/
  1108.     public String modifyOHAllowance
  1109.         (ArrayList benefitList,ArrayList contactList,InjuryPopDetails injuryBean,
  1110.             WorkflowParamBean workflowParamBean,String mode,boolean canSendForWorkflow,DMSRequestHeaderBean headerBean)
  1111.             throws GOSIException
  1112.     {
  1113.         long startTime   = 0;
  1114.         long endTime     = 0;
  1115.         long elapsedTime = 0;
  1116.         startTime = System.currentTimeMillis();
  1117.  
  1118.         String message = GOSIErrorMessages.getErrorDesc("SOI_ERR_4192");
  1119.         try
  1120.         {
  1121.             // This method updates, deletes the records in the oh benefit table
  1122.             // updates the status during the workflow and
  1123.             // deletes the records if benefit is cancelled
  1124.             Short breakUpType = null;
  1125.  
  1126.             FinancialAccountingInterface faInterface;
  1127.             faInterface = FinanceImplProxy.getFAInterface();
  1128.  
  1129.             Long userId = new Long (workflowParamBean.getUserId());
  1130.             Long workflowId = ((OHAllowanceBean)benefitList.get(0)).
  1131.                 getWorkflowId();
  1132.  
  1133.             Short fieldOffice = injuryBean.getFieldOffice();
  1134.  
  1135.             OHAllowanceEntityHome home=(OHAllowanceEntityHome)
  1136.                 ServiceLocator.getInstance().getRemoteHome(
  1137.                 OHConstants.OH_ALLOWANCE_ENTITY_JNDI,
  1138.                 OHAllowanceEntityHome.class);
  1139.             Timestamp currentTime=new Timestamp (System.currentTimeMillis());
  1140.             // method to trow error if it reaches the inbox of
  1141.             // interior audit manager, double check done for change of workflow
  1142.             if(OHConstants.APPROVE_INT_AUD_HEAD.equals(mode)&&
  1143.                 GOSIConstants.COMPLETED.equals
  1144.                     (workflowParamBean.getRoutingCriterion()))
  1145.             {
  1146.                 throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  1147.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  1148.                 "modifyOHAllowance()",null,"CMN_ERR_1000");
  1149.             }
  1150.             // This is the final approval where the status is
  1151.             // updated as approved and the finance interface called
  1152.             if(OHConstants.APPROVE_INT_AUD_CLK.equals(mode)&&
  1153.                 GOSIConstants.COMPLETED.equals
  1154.                     (workflowParamBean.getRoutingCriterion()))
  1155.             {
  1156.                 GOSIDebug.debugMessages("calling interface");
  1157.                 //Interface with finance
  1158.                 OHAllowanceBean benefitBean = (OHAllowanceBean) benefitList.get(0);
  1159.                 Long partyCode = null;
  1160.                 Short paymentMode = null;
  1161.                 for (int counter = 0; counter < benefitList.size(); counter++)
  1162.                 {
  1163.                     OHAllowanceBean allowanceBean = (OHAllowanceBean) benefitList.get(counter);
  1164.  
  1165.                     if(allowanceBean.getPaymentMode() != null)
  1166.                     {
  1167.                         paymentMode = allowanceBean.
  1168.                         getPaymentMode();
  1169.                         break;
  1170.                     }
  1171.                 }
  1172.  
  1173.                 int partyType=0;
  1174.                 GOSIDebug.debugMessages("session : bnft pay 2 :"
  1175.                     +benefitBean.getBenefitPayableTo());
  1176.  
  1177.                 // getting the distict list for the particular transaction
  1178.                 // it will return either contributor , employer or both
  1179.                 // based on who its paying.
  1180.                 ArrayList payeeList = getDistinctPayableTo(workflowId);
  1181.                 GOSIDebug.debugMessages("payeee list" + payeeList.size());
  1182.                 for(int i=0 ; i<payeeList.size();i++)
  1183.                 {
  1184.                     CNInterfaceBean oCNInterfaceBean = new CNInterfaceBean();
  1185.                     ArrayList detailList=new ArrayList();
  1186.                     oCNInterfaceBean.setCreditNoteType
  1187.                         (new Integer(FAInterfaceConstants.OH_ALLOWANCE_CN));
  1188.                     oCNInterfaceBean.setTransactionDate(currentTime);
  1189.                     oCNInterfaceBean.setLocationCode(new Long("" + fieldOffice));
  1190.  
  1191.                     Short payeeType=(Short)payeeList.get(i);
  1192.                     String partyName = "";
  1193.                     GOSIDebug.debugMessages("partyType:"+payeeType);
  1194.                     GOSIDebug.debugMessages("partyCode:"+benefitBean.getPartyCode());
  1195.                     GOSIDebug.debugMessages("payment mode" +benefitBean.getPaymentMode() );
  1196.  
  1197.                     // if payable to is hospital -- currently this option is disabled
  1198.                     if((OHConstants.OH_BNFT_PAY_TO_HOS).equals(payeeType))
  1199.                     {
  1200.                         GOSIDebug.debugMessages("payable to hospital");
  1201.                         partyType=FAInterfaceConstants.HOSPITALS_PARTYTYPE;
  1202.                         fieldOffice = ((OHAllowanceBean)benefitList.get(0)).
  1203.                         getFieldofficeCode();
  1204.                         for(int k=0 ; k<benefitList.size();k++)
  1205.                         {
  1206.                             OHAllowanceBean bnftBean =
  1207.                                 (OHAllowanceBean)benefitList.get(k);
  1208.                             if(OHConstants.OH_BNFT_PAY_TO_HOS .equals
  1209.                                 (bnftBean.getBenefitPayableTo()))
  1210.                             {
  1211.                                 partyCode = bnftBean.getPartyCode();
  1212.                                 break;
  1213.                             }
  1214.                         }
  1215.                     }//if payable to is employer
  1216.                     else  if((OHConstants.OH_BNFT_PAY_TO_EMP).equals(payeeType))
  1217.                     {
  1218.                         GOSIDebug.debugMessages("payable to Employer");
  1219.                         partyType=FAInterfaceConstants.EMPLOYER_PARTYTYPE;
  1220.                         for(int k=0 ; k<benefitList.size();k++)
  1221.                         {
  1222.                             OHAllowanceBean bnftBean =
  1223.                                 (OHAllowanceBean)benefitList.get(k);
  1224.                             if (OHConstants.OH_BNFT_PAY_TO_EMP.equals(bnftBean.getBenefitPayableTo()))
  1225.                             {
  1226.                                 partyCode = bnftBean.getPartyCode();
  1227.                                 break;
  1228.                             }
  1229.                         }
  1230.                         partyName = injuryBean.getEstablishmentName();
  1231.                         // partyCode=benefitBean.getPartyCode();
  1232.                     }// if payable to is contributor or authorized person for contributor
  1233.                     else if(OHConstants.OH_BNFT_PAY_TO_CON.equals(payeeType)
  1234.                         ||OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals(payeeType))
  1235.                     {
  1236.                         GOSIDebug.debugMessages("payable to Contributor");
  1237.                         partyType = FAInterfaceConstants.CONTRIBUTOR_PARTYTYPE;
  1238.                         partyCode = injuryBean.getSocialInsuranceNumber();
  1239.                         partyName = injuryBean.getName();
  1240.  
  1241.  
  1242.                         OHServices ohServices = new OHServices();
  1243.                         // method to get the break up type in case of contributors
  1244.                         breakUpType = ohServices.getPartyAccountBreakUpType
  1245.                             (injuryBean.getInjuryID(),null,null);
  1246.  
  1247.                     }
  1248.                     GOSIDebug.debugMessages("\n\n partyType:"+payeeType);
  1249.                     GOSIDebug.debugMessages("partyCode:"+partyCode);
  1250.  
  1251.                     oCNInterfaceBean.setPartyType(new Integer(partyType));
  1252.                     oCNInterfaceBean.setPartyCode(partyCode);
  1253.                     oCNInterfaceBean.setCreatedBy(userId);
  1254.                     oCNInterfaceBean.setPayeeName(partyName);
  1255.                     if(breakUpType!=null)
  1256.                     {
  1257.                         oCNInterfaceBean.setBreakUpType(breakUpType);
  1258.                     }
  1259.                     // if paybable to contributor or authorized person
  1260.                     // check if contributor/authorizedperson is present as party in finance
  1261.                     // else create the party first
  1262.                     if(OHConstants.OH_BNFT_PAY_TO_CON.equals(payeeType)
  1263.                         ||OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals(payeeType))
  1264.                     {
  1265.  
  1266.  
  1267.                         ContributorBean contributorBean = ContributorUtilities.
  1268.                             displayContributorForSIN(injuryBean.getSocialInsuranceNumber());
  1269.                         GOSIDebug.debugMessages("contactId:"+contributorBean.getContactId());
  1270.                        
  1271.                        
  1272.                        
  1273.                         if(OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals(payeeType))
  1274.                         {                          
  1275.                             String authPersonName = getPayeeName(contributorBean.getContributorId());                            
  1276.                             if(authPersonName!=null &&
  1277.                                 !"".equals(authPersonName))
  1278.                             {
  1279.                                 oCNInterfaceBean.setPayeeName(authPersonName);
  1280.                             }
  1281.                         }
  1282.                         GOSIDebug.debugMessages("Payee Name :" + oCNInterfaceBean.getPayeeName());                 
  1283.                        
  1284.                         Long contactId = contributorBean.getContactId();
  1285.                         GOSIDebug.debugMessages("contactId:"+contactId);
  1286.                        
  1287.                         HashMap inputPartyCodePresent = new HashMap();
  1288.                         HashMap outputPartyCodePresent = new HashMap();
  1289.                         Boolean isPartyCodePresent = null;
  1290.                         inputPartyCodePresent.put("moduleId", new Short( GOSIConstants.OCCUPATIONAL_HAZARDS_ID));
  1291.                         inputPartyCodePresent.put("partyType", new Integer (FAInterfaceConstants.CONTRIBUTOR_PARTYTYPE));
  1292.                         inputPartyCodePresent.put("partyCode", partyCode);
  1293.                         inputPartyCodePresent.put("methodDescription",
  1294.                         FAInterfaceConstants.VALIDATE_PARTY);
  1295.                         outputPartyCodePresent = faInterface.invokeService(inputPartyCodePresent);
  1296.                         if(outputPartyCodePresent != null)
  1297.                         {
  1298.                             isPartyCodePresent = (Boolean)
  1299.                             outputPartyCodePresent.get("partyExists");
  1300.                             GOSIDebug.debugMessages("isPartyCodePresent" +
  1301.                             isPartyCodePresent);
  1302.                             if(isPartyCodePresent != null)
  1303.                             {
  1304.  
  1305.                                 if(new Boolean(false).equals(isPartyCodePresent))
  1306.                                 {
  1307.                                     GOSIDebug.debugMessages("inside not present party");
  1308.  
  1309.                                     /*  Store the contributor details in
  1310.                                         PartyInterfaceBean
  1311.                                         to create party type
  1312.                                         for the contributor*/
  1313.  
  1314.                                     PartyInterfaceBean partyBean = new
  1315.                                     PartyInterfaceBean();
  1316.  
  1317.                                     partyBean.setPartyNameArb
  1318.                                     (injuryBean.getName());
  1319.                                     partyBean.setPartyType(new Integer(
  1320.                                     FAInterfaceConstants.CONTRIBUTOR_PARTYTYPE));
  1321.                                     partyBean.setPartyCode
  1322.                                     (partyCode);
  1323.                                     partyBean.setPaymentTerm(new Long
  1324.                                     ("" + FAInterfaceConstants.
  1325.                                     IMMEDIATE_PAYMENTTERM));
  1326.  
  1327.                                     //Added to get the breakUpType of party
  1328.  
  1329.  
  1330.                                     partyBean.setBreakUpType(breakUpType);
  1331.  
  1332.                                     //Addition ends here
  1333.  
  1334.                                     /* To be removed has been removed :) */
  1335.                                     partyBean.setContactID
  1336.                                     (contactId);
  1337.                                     partyBean.setContactType(new Integer                                    (FAInterfaceConstants.
  1338.                                     INDIVIDUAL_CONTACT_TYPE));
  1339.  
  1340.                                     GOSIDebug.debugMessages("getContactId:"+partyBean.getContactID());
  1341.                                     /* To be removed */
  1342.  
  1343.                                     GOSIDebug.debugMessages
  1344.                                     ("last modified by  " +
  1345.                                     userId);
  1346.                                     partyBean.setCreatedBy
  1347.                                     (userId);
  1348.                                     partyBean.setCreationTimestamp
  1349.                                     (new Timestamp
  1350.                                     (System.currentTimeMillis()));
  1351.                                     partyBean.setModuleId(GOSIConstants.
  1352.                                     OCCUPATIONAL_HAZARDS_ID);
  1353.  
  1354.                                     HashMap inputPartyDetails = new HashMap();
  1355.                                     HashMap outputPartyDetails = new HashMap();
  1356.  
  1357.                                     inputPartyDetails.put("methodDescription",
  1358.                                     FAInterfaceConstants.PARTY_INTERFACE);
  1359.                                     inputPartyDetails.put
  1360.                                     ("interfaceBean",partyBean);
  1361.                                     outputPartyDetails =
  1362.                                     faInterface.invokeService(inputPartyDetails);
  1363.                                     GOSIDebug.debugMessages("outputPartyDetails" +
  1364.                                     outputPartyDetails);
  1365.                                 }
  1366.                             }
  1367.                         }
  1368.                     }
  1369.                     // payment mode to be set as Local cheque
  1370.                     // if payable to is employer or hospital
  1371.                     if((OHConstants.OH_BNFT_PAY_TO_HOS.equals(payeeType)
  1372.                     ||(OHConstants.OH_BNFT_PAY_TO_EMP).equals(payeeType)))
  1373.                     {
  1374.                         oCNInterfaceBean.setPaymentMode
  1375.                         (new Integer
  1376.                         (FAInterfaceConstants.LC_CHEQUE));
  1377.                     }
  1378.                     else if((OHConstants.OH_BNFT_PAY_TO_CON).equals(payeeType))
  1379.                     {
  1380.                         // else if payment mode is contributor set the payment mode
  1381.                         // specified by the user . bank transfer is currently disabled
  1382.                         if(paymentMode != null)
  1383.                         {
  1384.                             if(OHConstants.PAYMENT_MODE_BANK_TRANSFER.
  1385.                             equals(paymentMode))
  1386.                             {
  1387.                                 oCNInterfaceBean.setPaymentMode
  1388.                                 (new Integer
  1389.                                 (FAInterfaceConstants.ACCOUNT_TRANSFER));
  1390.                             }
  1391.                             else if(OHConstants.PAYMENT_MODE_CHEQUE.
  1392.                             equals(paymentMode))
  1393.                             {
  1394.                                 oCNInterfaceBean.setPaymentMode
  1395.                                 (new Integer
  1396.                                 (FAInterfaceConstants.LC_CHEQUE));
  1397.                             }
  1398.                             else if(OHConstants.PAYMENT_MODE_CHEQUE_OVERSEAS.
  1399.                             equals(paymentMode))
  1400.                             {
  1401.                                 oCNInterfaceBean.setPaymentMode
  1402.                                     (new Integer(FAInterfaceConstants.LC_CHEQUE));
  1403.                                 oCNInterfaceBean.setLocationCode
  1404.                                     (new Long(""+OHConstants.FIELD_OFFICE_GOSI_RIYADH));
  1405.                             }
  1406.                         }
  1407.                         else
  1408.                         {
  1409.                             oCNInterfaceBean.setPaymentMode
  1410.                             (new Integer
  1411.                             (FAInterfaceConstants.LC_CHEQUE));
  1412.                         }
  1413.                     }else
  1414.                     {
  1415.                             oCNInterfaceBean.setPaymentMode
  1416.                             (new Integer
  1417.                             (FAInterfaceConstants.LC_CHEQUE));
  1418.                     }
  1419.                     // setting currency ,exchange rate and other required values
  1420.                      oCNInterfaceBean.setCurrency
  1421.                      (new Integer(FAInterfaceConstants.LC_CURRENCY));
  1422.                      
  1423.                     int baseCurrency = GOSIUtilities.getBaseCurrency();
  1424.                     GOSIDebug.debugMessages("base currency " + baseCurrency );
  1425.                     if(baseCurrency ==
  1426.                     FAInterfaceConstants.LC_CURRENCY)
  1427.                     {
  1428.                         oCNInterfaceBean.setExchangeRateType(new Integer
  1429.                         (FAInterfaceConstants.ERT_NONE));
  1430.                         oCNInterfaceBean.setExchangeRate
  1431.                         (new Double(FAInterfaceConstants.
  1432.                         LC_EXCHANGERATE));
  1433.                     }
  1434.                     else
  1435.                     {
  1436.                         oCNInterfaceBean.setExchangeRateType(new Integer
  1437.                         (FAInterfaceConstants.ERT_CORPORATE));
  1438.  
  1439.                     }
  1440.                     GOSIDebug.debugMessages("exchange rate type " +
  1441.                     oCNInterfaceBean.getExchangeRateType());
  1442.  
  1443.                     oCNInterfaceBean.setPaymentTerm(new Integer
  1444.                     (FAInterfaceConstants.IMMEDIATE_PAYMENTTERM));
  1445.                     oCNInterfaceBean.setStatus(new Integer
  1446.                     (FAInterfaceConstants.WORKFLOW_NOT_REQUIRED));
  1447.                     oCNInterfaceBean.setModuleId
  1448.                     (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  1449.  
  1450.                     // getting the details for each distict payee type
  1451.                     HashMap benefitDetails = getDetailsList
  1452.                         (benefitBean.getWorkflowId(),payeeType,fieldOffice,paymentMode);
  1453.  
  1454.                     detailList=(ArrayList)benefitDetails.get("detailList");
  1455.                     Double total = (Double)benefitDetails.get("total");
  1456.                     oCNInterfaceBean.setAmountFC(total);
  1457.                     String narration = GOSIErrorMessages.getErrorDesc("SOI_ERR_5115")
  1458.                             + " "
  1459.                             + total
  1460.                             + " for "
  1461.                             + GOSIErrorMessages.getErrorDesc("SOI_ERR_5582")
  1462.                             + " "
  1463.                             + injuryBean.getSocialInsuranceNumber().longValue();
  1464.                     GOSIDebug.debugMessages("SIN :" + injuryBean.getSocialInsuranceNumber().longValue() + ":");
  1465.                     GOSIDebug.debugMessages("narration :" + narration + ":");
  1466.                     oCNInterfaceBean.setNarration(narration);
  1467.  
  1468.                     /* commented on 4/16/2005  bcos payment mode is set earlier
  1469.                     oCNInterfaceBean.setPaymentMode
  1470.                       (new Integer
  1471.                         (FAInterfaceConstants.LC_CHEQUE));
  1472.                     */
  1473.  
  1474.                     GOSIDebug.debugMessages("PAYMENT MODE &&&& " +
  1475.                     oCNInterfaceBean.getPaymentMode());
  1476.  
  1477.                     // The below logic explains how to adjust the amount
  1478.                     // if any negative amount is present as adjustment
  1479.                     // the negative amount will be adjusted with the next positive detail
  1480.                     double adjustmentAmount = 0.00;
  1481.                     boolean isNeedtobeAdjusted = false;
  1482.                     for(int j=0;j<detailList.size();j++)
  1483.                     {
  1484.                         CNInterfaceDetailBean oDetailBean=
  1485.                             (CNInterfaceDetailBean)detailList.get(j);
  1486.  
  1487.                         if(isNeedtobeAdjusted)
  1488.                         {
  1489.                             oDetailBean.setAmountFC(new Double(
  1490.                                 oDetailBean.getAmountFC().doubleValue()+adjustmentAmount));
  1491.                             adjustmentAmount =0.00;
  1492.                             isNeedtobeAdjusted = false;
  1493.                         }
  1494.                         if(oDetailBean.getAmountFC().doubleValue()<0)
  1495.                         {
  1496.                             adjustmentAmount = oDetailBean.getAmountFC().doubleValue();
  1497.                             isNeedtobeAdjusted = true;
  1498.                             detailList.remove(j);
  1499.                             j--;
  1500.                         }
  1501.                         GOSIDebug.debugMessages("\n  getAmountFC  :"+oDetailBean.getAmountFC());
  1502.                         GOSIDebug.debugMessages("\n  ShortDesc  :"+oDetailBean.getShortDesc());
  1503.                         GOSIDebug.debugMessages("ReasonCode   :"+oDetailBean.getReasonCode());
  1504.                     }
  1505.                     GOSIDebug.debugMessages("detail List size :"+detailList.size());
  1506.                     oCNInterfaceBean.setCnInterfaceDetailList(detailList);
  1507.                     java.util.HashMap interfaceInput=new HashMap();
  1508.                     interfaceInput.put("interfaceBean",oCNInterfaceBean);
  1509.                     interfaceInput.put("methodDescription",
  1510.                         FAInterfaceConstants.CN_INTERFACE);
  1511.  
  1512.  
  1513.                     GOSIDebug.debugMessages("before invoking FA Interface");
  1514.                     GOSIDebug.debugMessages("Payee Name :"+oCNInterfaceBean.getPayeeName());
  1515.                     //calling the finance interface
  1516.                     //the return value will be stored as the journal header id
  1517.                     java.util.HashMap returnValue =
  1518.                         faInterface.invokeService(interfaceInput);
  1519.                     Long headerId=(Long)returnValue.get("returnValue");
  1520.                     GOSIDebug.debugMessages("HeaderId============="+headerId);
  1521.                     // method to update the journal header id in benefit bean
  1522.                     benefitList=setJournalType(benefitList,payeeType,headerId);
  1523.  
  1524.                 }
  1525.             }
  1526.             GOSIDebug.debugMessages("interface closed");
  1527.             // the benefit records will be updated based on mode
  1528.             for(int i=0;i<benefitList.size();i++)
  1529.             {
  1530.                 OHAllowanceBean benefitBean=(OHAllowanceBean)benefitList.get(i);
  1531.                 // the benefit record is inserted if mode is new
  1532.                 if(benefitBean.getMode()==benefitBean.NEW_MODE)
  1533.                 {
  1534.                     benefitBean.setCreationTimestamp(currentTime);
  1535.                     benefitBean.setOhBenId(GOSIUtilities.getPrimaryKey
  1536.                         ("T_OHBENEFIT",benefitBean.getCreatedBy()));
  1537.                     benefitBean.setInjuryId(injuryBean.getInjuryID());
  1538.                     benefitBean.setContributorId(injuryBean.getContributorId());
  1539.                     OHAllowanceEntity remoteEntity=(OHAllowanceEntity)home.create(benefitBean);
  1540.                 }// benefit record is deleted if mode is delete
  1541.                 else if(benefitBean.getMode()==benefitBean.DELETE_MODE)
  1542.                 {
  1543.                     benefitList.remove (i--);
  1544.                    
  1545.                     benefitBean.setLastModifiedTimestamp(currentTime);
  1546.                     OHAllowanceEntity remoteEntity=
  1547.                         (OHAllowanceEntity)home.findByPrimaryKey
  1548.                             (benefitBean.getOhBenId());
  1549.                     remoteEntity.remove();
  1550.                 }// else the benefit record is modified
  1551.                 else
  1552.                 {
  1553.                     benefitBean.setLastModifiedTimestamp(currentTime);
  1554.                     OHAllowanceEntity remoteEntity=
  1555.                         (OHAllowanceEntity)home.findByPrimaryKey
  1556.                             (benefitBean.getOhBenId());
  1557.                     remoteEntity.modifyOHBenefits(benefitBean);
  1558.                 }
  1559.             }
  1560.             GOSIDebug.debugMessages("OHAllowance Updated sucessfully");
  1561.  
  1562.             if(OHConstants.REENTER.equals(mode))
  1563.             {
  1564.                 /* Verify autorized person details */
  1565.                 for (int i = 0; i < benefitList.size (); i++)
  1566.                 {
  1567.                     OHAllowanceBean benefitBean = (OHAllowanceBean) benefitList.get (i);
  1568.  
  1569.                     if(OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals (benefitBean.getBenefitPayableTo ()))
  1570.                     {
  1571.                         isAuthPersonPresent (benefitBean.getContributorId ());
  1572.                         break;
  1573.                     }
  1574.                 }
  1575.  
  1576.                 /* Validate contact details */
  1577.                 validateContactDetails (contactList, benefitList);
  1578.  
  1579.                 /* Create recovery records if benefit amount < 0 */
  1580.                 HashMap updateRecoveryMap = updateRecovery (benefitList, workflowParamBean, injuryBean);
  1581.  
  1582.                 double totalAmount = ((Double) updateRecoveryMap.get ("totalAmount")).doubleValue ();
  1583.  
  1584.                 if (totalAmount < 0)
  1585.                 {
  1586.                     message = GOSIErrorMessages.getErrorDesc ("SOI_ERR_5194");
  1587.  
  1588.                     if(updateRecoveryMap.get ("workFlowEmployer") != null)
  1589.                     {
  1590.                         message = message + " : " + (String) updateRecoveryMap.get ("workFlowEmployer");
  1591.                     }
  1592.                     if(updateRecoveryMap.get ("workFlowContributor") != null)
  1593.                     {
  1594.                         message = message + " : " + (String) updateRecoveryMap.get ("workFlowContributor");
  1595.                     }
  1596.                 }
  1597.  
  1598.                 /* Approval is not needed if recovery is indicated */
  1599.                 if(workflowParamBean.getRoutingCriterion().equals(GOSIConstants.COMPLETED))
  1600.                 {
  1601.                     workflowParamBean.setRangeCheck (
  1602.                             GOSIConstants.RANGECHECK_IS_TYPE, (totalAmount < 0) ? OHConstants.RANGE_VALUE_STOP.longValue ()
  1603.                                                                                 : OHConstants.RANGE_VALUE_CONTINUE.longValue ());
  1604.                 }
  1605.  
  1606.                 workflowParamBean.setPrimaryKeyOfTherecord (workflowId.toString ());
  1607.                 workflowParamBean.setStepShortName ("REENTER_MISC_OH_ALLWNC");
  1608.  
  1609.                 /* Set DMS header bean and call DMS interface */
  1610.                 if(headerBean != null)
  1611.                 {
  1612.                     headerBean.setSourceRecordId (injuryBean.getInjuryID ().toString());
  1613.                     headerBean.setSourceTable    (SITables.T_INJURY);
  1614.                     headerBean.setCreatedBy      (new Long (workflowParamBean.getUserId ()));
  1615.                     headerBean.setKeyList        (DMSConstants.SI_NUMBER, injuryBean.getSocialInsuranceNumber ().toString ());
  1616.                     headerBean.setKeyList        (DMSConstants.REGISTRATION_NUMBER, injuryBean.getRegistrationNumber ().toString ());
  1617.                     headerBean.setKeyList        (DMSConstants.INJURY_NUMBER, injuryBean.getInjuryNumber ().toString ());
  1618.  
  1619.                     DMSUtilities.startDMS (headerBean);
  1620.                 }
  1621.             }
  1622.  
  1623.             if (canSendForWorkflow)
  1624.             {
  1625.                 // can send for workflow is set from the servlet
  1626.                 // it will be true if called from oh benefit screen
  1627.                 // else if its from the treatemnt period screen its will be false
  1628.  
  1629.                 workflowParamBean.setrecordDescription(
  1630.                     workflowParamBean.getrecordDescription () + " - " + injuryBean.getSocialInsuranceNumber ());
  1631.                
  1632.                 String userName = "";
  1633.  
  1634.                 try
  1635.                 {
  1636.                     userName = GOSIUtilities.startWorkflow (workflowParamBean);
  1637.                 }
  1638.                 catch (GOSIException ge)
  1639.                 {
  1640.                     if (ge.getErrorId().equals("CMN_ERR_1019"))
  1641.                     {
  1642.                         workflowParamBean.setTargetUserId (0);
  1643.                         userName = GOSIUtilities.startWorkflow (workflowParamBean);
  1644.                     }
  1645.                     else throw ge;
  1646.                 }
  1647.  
  1648.                 if (userName != null && !"".equals (userName))
  1649.                 {
  1650.                     message = GOSIErrorMessages.getErrorDesc ("SOI_ERR_5194") + " " + userName;
  1651.                 }
  1652.             }
  1653.  
  1654.             endTime = System.currentTimeMillis();
  1655.             elapsedTime = endTime - startTime;
  1656.             GOSIInstrumentationLog.writeInstrumentationToLog(
  1657.                 this.getClass().toString(),
  1658.                 "modifyOHAllowance()",
  1659.                 elapsedTime);
  1660.  
  1661.             return message;
  1662.             // return the message with username if send for workflow
  1663.         }
  1664.         catch(GOSIException ge)
  1665.         {
  1666.                 GOSIDebug.debugMessages("session :modify  :ge: "+ge);
  1667.                 ctx.setRollbackOnly();
  1668.                 throw ge;
  1669.         }
  1670.         catch(Exception e)
  1671.         {
  1672.             GOSIDebug.debugMessages("session :modify  :e: "+e);
  1673.             ctx.setRollbackOnly();
  1674.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  1675.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  1676.                 "modifyOHAllowance()",e,"CMN_ERR_1000");
  1677.         }
  1678.  
  1679.     }
  1680.  
  1681.  
  1682.     /**
  1683.     * @METHOD NAME              :   MaintainOHAllowanceSessionEJB
  1684.     * @INFORMATION              :   This method is the constructor$
  1685.     * @PARAM                    :   class java.lang.String
  1686.     * @RETURN                   :   class java.lang.Class
  1687.     * @EXCEPTION                :
  1688.     * @LAST MODIFIED BY         :
  1689.     * @LAST MODIFIED DATE       :
  1690.     **/
  1691.     public MaintainOHAllowanceSessionEJB    ()
  1692.     {
  1693.  
  1694.     }
  1695.  
  1696.     /**
  1697.     * @METHOD NAME              :   ejbCreate
  1698.     * @INFORMATION              :   This method is to  ejb Create
  1699.     * @PARAM                    :
  1700.     * @RETURN                   :   void
  1701.     * @EXCEPTION                :
  1702.     * @LAST MODIFIED BY         :
  1703.     * @LAST MODIFIED DATE       :
  1704.     **/
  1705.     public void ejbCreate    ()
  1706.     {
  1707.  
  1708.     }
  1709.  
  1710.     /**
  1711.     * @METHOD NAME              :   ejbRemove
  1712.     * @INFORMATION              :   This method is to  ejb Remove
  1713.     * @PARAM                    :
  1714.     * @RETURN                   :   void
  1715.     * @EXCEPTION                :
  1716.     * @LAST MODIFIED BY         :
  1717.     * @LAST MODIFIED DATE       :
  1718.     **/
  1719.     public void ejbRemove    ()
  1720.     {
  1721.  
  1722.     }
  1723.  
  1724.     /**
  1725.     * @METHOD NAME              :   ejbActivate
  1726.     * @INFORMATION              :   This method is to  ejb Activate
  1727.     * @PARAM                    :
  1728.     * @RETURN                   :   void
  1729.     * @EXCEPTION                :
  1730.     * @LAST MODIFIED BY         :
  1731.     * @LAST MODIFIED DATE       :
  1732.     **/
  1733.     public void ejbActivate    ()
  1734.     {
  1735.  
  1736.     }
  1737.  
  1738.     /**
  1739.     * @METHOD NAME              :   ejbPassivate
  1740.     * @INFORMATION              :   This method is to  ejb Passivate
  1741.     * @PARAM                    :
  1742.     * @RETURN                   :   void
  1743.     * @EXCEPTION                :
  1744.     * @LAST MODIFIED BY         :
  1745.     * @LAST MODIFIED DATE       :
  1746.     **/
  1747.     public void ejbPassivate    ()
  1748.     {
  1749.  
  1750.     }
  1751.  
  1752.     /**
  1753.     * @METHOD NAME              :   setSessionContext
  1754.     * @INFORMATION              :   This method is to  set Session Context
  1755.     * @PARAM                    :   interface javax.ejb.SessionContext
  1756.     * @RETURN                   :   void
  1757.     * @EXCEPTION                :
  1758.     * @LAST MODIFIED BY         :
  1759.     * @LAST MODIFIED DATE       :
  1760.     **/
  1761.     public void setSessionContext    (javax.ejb.SessionContext sc)
  1762.     {
  1763.         this.ctx=sc;
  1764.     }
  1765.  
  1766.  
  1767.     /**
  1768.     * @METHOD NAME              :   calculateDailyAllowance
  1769.     * @INFORMATION              :   This method is to calculate Daily Allowance
  1770.     * @PARAM                    :   class java.util.ArrayList,
  1771.                                     class java.lang.Double,
  1772.                                     class java.lang.Short,
  1773.                                     class java.lang.String
  1774.     * @RETURN                   :   class java.util.ArrayList
  1775.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  1776.     * @LAST MODIFIED BY         :
  1777.     * @LAST MODIFIED DATE       :
  1778.     **/
  1779.     private ArrayList calculateDailyAllowance
  1780.         (ArrayList trmtList,Double totalWage,Short  payableTo,String calenderType)
  1781.             throws GOSIException
  1782.     {
  1783.         ArrayList benefitList = new ArrayList();
  1784.  
  1785.         try
  1786.         {   // this method calculates the oh benefit
  1787.             // the period for which the benefit need to be calculated is set in the trmt list
  1788.             // the other parameters are used for calculating the benefit for each trmt period
  1789.             Long injuryId = null;
  1790.             if(trmtList!=null&&trmtList.size()!=0)
  1791.             {
  1792.                 injuryId =((TreatmentPeriodBean)trmtList.get(0)).getInjuryId();
  1793.             }
  1794.             for(int i=0;i<trmtList.size();i++)
  1795.             {
  1796.                 TreatmentPeriodBean trmtBean= new TreatmentPeriodBean();
  1797.                 trmtBean=(TreatmentPeriodBean)trmtList.get(i);
  1798.                 OHAllowanceBean benefitBean = new OHAllowanceBean();
  1799.                 GOSIDebug.debugMessages("startDate:" + trmtBean.getStartDateGreg() + ":");
  1800.                 GOSIDebug.debugMessages("EndDate:" + trmtBean.getEndDateGreg() + ":");
  1801.                 benefitBean.setInjuryId(trmtBean.getInjuryId());
  1802.                 benefitBean.setBenStDateGreg(trmtBean.getStartDateGreg());
  1803.                 benefitBean.setBenEndDateGreg(trmtBean.getEndDateGreg());
  1804.                 benefitBean.setTotalContWage(totalWage);
  1805.                 benefitBean.setBenefitPayableTo(payableTo);
  1806.  
  1807.                 if(trmtBean.getTreatmentType().equals
  1808.                         (OHConstants.TRMT_TYPE_INPATIENT))
  1809.                 {
  1810.                     benefitBean.setOhBenCode
  1811.                         (OHConstants.OH_ALWNC_DAIlY_INPATIENT);
  1812.                 }else
  1813.                 {
  1814.                     benefitBean.setOhBenCode
  1815.                         (OHConstants.OH_ALWNC_DAIlY_OUTPATIENT);
  1816.                 }
  1817.                 GOSIDebug.debugMessages("HospitalType:" + trmtBean.getHospitalType());
  1818.                 if(OHConstants.HIJRAH.equals(calenderType))
  1819.                 {
  1820.                     benefitBean = setDailyAllowanceHij
  1821.                         (benefitBean,trmtBean.getHospitalType());
  1822.                 }else
  1823.                 {
  1824.                     benefitBean = setDailyAllowanceGreg
  1825.                         (benefitBean,trmtBean.getHospitalType());
  1826.                 }
  1827.                 benefitList.add(benefitBean);
  1828.             }
  1829.             return benefitList;
  1830.         }
  1831.         catch(GOSIException ge)
  1832.         {
  1833.             GOSIDebug.debugMessages("session:calculateDailyAllowance:ge:"+ge);
  1834.             throw ge;
  1835.         }
  1836.         catch(Exception e)
  1837.         {
  1838.             GOSIDebug.debugMessages("session:calculateDailyAllowance:e:"+e);
  1839.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  1840.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  1841.                 "calculateDailyAllowance()",e,"CMN_ERR_1000");
  1842.         }
  1843.  
  1844.     }
  1845.  
  1846.     /**
  1847.     * @METHOD NAME              :   setDailyAllowanceGreg
  1848.     * @INFORMATION              :   This method is to  set Daily Allowance calculation for Gregorian employers
  1849.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.OHAllowanceBean,
  1850.                                     class java.lang.Short
  1851.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.OHAllowanceBean
  1852.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  1853.     * @LAST MODIFIED BY         :
  1854.     * @LAST MODIFIED DATE       :
  1855.     **/
  1856.     private OHAllowanceBean setDailyAllowanceGreg
  1857.         (OHAllowanceBean benefitBean,Short hospitalType)throws GOSIException
  1858.     {
  1859.         try
  1860.         {
  1861.             GOSIDebug.debugMessages("\t\t Start setDailyAllowanceGreg - MaintainOHAllowanceSessionEJB");
  1862.             // this method calculates the dailly allowace for the particular benefit bean
  1863.             // it get the start and end dates and based on the calender type
  1864.             // splits / dont split the record and calculate the benefit
  1865.             // this is called if the calender type is gregorian
  1866.             int noDays = benefitBean.getNumberDays();
  1867.             double wage = benefitBean.getTotalContWage().doubleValue();
  1868.             GOSIDebug.debugMessages("Wage:" + wage);
  1869.             double percentage = 0;
  1870.             Timestamp startDate = benefitBean.getBenStDateGreg();
  1871.             String lawIndicator = OHConstants.NEW_LAW;
  1872.             if(startDate.compareTo(OHRuleBean.getNewLawApplicableDate())<0)
  1873.             {
  1874.                 lawIndicator = OHConstants.OLD_LAW;
  1875.             }
  1876.             Timestamp endDate = benefitBean.getBenEndDateGreg();
  1877.             Calendar cal= Calendar.getInstance();
  1878.  
  1879.             cal.setTime(new java.util.Date(startDate.getTime()));
  1880.             int firstMonth = cal.get(Calendar.MONTH);
  1881.             int firstYear = cal.get(Calendar.YEAR);
  1882.             GOSIDebug.debugMessages("FirstYear:" + firstYear);
  1883.  
  1884.             cal.setTime(new java.util.Date(endDate.getTime()));
  1885.             int secondMonth = cal.get(Calendar.MONTH);
  1886.             int secondYear = cal.get(Calendar.YEAR);
  1887.             GOSIDebug.debugMessages("SecondYear:" + secondYear);
  1888.             int noMonths = 0;
  1889.             boolean flag = false;
  1890.             if(secondYear > firstYear)
  1891.             {
  1892.                 secondMonth = secondMonth + ((secondYear-firstYear)*12);
  1893.             }
  1894.  
  1895.             if(secondMonth > firstMonth)
  1896.             {
  1897.                 flag = true;
  1898.                 noMonths = secondMonth - firstMonth+1;
  1899.             }
  1900.  
  1901.             if(benefitBean.getOhBenCode().equals
  1902.                 (OHConstants.OH_ALWNC_DAIlY_INPATIENT))
  1903.             {
  1904.                 if(hospitalType.equals(OHConstants.REG_HOSPITAL))
  1905.                 {
  1906.                     //percentage =0.75;
  1907.                     percentage = OHRuleBean.
  1908.                         getInpatientPercentageforRegHospital(lawIndicator);
  1909.                 }
  1910.                 else if(hospitalType.equals(OHConstants.UNREG_HOSPITAL))
  1911.                 {
  1912.                     //percentage =0.75;
  1913.                     percentage = OHRuleBean.
  1914.                         getInpatientPercentageforUnRegHospital(lawIndicator);
  1915.  
  1916.                 }else if(hospitalType.equals(OHConstants.GOVT_FREE_HOSPITAL))
  1917.                 {
  1918.                     //percentage =1.0;
  1919.                     percentage = OHRuleBean.
  1920.                         getInpatientPercentageforGovFreeHospital(lawIndicator);
  1921.  
  1922.                 }else if(hospitalType.equals(OHConstants.GOVT_PAID_HOSPITAL))
  1923.                 {
  1924.                     //percentage =0.75;
  1925.                     percentage = OHRuleBean.
  1926.                         getInpatientPercentageforGovPaidHospital(lawIndicator);
  1927.                 }
  1928.             }else
  1929.             {
  1930.                 if(hospitalType.equals(OHConstants.REG_HOSPITAL))
  1931.                 {
  1932.                     //percentage =1.0;
  1933.                     percentage = OHRuleBean.
  1934.                         getOutpatientPercentageforRegHospital(lawIndicator);
  1935.                 }else if(hospitalType.equals(OHConstants.UNREG_HOSPITAL))
  1936.                 {
  1937.                     //percentage =1.0;
  1938.                     percentage = OHRuleBean.
  1939.                         getOutpatientPercentageforUnRegHospital(lawIndicator);
  1940.                 }else if(hospitalType.equals(OHConstants.GOVT_FREE_HOSPITAL))
  1941.                 {
  1942.                     //percentage =1.0;
  1943.                     percentage = OHRuleBean.
  1944.                         getOutpatientPercentageforGovFreeHospital(lawIndicator);
  1945.                 }else if(hospitalType.equals(OHConstants.GOVT_PAID_HOSPITAL))
  1946.                 {
  1947.                     //percentage =1.0;
  1948.                     percentage = OHRuleBean.
  1949.                         getOutpatientPercentageforGovPaidHospital(lawIndicator);
  1950.                 }
  1951.             }
  1952.             int maxDays = 0;
  1953.             double amount = 0;
  1954.             if(flag)
  1955.             {
  1956.                 for(int i=1;i<=noMonths;i++)
  1957.                 {
  1958.                     if(i == 1)
  1959.                     {
  1960.                         cal.setTime(new java.util.Date(startDate.getTime()));
  1961.                         noDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH)
  1962.                             -cal.get(Calendar.DAY_OF_MONTH)+1;
  1963.                         maxDays = cal.getActualMaximum((Calendar.DAY_OF_MONTH));
  1964.                     }
  1965.                     else if(i>1 && i<noMonths)
  1966.                     {
  1967.                         cal.setTime(new java.util.Date(startDate.getTime()));
  1968.                         cal.add(Calendar.MONTH,(i-1));
  1969.                         noDays= cal.getActualMaximum((Calendar.DAY_OF_MONTH));
  1970.                         maxDays= cal.getActualMaximum((Calendar.DAY_OF_MONTH));
  1971.                     }
  1972.                     else if(i == noMonths)
  1973.                     {
  1974.                         cal.setTime(new java.util.Date(endDate.getTime()));
  1975.                         noDays=cal.get(Calendar.DAY_OF_MONTH);
  1976.                         maxDays=cal.getActualMaximum((Calendar.DAY_OF_MONTH));
  1977.                     }
  1978.                     GOSIDebug.debugMessages("NoDays :"+noDays);
  1979.                     GOSIDebug.debugMessages("MaxDays :"+maxDays);
  1980.                     GOSIDebug.debugMessages("Percentage :"+percentage);
  1981.                     amount = amount +
  1982.                         ((noDays*percentage*
  1983.                             benefitBean.getTotalContWage().doubleValue())
  1984.                                 /maxDays);
  1985.                     GOSIDebug.debugMessages("Amount:"+amount);
  1986.                 }
  1987.             }else
  1988.             {
  1989.                 noDays=benefitBean.getNumberDays();
  1990.                 cal.setTime(new java.util.Date(startDate.getTime()));
  1991.                 maxDays= cal.getActualMaximum((Calendar.DAY_OF_MONTH));
  1992.                 GOSIDebug.debugMessages("NoDays :" + noDays);
  1993.                 GOSIDebug.debugMessages("MaxDays :" + maxDays);
  1994.                 GOSIDebug.debugMessages("Percentage :" + percentage);
  1995.                 amount =
  1996.                     ((noDays*percentage*benefitBean.getTotalContWage()
  1997.                         .doubleValue())/maxDays);
  1998.                 GOSIDebug.debugMessages("Amount:" + amount);
  1999.             }
  2000.  
  2001.  
  2002.             Double benAmount = new Double(amount);
  2003.             benefitBean.setBenAmount(benAmount);
  2004.             GOSIDebug.debugMessages("\t\t End setDailyAllowanceGreg - MaintainOHAllowanceSessionEJB");
  2005.             return benefitBean;
  2006.         }
  2007.         catch(Exception e)
  2008.         {
  2009.             GOSIDebug.debugMessages("session:setDailyAllowance:e:" + e);
  2010.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  2011.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2012.                 "setDailyAllowance()",e,"CMN_ERR_1000");
  2013.         }
  2014.     }
  2015.  
  2016.     /**
  2017.     * @METHOD NAME              :   setDailyAllowanceHij
  2018.     * @INFORMATION              :   This method is to  set Daily Allowance calculation for  Hijrah employers
  2019.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.OHAllowanceBean,
  2020.                                     class java.lang.Short
  2021.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.OHAllowanceBean
  2022.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2023.     * @LAST MODIFIED BY         :
  2024.     * @LAST MODIFIED DATE       :
  2025.     **/
  2026.     private OHAllowanceBean setDailyAllowanceHij
  2027.         (OHAllowanceBean benefitBean,Short hospitalType)throws GOSIException
  2028.     {
  2029.         try
  2030.         {
  2031.              GOSIDebug.debugMessages("--------------setDailyAllowanceHIJ---------");
  2032.             // this method calculates the dailly allowace for the particulat benefit bean
  2033.             // it get the start and end dates and based on the calender type
  2034.             // splits / dont split the record and calculate the benefit
  2035.             // this is called if the calender type is hijrah
  2036.             int noDays=benefitBean.getNumberDays();
  2037.             double wage=benefitBean.getTotalContWage().doubleValue();
  2038.             double percentage =0;
  2039.             Timestamp startDate=benefitBean.getBenStDateGreg();
  2040.             String lawIndicator = OHConstants.NEW_LAW;
  2041.             if(startDate.compareTo(OHRuleBean.getNewLawApplicableDate())<0)
  2042.             {
  2043.                 lawIndicator =OHConstants.OLD_LAW;
  2044.             }
  2045.             String startDateHij = OHUtilities.getDateStr(startDate,OHConstants.HIJRAH);
  2046.             Timestamp endDate=benefitBean.getBenEndDateGreg();
  2047.             String endDateHij = OHUtilities.getDateStr(endDate,OHConstants.HIJRAH);
  2048.             GOSIDebug.debugMessages("startDate:"+startDateHij);
  2049.             GOSIDebug.debugMessages("  endDate:"+endDateHij);
  2050.             int firstMonth=OHUtilities.getMonth(startDateHij);
  2051.             int firstYear= OHUtilities.getYear(startDateHij);
  2052.             GOSIDebug.debugMessages("firstyear:"+firstYear);
  2053.  
  2054.             //cal.setTime(new java.util.Date(endDate.getTime()));
  2055.             int secondMonth=OHUtilities.getMonth(endDateHij);
  2056.             int secondYear =OHUtilities.getYear(endDateHij);
  2057.             int noMonths=0;
  2058.             boolean flag=false;
  2059.             if(secondYear > firstYear)
  2060.             {
  2061.                 secondMonth=secondMonth+((secondYear-firstYear)*12);
  2062.             }
  2063.             GOSIDebug.debugMessages("No Months :"+noMonths);
  2064.             if(secondMonth > firstMonth)
  2065.             {
  2066.                 flag= true;
  2067.                 noMonths=secondMonth-firstMonth+1;
  2068.             }
  2069.             GOSIDebug.debugMessages("flag:"+flag);
  2070.             if(benefitBean.getOhBenCode().equals(OHConstants.OH_ALWNC_DAIlY_INPATIENT))
  2071.             {
  2072.                 if(hospitalType.equals(OHConstants.REG_HOSPITAL))
  2073.                 {
  2074.                     //percentage =0.75;
  2075.                     percentage=OHRuleBean.getInpatientPercentageforRegHospital(lawIndicator);
  2076.                 }
  2077.                 else if(hospitalType.equals(OHConstants.UNREG_HOSPITAL))
  2078.                 {
  2079.                     //percentage =0.75;
  2080.                     percentage=OHRuleBean.getInpatientPercentageforUnRegHospital(lawIndicator);
  2081.  
  2082.                 }else if(hospitalType.equals(OHConstants.GOVT_FREE_HOSPITAL))
  2083.                 {
  2084.                     //percentage =1.0;
  2085.                     percentage=OHRuleBean.getInpatientPercentageforGovFreeHospital(lawIndicator);
  2086.  
  2087.                 }else if(hospitalType.equals(OHConstants.GOVT_PAID_HOSPITAL))
  2088.                 {
  2089.                     //percentage =0.75;
  2090.                     percentage=OHRuleBean.getInpatientPercentageforGovPaidHospital(lawIndicator);
  2091.                 }
  2092.             }else
  2093.             {
  2094.                 if(hospitalType.equals(OHConstants.REG_HOSPITAL))
  2095.                 {
  2096.                     //percentage =1.0;
  2097.                     percentage=OHRuleBean.getOutpatientPercentageforRegHospital(lawIndicator);
  2098.                 }else if(hospitalType.equals(OHConstants.UNREG_HOSPITAL))
  2099.                 {
  2100.                     //percentage =1.0;
  2101.                     percentage=OHRuleBean.getOutpatientPercentageforUnRegHospital(lawIndicator);
  2102.                 }else if(hospitalType.equals(OHConstants.GOVT_FREE_HOSPITAL))
  2103.                 {
  2104.                     //percentage =1.0;
  2105.                     percentage=OHRuleBean.getOutpatientPercentageforGovFreeHospital(lawIndicator);
  2106.                 }else if(hospitalType.equals(OHConstants.GOVT_PAID_HOSPITAL))
  2107.                 {
  2108.                     //percentage =1.0;
  2109.                     percentage=OHRuleBean.getOutpatientPercentageforGovPaidHospital(lawIndicator);
  2110.                 }
  2111.             }
  2112.             int maxDays=0;
  2113.             double amount=0;
  2114.             if(flag)
  2115.             {
  2116.                 for(int i=1;i<=noMonths;i++)
  2117.                 {
  2118.                     if(i==1)
  2119.                     {
  2120.                         String lastDateHij =OHUtilities.getMonthEndDate(startDateHij);
  2121.                         noDays = OHUtilities.getDay(lastDateHij)-OHUtilities.getDay(startDateHij)+1;
  2122.                         maxDays =OHUtilities.getDay(lastDateHij);
  2123.                     }
  2124.                     else if(i>1 && i<noMonths)
  2125.                     {
  2126.                         String addedMonthDate =GOSIDateUtilities.getDateForMonths
  2127.                                 (startDateHij,GOSIConstants.HIJ_CALENDARTYPE,
  2128.                                     GOSIConstants.DATE_NEXT_INDICATOR,(i-1));
  2129.                         String lastDateHij =OHUtilities.getMonthEndDate(addedMonthDate);
  2130.                         noDays = OHUtilities.getDay(lastDateHij);
  2131.                         maxDays =OHUtilities.getDay(lastDateHij);
  2132.                     }
  2133.                     else if(i==noMonths)
  2134.                     {
  2135.                         //cal.setTime(new java.util.Date(endDate.getTime()));
  2136.                         String lastDateHij =OHUtilities.getMonthEndDate(endDateHij);
  2137.                         noDays = OHUtilities.getDay(endDateHij);
  2138.                         maxDays= OHUtilities.getDay(lastDateHij);
  2139.                     }
  2140.                     GOSIDebug.debugMessages("noDays :"+noDays);
  2141.                     GOSIDebug.debugMessages("maxDays :"+maxDays);
  2142.                     GOSIDebug.debugMessages("percentage :"+percentage);
  2143.                     amount=amount+((noDays*percentage*benefitBean.getTotalContWage().doubleValue())/maxDays);
  2144.                     GOSIDebug.debugMessages("temp amount:"+amount);
  2145.                 }
  2146.             }else
  2147.             {
  2148.                 noDays=benefitBean.getNumberDays();
  2149.                 String lastDateHij =OHUtilities.getMonthEndDate(endDateHij);
  2150.                 maxDays= OHUtilities.getDay(lastDateHij);
  2151.                 amount =((noDays*percentage*benefitBean.getTotalContWage().doubleValue())/maxDays);
  2152.             }
  2153.  
  2154.  
  2155.             Double benAmount=new Double(amount);
  2156.             benefitBean.setBenAmount(benAmount);
  2157.             GOSIDebug.debugMessages("--------------setDailyAllowance*---------");
  2158.             return benefitBean;
  2159.  
  2160.         }
  2161.         catch(Exception e)
  2162.         {
  2163.             GOSIDebug.debugMessages("session-clcltDlyAllwnc : The exception is "+e);
  2164.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  2165.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2166.                 "setDailyAllowance()",e,"CMN_ERR_1000");
  2167.         }
  2168.     }
  2169.  
  2170.  
  2171.     /**
  2172.     * @METHOD NAME              :   getPayableHospital
  2173.     * @INFORMATION              :   This method is to  get Payable Hospital
  2174.     * @PARAM                    :   class java.lang.Long,
  2175.                                     class java.sql.Timestamp
  2176.     * @RETURN                   :   class java.lang.Long
  2177.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2178.     * @LAST MODIFIED BY         :
  2179.     * @LAST MODIFIED DATE       :
  2180.     **/
  2181.     private Long  getPayableHospital(Long injuryId,Timestamp compStartDate,boolean isTreatmentApproved)
  2182.         throws GOSIException
  2183.     {
  2184.         PreparedStatement ps = null;
  2185.         ResultSet rs =null;
  2186.         String sqlQuery;
  2187.         boolean flag=true;
  2188.         Long hospitalCode = null;
  2189.         // this method is to get the hospital details for which the the companion
  2190.         // allowance is to be paid , this functionality is currently diabled
  2191.         // and now the companion allowance is paid with treatment service
  2192.  
  2193.         sqlQuery = " select HOSPITALCODE from " + SITables.T_TREATMENT +
  2194.                    " where INJURYID= ? and STARTDATE <= ? "+
  2195.                    " and ENDDATE>=? and TREATMENTSTATUS = ? ";
  2196.         try
  2197.         {
  2198.             ps  =con.prepareStatement(sqlQuery);
  2199.             ps.setLong(1,injuryId.longValue());
  2200.             ps.setTimestamp(2,compStartDate);
  2201.             ps.setTimestamp(3,compStartDate);
  2202.             if(isTreatmentApproved)
  2203.             {
  2204.                 ps.setShort(4,OHConstants.TRMT_STS_APPROVED.shortValue());
  2205.             }else
  2206.             {
  2207.                 ps.setShort(4,OHConstants.TRMT_STS_ENTERED.shortValue());
  2208.             }
  2209.             rs=ps.executeQuery();
  2210.             if(rs!=null)
  2211.             {
  2212.                 while(rs.next())
  2213.                 {
  2214.                         hospitalCode=new Long(rs.getLong("HOSPITALCODE"));
  2215.                 }
  2216.             }
  2217.         }
  2218.         catch(Exception e)
  2219.         {
  2220.             GOSIDebug.debugMessages("session:getPayableHospital :e:"+e);
  2221.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  2222.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2223.                 "getPayableHospital()",e,"CMN_ERR_1000");
  2224.         }
  2225.         finally
  2226.         {
  2227.             GOSIUtilities.cleanUp(ps,rs);
  2228.         }
  2229.         return hospitalCode;
  2230.     }
  2231.  
  2232.  
  2233.  
  2234.     /**
  2235.     * @METHOD NAME              :   getBenefitStartDate
  2236.     * @INFORMATION              :   This method is to  get Benefit Start Date
  2237.                                     of the entered benefit in workflow
  2238.     * @PARAM                    :   class java.lang.Long
  2239.     * @RETURN                   :   class java.sql.Timestamp
  2240.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2241.     * @LAST MODIFIED BY         :
  2242.     * @LAST MODIFIED DATE       :
  2243.     **/
  2244.     private Timestamp getBenefitStartDate(Long injuryId)
  2245.         throws GOSIException
  2246.     {   Timestamp benifitStartDate=null;
  2247.         PreparedStatement ps = null;
  2248.         ResultSet rs = null;
  2249.         String sqlQuery;
  2250.         // This method is to  get Benefit Start Date
  2251.         // of the entered benefit in workflow
  2252.         try
  2253.         {
  2254.             sqlQuery= "  select max (BENENDDATE) from "+
  2255.                 SITables.T_OHBENEFIT + " where INJURYID=? and "+
  2256.                 " ( OHBENCODE =? or OHBENCODE = ? or OHBENCODE = ? ) ";
  2257.             ps  =con.prepareStatement(sqlQuery);
  2258.             ps.setLong(1,injuryId.longValue());
  2259.             ps.setShort(2,OHConstants.OH_ALWNC_DAIlY_INPATIENT.shortValue());
  2260.             ps.setShort(3,OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.shortValue());
  2261.             ps.setShort(4,OHConstants.OH_ALWNC_CONVEYENCE.shortValue());
  2262.             rs  =ps.executeQuery();
  2263.             while(rs.next())
  2264.             {
  2265.                 if(rs.getObject(1)!=null)
  2266.                 {
  2267.                     benifitStartDate=rs.getTimestamp(1);
  2268.                 }
  2269.             }
  2270.             // if no benefit is found the benefit start date is the next day of injury
  2271.             sqlQuery =" select INJURYDATE from "+
  2272.                 SITables.T_INJURY + " where INJURYID=? ";
  2273.             if(benifitStartDate==null)
  2274.             {
  2275.                 ps  =con.prepareStatement(sqlQuery);
  2276.                 ps.setLong(1,injuryId.longValue());
  2277.                 rs  =ps.executeQuery();
  2278.                 while(rs.next())
  2279.                 {
  2280.                     benifitStartDate=rs.getTimestamp("INJURYDATE");
  2281.                 }
  2282.             }
  2283.             if(benifitStartDate!=null)
  2284.             {
  2285.                 benifitStartDate=GOSIUtilities.getNextDate(benifitStartDate);
  2286.             }
  2287.             return benifitStartDate;
  2288.         }
  2289.         catch(GOSIException ge)
  2290.         {
  2291.             GOSIDebug.debugMessages("session-getBenefitStartDate: exp is:"+ge);
  2292.             throw ge;
  2293.         }
  2294.         catch(Exception e)
  2295.         {
  2296.             GOSIDebug.debugMessages("session-getBenefitStartDate: exp is:"+e);
  2297.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  2298.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2299.                 "calculateDailyAllowance()",e,"CMN_ERR_1000");
  2300.         }
  2301.         finally
  2302.         {
  2303.             GOSIUtilities.cleanUp(ps, rs);
  2304.         }
  2305.     }
  2306.  
  2307.  
  2308.     /**
  2309.     * @METHOD NAME              :   canAvailBenefitdueToDisablity
  2310.     * @INFORMATION              :   This method is to  check whether contributor
  2311.                                     can Avail Benefit due To Disablity
  2312.     * @PARAM                    :   class java.lang.Long
  2313.     * @RETURN                   :   boolean
  2314.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2315.     * @LAST MODIFIED BY         :
  2316.     * @LAST MODIFIED DATE       :
  2317.     **/
  2318.     private boolean canAvailBenefitdueToDisablity(Long socInsNumber)
  2319.         throws GOSIException
  2320.     {
  2321.  
  2322.         String sqlQuery;
  2323.         boolean flag = true;
  2324.         PreparedStatement ps = null;
  2325.         ResultSet rs = null;
  2326.         try
  2327.         {
  2328.             // this method checks if the contributor has a disability percentage
  2329.             // more than 50 percent if his maximum disability is more than 50
  2330.             // it returns false else true
  2331.             sqlQuery = " select max(DISABILITYPERCENTAGE) MAXDISABILITY from "+
  2332.                         SITables.T_DISBASSMT +
  2333.                       " where SOCIALINSURANCENUMBER = ? "+
  2334.                       " and ((DISBSTATUS = ? and WORKFLOWSTATUS = ? ) or "+
  2335.                       " DISBSTATUS in(?,?)) ";
  2336.             ps  =con.prepareStatement(sqlQuery);
  2337.             ps.setLong(1,socInsNumber.longValue());
  2338.             ps.setShort(2,OHConstants.ASSMT_COMPLETED.shortValue());
  2339.             ps.setShort(3,OHConstants.ASSMT_COMPLETED.shortValue());
  2340.             ps.setShort(4,OHConstants.ASSMT_APPEALED.shortValue());
  2341.             ps.setShort(5,OHConstants.ASSMT_APPEAL_WITHDRAWN.shortValue());
  2342.            
  2343.             GOSIDebug.debugMessages("SqlQuery:" + sqlQuery + ":");
  2344.             GOSIDebug.debugMessages("\t\t Param 1 :" + socInsNumber.longValue() + ":");
  2345.             GOSIDebug.debugMessages("\t\t Param 2 :" + OHConstants.ASSMT_COMPLETED.shortValue() + ":");
  2346.             GOSIDebug.debugMessages("\t\t Param 3 :" + OHConstants.ASSMT_COMPLETED.shortValue() + ":");
  2347.             GOSIDebug.debugMessages("\t\t Param 4 :" + OHConstants.ASSMT_APPEALED.shortValue() + ":");
  2348.             GOSIDebug.debugMessages("\t\t Param 5 :" + OHConstants.ASSMT_APPEAL_WITHDRAWN.shortValue() + ":");
  2349.  
  2350.             rs = ps.executeQuery();
  2351.             double percentage = 0.00;
  2352.             while(rs.next())
  2353.             {
  2354.                 if(rs.getObject("MAXDISABILITY")!=null)
  2355.                 {
  2356.                     percentage=rs.getDouble("MAXDISABILITY");
  2357.                 }
  2358.                 GOSIDebug.debugMessages("Percentage Disability :" + percentage);
  2359.             }
  2360.             GOSIDebug.debugMessages("Flag:" + (percentage > 50.00));
  2361.             if(percentage > OHRuleBean.getMaxEligibleDisPercentageforDA())
  2362.             {
  2363.                 flag = false;
  2364.             }
  2365.             return flag;
  2366.         }
  2367.         catch(Exception e)
  2368.         {
  2369.             GOSIDebug.debugMessages("session-checkDisabilityStatus: exp is:"+e);
  2370.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  2371.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2372.                 "canAvailBenefitdueToDisablity()",e,"CMN_ERR_1000");
  2373.         }
  2374.         finally
  2375.         {
  2376.             GOSIUtilities.cleanUp(ps,rs);
  2377.         }
  2378.     }
  2379.  
  2380.  
  2381.  
  2382.     /**
  2383.     * @METHOD NAME              :   getContributorBank
  2384.     * @INFORMATION              :   This method is to  get Contributor Bank details
  2385.     * @PARAM                    :   class java.lang.Long
  2386.     * @RETURN                   :   class gosi.business.socialinsurance.annuities.common.beans.PaymentBankAccountBean
  2387.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2388.     * @LAST MODIFIED BY         :
  2389.     * @LAST MODIFIED DATE       :
  2390.     **/
  2391.    public PaymentBankAccountBean getContributorBank( Long socInsNum)
  2392.      throws gosi.core.util.GOSIException
  2393.   {
  2394.         long startTime   = 0;
  2395.         long endTime     = 0;
  2396.         long elapsedTime = 0;
  2397.         startTime = System.currentTimeMillis();
  2398.  
  2399.     double wage=0;
  2400.     PaymentBankAccountBean bankAccBean = null;
  2401.     PreparedStatement ps = null;
  2402.     ResultSet rs =null;
  2403.     try
  2404.     {
  2405.         // This method returns the bank details of the contributor
  2406.         // stored in the T_paymentbank account table
  2407.         String sqlQuery=""+
  2408.             " select "+
  2409.             " PAYMENTACCOUNTRECID,"+
  2410.             " BANKCODE, "+
  2411.             " BRANCHCODE,   "+
  2412.             " ACCOUNTNUMBER, "+
  2413.             " CONTRIBUTORID, "+
  2414.             " PAYEETYPE,"+
  2415.             " PAYEEID,"+
  2416.             " STARTDATE, "+
  2417.             " STARTDATEENTFMT, "+
  2418.             " WORKFLOWSTATUS, "+
  2419.             " CREATEDBY,"+
  2420.             " CREATIONTIMESTAMP ,"+
  2421.             " LASTMODIFIEDBY ,"+
  2422.             " LASTMODIFIEDTIMESTAMP "+
  2423.             " from "+ SITables.T_PAYMENTBANKACCOUNT +
  2424.             " where CONTRIBUTORID= "+
  2425.             " (select CONTRIBUTORID from "+
  2426.               SITables.T_CONTRIBUTOR +
  2427.             " where SOCIALINSURANCENUMBER=? )"+
  2428.             " and PAYEETYPE= ? and "+
  2429.             " ENDDATE is null ";
  2430.         GOSIDebug.debugMessages("sqlQuery:"+sqlQuery);
  2431.         con=GOSIUtilities.getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  2432.         ps=con.prepareStatement(sqlQuery);
  2433.         ps.setLong(1,socInsNum.longValue());
  2434.         ps.setShort(2,OHConstants.PAYEE_TYPE_CONTRIBUTOR.shortValue());
  2435.         rs=ps.executeQuery();
  2436.         while(rs.next())
  2437.         {
  2438.             bankAccBean = new PaymentBankAccountBean();
  2439.             bankAccBean.setPaymentAccountRecId
  2440.                 (new Long(rs.getLong("PAYMENTACCOUNTRECID")));
  2441.             bankAccBean.setBankCode(new Short (rs.getShort("BANKCODE")));
  2442.             bankAccBean.setBranchCode(new Short (rs.getShort("BRANCHCODE")));
  2443.             bankAccBean.setAccountNumber(rs.getString("ACCOUNTNUMBER"));
  2444.             bankAccBean.setContributorId
  2445.                 (new Long (rs.getLong("CONTRIBUTORID")));
  2446.             bankAccBean.setPayeeType(new Short(rs.getShort("PAYEETYPE")));
  2447.             bankAccBean.setPayeeId(new Long(rs.getLong("PAYEEID")));
  2448.             bankAccBean.setStartDate(rs.getTimestamp("STARTDATE"));
  2449.             bankAccBean.setStartDateEntFmt(rs.getString("STARTDATEENTFMT"));
  2450.             bankAccBean.setWorkflowStatus
  2451.                 (new Short(rs.getShort("WORKFLOWSTATUS")));
  2452.             bankAccBean.setCreatedBy(new Long(rs.getLong("CREATEDBY")));
  2453.             bankAccBean.setCreationTimestamp
  2454.                 (rs.getTimestamp("CREATIONTIMESTAMP"));
  2455.             if(rs.getObject("LASTMODIFIEDBY")!=null)
  2456.             {
  2457.                 bankAccBean.setLastModifiedBy
  2458.                     (new Long (rs.getLong("LASTMODIFIEDBY")));
  2459.                 bankAccBean.setLastModifiedTimestamp
  2460.                     (rs.getTimestamp("LASTMODIFIEDTIMESTAMP"));
  2461.             }
  2462.             bankAccBean.setMode(AuditBean.OLD_MODE);
  2463.         }
  2464.         endTime = System.currentTimeMillis();
  2465.         elapsedTime = endTime - startTime;
  2466.         GOSIInstrumentationLog.writeInstrumentationToLog(
  2467.                 this.getClass().toString(),
  2468.                 "getContributorBank()",
  2469.                 elapsedTime);
  2470.  
  2471.         return bankAccBean;
  2472.     }
  2473.     catch(GOSIException ge)
  2474.     {
  2475.         throw ge;
  2476.     }
  2477.     catch(Exception e)
  2478.     {
  2479.         GOSIDebug.debugMessages("session-getContributorBank : e: "+e);
  2480.         throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  2481.             GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2482.             "getContributorBank()",e,"CMN_ERR_1000");
  2483.     }
  2484.     finally
  2485.     {
  2486.         GOSIUtilities. cleanUp(con,ps,rs);
  2487.     }
  2488.  }
  2489.  
  2490.     /**
  2491.     * @METHOD NAME              :   getContributorId
  2492.     * @INFORMATION              :   This method is to  get Contributor Id
  2493.     * @PARAM                    :   class java.lang.Long
  2494.     * @RETURN                   :   class java.lang.Long
  2495.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2496.     * @LAST MODIFIED BY         :
  2497.     * @LAST MODIFIED DATE       :
  2498.     **/
  2499.     public Long getContributorId(Long socInsNum)throws GOSIException
  2500.     {
  2501.         long startTime   = 0;
  2502.         long endTime     = 0;
  2503.         long elapsedTime = 0;
  2504.         startTime = System.currentTimeMillis();
  2505.  
  2506.         Long contributorId = null;
  2507.         PreparedStatement ps = null;
  2508.         ResultSet rs =null;
  2509.         try
  2510.         {
  2511.             // this is the query to get the contributor id of the contributor
  2512.             // using social insurance number
  2513.             String sqlQuery = " select CONTRIBUTORID from "+
  2514.                                 SITables.T_CONTRIBUTOR +
  2515.                               " where SOCIALINSURANCENUMBER=? ";
  2516.             con=GOSIUtilities.getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  2517.             ps=con.prepareStatement(sqlQuery);
  2518.             ps.setLong(1, socInsNum.longValue());
  2519.             rs = ps.executeQuery();
  2520.             while(rs.next())
  2521.             {
  2522.                 contributorId = new Long(rs.getLong("CONTRIBUTORID"));
  2523.             }
  2524.             endTime = System.currentTimeMillis();
  2525.             elapsedTime = endTime - startTime;
  2526.             GOSIInstrumentationLog.writeInstrumentationToLog(
  2527.                 this.getClass().toString(),
  2528.                 "getContributorId()",
  2529.                 elapsedTime);
  2530.  
  2531.             return contributorId;
  2532.         }
  2533.         catch (GOSIException ge)
  2534.         {
  2535.             GOSIDebug.debugMessages("session:getContributorId:ge:"+ge);
  2536.             throw ge;
  2537.         }
  2538.         catch (Exception e)
  2539.         {
  2540.             GOSIDebug.debugMessages("session:getContributorId:e:"+e);
  2541.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  2542.             GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2543.             "getTotalContibutorWage()",e,"CMN_ERR_1000");
  2544.         }
  2545.         finally
  2546.         {
  2547.             GOSIUtilities. cleanUp(con,ps,rs);
  2548.         }
  2549.     }
  2550.     /**
  2551.     * @METHOD NAME              :   saveBankDetails
  2552.     * @INFORMATION              :   This method is to  save Bank Details
  2553.     * @PARAM                    :   class gosi.business.socialinsurance.annuities.common.beans.PaymentBankAccountBean
  2554.     * @RETURN                   :   void
  2555.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2556.     * @LAST MODIFIED BY         :
  2557.     * @LAST MODIFIED DATE       :
  2558.     **/
  2559.     public void saveBankDetails
  2560.         (PaymentBankAccountBean bankAccountBean) throws GOSIException
  2561.     {
  2562.         long startTime   = 0;
  2563.         long endTime     = 0;
  2564.         long elapsedTime = 0;
  2565.         startTime = System.currentTimeMillis();
  2566.  
  2567.         try
  2568.         {
  2569.             // this method saves the bank details entered by the user
  2570.             // into the T_PAYMENTBANKACCOUNT table
  2571.             // based on the modes it will insert or update the table
  2572.             PaymentBankAccountEntityHome home=(PaymentBankAccountEntityHome)
  2573.                 ServiceLocator.getInstance().getRemoteHome(
  2574.                 OHConstants.PAYMENT_BANK_ENTITY_JNDI,
  2575.                 PaymentBankAccountEntityHome.class);
  2576.             Timestamp currentTime=new Timestamp (System.currentTimeMillis());
  2577.             if(AuditBean.OLD_MODE == bankAccountBean.getMode())
  2578.             {
  2579.                 GOSIDebug.debugMessages("no need to change Bank account details");
  2580.             }
  2581.             else if ((AuditBean.NEW_MODE == bankAccountBean.getMode()))
  2582.             {
  2583.                 GOSIDebug.debugMessages("the mode is new mode");
  2584.                 bankAccountBean.setPaymentAccountRecId(GOSIUtilities.
  2585.                     getPrimaryKey("T_PAYMENTBANKACCOUNT",
  2586.                         bankAccountBean.getCreatedBy()));
  2587.                 bankAccountBean.setCreationTimestamp
  2588.                     (new Timestamp(System.currentTimeMillis()));
  2589.                 PaymentBankAccountEntity remote = home.create(bankAccountBean);
  2590.             }
  2591.             else if ((AuditBean.MODIFY_MODE == bankAccountBean.getMode()))
  2592.             {
  2593.                 GOSIDebug.debugMessages("the mode is modify mode");
  2594.                 PaymentBankAccountEntity remote=home.findByPrimaryKey
  2595.                         (bankAccountBean.getPaymentAccountRecId());
  2596.                 remote.modify(bankAccountBean);
  2597.             }
  2598.             endTime = System.currentTimeMillis();
  2599.             elapsedTime = endTime - startTime;
  2600.             GOSIInstrumentationLog.writeInstrumentationToLog(
  2601.                 this.getClass().toString(),
  2602.                 "saveBankDetails()",
  2603.                 elapsedTime);
  2604.  
  2605.         }
  2606.         catch(GOSIException ge)
  2607.         {
  2608.                 GOSIDebug.debugMessages("session:save:ge:"+ge);
  2609.                 ctx.setRollbackOnly();
  2610.                 throw ge;
  2611.         }
  2612.         catch(Exception e)
  2613.         {
  2614.             GOSIDebug.debugMessages("servlet-saveBankDetails :The exception is "+e);
  2615.             ctx.setRollbackOnly();
  2616.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  2617.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2618.                 "saveBankDetails()",e,"CMN_ERR_1000");
  2619.         }
  2620.     }
  2621.  
  2622.  
  2623.     /**
  2624.     * @METHOD NAME              :   setEstablishmentDetails
  2625.     * @INFORMATION              :   This method is to  set Establishment Details for the injury
  2626.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  2627.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  2628.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2629.     * @LAST MODIFIED BY         :
  2630.     * @LAST MODIFIED DATE       :
  2631.     **/
  2632.     private InjuryPopDetails setEstablishmentDetails
  2633.         (InjuryPopDetails injuryDetails)throws GOSIException
  2634.     {
  2635.         GOSIDebug.debugMessages("Start setEstablishmentDetails - MaintainOHAllowanceSessionEJB");
  2636.         String establishmentName = "xyz";  
  2637.         java.sql.ResultSet rs = null;
  2638.         java.sql.PreparedStatement ps = null;
  2639.         try
  2640.         {
  2641.             // establishment and engagement details to be set
  2642.             // esatablishment details like name ,registration number ,
  2643.             // responsible for oh payment etc are set
  2644.             EstablishmentBean estBean = EstablishmentUtility.
  2645.                 getEstablishmentDetails(injuryDetails.getEstablishmentId().longValue(),
  2646.                     false,true);
  2647.             injuryDetails.setEstablishmentName(estBean.getEstablishmentNameArb());
  2648.             injuryDetails.setEstablishmentNameEnglish(estBean.getEstablishmentNameEng());
  2649.             injuryDetails.setRegistrationNumber(estBean.getRegistrationNumber());
  2650.             if(estBean.getResponsibleForOHPayment() != null)
  2651.             {
  2652.                 injuryDetails.setBenefitPayableTo
  2653.                     (new Short(estBean.getResponsibleForOHPayment().shortValue()));            
  2654.                 injuryDetails.setInjuredEstablishmentBenefitPayableTo(
  2655.                     new Short(estBean.getResponsibleForOHPayment().shortValue()));
  2656.             }
  2657.            
  2658.             //The Complication allowance is paid like injury allowance.
  2659.             //no need to pay to contributor when he is getting wage from employer.
  2660.             /*         
  2661.             if(injuryDetails.getComplicationDate() != null)
  2662.             {
  2663.                 injuryDetails.setBenefitPayableTo
  2664.                     (OHConstants.OH_BNFT_PAY_TO_CON);
  2665.             }*/
  2666.             GOSIDebug.debugMessages("Benefit PayableTo :" + injuryDetails.getBenefitPayableTo());
  2667.             double wage = 0;
  2668.             // the logic below checks if the contributor has any valid engagement
  2669.             // on complication date and if any set the flag setIsEngagementPresentOnComplication
  2670.             // to true and calender date as complication date else its false and injury date
  2671.             Timestamp injDate = injuryDetails.getInjuryDate();
  2672.             Timestamp calDate = injuryDetails.getInjuryDate();
  2673.             if(injuryDetails.getComplicationDate()!=null)
  2674.             {
  2675.                 injDate = injuryDetails.getComplicationDate();
  2676.                 calDate = injuryDetails.getComplicationDate();
  2677.                 injuryDetails = getEngagementforEstablishment(injDate,injuryDetails);
  2678.                 if(injuryDetails.getEngagementId() == null)
  2679.                 {
  2680.                     injDate = injuryDetails.getInjuryDate();
  2681.                     calDate = injuryDetails.getInjuryDate();
  2682.                     injuryDetails = getEngagementforEstablishment(injDate,injuryDetails);
  2683.                     injuryDetails.setIsEngagementPresentOnComplicationAndEligibleForOH(false);
  2684.  
  2685.                 }
  2686.                 else if(OHUtilities.isEligibleforOHCoverage(injuryDetails.getEstablishmentId(), injDate))
  2687.                 {
  2688.                     injuryDetails.setIsEngagementPresentOnComplicationAndEligibleForOH(true);
  2689.                 }
  2690.             }else
  2691.             {
  2692.                 injuryDetails = getEngagementforEstablishment(injDate,injuryDetails);
  2693.                 injuryDetails.setIsEngagementPresentOnComplicationAndEligibleForOH(false);
  2694.             }
  2695.  
  2696.             GOSIDebug.debugMessages(" IsEngagementPresentOnComplicationAndEligibleForOH :"+
  2697.                     injuryDetails.getIsEngagementPresentOnComplicationAndEligibleForOH());
  2698.  
  2699.             // this method set the establishment calender at the time of injury
  2700.             String calType = EstablishmentUtility.getCalendar
  2701.                 (estBean.getEstablishmentId(),calDate);
  2702.             injuryDetails.setCalendarType(calType);
  2703.            
  2704.             GOSIDebug.debugMessages("End setEstablishmentDetails - MaintainOHAllowanceSessionEJB");
  2705.             return injuryDetails;
  2706.         }
  2707.         catch(Exception e)
  2708.         {
  2709.             GOSIDebug.debugMessages("Exception inside setEstablishmentDetails :" + e);
  2710.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  2711.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2712.                 "getEstablishmentName()",e,"CMN_ERR_1000");
  2713.         }finally
  2714.         {
  2715.             GOSIUtilities.cleanUp(ps,rs);
  2716.         }
  2717.     }
  2718.     /**
  2719.     * @METHOD NAME              :   getEngagementforEstablishment
  2720.     * @INFORMATION              :   This method is to  get engagement Details for the establishment of the injury
  2721.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  2722.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  2723.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2724.     * @LAST MODIFIED BY         :
  2725.     * @LAST MODIFIED DATE       :
  2726.     **/
  2727.  
  2728.     private InjuryPopDetails getEngagementforEstablishment
  2729.         (Timestamp injuryDate,InjuryPopDetails injuryDetails)
  2730.             throws GOSIException
  2731.     {
  2732.         GOSIDebug.debugMessages("\t\t Start getEngagementforEstablishment - MaintainOHAllowanceSessionEJB");
  2733.         java.sql.ResultSet rs = null;
  2734.         java.sql.PreparedStatement ps = null;
  2735.         StringBuffer sqlQuery = new StringBuffer();
  2736.         Connection con1 = null;
  2737.         ArrayList contributorIdList = null;
  2738.         try
  2739.         {
  2740.             // the below logic gets the engagement of the contributor
  2741.             // on the time of injury with the registered establishment
  2742.  
  2743.             if(injuryDetails.getMergedSIN()!= null)
  2744.             {
  2745.                 // if the contributor has a merged sin
  2746.                 contributorIdList = getContributorIdList(injuryDetails.getMergedSIN());
  2747.             }
  2748.             else
  2749.             {
  2750.                  // if the contriubutor doesnt have a merged sin   
  2751.                 contributorIdList = new ArrayList();
  2752.                 contributorIdList.add(injuryDetails.getContributorId());
  2753.            
  2754.             }
  2755.                 sqlQuery.append(" SELECT");
  2756.                     sqlQuery.append(" ENGAGEMENTID ");
  2757.                 sqlQuery.append(" FROM ");             
  2758.                     sqlQuery.append(SITables.T_ENGAGEMENT);
  2759.                 sqlQuery.append(" WHERE ");
  2760.                     sqlQuery.append(" CONTRIBUTORID = ? AND ");
  2761.                     sqlQuery.append(" ESTABLISHMENTID = ? AND ");
  2762.                     sqlQuery.append(" JOININGDATE <= ?  AND ");
  2763.                     sqlQuery.append(" (LEAVINGDATE is null or LEAVINGDATE >= ?) AND ");
  2764.                     sqlQuery.append(" ENGAGEMENTSTATUS NOT IN ( ?,?) ");
  2765.             con1 = GOSIUtilities.getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  2766.             ps = con1.prepareStatement(sqlQuery.toString());
  2767.                          
  2768.             ps.setLong(2,injuryDetails.getEstablishmentId().longValue());
  2769.             ps.setTimestamp(3,injuryDate);
  2770.                 ps.setTimestamp(4,injuryDate);
  2771.             ps.setShort(5,RegistrationConstants.ENG_JOIN_IN_PROGRESS.shortValue());
  2772.                         // PRD00078198 to avoid return cancel ENGAGEMENT for the contributor.
  2773.                         ps.setShort(6, RegistrationConstants.ENG_CANCELLED.shortValue());
  2774.             for(int i = 0 ; i < contributorIdList.size(); i++)
  2775.             {
  2776.                 ps.setLong(1,((Long)contributorIdList.get(i)).longValue());
  2777.                 GOSIDebug.debugMessages("sqlQuery:" + sqlQuery.toString() + ":");
  2778.                 GOSIDebug.debugMessages("\t\t Param 1 :" + (Long)contributorIdList.get(i) + ":");          
  2779.                 GOSIDebug.debugMessages("\t\t Param 2 :" + injuryDetails.getEstablishmentId().longValue() + ":");
  2780.                 GOSIDebug.debugMessages("\t\t Param 3 :" + injuryDate + ":");
  2781.                 GOSIDebug.debugMessages("\t\t Param 4 :" + injuryDate + ":");
  2782.                 GOSIDebug.debugMessages("\t\t Param 5 :" + RegistrationConstants.ENG_JOIN_IN_PROGRESS.shortValue() + ":");
  2783.                                 GOSIDebug.debugMessages("\t\t Param 6 :" + RegistrationConstants.ENG_CANCELLED.shortValue() + ":");
  2784.                 GOSIDebug.debugMessages("Time:" + System.currentTimeMillis());
  2785.                 rs = ps.executeQuery();
  2786.                 GOSIDebug.debugMessages("Time:" + System.currentTimeMillis());
  2787.                 if(rs.next())
  2788.                 {
  2789.                     if( rs.getObject("ENGAGEMENTID") != null)
  2790.                     {
  2791.                         long engagementId = rs.getLong("ENGAGEMENTID");
  2792.                         GOSIDebug.debugMessages("Engagement Id:" + engagementId + ":");
  2793.                         injuryDetails.setEngagementId(new Long(engagementId));
  2794.                         break;
  2795.                     }
  2796.                 }
  2797.             }
  2798.             // the injury's engagement id is set if found into the injury bean
  2799.             GOSIDebug.debugMessages("Engagement Id in InjuryDetails Bean:" + injuryDetails.getEngagementId() + ":");
  2800.             GOSIDebug.debugMessages("\t\t End getEngagementforEstablishment - MaintainOHAllowanceSessionEJB");
  2801.             return injuryDetails;
  2802.         }
  2803.         catch(Exception e)
  2804.         {
  2805.             GOSIDebug.debugMessages("Exception inside getEngagementforEstablishment :" + e);
  2806.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  2807.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2808.                 "getEngagementforEstablishment()",e,"CMN_ERR_1000");
  2809.         }finally
  2810.         {
  2811.             GOSIUtilities.cleanUp(con1,ps,rs);
  2812.         }
  2813.  
  2814.     }
  2815.  
  2816.  
  2817.  
  2818.     /**
  2819.     * @METHOD NAME              :   getReasonCode
  2820.     * @INFORMATION              :   This method is to  get Reason Code of finance
  2821.     * @PARAM                    :   class java.lang.Short
  2822.     * @RETURN                   :   int
  2823.     * @EXCEPTION                :
  2824.     * @LAST MODIFIED BY         :
  2825.     * @LAST MODIFIED DATE       :
  2826.     **/
  2827.     private int getReasonCode(Short benefitType)
  2828.     {
  2829.  
  2830.         int reasonCode=0;
  2831.         if(OHConstants.OH_ALWNC_DAIlY_INPATIENT.equals(benefitType))
  2832.         {
  2833.             reasonCode = FAInterfaceConstants.IN_PATIENT_DAILY_ALLOWANCE_RC;
  2834.         }
  2835.         else if(OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.equals(benefitType))
  2836.         {
  2837.             reasonCode = FAInterfaceConstants.OUT_PATIENT_DAILY_ALLOWANCE_RC;
  2838.         }
  2839.         else if(OHConstants.OH_ALWNC_CONVEYENCE.equals(benefitType))
  2840.         {
  2841.             reasonCode = FAInterfaceConstants.CONVEYANCE_ALLOWANCE_RC;
  2842.         }
  2843.         else if(OHConstants.OH_ALWNC_COMP_CONVEYENCE.equals(benefitType))
  2844.         {
  2845.             reasonCode = FAInterfaceConstants.COMPANI0N_CONVEYANCE_ALLOWANCE_RC;
  2846.  
  2847.         }else if(OHConstants.OH_ALWNC_COMP_DAILY.equals(benefitType))
  2848.         {
  2849.             reasonCode = FAInterfaceConstants.COMPANION_DAILY_ALLOWANCE_RC;
  2850.         }
  2851.         else if(OHConstants.OH_ALWNC_DOC_COMP_DAILY.equals(benefitType))
  2852.         {
  2853.             reasonCode = FAInterfaceConstants.COMPANION_DAILY_ALLW_DOCTOR_RC;
  2854.         }
  2855.         else if(OHConstants.OH_ALWNC_NUR_COMP_DAILY.equals(benefitType))
  2856.         {
  2857.             reasonCode = FAInterfaceConstants.COMPANION_DAILY_ALLW_NURSE_RC;
  2858.         }
  2859.         else
  2860.         if(OHConstants.OH_ALWNC_DAILY_INPATIENT_ADJUSTMENT.equals(benefitType))
  2861.         {
  2862.             reasonCode = FAInterfaceConstants.IN_PATIENT_DAILY_ALLW_ADJST_RC;
  2863.         }
  2864.         else
  2865.         if(OHConstants.OH_ALWNC_DAILY_OUTPATIENT_ADJUSTMENT.equals(benefitType))
  2866.         {
  2867.             reasonCode = FAInterfaceConstants.OUT_PATIENT_DAILY_ALLW_ADJST_RC;
  2868.         }
  2869.         else if(OHConstants.OH_ALWNC_CONVEYENCE_ADJUSTMENT.equals(benefitType))
  2870.         {
  2871.             reasonCode = FAInterfaceConstants.CONVEYANCE_ALLOWANCE_RC;
  2872.         }else if (OHConstants.OH_ALWNC_MISCELLANEOUS.equals(benefitType))
  2873.         {
  2874.             reasonCode = FAInterfaceConstants.OUT_PATIENT_DAILY_ALLOWANCE_RC;
  2875.         }
  2876.  
  2877.  
  2878.         return reasonCode;
  2879.     }
  2880.  
  2881.  
  2882.     /**
  2883.     * @METHOD NAME              :   getDistinctPayableTo
  2884.     * @INFORMATION              :   This method is to  get Distinct Payable To
  2885.                                     entities(contributor /establishment/authorized person)
  2886.     * @PARAM                    :   class java.lang.Long
  2887.     * @RETURN                   :   class java.util.ArrayList
  2888.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2889.     * @LAST MODIFIED BY         :
  2890.     * @LAST MODIFIED DATE       :
  2891.     **/
  2892.     private ArrayList getDistinctPayableTo(Long workflowId)
  2893.         throws GOSIException
  2894.     {
  2895.         String sqlQuery;
  2896.         PreparedStatement ps = null;
  2897.         ResultSet rs =null;
  2898.         ArrayList payableList = new ArrayList();
  2899.         sqlQuery = " select distinct (PAYABLETO) from "+
  2900.                     SITables.T_OHBENEFIT +
  2901.                    " where WORKFLOWID=? ";
  2902.         try
  2903.         {
  2904.             // This query is used to get the distict entities to which
  2905.             // the oh benefit is paid ,
  2906.             con=GOSIUtilities.
  2907.                 getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  2908.             ps =con.prepareStatement(sqlQuery);
  2909.  
  2910.             GOSIDebug.debugMessages("sqlquery" + sqlQuery);
  2911.             GOSIDebug.debugMessages("workflowId" + workflowId);
  2912.             ps.setLong(1,workflowId.longValue());
  2913.             rs=ps.executeQuery();
  2914.             while(rs.next())
  2915.             {
  2916.                 payableList.add(new Short(rs.getShort("PAYABLETO")));
  2917.             }
  2918.             GOSIDebug.debugMessages("PAYABLELIST "  +payableList.size());
  2919.         }
  2920.         catch(Exception e)
  2921.         {
  2922.             GOSIDebug.debugMessages("session-compAlwnc :The exception is "+e);
  2923.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  2924.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  2925.                 "calculateCompanionAllowance()",e,"CMN_ERR_1000");
  2926.         }
  2927.         finally
  2928.         {
  2929.             GOSIUtilities.cleanUp(con,ps,rs);
  2930.             return payableList;
  2931.         }
  2932.     }
  2933.     /**
  2934.     * @METHOD NAME              :   setJournalType
  2935.     * @INFORMATION              :   This method is to  set Journal Type for finance
  2936.     * @PARAM                    :   class java.util.ArrayList,
  2937.                                     class java.lang.Short,
  2938.                                     class java.lang.Long
  2939.     * @RETURN                   :   class java.util.ArrayList
  2940.     * @EXCEPTION                :
  2941.     * @LAST MODIFIED BY         :
  2942.     * @LAST MODIFIED DATE       :
  2943.     **/
  2944.     private ArrayList setJournalType(ArrayList benefitList,Short payableTo,
  2945.         Long journalHeaderId )
  2946.     {
  2947.         // this method set the journal header id into each of the
  2948.         // benefit bean in the benefit list
  2949.         for(int i=0;i<benefitList.size();i++)
  2950.         {
  2951.             OHAllowanceBean benefitBean = (OHAllowanceBean)benefitList.get(i);
  2952.             if(payableTo.equals(benefitBean.getBenefitPayableTo()))
  2953.             {
  2954.                 benefitBean.setJournalHeaderId(journalHeaderId);
  2955.             }
  2956.         }
  2957.         return benefitList;
  2958.     }
  2959.  
  2960.     /**
  2961.     * @METHOD NAME              :   getDetailsList
  2962.     * @INFORMATION              :   This method is to  get Details List for populating
  2963.                                     credit note details, namely the benefit types and amount
  2964.     * @PARAM                    :   class java.lang.Long,
  2965.                                     class java.lang.Short,
  2966.                                     class java.lang.Short
  2967.     * @RETURN                   :   class java.util.HashMap
  2968.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  2969.     * @LAST MODIFIED BY         :
  2970.     * @LAST MODIFIED DATE       :
  2971.     **/
  2972.     private HashMap getDetailsList(Long workflowId,Short payeeType,
  2973.         Short fieldOffice,Short paymentMode)throws GOSIException
  2974.     {
  2975.         String sqlQuery="";
  2976.         ArrayList detailList=new ArrayList();
  2977.         HashMap details =new HashMap();
  2978.         PreparedStatement ps = null;
  2979.         ResultSet rs =null;
  2980.         try
  2981.         {
  2982.             // first the distict benefit codes for a particular payable to
  2983.             // and workflowid is found
  2984.             con=GOSIUtilities.getConnection
  2985.                 (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  2986.             sqlQuery = " select distinct OHBENCODE,OHBENTYPE from "+
  2987.                         SITables.T_OHBENEFIT +" where WORKFLOWID= ? "+
  2988.                        " and PAYABLETO = ? "+
  2989.                        " order by OHBENCODE ";
  2990.             ps = con.prepareStatement(sqlQuery);
  2991.             ps.setLong(1,workflowId.longValue());
  2992.             ps.setShort(2,payeeType.shortValue());
  2993.             rs=ps.executeQuery();
  2994.             ArrayList benCodeList= new ArrayList();
  2995.             while (rs.next())
  2996.             {
  2997.                 benCodeList.add(new Short (rs.getShort("OHBENCODE")));
  2998.                 benCodeList.add(rs.getString("OHBENTYPE"));
  2999.             }
  3000.             double total = 0.00;
  3001.             // for each of the distinct benefit codes the sum of the
  3002.             // benefit amount is taken and set into the details list
  3003.             for(int i=0; i< benCodeList.size();i++)
  3004.             {
  3005.                 Short benCode = (Short)benCodeList.get(i);
  3006.                 String benType =(String)benCodeList.get(i+1);
  3007.                 i++;
  3008.                 sqlQuery = " select sum (BENAMOUNT) TOTAL from "+
  3009.                             SITables.T_OHBENEFIT +" where WORKFLOWID=? "+
  3010.                            " and OHBENCODE= ? and PAYABLETO = ? ";
  3011.                 ps = con.prepareStatement(sqlQuery);
  3012.                 ps.setLong(1,workflowId.longValue());
  3013.                 ps.setShort(2,benCode.shortValue());
  3014.                 ps.setShort(3,payeeType.shortValue());
  3015.                 rs=ps.executeQuery();
  3016.                 ArrayList serviceList= new ArrayList();
  3017.                 double sum = 0.00;
  3018.                 while (rs.next())
  3019.                 {
  3020.                     sum = rs.getDouble("TOTAL");
  3021.                 }
  3022.                 CNInterfaceDetailBean oDetailBean=
  3023.                     new CNInterfaceDetailBean();
  3024.                 // if the payment mode is found to be overseas
  3025.                 // the field office is set to RIYADH FO
  3026.                 if(OHConstants.PAYMENT_MODE_CHEQUE_OVERSEAS.equals(paymentMode))
  3027.                 {
  3028.                     oDetailBean.setLocationCode(
  3029.                         new Integer(""+OHConstants.FIELD_OFFICE_GOSI_RIYADH));
  3030.                 }else
  3031.                 {
  3032.                     oDetailBean.setLocationCode(new Integer("" + fieldOffice));
  3033.                 }
  3034.                 oDetailBean.setShortDesc(benType);
  3035.                 oDetailBean.setReasonCode(new Integer
  3036.                     (getReasonCode(benCode)));
  3037.                 oDetailBean.setAmountFC(new Double (sum));
  3038.                 detailList.add(oDetailBean);
  3039.                 total=total+sum;
  3040.             }
  3041.             // the details are put into a hash map and returned
  3042.             details.put("detailList", detailList);
  3043.             details.put("total",new Double(total));
  3044.             return details;
  3045.         }
  3046.         catch(GOSIException ge)
  3047.         {
  3048.                 throw ge;
  3049.         }
  3050.         catch(Exception e)
  3051.         {
  3052.             GOSIDebug.debugMessages("servlet-searchInjury :The exception is "+e);
  3053.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3054.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3055.                 "saveOHAllowance()",e,"CMN_ERR_1000");
  3056.         }
  3057.         finally
  3058.         {
  3059.             GOSIUtilities.cleanUp(con,ps,rs);
  3060.         }
  3061.     }
  3062.  
  3063.     /**
  3064.     * @METHOD NAME              :   isBankDetailsPresent
  3065.     * @INFORMATION              :   This method is to check if Bank Details are Present or not
  3066.     * @PARAM                    :   class java.util.ArrayList,
  3067.                                     class java.lang.Long
  3068.     * @RETURN                   :   boolean
  3069.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3070.     * @LAST MODIFIED BY         :
  3071.     * @LAST MODIFIED DATE       :
  3072.     **/
  3073.     private boolean isBankDetailsPresent(ArrayList benefitList,Long socInsNum)
  3074.         throws GOSIException
  3075.     {
  3076.         boolean flag = true;
  3077.         try
  3078.         {
  3079.             // this method checks if a valid bank details is present for the contributor
  3080.             boolean isPayableToCon =false;
  3081.             for (int i=0;i<benefitList.size();i++)
  3082.             {
  3083.                 OHAllowanceBean benefitBean =
  3084.                     (OHAllowanceBean)benefitList.get(i);
  3085.                 if(OHConstants.OH_BNFT_PAY_TO_CON.equals
  3086.                     (benefitBean.getBenefitPayableTo()) )
  3087.                 {
  3088.                     GOSIDebug.debugMessages("bnft payable to :"+
  3089.                         benefitBean.getBenefitPayableTo());
  3090.                     GOSIDebug.debugMessages("payment mode :"+
  3091.                         benefitBean.getPaymentMode());
  3092.                     if(OHConstants.PAYMENT_MODE_BANK_TRANSFER.equals
  3093.                         (benefitBean.getPaymentMode()))
  3094.                     {
  3095.                         isPayableToCon = true;
  3096.                         break;
  3097.                     }
  3098.                 }
  3099.             }
  3100.             GOSIDebug.debugMessages("isPayableToCon"+isPayableToCon);
  3101.             if(isPayableToCon)
  3102.             {
  3103.                 PaymentBankAccountBean bankBean=getContributorBank(socInsNum);
  3104.                 if(bankBean == null)
  3105.                 {
  3106.                     flag =false;
  3107.                     //String message = "";
  3108.                     //message = GOSIErrorMessages.getErrorDesc("SOI_ERR_4541");
  3109.                     throw new GOSIException(GOSIConstants.SEVERITY_ONE,
  3110.                     GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3111.                     "isBankDetailsPresent()",
  3112.                     new GOSIException(), "SOI_ERR_4541");
  3113.                 }
  3114.             }
  3115.             return flag;
  3116.         }
  3117.         catch (GOSIException ge)
  3118.         {
  3119.             throw ge;
  3120.         }
  3121.         catch(Exception e)
  3122.         {
  3123.             GOSIDebug.debugMessages("session-compAlwnc :The exception is "+e);
  3124.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3125.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3126.                 "isBankDetailsPresent()",e,"CMN_ERR_1000");
  3127.         }
  3128.     }
  3129.  
  3130.  
  3131.     /**
  3132.     * @METHOD NAME              :   getInjuryStoppedPeriodList
  3133.     * @INFORMATION              :   This method is to  get Stopped Period for the injury
  3134.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  3135.     * @RETURN                   :   class java.util.ArrayList
  3136.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3137.     * @LAST MODIFIED BY         :
  3138.     * @LAST MODIFIED DATE       :
  3139.     **/
  3140.         private ArrayList getInjuryStoppedPeriodList(InjuryPopDetails injuryBean,boolean isTreatmentApproved)throws
  3141.             GOSIException
  3142.         {
  3143.             GOSIDebug.debugMessages("\t\t Start getInjuryStoppedPeriodList - MaintainOHAllowanceSessionEJB");
  3144.             PreparedStatement ps = null;
  3145.             ResultSet rs =null;
  3146.             try
  3147.             {
  3148.                 ArrayList stoppedPeriodList = new ArrayList();
  3149.                 // this query returns the stopped periods for the injury from the
  3150.                 // stop resume oh allowance table
  3151.                 String sqlQuery=    " select FROMDATE, "    +
  3152.                                     " TODATE, "+
  3153.                                     " STOPORRESUMEFLAG from  "      +
  3154.                                     SITables.T_STOPRESUMEOHALLOWANCE +
  3155.                                     " where "+
  3156.                                     " STATUS =? "+
  3157.                                     " and CONTRIBUTORID = ? and "+
  3158.                                     " FROMDATE <= ? and "+
  3159.                                     " TODATE >= ? ";
  3160.                 con= GOSIUtilities.getConnection
  3161.                     (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  3162.                 ps =con.prepareStatement(sqlQuery);
  3163.                 ps.setShort(1,
  3164.                     OHConstants.STOP_ALLOW_STS_APPROVED.shortValue());
  3165.                 ps.setLong(2, injuryBean.getContributorId().longValue());
  3166.                 ps.setTimestamp(3,injuryBean.getBenefitEndDate());
  3167.                 ps.setTimestamp(4,injuryBean.getBenefitStartDate());
  3168.                 rs=ps.executeQuery();
  3169.                 while(rs.next())
  3170.                 {
  3171.                     TreatmentPeriodBean trmtBean = new TreatmentPeriodBean();
  3172.                     trmtBean.setStartDateGreg(rs.getTimestamp("FROMDATE"));
  3173.                     trmtBean.setEndDateGreg(rs.getTimestamp("TODATE"));
  3174.                     Byte stopResumeflag =
  3175.                         new Byte(rs.getByte("STOPORRESUMEFLAG"));
  3176.                     // this method will add/remove the stopped period to the list
  3177.                     // based on the stopResumeflag
  3178.                     stoppedPeriodList = getStopPeriodList
  3179.                         (stoppedPeriodList,trmtBean,stopResumeflag);
  3180.                 }
  3181.                 GOSIDebug.debugMessages("------getInjuryStoppedPeriodList (Out Patient)-------");
  3182.                 // this query returns the treatment periods with
  3183.                 // type out patient , this period also shd not be paid
  3184.                 sqlQuery =  " select STARTDATE, ENDDATE from " +
  3185.                             SITables.T_TREATMENT + " where TREATMENTSTATUS =? "+
  3186.                             " and TREATMENTTYPE = ? and INJURYID = ? "+
  3187.                             " and STARTDATE <= ? and ENDDATE >= ?";
  3188.  
  3189.                 ps = con.prepareStatement(sqlQuery);
  3190.                 if(isTreatmentApproved)
  3191.                 {
  3192.                     ps.setShort(1,OHConstants.TRMT_STS_APPROVED.shortValue());
  3193.                 }else
  3194.                 {
  3195.                     ps.setShort(1,OHConstants.TRMT_STS_ENTERED.shortValue());
  3196.                 }
  3197.                 ps.setShort(2,OHConstants.TRMT_TYPE_OUTPATIENT.shortValue());
  3198.                 ps.setLong(3,injuryBean.getInjuryID().longValue());
  3199.                 ps.setTimestamp(4,injuryBean.getBenefitEndDate());
  3200.                 ps.setTimestamp(5,injuryBean.getBenefitStartDate());
  3201.                 rs = ps.executeQuery();
  3202.                 while(rs.next())
  3203.                 {
  3204.                     TreatmentPeriodBean trmtBean = new TreatmentPeriodBean();
  3205.                     trmtBean.setStartDateGreg(rs.getTimestamp("STARTDATE"));
  3206.                     trmtBean.setEndDateGreg(rs.getTimestamp("ENDDATE"));
  3207.                     Byte stopResumeflag = OHConstants.STOP_ALLOWANCE_FLAG;
  3208.                     // this method will add the stopped period to the list
  3209.                     stoppedPeriodList = getStopPeriodList
  3210.                         (stoppedPeriodList,trmtBean,stopResumeflag);
  3211.  
  3212.                 }
  3213.                 GOSIDebug.debugMessages("------getInjuryStoppedPeriodList (Out Patient)-------");
  3214.                 GOSIDebug.debugMessages("\t\t End getInjuryStoppedPeriodList - MaintainOHAllowanceSessionEJB");
  3215.  
  3216.                 return stoppedPeriodList;
  3217.             }
  3218.             catch(GOSIException ge)
  3219.             {
  3220.                 throw ge;
  3221.             }
  3222.             catch(Exception e)
  3223.             {
  3224.                 throw new GOSIException();
  3225.             }
  3226.             finally
  3227.             {
  3228.                 GOSIUtilities.cleanUp(ps,rs);
  3229.             }
  3230.         }
  3231.  
  3232.  
  3233.  
  3234.     /**
  3235.     * @METHOD NAME              :   getAllowncePayablePeriodList
  3236.     * @INFORMATION              :   This method is to  get Allownce Payable Period
  3237.                                     List for injury
  3238.     * @PARAM                    :   class java.util.ArrayList,
  3239.                                     class java.util.ArrayList
  3240.     * @RETURN                   :   class java.util.ArrayList
  3241.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3242.     * @LAST MODIFIED BY         :
  3243.     * @LAST MODIFIED DATE       :
  3244.     **/
  3245.     private ArrayList getAllowncePayablePeriodList(ArrayList trmtList ,
  3246.         ArrayList actualStoppedList)throws GOSIException
  3247.     {
  3248.  
  3249.         try
  3250.         {
  3251.             // the below logic removes the stopped period from the
  3252.             // actual payable period
  3253.             ArrayList newTrmtList = new ArrayList();
  3254.             int l = -1;
  3255.             int trmtListSize = trmtList.size();
  3256.             int stoppedListSize = actualStoppedList.size();
  3257.             for(int i=0;i<stoppedListSize;i++)
  3258.             {
  3259.                 TreatmentPeriodBean stopBean = (TreatmentPeriodBean)
  3260.                     actualStoppedList.get(i);
  3261.                 for(int j=0;j<trmtListSize;j++)
  3262.                 {
  3263.                     TreatmentPeriodBean trmtBean =
  3264.                         (TreatmentPeriodBean)trmtList.get(j);
  3265.                     if(stopBean.getStartDateGreg().compareTo
  3266.                             (trmtBean.getStartDateGreg())>=0 &&
  3267.                         stopBean.getStartDateGreg().compareTo
  3268.                             (trmtBean.getEndDateGreg())<=0 )
  3269.                     {
  3270.                         if(l==j)
  3271.                         {
  3272.                             trmtBean.setStartDateGreg(GOSIUtilities.getNextDate
  3273.                                 (((TreatmentPeriodBean)newTrmtList.
  3274.                                 get(newTrmtList.size()-1)).getEndDateGreg()));
  3275.                         }
  3276.                         l=j;
  3277.                         if(stopBean.getStartDateGreg().compareTo
  3278.                             (trmtBean.getStartDateGreg())==0 &&
  3279.                         stopBean.getEndDateGreg().compareTo
  3280.                             (trmtBean.getEndDateGreg())==0 )
  3281.                         {
  3282.                             trmtBean =null;
  3283.                             break;
  3284.                         }else
  3285.                         if((stopBean.getStartDateGreg().compareTo
  3286.                             (trmtBean.getStartDateGreg())==0 &&
  3287.                         stopBean.getEndDateGreg().compareTo
  3288.                             (trmtBean.getEndDateGreg())<0 ))
  3289.                         {
  3290.                                 trmtBean.setStartDateGreg(GOSIUtilities.
  3291.                                     getNextDate(stopBean.getEndDateGreg()));
  3292.                                 newTrmtList.add(trmtBean);
  3293.                                 break;
  3294.                         }
  3295.                         else
  3296.                         if((stopBean.getStartDateGreg().compareTo
  3297.                             (trmtBean.getStartDateGreg())>0 &&
  3298.                         stopBean.getEndDateGreg().compareTo
  3299.                             (trmtBean.getEndDateGreg())==0 ))
  3300.                         {
  3301.                                 trmtBean.setEndDateGreg
  3302.                                     (OHUtilities.getPrevDate
  3303.                                     (stopBean.getStartDateGreg()));
  3304.  
  3305.                                 newTrmtList.add(trmtBean);
  3306.                                 break;
  3307.                         }
  3308.                         else
  3309.                         if((stopBean.getStartDateGreg().compareTo
  3310.                             (trmtBean.getStartDateGreg())>0 &&
  3311.                         stopBean.getEndDateGreg().compareTo
  3312.                             (trmtBean.getEndDateGreg())<0 ))
  3313.                         {
  3314.                             TreatmentPeriodBean newTrmtBean =
  3315.                                 new TreatmentPeriodBean(trmtBean);
  3316.                             trmtBean.setEndDateGreg
  3317.                                 (OHUtilities.getPrevDate
  3318.                                     (stopBean.getStartDateGreg()));
  3319.                             newTrmtBean.setStartDateGreg
  3320.                                 (GOSIUtilities.getNextDate
  3321.                                     (stopBean.getEndDateGreg()));
  3322.                             newTrmtList.add(trmtBean);
  3323.                             newTrmtList.add(newTrmtBean);
  3324.                             break;
  3325.                         }else if(stopBean.getEndDateGreg().compareTo
  3326.                             (trmtBean.getEndDateGreg())>0)
  3327.                         {
  3328.                             if((stopBean.getStartDateGreg().compareTo
  3329.                                 (trmtBean.getStartDateGreg())>0))
  3330.                             {
  3331.                                 trmtBean.setEndDateGreg(OHUtilities.getPrevDate
  3332.                                     (stopBean.getStartDateGreg()));
  3333.                                 newTrmtList.add(trmtBean);
  3334.                             }else
  3335.                             if(stopBean.getStartDateGreg().compareTo
  3336.                                 (trmtBean.getStartDateGreg())==0)
  3337.                             {
  3338.                                 trmtBean = null;
  3339.                             }
  3340.                             for (int k=j;k<trmtListSize ;k++ )
  3341.                             {
  3342.                                 TreatmentPeriodBean tempTrmtBean =
  3343.                                   (TreatmentPeriodBean)actualStoppedList.get(k);
  3344.  
  3345.                                 if(stopBean.getEndDateGreg().compareTo
  3346.                                     (tempTrmtBean.getStartDateGreg())>=0 &&
  3347.                                 stopBean.getEndDateGreg().compareTo
  3348.                                     (tempTrmtBean.getEndDateGreg())<=0 )
  3349.                                 {
  3350.                                     if(stopBean.getEndDateGreg().compareTo
  3351.                                         (tempTrmtBean.getEndDateGreg())==0)
  3352.                                     {
  3353.                                         tempTrmtBean = null;
  3354.                                     }else if(stopBean.getEndDateGreg().compareTo
  3355.                                         (tempTrmtBean.getEndDateGreg())<=0)
  3356.                                     {
  3357.                                         tempTrmtBean.setStartDateGreg
  3358.                                             (GOSIUtilities.getNextDate
  3359.                                                 (stopBean.getEndDateGreg()));
  3360.                                         newTrmtList.add(tempTrmtBean);
  3361.                                     }
  3362.                                     break;
  3363.                                 }
  3364.                             }
  3365.                             break;
  3366.                         }
  3367.                     }
  3368.                 }
  3369.             }
  3370.             return newTrmtList;
  3371.         }
  3372.         catch(GOSIException ge)
  3373.         {
  3374.             GOSIDebug.debugMessages("session-getAllowncePayablePeriodList:ge:"+ge);
  3375.             throw ge;
  3376.         }
  3377.         catch(Exception e)
  3378.         {
  3379.             GOSIDebug.debugMessages("session-getAllowncePayablePeriodList:e:"+e);
  3380.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3381.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3382.                 "getAllowncePayablePeriodList()",e,"CMN_ERR_1000");
  3383.         }
  3384.     }
  3385.  
  3386.     /**
  3387.     * @METHOD NAME              :   getUniqueTreatmentIdLists
  3388.     * @INFORMATION              :   This method is to  get Unique Treatment Id Lists
  3389.     * @PARAM                    :   class java.util.ArrayList
  3390.     * @RETURN                   :   class java.util.ArrayList
  3391.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3392.     * @LAST MODIFIED BY         :
  3393.     * @LAST MODIFIED DATE       :
  3394.     **/
  3395.     private ArrayList getUniqueTreatmentIdLists(ArrayList trmtList)
  3396.         throws GOSIException
  3397.     {
  3398.         try
  3399.         {
  3400.             // the below logic get the unique treatmentids in the treatment list
  3401.             // and return the an array list with the unique ids
  3402.             int trmtListSize=trmtList.size();
  3403.             ArrayList uniqueTrmtList = new ArrayList();
  3404.             for(int i=0;i<trmtListSize;i++)
  3405.             {
  3406.                 TreatmentPeriodBean trmtBean=
  3407.                     (TreatmentPeriodBean)trmtList.get(i);
  3408.                 Long trmtId = trmtBean.getTreatmentId();
  3409.                 boolean trmtIdPresent = true;
  3410.                 for(int j=0;j<uniqueTrmtList.size();j++)
  3411.                 {
  3412.                     TreatmentPeriodBean tempTrmtBean=
  3413.                         (TreatmentPeriodBean)uniqueTrmtList.get(j);
  3414.                     Long trmpTrmtId = tempTrmtBean.getTreatmentId();
  3415.                     if(trmpTrmtId.equals(trmtId))
  3416.                     {
  3417.                         trmtIdPresent = false;
  3418.                         break;
  3419.                     }
  3420.                 }
  3421.                 if(trmtIdPresent)
  3422.                 {
  3423.                     uniqueTrmtList.add(trmtBean);
  3424.                 }
  3425.             }
  3426.             return uniqueTrmtList;
  3427.         }
  3428.         catch(Exception e)
  3429.         {
  3430.             GOSIDebug.debugMessages("session-getUniqueTreatmentIdLists:e:"+e);
  3431.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3432.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3433.                 "getUniqueTreatmentIdLists()",e,"CMN_ERR_1000");
  3434.         }
  3435.     }
  3436.  
  3437.  
  3438.  
  3439.     /**
  3440.     * @METHOD NAME              :   isValidVisitDate
  3441.     * @INFORMATION              :   This method is to  validate Visit Date
  3442.     * @PARAM                    :   class java.util.ArrayList,
  3443.                                     class gosi.business.socialinsurance.occupationalhazards.injury.beans.VisitBean
  3444.     * @RETURN                   :   boolean
  3445.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3446.     * @LAST MODIFIED BY         :
  3447.     * @LAST MODIFIED DATE       :
  3448.     **/
  3449.         private boolean isValidVisitDate(ArrayList stopPeriodList,
  3450.             VisitBean visitBean)throws GOSIException
  3451.         {
  3452.             try
  3453.             {
  3454.                 // the below logic checks wether a vist falls on the
  3455.                 // stopped or resumed period if falls on stopped period return false
  3456.                 Timestamp visitDate = visitBean.getDateOfVisitGreg();
  3457.                 Long visitInjuryId = visitBean.getInjuryId();
  3458.                 int stopPeriodListSize = stopPeriodList.size();
  3459.                 boolean isValidVisitflag = true;
  3460.                 for(int i=0;i<stopPeriodListSize;i++)
  3461.                 {
  3462.                     TreatmentPeriodBean trmtBean =
  3463.                         (TreatmentPeriodBean)stopPeriodList.get(i);
  3464.                     if(visitDate.compareTo(trmtBean.getStartDateGreg())>=0 &&
  3465.                         visitDate.compareTo(trmtBean.getEndDateGreg())<=0 &&
  3466.                         visitInjuryId.equals(trmtBean.getInjuryId()))
  3467.                     {
  3468.                         isValidVisitflag = false;
  3469.                         break;
  3470.                     }
  3471.                 }
  3472.                 return isValidVisitflag;
  3473.             }
  3474.             catch(Exception e)
  3475.             {
  3476.                 GOSIDebug.debugMessages("session-isValidVisitDate:e:"+e);
  3477.                 throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3478.                     GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3479.                     "isValidVisitDate()",e,"CMN_ERR_1000");
  3480.             }
  3481.  
  3482.         }
  3483.  
  3484.     /**
  3485.     * @METHOD NAME              :   isValidcompanionDate
  3486.     * @INFORMATION              :   This method is to Validate companion Dates
  3487.     * @PARAM                    :   class java.util.ArrayList,
  3488.                                     class java.sql.Timestamp
  3489.     * @RETURN                   :   boolean
  3490.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3491.     * @LAST MODIFIED BY         :
  3492.     * @LAST MODIFIED DATE       :
  3493.     **/
  3494.         private boolean isValidcompanionDate(ArrayList stopPeriodList,
  3495.             Timestamp companionDate)throws GOSIException
  3496.         {
  3497.             try
  3498.             {
  3499.                 // the below logic checks wether a companion dates falls on the
  3500.                 // stopped or resumed period if falls on stopped period return false
  3501.                 int stopPeriodListSize = stopPeriodList.size();
  3502.                 boolean isValidVisitflag = true;
  3503.                 for(int i=0;i<stopPeriodListSize;i++)
  3504.                 {
  3505.                     TreatmentPeriodBean trmtBean =
  3506.                         (TreatmentPeriodBean)stopPeriodList.get(i);
  3507.                     if(companionDate.compareTo(trmtBean.getStartDateGreg())>=0
  3508.                      && companionDate.compareTo(trmtBean.getEndDateGreg())<=0 )
  3509.                     {
  3510.                         isValidVisitflag = false;
  3511.                         break;
  3512.                     }
  3513.                 }
  3514.                 return isValidVisitflag;
  3515.             }
  3516.             catch(Exception e)
  3517.             {
  3518.                 GOSIDebug.debugMessages("session-isValidVisitDate:e:"+e);
  3519.                 throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3520.                     GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3521.                     "isValidcompanionDate()",e,"CMN_ERR_1000");
  3522.             }
  3523.  
  3524.         }
  3525.  
  3526.  
  3527.     /**
  3528.     * @METHOD NAME              :   changeDates
  3529.     * @INFORMATION              :   This method is to  change Dates to the user formats
  3530.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  3531.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  3532.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3533.     * @LAST MODIFIED BY         :
  3534.     * @LAST MODIFIED DATE       :
  3535.     **/
  3536.     public InjuryPopDetails changeDates(InjuryPopDetails injuryDetails)
  3537.         throws GOSIException
  3538.     {
  3539.         long startTime   = 0;
  3540.         long endTime     = 0;
  3541.         long elapsedTime = 0;
  3542.         startTime = System.currentTimeMillis();
  3543.         try
  3544.         {
  3545.             // this method converts the date entered as string into the
  3546.             // gregorian format injury date , bnefit start and enddates are converted
  3547.             Timestamp injuryDate =null;
  3548.             Timestamp benefitEndDate =null;
  3549.             Timestamp benefitStartDate =null;
  3550.             if(injuryDetails.getInjuryDateStr()!=null &&
  3551.                 !("").equals(injuryDetails.getInjuryDateStr()))
  3552.             {
  3553.                 if(OHConstants.HIJRAH.equals
  3554.                     (injuryDetails.getInjuryDateEntFmt()))
  3555.                 {
  3556.                     injuryDate=GOSIUtilities.getTimestamp
  3557.                         (GOSIDateUtilities.convertToGregorian
  3558.                             (injuryDetails.getInjuryDateStr()));
  3559.                 }else
  3560.                 {
  3561.                     injuryDate = GOSIUtilities.getTimestamp(
  3562.                         injuryDetails.getInjuryDateStr());
  3563.                 }
  3564.                 injuryDetails.setInjuryDate(injuryDate);
  3565.             }
  3566.             if(injuryDetails.getBenefitEndDateStr()!=null &&
  3567.                 !("").equals(injuryDetails.getBenefitEndDateStr()))
  3568.             {
  3569.                 if(OHConstants.HIJRAH.equals
  3570.                     (injuryDetails.getBenefitEndDateEntFmt()))
  3571.                 {
  3572.                     benefitEndDate=GOSIUtilities.getTimestamp
  3573.                         (GOSIDateUtilities.convertToGregorian
  3574.                             (injuryDetails.getBenefitEndDateStr()));
  3575.                 }else
  3576.                 {
  3577.                     benefitEndDate = GOSIUtilities.getTimestamp(
  3578.                         injuryDetails.getBenefitEndDateStr());
  3579.                 }
  3580.                 injuryDetails.setBenefitEndDate( benefitEndDate);
  3581.             }
  3582.             if(injuryDetails.getBenefitStartDateStr()!=null&&
  3583.                 !("").equals(injuryDetails.getBenefitStartDateStr()))
  3584.             {
  3585.  
  3586.                 if(OHConstants.HIJRAH.equals
  3587.                     (injuryDetails.getBenefitStartDateEntFmt()))
  3588.                 {
  3589.                     benefitStartDate=GOSIUtilities.getTimestamp
  3590.                         (GOSIDateUtilities.convertToGregorian
  3591.                             (injuryDetails.getBenefitStartDateStr()));
  3592.                 }else
  3593.                 {
  3594.                     benefitStartDate = GOSIUtilities.getTimestamp(
  3595.                         injuryDetails.getBenefitStartDateStr());
  3596.                 }
  3597.                injuryDetails.setBenefitStartDate( benefitStartDate);
  3598.             }
  3599.             endTime = System.currentTimeMillis();
  3600.             elapsedTime = endTime - startTime;
  3601.             GOSIInstrumentationLog.writeInstrumentationToLog(
  3602.                     this.getClass().toString(),
  3603.                     "changeDates()",
  3604.                     elapsedTime);
  3605.             return injuryDetails;
  3606.         }catch(GOSIException ge)
  3607.         {
  3608.             GOSIDebug.debugMessages("session-changeDates : ge:"+ge);
  3609.             throw ge;
  3610.         }catch(Exception e)
  3611.         {
  3612.             GOSIDebug.debugMessages("session-changeDates :The exception is "+e);
  3613.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3614.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3615.                 "changeDates()",e,"CMN_ERR_1000");
  3616.         }
  3617.  
  3618.     }
  3619.  
  3620.  
  3621.     /**
  3622.     * @METHOD NAME              :   changeBenefitDates
  3623.     * @INFORMATION              :   This method is to  change Benefit Dates to the user formats
  3624.     * @PARAM                    :   class java.util.ArrayList,
  3625.                                     class java.lang.String
  3626.     * @RETURN                   :   class java.util.ArrayList
  3627.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3628.     * @LAST MODIFIED BY         :
  3629.     * @LAST MODIFIED DATE       :
  3630.     **/
  3631.     public ArrayList changeBenefitDates(ArrayList benefitList ,
  3632.         String entryFormat) throws GOSIException
  3633.     {
  3634.         GOSIDebug.debugMessages("-------changeBenefitDates-------");
  3635.         GOSIDebug.debugMessages("EntFmt:"+entryFormat);
  3636.         long startTime   = 0;
  3637.         long endTime     = 0;
  3638.         long elapsedTime = 0;
  3639.         startTime = System.currentTimeMillis();
  3640.         // this method converts the time stamp dates generated to string of the specifed format
  3641.         // bnefit start and enddates in the generated benefit list are converted
  3642.  
  3643.         try
  3644.         {int listSize = benefitList.size();
  3645.             for(int i=0;i<listSize;i++)
  3646.             {
  3647.                 OHAllowanceBean benefitBean=(OHAllowanceBean)benefitList.get(i);
  3648.                 if(OHConstants.HIJRAH.equals(entryFormat))
  3649.                 {
  3650.                     benefitBean.setBenStDateStr
  3651.                         (GOSIDateUtilities.convertToHijra(
  3652.                                 GOSIUtilities.getDateFullString
  3653.                                     (benefitBean.getBenStDateGreg())));
  3654.                 }
  3655.                 else
  3656.                 {
  3657.                     benefitBean.setBenStDateStr
  3658.                         (GOSIUtilities.getDateFullString(
  3659.                             benefitBean.getBenStDateGreg()));
  3660.                 }
  3661.                 benefitBean.setBenStDateEntFmt(entryFormat);
  3662.                 if(OHConstants.HIJRAH.equals(entryFormat))
  3663.                 {
  3664.                     benefitBean.setBenEndDateStr
  3665.                         (GOSIDateUtilities.convertToHijra(
  3666.                                 GOSIUtilities.getDateFullString(
  3667.                                 benefitBean.getBenEndDateGreg())));
  3668.  
  3669.                 }
  3670.                 else
  3671.                 {
  3672.                     benefitBean.setBenEndDateStr
  3673.                         (GOSIUtilities.getDateFullString(
  3674.                             benefitBean.getBenEndDateGreg()));
  3675.                 }
  3676.                 benefitBean.setBenEndDateEntFmt(entryFormat)  ;
  3677.             }
  3678.             endTime = System.currentTimeMillis();
  3679.             elapsedTime = endTime - startTime;
  3680.             GOSIInstrumentationLog.writeInstrumentationToLog(
  3681.                 this.getClass().toString(),
  3682.                 "changeBenefitDates()",
  3683.                 elapsedTime);
  3684.  
  3685.         return benefitList;
  3686.         }catch(GOSIException ge)
  3687.         {
  3688.             throw ge;
  3689.         }catch(Exception e)
  3690.         {
  3691.             GOSIDebug.debugMessages("session-changeDates :The exception is "+e);
  3692.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3693.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3694.                 "changeBenefitDates()",e,"CMN_ERR_1000");
  3695.         }
  3696.     }
  3697.  
  3698.  
  3699.     /**
  3700.      * @return
  3701.      *
  3702.      */
  3703.  
  3704.  
  3705.     /**
  3706.     * @METHOD NAME              :   calculateOHAllowance
  3707.     * @INFORMATION              :   This method is to calculate OH Allowance
  3708.     * @PARAM                    :   class java.util.ArrayList
  3709.                                     boolean
  3710.     * @RETURN                   :   class java.util.ArrayList
  3711.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3712.     * @LAST MODIFIED BY         :
  3713.     * @LAST MODIFIED DATE       :
  3714.     **/
  3715.     public ArrayList calculateOHAllowance(ArrayList injuryList,boolean isTreatmentApproved)
  3716.         throws GOSIException
  3717.     {
  3718.         GOSIDebug.debugMessages("\t\t Start calculateOHAllowance - MaintainOHAllowanceSessionEJB");
  3719.  
  3720.         long startTime   = 0;
  3721.         long endTime     = 0;
  3722.         long elapsedTime = 0;
  3723.         startTime = System.currentTimeMillis();
  3724.         String calenderType = "";
  3725.  
  3726.         ArrayList benefitList = new ArrayList();
  3727.         try
  3728.         {          
  3729.             // this method is called from the OHAllowanceServlet to calculate oh benefit
  3730.             // for the contributor, the injury list contains details of injury
  3731.             // and the benefit period and the boolean flag determining to
  3732.             // calculate benefit for approved or unapporved trmeatment periods
  3733.             con = GOSIUtilities.getConnection (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  3734.  
  3735.             if (!isTreatmentApproved)
  3736.             {
  3737.                 // injury details from servlet
  3738.                 InjuryPopDetails injuryDetails  = (InjuryPopDetails) injuryList.remove (0);
  3739.  
  3740.                 // get current injury details
  3741.                 InjuryPopDetails injuryBean     = getInjuryBean (injuryDetails.getInjuryID());
  3742.  
  3743.                 injuryBean.setBenefitStartDate          (injuryDetails.getBenefitStartDate());
  3744.                 injuryBean.setBenefitStartDateStr       (injuryDetails.getBenefitStartDateStr());
  3745.                 injuryBean.setBenefitStartDateEntFmt    (injuryDetails.getBenefitStartDateEntFmt());
  3746.                 injuryBean.setBenefitEndDate            (injuryDetails.getBenefitEndDate());
  3747.                 injuryBean.setBenefitEndDateStr         (injuryDetails.getBenefitEndDateStr());
  3748.                 injuryBean.setBenefitEndDateEntFmt      (injuryDetails.getBenefitEndDateEntFmt());
  3749.  
  3750.                 if (injuryBean.getInjuryStatus().equals(OHConstants.INJ_STS_NOTIFIED))
  3751.                 {
  3752.                     // UnApproved Injury Details found for the
  3753.                     // period entered, Please redefine your calculation period
  3754.                     // or Approve the Injury record
  3755.                     throw new GOSIException (GOSIConstants.SEVERITY_FOUR,
  3756.                                              GOSIConstants.OCCUPATIONAL_HAZARDS,
  3757.                                              this.getClass().toString(),
  3758.                                              "calculateOHAllowance()",
  3759.                                              null,
  3760.                                              "SOI_ERR_5189");
  3761.                 }
  3762.  
  3763.                 // comparing end date with current date
  3764.                 if (injuryBean.getBenefitEndDate().compareTo(new Timestamp(System.currentTimeMillis())) > 0)
  3765.                 {
  3766.                     throw new GOSIException (GOSIConstants.SEVERITY_THREE,
  3767.                                              GOSIConstants.OCCUPATIONAL_HAZARDS,
  3768.                                              this.getClass().toString(),
  3769.                                              "calculateOHAllowance()",
  3770.                                              null,
  3771.                                              "SOI_ERR_4189");
  3772.                 }
  3773.  
  3774.                 //comparing startdate with end date
  3775.                 if (injuryBean.getBenefitStartDate().compareTo(injuryBean.getBenefitEndDate()) > 0)
  3776.                 {
  3777.                     throw new GOSIException (GOSIConstants.SEVERITY_THREE,
  3778.                                              GOSIConstants.OCCUPATIONAL_HAZARDS,
  3779.                                              this.getClass().toString(),
  3780.                                              "calculateOHAllowance()",
  3781.                                              null,
  3782.                                              "SOI_ERR_4190");
  3783.                 }
  3784.  
  3785.                 // getting contributor and establishment details
  3786.                 injuryBean = setContributorDetails (injuryBean);
  3787.                 injuryBean = setEstablishmentDetails (injuryBean);
  3788.  
  3789.                 //setting injury date to complication date
  3790.                 // if complication date is not null and
  3791.                 // the person is having a valid engagement on complication date
  3792.                 Timestamp injuryDate = injuryBean.getInjuryDate();
  3793.  
  3794.                 if (injuryBean.getComplicationDate() != null)
  3795.                 {
  3796.                     if (injuryBean.getIsEngagementPresentOnComplicationAndEligibleForOH())
  3797.                     {
  3798.                         injuryDate = injuryBean.getComplicationDate();
  3799.                     }
  3800.                     //setting wage for the injured engagement
  3801.                     injuryBean = setTotalConWage(injuryDate, injuryBean);
  3802.                 }
  3803.                 else
  3804.                 {
  3805.                     //setting wage for the injured engagement
  3806.                     injuryBean = setTotalConWage(injuryDate, injuryBean);
  3807.                 }
  3808.  
  3809.                 // store injury bean back into list
  3810.                 injuryList.add (0, injuryBean);
  3811.  
  3812.                 // calculating the total contributory wage
  3813.                 injuryList = getTotalContributorWage (injuryList);
  3814.  
  3815.                 if (injuryBean.getTotalConWage() == null || injuryBean.getTotalConWage().doubleValue() == 0)
  3816.                 {
  3817.                     throw new GOSIException (GOSIConstants.SEVERITY_TWO,
  3818.                                              GOSIConstants.SOCIAL_INSURANCE,
  3819.                                              this.getClass().toString(),
  3820.                                              "calculateOHAllowance()",
  3821.                                              null,
  3822.                                              "SOI_ERR_5559");
  3823.                 }
  3824.             }
  3825.  
  3826.             calenderType = getCalendarType(injuryList);
  3827.             int injuryListSize = injuryList.size();
  3828.             InjuryPopDetails injuryDetails = (InjuryPopDetails)injuryList.get(0);
  3829.             String entFmt = injuryDetails.getBenefitStartDateEntFmt();
  3830.             Long socInsNumber = injuryDetails.getSocialInsuranceNumber();
  3831.             Timestamp startDate = null;
  3832.             Timestamp endDate   = null;
  3833.             ArrayList totalPayablePeriodList = new ArrayList();
  3834.  
  3835.             // Logic for getting the treatment period list for which
  3836.             // benfit is to be calculated
  3837.             GOSIDebug.debugMessages("injuryListSize:" + injuryListSize +":" );
  3838.             for(int i=0;i<injuryListSize;i++)
  3839.             {
  3840.                 InjuryPopDetails injuryBean = (InjuryPopDetails)injuryList.get(i);
  3841.                 Long injuryId = injuryBean.getInjuryID();
  3842.                 startDate = injuryBean.getBenefitStartDate();
  3843.                 endDate = injuryBean.getBenefitEndDate();
  3844.                 ArrayList periodList = null;
  3845.                 ArrayList stoppedList = null;
  3846.                 ArrayList payablePeriodList = null;
  3847.                 periodList = getTreatmentPeriodList(injuryBean,isTreatmentApproved);
  3848.                 GOSIDebug.debugMessages("PeriodListSize:" + periodList.size());
  3849.                 if(periodList != null)
  3850.                 {
  3851.                     stoppedList = getInjuryStoppedPeriodList(injuryBean,isTreatmentApproved);
  3852.                     GOSIDebug.debugMessages("StoppedListSize:" + stoppedList.size());
  3853.                     payablePeriodList = getPayablePeriodList
  3854.                                             (periodList,stoppedList);
  3855.                     GOSIDebug.debugMessages("PayablePeriodListSize:" + payablePeriodList.size());
  3856.                 }
  3857.                 int payablePeriodListSize = payablePeriodList.size();
  3858.                 for (int j=0;j<payablePeriodListSize;j++)
  3859.                 {
  3860.                     totalPayablePeriodList.add(payablePeriodList.get(j));
  3861.                 }
  3862.             }
  3863.             // for each of the valid days the trmt type is set
  3864.             // so at the end this logic we get a list of days for which the
  3865.             // benefit is to be calculated
  3866.                 ArrayList daysList = new ArrayList();
  3867.                 startDate = injuryDetails.getBenefitStartDate();
  3868.                 endDate = injuryDetails.getBenefitEndDate();
  3869.                 GOSIDebug.debugMessages("StartDate :" + startDate + " EndDate:" + endDate);
  3870.                 int noDays = OHUtilities.getDays(startDate,endDate);
  3871.                 Timestamp trmtDate = startDate;
  3872.                 GOSIDebug.debugMessages("TotalPayableListSize:" + totalPayablePeriodList.size() + ":TotalDays:" + noDays +":");
  3873.                 for (int i=0; i<noDays ; i++)
  3874.                 {
  3875.                     TreatmentPeriodBean trmtBean = getTrmtDetailsforDate
  3876.                                             (trmtDate,totalPayablePeriodList);
  3877.                     if(trmtBean != null)
  3878.                     {
  3879.                         daysList.add(trmtBean);
  3880.                     }
  3881.                     trmtDate = GOSIUtilities.getNextDate(trmtDate);
  3882.                 }
  3883.                 GOSIDebug.debugMessages("DaysListSize:" + daysList.size());
  3884.                 for (int i=0; i<daysList.size() ; i++)
  3885.                 {
  3886.                     GOSIDebug.debugMessages("Date:" + ((TreatmentPeriodBean)daysList.get(i)).getStartDateGreg());
  3887.                 }
  3888.  
  3889.                 //ArrayList payablePeriodList = getBenefitPayableTrmtList(totalPayablePeriodList);
  3890.  
  3891.                 // this method converts back the days list into period lists
  3892.                 ArrayList payablePeriodList = getBenefitPayableTrmtList(daysList);
  3893.  
  3894.                 // this method calculates the daily allowace for the period
  3895.                 ArrayList dailyAllowanceList =
  3896.                     calculateDailyAllowance(injuryList,payablePeriodList,isTreatmentApproved);
  3897.                 //GOSIDebug.debugMessages("DailyAllowance LIST:" + dailyAllowanceList.size());
  3898.                 // this method calculate the vists for the period
  3899.                 ArrayList visitList =
  3900.                     calculateConveyenceAllowance(injuryList,false,isTreatmentApproved);
  3901.                 //GOSIDebug.debugMessages("ConveyenceAllowance LIST:" + visitList.size());
  3902.                 // this method calculates the companion allowance for the period
  3903.                 ArrayList companionList =
  3904.                     calculateCompanionAllowance(injuryList,false,isTreatmentApproved);
  3905.                 //GOSIDebug.debugMessages("CompanionAllowance LIST:" + companionList.size());
  3906.                 GOSIDebug.debugMessages("DailyAllowance LIST:" + dailyAllowanceList.size());
  3907.                 GOSIDebug.debugMessages("ConveyenceAllowance LIST:" + visitList.size());
  3908.                 GOSIDebug.debugMessages("CompanionAllowance LIST:" + companionList.size());
  3909.  
  3910.                 // if the person can get the oh benefit his daily allowance is
  3911.                 // added to the benefit list else only the other allowances are paid
  3912.                 if(this.canAvailBenefitdueToDisablity(socInsNumber))
  3913.                 {
  3914.                     benefitList = addToBenefitList(benefitList,dailyAllowanceList);
  3915.                 }
  3916.                 // adding vists to benefit list
  3917.                 benefitList = addToBenefitList(benefitList,visitList);
  3918.                 // adding companinon allowance to benefit list
  3919.                 benefitList = addToBenefitList(benefitList,companionList);
  3920.                 GOSIDebug.debugMessages("---------calculateOHAllowance*----------");
  3921.                 // changing the date of benefit list to users entry format
  3922.                 benefitList = changeBenefitDates(benefitList,entFmt);
  3923.                 for(int i=0;i<benefitList.size();i++)
  3924.                 {
  3925.                     OHAllowanceBean benefitBean =
  3926.                         (OHAllowanceBean)benefitList.get(i);
  3927.                     // setting injury number for each benefit
  3928.                     benefitBean.setInjuryNumber
  3929.                         (getInjuryNumber(injuryList,benefitBean.getInjuryId()));
  3930.                 }
  3931.                 GOSIDebug.debugMessages("---------calculateWorkerEmployerBenefitList----------");
  3932.                 if(injuryList.size()== 1)
  3933.                 {
  3934.                     // corercting the period for which to pay to employer and to contributor
  3935.                     GOSIDebug.debugMessages("BenefitList size before calling calculateWorkerEmployerBenefitList:" + benefitList.size() + ":");
  3936.                     benefitList = calculateWorkerEmployerBenefitList
  3937.                         (benefitList,injuryList);
  3938.  
  3939.                 //if contributor is working in more than one establishemnt then
  3940.                 //distribute total amount based on each establishment's wage.
  3941.                     benefitList = distributeWageToEstablishments(
  3942.                         benefitList,injuryList);
  3943.                 }
  3944.                 // checking if the single visit is already paid or not
  3945.                 // if paid it will throw an error
  3946.                 isDuplicateSingleVisit(benefitList);
  3947.                
  3948.                
  3949.                 endTime = System.currentTimeMillis();
  3950.                 elapsedTime = endTime - startTime;
  3951.                 GOSIInstrumentationLog.writeInstrumentationToLog(
  3952.                     this.getClass().toString(),
  3953.                     "calculateOHAllowance()",
  3954.                     elapsedTime);
  3955.                 GOSIDebug.debugMessages("\t\t End calculateOHAllowance - MaintainOHAllowanceSessionEJB");
  3956.                 return benefitList;    
  3957.  
  3958.         }
  3959.         catch(GOSIException ge)
  3960.         {
  3961.             GOSIDebug.debugMessages("session-calculateOHAllowance :ge:"+ge);
  3962.             throw ge;
  3963.         }catch(Exception e)
  3964.         {
  3965.             GOSIDebug.debugMessages("session-calculateOHAllowance :e:"+e);
  3966.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  3967.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  3968.                 "calculateOHAllowance()",e,"CMN_ERR_1000");
  3969.         }
  3970.         finally
  3971.         {
  3972.             GOSIDebug.debugMessages("connection Closed");
  3973.             GOSIUtilities.cleanUp(con);
  3974.         }
  3975.     }
  3976.  
  3977.     /**
  3978.     * @METHOD NAME              :   recalculateBenefitDetails
  3979.     * @INFORMATION              :   This method is to recalculate benefit details
  3980.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.RecalculateBenefitInputBean,
  3981.                                     class gosi.core.workflow.beans.WorkflowParamBean
  3982.     * @RETURN                   :   void
  3983.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  3984.     * @LAST MODIFIED BY         :
  3985.     * @LAST MODIFIED DATE       :
  3986.     **/
  3987.     public void recalculateBenefitDetails (RecalculateBenefitInputBean recalculateBean, WorkflowParamBean workflowParamBean)
  3988.         throws GOSIException
  3989.     {
  3990.         /**
  3991.          *  Service method for recalculating benefit amounts for a given contributor following a change
  3992.          *  in his or her wage.
  3993.          *
  3994.          *  This process creates a new OH benefit for the given contributor accounting for the difference
  3995.          *  in recalculated benefit amounts. If the difference is negative, an employer/contributor
  3996.          *  recovery transaction is added to the workflow registry.
  3997.          *
  3998.          *  This functionality is already present in OH Batch 12. It was reimplemented here to fulfill a service
  3999.          *  requirement from the Registration department; See CQ PRD00007841.
  4000.          */
  4001.         try
  4002.         {
  4003.             con = GOSIUtilities.getConnection (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  4004.  
  4005.             /**
  4006.              *  Step 1: Compile list of OH benefits subject to recalculation
  4007.              */
  4008.             ArrayList   benefitList = getBenefitListAffectedByWageChange (recalculateBean.getContributorId (),
  4009.                                                                           recalculateBean.getFromDate (),
  4010.                                                                           recalculateBean.getToDate ());
  4011.  
  4012.             if (benefitList == null || benefitList.size () == 0)
  4013.             {
  4014.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): Could not find any benefits affected by wage change for given contributor (contributor id: " + recalculateBean.getContributorId () + ")");
  4015.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): No further processing at this point");
  4016.  
  4017.                 return;
  4018.             }
  4019.             else
  4020.             {
  4021.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): Compiled benefit list has " + benefitList.size () + " element(s)");
  4022.             }
  4023.  
  4024.             /**
  4025.              *  Step 2: Compile list of injury records pertaining to OH benefit list compiled above
  4026.              */
  4027.             ArrayList   injuryList  = getInjuryListPertainingToBenefitRecalculation (benefitList,
  4028.                                                                                      recalculateBean.getEngagementId (),
  4029.                                                                                      recalculateBean.getWage (),
  4030.                                                                                      recalculateBean.getFromDate ());
  4031.  
  4032.             if (injuryList == null || injuryList.size () == 0)
  4033.             {
  4034.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): Could not retrieve injury details for the given contributor for injury records saved on " + recalculateBean.getFromDate () + " or later (contributor id: " + recalculateBean.getContributorId () + ", engagement id: " + recalculateBean.getEngagementId () + ")");
  4035.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): No further processing at this point");
  4036.  
  4037.                 return;
  4038.             }
  4039.             else
  4040.             {
  4041.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): Compiled injury record list has " + injuryList.size () + " element(s)");
  4042.             }
  4043.  
  4044.             /**
  4045.              *  Step 3: Recalculate and update OH benefits
  4046.              *
  4047.              *  Loop through the list of benefits affected by wage change and, in each loop iteration, recalculate the
  4048.              *  benefit amounts using provided wage data and update records accordingly.
  4049.              */
  4050.             Long    userId                  = new Long (workflowParamBean.getUserId ());
  4051.             String  calenderType            = getCalendarType (injuryList);
  4052.             Long    approvalWorkflowId      = GOSIUtilities.getPrimaryKey ("OHBNFTWORKFLOWID", userId);
  4053.             Long    recoveryWorkflowId      = GOSIUtilities.getPrimaryKey ("OHBNFTWORKFLOWID", userId);
  4054.  
  4055.             String  contributorName         = "";
  4056.             Long    socialInsuranceNumber   = null;
  4057.             Long    registrationNumber      = null;
  4058.             Short   destinationFieldOffice  = null;
  4059.  
  4060.             for (int i = 0; i < benefitList.size (); i++)
  4061.             {
  4062.                 InjuryPopDetails    injuryBean  = new InjuryPopDetails ();
  4063.                 OHAllowanceBean     benefitBean = (OHAllowanceBean) benefitList.get (i);
  4064.  
  4065.                 Timestamp startDate = benefitBean.getBenStDateGreg ();
  4066.                 Timestamp endDate   = benefitBean.getBenEndDateGreg ();
  4067.  
  4068.                 injuryBean.setBenefitStartDate  (benefitBean.getBenStDateGreg ());
  4069.                 injuryBean.setBenefitEndDate    (benefitBean.getBenEndDateGreg ());
  4070.  
  4071.                 injuryBean = getInjuryBean (injuryList, benefitBean.getInjuryId());
  4072.                 destinationFieldOffice = benefitBean.getFieldofficeCode();
  4073.  
  4074.                 Double totalConWage = injuryBean.getTotalConWage();
  4075.  
  4076.                 contributorName         = injuryBean.getName ();
  4077.                 socialInsuranceNumber   = injuryBean.getSocialInsuranceNumber ();
  4078.                 registrationNumber      = injuryBean.getRegistrationNumber ();
  4079.  
  4080.                 double changeAmount = totalConWage.doubleValue () - benefitBean.getTotalContWage ().doubleValue ();
  4081.  
  4082.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): Current contributor wage is " + totalConWage.doubleValue ());
  4083.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): Adjusted contributor wage is " + benefitBean.getTotalContWage ().doubleValue ());
  4084.  
  4085.                 benefitBean.setTotalContWage (new Double (changeAmount));
  4086.  
  4087.                 Long  injuryId      = benefitBean.getInjuryId ();
  4088.                 Short hospitalType  = getHospitalType (injuryId, startDate, endDate);
  4089.  
  4090.                 if (benefitBean.getBenStDateGreg ().compareTo (OHRuleBean.getNewLawApplicableDate ()) < 0 &&
  4091.                     benefitBean.getBenEndDateGreg ().compareTo (OHRuleBean.getNewLawApplicableDate ()) >= 0)
  4092.                 {
  4093.                     GOSIDebug.debugMessages ("recalculateBenefitDetails (): Recalculation is subject to former GOSI business that were applicable before " + OHRuleBean.getNewLawApplicableDate ());
  4094.  
  4095.                     OHAllowanceBean oldLawBean = new OHAllowanceBean (benefitBean);
  4096.                     OHAllowanceBean newLawBean = new OHAllowanceBean (benefitBean);
  4097.  
  4098.                     oldLawBean.setBenEndDateGreg (OHUtilities.getPrevDate (OHRuleBean.getNewLawApplicableDate ()));
  4099.                     newLawBean.setBenStDateGreg (OHRuleBean.getNewLawApplicableDate ());
  4100.  
  4101.                     if (OHConstants.HIJRAH.equals (calenderType))
  4102.                     {
  4103.                         oldLawBean = setDailyAllowanceHij (oldLawBean, hospitalType);
  4104.                         newLawBean = setDailyAllowanceHij (newLawBean, hospitalType);
  4105.                     }
  4106.                     else
  4107.                     {
  4108.                         oldLawBean = setDailyAllowanceGreg (oldLawBean, hospitalType);
  4109.                         newLawBean = setDailyAllowanceGreg (newLawBean, hospitalType);
  4110.                     }
  4111.  
  4112.                     double  totalAmount = oldLawBean.getBenAmount ().doubleValue ()
  4113.                                         + newLawBean.getBenAmount ().doubleValue ();
  4114.  
  4115.                     benefitBean.setBenAmount (new Double (totalAmount));
  4116.                 }
  4117.                 else
  4118.                 {
  4119.                     GOSIDebug.debugMessages ("recalculateBenefitDetails (): Recalculation is subject to current GOSI business rules applicable since " + OHRuleBean.getNewLawApplicableDate ());
  4120.  
  4121.                     if (OHConstants.HIJRAH.equals(calenderType))
  4122.                     {
  4123.                         benefitBean = setDailyAllowanceHij (benefitBean, hospitalType);
  4124.                     }
  4125.                     else
  4126.                     {
  4127.                         benefitBean = setDailyAllowanceGreg (benefitBean, hospitalType);
  4128.                     }
  4129.                 }
  4130.  
  4131.                 benefitBean.setTotalContWage        (totalConWage);
  4132.  
  4133.                 if (benefitBean.getBenAmount ().doubleValue () > 0)
  4134.                 {
  4135.                     benefitBean.setWorkflowId (approvalWorkflowId);
  4136.                 }
  4137.                 else if (benefitBean.getBenAmount ().doubleValue () < 0)
  4138.                 {
  4139.                     benefitBean.setWorkflowId (recoveryWorkflowId);
  4140.                 }
  4141.  
  4142.                 benefitBean.setBenStatus            (OHConstants.OH_BNFT_STS_ENTERED);
  4143.                 benefitBean.setWorkflowStatus       (OHConstants.WFS_OH_BNFT_ENTERED);
  4144.                 benefitBean.setCreatedBy            (userId);
  4145.                 benefitBean.setCreationTimestamp    (new Timestamp (System.currentTimeMillis ()));
  4146.                 benefitBean.setOhBenId              (GOSIUtilities.getPrimaryKey ("T_OHBENEFIT", userId));
  4147.  
  4148.                 if(benefitBean.getOhBenCode ().equals (OHConstants.OH_ALWNC_DAIlY_INPATIENT))
  4149.                 {
  4150.                     benefitBean.setOhBenCode (OHConstants.OH_ALWNC_DAILY_INPATIENT_ADJUSTMENT);
  4151.                     benefitBean.setOhBenType (GOSIUtilities.getDomainDesc("OH Benefit Type", OHConstants.OH_ALWNC_DAILY_INPATIENT_ADJUSTMENT.shortValue (), true));
  4152.                 }
  4153.                 else if(benefitBean.getOhBenCode ().equals (OHConstants.OH_ALWNC_DAIlY_OUTPATIENT))
  4154.                 {
  4155.                     benefitBean.setOhBenCode (OHConstants.OH_ALWNC_DAILY_OUTPATIENT_ADJUSTMENT);
  4156.                     benefitBean.setOhBenType (GOSIUtilities.getDomainDesc("OH Benefit Type", OHConstants.OH_ALWNC_DAILY_OUTPATIENT_ADJUSTMENT.shortValue (), true));
  4157.                 }
  4158.             }
  4159.  
  4160.             /**
  4161.              *  Step 4: Create OH Benefit for beneficiary
  4162.              *
  4163.              *  Insert a new benefit record for the beneficiary accounting for the difference amount
  4164.              *  due to recalculation. This benefit amount could be either positive or negative.
  4165.              */
  4166.             OHAllowanceEntityHome home = (OHAllowanceEntityHome)
  4167.                     ServiceLocator.getInstance ().getRemoteHome(
  4168.                                                     OHConstants.OH_ALLOWANCE_ENTITY_JNDI,
  4169.                                                     OHAllowanceEntityHome.class);
  4170.  
  4171.             boolean approvalNeeded = false;
  4172.             boolean recoveryNeeded = false;
  4173.  
  4174.             for (int i = 0; i < benefitList.size (); i++)
  4175.             {
  4176.                 OHAllowanceBean benefitBean = (OHAllowanceBean) benefitList.get (i);
  4177.  
  4178.                 if (benefitBean.getBenAmount ().doubleValue () > 0)
  4179.                 {
  4180.                     approvalNeeded = true;
  4181.                 }
  4182.                 else if (benefitBean.getBenAmount ().doubleValue () < 0)
  4183.                 {
  4184.                     recoveryNeeded = true;
  4185.  
  4186.                     benefitBean.setBenStatus      (OHConstants.OH_BNFT_STS_APPROVED);
  4187.                     benefitBean.setWorkflowStatus (OHConstants.WFS_OH_BNFT_APPROVED_OH_HEAD);
  4188.                 }
  4189.  
  4190.                 home.create (benefitBean);
  4191.             }
  4192.  
  4193.             /**
  4194.              *  Step 5: Complete recalculation process
  4195.              *
  4196.              *  Since recalculation may change benefit amount, it is necessary for this change to go through
  4197.              *  procedures to finalize such a change
  4198.              *
  4199.              */
  4200.             /**
  4201.              *  Step 5 (a): Start the approval transaction if an OH benefit having a postive amount was created
  4202.              */
  4203.             if (approvalNeeded)
  4204.             {
  4205.                 WorkflowParamBean approvalWorkflowBean  = new WorkflowParamBean ();
  4206.  
  4207.                 approvalWorkflowBean.setModuleId                (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  4208.                 approvalWorkflowBean.setUserId                  (userId.longValue ());
  4209.                 approvalWorkflowBean.setUserLocationId          (workflowParamBean.getUserLocationId ());
  4210.                 approvalWorkflowBean.setStepShortName           ("CALCULATE_OH_ALLWNC");
  4211.                 approvalWorkflowBean.setDestinationLocationId   (destinationFieldOffice.shortValue ());
  4212.                 approvalWorkflowBean.setrecordDescription       (GOSIErrorMessages.getErrorDesc ("SOI_ERR_5620") +  " - " + contributorName + " - " + socialInsuranceNumber);
  4213.                 approvalWorkflowBean.setRoutingCriterion        (GOSIConstants.COMPLETED);
  4214.                 approvalWorkflowBean.setPrimaryKeyOfTherecord   (approvalWorkflowId.toString ());
  4215.  
  4216.                 GOSIUtilities.startWorkflow (approvalWorkflowBean);
  4217.             }
  4218.  
  4219.             /**
  4220.              *  Step 5 (b): Recover amounts from parties if an OH benefit having a negative amount was created
  4221.              */
  4222.             if (recoveryNeeded)
  4223.             {
  4224.                 ArrayList recEmpList = new ArrayList ();
  4225.                 ArrayList recConList = new ArrayList ();
  4226.  
  4227.                 double recEmpAmount = 0.00;
  4228.                 double recConAmount = 0.00;
  4229.  
  4230.                 for (int i = 0; i < benefitList.size (); i++)
  4231.                 {
  4232.                     OHAllowanceBean benefitBean = (OHAllowanceBean) benefitList.get (i);
  4233.  
  4234.                     if (benefitBean.getBenAmount ().doubleValue () > 0)
  4235.                     {
  4236.                         continue;                           /* Omit recovering positive amounts */
  4237.                     }
  4238.  
  4239.                     if (OHConstants.OH_BNFT_PAY_TO_CON.equals (benefitBean.getBenefitPayableTo ()) ||
  4240.                         OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals (benefitBean.getBenefitPayableTo ()))
  4241.                     {
  4242.                         recConList.add (benefitBean);
  4243.  
  4244.                         recConAmount = recConAmount + Math.abs(benefitBean.getBenAmount ().doubleValue ());
  4245.                     }
  4246.                     else if (OHConstants.OH_BNFT_PAY_TO_EMP.equals (benefitBean.getBenefitPayableTo ()))
  4247.                     {
  4248.                         recEmpList.add (benefitBean);
  4249.  
  4250.                         recEmpAmount = recEmpAmount + Math.abs(benefitBean.getBenAmount ().doubleValue ());
  4251.                     }
  4252.                 }
  4253.  
  4254.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): Amount to be recovered from employer is " + recEmpAmount);
  4255.                 GOSIDebug.debugMessages ("recalculateBenefitDetails (): Amount to be recovered from contributor is " + recConAmount);
  4256.  
  4257.                 if (recEmpList.size () > 0)
  4258.                 {
  4259.                     Long recEmpWorkflowId   = GOSIUtilities.getPrimaryKey ("RECFROMEMPWORKFLOWID", userId);
  4260.                     Long recInjuryId        = null;
  4261.  
  4262.                     ArrayList recoverFromEmployerList = new ArrayList ();
  4263.  
  4264.                     for (int i = 0; i < recEmpList.size (); i++)
  4265.                     {
  4266.                         OHAllowanceBean benefitBean = (OHAllowanceBean) recEmpList.get (i);
  4267.  
  4268.                         recInjuryId = benefitBean.getInjuryId ();
  4269.  
  4270.                         RecEmployerBean recEmpBean  = new RecEmployerBean ();
  4271.  
  4272.                         recEmpBean.setRecID             (GOSIUtilities.getPrimaryKey ("T_RECFROMEMP", userId));
  4273.                         recEmpBean.setOhBenID           (benefitBean.getOhBenId ());
  4274.                         recEmpBean.setWorkFlowID        (recEmpWorkflowId);
  4275.                         recEmpBean.setEstablishmentID   (getEstablishmentId (benefitBean.getPartyCode (), injuryList));
  4276.  
  4277.                         if (benefitBean.getBenAmount () != null)
  4278.                         {
  4279.                             recEmpBean.setAmountDue (new Double (Math.abs(benefitBean.getBenAmount ().doubleValue ())));
  4280.                         }
  4281.                         else
  4282.                         {
  4283.                             recEmpBean.setAmountDue (new Double("0"));
  4284.                         }
  4285.  
  4286.                         recEmpBean.setAmountReceived    (new Double ("0"));
  4287.                         recEmpBean.setStatus            (OHConstants.REC_FROM_EMP_ENTERED);
  4288.                         recEmpBean.setRequestDate       (new Timestamp (System.currentTimeMillis ()));
  4289.                         recEmpBean.setRequestDateEntFmt (OHConstants.GREGORIAN);
  4290.                         recEmpBean.setWorkflowStatus    (OHConstants.REC_FROM_EMP_CLERK_ENT);
  4291.                         recEmpBean.setCreatedBy         (userId);
  4292.                         recEmpBean.setRecoveryType      (OHConstants.RECOVERY_TYPE_OH_BENEFIT);
  4293.                         recEmpBean.setInjuryId          (benefitBean.getInjuryId ());
  4294.                         recEmpBean.setCreationTimestamp (new Timestamp (System.currentTimeMillis ()));
  4295.                         recEmpBean.setLocationCode      (destinationFieldOffice);
  4296.  
  4297.                         recoverFromEmployerList.add (recEmpBean);
  4298.                     }
  4299.  
  4300.                     createRecFromEmp (recoverFromEmployerList);
  4301.  
  4302.                     WorkflowParamBean recoveryWorkflowBean = new WorkflowParamBean ();
  4303.  
  4304.                     recoveryWorkflowBean.setModuleId                (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  4305.                     recoveryWorkflowBean.setUserId                  (userId.longValue ());
  4306.                     recoveryWorkflowBean.setUserLocationId          (workflowParamBean.getUserLocationId ());
  4307.                     recoveryWorkflowBean.setStepShortName           ("REC_FROM_EMPLOYER");
  4308.                     recoveryWorkflowBean.setrecordDescription       (GOSIErrorMessages.getErrorDesc ("SOI_ERR_5621") + " - " + registrationNumber);
  4309.                     recoveryWorkflowBean.setDestinationLocationId   (destinationFieldOffice.shortValue ());
  4310.                     recoveryWorkflowBean.setRoutingCriterion        (GOSIConstants.COMPLETED);
  4311.                     recoveryWorkflowBean.setPrimaryKeyOfTherecord   (recEmpWorkflowId.toString () + "~" + recInjuryId.toString ());
  4312.  
  4313.                     GOSIUtilities.startWorkflow (recoveryWorkflowBean);
  4314.                 }
  4315.  
  4316.                 if (recConList.size () > 0)
  4317.                 {
  4318.                     ArrayList recoverContributorList = new ArrayList();
  4319.                     Long recConWorkflowId = GOSIUtilities.getPrimaryKey ("RECFROMCONWORKFLOWID", userId);
  4320.  
  4321.                     for (int i = 0; i < recConList.size (); i++)
  4322.                     {
  4323.                         OHAllowanceBean benefitBean = (OHAllowanceBean) recConList.get (i);
  4324.  
  4325.                         RecFromContributorHeaderBean recConBean = new RecFromContributorHeaderBean ();
  4326.  
  4327.                         recConBean.setOHBenID           (benefitBean.getOhBenId ());
  4328.                         recConBean.setWorkFlowID        (recConWorkflowId);
  4329.                         recConBean.setRecID             (GOSIUtilities.getPrimaryKey ("T_RECFROMCONTRIBUTOR", userId));
  4330.  
  4331.                         if (benefitBean.getBenAmount () != null)
  4332.                         {
  4333.                             recConBean.setAmountReceived (new Double (Math.abs(benefitBean.getBenAmount ().doubleValue ())));
  4334.                         }
  4335.                         else
  4336.                         {
  4337.                             recConBean.setAmountReceived (new Double ("0"));
  4338.                         }
  4339.  
  4340.                         recConBean.setFromDateGreg      (recalculateBean.getFromDate ());
  4341.                         recConBean.setFromDateEntFmt    (OHConstants.GREGORIAN);
  4342.                         recConBean.setToDateGreg        (recalculateBean.getToDate ());
  4343.                         recConBean.setToDateEntFmt      (OHConstants.GREGORIAN);
  4344.                         recConBean.setRequestDate       (new Timestamp (System.currentTimeMillis ()));
  4345.                         recConBean.setRequestDateEntFmt (OHConstants.GREGORIAN);
  4346.                         recConBean.setWorkflowStatus    (OHConstants.REC_FROM_CON_CLERK_ENT);
  4347.                         recConBean.setCreatedBy         (userId);
  4348.                         recConBean.setCreationTimestamp (new Timestamp (System.currentTimeMillis ()));
  4349.  
  4350.                         recoverContributorList.add(recConBean);
  4351.                     }
  4352.  
  4353.                     createRecFromCon (recoverContributorList);
  4354.  
  4355.                     WorkflowParamBean recoveryWorkflowBean = new WorkflowParamBean ();
  4356.  
  4357.                     recoveryWorkflowBean.setModuleId                (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  4358.                     recoveryWorkflowBean.setUserId                  (userId.longValue ());
  4359.                     recoveryWorkflowBean.setUserLocationId          (workflowParamBean.getUserLocationId ());
  4360.                     recoveryWorkflowBean.setStepShortName           ("REC_FROM_CONTRIBUTOR");
  4361.                     recoveryWorkflowBean.setrecordDescription       (GOSIErrorMessages.getErrorDesc ("SOI_ERR_5622") + " - " + socialInsuranceNumber);
  4362.                     recoveryWorkflowBean.setRoutingCriterion        (GOSIConstants.COMPLETED);
  4363.                     recoveryWorkflowBean.setDestinationLocationId   (destinationFieldOffice.shortValue ());
  4364.                     recoveryWorkflowBean.setPrimaryKeyOfTherecord   (recConWorkflowId.toString ());
  4365.  
  4366.                     GOSIUtilities.startWorkflow (recoveryWorkflowBean);
  4367.                 }
  4368.             }
  4369.         }
  4370.         catch (GOSIException ge)
  4371.         {
  4372.             throw   ge;
  4373.         }
  4374.         catch (Exception e)
  4375.         {
  4376.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  4377.                                        GOSIConstants.SOCIAL_INSURANCE,
  4378.                                        this.getClass ().toString (),
  4379.                                        "recalculateBenefitDetails ()",
  4380.                                        e,
  4381.                                        "CMN_ERR_1000");
  4382.         }
  4383.         finally
  4384.         {
  4385.             GOSIUtilities.cleanUp (con);
  4386.         }
  4387.     }
  4388.  
  4389.     /**
  4390.     * @METHOD NAME              :   getBenefitListAffectedByWageChange
  4391.     * @INFORMATION              :   Compiles a list of all approved benefits for a specific contributor
  4392.                                     for the purpose of recalculation
  4393.     * @PARAM                    :   long, java.sql.Timestamp, java.sql.Timestamp
  4394.     * @RETURN                   :   java.util.ArrayList
  4395.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  4396.     * @LAST MODIFIED BY         :
  4397.     * @LAST MODIFIED DATE       :
  4398.     **/
  4399.     private ArrayList getBenefitListAffectedByWageChange (Long contributorId, Timestamp fromDate, Timestamp toDate)
  4400.         throws GOSIException
  4401.     {
  4402.         ArrayList   benefitList = new ArrayList ();
  4403.  
  4404.         PreparedStatement   ps = null;
  4405.         ResultSet           rs = null;
  4406.  
  4407.         try
  4408.         {
  4409.             String  sqlQuery    = "SELECT   a.ohbenid, a.injuryid, a.fieldofficecode, a.ohbencode, a.ohbentype, a.benstdate, "
  4410.                                 + "         a.benstdateentfmt, a.benenddate, a.benenddateentfmt, a.benamount, a.benstatus, "
  4411.                                 + "         a.paymentmode, a.bankcode, a.bankaccnumber, a.totalcontwage, a.payableto, "
  4412.                                 + "         a.partycode, a.contributorid "
  4413.                                 + "    FROM " + SITables.T_OHBENEFIT + " a, " + SITables.T_INJURY + " b "
  4414.                                 + "   WHERE b.injurydate <= ? "
  4415.                                 + "     AND b.injurydate >= ? "
  4416.                                 + "     AND a.contributorid = ? "
  4417.                                 + "     AND a.ohbencode IN (?, ?, ?, ?) "
  4418.                                 + "     AND a.benstatus NOT IN (?, ?) "
  4419.                                 + "     AND a.injuryid = b.injuryid "
  4420.                                 + "ORDER BY a.benstdate, a.ohbenid";
  4421.  
  4422.             GOSIDebug.debugMessages ("-- sqlQuery -- " + sqlQuery);
  4423.  
  4424.             ps = con.prepareStatement (sqlQuery);
  4425.  
  4426.             int i = 0;
  4427.  
  4428.             ps.setTimestamp (++i, getEffectiveToDate (toDate));
  4429.             ps.setTimestamp (++i, fromDate);
  4430.             ps.setLong      (++i, contributorId.longValue ());
  4431.             ps.setShort     (++i, OHConstants.OH_ALWNC_DAIlY_INPATIENT.shortValue ());
  4432.             ps.setShort     (++i, OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.shortValue ());
  4433.             ps.setShort     (++i, OHConstants.OH_ALWNC_DAILY_INPATIENT_ADJUSTMENT.shortValue ());
  4434.             ps.setShort     (++i, OHConstants.OH_ALWNC_DAILY_OUTPATIENT_ADJUSTMENT.shortValue ());
  4435.             ps.setShort     (++i, OHConstants.OH_BNFT_STS_REJECTED.shortValue ());
  4436.             ps.setShort     (++i, OHConstants.OH_BNFT_STS_CANCELLED.shortValue ());
  4437.  
  4438.             rs = ps.executeQuery ();
  4439.  
  4440.             while (rs.next ())
  4441.             {
  4442.                 OHAllowanceBean benefitBean = new OHAllowanceBean ();
  4443.  
  4444.                 benefitBean.setInjuryId         (new Long (rs.getLong ("INJURYID")));
  4445.                 benefitBean.setFieldofficeCode  (new Short (rs.getShort ("FIELDOFFICECODE")));
  4446.                 benefitBean.setOhBenCode        (new Short (rs.getShort ("OHBENCODE")));
  4447.                 benefitBean.setOhBenType        (rs.getString ("OHBENTYPE"));
  4448.                 benefitBean.setBenStDateGreg    (rs.getTimestamp ("BENSTDATE"));
  4449.                 benefitBean.setBenEndDateGreg   (rs.getTimestamp ("BENENDDATE"));
  4450.                 benefitBean.setBenStDateEntFmt  (rs.getString ("BENSTDATEENTFMT"));
  4451.                 benefitBean.setBenEndDateEntFmt (rs.getString ("BENENDDATEENTFMT"));
  4452.                 benefitBean.setBenAmount        (new Double (rs.getDouble ("BENAMOUNT")));
  4453.  
  4454.                 if (rs.getObject ("PAYMENTMODE") != null)
  4455.                 {
  4456.                     benefitBean.setPaymentMode  (new Short (rs.getShort ("PAYMENTMODE")));
  4457.                 }
  4458.                 else
  4459.                 {
  4460.                     benefitBean.setPaymentMode  (OHConstants.PAYMENT_MODE_CHEQUE);
  4461.                 }
  4462.  
  4463.                 if (rs.getObject ("BANKCODE") != null)
  4464.                 {
  4465.                     benefitBean.setBankCode (new Integer (rs.getInt ("BANKCODE")));
  4466.                 }
  4467.  
  4468.                 if (rs.getObject ("BANKACCNUMBER") != null)
  4469.                 {
  4470.                     benefitBean.setBankAccNumber (new Long (rs.getLong ("BANKACCNUMBER")));
  4471.                 }
  4472.  
  4473.                 benefitBean.setTotalContWage    (new Double (rs.getDouble ("TOTALCONTWAGE")));
  4474.                 benefitBean.setBenefitPayableTo (new Short (rs.getShort ("PAYABLETO")));
  4475.                 benefitBean.setPartyCode        (new Long (rs.getLong ("PARTYCODE")));
  4476.                 benefitBean.setContributorId    (new Long (rs.getLong ("CONTRIBUTORID")));
  4477.  
  4478.                 if (OHConstants.OH_ALWNC_DAILY_INPATIENT_ADJUSTMENT.equals (benefitBean.getOhBenCode ()) ||
  4479.                     OHConstants.OH_ALWNC_DAILY_OUTPATIENT_ADJUSTMENT.equals (benefitBean.getOhBenCode ()))
  4480.                 {
  4481.                     benefitList.remove (benefitList.size () - 1);
  4482.  
  4483.                     if(OHConstants.OH_ALWNC_DAILY_INPATIENT_ADJUSTMENT.equals (benefitBean.getOhBenCode ()))
  4484.                     {
  4485.                         benefitBean.setOhBenCode (OHConstants.OH_ALWNC_DAIlY_INPATIENT);
  4486.                     }
  4487.                     else if(OHConstants.OH_ALWNC_DAILY_OUTPATIENT_ADJUSTMENT.equals (benefitBean.getOhBenCode ()))
  4488.                     {
  4489.                         benefitBean.setOhBenCode (OHConstants.OH_ALWNC_DAIlY_OUTPATIENT);
  4490.                     }
  4491.  
  4492.                     benefitList.add (benefitBean);
  4493.                 }
  4494.                 else if (OHConstants.OH_ALWNC_DAIlY_INPATIENT.equals (benefitBean.getOhBenCode ()) &&
  4495.                          benefitBean.getBenAmount () != null &&
  4496.                          benefitBean.getBenAmount ().doubleValue () < 0.00)
  4497.                 {
  4498.                     /* Skipping record; does not need to be considered for adjustment */
  4499.                 }
  4500.                 else
  4501.                 {
  4502.                     benefitList.add (benefitBean);
  4503.                 }
  4504.             }
  4505.         }
  4506.         catch (Exception e)
  4507.         {
  4508.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  4509.                                        GOSIConstants.SOCIAL_INSURANCE,
  4510.                                        this.getClass ().toString (),
  4511.                                        "getBenefitListAffectedByWageChange ()",
  4512.                                        e,
  4513.                                        "CMN_ERR_1000");
  4514.         }
  4515.         finally
  4516.         {
  4517.             GOSIUtilities.cleanUp (ps, rs);
  4518.         }
  4519.  
  4520.         return  benefitList;
  4521.     }
  4522.  
  4523.     /**
  4524.     * @METHOD NAME              :   getEffectiveToDate
  4525.     * @INFORMATION              :   Determines the effective end date on which a benefit recalculation is applicable
  4526.                                     for the purpose of recalculation
  4527.     * @PARAM                    :   java.sql.Timestamp
  4528.     * @RETURN                   :   java.sql.Timestamp
  4529.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  4530.     * @LAST MODIFIED BY         :
  4531.     * @LAST MODIFIED DATE       :
  4532.     **/
  4533.     private Timestamp getEffectiveToDate (Timestamp toDate)
  4534.         throws GOSIException
  4535.     {
  4536.         Timestamp effectiveToDate = null;
  4537.  
  4538.         try
  4539.         {
  4540.             Calendar calendar = GregorianCalendar.getInstance ();
  4541.  
  4542.             calendar.setTime (toDate);
  4543.  
  4544.             if (calendar.get (Calendar.DAY_OF_MONTH) == calendar.getActualMaximum (Calendar.DAY_OF_MONTH))
  4545.             {
  4546.                 calendar.add (Calendar.MONTH, 1);
  4547.                 calendar.set (Calendar.DAY_OF_MONTH, calendar.getActualMaximum (Calendar.DAY_OF_MONTH));
  4548.  
  4549.                 effectiveToDate = new Timestamp (calendar.getTimeInMillis ());
  4550.             }
  4551.             else
  4552.             {
  4553.                 effectiveToDate = toDate;
  4554.             }
  4555.         }
  4556.         catch (Exception e)
  4557.         {
  4558.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  4559.                                        GOSIConstants.SOCIAL_INSURANCE,
  4560.                                        this.getClass ().toString (),
  4561.                                        "getEffectiveToDate ()",
  4562.                                        e,
  4563.                                        "CMN_ERR_1000");
  4564.         }
  4565.  
  4566.         return effectiveToDate;
  4567.     }
  4568.  
  4569.     /**
  4570.     * @METHOD NAME              :   getInjuryListPertainingToBenefitRecalculation
  4571.     * @INFORMATION              :   Compiles a list of all injuries pertaining to benefits found in the given list
  4572.                                     for the purpose of recalculation
  4573.     * @PARAM                    :   java.util.ArrayList,
  4574.                                     java.lang.Long,
  4575.                                     java.lang.Double,
  4576.                                     java.sql.Timestamp
  4577.     * @RETURN                   :   java.util.ArrayList
  4578.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  4579.     * @LAST MODIFIED BY         :
  4580.     * @LAST MODIFIED DATE       :
  4581.     **/
  4582.     private ArrayList getInjuryListPertainingToBenefitRecalculation (ArrayList benefitList, Long engagementIdWC, Double newWage, Timestamp wageChangeDate)
  4583.         throws GOSIException
  4584.     {
  4585.         ArrayList   injuryList = null;
  4586.  
  4587.         try
  4588.         {
  4589.             Hashtable injuryTable = new Hashtable ();
  4590.  
  4591.             for (int i = 0; i < benefitList.size (); i++)
  4592.             {
  4593.                 OHAllowanceBean  benefitBean = (OHAllowanceBean) benefitList.get (i);
  4594.  
  4595.                 if (! injuryTable.containsKey (benefitBean.getInjuryId ()))
  4596.                 {
  4597.                     InjuryPopDetails injuryBean = getInjuryBean (benefitBean.getInjuryId ());
  4598.  
  4599.                     injuryBean = setContributorDetails (injuryBean);
  4600.                     injuryBean = setEstablishmentDetails (injuryBean);
  4601.  
  4602.                     injuryTable.put (benefitBean.getInjuryId (), injuryBean);
  4603.                 }
  4604.             }
  4605.  
  4606.             injuryList = new ArrayList (injuryTable.values ());             /* Set view of all injury records */
  4607.  
  4608.             String calendarType = getCalendarType (injuryList);
  4609.  
  4610.             for (int i = 0; i < injuryList.size (); i++)
  4611.             {
  4612.                 InjuryPopDetails injuryBean = (InjuryPopDetails) injuryList.get (i);
  4613.  
  4614.                 Timestamp injuryDate = injuryBean.getInjuryDate ();
  4615.  
  4616.                 if (injuryBean.getComplicationDate () != null)
  4617.                 {
  4618.                     injuryDate = injuryBean.getComplicationDate ();
  4619.                 }
  4620.  
  4621.                 String injuryDateStr = OHUtilities.getDateStr (injuryDate, calendarType);
  4622.  
  4623.                 int month       = OHUtilities.getMonth (injuryDateStr);
  4624.                 int year        = OHUtilities.getYear (injuryDateStr);
  4625.                 int lastMonth   = month - 1;
  4626.                 int lastYear    = year;
  4627.  
  4628.                 if (lastMonth == 0)
  4629.                 {
  4630.                     lastMonth = 12;             /* Overlap month */
  4631.                     lastYear  = year - 1;       /* Decrement year due to overlapping */
  4632.                 }
  4633.  
  4634.                 Double wage = new Double ("0.00");
  4635.  
  4636.                 Long engagementId = injuryBean.getEngagementId ();
  4637.  
  4638.                 Timestamp firstDate = OHUtilities.getGregDate (OHUtilities.getMonthStartDate (lastMonth, lastYear), calendarType);
  4639.                 Timestamp lastDate  = OHUtilities.getGregDate (GOSIDateUtilities.getMonthEndDate (lastMonth, lastYear), calendarType);
  4640.  
  4641.                 wage = getWageforMonth (engagementId, lastDate);
  4642.  
  4643.                 if (wage == null)
  4644.                 {
  4645.                     lastDate = OHUtilities.getGregDate (GOSIDateUtilities.getMonthEndDate (month, year), calendarType);
  4646.  
  4647.                     wage = getWageforMonth (engagementId, lastDate);
  4648.                 }
  4649.  
  4650.                 if (engagementId.equals (engagementIdWC))
  4651.                 {
  4652.                     if (! lastDate.before (wageChangeDate))
  4653.                     {
  4654.                         wage = newWage;
  4655.                     }
  4656.                     else
  4657.                     {
  4658.                         return null;                /* Invalidate data and abort the process */
  4659.                     }
  4660.                 }
  4661.  
  4662.                 injuryBean.setTotalConWage (wage);
  4663.             }
  4664.  
  4665.             injuryList = updateTotalContributorWage (injuryList, engagementIdWC, newWage, wageChangeDate);
  4666.         }
  4667.         catch(GOSIException ge)
  4668.         {
  4669.             throw ge;
  4670.         }
  4671.         catch(Exception e)
  4672.         {
  4673.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  4674.                                        GOSIConstants.SOCIAL_INSURANCE,
  4675.                                        this.getClass ().toString (),
  4676.                                        "getInjuryListPertainingToBenefitRecalculation ()",
  4677.                                        e,
  4678.                                        "CMN_ERR_1000");
  4679.         }
  4680.  
  4681.         return  injuryList;
  4682.     }
  4683.  
  4684.     /**
  4685.     * @METHOD NAME              :   updateTotalContributorWage
  4686.     * @INFORMATION              :   update total contributor wage due to wage change
  4687.     * @PARAM                    :   class java.util.ArrayList
  4688.                                     class java.lang.Long,
  4689.                                     class java.lang.Double,
  4690.                                     class java.sql.Timestamp
  4691.     * @RETURN                   :   class java.util.ArrayList
  4692.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  4693.     * @LAST MODIFIED BY         :
  4694.     * @LAST MODIFIED DATE       :
  4695.     **/
  4696.     private ArrayList updateTotalContributorWage (ArrayList  injuryList,
  4697.                                                        Long  engagementIdWC,
  4698.                                                      Double  newWage,
  4699.                                                   Timestamp  wageChangeDate)  throws GOSIException
  4700.     {
  4701.         /**
  4702.          *  The total contributor wage is composed of several wages added up from
  4703.          *  having multiple engagements (i.e. multiple employers) at a time.
  4704.          *
  4705.          *  In the event of a backdated wage change to one or more of these engagements,
  4706.          *  injury records pertaining to the other engagment records have to be updated to
  4707.          *  reflect the total wage correctly; hence, this method is invoked.
  4708.          *
  4709.          *  This method was implemented just to ensure consistency of injury records
  4710.          *  in the event of a backdated change. In other words, if the contributor for
  4711.          *  whom the wage change is being processed for had only one engagement (i.e. single employer)
  4712.          *  for duration of the wage change proposed time frame, then calling this method will
  4713.          *  have no effect on the process.
  4714.          */
  4715.  
  4716.         PreparedStatement   ps = null;
  4717.         ResultSet           rs = null;
  4718.  
  4719.         try
  4720.         {
  4721.             for (int i = 0; i < injuryList.size (); i++)
  4722.             {
  4723.                 InjuryPopDetails injuryBean = (InjuryPopDetails) injuryList.get (i);
  4724.  
  4725.                 Timestamp injuryDate = injuryBean.getInjuryDate ();
  4726.  
  4727.                 if (injuryBean.getComplicationDate () != null)
  4728.                 {
  4729.                     injuryDate = injuryBean.getComplicationDate ();
  4730.                 }
  4731.  
  4732.                 String sqlQuery      = "SELECT DISTINCT engagementid"
  4733.                                      + "           FROM " + SITables.T_ENGAGEMENT
  4734.                                      + "          WHERE contributorid = ?"
  4735.                                      + "            AND joiningdate <= ?"
  4736.                                      + "            AND (leavingdate >= ? OR leavingdate IS NULL)"
  4737.                                      + "            AND engagementstatus != ?";
  4738.  
  4739.                 ps = con.prepareStatement (sqlQuery);
  4740.  
  4741.                 ps.setLong       (1, (injuryBean.getContributorId ()).longValue ());
  4742.                 ps.setTimestamp  (2, injuryDate);
  4743.                 ps.setTimestamp  (3, injuryDate);
  4744.                 ps.setShort      (4, RegistrationConstants.ENG_JOIN_IN_PROGRESS.shortValue ());
  4745.  
  4746.                 rs = ps.executeQuery ();
  4747.  
  4748.                 ArrayList engagementList = new ArrayList ();
  4749.  
  4750.                 while (rs.next ())
  4751.                 {
  4752.                     Long engagementId = new Long (rs.getLong ("ENGAGEMENTID"));
  4753.  
  4754.                     engagementList.add (engagementId);
  4755.                 }
  4756.  
  4757.                 Short payableTo = OHConstants.OH_BNFT_PAY_TO_CON;   /* Default payee */
  4758.  
  4759.                 if (engagementList.size () > 2)
  4760.                 {
  4761.                     payableTo = OHConstants.OH_BNFT_PAY_TO_CON;     /* Due to multiple engagements */
  4762.                 }
  4763.                 else
  4764.                 {
  4765.                     if (OHConstants.OH_BNFT_PAY_TO_EMP.equals (injuryBean.getBenefitPayableTo ()) &&
  4766.                         injuryBean.getWageStopDate () == null)
  4767.                     {
  4768.                         payableTo = OHConstants.OH_BNFT_PAY_TO_EMP;     /* As indicated in the injury record */
  4769.                     }
  4770.                 }
  4771.  
  4772.                 /* Set benefit payable to */
  4773.                 injuryBean.setBenefitPayableTo (payableTo);
  4774.  
  4775.                 double totalContributorWage = 0.00;
  4776.  
  4777.                 /* Add up wage amounts for each engagement record */
  4778.                 for (int j = 0; j < engagementList.size (); j++)
  4779.                 {
  4780.                     Long   engagementId         = (Long) engagementList.get (j);
  4781.                     Double engagementWage       = null;                              /* Wage amount pertaining to an engagment record */
  4782.  
  4783.                     if (engagementId.equals (injuryBean.getEngagementId ()))
  4784.                     {
  4785.                         engagementWage = injuryBean.getTotalConWage ();
  4786.                     }
  4787.                     else
  4788.                     {
  4789.                         String     injuryDateStr  = OHUtilities.getDateStr (injuryDate, OHConstants.HIJRAH);
  4790.                         int        month          = OHUtilities.getMonth (injuryDateStr);
  4791.                         int        year           = OHUtilities.getYear (injuryDateStr);
  4792.                         int        lastMonth      = month - 1;
  4793.                         int        lastYear       = year;
  4794.  
  4795.                         if (lastMonth == 0)
  4796.                         {
  4797.                             lastMonth = 12;             /* Overlap month */
  4798.                             lastYear  = year - 1;       /* Decrement year due to overlapping */
  4799.                         }
  4800.  
  4801.                         Timestamp date = OHUtilities.getGregDate (GOSIDateUtilities.getMonthEndDate (lastMonth, lastYear), OHConstants.HIJRAH);
  4802.  
  4803.                         engagementWage = getWageforMonth (engagementId, date);
  4804.  
  4805.                         if (engagementWage == null)
  4806.                         {
  4807.                             date            = OHUtilities.getGregDate (GOSIDateUtilities.getMonthEndDate (month, year), OHConstants.HIJRAH);
  4808.                             engagementWage  = getWageforMonth (engagementId, date);
  4809.                         }
  4810.  
  4811.                         if (engagementId.equals (engagementIdWC))
  4812.                         {
  4813.                             if (! date.before (wageChangeDate))
  4814.                             {
  4815.                                 /**
  4816.                                  *  Substitute wage amount found in records with newly adjusted wage for
  4817.                                  *  this engagement only and for the indicated time frame.
  4818.                                  */
  4819.                                 engagementWage = newWage;
  4820.                             }
  4821.                             else
  4822.                             {
  4823.                                 return null;        /* Invalidate data and abort the process */
  4824.                             }
  4825.                         }
  4826.                     }
  4827.  
  4828.                     if (engagementWage != null)
  4829.                     {
  4830.                         totalContributorWage = totalContributorWage + engagementWage.doubleValue ();
  4831.                     }
  4832.                 }
  4833.  
  4834.                 /* Update injury record with new total contribtor wage */
  4835.                 injuryBean.setTotalConWage (new Double (totalContributorWage));
  4836.             }
  4837.         }
  4838.         catch (GOSIException ge)
  4839.         {
  4840.             throw   ge;
  4841.         }
  4842.         catch (Exception e)
  4843.         {
  4844.             throw   new GOSIException (GOSIConstants.SEVERITY_TWO,
  4845.                                        GOSIConstants.SOCIAL_INSURANCE,
  4846.                                        this.getClass ().toString (),
  4847.                                        "updateTotalContributorWage ()",
  4848.                                        e,
  4849.                                        "CMN_ERR_1000");
  4850.         }
  4851.         finally
  4852.         {
  4853.             GOSIUtilities.cleanUp (ps, rs);
  4854.         }
  4855.  
  4856.         return  injuryList;
  4857.     }
  4858.  
  4859.     /**
  4860.     * @METHOD NAME              :   getInjuryBean
  4861.     * @INFORMATION              :   This method is to  get Injury Bean
  4862.     * @PARAM                    :   cass java.lang.Long
  4863.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  4864.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  4865.     * @LAST MODIFIED BY         :
  4866.     * @LAST MODIFIED DATE       :
  4867.     **/
  4868.     private InjuryPopDetails getInjuryBean (Long injuryId)
  4869.         throws GOSIException
  4870.     {
  4871.         InjuryPopDetails injuryBean = new InjuryPopDetails ();
  4872.  
  4873.         PreparedStatement  ps = null;
  4874.         ResultSet          rs = null;
  4875.  
  4876.         try
  4877.         {
  4878.             String sqlQuery      = "SELECT injuryid, socinsnumber, contributorid, establishmentid, injurydate,"
  4879.                                  + "       datecomplication, injurynumber, description, fieldofficecode,"
  4880.                                  + "       injurystatus, employernotifydate, workerintimationdate, wagestopdate,"
  4881.                                  + "       (NVL (workdisabilitydate, injurydate + 1)) mindisablitydate,"
  4882.                                  + "       treatmentstdate, treatmentenddate"
  4883.                                  + "  FROM t_injury"
  4884.                                  + " WHERE injuryid = ?";
  4885.  
  4886.             ps = con.prepareStatement (sqlQuery);
  4887.  
  4888.             ps.setLong (1, injuryId.longValue ());
  4889.  
  4890.             rs = ps.executeQuery ();
  4891.  
  4892.             if (rs.next ())
  4893.             {
  4894.                 injuryBean.setInjuryID              (new Long (rs.getLong ("INJURYID")));
  4895.                 injuryBean.setSocialInsuranceNumber (new Long (rs.getLong ("SOCINSNUMBER")));
  4896.                 injuryBean.setEstablishmentId       (new Long (rs.getLong ("ESTABLISHMENTID")));
  4897.                 injuryBean.setContributorId         (new Long (rs.getLong ("CONTRIBUTORID")));
  4898.                 injuryBean.setInjuryDate            (rs.getTimestamp ("INJURYDATE"));
  4899.  
  4900.                 if (rs.getObject ("DATECOMPLICATION") != null)
  4901.                 {
  4902.                     injuryBean.setComplicationDate (rs.getTimestamp ("DATECOMPLICATION"));
  4903.                 }
  4904.  
  4905.                 injuryBean.setInjuryNumber (new Long (rs.getLong ("INJURYNUMBER")));
  4906.  
  4907.                 if (rs.getObject ("DESCRIPTION") != null)
  4908.                 {
  4909.                     injuryBean.setDescription (rs.getString ("DESCRIPTION"));
  4910.                 }
  4911.  
  4912.                 injuryBean.setFieldOffice           (new Short (rs.getShort ("FIELDOFFICECODE")));
  4913.                 injuryBean.setInjuryStatus          (new Short (rs.getShort ("INJURYSTATUS")));
  4914.  
  4915.                 if (rs.getObject ("EMPLOYERNOTIFYDATE") != null)
  4916.                 {
  4917.                     injuryBean.setEmployerNotifyDate (rs.getTimestamp("EMPLOYERNOTIFYDATE"));
  4918.                 }
  4919.  
  4920.                 if (rs.getObject ("WORKERINTIMATIONDATE") != null)
  4921.                 {
  4922.                     injuryBean.setWorkerIntimationDate (rs.getTimestamp("WORKERINTIMATIONDATE"));
  4923.                 }
  4924.  
  4925.                 if (rs.getObject ("WAGESTOPDATE") != null)
  4926.                 {
  4927.                     injuryBean.setWageStopDate (rs.getTimestamp("WAGESTOPDATE"));
  4928.                 }
  4929.  
  4930.                 if (rs.getObject ("TREATMENTSTDATE") != null)
  4931.                 {
  4932.                     injuryBean.setTreatmentStartDate (rs.getTimestamp("TREATMENTSTDATE"));
  4933.                 }
  4934.  
  4935.                 if (rs.getObject ("TREATMENTENDDATE") != null)
  4936.                 {
  4937.                     injuryBean.setTreatmentEndDate (rs.getTimestamp("TREATMENTENDDATE"));
  4938.                 }
  4939.  
  4940.                 if (rs.getObject ("MINDISABLITYDATE") != null)
  4941.                 {
  4942.                     injuryBean.setWorkDisabilityDate (rs.getTimestamp("MINDISABLITYDATE"));
  4943.                 }
  4944.             }
  4945.         }
  4946.         catch (Exception e)
  4947.         {
  4948.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  4949.                                        GOSIConstants.SOCIAL_INSURANCE,
  4950.                                        this.getClass ().toString (),
  4951.                                        "getInjuryBean ()",
  4952.                                        e,
  4953.                                        "CMN_ERR_1000");
  4954.         }
  4955.         finally
  4956.         {
  4957.             GOSIUtilities.cleanUp (ps, rs);
  4958.         }
  4959.  
  4960.         return  injuryBean;
  4961.     }
  4962.  
  4963.     /**
  4964.     * @METHOD NAME              :   getInjuryBean
  4965.     * @INFORMATION              :   This method is to get Injury Bean
  4966.     * @PARAM                    :   class java.util.ArrayList,
  4967.                                     class java.lang.Long
  4968.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  4969.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  4970.     * @LAST MODIFIED BY         :
  4971.     * @LAST MODIFIED DATE       :
  4972.     **/
  4973.     private InjuryPopDetails getInjuryBean (ArrayList injuryList, Long injuryId)
  4974.         throws GOSIException
  4975.     {
  4976.         InjuryPopDetails injuryBean = null;
  4977.  
  4978.         try
  4979.         {
  4980.             for (int i = 0; i < injuryList.size(); i++)
  4981.             {
  4982.                 injuryBean = (InjuryPopDetails) injuryList.get (i);
  4983.  
  4984.                 if (injuryBean.getInjuryID ().equals (injuryId))
  4985.                 {
  4986.                     break;
  4987.                 }
  4988.             }
  4989.         }
  4990.         catch (Exception e)
  4991.         {
  4992.             throw   new GOSIException (GOSIConstants.SEVERITY_TWO,
  4993.                                        GOSIConstants.SOCIAL_INSURANCE,
  4994.                                        this.getClass ().toString (),
  4995.                                        "getInjuryBean ()",
  4996.                                        e,
  4997.                                        "CMN_ERR_1000");
  4998.         }
  4999.  
  5000.         return  injuryBean;
  5001.     }
  5002.  
  5003.     /**
  5004.     * @METHOD NAME              :   getEstablishmentId
  5005.     * @INFORMATION              :   This method is to get Establishment Id
  5006.     * @PARAM                    :   class java.lang.Long,
  5007.                                     class java.util.ArrayList
  5008.     * @RETURN                   :   class java.lang.Long
  5009.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5010.     * @LAST MODIFIED BY         :
  5011.     * @LAST MODIFIED DATE       :
  5012.     **/
  5013.     private Long getEstablishmentId (Long registrationNumber, ArrayList injuryList)
  5014.         throws GOSIException
  5015.     {
  5016.         Long establishmentId = null;
  5017.  
  5018.         try
  5019.         {
  5020.             for (int i = 0; i < injuryList.size (); i++)
  5021.             {
  5022.                 InjuryPopDetails injuryBean = (InjuryPopDetails) injuryList.get(i);
  5023.  
  5024.                 if (registrationNumber.equals (injuryBean.getRegistrationNumber ()))
  5025.                 {
  5026.                     establishmentId = injuryBean.getEstablishmentId ();
  5027.  
  5028.                     break;
  5029.                 }
  5030.             }
  5031.         }
  5032.         catch (Exception e)
  5033.         {
  5034.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  5035.                                        GOSIConstants.SOCIAL_INSURANCE,
  5036.                                        this.getClass ().toString (),
  5037.                                        "getEstablishmentId ()",
  5038.                                        e,
  5039.                                        "CMN_ERR_1000");
  5040.         }
  5041.         finally
  5042.         {
  5043.             return  establishmentId;
  5044.         }
  5045.     }
  5046.  
  5047.     /**
  5048.     * @METHOD NAME              :   getCalendarType
  5049.     * @INFORMATION              :   This method is to get the Calender Type of the
  5050.                                     establishment under which the injury is registered
  5051.     * @PARAM                    :   class java.util.ArrayList
  5052.     * @RETURN                   :   class java.lang.String
  5053.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5054.     * @LAST MODIFIED BY         :
  5055.     * @LAST MODIFIED DATE       :
  5056.     **/
  5057.     public String getCalendarType (ArrayList injuryList) throws GOSIException
  5058.     {
  5059.         String calendarType = OHConstants.GREGORIAN;
  5060.  
  5061.         try
  5062.         {
  5063.             for (int i = 0; i < injuryList.size (); i++)
  5064.             {
  5065.                 InjuryPopDetails injuryBean = (InjuryPopDetails) injuryList.get (i);
  5066.  
  5067.                 if (OHConstants.HIJRAH.equals (injuryBean.getCalendarType ()))
  5068.                 {
  5069.                     calendarType = OHConstants.HIJRAH;
  5070.                     break;
  5071.                 }
  5072.             }
  5073.         }
  5074.         catch (Exception e)
  5075.         {
  5076.             throw   new GOSIException (GOSIConstants.SEVERITY_TWO,
  5077.                                        GOSIConstants.SOCIAL_INSURANCE,
  5078.                                        this.getClass ().toString (),
  5079.                                        "getCalendarType ()",
  5080.                                        e,
  5081.                                        "CMN_ERR_1000");
  5082.         }
  5083.  
  5084.         return  calendarType;
  5085.     }
  5086.  
  5087.     /**
  5088.     * @METHOD NAME              :   getHospitalType
  5089.     * @INFORMATION              :   This method is to  get Hospital Type
  5090.     * @PARAM                    :   class java.lang.Long,
  5091.                                     class java.sql.Timestamp,
  5092.                                     class java.sql.Timestamp
  5093.     * @RETURN                   :   class java.lang.Short
  5094.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5095.     * @LAST MODIFIED BY         :
  5096.     * @LAST MODIFIED DATE       :
  5097.     **/
  5098.     private Short getHospitalType (Long injuryId, Timestamp startDate, Timestamp endDate)
  5099.         throws GOSIException
  5100.     {
  5101.         Short hospitalType = null;
  5102.  
  5103.         PreparedStatement   ps = null;
  5104.         ResultSet           rs = null;
  5105.  
  5106.         try
  5107.         {
  5108.             GOSIDebug.debugMessages ("getHospitalType (" + injuryId + ", " + startDate + ", " + endDate + ")");
  5109.  
  5110.             String sqlQuery = "SELECT HOSPITALTYPE "
  5111.                             + "  FROM " + SITables.T_HOSPITAL
  5112.                             + " WHERE HOSPITALCODE = "
  5113.                             + "                      (SELECT DISTINCT HOSPITALCODE "
  5114.                             + "                         FROM "+ SITables.T_TREATMENT
  5115.                             + "                        WHERE INJURYID = ? AND "
  5116.                             + "                              STARTDATE <= ? AND ENDDATE >= ? AND"
  5117.                             + "                              TREATMENTSTATUS in (?, ?)"
  5118.                             + "                      )";
  5119.  
  5120.             ps = con.prepareStatement (sqlQuery);
  5121.  
  5122.             GOSIDebug.debugMessages ("sqlQuery - " + sqlQuery);
  5123.  
  5124.             ps.setLong      (1, injuryId.longValue ());
  5125.             ps.setTimestamp (2, endDate);
  5126.             ps.setTimestamp (3, startDate);
  5127.             ps.setShort     (4, OHConstants.TRMT_STS_APPROVED.shortValue ());
  5128.             ps.setShort     (5, OHConstants.TRMT_STS_ENTERED.shortValue ());
  5129.  
  5130.             GOSIDebug.debugMessages ("sqlQuery arg 1 - " + injuryId.longValue ());
  5131.             GOSIDebug.debugMessages ("sqlQuery arg 2 - " + endDate);
  5132.             GOSIDebug.debugMessages ("sqlQuery arg 3 - " + startDate);
  5133.             GOSIDebug.debugMessages ("sqlQuery arg 4 - " + OHConstants.TRMT_STS_APPROVED.shortValue ());
  5134.             GOSIDebug.debugMessages ("sqlQuery arg 5 - " + OHConstants.TRMT_STS_ENTERED.shortValue ());
  5135.  
  5136.             rs = ps.executeQuery ();
  5137.  
  5138.             while (rs.next ())
  5139.             {
  5140.                 if (rs.getObject ("HOSPITALTYPE") != null)
  5141.                 {
  5142.                     hospitalType = new Short (rs.getShort ("HOSPITALTYPE"));
  5143.                 }
  5144.             }
  5145.         }
  5146.         catch (Exception e)
  5147.         {
  5148.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  5149.                                        GOSIConstants.SOCIAL_INSURANCE,
  5150.                                        this.getClass ().toString (),
  5151.                                        "getHospitalType ()",
  5152.                                        e,
  5153.                                        "CMN_ERR_1000");
  5154.         }
  5155.         finally
  5156.         {
  5157.             GOSIUtilities.cleanUp (ps,rs);
  5158.         }
  5159.  
  5160.         GOSIDebug.debugMessages ("hospitalType - " + hospitalType);
  5161.  
  5162.         return hospitalType;
  5163.     }
  5164.  
  5165.     /**
  5166.     * @METHOD NAME              :   addToBenefitList
  5167.     * @INFORMATION              :   This method is to add the new list to the benefit list
  5168.     * @PARAM                    :   class java.util.ArrayList,
  5169.                                     class java.util.ArrayList
  5170.     * @RETURN                   :   class java.util.ArrayList
  5171.     * @EXCEPTION                :
  5172.     * @LAST MODIFIED BY         :
  5173.     * @LAST MODIFIED DATE       :
  5174.     **/
  5175.     private ArrayList addToBenefitList(ArrayList currentList,ArrayList newList)
  5176.     {
  5177.         int newListSize = newList.size();
  5178.         for(int i= 0;i<newListSize;i++)
  5179.         {
  5180.             currentList.add(newList.get(i));
  5181.         }
  5182.         return currentList;
  5183.     }
  5184.  
  5185.  
  5186.     /**
  5187.     * @METHOD NAME              :   getTreatmentPeriodList
  5188.     * @INFORMATION              :   This method is to  get Treatment Period List for calculating oh allowance
  5189.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  5190.     * @RETURN                   :   class java.util.ArrayList
  5191.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5192.     * @LAST MODIFIED BY         :
  5193.     * @LAST MODIFIED DATE       :
  5194.     **/
  5195.      private ArrayList getTreatmentPeriodList(InjuryPopDetails injuryBean,boolean isTreatmentApproved)
  5196.             throws GOSIException
  5197.     {
  5198.         GOSIDebug.debugMessages("\t\t Start getTreatmentPeriodList - MaintainOHAllowanceSessionEJB");
  5199.  
  5200.         ArrayList benefitList = new ArrayList();
  5201.         PreparedStatement ps = null;
  5202.         ResultSet rs = null;
  5203.         try
  5204.         {
  5205.             //  isTreatmentApproved notify from which screen allowance is calculated
  5206.             //  true if from oh benefit screen
  5207.             //  false if from treatment period screen
  5208.  
  5209.             ArrayList trmtList = new ArrayList();
  5210.             Long injuryId = injuryBean.getInjuryID();
  5211.             Timestamp startDate = injuryBean.getBenefitStartDate();
  5212.             Timestamp endDate   = injuryBean.getBenefitEndDate();
  5213.                 String sqlQuery = "" +
  5214.                     " select a.TREATMENTID,a.INJURYID, " +
  5215.                     " a.HOSPITALCODE,b.HOSPITALTYPE,a.STARTDATE, " +
  5216.                     " a.ENDDATE,a.TREATMENTSTATUS,a.TREATMENTTYPE from " +
  5217.                         SITables.T_TREATMENT + " a, " +
  5218.                         SITables.T_HOSPITAL + " b " +
  5219.                     " where a.INJURYID =? and " +
  5220.                     " a.TREATMENTSTATUS =  ? "   +
  5221.                     " and a.ENDDATE >= ? and  a.STARTDATE <= ? " +
  5222.                     " and a.HOSPITALCODE = b.HOSPITALCODE " +
  5223.                     " order by STARTDATE ";
  5224.  
  5225.                     con = GOSIUtilities.getConnection
  5226.                         (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  5227.                     ps = con.prepareStatement(sqlQuery);
  5228.                     GOSIDebug.debugMessages("SqlQuery:" + sqlQuery + ":");
  5229.                     GOSIDebug.debugMessages("\t\t Param 1 :" + injuryId.longValue() + ":");
  5230.                     ps.setLong(1,injuryId.longValue());
  5231.                     if(isTreatmentApproved)
  5232.                     {
  5233.                         ps.setShort(2,OHConstants.TRMT_STS_APPROVED.shortValue());
  5234.                         GOSIDebug.debugMessages("\t\t Param 2 :" + OHConstants.TRMT_STS_APPROVED.shortValue() + ":");
  5235.                     }else
  5236.                     {
  5237.                         ps.setShort(2,OHConstants.TRMT_STS_ENTERED.shortValue());
  5238.                         GOSIDebug.debugMessages("\t\t Param 2 :" + OHConstants.TRMT_STS_ENTERED.shortValue() + ":");
  5239.                     }
  5240.                     ps.setTimestamp(3,startDate);
  5241.                     ps.setTimestamp(4,endDate);
  5242.                    
  5243.                     GOSIDebug.debugMessages("\t\t Param 3 :" + startDate + ":");
  5244.                     GOSIDebug.debugMessages("\t\t Param 4 :" + endDate + ":");
  5245.                     rs = ps.executeQuery();
  5246.             while(rs.next())
  5247.             {
  5248.  
  5249.                 TreatmentPeriodBean trmtBean=new TreatmentPeriodBean();
  5250.                 trmtBean.setTreatmentId(new Long(rs.getLong("TREATMENTID")));
  5251.                 trmtBean.setInjuryId(new Long(rs.getLong("INJURYID")));
  5252.                 trmtBean.setHospitalCode(new Long(rs.getLong("HOSPITALCODE")));
  5253.                 trmtBean.setHospitalType(new Short(rs.getShort("HOSPITALTYPE")));
  5254.                 trmtBean.setTreatmentType(new Short(rs.getShort("TREATMENTTYPE")));
  5255.                 trmtBean.setStartDateGreg(rs.getTimestamp("STARTDATE"));
  5256.                 trmtBean.setEndDateGreg(rs.getTimestamp("ENDDATE"));
  5257.                 trmtBean.setTreatmentStatus(new Short(rs.getShort("TREATMENTSTATUS")));
  5258.                 trmtList.add(trmtBean);
  5259.             }
  5260.             int trmtListSize = trmtList.size();
  5261.             // this logic sets start date and end dates of the first and
  5262.             // last bean to benefit start date and benefit end date
  5263.             if(trmtListSize > 0)
  5264.             {
  5265.                 TreatmentPeriodBean firstBean =
  5266.                     (TreatmentPeriodBean)trmtList.get(0);
  5267.                 if(startDate.compareTo(firstBean.getStartDateGreg())>0)
  5268.                 {
  5269.                     firstBean.setStartDateGreg(startDate);
  5270.                 }
  5271.                 TreatmentPeriodBean lastBean =
  5272.                     (TreatmentPeriodBean)trmtList.get(trmtListSize-1);
  5273.                 if(endDate.compareTo(lastBean.getEndDateGreg())<0)
  5274.                 {
  5275.                     lastBean.setEndDateGreg(endDate);
  5276.                 }
  5277.             }
  5278.             GOSIDebug.debugMessages("\t\t End getTreatmentPeriodList - MaintainOHAllowanceSessionEJB");
  5279.             return trmtList;
  5280.         }
  5281.         catch(GOSIException ge)
  5282.         {
  5283.             GOSIDebug.debugMessages("session-getTreatmentPeriodList :ge:" + ge);
  5284.             throw ge;
  5285.         }catch(Exception e)
  5286.         {
  5287.             GOSIDebug.debugMessages("session-getTreatmentPeriodList :e:" + e);
  5288.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  5289.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  5290.                 "getTreatmentPeriodList()",e,"CMN_ERR_1000");
  5291.         }
  5292.         finally
  5293.         {
  5294.             GOSIUtilities.cleanUp(con);
  5295.         }
  5296.     }
  5297.  
  5298.  
  5299.  
  5300.     /**
  5301.     * @METHOD NAME              :   getStopPeriodList
  5302.     * @INFORMATION              :   This method is to  get Stop Period List for the injury
  5303.     * @PARAM                    :   class java.util.ArrayList,
  5304.                                     class gosi.business.socialinsurance.occupationalhazards.injury.beans.TreatmentPeriodBean,
  5305.                                     class java.lang.Byte
  5306.     * @RETURN                   :   class java.util.ArrayList
  5307.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5308.     * @LAST MODIFIED BY         :
  5309.     * @LAST MODIFIED DATE       :
  5310.     **/
  5311.     public ArrayList getStopPeriodList(ArrayList stoppedPeriodList,
  5312.         TreatmentPeriodBean trmtBean, Byte stopResumeflag)throws GOSIException
  5313.     {
  5314.         //will itrate the list to come up with the actual stopped list
  5315.         // based on flag the trmt bean is added or removed from
  5316.         // the stop list
  5317.  
  5318.         long startTime   = 0;
  5319.         long endTime     = 0;
  5320.         long elapsedTime = 0;
  5321.         startTime = System.currentTimeMillis();
  5322.  
  5323.         int stopListSize = 0;
  5324.         Timestamp startDate = trmtBean.getStartDateGreg();
  5325.         Timestamp endDate = trmtBean.getEndDateGreg();
  5326.         if(stoppedPeriodList.size()== 0)
  5327.         {
  5328.             stoppedPeriodList.add(trmtBean);
  5329.         }else
  5330.         {
  5331.             // if resume flag is to resume oh allowance for the period
  5332.             // the for that particular period is removed from the stop periods
  5333.             if(OHConstants.RESUME_ALLOWANCE_FLAG.equals(stopResumeflag))
  5334.             {
  5335.                 stopListSize = stoppedPeriodList.size();
  5336.                 // the logic below checks each of the stoped period list with
  5337.                 // the resume period and if the resume period falls on the
  5338.                 // stopped period removes the stopped period from the list
  5339.                 // the code takes care of removing stopped records inside
  5340.                 // resume period as well as overlapping resume period in
  5341.                 // multiple stopped records, and resume period inside a particualr
  5342.                 // stopped record
  5343.                 for(int i=0;i<stopListSize;i++)
  5344.                 {
  5345.                     TreatmentPeriodBean stopBean =
  5346.                         (TreatmentPeriodBean)stoppedPeriodList.get(i);
  5347.                     Timestamp stopStartDate =stopBean.getStartDateGreg();
  5348.                     Timestamp stopEndDate =stopBean.getEndDateGreg();
  5349.                     if(startDate.compareTo(stopStartDate)>=0 &&
  5350.                         startDate.compareTo(stopEndDate)<=0 )
  5351.                     {
  5352.                         if(startDate.compareTo(stopStartDate)==0 &&
  5353.                         endDate.compareTo(stopEndDate)==0 )
  5354.                         {
  5355.                             stoppedPeriodList.remove(i);
  5356.                             break;
  5357.                         }else
  5358.                         if(startDate.compareTo(stopStartDate)==0 &&
  5359.                         endDate.compareTo(stopEndDate)<0 )
  5360.                         {
  5361.                                 stopBean.setStartDateGreg
  5362.                                     (GOSIUtilities.getNextDate(endDate));
  5363.                                 break;
  5364.                         }
  5365.                         else
  5366.                         if(startDate.compareTo(stopStartDate)>0 &&
  5367.                         endDate.compareTo(stopEndDate)==0 )
  5368.                         {
  5369.                                 stopBean.setEndDateGreg
  5370.                                     (OHUtilities.getPrevDate(startDate));
  5371.                                 break;
  5372.                         }
  5373.                         else
  5374.                         if(startDate.compareTo(stopStartDate)>0 &&
  5375.                             endDate.compareTo(stopEndDate)<0 )
  5376.                         {
  5377.                             TreatmentPeriodBean newTrmtBean =
  5378.                                 new TreatmentPeriodBean(stopBean);
  5379.                             stopBean.setEndDateGreg
  5380.                                 (OHUtilities.getPrevDate(startDate));
  5381.                             newTrmtBean.setStartDateGreg
  5382.                                 (GOSIUtilities.getNextDate(endDate));
  5383.                             stoppedPeriodList.add((i+1),newTrmtBean);
  5384.                             break;
  5385.                         }else if(endDate.compareTo(stopEndDate)>0)
  5386.                         {
  5387.                             if(startDate.compareTo(stopStartDate)>0)
  5388.                             {
  5389.                                 stopBean.setEndDateGreg
  5390.                                     (OHUtilities.getPrevDate(startDate));
  5391.                             }else
  5392.                             if(startDate.compareTo(stopStartDate)==0)
  5393.                             {
  5394.                                 stoppedPeriodList.remove(i);
  5395.                             }
  5396.                             for (int k=0;k<stoppedPeriodList.size() ;k++ )
  5397.                             {
  5398.                                 TreatmentPeriodBean tempTrmtBean =
  5399.                                   (TreatmentPeriodBean)stoppedPeriodList.get(k);
  5400.                                 if(endDate.compareTo
  5401.                                     (tempTrmtBean.getStartDateGreg())>=0 &&
  5402.                                    endDate.compareTo
  5403.                                     (tempTrmtBean.getEndDateGreg())<=0 )
  5404.                                 {
  5405.                                     if(stopBean.getEndDateGreg().compareTo
  5406.                                         (tempTrmtBean.getEndDateGreg())==0)
  5407.                                     {
  5408.                                         tempTrmtBean = null;
  5409.                                         stoppedPeriodList.remove(k);
  5410.                                         break;
  5411.  
  5412.                                     }else
  5413.                                     if(stopBean.getEndDateGreg().compareTo
  5414.                                         (tempTrmtBean.getEndDateGreg())<=0)
  5415.                                     {
  5416.                                         tempTrmtBean.setStartDateGreg
  5417.                                          (GOSIUtilities.getNextDate(endDate));
  5418.                                         break;
  5419.                                     }
  5420.                                 }
  5421.                             }
  5422.                             break;
  5423.                         }
  5424.                     }
  5425.                 }
  5426.             }
  5427.             else
  5428.             {
  5429.                 // the logic below checks the stop period list if its found
  5430.                 // empty new list is created and the stop list is inserted
  5431.                 // the logic also checks for overlapping stopped periods
  5432.                 // incase its resumed and then stopped again
  5433.  
  5434.                 if(stopListSize == 0)
  5435.                 {
  5436.                     stoppedPeriodList.add(trmtBean);
  5437.                 }else
  5438.                 {
  5439.                     for(int i=0;i<stopListSize;i++)
  5440.                     {
  5441.                         TreatmentPeriodBean stopBean =
  5442.                             (TreatmentPeriodBean)stoppedPeriodList.get(i);
  5443.                         Timestamp stopStartDate =stopBean.getStartDateGreg();
  5444.                         Timestamp nextStopStartDate = null;
  5445.                         if(i+1==stopListSize)
  5446.                         {
  5447.                             stoppedPeriodList.add(trmtBean);
  5448.                             break;
  5449.                         }
  5450.                         else
  5451.                         {
  5452.                             nextStopStartDate =
  5453.                             ((TreatmentPeriodBean)stoppedPeriodList.get(i+1)).
  5454.                                 getStartDateGreg();
  5455.                         }
  5456.                         if(nextStopStartDate !=null &&
  5457.                             startDate.compareTo(stopStartDate)>0 &&
  5458.                                 startDate.compareTo(nextStopStartDate)<0)
  5459.                         {
  5460.                             stoppedPeriodList.add(i+1,trmtBean);
  5461.                             break;
  5462.                         }
  5463.                     }
  5464.                 }
  5465.             }
  5466.         }
  5467.         endTime = System.currentTimeMillis();
  5468.         elapsedTime = endTime - startTime;
  5469.         GOSIInstrumentationLog.writeInstrumentationToLog(
  5470.                 this.getClass().toString(),
  5471.                 "getStopPeriodList()",
  5472.                 elapsedTime);
  5473.  
  5474.         return stoppedPeriodList;
  5475.     }
  5476.  
  5477.     /**
  5478.     * @METHOD NAME              :   getPayablePeriodList
  5479.     * @INFORMATION              :   This method is to  get Payable Period List
  5480.     * @PARAM                    :   class java.util.ArrayList,
  5481.                                     class java.util.ArrayList
  5482.     * @RETURN                   :   class java.util.ArrayList
  5483.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5484.     * @LAST MODIFIED BY         :
  5485.     * @LAST MODIFIED DATE       :
  5486.     **/
  5487.     private ArrayList getPayablePeriodList(ArrayList trmtList ,
  5488.         ArrayList actualStoppedList)throws GOSIException
  5489.     {
  5490.  
  5491.         // will itrate the list to come up with the actual payable period list
  5492.         // based on the stopped list the the periods stopped are
  5493.         // removed from the trmt list
  5494.  
  5495.         GOSIDebug.debugMessages("\t\t Start getPayablePeriodList - MaintainOHAllowanceSessionEJB");
  5496.         ArrayList newTrmtList = new ArrayList();
  5497.         int l = -1;
  5498.         int trmtListSize = trmtList.size();
  5499.         int stoppedListSize = actualStoppedList.size();
  5500.         if(stoppedListSize==0)
  5501.         {
  5502.             newTrmtList = trmtList;
  5503.         }
  5504.         for(int i=0;i<stoppedListSize;i++)
  5505.         {
  5506.             TreatmentPeriodBean stopBean = (TreatmentPeriodBean)actualStoppedList.get(i);
  5507.             for(int j=0;j<trmtListSize;j++)
  5508.             {
  5509.                 TreatmentPeriodBean trmtBean = (TreatmentPeriodBean)trmtList.get(j);
  5510.                 if(stopBean.getStartDateGreg().compareTo(trmtBean.getStartDateGreg())>=0 &&
  5511.                     stopBean.getStartDateGreg().compareTo(trmtBean.getEndDateGreg())<=0 )
  5512.                 {
  5513.                     if(l==j)
  5514.                     {
  5515.                         GOSIDebug.debugMessages("0.1 inside multiple stops");
  5516.                         trmtBean.setStartDateGreg(GOSIUtilities.getNextDate
  5517.                             (((TreatmentPeriodBean)newTrmtList.get
  5518.                                 (newTrmtList.size()-1)).getEndDateGreg()));
  5519.                     }
  5520.                     l=j;
  5521.                     if(stopBean.getStartDateGreg().compareTo(trmtBean.getStartDateGreg())==0 &&
  5522.                     stopBean.getEndDateGreg().compareTo(trmtBean.getEndDateGreg())==0 )
  5523.                     {
  5524.                         GOSIDebug.debugMessages("1.Treatment period Removed at"+j);
  5525.                         trmtBean =null;
  5526.                         break;
  5527.                     }else
  5528.                     if(stopBean.getStartDateGreg().compareTo(trmtBean.getStartDateGreg())==0 &&
  5529.                     stopBean.getEndDateGreg().compareTo(trmtBean.getEndDateGreg())<0 )
  5530.                     {
  5531.                             GOSIDebug.debugMessages("2.Treatment period start Date set at"+j);
  5532.                             trmtBean.setStartDateGreg(GOSIUtilities.getNextDate(stopBean.getEndDateGreg()));
  5533.                             newTrmtList.add(trmtBean);
  5534.                             break;
  5535.                     }
  5536.                     else
  5537.                     if(stopBean.getStartDateGreg().compareTo(trmtBean.getStartDateGreg())>0 &&
  5538.                     stopBean.getEndDateGreg().compareTo(trmtBean.getEndDateGreg())==0 )
  5539.                     {
  5540.                             GOSIDebug.debugMessages("3.Treatment period End Date set at"+j);
  5541.                             trmtBean.setEndDateGreg(OHUtilities.getPrevDate(stopBean.getStartDateGreg()));
  5542.                             newTrmtList.add(trmtBean);
  5543.                             break;
  5544.                     }
  5545.                     else
  5546.                     if(stopBean.getStartDateGreg().compareTo(trmtBean.getStartDateGreg())>0 &&
  5547.                     stopBean.getEndDateGreg().compareTo(trmtBean.getEndDateGreg())<0 )
  5548.                     {
  5549.                         GOSIDebug.debugMessages("4. two Treatment period set at"+j);
  5550.                         TreatmentPeriodBean newTrmtBean = new TreatmentPeriodBean(trmtBean);
  5551.                         trmtBean.setEndDateGreg(OHUtilities.getPrevDate(stopBean.getStartDateGreg()));
  5552.                         newTrmtBean.setStartDateGreg(GOSIUtilities.getNextDate(stopBean.getEndDateGreg()));
  5553.                         newTrmtList.add(trmtBean);
  5554.                         newTrmtList.add(newTrmtBean);
  5555.                         break;
  5556.                     }else if(stopBean.getEndDateGreg().compareTo(trmtBean.getEndDateGreg())>0)
  5557.                     {
  5558.                         GOSIDebug.debugMessages(" 5 gone into to big if");
  5559.                         if(stopBean.getStartDateGreg().compareTo(trmtBean.getStartDateGreg())>0)
  5560.                         {
  5561.                             GOSIDebug.debugMessages("5.1 end date set");
  5562.                             trmtBean.setEndDateGreg(OHUtilities.getPrevDate(stopBean.getStartDateGreg()));
  5563.                             newTrmtList.add(trmtBean);
  5564.                         }else
  5565.                         if(stopBean.getStartDateGreg().compareTo(trmtBean.getStartDateGreg())==0)
  5566.                         {
  5567.                             GOSIDebug.debugMessages("5.2 bean removed");
  5568.                             trmtBean = null;
  5569.                         }
  5570.                         for (int k=(j+1);k<trmtListSize ;k++ )
  5571.                         {
  5572.                             GOSIDebug.debugMessages("5.3.0 k value :" + k);
  5573.                             TreatmentPeriodBean tempTrmtBean = (TreatmentPeriodBean)trmtList.get(k);
  5574.                             if(stopBean.getEndDateGreg().compareTo(tempTrmtBean.getStartDateGreg())>=0 &&
  5575.                                 stopBean.getEndDateGreg().compareTo(tempTrmtBean.getEndDateGreg())<=0 )
  5576.                             {
  5577.                                 GOSIDebug.debugMessages("5.3 k value :" + k);
  5578.                                 if(stopBean.getEndDateGreg().compareTo(tempTrmtBean.getEndDateGreg())==0)
  5579.                                 {
  5580.                                     GOSIDebug.debugMessages("5.4 bean set to null at :" + k);
  5581.                                     tempTrmtBean = null;
  5582.                                 }else if(stopBean.getEndDateGreg().compareTo(tempTrmtBean.getEndDateGreg())<=0)
  5583.                                 {
  5584.                                     GOSIDebug.debugMessages("5.5 startDate set for " + k);
  5585.                                     tempTrmtBean.setStartDateGreg(GOSIUtilities.getNextDate(stopBean.getEndDateGreg()));
  5586.                                     newTrmtList.add(tempTrmtBean);
  5587.                                 }
  5588.                                 j = k;
  5589.                                 break;
  5590.                             }
  5591.                         }
  5592.                         //break;
  5593.                     }
  5594.                 }
  5595.             }
  5596.         }
  5597.         for(int j=0;j<trmtListSize;j++)
  5598.         {
  5599.             TreatmentPeriodBean trmtBean = (TreatmentPeriodBean)trmtList.get(j);
  5600.             Timestamp trmtStartDate =trmtBean.getStartDateGreg();
  5601.             Timestamp trmtEndDate = trmtBean.getEndDateGreg();
  5602.             boolean flag = true;
  5603.             for(int i=0;i<stoppedListSize;i++)
  5604.             {
  5605.                 TreatmentPeriodBean stopBean = (TreatmentPeriodBean)actualStoppedList.get(i);
  5606.                 Timestamp stopStartDate =stopBean.getStartDateGreg();
  5607.                 Timestamp stopEndDate =stopBean.getEndDateGreg();
  5608.                 if((stopStartDate.compareTo(trmtStartDate)<=0 &&
  5609.                     stopEndDate.compareTo(trmtStartDate)>=0)||
  5610.                     (stopStartDate.compareTo(trmtEndDate)<=0 &&
  5611.                     stopEndDate.compareTo(trmtEndDate)>=0) )
  5612.                 {
  5613.                     flag = false;
  5614.                     break;
  5615.                 }
  5616.  
  5617.             }
  5618.             if(flag)
  5619.             {
  5620.                newTrmtList.add(trmtBean);
  5621.             }
  5622.         }
  5623.         GOSIDebug.debugMessages("\t\t End getPayablePeriodList - MaintainOHAllowanceSessionEJB");
  5624.         return newTrmtList;
  5625.     }
  5626.  
  5627.     /**
  5628.     * @METHOD NAME              :   getTrmtDetailsforDate
  5629.     * @INFORMATION              :   This method is to get Trmt Details for a Date
  5630.     * @PARAM                    :   class java.sql.Timestamp,
  5631.                                     class java.util.ArrayList
  5632.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.TreatmentPeriodBean
  5633.     * @EXCEPTION                :
  5634.     * @LAST MODIFIED BY         :
  5635.     * @LAST MODIFIED DATE       :
  5636.     **/
  5637.     private TreatmentPeriodBean getTrmtDetailsforDate
  5638.         (Timestamp trmtDate,ArrayList trmtList)
  5639.     {
  5640.         GOSIDebug.debugMessages("\t\t Start getTrmtDetailsforDate - MaintainOHAllowanceSessionEJB");
  5641.         // This method is called to find set the payment type for
  5642.         // the trmt date (inpatient/outpatient)?
  5643.         TreatmentPeriodBean tempTrmtBean = null;
  5644.         int trmtListSize = trmtList.size();
  5645.         for (int i=0; i<trmtListSize ; i++)
  5646.         {
  5647.             TreatmentPeriodBean trmtBean = (TreatmentPeriodBean)trmtList.get(i);
  5648.             if(trmtBean.getStartDateGreg().compareTo(trmtDate)<=0 &&
  5649.                 trmtBean.getEndDateGreg().compareTo(trmtDate)>=0 )
  5650.             {
  5651.                 if(tempTrmtBean == null)
  5652.                 {
  5653.                     tempTrmtBean = new TreatmentPeriodBean(trmtBean);
  5654.                     tempTrmtBean.setStartDateGreg(trmtDate);
  5655.                     tempTrmtBean.setEndDateGreg(trmtDate);
  5656.                 }else
  5657.                 {
  5658.                     if(OHConstants.TRMT_TYPE_INPATIENT.equals(trmtBean.getTreatmentType()))
  5659.                     {
  5660.                         tempTrmtBean = new TreatmentPeriodBean(trmtBean);
  5661.                         tempTrmtBean.setStartDateGreg(trmtDate);
  5662.                         tempTrmtBean.setEndDateGreg(trmtDate);
  5663.                     }
  5664.                 }
  5665.             }
  5666.         }
  5667.         GOSIDebug.debugMessages("\t\t End getTrmtDetailsforDate - MaintainOHAllowanceSessionEJB");
  5668.         return tempTrmtBean;
  5669.     }
  5670.  
  5671.  
  5672.     /**
  5673.     * @METHOD NAME              :   getBenefitPayableTrmtList
  5674.     * @INFORMATION              :   This method is to  get Benefit Payable Trmt List
  5675.     * @PARAM                    :   class java.util.ArrayList
  5676.     * @RETURN                   :   class java.util.ArrayList
  5677.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5678.     * @LAST MODIFIED BY         :
  5679.     * @LAST MODIFIED DATE       :
  5680.     **/
  5681.     private ArrayList getBenefitPayableTrmtList(ArrayList trmtList)
  5682.         throws GOSIException
  5683.     {
  5684.         GOSIDebug.debugMessages("\t\t Start getBenefitPayableTrmtList - MaintainOHAllowanceSessionEJB");
  5685.         // will list of the dates for which benefit can be payed
  5686.         ArrayList newTrmtList = new ArrayList();
  5687.         for(int i=0; i<trmtList.size() ; i++)
  5688.         {
  5689.             TreatmentPeriodBean trmtBean =
  5690.                 (TreatmentPeriodBean)trmtList.get(i);
  5691.             // this gives the position of bean where the trmt type change in the trmt list
  5692.             int j = getChangeStatus(trmtList,trmtBean,i);
  5693.             TreatmentPeriodBean tempTrmtBean =
  5694.                 (TreatmentPeriodBean)trmtList.get(j);
  5695.             trmtBean.setEndDateGreg(tempTrmtBean.getEndDateGreg());
  5696.             newTrmtList.add(trmtBean);
  5697.             i=j;
  5698.         }
  5699.         GOSIDebug.debugMessages("\t\t End getBenefitPayableTrmtList - MaintainOHAllowanceSessionEJB");
  5700.         return newTrmtList;
  5701.     }
  5702.  
  5703.     /**
  5704.     * @METHOD NAME              :   getChangeStatus
  5705.     * @INFORMATION              :   This method is to get Change Status
  5706.                                     returns record id where trmt type changes
  5707.     * @PARAM                    :   class java.util.ArrayList,
  5708.                                     class gosi.business.socialinsurance.occupationalhazards.injury.beans.TreatmentPeriodBean,
  5709.                                     int
  5710.     * @RETURN                   :   int
  5711.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5712.     * @LAST MODIFIED BY         :
  5713.     * @LAST MODIFIED DATE       :
  5714.     **/
  5715.     private int getChangeStatus(ArrayList trmtList,
  5716.         TreatmentPeriodBean trmtBean,int recNum)throws GOSIException
  5717.     {
  5718.         GOSIDebug.debugMessages("\t\t Start getChangeStatus - MaintainOHAllowanceSessionEJB");
  5719.         int j = recNum;
  5720.         Timestamp tempDate = trmtBean.getStartDateGreg();
  5721.         GOSIDebug.debugMessages("tempDate :" + tempDate);
  5722.         GOSIDebug.debugMessages("j:" + j);
  5723.         GOSIDebug.debugMessages("Temp InjuryId:" + trmtBean.getInjuryId());
  5724.         GOSIDebug.debugMessages("Temp TreatmentId:" + trmtBean.getTreatmentId());
  5725.         GOSIDebug.debugMessages("_____________________________________");
  5726.         // logic to check where the treatment type changes from
  5727.         // element at recNum
  5728.         for (int i=recNum; i<trmtList.size() ; i++)
  5729.         {
  5730.             TreatmentPeriodBean tempTrmtBean =
  5731.                 (TreatmentPeriodBean)trmtList.get(i);
  5732.             GOSIDebug.debugMessages("TempTDate:" + tempTrmtBean.getStartDateGreg());
  5733.             GOSIDebug.debugMessages("j:" + j);
  5734.             GOSIDebug.debugMessages("Temp InjuryId" + tempTrmtBean.getInjuryId());
  5735.             GOSIDebug.debugMessages("Temp TId" + tempTrmtBean.getTreatmentId());
  5736.             if(tempTrmtBean.getInjuryId().equals(trmtBean.getInjuryId()) &&
  5737.               tempTrmtBean.getTreatmentId().equals(trmtBean.getTreatmentId())&&
  5738.               tempDate.equals(tempTrmtBean.getStartDateGreg()))
  5739.             {
  5740.                 j = i;
  5741.                 tempDate = GOSIUtilities.getNextDate
  5742.                         (tempTrmtBean.getStartDateGreg());
  5743.             }else
  5744.             {
  5745.                 j = i - 1;
  5746.                 break;
  5747.             }
  5748.         }
  5749.         GOSIDebug.debugMessages("\t\t End getChangeStatus - MaintainOHAllowanceSessionEJB");
  5750.         return j;
  5751.     }
  5752.  
  5753.     /**
  5754.     * @METHOD NAME              :   calculateDailyAllowance
  5755.     * @INFORMATION              :   This method is to calculate Daily Allowance
  5756.     * @PARAM                    :   class java.util.ArrayList,
  5757.                                     class java.util.ArrayList
  5758.     * @RETURN                   :   class java.util.ArrayList
  5759.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  5760.     * @LAST MODIFIED BY         :
  5761.     * @LAST MODIFIED DATE       :
  5762.     **/
  5763.     private ArrayList calculateDailyAllowance(ArrayList injuryList,
  5764.         ArrayList periodList,boolean isTreatmentApproved)
  5765.         throws GOSIException
  5766.     {
  5767.         GOSIDebug.debugMessages("\t\t Start calculateDailyAllowance - MaintainOHAllowanceSessionEJB");
  5768.         PreparedStatement ps = null;
  5769.         ResultSet rs = null;
  5770.         String sqlQuery = "";
  5771.         try
  5772.         {
  5773.             // this method calculates the dailly allowance
  5774.             // input is the injury list with all details of contriubtor
  5775.             // and period list with the actual payable period
  5776.  
  5777.             String calenderType = getCalendarType(injuryList);
  5778.             GOSIDebug.debugMessages("PeriodListsize:" + periodList.size() + ":");
  5779.             ArrayList trmtList = new ArrayList();
  5780.             int c= periodList.size();
  5781.             Timestamp workStopDate = null;
  5782.             Timestamp workStartDate = null;
  5783.             Timestamp firstInjuryDate = null;
  5784.             Timestamp benefitStartDate =
  5785.                 ((InjuryPopDetails)injuryList.get(0)).getBenefitStartDate();
  5786.             Timestamp benefitEndDate =
  5787.                 ((InjuryPopDetails)injuryList.get(0)).getBenefitEndDate();
  5788.             Long contributorId =
  5789.                 ((InjuryPopDetails)injuryList.get(0)).getContributorId();
  5790.             int periodListSize =periodList.size();
  5791.             for(int i=0; i<periodListSize; i++)
  5792.             {
  5793.                 trmtList.add(periodList.get(i));
  5794.             }
  5795.             String subQuery = "";
  5796.             int injuryListSize =injuryList.size();
  5797.             if(injuryListSize==1)
  5798.             {
  5799.                 subQuery = "";
  5800.             }else
  5801.             {
  5802.                 for(int i=0;i<(injuryListSize-1);i++)
  5803.                 {
  5804.                     subQuery = subQuery + " ?, ";
  5805.                 }
  5806.             }
  5807.             // Query to find from which date the benefit can be paid
  5808.             // benefit will be paid from work disability date
  5809.             // till date of return to work normally
  5810.             Timestamp currentDate = new Timestamp(System.currentTimeMillis());
  5811.             sqlQuery = " select " +
  5812.                 " min(NVL(DATECOMPLICATION,INJURYDATE)) MININJURYDATE , " +
  5813.                 " min(NVL(NVL(DATECOMPLICATION+1,WORKDISABILITYDATE),NVL(DATECOMPLICATION+1,INJURYDATE +1))) MINDISABLITYDATE," +
  5814.                 " max(NVL(DATERETURNTOWORK,?)) MAXRETURNTOWORKDATE from " +
  5815.                  SITables.T_INJURY +
  5816.                 " where INJURYID in ( " +
  5817.                  subQuery +
  5818.                 " ?) ";
  5819.             GOSIDebug.debugMessages("sqlQuery:" + sqlQuery + ":");
  5820.             GOSIDebug.debugMessages("\t\t Param 1 :" + currentDate + ":");
  5821.             ps = con.prepareStatement(sqlQuery);
  5822.             ps.setTimestamp(1,currentDate);
  5823.  
  5824.             for(int i=0;i<injuryListSize;i++)
  5825.             {
  5826.                 Long injuryId =
  5827.                     ((InjuryPopDetails)injuryList.get(i)).getInjuryID();
  5828.                 ps.setLong(i+2,injuryId.longValue());
  5829.                 GOSIDebug.debugMessages("\t\t Param " + (i+2) + ":" + injuryId.longValue() + ":");
  5830.             }
  5831.             rs = ps.executeQuery();
  5832.             while(rs.next())
  5833.             {
  5834.                Timestamp minInjuryDate = null;
  5835.                 if(rs.getObject("MININJURYDATE")!= null)
  5836.                 {
  5837.                     minInjuryDate = rs.getTimestamp("MININJURYDATE");
  5838.                 }
  5839.                 if(rs.getObject("MINDISABLITYDATE")!= null)
  5840.                 {
  5841.                     workStopDate = rs.getTimestamp("MINDISABLITYDATE");
  5842.                     GOSIDebug.debugMessages("TestIFB workstopdate: "+workStopDate) ;
  5843.                     if(minInjuryDate.equals(workStopDate))
  5844.                     {
  5845.                         workStopDate = GOSIUtilities.getNextDate(minInjuryDate);
  5846.                         GOSIDebug.debugMessages("TestIF workstopdate: "+workStopDate) ;
  5847.                     }
  5848.                     else if(minInjuryDate.after(workStopDate))
  5849.                     {
  5850.                     workStopDate = GOSIUtilities.getNextDate(minInjuryDate);
  5851.                     GOSIDebug.debugMessages("TestELSE workstopdate: "+workStopDate) ;
  5852.                     }
  5853.                 }
  5854.                 if(rs.getObject("MAXRETURNTOWORKDATE")!= null)
  5855.                 {
  5856.                     workStartDate = rs.getTimestamp("MAXRETURNTOWORKDATE");
  5857.                     if(workStartDate.compareTo(currentDate)==0)
  5858.                     {
  5859.                         workStartDate = null;
  5860.                     }
  5861.                 }
  5862.             }
  5863.             // logic to set the start and end dates
  5864.             Timestamp actualStartDate = null;
  5865.             Timestamp actualEndDate   = null;
  5866.             if(workStopDate!=null && workStopDate.compareTo(benefitStartDate)>0)
  5867.             {
  5868.                 actualStartDate  = workStopDate;
  5869.             }
  5870.             else
  5871.             {
  5872.                 actualStartDate  =benefitStartDate;
  5873.             }
  5874.  
  5875.             //GOSIDebug.debugMessages("startDate :"+startDate);
  5876.             GOSIDebug.debugMessages("ActualStartDate :" + actualStartDate + ":");
  5877.             /*if(canWaive)
  5878.             {
  5879.                 if(startDate.compareTo(actualStartDate)>0)
  5880.                 {
  5881.                     actualStartDate =startDate;
  5882.                 }
  5883.             }*/
  5884.             GOSIDebug.debugMessages("ActualStartDate :" + actualStartDate + ":");
  5885.             if(workStartDate!=null && workStartDate.compareTo(benefitEndDate)<0)
  5886.             {
  5887.                 actualEndDate  = OHUtilities.getPrevDate(workStartDate);
  5888.             }else
  5889.             {
  5890.                 actualEndDate  =benefitEndDate;
  5891.             }
  5892.             /*if(canWaive)
  5893.             {
  5894.                 startDate = getActualWaivableFromDate(injuryList);
  5895.             }*/
  5896.             GOSIDebug.debugMessages("Actual startDate :" + actualStartDate);
  5897.             GOSIDebug.debugMessages("Actual endDate :" + actualEndDate);
  5898.             int trmtListSize = trmtList.size();
  5899.             //Timestamp trmtStartDate =((TreatmentPeriodBean)trmtList.get(0)).getStartDateGreg();
  5900.             //Timestamp trmtEndDate =((TreatmentPeriodBean)trmtList.get(trmtListSize-1)).getEndDateGreg();
  5901.             for(int i=0;i<trmtList.size();i++)
  5902.             {
  5903.                 TreatmentPeriodBean trmtBean =(TreatmentPeriodBean)trmtList.get(i);
  5904.                 Timestamp trmtStartDate = trmtBean.getStartDateGreg();
  5905.                 Timestamp trmtEndDate = trmtBean.getEndDateGreg();
  5906.                  GOSIDebug.debugMessages("-----------------------------------");
  5907.                  GOSIDebug.debugMessages("Actual startDate :" + actualStartDate);
  5908.                  GOSIDebug.debugMessages("Actual endDate   :" + actualEndDate);
  5909.                  GOSIDebug.debugMessages("TrmtStartDate    :" + trmtStartDate);
  5910.                  GOSIDebug.debugMessages("TrmtEndDate      :" + trmtEndDate);
  5911.                 // if actual dates before Treatment period
  5912.                 if(actualStartDate.compareTo(trmtStartDate)<0 &&
  5913.                     actualEndDate.compareTo(trmtStartDate)<0)
  5914.                 {
  5915.                     GOSIDebug.debugMessages("----1");
  5916.                     GOSIDebug.debugMessages("1 element at"+ i+" removed");
  5917.                     trmtList.remove(i);
  5918.                     i=-1;
  5919.                 }
  5920.                 // if actual dates comes inside a Treatment period
  5921.                 // ActualstartDate after trmt st Date
  5922.                 else if(actualStartDate.compareTo(trmtStartDate)>0 &&
  5923.                     actualStartDate.compareTo(trmtEndDate)<=0)
  5924.                 {
  5925.                     GOSIDebug.debugMessages("----2 ");
  5926.                     trmtBean.setStartDateGreg(actualStartDate);
  5927.                     GOSIDebug.debugMessages("2 element at"+ i +" startDate set");
  5928.                 }
  5929.  
  5930.                 //Trmt period before actual startDate
  5931.                 if(trmtBean.getStartDateGreg().compareTo(actualStartDate)<0 &&
  5932.                     trmtBean.getEndDateGreg().compareTo(actualStartDate)<0)
  5933.                 {
  5934.                     GOSIDebug.debugMessages("----3");
  5935.                     GOSIDebug.debugMessages("3 at "+i+" removed before period");
  5936.                     trmtList.remove(i);
  5937.                     i=-1;
  5938.  
  5939.                 }
  5940.                 //trmt period after actual end Dates
  5941.                 if(trmtBean.getStartDateGreg().compareTo(actualEndDate)>0 &&
  5942.                     trmtBean.getEndDateGreg().compareTo(actualEndDate)>0)
  5943.                 {
  5944.                     GOSIDebug.debugMessages("----4");
  5945.                     GOSIDebug.debugMessages("4 at"+i+" removed after period");
  5946.                     trmtList.remove(i);
  5947.                     i=-1;
  5948.  
  5949.                 }
  5950.                 // actual enddate after trmtStartDate and
  5951.                 //  actual enddate before trmtEndDate
  5952.                 else
  5953.                 if(actualEndDate.compareTo(trmtBean.getStartDateGreg()) >= 0 &&
  5954.                     actualEndDate.compareTo(trmtBean.getEndDateGreg())< 0)
  5955.                 {
  5956.                     GOSIDebug.debugMessages("----5");
  5957.                     GOSIDebug.debugMessages(" 5 element at"+ i +" endDateSet");
  5958.                     trmtBean.setEndDateGreg(actualEndDate);
  5959.                 }
  5960.                 GOSIDebug.debugMessages("-----------------------------------");
  5961.             }
  5962.             GOSIDebug.debugMessages("TrmtListSize:" + trmtList.size());
  5963.             /*  code for making the day b4 the work startdate as outpatient if
  5964.             it happens to be out patient: modified code below
  5965.             if(workStartDate!=null)
  5966.             {
  5967.                 TreatmentPeriodBean trmtBean =
  5968.                     (TreatmentPeriodBean)trmtList.get(trmtList.size()-1);
  5969.                 Timestamp trmtStartDate = trmtBean.getStartDateGreg();
  5970.                 Timestamp trmtEndDate =trmtBean.getEndDateGreg();
  5971.                 if(workStartDate.compareTo
  5972.                     (GOSIUtilities.getNextDate(trmtEndDate))==0)
  5973.                 {
  5974.                     if(OHConstants.TRMT_TYPE_INPATIENT.equals
  5975.                         (trmtBean.getTreatmentType()))
  5976.                     {
  5977.                         if(trmtStartDate.compareTo(trmtEndDate)==0)
  5978.                         {
  5979.                             trmtBean.setTreatmentType
  5980.                                 (OHConstants.TRMT_TYPE_OUTPATIENT);
  5981.                         }else
  5982.                         {
  5983.                             TreatmentPeriodBean tempTrmtBean =
  5984.                                 new TreatmentPeriodBean(trmtBean);
  5985.                             tempTrmtBean.setStartDateGreg(trmtEndDate);
  5986.                             trmtBean.setEndDateGreg
  5987.                                 (OHUtilities.getPrevDate(trmtEndDate));
  5988.                             trmtList.add(tempTrmtBean);
  5989.                         }
  5990.                     }
  5991.                 }
  5992.             }
  5993.             */
  5994.             /* commented  iteration to make a single day outpatient if the single day
  5995.                happened to be an inpatient between two sickleave or out patient periods
  5996.             for(int i=1; i < (trmtList.size()-1);i++)
  5997.             {
  5998.                 TreatmentPeriodBean trmtBean=
  5999.                     (TreatmentPeriodBean)trmtList.get(i);
  6000.                 if(trmtBean.getStartDateGreg().compareTo
  6001.                     (trmtBean.getEndDateGreg())==0)
  6002.                 {
  6003.                     if(trmtBean.getTreatmentType().equals
  6004.                                 (OHConstants.TRMT_TYPE_INPATIENT))
  6005.                     {
  6006.                         if((!((TreatmentPeriodBean)trmtList.get(i+1)).
  6007.                                 getTreatmentType().equals
  6008.                                     (OHConstants.TRMT_TYPE_INPATIENT))&&
  6009.                         (!((TreatmentPeriodBean)trmtList.get(i-1)).
  6010.                                 getTreatmentType().equals
  6011.                                     (OHConstants.TRMT_TYPE_INPATIENT)))
  6012.                         {
  6013.                             ((TreatmentPeriodBean)trmtList.get(i)).
  6014.                                 setTreatmentType
  6015.                                     (OHConstants.TRMT_TYPE_OUTPATIENT);
  6016.                         }
  6017.                     }
  6018.                 }
  6019.             }
  6020.             */
  6021.             // code for making the last day of an inpatient period as out patient
  6022.  
  6023.             for(int i=0; i < (trmtList.size());i++)
  6024.             {
  6025.                 TreatmentPeriodBean trmtBean=
  6026.                     (TreatmentPeriodBean)trmtList.get(i);
  6027.                 if(trmtBean.getTreatmentType().equals
  6028.                                 (OHConstants.TRMT_TYPE_INPATIENT))
  6029.                 {
  6030.                     if(canLastDayMadeOutpatient(trmtBean,isTreatmentApproved))
  6031.                     {
  6032.                         if(1 == trmtBean.getTreatmentPeriod().intValue())
  6033.                         {
  6034.                             trmtBean.setTreatmentType(OHConstants.TRMT_TYPE_OUTPATIENT);
  6035.                         }else
  6036.                         {
  6037.                             Timestamp lastDate = trmtBean.getEndDateGreg();
  6038.                             trmtBean.setEndDateGreg(OHUtilities.getPrevDate(lastDate));
  6039.                             TreatmentPeriodBean tempTrmtBean =
  6040.                                 new TreatmentPeriodBean(trmtBean);
  6041.                             tempTrmtBean.setStartDateGreg(lastDate);
  6042.                             tempTrmtBean.setEndDateGreg(lastDate);
  6043.                             tempTrmtBean.setTreatmentType(OHConstants.TRMT_TYPE_OUTPATIENT);
  6044.                             trmtList.add(++i,tempTrmtBean);
  6045.                             GOSIDebug.debugMessages("i:"+i);
  6046.                         }
  6047.                     }
  6048.                 }
  6049.             }
  6050.  
  6051.             // printing each trmt start and end dates and type
  6052.             for (int i=0;i< trmtList.size();i++)
  6053.             {
  6054.                TreatmentPeriodBean trmtBean =
  6055.                    (TreatmentPeriodBean)trmtList.get(i);
  6056.                GOSIDebug.debugMessages("StartDate   :" + trmtBean.getStartDateGreg());
  6057.                GOSIDebug.debugMessages("EndDate     :" + trmtBean.getEndDateGreg());
  6058.                GOSIDebug.debugMessages("TrmtType    :" + trmtBean.getTreatmentType());
  6059.                GOSIDebug.debugMessages("HospitalType:" + trmtBean.getHospitalType());
  6060.             }
  6061.             Double totalWage =
  6062.                 ((InjuryPopDetails)injuryList.get(0)).getTotalConWage();
  6063.             Short  payableTo =
  6064.                 ((InjuryPopDetails)injuryList.get(0)).getBenefitPayableTo();
  6065.             GOSIDebug.debugMessages("TotalConWage:" + totalWage);
  6066.             // method called to calculate the benefit amount
  6067.             ArrayList benefitList =
  6068.                 calculateDailyAllowance(trmtList,totalWage,payableTo,calenderType);
  6069.             GOSIDebug.debugMessages("---------calculateDailyAllowance*-----------");
  6070.             for (int i=0;i<benefitList.size();i++)
  6071.             {
  6072.                 ((OHAllowanceBean)benefitList.get(i)).
  6073.                     setContributorId(contributorId);
  6074.             }
  6075.             // adjustment if last paid period is paid as  out patient
  6076.             // and current start date is inpatient
  6077.             adjustLastInpatientDate(injuryList,benefitList,isTreatmentApproved);
  6078.             GOSIDebug.debugMessages("\t\t End calculateDailyAllowance - MaintainOHAllowanceSessionEJB");
  6079.             return benefitList;
  6080.         }
  6081.         catch(GOSIException ge)
  6082.         {
  6083.             GOSIDebug.debugMessages("session-getTreatmentPeriodList :ge:"+ge);
  6084.             throw ge;
  6085.         }catch(Exception e)
  6086.         {
  6087.             GOSIDebug.debugMessages("session-getTreatmentPeriodList :e:"+e);
  6088.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  6089.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  6090.                 "getTreatmentPeriodList()",e,"CMN_ERR_1000");
  6091.         }
  6092.         finally
  6093.         {
  6094.             GOSIUtilities.cleanUp(ps,rs);
  6095.         }
  6096.     }
  6097.     /*
  6098.     */
  6099.  
  6100.     /**
  6101.     * @METHOD NAME              :   calculateCompanionAllowance
  6102.     * @INFORMATION              :   This method is to calculate companion Allowance
  6103.     * @PARAM                    :   class java.util.ArrayList,
  6104.                                     boolean
  6105.     * @RETURN                   :   class java.util.ArrayList
  6106.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  6107.     * @LAST MODIFIED BY         :
  6108.     * @LAST MODIFIED DATE       :
  6109.     **/
  6110.     private ArrayList calculateCompanionAllowance(ArrayList injuryList ,
  6111.         boolean resumeFlag,boolean isTreatmentApproved )throws GOSIException
  6112.     {
  6113.         GOSIDebug.debugMessages("\n\n--------calculateCompanionAllowance--------");
  6114.         String sqlQuery;
  6115.         ArrayList compAllowanceList=new ArrayList();
  6116.         PreparedStatement ps = null;
  6117.         ResultSet rs =null;
  6118.         boolean flag=true;
  6119.         String subQuery = "";
  6120.         int injuryListSize = injuryList.size();
  6121.         try
  6122.         {
  6123.             // companion allowance is calculated for every injury
  6124.             for (int i=0;i<injuryListSize;i++)
  6125.             {
  6126.                 InjuryPopDetails injuryBean =
  6127.                     (InjuryPopDetails)injuryList.get(i);
  6128.                 Long injuryId= injuryBean.getInjuryID();
  6129.                 Long contributorId = injuryBean.getContributorId();
  6130.                 ArrayList stoppedList =getInjuryStoppedPeriodList
  6131.                     (injuryBean,isTreatmentApproved);
  6132.                 // if its calculated from stop resume oh allowance
  6133.                 // the stopped period needs to be considered
  6134.                 // else all companion details to be paid
  6135.                 if(resumeFlag)
  6136.                 {
  6137.                     TreatmentPeriodBean trmtBean = new TreatmentPeriodBean();
  6138.                     trmtBean.setInjuryId(injuryBean.getInjuryID());
  6139.                     trmtBean.setStartDateGreg(injuryBean.getBenefitStartDate());
  6140.                     trmtBean.setEndDateGreg(injuryBean.getBenefitEndDate());
  6141.                     stoppedList =getStopPeriodList
  6142.                       (stoppedList,trmtBean,OHConstants.RESUME_ALLOWANCE_FLAG);
  6143.                 }
  6144.                 /*
  6145.                 sqlQuery = " select OHBENID from "+SITables.T_OHBENEFIT +
  6146.                     " where INJURYID =?  and "+
  6147.                     " ( OHBENCODE = ? or OHBENCODE = ? or OHBENCODE = ? )";
  6148.  
  6149.                 ps  =con.prepareStatement(sqlQuery);
  6150.                 ps.setLong (1,injuryId.longValue());
  6151.                 ps.setShort(2,OHConstants.OH_ALWNC_DOC_COMP_DAILY.shortValue());
  6152.                 ps.setShort(3,OHConstants.OH_ALWNC_NUR_COMP_DAILY.shortValue());
  6153.                 ps.setShort(4,OHConstants.OH_ALWNC_COMP_DAILY.shortValue());
  6154.                 rs=ps.executeQuery();
  6155.                 if(rs!=null)
  6156.                 {
  6157.                     while(rs.next())
  6158.                     {
  6159.                         flag=false;
  6160.                     }
  6161.                 }
  6162.                 */
  6163.                 //Query to get companion details for the benefit period
  6164.                 sqlQuery=" select INJURYID,TYPEOFCOMP,CONVALLOWANCECOMP, "+
  6165.                         " DAILYALLOWANCECOMP,STATUS, "+
  6166.                         " COMPSTDATE,COMPENDDATE from  "+
  6167.                           SITables.T_COMPANION +
  6168.                         " where INJURYID =? and STATUS = ? "+
  6169.                         " and COMPSTDATE >= ? and COMPENDDATE <=? "+
  6170.                         " and TYPEOFCOMP = ? ";
  6171.  
  6172.                 GOSIDebug.debugMessages("sqlQuery :"+sqlQuery);
  6173.                 GOSIDebug.debugMessages("flag:"+flag);
  6174.                 if(flag)
  6175.                 {
  6176.                     ps = con.prepareStatement(sqlQuery);
  6177.                     ps.setLong (1, injuryId.longValue());
  6178.                     ps.setShort(2,OHConstants.COMP_STS_APPROVED.shortValue());
  6179.                     ps.setTimestamp(3,injuryBean.getBenefitStartDate());
  6180.                     ps.setTimestamp(4,injuryBean.getBenefitEndDate());
  6181.                     ps.setShort(5,OHConstants.COMPANION_TYPE_OTHERS.shortValue());
  6182.                     rs  =ps.executeQuery();
  6183.                     double compDailyAllowanceAmt=0;
  6184.                     double compConvAllowanceAmt=0;
  6185.                     Short compType = null;
  6186.                     OHAllowanceBean benefitBean=null;
  6187.                     while(rs.next())
  6188.                     {
  6189.                         GOSIDebug.debugMessages("inside rs.next");
  6190.                         benefitBean=new OHAllowanceBean();
  6191.                         benefitBean.setInjuryId
  6192.                             (new Long( rs.getLong("INJURYID")));
  6193.                         compType = new Short(rs.getShort("TYPEOFCOMP"));
  6194.                         compDailyAllowanceAmt=
  6195.                             rs.getDouble("DAILYALLOWANCECOMP");
  6196.                         if(rs.getObject("CONVALLOWANCECOMP")!=null)
  6197.                         {
  6198.                             compConvAllowanceAmt=
  6199.                                 rs.getDouble("CONVALLOWANCECOMP");
  6200.                         }
  6201.                         benefitBean.setBenStDateGreg
  6202.                             (rs.getTimestamp("COMPSTDATE"));
  6203.                         benefitBean.setBenEndDateGreg
  6204.                             (rs.getTimestamp("COMPENDDATE"));
  6205.                     }
  6206.                     GOSIDebug.debugMessages("benefitbean :"+benefitBean);
  6207.                     if(benefitBean == null)
  6208.                     {
  6209.                         compAllowanceList=new ArrayList();
  6210.                     }
  6211.                     else
  6212.                     {
  6213.                         // calculating companion allowance paid
  6214.                         Timestamp compStartDate =benefitBean.getBenStDateGreg();
  6215.                         Timestamp compEndDate=benefitBean.getBenEndDateGreg() ;
  6216.                         OHAllowanceBean compDailyAllowance=new OHAllowanceBean();
  6217.                         if(compDailyAllowanceAmt!=0)
  6218.                         {
  6219.                             compDailyAllowance.setInjuryId(injuryId);
  6220.                             compDailyAllowance.setContributorId(contributorId);
  6221.                             compDailyAllowance.setBenStDateGreg
  6222.                                 (benefitBean.getBenStDateGreg());
  6223.                             compDailyAllowance.setBenEndDateGreg
  6224.                                 (benefitBean.getBenEndDateGreg());
  6225.                             compDailyAllowance.setBenAmount
  6226.                                 (new Double(compDailyAllowanceAmt));
  6227.  
  6228.                             if(OHConstants.COMPANION_TYPE_DOCTOR.
  6229.                                 equals(compType))
  6230.                             {
  6231.                                 compDailyAllowance.setBenefitPayableTo
  6232.                                     (OHConstants.OH_BNFT_PAY_TO_HOS);
  6233.                                 compDailyAllowance.setOhBenCode
  6234.                                     (OHConstants.OH_ALWNC_DOC_COMP_DAILY);
  6235.                                 compDailyAllowance.setPartyCode
  6236.                                     (getPayableHospital(injuryId,
  6237.                                         benefitBean.getBenStDateGreg(),isTreatmentApproved));
  6238.                             }else
  6239.                             if(OHConstants.COMPANION_TYPE_NURSE.
  6240.                                 equals(compType))
  6241.                             {
  6242.                                 compDailyAllowance.setBenefitPayableTo
  6243.                                     (OHConstants.OH_BNFT_PAY_TO_HOS);
  6244.                                 compDailyAllowance.setOhBenCode
  6245.                                     (OHConstants.OH_ALWNC_NUR_COMP_DAILY);
  6246.                                 compDailyAllowance.setPartyCode
  6247.                                     (getPayableHospital(injuryId,
  6248.                                         benefitBean.getBenStDateGreg(),isTreatmentApproved));
  6249.                             }else
  6250.                             {
  6251.                                 compDailyAllowance.setBenefitPayableTo
  6252.                                     (OHConstants.OH_BNFT_PAY_TO_CON);
  6253.                                 compDailyAllowance.setOhBenCode
  6254.                                     (OHConstants.OH_ALWNC_COMP_DAILY);
  6255.                             }
  6256.                             compAllowanceList.add(compDailyAllowance);
  6257.                         }
  6258.                     }
  6259.                 }
  6260.             }
  6261.             //GOSIDebug.debugMessages("comPList size:"+compAllowanceList.size());
  6262.             GOSIDebug.debugMessages("-------calculateCompanionAllowance*----------");
  6263.             return compAllowanceList;
  6264.         }
  6265.     /*  catch(GOSIException ge)
  6266.         {
  6267.              GOSIDebug.debugMessages("session-compAlwnc :The exception is "+ge);
  6268.              throw ge;
  6269.         }*/
  6270.         catch(Exception e)
  6271.         {
  6272.             GOSIDebug.debugMessages("session-compAlwnc :The exception is "+e);
  6273.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  6274.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  6275.                 "calculateCompanionAllowance()",e,"CMN_ERR_1000");
  6276.         }
  6277.         finally
  6278.         {
  6279.           GOSIUtilities.cleanUp(ps, rs);
  6280.         }
  6281.  
  6282.     }
  6283.  
  6284.  
  6285.     /**
  6286.     * @METHOD NAME              :   calculateConveyenceAllowance
  6287.     * @INFORMATION              :   This method is to calculate Conveyence Allowance
  6288.     * @PARAM                    :   class java.util.ArrayList,
  6289.                                     boolean
  6290.     * @RETURN                   :   class java.util.ArrayList
  6291.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  6292.     * @LAST MODIFIED BY         :
  6293.     * @LAST MODIFIED DATE       :
  6294.     **/
  6295.     private ArrayList calculateConveyenceAllowance
  6296.         (ArrayList injuryList, boolean resumeFlag ,boolean isTreatmentApproved )
  6297.             throws GOSIException
  6298.     {
  6299.         GOSIDebug.debugMessages("\n\n-------calculateConveyenceAllowance---------");
  6300.         ArrayList conveyanceBenefitList = new ArrayList();
  6301.         PreparedStatement ps = null;
  6302.         ResultSet rs =null;
  6303.         int injuryListSize = injuryList.size();
  6304.         try
  6305.         {
  6306.             // visit allowance will be  calculated for each injury
  6307.             for(int j=0;j<injuryListSize;j++)
  6308.             {
  6309.  
  6310.                 ps = null;
  6311.                 rs =null;
  6312.                 ArrayList visitsList=new ArrayList();
  6313.                 InjuryPopDetails injuryBean=(InjuryPopDetails)injuryList.get(j);
  6314.                 Timestamp startDate=injuryBean.getBenefitStartDate();
  6315.                 Timestamp injuryDate = injuryBean.getInjuryDate();
  6316.                 Timestamp visitLastDate = null;
  6317.                 if(startDate.compareTo(injuryDate)<0)
  6318.                 {
  6319.                     startDate = injuryDate;
  6320.                 }
  6321.                 Timestamp endDate=injuryBean.getBenefitEndDate();
  6322.  
  6323.                 GOSIDebug.debugMessages("startDate::::::::"+startDate);
  6324.                 GOSIDebug.debugMessages("endDate::::::::::"+endDate);
  6325.                 Short payableTo = injuryBean.getBenefitPayableTo();
  6326.                 Long contributorId = injuryBean.getContributorId();
  6327.                 Long injuryId = injuryBean.getInjuryID();
  6328.  
  6329.                 boolean firstVisitflag =canFirstVisitBeCalculated(injuryBean);
  6330.                 // Query to get the visit records for the period
  6331.                 String sqlQuery;
  6332.                 sqlQuery=" select a.VISITID,a.INJURYID,a.TREATMENTID,"+
  6333.                     " NVL(a.DATEOFVISIT ,(select ENDDATE from "+
  6334.                     SITables.T_TREATMENT +
  6335.                     " b where b.TREATMENTID =a.TREATMENTID) )  VISITDATE ,"+
  6336.                     " a.NUMBERVISITS  from "+SITables.T_VISITS +" a where "+
  6337.                     " injuryId = ?  "+
  6338.                     " and VISITSTATUS = ? order by VISITDATE asc ";
  6339.                 OHAllowanceBean benefitBean=new OHAllowanceBean();
  6340.  
  6341.                 // getting the stopped period list for the injury
  6342.                 ArrayList stoppedList =getInjuryStoppedPeriodList(injuryBean,isTreatmentApproved);
  6343.                 if(resumeFlag)
  6344.                 {
  6345.                     TreatmentPeriodBean trmtBean = new TreatmentPeriodBean();
  6346.                     trmtBean.setInjuryId(injuryBean.getInjuryID());
  6347.                     trmtBean.setStartDateGreg(injuryBean.getBenefitStartDate());
  6348.                     trmtBean.setEndDateGreg(injuryBean.getBenefitEndDate());
  6349.                     stoppedList =getStopPeriodList
  6350.                       (stoppedList,trmtBean,OHConstants.RESUME_ALLOWANCE_FLAG);
  6351.                 }
  6352.                 ps=con.prepareStatement(sqlQuery);
  6353.                 ps.setLong(1,injuryId.longValue());
  6354.                 ps.setShort(2, OHConstants.VISITS_STS_APPROVED.shortValue());
  6355.                 GOSIDebug.debugMessages("sqlQuery:"+sqlQuery);
  6356.                 rs=ps.executeQuery();
  6357.                 while(rs.next())
  6358.                 {
  6359.                     GOSIDebug.debugMessages("Has visits");
  6360.                     VisitBean visitBean =new VisitBean();
  6361.                     visitBean.setVisitId(new Long(rs.getLong("VISITID")));
  6362.                     visitBean.setInjuryId(new Long(rs.getLong("INJURYID")));
  6363.                     Timestamp visitDate =rs.getTimestamp("VISITDATE");
  6364.                     visitBean.setDateOfVisitGreg(visitDate);
  6365.                     visitBean.setNumberVisits
  6366.                         (new Integer(rs.getInt("NUMBERVISITS")));
  6367.                     visitBean.setTreatmentId
  6368.                         (new Long(rs.getLong("TREATMENTID")));
  6369.  
  6370.                     if(startDate.compareTo(visitDate)<=0&&
  6371.                         endDate.compareTo(visitDate)>=0)
  6372.                     {
  6373.                         if(isValidVisitDate(stoppedList,visitBean))
  6374.                         {
  6375.                             visitsList.add(visitBean);
  6376.                         }
  6377.                         visitLastDate = visitDate ;
  6378.                     }
  6379.                 }
  6380.                 if(visitLastDate != null)
  6381.                 {
  6382.                     if(visitLastDate.compareTo(endDate) < 0)
  6383.                     {
  6384.                         endDate =visitLastDate;
  6385.                     }
  6386.                 }
  6387.                 GOSIDebug.debugMessages("visitList size:"+visitsList.size());
  6388.  
  6389.                 double conveyenceAmount=0;
  6390.  
  6391.                 // calling rule bean to get the visit amount per day
  6392.                 // if first visit flag is true 15 riyals is subtracted from the vist amount
  6393.                 for(int i=0;i<visitsList.size();i++)
  6394.                 {
  6395.                     VisitBean visitBean=(VisitBean)visitsList.get(i);
  6396.                     double amount=0;
  6397.  
  6398.                     amount = visitBean.getNumberVisits().intValue()*
  6399.                             OHRuleBean.getVisitAmountperVisit();
  6400.                     if(i==0 && firstVisitflag)
  6401.                     {
  6402.                         amount = amount - OHRuleBean.getFirstVisitAmount();
  6403.                     }
  6404.                     if(amount > OHRuleBean.getMaxVisitAmountperDay())
  6405.                     {
  6406.                         amount=OHRuleBean.getMaxVisitAmountperDay();
  6407.                     }
  6408.                     conveyenceAmount=conveyenceAmount+amount;
  6409.                 }
  6410.  
  6411.                 // setting the visit amount into the benefit bean
  6412.                 if(conveyenceAmount!=0)
  6413.                 {
  6414.                     benefitBean.setInjuryId(injuryBean.getInjuryID());
  6415.                     benefitBean.setBenStDateGreg(startDate);
  6416.                     benefitBean.setBenEndDateGreg(endDate);
  6417.                     benefitBean.setBenAmount(new Double(conveyenceAmount));
  6418.                     benefitBean.setOhBenCode(OHConstants.OH_ALWNC_CONVEYENCE);
  6419.                     benefitBean.setBenefitPayableTo(payableTo);
  6420.                     benefitBean.setContributorId(contributorId);
  6421.                     benefitBean.setTotalContWage(injuryBean.getTotalConWage());
  6422.                     conveyanceBenefitList.add(benefitBean);
  6423.                 }else
  6424.                 {
  6425.                     benefitBean=null;
  6426.                 }
  6427.             }
  6428.             GOSIDebug.debugMessages("-------calculateConveyenceAllowance*--------");
  6429.  
  6430.             return conveyanceBenefitList;
  6431.         }
  6432.         catch(Exception e)
  6433.         {
  6434.             GOSIDebug.debugMessages("session-calConv :The exception is "+e);
  6435.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  6436.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  6437.                 "calculateConveyenceAllowance()",e,"CMN_ERR_1000");
  6438.         }
  6439.         finally
  6440.         {
  6441.              GOSIUtilities.cleanUp(ps, rs);
  6442.         }
  6443.  
  6444.     }
  6445.  
  6446.     /**
  6447.     * @METHOD NAME              :   canLastDayMadeOutpatient
  6448.     * @INFORMATION              :   This method is to  check wether last day can
  6449.                                     be Made Outpatient
  6450.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.TreatmentPeriodBean
  6451.     * @RETURN                   :   boolean
  6452.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  6453.     * @LAST MODIFIED BY         :
  6454.     * @LAST MODIFIED DATE       :
  6455.     **/
  6456.     private boolean canLastDayMadeOutpatient(TreatmentPeriodBean trmtBean,
  6457.         boolean isTreatmentApproved)
  6458.     throws GOSIException
  6459.     {
  6460.         PreparedStatement ps = null;
  6461.         ResultSet rs = null;
  6462.         boolean canLastDayMadeOutpatient = false;
  6463.         try
  6464.         {
  6465.             // for every treatment if the next day of the end date is of
  6466.             // any type  other than inpatient the last day can be made out patient
  6467.             // but the current treatment type shd be inpatient
  6468.             Timestamp nextDate = GOSIUtilities.getNextDate(trmtBean.getEndDateGreg());
  6469.             Short trmtType = null;
  6470.             String sqlQuery = " select TREATMENTTYPE from "+
  6471.                 SITables.T_TREATMENT + " where "+
  6472.                 "INJURYID = ? and STARTDATE <= ? and  ENDDATE >= ? "+
  6473.                 " and TREATMENTSTATUS =? ";
  6474.             ps = con.prepareStatement(sqlQuery);
  6475.             ps.setLong(1, trmtBean.getInjuryId().longValue());
  6476.             ps.setTimestamp(2,nextDate);
  6477.             ps.setTimestamp(3,nextDate);
  6478.             if(isTreatmentApproved)
  6479.             {
  6480.                 ps.setShort(4,OHConstants.TRMT_STS_APPROVED.shortValue());
  6481.             }else
  6482.             {
  6483.                 ps.setShort(4,OHConstants.TRMT_STS_ENTERED.shortValue());
  6484.             }
  6485.             rs = ps.executeQuery();
  6486.             while(rs.next())
  6487.             {
  6488.                 if(rs.getObject("TREATMENTTYPE")!=null)
  6489.                 {
  6490.                     trmtType = new Short(rs.getShort("TREATMENTTYPE"));
  6491.                 }
  6492.             }
  6493.             GOSIDebug.debugMessages("TrmtType :" + trmtType + ":");
  6494.             if( trmtType!= null )
  6495.             {
  6496.                 if(OHConstants.TRMT_TYPE_INPATIENT.equals(trmtType))
  6497.                 {
  6498.                     canLastDayMadeOutpatient = false;
  6499.                 }else
  6500.                 {
  6501.                     canLastDayMadeOutpatient = true;
  6502.                 }
  6503.             }else
  6504.             {
  6505.                 canLastDayMadeOutpatient = true;
  6506.             }
  6507.             return canLastDayMadeOutpatient;
  6508.         }
  6509.         catch(GOSIException ge)
  6510.         {
  6511.             throw ge;
  6512.         }
  6513.         catch(Exception e)
  6514.         {
  6515.             GOSIDebug.debugMessages("session-canLastDayMadeOutpatient:e:"+e);
  6516.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  6517.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  6518.                 "canLastDayMadeOutpatient()",e,"CMN_ERR_1000");
  6519.         }
  6520.         finally
  6521.         {
  6522.              GOSIUtilities.cleanUp(ps, rs);
  6523.         }
  6524.     }
  6525.  
  6526.  
  6527.     /**
  6528.     * @METHOD NAME              :   canFirstVisitBeCalculated
  6529.     * @INFORMATION              :   This method is to  check whether First Visit Be Calculated
  6530.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  6531.     * @RETURN                   :   boolean
  6532.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  6533.     * @LAST MODIFIED BY         :
  6534.     * @LAST MODIFIED DATE       :
  6535.     **/
  6536.     private boolean canFirstVisitBeCalculated(InjuryPopDetails injuryBean)
  6537.         throws GOSIException
  6538.     {
  6539.         GOSIDebug.debugMessages("\n\n--------canFirstVisitBeCalculated----------");
  6540.         PreparedStatement ps=null;
  6541.         ResultSet rs= null;
  6542.         try
  6543.         {
  6544.             // if no visits has been paid for an injury the flag
  6545.             // canFirstVisitBeCalculated is true else false
  6546.             Long injuryId = injuryBean.getInjuryID();
  6547.             boolean canFirstVisitBeCalculated =true;
  6548.             String sqlQuery = "select OHBENID from "+
  6549.                 SITables.T_OHBENEFIT +
  6550.                 " where INJURYID = ? "+
  6551.                 " and OHBENCODE = ? "+
  6552.                 " and BENSTATUS not in(?,?) " ;
  6553.  
  6554.             ps =con.prepareStatement(sqlQuery);
  6555.             ps.setLong(1,injuryId.longValue());
  6556.             ps.setShort(2,OHConstants.OH_ALWNC_CONVEYENCE.shortValue());
  6557.             ps.setShort(3,OHConstants.OH_BNFT_STS_REJECTED.shortValue());
  6558.             ps.setShort(4,OHConstants.OH_BNFT_STS_CANCELLED.shortValue());
  6559.             rs = ps.executeQuery();
  6560.             if(rs.next())
  6561.             {
  6562.                 canFirstVisitBeCalculated = false;
  6563.             }
  6564.  
  6565.  
  6566.             GOSIDebug.debugMessages("---------canFirstVisitBeCalculated*--------"+canFirstVisitBeCalculated);
  6567.             return canFirstVisitBeCalculated;
  6568.         }
  6569.         catch(Exception e)
  6570.         {
  6571.             GOSIDebug.debugMessages("session:canFirstVisitBeCalculated:e:"+e);
  6572.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  6573.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  6574.                 "getTotalContibutorWage()",e,"CMN_ERR_1000");
  6575.         }
  6576.         finally
  6577.         {
  6578.             GOSIUtilities. cleanUp(ps,rs);
  6579.         }
  6580.     }
  6581.  
  6582.     /**
  6583.     * @METHOD NAME              :   getIntimationDates
  6584.     * @INFORMATION              :   This method is to  get Intimation Dates from injury
  6585.     * @PARAM                    :   class java.util.ArrayList
  6586.     * @RETURN                   :   class java.util.HashMap
  6587.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  6588.     * @LAST MODIFIED BY         :
  6589.     * @LAST MODIFIED DATE       :
  6590.     **/
  6591.     private HashMap getIntimationDates
  6592.         (ArrayList injuryList) throws GOSIException
  6593.     {
  6594.         GOSIDebug.debugMessages("----------getIntimationDates-----------");
  6595.         try
  6596.         {
  6597.             // this method sets the varios intimation dates for the injury
  6598.             // like the worker notification date , employer notification date
  6599.             // and based on the dates the benefit start date is calculated
  6600.             // if there is a delay in notification the the delay notification
  6601.             // flag is set
  6602.             int injuryListSize = injuryList.size();
  6603.             for (int i=0; i< injuryListSize; i++ )
  6604.             {
  6605.                 InjuryPopDetails injuryBean =
  6606.                     (InjuryPopDetails)injuryList.get(i);
  6607.                 Timestamp injuryDate = injuryBean.getInjuryDate();
  6608.                 Timestamp workDisabilityDate=injuryBean.getWorkDisabilityDate();
  6609.                 Timestamp employerNotifyDate=injuryBean.getEmployerNotifyDate();
  6610.                 Timestamp workerIntimationDate =
  6611.                     injuryBean.getWorkerIntimationDate();
  6612.                 Timestamp startDate = workDisabilityDate;
  6613.                 int workerIntimationDay =
  6614.                     OHUtilities.getDays(injuryDate,workerIntimationDate);
  6615.                 int employerNotifyDay =
  6616.                   OHUtilities.getDays(workerIntimationDate,employerNotifyDate);
  6617.                 boolean payFromInjuryDate = true;
  6618.                 boolean payFromWorkerIntimationDate =false;
  6619.                 boolean payFromEmpNotifyDate =false;
  6620.                 boolean canWaiveDelay =false;
  6621.                 Short reportingStatus = null;
  6622.                 GOSIDebug.debugMessages("workerIntimationDay:"+workerIntimationDay);
  6623.                 GOSIDebug.debugMessages("employerNotifyDay:"+employerNotifyDay);
  6624.  
  6625.                 if(workerIntimationDay > OHRuleBean.getMaxLimitWorkerIntimation())
  6626.                 {
  6627.                     payFromInjuryDate = false ;
  6628.                     payFromWorkerIntimationDate =true;
  6629.  
  6630.                     GOSIDebug.debugMessages("payFromWorkerIntimationDate:"+payFromWorkerIntimationDate);
  6631.                     GOSIDebug.debugMessages("payFromEmpNotifyDate:"+payFromEmpNotifyDate);
  6632.  
  6633.                 }
  6634.                 if(employerNotifyDay > OHRuleBean.getMaxLimitEmployerNotification())
  6635.                 {
  6636.                     payFromInjuryDate = false ;
  6637.                     payFromEmpNotifyDate = true;
  6638.  
  6639.                     GOSIDebug.debugMessages("payFromWorkerIntimationDate:"+payFromWorkerIntimationDate);
  6640.                     GOSIDebug.debugMessages("payFromEmpNotifyDate:"+payFromEmpNotifyDate);
  6641.  
  6642.                 }
  6643.                 if( payFromEmpNotifyDate && payFromWorkerIntimationDate)
  6644.                 {
  6645.                     GOSIDebug.debugMessages(""+payFromWorkerIntimationDate+","+payFromEmpNotifyDate);
  6646.                     startDate  = employerNotifyDate;
  6647.                     reportingStatus = injuryBean.LATE_REPORTED;
  6648.                 }else
  6649.                 if( !payFromEmpNotifyDate && payFromWorkerIntimationDate)
  6650.                 {
  6651.                     GOSIDebug.debugMessages(""+payFromWorkerIntimationDate+","+payFromEmpNotifyDate);
  6652.                     startDate  = workerIntimationDate;
  6653.                     reportingStatus = injuryBean.WORKER_LATE_REPORTING;
  6654.                 }else
  6655.                 if( !payFromEmpNotifyDate && !payFromWorkerIntimationDate)
  6656.                 {
  6657.                     GOSIDebug.debugMessages(""+payFromWorkerIntimationDate+","+payFromEmpNotifyDate);
  6658.                     startDate  = workDisabilityDate;
  6659.                     reportingStatus = injuryBean.NORMAL_REPORTING;
  6660.                 }else
  6661.                 if( payFromEmpNotifyDate && !payFromWorkerIntimationDate)
  6662.                 {
  6663.                     GOSIDebug.debugMessages(""+payFromWorkerIntimationDate+","+payFromEmpNotifyDate);
  6664.                     startDate  = employerNotifyDate;
  6665.                     reportingStatus = injuryBean.EMPLOYER_LATE_REPORTING;
  6666.                 }
  6667.                 GOSIDebug.debugMessages("startDate :"+startDate);
  6668.                 injuryBean.setStartDate(startDate);
  6669.                 injuryBean.setReportingStatus(reportingStatus);
  6670.             }
  6671.             Timestamp startDate =null;
  6672.             for (int i=0; i< injuryListSize; i++ )
  6673.             {
  6674.                 InjuryPopDetails injuryBean =
  6675.                     (InjuryPopDetails)injuryList.get(i);
  6676.                 if(startDate ==null)
  6677.                 {
  6678.                     startDate = injuryBean.getStartDate();
  6679.                 }else
  6680.                 {
  6681.                     if( startDate.compareTo(injuryBean.getStartDate())>0)
  6682.                     {
  6683.                         startDate =injuryBean.getStartDate();
  6684.                     }
  6685.                 }
  6686.             }
  6687.             GOSIDebug.debugMessages("startDate :"+startDate);
  6688.             HashMap details = new HashMap();
  6689.             /*for (int i=0; i< injuryListSize; i++ )
  6690.             {
  6691.                 InjuryPopDetails injuryBean = (injuryPopDetails)injurylist.get(i);
  6692.                 injuryBean.setStartDate(startDate);
  6693.             }*/
  6694.             details.put("injuryList",injuryList);
  6695.             details.put("startDate",startDate);
  6696.             GOSIDebug.debugMessages("----------getIntimationDates**-----------");
  6697.             return details;
  6698.         }
  6699.         catch (Exception e)
  6700.         {
  6701.             throw new GOSIException();
  6702.         }
  6703.     }
  6704.  
  6705.  
  6706.     /**
  6707.     * @METHOD NAME              :   searchOHAllowance
  6708.     * @INFORMATION              :   This method is to  search OH Allowance
  6709.     * @PARAM                    :   class java.lang.Long
  6710.     * @RETURN                   :   class java.util.HashMap
  6711.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  6712.     * @LAST MODIFIED BY         :
  6713.     * @LAST MODIFIED DATE       :
  6714.     **/
  6715.  
  6716.     public HashMap searchOHAllowance(Long workflowId)
  6717.         throws GOSIException
  6718.     {
  6719.         long startTime   = 0;
  6720.         long endTime     = 0;
  6721.         long elapsedTime = 0;
  6722.         startTime = System.currentTimeMillis();
  6723.         // here the oh benefit records for the workflowid is fetched
  6724.         // from the oh benefit table , this method is called in
  6725.         // workflow
  6726.         PreparedStatement ps = null;
  6727.         ResultSet rs =null;
  6728.         //Query to get benefit details
  6729.         String sqlQuery = "" + "select " + " OHBENID, " + " INJURYID, "
  6730.                 + " CONTRIBUTORID, " + "    FIELDOFFICECODE, " + " OHBENCODE, "
  6731.                 + " OHBENTYPE, " + "    BENSTDATE, " + " BENSTDATEENTFMT,"
  6732.                 + " BENENDDATE, " + "   BENENDDATEENTFMT, " + " BENAMOUNT, "
  6733.                 + " BENSTATUS, " + " PAYMENTMODE, " + " BANKCODE, "
  6734.                 + " BANKACCNUMBER, " + " DATEPAYMENT, "
  6735.                 + " DATEPAYMENTENTFMT, " + " WORKFLOWSTATUS, JOURNALHEADERID , "
  6736.                 + " TOTALCONTWAGE, " + " CREATEDBY, " + "   CREATIONTIMESTAMP, "
  6737.                 + " LASTMODIFIEDBY, " + "   LASTMODIFIEDTIMESTAMP, "
  6738.                 + "   REJECTIONCODE, " + " PAYABLETO, " + "   PARTYCODE, "
  6739.                 + " DESCRIPTION, " + "  WORKFLOWID from " + SITables.T_OHBENEFIT
  6740.                 + " where WORKFLOWID = ? " + " order by OHBENID ";
  6741.         HashMap details = new HashMap();
  6742.         try
  6743.         {
  6744.             Long conId = null;         
  6745.             GOSIDebug.debugMessages("SqlQuery :" + sqlQuery + ":");
  6746.             GOSIDebug.debugMessages("\t\t Param 1 :" + workflowId.longValue() + ":");
  6747.             String entFmt = OHConstants.DEFAULT_ENT_FMT;
  6748.             ArrayList benefitList=new ArrayList();
  6749.             con=GOSIUtilities.getConnection
  6750.                 (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  6751.             ps=con.prepareStatement(sqlQuery);
  6752.             ps.setLong(1,workflowId.longValue());
  6753.             rs=ps.executeQuery();
  6754.             while(rs.next())
  6755.             {
  6756.                 OHAllowanceBean benefitBean=new OHAllowanceBean();
  6757.                 benefitBean.setOhBenId(new Long(rs.getLong("OHBENID")));
  6758.                 benefitBean.setInjuryId (new Long(rs.getLong("INJURYID")));
  6759.                 benefitBean.setContributorId
  6760.                     (new Long(rs.getLong("CONTRIBUTORID")));
  6761.  
  6762.                 GOSIDebug.debugMessages("----conId:"+conId);
  6763.                 if(conId !=null)
  6764.                 {
  6765.  
  6766.                     GOSIDebug.debugMessages("conId:"+conId);
  6767.                     GOSIDebug.debugMessages("conId:"+benefitBean.getContributorId());
  6768.  
  6769.                     if(!conId.equals( benefitBean.getContributorId()))
  6770.                     {
  6771.                         throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  6772.                         GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  6773.                         "searchOHAllowance()",
  6774.                         "Data Corrupted,Contact System Administrator",
  6775.                         null,"CMN_ERR_1000");
  6776.                     }
  6777.                 }else
  6778.                 {
  6779.                     conId = benefitBean.getContributorId();
  6780.                 }
  6781.                 GOSIDebug.debugMessages("---conId:"+conId);
  6782.  
  6783.                 benefitBean.setFieldofficeCode
  6784.                     (new Short(rs.getShort("FIELDOFFICECODE")));
  6785.                 benefitBean.setOhBenCode(new Short(rs.getShort("OHBENCODE")));
  6786.                 benefitBean.setOhBenType(rs.getString("OHBENTYPE"));
  6787.                 benefitBean.setBenStDateGreg(rs.getTimestamp("BENSTDATE"));
  6788.                 benefitBean.setBenStDateEntFmt(rs.getString("BENSTDATEENTFMT"));
  6789.                 benefitBean.setBenEndDateGreg
  6790.                     (rs.getTimestamp("BENENDDATE"));
  6791.                 benefitBean.setBenEndDateEntFmt
  6792.                     (rs.getString("BENENDDATEENTFMT"));
  6793.                 entFmt=benefitBean.getBenEndDateEntFmt();
  6794.                 benefitBean.setBenAmount(new Double(rs.getDouble("BENAMOUNT")));
  6795.                 benefitBean.setBenStatus(new Short(rs.getShort("BENSTATUS")));
  6796.                
  6797.                 if(rs.getObject("JOURNALHEADERID")!=null)
  6798.                 {
  6799.                     benefitBean.setJournalHeaderId
  6800.                         (new Long(rs.getLong("JOURNALHEADERID")));
  6801.                 }
  6802.                
  6803.                 if(rs.getObject("PAYMENTMODE")!=null)
  6804.                 {
  6805.                     benefitBean.setPaymentMode
  6806.                         (new Short(rs.getShort("PAYMENTMODE")));
  6807.                 }
  6808.                 if(rs.getObject("BANKCODE")!=null)
  6809.                 {
  6810.                     benefitBean.setBankCode
  6811.                         (new Integer(rs.getInt("BANKCODE")));
  6812.                 }
  6813.                 if(rs.getObject("BANKACCNUMBER")!=null)
  6814.                 {
  6815.                     benefitBean.setBankAccNumber
  6816.                         (new Long(rs.getLong("BANKACCNUMBER")));
  6817.                 }
  6818.                 if(rs.getObject("DATEPAYMENT")!=null)
  6819.                 {
  6820.                     benefitBean.setDatePaymentGreg
  6821.                         (rs.getTimestamp("DATEPAYMENT"));
  6822.                     benefitBean.setDatePaymentEntFmt
  6823.                         (rs.getString("DATEPAYMENTENTFMT"));
  6824.                 }
  6825.                 benefitBean.setWorkflowStatus
  6826.                     (new Short(rs.getShort("WORKFLOWSTATUS")));
  6827.                 benefitBean.setTotalContWage
  6828.                     (new Double(rs.getDouble("TOTALCONTWAGE")));
  6829.                 benefitBean.setCreatedBy(new Long(rs.getLong("CREATEDBY")));
  6830.                 benefitBean.setCreationTimestamp
  6831.                     (rs.getTimestamp("CREATIONTIMESTAMP"));
  6832.                 if(rs.getObject("LASTMODIFIEDBY")!=null)
  6833.                 {
  6834.                     benefitBean.setLastModifiedBy
  6835.                         (new Long(rs.getLong("LASTMODIFIEDBY")));
  6836.                     benefitBean.setLastModifiedTimestamp
  6837.                         (rs.getTimestamp("LASTMODIFIEDTIMESTAMP"));
  6838.                 }
  6839.                 if(rs.getObject("REJECTIONCODE")!=null)
  6840.                 {
  6841.                     benefitBean.setRejectionCode
  6842.                         (new Short(rs.getShort("REJECTIONCODE")));
  6843.                 }
  6844.                 if(rs.getObject("PARTYCODE")!=null)
  6845.                 {
  6846.                     benefitBean.setPartyCode
  6847.                         (new Long (rs.getLong("PARTYCODE")));
  6848.                 }
  6849.                 if(rs.getObject("PAYABLETO")!=null)
  6850.                 {
  6851.                     benefitBean.setBenefitPayableTo
  6852.                         (new Short (rs.getShort("PAYABLETO")));
  6853.                 }
  6854.                 if(rs.getObject("DESCRIPTION")!=null)
  6855.                 {
  6856.                     benefitBean.setDescription(rs.getString("DESCRIPTION"));
  6857.                 }
  6858.                 GOSIDebug.debugMessages("DESCRIPTION:"+benefitBean.getDescription());
  6859.                 benefitBean.setWorkflowId(new Long(rs.getLong("WORKFLOWID")));
  6860.                 benefitList.add(benefitBean);
  6861.             }
  6862.             if(benefitList!= null && benefitList.size()>0)
  6863.             {
  6864.                 Double totalConWage=
  6865.                     ((OHAllowanceBean) benefitList.get(0)).getTotalContWage();
  6866.                 Long   contributorId =
  6867.                     ((OHAllowanceBean) benefitList.get(0)).getContributorId();
  6868.                 entFmt =((OHAllowanceBean) benefitList.get(0)).getBenStDateEntFmt();
  6869.  
  6870.                 //query to get injury details
  6871.                 sqlQuery    = "SELECT   a.injuryid, a.socinsnumber, a.contributorid, a.establishmentid, "
  6872.                             + "         a.injurydate, a.injurynumber, a.description, a.treatmentstdate, "
  6873.                             + "         a.treatmentenddate, a.fieldofficecode, a.injurystatus, "
  6874.                             + "         a.employernotifydate, a.workerintimationdate, a.wagestopdate, "
  6875.                             + "         NVL (a.workdisabilitydate, a.injurydate + 1) workdisabilitydate, "
  6876.                             + "         MIN (b.benstdate) benstartdate, MAX (b.benenddate) benenddate "
  6877.                             + "    FROM " + SITables.T_INJURY + " a, " + SITables.T_OHBENEFIT + " b "
  6878.                             + "   WHERE a.injuryid = b.injuryid "
  6879.                             + "     AND a.contributorid = ? "
  6880.                             + "     AND b.workflowid = ? "
  6881.                             + "     AND a.injurystatus != ? "
  6882.                             + "GROUP BY a.injuryid, a.socinsnumber, a.contributorid, a.establishmentid, "
  6883.                             + "         a.injurydate, a.injurynumber, a.description, a.treatmentstdate, "
  6884.                             + "         a.treatmentenddate, a.fieldofficecode, a.injurystatus, a.employernotifydate, "
  6885.                             + "         a.workerintimationdate, a.wagestopdate, a.workdisabilitydate, a.injurydate "
  6886.                             + "ORDER BY a.injurydate ";
  6887.  
  6888.                 GOSIDebug.debugMessages("SqlQuery :"  +sqlQuery + ":");
  6889.                 GOSIDebug.debugMessages("\t\t Param 1 :" + contributorId.longValue() + ":");
  6890.                 GOSIDebug.debugMessages("\t\t Param 2 :" + workflowId.longValue() + ":");
  6891.                 GOSIDebug.debugMessages("\t\t Param 3 :" + OHConstants.INJ_STS_CANCELLED.shortValue() + ":");
  6892.                 ArrayList  injuryList = new ArrayList();
  6893.                     ps=con.prepareStatement(sqlQuery);
  6894.                     ps.setLong(1,contributorId.longValue());
  6895.                     ps.setLong(2,workflowId.longValue());
  6896.                     ps.setShort(3,OHConstants.INJ_STS_CANCELLED.shortValue());
  6897.  
  6898.                     rs=ps.executeQuery();
  6899.                     while(rs.next())
  6900.                     {
  6901.                         GOSIDebug.debugMessages("searchInjuryList has records");
  6902.                         InjuryPopDetails injuryDetails =new InjuryPopDetails();
  6903.                         injuryDetails.setInjuryID(new Long(rs.getLong("INJURYID")));
  6904.                         injuryDetails.setSocialInsuranceNumber
  6905.                                 (new Long(rs.getLong("SOCINSNUMBER")));
  6906.                         injuryDetails.setEstablishmentId
  6907.                                 (new Long(rs.getLong("ESTABLISHMENTID")));
  6908.                         injuryDetails.setContributorId
  6909.                                 (new Long(rs.getLong("CONTRIBUTORID")));
  6910.                         injuryDetails.setInjuryDate(rs.getTimestamp("INJURYDATE"));
  6911.                         if (OHConstants.HIJRAH.equals(entFmt))
  6912.                         {
  6913.                             injuryDetails.setInjuryDateStr
  6914.                                 (GOSIDateUtilities.convertToHijra(
  6915.                                         GOSIUtilities.getDateFullString(
  6916.                                         injuryDetails.getInjuryDate())));
  6917.                         }
  6918.                         else
  6919.                         {
  6920.                             injuryDetails.setInjuryDateStr
  6921.                                 (GOSIUtilities.getDateFullString(
  6922.                                     injuryDetails.getInjuryDate()));
  6923.                         }
  6924.  
  6925.                         injuryDetails.setInjuryNumber
  6926.                                 (new Long(rs.getLong("INJURYNUMBER")));
  6927.                         injuryDetails.setDescription(rs.getString("DESCRIPTION"));
  6928.                         injuryDetails.setTreatmentStartDate(rs.getTimestamp("TREATMENTSTDATE"));
  6929.                         injuryDetails.setTreatmentEndDate(rs.getTimestamp("TREATMENTENDDATE"));
  6930.                         injuryDetails.setFieldOffice
  6931.                                 (new Short(rs.getShort("FIELDOFFICECODE")));
  6932.                         injuryDetails.setInjuryStatus
  6933.                             (new Short(rs.getString("INJURYSTATUS")));
  6934.                         if(rs.getObject("EMPLOYERNOTIFYDATE")!= null)
  6935.                         {
  6936.                             injuryDetails.setEmployerNotifyDate
  6937.                             (rs.getTimestamp("EMPLOYERNOTIFYDATE"));
  6938.                         }
  6939.                         if(rs.getObject("WORKERINTIMATIONDATE")!= null)
  6940.                         {
  6941.                             injuryDetails.setWorkerIntimationDate
  6942.                             (rs.getTimestamp("WORKERINTIMATIONDATE"));
  6943.                         }
  6944.                         if(rs.getObject("WAGESTOPDATE")!= null)
  6945.                         {
  6946.                             injuryDetails.setWageStopDate
  6947.                             (rs.getTimestamp("WAGESTOPDATE"));
  6948.                         }
  6949.                         if(rs.getObject("WORKDISABILITYDATE")!= null)
  6950.                         {
  6951.                             injuryDetails.setWorkDisabilityDate
  6952.                             (rs.getTimestamp("WORKDISABILITYDATE"));
  6953.                         }
  6954.                         // setting contributor details
  6955.                         injuryDetails = setContributorDetails(injuryDetails);
  6956.                         // setting establishment details
  6957.                         injuryDetails=setEstablishmentDetails(injuryDetails);
  6958.                         injuryDetails.setBenefitStartDateStr
  6959.                             (OHUtilities.getDateStr(rs.getTimestamp("BENSTARTDATE"),entFmt));
  6960.                         injuryDetails.setBenefitEndDateStr
  6961.                             (OHUtilities.getDateStr(rs.getTimestamp("BENENDDATE"),entFmt));
  6962.                         injuryDetails.setBenefitStartDate(rs.getTimestamp("BENSTARTDATE"));
  6963.                         injuryDetails.setBenefitEndDate(rs.getTimestamp("BENENDDATE"));
  6964.                         injuryDetails.setTotalConWage(totalConWage);
  6965.                        
  6966.                         GOSIDebug.debugMessages("pay to SI: " + injuryDetails.getBenefitPayableTo());
  6967.                         injuryList.add(injuryDetails);
  6968.  
  6969.                 }
  6970.                 //getting total contributory wage
  6971.                 injuryList = getTotalContributorWage(injuryList);
  6972.                 int injuryListSize = injuryList.size();
  6973.                 // checking for wage change
  6974.                 for(int i=0;i<injuryListSize;i++)
  6975.                 {
  6976.                     InjuryPopDetails injuryBean=(InjuryPopDetails)injuryList.get(i);
  6977.                     if(injuryBean.getTotalConWage().doubleValue()!=
  6978.                         totalConWage.doubleValue())
  6979.                     {
  6980.                         GOSIDebug.debugMessages("wage Changed");
  6981.                         injuryBean.setTotalConWage(totalConWage);
  6982.                     }
  6983.                 }
  6984.                 // changeing the time stamp dates to string dates
  6985.                 benefitList = changeBenefitDates(benefitList,entFmt);
  6986.                
  6987.                 boolean benefitPayableToAuthperson = false;
  6988.                
  6989.                 for(int i=0;i<benefitList.size();i++)
  6990.                 {
  6991.                     // setting injurynumber for benefit
  6992.                     OHAllowanceBean benefitBean = (OHAllowanceBean)benefitList.get(i);
  6993.                     benefitBean.setInjuryNumber
  6994.                         (getInjuryNumber(injuryList,benefitBean.getInjuryId()));
  6995.                    
  6996.                     /* benefitPayableToAuthperson flag will be true only when the payment is
  6997.                      * choosen to pay for Authorized Person*/
  6998.                     if(benefitBean.getBenefitPayableTo().equals(OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON))
  6999.                     {
  7000.                         benefitPayableToAuthperson = true;
  7001.                     }
  7002.                 }              
  7003.                
  7004.                  /* if the benefit payableTo is authorized person then set the
  7005.                  * injurydetails payableTo as authorized person.
  7006.                  */            
  7007.                 if(benefitPayableToAuthperson)
  7008.                 {
  7009.                     for(int i=0;i<injuryListSize;i++)
  7010.                     {
  7011.                         InjuryPopDetails injuryBean = (InjuryPopDetails)injuryList.get(i);
  7012.                         injuryBean.setBenefitPayableTo(OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON);
  7013.                     }                                      
  7014.                 }              
  7015.                 // getting  waving details
  7016.                 details = getIntimationDates(injuryList);              
  7017.                 boolean canWaiveDelay = canWaiveDelayNotification(workflowId,injuryList);
  7018.                 boolean canReenterBenefit = canReenterBenefit(workflowId, injuryList);
  7019.  
  7020.                 details.put("canWaiveDelay", new Boolean(canWaiveDelay));
  7021.                 details.put("canReenterBenefit", new Boolean(canReenterBenefit));
  7022.                 //details.put("injuryList",injuryList);
  7023.                 details.put("benefitList",benefitList);
  7024.             }
  7025.             GOSIDebug.debugMessages("-----searchOHAllowance*--------");
  7026.  
  7027.             endTime = System.currentTimeMillis();
  7028.             elapsedTime = endTime - startTime;
  7029.             GOSIInstrumentationLog.writeInstrumentationToLog(
  7030.                 this.getClass().toString(),
  7031.                 "searchOHAllowance()",
  7032.                 elapsedTime);
  7033.  
  7034.             return details;
  7035.         }
  7036.         catch(GOSIException ge)
  7037.         {
  7038.             GOSIDebug.debugMessages("session-searchOHAllowance : The exp is "+ge);
  7039.             throw ge;
  7040.         }
  7041.         catch(Exception e)
  7042.         {
  7043.             GOSIDebug.debugMessages("session-searchOHAllowance : The exp is "+e);
  7044.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  7045.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  7046.                 "searchOHAllowance()",e,"CMN_ERR_1000");
  7047.         }
  7048.         finally
  7049.         {
  7050.             GOSIUtilities.cleanUp(con,ps,rs);
  7051.         }
  7052.     }
  7053.  
  7054.  
  7055.  
  7056.     /**
  7057.     * @METHOD NAME              :   canWaiveDelayNotification
  7058.     * @INFORMATION              :   This method is to  check can Waive Delay Notification
  7059.     * @PARAM                    :   class java.lang.Long,
  7060.                                     class java.util.ArrayList
  7061.     * @RETURN                   :   boolean
  7062.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7063.     * @LAST MODIFIED BY         :
  7064.     * @LAST MODIFIED DATE       :
  7065.     **/
  7066.     private boolean canWaiveDelayNotification
  7067.         (Long workflowId,ArrayList injuryList)throws GOSIException
  7068.     {
  7069.         PreparedStatement ps = null;
  7070.         ResultSet rs = null;
  7071.         boolean canWaive  = false;
  7072.         try
  7073.         {
  7074.             // it get the canwaive flag from the get intimation method
  7075.             // and checks if the delay can be waived
  7076.             // this method is called during workflow
  7077.             String  sqlQuery = "select MIN(BENSTDATE) MINBENSTARTDATE, "+
  7078.                 " MAX(BENENDDATE) MAXBENENDDATE from " +
  7079.                   SITables.T_OHBENEFIT +" where WORKFLOWID =? ";
  7080.             String sqlQuery2= " and OHBENCODE in(?,?) ";
  7081.             ps = con.prepareStatement(sqlQuery);
  7082.             ps.setLong(1,workflowId.longValue());
  7083.             rs = ps.executeQuery();
  7084.             Timestamp startDate = null;
  7085.             Timestamp endDate = null;
  7086.             while(rs.next())
  7087.             {
  7088.                 if(rs.getObject("MINBENSTARTDATE")!=null)
  7089.                 {
  7090.                     startDate = rs.getTimestamp("MINBENSTARTDATE");
  7091.                 }
  7092.                 if(rs.getObject("MAXBENENDDATE")!=null)
  7093.                 {
  7094.                     endDate   = rs.getTimestamp("MAXBENENDDATE");
  7095.                 }
  7096.             }
  7097.             /* To get Daily allowance startDate and end date */
  7098.             sqlQuery =sqlQuery +sqlQuery2;
  7099.             GOSIDebug.debugMessages("sqlQuery:\n"+sqlQuery);
  7100.             ps = con.prepareStatement(sqlQuery);
  7101.             ps.setLong(1,workflowId.longValue());
  7102.             ps.setShort(2,OHConstants.OH_ALWNC_DAIlY_INPATIENT.shortValue());
  7103.             ps.setShort(3,OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.shortValue());
  7104.             rs = ps.executeQuery();
  7105.             Timestamp dailyAllowanceStartDate = null;
  7106.             Timestamp dailyAllowanceEndDate = null;
  7107.             while(rs.next())
  7108.             {
  7109.                 if(rs.getObject("MINBENSTARTDATE")!=null)
  7110.                 {
  7111.                     dailyAllowanceStartDate= rs.getTimestamp("MINBENSTARTDATE");
  7112.                 }
  7113.                 else
  7114.                 {
  7115.                     dailyAllowanceStartDate = startDate;
  7116.                 }
  7117.                 if(rs.getObject("MAXBENENDDATE")!=null)
  7118.                 {
  7119.                     dailyAllowanceEndDate= rs.getTimestamp("MAXBENENDDATE");
  7120.                 }
  7121.             }
  7122.  
  7123.             HashMap details = getIntimationDates(injuryList);
  7124.             injuryList =(ArrayList)details.get(injuryList);
  7125.             startDate = (Timestamp)details.get("startDate");
  7126.             GOSIDebug.debugMessages("dailyAllowanceStartDate:"+dailyAllowanceStartDate);
  7127.             GOSIDebug.debugMessages("startDate:"+startDate);
  7128.             // if benefit start date after the daily allowance start date
  7129.             // the can waive is ture else false bcos nothing to waive
  7130.             if(startDate.compareTo(dailyAllowanceStartDate)>0 )
  7131.             {
  7132.                 canWaive =true;
  7133.             }
  7134.             else
  7135.             {
  7136.                 canWaive =false;
  7137.                 GOSIDebug.debugMessages("No need To check for waive delay intimation");
  7138.                 GOSIDebug.debugMessages("status :"+startDate.compareTo(dailyAllowanceStartDate));
  7139.             }
  7140.             return canWaive;
  7141.         }
  7142.         catch (Exception e)
  7143.         {
  7144.             GOSIDebug.debugMessages("session - canWaiveDelayNotification :e:"+e);
  7145.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  7146.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  7147.                 "getActualWaivableFromDate()",e,"CMN_ERR_1000");
  7148.         }
  7149.         finally
  7150.         {
  7151.             GOSIUtilities.cleanUp(ps,rs);
  7152.         }
  7153.     }
  7154.  
  7155.     /**
  7156.     * @METHOD NAME              :   canReenterBenefit
  7157.     * @INFORMATION              :   This method is to  check can Reenter Benefit
  7158.     * @PARAM                    :   class java.lang.Long,
  7159.                                     class java.util.ArrayList
  7160.     * @RETURN                   :   boolean
  7161.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7162.     * @LAST MODIFIED BY         :
  7163.     * @LAST MODIFIED DATE       :
  7164.     **/
  7165.     private boolean canReenterBenefit (Long workflowId, ArrayList injuryList) throws GOSIException
  7166.     {
  7167.         boolean canReenterBenefit  = true;
  7168.  
  7169.         PreparedStatement ps = null;
  7170.         ResultSet         rs = null;
  7171.  
  7172.         try
  7173.         {
  7174.             String  sqlQuery    = "SELECT COUNT(*) "
  7175.                                 + "  FROM " + SITables.T_OHBENEFIT
  7176.                                 + " WHERE WORKFLOWID = ? AND OHBENCODE <> ? ";
  7177.  
  7178.             ps = con.prepareStatement (sqlQuery);
  7179.  
  7180.             ps.setLong  (1, workflowId.longValue ());
  7181.             ps.setShort (2, OHConstants.OH_ALWNC_MISCELLANEOUS.shortValue ());
  7182.  
  7183.             rs = ps.executeQuery ();
  7184.  
  7185.             if (rs.next () && rs.getLong (1) > 0)
  7186.             {
  7187.                 canReenterBenefit = false;                              /* Benefits other than miscellaneous benefits cannot be reentered */
  7188.             }
  7189.  
  7190.         }
  7191.         catch (Exception e)
  7192.         {
  7193.             throw   new GOSIException   (GOSIConstants.SEVERITY_TWO,
  7194.                                          GOSIConstants.SOCIAL_INSURANCE,
  7195.                                          this.getClass ().toString (),
  7196.                                          "canReenterBenefit ()",
  7197.                                          e,
  7198.                                          "CMN_ERR_1000");
  7199.         }
  7200.         finally
  7201.         {
  7202.             GOSIUtilities.cleanUp (ps, rs);
  7203.         }
  7204.  
  7205.         return canReenterBenefit;
  7206.     }
  7207.  
  7208.     /**
  7209.     * @METHOD NAME              :   getActualWaivableFromDate
  7210.     * @INFORMATION              :   This method is to  get Actual Waivable From Date
  7211.     * @PARAM                    :   class java.util.ArrayList
  7212.     * @RETURN                   :   class java.sql.Timestamp
  7213.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7214.     * @LAST MODIFIED BY         :
  7215.     * @LAST MODIFIED DATE       :
  7216.     **/
  7217.     private Timestamp getActualWaivableFromDate(ArrayList injuryList)
  7218.         throws GOSIException
  7219.     {
  7220.         try
  7221.         {
  7222.             // if the delay in notification is to be waived this
  7223.             // calculates the day from which the benefit can be calculated
  7224.             int injuryListSize =injuryList.size();
  7225.             for ( int i=0;i<injuryListSize ; i++)
  7226.             {
  7227.                 InjuryPopDetails injuryBean =(InjuryPopDetails)injuryList.get(i);
  7228.                 if(!injuryBean.getReportingStatus().equals
  7229.                     (injuryBean.NORMAL_REPORTING))
  7230.                 {
  7231.                     if(injuryBean.getReportingStatus().equals
  7232.                         (injuryBean.WORKER_LATE_REPORTING))
  7233.                     {
  7234.                         injuryBean.setStartDate
  7235.                             (injuryBean.getWorkDisabilityDate());
  7236.                     }else if(injuryBean.getReportingStatus().equals
  7237.                         (injuryBean.EMPLOYER_LATE_REPORTING))
  7238.                     {
  7239.                         injuryBean.setStartDate
  7240.                             (injuryBean.getWorkDisabilityDate());
  7241.                     }
  7242.                     else if(injuryBean.getReportingStatus().equals
  7243.                         (injuryBean.LATE_REPORTED))
  7244.                     {
  7245.                         injuryBean.setStartDate
  7246.                             (injuryBean.getWorkDisabilityDate());
  7247.                     }
  7248.                 }else
  7249.                 {
  7250.                     injuryBean.setStartDate
  7251.                         (injuryBean.getWorkDisabilityDate());
  7252.                 }
  7253.             }
  7254.             Timestamp startDate =null;
  7255.             for (int i=0; i< injuryListSize; i++ )
  7256.             {
  7257.                 InjuryPopDetails injuryBean=(InjuryPopDetails)injuryList.get(i);
  7258.                 if(startDate ==null)
  7259.                 {
  7260.                     startDate = injuryBean.getStartDate();
  7261.                 }else
  7262.                 {
  7263.                     if( startDate.compareTo(injuryBean.getStartDate())>0)
  7264.                     {
  7265.                         startDate =injuryBean.getStartDate();
  7266.                     }
  7267.                 }
  7268.             }
  7269.             return startDate;
  7270.         }
  7271.         /*catch(GOSIException ge)
  7272.         {
  7273.             GOSIDebug.debugMessages("session - getActualWaivableFromDate :ge:"+ge);
  7274.             throw ge;
  7275.         }*/catch(Exception e)
  7276.         {
  7277.             GOSIDebug.debugMessages("session - getActualWaivableFromDate :e:"+e);
  7278.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  7279.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  7280.                 "getActualWaivableFromDate()",e,"CMN_ERR_1000");
  7281.         }
  7282.     }
  7283.     /**
  7284.     * @METHOD NAME              :   isDuplicateSingleVisit
  7285.     * @INFORMATION              :   This method is to  check if the benefit contains only visits
  7286.     * @PARAM                    :   class java.util.ArrayList
  7287.     * @RETURN                   :   class java.sql.Timestamp
  7288.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7289.     * @LAST MODIFIED BY         :
  7290.     * @LAST MODIFIED DATE       :
  7291.     **/
  7292.  
  7293.     private void isDuplicateSingleVisit (ArrayList benefitList)
  7294.     throws GOSIException
  7295.     {
  7296.         PreparedStatement ps = null;
  7297.         ResultSet rs = null;
  7298.         try
  7299.         {
  7300.             if(benefitList !=null && benefitList.size()==1)
  7301.             {
  7302.                 OHAllowanceBean benefitBean = (OHAllowanceBean)benefitList.get(0);
  7303.  
  7304.                 // if the beneift list contains only visits this logic check
  7305.                 // if it has been calculated earlier to prevent duplicates
  7306.                 if(OHConstants.OH_ALWNC_CONVEYENCE.equals
  7307.                     (benefitBean.getOhBenCode()))
  7308.                 {
  7309.                     boolean isCalculated = false;
  7310.                     String sqlQuery  = " select OHBENID from "+
  7311.                         SITables.T_OHBENEFIT +
  7312.                         " where  INJURYID = ? and OHBENCODE = ? and BENSTATUS not in(?,?) "+
  7313.                         " and  BENSTDATE = ? and BENENDDATE = ? ";
  7314.                     ps = con.prepareStatement(sqlQuery);
  7315.                     ps.setLong(1,benefitBean.getInjuryId().longValue());
  7316.                     ps.setShort(2,OHConstants.OH_ALWNC_CONVEYENCE.shortValue());
  7317.                     ps.setShort(3,OHConstants.OH_BNFT_STS_REJECTED.shortValue());
  7318.                     ps.setShort(4,OHConstants.OH_BNFT_STS_CANCELLED.shortValue());
  7319.                     ps.setTimestamp(5,benefitBean.getBenStDateGreg());
  7320.                     ps.setTimestamp(6,benefitBean.getBenEndDateGreg());
  7321.                     rs = ps.executeQuery();
  7322.                     if(rs.next())
  7323.                     {
  7324.                         isCalculated = true;
  7325.                     }
  7326.  
  7327.                     if(isCalculated)
  7328.                     {
  7329.                         throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  7330.                             GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  7331.                             "isDuplicateSingleVisit()",null,"SOI_ERR_5190");
  7332.                     }
  7333.                 }
  7334.             }
  7335.         }
  7336.         catch (GOSIException ge)
  7337.         {
  7338.             throw ge;
  7339.         }
  7340.         catch(Exception e)
  7341.         {
  7342.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  7343.             GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  7344.             "isDuplicateSingleVisit()",e,"CMN_ERR_1000");
  7345.         }
  7346.         finally
  7347.         {
  7348.             GOSIUtilities.cleanUp(ps,rs);
  7349.         }
  7350.     }
  7351.  
  7352.  
  7353.     /**
  7354.     * @METHOD NAME              :   calculateResumeOHAllowance
  7355.     * @INFORMATION              :   This method is to calculate Resume OH Allowance
  7356.     * @PARAM                    :   class java.util.ArrayList,
  7357.                                     boolean,
  7358.                                     boolean
  7359.     * @RETURN                   :   class java.util.ArrayList
  7360.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7361.     * @LAST MODIFIED BY         :
  7362.     * @LAST MODIFIED DATE       :
  7363.     **/
  7364.     public ArrayList calculateResumeOHAllowance(ArrayList injuryList,
  7365.         boolean resumeFlag,boolean canWaive)throws GOSIException
  7366.     {
  7367.         long startTime   = 0;
  7368.         long endTime     = 0;
  7369.         long elapsedTime = 0;
  7370.         startTime = System.currentTimeMillis();
  7371.         boolean isTreatmentApproved = true;
  7372.  
  7373.         ArrayList benefitList = new ArrayList();
  7374.         try
  7375.         {
  7376.             GOSIDebug.debugMessages("\n\n------calculateResumeOHAllowance---------");
  7377.             // this method is called from the stop resume oh allowance servlet
  7378.             // to display  the benefit amount for the stopped periods
  7379.             // the logic here is similar to the actual calculate method
  7380.             con=GOSIUtilities.getConnection
  7381.                 (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  7382.             int injuryListSize = injuryList.size();
  7383.             InjuryPopDetails injuryDetails =(InjuryPopDetails)injuryList.get(0);
  7384.  
  7385.             Long socInsNumber = injuryDetails.getSocialInsuranceNumber();
  7386.             Timestamp startDate = null;
  7387.             Timestamp endDate   =null;
  7388.             ArrayList totalPayablePeriodList = new ArrayList();
  7389.             for(int i=0;i<injuryListSize;i++)
  7390.             {
  7391.                 InjuryPopDetails injuryBean =
  7392.                     (InjuryPopDetails)injuryList.get(i);
  7393.                 Long injuryId = injuryBean.getInjuryID();
  7394.                 startDate =injuryBean.getBenefitStartDate();
  7395.                 endDate = injuryBean.getBenefitEndDate();
  7396.                 ArrayList periodList =null;
  7397.                 ArrayList stoppedList =null;
  7398.                 ArrayList payablePeriodList =null;
  7399.                 periodList = getTreatmentPeriodList(injuryBean,isTreatmentApproved);
  7400.                 GOSIDebug.debugMessages("periodListSize:"+periodList.size());
  7401.                 if(periodList != null)
  7402.                 {
  7403.                     stoppedList = getInjuryStoppedPeriodList(injuryBean,isTreatmentApproved);
  7404.                     GOSIDebug.debugMessages("stoppedListSize:"+stoppedList.size());
  7405.                     for(int a=0;a<stoppedList.size();a++)
  7406.                     {
  7407.                         TreatmentPeriodBean trmtBean =
  7408.                             (TreatmentPeriodBean)stoppedList.get(a);
  7409.                         GOSIDebug.debugMessages("stopStartDate :"+trmtBean.getStartDateGreg());
  7410.                         GOSIDebug.debugMessages("stopEndDate   :"+trmtBean.getEndDateGreg());
  7411.                     }
  7412.                     if(resumeFlag)
  7413.                     {
  7414.                         TreatmentPeriodBean trmtBean = new TreatmentPeriodBean();
  7415.                         trmtBean.setInjuryId(injuryBean.getInjuryID());
  7416.                         trmtBean.setStartDateGreg(startDate);
  7417.                         trmtBean.setEndDateGreg(endDate);
  7418.                         stoppedList =getStopPeriodList(stoppedList,trmtBean,
  7419.                             OHConstants.RESUME_ALLOWANCE_FLAG);
  7420.  
  7421.                         for(int a=0;a<stoppedList.size();a++)
  7422.                         {
  7423.                             TreatmentPeriodBean atrmtBean =
  7424.                                 (TreatmentPeriodBean)stoppedList.get(a);
  7425.                             GOSIDebug.debugMessages("AstopStartDate :"+atrmtBean.getStartDateGreg());
  7426.                             GOSIDebug.debugMessages("AstopEndDate   :"+atrmtBean.getEndDateGreg());
  7427.                         }
  7428.  
  7429.                     }
  7430.                     GOSIDebug.debugMessages("stoppedListSize:"+stoppedList.size());
  7431.                     payablePeriodList = getPayablePeriodList
  7432.                                             (periodList,stoppedList);
  7433.                     GOSIDebug.debugMessages("payablePeriodListSize:"+payablePeriodList.size());
  7434.                 }
  7435.                 int payablePeriodListSize =payablePeriodList.size();
  7436.                 for (int j=0;j<payablePeriodListSize;j++)
  7437.                 {
  7438.                     totalPayablePeriodList.add(payablePeriodList.get(j));
  7439.                 }
  7440.             }
  7441.                 ArrayList daysList = new ArrayList();
  7442.                 startDate =injuryDetails.getBenefitStartDate();
  7443.                 endDate = injuryDetails.getBenefitEndDate();
  7444.                 GOSIDebug.debugMessages("startDate :"+startDate+"\nendDate:"+endDate);
  7445.                 int noDays =OHUtilities.getDays(startDate,endDate);
  7446.                 Timestamp trmtDate =startDate;
  7447.                 GOSIDebug.debugMessages("totalPayableListSize:"+totalPayablePeriodList.size());
  7448.                 for (int i=0; i<noDays ; i++)
  7449.                 {
  7450.                     TreatmentPeriodBean trmtBean = getTrmtDetailsforDate
  7451.                                             (trmtDate,totalPayablePeriodList);
  7452.                     if(trmtBean!= null)
  7453.                     {
  7454.                         daysList.add(trmtBean);
  7455.                     }
  7456.                     trmtDate = GOSIUtilities.getNextDate(trmtDate);
  7457.                 }
  7458.                 GOSIDebug.debugMessages("daysListSize:"+daysList.size());
  7459.                 for (int i=0; i<daysList.size() ; i++)
  7460.                 {
  7461.                     GOSIDebug.debugMessages("Date:"+((TreatmentPeriodBean)daysList.get(i)).getStartDateGreg());
  7462.                 }
  7463.                 //ArrayList payablePeriodList =getBenefitPayableTrmtList(totalPayablePeriodList);
  7464.                 ArrayList payablePeriodList =getBenefitPayableTrmtList(daysList);
  7465.                 ArrayList dailyAllowanceList = new ArrayList();
  7466.                 if(canWaive==false)
  7467.                 {
  7468.                     HashMap details = getIntimationDates(injuryList);
  7469.                     Timestamp newStartDate =(Timestamp)details.get("startDate");
  7470.                     ArrayList newInjuryList = new ArrayList();
  7471.                     for(int i=0;i<injuryList.size();i++)
  7472.                     {
  7473.                         InjuryPopDetails injuryBean =
  7474.                             ((InjuryPopDetails)injuryList.get(i));
  7475.                         //injuryBean.setBenefitStartDate(newStartDate);
  7476.                         GOSIDebug.debugMessages("injuryBean:"+injuryBean);
  7477.                         newInjuryList.add(new InjuryPopDetails(injuryBean));
  7478.                     }
  7479.                     for(int i=0;i<newInjuryList.size();i++)
  7480.                     {
  7481.                         InjuryPopDetails injuryBean =
  7482.                             ((InjuryPopDetails)newInjuryList.get(i));
  7483.                         GOSIDebug.debugMessages("injuryBean:"+injuryBean);
  7484.                         injuryBean.setBenefitStartDate(newStartDate);
  7485.                     }
  7486.                     dailyAllowanceList = calculateDailyAllowance
  7487.                                 (newInjuryList,payablePeriodList,isTreatmentApproved);
  7488.                 }else
  7489.                 {
  7490.                     dailyAllowanceList = calculateDailyAllowance
  7491.                         (injuryList,payablePeriodList,isTreatmentApproved);
  7492.                 }
  7493.                 GOSIDebug.debugMessages("DA LIST:"+dailyAllowanceList.size());
  7494.                 ArrayList visitList = new ArrayList();
  7495.                 ArrayList companionList =new ArrayList();
  7496.                 if(canWaive)
  7497.                 {
  7498.                     visitList =
  7499.                         calculateConveyenceAllowance(injuryList,resumeFlag,isTreatmentApproved);
  7500.                     companionList =
  7501.                         calculateCompanionAllowance(injuryList,resumeFlag,isTreatmentApproved);
  7502.                 }
  7503.                 GOSIDebug.debugMessages("CA LIST:"+visitList.size());
  7504.                 GOSIDebug.debugMessages("COMPA LIST:"+companionList.size());
  7505.                 GOSIDebug.debugMessages("\nDA LIST:"+dailyAllowanceList.size());
  7506.                 GOSIDebug.debugMessages("CA LIST:"+visitList.size());
  7507.                 GOSIDebug.debugMessages("COMPA LIST:"+companionList.size());
  7508.                 if(this.canAvailBenefitdueToDisablity(socInsNumber))
  7509.                 {
  7510.                     benefitList = addToBenefitList(benefitList,dailyAllowanceList);
  7511.                 }
  7512.                 benefitList = addToBenefitList(benefitList,visitList);
  7513.                 benefitList = addToBenefitList(benefitList,companionList);
  7514.                 GOSIDebug.debugMessages("--------calculateResumeOHAllowance*------");
  7515.                 benefitList=changeBenefitDates(benefitList,"G");
  7516.  
  7517.                 endTime = System.currentTimeMillis();
  7518.                 elapsedTime = endTime - startTime;
  7519.                 GOSIInstrumentationLog.writeInstrumentationToLog(
  7520.                 this.getClass().toString(),
  7521.                 "calculateResumeOHAllowance()",
  7522.                 elapsedTime);
  7523.  
  7524.  
  7525.                 return benefitList;
  7526.         }
  7527.         catch(GOSIException ge)
  7528.         {
  7529.             GOSIDebug.debugMessages("session-calculateOHAllowance :ge:"+ge);
  7530.             throw ge;
  7531.         }catch(Exception e)
  7532.         {
  7533.             GOSIDebug.debugMessages("session-calculateOHAllowance :e:"+e);
  7534.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  7535.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  7536.                 "calculateOHAllowance()",e,"CMN_ERR_1000");
  7537.         }
  7538.         finally
  7539.         {
  7540.             GOSIDebug.debugMessages("connection Closed");
  7541.             GOSIUtilities.cleanUp(con);
  7542.         }
  7543.     }
  7544.  
  7545.     /**
  7546.     * @METHOD NAME              :   getNextPayableDates
  7547.     * @INFORMATION              :   This method is to  get Next Payable Dates
  7548.     * @PARAM                    :   class java.util.ArrayList
  7549.     * @RETURN                   :   class java.lang.String
  7550.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7551.     * @LAST MODIFIED BY         :
  7552.     * @LAST MODIFIED DATE       :
  7553.     **/
  7554.         public String getNextPayableDates (ArrayList injuryList)
  7555.             throws GOSIException
  7556.         {
  7557.             long startTime   = 0;
  7558.             long endTime     = 0;
  7559.             long elapsedTime = 0;
  7560.             startTime = System.currentTimeMillis();
  7561.             Long injuryId=null;
  7562.             Timestamp compDate = null;
  7563.             Timestamp startDate = null;
  7564.             PreparedStatement ps = null;
  7565.             ResultSet rs = null;
  7566.             Timestamp resumedate= null;
  7567.             try
  7568.             {
  7569.                 // the next payable date is the next day of the end date of the
  7570.                 // last paid benefit , if till now no benefits are paid
  7571.                 // its the next day of complication or the injury date
  7572.                 con = GOSIUtilities.getConnection
  7573.                     (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  7574.                 Long contributorId = ((InjuryPopDetails)
  7575.                     injuryList.get(0)).getContributorId();
  7576.                 String subQuery = "";
  7577.                 Timestamp benefitStartDate =
  7578.                     ((InjuryPopDetails)injuryList.get(0)).getBenefitStartDate();
  7579.                 int injuryListSize =injuryList.size();
  7580.                 if(injuryListSize==1)
  7581.                 {
  7582.                     subQuery = "";
  7583.                 }else
  7584.                 {
  7585.                     for(int i=0;i<(injuryListSize-1);i++)
  7586.                     {
  7587.                         subQuery=subQuery+" ?, ";
  7588.                     }
  7589.                 }
  7590.                 String sqlQuery =
  7591.                     " select max(BENENDDATE) MAXBENENDDATE from "+
  7592.                     SITables.T_OHBENEFIT + " where CONTRIBUTORID = ? and "+
  7593.                     " BENSTATUS != ? and INJURYID in ( " + subQuery + " ?)";
  7594.                 ps = con.prepareStatement(sqlQuery);
  7595.                 ps.setLong(1,contributorId.longValue());
  7596.                 ps.setShort(2,OHConstants.OH_BNFT_STS_CANCELLED.shortValue());
  7597.                 for(int i=0;i<injuryListSize;i++)
  7598.                 {
  7599.                     injuryId =
  7600.                         ((InjuryPopDetails)injuryList.get(i)).getInjuryID();
  7601.                 GOSIDebug.debugMessages("injuryId=" + injuryId);
  7602.                     ps.setLong(i+3,injuryId.longValue());
  7603.                 }
  7604.                 GOSIDebug.debugMessages("SqlQuery :" + sqlQuery);              
  7605.                 GOSIDebug.debugMessages("ContributorId :" + contributorId.longValue());
  7606.                 GOSIDebug.debugMessages("OHConstants.OH_BNFT_STS_CANCELLED :" +
  7607.                         OHConstants.OH_BNFT_STS_CANCELLED.shortValue());
  7608.                 rs= ps.executeQuery();
  7609.                 while(rs.next())
  7610.                 {
  7611.                     if(rs.getObject("MAXBENENDDATE")!= null)
  7612.                     {
  7613.                         startDate = rs.getTimestamp("MAXBENENDDATE");
  7614.                     }
  7615.                 }
  7616.                 if(startDate == null)
  7617.                 {
  7618.                     for(int i=0;i<injuryListSize;i++)
  7619.                     {
  7620.                         Timestamp injuryDate =
  7621.                         ((InjuryPopDetails)injuryList.get(i)).getInjuryDate();
  7622.                         if(startDate == null)
  7623.                         {
  7624.                             startDate =injuryDate;
  7625.                         }
  7626.                         else
  7627.                         {
  7628.                             if(startDate.compareTo(injuryDate) > 0)
  7629.                             {
  7630.                                 startDate  = injuryDate;
  7631.                             }
  7632.                         }
  7633.                     }
  7634.                 }else
  7635.                 {
  7636.                     startDate = GOSIUtilities.getNextDate(startDate);
  7637.                 }
  7638.                 GOSIUtilities.cleanUp(ps,rs);
  7639.                 sqlQuery="SELECT DATECOMPLICATION FROM "+
  7640.                         SITables.T_INJURY +" WHERE  "+
  7641.                         "DATECOMPLICATION IS NOT NULL and "+
  7642.                         " INJURYSTATUS in(?,?,?,?)"+
  7643.                         " AND INJURYID=?";
  7644.                 ps = con.prepareStatement(sqlQuery);
  7645.                 ps.setShort(1, OHConstants.INJ_STS_APPROVED.shortValue());
  7646.                 ps.setShort(2, OHConstants.INJ_STS_CURED_WITHOUT_DISABILITY.shortValue());
  7647.                 ps.setShort(3, OHConstants.INJ_STS_CURED_WITH_DISABILITY.shortValue());
  7648.                 ps.setShort(4, OHConstants.INJ_STS_RESULTED_IN_DEATH.shortValue());
  7649.                 ps.setLong(5, injuryId.longValue());
  7650.                 GOSIDebug.debugMessages("sqlQuery="+sqlQuery);
  7651.                 rs= ps.executeQuery();
  7652.                 if(rs.next())
  7653.                 {
  7654.                     compDate=rs.getTimestamp("DATECOMPLICATION");
  7655.                 }
  7656.                 GOSIUtilities.cleanUp(ps,rs);
  7657.                 //check if there is any resume request for injuryid
  7658.                 sqlQuery="SELECT RESUMEDATE FROM "+
  7659.                 SITables.T_RESUMETREATMENT +" WHERE  "+
  7660.                 "INJURYID=?";
  7661.                 ps = con.prepareStatement(sqlQuery);
  7662.                 ps.setLong(1, injuryId.longValue());
  7663.                 GOSIDebug.debugMessages("sqlQuery="+sqlQuery);
  7664.                 rs= ps.executeQuery();
  7665.                 if(rs.next())
  7666.                 {
  7667.                     //
  7668.                     if(rs.getTimestamp("RESUMEDATE") != null)
  7669.                     {
  7670.                         resumedate = rs.getTimestamp("RESUMEDATE");
  7671.                     }
  7672.                 }
  7673.                 String msg = "";
  7674.                 GOSIDebug.debugMessages("startDate"+startDate);
  7675.                 GOSIDebug.debugMessages("benefitStartDate"+benefitStartDate);
  7676.                 GOSIDebug.debugMessages("compDate"+compDate);
  7677.  
  7678.                 if (resumedate !=null && startDate.compareTo(resumedate)==0)
  7679.                 {
  7680.                     String startDateStr = OHUtilities.getDateStr(resumedate,"G");
  7681.                     msg = GOSIErrorMessages.getErrorDesc("SOI_ERR_5385")+startDateStr;
  7682.                 }
  7683.                 else
  7684.                 if(startDate.compareTo(benefitStartDate)!=0 && resumedate ==null)
  7685.                 {
  7686.                     String startDateStr = OHUtilities.getDateStr(startDate,"G");
  7687.                     msg = GOSIErrorMessages.getErrorDesc("SOI_ERR_5385")+startDateStr;
  7688.                 }                  
  7689.                 else
  7690.                 if(startDate.compareTo(benefitStartDate)==0&& resumedate ==null)
  7691.                 {
  7692.                 }
  7693.                 else
  7694.                 if(compDate!=null && resumedate ==null)
  7695.                 {
  7696.                     if(compDate.compareTo(benefitStartDate)!=0)
  7697.                     {
  7698.                         String compDateStr = OHUtilities.getDateStr(compDate,"G");
  7699.                         msg = GOSIErrorMessages.getErrorDesc("SOI_ERR_5385")+compDateStr;
  7700.                     }
  7701.                 }
  7702.                 GOSIDebug.debugMessages("message:"+msg);
  7703.                 endTime = System.currentTimeMillis();
  7704.                 elapsedTime = endTime - startTime;
  7705.                 GOSIInstrumentationLog.writeInstrumentationToLog(
  7706.                 this.getClass().toString(),
  7707.                 "getNextPayableDates()",
  7708.                 elapsedTime);
  7709.  
  7710.                 return msg;
  7711.             }
  7712.             catch (GOSIException ge)
  7713.             {
  7714.                 throw ge;
  7715.             }
  7716.             catch (Exception e)
  7717.             {
  7718.                 throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  7719.                     GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  7720.                     "getNextPayableDates()",e,"CMN_ERR_1000");
  7721.             }
  7722.             finally
  7723.             {
  7724.                 GOSIUtilities.cleanUp(con,ps,rs);
  7725.             }
  7726.  
  7727.         }
  7728.  
  7729.     /**
  7730.     * @METHOD NAME              :   getInjuryNumber
  7731.     * @INFORMATION              :   This method returns the Injury Number of the injury
  7732.     * @PARAM                    :   class java.util.ArrayList,
  7733.                                     class java.lang.Long
  7734.     * @RETURN                   :   class java.lang.Long
  7735.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7736.     * @LAST MODIFIED BY         :
  7737.     * @LAST MODIFIED DATE       :
  7738.     **/
  7739.         private Long getInjuryNumber(ArrayList injuryList,Long injuryId)
  7740.             throws GOSIException
  7741.         {
  7742.             try
  7743.             {
  7744.                 Long injuryNumber = null;
  7745.                 for(int i=0;i<injuryList.size();i++)
  7746.                 {
  7747.                     InjuryPopDetails injuryBean =
  7748.                         (InjuryPopDetails)injuryList.get(i);
  7749.                     if(injuryId.equals(injuryBean.getInjuryID()))
  7750.                     {
  7751.                         injuryNumber = injuryBean.getInjuryNumber();
  7752.                         break;
  7753.                     }
  7754.  
  7755.                 }
  7756.                 return injuryNumber;
  7757.             }
  7758.             catch (Exception e)
  7759.             {
  7760.                 throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  7761.                     GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  7762.                     "getInjuryNumber()",e,"CMN_ERR_1000");
  7763.             }
  7764.         }
  7765.  
  7766.  
  7767.     /**
  7768.     * @METHOD NAME              :   createRecFromEmp
  7769.     * @INFORMATION              :   This method is to  create Rec From Emp
  7770.     * @PARAM                    :   class java.util.ArrayList
  7771.     * @RETURN                   :   void
  7772.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7773.     * @LAST MODIFIED BY         :
  7774.     * @LAST MODIFIED DATE       :
  7775.     **/
  7776.     private void createRecFromEmp(ArrayList recEmpList)throws GOSIException
  7777.     {
  7778.         try
  7779.         {
  7780.             RecEmployerEntityHome home=(RecEmployerEntityHome)
  7781.                 ServiceLocator.getInstance().getRemoteHome(
  7782.                 OHConstants.REC_FROM_EMP_ENTITY_JNDI,
  7783.                 RecEmployerEntityHome.class);
  7784.             for(int i=0;i<recEmpList.size();i++)
  7785.             {
  7786.                 home.create((RecEmployerBean)recEmpList.get(i));
  7787.             }
  7788.  
  7789.         }
  7790.         catch (GOSIException ge)
  7791.         {
  7792.             throw ge;
  7793.         }
  7794.         catch (Exception e)
  7795.         {
  7796.             throw new GOSIException(GOSIConstants.SEVERITY_ONE,
  7797.             GOSIConstants.SOCIAL_INSURANCE,
  7798.             this.getClass().toString(),
  7799.             "createRecFromEmp()",e,"CMN_ERR_1000");
  7800.         }
  7801.  
  7802.     }
  7803.  
  7804.     /**
  7805.     * @METHOD NAME              :   createRecFromCon
  7806.     * @INFORMATION              :   This method is to  create Rec From Con
  7807.     * @PARAM                    :   class java.util.ArrayList
  7808.     * @RETURN                   :   void
  7809.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7810.     * @LAST MODIFIED BY         :
  7811.     * @LAST MODIFIED DATE       :
  7812.     **/
  7813.     private void createRecFromCon(ArrayList recConList)throws GOSIException
  7814.     {
  7815.         try
  7816.         {
  7817.             RecFromContributorEntityHome home=(RecFromContributorEntityHome)
  7818.                 ServiceLocator.getInstance().getRemoteHome(
  7819.                 OHConstants.REC_FROM_CON_ENTITY_JNDI,
  7820.                 RecFromContributorEntityHome.class);
  7821.             home.create(recConList);
  7822.         }
  7823.         catch (GOSIException ge)
  7824.         {
  7825.             throw ge;
  7826.         }
  7827.         catch (Exception e)
  7828.         {
  7829.             throw new GOSIException(GOSIConstants.SEVERITY_ONE,
  7830.             GOSIConstants.SOCIAL_INSURANCE,
  7831.             this.getClass().toString(),
  7832.             "createRecFromConp()",e,"CMN_ERR_1000");
  7833.         }
  7834.  
  7835.     }
  7836.  
  7837.     /**
  7838.     * @METHOD NAME              :   calculateWorkerEmployerBenefitList
  7839.     * @INFORMATION              :   This method is to  workers Employer BenefitList
  7840.     * @PARAM                    :   class java.util.ArrayList,
  7841.                                     class java.util.ArrayList
  7842.     * @RETURN                   :   class java.util.ArrayList
  7843.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7844.     * @LAST MODIFIED BY         :
  7845.     * @LAST MODIFIED DATE       :
  7846.     **/
  7847.     private ArrayList calculateWorkerEmployerBenefitList(ArrayList
  7848.         curBenefitList,ArrayList injuryList) throws GOSIException
  7849.     {
  7850.         // this method will split the benefit to woker / employer based on wage stop date
  7851.         ArrayList newBenefitList = new ArrayList();
  7852.         Timestamp wageStopDate = null;
  7853.         Timestamp nextDate = null;
  7854.         GOSIDebug.debugMessages("\t\t Start calculateWorkerEmployerBenefitList - MaintainOHAllowanceSessionEJB");
  7855.         try
  7856.         {
  7857.             InjuryPopDetails injuryBean = (InjuryPopDetails)injuryList.get(0);
  7858.             wageStopDate = getWageStopDate(injuryBean.getInjuryID());
  7859.             if(wageStopDate != null)
  7860.             {
  7861.                 GOSIDebug.debugMessages("Before for------------");
  7862.                 injuryBean.setWageStopDate(wageStopDate);
  7863.                 // till the wage stop date the allowance will be paid to the
  7864.                 // establishment after that it will be paid to contributor
  7865.  
  7866.                 for(int i=0;i<curBenefitList.size();i++)
  7867.                 {
  7868.                     GOSIDebug.debugMessages("i:" + i);
  7869.                     OHAllowanceBean benefitBean = (OHAllowanceBean)curBenefitList.get(i);
  7870.                     GOSIDebug.debugMessages("BenefitPayableTo:" + benefitBean.getBenefitPayableTo());
  7871.                     if(benefitBean.getBenefitPayableTo().equals
  7872.                         (OHConstants.OH_BNFT_PAY_TO_CON) )
  7873.                     {
  7874.                         if(OHConstants.OH_ALWNC_DAIlY_INPATIENT.equals(benefitBean.getOhBenCode())
  7875.                             ||OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.equals(benefitBean.getOhBenCode()))
  7876.                         {
  7877.                             if((benefitBean.getBenStDateGreg().equals(wageStopDate))&&
  7878.                                     (benefitBean.getBenEndDateGreg().equals(wageStopDate)))
  7879.                             {
  7880.                                 GOSIDebug.debugMessages(" both on the same day");
  7881.                                 benefitBean.setBenefitPayableTo(OHConstants.OH_BNFT_PAY_TO_EMP);
  7882.                                 benefitBean.setPartyCode(injuryBean.getRegistrationNumber());
  7883.                                 benefitBean.setPaymentMode(null);
  7884.                                 newBenefitList.add(benefitBean);
  7885.  
  7886.                             }else      
  7887.                             if((!benefitBean.getBenStDateGreg().after(wageStopDate))&&
  7888.                                     (!benefitBean.getBenEndDateGreg().after(wageStopDate)))
  7889.                             {
  7890.                                 GOSIDebug.debugMessages(" both before");
  7891.                                 benefitBean.setBenefitPayableTo(OHConstants.OH_BNFT_PAY_TO_EMP);
  7892.                                 benefitBean.setPartyCode(injuryBean.getRegistrationNumber());
  7893.                                 benefitBean.setPaymentMode(null);
  7894.                                 newBenefitList.add(benefitBean);
  7895.  
  7896.                             }else if((!benefitBean.getBenStDateGreg().after(wageStopDate))&&
  7897.                                     (benefitBean.getBenEndDateGreg().after(wageStopDate)))
  7898.                             {
  7899.                                 GOSIDebug.debugMessages(" before and after");
  7900.                                 OHAllowanceBean nextBenefitBean = new OHAllowanceBean();
  7901.                                 nextBenefitBean.setInjuryId(benefitBean.getInjuryId());
  7902.                                 nextBenefitBean.setContributorId(benefitBean.getContributorId());
  7903.                                 nextBenefitBean.setTotalContWage(benefitBean.getTotalContWage());
  7904.                                 nextBenefitBean.setBenefitPayableTo(OHConstants.OH_BNFT_PAY_TO_EMP);
  7905.                                 nextBenefitBean.setOhBenCode(benefitBean.getOhBenCode());
  7906.                                 nextBenefitBean.setInjuryNumber(benefitBean.getInjuryNumber());
  7907.                                 nextBenefitBean.setWorkflowId(benefitBean.getWorkflowId());
  7908.                                 nextBenefitBean.setOhBenId(benefitBean.getOhBenId());
  7909.                                 nextBenefitBean.setFieldofficeCode(benefitBean.getFieldofficeCode());
  7910.                                 nextBenefitBean.setOhBenType(benefitBean.getOhBenType());
  7911.  
  7912.                                 nextBenefitBean.setBenStDateGreg(benefitBean.getBenStDateGreg());
  7913.                                 nextBenefitBean.setBenStDateStr(benefitBean.getBenStDateStr());
  7914.                                 nextBenefitBean.setBenStDateEntFmt(benefitBean.getBenStDateEntFmt());
  7915.  
  7916.                                 nextBenefitBean.setBenEndDateGreg(wageStopDate);
  7917.                                 nextBenefitBean.setBenEndDateStr(GOSIUtilities.getDateFullString(wageStopDate));
  7918.                                 nextBenefitBean.setBenEndDateEntFmt(benefitBean.getBenEndDateEntFmt());
  7919.  
  7920.                                 nextBenefitBean.setBenStatus(benefitBean.getBenStatus());
  7921.                                 nextBenefitBean.setPaymentMode(benefitBean.getPaymentMode());
  7922.                                 nextBenefitBean.setBankCode(benefitBean.getBankCode());
  7923.                                 nextBenefitBean.setBankAccNumber(benefitBean.getBankAccNumber());
  7924.                                 nextBenefitBean.setDatePaymentGreg(benefitBean.getDatePaymentGreg());
  7925.                                 nextBenefitBean.setDatePaymentEntFmt(benefitBean.getDatePaymentEntFmt());
  7926.                                 nextBenefitBean.setWorkflowStatus(benefitBean.getWorkflowStatus());
  7927.                                 nextBenefitBean.setJournalHeaderId(benefitBean.getJournalHeaderId());
  7928.                                 nextBenefitBean.setPartyCode(benefitBean.getPartyCode());
  7929.  
  7930.                                 int noDays =OHUtilities.getDays(nextBenefitBean.getBenStDateGreg(),wageStopDate);
  7931.                                 int maxDays=OHUtilities.getDays(benefitBean.getBenStDateGreg(),benefitBean.getBenEndDateGreg());
  7932.  
  7933.                                 double amount1=(benefitBean.getBenAmount().doubleValue()*noDays)/maxDays;
  7934.                                 double amount2=(benefitBean.getBenAmount().doubleValue()*(maxDays-noDays))/maxDays;
  7935.                                 nextBenefitBean.setBenAmount(new Double(amount1));
  7936.  
  7937.                                 newBenefitList.add(nextBenefitBean);
  7938.  
  7939.                                 nextDate=GOSIUtilities.getRequiredDate(wageStopDate,1);
  7940.                                 benefitBean.setBenStDateGreg(nextDate);
  7941.                                 benefitBean.setBenStDateStr(GOSIUtilities.getDateFullString(nextDate));
  7942.                                 benefitBean.setBenAmount(new Double(amount2));
  7943.  
  7944.                                 newBenefitList.add(benefitBean);
  7945.  
  7946.                             }else
  7947.                             {
  7948.                                 GOSIDebug.debugMessages(" after");
  7949.                                 newBenefitList.add(benefitBean);
  7950.                             }
  7951.                         }else
  7952.                         {
  7953.                             GOSIDebug.debugMessages(" not inpatient of out patient ");
  7954.                             newBenefitList.add(benefitBean);
  7955.                         }
  7956.                     }else
  7957.                     {
  7958.  
  7959.                         newBenefitList.add(benefitBean);
  7960.                     }
  7961.                 }
  7962.                 GOSIDebug.debugMessages("After for------------");
  7963.             }else
  7964.             {
  7965.                 GOSIDebug.debugMessages("Not payable to contributor ");
  7966.                 newBenefitList = curBenefitList;
  7967.             }
  7968.             GOSIDebug.debugMessages("\t\t End calculateWorkerEmployerBenefitList - MaintainOHAllowanceSessionEJB");
  7969.             return newBenefitList;
  7970.  
  7971.         }
  7972.         catch(GOSIException ge)
  7973.         {
  7974.             GOSIDebug.debugMessages("session:calculateWorkerEmployerBenefitList :ge:"+ge);
  7975.             throw ge;
  7976.         }
  7977.         catch(Exception e)
  7978.         {
  7979.             GOSIDebug.debugMessages("session:getTotalContibutorWage :e:"+e);
  7980.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  7981.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  7982.                 "calculateWorkerEmployerBenefitList()",e,"CMN_ERR_1000");
  7983.         }
  7984.         finally
  7985.         {
  7986.             //GOSIUtilities.cleanUp(ps,rs);
  7987.         }
  7988.     }
  7989.  
  7990.  
  7991.     /**
  7992.     * @METHOD NAME              :   checkSaveOHBenefit
  7993.     * @INFORMATION              :   This method is to check if oh benefit is Saved
  7994.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.CompanionBean,
  7995.                                     class gosi.core.workflow.beans.WorkflowParamBean,
  7996.                                     class java.lang.Long
  7997.     * @RETURN                   :   void
  7998.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  7999.     * @LAST MODIFIED BY         :
  8000.     * @LAST MODIFIED DATE       :
  8001.     **/
  8002.     public void checkSaveOHBenefit(CompanionBean companionBean,
  8003.         WorkflowParamBean workflowParamBean,Long siNum) throws GOSIException
  8004.     {
  8005.         // checks if oh benefit is saved for the period ,
  8006.         //if saved starts a new oh workflow for companion allowance
  8007.         PreparedStatement ps=null;
  8008.         ResultSet rs=null;
  8009.         String sqlQuery=null;
  8010.         Long contributorId=null;
  8011.         boolean canSendforWorkflow = false;
  8012.         try
  8013.         {
  8014.             sqlQuery="SELECT CONTRIBUTORID FROM "+SITables.T_INJURY+
  8015.                     " WHERE INJURYID=?";
  8016.             GOSIDebug.debugMessages("sqlQuery="+sqlQuery+"companionBean.getInjuryId()="+companionBean.getInjuryId());
  8017.             con=GOSIUtilities.getConnection(
  8018.                     GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  8019.             ps=con.prepareStatement(sqlQuery);
  8020.             ps.setLong(1,companionBean.getInjuryId().longValue());
  8021.             rs=ps.executeQuery();
  8022.             if(rs.next())
  8023.             {
  8024.                 contributorId=new Long (rs.getLong("CONTRIBUTORID"));
  8025.             }
  8026.             GOSIUtilities.cleanUp(ps,rs);
  8027.             Long workflowId=null;
  8028.             Short benefitPayableTo = null;
  8029.             Short paymentMode = OHConstants.PAYMENT_MODE_CHEQUE;
  8030.             // Query to check if there is benefit paid for the period
  8031.             // if its not paid no records will be iserted into t_ohbenefit
  8032.             // canSendforWorkflow will be true if oh benefit already calculated for
  8033.             // the period
  8034.  
  8035.             if(contributorId!=null)
  8036.             {
  8037.                 int i=0;
  8038.                 sqlQuery="SELECT OHBENID,WORKFLOWID,PAYMENTMODE, PAYABLETO FROM "
  8039.                 +SITables.T_OHBENEFIT+
  8040.                 " WHERE CONTRIBUTORID = ? AND BENSTATUS NOT IN (?,?)"+
  8041.                 " AND BENSTDATE <= ? AND BENENDDATE >=?";
  8042.  
  8043.                 GOSIDebug.debugMessages("sqlQuery="+sqlQuery+
  8044.                     "companionBean.getCompStDateGreg()="
  8045.                     +companionBean.getCompStDateGreg()+
  8046.                     "contributorId.longValue()="
  8047.                     +contributorId.longValue());
  8048.  
  8049.                 ps=con.prepareStatement(sqlQuery);
  8050.                 ps.setLong(++i,contributorId.longValue());
  8051.                 ps.setShort(++i,OHConstants.OH_BNFT_STS_CANCELLED.shortValue());
  8052.                 ps.setShort(++i,OHConstants.OH_BNFT_STS_REJECTED.shortValue());
  8053.                 ps.setTimestamp(++i,companionBean.getCompStDateGreg());
  8054.                 ps.setTimestamp(++i,companionBean.getCompStDateGreg());
  8055.                 rs=ps.executeQuery();
  8056.  
  8057.                 WHILE:while(rs.next())
  8058.                 {
  8059.                     canSendforWorkflow = true;
  8060.                     benefitPayableTo = new Short(rs.getShort("PAYABLETO"));
  8061.  
  8062.                     if(rs.getObject("PAYMENTMODE") != null)
  8063.                     {
  8064.                         paymentMode = new Short(rs.getShort("PAYMENTMODE"));
  8065.                     }
  8066.  
  8067.                     workflowId=new Long(rs.getInt("WORKFLOWID"));
  8068.                     if(OHConstants.OH_BNFT_PAY_TO_CON.equals(benefitPayableTo))
  8069.                     {
  8070.                         break WHILE;
  8071.                     }
  8072.                 }
  8073.                 GOSIUtilities.cleanUp(ps,rs);
  8074.             }
  8075.             GOSIDebug.debugMessages("workflowId="+workflowId);
  8076.             // if companion allowance can be send for workflow
  8077.             // it will be inserted into the oh benefit bean and a
  8078.             // workflow record created
  8079.             if(canSendforWorkflow)
  8080.             {
  8081.                 HashMap details=null;
  8082.                 ArrayList existingBenefitList=null;
  8083.                 ArrayList benefitList=new ArrayList();
  8084.                 OHAllowanceBean allowanceBean= null;
  8085.                 details = searchOHAllowance(workflowId);
  8086.  
  8087.                 existingBenefitList=(ArrayList)details.get("benefitList");
  8088.                 allowanceBean=(OHAllowanceBean)existingBenefitList.get(0);
  8089.  
  8090.                 allowanceBean.setOhBenCode(OHConstants.OH_ALWNC_COMP_DAILY);
  8091.                 allowanceBean.setOhBenType(GOSIUtilities.getDomainDesc
  8092.                   ("OH Benefit Type",OHConstants.OH_ALWNC_COMP_DAILY.shortValue()));
  8093.                 allowanceBean.setBenStDateGreg(companionBean.getCompStDateGreg());
  8094.                 allowanceBean.setBenStDateEntFmt(companionBean.getCompStDateEntFmt());
  8095.                 allowanceBean.setBenEndDateGreg(companionBean.getCompEndDateGreg());
  8096.                 allowanceBean.setBenEndDateEntFmt(companionBean.getCompEndDateEntFmt());
  8097.                 allowanceBean.setBenStDateStr(companionBean.getCompStartDateStr());
  8098.                 allowanceBean.setBenEndDateStr(companionBean.getCompEndDateStr());
  8099.  
  8100.                 allowanceBean.setBenAmount(companionBean.getDailyAllowanceComp());
  8101.                 allowanceBean.setBenefitPayableTo(OHConstants.OH_BNFT_PAY_TO_CON);
  8102.                 allowanceBean.setPaymentMode(paymentMode);
  8103.                 allowanceBean.setPartyCode(siNum);
  8104.  
  8105.                 allowanceBean.setBenStatus(OHConstants.OH_BNFT_STS_ENTERED);
  8106.                 allowanceBean.setWorkflowStatus(OHConstants.WFS_OH_BNFT_ENTERED);
  8107.                 allowanceBean.setWorkflowId(
  8108.                     GOSIUtilities.getPrimaryKey("OHBNFTWORKFLOWID",
  8109.                     new Long(workflowParamBean.getUserId())));
  8110.                 allowanceBean.setInjuryId(companionBean.getInjuryId());
  8111.  
  8112.  
  8113.                 allowanceBean.setCreatedBy(new Long (workflowParamBean.getUserId()));
  8114.                 allowanceBean.setCreationTimestamp(new Timestamp(System.currentTimeMillis()));
  8115.                 allowanceBean.setLastModifiedBy(null);
  8116.                 allowanceBean.setLastModifiedTimestamp(null);
  8117.  
  8118.  
  8119.                 benefitList.add(allowanceBean);
  8120.                 workflowParamBean.
  8121.                     setPrimaryKeyOfTherecord(allowanceBean.getWorkflowId().toString());
  8122.                 GOSIDebug.debugMessages("workflowParamBean="+workflowParamBean);
  8123.                 String message=saveOHAllowance(benefitList,workflowParamBean,siNum,null);
  8124.             }
  8125.         }
  8126.         catch(GOSIException ge)
  8127.         {
  8128.             throw ge;
  8129.         }
  8130.         catch(Exception e)
  8131.         {
  8132.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  8133.             GOSIConstants.SOCIAL_INSURANCE,
  8134.             this.getClass().toString(),
  8135.             "checkSaveOHBenefit()",e,"CMN_ERR_1000");
  8136.         }
  8137.  
  8138.         finally
  8139.         {
  8140.             GOSIUtilities.cleanUp(con,ps,rs);
  8141.         }
  8142.  
  8143.     }
  8144.  
  8145.     /**
  8146.     * @METHOD NAME              :   adjustLastInpatientDate
  8147.     * @INFORMATION              :   This method is to adjust the last inpatient
  8148.                                     trmt date to the benefit list
  8149.     * @PARAM                    :   class java.util.ArrayList,
  8150.                                     class java.util.ArrayList
  8151.     * @RETURN                   :   class java.util.ArrayList
  8152.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  8153.     * @LAST MODIFIED BY         :
  8154.     * @LAST MODIFIED DATE       :
  8155.     **/
  8156.     private ArrayList adjustLastInpatientDate(ArrayList injuryList,
  8157.         ArrayList benefitList,boolean isTreatmentApproved)  throws GOSIException
  8158.     {
  8159.         try
  8160.         {
  8161.             GOSIDebug.debugMessages("Start adjustLastInpatientDate - MaintainOHAllowanceSessionEJB");
  8162.             // these methods added for the adjustment of the last
  8163.             // inpatient period payed as sickleave.
  8164.  
  8165.             if(benefitList.size()==0)
  8166.             {
  8167.                 return benefitList;
  8168.             }
  8169.             OHAllowanceBean benefitBean = (OHAllowanceBean)benefitList.get(0);
  8170.             Timestamp benefitStartDate  =  benefitBean.getBenStDateGreg();
  8171.             Long injuryId = benefitBean.getInjuryId();
  8172.             Timestamp prevBenefitDate = OHUtilities.getPrevDate(benefitStartDate);
  8173.             Double totalContWage = benefitBean.getTotalContWage();
  8174.             HashMap details = null;
  8175.             Short hospitalType = null;
  8176.             Short prevTreatmentType = null;
  8177.             Short currentTreatmentType = null;
  8178.             Short prevBenefitType = null;
  8179.             // for getting previos trmt type isTreatmentApproved is true
  8180.             details = getTreatmentType(injuryId,prevBenefitDate,true);
  8181.  
  8182.             if (details.get("treatmentType")!= null)
  8183.             {
  8184.                 prevTreatmentType = (Short)details.get("treatmentType");
  8185.                 hospitalType      = (Short)details.get("hospitalType");
  8186.             }
  8187.             if(prevTreatmentType == null)
  8188.             {
  8189.                 return benefitList;
  8190.             }
  8191.  
  8192.             OHAllowanceBean PrevBenefitBean = getPrevBenefitBean(injuryId,prevBenefitDate);
  8193.             if(PrevBenefitBean == null)
  8194.             {
  8195.                 return benefitList;
  8196.             }
  8197.             prevBenefitType = PrevBenefitBean.getOhBenCode();
  8198.  
  8199.             details = getTreatmentType(injuryId,benefitStartDate,isTreatmentApproved);
  8200.             if (details.get("treatmentType")!= null)
  8201.             {
  8202.                 currentTreatmentType = (Short)details.get("treatmentType");
  8203.             }
  8204.  
  8205.             OHAllowanceBean adjBenBean = new OHAllowanceBean(PrevBenefitBean);
  8206.             adjBenBean.setTotalContWage(totalContWage);
  8207.  
  8208.             // if the previos trmt type is inpatient
  8209.             // and the previos paid trmt type is out patient
  8210.             // and the cureent trmt type is inpatient
  8211.             // the extra amount paid last time as outpatient is adjusted this time
  8212.  
  8213.             if(OHConstants.TRMT_TYPE_INPATIENT.equals(prevTreatmentType)&&
  8214.                 OHConstants.TRMT_TYPE_INPATIENT.equals(currentTreatmentType)&&
  8215.                 OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.equals(prevBenefitType))
  8216.             {
  8217.                 String calenderType = getCalendarType(injuryList);
  8218.                 adjBenBean.setOhBenCode
  8219.                         (OHConstants.OH_ALWNC_DAIlY_INPATIENT);
  8220.  
  8221.                 if(OHConstants.HIJRAH.equals(calenderType))
  8222.                 {
  8223.                     adjBenBean=setDailyAllowanceHij
  8224.                         (adjBenBean,hospitalType);
  8225.                 }else
  8226.                 {
  8227.                     adjBenBean=setDailyAllowanceGreg
  8228.                         (adjBenBean,hospitalType);
  8229.                 }
  8230.                 Double prevOUTBenAmount = PrevBenefitBean.getBenAmount();
  8231.                 Double adjINBenAmount = adjBenBean.getBenAmount();
  8232.                 double adjBenAmount = adjINBenAmount.doubleValue()-prevOUTBenAmount.doubleValue();
  8233.                 GOSIDebug.debugMessages("BENEFIT AMOUNT PREVOUT :"+prevOUTBenAmount);
  8234.                 GOSIDebug.debugMessages("BENEFIT AMOUNT ADJIN   :"+adjINBenAmount);
  8235.                 GOSIDebug.debugMessages("BENEFIT AMOUNT ADJ     :"+adjBenAmount);
  8236.                 if(adjBenAmount!= 0)
  8237.                 {
  8238.                     adjBenBean.setBenAmount(new Double(adjBenAmount));
  8239.                     if(OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals(
  8240.                         adjBenBean.getBenefitPayableTo()))
  8241.                     {
  8242.                         adjBenBean.setBenefitPayableTo(OHConstants.OH_BNFT_PAY_TO_CON);
  8243.                     }
  8244.                     benefitList.add(0,adjBenBean);
  8245.                 }
  8246.             }
  8247.             GOSIDebug.debugMessages("BenefitListSize:" + benefitList + ":");
  8248.             GOSIDebug.debugMessages("End adjustLastInpatientDate - MaintainOHAllowanceSessionEJB");
  8249.             return benefitList;
  8250.  
  8251.         }
  8252.         catch(GOSIException ge)
  8253.         {
  8254.             throw ge;
  8255.         }
  8256.         catch(Exception e)
  8257.         {
  8258.             GOSIDebug.debugMessages("session-getPrevBenefitBean : The exp is "+e);
  8259.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  8260.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  8261.                 "getTreatmentType()",e,"CMN_ERR_1000");
  8262.         }
  8263.  
  8264.  
  8265.     }
  8266.  
  8267.  
  8268.     /**
  8269.     * @METHOD NAME              :   getTreatmentType
  8270.     * @INFORMATION              :   This method is to  get Treatment Type
  8271.     * @PARAM                    :   class java.lang.Long,
  8272.                                     class java.sql.Timestamp
  8273.     * @RETURN                   :   class java.util.HashMap
  8274.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  8275.     * @LAST MODIFIED BY         :
  8276.     * @LAST MODIFIED DATE       :
  8277.     **/
  8278.     private HashMap getTreatmentType(Long injuryId,Timestamp treatmentDate,boolean isTreatmentApproved)
  8279.         throws GOSIException
  8280.         {
  8281.             PreparedStatement ps = null;
  8282.             ResultSet rs = null;
  8283.             String sqlQuery = "";
  8284.             Short treatmentType = null;
  8285.             Short hospitalType = null;
  8286.             HashMap details = new HashMap();
  8287.             try
  8288.             {
  8289.                 // this query returns the treatment and hosptial type for an injury
  8290.                 // at a particular date
  8291.                 sqlQuery = " select a.HOSPITALTYPE,b.TREATMENTTYPE from "+
  8292.                     SITables.T_HOSPITAL  +" a ,"+
  8293.                     SITables.T_TREATMENT +" b where b.INJURYID =? and "+
  8294.                 " a.hospitalcode = b.hospitalcode and "+
  8295.                 " b.STARTDATE <= ? and b.ENDDATE >= ? and "+
  8296.                 " TREATMENTSTATUS = ? ";
  8297.                 ps = con.prepareStatement(sqlQuery);
  8298.                 ps.setLong(1,injuryId.longValue());
  8299.                 ps.setTimestamp(2,treatmentDate);
  8300.                 ps.setTimestamp(3,treatmentDate);
  8301.                 if(isTreatmentApproved)
  8302.                 {
  8303.                     ps.setShort(4,OHConstants.TRMT_STS_APPROVED.shortValue());
  8304.                 }else
  8305.                 {
  8306.                     ps.setShort(4,OHConstants.TRMT_STS_ENTERED.shortValue());
  8307.                 }
  8308.                 rs = ps.executeQuery();
  8309.                 while (rs.next())
  8310.                 {
  8311.                     if(rs.getObject("TREATMENTTYPE")!= null)
  8312.                     {
  8313.                         treatmentType = new Short(rs.getShort("TREATMENTTYPE"));
  8314.                         details.put("treatmentType",treatmentType);
  8315.                     }
  8316.                     if(rs.getObject("HOSPITALTYPE")!= null)
  8317.                     {
  8318.                         hospitalType = new Short(rs.getShort("HOSPITALTYPE"));
  8319.                         details.put("hospitalType",hospitalType);
  8320.                     }
  8321.                 }
  8322.                 return details;
  8323.             }
  8324.             catch(Exception e)
  8325.             {
  8326.                 GOSIDebug.debugMessages("session-getPrevBenefitBean : The exp is "+e);
  8327.                 throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  8328.                     GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  8329.                     "getTreatmentType()",e,"CMN_ERR_1000");
  8330.             }
  8331.             finally
  8332.             {
  8333.                 GOSIUtilities.cleanUp(ps,rs);
  8334.             }
  8335.  
  8336.         }
  8337.  
  8338.     /**
  8339.     * @METHOD NAME              :   getPrevBenefitBean
  8340.     * @INFORMATION              :   This method is to  get Previous Benefit Bean
  8341.     * @PARAM                    :   class java.lang.Long,
  8342.                                     class java.sql.Timestamp
  8343.     * @RETURN                   :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.OHAllowanceBean
  8344.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  8345.     * @LAST MODIFIED BY         :
  8346.     * @LAST MODIFIED DATE       :
  8347.     **/
  8348.         private OHAllowanceBean getPrevBenefitBean (Long injuryId,Timestamp benefitDate)
  8349.             throws GOSIException
  8350.         {
  8351.             GOSIDebug.debugMessages("Starting getPrevBenefitBean - MaintainOHAllowanceSessionEJB");
  8352.             PreparedStatement ps = null;
  8353.             ResultSet rs =null;
  8354.             OHAllowanceBean prevBenefitBean=null;
  8355.             try
  8356.             {
  8357.                 // this method returns the last paid benefit bean
  8358.                 // is used to find the adjustment amount
  8359.                 String sqlQuery = "" + " select " + " OHBENID, INJURYID, "
  8360.                     + " CONTRIBUTORID, FIELDOFFICECODE, "
  8361.                     + " OHBENCODE, OHBENTYPE, BENSTDATE, "
  8362.                     + " BENSTDATEENTFMT, BENENDDATE, "
  8363.                     + " BENENDDATEENTFMT, BENAMOUNT, BENSTATUS, "
  8364.                     + " PAYMENTMODE, BANKCODE, BANKACCNUMBER, "
  8365.                     + " DATEPAYMENT, DATEPAYMENTENTFMT, "
  8366.                     + " WORKFLOWSTATUS, TOTALCONTWAGE, CREATEDBY, "
  8367.                     + " CREATIONTIMESTAMP, LASTMODIFIEDBY, "
  8368.                     + " LASTMODIFIEDTIMESTAMP, REJECTIONCODE, "
  8369.                     + " PAYABLETO, PARTYCODE, WORKFLOWID    from "
  8370.                     + SITables.T_OHBENEFIT
  8371.                     + " where INJURYID = ? "
  8372.                     + " and BENSTDATE = ? "
  8373.                     + " and BENENDDATE = ? "
  8374.                     + " and BENSTATUS not in (?,?) "
  8375.                     + " and OHBENCODE in (?,?) ";
  8376.                
  8377.                 String entFmt = OHConstants.DEFAULT_ENT_FMT;
  8378.                 ps=con.prepareStatement(sqlQuery);
  8379.                 ps.setLong(1,injuryId.longValue());
  8380.                 ps.setTimestamp(2,benefitDate);
  8381.                 ps.setTimestamp(3,benefitDate);
  8382.                 ps.setShort(4,OHConstants.OH_BNFT_STS_REJECTED.shortValue());
  8383.                 ps.setShort(5,OHConstants.OH_BNFT_STS_CANCELLED.shortValue());
  8384.                 ps.setShort(6,OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.shortValue());
  8385.                 ps.setShort(7,OHConstants.OH_ALWNC_DAILY_OUTPATIENT_ADJUSTMENT.shortValue());
  8386.                 GOSIDebug.debugMessages("SqlQuery:"+sqlQuery);
  8387.                 GOSIDebug.debugMessages("\t\t Param 1 :" + injuryId.longValue() + ":");
  8388.                 GOSIDebug.debugMessages("\t\t Param 2 :" + benefitDate + ":");
  8389.                 GOSIDebug.debugMessages("\t\t Param 3 :" + benefitDate + ":");
  8390.                 GOSIDebug.debugMessages("\t\t Param 4 :" + OHConstants.OH_BNFT_STS_REJECTED.shortValue() + ":");
  8391.                 GOSIDebug.debugMessages("\t\t Param 5 :" + OHConstants.OH_BNFT_STS_CANCELLED.shortValue()+ ":");
  8392.                 GOSIDebug.debugMessages("\t\t Param 6 :" + OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.shortValue() + ":");
  8393.                 GOSIDebug.debugMessages("\t\t Param 7 :" + OHConstants.OH_ALWNC_DAILY_OUTPATIENT_ADJUSTMENT.shortValue() + ":");
  8394.                 rs = ps.executeQuery();
  8395.                 ArrayList prevBenefitList = new ArrayList();
  8396.                 double benefitAmount = 0.00;
  8397.                 while(rs.next())
  8398.                 {
  8399.                     OHAllowanceBean benefitBean=new OHAllowanceBean();
  8400.                     benefitBean.setOhBenId(new Long(rs.getLong("OHBENID")));
  8401.                     benefitBean.setInjuryId (new Long(rs.getLong("INJURYID")));
  8402.                     benefitBean.setContributorId
  8403.                         (new Long(rs.getLong("CONTRIBUTORID")));
  8404.                     benefitBean.setFieldofficeCode
  8405.                         (new Short(rs.getShort("FIELDOFFICECODE")));
  8406.                     benefitBean.setOhBenCode(new Short(rs.getShort("OHBENCODE")));
  8407.                     benefitBean.setOhBenType(rs.getString("OHBENTYPE"));
  8408.                     benefitBean.setBenStDateGreg(rs.getTimestamp("BENSTDATE"));
  8409.                     benefitBean.setBenStDateEntFmt(rs.getString("BENSTDATEENTFMT"));
  8410.                     benefitBean.setBenEndDateGreg
  8411.                         (rs.getTimestamp("BENENDDATE"));
  8412.                     benefitBean.setBenEndDateEntFmt
  8413.                         (rs.getString("BENENDDATEENTFMT"));
  8414.                     entFmt=benefitBean.getBenEndDateEntFmt();
  8415.                     benefitBean.setBenAmount(new Double(rs.getDouble("BENAMOUNT")));
  8416.                     benefitAmount = benefitAmount+benefitBean.getBenAmount().doubleValue();
  8417.                     benefitBean.setBenStatus(new Short(rs.getShort("BENSTATUS")));
  8418.                     if(rs.getObject("PAYMENTMODE")!=null)
  8419.                     {
  8420.                         benefitBean.setPaymentMode
  8421.                             (new Short(rs.getShort("PAYMENTMODE")));
  8422.                     }
  8423.                     if(rs.getObject("BANKCODE")!=null)
  8424.                     {
  8425.                         benefitBean.setBankCode
  8426.                             (new Integer(rs.getInt("BANKCODE")));
  8427.                     }
  8428.                     if(rs.getObject("BANKACCNUMBER")!=null)
  8429.                     {
  8430.                         benefitBean.setBankAccNumber
  8431.                             (new Long(rs.getLong("BANKACCNUMBER")));
  8432.                     }
  8433.                     if(rs.getObject("DATEPAYMENT")!=null)
  8434.                     {
  8435.                         benefitBean.setDatePaymentGreg
  8436.                             (rs.getTimestamp("DATEPAYMENT"));
  8437.                         benefitBean.setDatePaymentEntFmt
  8438.                             (rs.getString("DATEPAYMENTENTFMT"));
  8439.                     }
  8440.                     benefitBean.setWorkflowStatus
  8441.                         (new Short(rs.getShort("WORKFLOWSTATUS")));
  8442.                     benefitBean.setTotalContWage
  8443.                         (new Double(rs.getDouble("TOTALCONTWAGE")));
  8444.                     benefitBean.setCreatedBy(new Long(rs.getLong("CREATEDBY")));
  8445.                     benefitBean.setCreationTimestamp
  8446.                         (rs.getTimestamp("CREATIONTIMESTAMP"));
  8447.                     if(rs.getObject("LASTMODIFIEDBY")!=null)
  8448.                     {
  8449.                         benefitBean.setLastModifiedBy
  8450.                             (new Long(rs.getLong("LASTMODIFIEDBY")));
  8451.                         benefitBean.setLastModifiedTimestamp
  8452.                             (rs.getTimestamp("LASTMODIFIEDTIMESTAMP"));
  8453.                     }
  8454.                     if(rs.getObject("REJECTIONCODE")!=null)
  8455.                     {
  8456.                         benefitBean.setRejectionCode
  8457.                             (new Short(rs.getShort("REJECTIONCODE")));
  8458.                     }
  8459.                     if(rs.getObject("PARTYCODE")!=null)
  8460.                     {
  8461.                         benefitBean.setPartyCode
  8462.                             (new Long (rs.getLong("PARTYCODE")));
  8463.                     }
  8464.                     if(rs.getObject("PAYABLETO")!=null)
  8465.                     {
  8466.                         benefitBean.setBenefitPayableTo
  8467.                             (new Short (rs.getShort("PAYABLETO")));
  8468.                     }
  8469.                     benefitBean.setWorkflowId(new Long(rs.getLong("WORKFLOWID")));
  8470.                     prevBenefitList.add(benefitBean);
  8471.                 }
  8472.                 if(prevBenefitList.size()==0)
  8473.                 {
  8474.                     prevBenefitBean = null;
  8475.                 }else
  8476.                 if(prevBenefitList.size()==1)
  8477.                 {
  8478.                     prevBenefitBean = (OHAllowanceBean)prevBenefitList.get(0);
  8479.                 }
  8480.                 else
  8481.                 {  
  8482.                     for (int i=0;i<prevBenefitList.size() ;i++ )
  8483.                     {
  8484.                         OHAllowanceBean benefitBean = (OHAllowanceBean)prevBenefitList.get(i);
  8485.                         if(OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.equals(benefitBean.getOhBenCode()))
  8486.                         {
  8487.                             prevBenefitBean = benefitBean;
  8488.                             prevBenefitBean.setBenAmount(new Double(benefitAmount));
  8489.                         }
  8490.                     }
  8491.                 }
  8492.                 GOSIDebug.debugMessages("Ending getPrevBenefitBean - MaintainOHAllowanceSessionEJB");
  8493.                 return prevBenefitBean;
  8494.  
  8495.             }
  8496.             catch(Exception e)
  8497.             {
  8498.                 GOSIDebug.debugMessages("session-getPrevBenefitBean : The exp is "+e);
  8499.                 throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  8500.                     GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  8501.                     "getPrevBenefitBean()",e,"CMN_ERR_1000");
  8502.             }
  8503.             finally
  8504.             {
  8505.                 GOSIUtilities.cleanUp(ps,rs);
  8506.             }
  8507.         }
  8508.  
  8509.  
  8510.     /**
  8511.     * @METHOD NAME              :   getPayeeName
  8512.     * @INFORMATION              :   This method is to  get Payee Name
  8513.     * @PARAM                    :   class java.lang.Long
  8514.     * @RETURN                   :   class java.lang.String
  8515.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  8516.     * @LAST MODIFIED BY         :
  8517.     * @LAST MODIFIED DATE       :
  8518.     **/
  8519.     private String getPayeeName(Long contributorId)
  8520.         throws GOSIException
  8521.     {
  8522.         // payee name = authorized person name if he is there else contributor name
  8523.         PreparedStatement ps = null;
  8524.         ResultSet rs = null;
  8525.         String payeeName = null;
  8526.         Long personId = null;
  8527.         Long contactId = null;
  8528.          
  8529.         try
  8530.         {
  8531.             String sqlQuery = " select AUTHORIZEDPERSONID FROM "
  8532.                     + SITables.T_OHAUTHORIZEDPERSON
  8533.                     + " where CONTRIBUTORID =? and STATUS = ? ";
  8534.             con = GOSIUtilities.getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  8535.            
  8536.             ps = con.prepareStatement(sqlQuery);
  8537.             GOSIDebug.debugMessages("SqlQuery :" + sqlQuery + ":");
  8538.             GOSIDebug.debugMessages("\t\t Param 1 :" + contributorId.longValue() + ":");
  8539.             GOSIDebug.debugMessages("\t\t Param 2 :" + OHConstants.AUTHORIZED_PERSON_STATUS_ACTIVE.shortValue() + ":");
  8540.            
  8541.             ps.setLong(1, contributorId.longValue());
  8542.             ps.setShort(2, OHConstants.AUTHORIZED_PERSON_STATUS_ACTIVE.shortValue());
  8543.             rs = ps.executeQuery();
  8544.             if(rs.next())
  8545.             {
  8546.                 personId = new Long(rs.getLong("AUTHORIZEDPERSONID"));         
  8547.                
  8548.             }
  8549.             if(personId != null)
  8550.             {
  8551.                 PersonBean  personBean  = PersonUtilities.displayPerson(personId);
  8552.                 payeeName = personBean.getFirstName();
  8553.                 if(personBean.getSecondName()!= null)
  8554.                 {
  8555.                     payeeName = payeeName + " " + personBean.getSecondName();
  8556.                 }
  8557.                 if(personBean.getThirdName()!= null)
  8558.                 {
  8559.                     payeeName = payeeName + " " + personBean.getThirdName();
  8560.                 }
  8561.                 if(personBean.getSurName()!= null)
  8562.                 {
  8563.                     payeeName = payeeName + " " + personBean.getSurName();
  8564.                 }
  8565.             }
  8566.             return payeeName;
  8567.         }
  8568.         catch (GOSIException ge)
  8569.         {
  8570.             throw ge;
  8571.         }
  8572.         catch(Exception se)
  8573.         {
  8574.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  8575.             GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  8576.             "getPayeeName()",se,"CMN_ERR_1000");
  8577.         }
  8578.         finally
  8579.         {
  8580.             GOSIUtilities.cleanUp(con,ps,rs);
  8581.         }
  8582.     }
  8583.  
  8584.  
  8585.     /**
  8586.     * @METHOD NAME              :   sentOHAllowanceforWorkflow
  8587.     * @INFORMATION              :   This method is to  sent OH Allowancefor
  8588.                                     Workflow from view benefit screen
  8589.     * @PARAM                    :   class java.lang.Long,
  8590.                                     class gosi.core.workflow.beans.WorkflowParamBean
  8591.     * @RETURN                   :   class java.lang.String
  8592.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  8593.     * @LAST MODIFIED BY         :
  8594.     * @LAST MODIFIED DATE       :
  8595.     **/
  8596.     public String sentOHAllowanceforWorkflow(Long injuryId ,
  8597.         WorkflowParamBean workflowParamBean)throws GOSIException
  8598.     {
  8599.         PreparedStatement ps = null;
  8600.         ResultSet rs = null;
  8601.         try
  8602.         {
  8603.             // this query picks up all records with workflow staus
  8604.             // pending data entry and send them into workflow inbox
  8605.             // only for cases migrated into the new system
  8606.  
  8607.             ArrayList benefitList = new ArrayList();
  8608.             String name = "";
  8609.             con = GOSIUtilities.getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  8610.             String sqlQuery = " select OHBENID "+
  8611.             " from " +SITables.T_OHBENEFIT +
  8612.             " where INJURYID = ? and BENSTATUS = ?  and WORKFLOWSTATUS = ? ";
  8613.             ps = con.prepareStatement(sqlQuery);
  8614.             ps.setLong(1,injuryId.longValue());
  8615.             ps.setLong(2,OHConstants.OH_BNFT_STS_ENTERED.shortValue());
  8616.             ps.setLong(3,OHConstants.WFS_OH_BNFT_PENDING_DATA_ENTRY.shortValue());
  8617.             rs = ps.executeQuery();
  8618.             while(rs.next())
  8619.             {
  8620.                 Long benefitId = new Long(rs.getLong("OHBENID"));
  8621.                 benefitList.add(benefitId);
  8622.             }
  8623.             Long userId=new Long(workflowParamBean.getUserId());
  8624.             Timestamp currentTime =new Timestamp(System.currentTimeMillis());
  8625.  
  8626.             if(benefitList.size()>0)
  8627.             {
  8628.                 Long workflowId=GOSIUtilities.getPrimaryKey("OHBNFTWORKFLOWID",userId);
  8629.                 OHAllowanceEntityHome home=(OHAllowanceEntityHome)
  8630.                     ServiceLocator.getInstance().getRemoteHome(
  8631.                     OHConstants.OH_ALLOWANCE_ENTITY_JNDI,
  8632.                     OHAllowanceEntityHome.class);
  8633.                 // updating oh benefit
  8634.                 for (int i=0;i<benefitList.size();i++)
  8635.                 {
  8636.                     Long benefitId = (Long)benefitList.get(i);
  8637.                     OHAllowanceEntity remote=(OHAllowanceEntity)
  8638.                         home.findByPrimaryKey(benefitId);
  8639.                     OHAllowanceBean benefitBean = remote.getOHBenefits();
  8640.                     benefitBean.setWorkflowId(workflowId);
  8641.                     benefitBean.setWorkflowStatus(OHConstants.WFS_OH_BNFT_ENTERED);
  8642.                     benefitBean.setLastModifiedBy(userId);
  8643.                     benefitBean.setLastModifiedTimestamp(currentTime);
  8644.                     remote.modifyOHBenefits(benefitBean);
  8645.                 }
  8646.  
  8647.                 workflowParamBean.setPrimaryKeyOfTherecord(workflowId.toString());
  8648.                 name = GOSIUtilities.startWorkflow(workflowParamBean);
  8649.             }else
  8650.             {
  8651.                 throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  8652.                 GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  8653.                 "sentOHAllowanceforWorkflow()",null,"CMN_ERR_1000");
  8654.             }
  8655.             return name;
  8656.         }
  8657.         catch (GOSIException ge)
  8658.         {
  8659.             ctx.setRollbackOnly();
  8660.             throw ge;
  8661.         }
  8662.         catch(Exception e)
  8663.         {
  8664.             ctx.setRollbackOnly();
  8665.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  8666.             GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  8667.             "sentOHAllowanceforWorkflow()",e,"CMN_ERR_1000");
  8668.         }
  8669.         finally
  8670.         {
  8671.             GOSIUtilities.cleanUp(con,ps,rs);
  8672.         }
  8673.     }
  8674.  
  8675.     /**
  8676.     * @METHOD NAME              :   validateContactDetails
  8677.     * @INFORMATION              :   This method is to validate the payment details if payment mode is overseas cheque
  8678.     * @PARAM                    :   class java.util.ArrayList,
  8679.     * @PARAM                    :   class java.util.ArrayList,
  8680.                                     class java.lang.Long
  8681.     * @RETURN                   :   void
  8682.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  8683.     * @LAST MODIFIED BY         :
  8684.     * @LAST MODIFIED DATE       :
  8685.     **/
  8686.  
  8687.     private void validateContactDetails(ArrayList contactList,
  8688.         ArrayList benefitList) throws GOSIException
  8689.     {
  8690.         try
  8691.         {
  8692.             boolean isPayableToCon = false;
  8693.             boolean hasValidContact = false;
  8694.             boolean isContactDetailsPresent = false;
  8695.             Long createdBy = null;
  8696.             // this method validates the contact details of the contributor
  8697.             // checks if his adress is non saudi if the payment mode is FC check
  8698.             Short paymentMode = null;
  8699.             Long contributorId = null;
  8700.             for (int i =0;i<benefitList.size() ;i++ )
  8701.             {
  8702.                 OHAllowanceBean benefitBean = (OHAllowanceBean)benefitList.get(i);
  8703.                 createdBy = benefitBean.getCreatedBy();
  8704.                 if(OHConstants.OH_BNFT_PAY_TO_CON.equals(benefitBean.getBenefitPayableTo())
  8705.                     ||OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals(benefitBean.getBenefitPayableTo()))
  8706.                 {
  8707.                     isPayableToCon = true;
  8708.                     paymentMode = benefitBean.getPaymentMode();
  8709.                     contributorId = benefitBean.getContributorId();
  8710.                     break;
  8711.                 }
  8712.             }
  8713.             if(contactList == null)
  8714.             {
  8715.                 isContactDetailsPresent = false;
  8716.  
  8717.             }else
  8718.             {
  8719.                 isContactDetailsPresent = true;
  8720.             }
  8721.             if(isPayableToCon &&
  8722.                 OHConstants.PAYMENT_MODE_CHEQUE_OVERSEAS.equals(paymentMode))
  8723.             {
  8724.                 if(contactList == null)
  8725.                 {
  8726.                     ContributorBean contributorBean = ContributorUtilities.
  8727.                         displayContributor(contributorId);
  8728.                     Long contactId = contributorBean.getContactId();
  8729.                     GOSIDebug.debugMessages("contactId:"+contactId);
  8730.                     contactList = GOSIUtilities.
  8731.                         getIndividualContactDetails
  8732.                             (contactId,GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  8733.                 }
  8734.                 if(contactList != null && contactList.size()>0)
  8735.                 {
  8736.                     for (int i =0;i<contactList.size() ;i++ )
  8737.                     {
  8738.                         IndividualContactBean contactBean = (IndividualContactBean)contactList.get(i);
  8739.                         if(contactBean.getCurrentMailingAddrInd()==RegistrationConstants.CURRENT_MAILING_ADDRESS.byteValue())
  8740.                         {
  8741.                             if(contactBean.getCountry()!= OHConstants.NATIONALITY_CODE_SAUDI.shortValue())
  8742.                             {
  8743.                                 hasValidContact = true;
  8744.                             }
  8745.                             break;
  8746.                         }
  8747.                     }
  8748.                 }
  8749.                 if(!hasValidContact)
  8750.                 {
  8751.                     throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  8752.                     GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  8753.                     "validatePaymentDetails()",null,"SOI_ERR_5548");
  8754.                 }
  8755.             }
  8756.             else if(isPayableToCon &&
  8757.                 OHConstants.PAYMENT_MODE_CHEQUE.equals(paymentMode))
  8758.             {
  8759.                 if(contactList == null)
  8760.                 {
  8761.                     ContributorBean contributorBean = ContributorUtilities.
  8762.                         displayContributor(contributorId);
  8763.                     Long contactId = contributorBean.getContactId();
  8764.                     GOSIDebug.debugMessages("contactId:"+contactId);
  8765.                     contactList = GOSIUtilities.
  8766.                         getIndividualContactDetails
  8767.                             (contactId,GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  8768.                 }
  8769.                 if(contactList != null && contactList.size()>0)
  8770.                 {
  8771.                     for (int i =0;i<contactList.size() ;i++ )
  8772.                     {
  8773.                         IndividualContactBean contactBean = (IndividualContactBean)contactList.get(i);
  8774.                         if(contactBean.getCurrentMailingAddrInd()==RegistrationConstants.CURRENT_MAILING_ADDRESS.byteValue())
  8775.                         {
  8776.                             if(contactBean.getCountry()== OHConstants.NATIONALITY_CODE_SAUDI.shortValue())
  8777.                             {
  8778.                                 hasValidContact = true;
  8779.                             }
  8780.                             break;
  8781.                         }
  8782.                     }
  8783.                 }
  8784.                 if(!hasValidContact)
  8785.                 {
  8786.                     throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  8787.                     GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  8788.                     "validatePaymentDetails()",null,"SOI_ERR_7213");
  8789.                 }
  8790.             }
  8791.             // inserting contact Details
  8792.             if(isContactDetailsPresent)
  8793.             {
  8794.                 AuditBean contactAuditBean =new AuditBean();
  8795.                 Timestamp currentTime =new Timestamp(System.currentTimeMillis());
  8796.                 contactAuditBean.setCreatedBy(createdBy);
  8797.                 contactAuditBean.setLastModifiedBy(createdBy);
  8798.                 contactAuditBean.setCreationTimestamp(currentTime);
  8799.                 contactAuditBean.setLastModifiedTimestamp(currentTime);
  8800.                 contactAuditBean.setModuleId(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  8801.                 boolean contactflag =false;
  8802.  
  8803.                 if((contactList!=null)&&(contactList.size()!=0))
  8804.                 {   int count = 0;
  8805.                     for(int i=0; i<contactList.size();i++)
  8806.                     {
  8807.                         IndividualContactBean contactBean=
  8808.                             (IndividualContactBean)contactList.get(i);
  8809.                         GOSIDebug.debugMessages("mode:"+contactBean.getMode());
  8810.                         if(AuditBean.DELETE_MODE != contactBean.getMode())
  8811.                         {
  8812.                             count=count+1;
  8813.                         }
  8814.                     }
  8815.                     if(count==0)
  8816.                     {
  8817.                         contactflag = false;
  8818.                     }else
  8819.                     {
  8820.                         contactflag=true;
  8821.                     }
  8822.                 }else
  8823.                 {
  8824.                     contactflag=false;
  8825.                 }
  8826.                 if(!contactflag)
  8827.                 {
  8828.                     throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  8829.                     GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  8830.                     "validatePaymentDetails()",null,"SOI_ERR_4406");
  8831.                 }
  8832.                 GOSIUtilities.modifyIndividualContactDetails(contactList,contactAuditBean);
  8833.             }
  8834.  
  8835.         }
  8836.         catch (GOSIException ge)
  8837.         {
  8838.             throw ge;
  8839.         }
  8840.         catch(Exception e)
  8841.         {
  8842.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  8843.             GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  8844.             "validatePaymentDetails()",e,"CMN_ERR_1000");
  8845.         }
  8846.     }
  8847.  
  8848.  
  8849.     /**
  8850.     * @METHOD NAME              :   cancelChequeIssued
  8851.     * @INFORMATION              :   This method is to update the status of paid
  8852.                                     ohbenfit to cheque returned when the cheque is
  8853.                                     cancelled by finance
  8854.     * @PARAM                    :   class java.util.HashMap
  8855.     * @RETURN                   :   class java.util.HashMap
  8856.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  8857.     * @LAST MODIFIED BY         :
  8858.     * @LAST MODIFIED DATE       :
  8859.     **/
  8860.     public HashMap cancelChequeIssued(HashMap hashMapInterfaceInput)
  8861.         throws GOSIException
  8862.     {
  8863.         PreparedStatement ps = null;
  8864.         ResultSet rs = null;
  8865.         try
  8866.         {
  8867.             ArrayList benefitList = new ArrayList();
  8868.             // this interface method updates the oh benefit status
  8869.             // to check returned when  the check is cancelled in finance
  8870.             Long journalHeaderId = (Long)hashMapInterfaceInput.
  8871.                 get(OccupationalHazardsInterfaceConstants.CREDIT_NOTE_ID);
  8872.  
  8873.             Short moduleId =(Short)hashMapInterfaceInput.
  8874.                 get(OccupationalHazardsInterfaceConstants.MODULE_ID);
  8875.  
  8876.             con = GOSIUtilities.getConnection(moduleId.shortValue());
  8877.             String sqlQuery = " select OHBENID "+
  8878.             " from " +SITables.T_OHBENEFIT +
  8879.             " where JOURNALHEADERID = ? and BENSTATUS in(?,?)  ";
  8880.             ps = con.prepareStatement(sqlQuery);
  8881.             ps.setLong(1,journalHeaderId.longValue());
  8882.             ps.setLong(2,OHConstants.OH_BNFT_STS_PAID.shortValue());
  8883.             ps.setLong(3,OHConstants.OH_BNFT_STS_APPROVED.shortValue());
  8884.             rs = ps.executeQuery();
  8885.             while(rs.next())
  8886.             {
  8887.                 Long benefitId = new Long(rs.getLong("OHBENID"));
  8888.                 benefitList.add(benefitId);
  8889.             }
  8890.             Long userId=(Long)hashMapInterfaceInput.
  8891.                 get(OccupationalHazardsInterfaceConstants.USER_ID);
  8892.  
  8893.             Timestamp currentTime = new Timestamp(System.currentTimeMillis());         
  8894.             MaintainOHServicesEntityHome home = (MaintainOHServicesEntityHome) ServiceLocator
  8895.                     .getInstance().getRemoteHome(
  8896.                             OHConstants.MAINTAIN_OH_SERVICES_ENTITY_JNDI,
  8897.                             MaintainOHServicesEntityHome.class);
  8898.             MaintainOHServicesEntity remote = home.findByPrimaryKey(new Long("0"));
  8899.             remote.updateOHBenefitStatus(hashMapInterfaceInput);
  8900.             return hashMapInterfaceInput;
  8901.         }
  8902.         catch (GOSIException ge)
  8903.         {
  8904.             ctx.setRollbackOnly();
  8905.             throw ge;
  8906.         }
  8907.         catch(Exception e)
  8908.         {
  8909.             ctx.setRollbackOnly();
  8910.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  8911.             GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  8912.             "cancelChequeIssued()",e,"CMN_ERR_1000");
  8913.         }
  8914.         finally
  8915.         {
  8916.             GOSIUtilities.cleanUp(con,ps,rs);
  8917.         }
  8918.     }
  8919.  
  8920.     /**
  8921.     * @METHOD NAME              :   reIssueCancelledCheque
  8922.     * @INFORMATION              :   This method is to  re isssue the
  8923.                                     cancelled cheque details with the new details
  8924.     * @PARAM                    :   class java.lang.Long
  8925.     * @RETURN                   :   class java.util.ArrayList
  8926.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  8927.     * @LAST MODIFIED BY         :
  8928.     * @LAST MODIFIED DATE       :
  8929.     **/
  8930.     public void reIssueCancelledCheque(ArrayList contactList,
  8931.         WorkflowParamBean workflowParamBean, Long contributorId,Short paymentMode, Integer chequeCancelCode,
  8932.         PersonBean personBean,boolean isArabNation)
  8933.         throws GOSIException
  8934.     {
  8935.         PreparedStatement ps = null;
  8936.         ResultSet rs = null;
  8937.         String payeeFirstName   = "";
  8938.         String payeeSecondName  = "";
  8939.         String payeeThirdName   = "";
  8940.         String payeeSurName     = "";
  8941.         String payeeName        = "";
  8942.         String payeeNameEnglish = "";
  8943.         Short paymentModeFA=null;
  8944.         try
  8945.         {
  8946.             ArrayList benefitList = new ArrayList();
  8947.             OHAllowanceBean ohBenefitBean= new OHAllowanceBean();
  8948.             con = GOSIUtilities.getConnection(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  8949.             // query to get all benefit with status returned
  8950.             String sqlQuery = " select OHBENID,JOURNALHEADERID "+
  8951.                 " from " +SITables.T_OHBENEFIT +
  8952.                 " where CONTRIBUTORID = ?  and BENSTATUS IN (?, ?)  ";
  8953.  
  8954.             GOSIDebug.debugMessages("SqlQuery :" + sqlQuery + ":");
  8955.             GOSIDebug.debugMessages("\t\t Param 1 :" + contributorId.longValue() + ":");
  8956.             GOSIDebug.debugMessages("\t\t Param 2 :" + OHConstants.OH_BNFT_STS_RETURNED.shortValue() + ":");
  8957.             GOSIDebug.debugMessages("\t\t Param 3 :" + OHConstants.OH_BNFT_STS_RETURNED2.shortValue() + ":");
  8958.  
  8959.             ps = con.prepareStatement(sqlQuery);
  8960.             ps.setLong(1, contributorId.longValue());
  8961.             ps.setLong(2, OHConstants.OH_BNFT_STS_RETURNED.shortValue());
  8962.             ps.setLong(3, OHConstants.OH_BNFT_STS_RETURNED2.shortValue());
  8963.             rs = ps.executeQuery();
  8964.             while(rs.next())
  8965.             {
  8966.                 ohBenefitBean.setOhBenId(new Long(rs.getLong("OHBENID")));
  8967.                 ohBenefitBean.setJournalHeaderId(new Long(rs.getLong("JOURNALHEADERID")));
  8968.                 benefitList.add(ohBenefitBean);
  8969.             }
  8970.             Long userId = new Long(workflowParamBean.getUserId());
  8971.             Timestamp currentTime =new Timestamp(System.currentTimeMillis());
  8972.  
  8973.             ArrayList newBenefitList = new ArrayList();
  8974.             // updating all returned benefits to status approved
  8975.  
  8976.             OHAllowanceEntityHome home=(OHAllowanceEntityHome)
  8977.                     ServiceLocator.getInstance().getRemoteHome(
  8978.                     OHConstants.OH_ALLOWANCE_ENTITY_JNDI,
  8979.                     OHAllowanceEntityHome.class);
  8980.  
  8981.             if(benefitList.size()>0)
  8982.             {
  8983.                 for (int i=0;i<benefitList.size();i++)
  8984.                 {
  8985.                 OHAllowanceBean OHAllowanceBean = (OHAllowanceBean)benefitList.get(i);
  8986.                 OHAllowanceEntity remote=(OHAllowanceEntity)
  8987.                     home.findByPrimaryKey(OHAllowanceBean.getOhBenId());
  8988.                 OHAllowanceBean benefitBean = remote.getOHBenefits();
  8989.  
  8990.                 benefitBean.setBenStatus(OHConstants.OH_BNFT_STS_APPROVED);
  8991.                 benefitBean.setWorkflowStatus(OHConstants.WFS_OH_BNFT_APPROVED_INT_AUD_CLK);
  8992.                 benefitBean.setPaymentMode(paymentMode);
  8993.                 benefitBean.setLastModifiedBy(userId);
  8994.                 benefitBean.setLastModifiedTimestamp(currentTime);
  8995.                 remote.modifyOHBenefits(benefitBean);
  8996.                 newBenefitList.add(benefitBean);
  8997.                 }
  8998.             }
  8999.             else
  9000.             {
  9001.                 throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9002.                 GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  9003.                 "cancelChequeIssued()",null,"CMN_ERR_1000");
  9004.             }
  9005.             // validating the contact detals for the contributor
  9006.             validateContactDetails(contactList,newBenefitList);
  9007.             // calling finance interface  to remove hold and
  9008.             // update the payment mode
  9009.             ContributorBean contributorBean = ContributorUtilities.
  9010.                 displayContributor(contributorId);
  9011.             /* Convert payment mode to its equivalent value in finance */
  9012.             if (paymentMode != null)
  9013.             {
  9014.                 if (paymentMode.equals(OHConstants.PAYMENT_MODE_BANK_TRANSFER))
  9015.                 {
  9016.                     paymentModeFA = new Short ((short) FAConstants.ACCOUNT_TRANSFER);
  9017.                 }
  9018.                 else if (paymentMode.equals(OHConstants.PAYMENT_MODE_CHEQUE))
  9019.                 {
  9020.                     paymentModeFA = new Short ((short) FAConstants.LC_CHEQUE);
  9021.                 }
  9022.                 else if (paymentMode.equals(OHConstants.PAYMENT_MODE_CHEQUE_OVERSEAS))
  9023.                 {
  9024.                     paymentModeFA = new Short ((short) FAConstants.LC_CHEQUE);
  9025.                 }
  9026.                 else if (paymentMode.equals(OHConstants.PAYMENT_MODE_CHEQUE_AUTHORIZED_PERSON))
  9027.                 {
  9028.                     paymentModeFA = new Short ((short) FAConstants.LC_CHEQUE);
  9029.                 }
  9030.                 else
  9031.                 {
  9032.                     paymentModeFA = new Short ((short) FAConstants.LC_CHEQUE);
  9033.                 }
  9034.             }
  9035.            
  9036.             IndividualContactBean contactBean = null;
  9037.  
  9038.                 for (int i = 0; i < contactList.size(); i++)
  9039.                 {
  9040.                     IndividualContactBean aContactBean = (IndividualContactBean)contactList.get(i);
  9041.                     if(aContactBean.getCurrentMailingAddrInd()==RegistrationConstants.CURRENT_MAILING_ADDRESS.byteValue())
  9042.                     {
  9043.                         contactBean = aContactBean;
  9044.                         break;
  9045.                     }
  9046.                 }          
  9047.  
  9048.  
  9049.             payeeNameEnglish = personBean.getNameEnglish();
  9050.  
  9051.             if(!isArabNation)
  9052.             {
  9053.                 if ((payeeNameEnglish == null) || "".equals(payeeNameEnglish))
  9054.                 {
  9055.                  throw   new GOSIException (GOSIConstants.SEVERITY_THREE,
  9056.                                                    GOSIConstants.SOCIAL_INSURANCE,
  9057.                                                    this.getClass ().toString (),
  9058.                                                    "reIssueCancelledCheque ()",
  9059.                                                    new GOSIException (),
  9060.                                                    "SOI_ERR_5619");
  9061.                 }
  9062.                 payeeName=payeeNameEnglish;
  9063.                 StringTokenizer names=new StringTokenizer(payeeNameEnglish," ");
  9064.                
  9065.                 if(names.hasMoreTokens())
  9066.                 {
  9067.                 payeeFirstName=String.valueOf(names.nextToken());
  9068.                 }
  9069.                 if(names.hasMoreTokens())
  9070.                 {
  9071.                 payeeSecondName=String.valueOf(names.nextToken());
  9072.                 }
  9073.                 if(names.hasMoreTokens())
  9074.                 {
  9075.                 payeeThirdName=String.valueOf(names.nextToken());
  9076.                 }
  9077.                 if(names.hasMoreTokens())
  9078.                 {
  9079.                 payeeSurName=String.valueOf(names.nextToken());
  9080.                 }
  9081.                 if(payeeFirstName.length()>11 || payeeSecondName.length()>11 || payeeThirdName.length()>11 || payeeSurName.length()>11) {
  9082.                     throw   new GOSIException (GOSIConstants.SEVERITY_THREE,
  9083.                             GOSIConstants.SOCIAL_INSURANCE,
  9084.                             this.getClass ().toString (),
  9085.                             "reIssueCancelledCheque ()",
  9086.                             new GOSIException (),
  9087.                             "SOI_ERR_5820");
  9088.                 }
  9089.                 contactBean.setLanguageType("E");
  9090.             }
  9091.             else
  9092.             {
  9093.                 payeeName=personBean.getFullName();
  9094.                 payeeFirstName = personBean.getFirstName();
  9095.                 payeeSecondName = personBean.getSecondName();
  9096.                 payeeThirdName = personBean.getThirdName();
  9097.                 payeeSurName = personBean.getSurName();
  9098.                 contactBean.setLanguageType("A");
  9099.             }
  9100.            
  9101.             HashMap interfaceInputMap = new HashMap();
  9102.             interfaceInputMap.put("methodDescription", FAInterfaceConstants.PAY_ONLINE_REL_HOLD_INTERFACE);
  9103.             interfaceInputMap.put(FAInterfaceConstants.BENEFICIARY_ID, contributorBean.getSocialInsuranceNumber());
  9104.             interfaceInputMap.put(FAInterfaceConstants.MODULE_ID, new Short(GOSIConstants.OCCUPATIONAL_HAZARDS_ID));
  9105.             interfaceInputMap.put(FAInterfaceConstants.RELEASE_UNTIL_DATE, currentTime);
  9106.             interfaceInputMap.put(FAInterfaceConstants.LAST_MODIFIED_BY, userId);
  9107.             interfaceInputMap.put(FAInterfaceConstants.PAYMENT_MODE, paymentModeFA);
  9108.             if(chequeCancelCode.equals(FAInterfaceConstants.BENEFICIARY_NOT_ALIVE))
  9109.                 interfaceInputMap.put(FAInterfaceConstants.BENEFICIARY_NOT_ALIVE, chequeCancelCode);
  9110.             else if(chequeCancelCode.equals(FAInterfaceConstants.BENEFICIARY_LEFT_SA))
  9111.                 interfaceInputMap.put(FAInterfaceConstants.BENEFICIARY_LEFT_SA, chequeCancelCode);
  9112.             interfaceInputMap.put(FAInterfaceConstants.PAYEE_FIRST_NAME, payeeFirstName);
  9113.             interfaceInputMap.put(FAInterfaceConstants.PAYEE_SECOND_NAME, payeeSecondName);
  9114.             interfaceInputMap.put(FAInterfaceConstants.PAYEE_THIRD_NAME, payeeThirdName);
  9115.             interfaceInputMap.put(FAInterfaceConstants.PAYEE_SUR_NAME, payeeSurName);
  9116.             interfaceInputMap.put(FAInterfaceConstants.PAYEE_NAME, payeeName);
  9117.             interfaceInputMap.put(FAInterfaceConstants.CONTACT_ID, contactBean.getContactId());
  9118.             interfaceInputMap.put(FAInterfaceConstants.BENADDRESS, contactBean.getFreeTextDescription());
  9119.             interfaceInputMap.put(FAInterfaceConstants.COUNTRY, contactBean.getCountry());
  9120.             interfaceInputMap.put(FAInterfaceConstants.LANGUAGE_CODE, contactBean.getLanguageType());
  9121.  
  9122.             //Service parameters
  9123.             GOSIDebug.debugMessages("***********************************************************");
  9124.             GOSIDebug.debugMessages("Invoking finance service: ");
  9125.             GOSIDebug.debugMessages(" param methodDescription = FAInterfaceConstants.PAY_ONLINE_REL_HOLD_INTERFACE");
  9126.             GOSIDebug.debugMessages(" param FAInterfaceConstants.BENEFICIARY_ID = " + contributorBean.getSocialInsuranceNumber());
  9127.             GOSIDebug.debugMessages(" param FAInterfaceConstants.MODULE_ID = GOSIConstants.OCCUPATIONAL_HAZARDS_ID");
  9128.             GOSIDebug.debugMessages(" param FAInterfaceConstants.RELEASE_UNTIL_DATE = " + currentTime);
  9129.             GOSIDebug.debugMessages(" param FAInterfaceConstants.LAST_MODIFIED_BY = " + userId);
  9130.             GOSIDebug.debugMessages(" param FAInterfaceConstants.PAYMENT_MODE = " + paymentModeFA);
  9131.             if(chequeCancelCode.equals(FAInterfaceConstants.BENEFICIARY_NOT_ALIVE))
  9132.                 GOSIDebug.debugMessages(" param FAInterfaceConstants.BENEFICIARY_NOT_ALIVE = " + chequeCancelCode);
  9133.             else if(chequeCancelCode.equals(FAInterfaceConstants.BENEFICIARY_LEFT_SA))
  9134.                 GOSIDebug.debugMessages(" param FAInterfaceConstants.BENEFICIARY_LEFT_SA = " + chequeCancelCode);
  9135.             GOSIDebug.debugMessages(" param FAInterfaceConstants.PAYEE_FIRST_NAME = " + payeeFirstName);
  9136.             GOSIDebug.debugMessages(" param FAInterfaceConstants.PAYEE_SECOND_NAME = " + payeeSecondName);
  9137.             GOSIDebug.debugMessages(" param FAInterfaceConstants.PAYEE_THIRD_NAME = " + payeeThirdName);
  9138.             GOSIDebug.debugMessages(" param FAInterfaceConstants.PAYEE_SUR_NAME = " + payeeSurName);
  9139.             GOSIDebug.debugMessages(" param FAInterfaceConstants.PAYEE_NAME = " + payeeName);
  9140.             GOSIDebug.debugMessages(" param FAInterfaceConstants.CONTACT_ID = " + contactBean.getContactId());
  9141.             GOSIDebug.debugMessages(" param FAInterfaceConstants.BENADDRESS = " + contactBean.getFreeTextDescription());
  9142.             GOSIDebug.debugMessages(" param FAInterfaceConstants.COUNTRY = " + contactBean.getCountry());
  9143.             GOSIDebug.debugMessages(" param FAInterfaceConstants.LANGUAGE_CODE = " + contactBean.getLanguageType());
  9144.             GOSIDebug.debugMessages("***********************************************************");
  9145.  
  9146.             FinancialAccountingInterface faInterface;
  9147.             faInterface = FinanceImplProxy.getFAInterface();
  9148.             interfaceInputMap = faInterface.invokeService(interfaceInputMap);
  9149.  
  9150.  
  9151.             if(!interfaceInputMap.isEmpty())
  9152.             {
  9153.                 Iterator iterator = interfaceInputMap.keySet().iterator();
  9154.  
  9155.                 ArrayList journalHeaderIdlist = new ArrayList();
  9156.                 while(iterator.hasNext())
  9157.                 {
  9158.                 Long oldJournalHeaderId = null;
  9159.                 oldJournalHeaderId=(Long)iterator.next();
  9160.                 journalHeaderIdlist.add(oldJournalHeaderId);
  9161.                 }
  9162.  
  9163.                 ArrayList OHBenefitIdList = getOHBenefitIdList(journalHeaderIdlist);
  9164.  
  9165.                 if(OHBenefitIdList.size()>0)
  9166.                 {
  9167.                 for (int i=0;i<OHBenefitIdList.size();i++)
  9168.                 {
  9169.                     OHAllowanceBean OHAllowanceBean1 = (OHAllowanceBean)OHBenefitIdList.get(i);
  9170.                     OHAllowanceEntity remote=(OHAllowanceEntity)
  9171.                         home.findByPrimaryKey(OHAllowanceBean1.getOhBenId());
  9172.                     OHAllowanceBean newOHAllowanceBean = remote.getOHBenefits();
  9173.                     if( interfaceInputMap.containsKey(newOHAllowanceBean.getJournalHeaderId()))
  9174.                     {
  9175.                         newOHAllowanceBean.setJournalHeaderId((Long)interfaceInputMap.get(newOHAllowanceBean.getJournalHeaderId()));
  9176.                         newOHAllowanceBean.setBenStatus(OHConstants.OH_BNFT_STS_APPROVED);
  9177.                         newOHAllowanceBean.setWorkflowStatus(OHConstants.WFS_OH_BNFT_APPROVED_INT_AUD_CLK);
  9178.                         newOHAllowanceBean.setPaymentMode(paymentMode);
  9179.                         newOHAllowanceBean.setLastModifiedBy(userId);
  9180.                         newOHAllowanceBean.setLastModifiedTimestamp(currentTime);
  9181.                         remote.modifyOHBenefits(newOHAllowanceBean);
  9182.                     }
  9183.                 }
  9184.                 }
  9185.             }
  9186.             else
  9187.             {
  9188.                  throw   new GOSIException (GOSIConstants.SEVERITY_THREE,
  9189.                                                    GOSIConstants.SOCIAL_INSURANCE,
  9190.                                                    this.getClass ().toString (),
  9191.                                                    "reIssueCancelledCheque ()",
  9192.                                                    new GOSIException (),
  9193.                                                    "SOI_ERR_5610");
  9194.             }
  9195.         }
  9196.         catch (GOSIException ge)
  9197.         {
  9198.             ctx.setRollbackOnly();
  9199.             throw ge;
  9200.         }
  9201.         catch(Exception e)
  9202.         {
  9203.             ctx.setRollbackOnly();
  9204.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9205.             GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  9206.             "reIssueCancelledCheque()",e,"CMN_ERR_1000");
  9207.         }
  9208.         finally
  9209.         {
  9210.             GOSIUtilities.cleanUp(con,ps,rs);
  9211.         }
  9212.  
  9213.     }
  9214.  
  9215.     /**
  9216.     * @METHOD NAME              :   saveContactDetailsContributor
  9217.     * @INFORMATION              :   This method is to save the contact details
  9218.                                     of the contributor
  9219.     * @PARAM                    :   class java.lang.Long
  9220.     * @RETURN                   :   class java.util.ArrayList
  9221.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  9222.     * @LAST MODIFIED BY         :
  9223.     * @LAST MODIFIED DATE       :
  9224.     **/
  9225.     public void saveContactDetailsContributor(ArrayList contactList,
  9226.         WorkflowParamBean workflowParamBean)
  9227.         throws GOSIException
  9228.     {
  9229.         try
  9230.         {
  9231.  
  9232.             Long createdBy = new Long(workflowParamBean.getUserId());
  9233.             Timestamp currentTime =new Timestamp(System.currentTimeMillis());
  9234.             // this will update the contact details of the contributor
  9235.             if(contactList != null)
  9236.             {
  9237.                 AuditBean contactAuditBean = new AuditBean();
  9238.                 contactAuditBean.setCreatedBy(createdBy);
  9239.                 contactAuditBean.setLastModifiedBy(createdBy);
  9240.                 contactAuditBean.setCreationTimestamp(currentTime);
  9241.                 contactAuditBean.setLastModifiedTimestamp(currentTime);
  9242.                 contactAuditBean.setModuleId(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  9243.                 boolean contactflag =false;
  9244.  
  9245.                 if((contactList!=null)&&(contactList.size()!=0))
  9246.                 {   int count = 0;
  9247.                     for(int i=0; i<contactList.size();i++)
  9248.                     {
  9249.                         IndividualContactBean contactBean=
  9250.                             (IndividualContactBean)contactList.get(i);
  9251.                         GOSIDebug.debugMessages("mode:"+contactBean.getMode());
  9252.                         if(AuditBean.DELETE_MODE != contactBean.getMode())
  9253.                         {
  9254.                             count=count+1;
  9255.                         }
  9256.                     }
  9257.                     if(count==0)
  9258.                     {
  9259.                         contactflag = false;
  9260.                     }else
  9261.                     {
  9262.                         contactflag=true;
  9263.                     }
  9264.                 }else
  9265.                 {
  9266.                     contactflag=false;
  9267.                 }
  9268.                 if(!contactflag)
  9269.                 {
  9270.                     throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  9271.                     GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  9272.                     "saveContactDetailsContributor()",null,"SOI_ERR_4406");
  9273.                 }
  9274.                 GOSIUtilities.modifyIndividualContactDetails(contactList,contactAuditBean);
  9275.             }
  9276.         }
  9277.         catch (GOSIException ge)
  9278.         {
  9279.             ctx.setRollbackOnly();
  9280.             throw ge;
  9281.         }
  9282.         catch(Exception e)
  9283.         {
  9284.             ctx.setRollbackOnly();
  9285.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9286.             GOSIConstants.SOCIAL_INSURANCE, this.getClass().toString(),
  9287.             "saveContactDetailsContributor()",e,"CMN_ERR_1000");
  9288.         }
  9289.     }
  9290.  
  9291.  
  9292.     /**
  9293.     * @METHOD NAME              :   searchInjuryMiscAllowance
  9294.     * @INFORMATION              :   This method is to  search Injury List with sin and injurydate
  9295.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  9296.     * @RETURN                   :   class java.util.ArrayList
  9297.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  9298.     * @LAST MODIFIED BY         :
  9299.     * @LAST MODIFIED DATE       :
  9300.     **/
  9301.    public ArrayList searchInjuryMiscAllowance(InjuryPopDetails searchBean)
  9302.         throws GOSIException
  9303.     {
  9304.         // get injury with status other than cancelled
  9305.         long startTime   = 0;
  9306.         long endTime     = 0;
  9307.         long elapsedTime = 0;
  9308.         startTime = System.currentTimeMillis();
  9309.  
  9310.         PreparedStatement ps = null;
  9311.         ResultSet rs =null;
  9312.         GOSIDebug.debugMessages("-----session:searchInjuryMiscAllowance-----");
  9313.         String message ="";
  9314.  
  9315.         Long socInsNum = searchBean.getSocialInsuranceNumber();
  9316.         Timestamp injuryDate = searchBean.getInjuryDate();
  9317.         String entFmt = searchBean.getInjuryDateEntFmt();
  9318.         GOSIDebug.debugMessages("EntFmt:"+entFmt);
  9319.         GOSIDebug.debugMessages("SIN:"+socInsNum+"\n startDate:"+injuryDate);
  9320.         String sqlQuery="";
  9321.         ArrayList injuryList=new ArrayList();
  9322.         //Query to get injurys which has trmt for the benefit period
  9323.         sqlQuery= " select "+
  9324.             " INJURYID,   "+
  9325.             " SOCINSNUMBER,   "+
  9326.             " CONTRIBUTORID,  "+
  9327.             " ESTABLISHMENTID,  "+
  9328.             " INJURYDATE, "+
  9329.             " DATECOMPLICATION, "+
  9330.             " INJURYNUMBER,   "+
  9331.             " DESCRIPTION,    "+
  9332.             " FIELDOFFICECODE, "+
  9333.             " INJURYSTATUS, "+
  9334.             " EMPLOYERNOTIFYDATE, "+
  9335.             " WORKERINTIMATIONDATE, "+
  9336.             " WAGESTOPDATE, "+
  9337.             " DATEOFDEATH, "+
  9338.             " (NVL(WORKDISABILITYDATE,INJURYDATE +1)) MINDISABLITYDATE, "+
  9339.             " TREATMENTSTDATE, "+
  9340.             " TREATMENTENDDATE " +
  9341.             " from "+ SITables.T_INJURY +
  9342.             " where SOCINSNUMBER=? "+
  9343.             " and INJURYDATE  = ? "+
  9344.             " and INJURYSTATUS not in (?,?,?) "+
  9345.             " order by INJURYDATE ";
  9346.  
  9347.         GOSIDebug.debugMessages("sqlQuery :\n"  +sqlQuery);
  9348.         try
  9349.         {
  9350.            Timestamp currentDate = new Timestamp(System.currentTimeMillis());
  9351.             // comparing end date with current date
  9352.             if(injuryDate.compareTo(currentDate)>0)
  9353.             {
  9354.                 throw new GOSIException( GOSIConstants.SEVERITY_THREE,
  9355.                                         GOSIConstants.OCCUPATIONAL_HAZARDS,
  9356.                                         this.getClass().toString(),
  9357.                                         "searchInjuryList()",null,
  9358.                                         "SOI_ERR_4038");
  9359.             }
  9360.             con = GOSIUtilities.getConnection
  9361.                 (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  9362.             ps=con.prepareStatement(sqlQuery);
  9363.             ps.setLong(1,socInsNum.longValue());
  9364.             ps.setTimestamp(2,injuryDate);
  9365.             ps.setShort(3,OHConstants.INJ_STS_NOTIFIED.shortValue());
  9366.             ps.setShort(4,OHConstants.INJ_STS_FIRST_NOTIFIED.shortValue());
  9367.             ps.setShort(5,OHConstants.INJ_STS_CANCELLED.shortValue());
  9368.             rs=ps.executeQuery();
  9369.             while(rs.next())
  9370.             {
  9371.                 GOSIDebug.debugMessages("searchInjuryList has records");
  9372.                 InjuryPopDetails injuryDetails =new InjuryPopDetails();
  9373.                 injuryDetails.setInjuryID(new Long(rs.getLong("INJURYID")));
  9374.                 injuryDetails.setSocialInsuranceNumber
  9375.                         (new Long(rs.getLong("SOCINSNUMBER")));
  9376.                 injuryDetails.setEstablishmentId
  9377.                         (new Long(rs.getLong("ESTABLISHMENTID")));
  9378.                 injuryDetails.setContributorId
  9379.                         (new Long(rs.getLong("CONTRIBUTORID")));
  9380.                 injuryDetails.setInjuryDate(rs.getTimestamp("INJURYDATE"));
  9381.                 injuryDetails.setInjuryDateEntFmt(entFmt);
  9382.                 if (OHConstants.HIJRAH.equals(entFmt))
  9383.                 {
  9384.                     injuryDetails.setInjuryDateStr
  9385.                         (GOSIDateUtilities.convertToHijra(
  9386.                                 GOSIUtilities.getDateFullString(
  9387.                                 injuryDetails.getInjuryDate())));
  9388.                 }
  9389.                 else
  9390.                 {
  9391.                     injuryDetails.setInjuryDateStr
  9392.                         (GOSIUtilities.getDateFullString(
  9393.                             injuryDetails.getInjuryDate()));
  9394.                 }
  9395.                 if(rs.getObject("DATECOMPLICATION")!= null)
  9396.                 {
  9397.                     /* Populate data with the complication date */
  9398.                     injuryDetails.setComplicationDate
  9399.                         (rs.getTimestamp("DATECOMPLICATION"));
  9400.  
  9401.                     if (OHConstants.HIJRAH.equalsIgnoreCase (injuryDetails.getInjuryDateEntFmt ()))
  9402.                     {
  9403.                         injuryDetails.setComplicationDateStr
  9404.                             (GOSIDateUtilities.convertToHijra(
  9405.                                     GOSIUtilities.getDateFullString(
  9406.                                         injuryDetails.getComplicationDate())));
  9407.                     }
  9408.                     else
  9409.                     {
  9410.                         injuryDetails.setComplicationDateStr
  9411.                             (GOSIUtilities.getDateFullString(injuryDetails.getComplicationDate()));
  9412.                     }
  9413.                 }
  9414.                 injuryDetails.setInjuryNumber
  9415.                         (new Long(rs.getLong("INJURYNUMBER")));
  9416.  
  9417.                 GOSIDebug.debugMessages("injury number:"+injuryDetails.getInjuryNumber());
  9418.                 injuryDetails.setDescription(rs.getString("DESCRIPTION"));
  9419.                 injuryDetails.setFieldOffice
  9420.                         (new Short(rs.getShort("FIELDOFFICECODE")));
  9421.                 injuryDetails.setInjuryStatus
  9422.                     (new Short(rs.getString("INJURYSTATUS")));
  9423.                 if(rs.getObject("EMPLOYERNOTIFYDATE")!= null)
  9424.                 {
  9425.                     injuryDetails.setEmployerNotifyDate
  9426.                     (rs.getTimestamp("EMPLOYERNOTIFYDATE"));
  9427.                 }
  9428.                 if(rs.getObject("WORKERINTIMATIONDATE")!= null)
  9429.                 {
  9430.                     injuryDetails.setWorkerIntimationDate
  9431.                     (rs.getTimestamp("WORKERINTIMATIONDATE"));
  9432.                 }
  9433.                 if(rs.getObject("WAGESTOPDATE")!= null)
  9434.                 {
  9435.                     injuryDetails.setWageStopDate
  9436.                     (rs.getTimestamp("WAGESTOPDATE"));
  9437.                 }
  9438.  
  9439.                 if(rs.getObject("TREATMENTSTDATE")!= null)
  9440.                 {
  9441.                     injuryDetails.setTreatmentStartDate
  9442.                     (rs.getTimestamp("TREATMENTSTDATE"));
  9443.                 }
  9444.                 if(rs.getObject("TREATMENTENDDATE")!= null)
  9445.                 {
  9446.                     injuryDetails.setTreatmentEndDate
  9447.                     (rs.getTimestamp("TREATMENTENDDATE"));
  9448.                 }
  9449.                 if(rs.getObject("MINDISABLITYDATE")!=null)
  9450.                 {
  9451.                     injuryDetails.setWorkDisabilityDate
  9452.                         (rs.getTimestamp("MINDISABLITYDATE"));
  9453.                 }
  9454.                 if(rs.getObject("DATEOFDEATH")!= null)
  9455.                 {
  9456.                     injuryDetails.setDeathDate(rs.getTimestamp("DATEOFDEATH"));
  9457.                 }
  9458.                 // setting contributor details
  9459.                 injuryDetails = setContributorDetails(injuryDetails);
  9460.                 // setting establishment details
  9461.                 injuryDetails=setEstablishmentDetails(injuryDetails);
  9462.  
  9463.                 GOSIDebug.debugMessages("pay to SI: "
  9464.                     +injuryDetails.getBenefitPayableTo());
  9465.                 injuryList.add(injuryDetails);
  9466.                // adding injurydetails to list  for multiple injuryies
  9467.             }
  9468.             int injuryListSize =injuryList.size();
  9469.             if(injuryListSize==0)
  9470.             {
  9471.                 throw new GOSIException( GOSIConstants.SEVERITY_FOUR,
  9472.                                         GOSIConstants.OCCUPATIONAL_HAZARDS,
  9473.                                         this.getClass().toString(),
  9474.                                         "searchInjuryList()",null,
  9475.                                         "SOI_ERR_4762");
  9476.             }
  9477.             for(int i=0;i<injuryListSize;i++)
  9478.             {
  9479.                 InjuryPopDetails injuryDetails =
  9480.                     (InjuryPopDetails)injuryList.get(i);
  9481.                 GOSIDebug.debugMessages("injury number:"+injuryDetails.getInjuryNumber());
  9482.  
  9483.                 if(injuryDetails.getInjuryStatus().equals
  9484.                     (OHConstants.INJ_STS_NOTIFIED))
  9485.                 {
  9486.                     // UnApproved Injury Details found for the
  9487.                     // period entered, Please redefine your calculation period
  9488.                     // or Approve the Injury record
  9489.                     throw new GOSIException( GOSIConstants.SEVERITY_FOUR,
  9490.                                         GOSIConstants.OCCUPATIONAL_HAZARDS,
  9491.                                         this.getClass().toString(),
  9492.                                         "searchInjuryList()",null,
  9493.                                         "SOI_ERR_5189");
  9494.                 }else
  9495.                 {
  9496.                     //setting injury date to complication date
  9497.                     // if complication date is not null and
  9498.                     // the person is having a valid engagement on complication date
  9499.                     Timestamp tempInjuryDate = injuryDetails.getInjuryDate();
  9500.                     if(injuryDetails.getComplicationDate()!=null)
  9501.                     {
  9502.                         if(injuryDetails.getIsEngagementPresentOnComplicationAndEligibleForOH())
  9503.                         {
  9504.                             tempInjuryDate = injuryDetails.getComplicationDate();
  9505.                         }
  9506.                         //setting wage for the injured engagement
  9507.                         injuryDetails = setTotalConWage(tempInjuryDate,injuryDetails);
  9508.  
  9509.                     }else
  9510.                     {
  9511.                         //setting wage for the injured engagement
  9512.                         injuryDetails = setTotalConWage(tempInjuryDate,injuryDetails);
  9513.                     }
  9514.                 }
  9515.             }
  9516.             // calculating the total contributory wage
  9517.             injuryList=getTotalContributorWage(injuryList);
  9518.  
  9519.             endTime = System.currentTimeMillis();
  9520.             elapsedTime = endTime - startTime;
  9521.             GOSIInstrumentationLog.writeInstrumentationToLog(
  9522.                     this.getClass().toString(),
  9523.                     "searchInjuryMiscAllowance()",
  9524.                     elapsedTime);
  9525.  
  9526.         }
  9527.         catch (GOSIException ge)
  9528.         {
  9529.             throw ge;
  9530.         }
  9531.         catch(Exception e)
  9532.         {
  9533.             GOSIDebug.debugMessages("session:searchInjuryMiscAllowance:e:"+e);
  9534.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9535.                                         GOSIConstants.SOCIAL_INSURANCE,
  9536.                                         this.getClass().toString(),
  9537.                                         "searchInjuryMiscAllowance()",e,
  9538.                                         "CMN_ERR_1000");
  9539.  
  9540.         }
  9541.         finally
  9542.         {
  9543.              GOSIUtilities.cleanUp(con, ps, rs);
  9544.         }
  9545.         return injuryList ;
  9546.     }
  9547.  
  9548.     /**
  9549.     * @METHOD NAME              :   isValidMiscBenefit
  9550.     * @INFORMATION              :   This method is to  validate the misc benefit entered
  9551.     * @PARAM                    :   class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryPopDetails
  9552.     * @RETURN                   :   class java.util.ArrayList
  9553.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  9554.     * @LAST MODIFIED BY         :
  9555.     * @LAST MODIFIED DATE       :
  9556.     **/
  9557.    public OHAllowanceBean isValidMiscBenefit(OHAllowanceBean benefitBean,
  9558.        InjuryPopDetails injuryBean)
  9559.         throws GOSIException
  9560.     {
  9561.         try
  9562.         {
  9563.             long startTime   = 0;
  9564.             long endTime     = 0;
  9565.             long elapsedTime = 0;
  9566.             startTime = System.currentTimeMillis();
  9567.             Timestamp tempDate = null;
  9568.             Timestamp currentDate = new Timestamp(startTime);
  9569.  
  9570.             // if benefit end date after current date
  9571.             if(benefitBean.getBenEndDateGreg().after(currentDate))
  9572.             {
  9573.                 throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9574.                             GOSIConstants.SOCIAL_INSURANCE,
  9575.                             this.getClass().toString(),
  9576.                             "isValidMiscBenefit()",null,
  9577.                             "SOI_ERR_4189");
  9578.             }
  9579.             // if benefit end date before start date
  9580.             if(benefitBean.getBenEndDateGreg().before(benefitBean.getBenStDateGreg()))
  9581.             {
  9582.                 throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9583.                             GOSIConstants.SOCIAL_INSURANCE,
  9584.                             this.getClass().toString(),
  9585.                             "isValidMiscBenefit()",null,
  9586.                             "SOI_ERR_4190");
  9587.             }
  9588.             // if complication date is not null temp date is complication date
  9589.             // else injury date
  9590.             if(injuryBean.getComplicationDate()!= null)
  9591.             {
  9592.                 tempDate = injuryBean.getComplicationDate();
  9593.             }else
  9594.             {
  9595.                 tempDate = injuryBean.getInjuryDate();
  9596.             }
  9597.             // if benefit start date after temp date (injury/ complication date)
  9598.             if(tempDate.after(benefitBean.getBenStDateGreg()))
  9599.             {
  9600.                 throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9601.                             GOSIConstants.SOCIAL_INSURANCE,
  9602.                             this.getClass().toString(),
  9603.                             "isValidMiscBenefit()",null,
  9604.                             "SOI_ERR_5551");
  9605.             }
  9606.             // if injury status is approved and benefit enddate after treatment end date
  9607.             // not a valid benefit enter treatment first
  9608.             if(OHConstants.INJ_STS_APPROVED.equals(injuryBean.getInjuryStatus())
  9609.                 ||OHConstants.INJ_STS_CURED_WITHOUT_DISABILITY.equals(injuryBean.getInjuryStatus()))
  9610.             {
  9611.                 if(benefitBean.getBenEndDateGreg().after(injuryBean.getTreatmentEndDate()))
  9612.                 {
  9613.                     throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9614.                             GOSIConstants.SOCIAL_INSURANCE,
  9615.                             this.getClass().toString(),
  9616.                             "isValidMiscBenefit()",null,
  9617.                             "SOI_ERR_5552");
  9618.                 }
  9619.             }
  9620.             // if injury status equals resulted in death no payment shd be after the
  9621.             // death date
  9622.             if(OHConstants.INJ_STS_RESULTED_IN_DEATH.equals(injuryBean.getInjuryStatus()))
  9623.             {
  9624.                 if(benefitBean.getBenEndDateGreg().after(
  9625.                     injuryBean.getDeathDate()))
  9626.                 {
  9627.                     throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9628.                             GOSIConstants.SOCIAL_INSURANCE,
  9629.                             this.getClass().toString(),
  9630.                             "isValidMiscBenefit()",null,
  9631.                             "SOI_ERR_5554");
  9632.                 }
  9633.             }
  9634.             // if benefit started before the treatment ,enter allowance as a missed period
  9635.             if(benefitBean.getBenStDateGreg().before(injuryBean.getTreatmentStartDate()))
  9636.             {
  9637.                     throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9638.                             GOSIConstants.SOCIAL_INSURANCE,
  9639.                             this.getClass().toString(),
  9640.                             "isValidMiscBenefit()",null,
  9641.                             "SOI_ERR_5553");
  9642.             }
  9643.  
  9644.             endTime = System.currentTimeMillis();
  9645.             elapsedTime = endTime - startTime;
  9646.             GOSIInstrumentationLog.writeInstrumentationToLog(
  9647.                     this.getClass().toString(),
  9648.                     "isValidMiscBenefit()",
  9649.                     elapsedTime);
  9650.         }
  9651.         catch(GOSIException ge)
  9652.         {
  9653.             GOSIDebug.debugMessages("session:isValidMiscBenefit:ge:"+ge);
  9654.             throw ge;
  9655.         }
  9656.         catch(Exception e)
  9657.         {
  9658.             GOSIDebug.debugMessages("session:isValidMiscBenefit:e:"+e);
  9659.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9660.                                         GOSIConstants.SOCIAL_INSURANCE,
  9661.                                         this.getClass().toString(),
  9662.                                         "isValidMiscBenefit()",e,
  9663.                                         "CMN_ERR_1000");
  9664.  
  9665.         }
  9666.         return benefitBean ;
  9667.     }
  9668.  
  9669.  
  9670.     /**
  9671.     * @METHOD NAME              :   saveMiscOHAllowance
  9672.     * @INFORMATION              :   This method is to  save Miscellaneous OH Allowance into the T_ohbenefit table
  9673.     * @PARAM                    :   class java.util.ArrayList,
  9674.                                     class gosi.core.workflow.beans.WorkflowParamBean,
  9675.                                     class java.lang.Long
  9676.     * @RETURN                   :   class java.lang.String
  9677.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  9678.     * @LAST MODIFIED BY         :
  9679.     * @LAST MODIFIED DATE       :
  9680.     **/
  9681.     public String saveMiscOHAllowance(InjuryPopDetails injuryBean,
  9682.         ArrayList benefitList,ArrayList contactList,
  9683.         WorkflowParamBean workflowParamBean,
  9684.         DMSRequestHeaderBean headerBean)
  9685.             throws GOSIException
  9686.     {
  9687.         long startTime   = 0;
  9688.         long endTime     = 0;
  9689.         long elapsedTime = 0;
  9690.         startTime = System.currentTimeMillis();
  9691.         double totalAmount = 0.00;
  9692.  
  9693.         String message = "";
  9694.         try
  9695.         {
  9696.             GOSIDebug.debugMessages(""+OHConstants.OH_ALLOWANCE_ENTITY_JNDI);
  9697.             OHAllowanceEntityHome home=(OHAllowanceEntityHome)
  9698.                 ServiceLocator.getInstance().getRemoteHome(
  9699.                 OHConstants.OH_ALLOWANCE_ENTITY_JNDI,
  9700.                 OHAllowanceEntityHome.class);
  9701.             Timestamp currentTime=new Timestamp (System.currentTimeMillis());
  9702.  
  9703.             Long workflowId = GOSIUtilities.getPrimaryKey
  9704.                 ("OHBNFTWORKFLOWID",new Long(workflowParamBean.getUserId()));
  9705.  
  9706.             for(int i=0;i<benefitList.size();i++)
  9707.             {
  9708.                 OHAllowanceBean benefitBean=(OHAllowanceBean)benefitList.get(i);
  9709.                 benefitBean.setOhBenId(GOSIUtilities.getPrimaryKey
  9710.                     ("T_OHBENEFIT",new Long(workflowParamBean.getUserId())));
  9711.                 benefitBean.setContributorId(injuryBean.getContributorId());
  9712.                 benefitBean.setInjuryId(injuryBean.getInjuryID());
  9713.                 benefitBean.setFieldofficeCode(workflowParamBean.getUserLocationId());
  9714.  
  9715.                 benefitBean.setBenStatus(OHConstants.OH_BNFT_STS_ENTERED);
  9716.  
  9717.                
  9718.                 if(benefitBean.getBenAmount().doubleValue() > 0.00)
  9719.                 {
  9720.                     benefitBean.setWorkflowStatus(OHConstants.WFS_OH_BNFT_ENTERED);
  9721.                 }
  9722.                 else if(benefitBean.getBenAmount().doubleValue() < 0.00)
  9723.                 {
  9724.                     benefitBean.setWorkflowStatus(OHConstants.WFS_OH_BNFT_RECOVER);
  9725.                 }
  9726.  
  9727.                 benefitBean.setTotalContWage(injuryBean.getTotalConWage());
  9728.                 benefitBean.setWorkflowId(workflowId);
  9729.                 benefitBean.setCreatedBy(new Long(workflowParamBean.getUserId()));
  9730.                 benefitBean.setCreationTimestamp(currentTime);
  9731.                 if(OHConstants.OH_BNFT_PAY_TO_EMP.equals(benefitBean.getBenefitPayableTo()))
  9732.                 {
  9733.                     benefitBean.setPartyCode(injuryBean.getRegistrationNumber());
  9734.                 }else
  9735.                 {
  9736.                     benefitBean.setPartyCode(injuryBean.getSocialInsuranceNumber());
  9737.                 }
  9738.             }
  9739.  
  9740.             // checking if an autorized person is present
  9741.             // if mode is OH_BNFT_PAY_TO_AUTH_PERSON
  9742.             for(int i=0;i<benefitList.size();i++)
  9743.             {
  9744.                 OHAllowanceBean benefitBean=(OHAllowanceBean)benefitList.get(i);
  9745.                 if(OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals(benefitBean.getBenefitPayableTo()))
  9746.                 {
  9747.                     isAuthPersonPresent(benefitBean.getContributorId());
  9748.                     break;
  9749.                 }
  9750.             }
  9751.             // validating the contact details of the contributor
  9752.             validateContactDetails(contactList,benefitList);
  9753.  
  9754.             // check for overlapping misc benefits
  9755.             if(hasOverlappingMiscBenefits(benefitList))
  9756.             {
  9757.                 throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  9758.                                            GOSIConstants.SOCIAL_INSURANCE,
  9759.                                            this.getClass().toString(),
  9760.                                            "saveMiscOHAllowance()",
  9761.                                            new Exception ("Given benefit periods are overlapping"),
  9762.                                            "SOI_ERR_5653");
  9763.             }
  9764.             else
  9765.             {
  9766.                 ArrayList allMiscBenefits = new ArrayList ();
  9767.  
  9768.                 allMiscBenefits.addAll (benefitList);
  9769.                 allMiscBenefits.addAll (getMiscBenefitList (injuryBean.getInjuryID()));
  9770.  
  9771.                 if(hasOverlappingMiscBenefits(allMiscBenefits))
  9772.                 {
  9773.                     throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  9774.                                                GOSIConstants.SOCIAL_INSURANCE,
  9775.                                                this.getClass().toString(),
  9776.                                                "saveMiscOHAllowance()",
  9777.                                                new Exception ("Misc benefits for given period were already entered"),
  9778.                                                "SOI_ERR_5652");
  9779.                 }
  9780.             }
  9781.  
  9782.             //inserting benefit details into the T_ohbenefit table
  9783.             for(int i=0;i<benefitList.size();i++)
  9784.             {
  9785.                 OHAllowanceBean benefitBean=(OHAllowanceBean)benefitList.get(i);
  9786.                 OHAllowanceEntity remoteEntity=(OHAllowanceEntity)home.create(benefitBean);
  9787.                 GOSIDebug.debugMessages("After calling entity:" + remoteEntity);
  9788.             }
  9789.  
  9790.             HashMap updateRecoveryMap = updateRecovery(benefitList,workflowParamBean,injuryBean);  
  9791.             totalAmount = ((Double)updateRecoveryMap.get("totalAmount")).doubleValue();
  9792.             message = GOSIErrorMessages.getErrorDesc("SOI_ERR_5194");
  9793.             //calling the workflow interface
  9794.             if(totalAmount > 0 && workflowParamBean!=null)
  9795.             {
  9796.                 workflowParamBean.setPrimaryKeyOfTherecord(workflowId.toString());
  9797.                 String userName = GOSIUtilities.startWorkflow(workflowParamBean);
  9798.                 GOSIDebug.debugMessages("user :" + userName);
  9799.                     message = message + " "  + userName;
  9800.             }
  9801.  
  9802.             if(null != updateRecoveryMap.get("workFlowEmployer"))
  9803.             {              
  9804.                 message = message + " : " + (String)updateRecoveryMap.get("workFlowEmployer");
  9805.             }
  9806.             if(null != updateRecoveryMap.get("workFlowContributor"))
  9807.             {
  9808.                 message = message + " : " + (String)updateRecoveryMap.get("workFlowContributor");
  9809.             }
  9810.  
  9811.  
  9812.             // the DMS key values are set and the dms interface called
  9813.             if(headerBean != null)
  9814.             {
  9815.                 headerBean.setSourceRecordId
  9816.                 ("" + injuryBean.getInjuryID());
  9817.                 headerBean.
  9818.                 setSourceTable(SITables.T_INJURY);
  9819.                 headerBean.setCreatedBy
  9820.                 (new Long (workflowParamBean.getUserId()));
  9821.                 headerBean.setKeyList(DMSConstants.SI_NUMBER,
  9822.                 "" + injuryBean.getSocialInsuranceNumber());
  9823.                 headerBean.setKeyList(DMSConstants.REGISTRATION_NUMBER,
  9824.                 "" + injuryBean.getRegistrationNumber());
  9825.                 headerBean.setKeyList(DMSConstants.INJURY_NUMBER,
  9826.                 "" + injuryBean.getInjuryNumber());
  9827.                 DMSUtilities.startDMS(headerBean);
  9828.             }
  9829.  
  9830.  
  9831.             endTime = System.currentTimeMillis();
  9832.             elapsedTime = endTime - startTime;
  9833.             GOSIInstrumentationLog.writeInstrumentationToLog(
  9834.                 this.getClass().toString(),
  9835.                 "saveMiscOHAllowance()",
  9836.                 elapsedTime);
  9837.  
  9838.             return message;
  9839.         }
  9840.         catch(GOSIException gosiException)
  9841.         {
  9842.                 GOSIDebug.debugMessages("session:saveMiscOHAllowance:ge:message:" +
  9843.                         gosiException.getMessage());
  9844.                 ctx.setRollbackOnly();
  9845.                 throw gosiException;
  9846.         }
  9847.         catch(Exception e)
  9848.         {
  9849.             GOSIDebug.debugMessages("session:saveMiscOHAllowance: :The exception is "+e);
  9850.             ctx.setRollbackOnly();
  9851.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  9852.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  9853.                 "saveMiscOHAllowance()",e,"CMN_ERR_1000");
  9854.         }
  9855.  
  9856.     }
  9857.  
  9858.     /**
  9859.     * @METHOD NAME              :   hasOverlappingMiscBenefits
  9860.     * @INFORMATION              :   This method is to check for overlapping misc benefits
  9861.     * @PARAM                    :   class java.util.ArrayList
  9862.     * @RETURN                   :   void
  9863.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  9864.     * @LAST MODIFIED BY         :
  9865.     * @LAST MODIFIED DATE       :
  9866.     **/
  9867.     private boolean hasOverlappingMiscBenefits (ArrayList benefitList) throws GOSIException
  9868.     {
  9869.         boolean hasOverlappingMiscBenefits = false;
  9870.  
  9871.         try
  9872.         {
  9873.             main_loop:
  9874.             for (int i = 0; i < benefitList.size () - 1; i++)
  9875.             {
  9876.                 OHAllowanceBean miscBenefitBean = (OHAllowanceBean) benefitList.get (i);
  9877.  
  9878.                 if (OHConstants.OH_BNFT_STS_CANCELLED.equals(miscBenefitBean.getBenStatus()) || miscBenefitBean.getMode() == miscBenefitBean.DELETE_MODE)
  9879.                 {
  9880.                     continue;
  9881.                 }
  9882.  
  9883.                 for (int j = i + 1; j < benefitList.size (); j++)
  9884.                 {
  9885.                     OHAllowanceBean benefitBean = (OHAllowanceBean) benefitList.get (j);
  9886.  
  9887.                     if (OHConstants.OH_BNFT_STS_CANCELLED.equals(benefitBean.getBenStatus()) || benefitBean.getMode() == benefitBean.DELETE_MODE)
  9888.                     {
  9889.                         continue;
  9890.                     }
  9891.  
  9892.                     if (benefitBean.getInjuryId().equals(miscBenefitBean.getInjuryId()))
  9893.                     {
  9894.                         if (miscBenefitBean.getBenStDateGreg().after(benefitBean.getBenEndDateGreg()) ||
  9895.                             miscBenefitBean.getBenEndDateGreg().before(benefitBean.getBenStDateGreg()))
  9896.                         {
  9897.                             continue;
  9898.                         }
  9899.  
  9900.                         hasOverlappingMiscBenefits = true;
  9901.  
  9902.                         break main_loop;
  9903.                     }
  9904.                 }
  9905.             }
  9906.         }
  9907.         catch (Exception e)
  9908.         {
  9909.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  9910.                                        GOSIConstants.SOCIAL_INSURANCE,
  9911.                                        this.getClass().toString(),
  9912.                                        "hasOverlappingMiscBenefits ()",
  9913.                                        e,
  9914.                                        "CMN_ERR_1000");
  9915.         }
  9916.  
  9917.         return  hasOverlappingMiscBenefits;
  9918.     }
  9919.  
  9920.     /**
  9921.     * @METHOD NAME              :   getMiscBenefitList
  9922.     * @INFORMATION              :   This method is to get Misc Benefit List
  9923.     * @PARAM                    :   class java.lang.Long
  9924.     * @RETURN                   :   class java.util.ArrayList
  9925.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  9926.     * @LAST MODIFIED BY         :
  9927.     * @LAST MODIFIED DATE       :
  9928.     **/
  9929.     public ArrayList getMiscBenefitList (Long injuryId) throws GOSIException
  9930.     {
  9931.         ArrayList   miscBenefitList = new ArrayList ();
  9932.  
  9933.         PreparedStatement   ps  = null;
  9934.         ResultSet           rs  = null;
  9935.  
  9936.         try
  9937.         {
  9938.             con = GOSIUtilities.getConnection (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  9939.  
  9940.             String sqlQuery     = "SELECT ohbenid, injuryid, contributorid, fieldofficecode, ohbencode, "
  9941.                                 + "       ohbentype, benstdate, benstdateentfmt, benenddate, benenddateentfmt, "
  9942.                                 + "       benamount, benstatus, paymentmode, bankcode, bankaccnumber, "
  9943.                                 + "       datepayment, datepaymententfmt, workflowstatus, totalcontwage, "
  9944.                                 + "       workflowid, rejectioncode, payableto, partycode, description, "
  9945.                                 + "       createdby, creationtimestamp, lastmodifiedby, lastmodifiedtimestamp "
  9946.                                 + "  FROM " + SITables.T_OHBENEFIT
  9947.                                 + " WHERE ohbencode = ? AND benstatus <> ? AND injuryid = ?";
  9948.  
  9949.             ps = con.prepareStatement (sqlQuery);
  9950.  
  9951.             ps.setShort (1, OHConstants.OH_ALWNC_MISCELLANEOUS.shortValue ());
  9952.             ps.setShort (2, OHConstants.OH_BNFT_STS_CANCELLED.shortValue ());
  9953.             ps.setLong  (3, injuryId.longValue ());
  9954.  
  9955.             rs = ps.executeQuery ();
  9956.  
  9957.             while (rs.next())
  9958.             {
  9959.                 OHAllowanceBean benefitBean = new OHAllowanceBean ();
  9960.  
  9961.                 benefitBean.setOhBenId              (new Long(rs.getLong("OHBENID")));
  9962.                 benefitBean.setInjuryId             (new Long(rs.getLong("INJURYID")));
  9963.                 benefitBean.setContributorId        (new Long(rs.getLong("CONTRIBUTORID")));
  9964.                 benefitBean.setFieldofficeCode      (new Short(rs.getShort("FIELDOFFICECODE")));
  9965.                 benefitBean.setOhBenCode            (new Short(rs.getShort("OHBENCODE")));
  9966.                 benefitBean.setOhBenType            (rs.getString("OHBENTYPE"));
  9967.                 benefitBean.setBenStDateGreg        (rs.getTimestamp("BENSTDATE"));
  9968.                 benefitBean.setBenStDateEntFmt      (rs.getString("BENSTDATEENTFMT"));
  9969.                 benefitBean.setBenEndDateGreg       (rs.getTimestamp("BENENDDATE"));
  9970.                 benefitBean.setBenEndDateEntFmt     (rs.getString("BENENDDATEENTFMT"));
  9971.                 benefitBean.setBenAmount            (new Double(rs.getDouble("BENAMOUNT")));
  9972.                 benefitBean.setBenStatus            (new Short(rs.getShort("BENSTATUS")));
  9973.  
  9974.                 if (rs.getObject("PAYMENTMODE") != null)
  9975.                 {
  9976.                     benefitBean.setPaymentMode (new Short(rs.getShort("PAYMENTMODE")));
  9977.                 }
  9978.                 if (rs.getObject("BANKCODE") != null)
  9979.                 {
  9980.                     benefitBean.setBankCode (new Integer(rs.getInt("BANKCODE")));
  9981.                 }
  9982.                 if (rs.getObject("BANKACCNUMBER") != null)
  9983.                 {
  9984.                     benefitBean.setBankAccNumber (new Long(rs.getLong("BANKACCNUMBER")));
  9985.                 }
  9986.                 if (rs.getObject("DATEPAYMENT") != null)
  9987.                 {
  9988.                     benefitBean.setDatePaymentGreg   (rs.getTimestamp("DATEPAYMENT"));
  9989.                     benefitBean.setDatePaymentEntFmt (rs.getString("DATEPAYMENTENTFMT"));
  9990.                 }
  9991.  
  9992.                 benefitBean.setWorkflowStatus       (new Short(rs.getShort("WORKFLOWSTATUS")));
  9993.                 benefitBean.setTotalContWage        (new Double(rs.getDouble("TOTALCONTWAGE")));
  9994.  
  9995.                 if (rs.getObject("WORKFLOWID") != null)
  9996.                 {
  9997.                     benefitBean.setWorkflowId (new Long(rs.getLong("WORKFLOWID")));
  9998.                 }
  9999.                 if (rs.getObject("REJECTIONCODE") != null)
  10000.                 {
  10001.                     benefitBean.setRejectionCode (new Short(rs.getShort("REJECTIONCODE")));
  10002.                 }
  10003.                 if (rs.getObject("PARTYCODE") != null)
  10004.                 {
  10005.                     benefitBean.setPartyCode (new Long (rs.getLong("PARTYCODE")));
  10006.                 }
  10007.                 if (rs.getObject("PAYABLETO") != null)
  10008.                 {
  10009.                     benefitBean.setBenefitPayableTo (new Short (rs.getShort("PAYABLETO")));
  10010.                 }
  10011.                 if (rs.getObject("DESCRIPTION") != null)
  10012.                 {
  10013.                     benefitBean.setDescription (rs.getString("DESCRIPTION"));
  10014.                 }
  10015.  
  10016.                 benefitBean.setCreatedBy            (new Long(rs.getLong("CREATEDBY")));
  10017.                 benefitBean.setCreationTimestamp    (rs.getTimestamp("CREATIONTIMESTAMP"));
  10018.  
  10019.                 if (rs.getObject("LASTMODIFIEDBY") != null)
  10020.                 {
  10021.                     benefitBean.setLastModifiedBy        (new Long(rs.getLong("LASTMODIFIEDBY")));
  10022.                     benefitBean.setLastModifiedTimestamp (rs.getTimestamp("LASTMODIFIEDTIMESTAMP"));
  10023.                 }
  10024.  
  10025.                 /**
  10026.                  *  Add misc. benefit to the list
  10027.                  */
  10028.                 miscBenefitList.add (benefitBean);
  10029.             }
  10030.         }
  10031.         catch (GOSIException ge)
  10032.         {
  10033.             throw   ge;
  10034.         }
  10035.         catch (Exception e)
  10036.         {
  10037.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  10038.                                        GOSIConstants.SOCIAL_INSURANCE,
  10039.                                        this.getClass().toString(),
  10040.                                        "getMiscBenefitList ()",
  10041.                                        e,
  10042.                                        "CMN_ERR_1000");
  10043.         }
  10044.         finally
  10045.         {
  10046.             GOSIUtilities.cleanUp (con, ps, rs);
  10047.         }
  10048.  
  10049.         return  miscBenefitList;
  10050.     }
  10051.  
  10052.     /**
  10053.     * @METHOD NAME         :   updateRecovery
  10054.     * @INFORMATION         :   This method is to  update Recovery
  10055.     * @PARAM               :   class java.util.ArrayList,
  10056.                                class gosi.core.workflow.beans.WorkflowParamBean,
  10057.                                class gosi.business.socialinsurance.occupationalhazards.injury.beans.InjuryBean
  10058.     * @RETURN              :   class java.util.HashMap
  10059.     * @EXCEPTION           :   class gosi.core.util.GOSIException
  10060.     * @LAST MODIFIED BY    :
  10061.     * @LAST MODIFIED DATE  :
  10062.     **/
  10063.     private HashMap updateRecovery(ArrayList benefitList,
  10064.             WorkflowParamBean workflowParamBean,
  10065.             InjuryPopDetails injuryBean) throws GOSIException
  10066.     {
  10067.         double totalAmount = 0.00;
  10068.         String workFlowEmployer = null;
  10069.         String workFlowContributor = null;
  10070.         HashMap updateRecoveryMap = new HashMap();
  10071.  
  10072.         try
  10073.         {
  10074.             for(int i=0; i < benefitList.size(); i++)
  10075.             {
  10076.                 OHAllowanceBean benefitBean = (OHAllowanceBean) benefitList.get(i);
  10077.                 totalAmount += benefitBean.getBenAmount().doubleValue();
  10078.             }
  10079.             if(totalAmount < 0)
  10080.             {
  10081.                 ArrayList recEmpList = new ArrayList();
  10082.                 ArrayList recConList = new ArrayList();
  10083.                 double recEmpAmount = 0.00;
  10084.                 double recConAmount = 0.00;
  10085.                 for(int i=0;i<benefitList.size();i++)
  10086.                 {
  10087.                     OHAllowanceBean benefitBean = (OHAllowanceBean)benefitList.get(i);
  10088.                     if(OHConstants.OH_BNFT_PAY_TO_CON.equals(benefitBean.getBenefitPayableTo()) ||
  10089.                        OHConstants.OH_BNFT_PAY_TO_AUTH_PERSON.equals(benefitBean.getBenefitPayableTo()))
  10090.                     {
  10091.                         recConList.add(benefitBean);
  10092.                         recConAmount += benefitBean.getBenAmount().doubleValue();
  10093.                     }
  10094.                     else if(OHConstants.OH_BNFT_PAY_TO_EMP.equals(benefitBean.getBenefitPayableTo()))
  10095.                     {
  10096.                         recEmpList.add(benefitBean);
  10097.                         recEmpAmount += benefitBean.getBenAmount().doubleValue();
  10098.                     }
  10099.                 }
  10100.                 if(recEmpList.size() > 0 && recEmpAmount < 0 )
  10101.                 {
  10102.                     Long recEmpWorkflowId = GOSIUtilities.getPrimaryKey("RECFROMEMPWORKFLOWID",new Long (workflowParamBean.getUserId()));
  10103.                     Long recInjuryId = null;
  10104.                     ArrayList recoverFromEmployerList = new ArrayList();
  10105.                     for (int i=0;i<recEmpList.size();i++)
  10106.                     {
  10107.                         OHAllowanceBean benefitBean = (OHAllowanceBean)recEmpList.get(i);
  10108.                         RecEmployerBean recEmpBean = new RecEmployerBean();
  10109.                         recEmpBean.setRecID(GOSIUtilities.getPrimaryKey("T_RECFROMEMP",new Long (workflowParamBean.getUserId())));
  10110.                         recEmpBean.setOhBenID(benefitBean.getOhBenId());
  10111.                         recEmpBean.setWorkFlowID(recEmpWorkflowId);
  10112.                         recEmpBean.setEstablishmentID(injuryBean.getEstablishmentId());
  10113.  
  10114.                         if(benefitBean.getBenAmount()!=null)
  10115.                         {
  10116.                             recEmpBean.setAmountDue(new Double(Math.abs(benefitBean.getBenAmount().doubleValue())));
  10117.                         }else
  10118.                         {
  10119.                                recEmpBean.setAmountDue(new Double("0"));
  10120.                         }
  10121.                         recEmpBean.setAmountReceived(new Double("0"));
  10122.                         recEmpBean.setStatus(OHConstants.REC_FROM_EMP_ENTERED);
  10123.                         recEmpBean.setRequestDate(new Timestamp(System.currentTimeMillis()));
  10124.                         recEmpBean.setRequestDateEntFmt(OHConstants.GREGORIAN);
  10125.                         recEmpBean.setWorkflowStatus(OHConstants.REC_FROM_EMP_CLERK_ENT);
  10126.                         recEmpBean.setCreatedBy(new Long(workflowParamBean.getUserId()));
  10127.                         recEmpBean.setRecoveryType(OHConstants.RECOVERY_TYPE_OH_BENEFIT);
  10128.                         recEmpBean.setInjuryId(benefitBean.getInjuryId());
  10129.                         recInjuryId = benefitBean.getInjuryId();
  10130.                         recEmpBean.setCreationTimestamp(new Timestamp(System.currentTimeMillis()));
  10131.                         recEmpBean.setLocationCode(workflowParamBean.getUserLocationId());
  10132.                         recoverFromEmployerList.add(recEmpBean);
  10133.                     }
  10134.                     createRecFromEmp(recoverFromEmployerList);
  10135.                     workflowParamBean.setPrimaryKeyOfTherecord(recEmpWorkflowId.toString() + "~" + recInjuryId.toString());
  10136.                     workflowParamBean.setModuleId(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  10137.                     workflowParamBean.setStepShortName("REC_FROM_EMPLOYER");
  10138.                     workflowParamBean.setrecordDescription(GOSIErrorMessages.getErrorDesc("SOI_ERR_4360") + " - " + injuryBean.getRegistrationNumber());
  10139.                     workflowParamBean.setRoutingCriterion(GOSIConstants.COMPLETED);
  10140.                     workFlowEmployer = GOSIUtilities.startWorkflow(workflowParamBean);
  10141.                 }
  10142.  
  10143.                 if (recConList.size() > 0 && recConAmount < 0)
  10144.                 {
  10145.                     Long recInjuryId = null;
  10146.                     Long recConWorkflowId = GOSIUtilities.getPrimaryKey("RECFROMCONWORKFLOWID",new Long (workflowParamBean.getUserId()));
  10147.                     ArrayList recoverContributorList = new ArrayList();
  10148.  
  10149.                     for(int i=0; i<recConList.size(); i++)
  10150.                     {
  10151.                         OHAllowanceBean benefitBean = (OHAllowanceBean)recConList.get(i);
  10152.                         RecFromContributorHeaderBean recConBean = new RecFromContributorHeaderBean();
  10153.                         recConBean.setOHBenID(benefitBean.getOhBenId());
  10154.                         recConBean.setWorkFlowID(recConWorkflowId);
  10155.                         recConBean.setRecID(GOSIUtilities.getPrimaryKey("T_RECFROMCONTRIBUTOR",new Long (workflowParamBean.getUserId())));
  10156.                         if(benefitBean.getBenAmount()!=null)
  10157.                         {
  10158.                             recConBean.setAmountReceived(new Double(Math.abs(benefitBean.getBenAmount().doubleValue())));
  10159.                         }else
  10160.                         {
  10161.                                recConBean.setAmountReceived(new Double("0"));
  10162.                         }
  10163.                         recConBean.setFromDateGreg(benefitBean.getBenStDateGreg());
  10164.                         recConBean.setFromDateEntFmt(OHConstants.GREGORIAN);
  10165.                         recConBean.setToDateGreg(benefitBean.getBenEndDateGreg());
  10166.                         recConBean.setToDateEntFmt(OHConstants.GREGORIAN);
  10167.                         recConBean.setRequestDate(new Timestamp(System.currentTimeMillis()));
  10168.                         recConBean.setRequestDateEntFmt(OHConstants.GREGORIAN);
  10169.                         recConBean.setWorkflowStatus(OHConstants.REC_FROM_CON_CLERK_ENT);
  10170.                         recConBean.setCreatedBy(new Long(workflowParamBean.getUserId()));
  10171.                         recInjuryId = benefitBean.getInjuryId();
  10172.                         recConBean.setCreationTimestamp(new Timestamp(System.currentTimeMillis()));
  10173.                         recoverContributorList.add(recConBean);
  10174.                     }
  10175.                     createRecFromCon(recoverContributorList);
  10176.                     workflowParamBean.setPrimaryKeyOfTherecord(recConWorkflowId.toString());
  10177.                     workflowParamBean.setModuleId(GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  10178.                     workflowParamBean.setStepShortName("REC_FROM_CONTRIBUTOR");
  10179.                     workflowParamBean.setrecordDescription(GOSIErrorMessages.getErrorDesc("SOI_ERR_4701") + " - " + injuryBean.getSocialInsuranceNumber());
  10180.                     workflowParamBean.setRoutingCriterion(GOSIConstants.COMPLETED);
  10181.                     workFlowContributor = GOSIUtilities.startWorkflow(workflowParamBean);
  10182.                 }
  10183.             }
  10184.  
  10185.             updateRecoveryMap.put("totalAmount",new Double(totalAmount));
  10186.             updateRecoveryMap.put("workFlowEmployer",workFlowEmployer);
  10187.             updateRecoveryMap.put("workFlowContributor",workFlowContributor);
  10188.            
  10189.         }
  10190.         catch (GOSIException ge)
  10191.         {
  10192.             GOSIDebug.debugMessages("session:updateRecovery:ge:"+ge);
  10193.             throw ge;
  10194.         }
  10195.         catch(Exception e)
  10196.         {
  10197.             GOSIDebug.debugMessages("session:updateRecovery:e:"+e);
  10198.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  10199.                                         GOSIConstants.SOCIAL_INSURANCE,
  10200.                                         this.getClass().toString(),
  10201.                                         "updateRecovery()",e,
  10202.                                         "CMN_ERR_1000");
  10203.         }
  10204.         return updateRecoveryMap;
  10205.     }
  10206.  
  10207.     /**
  10208.     * @METHOD NAME         :   getContributorIdList
  10209.     * @INFORMATION         :   This method is to  get the contributor list using
  10210.                                mergedSocialInsuranceNumber 
  10211.     * @PARAM               :   class java.lang.Long
  10212.     * @RETURN              :   class java.util.ArrayList
  10213.     * @EXCEPTION           :   class gosi.core.util.GOSIException
  10214.     * @LAST MODIFIED BY    :
  10215.     * @LAST MODIFIED DATE  :
  10216.     **/
  10217.     private ArrayList getContributorIdList(Long mergedSocialInsuranceNumber)
  10218.         throws GOSIException
  10219.     {      
  10220.         ArrayList contributorIdList = new ArrayList();
  10221.         ResultSet rsContributorList = null;
  10222.         PreparedStatement psContributorList = null;
  10223.         StringBuffer sqlQuery = new StringBuffer();
  10224.         Connection conContributorList = null;
  10225.        
  10226.         GOSIDebug.debugMessages("Start getContributorIdList - MaintainOHAllowanceSessionEJB");     
  10227.         try
  10228.         {
  10229.             /*
  10230.              * Get the list of contributorid from T_CONTRIBUTOR with
  10231.              * mergedsocialinsurancenumber and store it in the list.
  10232.              */
  10233.             sqlQuery.append("SELECT");
  10234.                 sqlQuery.append(" CONTRIBUTORID");
  10235.             sqlQuery.append(" FROM ");
  10236.                 sqlQuery.append(SITables.T_CONTRIBUTOR);
  10237.             sqlQuery.append(" WHERE ");
  10238.                 sqlQuery.append("MERGEDSOCIALINSURANCENUMBER = ? ");
  10239.            
  10240.             GOSIDebug.debugMessages("SqlQuery :" + sqlQuery.toString() + ":");
  10241.             GOSIDebug.debugMessages("\t\t Param 1 :" +
  10242.                     mergedSocialInsuranceNumber.longValue() + ":");
  10243.            
  10244.             conContributorList = GOSIUtilities.getConnection(
  10245.                     GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  10246.             psContributorList = con.prepareStatement(sqlQuery.toString());
  10247.             psContributorList.setLong(1,mergedSocialInsuranceNumber.longValue());
  10248.             GOSIDebug.debugMessages("Start Time:" + System.currentTimeMillis());
  10249.             rsContributorList = psContributorList.executeQuery();
  10250.             GOSIDebug.debugMessages("End Time:" + System.currentTimeMillis());
  10251.             while(rsContributorList.next())
  10252.             {              
  10253.                 contributorIdList.add(new Long(
  10254.                         rsContributorList.getLong("CONTRIBUTORID")));
  10255.                 GOSIDebug.debugMessages("Contributorid :" +
  10256.                         rsContributorList.getString("CONTRIBUTORID") + ":");
  10257.             }
  10258.         }
  10259.         catch(GOSIException ge)
  10260.         {
  10261.             GOSIDebug.debugMessages("Error Getting ContributorList :" +
  10262.                     ge.getMessage() + ":");
  10263.             throw ge;
  10264.         }
  10265.         catch(Exception e)
  10266.         {
  10267.             GOSIDebug.debugMessages("Error Getting ContributorList :" +
  10268.                     e.getMessage() + ":");
  10269.             throw new GOSIException( GOSIConstants.SEVERITY_ONE,
  10270.                     GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  10271.                     "getContributorIdList()",e,"CMN_ERR_1000");        
  10272.         }
  10273.         finally
  10274.         {
  10275.             GOSIUtilities.cleanUp(conContributorList,psContributorList,
  10276.                     rsContributorList);
  10277.         }
  10278.         GOSIDebug.debugMessages("End getContributorIdList - MaintainOHAllowanceSessionEJB");
  10279.         return contributorIdList;      
  10280.     }
  10281.  
  10282.     /**
  10283.     * @METHOD NAME         :   distributeWageToEstablishments
  10284.     * @INFORMATION         :   This method is to  distribute the wage to establishment
  10285.                                and to the contributor based on the wagestop date.  
  10286.     * @PARAM               :   class java.lang.Long
  10287.     * @RETURN              :   class java.util.ArrayList
  10288.     * @EXCEPTION           :   class gosi.core.util.GOSIException
  10289.     * @LAST MODIFIED BY    :
  10290.     * @LAST MODIFIED DATE  :
  10291.     **/
  10292.     private ArrayList distributeWageToEstablishments(ArrayList benefitList,
  10293.                 ArrayList injuryList) throws GOSIException
  10294.     {      
  10295.         GOSIDebug.debugMessages("\t\t Start distributeWageToEstablisments - MaintainOHAllowanceSessionEJB");
  10296.         ArrayList benList = new ArrayList();
  10297.         Timestamp wageStopDate = null;
  10298.         Double totalConWage = null;
  10299.  
  10300.         InjuryPopDetails injuryDetails = (InjuryPopDetails)injuryList.get(0);
  10301.         wageStopDate = injuryDetails.getWageStopDate();
  10302.         totalConWage = injuryDetails.getTotalConWage();
  10303.         GOSIDebug.debugMessages("WageStopDate:" + wageStopDate + ":");
  10304.         GOSIDebug.debugMessages("TotalContWage:" + totalConWage + ":");
  10305.         GOSIDebug.debugMessages("Initial BenefitListSize:" + benefitList.size() + ":");
  10306.        
  10307.         if(wageStopDate != null && !totalConWage.equals(injuryDetails.getInjuredEstablishmentWage()))
  10308.         {
  10309.             Double benefitAmount = null;
  10310.             GOSIDebug.debugMessages("Wage Stop date is Not Null");
  10311.             for(int i =0;i<benefitList.size();i++)
  10312.             {
  10313.                 OHAllowanceBean benefitBean = (OHAllowanceBean)benefitList.get(i);
  10314.                 if(OHConstants.OH_BNFT_PAY_TO_EMP.equals(benefitBean.getBenefitPayableTo()))
  10315.                 {
  10316.                     OHAllowanceBean newBenefitBean = new OHAllowanceBean(benefitBean);
  10317.                     newBenefitBean.setBenefitPayableTo(OHConstants.OH_BNFT_PAY_TO_CON);
  10318.                     double localBenefitAmount = (injuryDetails.getInjuredEstablishmentWage().doubleValue() / totalConWage.doubleValue()) * benefitBean.getBenAmount().doubleValue();
  10319.                     benefitAmount = new Double(localBenefitAmount);
  10320.                     GOSIDebug.debugMessages("SplitedBenefitAmount :" + benefitAmount + ":");                                           
  10321.                     newBenefitBean.setBenAmount(new Double(benefitBean.getBenAmount().doubleValue() - benefitAmount.doubleValue()));
  10322.                     benefitBean.setBenAmount(benefitAmount);               
  10323.                     benList.add(newBenefitBean);                       
  10324.                 }
  10325.                 benList.add(benefitBean);
  10326.             }              
  10327.         }
  10328.         else
  10329.         {
  10330.             GOSIDebug.debugMessages("InjuredEstablishmentWage      :"+ injuryDetails.getInjuredEstablishmentWage() +":");
  10331.             GOSIDebug.debugMessages("InjuredEstablishmentPayableTo :"+ injuryDetails.getInjuredEstablishmentBenefitPayableTo() +":");          
  10332.             if(!totalConWage.equals(injuryDetails.getInjuredEstablishmentWage())
  10333.                     && OHConstants.OH_BNFT_PAY_TO_EMP.equals(
  10334.                         injuryDetails.getInjuredEstablishmentBenefitPayableTo()))
  10335.             {
  10336.                 Double benefitAmount = null;
  10337.                 //Split the benefit amount into two.
  10338.                 /*Change the benefitbean's and new benefitBean's amount based on the total
  10339.                 amount calculation
  10340.                 */
  10341.                 //Payment Calculation to the InjuredEstablishment.
  10342.                 for(int i =0;i<benefitList.size();i++)
  10343.                 {
  10344.                     OHAllowanceBean benefitBean = (OHAllowanceBean)benefitList.get(i);
  10345.                     OHAllowanceBean newBenefitBean = new OHAllowanceBean(benefitBean);
  10346.                     if(OHConstants.OH_ALWNC_DAIlY_INPATIENT.equals(benefitBean.getOhBenCode())
  10347.                         || OHConstants.OH_ALWNC_DAIlY_OUTPATIENT.equals(benefitBean.getOhBenCode()))
  10348.                     {
  10349.                         newBenefitBean.setBenefitPayableTo(OHConstants.OH_BNFT_PAY_TO_EMP);
  10350.                         double localBenefitAmount = (injuryDetails.getInjuredEstablishmentWage().doubleValue() / totalConWage.doubleValue()) * benefitBean.getBenAmount().doubleValue();
  10351.                         benefitAmount = new Double(localBenefitAmount);
  10352.                         GOSIDebug.debugMessages("SplitedBenefitAmount :" + benefitAmount + ":");
  10353.                                        
  10354.                     newBenefitBean.setBenAmount(benefitAmount);
  10355.                     benefitBean.setBenAmount(new Double(benefitBean.getBenAmount().doubleValue() - benefitAmount.doubleValue()));              
  10356.                     benList.add(newBenefitBean);
  10357.                     }
  10358.                     benList.add(benefitBean);
  10359.                 }
  10360.             }
  10361.             else
  10362.             {
  10363.                 benList = benefitList;
  10364.             }
  10365.         }
  10366.         GOSIDebug.debugMessages("=========Final BenefitList Size:" + benList.size() + ":");
  10367.         GOSIDebug.debugMessages("\t\t End distributeWageToEstablisments - MaintainOHAllowanceSessionEJB");
  10368.         return benList;
  10369.     }
  10370.  
  10371.     private Timestamp getWageStopDate(Long injuryid) throws GOSIException
  10372.     {
  10373.         PreparedStatement ps = null;
  10374.         ResultSet rs = null;
  10375.         StringBuffer sqlQuery = new StringBuffer();
  10376.         Timestamp wageStopDate = null;
  10377.         GOSIDebug.debugMessages("\t\t Start getWageStopDate - MaintainOHAllowanceSessionEJB");
  10378.         try
  10379.         {
  10380.             sqlQuery.append("SELECT WAGESTOPDATE FROM T_INJURY WHERE INJURYID = ?");
  10381.  
  10382.             GOSIDebug.debugMessages("SqlQuery:" + sqlQuery.toString()  + ":");
  10383.             GOSIDebug.debugMessages("\t\t Param 1 :" + injuryid.longValue() + ":");
  10384.             ps = con.prepareStatement(sqlQuery.toString());
  10385.             ps.setLong(1,injuryid.longValue());
  10386.             rs = ps.executeQuery();
  10387.             if(rs.next())
  10388.             {              
  10389.                 wageStopDate = rs.getTimestamp("WAGESTOPDATE");            
  10390.                 wageStopDate = GOSIUtilities.getRequiredDate(wageStopDate,-1);             
  10391.                 GOSIDebug.debugMessages("Wage StopDate:" + wageStopDate + ":");
  10392.                 // this is to make sure that the establishment will be
  10393.                 // paid till the last wage paid date.
  10394.             }
  10395.         }
  10396.         catch(GOSIException ge)
  10397.         {
  10398.             GOSIDebug.debugMessages("Session:getWageStopDate :" + ge);
  10399.             throw ge;
  10400.         }
  10401.         catch(Exception e)
  10402.         {
  10403.             GOSIDebug.debugMessages("Session:getWageStopDate :" + e);
  10404.             throw new GOSIException( GOSIConstants.SEVERITY_TWO,
  10405.                 GOSIConstants.SOCIAL_INSURANCE,this.getClass().toString(),
  10406.                 "getWageStopDate()",e,"CMN_ERR_1000");
  10407.         }
  10408.         finally
  10409.         {
  10410.             GOSIUtilities.cleanUp(ps,rs);
  10411.         }
  10412.         GOSIDebug.debugMessages("\t\t End getWageStopDate - MaintainOHAllowanceSessionEJB");
  10413.         return wageStopDate;
  10414.     }  
  10415.  
  10416.     /**
  10417.     * @METHOD NAME              :   getCancellationReasonForReturnedBenefitCheque
  10418.     * @INFORMATION              :   This method will invoke service from finance to get the cancellation details.
  10419.     * @PARAM                    :   long
  10420.     * @RETURN                   :   java.lang.Integer
  10421.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  10422.     * @LAST MODIFIED BY         :  
  10423.     * @LAST MODIFIED DATE       :  
  10424.     **/
  10425.     public Integer getCancellationReasonForReturnedBenefitCheque (long journalHeaderId)
  10426.             throws GOSIException
  10427.     {
  10428.         /* Invoke service from finance to get additional information about the status of the
  10429.          * returned check recipient */
  10430.         try
  10431.         {
  10432.             HashMap interfaceInputMap = new HashMap ();
  10433.             interfaceInputMap.put (FAInterfaceConstants.METHOD_DESCRIPTION, FAInterfaceConstants.CHEQUE_RETURN_INTERFACE);
  10434.             interfaceInputMap.put (FAInterfaceConstants.MODULE_ID, new Short (GOSIConstants.OCCUPATIONAL_HAZARDS_ID));
  10435.             interfaceInputMap.put ("CN_DN_RecordId", new Long (journalHeaderId));
  10436.  
  10437.             FinancialAccountingInterface faInterface;
  10438.             faInterface = FinanceImplProxy.getFAInterface ();
  10439.  
  10440.             interfaceInputMap = faInterface.invokeService (interfaceInputMap);
  10441.  
  10442.             GOSIDebug.debugMessages("chequeCancellationCode " + interfaceInputMap.get ("CancellationCode"));
  10443.             GOSIDebug.debugMessages("chequeCancelCodeDesc " + interfaceInputMap.get ("CancelCodeDesc"));
  10444.  
  10445.             /**
  10446.              *  Service method will return the cancellation reason as an Integer value, below is the description matrix
  10447.              *
  10448.              *  Cancellation Reason Code                                    |   Cancellation Reason Description
  10449.              *  ----------------------------------------------------------- | ---------------------------------------------------------------
  10450.              *  FAInterfaceConstants.CHEQUE_NOT_CANCELLED                   |   Cheque is returned but not yet canceled in finance
  10451.              *  FAInterfaceConstants.OVER_SIX_MONTHS                        |   Cheque has not been cashed for over six months
  10452.              *  FAInterfaceConstants.DAMAGED_CHEQUE_BENEFICIARY_REQUEST     |   Cheque is in the incorrect amt/name or it was lost or damaged
  10453.              *  FAInterfaceConstants.BENEFICIARY_LEFT_SA                    |   Cheque canceled. Beneficiary residing overseas
  10454.              *  FAInterfaceConstants.BENEFICIARY_NOT_ALIVE                  |   The beneficiary is no longer alive
  10455.              *  FAInterfaceConstants.CANCEL_REASON_OTHERS                   |   Cancellation reason not indicated
  10456.              */
  10457.             String cancellationCodeStr = (String) interfaceInputMap.get ("CancellationCode");
  10458.  
  10459.             if (cancellationCodeStr == null ||
  10460.                 Integer.valueOf(cancellationCodeStr).intValue () == 0)
  10461.             {
  10462.                 return  FAInterfaceConstants.CHEQUE_NOT_CANCELLED;      // For compatibility
  10463.             }
  10464.            
  10465.             return  Integer.valueOf(cancellationCodeStr);
  10466.         }
  10467.         catch (GOSIException ge)
  10468.         {
  10469.             GOSIDebug.debugMessages ("Invoking finance service failed ! Could not determine cheque status.");
  10470.             throw ge;
  10471.         }
  10472.         catch (Exception e)
  10473.         {
  10474.             GOSIDebug.debugMessages ("Session:getCancellationReasonForReturnedBenefitCheque :" + e);
  10475.  
  10476.             throw new GOSIException (GOSIConstants.SEVERITY_TWO,
  10477.                                      GOSIConstants.SOCIAL_INSURANCE,
  10478.                                      this.getClass ().toString (),
  10479.                                      "getCancellationReasonForReturnedBenefitCheque ()",
  10480.                                      e,
  10481.                                      "CMN_ERR_1000");
  10482.         }
  10483.     }
  10484.  
  10485.     /**
  10486.     * @METHOD NAME              :   getEstablishmentID
  10487.     * @INFORMATION              :   This method is to take injuryid and returns establishmentID
  10488.     * @PARAM                    :   class java.lang.Double,
  10489.                                     class java.sql.Timestamp,
  10490.                                     class java.lang.Long,
  10491.                                     class java.lang.Long,
  10492.                                     boolean,
  10493.                                     class gosi.core.workflow.beans.WorkflowParamBean
  10494.     * @RETURN                   :   void
  10495.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  10496.     * @LAST MODIFIED BY         :
  10497.     * @LAST MODIFIED DATE       :
  10498.     **/
  10499.     Long getEstablishmentID(Long injuryId)
  10500.     throws GOSIException
  10501.     {
  10502.         Long    establishmentId = null;
  10503.  
  10504.         PreparedStatement   ps  = null;
  10505.         ResultSet           rs  = null;
  10506.  
  10507.         try
  10508.         {
  10509.             /* Get connection handler */
  10510.             con = GOSIUtilities.getConnection (GOSIConstants.OCCUPATIONAL_HAZARDS_ID);
  10511.  
  10512.             /* Compile SQL statement object */
  10513.             ps  = con.prepareStatement ("SELECT ESTABLISHMENTID FROM " + SITables.T_INJURY + "WHERE INJURYID=?");
  10514.             ps.setLong (1, injuryId.longValue ());
  10515.  
  10516.             /* Execute query, and download the result set */
  10517.             rs  = ps.executeQuery ();
  10518.  
  10519.             if (rs.next ())
  10520.             {
  10521.                 establishmentId = (new Long (rs.getLong ("ESTABLISHMENTID")));
  10522.             }
  10523.         }
  10524.         catch (GOSIException ge)
  10525.         {
  10526.             GOSIDebug.debugMessages ("Session:getEstablishmentID :" + ge);
  10527.             throw ge;
  10528.         }
  10529.         catch (Exception e)
  10530.         {
  10531.             GOSIDebug.debugMessages ("Session:getEstablishmentID :" + e);
  10532.  
  10533.             throw   new GOSIException   (GOSIConstants.SEVERITY_TWO,
  10534.                                          GOSIConstants.SOCIAL_INSURANCE,
  10535.                                          this.getClass().toString(),
  10536.                                          "getEstablishmentID()",
  10537.                                          e,
  10538.                                          "CMN_ERR_1000");
  10539.         }
  10540.         finally
  10541.         {
  10542.             GOSIUtilities.cleanUp (ps, rs);
  10543.         }
  10544.  
  10545.         return establishmentId;
  10546.     }
  10547.     /**
  10548.     * @METHOD NAME              :   getOHBenefitIdList
  10549.     * @INFORMATION              :   This method is to get OH Benefit Id List
  10550.     * @PARAM                    :   class java.util.ArrayList
  10551.     * @RETURN                   :   class java.util.ArrayList
  10552.     * @EXCEPTION                :   class gosi.core.util.GOSIException
  10553.     * @LAST MODIFIED BY         :
  10554.     * @LAST MODIFIED DATE       :
  10555.     **/
  10556.     private ArrayList getOHBenefitIdList (ArrayList journalHeaderIdList) throws GOSIException
  10557.     {
  10558.         ArrayList   OHBenefitIdList = new ArrayList ();
  10559.  
  10560.         PreparedStatement   ps  = null;
  10561.         ResultSet           rs  = null;
  10562.  
  10563.         try
  10564.         {
  10565.             String subQuery = "";
  10566.             int journalHeaderIdListSize =journalHeaderIdList.size();
  10567.            
  10568.             for(int i=0;i<journalHeaderIdListSize;i++)
  10569.             {
  10570.                 if(i==0)
  10571.                 {
  10572.                  subQuery = " ? ";
  10573.                 }
  10574.                 else
  10575.                 {
  10576.                 subQuery = subQuery + " ,? ";
  10577.                 }
  10578.             }
  10579.            
  10580.             String sqlQuery     = " SELECT OHBENID, JOURNALHEADERID "
  10581.                                 + "  FROM " + SITables.T_OHBENEFIT
  10582.                                 + " WHERE JOURNALHEADERID in ( " + subQuery + " ) ";
  10583.  
  10584.             ps = con.prepareStatement (sqlQuery);
  10585.  
  10586.             for(int i=0;i<journalHeaderIdListSize;i++)
  10587.             {
  10588.                 Long journalHeaderId =  (Long) journalHeaderIdList.get(i);
  10589.                 ps.setLong(i+1,journalHeaderId.longValue());
  10590.                 GOSIDebug.debugMessages("\t\t Param " + (i+1) + ":" + journalHeaderId.longValue() + ":");
  10591.             }
  10592.             rs = ps.executeQuery ();
  10593.            
  10594.             while (rs.next())
  10595.             {
  10596.                 OHAllowanceBean benefitBean = new OHAllowanceBean ();
  10597.                
  10598.                 if (rs.getObject("OHBENID") != null)
  10599.                 {
  10600.                     benefitBean.setOhBenId(new Long(rs.getLong("OHBENID")));
  10601.                 }
  10602.                 if (rs.getObject("JOURNALHEADERID") != null)
  10603.                 {
  10604.                     benefitBean.setJournalHeaderId(new Long(rs.getLong("JOURNALHEADERID")));
  10605.                 }
  10606.                
  10607.                 OHBenefitIdList.add (benefitBean);
  10608.             }
  10609.         }
  10610.         catch (Exception e)
  10611.         {
  10612.             throw   new GOSIException (GOSIConstants.SEVERITY_ONE,
  10613.                                        GOSIConstants.SOCIAL_INSURANCE,
  10614.                                        this.getClass().toString(),
  10615.                                        "getOHBenefitIdList ()",
  10616.                                        e,
  10617.                                        "CMN_ERR_1000");
  10618.         }
  10619.         finally
  10620.         {
  10621.             GOSIUtilities.cleanUp (ps, rs);
  10622.         }
  10623.  
  10624.         return  OHBenefitIdList;
  10625.     }
  10626. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement