Exemple #1
0
def start_dcmqrscp(server_port=2000,
                   server_AET='OFFIS_AE',
                   install_dir_base='/tmp/dcmqrscp',
                   dcmtk_base='/usr',
                   populate=False):
    """
    Starts an instance of dcmqrscp with server_port and server_AET in
    an xterm window.  The database and config file will be created in
    the directory install_dir_base/server_AET.  The dcmtk_bas
    parameter is the directory where the offis toolkit executables reside.
    It is possible to start several instances by using different ports
    and AE titles.
    """

    # clean up
    install_dir = install_dir_base + '/' + server_AET
    os.system('rm -rf %s' % install_dir)
    try:
        os.mkdir(install_dir_base)
    except:
        pass
    os.mkdir(install_dir)
    os.mkdir(install_dir + '/db')

    # create dcmqrscp configuration file base on config_template
    f = open(install_dir + '/dcmqrscp.cfg', 'w')
    f.write(config_template % (server_port, server_AET, install_dir))
    f.close()

    # start dcmqrscp in a separate window
    cmd = 'cd %s;xterm -T %s -e "%s/bin/dcmqrscp -d -c dcmqrscp.cfg;read"&' % \
        (install_dir, server_AET, dcmtk_base)
    os.system(cmd)
    time.sleep(1)

    if populate:
        # populate db with a some data
        storescu_cmd = dcmtk_base + \
            '/bin/storescu localhost %d -aec %s ' % (server_port, server_AET)
        for ii in os.listdir(testfiles_dir()):
            if ii.endswith('.dcm'):
                os.system(storescu_cmd + os.path.join(testfiles_dir(), ii))
def start_dcmqrscp(server_port=2000, server_AET='OFFIS_AE',
                   install_dir_base='/tmp/dcmqrscp', dcmtk_base='/usr',
                   populate=False):
    """
    Starts an instance of dcmqrscp with server_port and server_AET in
    an xterm window.  The database and config file will be created in
    the directory install_dir_base/server_AET.  The dcmtk_bas
    parameter is the directory where the offis toolkit executables reside.
    It is possible to start several instances by using different ports
    and AE titles.
    """

    # clean up
    install_dir = install_dir_base + '/' + server_AET
    os.system('rm -rf %s' % install_dir)
    try:
        os.mkdir(install_dir_base)
    except:
        pass
    os.mkdir(install_dir)
    os.mkdir(install_dir + '/db')

    # create dcmqrscp configuration file base on config_template
    f = open(install_dir + '/dcmqrscp.cfg', 'w')
    f.write(config_template % (server_port, server_AET, install_dir))
    f.close()

    # start dcmqrscp in a separate window
    cmd = 'cd %s;xterm -e "%s/bin/dcmqrscp -d -c dcmqrscp.cfg;read"&' % \
        (install_dir, dcmtk_base)
    os.system(cmd)
    time.sleep(1)

    if populate:
        # populate db with a some data
        storescu_cmd = dcmtk_base + \
            '/bin/storescu localhost %d -aec %s ' % (server_port, server_AET)
        for ii in os.listdir(testfiles_dir()):
            if ii.endswith('.dcm'):
                os.system(storescu_cmd + os.path.join(testfiles_dir(), ii))
Exemple #3
0
def OnReceiveMove(self, ident, remoteAE):
    # ds is the identifyer dataset
    # pretend that we lookup the database to find a list of datasets to be moved
    yield dict(AET=remoteAE, Port=2001, Address='localhost')
    
    nop = 10
    yield nop
    
    for ii in range(nop):
        # create fake dataset
        ds = dicom.read_file(os.path.join(testfiles_dir(),"rtplan.dcm"))
        print "sending fake dataset"
        yield ds
Exemple #4
0
def OnReceiveMove(self, ident, remoteAE):
    # ds is the identifyer dataset
    # pretend that we lookup the database to find a list of datasets to be moved
    yield dict(AET=remoteAE, Port=2001, Address='localhost')

    nop = 10
    yield nop

    for ii in range(nop):
        # create fake dataset
        ds = dicom.read_file(os.path.join(testfiles_dir(), "rtplan.dcm"))
        print "sending fake dataset"
        yield ds
Exemple #5
0
    # must return appropriate status
    return 0


# setup AE
MyAE = AE(
    "SPIN",
    9999,
    [],
    [
        MRImageStorageSOPClass,
        CTImageStorageSOPClass,
        RTImageStorageSOPClass,
        RTPlanStorageSOPClass,
        VerificationSOPClass,
    ],
)
MyAE.OnAssociateRequest = OnAssociateRequest
MyAE.OnAssociateResponse = OnAssociateResponse
MyAE.OnReceiveStore = OnReceiveStore
MyAE.OnReceiveEcho = OnReceiveEcho


dcmtkscu.run_in_term("storescu -d localhost 9999 " + os.path.join(testfiles_dir(), "rtplan.dcm"))

# start AE
print "starting AE ...,"
MyAE.start()
print "done"
MyAE.QuitOnKeyboardInterrupt()
Exemple #6
0
# call back


def OnAssociateResponse(association):
    print "Association response received"


# create application entity
MyAE = AE('localhost', 9999, [RTPlanStorageSOPClass, VerificationSOPClass], [])
MyAE.OnAssociateResponse = OnAssociateResponse

# remote application entity
RemoteAE = {'Address': 'localhost', 'Port': 2000, 'AET': 'OFFIS_AE'}

# create some dataset
d = dicom.read_file(os.path.join(testfiles_dir(), "rtplan.dcm"))

# create association with remote AE
print "Request association"
assoc = MyAE.RequestAssociation(RemoteAE)

# perform a DICOM ECHO
# time.sleep(2)
print "DICOM Echo ... ",
st = assoc.VerificationSOPClass.SCU(1)
print 'done with status "%s"' % st

# send dataset using RTPlanStorageSOPClass
# time.sleep(2)
print "DICOM StoreSCP ... ",
st = assoc.RTPlanStorageSOPClass.SCU(d, 1)
Exemple #7
0
    ds.is_little_endian = True
    ds.is_implicit_VR = True
    ds.save_as(filename)
    print "File %s written" % filename
    # must return appropriate status
    return 0

# setup AE
MyAE = AE('SPIN', 9999, [],[MRImageStorageSOPClass,
                            CTImageStorageSOPClass,
                            RTImageStorageSOPClass,
                            RTPlanStorageSOPClass,
                            VerificationSOPClass])
MyAE.OnAssociateRequest = OnAssociateRequest
MyAE.OnAssociateResponse = OnAssociateResponse
MyAE.OnReceiveStore = OnReceiveStore
MyAE.OnReceiveEcho = OnReceiveEcho


dcmtkscu.run_in_term('storescu -d localhost 9999 ' + os.path.join(testfiles_dir(), 'rtplan.dcm'))

# start AE
print "starting AE ...,"
MyAE.start()
print "done"
MyAE.QuitOnKeyboardInterrupt()




Exemple #8
0
    file_meta.ImplementationClassUID = "1.2.3.4"  # !!! Need valid UIDs here
    filename = '/tmp/%s.dcm' % DS.SOPInstanceUID
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0" * 128)
    ds.update(DS)
    ds.is_little_endian = True
    ds.is_implicit_VR = True
    ds.save_as(filename)
    print "File %s written" % filename
    # must return appropriate status
    return 0


# setup AE
MyAE = AE('SPIN', 9999, [], [
    MRImageStorageSOPClass, CTImageStorageSOPClass, RTImageStorageSOPClass,
    RTPlanStorageSOPClass, VerificationSOPClass
])
MyAE.OnAssociateRequest = OnAssociateRequest
MyAE.OnAssociateResponse = OnAssociateResponse
MyAE.OnReceiveStore = OnReceiveStore
MyAE.OnReceiveEcho = OnReceiveEcho

dcmtkscu.run_in_term('storescu -d localhost 9999 ' +
                     os.path.join(testfiles_dir(), 'rtplan.dcm'))

# start AE
print "starting AE ...,"
MyAE.start()
print "done"
MyAE.QuitOnKeyboardInterrupt()
Exemple #9
0
# call back


def OnAssociateResponse(association):
    print "Association response received"

# create application entity
MyAE = AE('localhost', 9999, [RTPlanStorageSOPClass, VerificationSOPClass], [])
MyAE.OnAssociateResponse = OnAssociateResponse

# remote application entity
RemoteAE = {'Address': 'localhost', 'Port': 2000, 'AET': 'OFFIS_AE'}

# create some dataset
d = dicom.read_file(os.path.join(testfiles_dir(), "rtplan.dcm"))

# create association with remote AE
print "Request association"
assoc = MyAE.RequestAssociation(RemoteAE)


# perform a DICOM ECHO
# time.sleep(2)
print "DICOM Echo ... ",
st = assoc.VerificationSOPClass.SCU(1)
print 'done with status "%s"' % st


# send dataset using RTPlanStorageSOPClass
# time.sleep(2)
Exemple #10
0
    filename = '/tmp/%s.dcm' % DS.SOPInstanceUID
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0" * 128)
    ds.update(DS)
    ds.is_little_endian = True
    ds.is_implicit_VR = True
    ds.save_as(filename)
    print "File %s written" % filename
    # must return appropriate status
    return 0

# setup AE
MyAE = AE('SPIN', 9999, [], [MRImageStorageSOPClass,
                             CTImageStorageSOPClass,
                             RTImageStorageSOPClass,
                             RTPlanStorageSOPClass,
                             VerificationSOPClass])
MyAE.OnAssociateRequest = OnAssociateRequest
MyAE.OnAssociateResponse = OnAssociateResponse
MyAE.OnReceiveStore = OnReceiveStore
MyAE.OnReceiveEcho = OnReceiveEcho


dcmtkscu.run_in_term('storescu -d localhost 9999 ' +
                     os.path.join(testfiles_dir(), 'rtplan.dcm'))

# start AE
print "starting AE ...,"
MyAE.start()
print "done"
MyAE.QuitOnKeyboardInterrupt()