-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
444 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.9.0 | ||
0.9.1 |
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
95 changes: 95 additions & 0 deletions
95
promort/clinical_annotations_manager/management/commands/get_gleason_data.py
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,95 @@ | ||
# Copyright (c) 2021, CRS4 | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
# this software and associated documentation files (the "Software"), to deal in | ||
# the Software without restriction, including without limitation the rights to | ||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
# the Software, and to permit persons to whom the Software is furnished to do so, | ||
# subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.core.paginator import Paginator | ||
from clinical_annotations_manager.models import GleasonElement | ||
|
||
from csv import DictWriter | ||
|
||
import logging | ||
|
||
logger = logging.getLogger('promort_commands') | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """ | ||
Export existing Gleason items data to CSV. | ||
No ROIs are exported, only metadata; to export ROIs use the extract_gleason_elements command. | ||
""" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('--output_file', dest='output', type=str, required=True, | ||
help='path of the output CSV file') | ||
parser.add_argument('--page_size', dest='page_size', type=int, default=0, | ||
help='the number of records retrieved for each page (this will enable pagination)') | ||
|
||
def _dump_row(self, gleason_element, csv_writer): | ||
try: | ||
creation_start_date = gleason_element.creation_start_date.strftime('%Y-%m-%d %H:%M:%S') | ||
except AttributeError: | ||
creation_start_date = None | ||
fr_ann = gleason_element.focus_region_annotation | ||
csv_writer.writerow( | ||
{ | ||
'case_id': fr_ann.focus_region.core.slice.slide.case.id, | ||
'slide_id': fr_ann.focus_region.core.slice.slide.id, | ||
'rois_review_step_id': fr_ann.annotation_step.rois_review_step.label, | ||
'clinical_review_step_id': fr_ann.annotation_step.label, | ||
'reviewer': fr_ann.author.username, | ||
'focus_region_id': fr_ann.focus_region.id, | ||
'focus_region_label': fr_ann.focus_region.label, | ||
'core_id': fr_ann.focus_region.core.id, | ||
'core_label': fr_ann.focus_region.core.label, | ||
'gleason_element_id': gleason_element.id, | ||
'gleason_type': gleason_element.gleason_type, | ||
'creation_start_date': creation_start_date, | ||
'creation_date': gleason_element.creation_date.strftime('%Y-%m-%d %H:%M:%S') | ||
} | ||
) | ||
|
||
def _dump_data(self, page_size, csv_writer): | ||
if page_size > 0: | ||
logger.info('Pagination enabled (%d records for page)', page_size) | ||
ge_qs = GleasonElement.objects.get_queryset().order_by('creation_date') | ||
paginator = Paginator(ge_qs, page_size) | ||
for x in paginator.page_range: | ||
logger.info(f'-- page {x} --') | ||
page = paginator.page(x) | ||
for ge in page.object_list: | ||
self._dump_row(ge, csv_writer) | ||
else: | ||
logger.info('Loading full batch') | ||
gleason_elements = GleasonElement.objects.all() | ||
for ge in gleason_elements: | ||
self._dump_row(ge, csv_writer) | ||
|
||
def _export_data(self, out_file, page_size): | ||
header = ['case_id', 'slide_id', 'rois_review_step_id', 'clinical_review_step_id', 'reviewer', 'focus_region_id', | ||
'focus_region_label', 'core_id', 'core_label', 'gleason_element_id', 'gleason_type', | ||
'creation_start_date', 'creation_date'] | ||
with open(out_file, 'w') as ofile: | ||
writer = DictWriter(ofile, delimiter=',', fieldnames=header) | ||
writer.writeheader() | ||
self._dump_data(page_size, writer) | ||
|
||
def handle(self, *args, **opts): | ||
logger.info('=== Starting export job ===') | ||
self._export_data(opts['output'], opts['page_size']) | ||
logger.info('=== Data saved to {0} ==='.format(opts['output'])) |
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
33 changes: 33 additions & 0 deletions
33
promort/clinical_annotations_manager/migrations/0018_auto_20211128_1525.py
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,33 @@ | ||
# Generated by Django 3.1.13 on 2021-11-28 15:25 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('clinical_annotations_manager', '0017_auto_20210424_1321'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='coreannotation', | ||
old_name='creation_start_date', | ||
new_name='action_start_time', | ||
), | ||
migrations.RenameField( | ||
model_name='focusregionannotation', | ||
old_name='creation_start_date', | ||
new_name='action_start_time', | ||
), | ||
migrations.RenameField( | ||
model_name='gleasonelement', | ||
old_name='creation_start_date', | ||
new_name='action_start_time', | ||
), | ||
migrations.RenameField( | ||
model_name='sliceannotation', | ||
old_name='creation_start_date', | ||
new_name='action_start_time', | ||
), | ||
] |
33 changes: 33 additions & 0 deletions
33
promort/clinical_annotations_manager/migrations/0019_auto_20211201_0933.py
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,33 @@ | ||
# Generated by Django 3.1.13 on 2021-12-01 09:33 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('clinical_annotations_manager', '0018_auto_20211128_1525'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='coreannotation', | ||
name='action_complete_time', | ||
field=models.DateTimeField(default=None, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='focusregionannotation', | ||
name='action_complete_time', | ||
field=models.DateTimeField(default=None, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='gleasonelement', | ||
name='action_complete_time', | ||
field=models.DateTimeField(default=None, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='sliceannotation', | ||
name='action_complete_time', | ||
field=models.DateTimeField(default=None, null=True), | ||
), | ||
] |
30 changes: 30 additions & 0 deletions
30
promort/clinical_annotations_manager/migrations/0020_auto_20211206_1018.py
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,30 @@ | ||
# Generated by Django 3.1.13 on 2021-12-06 10:18 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def update_action_complete_time(apps, schema_editor): | ||
GleasonElements = apps.get_model('clinical_annotations_manager', 'GleasonElement') | ||
for g_element in GleasonElements.objects.all(): | ||
g_element.action_complete_time = g_element.creation_date | ||
g_element.creation_date = g_element.focus_region_annotation.creation_date | ||
g_element.save() | ||
|
||
|
||
def reverse_action_complete_time(apps, schema_editor): | ||
GleasonElements = apps.get_model('clinical_annotations_manager', 'GleasonElement') | ||
for g_element in GleasonElements.objects.all(): | ||
g_element.creation_date = g_element.action_complete_time | ||
g_element.action_complete_time = None | ||
g_element.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('clinical_annotations_manager', '0019_auto_20211201_0933'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(update_action_complete_time, reverse_action_complete_time), | ||
] |
Oops, something went wrong.