gacou54 / pyorthanc

Python library that wrap the Orthanc REST API and facilitate the manipulation of data in Orthanc
MIT License
49 stars 10 forks source link

Question: The behavior of find function #22

Closed OmarAbuhassan closed 1 year ago

OmarAbuhassan commented 1 year ago

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.

gacou54 commented 1 year ago

Hi!

The find function will index all resources (patients, studies, series and instances) that fit the filters (the (patient/study/series/instance)_filter parameters) that are in the Orthanc server, independently of if they are stable or unstable. Note that this makes find a function that can be long to process, especially on large Orthanc servers or when you parse/apply a filter on CT instances.

As for the IsStable criteria, you can still parse with it since it is in the DICOM Ressource main information. With find, for example:

import pyorthanc

orthanc = pyorthanc.Orthanc('url', 'username', 'password')

def is_patient_stable(patient: pyorthanc.Patient) -> bool:
    return patient.get_main_information()['IsStable']

stable_patients = pyorthanc.find(o, patient_filter=is_patient_stable)

# You can now check the data
stable_patient = stable_patients[0]

# Because the find method has been used, all the 
# child studies/series/instances have been indexed
a_study = stable_patient.studies[0] 
a_series = a_study.series[0]
instance = a_series.instances[0]
pydicom_dataset = instance.get_pydicom()

If you don't want to parse all the DICOM level, but only the studies for example, you can still do something like that

from pyorthanc import Study, Orthanc

orthanc = Orthanc(...)

def is_study_stable(study: Study) -> bool:
    return study.get_main_information()['IsStable']

stable_studies = [Study(id_, orthanc) for id_ in orthanc.get_studies() if is_study_stable(Study(id_, orthanc))]

Hope that helps! I plan to do much documentation soon, that's the kind of thing I would add.

Don't hesitate to comment back if you still have questions.