2022-10-26 23:22:04 +03:00
|
|
|
from drf_spectacular.utils import extend_schema
|
2022-10-29 22:46:19 +03:00
|
|
|
from rest_framework import generics, status
|
|
|
|
from rest_framework.exceptions import ValidationError
|
2022-10-30 00:12:13 +03:00
|
|
|
from rest_framework.generics import GenericAPIView, get_object_or_404
|
2022-10-26 23:22:04 +03:00
|
|
|
from rest_framework.parsers import FormParser, MultiPartParser
|
2022-10-29 22:46:19 +03:00
|
|
|
from rest_framework.response import Response
|
2022-10-26 23:22:04 +03:00
|
|
|
|
2022-10-30 00:12:13 +03:00
|
|
|
from ..models import Circle, Dicom, Roi
|
2022-10-29 22:46:19 +03:00
|
|
|
from ..services import process_files
|
2022-10-28 21:52:02 +03:00
|
|
|
from .serializers import (
|
|
|
|
CircleSerializer,
|
|
|
|
DicomSerializer,
|
|
|
|
ListDicomSerializer,
|
2022-10-30 00:12:13 +03:00
|
|
|
RoiSerializer,
|
|
|
|
SmartFileUploadSerializer,
|
2022-10-28 21:52:02 +03:00
|
|
|
)
|
2022-10-26 23:22:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
class ListCreateDicomApi(generics.ListCreateAPIView):
|
|
|
|
serializer_class = ListDicomSerializer
|
|
|
|
parser_classes = [MultiPartParser, FormParser]
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return Dicom.objects.filter(user=self.request.user)
|
|
|
|
|
|
|
|
|
|
|
|
class RetrieveUpdateDeleteDicomApi(generics.RetrieveUpdateDestroyAPIView):
|
|
|
|
def get_queryset(self):
|
|
|
|
return Dicom.objects.filter(user=self.request.user)
|
|
|
|
|
|
|
|
serializer_class = DicomSerializer
|
|
|
|
parser_classes = [MultiPartParser, FormParser]
|
|
|
|
|
|
|
|
lookup_field = "slug"
|
2022-10-28 21:52:02 +03:00
|
|
|
|
|
|
|
|
2022-10-30 00:12:13 +03:00
|
|
|
class CreateroiApi(generics.CreateAPIView):
|
|
|
|
serializer_class = RoiSerializer
|
2022-10-28 21:52:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
class CreateCircleApi(generics.CreateAPIView):
|
|
|
|
serializer_class = CircleSerializer
|
|
|
|
|
|
|
|
|
2022-10-30 00:12:13 +03:00
|
|
|
class RetrieveUpdateDeleteroiApi(generics.RetrieveUpdateDestroyAPIView):
|
|
|
|
serializer_class = RoiSerializer
|
2022-10-28 21:52:02 +03:00
|
|
|
|
|
|
|
def get_object(self):
|
2022-10-30 00:12:13 +03:00
|
|
|
return get_object_or_404(Roi, id=self.request.parser_context["kwargs"]["id"])
|
2022-10-28 21:52:02 +03:00
|
|
|
|
|
|
|
@extend_schema(description="Note: coordinated are dropped on update")
|
|
|
|
def put(self, request, *args, **kwargs):
|
|
|
|
return self.update(request, *args, **kwargs)
|
|
|
|
|
|
|
|
@extend_schema(description="Note: coordinated are dropped on update")
|
|
|
|
def patch(self, request, *args, **kwargs):
|
|
|
|
return self.partial_update(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class RetrieveUpdateDeleteCircleApi(generics.RetrieveUpdateDestroyAPIView):
|
|
|
|
serializer_class = CircleSerializer
|
|
|
|
|
|
|
|
def get_object(self):
|
|
|
|
return get_object_or_404(Circle, id=self.request.parser_context["kwargs"]["id"])
|
|
|
|
|
|
|
|
@extend_schema(description="Note: coordinated are dropped on update")
|
|
|
|
def patch(self, request, *args, **kwargs):
|
|
|
|
return self.partial_update(request, *args, **kwargs)
|
|
|
|
|
|
|
|
@extend_schema(description="Note: coordinated are dropped on update")
|
|
|
|
def put(self, request, *args, **kwargs):
|
|
|
|
return self.update(request, *args, **kwargs)
|
2022-10-29 22:46:19 +03:00
|
|
|
|
|
|
|
|
2022-10-30 00:12:13 +03:00
|
|
|
class SmartFileUploadApi(GenericAPIView):
|
2022-10-29 22:46:19 +03:00
|
|
|
parser_classes = [MultiPartParser, FormParser]
|
2022-10-30 00:12:13 +03:00
|
|
|
serializer_class = SmartFileUploadSerializer
|
2022-10-29 22:46:19 +03:00
|
|
|
|
2022-10-30 00:12:13 +03:00
|
|
|
@extend_schema(responses={201: DicomSerializer(many=True)})
|
2022-10-29 22:46:19 +03:00
|
|
|
def post(self, request):
|
|
|
|
if "file" not in request.data:
|
|
|
|
raise ValidationError("no files")
|
|
|
|
d_list = process_files(request.FILES.getlist("file"), request.user)
|
|
|
|
return Response(
|
|
|
|
DicomSerializer(d_list.files.all(), many=True).data,
|
|
|
|
status=status.HTTP_201_CREATED,
|
|
|
|
)
|
2022-10-30 00:12:13 +03:00
|
|
|
|
|
|
|
|
|
|
|
class UpdateDicomLayerApi(GenericAPIView):
|
|
|
|
serializer_class = SmartFileUploadSerializer
|