Skip to content

Commit 3e1417e

Browse files
committed
Contruct CIVData with dicom on serializers
1 parent ca49960 commit 3e1417e

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

app/grandchallenge/algorithms/serializers.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Job,
2323
annotate_input_output_counts,
2424
)
25+
from grandchallenge.cases.widgets import DICOMUploadWithName
2526
from grandchallenge.components.backends.exceptions import (
2627
CIVNotEditableException,
2728
)
@@ -310,35 +311,30 @@ def validate_inputs_and_return_matching_interface(self, *, inputs):
310311
@staticmethod
311312
def reformat_inputs(*, serialized_civs):
312313
"""Takes serialized CIV data and returns list of CIVData objects."""
313-
possible_keys = [
314-
"image",
315-
"value",
316-
"file",
317-
"user_upload",
318-
"upload_session",
319-
]
320314

321315
data = []
322316
for civ in serialized_civs:
323-
found_keys = [
324-
key for key in possible_keys if civ.get(key) is not None
325-
]
326-
327-
if not found_keys:
328-
raise serializers.ValidationError(
329-
f"You must provide at least one of {possible_keys}"
330-
)
331-
332-
if len(found_keys) > 1:
333-
raise serializers.ValidationError(
334-
f"You can only provide one of {possible_keys} for each interface."
335-
)
336-
317+
interface = civ["interface"]
318+
upload_session = civ.get("upload_session")
319+
user_upload = civ.get("user_upload")
320+
image = civ.get("image")
321+
value = civ.get("value")
322+
user_uploads = civ.get("user_uploads")
323+
image_name = civ.get("image_name")
324+
dicom_upload_with_name = (
325+
DICOMUploadWithName(name=image_name, user_uploads=user_uploads)
326+
if user_uploads and image_name
327+
else None
328+
)
337329
try:
338330
data.append(
339331
CIVData(
340-
interface_slug=civ["interface"].slug,
341-
value=civ[found_keys[0]],
332+
interface_slug=interface.slug,
333+
value=upload_session
334+
or user_upload
335+
or image
336+
or value
337+
or dicom_upload_with_name,
342338
)
343339
)
344340
except ValidationError as e:

app/grandchallenge/components/serializers.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from rest_framework.relations import SlugRelatedField
77

88
from grandchallenge.cases.models import Image, RawImageUploadSession
9+
from grandchallenge.cases.widgets import DICOMUploadWithName
910
from grandchallenge.components.backends.exceptions import (
1011
CINotAllowedException,
1112
CIVNotEditableException,
@@ -279,14 +280,25 @@ def update(self, instance, validated_data):
279280

280281
for value in values:
281282
interface = value["interface"]
282-
upload_session = value.get("upload_session", None)
283-
user_upload = value.get("user_upload", None)
284-
image = value.get("image", None)
285-
value = value.get("value", None)
283+
upload_session = value.get("upload_session")
284+
user_upload = value.get("user_upload")
285+
image = value.get("image")
286+
value = value.get("value")
287+
user_uploads = value.get("user_uploads")
288+
image_name = value.get("image_name")
289+
dicom_upload_with_name = (
290+
DICOMUploadWithName(name=image_name, user_uploads=user_uploads)
291+
if user_uploads and image_name
292+
else None
293+
)
286294
civ_data_objects.append(
287295
CIVData(
288296
interface_slug=interface.slug,
289-
value=upload_session or user_upload or image or value,
297+
value=upload_session
298+
or user_upload
299+
or image
300+
or value
301+
or dicom_upload_with_name,
290302
)
291303
)
292304
try:

0 commit comments

Comments
 (0)