PythonでPACSにdicomファイルを送る方法
CONQUEST DICOM Serverをインストールしているサーバのfsckが失敗してlost+foundディレクトリに
大量のdicomファイルがあったので、それをCONQUEST DICOM Serverに再登録するためのスクリプト
easy_installでpydicom,pynetdicomをインストールすること
#!/usr/bin/env python import sys from netdicom.applicationentity import AE from netdicom.SOPclass import * from dicom.UID import * import dicom import os import traceback remote_host = "xxx.xxx.xxx.xxx" remote_port = 5678 def OnAssociateResponse(association): print "Association response received" MyAE = AE("自分のAEタイトル", 9999, [ StorageSOPClass, VerificationSOPClass],[], [ImplicitVRLittleEndian]) MyAE.OnAssociateResponse = OnAssociateResponse RemoteAE = dict(Address=remote_host, Port=remote_port, AET="CONQUEST") print "Request association" assoc = MyAE.RequestAssociation(RemoteAE) print "DICOM Echo ... ", st = assoc.VerificationSOPClass.SCU(1) print 'done with status "%s"' % st for dpath, dnames, fnames in os.walk("lost+foundにあったdicomファイル置き場のパス"): for fname in fnames: full = dpath + "/" + fname print full d = dicom.read_file(full, None, False, True) print "DICOM StoreSCU ... ", try: st = assoc.SCU(d, 1) print 'done with status "%s"' % st except Exception as inst: print "problem -> ", inst print "trace -> ", traceback.format_exc() print "Release association" assoc.Release(0) MyAE.Quit()
あー、PACSぐらい商用のもの導入してほしい。。。