def update(self, request, *args, **kwargs): data = request.data # 转换时间 start = data.get("start", None) end = data.get("end", None) if start: start = datetime.datetime.strptime(start, "%H:%M").time() data["start"] = start if end: end = datetime.datetime.strptime(end, "%H:%M").time() data["end"] = end # 预约时间实例 restime = ReservationTime.objects.filter(id=self.kwargs.get("pk")) if not restime: return return_not_find("预约时间段不存在!") restime = restime[0] ser = ReservationTimeSerializer( instance=restime, data=data, partial=True ) if not ser.is_valid(): return return_param_error() ser.save() return return_success("更新成功!")
def create(self, request, *args, **kwargs): data = request.data data["creator"] = request.user.id ser = MedicineSerializer(data=data) if not ser.is_valid(): return return_param_error() ser.save() return return_success("创建药物成功!")
def create(self, request, *args, **kwargs): """ 分为两种情况 1. 管理员创建,此时需要传入doctor来指定医生 2. 专家医生创建,此时可不传入doctor(传入也不使用) """ data = request.data doctor_id = request.data.pop("doctor", None) date = data.get("date", None) start = data.get("start", None) end = data.get("end", None) if not all((date, start, end)): return return_param_error() # 管理员请求但没有传入doctor if not doctor_id and request.user.is_staff: return return_param_error() expert = Group.objects.get(name="专家医生") # 请求者不是专家医生、不是管理员时无权限 if ( expert not in request.user.groups.all() and not request.user.is_staff ): return return_forbiden() doctor = request.user # 请求者是管理员,doctor需要另外指定 if request.user.is_staff: doctor = User.objects.filter(id=doctor_id) if not doctor: return return_not_find("专家医生未找到!") doctor = doctor[0] # 指定的doctor不是专家医生 if expert not in doctor.groups.all(): return return_param_error() # 转换时间 date = datetime.datetime.strptime(date, "%Y-%m-%d").date() start = datetime.datetime.strptime(start, "%H:%M").time() end = datetime.datetime.strptime(end, "%H:%M").time() data["date"] = date data["start"] = start data["end"] = end data["doctor"] = doctor.id ser = VisitSerializer(data=data) if not ser.is_valid(): return return_param_error() ser.save() return return_success("创建成功!")
def update(self, request, *args, **kwargs): m = Medicine.objects.all().filter(id=self.kwargs.get("pk", 0)) if not m: return return_not_find("药物不存在!") m = m[0] data = request.data data["modifier"] = request.user.id ser = MedicineSerializer(instance=m, data=data, partial=True) if not ser.is_valid(): print(ser.errors) return return_param_error() ser.save() return return_success("药物更新成功!")
def update(self, request, *args, **kwargs): res = Reservation.objects.all().filter(id=self.kwargs.get("pk", 0)) if not res: return return_not_find("预约不存在!") res = res[0] # 如果请求的用户不是该预约的病人、医生或者不是管理员时无权限 if ( not res.patient == request.user and not res.doctor == request.user and not request.user.is_staff ): return return_forbiden() data = request.data is_cancel = data.get("is_cancel", None) # 取消预约 if is_cancel: res.is_cancel = 1 res.save() return return_success("取消预约成功!") # TODO: 其他字段检测 return return_success("更新预约成功!")
def update(self, request, *args, **kwargs): mt = MedicineType.objects.all().filter(id=self.kwargs.get("pk", 0)) if not mt: return return_not_find("药物类型不存在!") mt = mt[0] data = request.data data["modifier"] = request.user.id ser = MedicineTypeSerializer(instance=mt, data=data, partial=True) if not ser.is_valid(): return return_param_error() ser.save() return return_success("更新药物类型成功!")
def create(self, request, *args, **kwargs): data = request.data start = data.get("start", None) end = data.get("end", None) if not all((start, end)): return return_param_error() # 转换时间 start = datetime.datetime.strptime(start, "%H:%M").time() end = datetime.datetime.strptime(end, "%H:%M").time() data["start"] = start data["end"] = end ser = ReservationTimeSerializer(data=data) if not ser.is_valid(): print(ser.errors) return return_param_error() ser.save() return return_success("预约时间段添加成功!")
def update(self, request, *args, **kwargs): visit = Visit.objects.all().filter(id=self.kwargs.get("pk", 0)) if not visit: return return_not_find("坐诊时间不存在!") visit = visit[0] # 不是坐诊时间相关医生、不是管理员时没有操作权限 if request.user != visit.doctor and not request.user.is_staff: return return_forbiden() # 如果是专家医生,不允许指定医生 if not request.user.is_staff: request.data.pop("doctor") data = request.data # 时期、时间转换 date = data.get("date", None) if date: date = datetime.datetime.strptime(date, "%Y-%m-%d").date() data["date"] = date start = data.get("start", None) if start: start = datetime.datetime.strptime(start, "%H:%M").time() data["start"] = start end = data.get("end", None) if end: end = datetime.datetime.strptime(end, "%H:%M").time() data["end"] = end ser = VisitSerializer(instance=visit, data=data, partial=True) if not ser.is_valid(): return return_param_error() ser.save() return return_success("更新成功!")