Skip to content

Commit

Permalink
Added is_occupied read-only field in Bed (#1083)
Browse files Browse the repository at this point in the history
feat (bed): added is_occupied read-only field
  • Loading branch information
khavinshankar authored Oct 28, 2022
1 parent 5bde4b6 commit 2b6c282
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion care/facility/api/serializers/bed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.shortcuts import get_object_or_404
from rest_framework.exceptions import ValidationError
from rest_framework.serializers import ModelSerializer, UUIDField
from rest_framework.serializers import BooleanField, ModelSerializer, UUIDField

from care.facility.api.serializers import TIMESTAMP_FIELDS
from care.facility.api.serializers.asset import AssetLocationSerializer, AssetSerializer
Expand All @@ -20,6 +20,7 @@ class BedSerializer(ModelSerializer):
bed_type = ChoiceField(choices=BedTypeChoices)

location_object = AssetLocationSerializer(source="location", read_only=True)
is_occupied = BooleanField(default=False, read_only=True)

location = UUIDField(write_only=True, required=True)
facility = UUIDField(write_only=True, required=True)
Expand Down
4 changes: 4 additions & 0 deletions care/facility/models/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Bed(BaseModel):
AssetLocation, on_delete=models.PROTECT, null=False, blank=False
)

@property
def is_occupied(self) -> bool:
return ConsultationBed.objects.filter(bed=self, end_date__isnull=True).exists()

def __str__(self):
return self.name

Expand Down

0 comments on commit 2b6c282

Please sign in to comment.