private void addVisitsRecord(HttpServletRequest request, HttpServletResponse response, DatabaseConnection dbcon, Login credentials) 
           throws ServletException, IOException {
            Visit v = null;   
             try 
             {
                //the set ID part might be pretty messed up....
                ResultSet newRows = dbcon.selectRows("Visit", "MAX(ApptID)", null);
                newRows.next();
                v = new Visit();
                v.setApptID(newRows.getInt("MAX(ApptID)") + 1);
                v.setProcedure(request.getParameter("visit_procedure"));
                v.setResult(request.getParameter("visit_result"));
                v.setPrescription(request.getParameter("visit_prescription"));
                v.setComment(request.getParameter("visit_comment"));
                
                String startDateString = request.getParameter("visit_arrival");
                String endDateString = request.getParameter("visit_departure");
                String startYear = "";
                String startMonth = "";
                String startDay = "";
                String endYear = "";
                String endMonth = "";
                String endDay = "";

                if (!startDateString.equals("") && !endDateString.equals("")) {
                    String[] startDateArray = startDateString.split("/");
                    startYear = startDateArray[2];
                    startMonth = startDateArray[0];
                    startDay = startDateArray[1];

                    String[] endDateArray = endDateString.split("/");
                    endYear = endDateArray[2];
                    endMonth = endDateArray[0];
                    endDay = endDateArray[1];
                }

                String arrivalTime = "";
                String departTime = "";

                if (!startYear.equals("") && !startMonth.equals("") && !startDay.equals("") &&
                        !endYear.equals("") && !endMonth.equals("") && !endDay.equals("")) {

                    arrivalTime = "'"+startYear+"-"+startMonth+"-"+startDay+" 00:00:00'";
                    departTime = "'"+endYear+"-"+endMonth+"-"+endDay+" 23:59:59'";
                }

                java.util.Date date= new java.util.Date(); 
                Timestamp currentTime = new Timestamp(date.getTime());
                String currentTimeString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(currentTime);
                currentTimeString = "'"+currentTimeString+"'";
                
                dbcon.insertRows("Visit", 
                    "ApptID,ArrivalTime,DepartTime,V_Procedure,Result,Prescription,V_Comment,AuditTime,AuditByID",
                    "'"+v.getApptID()+"'" +"," + arrivalTime+","+ departTime+","+"'"+v.getProcedure()+"'"+","+"'"+v.getResult()+"'"+","+"'"+v.getPrescription()+"'"+","+"'"+v.getComment()+"'"+","+currentTimeString+","+credentials.getLoginId());
            
                getServletContext().getRequestDispatcher("/doctor/doctor.jsp").forward(request, response);
             } 
            catch (SQLException ex) 
            {
                //request.setAttribute("exception", ex);
                getServletContext().getRequestDispatcher("/doctor/doctor_addvisitrecord.jsp").forward(request, response);
            }
        }