Skip to content

Commit

Permalink
add rounds_type filter for daily rounds (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak authored Sep 2, 2022
1 parent 576b901 commit 81823a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions care/facility/api/viewsets/daily_round.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django_filters import rest_framework as filters
from dry_rest_permissions.generics import DRYPermissions
from rest_framework import mixins
from rest_framework.decorators import action
Expand All @@ -16,6 +17,20 @@
DailyRoundAttributes = [f.name for f in DailyRound._meta.get_fields()]


class DailyRoundFilterSet(filters.FilterSet):
rounds_type = filters.CharFilter(method="filter_rounds_type")

def filter_rounds_type(self, queryset, name, value):
rounds_type = set()
values = value.split(",")
for v in values:
try:
rounds_type.add(DailyRound.RoundsTypeDict[v])
except KeyError:
pass
return queryset.filter(rounds_type__in=list(rounds_type))


class DailyRoundsViewSet(
AssetUserAccessMixin,
mixins.CreateModelMixin,
Expand All @@ -31,6 +46,9 @@ class DailyRoundsViewSet(
)
queryset = DailyRound.objects.all().order_by("-id")
lookup_field = "external_id"
filterset_class = DailyRoundFilterSet

filter_backends = (filters.DjangoFilterBackend,)

FIELDS_KEY = "fields"
MAX_FIELDS = 20
Expand Down
2 changes: 2 additions & 0 deletions care/facility/models/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from multiselectfield import MultiSelectField

from care.facility.models import CATEGORY_CHOICES, PatientBaseModel
from care.facility.models.base import covert_choice_dict
from care.facility.models.bed import AssetBed
from care.facility.models.json_schema.daily_round import (
BLOOD_PRESSURE,
Expand All @@ -31,6 +32,7 @@ class RoundsType(enum.Enum):
AUTOMATED = 300

RoundsTypeChoice = [(e.value, e.name) for e in RoundsType]
RoundsTypeDict = covert_choice_dict(RoundsTypeChoice)

class ConsciousnessType(enum.Enum):
UNKNOWN = 0
Expand Down

0 comments on commit 81823a9

Please sign in to comment.