gt: 		recordObj = getBillingRecordObj(ch1Id);
context: /**
   * Copyright (c) 2006-. OSCARservice, OpenSoft System. All Rights Reserved.
   * This software is published under the GPL GNU General Public License.
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version 2
   * of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   */
  package oscar.oscarBilling.ca.on.pageUtil;
  
  import java.math.BigDecimal;
  import java.util.List;
  import java.util.Properties;
  import java.util.Vector;
  
  import javax.servlet.http.HttpServletRequest;
  
  import org.apache.log4j.Logger;
  import org.oscarehr.util.MiscUtils;
  
  import oscar.oscarBilling.ca.on.data.BillingClaimHeader1Data;
  import oscar.oscarBilling.ca.on.data.BillingDataHlp;
  import oscar.oscarBilling.ca.on.data.BillingItemData;
  import oscar.oscarBilling.ca.on.data.BillingProviderData;
  import oscar.oscarBilling.ca.on.data.JdbcBilling3rdPartImpl;
  import oscar.oscarBilling.ca.on.data.JdbcBillingClaimImpl;
  import oscar.oscarBilling.ca.on.data.JdbcBillingCodeImpl;
  import oscar.oscarBilling.ca.on.data.JdbcBillingCorrection;
  import oscar.oscarBilling.ca.on.data.JdbcBillingPageUtil;
  import oscar.oscarBilling.ca.on.data.JdbcBillingReviewImpl;
  import oscar.util.StringUtils;
  
  public class BillingCorrectionPrep {
  	private static final Logger _logger = Logger
  			.getLogger(BillingCorrectionPrep.class);
  
  	JdbcBillingCorrection dbObj = new JdbcBillingCorrection();
  
  	// 
  	public List getBillingRecordObj(String id) {
  		List ret = dbObj.getBillingRecordObj(id);
  		return ret;
  	}
  
  	// get error code
  	public List getBillingExplanatoryList(String id) {
  		List ret = dbObj.getBillingExplanatoryList(id);
  		return ret;
  	}
  
  	// get rejected code
  	public List getBillingRejectList(String id) {
  		List ret = dbObj.getBillingRejectList(id);
  		return ret;
  	}
  
  	// compare the obj first, push old record to repo if needed.
  	public boolean updateBillingClaimHeader(BillingClaimHeader1Data ch1Obj,
  			HttpServletRequest requestData) {
  		boolean ret = true;
                  String status;
  		if (isChangedBillingClaimHeader(ch1Obj, requestData)) {
  			int i = dbObj.addRepoClaimHeader(ch1Obj);
  			_logger.info("updateBillingClaimHeader(old value = " + i
  					+ ch1Obj.getStatus() + "|" + ch1Obj.getRef_num() + "|"
  					+ ch1Obj.getAdmission_date() + "|"
  					+ ch1Obj.getFacilty_num() + "|" + ch1Obj.getMan_review()
  					+ "|" + ch1Obj.getBilling_date() + "|"
  					+ ch1Obj.getProviderNo() + "|" + ch1Obj.getCreator());
                          
                          status = requestData.getParameter("status").substring(0,1);
                          if( status.equals("S") && !ch1Obj.getStatus().equals(status)) {
                              this.updateExt("payDate", requestData);
                          }
  			ch1Obj.setStatus(status);
  			
  			ch1Obj.setPay_program(requestData.getParameter("payProgram"));
  			if(requestData.getParameter("status").substring(0,1).equals("N")){
  				ch1Obj.setPay_program("NOT");				
  			}
  						
  			ch1Obj.setRef_num(requestData.getParameter("rdohip"));
  			ch1Obj.setVisittype(requestData.getParameter("visittype"));
  
  			ch1Obj.setAdmission_date(requestData.getParameter("xml_vdate"));
  			ch1Obj.setFacilty_num(requestData.getParameter("clinic_ref_code"));
  			ch1Obj
  					.setMan_review(requestData.getParameter("m_review") == null ? ""
  							: "Y");
  			ch1Obj.setBilling_date(requestData
  					.getParameter("xml_appointment_date"));
  			ch1Obj.setProviderNo(requestData.getParameter("provider_no"));
  			ch1Obj.setComment(requestData.getParameter("comment"));
  
  			// provider_ohip_no update as well
  			BillingProviderData otemp = (new JdbcBillingPageUtil())
  					.getProviderObj(requestData.getParameter("provider_no"));
  			ch1Obj.setProvider_ohip_no(otemp.getOhipNo());
  			ch1Obj.setProvider_rma_no(otemp.getRmaNo());
  			ch1Obj.setCreator((String) requestData.getSession().getAttribute(
  					"user"));
  			
  			ch1Obj.setClinic(requestData.getParameter("site"));
  			
  			ch1Obj.setProvince(requestData.getParameter("hc_type"));
  			
  			ch1Obj.setLocation(requestData.getParameter("xml_slicode"));
  			ret = dbObj.updateBillingClaimHeader(ch1Obj);
  		}
  		
  		//set inactive 3rd party payment record if user switched from 3rd party to some other pay program
  		String payProgram = requestData.getParameter("payProgram");				
  		if( requestData.getParameter("oldStatus").equals("thirdParty") && ("HCP".equals(payProgram) || "RMB".equals(payProgram) || "WCB".equals(payProgram)) ) {
  			setInactive("payment", requestData);
  			setInactive("refund", requestData);
  			setInactive("payDate", requestData);
  			setInactive("billTo", requestData);
  		}
  
  		// 3rd party elements
  		if (requestData.getParameter("payment") != null) {
  			ret = update3rdPartyItem("payment", requestData);
              ret = update3rdPartyItem("refund", requestData);
              ret = update3rdPartyItem("payDate", requestData);
              ch1Obj.setPaid(requestData.getParameter("payment"));
              ret = dbObj.updateBillingClaimHeader(ch1Obj);
  		}
  
  		if (requestData.getParameter("billTo") != null) {
  			ret = update3rdPartyItem("billTo", requestData);
  		}
  
  		return ret;
  	}
  	
  		public void setInactive(String key, HttpServletRequest request) {
  			JdbcBilling3rdPartImpl tobj = new JdbcBilling3rdPartImpl();
  			String billingNo = request.getParameter("xml_billing_no");
  			tobj.updateKeyStatus(billingNo, key, JdbcBilling3rdPartImpl.INACTIVE);
  		}
  
          /*
           * Need to use billing extension table to capture data for invoices in
           * addition to 3rd party bills
           */
          public void updateExt(String key, HttpServletRequest request) {
              update3rdPartyItem(key, request);
          }
  
          public boolean update3rdPartyItem(String key, HttpServletRequest request) {
  		boolean ret = true;
  		JdbcBilling3rdPartImpl tobj = new JdbcBilling3rdPartImpl();
  		String billingNo = request.getParameter("xml_billing_no");
  		if( tobj.keyExists(billingNo, key) ) {
                      ret = tobj.updateKeyValue(billingNo, key, request.getParameter(key));
                  }
                  else {
                      ret = tobj.add3rdBillExt(billingNo, request.getParameter("demoNo"), key, request.getParameter(key));
                  }
  		return ret;
  	}
  
  	public boolean update3rdPartyItem(HttpServletRequest request) {
  		boolean ret = true;
  		JdbcBilling3rdPartImpl tobj = new JdbcBilling3rdPartImpl();
  		String billingNo = request.getParameter("xml_billing_no");
  		tobj.updateKeyValue(billingNo, "payment", request
  				.getParameter("payment"));
  		tobj
  				.updateKeyValue(billingNo, "refund", request
  						.getParameter("refund"));
  		return ret;
  	}
  
  	public boolean updateBillingItem(List lItemObj, HttpServletRequest request) {
  		boolean ret = true; // dbObj.updateBillingClaimHeader(ch1Obj);
  		// _logger.info("updateBillingItem(old value = ");
  		Vector vecName = new Vector();
  		Vector vecUnit = new Vector();
  		Vector vecFee = new Vector();
  		Vector vecStatus = new Vector();
  		String dx = request.getParameter("xml_diagnostic_detail");
  		dx = dx.length() > 2 ? dx.substring(0, 3) : dx;
  		String serviceDate = request.getParameter("xml_appointment_date");
  
  		for (int i = 0; i < BillingDataHlp.FIELD_MAX_SERVICE_NUM; i++) {
  			if (request.getParameter("servicecode" + i) != null
  					&& request.getParameter("servicecode" + i).length() > 0) { // == 5
  				vecName.add(request.getParameter("servicecode" + i));
  				vecUnit.add(request.getParameter("billingunit" + i));
  				vecFee.add(request.getParameter("billingamount" + i));
  				vecStatus
  						.add(request.getParameter("itemStatus" + i) == null ? "O"
  								: "S");
  			}
  		}
  
  		// update item first
  		String claimId = "0";
  		for (int i = 0; i < lItemObj.size(); i++) {
  			BillingItemData iObj = (BillingItemData) lItemObj.get(i);
  			ret = changeItem(iObj, dx, serviceDate, vecName, vecUnit, vecFee,
  					vecStatus);
  			claimId = iObj.getCh1_id();
  			_logger.info(iObj.getService_code() + " lItemObj = " + ret);
  		}
  
  		// add item if possible
  		for (int i = 0; i < vecName.size(); i++) {
  			String sName = (String) vecName.get(i);
  			String sUnit = (String) vecUnit.get(i);
  			String sFee = (String) vecFee.get(i);
  			String sStatus = (String) vecStatus.get(i);
  			ret = addItem(lItemObj, dx, serviceDate, sName, sUnit, sFee,
  					sStatus);
  			_logger.info(sName + " lItemObj(value = " + ret);
  		}
  
  		// recalculate amount
  		String newAmount = sumFee(vecFee);
  		_logger.info(" lItemObj(newAmount = " + newAmount);
  		updateAmount(newAmount, claimId);		
  
  		return ret;
  	}
  
  	
  	// billing correction
  	public String getBillingCodeDesc(String codeName) {
  		String ret = null;
  		JdbcBillingCodeImpl dbCodeObj = new JdbcBillingCodeImpl();
  		List descL = dbCodeObj.getBillingCodeAttr(codeName);
  		ret = descL.size() > 1 ? (String) descL.get(1) : "Unknown";
  		return ret;
  	}
  
  	// billing correction
  	public Properties getBillingCodeDesc(List codeName) {
  		JdbcBillingCodeImpl dbCodeObj = new JdbcBillingCodeImpl();
  		Properties ret = new Properties();
  		for (int i = 0; i < codeName.size(); i++) {
  			List descL = dbCodeObj.getBillingCodeAttr((String) codeName.get(i));
  			String desc = descL.size() > 1 ? (String) descL.get(1) : "Unknown";
  			ret.setProperty((String) codeName.get(i), desc);
  		}
  		return ret;
  	}
  
  	// from billing correction
  	public List getBillingClaimHeaderObj(String ch1Id) {
  		List recordObj = null;
  