Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old bed name field and fix bed name validator #1894

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions care/facility/migrations/0414_remove_bed_old_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.10 on 2024-02-14 11:41

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("facility", "0413_eventtype_patientconsultationevent_and_more"),
]

operations = [
migrations.RemoveField(
model_name="bed",
name="old_name",
),
]
4 changes: 2 additions & 2 deletions care/facility/models/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
However this is an addon feature and is not required for the regular patient flow,
Leaving scope to build rooms and wards to being even more organization.
"""

from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import JSONField
Expand All @@ -17,7 +18,6 @@

class Bed(BaseModel):
name = models.CharField(max_length=1024)
old_name = models.CharField(max_length=1024, null=True, blank=True)
description = models.TextField(default="", blank=True)
bed_type = models.IntegerField(
choices=BedTypeChoices, default=BedType.REGULAR.value
Expand Down Expand Up @@ -49,7 +49,7 @@ def __str__(self):

def validate(self) -> None:
if (
Bed.objects.filter(location=self.location, name=self.name)
Bed.objects.filter(location=self.location, name__iexact=self.name)
.exclude(pk=self.pk)
.exists()
):
Expand Down
30 changes: 30 additions & 0 deletions care/facility/tests/test_bed_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ def test_create(self):
sample_data["number_of_beds"],
)

def test_create_with_same_name(self):
sample_data = {
"bed_type": "REGULAR",
"description": "Testing creation of beds.",
"facility": self.facility.external_id,
"location": self.asset_location.external_id,
"name": "Test Bed",
"number_of_beds": 1,
}
response = self.client.post("/api/v1/bed/", sample_data, format="json")
self.assertIs(response.status_code, status.HTTP_201_CREATED)

response = self.client.post("/api/v1/bed/", sample_data, format="json")
self.assertIs(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.json()["name"],
["Bed with same name already exists in location."],
)

# validate case insensitive
sample_data["name"] = "test bed"
response = self.client.post("/api/v1/bed/", sample_data, format="json")
self.assertIs(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.json()["name"],
["Bed with same name already exists in location."],
)

self.assertEqual(Bed.objects.filter(facility=self.facility).count(), 1)


class MultipleBedTest(TestUtils, APITestCase):
@classmethod
Expand Down
Loading