Commit e1095d1a authored by CORP\sonam.kamble's avatar CORP\sonam.kamble

Added Appointment servlet for Koye

parent f10ec447
package ibase.dashboard.crm.ejb;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.json.XML;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.DBAccessEJB;
public class Appointment
{
private E12GenericUtility genericUtility = new E12GenericUtility();
@SuppressWarnings({ "unchecked", "static-access" })
public String getAppointmentData(UserInfoBean userInfoBean) {
String sql = "",aptId = "";
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
String transDB = userInfoBean.getTransDB();
String userCode = userInfoBean.getLoginCode();
JSONObject jsonObject = null;
JSONArray jsonArray = new JSONArray();
try
{
conn = connDriver.getConnectDB(transDB);
sql = " SELECT PT.FIRST_NAME || ' ' || PT.MIDDLE_NAME || ' ' || PT.LAST_NAME AS PATIENT_NAME, "+
" PT.PATIENT_CODE, APT.APPOINT_ID AS APPT_ID, TO_CHAR( APT.APPOINT_DATE, 'DD FMMONTH YYYY' ) AS APPT_DATE," +
" APT.STATUS AS STATUS,(TO_CHAR( SYSDATE, 'YYYY' ) - TO_CHAR( PT.BIRTH_DATE, 'YYYY' )) AS AGE, UPPER(PT.SEX) AS GENDER, " +
" '/IBASE/RESOURCE/IMAGES/DETAILFORMICON/COMPLETED.PNG' AS VISIT_COMP_ICON, " +
" '/IBASE/RESOURCE/IMAGES/DETAILFORMICON/DOC_VERIFY.PNG' AS VERIFY_DOC_ICON, " +
" ( SELECT COUNT(AA.APPOINT_DATE) COUNT " +
" FROM APPOINTMENT AA " +
" WHERE AA.APPOINT_DATE = APT.APPOINT_DATE " +
" GROUP BY APPOINT_DATE " +
" ) AS COUNT_DAYS " +
" FROM APPOINTMENT APT " +
" JOIN PATIENT PT " +
" ON APT.PATIENT_CODE = PT.PATIENT_CODE " +
" WHERE DOCTOR_CODE = ? " +
" AND (TO_CHAR( APPOINT_DATE, 'DD/MM/YY' ) BETWEEN TO_CHAR( SYSDATE , 'DD/MM/YY' ) " +
" AND TO_CHAR( SYSDATE + 1 , 'DD/MM/YY' ) )" +
" GROUP BY PT.FIRST_NAME,PT.MIDDLE_NAME,PT.LAST_NAME,PT.PATIENT_CODE,APT.APPOINT_ID," +
" APT.APPOINT_DATE,APT.STATUS,PT.BIRTH_DATE,PT.SEX " +
" ORDER BY APPOINT_ID";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, userCode);
rs = pStmt.executeQuery();
while (rs.next())
{
jsonObject = new JSONObject();
jsonObject.put("PATIENT_CODE", genericUtility.checkNull(rs.getString("PATIENT_CODE")));
jsonObject.put("PATIENT_NAME", genericUtility.checkNull(rs.getString("PATIENT_NAME")));
jsonObject.put("APPT_ID", genericUtility.checkNull(rs.getString("APPT_ID")));
jsonObject.put("APPT_DATE", genericUtility.checkNull(rs.getString("APPT_DATE")));
jsonObject.put("STATUS", genericUtility.checkNull(rs.getString("STATUS")));
jsonObject.put("AGE", genericUtility.checkNull(rs.getString("AGE")));
jsonObject.put("GENDER", genericUtility.checkNull(rs.getString("GENDER")));
jsonObject.put("VISIT_COMP_ICON", genericUtility.checkNull(rs.getString("VISIT_COMP_ICON")));
jsonObject.put("VERIFY_DOC_ICON", genericUtility.checkNull(rs.getString("VERIFY_DOC_ICON")));
aptId = genericUtility.checkNull(rs.getString("APPT_ID"));
String hostUrl = CommonConstants.TOMCAT_HOME;
String object = "PatientImages";
String objName= "doctor_appointment";
String docAttachType="png";
//fldValue=CUST000001&object=PatientImages&objName=doctor_appointment&ALT_FLD_VALUE=CUST000001&docAttachType=png
String imgUrl = hostUrl + "/ibase/CustomMenuImageServlet?fldValue="+aptId+"&ALT_FLD_VALUE="+aptId+"&object="+object+
"&objName="+objName+"&docAttachType="+docAttachType;
jsonObject.put("PROFILE_ICON",imgUrl);
jsonArray.add(jsonObject);
jsonObject = null;
}
}
catch(Exception e)
{
System.out.println("Exception in getAppointment :: "+e);
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception e)
{
System.out.println("Exception while closing resourse in Appointment Dashboard ... "+e);
}
}
return jsonArray.toString();
}
@SuppressWarnings({ "static-access", "resource" })
public String updateApptStatus(String apptId,UserInfoBean userInfoBean)
{
String errSting = "",sql = "",status = "",patientName ="",patientCode = "";
int cnt = 0;
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
String transDB = userInfoBean.getTransDB();
String userCode = userInfoBean.getLoginCode();
org.json.JSONObject jsonObject = new org.json.JSONObject();
try
{
conn = connDriver.getConnectDB(transDB);
sql= " SELECT APT.STATUS,PT.PATIENT_CODE,PT.FIRST_NAME || ' ' || PT.MIDDLE_NAME || ' ' || PT.LAST_NAME AS PATIENT_NAME\n" +
" FROM APPOINTMENT APT \n" +
" JOIN PATIENT PT\n" +
" ON PT.PATIENT_CODE = APT.PATIENT_CODE \n" +
" WHERE APT.APPOINT_ID = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, apptId);
rs = pStmt.executeQuery();
if(rs.next())
{
status = genericUtility.checkNull(rs.getString("STATUS"));
patientName = genericUtility.checkNull(rs.getString("PATIENT_NAME"));
patientCode = genericUtility.checkNull(rs.getString("PATIENT_CODE"));
}
if("C".equalsIgnoreCase(status))
{
errSting = genericUtility.getErrorString("appt_id", "VMAPPTCPAR", userCode);
jsonObject = convertXmlToJsonInError(errSting);
}
else
{
sql = "update APPOINTMENT set status = ? where APPOINT_ID = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, "C");
pStmt.setString(2, apptId);
cnt = pStmt.executeUpdate();
System.out.println("Update Status Count :: "+cnt);
if(cnt > 0)
{
conn.commit();
errSting = genericUtility.getErrorString("appt_id", "VMAPPTCOMP", userCode);
jsonObject = convertXmlToJsonInError(errSting);
}
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
}
jsonObject.append("patient_name", patientName);
jsonObject.append("patient_code", patientCode);
}
catch (Exception e)
{
System.out.println("Exception in Appointment Dashboard ..............."+e);
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception e)
{
System.out.println("Exception while closing resourse in Appointment Dashboard ... "+e);
}
}
return jsonObject.toString();
}
@SuppressWarnings({ "unchecked", "static-access", "resource" })
public String getDoctorDetails(UserInfoBean userInfoBean)
{
System.out.println("Inside getDoctorDetails ");
String sql = "";
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
String transDB = userInfoBean.getTransDB();
String userCode = userInfoBean.getLoginCode();
JSONObject jsonObject = new JSONObject();
List<String> visitplaces = new ArrayList<String>();
try
{
conn=connDriver.getConnectDB(transDB);
sql="SELECT SC_CODE,FIRST_NAME||' '|| MIDDLE_NAME ||' '||LAST_NAME AS NAME FROM STRG_CUSTOMER WHERE SC_CODE= ?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, userCode);
rs = pStmt.executeQuery();
while (rs.next())
{
jsonObject.put("SC_CODE", genericUtility.checkNull(rs.getString("SC_CODE")));
jsonObject.put("NAME", genericUtility.checkNull(rs.getString("NAME")));
}
pStmt=null;
rs= null;
sql = "SELECT VISIT_PLACE FROM STRG_VISIT_HOURS WHERE SC_CODE = ?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, userCode);
rs = pStmt.executeQuery();
while (rs.next())
{
visitplaces.add(genericUtility.checkNull(rs.getString("VISIT_PLACE")).trim());
}
jsonObject.put("VISIT_PLACES",visitplaces);
}
catch(Exception e)
{
System.out.println("Exception in getDoctorDetails :: "+e.getMessage());
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception e)
{
System.out.println("Exception While Closing resourses ..... :: "+e);
}
}
return jsonObject.toString();
}
public String insertUnableToVisit(String data,UserInfoBean userInfoBean)
{
System.out.println("Inside insertUnableToVisit ");
String lineNo = "",visitplace = "",errSting="",fromDateStr="",toDateStr="",scCode="",remarks="";
String sql = "";
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
String transDB = userInfoBean.getTransDB();
String userCode = userInfoBean.getLoginCode();
org.json.JSONObject jsonObject = new org.json.JSONObject();
List<String> visitplaces = new ArrayList<String>();
java.util.Date frDate = null;
java.util.Date toDate = null;
Timestamp fromDtTStmp = null;
Timestamp toDtTStmp = null;
SimpleDateFormat output = new SimpleDateFormat(CommonConstants.APPL_DATE_FORMAT);
try
{
try
{
org.json.JSONObject jsonData = new org.json.JSONObject(data);
System.out.println("#jsonData " + jsonData.toString());
scCode = jsonData.getString("scCode");
fromDateStr = jsonData.getString("fromDate");
toDateStr = jsonData.getString("toDate");
visitplace = jsonData.getString("visitPlace");
remarks = jsonData.getString("remark");
//SimpleDateFormat input = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
if("".equalsIgnoreCase(visitplace))
{
errSting = this.genericUtility.getErrorString("visit_place", "VSTPLBLANK", userCode);
System.out.println("Error Vicky :: "+errSting);
jsonObject = this.convertXmlToJsonInError(errSting);
return jsonObject.toString();
}
;
try
{
frDate = output.parse(fromDateStr);
toDate = output.parse(toDateStr);
System.out.println("frDate [" + frDate + "] toDate[" + toDate + "]");
}
catch (Exception e)
{
e.printStackTrace();
}
// fromDateStr = output.format(frDate);
//toDateStr = output.format(toDate);
fromDtTStmp = Timestamp.valueOf(String.valueOf(this.genericUtility.getValidDateString(fromDateStr, this.genericUtility.getApplDateFormat(), this.genericUtility.getDBDateFormat())) + " 00:00:00.00");
toDtTStmp = Timestamp.valueOf(String.valueOf(this.genericUtility.getValidDateString(toDateStr, this.genericUtility.getApplDateFormat(), this.genericUtility.getDBDateFormat())) + " 00:00:00.00");
if (toDtTStmp.before(fromDtTStmp))
{
errSting = this.genericUtility.getErrorString("to_date", "VTTODTINVA", userCode);
System.out.println("Error Vicky :: "+errSting);
jsonObject = this.convertXmlToJsonInError(errSting);
return jsonObject.toString();
}
}
catch(Exception e)
{
System.out.println("Excepetion ...1 "+e.getMessage());
}
conn=connDriver.getConnectDB(transDB);
sql="SELECT LINE_NO FROM STRG_VISIT_HOURS WHERE SC_CODE = ? AND VISIT_PLACE = ?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, userCode);
pStmt.setString(2, visitplace);
rs = pStmt.executeQuery();
while (rs.next())
{
lineNo = genericUtility.checkNull(rs.getString("LINE_NO"));
}
pStmt=null;
rs= null;
if(!"".equalsIgnoreCase(lineNo))
{
int cnt = 0;
sql = "select count(1) as cnt from VISIT_UNAVAILABLE where SC_CODE = ? and FR_DATE = ? and TO_DAATE = ? and VIST_REF_NO = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, userCode);
pStmt.setTimestamp(2, fromDtTStmp);
pStmt.setTimestamp(3, toDtTStmp);
pStmt.setString(4, lineNo);
rs = pStmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
pStmt=null;
rs= null;
if( cnt > 0)
{
errSting = genericUtility.getErrorString("SC_CODE", "VSASTUNAVL", userCode);
jsonObject = convertXmlToJsonInError(errSting);
}
else
{
cnt = 0;
sql = "INSERT INTO VISIT_UNAVAILABLE (SC_CODE,FR_DATE,TO_DAATE,VIST_REF_NO,REMARK) VALUES (?,?,?,?,?)";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, userCode);
pStmt.setTimestamp(2, fromDtTStmp);
pStmt.setTimestamp(3, toDtTStmp);
pStmt.setString(4, lineNo);
pStmt.setString(5, remarks);
cnt = pStmt.executeUpdate();
if(cnt > 0)
{
conn.commit();
errSting = genericUtility.getErrorString("SC_CODE", "VISUNAVAIL", userCode);
jsonObject = convertXmlToJsonInError(errSting);
}
else
{
jsonObject.put("Error","Error Visit un available");
}
}
SimpleDateFormat format2 = new SimpleDateFormat("dd-MMM-yy");
frDate = output.parse(fromDateStr);
toDate = output.parse(toDateStr);
System.out.println(format2.format(frDate));
fromDateStr = format2.format(frDate);
toDateStr = format2.format(toDate);
System.out.println("FromDateStr :: "+fromDateStr+" toDateStr::"+toDateStr);
jsonObject.append("from_date", fromDateStr);
jsonObject.append("to_date", toDateStr);
jsonObject.append("visit_place", visitplace);
}
else
{
errSting = genericUtility.getErrorString("SC_CODE", "VSTPLINVAL", userCode);
jsonObject = convertXmlToJsonInError(errSting);
}
}
catch(Exception e)
{
System.out.println("Exception in getDoctorDetails :: "+e.getMessage());
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception e)
{
System.out.println("Exception While Closing resourses ..... :: "+e);
}
}
return jsonObject.toString();
}
public org.json.JSONObject convertXmlToJsonInError(String xmlString)
{
org.json.JSONObject jsonObject = new org.json.JSONObject();
try
{
org.json.JSONObject obj = XML.toJSONObject(xmlString);
org.json.JSONObject root = obj.getJSONObject("Root");
org.json.JSONObject Errors = root.getJSONObject("Errors");
org.json.JSONObject error = Errors.getJSONObject("error");
String trace = error.getString("trace");
String columnName = error.getString("column_name");
String description = error.getString("description");
org.json.JSONArray jsonArraytype = error.getJSONArray("type");
String type = jsonArraytype.getString(1);
System.out.println("trace"+trace+"\t column_name"+columnName+"\t description"+description+"\t type:"+type);
jsonObject.put("trace", trace);
jsonObject.put("column_name", columnName);
jsonObject.put("description", description);
jsonObject.put("type", type);
}
catch (Exception e)
{
System.out.println("SellsStock.convertXmlToJsonInError()"+e);
}
return jsonObject;
}
public String registerDoctor(String data,UserInfoBean userInfoBean)
{
System.out.println("Inside insertUnableToVisit ");
String lineNo = "",visitplace = "",errSting="",fromDateStr="",toDateStr="",scCode="",remarks="";
String sql = "";
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
String transDB = userInfoBean.getTransDB();
String userCode = userInfoBean.getLoginCode();
org.json.JSONObject jsonObject = new org.json.JSONObject();
List<String> visitplaces = new ArrayList<String>();
java.util.Date frDate = null;
java.util.Date toDate = null;
Timestamp fromDtTStmp = null;
Timestamp toDtTStmp = null;
SimpleDateFormat output = new SimpleDateFormat(CommonConstants.APPL_DATE_FORMAT);
try
{
try
{
org.json.JSONObject jsonData = new org.json.JSONObject(data);
System.out.println("#jsonData " + jsonData.toString());
scCode = jsonData.getString("scCode");
fromDateStr = jsonData.getString("fromDate");
toDateStr = jsonData.getString("toDate");
visitplace = jsonData.getString("visitPlace");
remarks = jsonData.getString("remark");
}
catch(Exception e)
{
System.out.println("Exception 001"+e.getMessage());
}
}catch(Exception e)
{
System.out.println("Exception 002"+e.getMessage());
}
return null;
}
public String registerPatient(String data,UserInfoBean userInfoBean)
{
System.out.println("Inside insertUnableToVisit ");
String sql = "",tranID="";
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
String transDB = userInfoBean.getTransDB();
String userCode = userInfoBean.getLoginCode();
org.json.JSONObject jsonObject = new org.json.JSONObject();
List<String> visitplaces = new ArrayList<String>();
java.util.Date frDate = null;
java.util.Date toDate = null;
Timestamp fromDtTStmp = null;
Timestamp toDtTStmp = null;
SimpleDateFormat output = new SimpleDateFormat(CommonConstants.APPL_DATE_FORMAT);
final DBAccessEJB dbAcc = new DBAccessEJB();
try
{
try
{
org.json.JSONObject jsonData = new org.json.JSONObject(data);
System.out.println("#jsonData " + jsonData.toString());
}
catch(Exception e)
{
System.out.println("Exception 01 "+e.getMessage());
}
tranID = dbAcc.generateTranId("W_WELCOME_SCREEN", userInfoBean.getSiteCode(), userInfoBean.getLoginCode(), conn);
}catch(Exception e)
{
System.out.println("Exception 02 "+e.getMessage());
}
return null;
}
public String insertUser()
{
System.out.println("Inside insertUnableToVisit ");
String sql = "";
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
try
{
try
{
conn = connDriver.getConnectDB();
}
catch(Exception e)
{
System.out.println("Exception 01 "+e.getMessage());
}
}catch(Exception e)
{
System.out.println("Exception 02 "+e.getMessage());
}
return null;
}
}
package ibase.dashboard.crm.servlet;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import ibase.dashboard.crm.ejb.Appointment;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.utility.ITMException;
public class AppointmentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
HttpSession session = null;
String jsonObjData = null;
OutputStream outputStream = null;
UserInfoBean userInfo = null;
Appointment appointment = new Appointment();
try
{
response.setContentType("application/xml");
session = request.getSession(true);
userInfo = (ibase.utility.UserInfoBean) session.getAttribute("USER_INFO");
jsonObjData = appointment.getAppointmentData(userInfo);
//System.out.println(" Final data set for AppointmentServlet Dashboard :: " + jsonObjData);
outputStream = response.getOutputStream();
outputStream.write(jsonObjData.toString().getBytes());
outputStream.flush();
outputStream.close();
}
catch (Exception e)
{
System.out.println("Exception : AppointmentServlet :doPost(HttpServletRequest request, HttpServletResponse response) :"+ e);
try
{
throw new ITMException(e);
}
catch (ITMException e1)
{
e1.printStackTrace();
}
}
finally
{
if(appointment != null)
{
appointment = null;
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment