this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Completed some todos and typo (#3378)

fixed some todos

authored by

Prafful Sharma and committed by
GitHub
4ba70ad4 4e77a024

+181 -8
-1
TODO.md
··· 1 - - Requests should have a filter to show children's requests in location/inventory/other location based API's ( Done for inventory )
-1
care/emr/api/viewsets/charge_item.py
··· 91 91 def validate_service_resource( 92 92 facility, service_resource, service_resource_id, patient, encounter=None 93 93 ): 94 - # TODO Validate with Patient and Encounter 95 94 try: 96 95 if service_resource == ChargeItemResourceOptions.service_request.value: 97 96 qs = ServiceRequest.objects.filter(
+20 -1
care/emr/api/viewsets/device.py
··· 1 1 from django.db import transaction 2 + from django.db.models import Q 2 3 from django.utils import timezone 3 4 from django_filters import rest_framework as filters 4 5 from pydantic import UUID4, BaseModel ··· 42 43 from care.emr.resources.encounter.constants import COMPLETED_CHOICES 43 44 from care.facility.models import Facility 44 45 from care.security.authorization import AuthorizationController 46 + from care.utils.filters.dummy_filter import DummyBooleanFilter 45 47 from care.utils.shortcuts import get_object_or_404 46 48 47 49 ··· 49 51 current_encounter = filters.UUIDFilter(field_name="current_encounter__external_id") 50 52 current_location = filters.UUIDFilter(field_name="current_location__external_id") 51 53 care_type = filters.CharFilter(field_name="care_type") 54 + include_children = DummyBooleanFilter() 52 55 53 56 54 57 class DeviceViewSet(EMRModelViewSet): ··· 133 136 location = get_object_or_404( 134 137 FacilityLocation, external_id=self.request.GET["location"] 135 138 ) 139 + include_children = ( 140 + self.request.GET.get("include_children", "false").lower() == "true" 141 + ) 136 142 if AuthorizationController.call( 137 143 "can_read_devices_on_location", self.request.user, location 138 144 ): 139 - queryset = queryset.filter(current_location=location) 145 + if include_children: 146 + queryset = queryset.filter( 147 + Q(current_location=location) 148 + | Q(current_location__parent_cache__overlap=[location.id]) 149 + ) 150 + else: 151 + queryset = queryset.filter(current_location=location) 152 + elif include_children: 153 + queryset = queryset.filter( 154 + facility_organization_cache__overlap=users_facility_organizations 155 + ).filter( 156 + Q(current_location=location) 157 + | Q(current_location__parent_cache__overlap=[location.id]) 158 + ) 140 159 else: 141 160 queryset = queryset.filter( 142 161 facility_organization_cache__overlap=users_facility_organizations,
+13 -2
care/emr/api/viewsets/inventory/dispense_order.py
··· 1 + from django.db.models import Q 1 2 from django.shortcuts import get_object_or_404 2 3 from django_filters import rest_framework as filters 3 4 from rest_framework.exceptions import PermissionDenied, ValidationError ··· 20 21 ) 21 22 from care.facility.models.facility import Facility 22 23 from care.security.authorization.base import AuthorizationController 23 - from care.utils.filters.dummy_filter import DummyUUIDFilter 24 + from care.utils.filters.dummy_filter import DummyBooleanFilter, DummyUUIDFilter 24 25 25 26 26 27 class DispenseOrderFilters(filters.FilterSet): ··· 28 29 created_date = filters.DateRangeFilter() 29 30 patient = filters.UUIDFilter(field_name="patient__external_id") 30 31 location = DummyUUIDFilter() 32 + include_children = DummyBooleanFilter() 31 33 32 34 33 35 class DispenseOrderViewSet( ··· 112 114 raise PermissionDenied( 113 115 "You do not have permission to read dispense order" 114 116 ) 115 - queryset = queryset.filter(location=location) 117 + include_children = ( 118 + self.request.GET.get("include_children", "false").lower() == "true" 119 + ) 120 + if include_children: 121 + queryset = queryset.filter( 122 + Q(location=location) 123 + | Q(location__parent_cache__overlap=[location.id]) 124 + ) 125 + else: 126 + queryset = queryset.filter(location=location) 116 127 else: 117 128 raise ValidationError("Location is required for non-pharmacists") 118 129 return queryset
-1
care/emr/api/viewsets/organization.py
··· 107 107 raise PermissionDenied( 108 108 "User does not have the required permissions to delete organizations" 109 109 ) 110 - # TODO delete should not be allowed if there are any children left 111 110 112 111 def authorize_update(self, request_obj, model_instance): 113 112 if self.request.user.is_superuser:
+1 -1
care/emr/resources/facility_organization/spec.py
··· 42 42 @classmethod 43 43 def validate_encounter_exists(cls, facility): 44 44 if not Facility.objects.filter(external_id=facility).exists(): 45 - err = "Faciltiy not found" 45 + err = "Facility not found" 46 46 raise ValueError(err) 47 47 return facility 48 48
+58 -1
care/emr/tests/test_device_api.py
··· 4 4 5 5 from django.urls import reverse 6 6 7 - from care.emr.models import Device 7 + from care.emr.models import Device, FacilityLocation 8 8 from care.emr.resources.device.spec import ( 9 9 DeviceAvailabilityStatusChoices, 10 10 DeviceStatusChoices, ··· 14 14 EncounterPriorityChoices, 15 15 StatusChoices, 16 16 ) 17 + from care.emr.resources.location.spec import FacilityLocationModeChoices 17 18 from care.emr.tests.test_location_api import FacilityLocationMixin 18 19 from care.security.permissions.device import DevicePermissions 19 20 from care.security.permissions.encounter import EncounterPermissions ··· 571 572 response.json()["detail"], 572 573 "You do not have permission to manage facility organization", 573 574 ) 575 + 576 + def test_list_device_with_include_children_filter(self): 577 + self.add_permissions( 578 + [ 579 + DevicePermissions.can_list_devices.name, 580 + DevicePermissions.can_manage_devices.name, 581 + FacilityLocationPermissions.can_write_facility_locations.name, 582 + ] 583 + ) 584 + 585 + parent_location = self.create_facility_location( 586 + name="Parent Location", mode=FacilityLocationModeChoices.kind.value 587 + ) 588 + 589 + child_location = self.create_facility_location( 590 + name="Child Location", parent=parent_location["id"] 591 + ) 592 + 593 + device_at_parent = self.create_device(registered_name="Device at Parent") 594 + device_at_child = self.create_device(registered_name="Device at Child") 595 + 596 + parent_obj = FacilityLocation.objects.get(external_id=parent_location["id"]) 597 + child_obj = FacilityLocation.objects.get(external_id=child_location["id"]) 598 + 599 + Device.objects.filter(external_id=device_at_parent["id"]).update( 600 + current_location=parent_obj 601 + ) 602 + Device.objects.filter(external_id=device_at_child["id"]).update( 603 + current_location=child_obj 604 + ) 605 + 606 + response = self.client.get(self.base_url + f"?location={parent_location['id']}") 607 + self.assertEqual(response.status_code, 200) 608 + self.assertEqual(response.json()["count"], 1) 609 + 610 + response = self.client.get( 611 + self.base_url + f"?location={parent_location['id']}&include_children=false" 612 + ) 613 + self.assertEqual(response.status_code, 200) 614 + self.assertEqual(response.json()["count"], 1) 615 + 616 + response = self.client.get( 617 + self.base_url + f"?location={parent_location['id']}&include_children=true" 618 + ) 619 + self.assertEqual(response.status_code, 200) 620 + self.assertEqual(response.json()["count"], 2) 621 + results = response.json()["results"] 622 + device_names = [d["registered_name"] for d in results] 623 + self.assertIn("Device at Parent", device_names) 624 + self.assertIn("Device at Child", device_names) 625 + 626 + response = self.client.get( 627 + self.base_url + f"?location={parent_location['id']}&include_children=TRUE" 628 + ) 629 + self.assertEqual(response.status_code, 200) 630 + self.assertEqual(response.json()["count"], 2) 574 631 575 632 576 633 class TestDeviceLocationHistoryViewSet(DeviceBaseTest):
+89
care/emr/tests/test_dispense_order_api.py
··· 3 3 4 4 from care.emr.models import FacilityLocation, FacilityLocationOrganization 5 5 from care.emr.models.medication_dispense import DispenseOrder 6 + from care.emr.resources.location.spec import FacilityLocationModeChoices 6 7 from care.emr.resources.medication.dispense.dispense_order import ( 7 8 MedicationDispenseOrderStatusOptions, 8 9 ) ··· 544 545 self.assertEqual( 545 546 response.data["results"][0]["id"], str(dispense_order2.external_id) 546 547 ) 548 + 549 + def test_list_dispense_orders_with_include_children_filter(self): 550 + parent_location = baker.make( 551 + FacilityLocation, 552 + facility=self.facility, 553 + name="Parent Location", 554 + mode=FacilityLocationModeChoices.kind.value, 555 + ) 556 + baker.make( 557 + FacilityLocationOrganization, 558 + location=parent_location, 559 + organization=self.facility_organization, 560 + ) 561 + 562 + child_location = baker.make( 563 + FacilityLocation, 564 + facility=self.facility, 565 + name="Child Location", 566 + parent=parent_location, 567 + ) 568 + baker.make( 569 + FacilityLocationOrganization, 570 + location=child_location, 571 + organization=self.facility_organization, 572 + ) 573 + 574 + order_at_parent = self.create_dispense_order( 575 + location=parent_location, 576 + patient=self.patient, 577 + name="Order at Parent", 578 + status=MedicationDispenseOrderStatusOptions.draft, 579 + facility=self.facility, 580 + ) 581 + order_at_child = self.create_dispense_order( 582 + location=child_location, 583 + patient=self.patient, 584 + name="Order at Child", 585 + status=MedicationDispenseOrderStatusOptions.draft, 586 + facility=self.facility, 587 + ) 588 + 589 + self.attach_role_facility_organization_user( 590 + user=self.user, 591 + role=self.role, 592 + facility_organization=self.facility_organization, 593 + ) 594 + self.client.force_authenticate(user=self.user) 595 + 596 + response = self.client.get( 597 + self.generate_base_url(self.facility.external_id), 598 + {"location": str(parent_location.external_id)}, 599 + format="json", 600 + ) 601 + self.assertEqual(response.status_code, 200) 602 + self.assertEqual(len(response.data["results"]), 1) 603 + self.assertEqual( 604 + response.data["results"][0]["id"], str(order_at_parent.external_id) 605 + ) 606 + 607 + response = self.client.get( 608 + self.generate_base_url(self.facility.external_id), 609 + { 610 + "location": str(parent_location.external_id), 611 + "include_children": "false", 612 + }, 613 + format="json", 614 + ) 615 + self.assertEqual(response.status_code, 200) 616 + self.assertEqual(len(response.data["results"]), 1) 617 + 618 + response = self.client.get( 619 + self.generate_base_url(self.facility.external_id), 620 + {"location": str(parent_location.external_id), "include_children": "true"}, 621 + format="json", 622 + ) 623 + self.assertEqual(response.status_code, 200) 624 + self.assertEqual(len(response.data["results"]), 2) 625 + order_ids = [result["id"] for result in response.data["results"]] 626 + self.assertIn(str(order_at_parent.external_id), order_ids) 627 + self.assertIn(str(order_at_child.external_id), order_ids) 628 + 629 + response = self.client.get( 630 + self.generate_base_url(self.facility.external_id), 631 + {"location": str(parent_location.external_id), "include_children": "TRUE"}, 632 + format="json", 633 + ) 634 + self.assertEqual(response.status_code, 200) 635 + self.assertEqual(len(response.data["results"]), 2)