首先我们要建立五个对象
1.医生
private String doctorid ;//编号
private String name ;
private String departmentName;//科室
private String gender;//性别
private int age;
private String sprecialty;//主治方向
private LocalDate joinDate;//入职时间
private ArrayList<Schedule> schedules = new ArrayList<>();
2.日程安排
private LocalDate today;
private boolean update;//是否排班过,默认未排班
//上午
private boolean morning;//是否看诊
private LocalTime mstart;
private LocalTime mend;
private int mTotalNumber;//全部人数
private int mAppointNumber;//预约人数
//下午
private boolean afternoon;//是否看诊
private LocalTime astart;
private LocalTime aend;
private int aTotalNumber;//全部人数
private int aAppointNumber;//预约人数
3.科室
//科室类
private String name;
private ArrayList<Doctor> doctors = new ArrayList<>();
4.预约信息:包含预约时间,患者信息,所选医生,状态等属性
//包含预约时间,患者信息,所选医生,状态等属性
private String userName;
private char sex;
private int age;
private String tel;
private String desc;
private String departName;
private String doctorId;
private LocalDateTime appointDateTime;
5.系统
//1.系统需要储存全部信息
private ArrayList<Department> allDepartments = new ArrayList();
//2.系统需要储存全部预约信息
private ArrayList<Appointment> allAppointments = new ArrayList();
private Scanner input = new Scanner(System.in);
然后我们开始在医院系统导包
package frame; import bean.Appointment; import bean.Department; import bean.Doctor; import bean.Schedule; import jdk.swing.interop.SwingInterOpUtils; import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Scanner; import java.util.UUID;
1.设置start功能函数
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("请输入操作命令:");
Scanner sc = new Scanner(System.in);
switch (input.next()) {
case "1":
addDepartment();
break;
case "2":
deleteDepartment();
break;
case "3":
break;
case "4":
addDector();
break;
case "5":
setDoctorjob();
break;
case "6":
showAllDoctoerInfos();
break;
case "7":
appointmentDoctor();
break;
case "8":
SearchDoctorInfos();
break;
default:
System.out.println("当前输入指令错误,请重新输入!");
}
}
}
2.展示所有医生的坐诊信息功能函数
private void showAllDoctoerInfos() {
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(j);
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.getToday());//获取今天日期
if (!schedule.isUpdate()) //是否排班过
{
System.out.println("未排班~~~~~~\t\t\t");
continue;
}
if (schedule.isMorning()) {
System.out.println("上午" + schedule.getMstart() + "-" + schedule.getMend() + "已预约/总数" + schedule.getmTotalNumber() + "/" +schedule.getmAppointNumber() );
} else {
System.out.println("上午休息");
}
if (schedule.isAfternoon()) {
System.out.println("下午" + schedule.getAstart() + "-" + schedule.getAend() + "已预约/总数" + schedule.getaTotalNumber() + "/" + schedule.getaAppointNumber());
}
}
}
}
}
3.设置医生坐诊时间
public void setDoctorjob() {
System.out.println("=======设置医生坐诊时间=======");
Department department = getDepartmentByUser();
//选择医生
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("请输入数字选择医生:");
//2.接受命令
int commend = input.nextInt();
if (commend < 1 || commend > doctors.size()) {
System.out.println("输入有误,请重新输入!!!");
continue;
}
Doctor doctor = doctors.get(commend - 1);
//3.为这个医生设置未来七天的坐诊情况
ArrayList<Schedule> schedules = doctor.getSchedules();
//更新未来七天时间
updateSchedules(schedules);
//4.修改坐诊信息,依次展示这个医生的坐诊信息
for (int k = 0; k < schedules.size(); k++) {
Schedule schedule = schedules.get(k);
updateDoctorSchedule(schedule);
}
break;
}
}
4.设置医生坐诊时间功能函数
private void updateDoctorSchedule(Schedule schedule) {
LocalDate today = schedule.getToday();
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() + "已预约/总数:\t" +schedule.getmTotalNumber() + "/" + schedule.getmAppointNumber() );
} else {
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 answer = input.next();
if (answer.equals("y")) {
schedule.setUpdate(true);
System.out.println("上午是否上班?y/n");
String answer2 = input.next();
if (answer2.equals("y")) {
schedule.setMorning(true);
System.out.println("上班的开始时间和结束时间是:");
String start = input.next();
String end = input.next();
System.out.println("可预约人数是:");
int appointNumber = input.nextInt();
schedule.setMstart(LocalTime.parse(start));
schedule.setMend(LocalTime.parse(end));
schedule.setmAppointNumber(appointNumber);
} else {
schedule.setMorning(false);
}
System.out.println("下午是否上班?y/n");
String answer3 = input.next();
if (answer3.equals("y")) {
schedule.setAfternoon(true);
System.out.println("上班的开始时间和结束时间是:");
String start = input.next();
String end = input.next();
System.out.println("可预约人数是:");
int appointNumber = input.nextInt();
schedule.setAstart(LocalTime.parse(start));
schedule.setAend(LocalTime.parse(end));
schedule.setaAppointNumber(appointNumber);
} else {
schedule.setAfternoon(false);
}
}
}
5.更新日程功能函数
private void updateSchedules(ArrayList<Schedule> schedules) {
if (schedules.size() == 0) {
for (int i = 0; i <= 6; i++) {
Schedule schedule = new Schedule();//创建一个新的 Schedule 对象,并将其存储在名为 schedule 的变量中。
LocalDate today = LocalDate.now();//获取当前的日期,并将其存储在 now 变量中。
schedule.setToday(today.plusDays(i));//将 schedule 对象的日期设置为当前日期加 i 天后的日期。
schedules.add(schedule);//将配置好的 schedule 对象添加到 schedules 列表中。
}
return;
}
// 去除过期的时间
for (int i = 0; i < schedules.size(); i++) {
Schedule schedule = schedules.get(i);//现有日程赋值给schedule
LocalDate now = LocalDate.now();//获取当前日期
LocalDate current = schedule.getToday();
if (current.equals(now)) {//如果找到第一个与当前日期相同的时间表,意味着后面的时间表都在未来,因此停止删除。
break;
}
if (current.isBefore(now)) {//如果某个日期早于当前日期,将其从列表中移除。
schedules.remove(schedule);
i--;
}
}
// 补全当前和未来6天的时间 【s1, s2, s3,】
LocalDate last = schedules.get(schedules.size() - 1).getToday();//获取列表中最后一个时间表的日期。
int size = schedules.size();
for (int i = 0; i < 7 - size; i++) {//7 - size 确定还需要补充多少天的时间表。
Schedule schedule = new Schedule();
schedule.setToday(last.plusDays(i + 1));//last.plusDays(i + 1) 通过加上适当的天数,创建新的日期
schedules.add(schedule);
}
}
6.选择科室
//选择科室
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 commend = input.nextInt();
if (commend < 1 || commend > allDepartments.size()) {
System.out.println("选择有误!");
continue;
}
Department department = allDepartments.get(commend - 1);//得到科室
return department;
}
}
7.录入医生
private void addDector() {
System.out.println("=======录入医生========");
while (true) {
//1.选择科室
Department department = getDepartmentByUser();
if (department == null) {
return;
}
Doctor doctor = new Doctor();
doctor.setDepartmentName(department.getName());
//录入医生ID
doctor.setDoctorid(UUID.randomUUID().toString());
System.out.println("请输入医生的姓名:");
String name = input.next();
doctor.setName(name);
System.out.println("请输入医生的性别:");
String sex = input.next();
doctor.setGender(sex);
System.out.println("请输入医生的年龄:");
int age = input.nextInt();
doctor.setAge(age);
System.out.println("请输入医生的特长:");
String specialty = input.next();
doctor.setSprecialty(specialty);
System.out.println("请输入医生的入职日期(格式:yyyy-MM-dd):");
String joinDateString = input.next();
LocalDate joinDate = LocalDate.parse(joinDateString);
doctor.setJoinDate(joinDate);
department.getDoctors().add(doctor);
System.out.println("录入医生到该科室成功!");
break;
}
}
8.建立科室
private void addDepartment() {
System.out.println("=======建立科室======");
OUT:
while (true) {
System.out.println("请您输入科室的名称:");
String name = input.next();
//判断科室是否存在
for (int i = 0; i < allDepartments.size(); i++) {
Department department = allDepartments.get(i);
if (department.getName().equals(name)) {
System.out.println("科室已存在,请重新创立");
continue OUT;
}
}
Department department = new Department();
department.setName(name);
allDepartments.add(department);
System.out.println("添加科室成功!");
break;
}
}
9.删除科室
public void deleteDepartment() {
System.out.println("=======删除科室======");
OUT:
while (true) {
System.out.println("请您输入科室的名称:");
String name = input.next();
//判断科室是否存在
for (int i = 0; i < allDepartments.size(); i++) {
Department department = allDepartments.get(i);
if (department.getName().equals(name)) {
allDepartments.remove(department);
System.out.println("科室删除成功!");
break OUT; // 跳出外部while循环,结束删除操作
}
}
// 如果没有找到匹配的科室名称,提示用户重新输入
System.out.println("科室不存在,请重新搜索");
continue OUT;
}
}
10.预约医生
private void appointmentDoctor() {
System.out.println("=========预约挂号==========");
System.out.println("请选择你要挂号的科室:");
for (int i = 0; i < allDepartments.size(); i++) {
Department department = allDepartments.get(i);
System.out.println((i + 1) + "." + department.getName());
}
int choice = input.nextInt() - 1;
Department department = allDepartments.get(choice);
System.out.println("请选择你要挂号的医生:");
ArrayList<Doctor> doctors = department.getDoctors();
for (int i = 0; i < doctors.size(); i++) {
Doctor doctor = doctors.get(i);
System.out.println((i + 1) + "、" + doctor.getName());
System.out.println("医生ID: " + doctor.getDoctorid());
System.out.println("性别: " + doctor.getGender());
System.out.println("年龄: " + doctor.getAge());
System.out.println("专长: " + doctor.getSprecialty());
System.out.println("科室: " + doctor.getDepartmentName());
System.out.println("入职日期: " + doctor.getJoinDate());
System.out.println("------------------------------");
}
int choice1 = 0;
while (true) {
System.out.println("请选择你要挂号的医生:");
choice1 = input.nextInt() - 1;
if (choice1 < 0 || choice1 >= doctors.size()) {
System.out.println("无效的选择,请重新开始。");
continue;
}
break;
}
Doctor doctor = doctors.get(choice1);
System.out.println("坐诊时间: \n" + getDoctorSchedules(doctor.getDoctorid()));
LocalDate appointDate;
while (true) {
System.out.println("请输入你要预约的时间:(格式:yyyy-MM-dd)");
String appoint = input.next();
try {
appointDate = LocalDate.parse(appoint);
break;
} catch (
DateTimeParseException e) {//catch (DateTimeParseException e): 这一部分用于捕获 LocalDate.parse(appoint) 可能抛出的 DateTimeParseException 异常。
System.out.println("日期格式错误,请使用 yyyy-MM-dd 格式。");
continue;
}
}
ArrayList<Schedule> schedules = doctor.getSchedules();
for (int i = 0; i < schedules.size(); i++) {
Schedule schedule = schedules.get(i);
if (appointDate.equals(schedule.getToday())) {
while (true) {
System.out.println("请输入你要预约的是:0.上午1.下午");
String choice2 = input.next();
if (choice2.equals("0")) {
schedule.setmTotalNumber(schedule.getmTotalNumber()+ 1);
System.out.println("恭喜您预约成功!\t预约时间为:" + schedule.getMstart());
System.out.println("排号为:" + schedule.getmTotalNumber());
return ;
} else if (choice2.equals("1")) {
schedule.setaTotalNumber(schedule.getaTotalNumber() + 1);
System.out.println("恭喜您预约成功!\t预约时间为:" + schedule.getAstart());
System.out.println("排号为:" + schedule.getaTotalNumber());
return ;
} else {
System.out.println("无效的选择,请您重新输入");
continue;
}
}
}
}
System.out.println("预约日期未找到,请您重新输入");
}
11.搜索医生坐诊信息
private void SearchDoctorInfos() {
System.out.println("=======搜索指定医生的坐诊信息=======");
while (true) {
System.out.println("请您输入医生的ID号码");
String id = input.next();
boolean doctorFound = false;
for (int i = 0; i < allDepartments.size(); i++) {
Department department = allDepartments.get(i);
ArrayList<Doctor> doctors = department.getDoctors();
for (int j = 0; j < doctors.size(); j++) {
Doctor doctor = doctors.get(j);
if (doctor.getDoctorid().equals(id)) {
doctorFound = true; // 找到医生,设置标志为true
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.getToday());//获取今天日期
if (!schedule.isUpdate()) //是否排班过
{
System.out.println("未排班~~~~~~\t\t\t");
continue;
}
if (schedule.isMorning()) {
System.out.println("上午" + schedule.getMstart() + "-" + schedule.getMend() + "已预约/总数" +schedule.getmTotalNumber()+ "/" + schedule.getmAppointNumber() );
} else {
System.out.println("上午休息");
}
if (schedule.isAfternoon()) {
System.out.println("下午" + schedule.getAstart() + "-" + schedule.getAend() + "已预约/总数" +schedule.getaTotalNumber() + "/" +schedule.getaAppointNumber() );
}
}
return;
}
}
}
if (!doctorFound) {
System.out.println("没有找到该医生,请您重新输入");
}
}
}
12.得到医生日程功能函数
private String getDoctorSchedules(String doctorId) {
for (Department department : allDepartments) {
for (Doctor doctor : department.getDoctors()) {
if (doctor.getDoctorid().equals(doctorId)) {
ArrayList<Schedule> schedules = doctor.getSchedules();
updateSchedules(schedules); // 更新时间
StringBuilder sb = new StringBuilder();
for (Schedule schedule : schedules) {
sb.append(schedule.getToday()).append(": ");
if (!schedule.isUpdate()) {
sb.append("未排班");
} else {
if (schedule.isMorning()) {
sb.append("上午").append(schedule.getMstart()).append("-").append(schedule.getMend())
.append(" 已预约/总数 ").append(schedule.getmAppointNumber()).append("/").append(schedule.getmTotalNumber());
}
if (schedule.isAfternoon()) {
sb.append(" 下午").append(schedule.getAstart()).append("-").append(schedule.getAend())
.append(" 已预约/总数 ").append(schedule.getaTotalNumber()).append("/").append(schedule.getaAppointNumber());
}
}
sb.append("\n");
}
return sb.toString();
}
}
}
return "未找到医生的坐诊信息。";
}
APP运行
import frame.HospitalManager;
public class APP {
public static void main(String[] args) {
//1.创建一个医院管理对象
HospitalManager hm = new HospitalManager();
hm.start();
}
}