Skip to content

Commit

Permalink
added params to input and copy JSON files
Browse files Browse the repository at this point in the history
Sandip117 committed Dec 10, 2024
1 parent 68cac3b commit cb8d18b
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions pacs_retrieve.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
)
logger.remove()
logger.add(sys.stderr, format=logger_format)
__version__ = '1.0.1'
__version__ = '1.0.2'

DISPLAY_TITLE = r"""
_ _ _
@@ -37,9 +37,7 @@
"""


parser = ArgumentParser(description='!!!CHANGE ME!!! An example ChRIS plugin which '
'counts the number of occurrences of a given '
'word in text files.',
parser = ArgumentParser(description='A plugin to retrieve DICOM images from a remote PACS using pfdcm',
formatter_class=ArgumentDefaultsHelpFormatter)

parser.add_argument(
@@ -55,10 +53,16 @@
help='name of the PACS'
)
parser.add_argument(
'--PACSdirective',
'--inputJSONfile',
default='',
type=str,
help='directive to query the PACS'
help='JSON file containing DICOM data to be retrieved'
)
parser.add_argument(
'--copyInputFile',
default=False,
action="store_true",
help='If specified, copy input JSON to output dir'
)
parser.add_argument('-V', '--version', action='version',
version=f'%(prog)s {__version__}')
@@ -89,16 +93,25 @@ def main(options: Namespace, inputdir: Path, outputdir: Path):

print(DISPLAY_TITLE)

directive = json.loads(options.PACSdirective)

retrieve_response = pfdcm.retrieve_pacsfiles(directive, options.PACSurl, options.PACSname)

LOG(f"response: {pprint.pformat(retrieve_response)}")
op_json_file_path = os.path.join(options.outputdir, "retrieve_response.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(retrieve_response, indent=4))
mapper = PathMapper.file_mapper(inputdir, outputdir, glob=options.inputJSONfile)
for input_file, output_file in mapper:
if options.copyInputFile:
output_file.write_text(input_file.read_text())
# Open and read the JSON file
with open(input_file, 'r') as file:
data = json.load(file)
for series in data:
directive = {}
directive["SeriesInstanceUID"] = series["SeriesInstanceUID"]
directive["StudyInstanceUID"] = series["StudyInstanceUID"]
retrieve_response = pfdcm.retrieve_pacsfiles(directive, options.PACSurl, options.PACSname)

LOG(f"response: {pprint.pformat(retrieve_response)}")
op_json_file_path = os.path.join(options.outputdir, f"{series["SeriesInstanceUID"]}_retrieve.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(retrieve_response, indent=4))


if __name__ == '__main__':

0 comments on commit cb8d18b

Please sign in to comment.