| Conditions | 7 |
| Total Lines | 54 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import logging |
||
| 7 | def findTimePointUpdateDatabase(token, DCCID, database_path, table_name): |
||
| 8 | """ |
||
| 9 | Find the timepoint of the subject, IF they exist, then update the given database by finding its relevant MRN. |
||
| 10 | :param token: |
||
| 11 | :param DCCID: |
||
| 12 | :param database_path: |
||
| 13 | :param table_name: |
||
| 14 | :param ColumnName: |
||
| 15 | :param ColumnValue: |
||
| 16 | :return: |
||
| 17 | """ |
||
| 18 | |||
| 19 | logger = logging.getLogger('Intermediate_findTimePointUpdateDatabase') |
||
| 20 | |||
| 21 | MRN = -1 |
||
| 22 | |||
| 23 | |||
| 24 | # todo: permission must be checked to ensure we are not geting 401 error! which is an access issue. |
||
| 25 | # todo: 2018-07-24 continue debug this code about entry creation. |
||
| 26 | time_point = findLatestTimePoint(token, DCCID) |
||
| 27 | |||
| 28 | # Timepoint Check |
||
| 29 | if time_point is None: |
||
| 30 | return False, "No timepoint found" |
||
| 31 | else: |
||
| 32 | logger.info("Timepoint retrieved okay:" + time_point) |
||
| 33 | |||
| 34 | # Validate table and schema congruency |
||
| 35 | success, reason = validateLocalTableAndSchema(database_path, table_name, "DCCID") |
||
| 36 | if not success: |
||
| 37 | return False, reason |
||
| 38 | |||
| 39 | # Check local database for the rows with matching DCCID. |
||
| 40 | success, subject_rows = check_value(database_path, table_name, "DCCID", DCCID) |
||
| 41 | if not success: |
||
| 42 | return False, "No entries with this DCCID!" |
||
| 43 | |||
| 44 | # Recall each row WILL conform to schema. |
||
| 45 | for row in subject_rows: |
||
| 46 | |||
| 47 | # Get MRN: |
||
| 48 | DCCID_table_index = check_header_index(database_path, table_name, "DCCID") |
||
| 49 | |||
| 50 | assert (str(DCCID) == str(row[DCCID_table_index])) |
||
| 51 | |||
| 52 | # Need to update these rows with the new value. |
||
| 53 | MRN = row[0] # the identifier of the record. |
||
| 54 | |||
| 55 | try: |
||
| 56 | update_entry(database_path, table_name, CNBP_schema_keyfield, MRN, "Timepoint", time_point) |
||
| 57 | except IOError: |
||
| 58 | return False, "Check the database is not read only. " |
||
| 59 | |||
| 60 | return True, "Timepoint successfully updated in the local SQLite database." |
||
| 61 | |||
| 68 |
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.