}
dayCheckDL = dayCheckDL.substring(4,dayCheckDL.length());
//if user want some medication schedule be deleted.
if(delMed != null){
newMed = delMed;
addMed = new Medication(Integer.parseInt(newMed));
createMed(addMed,form);
addMed.setUsername(user.getEmailAddress());
addMed.setDayChecks(dayCheckDL);
//addMed.setAllNum(allNum + 1);
//create a new user.
medDAO.create(addMed);
synchronized(session){
session.setAttribute("deletelist",delList);
request.setAttribute("addmedform", null);
request.setAttribute("message","Successfully added " + form.getName()+ ". ");
}
//if no scheduled medication be deleted.
}else{
int allSize = medDAO.size();
//System.out.println("all size is " + Integer.toString(allSize));
//initialization situation.
if(allSize == 0){
newMed = Integer.toString(allSize);
System.out.println("all size is " + newMed);
addMed = new Medication(Integer.parseInt(newMed));
createMed(addMed,form);
addMed.setUsername(user.getEmailAddress());
addMed.setDayChecks(dayCheckDL);
medDAO.create(addMed);
synchronized(session){
session.setAttribute("deletelist", null);
request.setAttribute("addmedform", null);
request.setAttribute("message","Successfully added " + form.getName() + ".");
}
}else{
allSize = medDAO.getLastId();
newMed = Integer.toString(allSize);
addMed = new Medication(Integer.parseInt(newMed) + 1);
createMed(addMed,form);
addMed.setUsername(user.getEmailAddress());
addMed.setDayChecks(dayCheckDL);
medDAO.create(addMed);
synchronized(session){