How to use the pynetdicom.StoragePresentationContexts function in pynetdicom

To help you get started, we’ve selected a few pynetdicom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pydicom / pynetdicom / pynetdicom / apps / storescp / storescp.py View on Github external
handlers = [(evt.EVT_C_STORE, handle_store)]

# Test output-directory
if args.output_directory is not None:
    if not os.access(args.output_directory, os.W_OK|os.X_OK):
        APP_LOGGER.error('No write permissions or the output '
                     'directory may not exist:')
        APP_LOGGER.error("    {0!s}".format(args.output_directory))
        sys.exit()

# Create application entity
ae = AE(ae_title=args.aetitle)

# Add presentation contexts with specified transfer syntaxes
for context in StoragePresentationContexts:
    ae.add_supported_context(context.abstract_syntax, transfer_syntax)
for context in VerificationPresentationContexts:
    ae.add_supported_context(context.abstract_syntax, transfer_syntax)

ae.maximum_pdu_size = args.max_pdu

# Set timeouts
ae.network_timeout = args.timeout
ae.acse_timeout = args.acse_timeout
ae.dimse_timeout = args.dimse_timeout

ae.start_server((args.bind_addr, args.port), evt_handlers=handlers)
github pydicom / pynetdicom / pynetdicom / apps / movescu / movescu.py View on Github external
APP_LOGGER.error('Directory may not exist or you may not have write '
                         'permission')
            # Failed - Out of Resources - IOError
            status_ds.Status = 0xA700
        except:
            APP_LOGGER.error('Could not write file to specified directory:')
            APP_LOGGER.error("    {0!s}".format(os.path.dirname(filename)))
            # Failed - Out of Resources - Miscellaneous error
            status_ds.Status = 0xA701

        return status_ds

    store_handlers = [(evt.EVT_C_STORE, handle_store)]

    ae.ae_title = args.store_aet
    ae.supported_contexts = StoragePresentationContexts
    scp = ae.start_server(('', args.store_port),
                          block=False,
                          evt_handlers=store_handlers)

ae.ae_title = args.calling_aet
ae.requested_contexts = QueryRetrievePresentationContexts


# Request association with remote AE
assoc = ae.associate(args.peer, args.port, ae_title=args.called_aet)

if assoc.is_established:
    # Create query dataset
    ds = Dataset()
    ds.PatientName = '*'
    ds.QueryRetrieveLevel = "PATIENT"
github pydicom / pynetdicom / pynetdicom / apps / storescu / storescu.py View on Github external
transfer_syntax = [ExplicitVRLittleEndian,
                   ImplicitVRLittleEndian,
                   DeflatedExplicitVRLittleEndian,
                   ExplicitVRBigEndian]

if args.request_little:
    transfer_syntax = [ExplicitVRLittleEndian]
elif args.request_big:
    transfer_syntax = [ExplicitVRBigEndian]
elif args.request_implicit:
    transfer_syntax = [ImplicitVRLittleEndian]

# Bind to port 0, OS will pick an available port
ae = AE(ae_title=args.calling_aet)

for context in StoragePresentationContexts:
    ae.add_requested_context(context.abstract_syntax, transfer_syntax)

# Request association with remote
assoc = ae.associate(args.peer, args.port, ae_title=args.called_aet)

if assoc.is_established:
    APP_LOGGER.info('Sending file: {0!s}'.format(args.dcmfile_in))

    status = assoc.send_c_store(dataset)

    assoc.release()
github pydicom / pynetdicom / pynetdicom / apps / getscp / getscp.py View on Github external
dcm_files = [os.path.join(DATA_DIR, x) for x in dcm_files]
        yield len(dcm_files)
    except:
        dcm_files = []
        yield 0

    for dcm in dcm_files:
        ds = dcmread(dcm, force=True)
        yield 0xFF00, ds

handlers = [(evt.EVT_C_GET, handle_get)]

# Create application entity
ae = AE(ae_title=args.aetitle)

for context in StoragePresentationContexts:
    ae.add_supported_context(
        context.abstract_syntax, transfer_syntax, scp_role=True, scu_role=False
    )
for context in QueryRetrievePresentationContexts:
    ae.add_supported_context(context.abstract_syntax, transfer_syntax)

ae.maximum_pdu_size = args.max_pdu

# Set timeouts
ae.network_timeout = args.timeout
ae.acse_timeout = args.acse_timeout
ae.dimse_timeout = args.dimse_timeout

ae.start_server(('', args.port), evt_handlers=handlers)
github pydicom / pynetdicom / pynetdicom / apps / movescp / movescp.py View on Github external
yield len(dcm_files)

    # Matching datasets to send
    for dcm in dcm_files:
        ds = dcmread(dcm, force=True)
        yield 0xff00, ds


handlers = [(evt.EVT_C_MOVE, handle_move)]

# Create application entity
ae = AE(ae_title=args.aetitle)

# Add the requested Storage Service presentation contexts
# Used when sending the dataset to the move destination Storage SCP
for context in StoragePresentationContexts:
    ae.add_requested_context(context.abstract_syntax, transfer_syntax)

# Add the supported QR Service presentation contexts
for context in QueryRetrievePresentationContexts:
    ae.add_supported_context(context.abstract_syntax, transfer_syntax)

ae.maximum_pdu_size = args.max_pdu

# Set timeouts
ae.network_timeout = args.timeout
ae.acse_timeout = args.acse_timeout
ae.dimse_timeout = args.dimse_timeout

ae.start_server(('', args.port), evt_handlers=handlers)
github pydicom / pynetdicom / pynetdicom / apps / getscu / getscu.py View on Github external
_setup_logging(levels[args.log_level])

if args.log_config:
    fileConfig(args.log_config)

APP_LOGGER.debug('$getscu.py v{0!s}'.format(VERSION))
APP_LOGGER.debug('')


# Create application entity
# Binding to port 0 lets the OS pick an available port
ae = AE(ae_title=args.calling_aet)

for context in QueryRetrievePresentationContexts:
    ae.add_requested_context(context.abstract_syntax)
for context in StoragePresentationContexts[:115]:
    ae.add_requested_context(context.abstract_syntax)

# Add SCP/SCU Role Selection Negotiation to the extended negotiation
# We want to act as a Storage SCP
ext_neg = []
for context in StoragePresentationContexts:
    ext_neg.append(build_role(context.abstract_syntax, scp_role=True))

# Create query dataset
d = Dataset()
d.PatientName = '*'
d.QueryRetrieveLevel = "PATIENT"

if args.patient:
    query_model = PatientRootQueryRetrieveInformationModelGet
elif args.study:
github pydicom / pynetdicom / pynetdicom / benchmarks / bench_presentation.py View on Github external
def setup(self):
        # Requestor presentation contexts - max 126
        self.requestor_contexts = []
        for ii, cx in enumerate(StoragePresentationContexts):
            cx.context_id = ii * 2 + 1
            self.requestor_contexts.append(cx)

        # Acceptor presentation contexts - no max
        self.acceptor_contexts = []
        for ii, cx in enumerate(StoragePresentationContexts):
            cx = deepcopy(cx)
            cx.context_id = ii * 2 + 1
            cx.transfer_syntax = ['1.2.840.10008.1.2']
            cx.result = 0x00

            self.acceptor_contexts.append(cx)