|
1
|
|
|
import logging |
|
|
|
|
|
|
2
|
|
|
from LocalDB.query import validateLocalTableAndSchema, check_value, update_entry, check_header_index |
|
|
|
|
|
|
3
|
|
|
from LORIS.timepoint import findLatestTimePoint |
|
|
|
|
|
|
4
|
|
|
from LocalDB.schema import CNBP_schema_keyfield |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
|
|
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
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
if __name__ == '__main__': |
|
64
|
|
|
|
|
65
|
|
|
# Unit test |
|
66
|
|
|
from Integration.test_Integration import test_updateLocalTimepoint |
|
|
|
|
|
|
67
|
|
|
test_updateLocalTimepoint() |
|
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.