Skip to content

Commit

Permalink
Merge branch 'ohcnetwork:develop' into fix-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
shauryag2002 authored Dec 20, 2024
2 parents bdd555e + fbf76d7 commit 7bc037f
Show file tree
Hide file tree
Showing 46 changed files with 342 additions and 1,089 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* text=auto
scripts/* text eol=lf
*.sh text eol=lf
4 changes: 4 additions & 0 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-
- name: Create new cache
run: |
mkdir -p /tmp/.buildx-cache-new
- name: Bake docker images
uses: docker/bake-action@v5
with:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ up:
down:
docker compose -f docker-compose.yaml -f $(docker_config_file) down

teardown:
docker compose -f docker-compose.yaml -f $(docker_config_file) down -v

load-dummy-data:
docker compose exec backend bash -c "python manage.py load_dummy_data"

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ to load dummy data for testing run:
```bash
make load-dummy-data
```
Stops and removes the containers without affecting the volumes:

```bash
make down
```
Stops and removes the containers and their volumes:

```bash
make teardown
```

#### Docker

Expand Down
28 changes: 0 additions & 28 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
GENDER_CHOICES,
Disease,
Facility,
FacilityPatientStatsHistory,
PatientContactDetails,
PatientMetaInfo,
PatientNotes,
Expand Down Expand Up @@ -358,33 +357,6 @@ def update(self, instance, validated_data):
return patient


class FacilityPatientStatsHistorySerializer(serializers.ModelSerializer):
id = serializers.CharField(source="external_id", read_only=True)
entry_date = serializers.DateField(default=lambda: now().date())
facility = ExternalIdSerializerField(
queryset=Facility.objects.all(), read_only=True
)

class Meta:
model = FacilityPatientStatsHistory
exclude = (
"deleted",
"external_id",
)
read_only_fields = (
"id",
"facility",
)

def create(self, validated_data):
instance, _ = FacilityPatientStatsHistory.objects.update_or_create(
facility=validated_data["facility"],
entry_date=validated_data["entry_date"],
defaults={**validated_data, "deleted": False},
)
return instance


class PatientSearchSerializer(serializers.ModelSerializer):
gender = ChoiceField(choices=GENDER_CHOICES)
patient_id = serializers.UUIDField(source="external_id", read_only=True)
Expand Down
24 changes: 0 additions & 24 deletions care/facility/api/serializers/summary.py

This file was deleted.

2 changes: 1 addition & 1 deletion care/facility/api/viewsets/camera_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_serializer_context(self):

class CameraPresetViewSet(GenericViewSet, ListModelMixin):
serializer_class = CameraPresetSerializer
queryset = CameraPreset.objects.all().select_related(
queryset = CameraPreset.objects.filter(asset_bed__deleted=False).select_related(
"asset_bed", "created_by", "updated_by"
)
lookup_field = "external_id"
Expand Down
6 changes: 0 additions & 6 deletions care/facility/api/viewsets/facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from care.facility.models import (
Facility,
FacilityCapacity,
FacilityPatientStatsHistory,
HospitalDoctors,
)
from care.facility.models.facility import FacilityHubSpoke, FacilityUser
Expand Down Expand Up @@ -134,11 +133,6 @@ def list(self, request, *args, **kwargs):
elif self.FACILITY_DOCTORS_CSV_KEY in request.GET:
mapping.update(HospitalDoctors.CSV_RELATED_MAPPING.copy())
pretty_mapping.update(HospitalDoctors.CSV_MAKE_PRETTY.copy())
elif self.FACILITY_TRIAGE_CSV_KEY in request.GET:
mapping.update(FacilityPatientStatsHistory.CSV_RELATED_MAPPING.copy())
pretty_mapping.update(
FacilityPatientStatsHistory.CSV_MAKE_PRETTY.copy()
)
queryset = self.filter_queryset(self.get_queryset()).values(*mapping.keys())
return render_to_csv_response(
queryset, field_header_map=mapping, field_serializer_map=pretty_mapping
Expand Down
2 changes: 2 additions & 0 deletions care/facility/api/viewsets/facility_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class UserFilter(filters.FilterSet):
choices=[(key, key) for key in User.TYPE_VALUE_MAP],
coerce=lambda role: User.TYPE_VALUE_MAP[role],
)
username = filters.CharFilter(field_name="username", lookup_expr="icontains")

class Meta:
model = User
Expand All @@ -39,6 +40,7 @@ def get_queryset(self):
external_id=self.kwargs.get("facility_external_id"),
)
queryset = facility.users.filter(
is_active=True,
deleted=False,
).order_by("-last_login")
return queryset.prefetch_related(
Expand Down
60 changes: 1 addition & 59 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from drf_spectacular.utils import extend_schema, extend_schema_view
from dry_rest_permissions.generics import DRYPermissionFiltersBase, DRYPermissions
from rest_framework import filters as rest_framework_filters
from rest_framework import mixins, serializers, status, viewsets
from rest_framework import mixins, serializers, status
from rest_framework.decorators import action
from rest_framework.exceptions import ValidationError
from rest_framework.filters import BaseFilterBackend
Expand All @@ -40,7 +40,6 @@
from rest_framework.viewsets import GenericViewSet

from care.facility.api.serializers.patient import (
FacilityPatientStatsHistorySerializer,
PatientDetailSerializer,
PatientListSerializer,
PatientNotesEditSerializer,
Expand All @@ -58,7 +57,6 @@
BedTypeChoices,
DailyRound,
Facility,
FacilityPatientStatsHistory,
PatientNotes,
PatientNoteThreadChoices,
PatientRegistration,
Expand Down Expand Up @@ -730,62 +728,6 @@ def get_queryset(self) -> QuerySet:
)


class FacilityPatientStatsHistoryFilterSet(filters.FilterSet):
entry_date = filters.DateFromToRangeFilter(field_name="entry_date")


class FacilityPatientStatsHistoryViewSet(viewsets.ModelViewSet):
lookup_field = "external_id"
permission_classes = (IsAuthenticated, DRYPermissions)
queryset = FacilityPatientStatsHistory.objects.filter(
facility__deleted=False
).order_by("-entry_date")
serializer_class = FacilityPatientStatsHistorySerializer
filter_backends = (filters.DjangoFilterBackend,)
filterset_class = FacilityPatientStatsHistoryFilterSet
http_method_names = ["get", "post", "delete"]

def get_queryset(self):
user = self.request.user
queryset = self.queryset.filter(
facility__external_id=self.kwargs.get("facility_external_id")
)
if user.is_superuser:
return queryset
if self.request.user.user_type >= User.TYPE_VALUE_MAP["StateLabAdmin"]:
return queryset.filter(facility__state=user.state)
if self.request.user.user_type >= User.TYPE_VALUE_MAP["DistrictLabAdmin"]:
return queryset.filter(facility__district=user.district)
return queryset.filter(facility__users__id__exact=user.id)

def get_object(self):
return get_object_or_404(
self.get_queryset(), external_id=self.kwargs.get("external_id")
)

def get_facility(self):
facility_qs = Facility.objects.filter(
external_id=self.kwargs.get("facility_external_id")
)
if not self.request.user.is_superuser:
facility_qs.filter(users__id__exact=self.request.user.id)
return get_object_or_404(facility_qs)

def perform_create(self, serializer):
return serializer.save(facility=self.get_facility())

def list(self, request, *args, **kwargs):
"""
Patient Stats - List
Available Filters
- entry_date_before: date in YYYY-MM-DD format, inclusive of this date
- entry_date_before: date in YYYY-MM-DD format, inclusive of this date
"""
return super().list(request, *args, **kwargs)


class PatientSearchSetPagination(PageNumberPagination):
page_size = 200

Expand Down
126 changes: 0 additions & 126 deletions care/facility/api/viewsets/summary.py

This file was deleted.

25 changes: 0 additions & 25 deletions care/facility/management/commands/summarize.py

This file was deleted.

Loading

0 comments on commit 7bc037f

Please sign in to comment.