Skip to content

Commit

Permalink
Disable the Bed List of Already occupied Beds (back-end change) (#2116)
Browse files Browse the repository at this point in the history
* backend changes

* adding suggested changes

* adding suggested change

* add suggested changes

* add tets

* Update care/facility/tests/test_bed_api.py

Co-authored-by: Rithvik Nishad <rithvikn2001@gmail.com>

* fix lint

---------

Co-authored-by: Aakash Singh <mail@singhaakash.dev>
Co-authored-by: Rithvik Nishad <rithvikn2001@gmail.com>
Co-authored-by: rithviknishad <mail@rithviknishad.dev>
Co-authored-by: Vignesh Hari <vichuhari100@gmail.com>
  • Loading branch information
5 people authored May 22, 2024
1 parent 0214e4e commit 5670c81
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions care/facility/api/viewsets/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ class BedFilter(filters.FilterSet):
facility = filters.UUIDFilter(field_name="facility__external_id")
location = filters.UUIDFilter(field_name="location__external_id")
bed_type = CareChoiceFilter(choice_dict=inverse_bed_type)
not_occupied_by_asset_type = filters.CharFilter(
method="filter_bed_is_not_occupied_by_asset_type"
)

def filter_bed_is_not_occupied_by_asset_type(self, queryset, name, value):
if value:
return queryset.filter(
~Exists(
AssetBed.objects.filter(
bed__id=OuterRef("id"),
asset__asset_class=value,
)
)
)
return queryset


class BedViewSet(
Expand Down
28 changes: 28 additions & 0 deletions care/facility/tests/test_bed_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from rest_framework.test import APITestCase

from care.facility.models import Bed
from care.facility.models.bed import AssetBed
from care.utils.assetintegration.asset_classes import AssetClasses
from care.utils.tests.test_utils import TestUtils


Expand Down Expand Up @@ -36,3 +38,29 @@ def test_list_beds(self):
with self.assertNumQueries(5):
response = self.client.get("/api/v1/bed/")
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_list_non_occupied_beds(self):
linked_bed = Bed.objects.create(
name="linked_bed",
location=self.asset_location,
facility=self.facility,
)
asset = self.create_asset(
self.asset_location, asset_class=AssetClasses.HL7MONITOR.name
)
AssetBed.objects.create(bed=linked_bed, asset=asset)

# 4 beds 1 linked with HL7MONITOR and 3 created in setup

response = self.client.get("/api/v1/bed/")

# Assert list returns 4 beds
self.assertEqual(response.json()["count"], 4)

response_with_not_occupied_bed = self.client.get(
"/api/v1/bed/",
{"not_occupied_by_asset_type": "HL7MONITOR"},
)

# Assert count of unoccupied beds is 3
self.assertEqual(response_with_not_occupied_bed.json()["count"], 3)

0 comments on commit 5670c81

Please sign in to comment.