Exemplo n.º 1
0
    def setUpClass(cls):
        # Set up a database connection
        cls.db = Database.from_key('tests/credentials',
                                   'config/credentials.key')

        # Select a patient
        query = 'SELECT TOP(1) ID, patientID FROM patientRepresentations'
        res0 = cls.db.run(query)
        cls.patientRepID = res0.rows[0].ID

        def roi_query_helper(prepID):
            '''
            Get all ROI's for a patient ID
            '''
            query = '''
                SELECT TOP(2) patientRepID, ID, name
                FROM RegionsOfInterest
                WHERE patientRepID = {}
                ORDER BY name asc
            '''.format(prepID)
            return cls.db.run(query).rows

        # Store patientRepID and a few ROI names and IDs
        res1 = roi_query_helper(cls.patientRepID)
        # Get a few masks
        res2, _ = cls.db.regions_of_interest.get_masks(
            cls.patientRepID, [str(r.name) for r in res1])
        cls.masks = list(res2.values())
Exemplo n.º 2
0
    def setUpClass(cls):
        # Set up a database connection
        cls.db = Database.from_key('tests/credentials',
                                   'config/credentials.key')

        # Select a patient
        query = 'SELECT TOP(1) ID, patientID FROM patientRepresentations'
        res = cls.db.run(query)
        cls.patientRepID = res.rows[0].ID

        # Get a dose grid for a patient
        res0 = cls.db.radiotherapy_sessions.get_session_ids(cls.patientRepID)
        cls.dg = cls.db.radiotherapy_sessions.get_dose_grid(res0.rows[0][0])

        def roi_query_helper(prepID):
            '''
            Get all ROI's for a patient ID
            '''
            query = '''
                SELECT TOP(1) patientRepID, ID, name
                FROM RegionsOfInterest
                WHERE patientRepID = {}
                ORDER BY name asc
            '''.format(prepID)
            return cls.db.run(query).rows[0]

        # Store patientRepID and name of ROIs with a certain number of occurrences
        res1 = roi_query_helper(cls.patientRepID)

        res2 = cls.db.regions_of_interest.get_id_by_patient_rep_id_name(
            res1.patientRepID, str(res1.name))

        cls.mask = cls.db.regions_of_interest.get_mask(res2)
        # Create a dose mask
        cls.dm = DoseMask(cls.mask, cls.dg)
    def setUpClass(cls):
        # Set up a database connection
        cls.db = Database.from_key('tests/credentials',
                                   'config/credentials.key')

        # Select a patient
        query = 'SELECT TOP(1) ID, patientID FROM patientRepresentations'
        res = cls.db.run(query)
        cls.patientRepID = res.rows[0].ID
        cls.patientID = res.rows[0].patientID

        def roi_query_helper(count):
            '''
            Get a patientRepID and ROI name that appears a certain number of times
            '''
            query = '''
                WITH query1 as (
                    SELECT patientRepID, name, count(*) as count
                    FROM RegionsOfInterest
                    GROUP BY name, patientRepID
                )
                SELECT TOP(1) * FROM query1 WHERE count = {}
            '''.format(count)
            res = cls.db.run(query)
            return res.rows[0]

        # Store patientRepID and name of ROIs with a certain number of occurrences
        res0 = roi_query_helper(1)
        cls.one_roi = [res0.patientRepID, str(res0.name)]
        res1 = roi_query_helper(2)
        cls.many_rois = [res1.patientRepID, str(res1.name)]
    def setUpClass(cls):
        # Set up a database connection
        cls.db = Database.from_key('tests/credentials',
                                   'config/credentials.key')

        query = 'SELECT TOP(1) patientID FROM Patients'
        res = cls.db.run(query)
        cls.patientID = res.rows[0].patientID
    def setUpClass(cls):
        # Set up a database connection
        cls.db = Database.from_key('tests/credentials',
                                   'config/credentials.key')

        cls.rois = ['l_parotid', 'r_parotid']
        prepIDs = cls.db.regions_of_interest.get_patient_rep_ids_with_rois(
            cls.rois)
        if len(prepIDs) >= 2:
            cls.patientRep_1 = prepIDs[0]
            cls.patientRep_2 = prepIDs[1]
Exemplo n.º 6
0
    def setUpClass(cls):
        # Set up a database connection
        cls.db = Database.from_key('tests/credentials',
                                   'config/credentials.key')

        # Select a patient
        query = 'SELECT TOP(1) ID, patientID FROM patientRepresentations'
        res = cls.db.run(query)
        cls.patientRepID = res.rows[0].ID
        cls.patientID = res.rows[0].patientID

        # Files to delete
        cls.file_path = 'tests/files/'
        cls.to_remove = []
Exemplo n.º 7
0
    def setUpClass(cls):
        # Set up a database connection
        cls.db = Database.from_key('tests/credentials',
                                   'config/credentials.key')

        # Select a patient
        query = 'SELECT TOP(1) ID, patientID FROM patientRepresentations'
        res = cls.db.run(query)
        cls.patientRepID = res.rows[0].ID
        cls.patientID = res.rows[0].patientID

        res = cls.db.radiotherapy_sessions.get_session_ids(cls.patientRepID)
        # Normal dose grid
        cls.dg = cls.db.radiotherapy_sessions.get_dose_grid(res.rows[0][0])
        # Scaled dose grid
        cls.dg_scaled = cls.db.radiotherapy_sessions.get_dose_grid(
            res.rows[0][0])
        cls.dg_scaled.dose_scaling_factor = 0.5
    def setUpClass(cls):
        # Set up a database connection
        cls.db = Database.from_key('tests/credentials',
                                   'config/credentials.key')

        # Select a patient
        query = 'SELECT TOP(1) ID, patientID FROM patientRepresentations'
        res = cls.db.run(query)
        cls.patientRepID = res.rows[0].ID

        def roi_query_helper(prepID):
            '''
            Get all ROI's for a patient ID
            '''
            query = '''
                SELECT TOP(1) patientRepID, ID, name
                FROM RegionsOfInterest
                WHERE patientRepID = {}
                ORDER BY name asc
            '''.format(prepID)
            return cls.db.run(query).rows[0]

        # Store patientRepID and name of ROIs with a certain number of occurrences
        res1 = roi_query_helper(cls.patientRepID)

        res2 = cls.db.regions_of_interest.get_id_by_patient_rep_id_name(
            res1.patientRepID, str(res1.name))

        base_mask = cls.db.regions_of_interest.get_mask(res2)
        # Make one mask that is contiguous
        cont_pts = [[i, j, k] for i in range(10) for j in range(10)
                    for k in range(10)]
        cls.good_mask = tf.general.fill_mask(base_mask, cont_pts)
        # And create one that is discontiguous
        discont_pts = [[i, j, k] for i in range(10) for j in range(10)
                       for k in range(10) if k < 4 or k > 5]
        cls.bad_mask = tf.general.fill_mask(base_mask, discont_pts)
Exemplo n.º 9
0
            '-q': 0,
            '-d': 1,
            '-v': 2
        }
        return verb_dict[verbosity_flags[0]]


# RUN ALL UNIT TESTS ==============================================================================

if __name__ == '__main__':

    db = 'OncospaceHeadNeck'
    us = 'oncoguest'
    pw = '0ncosp@ceGuest'
    #connect to database
    dbase = Database(None, None, db, us, pw) #how to close?

    #initialize query classes
    PRQ = PatientRepresentationsQueries(dbase)
    ROIQ = RegionsOfInterestQueries(dbase)
    AQ = AssessmentsQueries(dbase)
    RSQ = RadiotherapySessionsQueries(dbase)
    manager = Manager()

    #create patient  list
    patients = PRQ.get_patient_id_LUT()
    masks = ROIQ.get_roi_names()
    module = 'dose'
    output = []
    #output = np.tile(-1, (10, len(masks)))#(len(patients), len(masks)))
    i = 0
Exemplo n.º 10
0
 def __init__(self, dr=None, ho=None, db='OncospaceHeadNeck', us='oncoguest', pw='0ncosp@ceGuest'):
     #connect to database
     self.dbase = Database(dr, ho, db, us, pw)
     self.manager = Manager()
Exemplo n.º 11
0
# ### Import modules

# In[1]:

from __future__ import print_function

from oncotools.connect import Database
from oncotools.data_elements.dose_map import DoseMask

import numpy as np

# ### Connect to the database

# In[2]:

db = Database(db='OncospaceHeadNeck', us='oncoguest', pw='0ncosp@ceGuest')

# ### Patient ID and Patient representation ID
#
# Individual patients are identified by a patientID.
#
# Each patient has at least one patient representations. A patient representation corresponds to one scan (a certain geometry) and a set of structures from that one scan.

# In[3]:

# Map patient representation ID to patient ID
patLUT = db.patient_representations.get_patient_id_LUT()

# Map patient ID to patient representation ID(s)
prepLUT = db.patient_representations.get_patient_rep_id_LUT()