def append_SeriesUID(MRN: int, SeriesUID: List[str]): """ Append record with SeriesUID list. which has particular MRN :param MRN: :return: """ database_path = config_get("LocalDatabasePath") existing_series_UID = get_SeriesUIDs(MRN) if existing_series_UID is None: total_series_UID = SeriesUID else: total_series_UID = existing_series_UID + SeriesUID # JSON dumps. json_seriesUID = json.dumps(total_series_UID) # Update the MRN record with SeriesUID LocalDB_query.update_entry( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN, "SeriesUID", json_seriesUID, )
def findTimePointUpdateDatabase(token, DCCID, database_path, table_name): """ Find the timepoint of the subject, IF they exist, then update the given database by finding its relevant MRN. :param token: :param DCCID: :param database_path: :param table_name: :return: """ MRN = -1 # @todo: permission must be checked to ensure we are not geting 401 error! which is an access issue. # @todo: 2018-07-24 continue debug this code about entry creation. time_point = LORIS_timepoint.findLatestTimePoint(token, DCCID) # Timepoint Check if time_point is None: return False, "No timepoint found" else: logger.info(f"Timepoint retrieved okay: {time_point}") # Validate table and schema congruency success, reason = LocalDB_query.validateLocalTableAndSchema( database_path, table_name, "DCCID") if not success: return False, reason # Check local database for the rows with matching DCCID. success, subject_rows = LocalDB_query.check_value(database_path, table_name, "DCCID", DCCID) if not success: return False, "No entries with this DCCID!" # Recall each row WILL conform to schema. for row in subject_rows: # Get MRN: DCCID_table_index = LocalDB_query.check_header_index( database_path, table_name, "DCCID") assert str(DCCID) == str(row[DCCID_table_index]) # Need to update these rows with the new value. MRN = row[0] # the identifier of the record. try: LocalDB_query.update_entry( database_path, table_name, CNBP_blueprint.keyfield, MRN, "Timepoint", time_point, ) except IOError: return False, "Check the database is not read only. " return True, "Timepoint successfully updated in the local SQLite database."
def append_StudyUID(MRN: int, StudyUID: str): """ Update record with proper completion status which STUDY has particular MRN :param MRN: :return: """ # convert new study UID to list. list_StudyUID_single_new = [StudyUID] database_path = config_get("LocalDatabasePath") # obtain list_StudyUID_existing_ones = get_StudyUIDs(MRN) if list_StudyUID_existing_ones is None: list_StudyUID_total = list_StudyUID_single_new else: list_StudyUID_total = list_StudyUID_existing_ones + list_StudyUID_single_new # JSON dumps. json_seriesUID = json.dumps(list_StudyUID_total) # Update the MRN record with StudyUID LocalDB_query.update_entry( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN, "StudyUID", json_seriesUID, )
def set_timepoint(MRN: int, Timepoint: str): """ Update record with proper Timepoint which has particular MRN :param MRN: :return: """ database_path = config_get("LocalDatabasePath") # Update the MRN record with Timepoint LocalDB_query.update_entry( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN, "Timepoint", Timepoint, )
def set_DCCID(MRN: int, DCCID: int): """ Update record with proper DCCID which has particular MRN :param MRN: :return: """ database_path = config_get("LocalDatabasePath") # Update the MRN record with DCCID LocalDB_query.update_entry( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN, "DCCID", DCCID, )
def set_CNNIDs(MRN: int, CaseIDs: List[int]): """ Update record with proper CNN which has particular MRN :param MRN: :return: """ database_path = config_get("LocalDatabasePath") # JSON dumps. json_CaseIDs = json.dumps(CaseIDs) # Update the MRN record with DCCID LocalDB_query.update_entry( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN, "CNNID", json_CaseIDs, )
def set_StudyUID(MRN: int, StudyUID: List[str]): """ Update record with SeriesUID list. which has particular MRN :param MRN: :return: """ database_path = config_get("LocalDatabasePath") # JSON dumps. json_seriesUID = json.dumps(StudyUID) # Update the MRN record with SeriesUID LocalDB_query.update_entry( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN, "StudyUID", json_seriesUID, )
def set_CNBP( MRN: int, CNBPID: str ): # fixme: all the SET RECORDS NEED TO CONSIDER THE MULTIROW possiblities. """ Update record with proper CNBPID which has particular MRN :param MRN: :return: """ database_path = config_get("LocalDatabasePath") # Update the MRN record with CNBPID LocalDB_query.create_entry(database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN) LocalDB_query.update_entry( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN, "CNBPID", CNBPID, )
def test_updateLocalTimepoint(): import os database_path = "Test.sqlite" DCCID = 768766 table_name = CNBP_blueprint.table_name # Remove database if previously existed. if os.path.exists(database_path): os.remove(database_path) # Create Database LocalDB_createCNBP.database(database_path) # Get login token: success, token = LORIS_query.login() # Create the entry with the right PSCID with proper DCCID on dev.cnbp.ca LocalDB_query.create_entry(database_path, table_name, CNBP_blueprint.keyfield, "8987888") # Update above entry with the right mock PSCID. LocalDB_query.update_entry( database_path, table_name, CNBP_blueprint.keyfield, "8987888", "DCCID", DCCID, ) # Now, the big guy. success, reason = findTimePointUpdateDatabase(token, DCCID, database_path, table_name) # Clean up database. os.remove(database_path) assert success
def test_SubjectUpdate(self): PathString = "TestCNBPQuery.sqlite" # if SQL already exist, quit script. SQLPath = Path(PathString) # check if path is a file and exist. if SQLPath.is_file(): logger.info( "Test SQLite database file already exist. Gonna mess with it!") """'Delete current database! During testing only""" os.remove(PathString) # Create the database assert LocalDB_createCNBP.database(PathString) logger.info( "Test SQLite database successfully created. Gonna mess with it!") tableName = "id_table" # All CNBP database should have this table name. MRNColumn = "MRN" CNBPIDColumn = "CNBPID" LocalDB_query.create_entry(PathString, tableName, MRNColumn, 2918210) LocalDB_query.create_entry(PathString, tableName, MRNColumn, 23452346) LocalDB_query.create_entry(PathString, tableName, MRNColumn, 2345234) LocalDB_query.create_entry(PathString, tableName, MRNColumn, 273411) LocalDB_query.create_entry(PathString, tableName, MRNColumn, 364573) LocalDB_query.create_entry(PathString, tableName, MRNColumn, 7424141) Prefix = config_get("institutionID") LocalDB_query.update_entry(PathString, tableName, MRNColumn, 7424141, CNBPIDColumn, f"{Prefix}0010001") LocalDB_query.update_entry(PathString, tableName, MRNColumn, 2345234, CNBPIDColumn, f"{Prefix}0010002") LocalDB_query.update_entry(PathString, tableName, MRNColumn, 2918210, CNBPIDColumn, f"{Prefix}0010003") LocalDB_query.update_entry(PathString, tableName, MRNColumn, 273411, CNBPIDColumn, f"{Prefix}0010004") success, _ = LocalDB_query.check_value(PathString, tableName, CNBPIDColumn, "CNBPID0010006") assert not success success, _ = LocalDB_query.check_value(PathString, tableName, CNBPIDColumn, f"{Prefix}0010001") assert success success, _ = LocalDB_query.check_value(PathString, tableName, CNBPIDColumn, 55555) assert not success success, _ = LocalDB_query.check_value(PathString, tableName, CNBPIDColumn, 742) assert not success success, _ = LocalDB_query.check_value(PathString, tableName, CNBPIDColumn, f"{Prefix}0010003") assert success logger.info("Tested SQLIte database entry. ") # Remove test data base created os.remove(PathString) return True