Completed
Pull Request — master (#3)
by Yang
04:29
created

LORIS_candidates.checkPSCIDExist()   B

Complexity

Conditions 7

Size

Total Lines 45
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 24
nop 2
dl 0
loc 45
rs 7.904
c 0
b 0
f 0
1
import sys
0 ignored issues
show
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...
2
import os
3
import re
4
import json
5
import logging
6
from dotenv import load_dotenv
7
from LORIS.query import LORIS_query
0 ignored issues
show
introduced by
Unable to import 'LORIS.query'
Loading history...
8
from LORIS.helper import LORIS_helper
0 ignored issues
show
introduced by
Unable to import 'LORIS.helper'
Loading history...
9
from LocalDB.schema import CNBP_blueprint
0 ignored issues
show
Bug introduced by
The name schema does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.schema'
Loading history...
10
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
11
logger = logging.getLogger(__name__)
0 ignored issues
show
Coding Style Naming introduced by
The name logger does not conform to the constant naming conventions ((([A-Z_][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...
12
13
class LORIS_candidates:
0 ignored issues
show
Coding Style Naming introduced by
The name LORIS_candidates does not conform to the class naming conventions ([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 class 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...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
14
15
    @staticmethod
16
    def parse_PSCID(PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name parse_PSCID does not conform to the method 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...
Coding Style Naming introduced by
The name PSCID does not conform to the argument 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...
17
        """
18
        Return three parts of the PSCID: institution, project, subject
19
        :param PSCID:
20
        :return:
21
        """
22
        success = load_dotenv()
23
        if not success:
24
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
25
26
        # Loading regular expression
27
        re_institution = CNBP_blueprint.PSCID_schema_institution
28
        re_project = CNBP_blueprint.PSCID_schema_project
29
        re_subject = CNBP_blueprint.PSCID_schema_subject
30
31
        # Use expression to extract from the inputted PSCID
32
        input_institution = re.search(re_institution, PSCID).group(0)
33
        input_project = re.search(re_project, PSCID).group(0)
34
        input_subject = re.search(re_subject, PSCID).group(0)
35
36
        if input_subject is None or input_project is None or input_institution is None:
37
            success = False
38
        else:
39
            success = True
40
41
        return success, input_institution, input_project, input_subject
42
43
    @staticmethod
44
    def check_instutitionID_compliance(input_institutionID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_instutitionID_compliance does not conform to the method 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...
Coding Style Naming introduced by
The name input_institutionID does not conform to the argument 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...
Coding Style introduced by
This method 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...
45
        # Parse from the .env standardization
46
        InsitituionID = os.getenv("institutionID")
0 ignored issues
show
Coding Style Naming introduced by
The name InsitituionID does not conform to the variable 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...
47
48
        # Check if institution ID matches
49
        if not (input_institutionID == InsitituionID):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after not.
Loading history...
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
50
            return False
51
        else:
52
            return True
53
54
    @staticmethod
55
    def check_projectID_compliance(input_projectID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_projectID_compliance does not conform to the method 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...
Coding Style Naming introduced by
The name input_projectID does not conform to the argument 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...
Coding Style introduced by
This method 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...
56
57
        # Load ProjectIDs from the environment.
58
        success = load_dotenv()
59
        if not success:
60
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
61
62
        projectID_dictionary_json: str = os.getenv("projectID_dictionary")
0 ignored issues
show
Coding Style Naming introduced by
The name projectID_dictionary_json does not conform to the variable 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...
63
        projectID_list = json.loads(projectID_dictionary_json)
0 ignored issues
show
Coding Style Naming introduced by
The name projectID_list does not conform to the variable 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...
64
65
        # check if project ID is in the projectID list.
66
        isRecognized = input_projectID in projectID_list
0 ignored issues
show
Coding Style Naming introduced by
The name isRecognized does not conform to the variable 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...
67
68
        return isRecognized
69
70
    @staticmethod
71
    def check_subjectID_compliance(input_subjectID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_subjectID_compliance does not conform to the method 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...
Coding Style Naming introduced by
The name input_subjectID does not conform to the argument 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...
Coding Style introduced by
This method 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...
72
        if not input_subjectID.isdigit():
73
            return False
74
75
        if int(input_subjectID) < 9999 or int(input_subjectID) > 0:
0 ignored issues
show
Unused Code introduced by
The if statement can be replaced with 'return bool(test)'
Loading history...
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
76
            return True
77
        else:
78
            return False
79
80
    @staticmethod
81
    def check_PSCID_compliance(PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_PSCID_compliance does not conform to the method 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...
Coding Style Naming introduced by
The name PSCID does not conform to the argument 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...
82
        """
83
        Checks PSCID inputed for 1) InstitionID format, 2) ProjectID format, 3) SubjectID format.
84
        :param PSCID:
85
        :return:
86
        """
87
        logger = logging.getLogger(__name__)
0 ignored issues
show
Comprehensibility Bug introduced by
logger is re-defining a name which is already available in the outer-scope (previously defined on line 11).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
88
89
        # Parse from input PSCID
90
        success, input_institution, input_project, input_subject = LORIS_candidates.parse_PSCID(PSCID)
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...
91
92
        # Ensure parsing success
93
        if not success:
94
            return False
95
96
        # Check institution ID to ensure that
97
        if not LORIS_candidates.check_instutitionID_compliance(input_institution):
98
            logger.info("Institution not compliant")
99
            return False
100
101
        # Check if projectID already exist
102
        if not LORIS_candidates.check_projectID_compliance(input_project):
103
            logger.info("ProjectID not recognized")
104
            return False
105
106
        # Check last four digits: make sure the last four characters are digits.
107
        if not LORIS_candidates.check_subjectID_compliance(str(input_subject)):
108
            logger.info("SubjectID not standardized")
109
            return False
110
111
        return True
112
113
    @staticmethod
114
    def check_DCCID(DCCID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_DCCID does not conform to the method 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...
Coding Style Naming introduced by
The name DCCID does not conform to the argument 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...
115
        """
116
        Check if DCCID id conform.
117
        :param DCCID:
118
        :return:
119
        """
120
        if not len(str(DCCID)) == 6:
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
Unused Code introduced by
Consider changing "not len(str(DCCID)) == 6" to "len(str(DCCID)) != 6"
Loading history...
121
            return False
122
        elif not str(DCCID).isnumeric():
123
            return False
124
        elif DCCID > 999999:
125
            return False
126
        elif DCCID < 0:
127
            return False
128
        else:
129
            return True
130
131
    @staticmethod
132
    def deleteCandidateCNBP(DCCID, PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name deleteCandidateCNBP does not conform to the method 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...
Coding Style Naming introduced by
The name DCCID does not conform to the argument 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...
Coding Style Naming introduced by
The name PSCID does not conform to the argument 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...
Coding Style introduced by
This method 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...
133
        # todo: this should really be done through API. But Currently LORIS does not offer such API.
134
        # NOTE! If you EVER get NULL coalese not recognized error, make sure that the PHP version being called from the SSH session is 7+ or else. We had a major issue where the PHP version from SSH session being LOWER than the bashrc profile.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (243/100).

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

Loading history...
135
        # Load the credential variables.
136
        success = load_dotenv()
137
        if not success:
138
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
139
        ProxyIP = os.getenv("ProxyIP")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyIP does not conform to the variable 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...
140
        ProxyUsername = os.getenv("ProxyUsername")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyUsername does not conform to the variable 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...
141
        ProxyPassword = os.getenv("ProxyPassword")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyPassword does not conform to the variable 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...
142
        LORISHostPassword = os.getenv("LORISHostPassword")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostPassword does not conform to the variable 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...
143
        LORISHostUsername = os.getenv("LORISHostUsername")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostUsername does not conform to the variable 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...
144
        LORISHostIP = os.getenv("LORISHostIP")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostIP does not conform to the variable 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...
145
        DeletionScript = os.getenv("DeletionScript")
0 ignored issues
show
Coding Style Naming introduced by
The name DeletionScript does not conform to the variable 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...
146
147
        # Export some variables for subsequent deletion clean script against production database (yes... because we could not automate LORIS development...):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (157/100).

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

Loading history...
148
        # command_string = "testout="+"'php " + DeletionScript + " delete_candidate " + str(DCCID) + " " + PSCID + " confirm';" + "echo $testout > /tmp/output.txt"
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (163/100).

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

Loading history...
149
        # NOTE! If you EVER get NULL coalese not recognized error, make sure that the PHP version being called from the SSH session is 7+ or else. We had a major issue where the PHP version from SSH session being LOWER than the bashrc profile.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (243/100).

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

Loading history...
150
        command_string = "/opt/rh//rh-php70/root/usr/bin/php " + DeletionScript + " delete_candidate " + str(DCCID) + " " + PSCID + " confirm"
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (142/100).

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

Loading history...
151
        # command_string = "/opt/php -v > /tmp/output1.txt"
152
153
154
        logger.info(command_string)
155
156
        # Establish connection to client.
157
        Client = LORIS_helper.getProxySSHClient(ProxyIP, ProxyUsername, ProxyPassword, LORISHostIP, LORISHostUsername,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

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

Loading history...
Coding Style Naming introduced by
The name Client does not conform to the variable 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...
158
                                                LORISHostPassword)
159
160
        # Execute the command
161
        LORIS_helper.triggerCommand(Client, command_string)
162
163
        # Close the client.
164
        Client.close()
165
166
167
    @staticmethod
168
    def createCandidateCNBP(token, proposed_PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name createCandidateCNBP does not conform to the method 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...
Coding Style Naming introduced by
The name proposed_PSCID does not conform to the argument 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...
169
        """
170
        Create a candidate using the given PSCID
171
        :param token
172
        :param proposed_PSCID:
173
        :return: DCCID
174
        """
175
        logger = logging.getLogger('LORIS_CreateCNBPCandidates')
0 ignored issues
show
Comprehensibility Bug introduced by
logger is re-defining a name which is already available in the outer-scope (previously defined on line 11).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
176
        logger.info("Creating CNBP Candidates: " + proposed_PSCID)
177
178
        _, PSCID_exist = LORIS_candidates.checkPSCIDExist(token, proposed_PSCID)
0 ignored issues
show
Coding Style Naming introduced by
The name PSCID_exist does not conform to the variable 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...
179
        if PSCID_exist:
180
            logger.info("PSCID already exist. Quitting.")
181
            return False ,None
0 ignored issues
show
Coding Style introduced by
No space allowed before comma
Loading history...
Coding Style introduced by
Exactly one space required after comma
Loading history...
182
183
        Candidate = {}
0 ignored issues
show
Coding Style Naming introduced by
The name Candidate does not conform to the variable 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...
184
        Candidate['Project'] = 'loris'
185
        Candidate['PSCID'] = proposed_PSCID
186
        Candidate['DoB'] = '2018-05-04'
187
        Candidate['Gender'] = 'Female'
188
189
        data = {"Candidate":Candidate}
190
191
        data_json = json.dumps(data)
192
193
        response_code, response = LORIS_query.postCNBP(token, "candidates/", data_json)
194
        if not LORIS_helper.is_response_success(response_code, 201):
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
195
            return False, None
196
        elif response is not None:  # only try to decode if response is not empty!
197
            response_json = response.json()
198
            meta = response_json.get('Meta')
199
            CandID = meta.get('CandID')
0 ignored issues
show
Coding Style Naming introduced by
The name CandID does not conform to the variable 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...
200
            return True, CandID
201
        else:
202
            return False, None
203
204
    @staticmethod
205
    def checkPSCIDExist(token, proposed_PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name checkPSCIDExist does not conform to the method 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...
Coding Style Naming introduced by
The name proposed_PSCID does not conform to the argument 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...
206
        """
207
        Check if Site/Study already contain the PSCID
208
        :param token:
209
        :param proposed_PSCID:
210
        :return: bool for connection, bool on if such PSCID (INSTITUTIONID + PROJECTID + SUBJECTID) exist already.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (114/100).

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

Loading history...
211
        """
212
        logger = logging.getLogger('LORIS_checkPSCIDExist')
0 ignored issues
show
Comprehensibility Bug introduced by
logger is re-defining a name which is already available in the outer-scope (previously defined on line 11).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
213
        logger.info("Checking if PSCID exist: "+proposed_PSCID)
214
        success = load_dotenv()
215
        if not success:
216
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
217
        institution_check = os.getenv("institutionID")
218
219
220
        #Get list of projects
221
        response_success, loris_project = LORIS_query.getCNBP(token, r"projects/loris")
222
        if not response_success:
223
            return response_success, None
224
225
        #Get list of candidates (Candidates in v0.0.1)
226
        candidates = loris_project.get("Candidates")
227
        logger.info(candidates)
228
229
        for DCCID in candidates: #these candidates should really be only from the same ID regions.
0 ignored issues
show
Coding Style Naming introduced by
The name DCCID does not conform to the variable 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...
230
            response_success, candidate_json = LORIS_query.getCNBP(token, r"candidates/"+DCCID)
231
            if not response_success:
232
                return response_success, False
233
            # Each site following the naming convention should have SITE prefix and PI prefix and PROJECT prefix to avoid collision
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (131/100).

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

Loading history...
234
235
            # A site check here.
236
            candidate_meta = candidate_json.get("Meta")
237
            candidate_pscID = candidate_meta.get("PSCID")
0 ignored issues
show
Coding Style Naming introduced by
The name candidate_pscID does not conform to the variable 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...
238
239
            # Not gonna check is institution ID doesn't even match.
240
            if candidate_pscID[0:3] != institution_check:
241
                continue
242
243
            elif candidate_pscID == proposed_PSCID:
244
                return response_success, True
245
246
                #latest_timepoint = findLatestTimePoint(DCCID)
247
248
        return True, False
249
250
    @staticmethod
251
    def checkDCCIDExist(token, proposed_DCCID):
0 ignored issues
show
Coding Style Naming introduced by
The name checkDCCIDExist does not conform to the method 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...
Coding Style Naming introduced by
The name proposed_DCCID does not conform to the argument 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...
252
        """
253
        Check if Site/Study already contain the PSCID
254
        :param token:
255
        :param proposed_DCCID:
256
        :return:
257
        """
258
        logger = logging.getLogger('LORIS_checkDCCIDExist')
0 ignored issues
show
Comprehensibility Bug introduced by
logger is re-defining a name which is already available in the outer-scope (previously defined on line 11).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
259
        logger.info("Checking if DCCID exist: "+str(proposed_DCCID))
260
        success = load_dotenv()
261
        if not success:
262
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
263
        institution_check = os.getenv("institutionID")
0 ignored issues
show
Unused Code introduced by
The variable institution_check seems to be unused.
Loading history...
264
265
        assert (LORIS_candidates.check_DCCID(proposed_DCCID))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
266
267
        #Get list of projects
268
        response, loris_project = LORIS_query.getCNBP(token, r"projects/loris")
269
        response_success = LORIS_helper.is_response_success(response, 200)
270
271
        if not response_success:
272
            logger.info("FAILED log response: " + str(response))
273
            return response_success, None
274
275
        #Get list of candidates (Candidates in v0.0.1)
276
        candidates = loris_project.get("Candidates")
277
        logger.info(candidates)
278
279
        for DCCID in candidates:
0 ignored issues
show
Coding Style Naming introduced by
The name DCCID does not conform to the variable 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...
280
            if str(proposed_DCCID) == DCCID:
281
                return response_success, True
282
            else:
283
                continue
284
        return response_success, False
285
286
if __name__ == "__main__":
287
    LORIS_candidates.deleteCandidateCNBP(958607, "CNBP8881234")
288
    #print(LORIS_candidates.check_projectID_compliance("GL01"))
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...