医院挂号系统

需求:

  1. 科室管理:新增科室。
  2. 医生管理:录入医生信息,以及科室信息。修改医生信息(主要是修改个人信息和科室)。
  3. 坐诊信息设置:可以设置医生当天和未来6天的坐诊情况,包括上午和下午的坐诊时间段和可预约的数量,系统将自动保存到该医生的坐诊信息列表中。
  4. 全部信息展示:按照科室,展示每个医生七天的坐诊情况,需要按照科室归类展示。

bean.Department类

import java.util.ArrayList;
//科室类
public class Department {
    private String name;    //科室名称
    private ArrayList doctors = new ArrayList<>();

    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;
    }

    public int getNumber(){
        return doctors.size();
    }
}

bean.Doctor类

import java.time.LocalDate;
import java.util.ArrayList;

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<>();

    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;
    }
}

bean.Schedule类

import java.time.LocalDate;
import java.time.LocalTime;

//调度类
public class Schedule {
    private LocalDate today;    //日期
    private boolean uptate;     //是否排过班,默认是未排班
    // 上午
    private boolean morning;    //是否看诊
    private LocalTime mstart;   //上午看诊时间
    private LocalTime mend;     //上午截至时间
    private int moTotalNumber;  //上午接诊的总人数
    private int mAppointNumber; //上午预约人数

    //下午
    private boolean afternoon;    //是否看诊
    private LocalTime astart;   //下午看诊时间
    private LocalTime aend;     //下午截至时间
    private int aTotalNumber;  //下午接诊的总人数
    private int aAppointNumber; //下午预约人数

    public LocalDate getToday() {
        return today;
    }

    public void setToday(LocalDate today) {
        this.today = today;
    }

    public boolean isUptate() {
        return uptate;
    }

    public void setUptate(boolean uptate) {
        this.uptate = uptate;
    }

    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 getMoTotalNumber() {
        return moTotalNumber;
    }

    public void setMoTotalNumber(int moTotalNumber) {
        this.moTotalNumber = moTotalNumber;
    }

    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;
    }

}

 frame.HospitManager类

import com.pt2.bean.Department;
import com.pt2.bean.Doctor;
import com.pt2.bean.Schedule;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.UUID;

public class HospitaManager {
    // 系统需要存储全部科室信息
    private ArrayList allDepartments = 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.医生管理-医生坐诊设置(可设置当天和未来6天的坐诊情况)");
            System.out.println("4.医生管理-展示全部医生的坐诊详情(当前和未来6天的坐诊详情)");
            System.out.println("请输入操作命令:");

            switch (sc.nextInt()){
                case 1:
                    addDepartment();
                    break;
                case 2:
                    addDoctor();
                    break;
                case 3:
                    setDoctorJob();
                    break;
                case 4:
                    showAllDoctorInfos();
                    break;
                default:
                    System.out.println("您输入的命令不正确,请重试!");
            }
        }
    }

    private void showAllDoctorInfos() {
        System.out.println("=====全部医生的坐诊详情如下=====");
        for (int i = 0; i < allDepartments.size(); i++) {
            Department department = allDepartments.get(i);
            System.out.println((i+1) + "," + department.getDoctors());
            System.out.println("-------------------------------------------------");
            ArrayList doctors = department.getDoctors();
            for (int j = 0; j < doctors.size(); j++) {
                Doctor doctor = doctors.get(j);
                System.out.println(doctor.getName() + "医生的坐班信息如下:");
                ArrayList 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.isUptate()){
                        System.out.println("未排班\t\t\t");
                        continue;
                    }

                    if (schedule.isMorning()){
                        System.out.println("坐诊 时间为:" + schedule.getMstart() + "-" + schedule.getMend() + "总数/预约数:" + schedule.getMoTotalNumber());
                    }else{
                        System.out.println("休息");
                    }
                    System.out.println();
                    System.out.println("\t下午\t");
                    if (schedule.isAfternoon()){
                        System.out.println("坐诊 时间为:" + schedule.getAstart() + "-" + schedule.getAend() + "总数/预约数:" + schedule.getaTotalNumber());
                    }else {
                        System.out.println("休息");
                    }
                }
            }
        }
    }

    private void setDoctorJob() {
        System.out.println("=====设置医生的坐诊时间=====");
        Department department = getDepartmentByUser();
        if (department == null){
            System.out.println("当前无任何科室");
            return;
        }

        ArrayList 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("请输入:");
            // 接收命令
            int command = sc.nextInt();
            if (command < 1 || command > allDepartments.size()){
                System.out.println("选择有误,请重新确认");
                continue;
            }

            Doctor doctor = doctors.get(command - 1);
            // 为这个医生设置坐诊情况
            ArrayList schedules = doctor.getSchedules();
            // 更新未来其他的时间
            updateSchedules(schedules);

            // 修改坐诊信息,依次展示这个医生的坐诊情况
            for (int i = 0; i < schedules.size(); i++) {
                Schedule schedule = schedules.get(i);
                updateDoctorSchedule(schedule);
            }
            break;
        }
    }

    private void updateDoctorSchedule(Schedule schedule) {
        LocalDate today = schedule.getToday();
        System.out.println(today + "的安排如下:");
        if (!schedule.isUptate()){
            System.out.println("未排班\t\t\t");
        }else {
            System.out.println("\t上午\t");
            if (schedule.isMorning()){
                System.out.println("坐诊 时间为:" + schedule.getMstart() + "-" + schedule.getMend() + "总数/预约数:" + schedule.getMoTotalNumber());
            }else{
                System.out.println("休息");
            }
            System.out.println();
            System.out.println("\t下午\t");
            if (schedule.isAfternoon()){
                System.out.println("坐诊 时间为:" + schedule.getAstart() + "-" + schedule.getAend() + "总数/预约数:" + schedule.getaTotalNumber());
            }else {
                System.out.println("休息");
            }
        }
        System.out.println("是否修改?y/n");
        String rs = sc.next();
        if ("y".equals(rs)){
            schedule.setUptate(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.setMend(LocalTime.parse(end));
                schedule.setMoTotalNumber(number);
            }else {
                schedule.setMorning(false);
            }

            System.out.println("下午是否上班?y/n");
            String rs3 = sc.next();
            if ("y".equals(rs3)){
                schedule.setAfternoon(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.setAend(LocalTime.parse(end));
                schedule.setaTotalNumber(number);
            }else {
                schedule.setAfternoon(false);
            }
        }
    }

    private void updateSchedules(ArrayList schedules) {
        if (schedules.size() == 0){
            for (int i = 0; i <= 6 ; i++) {
                Schedule schedule = new Schedule();
                LocalDate now = LocalDate.now();
                schedule.setToday(now.plusDays(i));
                schedules.add(schedule);
            }
            return;
        }

        // 除去过期的时间
        for (int i = 0; i < schedules.size(); i++) {
            Schedule schedule = schedules.get(i);
            LocalDate now = LocalDate.now();
            LocalDate current = schedule.getToday();
            if (current.equals(now)){
                break;
            }
            if (current.isBefore(now)){
                schedules.remove(schedule);
                i--;
            }
        }

        // 补全当前和未来6天的时间
        LocalDate last = schedules.get(schedules.size() - 1).getToday();
        for (int i = 0; i < 7 - schedules.size(); i++) {
            Schedule schedule = new Schedule();
            schedule.setToday(last.plusDays(i + 1));
            schedules.add(schedule);
        }
    }

    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());

            // 录入医生的id
            doctor.setDoctorId(UUID.randomUUID().toString());

            System.out.println("请输入医生的姓名:");
            String name = sc.next();
            doctor.setName(name);

            System.out.println("请输入医生的性别:");
            String sex = sc.next();
            doctor.setGender(sex);

            System.out.println("请输入医生的年龄:");
            int age = sc.nextInt();
            doctor.setAge(age);

            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);

            department.getDoctors().add(doctor);
            System.out.println("录入医生到该科室成功!");
            break;
        }
    }

    private Department  getDepartmentByUser() {
        if (allDepartments.size() == 0){
            return null;
        }
        while (true) {
            // 先选择科室
            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("请输入:");
            // 接收命令
            int command = sc.nextInt();
            if (command < 1 || command > allDepartments.size()){
                System.out.println("选择有误,请重新确认");
                continue;
            }
            // 得到科室
            Department department = allDepartments.get(command - 1);
            return department;
        }
    }

    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);
                System.out.println("您输入的部门名称存在,请重试!");
                if (department.getName().equals(name)) continue OUT;
            }

            Department department = new Department();
            department.setName(name);
            allDepartments.add(department);
            System.out.println("添加科室成功!");
            break;
        }
    }
}

你可能感兴趣的:(java,算法)