|
@@ -0,0 +1,96 @@
|
|
|
+import os
|
|
|
+import json
|
|
|
+import re
|
|
|
+import sys
|
|
|
+
|
|
|
+
|
|
|
+fhome=os.path.expanduser('~')
|
|
|
+sys.path.insert(1,fhome+'/software/src/labkeyInterface')
|
|
|
+import labkeyInterface
|
|
|
+import labkeyDatabaseBrowser
|
|
|
+
|
|
|
+sys.path.insert(1,fhome+'/software/src/orthancInterface')
|
|
|
+import orthancInterface
|
|
|
+import orthancDatabaseBrowser
|
|
|
+
|
|
|
+fconfig=os.path.join(fhome,'.labkey','network.json')
|
|
|
+
|
|
|
+net=labkeyInterface.labkeyInterface()
|
|
|
+net.init(fconfig)
|
|
|
+db=labkeyDatabaseBrowser.labkeyDB(net)
|
|
|
+
|
|
|
+
|
|
|
+onet=orthancInterface.orthancInterface()
|
|
|
+onet.init(fconfig)
|
|
|
+odb=orthancDatabaseBrowser.orthancDB(onet)
|
|
|
+
|
|
|
+i=0
|
|
|
+project='Orthanc/Database'
|
|
|
+
|
|
|
+patients=odb.getPatients()
|
|
|
+
|
|
|
+for p in patients:
|
|
|
+ pdata=odb.getPatientData(p)
|
|
|
+ dicom=pdata['MainDicomTags']
|
|
|
+ patientId=dicom['PatientID']
|
|
|
+
|
|
|
+ print("Patient: {} ID: {}".format(p,patientId))
|
|
|
+
|
|
|
+ qfilter={'variable':'PatientId','value':patientId,'oper':'eq'}
|
|
|
+ ds=db.selectRows(project,'study','Demographics',[qfilter])
|
|
|
+ if len(ds['rows'])==0:
|
|
|
+ row={}
|
|
|
+ row['PatientId']=patientId
|
|
|
+ row['birthDate']=dicom['PatientBirthDate']
|
|
|
+ row['PatientName']=dicom['PatientName']
|
|
|
+ row['OrthancId']=p
|
|
|
+ db.modifyRows('insert',project,'study','Demographics',[row])
|
|
|
+
|
|
|
+ for s in pdata['Studies']:
|
|
|
+ sdata=odb.getStudyData(s)
|
|
|
+ sdicom=sdata['MainDicomTags']
|
|
|
+ sid=sdicom['StudyInstanceUID']
|
|
|
+ print('Study: {}/{}'.format(s,sid))
|
|
|
+ #print('Data: {}'.format(sdata))
|
|
|
+ sdate=sdicom['StudyDate']
|
|
|
+ #continue
|
|
|
+
|
|
|
+
|
|
|
+ for se in sdata['Series']:
|
|
|
+
|
|
|
+ qfilter={'variable':'orthancSeries','value':se,'oper':'eq'}
|
|
|
+ ds=db.selectRows(project,'study','Imaging',[qfilter])
|
|
|
+ if len(ds['rows'])>0:
|
|
|
+ continue
|
|
|
+
|
|
|
+ #count existing entries for patient
|
|
|
+ qfilter={'variable':'PatientId','value':patientId,'oper':'eq'}
|
|
|
+ ds=db.selectRows(project,'study','Imaging',[qfilter])
|
|
|
+ seqNum=len(ds['rows'])
|
|
|
+
|
|
|
+ sedata=odb.getSeriesData(se)
|
|
|
+ sedicom=sedata['MainDicomTags']
|
|
|
+ seid=sedicom['SeriesInstanceUID']
|
|
|
+ print('Series: {}/{}'.format(se,seid))
|
|
|
+ #print('Data: {}'.format(sedata))
|
|
|
+ seDesc="NONE"
|
|
|
+ try:
|
|
|
+ seDesc=sedicom['SeriesDescription']
|
|
|
+ except KeyError:
|
|
|
+ pass
|
|
|
+
|
|
|
+ print('ID: {}.'.format(seDesc))
|
|
|
+
|
|
|
+ row={}
|
|
|
+ row['PatientId']=patientId
|
|
|
+ row['sequenceNum']=seqNum
|
|
|
+ row['dicomStudy']=sid
|
|
|
+ row['orthancStudy']=s
|
|
|
+ row['dicomSeries']=seid
|
|
|
+ row['orthancSeries']=se
|
|
|
+ row['studyDate']=sdate
|
|
|
+ row['seriesDescription']=seDesc
|
|
|
+ db.modifyRows('insert',project,'study','Imaging',[row])
|
|
|
+
|
|
|
+
|
|
|
+print("Done")
|