模拟医院挂号系统功能
1. 科室管理:新增科室,删除科室(如果有医生在,则不能删除该科室),修改科室
2. 医生管理:录入医生信息以及科室信息,修改医生信息(主要是修改个人信息和科室)
3. 坐诊信息设置:可以设置医生当天和未来6天的坐诊情况,包括上午和下午的坐诊时间段和可预约数量,系统将自动保存到该医生的坐诊信息列表中
4. 全部信息展示:按照科室,展示每个医生七天的坐诊情况,需要按照科室归类展示
5. 预约功能:用户可以选择要预约的科室,医生、日期和时间段,并输入患者的个人信息,系统将激动判断该时间段是否还有预约名额,并保存预约信息
6. 搜索功能:用户可以输入搜索日期和时间段,系统将自动搜索未来七天内在该时间段坐诊的医生信息,并按照科室分类展示
7. 可以查询某个医生未来7天,病人对他的预约情况
- //App
- public class App {
- public static void main(String[] args) {
- //创建一个医院管理对象
- HospitalManager h = new HospitalManager();
- h.start();
- }
- }
- //Doctor
- //医生类
- public class Doctor {
- private String doctorId; //编号(唯一)
- private String name; //姓名
- private String departmentName; //科室名称
- private String gender; //性别
- private int age; //年龄
- private String specialty; //主治方向
- private LocalDate joinDate; //入职时间
- private ArrayList
schedules = new ArrayList<>(); //7天坐诊情况 -
- public Doctor() {
- }
-
- public Doctor(String doctorId, String name, String departmentName, String gender, int age, String specialty, LocalDate joinDate, ArrayList
schedules) { - this.doctorId = doctorId;
- this.name = name;
- this.departmentName = departmentName;
- this.gender = gender;
- this.age = age;
- this.specialty = specialty;
- this.joinDate = joinDate;
- this.schedules = schedules;
- }
-
- public String getDoctorId() {
- return doctorId;
- }
-
- public void setDoctorId(String doctorId) {
- this.doctorId = doctorId;
- }
-
- 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 int getAge() {
- return age;
- }
-
- public void setAge(int 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
getSchedules() { - return schedules;
- }
-
- public void setSchedules(ArrayList
schedules) { - this.schedules = schedules;
- }
- }
- //Department
- //科室类
- public class Department {
- private String name;
- private ArrayList
doctors = new ArrayList<>(); -
- public Department() {
- }
-
- public Department(String name, ArrayList
doctors) { - this.name = name;
- this.doctors = doctors;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public ArrayList
getDoctors() { - return doctors;
- }
-
- public void setDoctors(ArrayList
doctors) { - this.doctors = doctors;
- }
- }
- //Schedule
- //医生坐诊情况类
- public class Schedule {
- private LocalDate today; //当天日期
- private boolean update = false; //是否排班(默认未排班false)
- //上午
- private boolean morning; //是否看诊
- private LocalTime mStart; //上午开始时间
- private LocalTime mEnd; //上午结束时间
- private int mTotalNum; //上午可预约人数
- private int mAppointNum; //上午已预约人数
-
- //下午
- private boolean afternoon; //是否看诊
- private LocalTime aStart; //下午开始时间
- private LocalTime aEnd; //下午结束时间
- private int aTotalNum; //下午可预约人数
- private int aAppointNum; //下午已预约人数
-
- public Schedule() {
- }
-
- public Schedule(LocalDate today, boolean update, boolean morning, LocalTime mStart, LocalTime mEnd, int mTotalNum, int mAppointNum, boolean afternoon, LocalTime aStart, LocalTime aEnd, int aTotalNum, int aAppointNum) {
- this.today = today;
- this.update = update;
- this.morning = morning;
- this.mStart = mStart;
- this.mEnd = mEnd;
- this.mTotalNum = mTotalNum;
- this.mAppointNum = mAppointNum;
- this.afternoon = afternoon;
- this.aStart = aStart;
- this.aEnd = aEnd;
- this.aTotalNum = aTotalNum;
- this.aAppointNum = aAppointNum;
- }
-
- public boolean isUpdate() {
- return update;
- }
-
- public void setUpdate(boolean update) {
- this.update = update;
- }
-
- public LocalDate getToday() {
- return today;
- }
-
- public void setToday(LocalDate today) {
- this.today = today;
- }
-
- 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 getmTotalNum() {
- return mTotalNum;
- }
-
- public void setmTotalNum(int mTotalNum) {
- this.mTotalNum = mTotalNum;
- }
-
- public int getmAppointNum() {
- return mAppointNum;
- }
-
- public void setmAppointNum(int mAppointNum) {
- this.mAppointNum = mAppointNum;
- }
-
- 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 getaTotalNum() {
- return aTotalNum;
- }
-
- public void setaTotalNum(int aTotalNum) {
- this.aTotalNum = aTotalNum;
- }
-
- public int getaAppointNum() {
- return aAppointNum;
- }
-
- public void setaAppointNum(int aAppointNum) {
- this.aAppointNum = aAppointNum;
- }
- }
- //Appointment
- //患者预约信息类
- public class Appointment {
- private String userName; //患者姓名
- private String sex; //患者性别
- private int age; //患者年龄
- private String tel; //患者电话
- private String desc; //病情描述
- private String departmentName; //挂号科室
- private String doctorId; //看诊医生id
- private LocalDateTime appointDateTime; //预约时间
-
- public Appointment() {
- }
-
-
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getSex() {
- return sex;
- }
-
- public void setSex(String 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 getDepartmentName() {
- return departmentName;
- }
-
- public void setDepartmentName(String departmentName) {
- this.departmentName = departmentName;
- }
-
- public String getDoctorId() {
- return doctorId;
- }
-
- public void setDoctorId(String doctorId) {
- this.doctorId = doctorId;
- }
-
- public LocalDateTime getAppointDateTime() {
- return appointDateTime;
- }
-
- public void setAppointDateTime(LocalDateTime appointDateTime) {
- this.appointDateTime = appointDateTime;
- }
- }
- /*
- 模拟医院挂号系统功能
- 1. 科室管理:新增科室,删除科室(如果有医生在,则不能删除该科室),修改科室名称
- 2. 医生管理:录入医生信息以及科室信息,修改医生信息(主要是修改个人信息和科室)
- 3. 坐诊信息设置:可以设置医生当天和未来6天的坐诊情况,包括上午和下午的坐诊时间段和可预约数量,系统将自动保存到该医生的坐诊信息列表中
- 4. 全部信息展示:按照科室,展示每个医生七天的坐诊情况,需要按照科室归类展示
- 5. 预约功能:用户可以选择要预约的科室,医生、日期和时间段,并输入患者的个人信息,系统将激动判断该时间段是否还有预约名额,并保存预约信息
- 6. 搜索功能:用户可以输入搜索日期和时间段,系统将自动搜索未来七天内在该时间段坐诊的医生信息,并按照科室分类展示
- 7. 可以查询某个医生未来7天,病人对他的预约情况
- */
-
- //HospitalManager
- public class HospitalManager {
- //系统需要存储全部科室信息
- private ArrayList
departments = new ArrayList<>(); -
- //系统需要记录全部预约信息
- private ArrayList
appointments = new ArrayList<>(); -
- 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.搜索--查看某医生坐诊情况(当天和未来6天的坐诊详情)====");
- System.out.println("====8.挂号--挂号预约====");
- System.out.println("====9.退出====");
- System.out.println("请输入您的操作指令(1-9):");
- switch (sc.next()){
- case "1":
- addDepartment();
- break;
- case "2":
- deleteDepartment();
- break;
- case "3":
- modifyDepartment();
- break;
- case "4":
- addDoctor();
- break;
- case "5":
- setDoctorJob();
- break;
- case "6":
- searchAllJob();
- break;
- case "7":
- searchOneJob();
- break;
- case "8":
- Appoint();
- break;
- case "9":
- return;
- default:
- System.out.println("您选择的操作不存在,请重新选择");
- break;
- }
- }
- }
-
- private void Appoint() {
- System.out.println("====挂号预约====");
- //判断有没有科室(医院没有科室就一定没有医生)
- if(isDepartment()==false) {
- System.out.println("没有科室就没有医生");
- return;
- }
-
- //有科室
- while(true) {
- showAllDepartment(); //展示已有科室
- //先选择科室
- System.out.println("请选择挂号科室(最大选择" + departments.size() + "):");
- int command1 = sc.nextInt();
- if (existDepartment(command1) == false) {
- //不存在该科室
- continue;
- }
- //存在该科室
- Department department = departments.get(command1 - 1);
- //判断该科室是否存在医生
- if (department.getDoctors().size() == 0) {
- //没有医生
- System.out.println("该科室无医生");
- return;
- }
- //有医生
- while (true) {
- //显示该科室的全部医生
- showAllDoctor(department);
- Appointment a = new Appointment();
- a.setDepartmentName(department.getName()); //保存挂号科室名称
-
- //选择看诊的医生
- ArrayList
doctors = department.getDoctors(); - System.out.println("请选择看诊医生的序号(最大选择"+doctors.size()+"):");
- int command2 = sc.nextInt();
- if(existDoctor(doctors,command2)==false){
- //不存在该医生
- continue;
- }
- //存在该医生
- Doctor d = doctors.get(command2-1); //保存选择的医生对象
- //展示该医生的排班信息
- print(d);
- ArrayList
arr = d.getSchedules(); //arr保存该医生的排班信息 - //如果该医生一次都没排过(arr数组都是空的)
- if(arr.size() == 0){
- System.out.println("该医生未排班,请重新选择");
- continue;
- }
- OUT:
- while (true) {
- //该医生排过班(arr数组不是空的)
- System.out.println("请选择看诊日期:");
- String dayStr = sc.next();
- LocalDate ld = LocalDate.parse(dayStr);
- for (int i = 0; i < arr.size(); i++) {
- Schedule s = arr.get(i);
- if(s.getToday().equals(ld)){
- //存在该天的排班情况
- if(s.isUpdate() == false){
- System.out.println("该医生未排班,请重新选择日期");
- continue OUT;
- }
- //当天排班了s.isUpdate() == true
- while (true) {
- System.out.println("请输入看诊的时间(1:上午or2:下午):");
- int com = sc.nextInt();
- if(com == 1) { //选择上午看诊
- if (s.isMorning() == false) { //上午休息
- System.out.println("该医生上午休息,请重新选择");
- continue OUT;
- } else { //上午不休息
- if (s.getmAppointNum() < s.getmTotalNum()) { //上午预约人数没满
- s.setmAppointNum(s.getmAppointNum()+1); //医生可预约人数-1
-
- a.setDoctorId(d.getDoctorId()); //设置看诊医生id
- LocalDate appointDate = s.getToday();
- LocalTime appointTime = s.getmStart();
- LocalDateTime appointDateTime = LocalDateTime.of(appointDate,appointTime);
- a.setAppointDateTime(appointDateTime);
-
- System.out.println("请输入患者姓名:");
- a.setUserName(sc.next());
- System.out.println("请输入患者性别:");
- a.setSex(sc.next());
- System.out.println("请输入患者年龄:");
- a.setAge(sc.nextInt());
- System.out.println("请输入患者电话:");
- a.setTel(sc.next());
- System.out.println("请输入病情描述:");
- a.setDesc(sc.next());
- System.out.println("预约成功");
- return;
- } else {
- System.out.println("该医生当天上午已约满,请重新选择");
- continue OUT;
- }
- }
- }else if(com == 2){ // //选择下午看诊
- if (s.isAfternoon() == false) { //下午休息
- System.out.println("该医生下午休息,请重新选择");
- continue OUT;
- } else { //下午不休息
- if (s.getaAppointNum() < s.getaTotalNum()) { //下午预约人数没满
- s.setaAppointNum(s.getaAppointNum()+1); //医生可预约人数-1
-
- a.setDoctorId(d.getDoctorId()); //设置看诊医生id
- LocalDate appointDate = s.getToday();
- LocalTime appointTime = s.getaStart();
- LocalDateTime appointDateTime = LocalDateTime.of(appointDate,appointTime);
- a.setAppointDateTime(appointDateTime);
-
- System.out.println("请输入患者姓名:");
- a.setUserName(sc.next());
- System.out.println("请输入患者性别:");
- a.setSex(sc.next());
- System.out.println("请输入患者年龄:");
- a.setAge(sc.nextInt());
- System.out.println("请输入患者电话:");
- a.setTel(sc.next());
- System.out.println("请输入病情描述:");
- a.setDesc(sc.next());
- System.out.println("预约成功");
- return;
- } else {
- System.out.println("该医生当天下午已约满,请重新选择");
- continue OUT;
- }
- }
- }else{
- System.out.println("输入有误,请重新输入");
- continue;
- }
- }
-
- }
- }
- //不存在该天的排班情况
- System.out.println("您选择的看诊日期不在近7天,请重新选择");
- continue;
- }
- }
- }
- }
-
- //查看某医生近7天的全部坐诊情况和预约情况(根据id查更加规范)
- private void searchOneJob() {
- //判断有没有科室(没有科室就一定没有医生)
- if(isDepartment()==false) {
- System.out.println("没有科室就没有医生");
- return;
- }
-
- //有科室
- System.out.println("请输入你要查找的医生姓名:");
- String name = sc.next();
-
- for (int i = 0; i < departments.size(); i++) {
- Department department = departments.get(i); //department保存第i个科室信息
- ArrayList
arr = department.getDoctors(); //创建arr集合(该集合保存的是某科室全部的医生信息) - if(arr.size() != 0){ //某科室有医生
- for (int j = 0; j < arr.size(); j++) {
- Doctor d = arr.get(j); //保存医生信息
- if(d.getName().equals(name)){ //如果找到同名医生就输出
- System.out.println((d.getDepartmentName()));
- print(d);
- return;
- }
- }
- }
- }
-
- //遍历后还没找到
- System.out.println("查无此人");
- }
-
- //打印某医生的排班信息
- private void print(Doctor d) {
- System.out.println(d.getName()+"的排班情况:");
-
- ArrayList
arr_s = d.getSchedules(); //医生的排班表 - //先更新当前和未来6天的时间
- updateSchedule(arr_s);
-
- if (arr_s.size() == 0){
- //没有进行过一次排班(arr_s就是空的)
- System.out.println("该医生未排班");
- return;
- }
- //不是空的
- for (int k = 0; k < arr_s.size() ; k++) {
- Schedule s = arr_s.get(k);
- System.out.println(s.getToday()+"的排班情况:");
- if(s.isUpdate() == false){
- System.out.println("未排班");
- continue;
- }
- //已排班
- if(s.isMorning() == true){
- System.out.println("上午:"+s.getmStart()+"-"+s.getmEnd()+" 可预约人数:"+s.getmTotalNum()+" 已预约人数:"+s.getmAppointNum());
- }else{
- System.out.println("上午休息");
- }
-
- if(s.isAfternoon() == true){
- System.out.println("下午:"+s.getaStart()+"-"+s.getaEnd()+" 可预约人数:"+s.getaTotalNum()+" 已预约人数:"+s.getaAppointNum());
- }else{
- System.out.println("下午休息");
- }
- }
- }
-
- private void searchAllJob() {
- System.out.println("====全部医生的坐班信息====");
- //判断有没有科室(没有科室就一定没有医生)
- if(isDepartment()==false) {
- System.out.println("没有科室就没有医生");
- return;
- }
- //有科室
- for (int i = 0; i < departments.size(); i++) {
- Department department = departments.get(i); //department保存第i个科室信息
- ArrayList
arr = department.getDoctors(); //创建arr集合(该集合保存的是某科室全部的医生信息) - if(arr.size() == 0){ //没有医生
- System.out.println("===="+department.getName()+"没有医生====");
- continue;
- }
- //有医生
- System.out.println("===="+department.getName()+"医生的排班情况====");
- for (int j = 0; j < arr.size(); j++) {
- Doctor d = arr.get(j); //科室中第j个医生的信息
- print(d); //打印医生的排班信息
- }
- }
-
- }
-
- private void setDoctorJob() {
- System.out.println("====医生坐诊设置====");
- //判断有没有科室
- if(isDepartment()==false) {
- return;
- }
- //有科室
- while(true) {
- showAllDepartment(); //展示已有科室
- //先选择科室
- System.out.println("请选择要排班的医生的科室(最大选择"+departments.size()+"):");
- int command1 = sc.nextInt();
- if(existDepartment(command1)==false){
- //不存在该科室
- continue;
- }
- //存在该科室
- Department department = departments.get(command1-1);
- //判断该科室是否存在医生
- if(department.getDoctors().size() == 0){
- //没有医生
- System.out.println("该科室无医生");
- continue;
- }
- //有医生
- while(true){
- //显示该科室的全部医生
- showAllDoctor(department);
-
- //选择需要排班的医生
- ArrayList
doctors = department.getDoctors(); - System.out.println("请选择要排班的医生的序号(最大选择"+doctors.size()+"):");
- int command2 = sc.nextInt();
- if(existDoctor(doctors,command2)==false){
- //不存在该医生
- continue;
- }
- //存在该医生
- Doctor d = doctors.get(command2-1); //保存选择的医生对象
-
- // 为该医生设置坐诊时间
-
- //获取该医生的坐诊情况
- ArrayList
schedules = d.getSchedules(); //第一次getSchedules()里面肯定是空的 - //先更新当前和未来6天的时间
- updateSchedule(schedules);
-
- //再给该医生当天和未来6天进行排班
- for (int i = 0; i < schedules.size(); i++) {
- Schedule s = schedules.get(i);
- updateDoctorSchedule(s);
- }
- System.out.println("已完成"+d.getName()+"排班"); //已某医生的排班
- return;
- }
- }
- }
-
- //给医生进行排班
- private void updateDoctorSchedule(Schedule s) {
- LocalDate today = s.getToday();
- System.out.println(today+"的安排如下:");
- if(s.isUpdate()==false){ //未排班
- System.out.println("未排班");
- }else{ //已排班(显示排班情况)
- //上午是否休息
- if(s.isMorning() == false){
- //上午休息
- System.out.println("上午休息");
- }else{
- //上午不休息
- System.out.println("上午:"+s.getmStart()+"-"+s.getmEnd()+" 可预约人数:"+s.getmTotalNum()+" 已预约人数:"+s.getmAppointNum());
- }
-
- //下午是否休息
- if(s.isAfternoon() == false){
- //下午休息
- System.out.println("下午休息");
- }else{
- //下午不休息
- System.out.println("下午:"+s.getaStart()+"-"+s.getaEnd()+" 可预约人数:"+s.getaTotalNum()+" 已预约人数:"+s.getaAppointNum());
- }
- }
- OUT:
- while (true) { //快捷键Ctrl+Alt+T
- System.out.println("是否修改排班?y/n");
- String command = sc.next();
- switch(command){
- case "y": //修改排班
- s.setUpdate(true);
- while (true) {
- System.out.println("上午是否看诊?y/n");
- String choose = sc.next();
- if(choose.equals("y")){
- s.setMorning(true);
- System.out.println("请输入看诊开始时间:");
- String start = sc.next();
- System.out.println("请输入看诊结束时间:");
- String end = sc.next();
- LocalTime ltstart = LocalTime.parse(start);
- LocalTime ltend = LocalTime.parse(end);
- s.setmStart(ltstart); //保存开始时间
- s.setmEnd(ltend); //保存结束时间
- System.out.println("请输入上午可预约人数:");
- int num = sc.nextInt();
- s.setmTotalNum(num);
- System.out.println("已完成设置上午排班信息");
- break;
- }else if(choose.equals("n")){
- s.setMorning(false);
- System.out.println("已设置上午休息");
- break;
- }else{
- System.out.println("没有该选择,请重新选择");
- continue;
- }
- }
-
- while (true) {
- System.out.println("下午是否看诊?y/n");
- String choose = sc.next();
- if(choose.equals("y")){
- s.setAfternoon(true);
- System.out.println("请输入看诊开始时间:");
- String start = sc.next();
- System.out.println("请输入看诊结束时间:");
- String end = sc.next();
- LocalTime ltstart = LocalTime.parse(start);
- LocalTime ltend = LocalTime.parse(end);
- s.setaStart(ltstart); //保存开始时间
- s.setaEnd(ltend); //保存结束时间
- System.out.println("请输入下午可预约人数:");
- int num = sc.nextInt();
- s.setaTotalNum(num);
- System.out.println("已完成设置下午排班信息");
- break;
- }else if(choose.equals("n")){
- s.setAfternoon(false);
- System.out.println("已设置下午休息");
- break;
- }else{
- System.out.println("没有该选择,请重新选择");
- continue;
- }
- }
- return;
- case "n": //不修改排班
- return;
- default:
- System.out.println("没有该选择,请重新选择");
- continue OUT;
- }
- }
- }
-
- //更新当前和未来6天的时间
- private void updateSchedule(ArrayList
schedules) { - LocalDate now = LocalDate.now(); //获取当天日期(年月日)
-
- //存在两种情况
- //schedules集合里面没有任何schedule(没有任何时间),就是第一次排班
- //schedules集合存在7天的时间(可能部分是过期的,需要更新到今天的情况),非第一次排班 比如:3月1号更新过1-7号的,现在是3号,进去查看的时候应该更新为3-10号的
-
- //schedules集合里面没有任何schedule(没有任何时间)
- if(schedules.size() == 0){ //第一次排班
- for (int i = 0; i < 7; i++) { //排7天
- Schedule s = new Schedule(); //创建一个Schedule对象
- s.setToday(now.plusDays(i)); //设置Schedule对象的日期(规则:第一天就是当天+0 第二天就是当天+1 ……)
- schedules.add(s); //把Schedule对象存到schedules集合中
- }
- return;
- }
-
- //schedules集合存在7天的时间(可能部分是过期的,需要更新到今天的情况),非第一次排班 比如:3月1号更新过1-7号的,现在是3号,进去查看的时候应该更新为3-10号的
- //非第一次排班,去除过期的时间
- int count = 0; //记入过期了几天(也就是删除了几天)
- //集合中的删除操作,如果从前往后遍历,会存在漏删的情况,因此选择从后往前
- for (int i = schedules.size()-1; i >= 0; i--) { //遍历已保存的7天
- LocalDate ld = schedules.get(i).getToday(); //已经保存的第i个日期
- if(ld.isBefore(now)){ //保存的第i个日期早于今天的日期
- schedules.remove(i);
- count++;
- }
- }
-
- //如果有删除过期的时间,那么需要补全7天
- //count == 0说明没有删除日期
- if(count == 0){
- return;
- }
- //count不等于0说明有删除(那么应该从count-1开始补全日期,比如删除了5天,剩下2天,那么就应该从第3个位置(索引2)开始补5天)
- for (int i=7-count; i < 7; i++) {
- Schedule s = new Schedule(); //创建一个Schedule对象
- s.setToday(now.plusDays(i));
- schedules.add(s);
- }
- }
-
- private void addDoctor() {
- System.out.println("====添加医生====");
- //判断有没有科室
- if(isDepartment()==false) {
- return;
- }
- //有科室
- Doctor d = new Doctor();
- while(true){
- showAllDepartment(); //展示已有科室
- //先选择科室
- System.out.println("请选择新医生的入职科室(最大选择"+departments.size()+"):");
- int command = sc.nextInt();
- if(existDepartment(command)==false){
- //不存在该科室
- continue;
- }
- //存在该科室
- Department department = departments.get(command-1); //department记录选择的科室
- d.setDepartmentName(department.getName()); //记录员工科室
-
- //录入医生id
- d.setDoctorId(UUID.randomUUID().toString()); //随机返回16位的id
-
- System.out.println("请输入医生姓名:");
- d.setName(sc.next());
-
- System.out.println("请输入医生性别:");
- d.setGender(sc.next());
-
- System.out.println("请输入医生年龄:");
- d.setAge(sc.nextInt());
-
- System.out.println("请输入医生主治方向:");
- d.setSpecialty(sc.next());
-
- System.out.println("请输入医生入职时间(格式:yyyy-MM-dd):");
- String joinDateString = sc.next();
- d.setJoinDate(LocalDate.parse(joinDateString)); //把字符串转换成LocalDate对象
-
- //添加完医生个人信息,还需要把医生加到所在部门的集合里
- department.getDoctors().add(d);
- System.out.println("添加医生成功");
- break;
- }
- }
-
- private void modifyDepartment() {
- System.out.println("====修改科室名称====");
- //判断有没有科室
- if(isDepartment()==false){
- return;
- }
- //有科室
- while(true) {
- showAllDepartment();
- System.out.println("请选择你要修改的科室序号(最大选择"+departments.size()+"):");
- int command = sc.nextInt();
- if(existDepartment(command)==false){
- //不存在该科室
- continue;
- }
- //存在该科室
- Department department = departments.get(command-1); //department记录选择的科室
- System.out.println("你要为科室修改的新名字是:");
- String newName = sc.next();
- department.setName(newName);
- System.out.println("修改成功!");
- break;
- }
- }
-
- private void deleteDepartment() {
- System.out.println("====添加科室====");
- //判断有没有科室
- if(isDepartment()==false){
- return;
- }
- //有科室
- while(true){
- showAllDepartment();
- System.out.println("请选择你要删除的科室序号(最大选择"+departments.size()+"):");
- int command = sc.nextInt();
- if(existDepartment(command)==false){
- //不存在该科室
- continue;
- }
- //存在该科室
- Department department = departments.get(command-1);
- if(department.getDoctors().size() != 0){
- //科室中存在医生
- System.out.println("科室中存在医生,不能删除科室");
- return;
- }
- //科室中无医生,可以删除
- departments.remove(command-1);
- System.out.println("删除科室成功");
- break;
- }
- }
-
- //添加科室
- private void addDepartment() {
- System.out.println("====添加科室====");
- OUT: //标签
- while(true){
- System.out.println("请输入添加的科室名称:");
- String name = sc.next();
- //判断科室是否存在
- for (int i = 0; i < departments.size(); i++) {
- if (departments.get(i).getName().equals(name) == true) {
- //科室已存在
- System.out.println("您创建的科室已存在,请重新输入");
- continue OUT; //继续执行下一次外面的死循环(OUT)
- }
- }
- Department d = new Department();
- d.setName(name);
- departments.add(d);
- System.out.println("创建科室成功");
- break;
- }
- }
-
- //展示一个科室的全部医生
- private void showAllDoctor(Department department){
- System.out.println("===="+department.getName()+"====");
- ArrayList
arr = department.getDoctors(); - for (int i = 0; i < arr.size(); i++) {
- System.out.println(i+1 +"." + arr.get(i).getName());
- }
- }
-
- //展示已有的每个科室
- private void showAllDepartment(){
- System.out.println("====已有科室====");
- for (int i = 0; i < departments.size(); i++) {
- System.out.println(i+1+"."+departments.get(i).getName());
- }
- }
-
- //判断有没有科室
- private boolean isDepartment(){
- if(departments.size()==0){
- //没有科室
- System.out.println("当前无科室,请先添加科室");
- return false;
- }
- return true;
- }
-
- //判断选择的序号是否有科室存在
- private boolean existDepartment(int command){
- if(command < 1 || command > departments.size()){
- //没有该科室
- System.out.println("不存在该科室,请重新选择");
- return false;
- }
- //有该科室
- return true;
- }
-
- //判断选择的序号是否有医生存在
- private boolean existDoctor(ArrayList
doctors,int command) { - if(command < 1 || command > doctors.size()){
- //没有该医生
- System.out.println("不存在该医生,请重新选择");
- return false;
- }
- //有该医生
- return true;
- }
- }