コード例 #1
0
ファイル: views.py プロジェクト: lucalianas/ProMort
 def put(self, request, label, format=None):
     clinical_annotation = self._find_clinical_annotation(label)
     action = request.data.get('action')
     if action is not None:
         action = action.upper()
         if action == 'START':
             if not clinical_annotation.is_started():
                 clinical_annotation.start_date = datetime.now()
             else:
                 return Response({
                     'status': 'ERROR',
                     'message': 'clinical annotation can\'t be started'
                 }, status=status.HTTP_409_CONFLICT)
         elif action == 'FINISH':
             if clinical_annotation.can_be_closed() and not clinical_annotation.is_completed():
                 clinical_annotation.completion_date = datetime.now()
             else:
                 return Response({
                     'status': 'ERROR',
                     'message': 'clinical 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)
         clinical_annotation.save()
         serializer = ClinicalAnnotationSerializer(clinical_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)
コード例 #2
0
ファイル: views.py プロジェクト: crs4/ProMort
 def post(self, request, case, reviewer, rois_review, format=None):
     clinical_annotation_data = {
         'label': self._get_rois_review_label(rois_review, reviewer),
         'reviewer': reviewer,
         'case': case,
         'rois_review': rois_review
     }
     serializer = ClinicalAnnotationSerializer(data=clinical_annotation_data)
     if serializer.is_valid():
         try:
             serializer.save()
         except IntegrityError:
             return Response({
                 'status': 'ERROR',
                 'message': 'duplicated clinical annotation for case %s assignet 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)
コード例 #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)
コード例 #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)
コード例 #5
0
ファイル: views.py プロジェクト: lucalianas/ProMort
        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)
        serializer = ClinicalAnnotationSerializer(clinical_annotations, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)


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

    def _find_prediction_reviews(self, slide_id):
        try:
            return PredictionReview.objects.filter(slide=slide_id)
        except PredictionReview.DoesNotExist:
            raise NotFound('No prediction reviews found for slide ID {0}'.format(slide_id))

    def get(self, request, slide, format=None):
        prediction_reviews = self._find_prediction_reviews(slide)
        serializer = PredictionReviewSerializer(prediction_reviews, many=True)