GithubHelp home page GithubHelp logo

gacou54 / pyorthanc Goto Github PK

View Code? Open in Web Editor NEW
48.0 48.0 8.0 3.97 MB

Python library that wrap the Orthanc REST API and facilitate the manipulation of data in Orthanc

License: MIT License

Python 99.96% Dockerfile 0.04%

pyorthanc's People

Contributors

gacou54 avatar ylemarechal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyorthanc's Issues

shared-tags in series

It could be interesting to have a property in series for shared tags

For instance :
series = pyorthanc.Series (client=client, resource=resource)
series.shared-tags

that would be equivalent to the call :
/series/{resource}/shared-tags

Question: The behavior of find function

I am wondering about the behavior of find function, will it pull stable and unstable resource ? or just stable ones ?

Definition of stable from Orthanc book:
A DICOM resource (patient, study or series) is referred to as stable if it has not received any new instance for a certain amount of time.

import pydicom throwing "TypeError"

I am trying to work with pyorthanc, but its throwing me a "TypeError" while doing the import.

Python version: 3.8.12
I am using Miniconda3 as my conda distro ([GCC 7.5.0] :: Anaconda, Inc. on linux)

Please let me know if there is something I am doing wrong here.
Screenshot from 2023-09-14 17-40-58

HTTPX Timeout setting not synced w/ Orthanc setting

I'm not sure how many calls this might apply to, but when calling a C-MOVE from a remote modality, the timeout setting in the data dict appears to be just for Orthanc. HTTPX has it's own timeout default of 5s, so if the requested timeout is larger than that and the request does not resolve in 5s, an HTTPX timeout occurs. Using the C-MOVE in the readme as a start:

from pyorthanc import RemoteModality, Orthanc

orthanc = Orthanc('http://localhost:8042', 'username', 'password')

modality = RemoteModality(orthanc, 'modality')

# Query (C-Find) on modality
data = {'Level': 'Study', 'Query': {'PatientID': '*'}}
query_response = modality.query(data=data)

answer = modality.get_query_answers()[query_response['ID']]
print(answer)

# Retrieve (C-Move) results of query on a target modality (AET)
modality.move(query_response['ID'], {'Timeout': 300})   # <-here's the problem

I'm working on a VPN w/ a slow connection, so the move command takes a while.
Without modification, this will always raise an HTTPX timeout, regardless of the timeout setting (since HTTPX is not being passed this setting). It seems like a relatively easy fix; something like:

timeout = cmove_data.get("Timeout", 5)
dict(self.client.post_modalities_id_query(self.modality, json=data, timeout=timeout))

here:

return dict(self.client.post_modalities_id_query(self.modality, json=data))

You'd need to adjust post_modalities_id_query and self._post as well to handle the parameter, but this would at least make HTTPX use the same timeout as requested for Orthanc.

When I adjusted this manually by removing the timeout (by adding timeout=None) the C-MOVE was successful given enough time.

Add easier access to parent resources

Would be nice to have a cleaner way to access to the parent resources. Probably sometime like

series = pyorthanc.Series(...)

study: pyorthanc.Study = series.parent_study
patient: pyorthanc.Patient = series.parent_patient

Processing "large" DICOM datasets - ReadTimeout: timed out error

I am running the latest version of Orthanc (1.12.1) along with pyorthanc 1.11.5 on macOS Ventura 13.5.1 (Apply M2 Pro). I have loaded an fMRI DICOM dataset that contains 73365 DICOM instances and is ~900MB in size. When I try to do a resource modification (anonymization) via pyorthanc, the operation continues to yield a ReadTimeout: timed out error. I have tried setting orthanc.timeout = 20000 but the anonymization process seems to take a very long time and continues to time out. This is what I am using to anonymize:

anonymized_patient = Patient(id, orthanc).anonymize(keep=['PatientName'], replace={'PatientID': 'TheNewPatientID'}, remove=['ReferringPhysicianName'], force=True )

I would expect anonymization to take some time for this size dataset but I'm wondering if there is anything else I can do to have the process complete successfully (i.e. should I use the Async client in this case?). Any help would be greatly appreciated.

Better documentation

PyOrthanc should have a comprehensive ReadTheDocs for users. The actual documentation (README.md) is incomplete and hard to understand.

Raw_response option

This code is working :

if __name__ == '__main__':
    client = pyorthanc.Orthanc('orthanc', timeout=200, return_raw_response=False)
    series = pyorthanc.find_series(client, {'Modality': 'SR'})

But this one is KO :

if __name__ == '__main__':
    client = pyorthanc.Orthanc('orthanc', timeout=200, return_raw_response=True)
    series = pyorthanc.find_series(client, {'Modality': 'SR'})

We get this error

TypeError: object of type 'Response' has no len()

from this line.

When raw_reponse option is enabled, methods using requests are ko when they are waiting for response.content and get response body instead.

A possibility would be to keep raw_response in inner methods and return content (according to return_raw_response option) in higher levels. @gacou54, what do you think ?

Headers parameter in find

Hey, great project!

Could you add a headers parameter to the find function (

def find(orthanc_url: str,
). Headers are allowed in the Orthanc instantiation. We use Orthanc behind a proxy and requires a header. I'd love to use find via the proxy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.