目录
1 要求
2 创建项目与模块
2.1 创建项目
2.2 创建模块
2.3 创建包
3 新增实体类
3.1 看诊排班信息Schedule类
3.2 医生Doctor类
3.3 科室Department类
3.4 预约信息Appointment类
4 新增实现HospitalManager类
4.1 新增欢迎信息
4.2 添加科室addDepartment方法
4.3 添加医生
4.3.1 封装选择科室getDepartmentByUser方法
4.3.2 添加医生方法addDoctor
4.4 添加医生坐诊
4.4.1 封装更新当前到未来6天时间的updateSchedules方法
4.4.2 封装更新每一天坐诊详情updateDoctorSchedule方法
4.4.3 添加医生坐诊setDoctorJob方法
4.5 新增全部医生坐诊详情showAllDoctorInfo方法
5 主函数APP
前言:通过高级的学习,通过医院挂号系统来巩固学习知识点
1 要求
2 创建项目与模块
2.1 创建项目
略
2.2 创建模块
略
2.3 创建包
略
3 新增实体类
3.1 看诊排班信息Schedule类
package com.runa.bean;
import java.time.LocalDate;
import java.time.LocalTime;
public class Schedule {
// 某一天
private LocalDate toaday;
private boolean update; //是否排班过,默认未排班
// 上午
private boolean morning; //是否看诊
private LocalTime mstart; // 看诊开始时间 09:00:00
private LocalTime mend; // 看诊结束时间 12:00:00
private int mTotalNumber; // 接诊总人数
private int mAppointNumber; // 当前预约人数
// 下午
private boolean afternoon; //是否看诊
private LocalTime astart; // 看诊开始时间 14:00:00
private LocalTime aend; // 看诊结束时间 17:00:00
private int aTotalNumber; // 接诊总人数
private int aAppointNumber; // 当前预约人数
public LocalDate getToaday() {
return toaday;
}
public void setToaday(LocalDate toaday) {
this.toaday = toaday;
}
public boolean isUpdate() {
return update;
}
public void setUpdate(boolean update) {
this.update = update;
}
public boolean isMorning() {
return morning;
}
public void setMorning(boolean morning) {
this.morning = morning;
}
public LocalTime getMstart() {
return mstart;
}
public void setMstart(LocalTime mstart) {
this.mstart = mstart;
}
public LocalTime getMend() {
return mend;
}
public void setMend(LocalTime mend) {
this.mend = mend;
}
public int getmTotalNumber() {
return mTotalNumber;
}
public void setmTotalNumber(int mTotalNumber) {
this.mTotalNumber = mTotalNumber;
}
public int getmAppointNumber() {
return mAppointNumber;
}
public void setmAppointNumber(int mAppointNumber) {
this.mAppointNumber = mAppointNumber;
}
public boolean isAfternoon() {
return afternoon;
}
public void setAfternoon(boolean afternoon) {
this.afternoon = afternoon;
}
public LocalTime getAstart() {
return astart;
}
public void setAstart(LocalTime astart) {
this.astart = astart;
}
public LocalTime getAend() {
return aend;
}
public void setAend(LocalTime aend) {
this.aend = aend;
}
public int getaTotalNumber() {
return aTotalNumber;
}
public void setaTotalNumber(int aTotalNumber) {
this.aTotalNumber = aTotalNumber;
}
public int getaAppointNumber() {
return aAppointNumber;
}
public void setaAppointNumber(int aAppointNumber) {
this.aAppointNumber = aAppointNumber;
}
}
3.2 医生Doctor类
package com.runa.bean;
import java.time.LocalDate;
import java.util.ArrayList;
// 医生类
public class Doctor {
private String docrotId; // 编号
private String name; // 姓名
private String departmentName; //部门
private String gender; // 性别
private String age; //年龄
private String specialty; // 主治方向
private LocalDate joinDate; //入职日期
private ArrayList<Schedule> schedules = new ArrayList<>();
public String getDocrotId() {
return docrotId;
}
public void setDocrotId(String docrotId) {
this.docrotId = docrotId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSpecialty() {
return specialty;
}
public void setSpecialty(String specialty) {
this.specialty = specialty;
}
public LocalDate getJoinDate() {
return joinDate;
}
public void setJoinDate(LocalDate joinDate) {
this.joinDate = joinDate;
}
public ArrayList<Schedule> getSchedules() {
return schedules;
}
public void setSchedules(ArrayList<Schedule> schedules) {
this.schedules = schedules;
}
}
3.3 科室Department类
package com.runa.bean;
import java.util.ArrayList;
// 科室类
public class Department {
private String name; // 科室名
private ArrayList<Doctor> doctors = new ArrayList<>(); //医生集合
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<Doctor> getDoctors() {
return doctors;
}
public void setDoctors(ArrayList<Doctor> doctors) {
this.doctors = doctors;
}
}
3.4 预约信息Appointment类
package com.runa.bean;
import java.time.LocalDateTime;
// 预约类
public class Appointment {
// 包含预约信息、患者信息、所选医生、状态等属性
private String username; //患者姓名
private char sex; //患者性别
private int age; //患者年龄
private String tel; //患者电话
private String desc; //病情描述
private String departName; // 所挂科室名称
private String doctorId; // 所挂医生编号
private LocalDateTime appointDataTime; // 预约时间
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getDepartName() {
return departName;
}
public void setDepartName(String departName) {
this.departName = departName;
}
public String getDoctorId() {
return doctorId;
}
public void setDoctorId(String doctorId) {
this.doctorId = doctorId;
}
public LocalDateTime getAppointDataTime() {
return appointDataTime;
}
public void setAppointDataTime(LocalDateTime appointDataTime) {
this.appointDataTime = appointDataTime;
}
}
4 新增实现HospitalManager类
4.1 新增欢迎信息
package com.runa.frame;
import com.runa.bean.Appointment;
import com.runa.bean.Department;
import java.util.ArrayList;
import java.util.Scanner;
public class HospitalManager {
// 1 系统需要存储全部科室信息
private ArrayList<Department> alldepartments = new ArrayList<>();
// 2 系统需要记录全部的预约详情
private ArrayList<Appointment> appointments = new ArrayList<>();
private Scanner sc = new Scanner(System.in);
public void start(){
while (true) {
System.out.println("====欢迎进入新华医院信息管理系统====");
System.out.println("1、 科室管理-添加科室");
System.out.println("2、 科室管理-删除科室");
System.out.println("3、 科室管理-修改科室");
System.out.println("4、 医生管理-录入医生");
System.out.println("5、 医生管理-医生坐诊设置(可设置当天和未来6天的坐诊情况)");
System.out.println("6、 医生管理-展示全部医生的坐诊详情(当天和未来6天的坐诊详情)");
System.out.println("7、 医生管理-挂号预约");
System.out.println("8、 搜索某个医生当前和未来6天内的病人预约详情(展示每天预约病人的具体信息)");
System.out.println("请输入操作命令:");
switch (sc.next()){
case "1":
// addDepartment();
break;
// case "2":
// // addDepartment();
// break;
case "3":
// addDoctor();
break;
// case "4":
// // addDepartment();
// break;
case "5":
// setDoctorJob();
break;
// case "6":
// // addDepartment();
// break;
// case "7":
// // addDepartment();
// break;
// case "8":
// // addDepartment();
// break;
default:
System.out.println("当前输入有误,请重新输入!");
}
}
}
}
4.2 添加科室addDepartment方法
package com.runa.frame;
import com.runa.bean.Appointment;
import com.runa.bean.Department;
import java.util.ArrayList;
import java.util.Scanner;
public class HospitalManager {
// 1 系统需要存储全部科室信息
private ArrayList<Department> alldepartments = new ArrayList<>();
// 2 系统需要记录全部的预约详情
private ArrayList<Appointment> appointments = new ArrayList<>();
private Scanner sc = new Scanner(System.in);
public void start(){
while (true) {
System.out.println("====欢迎进入新华医院信息管理系统====");
System.out.println("1、 科室管理-添加科室");
System.out.println("2、 科室管理-删除科室");
System.out.println("3、 科室管理-修改科室");
System.out.println("4、 医生管理-录入医生");
System.out.println("5、 医生管理-医生坐诊设置(可设置当天和未来6天的坐诊情况)");
System.out.println("6、 医生管理-展示全部医生的坐诊详情(当天和未来6天的坐诊详情)");
System.out.println("7、 医生管理-挂号预约");
System.out.println("8、 搜索某个医生当前和未来6天内的病人预约详情(展示每天预约病人的具体信息)");
System.out.println("请输入操作命令:");
switch (sc.next()){
case "1":
addDepartment();
break;
// case "2":
// // addDepartment();
// break;
case "3":
//
break;
// case "4":
// // addDoctor();
// break;
case "5":
// setDoctorJob();
break;
// case "6":
// //
// break;
// case "7":
// //
// break;
// case "8":
// //
// break;
default:
System.out.println("当前输入有误,请重新输入!");
}
}
}
// 添加科室
private void addDepartment(){
System.out.println("======== 请输入科室名称 ========");
OUT:
while (true) {
System.out.println("请您输入科室名称:");
String name = sc.next();
// 判断名称是否存在
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
if(department.getName().equals(name)) continue OUT;
}
Department department = new Department();
department.setName(name);
alldepartments.add(department);
System.out.println("添加 【" + name + "】 科室成功");
break;
}
}
}
4.3 添加医生
4.3.1 封装选择科室getDepartmentByUser方法
// 封装选择科室
private Department getDepartmentByUser() {
if (alldepartments.size() == 0) return null;
while (true) {
// 1 选择科室
System.out.println("请选择科室");
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
System.out.println((i + 1) + "、" + department.getName());
}
System.out.println("请输入:");
// 2 接收命令
int command = sc.nextInt();
if (command < 1 || command > alldepartments.size()) {
System.out.println("选择有误,请重新确认");
continue;
}
// 3 得到科室
Department department = alldepartments.get(command - 1);
return department;
}
}
4.3.2 添加医生方法addDoctor
package com.runa.frame;
import com.runa.bean.Appointment;
import com.runa.bean.Department;
import com.runa.bean.Doctor;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.UUID;
public class HospitalManager {
// 1 系统需要存储全部科室信息
private ArrayList<Department> alldepartments = new ArrayList<>();
// 2 系统需要记录全部的预约详情
private ArrayList<Appointment> appointments = new ArrayList<>();
private Scanner sc = new Scanner(System.in);
public void start() {
while (true) {
System.out.println("====欢迎进入新华医院信息管理系统====");
System.out.println("1、 科室管理-添加科室");
System.out.println("2、 科室管理-删除科室");
System.out.println("3、 科室管理-修改科室");
System.out.println("4、 医生管理-录入医生");
System.out.println("5、 医生管理-医生坐诊设置(可设置当天和未来6天的坐诊情况)");
System.out.println("6、 医生管理-展示全部医生的坐诊详情(当天和未来6天的坐诊详情)");
System.out.println("7、 医生管理-挂号预约");
System.out.println("8、 搜索某个医生当前和未来6天内的病人预约详情(展示每天预约病人的具体信息)");
System.out.println("请输入操作命令:");
switch (sc.next()) {
case "1":
addDepartment();
break;
// case "2":
// // addDepartment();
// break;
case "3":
break;
case "4":
addDoctor();
break;
case "5":
// setDoctorJob();
break;
case "6":
// showAllDoctorInfo();
break;
// case "7":
// //
// break;
// case "8":
// //
// break;
default:
System.out.println("当前输入有误,请重新输入!");
}
}
}
// 添加科室
private void addDepartment() {
System.out.println("======== 请输入科室名称 ========");
OUT:
while (true) {
System.out.println("请您输入科室名称:");
String name = sc.next();
// 判断名称是否存在
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
if (department.getName().equals(name)) continue OUT;
}
Department department = new Department();
department.setName(name);
alldepartments.add(department);
System.out.println("添加 【" + name + "】 科室成功");
break;
}
}
// 添加医生
private void addDoctor() {
System.out.println("======== 录入医生 ========");
while (true) {
// 选择科室
Department department = getDepartmentByUser();
if(department == null){
System.out.println("当前无任何科室");
return;
}
Doctor doctor = new Doctor();
doctor.setDepartmentName(department.getName());
// 4 录入医生id
doctor.setDocrotId(UUID.randomUUID().toString());
// 输入姓名
System.out.println("请输入医生的姓名:");
String name = sc.next();
doctor.setName(name);
// 输入年龄
System.out.println("请输入医生的年龄:");
String sex = sc.next();
doctor.setAge(sex);
// 特长
System.out.println("请输入医生的特长:");
String specialty = sc.next();
doctor.setSpecialty(specialty);
// 入职日期
System.out.println("请输入医生的入职日期(格式:yyyy-MM-dd):");
String joinDateString = sc.next();
LocalDate joinDate = LocalDate.parse(joinDateString);
doctor.setJoinDate(joinDate);
// 将医生对象加到所在科室对象 第//3步得到了所在部门信息
department.getDoctors().add(doctor);
System.out.println("录入医生到该科室成功");
break;
}
}
// 封装选择科室
private Department getDepartmentByUser() {
if (alldepartments.size() == 0) return null;
while (true) {
// 1 选择科室
System.out.println("请选择科室");
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
System.out.println((i + 1) + "、" + department.getName());
}
System.out.println("请输入:");
// 2 接收命令
int command = sc.nextInt();
if (command < 1 || command > alldepartments.size()) {
System.out.println("选择有误,请重新确认");
continue;
}
// 3 得到科室
Department department = alldepartments.get(command - 1);
return department;
}
}
}
4.4 添加医生坐诊
4.4.1 封装更新当前到未来6天时间的updateSchedules方法
// 封装一个更新当前到未来6天的时间 参数schedules
private void updateSchedules(ArrayList<Schedule> schedules) {
if(schedules.size() == 0){
for (int i = 0; i < 6; i++) {
Schedule schedule = new Schedule();
LocalDate now = LocalDate.now();
schedule.setToaday(now.plusDays(i)); //+1
schedules.add(schedule);
}
return;
}
// 去除过期的时间
for (int i = 0; i < schedules.size(); i++) {
Schedule schedule = schedules.get(i);
LocalDate now = LocalDate.now();
LocalDate current = schedule.getToaday();
if(current.equals(now)){
break;
}
if(current.isBefore(now)){
schedules.remove(schedule);
i--;
}
}
// 补全当前和未来6天的时间【s1, s2, s3,】
LocalDate last = schedules.get(schedules.size() - 1).getToaday();
int size = schedules.size();
for (int i = 0; i < 7 - size; i++) {
Schedule schedule = new Schedule();
schedule.setToaday(last.plusDays(i + 1));
schedules.add(schedule);
}
}
4.4.2 封装更新每一天坐诊详情updateDoctorSchedule方法
// 封装一个更新每一天坐诊详情的方法 参数schedules
private void updateDoctorSchedule(Schedule schedule) {
LocalDate today = schedule.getToaday();
System.out.println(today + "的安排如下:");
if(!schedule.isUpdate()){
System.out.println("未排班\t\t\t");
}else{
System.out.println("\t上午\t");
if(schedule.isMorning()){
System.out.println("坐诊 时间为:" + schedule.getMstart() + "-"
+ schedule.getMend() + "总数/预约数" + schedule.getmTotalNumber() + "/" + schedule.getmAppointNumber());
}else{
System.out.println("休息");
}
System.out.println();
System.out.println("\t下午\t");
if(schedule.isAfternoon()){
System.out.println("坐诊 时间为:" + schedule.getAstart() + "-"
+ schedule.getAend() + "总数/预约数" + schedule.getaTotalNumber() + "/" + schedule.getaAppointNumber());
}else{
System.out.println("休息");
}
}
System.out.println("是否修改? y/n");
String rs = sc.next();
if("y".equals(rs)){
schedule.setUpdate(true); // 表示开始排班了
System.out.println("上午是否上班? y/n");
String rs2 = sc.next();
if("y".equals(rs2)){
schedule.setMorning(true);
System.out.println("上班的开始时间和结束时间是:");
String start = sc.next();
String end = sc.next();
System.out.println("可预约的人数是:");
int number = sc.nextInt();
schedule.setMstart(LocalTime.parse(start));
schedule.setMstart(LocalTime.parse(end));
schedule.setmTotalNumber(number);
}else {
schedule.setMorning(false);
}
System.out.println("下午是否上班? y/n");
String rs3 = sc.next();
if("y".equals(rs3)){
schedule.setMorning(true);
System.out.println("下班的开始时间和结束时间是:");
String start = sc.next();
String end = sc.next();
System.out.println("可预约的人数是:");
int number = sc.nextInt();
schedule.setAstart(LocalTime.parse(start));
schedule.setAstart(LocalTime.parse(end));
schedule.setaTotalNumber(number);
}else {
schedule.setAfternoon(false);
}
}
}
4.4.3 添加医生坐诊setDoctorJob方法
package com.runa.frame;
import com.runa.bean.Appointment;
import com.runa.bean.Department;
import com.runa.bean.Doctor;
import com.runa.bean.Schedule;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.UUID;
public class HospitalManager {
// 1 系统需要存储全部科室信息
private ArrayList<Department> alldepartments = new ArrayList<>();
// 2 系统需要记录全部的预约详情
private ArrayList<Appointment> appointments = new ArrayList<>();
private Scanner sc = new Scanner(System.in);
public void start() {
while (true) {
System.out.println("====欢迎进入新华医院信息管理系统====");
System.out.println("1、 科室管理-添加科室");
System.out.println("2、 科室管理-删除科室");
System.out.println("3、 科室管理-修改科室");
System.out.println("4、 医生管理-录入医生");
System.out.println("5、 医生管理-医生坐诊设置(可设置当天和未来6天的坐诊情况)");
System.out.println("6、 医生管理-展示全部医生的坐诊详情(当天和未来6天的坐诊详情)");
System.out.println("7、 医生管理-挂号预约");
System.out.println("8、 搜索某个医生当前和未来6天内的病人预约详情(展示每天预约病人的具体信息)");
System.out.println("请输入操作命令:");
switch (sc.next()) {
case "1":
addDepartment();
break;
// case "2":
// // ;
// break;
case "3":
break;
case "4":
addDoctor();
break;
case "5":
setDoctorJob();
break;
case "6":
// showAllDoctorInfo();
break;
// case "7":
// //
// break;
// case "8":
// //
// break;
default:
System.out.println("当前输入有误,请重新输入!");
}
}
}
// 添加科室
private void addDepartment() {
System.out.println("======== 请输入科室名称 ========");
OUT:
while (true) {
System.out.println("请您输入科室名称:");
String name = sc.next();
// 判断名称是否存在
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
if (department.getName().equals(name)) continue OUT;
}
Department department = new Department();
department.setName(name);
alldepartments.add(department);
System.out.println("添加 【" + name + "】 科室成功");
break;
}
}
// 添加医生
private void addDoctor() {
System.out.println("======== 录入医生 ========");
while (true) {
// 选择科室
Department department = getDepartmentByUser();
if(department == null){
System.out.println("当前无任何科室");
return;
}
Doctor doctor = new Doctor();
doctor.setDepartmentName(department.getName());
// 4 录入医生id
doctor.setDocrotId(UUID.randomUUID().toString());
// 输入姓名
System.out.println("请输入医生的姓名:");
String name = sc.next();
doctor.setName(name);
// 输入年龄
System.out.println("请输入医生的年龄:");
String sex = sc.next();
doctor.setAge(sex);
// 特长
System.out.println("请输入医生的特长:");
String specialty = sc.next();
doctor.setSpecialty(specialty);
// 入职日期
System.out.println("请输入医生的入职日期(格式:yyyy-MM-dd):");
String joinDateString = sc.next();
LocalDate joinDate = LocalDate.parse(joinDateString);
doctor.setJoinDate(joinDate);
// 将医生对象加到所在科室对象 第//3步得到了所在部门信息
department.getDoctors().add(doctor);
System.out.println("录入医生到该科室成功");
break;
}
}
// 封装选择科室
private Department getDepartmentByUser() {
if (alldepartments.size() == 0) return null;
while (true) {
// 1 选择科室
System.out.println("请选择科室");
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
System.out.println((i + 1) + "、" + department.getName());
}
System.out.println("请输入:");
// 2 接收命令
int command = sc.nextInt();
if (command < 1 || command > alldepartments.size()) {
System.out.println("选择有误,请重新确认");
continue;
}
// 3 得到科室
Department department = alldepartments.get(command - 1);
return department;
}
}
private void setDoctorJob(){
System.out.println("======== 设置医生的坐诊时间 ========");
// 1 选择科室 ,调用封装的方法
Department department = getDepartmentByUser();
// 2 选择医生
ArrayList<Doctor> doctors = department.getDoctors();
if(doctors.size() == 0){
System.out.println("当前科室下无医生~");
return;
}
while (true){
System.out.println("当前科室下的医生信息如下:");
for (int i = 0; i < doctors.size(); i++) {
Doctor doctor = doctors.get(i);
System.out.println((i + 1 ) + "、" + doctor.getName());
}
System.out.println("请输入需要设置坐诊医生的序号:");
// 3 接收命令
int command = sc.nextInt();
if(command < 1 || command > doctors.size()){
System.out.println("选择有误,请重新输入~");
continue;
}
Doctor doctor = doctors.get(command - 1);
// 4 为这个医生设置坐诊情况
ArrayList<Schedule> schedules = doctor.getSchedules();
// 更新当前到未来6天的时间 ,调用封装的方法
updateSchedules(schedules);
// 5 修改坐诊信息,依次展示这个医生的坐诊详情,为每一天的坐诊添加详情
for (int i = 0; i < schedules.size(); i++) {
Schedule schedule = schedules.get(i);
updateDoctorSchedule(schedule);
}
break;
}
}
// 封装一个更新每一天坐诊详情的方法 参数schedules
private void updateDoctorSchedule(Schedule schedule) {
LocalDate today = schedule.getToaday();
System.out.println(today + "的安排如下:");
if(!schedule.isUpdate()){
System.out.println("未排班\t\t\t");
}else{
System.out.println("\t上午\t");
if(schedule.isMorning()){
System.out.println("坐诊 时间为:" + schedule.getMstart() + "-"
+ schedule.getMend() + "总数/预约数" + schedule.getmTotalNumber() + "/" + schedule.getmAppointNumber());
}else{
System.out.println("休息");
}
System.out.println();
System.out.println("\t下午\t");
if(schedule.isAfternoon()){
System.out.println("坐诊 时间为:" + schedule.getAstart() + "-"
+ schedule.getAend() + "总数/预约数" + schedule.getaTotalNumber() + "/" + schedule.getaAppointNumber());
}else{
System.out.println("休息");
}
}
System.out.println("是否修改? y/n");
String rs = sc.next();
if("y".equals(rs)){
schedule.setUpdate(true); // 表示开始排班了
System.out.println("上午是否上班? y/n");
String rs2 = sc.next();
if("y".equals(rs2)){
schedule.setMorning(true);
System.out.println("上班的开始时间和结束时间是:");
String start = sc.next();
String end = sc.next();
System.out.println("可预约的人数是:");
int number = sc.nextInt();
schedule.setMstart(LocalTime.parse(start));
schedule.setMstart(LocalTime.parse(end));
schedule.setmTotalNumber(number);
}else {
schedule.setMorning(false);
}
System.out.println("下午是否上班? y/n");
String rs3 = sc.next();
if("y".equals(rs3)){
schedule.setMorning(true);
System.out.println("下班的开始时间和结束时间是:");
String start = sc.next();
String end = sc.next();
System.out.println("可预约的人数是:");
int number = sc.nextInt();
schedule.setAstart(LocalTime.parse(start));
schedule.setAstart(LocalTime.parse(end));
schedule.setaTotalNumber(number);
}else {
schedule.setAfternoon(false);
}
}
}
// 封装一个更新当前到未来6天的时间 参数schedules
private void updateSchedules(ArrayList<Schedule> schedules) {
if(schedules.size() == 0){
for (int i = 0; i < 6; i++) {
Schedule schedule = new Schedule();
LocalDate now = LocalDate.now();
schedule.setToaday(now.plusDays(i)); //+1
schedules.add(schedule);
}
return;
}
// 去除过期的时间
for (int i = 0; i < schedules.size(); i++) {
Schedule schedule = schedules.get(i);
LocalDate now = LocalDate.now();
LocalDate current = schedule.getToaday();
if(current.equals(now)){
break;
}
if(current.isBefore(now)){
schedules.remove(schedule);
i--;
}
}
// 补全当前和未来6天的时间【s1, s2, s3,】
LocalDate last = schedules.get(schedules.size() - 1).getToaday();
int size = schedules.size();
for (int i = 0; i < 7 - size; i++) {
Schedule schedule = new Schedule();
schedule.setToaday(last.plusDays(i + 1));
schedules.add(schedule);
}
}
}
4.5 新增全部医生坐诊详情showAllDoctorInfo方法
package com.runa.frame;
import com.runa.bean.Appointment;
import com.runa.bean.Department;
import com.runa.bean.Doctor;
import com.runa.bean.Schedule;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.UUID;
public class HospitalManager {
// 1 系统需要存储全部科室信息
private ArrayList<Department> alldepartments = new ArrayList<>();
// 2 系统需要记录全部的预约详情
private ArrayList<Appointment> appointments = new ArrayList<>();
private Scanner sc = new Scanner(System.in);
public void start() {
while (true) {
System.out.println("====欢迎进入新华医院信息管理系统====");
System.out.println("1、 科室管理-添加科室");
System.out.println("2、 科室管理-删除科室");
System.out.println("3、 科室管理-修改科室");
System.out.println("4、 医生管理-录入医生");
System.out.println("5、 医生管理-医生坐诊设置(可设置当天和未来6天的坐诊情况)");
System.out.println("6、 医生管理-展示全部医生的坐诊详情(当天和未来6天的坐诊详情)");
System.out.println("7、 医生管理-挂号预约");
System.out.println("8、 搜索某个医生当前和未来6天内的病人预约详情(展示每天预约病人的具体信息)");
System.out.println("请输入操作命令:");
switch (sc.next()) {
case "1":
addDepartment();
break;
// case "2":
// // ;
// break;
case "3":
break;
case "4":
addDoctor();
break;
case "5":
setDoctorJob();
break;
case "6":
showAllDoctorInfo();
break;
// case "7":
// //
// break;
// case "8":
// //
// break;
default:
System.out.println("当前输入有误,请重新输入!");
}
}
}
// 展示全部医生的坐诊详情
private void showAllDoctorInfo() {
System.out.println("======== 全部医生坐诊的详情如下 ========");
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
System.out.println((i + 1) + ", " + department.getName());
System.out.println("-----------------------------------------------------------------------------------");
ArrayList<Doctor> doctors = department.getDoctors();
for (int j = 0; j < doctors.size(); j++) {
Doctor doctor = doctors.get(i);
System.out.println(doctor.getName() + "医生的坐诊信息如下:");
ArrayList<Schedule> schedules = doctor.getSchedules();
updateSchedules(schedules); //更新一下时间
for (int k = 0; k < schedules.size(); k++) {
Schedule schedule = schedules.get(k);
System.out.println(schedule.getToaday());
if(!schedule.isUpdate()){
System.out.println("未排班\t\t\t");
continue;
}
if(schedule.isMorning()){
System.out.println("上午" + schedule.getMstart() + "-" + schedule.getMend()
+ " 总数/已预约" + schedule.getmTotalNumber() + "/" + schedule.getmTotalNumber());
} else {
System.out.println("上午 休息");
}
if(schedule.isAfternoon()){
System.out.println("下午" + schedule.getAstart() + "-" + schedule.getAend()
+ " 总数/已预约" + schedule.getaTotalNumber() + "/" + schedule.getaTotalNumber());
} else {
System.out.println("下午 休息");
}
}
}
}
}
// 添加科室
private void addDepartment() {
System.out.println("======== 请输入科室名称 ========");
OUT:
while (true) {
System.out.println("请您输入科室名称:");
String name = sc.next();
// 判断名称是否存在
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
if (department.getName().equals(name)) continue OUT;
}
Department department = new Department();
department.setName(name);
alldepartments.add(department);
System.out.println("添加 【" + name + "】 科室成功");
break;
}
}
// 添加医生
private void addDoctor() {
System.out.println("======== 录入医生 ========");
while (true) {
// 选择科室
Department department = getDepartmentByUser();
if(department == null){
System.out.println("当前无任何科室");
return;
}
Doctor doctor = new Doctor();
doctor.setDepartmentName(department.getName());
// 4 录入医生id
doctor.setDocrotId(UUID.randomUUID().toString());
// 输入姓名
System.out.println("请输入医生的姓名:");
String name = sc.next();
doctor.setName(name);
// 输入年龄
System.out.println("请输入医生的年龄:");
String sex = sc.next();
doctor.setAge(sex);
// 特长
System.out.println("请输入医生的特长:");
String specialty = sc.next();
doctor.setSpecialty(specialty);
// 入职日期
System.out.println("请输入医生的入职日期(格式:yyyy-MM-dd):");
String joinDateString = sc.next();
LocalDate joinDate = LocalDate.parse(joinDateString);
doctor.setJoinDate(joinDate);
// 将医生对象加到所在科室对象 第//3步得到了所在部门信息
department.getDoctors().add(doctor);
System.out.println("录入医生到该科室成功");
break;
}
}
// 封装选择科室
private Department getDepartmentByUser() {
if (alldepartments.size() == 0) return null;
while (true) {
// 1 选择科室
System.out.println("请选择科室");
for (int i = 0; i < alldepartments.size(); i++) {
Department department = alldepartments.get(i);
System.out.println((i + 1) + "、" + department.getName());
}
System.out.println("请输入:");
// 2 接收命令
int command = sc.nextInt();
if (command < 1 || command > alldepartments.size()) {
System.out.println("选择有误,请重新确认");
continue;
}
// 3 得到科室
Department department = alldepartments.get(command - 1);
return department;
}
}
private void setDoctorJob(){
System.out.println("======== 设置医生的坐诊时间 ========");
// 1 选择科室 ,调用封装的方法
Department department = getDepartmentByUser();
// 2 选择医生
ArrayList<Doctor> doctors = department.getDoctors();
if(doctors.size() == 0){
System.out.println("当前科室下无医生~");
return;
}
while (true){
System.out.println("当前科室下的医生信息如下:");
for (int i = 0; i < doctors.size(); i++) {
Doctor doctor = doctors.get(i);
System.out.println((i + 1 ) + "、" + doctor.getName());
}
System.out.println("请输入需要设置坐诊医生的序号:");
// 3 接收命令
int command = sc.nextInt();
if(command < 1 || command > doctors.size()){
System.out.println("选择有误,请重新输入~");
continue;
}
Doctor doctor = doctors.get(command - 1);
// 4 为这个医生设置坐诊情况
ArrayList<Schedule> schedules = doctor.getSchedules();
// 更新当前到未来6天的时间 ,调用封装的方法
updateSchedules(schedules);
// 5 修改坐诊信息,依次展示这个医生的坐诊详情,为每一天的坐诊添加详情
for (int i = 0; i < schedules.size(); i++) {
Schedule schedule = schedules.get(i);
updateDoctorSchedule(schedule);
}
break;
}
}
// 封装一个更新每一天坐诊详情的方法 参数schedules
private void updateDoctorSchedule(Schedule schedule) {
LocalDate today = schedule.getToaday();
System.out.println(today + "的安排如下:");
if(!schedule.isUpdate()){
System.out.println("未排班\t\t\t");
}else{
System.out.println("\t上午\t");
if(schedule.isMorning()){
System.out.println("坐诊 时间为:" + schedule.getMstart() + "-"
+ schedule.getMend() + "总数/预约数" + schedule.getmTotalNumber() + "/" + schedule.getmAppointNumber());
}else{
System.out.println("休息");
}
System.out.println();
System.out.println("\t下午\t");
if(schedule.isAfternoon()){
System.out.println("坐诊 时间为:" + schedule.getAstart() + "-"
+ schedule.getAend() + "总数/预约数" + schedule.getaTotalNumber() + "/" + schedule.getaAppointNumber());
}else{
System.out.println("休息");
}
}
System.out.println("是否修改? y/n");
String rs = sc.next();
if("y".equals(rs)){
schedule.setUpdate(true); // 表示开始排班了
System.out.println("上午是否上班? y/n");
String rs2 = sc.next();
if("y".equals(rs2)){
schedule.setMorning(true);
System.out.println("上班的开始时间和结束时间是:");
String start = sc.next();
String end = sc.next();
System.out.println("可预约的人数是:");
int number = sc.nextInt();
schedule.setMstart(LocalTime.parse(start));
schedule.setMstart(LocalTime.parse(end));
schedule.setmTotalNumber(number);
}else {
schedule.setMorning(false);
}
System.out.println("下午是否上班? y/n");
String rs3 = sc.next();
if("y".equals(rs3)){
schedule.setMorning(true);
System.out.println("下班的开始时间和结束时间是:");
String start = sc.next();
String end = sc.next();
System.out.println("可预约的人数是:");
int number = sc.nextInt();
schedule.setAstart(LocalTime.parse(start));
schedule.setAstart(LocalTime.parse(end));
schedule.setaTotalNumber(number);
}else {
schedule.setAfternoon(false);
}
}
}
// 封装一个更新当前到未来6天的时间 参数schedules
private void updateSchedules(ArrayList<Schedule> schedules) {
if(schedules.size() == 0){
for (int i = 0; i < 6; i++) {
Schedule schedule = new Schedule();
LocalDate now = LocalDate.now();
schedule.setToaday(now.plusDays(i)); //+1
schedules.add(schedule);
}
return;
}
// 去除过期的时间
for (int i = 0; i < schedules.size(); i++) {
Schedule schedule = schedules.get(i);
LocalDate now = LocalDate.now();
LocalDate current = schedule.getToaday();
if(current.equals(now)){
break;
}
if(current.isBefore(now)){
schedules.remove(schedule);
i--;
}
}
// 补全当前和未来6天的时间【s1, s2, s3,】
LocalDate last = schedules.get(schedules.size() - 1).getToaday();
int size = schedules.size();
for (int i = 0; i < 7 - size; i++) {
Schedule schedule = new Schedule();
schedule.setToaday(last.plusDays(i + 1));
schedules.add(schedule);
}
}
}
5 主函数APP
package com.runa;
import com.runa.frame.HospitalManager;
public class APP {
public static void main(String[] args) {
// 1 创建医院管理对象
HospitalManager h = new HospitalManager();
h.start();
}
}