generated from FNNDSC/python-chrisapp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacs_query.py
106 lines (91 loc) · 3.72 KB
/
pacs_query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
from pathlib import Path
from argparse import ArgumentParser, Namespace, ArgumentDefaultsHelpFormatter
from pflog import pflog
from loguru import logger
from chris_plugin import chris_plugin, PathMapper
import pfdcm
import json
import sys
import pprint
import os
LOG = logger.debug
logger_format = (
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> │ "
"<level>{level: <5}</level> │ "
"<yellow>{name: >28}</yellow>::"
"<cyan>{function: <30}</cyan> @"
"<cyan>{line: <4}</cyan> ║ "
"<level>{message}</level>"
)
logger.remove()
logger.add(sys.stderr, format=logger_format)
__version__ = '1.0.5'
DISPLAY_TITLE = r"""
_
| |
_ __ | |______ _ __ __ _ ___ ___ __ _ _ _ ___ _ __ _ _
| '_ \| |______| '_ \ / _` |/ __/ __| / _` | | | |/ _ \ '__| | | |
| |_) | | | |_) | (_| | (__\__ \| (_| | |_| | __/ | | |_| |
| .__/|_| | .__/ \__,_|\___|___/ \__, |\__,_|\___|_| \__, |
| | | | ______ | | __/ |
|_| |_| |______||_| |___/
"""
parser = ArgumentParser(description='A ChRIS plugin to query PACS using pfdcm',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument(
'--PACSurl',
default='',
type=str,
help='endpoint URL of pfdcm'
)
parser.add_argument(
'--PACSname',
default='MINICHRISORTHANC',
type=str,
help='name of the PACS'
)
parser.add_argument(
'--PACSdirective',
default='',
type=str,
help='directive to query the PACS'
)
parser.add_argument('-V', '--version', action='version',
version=f'%(prog)s {__version__}')
# The main function of this *ChRIS* plugin is denoted by this ``@chris_plugin`` "decorator."
# Some metadata about the plugin is specified here. There is more metadata specified in setup.py.
#
# documentation: https://fnndsc.github.io/chris_plugin/chris_plugin.html#chris_plugin
@chris_plugin(
parser=parser,
title='A ChRIS plugin to query a remote PACS',
category='', # ref. https://chrisstore.co/plugins
min_memory_limit='100Mi', # supported units: Mi, Gi
min_cpu_limit='1000m', # millicores, e.g. "1000m" = 1 CPU core
min_gpu_limit=0 # set min_gpu_limit=1 to enable GPU
)
def main(options: Namespace, inputdir: Path, outputdir: Path):
"""
*ChRIS* plugins usually have two positional arguments: an **input directory** containing
input files and an **output directory** where to write output files. Command-line arguments
are passed to this main method implicitly when ``main()`` is called below without parameters.
:param options: non-positional arguments parsed by the parser given to @chris_plugin
:param inputdir: directory containing (read-only) input files
:param outputdir: directory where to write output files
"""
LOG(DISPLAY_TITLE)
directive = json.loads(options.PACSdirective)
search_directive,_ = pfdcm.sanitize(directive)
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(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(generated_response, indent=4))
if __name__ == '__main__':
main()