📄 patient.java
字号:
package crqs.dboperation;
import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import crqs.util.*;
import crqs.infobeans.*;
import crqs.exceptions.RecordsNotExistException;
public class Patient extends DBOperation implements Serializable {
static final long serialVersionUID = 34060417;
// Constructor
public Patient() {
}
public Patient(String un, String pw) {
super(un, pw);
}
public boolean register(String userName, String passwd, String mailbox,
String phoneNO, String name, String address, String gender,
String age, String IDCard) throws SQLException {
String sql = "Select * from Patient where UserName='" + userName + "'";
try {
executeQuery(sql);
if (result.next())
return false;
else {
sql = "Insert into Patient"
+ "(UserName,Passwd,PName,Age,Gender,"
+ "PhoneNO,Mailbox,Address,IDCard) " + "values('"
+ userName + "','" + passwd + "','" + name + "'," + age
+ ",'" + gender + "','" + phoneNO + "','" + mailbox
+ "','" + address + "','" + IDCard + "')";
executeUpdate(sql);
return true;
}
} finally {
closeConnection();
}
}
public boolean login() throws SQLException, RecordsNotExistException {
String sql = "Select PName, Passwd" + " From Patient"
+ " Where UserName = '" + this.userName + "'";
try {
// System.out.println(sql);
executeQuery(sql);
if (result.next()) {
if (result.getString("Passwd").equals(this.password))
return true;
else
return false;
} else {
throw new RecordsNotExistException();
}
} finally {
closeConnection();
}
}
public PatientInfo getInfo() throws SQLException, RecordsNotExistException {
String sql = "Select * From Patient" + " Where UserName = '"
+ this.userName + "'";
try {
executeQuery(sql);
if (result.next()) {
PatientInfo info = new PatientInfo();
info.setUserName(result.getString("UserName"));
info.setPassword(result.getString("Passwd"));
info.setMailBox(result.getString("Mailbox"));
info.setPhone(result.getString("PhoneNO"));
info.setAge(result.getInt("Age"));
info.setGender(result.getString("Gender").charAt(0));
info.setRealName(result.getString("PName"));
info.setIdentity(result.getString("IDCard"));
info.setAddress(result.getString("Address"));
return info;
} else {
throw new RecordsNotExistException();
}
} finally {
closeConnection();
}
}
public DoctorInfo getDoctorInfo(String docID) throws SQLException,
RecordsNotExistException {
String sql = "Select DName, Gender, Age, SName, TName "
+ "from Doctor, Section, Title "
+ "where Doctor.SectionNO=Section.SectionNO "
+ "and Doctor.Title=Title.TitleNO " + "and UserName='" + docID
+ "'";
try {
executeQuery(sql);
if (result.next()) {
DoctorInfo di = new DoctorInfo();
di.setUserName(docID);
di.setRealName(result.getString("DName"));
di.setGender(result.getString("Gender").charAt(0));
di.setAge(result.getInt("Age"));
di.setSection(result.getString("SName"));
di.setTitle(result.getString("TName"));
return di;
} else
throw new RecordsNotExistException();
} finally {
closeConnection();
}
}
public boolean setInfo(String name, String gender, String age,
String IDCard, String phone, String mail, String address)
throws SQLException {
String sql = "Update Patient" + " Set" + " PName = '" + name + "',"
+ " Gender = '" + gender + "'," + " Age = " + age + ","
+ " IDCard = '" + IDCard + "'," + " PhoneNO = '" + phone + "',"
+ " Mailbox = '" + mail + "'," + " Address = '" + address + "'"
+ " Where UserName = '" + this.userName + "'";
try {
// System.out.println(sql);
executeUpdate(sql);
} finally {
closeConnection();
}
return true;
}
public Page queryRes(Date begin, Date end) throws SQLException,
RecordsNotExistException {
String query = "Select DoctorID, DName, "
+ "ResNO, ResDate, Confirmed, SName "
+ "From ReservationView "
+ "where PatientID='" + this.userName + "'"
+ " and ResDate >= '" + DateConvert.convert(begin)
+ "' and ResDate <= '" + DateConvert.convert(end) + "'";
ArrayList alist = new ArrayList();
Reservation reserve = new Reservation();
try {
executeQuery(query);
if (result.next()) {
do {
reserve.setDoctorId(result.getString("DoctorID"));
reserve.setDoctorName(result.getString("DName"));
reserve.setResNo(result.getString("ResNO"));
reserve.setReservationDate(result.getDate("ResDate"));
reserve.setConfirmed(result.getString("Confirmed")
.charAt(0));
reserve.setSeciton(result.getString("SName"));
alist.add(reserve);
reserve = new Reservation();
} while (result.next());
Page page = new Page(alist);
return page;
} else {
throw new RecordsNotExistException();
}
} catch (SQLException e) {
throw e;
} finally {
closeConnection();
}
}
public Page getMyReservation() throws SQLException,
RecordsNotExistException {
String sql = "Select ResNO, DoctorID, ResDate, Mark, Confirmed, DName, SName"
+ " From ReservationView"
+ " Where PatientID = '"+ this.userName + "'"
+ " and Confirmed = 'n' and ResDate >='"
+ DateConvert.convert(new Date())+"'";
ArrayList array = new ArrayList();
try {
// System.out.println(sql);
executeQuery(sql);
while (result.next()) {
Reservation res = new Reservation();
res.setResNo(result.getString("ResNO"));
res.setDoctorId(result.getString("DoctorID"));
res.setReservationDate(result.getDate("ResDate"));
res.setMark(result.getInt("Mark"));
res.setConfirmed(result.getString("Confirmed").charAt(0));
res.setDoctorName(result.getString("DName"));
res.setSeciton(result.getString("SName"));
array.add(res);
}
if (array.isEmpty())
throw new RecordsNotExistException();
Page reservations = new Page(array);
return reservations;
} finally {
closeConnection();
}
}
public Page getUnmarked() throws SQLException, RecordsNotExistException {
String sql = "Select ResNO, DoctorID, ResDate, Mark, Confirmed, DName, SName"
+ " From ReservationView"
+ " Where PatientID = '" + this.userName + "'"
+ " and Mark = 0 and Confirmed='y'";
ArrayList array = new ArrayList();
try {
// System.out.println(sql);
executeQuery(sql);
while (result.next()) {
Reservation res = new Reservation();
res.setResNo(result.getString("ResNO"));
res.setDoctorId(result.getString("DoctorID"));
res.setReservationDate(result.getDate("ResDate"));
res.setMark(result.getInt("Mark"));
res.setConfirmed(result.getString("Confirmed").charAt(0));
res.setDoctorName(result.getString("DName"));
res.setSeciton(result.getString("SName"));
array.add(res);
}
if (array.isEmpty())
throw new RecordsNotExistException();
Page reservations = new Page(array);
return reservations;
} finally {
closeConnection();
}
}
public boolean setPassword(String old, String newPw) throws SQLException {
String sql = "Select Passwd from Patient where UserName='"
+ this.userName + "'";
try {
executeQuery(sql);
result.next();
if (!result.getString(1).equals(old.trim()))
return false;
else {
sql = "Update Administrator set Passwd='" + newPw
+ "' where UserName='" + this.userName + "'";
executeUpdate(sql);
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -