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"
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())
def test_parse_study_response(): """Parse CFIND response for STUDY level. This is missing any series or instance info and should yield studies with no series """ qr = DICOMQR(host="host", port=123) parsed = qr.parse_c_find_response( create_c_find_study_response( study_instance_uids=[f"Study{i}" for i in range(1, 10)] ) ) assert len(parsed) == 9 assert len(parsed[0].series) == 0
def test_find_studies(monkeypatch): qr = DICOMQR(host="host", port=123) qr.send_c_find = Mock( return_value=create_c_find_image_response( study_instance_uid="Study1", series_instance_uids=["Series1"], sop_class_uids=[f"Instance{i}" for i in range(1, 10)], ) ) studies = qr.find_studies(query=None) assert len(studies) == 1 assert studies[0].uid == "Study1" assert len(studies[0].series[0].instances) == 9
def test_parse_instance_response(): """Parse CFIND response for IMAGE level. This should yield a full-depth study/series/instance object """ qr = DICOMQR(host="host", port=123) parsed = qr.parse_c_find_response( create_c_find_image_response( study_instance_uid="Study1", series_instance_uids=["Series1"], sop_class_uids=[f"Instance{i}" for i in range(1, 10)], ) ) assert len(parsed) == 1 assert len(parsed[0].series) == 1 assert len(parsed[0].series[0].instances) == 9
def create_image_level_study( study_instance_uid, series_instance_uids: List[str], sop_class_uids: List[str], ) -> Dataset: return DICOMQR.parse_c_find_response( create_c_find_image_response(study_instance_uid, series_instance_uids, sop_class_uids))[0]
def an_image_level_study() -> List[Study]: """A study with series and slice info""" response = create_c_find_image_response( study_instance_uid="Study1", series_instance_uids=["Series1", "Series2"], sop_class_uids=[f"Instance{i}" for i in range(1, 10)], ) return DICOMQR.parse_c_find_response(response)
def another_image_level_series() -> Series: """A study with series and slice info""" response = create_c_find_image_response( study_instance_uid="Study1", series_instance_uids=["Series2"], sop_class_uids=[f"Instance{i}" for i in range(1, 10)], ) study = DICOMQR.parse_c_find_response(response)[0] return study.get("Series2")
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 = IMPAXDataCenter(self.wado_url).log_in(wado_user, wado_pass) return Trolley( wado=Wado(session, self.wado_url), searcher=DICOMQR(host=host, port=port, aet=aet, aec=aec), )
def a_study_level_study(): """Study witnout slice info""" return DICOMQR.parse_c_find_response( create_c_find_study_response(study_instance_uids=["Study2"]))
PORT # Port to use on host AET # Application Entity Title - What to call yourself AEC # Application Entity Called - The name of the server you are calling Please set these before running this example """ from datetime import datetime from os import environ 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",