-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'vigneshhari/health-details' into medication_administration
- Loading branch information
Showing
56 changed files
with
1,788 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from rest_framework.exceptions import PermissionDenied | ||
from rest_framework.generics import get_object_or_404 | ||
|
||
from care.emr.models import Encounter, Patient | ||
from care.security.authorization import AuthorizationController | ||
|
||
|
||
class EncounterBasedAuthorizationBase: | ||
def get_patient_obj(self): | ||
return get_object_or_404( | ||
Patient, external_id=self.kwargs["patient_external_id"] | ||
) | ||
|
||
def authorize_update(self, request_obj, model_instance): | ||
if not AuthorizationController.call( | ||
"can_update_encounter_obj", self.request.user, model_instance.encounter | ||
): | ||
raise PermissionDenied("You do not have permission to update encounter") | ||
|
||
def authorize_create(self, instance): | ||
encounter = get_object_or_404(Encounter, external_id=instance.encounter) | ||
if not AuthorizationController.call( | ||
"can_update_encounter_obj", self.request.user, encounter | ||
): | ||
raise PermissionDenied("You do not have permission to update encounter") | ||
|
||
def authorize_delete(self, instance): | ||
if not AuthorizationController.call( | ||
"can_update_encounter_obj", self.request.user, instance.encounter | ||
): | ||
raise PermissionDenied("You do not have permission to update encounter") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.db.models import Q | ||
from django.utils.decorators import method_decorator | ||
from rest_framework.decorators import action, parser_classes | ||
from rest_framework.parsers import MultiPartParser | ||
from rest_framework.response import Response | ||
|
||
from care.emr.api.viewsets.base import EMRModelViewSet | ||
from care.emr.models.organziation import FacilityOrganizationUser, OrganizationUser | ||
from care.emr.resources.facility.spec import FacilityCreateSpec, FacilityReadSpec | ||
from care.facility.api.serializers.facility import FacilityImageUploadSerializer | ||
from care.facility.models import Facility | ||
from care.utils.file_uploads.cover_image import delete_cover_image | ||
|
||
|
||
class FacilityViewSet(EMRModelViewSet): | ||
database_model = Facility | ||
pydantic_model = FacilityCreateSpec | ||
pydantic_read_model = FacilityReadSpec | ||
|
||
def get_queryset(self): | ||
# TODO Add Permission checks | ||
organization_ids = list( | ||
OrganizationUser.objects.filter(user=self.request.user).values_list( | ||
"organization_id", flat=True | ||
) | ||
) | ||
return ( | ||
super() | ||
.get_queryset() | ||
.filter( | ||
Q( | ||
id__in=FacilityOrganizationUser.objects.filter( | ||
user=self.request.user | ||
).values_list("organization__facility_id") | ||
) | ||
| Q(geo_organization_cache__overlap=organization_ids) | ||
) | ||
) | ||
|
||
@method_decorator(parser_classes([MultiPartParser])) | ||
@action(methods=["POST"], detail=True) | ||
def cover_image(self, request, external_id): | ||
facility = self.get_object() | ||
serializer = FacilityImageUploadSerializer(facility, data=request.data) | ||
serializer.is_valid(raise_exception=True) | ||
serializer.save() | ||
return Response(serializer.data) | ||
|
||
@cover_image.mapping.delete | ||
def cover_image_delete(self, *args, **kwargs): | ||
facility = self.get_object() | ||
delete_cover_image(facility.cover_image_url, "cover_images") | ||
facility.cover_image_url = None | ||
facility.save() | ||
return Response(status=204) |
Oops, something went wrong.