Beispiel #1
0
 def put(self, request, label, format=None):
     rois_annotation = self._find_rois_annotation(label)
     action = request.data.get('action')
     if action is not None:
         action = action.upper()
         if action == 'START':
             if not rois_annotation.is_started():
                 rois_annotation.start_date = datetime.now()
             else:
                 return Response({
                     'status': 'ERROR',
                     'message': 'ROIs annotation can\'t be started'
                 }, status=status.HTTP_409_CONFLICT)
         elif action == 'FINISH':
             if rois_annotation.can_be_closed() and not rois_annotation.is_completed():
                 rois_annotation.completion_date = datetime.now()
             else:
                 return Response({
                     'status': 'ERROR',
                     'message': 'ROIs annotation can\'t be closed'
                 }, status=status.HTTP_409_CONFLICT)
         else:
             return Response({
                 'status': 'ERROR',
                 'message': '\'%s\' is not a valid action' % action
             }, status=status.HTTP_400_BAD_REQUEST)
         rois_annotation.save()
         serializer = ROIsAnnotationSerializer(rois_annotation)
         return Response(serializer.data, status=status.HTTP_200_OK)
     else:
         return Response({
             'status': 'ERROR',
             'message': 'Missing \'action\' field in request data'
         }, status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
 def post(self, request, case, reviewer, format=None):
     rois_annotation_data = {
         'reviewer': reviewer,
         'case': case,
         'label': uuid4().hex
     }
     serializer = ROIsAnnotationSerializer(data=rois_annotation_data)
     if serializer.is_valid():
         try:
             serializer.save()
         except IntegrityError:
             return Response({
                 'status': 'ERROR',
                 'message': 'duplicated rois annotation for case %s assigned to reviewer %s' %
                            (case, reviewer)
             }, status=status.HTTP_409_CONFLICT)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #3
0
 def get(self, request, username, format=None):
     try:
         worklist = []
         user_obj = User.objects.get(username=username)
         rois_annotations = ROIsAnnotation.objects.filter(reviewer=user_obj)
         clinical_annotations = (ClinicalAnnotation.objects.filter(reviewer=user_obj))
         rois_annotations_serializer = ROIsAnnotationSerializer(rois_annotations, many=True)
         clinical_annotations_serializer = ClinicalAnnotationSerializer(clinical_annotations, many=True)
         worklist.extend(rois_annotations_serializer.data)
         worklist.extend(clinical_annotations_serializer.data)
         return Response(worklist, status=status.HTTP_200_OK)
     except User.DoesNotExist:
         raise NotFound('no user with username %s' % username)
Beispiel #4
0
 def get(self, request, format=None):
     rois_reviews, clinical_reviews, prediction_reviews = self._get_pending_reviews(request.user.username)
     rois_serializer = ROIsAnnotationSerializer(rois_reviews, many=True)
     clinical_serializer = ClinicalAnnotationSerializer(clinical_reviews, many=True)
     prediction_serializer = PredictionReviewSerializer(prediction_reviews, many=True)
     questionnaire_requests = self._get_pending_questionnaire_requests(request.user.username)
     questionnaire_serializer = QuestionnaireRequestSerializer(questionnaire_requests, many=True)
     data = OrderedDict()
     # compose the worklist, keep clinical annotations only if ROIs annotation for the same case
     # was fully completed (and it was assigned to the current user)
     for c_ann in clinical_serializer.data:
         data[c_ann['label']] = c_ann
     for r_ann in rois_serializer.data:
         data[r_ann['label']] = r_ann
     worklist = list(data.values()) + prediction_serializer.data + questionnaire_serializer.data
     return Response(worklist, status=status.HTTP_200_OK)
Beispiel #5
0
    def post(self, request, format=None):
        raise MethodNotAllowed


class ROIsAnnotationsDetail(APIView):
    permission_classes = (IsReviewManager,)

    def _find_rois_annotation(self, case_id):
        try:
            return ROIsAnnotation.objects.filter(case=case_id)
        except ROIsAnnotation.DoesNotExist:
            raise NotFound('No ROIs annotations found for case ID \'%s\'' % case_id)

    def get(self, request, case, format=None):
        rois_annotations = self._find_rois_annotation(case)
        serializer = ROIsAnnotationSerializer(rois_annotations, many=True)
        return Response(serializer.data,
                        status=status.HTTP_200_OK)


class ClinicalAnnotationsDetail(APIView):
    permission_classes = (IsReviewManager,)

    def _find_clinical_annotation(self, case_id):
        try:
            return ClinicalAnnotation.objects.filter(case=case_id)
        except ClinicalAnnotation.DoesNotExist:
            raise NotFound('No clinical annotations found for case ID \'%s\'' % case_id)

    def get(self, request, case, format=None):
        clinical_annotations = self._find_clinical_annotation(case)