ctp-client 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,165 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ .docker/ctpm-temp/**
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
163
+
164
+ app.db
165
+ /ctpy/version.py
@@ -0,0 +1,14 @@
1
+ Copyright 2017 Biomedical Imaging Group Rotterdam, Departments of
2
+ Medical Informatics and Radiology, Erasmus MC, Rotterdam, The Netherlands
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: ctp-client
3
+ Version: 1.0.1
4
+ Summary: ctp-client is a Python client for [Clinical Trials Processor](https://mircwiki.rsna.org/index.php?title=MIRC_CTP).
5
+ Project-URL: CI/CD, https://gitlab.com/radiology/infrastructure/data-curation-tools/ctp-client/-/pipelines
6
+ Project-URL: Changelog, https://ctp-client.readthedocs.io/en/latest/changelog.html
7
+ Project-URL: Documentation, https://ctp-client.readthedocs.io
8
+ Project-URL: Download, https://gitlab.com/radiology/infrastructure/data-curation-tools/ctp-client/-/archive/master/ctp-client-master.zip
9
+ Project-URL: Homepage, https://gitlab.com/radiology/infrastructure/data-curation-tools/ctp-client.git
10
+ Project-URL: Issues, https://gitlab.com/radiology/infrastructure/data-curation-tools/ctp-client/-/issues
11
+ Author-email: BIGR Imaging Infrastructure Group <imaging.infrastructure@erasmusmc.nl>
12
+ License: Apache 2.0
13
+ License-File: LICENSE
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Education
17
+ Classifier: Intended Audience :: Healthcare Industry
18
+ Classifier: Intended Audience :: Information Technology
19
+ Classifier: Intended Audience :: Science/Research
20
+ Classifier: License :: OSI Approved :: Apache Software License
21
+ Classifier: Natural Language :: English
22
+ Classifier: Operating System :: OS Independent
23
+ Classifier: Programming Language :: Python :: 3 :: Only
24
+ Classifier: Programming Language :: Python :: 3.9
25
+ Classifier: Programming Language :: Python :: 3.10
26
+ Classifier: Programming Language :: Python :: 3.11
27
+ Classifier: Programming Language :: Python :: 3.12
28
+ Classifier: Programming Language :: Python :: 3.13
29
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
30
+ Classifier: Topic :: System :: Logging
31
+ Classifier: Topic :: Utilities
32
+ Requires-Python: >=3.9
33
+ Requires-Dist: beautifulsoup4==4.12.3
34
+ Requires-Dist: click-log==0.4.0
35
+ Requires-Dist: click-loglevel==0.5.1
36
+ Requires-Dist: click==8.1.3
37
+ Requires-Dist: pydantic==2.10.3
38
+ Requires-Dist: pyyaml==6.0.2
39
+ Requires-Dist: requests>=2.22.0
40
+ Requires-Dist: tabulate==0.9.0
41
+ Description-Content-Type: text/markdown
42
+
43
+ # CTPy
44
+
45
+ CTPy is a Python client for [Clinical Trials Processor](https://mircwiki.rsna.org/index.php?title=MIRC_CTP).
@@ -0,0 +1,3 @@
1
+ # CTPy
2
+
3
+ CTPy is a Python client for [Clinical Trials Processor](https://mircwiki.rsna.org/index.php?title=MIRC_CTP).
@@ -0,0 +1,43 @@
1
+ # Copyright 2017 Biomedical Imaging Group Rotterdam, Departments of
2
+ # Medical Informatics and Radiology, Erasmus MC, Rotterdam, The Netherlands
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ from typing import Optional
18
+
19
+ from .import version
20
+ from .client import CTPYclient
21
+
22
+ __version__ = version.version
23
+
24
+
25
+ def connect(host: str,
26
+ port: int,
27
+ username: str,
28
+ password: str,
29
+ rate_limit: Optional[int] = None) -> CTPYclient:
30
+ """
31
+ Createa a connection to a CTP server
32
+
33
+ :param host: host to connect to
34
+ :param port: port to connect to
35
+ :param username: username to login as
36
+ :param password: password for user
37
+ :param rate_limit: optionally limit the time between requests, this is specified
38
+ as the maximum requests per second
39
+
40
+ :return: CTP client object
41
+ """
42
+ ctpy_client = CTPYclient(host, port, username, password, rate_limit)
43
+ return ctpy_client
@@ -0,0 +1,17 @@
1
+ # Copyright 2017 Biomedical Imaging Group Rotterdam, Departments of
2
+ # Medical Informatics and Radiology, Erasmus MC, Rotterdam, The Netherlands
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ from .cli import cli
@@ -0,0 +1,157 @@
1
+ # Copyright 2017 Biomedical Imaging Group Rotterdam, Departments of
2
+ # Medical Informatics and Radiology, Erasmus MC, Rotterdam, The Netherlands
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ import socket
18
+ import logging
19
+ from pathlib import Path
20
+
21
+ import click
22
+ import tabulate
23
+ from click_loglevel import LogLevel
24
+ import yaml
25
+ from yaml.loader import SafeLoader
26
+
27
+ from ctpy import CTPYclient
28
+ from ctpy import exceptions
29
+ from ctpy.helpers import poll_object_tracker_for_studyuid, summarize_object_tracker_content
30
+
31
+ @click.group()
32
+ @click.version_option()
33
+ @click.pass_context
34
+ def cli(ctx):
35
+ ctx.ensure_object(dict)
36
+
37
+ @cli.command()
38
+ @click.option('--lookup-table-filename', type=Path, required=True)
39
+ @click.option('--ctp-host', required=True)
40
+ @click.option('--ctp-port', type=int, default=1180, required=True)
41
+ @click.option('--dicom-anonymizer-id', required=True)
42
+ @click.option('--username', required=True)
43
+ @click.option('--password', required=True, prompt=True, hide_input=True)
44
+ @click.option('--log-level', type=LogLevel(), default=logging.INFO)
45
+ @click.pass_context
46
+ def post_lookup_table(_, lookup_table_filename, ctp_host, ctp_port,
47
+ dicom_anonymizer_id, username, password, log_level):
48
+ logging.basicConfig(
49
+ format=f"%(asctime)s - {socket.gethostname()} - [%(levelname)-8s] %(message)s",
50
+ level=log_level,
51
+ )
52
+ ctpy_client = CTPYclient(ctp_host, ctp_port, username, password, rate_limit=0.2)
53
+ with open(lookup_table_filename, encoding='utf-8') as lookup_table_file:
54
+ lut = yaml.load(lookup_table_file, Loader=SafeLoader)
55
+ for key, value in lut.items():
56
+ try:
57
+ ctpy_client.add_to_lookup(dicom_anonymizer_id, key, value)
58
+ except exceptions.CTPYFailedAddingLUT:
59
+ pass
60
+ break
61
+
62
+ @cli.command()
63
+ @click.option('--ctp-host', required=True)
64
+ @click.option('--ctp-port', type=int, default=1180, required=True)
65
+ @click.option('--pipeline-id', type=int, default=0, required=True)
66
+ @click.option('--object-tracker-id', type=int, default=1, required=True)
67
+ @click.option('--username', required=True, default="king")
68
+ @click.option('--password', required=True, default="password", prompt=True, hide_input=True)
69
+ @click.option('--patient-id', required=True)
70
+ @click.option('--study-uid', 'study_uid_filter')
71
+ @click.option('--delay', type=int, default=5)
72
+ @click.option('--timeout', type=int, default=900)
73
+ @click.option('--log-level', type=LogLevel(), default=logging.INFO)
74
+ @click.pass_context
75
+ def check_object_tracker(_, ctp_host, ctp_port, pipeline_id, object_tracker_id,
76
+ username, password, patient_id, study_uid_filter, delay,
77
+ timeout, log_level):
78
+ logging.basicConfig(
79
+ format=f"%(asctime)s - {socket.gethostname()} - [%(levelname)-8s] %(message)s",
80
+ level=log_level,
81
+ )
82
+ ctpy_client = CTPYclient(ctp_host, ctp_port, username, password, rate_limit=0.2)
83
+ object_tracker_data = poll_object_tracker_for_studyuid(ctpy_client,
84
+ pipeline_id,
85
+ object_tracker_id,
86
+ patient_id,
87
+ study_uid_filter,
88
+ delay,
89
+ timeout)
90
+ logging.debug('patient_data: %s', object_tracker_data)
91
+ if object_tracker_data and patient_id in object_tracker_data:
92
+ for study_uid, series_info in object_tracker_data[patient_id].items():
93
+ for series_uid, instances in series_info.items():
94
+ logging.info('%s|%s|%s', study_uid, series_uid, instances)
95
+
96
+ @cli.command()
97
+ @click.option('--ctp-host', required=True)
98
+ @click.option('--ctp-port', type=int, default=1180, required=True)
99
+ @click.option('--pipeline-id', type=int, default=0, required=True)
100
+ @click.option('--idmap-id', type=int, default=1, required=True)
101
+ @click.option('--username', required=True, default="king")
102
+ @click.option('--password', required=True, default="password", prompt=True, hide_input=True)
103
+ @click.option('--keytype', required=True)
104
+ @click.option('--key', required=True)
105
+ @click.option('--log-level', type=LogLevel(), default=logging.INFO)
106
+ @click.pass_context
107
+ def query_idmap(_, ctp_host, ctp_port, pipeline_id, idmap_id, keytype, key,
108
+ username, password, log_level):
109
+ logging.basicConfig(
110
+ format=f"%(asctime)s - {socket.gethostname()} - [%(levelname)-8s] %(message)s",
111
+ level=log_level,
112
+ )
113
+ ctpy_client = CTPYclient(ctp_host, ctp_port, username, password, rate_limit=0.2)
114
+ study_uid = ctpy_client.idmap_search(pipeline_id, idmap_id, key, keytype)
115
+ if study_uid:
116
+ logging.info(study_uid)
117
+
118
+
119
+ @cli.command()
120
+ @click.option('--ctp-host', required=True)
121
+ @click.option('--ctp-port', type=int, default=1180, required=True)
122
+ @click.option('--username', required=False)
123
+ @click.option('--password', required=False)
124
+ def get_summary(ctp_host, ctp_port, username, password):
125
+ logging.basicConfig(
126
+ format=f"%(asctime)s - {socket.gethostname()} - [%(levelname)-8s] %(message)s",
127
+ level='INFO',
128
+ )
129
+ ctpy_client = CTPYclient(ctp_host, ctp_port, username, password, rate_limit=0.2)
130
+ summary = ctpy_client.get_ctp_summary()
131
+ logging.info(f"\n{tabulate.tabulate([s.to_table_row() for s in summary], headers=['pipeline', 'import', 'export', 'quarantines'])}")
132
+
133
+
134
+ @cli.command()
135
+ @click.option('--ctp-host', required=True)
136
+ @click.option('--ctp-port', type=int, default=1180, required=True)
137
+ @click.option('--username', required=True)
138
+ @click.option('--password', required=True)
139
+ @click.option('--pipeline-name', required=True)
140
+ def get_tracker_summary(ctp_host, ctp_port, username, password, pipeline_name):
141
+ logging.basicConfig(
142
+ format=f"%(asctime)s - {socket.gethostname()} - [%(levelname)-8s] %(message)s",
143
+ level='INFO',
144
+ )
145
+
146
+ ctpy_client = CTPYclient(ctp_host, ctp_port, username, password, rate_limit=0.2)
147
+ pipeline = ctpy_client.server.pipelines.get(pipeline_name)
148
+ if pipeline is None:
149
+ raise exceptions.CTPYPipelineNotFound(f"Pipeline {pipeline_name} not found!")
150
+
151
+ trackers_summary = list()
152
+ object_trackers = ctpy_client.find_object_tracker_stages(pipeline)
153
+ for tracker_id, object_tracker in object_trackers:
154
+ object_tracker_contents = ctpy_client.get_object_tracker_patient_info(pipeline_id=pipeline.pipeline_id, stage_id=tracker_id)
155
+
156
+ trackers_summary.append([object_tracker.name, *summarize_object_tracker_content(object_tracker_contents)])
157
+ logging.info(f"\n{tabulate.tabulate(trackers_summary, headers=['name', 'subjects', 'experiments', 'scans', 'instances'])}")