跳转到主要内容

Orthanc DICOM服务器的REST客户端

项目描述

beren

PyPI version

berenOrthanc(一个开源DICOM服务器)提供了一个REST客户端。

使用优秀的apiron库构建。

安装

使用pip

pip install beren

如何使用

导入客户端并提供服务器详情

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')

# Patient endpoints
orthanc.get_patients()
orthanc.get_patient(id)
...and so on

# Study endpoints
orthanc.get_studies()
orthanc.get_study(id)
...and so on

# Series endpoints
orthanc.get_series()
orthanc.get_one_series(id)
...and so on

# Instance endpoints
orthanc.get_instances()
orthanc.get_instance(id)
...and so on

# Get changes
orthanc.get_changes()

# Find objects by query
query = {'PatientName': 'Jon*'}
orthanc.find(query, level='Patient', expand=False, limit=2)

# Get previous queries
orthanc.get_queries()

有许多其他预配置的端点。

身份验证

许多服务器需要身份验证才能使用它们的API。在定义客户端时简单地提供有效的身份验证对象

from requests.auth import HTTPBasicAuth
auth = HTTPBasicAuth('orthanc', 'orthanc')
orthanc = Orthanc('https://test.server.com', auth=auth)

要覆盖默认身份验证,在调用端点时提供新的身份验证对象

new_auth = HTTPBasicAuth('new_user', 'new_password')
orthanc.get_patients(auth=auth)

高级配置

超时

某些服务器很慢(并且某些方法可能很慢)。例如,请求服务器中的所有实例可能导致在服务器响应之前超时。要修改超时设置,请使用apironTimeout

from apiron import Timeout
t = Timeout(read_timeout=6, connection_timeout=1)   # Modify the timeout

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')
orthanc.get_instances(timeout_spec=t)               # Use new timeout

如果端点很慢,请增加读取超时。为慢速服务器增加连接超时。

禁用证书检查

要禁用TLS证书检查,请使用会话

import requests
session = requests.sessions.Session()       # New session
session.verify = False                      # Disable certificate checking

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')
orthanc.get_patients(session=session)       # Use session

非HTTPS端点

当使用HTTP端点时,客户端将发出警告。医学数据尤其敏感,因此强烈考虑使用HTTPS。

您可以使用warn_insecure参数禁用警告

from beren import Orthanc
orthanc = Orthanc('http://insecure.endpoint.com', warn_insecure=False)

示例

将实例文件保存到本地目录

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')

with open('test_file.dcm', 'wb') as dcm:
    for chunk in orthanc.get_instance_file(<instance_id>):
        dcm.write(chunk)

获取一个系列的存档(DCM文件存档为zip文件)

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')

with open('test.zip', 'wb') as z:
    for chunk in orthanc.get_series_archive(<instance_id>):
        z.write(chunk)

进一步的帮助

未来目标

  • 异步请求
  • 记录每个函数
  • 更好的测试覆盖率

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

beren-0.7.1.tar.gz (26.1 kB 查看哈希值)

上传时间 源代码

构建分发

beren-0.7.1-py3-none-any.whl (29.9 kB 查看哈希值)

上传时间 Python 3

支持