def update(self, request, *args, **kwargs): record = MedicalRecord.objects.all().filter( id=self.kwargs.get("pk", 0)) if not record: return return_not_find("病历不存在!") record = record[0] if not record.can_modify: return return_param_error("此病历不可编辑!") data = request.data data["modifier"] = request.user.id onset_date = request.data.get("onset_date", None) if onset_date: data["onset_date"] = datetime.datetime.strptime( onset_date, "%Y-%m-%d").date() # 弹出不可更改的字段 data.pop("id", None) data.pop("time", None) data.pop("create_time", None) data.pop("modify_time", None) data.pop("patient", None) data.pop("department", None) data.pop("creator", None) ser = MedicalRecordSerializer(instance=record, data=data, partial=True) if not ser.is_valid(): print(ser.errors) return return_param_error() ser.save() return return_success("修改成功!")
def create(self, request, *args, **kwargs): # 验证是否传入patient和items patient_id = request.data.pop("patient", None) items = request.data.pop("items", None) if not patient_id or not items: return return_param_error() # 验证此id是否存在 patient = User.objects.all().filter(id=patient_id) if not patient: return return_not_find("病人不存在!") patient = patient[0] # 验证此id对应用户是否为病人 p = Group.objects.get(name="病人") if p not in patient.groups.all(): return return_param_error("此用户不是病人!") # 创建处方签 data = { "patient": patient_id, "is_paid": 0, "creator": request.user.id, } ser = PrescriptionSerializer(data=data) if not ser.is_valid(): print(ser.errors) return return_param_error() pre = ser.save() for item in items: item["prescription"] = pre.id ser = PrescriptionItemSerializer(data=items, many=True) if not ser.is_valid(): pre.delete() print(ser.errors) return return_param_error() ser.save() # 创建药单 data = {"creator": request.user.id, "prescription": pre.id} ser = MedicineHandoutRecordSerializer(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): ins = PayType.objects.all().filter(id=self.kwargs.get("pk", 0)) if not ins: return return_param_error("缴费类型不存在!") ins = ins[0] data = request.data data.pop("creator", None) data.pop("creator", None) data["modifier"] = request.user.id ser = PayTypeSerializer(instance=ins, data=data, partial=True) if not ser.is_valid(): print(ser.errors) return return_param_error() return return_success("修改成功!")
def create(self, request, *args, **kwargs): data = {"applicant": request.user.id} ser = AuditRecordSerializer(data=data) if not ser.is_valid(): print(ser.errors) return return_param_error() ins = ser.save() items = request.data for item in items: item["audit"] = ins.id ser = AuditItemSerializer(data=items, many=True) if not ser.is_valid(): ins.delete() print(ser.errors) return return_param_error() ser.save() return return_success("审核记录创建成功!")
def update(self, request, *args, **kwargs): ins = AuditRecord.objects.all().filter(id=self.kwargs.get("pk", 0)) if not ins: return return_not_find("审核记录不存在!") ins = ins[0] data = { "result": request.data.get("result", None), "commet": request.data.get("commet", None), } if data["result"]: data["result"] = 1 data["auditor"] = request.user.id ser = AuditRecordSerializer(instance=ins, data=data, partial=True) if not ser.is_valid(): print(ser.errors) return return_param_error() ser.save() return return_success("审核记录修改成功!")
def add_user_groups(self, request, pk=None): if not pk: return return_param_error() if not request.user or not request.user.is_staff: return return_forbiden() user = User.objects.all().filter(id=pk) if not user: return return_not_find("用户不存在!") group_id = request.data.get("group", None) if not group_id: return return_param_error() group = Group.objects.all().filter(id=group_id) if not group: return return_not_find("用户组不存在!") group = group[0] user = user[0] user.groups.add(group) return return_success("添加成功!")
def add_group_users(self, request, pk=None): if not pk: return return_param_error() group = Group.objects.filter(id=pk) if not group: return return_not_find("用户组不存在!") group = group[0] user_id = request.data.get("user", None) if not user_id: return return_param_error() user = User.objects.filter(id=user_id) if not user: return return_not_find("用户不存在!") user = user[0] if user in group.user_set.all(): return return_param_error("用户已在所添加的组内!") group.user_set.add(user) return return_success("添加成功!")
def create(self, request, *args, **kwargs): request.data["creator"] = request.user.id ser = RefundRecordSerializer(data=request.data) if not ser.is_valid(): print(ser.errors) return return_param_error() ins = ser.save() items = request.data.get("items", None) if not items: return return_param_error() for item in items: item["record"] = ins.id ser = RefundRecordItemSerializer(data=items, many=True) if not ser.is_valid(): ins.delete() print(ser.errors) return return_param_error() ser.save() return return_success("退款记录创建成功!")
def create(self, request, *args, **kwargs): data = request.data patient_id = data.get("patient", None) reservation_id = data.get("reservation", None) department_id = data.get("department", None) pay_id = data.get("pay", None) doctor_id = data.get("doctor", None) wait_queues = self.get_wait_queues() # 如果传入了预约,进行预约检查 if reservation_id: reservation = Reservation.objects.all().filter(id=reservation_id) if not reservation: return return_param_error("预约不存在!") reservation = reservation[0] if reservation.is_cancel: return return_param_error("该预约已取消!") if reservation.date < datetime.datetime.today().date(): return return_param_error("该预约已过期!") elif reservation.date > datetime.datetime.today().date(): return return_param_error("该预约时间不是今天!") if reservation.time.end <= datetime.datetime.now().time(): return return_param_error("该预约已过期!") if reservation.is_finish: return return_param_error("该预约已经使用过,无效!") if not reservation.is_paid or not reservation.pay: return return_param_error("该预约还未缴费!") data = { "patient": reservation.patient.id, "doctor": reservation.doctor.id if reservation.doctor else None, "department": reservation.department.id, "pay": reservation.pay.id, "reservation": reservation.id, } ser = WaitQueueSerializer(data=data) if not ser.is_valid(): print(ser.errors) return return_param_error() ins = ser.save() if self._add_into_queue(ins, wait_queues): # 更新 ins.reservation.is_finish = 1 ins.reservation.save() return return_success("成功加入到排队队列中!") else: return return_param_error("已经在排队中,不能重复添加!") # 不是预约,现场挂号病人排队 # 进行各项参数检查 if not all((patient_id, department_id, pay_id)): return return_param_error() patient = User.objects.all().filter(id=patient_id) if not patient: return return_param_error("病人不存在!") patient = patient[0] pg = Group.objects.get(name="病人") if pg not in patient.groups.all(): return return_param_error("此用户不是病人!") department = Group.objects.all().filter(id=department_id) if not department: return return_param_error("科室不存在!") department = department[0] dg = Group.objects.get(name="科室") if dg not in get_all_groups(department): return return_param_error("组不是科室!") pay = PayRecord.objects.all().filter(id=pay_id) if not pay: return return_param_error("缴费记录不存在!") pay = pay[0] if pay.patient.id != patient.id: return return_param_error("病人与缴费记录不对应!") data = { "patient": patient_id, "department": department_id, "pay": pay_id, } # 专家号再检查专家id if doctor_id: doctor = User.objects.all().filter(id=doctor_id) if not doctor: return return_param_error("医生不存在!") doctor = doctor[0] edg = Group.objects.get(name="专家医生") if edg not in doctor.groups.all(): return return_param_error("用户不是专家医生!") data["doctor"] = doctor_id ser = WaitQueueSerializer(data=data) if not ser.is_valid(): print(ser.errors) return return_param_error() if self._add_into_queue(ser.save(), wait_queues): return return_success("成功加入到排队队列中!") else: return return_param_error("已经在排队中,不能重复添加!")
def get(self, request, *args, **kwargs): return return_success("成功登出!")