Skip to main content

A small dicom client in python

Project description

Dicom Client V1

PyPi Distribution

API Introduction

There are four core methods that make up DICOM-Client. An interface has been defined to simplify interaction with DicomClient(). The purpose of these methods is to upload, download, and delete DCM files from DICOM Server:

class DicomClientInterface(ABC):
    @abstractmethod
    def __init__(self, base_url, token_cache):
        pass
    @abstractmethod
    def upload_dicom_folder(self, folder_name):
        pass
    @abstractmethod
    def upload_dicom_file(self, file_name):
        pass
    @abstractmethod
    def delete_dicom(self, study_id, series_id=None, instance_id=None):
        pass
    @abstractmethod
    def download_dicom(self, output_folder, study_id, series_id=None, instance_id=None):
        pass
    @abstractmethod
    def get_patient_study_ids(self, patient_id):
        pass

To use:

$ pip install dicom_client
$ export AUTH_CONNECTION_INFO="{'authority': 'https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47', 'client_id': '9cfb139d-d05d-4f5c-a10c-54e0ec338f53', 'client_secret': 'D.oD1q9SHc77syVRD-8vKi8UhbDXYoi~n~', 'oauth_resource': 'api://9cfb139d-d05d-4f5c-a10c-54e0ec338f53'}"
import ast 
import os 

from dicom_client import (
    DicomClient,
    TokenCache,
    dotdict,
    make_get_token_func,
)

base_url = "https://your_dicom_server_base_url.com"

auth = dotdict(ast.literal_eval(os.environ["AUTH_CONNECTION_INFO"])) 

token_cache = TokenCache(make_get_token_func(auth))
dicom_client = DicomClient(base_url, token_cache)

dicom_client.upload_dicom_folder("folder_name")
dicom_client.upload_dicom_file("file_name")
dicom_client.delete_dicom("study_id", "series_id", "instance_id")
dicom_client.download_dicom("output_folder", "study_id", "series_id", "instance_id")
dicom_client.get_patient_study_ids("patient_id")

This script can be used to validate your DICOM server deployment.

See Microsoft Dicom Server here: https://github.com/microsoft/dicom-server

For contributors:

Pre-reqs

  • Provision a dicom server
  • Get credentials for dicom server string values
  • Export them as environment variables for your debugging environment.

Our .vscode/settings.json point to a .env file:

"python.envFile": "${workspaceFolder}/.vscode/dev.env",

Our dev.env file needs these values in this format:

AUTH_CONNECTION_INFO="{'authority': 'https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47', 'client_id': '5bef631a-c4cd-4feb-aaf2-78ff5f7d7347', 'client_secret': 'REPLACE_WITH_YOUR_SECRET_mrpc.lgXK~C0.g146Gu3PcDG.W6Eg0d0I', 'oauth_resource': 'api://REPLACE_WITH_YOUR_RESOURCE_ID5bef631a-c4cd-4feb-aaf2-78ff5f7d7347'}"

Running Tests

Complete the pre-reqs and set the AUTH_CONNECTION_INFO environment variable, then:

$ git clone our_git_url
$ python3 -m venv .venv
$ pip install -r requirements.txt 
$ pytest tests

Make sure you've followed the prerequisites for running the tests locally and validated your dicom server host and exported the correct credentials. See README.md for more details or raise an issue for DICOM server support.

Unit tests

To run most of the unit tests (optionally with code coverage reporting), simply run:

$ pytest tests/unit [--cov=handler --cov-report=html:htmlcov]

Please see conftest.py for more information on these test parameters as they can be found with environment variables instead of arguments for development environments.

Pylint

Pylint provides static code analysis for python and uses our ./.pylintrc file for managing the configuration of the linter. We run pylint in our integration tests to ensure python coding standards. See more info about pylint here.

To run pylint locally:

pylint handler --output-format=colorized --rcfile=".pylintrc"

Formatting with Black

Black is an auto-formatting tool and checker for python that provides further code analysis, it to is run in our integration tests and is helpful to run locally to maintain code clarity and conform to team standards. More info can be found here.

To run black locally:

black --check --line-length 100 .
black --line-length 100 .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dicom-client-python-0.2.1.dev785.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file dicom-client-python-0.2.1.dev785.tar.gz.

File metadata

  • Download URL: dicom-client-python-0.2.1.dev785.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for dicom-client-python-0.2.1.dev785.tar.gz
Algorithm Hash digest
SHA256 69f3a761e97aa87699287e18d763d3a4e3ed025b9ced693035c93fce759be0a0
MD5 e251288f72b5d5e4f1acfb1e76ac50f3
BLAKE2b-256 7e18eb101aa4f2c86dc48cfe76501b2c1aa903732bf18c21e604c1600a915ccd

See more details on using hashes here.

Provenance

File details

Details for the file dicom_client_python-0.2.1.dev785-py3-none-any.whl.

File metadata

  • Download URL: dicom_client_python-0.2.1.dev785-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for dicom_client_python-0.2.1.dev785-py3-none-any.whl
Algorithm Hash digest
SHA256 fabc68038269148dbfb5c3d714a638886f33ce0e23db56361c799c19da09c9c0
MD5 2c2fb8e4e13f05acb222763f3912b046
BLAKE2b-256 653cdf8a1bec1168f0507c7f13b5c9e8a761e05d9895517aa37b62ee42867f65

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page