【发布时间】:2020-08-19 14:53:49
【问题描述】:
我正在为医生的预约设计一个架构。医生将可以选择更新他/她每月个别日子的时间安排。也没有几个月的限制。例如,医生将能够更新未来或当前月份任何日期的时间。 (只有以前的日期将被禁用)。前端部分已经完成,但我不明白如何为其创建 mongo 模型。当然,我不能将所有月份的日期都存储在模型中。解决这个问题的方法是什么? TIA
【问题讨论】:
我正在为医生的预约设计一个架构。医生将可以选择更新他/她每月个别日子的时间安排。也没有几个月的限制。例如,医生将能够更新未来或当前月份任何日期的时间。 (只有以前的日期将被禁用)。前端部分已经完成,但我不明白如何为其创建 mongo 模型。当然,我不能将所有月份的日期都存储在模型中。解决这个问题的方法是什么? TIA
【问题讨论】:
如果是我有这样的项目,我会从5个集合开始:
这样您就可以回到过去并知道是怎么做到的...永远不要将手指指向犯错的人,而是将其视为一种非常简单的方法来找出发生的事情以及如何解决防止它再次发生。
每个文档的内容完全取决于您,因为这将随着您正在做什么和如何做而改变
我会在这几行之间考虑一些事情:
// Users
{
username, hashedPassword, // credentials
permissions: [], // for when you start using permissions
active, // never delete data, just set the flag to "false", if, by GDPR rules you need to delete, you can change the name to "DELETED BY GDPR" and still maintain all references
}
// Patients
{
name,
address: { street, street2, city, zipcode, country }, // for invoicing proposes
mobile, // so you send them an SMS 24h before saying their appointment is "tomorrow"
}
// Doctors
{
name,
weekAvailability: [], // days of the week that a doctor is available as they normally work in more than one clinique
active, // never delete data, just set the flag to "false", if, by GDPR rules you need to delete, you can change the name to "DELETED BY GDPR" and still maintain all references
}
// Logs
{
action, // for example, "save", "add", "change"...
entity, // the collection name that the change happened
originalEntry, // the full document before changes
newEntry, // the full document after changes
timestamp, // the exact time of the change
user, // ref to users
}
// TimeRegistrations
{
user, // ref to users
patient, // ref to patients
doctor, // ref to doctors
title, description, appointmentStart, durationInMinutes,
}
关于基础架构...创建一个 API(REST 或 GRAPHQL,您最熟悉的那个),这样您就可以从一开始就将业务逻辑与前端分开
你的前端(可能是 React、Angular、VueJs)应该调用一个代理(nodeJs 服务器在前端旁边运行)来进行身份验证并调用 API,所以你应该在前端做的所有事情都类似于
fetch('/api/doctors')
.then(res => res.toJson())
.then(json => {
this.doctorsList = json
})
与user 的身份验证相同,您可以轻松地使用库为您提供 JWT 并轻松维护用户登录和正确的权限集
【讨论】:
第一种方法,但在您的情况下不好,即一个集合,
//doctors
{
_id: "",
appointments: [] // all appointments there
}
第二个会更好,但 NoSql 集合中的注释完全取决于您希望如何获取数据。两个合集:
//doctors
{
_id: "SOMETHING",
name: "SOMETHING"
}
//appointments
{
_id: "SOMETHING",
doctorId: "", // ref of doctor collection
appointmentAt: "",
appointmentAtMilli: "",
}
【讨论】: