diff --git a/atlas/forms.py b/atlas/forms.py index 27ca6338..ba9fd81c 100755 --- a/atlas/forms.py +++ b/atlas/forms.py @@ -31,7 +31,7 @@ class ExaminationForm(ModelForm): class SeriesFindingForm(ModelForm): class Meta: model = SeriesFinding - exclude = ["series", "annotation_json"] + exclude = ["series", "annotation_json", "viewport_json"] def __init__(self, *args, **kwargs): if kwargs.get("series_id"): diff --git a/atlas/models.py b/atlas/models.py index 35ef6412..90c6a913 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -220,6 +220,7 @@ class SeriesFinding(models.Model): ) findings = models.ManyToManyField(Finding, blank=True) annotation_json = models.TextField(null=True, blank=True) + viewport_json = models.TextField(null=True, blank=True) def __str__(self) -> str: findings = self.findings.all().values_list("name") diff --git a/atlas/templates/atlas/series_viewer.html b/atlas/templates/atlas/series_viewer.html index ac41140b..1ae51fcc 100755 --- a/atlas/templates/atlas/series_viewer.html +++ b/atlas/templates/atlas/series_viewer.html @@ -44,7 +44,7 @@ This series is not associated with any cases. {% for finding in series.findings.all %}
- + Findings: {{finding.findings.all|join:", "}}
Description: {{finding.description}}
Delete finding @@ -74,9 +74,12 @@ This series is not associated with any cases. $(".view-finding-button").each((n, el) => { $(el).click((e) => { dicom_element = $(".single-dicom-viewer").get(0); - json = JSON.parse(e.currentTarget.dataset.json); - cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(json); - cornerstone.reset(dicom_element); + annotationjson = JSON.parse(e.currentTarget.dataset.annotationjson); + viewport = JSON.parse(e.currentTarget.dataset.viewportjson) + //cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(json); + cornerstone.getEnabledElement(dicom_element).restoreToolState(annotationjson) + cornerstone.getEnabledElement(dicom_element).viewport = viewport + cornerstone.resize(dicom_element); }); @@ -85,13 +88,17 @@ This series is not associated with any cases. }); $(document).on('submit', '#series_finding_form', function (e) { + dicom_element = $(".single-dicom-viewer").get(0); +c = cornerstone.getEnabledElement(dicom_element); + $.ajax({ type: 'POST', url: '{% url "atlas:add_finding" %}', data: { description: $('#id_description').val(), series: {{series.pk}}, - annotation_json: JSON.stringify(cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState()), + annotation_json: JSON.stringify(c.saveToolState()), + viewport_json: JSON.stringify(c.viewport), findings: JSON.stringify($('#finding-form select[name="findings"]').find(":selected").map((i, el) => { return $(el).val() }).toArray()), csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(), action: 'post' diff --git a/atlas/views.py b/atlas/views.py index d1953cc9..314f047d 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -541,6 +541,7 @@ def create_series_findings(request): findings_ids = json.loads(request.POST.get("findings")) description = request.POST.get("description") annotation_json = request.POST.get("annotation_json") + viewport_json = request.POST.get("viewport_json") series = Series.objects.get(pk=series_id) findings = Finding.objects.filter(pk__in=findings_ids) @@ -549,6 +550,7 @@ def create_series_findings(request): series=series, description=description, annotation_json=annotation_json, + viewport_json=viewport_json, ) sf.findings.set(findings) sf.save()