def test_create_roi(): rt_ss = dataset.Dataset() rt_ss.StructureSetROISequence = [] rt_ss.StructureSetROISequence.append(dataset.Dataset()) rt_ss.StructureSetROISequence[0].ReferencedFrameOfReferenceUID = "1.2.3" rt_ss.StructureSetROISequence[0].ROINumber = "1" rt_ss.ROIContourSequence = [] rt_ss.RTROIObservationsSequence = [] roi_name = "NewTestROI" roi_coordinates = [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0] # a closed right triangle image_ds = dataset.Dataset() image_ds.SOPClassUID = "1.2.840.10008.5.1.4.1.1.2" image_ds.SOPInstanceUID = "1.2.3.4.5.6.7.8.9" patient_dict_container = PatientDictContainer() # container has to be initialised with kwargs content for the get/set to not fail for lack of an # "additional_parameters" dict. patient_dict_container.set_initial_values(None, None, None, blah="blah", rois={}) if patient_dict_container.get("rois") is not None: print("rois are present in patient dict container") updated_rtss = create_roi(rt_ss, roi_name, roi_coordinates, image_ds) first_contour = updated_rtss.ROIContourSequence[0].ContourSequence[0] assert (first_contour.ContourImageSequence[0].ReferencedSOPClassUID == image_ds.SOPClassUID) assert (first_contour.ContourGeometricType == "CLOSED_PLANAR") assert (rt_ss.RTROIObservationsSequence[0].RTROIInterpretedType == "ORGAN")
def test_calculate_matrix(): image_ds= dataset.Dataset() image_ds.PixelSpacing = [1,1] image_ds.ImageOrientationPatient=[1,0,0,0,1,0] image_ds.ImagePositionPatient=[0,0,0] image_ds.Rows=4 image_ds.Columns=4 array_x, array_y= calculate_matrix(image_ds) assert( np.all(array_x == np.array([0,1,2,3])) ) assert( np.all(array_y == np.array([0,1,2,3])) )
def test_add_to_roi(): rt_ss = dataset.Dataset() rt_ss.StructureSetROISequence = [] rt_ss.StructureSetROISequence.append(dataset.Dataset()) rt_ss.StructureSetROISequence[0].ReferencedFrameOfReferenceUID = "1.2.3" rt_ss.StructureSetROISequence[0].ROINumber = "1" rt_ss.StructureSetROISequence[0].ROIName = "NewTestROI" rt_ss.ROIContourSequence = [] rt_ss.RTROIObservationsSequence = [] roi_name = "NewTestROI" roi_coordinates = [0, 0, 0, 0, 1, 0, 1, 0, 0] # a right triangle image_ds = dataset.Dataset() image_ds.SOPClassUID = "1.2.840.10008.5.1.4.1.1.2" image_ds.SOPInstanceUID = "1.2.3.4.5.6.7.8.9" patient_dict_container = PatientDictContainer() # container has to be initialised with kwargs content # for the get/set to not fail for lack of an "additional_parameters" dict. patient_dict_container.set_initial_values(None, None, None, blah="blah", rois={}) if patient_dict_container.get("rois") is not None: print("rois are present in patient dict container") updated_rtss = create_roi(rt_ss, roi_name, [{'coords': roi_coordinates, 'ds': image_ds}]) # clearly the above is an opportunity to factor out to a fixture or similar rtss_with_added_roi = add_to_roi(updated_rtss, roi_name, roi_coordinates, image_ds) first_contour = rtss_with_added_roi.ROIContourSequence[0].\ ContourSequence[0] second_contour = rtss_with_added_roi.ROIContourSequence[0].\ ContourSequence[1] assert ( second_contour .ContourImageSequence[0] .ReferencedSOPClassUID == image_ds.SOPClassUID ) assert(first_contour.ContourGeometricType == "OPEN_PLANAR") assert (second_contour.ContourGeometricType == "OPEN_PLANAR")
def test_store_failure(ae_title: ae.AE): def callback(context, ds): assert ctx == context assert ds == _ds return statuses.C_MOVE_UNABLE_TO_PROCESS ctx = PContextDef(1, uids.BASIC_TEXT_SR_STORAGE, ImplicitVRLittleEndian) _ds = dataset.Dataset() ae_title.bus.subscribe(ae.AEChannels.STORE, callback) status = ae_title.on_receive_store(ctx, _ds) assert status.is_failure
def test_find(ae_title: ae.AE): def callback(context, ds): assert ctx == context assert ds == _ds return [(statuses.C_FIND_PENDING, dataset.Dataset()), (statuses.C_FIND_PENDING, dataset.Dataset())] ctx = PContextDef(1, uids.STUDY_ROOT_FIND_SOP_CLASS, ImplicitVRLittleEndian) _ds = dataset.Dataset() ae_title.bus.subscribe(ae.AEChannels.FIND, callback) results = ae_title.on_receive_find(ctx, _ds) for status, ds in results: assert status.is_pending assert ds is not None
def test_c_find_positive(self): test_name = 'Patient^Name^Test' remote_ae = dict(address='127.0.0.1', port=11112, aet='AET2', username='******', password='******') ds = dataset.Dataset() ds.PatientName = test_name ae2 = CFindServerAE(test_name, self, 'AET2', 11112)\ .add_scp(sc.qr_find_scp) with ae2: for result, status in c_find(remote_ae, 'AET1', ds): self.assertEqual(result.PatientName, test_name) self.assertEqual(status, statuses.SUCCESS)
def test_c_find_positive(self): test_name = 'Patient^Name^Test' ae1 = ae.ClientAE('AET1').add_scu(sc.qr_find_scu) ae2 = CFindServerAE(test_name, self, 'AET2', 11112)\ .add_scp(sc.qr_find_scp) with ae2: remote_ae = dict(address='127.0.0.1', port=11112, aet='AET2', username='******', password='******') with ae1.request_association(remote_ae) as assoc: service = assoc.get_scu(sc.PATIENT_ROOT_FIND_SOP_CLASS) req = dataset.Dataset() req.PatientName = test_name for result, status in service(req, 1): self.assertEqual(result.PatientName, test_name) self.assertEqual(status, statuses.SUCCESS)
def test_c_store_positive(self): rq = dataset.Dataset() rq.PatientName = 'Patient^Name^Test' rq.PatientID = 'TestID' rq.StudyInstanceUID = '1.2.3.4.5' rq.SeriesInstanceUID = '1.2.3.4.5.1' rq.SOPInstanceUID = '1.2.3.4.5.1.1' rq.SOPClassUID = sc.BASIC_TEXT_SR_STORAGE ae1 = ae.ClientAE('AET1').add_scu(sc.storage_scu, [sc.BASIC_TEXT_SR_STORAGE]) ae2 = CStoreAE(self, rq, 'AET2', 11112).add_scp(sc.storage_scp) with ae2: remote_ae = dict(address='127.0.0.1', port=11112, aet='AET2') with ae1.request_association(remote_ae) as assoc: service = assoc.get_scu(sc.BASIC_TEXT_SR_STORAGE) status = service(rq, 1) self.assertEqual(status, statuses.SUCCESS)
def test_move(ae_title: ae.AE): def callback(context, ds, destination): assert destination == 'REMOTE_PACS' assert ctx == context assert ds == _ds return [dataset.Dataset(), dataset.Dataset()] ctx = PContextDef(1, uids.STUDY_ROOT_MOVE_SOP_CLASS, ImplicitVRLittleEndian) _ds = dataset.Dataset() _devices = devices.Devices( ae_title.bus, { 'devices': { 'REMOTE_PACS': { 'address': '127.0.0.1', 'port': 11112, 'aet': 'REMOTE_PACS' } } }) ae_title.bus.subscribe(ae.AEChannels.MOVE, callback) results = ae_title.on_receive_move(ctx, _ds, 'REMOTE_PACS') assert len(list(results)) == 2
def callback(context, ds, destination): assert destination == 'REMOTE_PACS' assert ctx == context assert ds == _ds return [dataset.Dataset(), dataset.Dataset()]
def callback(context, ds): assert ctx == context assert ds == _ds return [(statuses.C_FIND_PENDING, dataset.Dataset()), (statuses.C_FIND_PENDING, dataset.Dataset())]
def on_receive_find(self, context, ds): self.test.assertEqual(ds.PatientName, self.test_name) rsp = dataset.Dataset() rsp.PatientName = self.test_name return iter([(rsp, statuses.SUCCESS)])