Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def processSeries(self, dcm_info, log_file, study_directory):
# get information of interest
series_description = self.processDicomField(dcm_info, "SeriesDescription")
series_date = self.processDicomField(dcm_info, "SeriesDate")
series_uid = self.processDicomField(dcm_info, "SeriesInstanceUID")
self.dp.qprint('Processing %s' % series_uid)
# log it
log_file.write(' SeriesDescription: ' + series_description + '\n')
log_file.write(' SeriesDate: ' + series_date + '\n')
log_file.write(' SeriesInstanceUID: ' + series_uid + '\n')
# create series directory
series_directory = pypx.utils.seriesPath(
study_directory, series_description, series_date, series_uid)
self.mkdir(series_directory, self.log_error)
# Save a mapping from this series_uid to the acutal FS location
# where the file will be written
str_mapFile = os.path.join(self.series_mapDir, '%s.json' % series_uid)
if not os.path.exists(str_mapFile):
self.mapFile_save( {series_uid : series_directory}, str_mapFile )
# store information as a configuration
series_info = configparser.ConfigParser()
series_info['SERIES'] = {
'SeriesDescription': series_description,
'SeriesDate': series_date,
'SeriesInstanceUID': series_uid,
'Location': series_directory
def processPatient(self, dcm_info, log_file, data_directory):
# get information of interest
patient_id = self.processDicomField(dcm_info, "PatientID")
patient_name = self.processDicomField(dcm_info, "PatientName")
self.dp.qprint('Processing %s...' % patient_id)
# log it
log_file.write(' PatientID: ' + patient_id + '\n')
log_file.write(' PatientName: ' + patient_name + '\n')
# create patient directory
patient_directory = pypx.utils.patientPath(data_directory, patient_id, patient_name)
self.mkdir(patient_directory, self.log_error)
# Save a mapping from this series_uid to the acutal FS location
# where the file will be written
str_mapFile = os.path.join(self.patient_mapDir, '%s.json' % patient_id)
if not os.path.exists(str_mapFile):
self.mapFile_save( {patient_id : patient_directory}, str_mapFile )
# create patient.info file
patient_info = configparser.ConfigParser()
patient_info['PATIENT'] = {
'PatientID': patient_id,
'PatientName': patient_name,
'Location': patient_directory
}
def processStudy(self, dcm_info, log_file, patient_directory):
# get information of interest
study_description = self.processDicomField(dcm_info, "StudyDescription")
study_date = self.processDicomField(dcm_info, "StudyDate")
study_uid = self.processDicomField(dcm_info, "StudyInstanceUID")
self.dp.qprint('Processing %s...' % study_uid)
# log it
log_file.write(' StudyDescription: ' + study_description + '\n')
log_file.write(' StudyDate: ' + study_date + '\n')
log_file.write(' StudyInstanceUID: ' + study_uid + '\n')
# create study directory
study_directory = pypx.utils.studyPath(
patient_directory, study_description, study_date, study_uid)
self.mkdir(study_directory, self.log_error)
# Save a mapping from this series_uid to the acutal FS location
# where the file will be written
str_mapFile = os.path.join(self.study_mapDir, '%s.json' % study_uid)
if not os.path.exists(str_mapFile):
self.mapFile_save( {study_uid : study_directory}, str_mapFile )
# create study.info file
study_info = configparser.ConfigParser()
study_info['STUDY'] = {
'StudyDescription': study_description,
'StudyDate': study_date,
'StudyInstanceUID': study_uid,
'Location': study_directory
def processImage(self, dcm_info, log_file, error_file, series_directory, tmp_file):
# get information of interest
image_uid = self.processDicomField(dcm_info, "SOPInstanceUID")
image_instance_number = self.processDicomField(dcm_info, "InstanceNumber")
# log it
log_file.write(' SOPInstanceUID: ' + image_uid + '\n')
log_file.write(' InstanceNumber: ' + image_instance_number + '\n')
image_path = pypx.utils.dataPath(series_directory, image_instance_number, image_uid)
if not os.path.exists(image_path):
try:
shutil.copy2(tmp_file, image_path)
except OSError as e:
errorfile = open(error_file, 'w')
errorfile.write('Copy ' + tmp_file + ' to ' + image_path + '\n')
errorfile.write('Error number: ' + str(e.errno) + '\n')
errorfile.write('File name: ' + e.filename + '\n')
errorfile.write('Error message: ' + e.strerror + '\n')
errorfile.close()
if not os.path.exists(image_path):
errorfile = open(error_file, 'w')
errorfile.write('File doesn\'t exist:' + image_path + '\n')
errorfile.close()
def processDicomField(self, dcm_info, field):
value = "no value provided"
if field in dcm_info:
value = pypx.utils.sanitize(dcm_info.data_element(field).value)
return value
# Global modules
import subprocess
# PYPX modules
from .base import Base
class Move(Base):
"""docstring for Move."""
def __init__(self, arg):
super(Move, self).__init__(arg)
def command(self, opt={}):
command = '--move ' + opt['aet_listener']
command += ' --timeout 5'
command += ' -k QueryRetrieveLevel=SERIES'
command += ' -k SeriesInstanceUID=' + opt['series_uid']
return self.executable + ' ' + command + ' ' + self.commandSuffix()
def run(self, opt={}):
response = subprocess.run(
self.command(opt), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
return self.handle(response)
# Global modules
import subprocess, re, collections
# PYPX modules
from .base import Base
class Find(Base):
"""docstring for Find."""
def __init__(self, arg):
super(Find, self).__init__(arg)
# to be moved out
self.postfilter_parameters = {
'PatientSex': '',
'PerformedStationAETitle': '',
'StudyDescription': '',
'SeriesDescription': ''
}
def command(self, opt={}):
command = '-xi -S'
return self.executable + ' ' + command + ' ' + self.query(opt) + ' ' + self.commandSuffix()
# Global modules
import subprocess
import pudb
import json
import pfmisc
from pfmisc._colors import Colors
# PYPX modules
from .base import Base
class Echo(Base):
"""
The 'Echo' class is essentially a stripped down module that
simply runs an 'echoscp' on the system shell.
"""
def __init__(self, arg):
"""
Constructor.
Largely simple/barebones constructor that calls the Base()
and sets up the executable name.
"""
super(Echo, self).__init__(arg)
self.dp = pfmisc.debug(
verbosity = self.verbosity,
def __init__(self, arg):
"""
Constructor.
Largely simple/barebones constructor that calls the Base()
and sets up the executable name.
"""
super(Echo, self).__init__(arg)
self.dp = pfmisc.debug(
verbosity = self.verbosity,
within = 'Echo',
syslog = False
)
def echo(opt={}):
return Echo(opt).run()