Skip to content

Commit

Permalink
Refactoring for a cleaner api interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gacou54 committed Aug 30, 2023
1 parent 29cb4c7 commit 93713f3
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 33 deletions.
13 changes: 8 additions & 5 deletions pyorthanc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from . import errors, util
from ._filtering import build_patient_forest, find, trim_patients
from ._find import find_instances, find_patients, find_series, find_studies, query_orthanc
from ._modality import Modality, RemoteModality
from ._resources import Instance, Patient, Series, Study
from .async_client import AsyncOrthanc
from .client import Orthanc
from .filtering import build_patient_forest, find, trim_patients
from .find import find_instances, find_patients, find_series, find_studies, query_orthanc
from .remote import RemoteModality
from .resources import Instance, Patient, Series, Study
from .retrieve import retrieve_and_write_instance, retrieve_and_write_patient, retrieve_and_write_patients, \
retrieve_and_write_series, retrieve_and_write_study


__all__ = [
'AsyncOrthanc',
'Orthanc',
'Modality',
'RemoteModality',
'Patient',
'Study',
Expand All @@ -29,4 +30,6 @@
'retrieve_and_write_study',
'retrieve_and_write_series',
'retrieve_and_write_instance',
'util',
'errors',
]
8 changes: 4 additions & 4 deletions pyorthanc/filtering.py → pyorthanc/_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from .async_client import AsyncOrthanc
from .client import Orthanc
from .resources.instance import Instance
from .resources.patient import Patient
from .resources.series import Series
from .resources.study import Study
from ._resources.instance import Instance
from ._resources.patient import Patient
from ._resources.series import Series
from ._resources.study import Study
from .util import async_to_sync


Expand Down
10 changes: 5 additions & 5 deletions pyorthanc/find.py → pyorthanc/_find.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Dict, List, Union

from .client import Orthanc
from .resources.instance import Instance
from .resources.patient import Patient
from .resources.resource import Resource
from .resources.series import Series
from .resources.study import Study
from ._resources.instance import Instance
from ._resources.patient import Patient
from ._resources.resource import Resource
from ._resources.series import Series
from ._resources.study import Study

DEFAULT_RESOURCES_LIMIT = 1_000

Expand Down
20 changes: 10 additions & 10 deletions pyorthanc/remote.py → pyorthanc/_modality.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from .client import Orthanc


class RemoteModality:
"""Wrapper around Orthanc API when dealing with a (remote) modality.
"""
class Modality:
"""Wrapper around Orthanc API when dealing with a modality."""

def __init__(self, client: Orthanc, modality: str) -> None:
"""Constructor
Expand All @@ -23,7 +22,7 @@ def __init__(self, client: Orthanc, modality: str) -> None:
self.modality = modality

def echo(self) -> bool:
"""C-Echo to remote modality
"""C-Echo to modality
Returns
-------
Expand Down Expand Up @@ -60,12 +59,12 @@ def query(self, data: Dict) -> Dict:
... }
... }
>>> remote_modality = RemoteModality(
>>> modality = Modality(
... client=Orthanc('http://localhost:8042'),
... modality='sample'
... )
>>> remote_modality.query(data)
>>> modality.query(data)
"""
return dict(self.client.post_modalities_id_query(self.modality, json=data))

Expand All @@ -88,13 +87,13 @@ def move(self, query_identifier: str, cmove_data: Dict) -> Dict:
Examples
--------
>>> remote_modality = RemoteModality(Orthanc('http://localhost:8042'), 'modality')
>>> query_id = remote_modality.query(
>>> modality = Modality(Orthanc('http://localhost:8042'), 'modality')
>>> query_id = modality.query(
... data={'Level': 'Series',
... 'Query': {'PatientID': '',
... 'Modality':'SR'}})
>>> remote_modality.move(
>>> modality.move(
... query_identifier=query_id['ID'],
... cmove_data={'TargetAet': 'TARGETAET'}
... )
Expand All @@ -103,7 +102,7 @@ def move(self, query_identifier: str, cmove_data: Dict) -> Dict:
return dict(self.client.post_queries_id_retrieve(query_identifier, json=cmove_data))

def store(self, instance_or_series_id: str) -> Dict:
"""Store series or instance to remote modality.
"""Store series or instance to modality.
Parameters
----------
Expand All @@ -130,3 +129,4 @@ def get_query_answers(self) -> Dict:
return answers


RemoteModality = Modality
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions pyorthanc/retrieve.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from typing import List

from .resources.instance import Instance
from .resources.patient import Patient
from .resources.series import Series
from .resources.study import Study
from ._resources.instance import Instance
from ._resources.patient import Patient
from ._resources.series import Series
from ._resources.study import Study


def retrieve_and_write_patients(patients: List[Patient], path: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from pyorthanc import AsyncOrthanc, Instance, Orthanc, Patient, RemoteModality, Series, Study
from pyorthanc import AsyncOrthanc, Instance, Modality, Orthanc, Patient, Series, Study
from .data import a_patient, a_series, a_study, an_instance
from .setup_server import ORTHANC_1, ORTHANC_2, add_modality, clear_data, setup_data

Expand Down Expand Up @@ -68,7 +68,7 @@ def modality(client, second_client):
add_modality(ORTHANC_1, ORTHANC_2.AeT, 'orthanc2', 4242)
add_modality(ORTHANC_2, ORTHANC_1.AeT, 'orthanc1', 4242)

return RemoteModality(client, ORTHANC_2.AeT)
return Modality(client, ORTHANC_2.AeT)


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/test_filtering.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from pyorthanc import Instance, Patient, Series, Study, filtering
from pyorthanc import Instance, Patient, Series, Study, find
from pyorthanc.util import make_datetime_from_dicom_date
from tests.data import a_patient, a_series, a_study, an_instance

Expand Down Expand Up @@ -29,7 +29,7 @@
])
def test_find(client_fixture, patient_filter, study_filter, series_filter, instance_filter, expected_nbr_of_patient,
expected_nbr_of_series, request):
patients = filtering.find(
patients = find(
orthanc=request.getfixturevalue(client_fixture),
patient_filter=patient_filter,
study_filter=study_filter,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_find.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from pyorthanc import find_instances, find_patients, find_series, find_studies, query_orthanc
from pyorthanc.find import DEFAULT_RESOURCES_LIMIT
from pyorthanc._find import DEFAULT_RESOURCES_LIMIT
from .conftest import LABEL_INSTANCE, LABEL_PATIENT, LABEL_SERIES, LABEL_STUDY
from .data import a_patient, a_series, a_study, an_instance

Expand Down
File renamed without changes.

0 comments on commit 93713f3

Please sign in to comment.