Passed
Pull Request — master (#3)
by Yang
04:58
created

step1_orthanc2DICOM()   B

Complexity

Conditions 7

Size

Total Lines 42
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 24
nop 1
dl 0
loc 42
rs 7.904
c 0
b 0
f 0
1
from orthanc.query import orthanc_query
0 ignored issues
show
Coding Style Naming introduced by
The name orthanc_to_DICOMs does not conform to the module naming conventions ((([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
introduced by
Unable to import 'orthanc.query'
Loading history...
2
from LORIS.helper import LORIS_helper
0 ignored issues
show
introduced by
Unable to import 'LORIS.helper'
Loading history...
3
import os
0 ignored issues
show
introduced by
standard import "import os" should be placed before "from orthanc.query import orthanc_query"
Loading history...
4
import logging
0 ignored issues
show
introduced by
standard import "import logging" should be placed before "from orthanc.query import orthanc_query"
Loading history...
5
6
7
def step1_orthanc2DICOM(data_folder_path):
0 ignored issues
show
Coding Style Naming introduced by
The name step1_orthanc2DICOM does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
8
    """
9
    The purpose of this function is to connect to orthanc, retrieve a list of subjects, download each one in turn and unzip them somewhere.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (139/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
10
    :return: whether it succeeded, and if succeeded, a list of all folders.
11
    """
12
    logger = logging.getLogger("Step1: Orthanc to DICOM files")
13
14
    # Input check
15
    if not os.path.exists(data_folder_path) or not os.path.isdir(data_folder_path):
16
        logger.info("Bad data folder path")
17
        return False, None
18
19
    # Query Orthanc for all subjects
20
    reseponse_code, list_subjects = orthanc_query.getOrthanc("patients/")
21
    if not LORIS_helper.is_response_success(reseponse_code, 200):
22
        logger.info("Could not connect to Orthanc.")
23
        return False, None
24
25
    all_subject_folder_paths = []
26
27
    # For all subjects, unzip them somewhere.
28
    for subject in list_subjects:
29
30
        status, zip_file = orthanc_query.getPatientZipOrthanc(subject)
31
32
        # Checks for output from getPatientZipOrthanc
33
        if not LORIS_helper.is_response_success(status, 200):
34
            logger.info("Could not get patient zip files from Orthanc")
35
            return False, None
36
        if not os.path.exists(zip_file):
37
            logger.info("Could not locate saved zip files after dowwnloading from Orthanc")
38
            return False, None
39
40
        # Create a directory based on the zip file, which has UUID as name and guarnteed to be unique.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
41
        file, ext = os.path.splitext(zip_file)
0 ignored issues
show
Unused Code introduced by
The variable ext seems to be unused.
Loading history...
42
        final_folder_name = data_folder_path + file
43
        os.mkdir(final_folder_name)
44
        orthanc_query.flatUnZip(zip_file, final_folder_name) #files are guarnteed to be unique and no overwrite of each other. .
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (128/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
45
46
        # Keep track of path extracted to for subsequent processing.
47
        all_subject_folder_paths.append(final_folder_name)
48
    return True, all_subject_folder_paths
49
50
def step2_dicom2LORIS(folder_paths):
0 ignored issues
show
Coding Style Naming introduced by
The name step2_dicom2LORIS does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Unused Code introduced by
The argument folder_paths seems to be unused.
Loading history...
51
    """
52
    Within each folder, verify they all have the same PatientID.
53
    :param folder_paths:
54
    :return:
55
    """
56
0 ignored issues
show
coding-style introduced by
Trailing newlines
Loading history...
57