Clinic-Booking-Project icon indicating copy to clipboard operation
Clinic-Booking-Project copied to clipboard

amazing idea could add this

Open dregypt opened this issue 2 years ago • 1 comments

class Appointment(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True) service = models.CharField(max_length=50, choices=SERVICE_CHOICES, default="Doctor care") doctor_name = models.CharField(max_length=50)
day = models.DateField(default=datetime.now) time = models.CharField(max_length=10, choices=TIME_CHOICES, default="3 PM") time_ordered = models.DateTimeField(default=datetime.now, blank=True) def str(self): return f"{self.user.username} | day: {self.day} | time: {self.time}"

class Doctor(models.Model): """docstring for Doctor""" user = models.OneToOneField(User, on_delete=models.CASCADE) image = models.ImageField('Profile Image', upload_to='Image/Doctors', max_length=500, default='dummy.png') first_name = models.CharField('First Name', max_length=50) second_name = models.CharField('Second Name', max_length=50) title = models.CharField('Title', max_length=200, default='Dr.') phone_no = models.CharField('Phone Number', max_length=50) email = models.EmailField('Email', max_length=250) gender = models.CharField('Gender', max_length=10) d_o_b = models.DateField('Date of Birth', blank=True) biography = models.CharField('Biography', max_length=1000, blank=True) address_line1 = models.CharField('Address Line 1', max_length=200, blank=True) pricing = models.FloatField('Amount', default=0.00) services = models.CharField('Services', max_length=1000, blank=True) specialization = models.CharField('Specialization', max_length=1000, blank=True) clinic = models.CharField('Clinic', max_length=100, blank=True) clinic_address = models.CharField('Clinic Address', max_length=100, blank=True) speciality = models.OneToOneField(Speciality, on_delete=models.CASCADE) def full_name(self): return self.title + " " + self.first_name + " " + self.second_name

def total_revenue(self):
	invoices = Invoice.objects.filter(doctor=self.id)
	revenue = 0.0
	for inv in invoices:
		revenue = revenue + inv.total_amount 
	return revenue

def availability(self):
	today = dt.date.today()
	duration = dt.timedelta(days=2)
	date = today + duration
	slot = 'unavailable'
	for x in range(1,8):
		day = str(f"{date:%A}").lower()
		schedule = DoctorSchedule.objects.get(doctor=self.id, day=day) # doctor, day, interval
		time_slots = TimeSlot.objects.filter(schedule=schedule.id) # schedule, start_time, end_time
		if time_slots.count() == 0:
			duration = dt.timedelta(days=1)
			date = date + duration
		else:
			appointments = Appointment.objects.filter(doctor=self.id, booking_date__date__gte=date)
			if appointments.count()==0:
				slot = "Available on "+str(f"{date:%a, %d %b}")
				break
			else:
				unavailable_time = []
				for appointment in appointments:
					unavailable_time += [appointment.booking_date.time]
				for slot in time_slots:
					if slot.start_time not in unavailable_time:
						slot = "Available on "+str(f"{date:%a, %d %b}")
						break
				if slot != 'unavailable':
					break
				else:
					duration = dt.timedelta(days=1)
					date = date + duration

	return slot

def today_time_slots(self):
	now = timezone.now()
	day = str(f"{now:%A}").lower()
	schedule = DoctorSchedule.objects.get(doctor=self.id, day=day)
	time_slots = TimeSlot.objects.filter(schedule=schedule.id)
	return time_slots

def open_now(self):
	now = timezone.now()
	day = str(f"{now:%A}").lower()
	schedule = DoctorSchedule.objects.get(doctor=self.id, day=day)
	time_slots = TimeSlot.objects.filter(schedule=schedule.id)
	for slot in time_slots:
		if now.time() > slot.start_time and now.time() < slot.end_time:
			return True
	return False
def service_list(self):
	services = self.services
	return services.split(',')

def specialization_list(self):
	specialization = self.specialization
	return specialization.split(',')


def my_patient_id(self):
	appointments = Appointment.objects.filter(doctor=self.id)
	patients = []
	for appointment in appointments:
		if appointment.patient.id not in patients:
			patients += [appointment.patient.id]
	return patients

class DoctorSchedule(models.Model): doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE) day = models.CharField('Day', max_length=10) interval = models.IntegerField('Interval') # doctor, day, interval

def all_timeslots(self):
	schedules = DoctorSchedule.objects.filter(doctor=self.doctor.id)
	slots = {}
	for schedule in schedules:
		day = 'slot_'+str(schedule.day)
		time_slots = TimeSlot.objects.filter(schedule=schedule.id)
		if time_slots == []:
			time_slots = None
		slots.setdefault(day, time_slots)
	return slots

def timeslots(self):
	schedule = DoctorSchedule.objects.get(id=self.id)
	time_slots = TimeSlot.objects.filter(schedule=schedule.id)
	return time_slots

class TimeSlot(models.Model): schedule = models.ForeignKey(DoctorSchedule, on_delete=models.CASCADE) start_time = models.TimeField('Start Time') end_time = models.TimeField('End Time') #schedule, start_time, end_time

def slot(self):
	time = str(f"{self.start_time:%I.%M %p}")+" - "+str(f"{self.end_time:%I.%M %p}")
	return time

dregypt avatar Jan 30 '23 12:01 dregypt