Skip to content

Commit

Permalink
update search and filter operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Dec 10, 2024
1 parent 6a9fff6 commit 756d8cb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
14 changes: 9 additions & 5 deletions pacs_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
logger.remove()
logger.add(sys.stderr, format=logger_format)
__version__ = '1.0.1'
__version__ = '1.0.2'

DISPLAY_TITLE = r"""
_
Expand Down Expand Up @@ -85,17 +85,21 @@ def main(options: Namespace, inputdir: Path, outputdir: Path):
:param outputdir: directory where to write output files
"""

print(DISPLAY_TITLE)
LOG(DISPLAY_TITLE)
directive = json.loads(options.PACSdirective)
search_directive,_ = pfdcm.sanitize(directive)

search_response = pfdcm.get_pfdcm_status(directive, options.PACSurl, options.PACSname)
search_response = pfdcm.get_pfdcm_status(search_directive, options.PACSurl, options.PACSname)
generated_response, file_count = pfdcm.autocomplete_directive(directive, search_response)

LOG(pprint.pformat(search_response['pypx']['data']))
# LOG(pprint.pformat(search_response['pypx']['data']))
LOG(pprint.pformat(generated_response))
LOG(f"file count is : {file_count}")
op_json_file_path = os.path.join(options.outputdir,"search_results.json")
# Open a json writer, and use the json.dumps()
# function to dump data
with open(op_json_file_path, 'w', encoding='utf-8') as jsonf:
jsonf.write(json.dumps(search_response['pypx']['data'], indent=4))
jsonf.write(json.dumps(generated_response, indent=4))


if __name__ == '__main__':
Expand Down
40 changes: 32 additions & 8 deletions pfdcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ def health_check(url: str):
except Exception as er:
raise Exception("Connection to pfdcm could not be established.")

def sanitize(directive: dict) -> (dict, dict):
"""
Remove any field that contains name or description
as pfdcm doesn't allow partial text search and these fields
may contain partial text.
"""
partial_directive = []
clone_directive = copy.deepcopy(directive)
for key in directive.keys():
if "Name" in key or "Description" in key:
partial_directive.append({key:clone_directive.pop(key)})
return clone_directive, dict(ChainMap(*partial_directive))


def get_pfdcm_status(directive: dict, url: str, pacs_name: str):
"""
Expand Down Expand Up @@ -63,29 +76,40 @@ def get_pfdcm_status(directive: dict, url: str, pacs_name: str):
except Exception as ex:
LOG(ex)

def autocomplete_directive(directive: dict, d_response: dict) -> (dict,int):
def autocomplete_directive(directive: dict, d_response: dict) -> (list,int):
"""
Autocomplete certain fields in the search directive using response
object from pfdcm
"""
search_directive,partial_directive = ''#sanitize(directive)
search_directive,partial_directive = sanitize(directive)
file_count = 0
res: list = []

# get the count of all matching files inside PACS
# we will be using this count to verify file registration
# in CUBE

for l_series in d_response['pypx']['data']:
for series in l_series["series"]:
ser = {}

# iteratively check for all search fields and update the search record simultaneously
# with SeriesInstanceUID and StudyInstanceUID
flag = False
for key in directive.keys():
if series.get(key) and directive[key].lower() in series[key]["value"].lower():
partial_directive[key] = series[key]["value"]
search_directive["SeriesInstanceUID"] = series["SeriesInstanceUID"]["value"]
search_directive["StudyInstanceUID"] = series["StudyInstanceUID"]["value"]
flag = True
else:
continue
file_count += int(series["NumberOfSeriesRelatedInstances"]["value"])
flag = False
if flag:
for label in series:
ser[label] = series[label]["value"]
res.append(ser)
file_count += int(series["NumberOfSeriesRelatedInstances"]["value"])
# ser["SeriesInstanceUID"] = series["SeriesInstanceUID"]["value"]
# ser["StudyInstanceUID"] = series["StudyInstanceUID"]["value"]
else:
continue

# _.update(partial_directive)
return search_directive, file_count
return res, file_count

0 comments on commit 756d8cb

Please sign in to comment.