Skip to content

Commit

Permalink
Support for study-only queries
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolphpienaar committed Dec 17, 2023
1 parent fb9f99b commit 294eefe
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
27 changes: 24 additions & 3 deletions pypx/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ def parser_setup(str_desc):
help = '"movescu" executable absolute location')

# Query settings
parser.add_argument(
'--StudyOnly',
action = 'store_true',
dest = 'StudyOnly',
default = False,
help = 'If specified, perform a query at the STUDY level only')
parser.add_argument(
'--QueryReturnTags',
action = 'store',
dest = 'QueryReturnTags',
type = str,
default = '',
help = 'A comma separated list of query return tags')
parser.add_argument(
'--AccessionNumber',
action = 'store',
Expand Down Expand Up @@ -385,7 +398,15 @@ def __init__(self, arg: Dict):
self.log = self.dp.qprint
self.then = do.Do(self.arg)

def queryCustom_create(self) -> dict:
parameters:dict = {}
if self.arg['QueryReturnTags']:
parameters = {k: '' for k in self.arg['QueryReturnTags'].split(',')}
parameters['QueryRetrieveLevel'] = 'SERIES'
return parameters

def query(self, opt={}):
custom:dict = {}
parameters = {
'AccessionNumber': '',
'PatientID': '',
Expand Down Expand Up @@ -413,7 +434,7 @@ def query(self, opt={}):
'AcquisitionProtocolDescription': '',
'AcquisitionProtocolName': '',
'QueryRetrieveLevel': 'SERIES'
}
} if not (custom := self.queryCustom_create()) else custom

query = ''
# we use a sorted dictionary so we can test generated command
Expand Down Expand Up @@ -477,8 +498,8 @@ async def run(self, opt={}):
'QueryRetrieveLevel': 'STUDY'
}
)

if formattedStudiesResponse['status'] != 'error':
# pudb.set_trace()
if formattedStudiesResponse['status'] != 'error' and not self.arg['StudyOnly']:
filteredStudiesResponse = {}
filteredStudiesResponse['status'] = formattedStudiesResponse['status']
filteredStudiesResponse['command'] = formattedStudiesResponse['command']
Expand Down
29 changes: 21 additions & 8 deletions pypx/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Report(Base):
px scripts and generates/prints reports.
"""

def reportTempate_construct(self, arg):
def reportTemplate_construct(self, arg):
"""
Construct the report based on either the internal
default template, or a parsing of user specified
Expand Down Expand Up @@ -81,6 +81,15 @@ def reportTempate_construct(self, arg):
self.d_reportTags[v[0]][v[1]] = \
self.arg[k].split(',')

def header_studySanitize(self):
self.d_reportTags['header']['study'] = [
k for k in self.d_reportTags['header']['study']
if k in self.arg['reportData']['command']
]
if 'Modality' not in self.arg['reportData']['command'] or \
'QueryRetrieveLevel=STUDY' in self.arg['reportData']['command']:
self.d_reportTags['header']['series'] = []

def __init__(self, arg):
"""
Constructor.
Expand All @@ -105,7 +114,9 @@ def __init__(self, arg):
self.d_report : dict = {}

super(Report, self).__init__(arg)
self.reportTempate_construct(arg)
# pudb.set_trace()
self.reportTemplate_construct(arg)
self.header_studySanitize()
self.dp = pfmisc.debug(
verbosity = self.verbosity,
within = 'Find',
Expand Down Expand Up @@ -150,7 +161,7 @@ def DICOMtag_lookup(d_DICOMfields, str_DICOMtag):
try:
str_value = d_DICOMfields[str_DICOMtag]['value']
except:
if str_DICOMtag == 'PatientAge':
if str_DICOMtag == 'PatientAge' and 'PatientBirthDate' in d_DICOMfields:
"""
Sometimes the PatientAge is not returned
in the call to PACS. In this case, calculate
Expand Down Expand Up @@ -265,8 +276,9 @@ def header_generate(study):
if k == 'study':
analyze = study
if k == 'series':
if len(study['series']):
analyze = study['series'][0]
if 'series' in study:
if len(study['series']):
analyze = study['series'][0]
l_tags = self.d_reportTags['header'][k]
l_headerTable, str_reportHeader, d_headerContents = \
block_build(analyze, l_tags, l_headerTable, str_reportHeader, d_headerContents)
Expand All @@ -290,20 +302,21 @@ def body_generate(study, studyCount):
str_reportSUID = ""
str_reportBody = ""
d_bodyFields = self.d_reportTags['body']
dl_bodyContents = []
dl_seriesUID = []
tb_bodyInstance = SingleTable([])
nonlocal seriesCount
for k in d_bodyFields.keys():
l_bodyTable = []
l_suidTable = []
d_bodyContents = {}
d_seriesUID = {}
dl_bodyContents = []
dl_seriesUID = []
l_seriesUIDtag = [
'SeriesInstanceUID',
'SeriesNumber',
'NumberOfSeriesRelatedInstances'
]
if k == 'series':
if k == 'series' and 'series' in study:
l_series = study['series']
# if len(self.arg['reportBodySeriesTags']):
# l_tags = self.arg['reportBodySeriesTags'].split()
Expand Down

0 comments on commit 294eefe

Please sign in to comment.