forked from prlbkj9i7/wzy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
211 lines
10 KiB
211 lines
10 KiB
import datetime
|
|
import uuid
|
|
from django.http import HttpResponseRedirect
|
|
from django.shortcuts import render
|
|
from django.views import View
|
|
from .models import *
|
|
|
|
class ChooseLoginView(View): # 选择登录
|
|
def get(self, request):
|
|
return render(request, 'chooselogin.html')
|
|
|
|
class PatientLoginView(View): # 患者登录
|
|
def get(self, request):
|
|
return render(request, 'patientlogin.html')
|
|
def post(self, request):
|
|
phone = request.POST.get('phone','')
|
|
password = request.POST.get('password','')
|
|
patient_list = Patient.objects.filter(phone=phone, password=password)
|
|
if patient_list:
|
|
print(type(patient_list[0]))
|
|
request.session.clear()
|
|
request.session['patient'] = patient_list[0].name
|
|
return HttpResponseRedirect("/patientcenter/")
|
|
else:
|
|
return HttpResponseRedirect("/patientlogin/")
|
|
|
|
class DoctorLoginView(View):
|
|
def get(self, request):
|
|
return render(request, 'doctorlogin.html')
|
|
def post(self, request):
|
|
phone = request.POST.get('phone','')
|
|
password = request.POST.get('password','')
|
|
doctor_list = Doctor.objects.filter(phone=phone, password=password)
|
|
if doctor_list:
|
|
request.session['doctor'] = doctor_list[0].name
|
|
request.session['doctor_image'] = str(doctor_list[0].img)
|
|
return HttpResponseRedirect("/doctorcenter/")
|
|
else:
|
|
return HttpResponseRedirect("/doctorlogin/")
|
|
|
|
class PatientRegisterView(View): # 患者注册
|
|
def get(self, request):
|
|
return render(request, 'patientregister.html')
|
|
def post(self, request):
|
|
phone = request.POST.get('phone','')
|
|
patientlist = Patient.objects.filter(phone=phone)
|
|
if patientlist:
|
|
return render(request, 'patientregister.html',{"err":1,"tips":"该号码已被注册"})
|
|
else:
|
|
password = request.POST.get('password','')
|
|
name = request.POST.get('name','')
|
|
sex = request.POST.get('sex','')
|
|
age = request.POST.get('age','')
|
|
patient = Patient.objects.create(phone=phone, password=password, name=name, sex=sex, age=age)
|
|
if patient:
|
|
return HttpResponseRedirect("/patientlogin/")
|
|
return HttpResponseRedirect("/patientregister/")
|
|
|
|
class PatientCenterView(View):
|
|
def get(self, request):
|
|
patient = request.session.get('patient','')
|
|
print(patient)
|
|
return render(request, 'patientcenter.html',{"patient_name":patient})
|
|
|
|
class ChooseDepartmentView(View):
|
|
def get(self, request):
|
|
department_list = Department.objects.filter().all()
|
|
return render(request, 'choosedepartment.html',{"department_list":department_list})
|
|
|
|
class ChooseDoctorAndTimeView(View):
|
|
def get(self, request, department_id):
|
|
department_id = int(department_id)
|
|
department_name= Department.objects.get(id=department_id).name
|
|
doctor_list = Doctor.objects.filter(department_id=department_id)
|
|
doctor_time_number_list = []
|
|
for doctor in doctor_list:
|
|
doctor_time_number_list.append([doctor,TimeNumber.objects.get(doctor_id=doctor.id)])
|
|
tomorrow =(datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
return render(request, 'choosedoctorandtime.html',{"department_name":department_name,"doctor_time_number_list":doctor_time_number_list,"tomorrow":tomorrow,"department_id":department_id})
|
|
|
|
class ConfirmRegistrationView(View):
|
|
def get(self, request, department_id, doctor_id, consultation_hour):
|
|
time_number = TimeNumber.objects.get(doctor_id=doctor_id)
|
|
if consultation_hour[:2] == '08' and time_number.eight == 0:
|
|
return
|
|
elif consultation_hour[:2] == '09' and time_number.nine == 0:
|
|
return
|
|
elif consultation_hour[:2] == '10' and time_number.ten == 0:
|
|
return
|
|
elif consultation_hour[:2] == '11' and time_number.eleven == 0:
|
|
return
|
|
elif consultation_hour[:2] == '14' and time_number.fourteen == 0:
|
|
return
|
|
elif consultation_hour[:2] == '15' and time_number.fifteen == 0:
|
|
return
|
|
elif consultation_hour[:2] == '16' and time_number.sixteen == 0:
|
|
return
|
|
elif consultation_hour[:2] == '17' and time_number.seventeen == 0:
|
|
return
|
|
department_id = int(department_id)
|
|
doctor_id = int(doctor_id)
|
|
patient = request.session.get('patient','')
|
|
doctor = Doctor.objects.get(id=doctor_id)
|
|
department = Department.objects.get(id=department_id)
|
|
patient_name = patient
|
|
doctor_name = doctor
|
|
registration_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
consultation_hour = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%Y-%m-%d")+" "+consultation_hour
|
|
patient_id = Patient.objects.filter(name=patient).first().id
|
|
address = department.address
|
|
registration_price =doctor.registration_price
|
|
return render(request, 'confirmregistration.html',{"patient_name":patient_name,"doctor_name":doctor_name,"registration_time":registration_time,"consultation_hour":consultation_hour,"patient_id":patient_id,"address":address,"registration_price":registration_price,"doctor_id":doctor_id})
|
|
|
|
def post(self, request,*args,**kwargs):
|
|
registration_time = request.POST.get('registration_time','')
|
|
consultation_hour = request.POST.get('consultation_hour','')
|
|
illness = request.POST.get('illness','')
|
|
doctor_id = request.POST.get('doctor_id','')
|
|
patient_id = request.POST.get('patient_id','')
|
|
address = request.POST.get('address','')
|
|
out_trade_num = uuid.uuid4().hex
|
|
payway = '支付宝'
|
|
status = '已支付,未检查'
|
|
register =Register.objects.filter(consultation_hour=consultation_hour,patient_id=patient_id)
|
|
if register:
|
|
return render(request, 'confirmregistration.html',{"message":"支付失败,该时间段已有挂号单"})
|
|
else:
|
|
Register.objects.create(registration_time=registration_time,consultation_hour=consultation_hour,illness=illness,address=address,out_trade_num=out_trade_num,payway=payway,status=status,patient_id=patient_id,doctor_id=doctor_id)
|
|
time_number = TimeNumber.objects.filter(doctor_id=doctor_id).first()
|
|
if consultation_hour[11:13] == '08':
|
|
time_number.eight = time_number.eight - 1
|
|
elif consultation_hour[11:13] == '09':
|
|
time_number.nine = time_number.nine - 1
|
|
elif consultation_hour[11:13] == '10':
|
|
time_number.ten = time_number.ten - 1
|
|
elif consultation_hour[11:13] == '11':
|
|
time_number.eleven = time_number.eleven - 1
|
|
elif consultation_hour[11:13] == '14':
|
|
time_number.fourteen = time_number.fourteen - 1
|
|
elif consultation_hour[11:13] == '15':
|
|
time_number.fifteen = time_number.fifteen - 1
|
|
elif consultation_hour[11:13] == '16':
|
|
time_number.sixteen = time_number.sixteen - 1
|
|
elif consultation_hour[11:13] == '17':
|
|
time_number.seventeen = time_number.seventeen - 1
|
|
time_number.save()
|
|
return render(request, 'confirmregistration.html',{"message":"支付成功"})
|
|
|
|
class PatientShowRegistrationView(View):
|
|
def get(self, request):
|
|
patient = Patient.objects.filter(name=request.session.get('patient','')).first()
|
|
register_list = Register.objects.filter(patient_id=patient.id)
|
|
return render(request, 'patientshowregistration.html',{"register_list":register_list})
|
|
class DoctorCenterView(View):
|
|
def get(self, request):
|
|
doctor =request.session.get('doctor','')
|
|
doctor_image = request.session.get('doctor_image','')
|
|
return render(request, 'doctorcenter.html',{"doctor":doctor,"doctor_image":doctor_image})
|
|
|
|
|
|
class DoctorShowRegistrationView(View):
|
|
def get(self, request):
|
|
doctor = request.session.get('doctor','')
|
|
doctor = Doctor.objects.filter(name=doctor).first()
|
|
try:
|
|
register_list =doctor.register_set.order_by('consultation_hour').filter(status='已支付,未检查').all()
|
|
except Exception as e:
|
|
print(e)
|
|
register_list=[]
|
|
|
|
return render(request, 'doctorshowregistration.html',{"register_list":register_list,"doctor_image":doctor.img})
|
|
def post(self, request):
|
|
register_id = request.POST.get('register_id','')
|
|
register = Register.objects.get(id=register_id)
|
|
register.status = '已检查'
|
|
print(register.consultation_hour)
|
|
consultation_hour = str(register.consultation_hour)[11:13]
|
|
register.save()
|
|
doctor =request.session.get('doctor','')
|
|
doctor =Doctor.objects.filter(name=doctor).first()
|
|
time_number = TimeNumber.objects.filter(doctor_id=doctor.id).first()
|
|
if consultation_hour == '08':
|
|
time_number.eight = time_number.eight + 1
|
|
elif consultation_hour == '09':
|
|
time_number.nine = time_number.nine + 1
|
|
elif consultation_hour == '10':
|
|
time_number.ten = time_number.ten + 1
|
|
elif consultation_hour == '11':
|
|
time_number.eleven = time_number.eleven + 1
|
|
elif consultation_hour == '14':
|
|
time_number.fourteen = time_number.fourteen + 1
|
|
elif consultation_hour == '15':
|
|
time_number.fifteen = time_number.fifteen + 1
|
|
elif consultation_hour == '16':
|
|
time_number.sixteen = time_number.sixteen + 1
|
|
elif consultation_hour == '17':
|
|
time_number.seventeen = time_number.seventeen + 1
|
|
time_number.save()
|
|
|
|
try:
|
|
register_list =doctor.register_set.order_by('consultation_hour').filter(status='已支付,未检查').all()
|
|
except Exception as e:
|
|
print(e)
|
|
register_list=[]
|
|
|
|
return render(request, 'doctorshowregistration.html',{"register_list":register_list,"doctor_image":doctor.img})
|
|
|
|
|
|
|
|
|