Coverage for apps/practitioners/models.py: 85%
57 statements
« prev ^ index » next coverage.py v6.4.4, created at 2024-06-21 10:57 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2024-06-21 10:57 -0600
1from django.db import models
2from djstripe.models import Customer
4from base.models import RandomSlugModel, TimeStampedModel
7class Practitioner(RandomSlugModel, TimeStampedModel):
8 """
9 This is the base model for practitioners
10 """
12 class Meta:
13 verbose_name = "Profesionista"
14 verbose_name_plural = "Profesionistas"
16 user = models.OneToOneField("users.User", on_delete=models.SET_NULL, null=True)
17 practitioner_type = models.ForeignKey(
18 "catalogues.PractitionerType", on_delete=models.PROTECT, null=True, blank=True
19 )
21 is_paid = models.BooleanField(default=False)
23 first_name = models.CharField(max_length=128, null=True)
24 middle_name = models.CharField(max_length=128, null=True, blank=True)
25 father_last_name = models.CharField(max_length=128, null=True, blank=True)
26 mother_last_name = models.CharField(max_length=128, null=True, blank=True)
27 full_name = models.CharField(max_length=512, null=True, blank=True, editable=False)
28 conversation = models.CharField(max_length=256, null=True, blank=True, editable=False)
30 class GenderChoices(models.TextChoices):
31 MALE = "M", "Hombre"
32 FEMALE = "F", "Mujer"
33 NONBINARY = "N", "No Binario"
34 UNDISCLOSED = "U", "Prefiero no decir"
36 gender = models.CharField(max_length=8, choices=GenderChoices.choices, null=True, blank=True)
38 @property
39 def email(self):
40 return self.user.email if self.user else None
42 @property
43 def patients_count(self):
44 return self.patient_set.count()
46 @property
47 def latest_appointment(self):
48 appt = self.appointments.first()
49 if appt:
50 return appt.appointment.date
51 return None
53 @property
54 def mobile(self):
55 return self.user.phone_number if self.user else None
57 @property
58 def customer(self) -> Customer:
59 return Customer.objects.get(subscriber=self)
61 def __str__(self):
62 return self.full_name or self.random_slug
64 @property
65 def google_calendar(self):
66 return self.calendars.filter(for_sync=True).first() or None
69class Certification(RandomSlugModel, TimeStampedModel):
70 """
71 Model to show available certifications for each pactitioner
72 """
74 class Meta:
75 verbose_name = "Certificación"
76 verbose_name_plural = "Certificaciones"
78 number = models.CharField(max_length=16)
79 specialty = models.ForeignKey("catalogues.Specialty", on_delete=models.PROTECT)
80 practitioner = models.ForeignKey("practitioners.Practitioner", on_delete=models.CASCADE)
83class PractitionerGoogleCalendar(RandomSlugModel, TimeStampedModel):
84 practitioner = models.ForeignKey("practitioners.Practitioner", on_delete=models.CASCADE, related_name="calendars")
85 calendar_id = models.CharField(max_length=256, null=True, blank=True)
86 name = models.CharField(max_length=256, null=True, blank=True)
87 timezone = models.CharField(max_length=128, null=True, blank=True, default="America/Mexico_City")
88 json = models.JSONField(null=True, blank=True)
89 for_sync = models.BooleanField(default=False)