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 get_CNNID(MRN: int) -> Optional[List[str]]: """ Assuming the MRN exist, get the CNNIDs of all scans that ever past through here. :param MRN: the MRN to look for :return: the CNBPID associated with that particular MRN number. """ # Load local database from .env file database_path = config_get("LocalDatabasePath") MRN_exist_in_database, KeyRecords = LocalDB_query.check_value( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN) if MRN_exist_in_database is False: return None # Only ONE record per MRN. assert len(KeyRecords) == 1 CNNID_index = LocalDB_query.check_header_index(database_path, CNBP_blueprint.table_name, "CNNID") # Load the json and return the variable structure json_CNNIDs = KeyRecords[0][CNNID_index] if json_CNNIDs is None: logger.warning("No existing CNNID Data information found.") return None list_CNNIDs = json.loads(json_CNNIDs) return list_CNNIDs
def get_scan_date(MRN: int) -> Optional[str]: """ Assuming the MRN exist, get the MRNID. :param MRN: the MRN to look for :return: the CNBPID associated with that particular MRN number. """ # Load local database from .env file database_path = config_get("LocalDatabasePath") MRN_exist_in_database, KeyRecords = LocalDB_query.check_value( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN) if MRN_exist_in_database is False: return None # Only ONE record per MRN, even if there are multiple timepoint. We keep the latest one. assert len(KeyRecords) == 1 date_header_index = LocalDB_query.check_header_index( database_path, CNBP_blueprint.table_name, "Date") scan_date = KeyRecords[0][date_header_index] return scan_date
def get_DCCID(MRN: int) -> Optional[str]: """ Assuming the MRN exist, get the MRNID. :param MRN: the MRN to look for :return: the CNBPID associated with that particular MRN number. """ # Load local database from .env file database_path = config_get("LocalDatabasePath") MRN_exist_in_database, KeyRecords = LocalDB_query.check_value( database_path, CNBP_blueprint.table_name, CNBP_blueprint.keyfield, MRN) if MRN_exist_in_database is False: return None # Only ONE record per MRN. assert len(KeyRecords) == 1 dcc_header_index = LocalDB_query.check_header_index( database_path, CNBP_blueprint.table_name, "DCCID") return KeyRecords[0][dcc_header_index]