package hospital.db.dboperation;
import java.sql.*;
import hospital.db.*;
import java.text.*;
/**
* 继承自DBOperation类,用以封装患者角色
*
* 作者:Fido Dido
*/
public class Patient
extends DBOperation{
public static final String NAME="Name";
public static final String SECTION="Section";
public static final String ANONYMOUS="anonymous";
private int PID;
/**
* 构造器
*
* 参数:
* id-用户名
*/
public Patient(String id)
throws InvalidUserException{
super(id);
}
/**
* 用户登录
*
* 参数:
* password-密码
*
* 返回值-操作结果:
* 1-操作成功
* 0-抛出一般异常
* -1-抛出数据库异常
* -2-登录失败
*/
public int login(String password){
conn=DBConnection.getConnection();
int res=0;
try{
strSQL="SELECT Username,Password,PID FROM patient WHERE Username='" + Util.encode(this.id) +
"' AND Password=password('" + Util.encode(password) + "')";
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(strSQL);
if(!rs.next())
throw new IllegalArgumentException("Password invalid.");
this.PID=rs.getInt("PID");
res=1;
}
catch(IllegalArgumentException iae){
Debug.log(Debug.getExceptionMsg(iae));
res= -2;
}
catch(SQLException sqle){
Debug.log(Debug.getExceptionMsg(sqle));
res= -1;
}
catch(Exception e){
res=0;
}
finally{
return res;
}
}
/**
* 用户注册
*
* 参数:
* username-用户名
* name-姓名
* password-密码
* age-年龄
* sex-性别
* address-联系地址
* phone-联系电话
*
* 返回值-操作结果:
* 1-操作成功
* 0-抛出一般异常
* -1-抛出数据库异常
* -2-帐户已存在
*/
public synchronized int addPatient(String username,String name,String password,int age,int sex,String address,
String phone){
int res=0;
conn=DBConnection.getConnection();
try{
strSQL="SELECT pid FROM patient WHERE patient.Username='" + username + "'";
stmt=conn.createStatement();
rs=stmt.executeQuery(strSQL);
if(rs.next())
throw new IllegalArgumentException("Patient Username '" + username + "' already existed.");
strSQL="INSERT INTO patient (Name,Username,Password,Age,Sex,Address,Phone) VALUES('" + name + "','" +
username + "',password('" + password + "')," + age + ",'" + sex + "','" + address + "','" + phone + "')";
stmt=conn.createStatement();
stmt.executeUpdate(strSQL);
res=1;
}
catch(SQLException sqle){
Debug.log(Debug.getExceptionMsg(sqle));
res= -1;
}
catch(IllegalArgumentException iae){
Debug.log(Debug.getExceptionMsg(iae));
res= -2;
}
catch(Exception e){
res=0;
}
finally{
return res;
}
}
/**
* 查询医生信息
*
* 参数:
* orderBy-结果集排序方式
*
* 返回值-操作结果:
* 1-操作成功
* 0-抛出一般异常
* -1-抛出数据库异常
*/
public int getDoctorInfo(String orderBy){
if(orderBy == null || orderBy.equals(""))
orderBy=Patient.NAME;
int res=0;
conn=DBConnection.getConnection();
strSQL="SELECT DID,Name,Age,Sex,Level,Section,Specialism,Phone FROM doctor ORDER BY " + orderBy;
try{
stmt=conn.createStatement();
rs=stmt.executeQuery(strSQL);
result=rs;
res=1;
}
catch(SQLException sqle){
Debug.log(Debug.getExceptionMsg(sqle));
res= -1;
}
catch(Exception e){
res=0;
}
finally{
return res;
}
}
/**
* 获取主治医生信息
*
* 返回值-操作结果:
* 1-操作成功
* 0-抛出一般异常
* -1-抛出数据库异常
*/
public int getCurrentDoctorInfo(){
int res=0;
conn=DBConnection.getConnection();
strSQL="SELECT Name,Age,Sex,Level,Section,Specialism,Phone FROM doctor,history WHERE history.Patient=" +
this.PID + " AND Finished=0 AND doctor.DID=history.Doctor";
try{
stmt=conn.createStatement();
rs=stmt.executeQuery(strSQL);
result=rs;
res=1;
}
catch(SQLException sqle){
Debug.log(Debug.getExceptionMsg(sqle));
res= -1;
}
catch(Exception e){
res=0;
}
finally{
return res;
}
}
/**
* 查询病历
*
* 返回值-操作结果:
* 1-操作结果
* 0-抛出一般异常
* -1-抛出数据库异常
*/
public int getHistory(){
int res=0;
conn=DBConnection.getConnection();
strSQL="SELECT * FROM history WHERE Patient=" + this.PID;
try{
stmt=conn.createStatement();
rs=stmt.executeQuery(strSQL);
res=1;
result=rs;
}
catch(SQLException sqle){
res= -1;
Debug.log(Debug.getExceptionMsg(sqle));
}
catch(Exception e){
res=0;
}
finally{
return res;
}
}
/**
* 预约
*
* 参数:
* did-医生编号
* day-预约日(0为周日,1为周一……)
* ap-上下午(0为上午,1为下午)
*
* 返回值-操作结果:
* 1-操作成功
* 0-抛出一般异常
* -1-抛出数据库异常
* -2-已在相同时间预约相同医生
* -3-day或ap格式错
*/
public synchronized int makeAppointment(String did,int day,int ap){
int res=0;
conn=DBConnection.getConnection();
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String[] days={"SunA","SunP","MonA","MonP","TueA","TueP","WedA","WedP","ThuA","ThuP","FriA","FriP","SatA","SatP"};
int index=0,curpc=0;
try{
if(day < 0 || day > 6 || ap < 0 || ap > 1)
throw new NumberFormatException();
index=day * 2 + ap;
stmt=conn.createStatement();
strSQL=
"SELECT * FROM curappointment WHERE DID='" +
did + "'";
rs=stmt.executeQuery(strSQL);
if(!rs.next() || (curpc=rs.getInt(days[index])) == 0)
throw new NumberFormatException();
strSQL="SELECT Doctor FROM pinqueue WHERE Doctor='" + did + "' AND Patient=" + this.PID + " AND Day=" + day +
" AND AP=" + ap;
rs=stmt.executeQuery(strSQL);
if(rs.next())
throw new IllegalArgumentException();
conn.setAutoCommit(false);
stmt=conn.createStatement();
strSQL="INSERT INTO pinqueue (Patient,Doctor,Day,AP,Date) VALUES (" + this.PID + ",'" + did + "'," + day + "," +
ap + ",'" + dateFormat.format(new java.util.Date()) + "')";
stmt.addBatch(strSQL);
strSQL="UPDATE curappointment SET " + days[index] + "=" + (curpc - 1) + " WHERE DID='" + did + "'";
stmt.addBatch(strSQL);
stmt.executeBatch();
conn.commit();
res=1;
}
catch(NumberFormatException nfe){
res= -3;
}
catch(SQLException sqle){
conn.rollback();
res= -1;
Debug.log(Debug.getExceptionMsg(sqle));
}
catch(IllegalArgumentException iae){
res= -2;
}
catch(Exception e){
Debug.log(Debug.getExceptionMsg(e));
res=0;
}
finally{
return res;
}
}
/**
* 取消预约
*
* 参数:
* qid-预约编号
*
* 返回值-操作结果:
* 1-操作结果
* 0-抛出一般异常
* -1-抛出数据库异常
*/
public synchronized int cancleAppointment(int qid){
int res=0;
conn=DBConnection.getConnection();
String[] days={"SunA","SunP","MonA","MonP","TueA","TueP","WedA","WedP","ThuA","ThuP","FriA","FriP","SatA","SatP"};
int index,curpc,day,ap;
String did="";
try{
strSQL="SELECT * FROM pinqueue WHERE QID=" + qid;
stmt=conn.createStatement();
rs=stmt.executeQuery(strSQL);
if(!rs.next())
throw new SQLException("QID does not exist.");
day=rs.getInt("Day");
ap=rs.getInt("AP");
did=rs.getString("Doctor");
index=day * 2 + ap;
strSQL="SELECT * FROM curappointment WHERE DID='" + did + "'";
rs=stmt.executeQuery(strSQL);
rs.next();
curpc=rs.getInt(days[index]);
conn.setAutoCommit(false);
stmt=conn.createStatement();
strSQL="DELETE FROM pinqueue WHERE QID=" + qid;
stmt.addBatch(strSQL);
strSQL="UPDATE curappointment SET " + days[index] + "=" + (curpc + 1) + " WHERE DID='" + did + "'";
stmt.addBatch(strSQL);
stmt.executeBatch();
conn.commit();
res=1;
}
catch(SQLException sqle){
conn.rollback();
res= -1;
没有合适的资源?快使用搜索试试~ 我知道了~
yiyuanmenzhen.rar_Java 医_医院门诊_患者_病历_门诊
共79个文件
jsp:27个
log:23个
class:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 41 浏览量
2022-09-22
16:55:16
上传
评论
收藏 537KB RAR 举报
温馨提示
完备的医院门诊系统,有身份验证,患者可以查询预约,退约,查看病历等操作,医生可查看患者情况,修改病历等,管理员管理医生帐号
资源推荐
资源详情
资源评论
收起资源包目录
yiyuanmenzhen.rar (79个子文件)
www.pudn.com.txt 218B
hospital
log
2004-09-21.log 167B
2007-05-18.log 77B
2005-06-03.log 154B
2007-05-31.log 77B
2007-06-06.log 77B
2007-06-05.log 154B
2004-11-09.log 4KB
2007-06-02.log 77B
2004-11-06.log 5KB
2004-09-26.log 75B
2007-05-17.log 154B
2004-10-03.log 534B
2007-05-21.log 77B
2004-09-27.log 36B
2004-11-10.log 2KB
2004-09-23.log 212B
2007-05-16.log 848B
2004-11-08.log 77B
2004-09-24.log 75B
2007-06-04.log 77B
2007-05-23.log 77B
2004-10-02.log 75B
2004-11-07.log 2KB
admin
getDoctorInfo.jsp 2KB
addDoctor.jsp 3KB
main.jsp 943B
removeDoctor.jsp 2KB
login.jsp 2KB
logout.jsp 241B
images
LEFTBAR.GIF 2KB
TOPBAR.GIF 17KB
Thumbs.db 57KB
WEB-INF
web.xml 717B
classes
hospital
db
Util.class 1KB
dboperation
Admin.java 6KB
Patient.class 10KB
Doctor.class 9KB
DBOperation.java~1~ 1KB
Patient.java 10KB
DBOperation.java 1KB
Doctor.java 9KB
DBOperation.class 1KB
InvalidUserException.class 465B
InvalidUserException.java 284B
Admin.class 6KB
Debug.class 3KB
InitServlet.class 914B
DBConnection.class 1KB
lib
mysql-connector-java-3.0.8-stable-bin.jar 210KB
mm.mysql-2.0.4-bin.jar 107KB
jdbc-mysql.jar 65KB
jdom-b6.jar 77KB
include
admin.inc 762B
doctor.inc 979B
ccs.inc 283B
head.inc 688B
patient.inc 1KB
patient
getDoctorInfo.jsp 2KB
main.jsp 947B
getHistory.jsp 2KB
login.jsp 2KB
cancleAppointment.jsp 2KB
makeAppointment.jsp 2KB
register.jsp 3KB
getDoctorAppointmentInfo.jsp 3KB
logout.jsp 280B
getAppointmentInfo.jsp 2KB
getCurrentDoctorInfo.jsp 2KB
doctor
getPatientInQueue.jsp 2KB
main.jsp 945B
updatePassword.jsp 2KB
updateHistory.jsp 2KB
login.jsp 2KB
finishHistory.jsp 2KB
getPatientHistory.jsp 2KB
createHistory.jsp 2KB
logout.jsp 259B
default.jsp 2KB
共 79 条
- 1
资源评论
四散
- 粉丝: 52
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 实验二:IP协议分析.zip
- 驱动代码驱动代码驱动代码驱动代码
- SVID_20240523_141155_1.mp4
- Code for the complete guide to tkinter tutorial
- 关于百货中心供应链管理系统.zip
- SimpleFolderIcon-master 修改Unity的Project下的文件夹图标
- A python Tkinter widget to display tile based maps
- A pure Python library for adding tables to a Tkinter application
- Vector资源文件.zip
- MobaXterm-Installer
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功