Esempio n. 1
0
def rollback(serie):
    if os.path.exists(serie["path"]):
        shutil.rmtree(serie["path"])
    seriesDB = list(Serie.selectBy(uid=serie["uid"], description=serie["serieDescription"]))
    if seriesDB:
        serieDB = list(seriesDB)[0]
        study = serieDB.study
        patient = study.patient
        toRemove = serieDB.delete()
        serieList = list(Serie.selectBy(uid = serieDB.uid))
        if not serieList:    
            imagePath = os.path.join(patient.directory, serieDB.uid)
            if os.path.exists(imagePath):
                shutil.rmtree(imagePath)
            serieList = list(Serie.selectBy(study=study))
            if not serieList:
                toRemove = study.delete()
                for remove in toRemove:
                    if os.path.exists(remove):
                        shutil.rmtree(remove)
                
                studyList = list(Study.selectBy(patient=patient))
                if not studyList:
                    toRemove =patient.delete()
                    for remove in toRemove:
                        if os.path.exists(remove):
                            shutil.rmtree(remove)
Esempio n. 2
0
def updateDatabase(serie):
    logging.debug("In Importer::updateDatabase()")
    patient = list(Patient.selectBy(uid=serie["patientUID"]))
    if not patient:      
        patient = Patient(uid=serie["patientUID"], 
                          name=serie["patientName"],
                          birthdate=serie["patientBirthdate"],
                          sex=serie["patientSex"],
                          tmp = False,
                          directory=serie["patientPath"])
    else:
        patient = patient[0]
    
    study = list(Study.selectBy(uid=serie["studyUID"]))
    if not study:
        study = Study(uid = serie["studyUID"], 
                  modality=serie["studyModality"],
                  description=serie["studyDescription"],
                  institution=serie["studyInstitution"],
                  tmp=False,
                  patient=patient)
    else:
        study = study[0]
    serieDB = list(Serie.selectBy(uid=serie["uid"], description=serie["serieDescription"]))      
    if serieDB:
        serieDB = serieDB[0]
        serieDB.file = serie["yaml"]
        serieDB.description = serie["serieDescription"] 
        serieDB.thickness = serie["serieThickness"]
        serieDB.size = serie["serieSize"]
        serieDB.zSpacing = serie["zspacing"]
        serieDB.dicomImages = len(serie["files"])
    else:         
        Serie(uid=serie["uid"], 
              file=serie["yaml"],
              description=serie["serieDescription"],
              thickness=serie["serieThickness"], 
              size=serie["serieSize"],   
              zSpacing=serie["zspacing"],
              tmp = False,
              dicomImages = len(serie["files"]),
              study=study)
Esempio n. 3
0
def serieExists(serieID, description):
    if list(Serie.select("uid='{0}' AND description='{1}'".format(serieID, description))):
        return True
    return False