⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 patient.java

📁 基于java的医院门诊管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		} finally {
			closeConnection();
		}
	}

	//r:重复预约
	//n:当日未提供预约
	//f:已达最大预约量
	//o:当日预约总量超出10000,应该不会发生
	// 返回预约号,或者不能重复预约的信息
	public String reserve(String docID, Date resDate) throws SQLException,
			RecordsNotExistException {
		String abbr;
		String sql;
		// String sectionName;
		int sum;
		final int MAX_PER_DAY = 10000;
		Connection conn = null;
		CallableStatement stmt = null;

		try {
			// 获取医生的科室号码
			conn = DBConnection.getConnection();
			stmt = conn.prepareCall("{?=call getSecAbbr(?)}");
			stmt.registerOutParameter(1, Types.VARCHAR);
			stmt.setString(2, docID);
			stmt.execute();
			abbr=stmt.getString(1);

			// 检查是否有重复的预约
			sql = "Select * From Reservation" + " Where DoctorID = '" + docID
					+ "'" + " and PatientID = '" + this.userName + "'"
					+ " and resDate = '" + DateConvert.convert(resDate) + "'";
			executeQuery(sql);
			if (result.next())
				return "r";

			// 检查是否有空闲
			sql = "Select Maximum, Reserved From Schedule" + " Where SDate = '"
					+ DateConvert.convert(resDate) + "'" + "	and DoctorID = '"
					+ docID + "'";
			executeQuery(sql);
			if (!result.next())
				return "n";
			else if (result.getInt("Maximum") <= result.getInt("Reserved"))
				return "f";

			// 获得今天所有预约的总数,计算当日序列号
			sql = "Select Sum(Reserved) From Schedule" + " Where SDate = '"
					+ DateConvert.convert(resDate) + "'";
			// System.out.println(sql);
			executeQuery(sql);
			result.next();
			if (result.getInt(1) < MAX_PER_DAY)
				sum = MAX_PER_DAY + result.getInt(1);
			else
				return "o";

			// 写数据库,返回预约号
			String resNO = abbr + DateConvert.toString(resDate) + sum;
			sql = "Insert into Reservation(ResNO, DoctorID, PatientID, ResDate, Mark, Confirmed)"
					+ " Values('"
					+ resNO
					+ "', '"
					+ docID
					+ "', '"
					+ this.userName
					+ "', '"
					+ DateConvert.convert(resDate)
					+ "', 0, 'n');"
					+ "Update Schedule"
					+ " Set Reserved = Reserved + 1"
					+ " Where DoctorID = '"
					+ docID
					+ "' and SDate = '"
					+ DateConvert.convert(resDate)
					+ "'";
			executeUpdate(sql);

			return resNO;
		} catch (SQLException e) {
			throw e;
		} finally {
			conn.close();
			stmt.close();
			closeConnection();
		}
	}

	

	public CaseInfo getCase(String caseno) throws SQLException,
			RecordsNotExistException {
		String sql = "Select * From Cases "
				+ " Where CaseNO = '"
				+ caseno + "'" + " and Finished = 'y'";

		try {
			executeQuery(sql);
			if (result.next()) {
				CaseInfo info = new CaseInfo();
				info.setCaseID(caseno);
				info.setDescription(result.getString("Description"));
				info.setDiagnose(result.getString("Diagnose"));
				info.setPrescription(result.getString("Prescription"));
				info.setFinish(result.getString("Finished").charAt(0));
				return info;
			} else {
				throw new RecordsNotExistException();
			}
		} finally {
			closeConnection();
		}
	}

	public void cancelRes(String resno) throws SQLException,
			RecordsNotExistException {
		Date date;
		String did;

		try {
			// 检查该预约是否存在
			String sql = "Select * From Reservation Where ResNO = '" + resno
					+ "'";
			executeQuery(sql);
			if (result.next()) {
				date = result.getDate("ResDate");
				did = result.getString("DoctorID");
			} else {
				throw new RecordsNotExistException();
			}
			// 更新数据库
			sql = "Delete from Reservation where ResNO = '" + resno + "';"
					+ "Update Schedule Set Reserved = Reserved - 1"
					+ " Where DoctorID = '" + did + "'" + " and SDate = '"
					+ DateConvert.convert(date) + "'";
			// System.out.println(sql);
			executeUpdate(sql);
		} catch (SQLException e) {
			throw e;
		} finally {
			closeConnection();
		}

	}

	public boolean mark(String resno, int mark) throws SQLException,
			RecordsNotExistException {
		boolean res = true;

		try {
			// 检查该预约是否存在
			String sql = "Select * From Reservation Where ResNO = '" + resno
					+ "'";
			executeQuery(sql);
			if (result.next()) {
				if (result.getString("Confirmed").charAt(0) == 'n') {
					res = false;
				} else {
					sql = "Update Reservation Set Mark = " + mark
							+ " Where ResNO = '" + resno + "'"
							+ " and Confirmed = 'y'";
					executeUpdate(sql);
				}
			} else {
				throw new RecordsNotExistException();
			}
		} catch (SQLException e) {
			throw e;
		} finally {
			closeConnection();
		}

		return res;
	}

	
	// DoctorInfo:医生信息
	// SQLException:数据库异常
	// RecordsNotExistException:记录不存在
	public DoctorInfo searchDoctor(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();
		}
	}

	// Page:医生信息的集合
	// SQLException:数据库异常
	// RecordsNotExistException:记录不存在
	public Page searchDoctor(String name, int secID, String gender, int title,
			Date date, boolean valiable) throws SQLException,
			RecordsNotExistException {
		String sql = null;
		if (valiable)
			sql = "Select UserName, DName, Gender, Age, SName, TName from Doctor, Section, Title, Schedule "
					+ "where Doctor.SectionNO=Section.SectionNO"
					+ " and Doctor.Title=TitleNO and Schedule.DoctorID=Doctor.UserName and Schedule.SDate='"
					+ DateConvert.convert(date)
					+ "' and Maximum>Reserved "
					+ (name.equals("all") ? " " : (" and DName='" + name + "'"))
					+ (secID == 0 ? " " : (" and Doctor.SectionNO=" + secID))
					+ " and Gender='"
					+ gender
					+ "'"
					+ (title == 0 ? " " : (" and Doctor.Title=" + title));
		else
			sql = "Select UserName, DName, Gender, Age, SName, TName from Doctor, Section, Title "
					+ "where Doctor.SectionNO=Section.SectionNO and Doctor.Title=TitleNO"
					+ (name.equals("all") ? " " : (" and DName='" + name + "'"))
					+ (secID == 0 ? " " : (" and Doctor.SectionNO=" + secID))
					+ " and Gender='"
					+ gender
					+ "'"
					+ (title == 0 ? " " : (" and Doctor.Title=" + title));
		try {
			executeQuery(sql);
			if (result.next()) {
				DoctorInfo di = null;
				ArrayList al = new ArrayList();
				do {
					di = new DoctorInfo();
					di.setUserName(result.getString("UserName"));
					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"));
					al.add(di);
				} while (result.next());
				return new Page(al);
			} else
				throw new RecordsNotExistException();
		} finally {
			closeConnection();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -