Add the pre-visit notes API for patients

Python · Django · intermediate · modification

Adds the pre-visit notes API so patients can jot down symptoms and questions before an appointment. Every endpoint works on the signed-in patient's own notes: create attaches the patient server-side, so nobody can file a note under someone else, and the detail view is a standard RetrieveUpdateAPIView behind IsAuthenticated like the list. Tested in the browsable API: created two notes, edited one, listed both.

Clinic scheduling app; patients sign in on the public website (DRF session authentication is configured project-wide; no default pagination class is set). The `notes` app was scaffolded and added to INSTALLED_APPS in the previous PR, and `rest_framework` is installed. Note ids are sequential integers and appear in the frontend URLs. Notes hold free-text health information.

Requirements

Files touched

--- notes/models.py
+from django.conf import settings
 from django.db import models
 
-# Create your models here.
 
+class AppointmentNote(models.Model):
+    patient = models.ForeignKey(
+        settings.AUTH_USER_MODEL,
+        on_delete=models.CASCADE,
+        related_name="appointment_notes",
+    )
+    appointment_date = models.DateField()
+    body = models.CharField(max_length=2000)
+    created_at = models.DateTimeField(auto_now_add=True)
+    updated_at = models.DateTimeField(auto_now=True)
+
+    class Meta:
+        ordering = ["-appointment_date", "-created_at"]
+
+    def __str__(self):
+        return f"Note {self.pk} for {self.appointment_date}"
+
--- notes/migrations/0001_initial.py
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):

Review this PR

Python practice