From f7354d1f3251e62ed28a9ff99b0f93961608ad2f Mon Sep 17 00:00:00 2001 From: Muchogo Date: Fri, 11 Mar 2022 11:12:19 +0300 Subject: [PATCH] chore: add appointment status choices and shared appointment identifier --- .../migrations/0002_auto_20220311_1137.py | 38 +++++++++++++++++++ mycarehub/appointments/models.py | 26 +++++++++++-- mycarehub/appointments/tests/test_models.py | 4 +- 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 mycarehub/appointments/migrations/0002_auto_20220311_1137.py diff --git a/mycarehub/appointments/migrations/0002_auto_20220311_1137.py b/mycarehub/appointments/migrations/0002_auto_20220311_1137.py new file mode 100644 index 0000000..600ab02 --- /dev/null +++ b/mycarehub/appointments/migrations/0002_auto_20220311_1137.py @@ -0,0 +1,38 @@ +# Generated by Django 3.2.12 on 2022-03-11 08:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('appointments', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='appointment', + name='appointment_uuid', + field=models.UUIDField(blank=True, editable=False, help_text='Identifier that is shared between KenyaEMR and MyCareHub', null=True), + ), + migrations.AlterField( + model_name='appointment', + name='date', + field=models.DateField(blank=True, null=True), + ), + migrations.AlterField( + model_name='appointment', + name='end_time', + field=models.TimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='appointment', + name='start_time', + field=models.TimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='appointment', + name='status', + field=models.CharField(choices=[('SCHEDULED', 'Scheduled'), ('RESCHEDULED', 'Rescheduled'), ('WAITING', 'Waiting'), ('MISSED', 'Missed'), ('COMPLETED', 'Completed'), ('INCONSULTATION', 'In Consultation'), ('WALKIN', 'Walk In'), ('CANCELLED', 'Cancelled'), ('NEEDSRESCHEDULE', 'Needs Reschedule')], max_length=36), + ), + ] diff --git a/mycarehub/appointments/models.py b/mycarehub/appointments/models.py index 91813e9..42da02f 100644 --- a/mycarehub/appointments/models.py +++ b/mycarehub/appointments/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models.enums import TextChoices from django.utils.translation import gettext_lazy as _ from mycarehub.clients.models import Client @@ -15,8 +16,25 @@ class Appointment(AbstractBase): It is referenced from the Open MRS appointment data model """ + class AppointmentStatus(TextChoices): + SCHEDULED = "SCHEDULED", _("Scheduled") + RESCHEDULED = "RESCHEDULED", _("Rescheduled") + WAITING = "WAITING", _("Waiting") + MISSED = "MISSED", _("Missed") + COMPLETED = "COMPLETED", _("Completed") + INCONSULTATION = "INCONSULTATION", _("In Consultation") + WALKIN = "WALKIN", _("Walk In") + CANCELLED = "CANCELLED", _("Cancelled") + NEEDSRESCHEDULE = "NEEDSRESCHEDULE", _("Needs Reschedule") + + appointment_uuid = models.UUIDField( + editable=False, + null=True, + blank=True, + help_text=_("Identifier that is shared between KenyaEMR and MyCareHub"), + ) appointment_type = models.CharField(max_length=36) - status = models.CharField(max_length=36) + status = models.CharField(max_length=36, choices=AppointmentStatus.choices) reason = models.TextField(max_length=1024, null=True, blank=True) client = models.ForeignKey(Client, on_delete=models.PROTECT) staff = models.ForeignKey(Staff, on_delete=models.PROTECT, null=True, blank=True) @@ -28,9 +46,9 @@ class Appointment(AbstractBase): null=True, blank=True, ) - date = models.DateField() - start_time = models.TimeField() - end_time = models.TimeField() + date = models.DateField(null=True, blank=True) + start_time = models.TimeField(null=True, blank=True) + end_time = models.TimeField(null=True, blank=True) def __str__(self) -> str: return f"{self.client} - {self.appointment_type} - {self.status}" diff --git a/mycarehub/appointments/tests/test_models.py b/mycarehub/appointments/tests/test_models.py index 62b790e..a3a35dd 100644 --- a/mycarehub/appointments/tests/test_models.py +++ b/mycarehub/appointments/tests/test_models.py @@ -12,8 +12,8 @@ def test_appointments_str(user): appointment = baker.make( Appointment, appointment_type="consultation", - status="completed", + status="COMPLETED", client=client, ) - assert str(appointment) == f"{client} - consultation - completed" + assert str(appointment) == f"{client} - consultation - COMPLETED"