【问题标题】:Implement Reservation System实施预约系统
【发布时间】:2018-09-24 15:22:03
【问题描述】:

我正在为移动应用程序开发一个spring boot MVC REST API,该系统是诊所的病人预约,我正在寻找显示医生可用时间问题的最佳解决方案。

问题定义:系统应允许用户从日历中选择诊所、医生和具体日期(年/月/日),系统将显示所选日期的可用时间,预约时间为30从早上 7 点到下午 6 点。

更多说明: 该系统由许多诊所组成,医生属于这些诊所,每个医生都有固定的时间供用户预订。这些时间分为每个半小时约会的日期。用户不能同时预约同一个医生。

示例: 患者 Joey 在 2018 年 5 月 21 日 3:30 预约了医生 x , 另一位患者 Jack 已打开应用程序进行预约 他选择医生 x 并选择与 joey 相同的日期(2018 年 5 月 21 日) 系统将显示从早上 7 点到下午 6 点(7 :00 和 7:30)的可用时间, 8:00 , 8:30 ......) 不包括 3:30 。

尝试的解决方案: 1) 在数据库中填写每年的可用时间并用标志标记时间。 2)当客户询问可用时间时,系统会遍历医生的所有预约并找到这些时间。 3)制作一个包含时间和日期的静态列表,当用户询问可用时间时,迭代约会并从列表中删除属于约会的时间。 4)制作数据库日历。 5)让管理页面的用户从管理页面手动填写时间。 我尝试了所有这些可能的解决方案,但我没有发现它们非常有效,我正在寻找更好的解决方案。

代码示例: 控制器部分:

 @RequestMapping(method = RequestMethod.GET , value = "/availabletimes")
public ResponseEntity<ResponseUtil> getAvailableTimes(@RequestParam String date){

    try {
        return new ResponseEntity<ResponseUtil> (new ResponseUtil(200, Constants.SUCCESS_STATUS, "Cancelled", service.getAvailableTimes(date)),HttpStatus.OK);
    }catch (BackendException e) {
        return new ResponseEntity<ResponseUtil> (new ResponseUtil(403, Constants.FAILED_STATUS, e.getMessage(), null),HttpStatus.FORBIDDEN);
    }

}

服务实现:

@Override
public List<String> getAvailableTimes(String date) {
    List<String> availableTimes = findAvailableTimes(date);

    if(availableTimes == null || availableTimes.isEmpty())
        throw new BackendException("No times available for the given date");

    return availableTimes;
}

private List<String> findAvailableTimes(String date){

    //TODO write the logic for findding the available times 
    return null;
}

存储库:

 public interface AppointmentRepo extends IRepository<Appointment, Long> {

List<Appointment> findByCustomer(Customer customer);

     }

实体:

@Entity
public class Appointment extends BaseEntity {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private Date appoitmentDate;

// Relations
@ManyToOne(fetch = FetchType.LAZY)
private Doctor doctor;
@ManyToOne(fetch = FetchType.LAZY)
private Clinic clinic;
@ManyToOne(fetch = FetchType.LAZY)
private Customer customer;
@ManyToOne(fetch = FetchType.LAZY)
private Follower follower;
@ManyToOne(fetch = FetchType.LAZY)
private AppointmentStatus appointmentStatus;
@OneToOne(fetch = FetchType.LAZY)
private Report report;

// Setters and Getters
public Doctor getDoctor() {
    return doctor;
}

public void setDoctor(Doctor doctor) {
    this.doctor = doctor;
}

public Clinic getClinic() {
    return clinic;
}

public void setClinic(Clinic clinic) {
    this.clinic = clinic;
}

public Customer getCustomer() {
    return customer;
}

public void setCustomer(Customer customer) {
    this.customer = customer;
}

public Follower getFollower() {
    return follower;
}

public void setFollower(Follower follower) {
    this.follower = follower;
}

public Date getAppoitmentDate() {
    return appoitmentDate;
}

public void setAppoitmentDate(Date appoitmentDate) {
    this.appoitmentDate = appoitmentDate;
}

public AppointmentStatus getAppointmentStatus() {
    return appointmentStatus;
}

public void setAppointmentStatus(AppointmentStatus appointmentStatus) {
    this.appointmentStatus = appointmentStatus;
}

public Report getReport() {
    return report;
}

public void setReport(Report report) {
    this.report = report;
}

}

【问题讨论】:

  • 抱歉,这个问题太宽泛了。
  • 我无法理解列出的五个解决方案中的任何一个。而且,效率在什么意义上?您需要一个大表、几个索引和一个 SQL 查询,因此它必须很快,除非您使用 TB 级数据运行它。
  • if(availableTimes == null || availableTimes.isEmpty()) throw new BackendException("No times available for the given date"); 这感觉不对。 1.永远不要让你的方法不必要地返回null。 2. 一个空列表就是这样:一个空列表。没有错误。

标签: java mysql performance spring-mvc spring-boot


【解决方案1】:

我有一个开源调度实用程序库(适用于 Android),可以处理工作时间和调度项目。它具有检查重复预订的功能,但到目前为止,它还没有返回预约空档的直接机制,但我将把它作为优先事项添加。您可以将此库的数组用于不同的诊所。您可以通过使用库中的机制在给定时间或之后获取下一个可用插槽并循环每个约会来间接获取插槽。登陆页面在这里:https://bitbucket.org/warwick/schedule_utils_demo/src/master/ 它还带有一个演示应用程序及其源代码。您也可以从 Google Play 商店下载演示应用程序:https://play.google.com/store/apps/details?id=com.WarwickWestonWright.ScheduleUtilsDemo 虽然它是一个 Android 库,但在我构建它时考虑到这一点,将它转换为标准 Java 库非常容易。当我添加了获取可用插槽列表的机制后,我会更新这篇文章。

【讨论】:

    【解决方案2】:

    我认为这不是编程问题,而是数据设计问题。

    用主键clinic_id, doctor_idtimedatepatient_id 的外键和state 字段创建一个表(实体)ClinicDoctorSchedule。 state 字段可以有以下值:open、reserved、used、no show。默认打开

    在此表中填写接下来两个月的时间表(时间表描述了在哪个诊所,哪个医生有时间)。

    这是一项繁重的工作,但一旦完成,您就可以每周更新表格。 (以一周为增量)虽然一开始工作量很大,但它也是一个灵活的解决方案,因为时间表的更改很容易应用

    患者选择weeknumber,系统从ClinicDoctorSchedule 全部返回timedates,其中clinic_id = 选定的诊所doctor_id = 选定的医生,timedate 介于firstweekdayhourlastweekdayhour 之间和state = 打开。

    当患者选择datetime 时,会发生两件事:

    1. 外键值填充patient_id
    2. 状态从开放变为保留。

    希望这会有所帮助。

    【讨论】:

    • 谢谢,但是您如何看待创建一个名为 time 的表并将这些时间放入列表中,然后通过删除与任何约会时间匹配的时间来获取可用时间。
    • @MahmoodMousa 但是为什么呢?使用由(clinic, doctor, timedate) 键入的单个表并链接到patient(或仍然可用时为NULL),您可以使用单个SQL 查询获得所需的一切,那么为什么要使用两个呢?由于可能大多数插槽都由患者填充,因此您不会存储无用的数据,所以这对我来说听起来很完美。只需为常见搜索添加索引。您所需要的只是随着时间的推移,根据管理员输入医生计划的其他表(或导入文件)生成新插槽的作业。
    猜你喜欢
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多