Last active
December 27, 2023 09:34
-
-
Save acidsound/2ca74e7d221d86b227427353a94767a3 to your computer and use it in GitHub Desktop.
2000포트로 Orthanc 에 send to modality 하면 series no 10006 생성해서 다시 전송하는 예제
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pynetdicom import AE, evt, AllStoragePresentationContexts, debug_logger | |
from pydicom.uid import generate_uid | |
debug_logger() | |
def sendBackToStore(ds): | |
ae2 = AE(ae_title=b'ORTHANC') | |
ae2.add_requested_context('1.2.840.10008.5.1.4.1.1.2', ['1.2.840.10008.1.2']) # CT Image Storage - Implicit VR Endian: Default Transfer Syntax for DICOM | |
ae2.add_requested_context('1.2.840.10008.5.1.4.1.1.7', ['1.2.840.10008.1.2']) # Secondary Capture Image Storage | |
ae2.add_requested_context('1.2.840.10008.1.1') # Verification SOP Class | |
# Associate with peer AE at IP 127.0.0.1 and port 4242 | |
assoc = ae2.associate("127.0.0.1", 4242) | |
if assoc.is_established: | |
# Use the C-STORE service to send the dataset | |
# returns the response status as a pydicom Dataset | |
status = assoc.send_c_store(ds) | |
# Check the status of the storage request | |
if status: | |
# If the storage request succeeded this will be 0x0000 | |
print('C-STORE request status: 0x{0:04x}'.format(status.Status)) | |
else: | |
print('Connection timed out, was aborted or received invalid response') | |
# Release the association | |
assoc.release() | |
else: | |
print('Association rejected, aborted or never connected') | |
# Implement a handler for evt.EVT_C_STORE | |
def handle_store(event): | |
"""Handle a C-STORE request event.""" | |
# Decode the C-STORE request's *Data Set* parameter to a pydicom Dataset | |
ds = event.dataset | |
# Add the File Meta Information | |
ds.file_meta = event.file_meta | |
ds.SeriesNumber = '10006' | |
ds.SeriesInstanceUID = generate_uid() | |
# Save the dataset using the SOP Instance UID as the filename | |
ds.save_as(ds.SOPInstanceUID, write_like_original=False) | |
# Return a 'Success' status | |
sendBackToStore(ds) | |
return 0x0000 | |
handlers = [(evt.EVT_C_STORE, handle_store)] | |
# Initialise the Application Entity | |
ae = AE(ae_title=b'STORESCP') | |
# Support presentation contexts for all storage SOP Classes | |
ae.supported_contexts = AllStoragePresentationContexts | |
# Start listening for incoming association requests | |
ae.start_server(("127.0.0.1", 2000), evt_handlers=handlers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment