123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #load all relevant patient data
- #requires labkeyInterface through labkeyDatabrowser db, labkeyFileBrowser fb, fbDMR, importDicom iDicom and loadDicom lDicom
-
- def getOICode(db, project, label):
- idFilter={"variable":"EMBRACE_ID",
- "oper":"eq",
- "value":label}
- fSet=db.selectRows(project,'study','PopisneStevilke',[idFilter])
- try:
- row=fSet["rows"][0]
- except:
- print("OI code for {} not found").format(label)
- return None
- return row["OICode"]
- def load(db,fb,fbDMR,iDicom,lDicom,project,label):
- print('loadPatient.load ver: 1.0.3')
- idFilter={'variable':'EMBRACE_ID','value':label,'oper':'eq'}
- ctFilter={'variable':'type','value':'CT','oper':'eq'}
- dsCT=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,ctFilter])
- returnObj={}
- try:
- ctRow=dsCT['rows'][0]
- except IndexError:
- return returnObj
-
- oiCode=getOICode(db,project,label)
-
- #load ct
- seqNum=ctRow['pseudoTransverseID']
- oiFilter={'variable':'PatientId','value':oiCode,'oper':'eq'}
- sFilter={'variable':'SequenceNum','value':'{:.0f}'.format(seqNum),'oper':'eq'}
-
- dsDicom=db.selectRows('Test/Transfer','study','Imaging',[oiFilter,sFilter])
- try:
- rDicom=dsDicom['rows'][0]
- except IndexError:
- return returnObj
-
- iPath=['dicom',rDicom['Study'],rDicom['Series']]
- dicomReadFilter={'seriesNumber':"SeriesLabel",
- 'studyInstanceUid':None,
- 'frameOfReferenceInstanceUid':None}
- ctVolumes=iDicom.loadVolumes(fb,'Test/Transfer',iPath,dicomReadFilter)
- ctNode=ctVolumes[0]['node']
- ctNode.SetName(label+'_CT')
- #load dmr
- #uses different server!!!
- dmrFilter={'variable':'type','value':'DMR','oper':'eq'}
- dsDMR=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,dmrFilter])
- try:
- dmrRow=dsDMR['rows'][0]
- except IndexError:
- return returnObj
-
- dmrName=dmrRow['Name']
- iPath=['PRETVORJENE',dmrName,'DICOM']
- dicomReadFilter={'seriesNumber':"SeriesLabel",
- 'sequenceName':"*tse2d1_3",
- 'percentPhaseFieldOfView':90,
- 'studyInstanceUid':None,
- 'frameOfReferenceInstanceUid':None,
- 'scanningSequence':None,
- 'sequenceVariant':None}
- dmrVolumes=iDicom.loadVolumes(fbDMR,project,iPath,dicomReadFilter)
- try:
- dmrNode=dmrVolumes[0]['node']
- dmrNode.SetName(label+'_DMR')
- except IndexError:
- return returnObj
- #load CT-RS
- ctrsFilter={'variable':'type','value':'CT-RS','oper':'eq'}
- dsCTRS=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,ctrsFilter])
- try:
- ctrsRow=dsCTRS['rows'][0]
- print('CTRS: {}'.format(len(dsCTRS['rows'])))
- except IndexError:
- return returnObj
- seqNum=ctrsRow['pseudoTransverseID']
- sFilter={'variable':'SequenceNum','value':'{:.0f}'.format(seqNum),'oper':'eq'}
-
- dsDicomRT=db.selectRows('Test/Transfer','study','Imaging',[oiFilter,sFilter])
- try:
- rDicomRT=dsDicomRT['rows'][0]
- print('CT-RS Dicom: {}'.format(len(dsDicomRT['rows'])))
- print('ID: {}'.format(rDicomRT['PatientId']))
- except IndexError:
- return returnObj
- iPath=['dicom',rDicomRT['Study'],rDicomRT['Series']]
- dicomReadFilter={'seriesNumber':"SeriesLabel",
- 'studyInstanceUid':None,
- 'frameOfReferenceInstanceUid':None}
- rtSeg=lDicom.loadSegmentations(fb,'Test/Transfer',iPath,dicomReadFilter)
- rtNode=rtSeg[0]['node']
- rtNode.SetName(label+'_CTRS')
- return {'CT':ctNode,'DMR':dmrNode,'CTRS':rtNode,
- 'metadataCT':ctVolumes[0]['metadata'],
- 'metadataDMR':dmrVolumes[0]['metadata'],
- 'metadataCTRS':rtSeg[0]['metadata']
- }
|