Esempio n. 1
0
def test_qr_query_exclude_default_params():
    """If a parameter has not been explicitly given to a DICOMQuery, it should not
    pollute any DICOM query so should be ignored
    """
    query = DICOMQuery(StudyInstanceUID="123")
    assert (
        query.PatientName == ""
    )  # not passed in init, so default empty value
    assert (
        "StudyInstanceUID" in query.as_dataset()
    )  # SID was passed so should exist
    assert "PatientName" not in query.as_dataset()  # not passed, so ignored
Esempio n. 2
0
def test_qr_query():
    query = DICOMQuery(
        StudyInstanceUID="123",
        QueryRetrieveLevel=QueryLevels.SERIES,
        minStudyDate=datetime(year=2020, month=3, day=1),
    )
    ds = query.as_dataset()
    assert ds.StudyInstanceUID == "123"
    assert ds.StudyDate == "20200301-"
    assert ds.QueryRetrieveLevel == QueryLevels.SERIES
    assert (
        ds.SeriesInstanceUID == ""
    )  # should be added as default for QueryLevel
Esempio n. 3
0
def test_qr_query_do_not_overwrite_parameters():
    """If a parameter is passed in init and also in IncludeFields, don't overwrite
    the init value
    """
    query = DICOMQuery(
        StudyInstanceUID="123",
        ProtocolName="foo",
        includeFields=["StudyInstanceUID", "ProtocolName"],
    )
    assert query.StudyInstanceUID == "123"
    assert query.ProtocolName == "foo"
    ds = query.as_dataset()
    assert ds.StudyInstanceUID == "123"
    assert ds.ProtocolName == "foo"
Esempio n. 4
0
def test_send_cfind(a_mock_ae_associate, monkeypatch):
    monkeypatch.setattr(
        "dicomtrolley.dicom_qr.AE.associate",
        Mock(return_value=a_mock_ae_associate),
    )
    qr = DICOMQR(host="host", port=123)
    results = qr.send_c_find(query=DICOMQuery())
    assert len(results) == 2
    assert results[0].PatientName == "patient"
Esempio n. 5
0
def test_send_cfind_no_connection(a_mock_ae_associate, monkeypatch):
    a_mock_ae_associate.is_established = False
    monkeypatch.setattr(
        "dicomtrolley.dicom_qr.AE.associate",
        Mock(return_value=a_mock_ae_associate),
    )

    qr = DICOMQR(host="host", port=123)
    with pytest.raises(DICOMTrolleyError):
        qr.send_c_find(query=DICOMQuery())
Esempio n. 6
0
def test_qr_query_exceptions(parameters):
    with pytest.raises(ValueError):
        DICOMQuery(**parameters)
Esempio n. 7
0
def test_qr_query_allowed_parameters(parameters):
    """These should work without problems"""
    assert DICOMQuery(**parameters).as_dataset()
Esempio n. 8
0
from dicomtrolley.dicom_qr import DICOMQR, DICOMQuery, QueryRetrieveLevels

print("Setting up DICOM query-retrieve")
dicom_qr = DICOMQR(
    host=environ["HOST"],
    port=int(environ["PORT"]),
    aet=environ["AET"],
    aec=environ["AEC"],
)

print("Perform a search")
studies = dicom_qr.find_studies(
    DICOMQuery(
        PatientName="BAL*",
        ProtocolName="Thorax",
        minStudyDate=datetime(year=2015, month=3, day=1),
        maxStudyDate=datetime(year=2015, month=4, day=1),
        includeFields=[
            "PatientBirthDate",
            "SOPClassesInStudy",
            "Modality",
            "StudyDescription",
            "SeriesDescription",
            "ProtocolName",
        ],
        QueryRetrieveLevel=QueryRetrieveLevels.SERIES,
    ))

print(f"Found {len(studies)} studies")