Repository: medtagger/MedTagger

Issue:
Disable (temporarily) conversion in X & Y axes
## Expected Behavior

Frontend won't be enabled soon, so backend should disable such conversion (for now).

## Actual Behavior

Backend always create views from X & Y axes but are not used anywhere.

## Additional comment

Let's make it optional and controllable somehow by users (ideally from the UI & API side?).



Discussion:

Resolving patch:
diff --git a/backend/medtagger/workers/conversion.py b/backend/medtagger/workers/conversion.py
--- a/backend/medtagger/workers/conversion.py
+++ b/backend/medtagger/workers/conversion.py
@@ -20,6 +20,7 @@
 
 logger = get_task_logger(__name__)
 
+CONVERT_IN_OTHER_AXES = False  # Disabled until Frontend will enable support for such Slices
 MAX_PREVIEW_X_SIZE = 256
 
 
@@ -47,20 +48,8 @@ def convert_scan_to_png(scan_id: ScanID) -> None:
         dicom_images.append(dicom_image)
         temp_files_to_remove.extend(files_to_remove)
 
-    # Correlate Dicom files with Slices and convert all Slices in the Z axis orientation
-    logger.info('Converting each Slice in Z axis.')
-    for dicom_image, _slice in zip(dicom_images, slices):
-        slice_pixels = convert_slice_to_normalized_8bit_array(dicom_image)
-        _convert_to_png_and_store(_slice, slice_pixels)
-
-    # Prepare a preview size and convert 3D scan to fit its max X's axis shape
-    logger.info('Normalizing Scan in 3D. This may take a while...')
-    normalized_scan = convert_scan_to_normalized_8bit_array(dicom_images, output_x_size=MAX_PREVIEW_X_SIZE)
-
-    # Prepare Slices in other orientations
-    logger.info('Preparing Slices in other axis.')
-    _prepare_slices_in_y_orientation(normalized_scan, scan)
-    _prepare_slices_in_x_orientation(normalized_scan, scan)
+    # Correlate Dicom files with Slices and convert all Slices
+    _convert_scan_in_all_axes(dicom_images, slices, scan)
 
     logger.info('Marking whole Scan as converted.')
     scan.mark_as_converted()
@@ -113,6 +102,32 @@ def _create_temporary_file(image: Optional[bytes] = None) -> str:
     return temp_file_name
 
 
+def _convert_scan_in_all_axes(dicom_images: List[FileDataset], slices: List[Slice], scan: Scan) -> None:
+    """Convert Scan in X, Y and Z axes.
+
+    NOTE: X & Y axes are now disabled (until Frontend will support it).
+
+    :param dicom_images: list of all Dicom images
+    :param slices: list of all Slices in given Scan
+    :param scan: Scan object to which new Slices should be added
+    """
+    logger.info('Converting each Slice in Z axis.')
+    for dicom_image, _slice in zip(dicom_images, slices):
+        slice_pixels = convert_slice_to_normalized_8bit_array(dicom_image)
+        _convert_to_png_and_store(_slice, slice_pixels)
+
+    # Convert only if it's enabled
+    if CONVERT_IN_OTHER_AXES:
+        # Prepare a preview size and convert 3D scan to fit its max X's axis shape
+        logger.info('Normalizing Scan in 3D. This may take a while...')
+        normalized_scan = convert_scan_to_normalized_8bit_array(dicom_images, output_x_size=MAX_PREVIEW_X_SIZE)
+
+        # Prepare Slices in other orientations
+        logger.info('Preparing Slices in other axis.')
+        _prepare_slices_in_y_orientation(normalized_scan, scan)
+        _prepare_slices_in_x_orientation(normalized_scan, scan)
+
+
 def _prepare_slices_in_y_orientation(normalized_scan: np.ndarray, scan: Scan) -> None:
     """Prepare and save Slices in Y orientation.
 


Test patch:
diff --git a/backend/tests/functional_tests/test_scan_upload.py b/backend/tests/functional_tests/test_scan_upload.py
--- a/backend/tests/functional_tests/test_scan_upload.py
+++ b/backend/tests/functional_tests/test_scan_upload.py
@@ -38,21 +38,21 @@ def test_scan_upload_and_conversion(prepare_environment: Any, synchronous_celery
     z_slices = SlicesRepository.get_slices_by_scan_id(scan_id)
     assert len(z_slices) == 3
     y_slices = SlicesRepository.get_slices_by_scan_id(scan_id, SliceOrientation.Y)
-    assert len(y_slices) == 256
+    assert not y_slices
     x_slices = SlicesRepository.get_slices_by_scan_id(scan_id, SliceOrientation.X)
-    assert len(x_slices) == 256
+    assert not x_slices
 
     # Step 3.1. Slices in Z axis
     z_slice = SlicesRepository.get_slice_converted_image(z_slices[2].id)
     z_slice_image = Image.open(io.BytesIO(z_slice))
     assert z_slice_image.size == (512, 512)
 
-    # Step 3.2. Slices in Y axis
-    y_slice = SlicesRepository.get_slice_converted_image(y_slices[128].id)
-    y_slice_image = Image.open(io.BytesIO(y_slice))
-    assert y_slice_image.size == (256, 186)
+    # Step 3.2. Slices in Y axis are disabled for now
+    # y_slice = SlicesRepository.get_slice_converted_image(y_slices[128].id)
+    # y_slice_image = Image.open(io.BytesIO(y_slice))
+    # assert y_slice_image.size == (256, 186)
 
-    # Step 3.3. Slices in Z axis
-    x_slice = SlicesRepository.get_slice_converted_image(x_slices[128].id)
-    x_slice_image = Image.open(io.BytesIO(x_slice))
-    assert x_slice_image.size == (256, 186)
+    # Step 3.3. Slices in Z axis are disabled for now
+    # x_slice = SlicesRepository.get_slice_converted_image(x_slices[128].id)
+    # x_slice_image = Image.open(io.BytesIO(x_slice))
+    # assert x_slice_image.size == (256, 186)