Skip to content

Commit

Permalink
Release v0.10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lucalianas committed Jun 22, 2023
2 parents 4af16c1 + ece982e commit 86c740d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion promort/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.1
0.10.2
3 changes: 2 additions & 1 deletion promort/promort/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import reviews_manager.views as rmv
from worklist_manager.views import UserWorkList, UserWorklistROIsAnnotation, \
UserWorklistClinicalAnnotation, WorkListAdmin
from rois_manager.views import SliceList, SliceDetail, CoreList, \
from rois_manager.views import SlideROIsList, SliceList, SliceDetail, CoreList, \
CoreDetail, FocusRegionList, FocusRegionDetail, ROIsTreeList
from clinical_annotations_manager.views import AnnotatedROIsTreeList, ClinicalAnnotationStepAnnotationsList, \
SliceAnnotationList, SliceAnnotationDetail, CoreAnnotationList, CoreAnnotationDetail, \
Expand Down Expand Up @@ -131,6 +131,7 @@ def to_url(self, value):
rmv.ClinicalAnnotationStepsList.as_view()),

# ROIs
path('api/slides/<slug:pk>/rois/', SlideROIsList.as_view()),
path('api/rois_annotation_steps/<rslabel:label>/rois_list/',
ROIsTreeList.as_view()),
path('api/rois_annotation_steps/<rslabel:label>/slices/',
Expand Down
58 changes: 58 additions & 0 deletions promort/rois_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from view_templates.views import GenericReadOnlyDetailView, GenericDetailView

from slides_manager.models import Slide
from reviews_manager.models import ROIsAnnotationStep
from reviews_manager.serializers import ROIsAnnotationStepFullSerializer, \
ROIsAnnotationStepROIsTreeSerializer
Expand All @@ -42,6 +43,63 @@
logger = logging.getLogger('promort')


class SlideROIsList(APIView):
permission_classes = (permissions.IsAuthenticated,)

def _serialize_rois_data(self, rois, roi_type, annotation_step):
rois_data = []
roi_parent_type = {
'slice': None,
'core': 'slice',
'focus_region': 'core'
}
for r in rois:
roi_details = {
'roi_id': r.id,
'roi_type': roi_type,
'annotation_step': annotation_step,
'parent_type': roi_parent_type[roi_type],
'parent_id': None
}
if roi_type == 'core':
roi_details['parent_id'] = r.slice.id
elif roi_type == 'focus_region':
roi_details['parent_id'] = r.core.id
rois_data.append(roi_details)
return rois_data

def get(self, request, pk, format=None):
try:
slide_obj = Slide.objects.get(id=pk)
except Slide.DoesNotExist:
raise NotFound('There is no Slide with label {0}'.format(pk))
roi_type = request.query_params.get('roi_type')
rois_annotation_steps = ROIsAnnotationStep.objects.filter(slide=slide_obj, completion_date__isnull=False)
rois = []
if roi_type is None:
for step in rois_annotation_steps:
rois.extend(self._serialize_rois_data(step.slices.all(), 'slice', step.label))
rois.extend(self._serialize_rois_data(step.cores, 'core', step.label))
rois.extend(self._serialize_rois_data(step.focus_regions, 'focus_region', step.label))
else:
if roi_type == 'slice':
for step in rois_annotation_steps:
print(step.label)
rois.extend(self._serialize_rois_data(step.slices.all(), 'slice', step.label))
elif roi_type == 'core':
for step in rois_annotation_steps:
rois.extend(self._serialize_rois_data(step.cores, 'core', step.label))
elif roi_type == 'focus_region':
for step in rois_annotation_steps:
rois.extend(self._serialize_rois_data(step.focus_regions, 'focus_region', step.label))
else:
return Response(
'{0} is not a valid ROI type'.format(roi_type),
status=status.HTTP_400_BAD_REQUEST
)
return Response(rois, status=status.HTTP_200_OK)


class ROIsTreeList(APIView):
permission_classes = (permissions.IsAuthenticated,)

Expand Down

0 comments on commit 86c740d

Please sign in to comment.