Skip to content

dicomtrolley.servers

Models VNA server specifics. Mainly log-in procedures

IMPAXDataCenter

WADO Login for AGFA IMPAX Data Center 3.1.1

Source code in dicomtrolley/servers.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
class IMPAXDataCenter:
    """WADO Login for AGFA IMPAX Data Center 3.1.1"""

    def __init__(self, wado_url):
        """

        Parameters
        ----------
        wado_url: str
            Full url of WADO endpoint login method, including https:// and port
        """
        self.wado_url = wado_url

    def log_in(self, user, password):
        """Get a logged in session for WADO on this server

        Parameters
        ----------
        user: str
            username
        password: str
            password to log in with

        Returns
        -------
        requests.Session
            A logged in session on IMPAX

        Raises
        ------
        DICOMTrolleyError
            If login fails for some reason

        """
        session = requests.Session()

        # AGFA IMPAX WADO login is stateful and strange.
        # A better method might be available. However, this one works.
        try:
            session.get(
                self.wado_url
            )  # this is required to make the next GET work..
            response = session.get(
                f"{self.wado_url}/j_security_check"
                f"?j_username={user}&j_password={password}"
            )
        except requests.exceptions.ConnectionError as e:
            raise DICOMTrolleyError(
                f"Error logging in to {self.wado_url}: {e}"
            ) from e

        if (
            "Login Failed!" in response.text
        ):  # login fail status_code is 200 OK..
            raise DICOMTrolleyError(
                f"Logging in to {self.wado_url} failed. "
                f"Invalid Credentials?"
            )
        else:
            return (
                session  # login worked. status_code is now 403 (forbidden)..
            )

    def get_dicom_qr_trolley(
        self,
        wado_user,
        wado_pass,
        host,
        port,
        aet="DICOMTROLLEY",
        aec="ANY-SCP",
    ) -> Trolley:
        """Log in to WADO and create a Trolley with wado and DICOM-QR

        Notes
        -----
        DICOM-QR credentials will only be verified during the first trolley find
        command.

        Parameters
        ----------
        wado_user: str
            User to log in to wado
        wado_pass: str
            Password for wado
        host: str
            Hostname for DICOM-QR
        port: int
            port for DICOM-QR
        aet: str, optional
            Application Entity Title - Name of the calling entity (this class).
            Defaults to 'DICOMTROLLEY'
        aec: str, optional
            Application Entity Called - The name of the server you are calling.
            Defaults to 'ANY-SCP'
        Returns
        -------

        """
        session = self.log_in(wado_user, wado_pass)
        return Trolley(
            downloader=WadoURI(session, self.wado_url),
            searcher=DICOMQR(host=host, port=port, aet=aet, aec=aec),
        )

__init__(wado_url)

Parameters

wado_url: str Full url of WADO endpoint login method, including https:// and port

Source code in dicomtrolley/servers.py
101
102
103
104
105
106
107
108
109
def __init__(self, wado_url):
    """

    Parameters
    ----------
    wado_url: str
        Full url of WADO endpoint login method, including https:// and port
    """
    self.wado_url = wado_url

get_dicom_qr_trolley(wado_user, wado_pass, host, port, aet='DICOMTROLLEY', aec='ANY-SCP')

Log in to WADO and create a Trolley with wado and DICOM-QR

Notes

DICOM-QR credentials will only be verified during the first trolley find command.

Parameters

wado_user: str User to log in to wado wado_pass: str Password for wado host: str Hostname for DICOM-QR port: int port for DICOM-QR aet: str, optional Application Entity Title - Name of the calling entity (this class). Defaults to 'DICOMTROLLEY' aec: str, optional Application Entity Called - The name of the server you are calling. Defaults to 'ANY-SCP' Returns


Source code in dicomtrolley/servers.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def get_dicom_qr_trolley(
    self,
    wado_user,
    wado_pass,
    host,
    port,
    aet="DICOMTROLLEY",
    aec="ANY-SCP",
) -> Trolley:
    """Log in to WADO and create a Trolley with wado and DICOM-QR

    Notes
    -----
    DICOM-QR credentials will only be verified during the first trolley find
    command.

    Parameters
    ----------
    wado_user: str
        User to log in to wado
    wado_pass: str
        Password for wado
    host: str
        Hostname for DICOM-QR
    port: int
        port for DICOM-QR
    aet: str, optional
        Application Entity Title - Name of the calling entity (this class).
        Defaults to 'DICOMTROLLEY'
    aec: str, optional
        Application Entity Called - The name of the server you are calling.
        Defaults to 'ANY-SCP'
    Returns
    -------

    """
    session = self.log_in(wado_user, wado_pass)
    return Trolley(
        downloader=WadoURI(session, self.wado_url),
        searcher=DICOMQR(host=host, port=port, aet=aet, aec=aec),
    )

log_in(user, password)

Get a logged in session for WADO on this server

Parameters

user: str username password: str password to log in with

Returns

requests.Session A logged in session on IMPAX

Raises

DICOMTrolleyError If login fails for some reason

Source code in dicomtrolley/servers.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def log_in(self, user, password):
    """Get a logged in session for WADO on this server

    Parameters
    ----------
    user: str
        username
    password: str
        password to log in with

    Returns
    -------
    requests.Session
        A logged in session on IMPAX

    Raises
    ------
    DICOMTrolleyError
        If login fails for some reason

    """
    session = requests.Session()

    # AGFA IMPAX WADO login is stateful and strange.
    # A better method might be available. However, this one works.
    try:
        session.get(
            self.wado_url
        )  # this is required to make the next GET work..
        response = session.get(
            f"{self.wado_url}/j_security_check"
            f"?j_username={user}&j_password={password}"
        )
    except requests.exceptions.ConnectionError as e:
        raise DICOMTrolleyError(
            f"Error logging in to {self.wado_url}: {e}"
        ) from e

    if (
        "Login Failed!" in response.text
    ):  # login fail status_code is 200 OK..
        raise DICOMTrolleyError(
            f"Logging in to {self.wado_url} failed. "
            f"Invalid Credentials?"
        )
    else:
        return (
            session  # login worked. status_code is now 403 (forbidden)..
        )

VitreaConnection

A server running Vitrea Connection 8.2.0.1

Source code in dicomtrolley/servers.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class VitreaConnection:
    """A server running Vitrea Connection 8.2.0.1"""

    def __init__(self, login_url):
        """

        Parameters
        ----------
        login_url: str
            Full url of login method, including https://
        """
        DeprecationWarning(
            "VitreaConnection will be removed in future versions. "
            "Use dicomtrolley.auth.VitreaAuth instead"
        )
        self.login_url = login_url

    def log_in(self, user, password, realm):
        """
        Parameters
        ----------
        user: str
            username
        password: str
            password to log in with
        realm: str
           realm to log in to

        Returns
        -------
        requests.Session
            A logged in session on the VNA

        Raises
        ------
        DICOMTrolleyError
            If login fails for some reason

        """
        session = requests.Session()
        response = session.post(
            self.login_url,
            headers={
                "X-Userid": user,
                "X-Password": password,
                "X-Realm": realm,
            },
        )
        if response.status_code == 401:
            raise DICOMTrolleyError(
                f"login failed. {response.status_code}:{response.reason}"
            )

        return session

    def get_mint_trolley(
        self, user, password, realm, wado_url, mint_url
    ) -> Trolley:
        """Create a logged in trolley with wado and mint

        Parameters
        ----------
        user: str
            User to log in with
        password:
            Password for user
        realm: str
            realm to log in to
        wado_url: str
            WADO endpoint, including http(s)://  and port
        mint_url
            MINT endpoint, including http(s)://  and port

        Returns
        -------
        Trolley
            logged in trolley with wado and mint

        """
        session = self.log_in(user=user, password=password, realm=realm)
        return Trolley(
            downloader=WadoURI(session=session, url=wado_url),
            searcher=Mint(session=session, url=mint_url),
        )

__init__(login_url)

Parameters

login_url: str Full url of login method, including https://

Source code in dicomtrolley/servers.py
15
16
17
18
19
20
21
22
23
24
25
26
27
def __init__(self, login_url):
    """

    Parameters
    ----------
    login_url: str
        Full url of login method, including https://
    """
    DeprecationWarning(
        "VitreaConnection will be removed in future versions. "
        "Use dicomtrolley.auth.VitreaAuth instead"
    )
    self.login_url = login_url

get_mint_trolley(user, password, realm, wado_url, mint_url)

Create a logged in trolley with wado and mint

Parameters

user: str User to log in with password: Password for user realm: str realm to log in to wado_url: str WADO endpoint, including http(s):// and port mint_url MINT endpoint, including http(s):// and port

Returns

Trolley logged in trolley with wado and mint

Source code in dicomtrolley/servers.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def get_mint_trolley(
    self, user, password, realm, wado_url, mint_url
) -> Trolley:
    """Create a logged in trolley with wado and mint

    Parameters
    ----------
    user: str
        User to log in with
    password:
        Password for user
    realm: str
        realm to log in to
    wado_url: str
        WADO endpoint, including http(s)://  and port
    mint_url
        MINT endpoint, including http(s)://  and port

    Returns
    -------
    Trolley
        logged in trolley with wado and mint

    """
    session = self.log_in(user=user, password=password, realm=realm)
    return Trolley(
        downloader=WadoURI(session=session, url=wado_url),
        searcher=Mint(session=session, url=mint_url),
    )

log_in(user, password, realm)

Parameters

user: str username password: str password to log in with realm: str realm to log in to

Returns

requests.Session A logged in session on the VNA

Raises

DICOMTrolleyError If login fails for some reason

Source code in dicomtrolley/servers.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def log_in(self, user, password, realm):
    """
    Parameters
    ----------
    user: str
        username
    password: str
        password to log in with
    realm: str
       realm to log in to

    Returns
    -------
    requests.Session
        A logged in session on the VNA

    Raises
    ------
    DICOMTrolleyError
        If login fails for some reason

    """
    session = requests.Session()
    response = session.post(
        self.login_url,
        headers={
            "X-Userid": user,
            "X-Password": password,
            "X-Realm": realm,
        },
    )
    if response.status_code == 401:
        raise DICOMTrolleyError(
            f"login failed. {response.status_code}:{response.reason}"
        )

    return session