Skip to content

Commit d5cb9f5

Browse files
committed
Define image view order in one place
1 parent 5a9f37b commit d5cb9f5

2 files changed

Lines changed: 31 additions & 66 deletions

File tree

manage_breast_screening/dicom/study_service.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from .models import Image, Study
66

7+
ORDERED_VIEWS = ["RCC", "RMLO", "RCCID", "RMLOID", "LCC", "LMLO", "LCCID", "LMLOID"]
8+
79

810
class StudyService:
911
def __init__(self, appointment, current_user):
@@ -59,16 +61,7 @@ def images_by_laterality_and_view(
5961
images: list["Image"],
6062
) -> dict[str, list["Image"]]:
6163
"""Group images by their laterality and view position."""
62-
grouped_images = {
63-
"LCC": [],
64-
"LMLO": [],
65-
"LCCID": [],
66-
"LMLOID": [],
67-
"RCC": [],
68-
"RMLO": [],
69-
"RCCID": [],
70-
"RMLOID": [],
71-
}
64+
grouped_images = {view: [] for view in ORDERED_VIEWS}
7265
for image in images:
7366
if image.laterality_and_view in grouped_images:
7467
grouped_images[image.laterality_and_view].append(image)

manage_breast_screening/mammograms/jinja2/mammograms/_image_grid.jinja

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,63 +24,35 @@
2424

2525
{% if image_count > 0 %}
2626
<div class="app-mammogram-cards">
27-
<div class="app-mammogram-card">
28-
{% set right_views_html %}
29-
<div class="app-mammogram-views">
30-
{% with images=images["RCC"], laterality="RCC", side="right" %}
31-
{% include "mammograms/_image_set.jinja" %}
32-
{% endwith %}
33-
{% with images=images["RMLO"], laterality="RMLO", side="right" %}
34-
{% include "mammograms/_image_set.jinja" %}
35-
{% endwith %}
36-
{% if images["RCCID"] | length > 0 %}
37-
{% with images=images["RCCID"], laterality="RCCID", side="right" %}
38-
{% include "mammograms/_image_set.jinja" %}
39-
{% endwith %}
27+
{% for side in ["Right", "Left"] %}
28+
<div class="app-mammogram-card">
29+
{% set rh_keys = [] %}
30+
{% for k in images %}
31+
{% if k[0] == side[0] %}
32+
{% set _ = rh_keys.append(k) %}
4033
{% endif %}
41-
{% if images["RMLOID"] | length > 0 %}
42-
{% with images=images["RMLOID"], laterality="RMLOID", side="right" %}
43-
{% include "mammograms/_image_set.jinja" %}
44-
{% endwith %}
45-
{% endif %}
46-
</div>
47-
{% endset %}
48-
{{ card({
49-
"heading": "Right breast",
50-
"headingLevel": "2",
51-
"feature": true,
52-
"descriptionHtml": right_views_html
53-
}) }}
54-
</div>
55-
56-
<div class="app-mammogram-card">
57-
{% set left_views_html %}
58-
<div class="app-mammogram-views">
59-
{% with images=images["LCC"], laterality="LCC", side="left" %}
60-
{% include "mammograms/_image_set.jinja" %}
61-
{% endwith %}
62-
{% with images=images["LMLO"], laterality="LMLO", side="left" %}
63-
{% include "mammograms/_image_set.jinja" %}
64-
{% endwith %}
65-
{% if images["LCCID"] | length > 0 %}
66-
{% with images=images["LCCID"], laterality="LCCID", side="left" %}
67-
{% include "mammograms/_image_set.jinja" %}
68-
{% endwith %}
69-
{% endif %}
70-
{% if images["LMLOID"] | length > 0 %}
71-
{% with images=images["LMLOID"], laterality="LMLOID", side="left" %}
72-
{% include "mammograms/_image_set.jinja" %}
73-
{% endwith %}
74-
{% endif %}
75-
</div>
76-
{% endset %}
77-
{{ card({
78-
"heading": "Left breast",
79-
"headingLevel": "2",
80-
"feature": true,
81-
"descriptionHtml": left_views_html
82-
}) }}
83-
</div>
34+
{% endfor %}
35+
{% set side_html %}
36+
<div class="app-mammogram-views">
37+
{% for laterality in rh_keys %}
38+
{% with images=images[laterality], side=side.lower() %}
39+
{% if not laterality.endswith("ID") %}
40+
{% include "mammograms/_image_set.jinja" %}
41+
{% elif images | length > 0 %}
42+
{% include "mammograms/_image_set.jinja" %}
43+
{% endif %}
44+
{% endwith %}
45+
{% endfor %}
46+
</div>
47+
{% endset %}
48+
{{ card({
49+
"heading": side ~ " breast",
50+
"headingLevel": "2",
51+
"feature": true,
52+
"descriptionHtml": side_html
53+
}) }}
54+
</div>
55+
{% endfor %}
8456
</div>
8557
{% endif %}
8658

0 commit comments

Comments
 (0)