Esempio n. 1
0
    def test_CreateSubject(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!")

        LocalDB_query.create_entry(PathString, CNBP_blueprint.table_name,
                                   CNBP_blueprint.keyfield, 291033)
        logger.info(
            "Test SQLite database successfully inserted with mock records. Gonna check!"
        )

        # Populate the table with some fake records.
        ConnectedDatabase = sqlite3.connect(PathString)
        c = ConnectedDatabase.cursor()
        c.execute(
            'SELECT * FROM {tablename} WHERE {columnname}="{columnvalue}"'.
            format(
                tablename=CNBP_blueprint.table_name,
                columnname=CNBP_blueprint.keyfield,
                columnvalue=291033,
            ))
        ResultRows = c.fetchall()

        assert len(ResultRows) > 0

        # Closing the connection to the database file
        ConnectedDatabase.close()

        # Remove test data base created
        os.remove(PathString)

        return True
Esempio n. 2
0
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,
    )
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
    def test_CreateSubjectCheckExist(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"

        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)

        success, _ = LocalDB_query.check_value(PathString, tableName,
                                               MRNColumn, 7129112)
        assert not success

        success, _ = LocalDB_query.check_value(PathString, tableName,
                                               MRNColumn, 2918210)
        assert success

        success, _ = LocalDB_query.check_value(PathString, tableName,
                                               MRNColumn, 712921)
        assert not success

        success, _ = LocalDB_query.check_value(PathString, tableName,
                                               MRNColumn, 742)
        assert not success

        success, _ = LocalDB_query.check_value(PathString, tableName,
                                               MRNColumn, 364573)
        assert success

        logger.info("Tested SQLIte database entry. ")

        # Remove test data base created
        os.remove(PathString)

        return True
Esempio n. 6
0
def create_MRN(MRN: int):
    database_path = config_get("LocalDatabasePath")

    # Create the MRN record
    LocalDB_query.create_entry(database_path, CNBP_blueprint.table_name,
                               CNBP_blueprint.keyfield, MRN)