add the ablitiy to truncate series on the site
This commit is contained in:
@@ -180,6 +180,26 @@ def series_remove_duplicate_images(request, series_id: int):
|
||||
|
||||
return len(dupes)
|
||||
|
||||
@router.get("/series_truncate/{series_id}/{start}/{end}/", auth=django_auth)
|
||||
def series_truncate(request, series_id: int, start: int, end:int):
|
||||
print(start, end)
|
||||
series = get_object_or_404(Series, pk=series_id)
|
||||
|
||||
if not series.check_user_can_edit(request.user):
|
||||
return {"status": "permission denied"}
|
||||
|
||||
images_removed = []
|
||||
for n, image in enumerate(series.get_images()):
|
||||
if n >= start and n <=end:
|
||||
continue
|
||||
else:
|
||||
print(n, image)
|
||||
image.removed=True
|
||||
image.image = None
|
||||
image.save()
|
||||
images_removed.append(image.pk)
|
||||
return {"status": "success", "images_removed": images_removed}
|
||||
|
||||
|
||||
@router.get("/get_cases_user", auth=django_auth, response=List[CaseSchema])
|
||||
def get_cases_user(request):
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 4.1.4 on 2023-12-18 10:22
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('atlas', '0031_seriesimage_replaced'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='series',
|
||||
name='modified',
|
||||
field=models.CharField(choices=[('NO', 'Not modified'), ('TR', 'Truncated'), ('RE', 'Resliced/resampled')], default='NO', max_length=2),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='seriesimage',
|
||||
name='removed',
|
||||
field=models.BooleanField(default=False, help_text='Set to true if the file this object refers to has been removed (either from series truncation or merging)'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.1.4 on 2023-12-18 11:47
|
||||
|
||||
import atlas.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('atlas', '0032_series_modified_seriesimage_removed'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='seriesimage',
|
||||
name='image',
|
||||
field=models.FileField(blank=True, null=True, upload_to=atlas.models.image_directory_path),
|
||||
),
|
||||
]
|
||||
+2
-16
@@ -466,7 +466,7 @@ def extract_image_dicom_json_from_ds(ds, url, image_index):
|
||||
|
||||
|
||||
class SeriesImage(SeriesImageBase):
|
||||
image = models.FileField(upload_to=image_directory_path)
|
||||
image = models.FileField(upload_to=image_directory_path, null=True)
|
||||
series = models.ForeignKey(
|
||||
"Series", related_name="images", on_delete=models.CASCADE, null=True
|
||||
)
|
||||
@@ -479,11 +479,6 @@ class SeriesImage(SeriesImageBase):
|
||||
help_text="Reference to the object that has replaced this one.",
|
||||
)
|
||||
|
||||
removed = models.BooleanField(
|
||||
default=False,
|
||||
help_text="Set to true if the file this object refers to has been removed (either from series truncation or merging)",
|
||||
)
|
||||
|
||||
def get_dicom_data(self):
|
||||
try:
|
||||
with pydicom.dcmread(self.image) as d:
|
||||
@@ -563,15 +558,6 @@ class Series(SeriesBase):
|
||||
related_name="series",
|
||||
)
|
||||
|
||||
|
||||
class SeriesModifiedChocies(models.TextChoices):
|
||||
NO = "NO", "Not modified",
|
||||
TR = "TR", "Truncated",
|
||||
RE = "RE", "Resliced/resampled",
|
||||
|
||||
|
||||
modified = models.CharField(max_length=2, default=SeriesModifiedChocies.NO, choices=SeriesModifiedChocies.choices)
|
||||
|
||||
series_instance_uid = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
# findings = models.TextField(null=True, blank=True, help_text="Findings on the series / stack")
|
||||
@@ -603,7 +589,7 @@ class Series(SeriesBase):
|
||||
|
||||
# TODO: clean up (this is rather convoluted....)
|
||||
image: SeriesImage
|
||||
for series_n, image in enumerate(self.images.all()):
|
||||
for series_n, image in enumerate(self.images.filter(removed=False)):
|
||||
ds = image.get_dicom_data()
|
||||
if series_n == 0:
|
||||
for tag in to_keep:
|
||||
|
||||
@@ -10,47 +10,64 @@
|
||||
This series is not associated with any cases.
|
||||
{% endif %}
|
||||
|
||||
<div id="single-dicom-viewer" class="dicom-viewer" data-images="{{ series.get_image_url_array }}" data-annotations=''>
|
||||
</div>
|
||||
|
||||
{% if editing_finding < 1 %}
|
||||
<button id="add-finding-button">Add finding</button>
|
||||
{% endif %}
|
||||
<button id="reset-viewport-button">Reset viewport</button>
|
||||
<div id="finding-form">
|
||||
<div class="hide" id="hidden-form">
|
||||
<form method="post" id="series_finding_form">
|
||||
{% csrf_token %}
|
||||
{{series_finding_form.management_form}}
|
||||
<div>
|
||||
<div>Description: {{ series_finding_form.description }}</div>
|
||||
<div>Findings: {{ series_finding_form.findings }}</div>
|
||||
<div>Structures: {{ series_finding_form.structures }}</div>
|
||||
</div>
|
||||
<input type="submit" value="Submit">
|
||||
<button id="cancel-add-finding-button">Cancel</button>
|
||||
</form>
|
||||
{% with image_url_array_and_count=series.get_image_url_array_and_count %}
|
||||
<div id="single-dicom-viewer" class="dicom-viewer" data-images="{{ image_url_array_and_count.0 }}" data-annotations=''>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details open>
|
||||
<summary>Findings</summary>
|
||||
|
||||
{% for finding in series.findings.all %}
|
||||
<div class="finding-box">
|
||||
<button class="view-finding-button" data-annotationjson={{finding.annotation_json}}
|
||||
data-viewportjson={{finding.viewport_json}} data-findingid={{finding.id}}>Click to view</button>
|
||||
<span class="view-finding-details">
|
||||
Finding(s): {% for f in finding.findings.all %}{{f.get_link}}{% endfor %}<br />
|
||||
Structure(s): {% for s in finding.structures.all %}{{s.get_link}}{% endfor %}<br />
|
||||
Description: {{finding.description}}<br />
|
||||
</span>
|
||||
<a href="{% url 'atlas:series_edit_finding' pk=series.pk finding_pk=finding.pk %}" class="edit-finding-link">Edit</a>
|
||||
<a href="{% url 'atlas:delete_finding' pk=finding.pk %}" class="delete-finding-link">Delete</a>
|
||||
{% if editing_finding < 1 %}
|
||||
<button id="add-finding-button">Add finding</button>
|
||||
{% endif %}
|
||||
<button id="reset-viewport-button">Reset viewport</button>
|
||||
<div id="finding-form">
|
||||
<div class="hide" id="hidden-form">
|
||||
<form method="post" id="series_finding_form">
|
||||
{% csrf_token %}
|
||||
{{series_finding_form.management_form}}
|
||||
<div>
|
||||
<div>Description: {{ series_finding_form.description }}</div>
|
||||
<div>Findings: {{ series_finding_form.findings }}</div>
|
||||
<div>Structures: {{ series_finding_form.structures }}</div>
|
||||
</div>
|
||||
<input type="submit" value="Submit">
|
||||
<button id="cancel-add-finding-button">Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
</details>
|
||||
<details open>
|
||||
<summary>Findings</summary>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{% for finding in series.findings.all %}
|
||||
<div class="finding-box">
|
||||
<button class="view-finding-button" data-annotationjson={{finding.annotation_json}}
|
||||
data-viewportjson={{finding.viewport_json}} data-findingid={{finding.id}}>Click to view</button>
|
||||
<span class="view-finding-details">
|
||||
Finding(s): {% for f in finding.findings.all %}{{f.get_link}}{% endfor %}<br />
|
||||
Structure(s): {% for s in finding.structures.all %}{{s.get_link}}{% endfor %}<br />
|
||||
Description: {{finding.description}}<br />
|
||||
</span>
|
||||
<a href="{% url 'atlas:series_edit_finding' pk=series.pk finding_pk=finding.pk %}" class="edit-finding-link">Edit</a>
|
||||
<a href="{% url 'atlas:delete_finding' pk=finding.pk %}" class="delete-finding-link">Delete</a>
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
</details>
|
||||
<details>
|
||||
<summary>Truncate series</summary>
|
||||
<p>
|
||||
This will limit the series to the selected bounds (the rest of the images will be deleted). This is useful when you have a large volume of which only a small area is relevant to the case. NOTE: once deleted the images cannot be recovered on the site (they would have to be reuploaded if required).
|
||||
</p>
|
||||
Start <input id="lower-truncation-bound-input" type="number" value="1"> <button id="set-lower-truncation-bound-button">Set</button><br/>
|
||||
End <input id="upper-truncation-bound-input"type="number" value="{{image_url_array_and_count.1}}"> <button id="set-upper-truncation-bound-button">Set</button><br/>
|
||||
<button id="truncate-button">Trucate series</button>
|
||||
<div id="trucate-output"></div>
|
||||
|
||||
</details>
|
||||
{% endwith %}
|
||||
|
||||
|
||||
<div>Author: {{ series.get_author_display }}</div>
|
||||
@@ -72,20 +89,20 @@
|
||||
<summary>
|
||||
Image details
|
||||
</summary>
|
||||
{% for image in series.images.all %}
|
||||
[{{ image.id }}] <a href='{% url "atlas:series_image_dicom" image.pk %}'>{{image.image.url}}</a>, pos: {{image.position}}, {{image.upload_filename}}
|
||||
{% for image in series.get_images %}
|
||||
[{{ image.id }}] <a href='{% url "atlas:series_image_dicom" image.pk %}'>{{image.image.url}}</a>, pos: {{image.position}}, {{image.upload_filename}}
|
||||
|
||||
|
||||
{% if image.image %}
|
||||
[{{image.image.size|filesizeformat}}]
|
||||
{% endif %}
|
||||
{% if image.image %}
|
||||
[{{image.image.size|filesizeformat}}]
|
||||
{% endif %}
|
||||
|
||||
{{image.image_md5_hash}} ({{image.is_dicom}})
|
||||
{{image.image_md5_hash}} ({{image.is_dicom}})
|
||||
|
||||
<br />
|
||||
<br />
|
||||
{% comment %} {{image.get_dicom_info|safe}}<br /> {% endcomment %}
|
||||
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</details>
|
||||
|
||||
<p>Total image size: {{series.get_total_image_size|filesizeformat}}</p>
|
||||
@@ -95,6 +112,35 @@
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("#set-lower-truncation-bound-button").click(() => {
|
||||
dicom_element = $(".cornerstone-element").get(0);
|
||||
index = cornerstone.getEnabledElement(dicom_element).toolStateManager.toolState.stack.data[0].currentImageIdIndex
|
||||
$("#lower-truncation-bound-input").val(index+1);
|
||||
});
|
||||
$("#set-upper-truncation-bound-button").click(() => {
|
||||
dicom_element = $(".cornerstone-element").get(0);
|
||||
index = cornerstone.getEnabledElement(dicom_element).toolStateManager.toolState.stack.data[0].currentImageIdIndex
|
||||
$("#upper-truncation-bound-input").val(index+1);
|
||||
});
|
||||
$("#truncate-button").click(() => {
|
||||
console.log("click")
|
||||
|
||||
lower_bound = parseInt($("#lower-truncation-bound-input").val()) - 1;
|
||||
upper_bound = parseInt($("#upper-truncation-bound-input").val()) - 1;
|
||||
|
||||
if (lower_bound >= upper_bound) {
|
||||
alert("The lower bound must be less than the upper bound.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(confirm(`Trucated series. This will leave ${upper_bound - lower_bound + 1} images.`) == true) {
|
||||
htmx.ajax("GET", `{% url 'api-1:series_truncate' series.id '****' '++++' %}`.replace("****", lower_bound).replace("++++", upper_bound), "#trucate-output")
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
|
||||
$("#add-finding-button").click(() => {
|
||||
dicom_element = $(".cornerstone-element").get(0);
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager.clear(dicom_element);
|
||||
|
||||
Reference in New Issue
Block a user