def test_conversion_rq(self): """ Check conversion to a -RQ PDU produces the correct output """ primitive = C_GET() primitive.MessageID = 7 primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' primitive.Priority = 0x02 ref_identifier = Dataset() ref_identifier.PatientID = '*' ref_identifier.QueryRetrieveLevel = "PATIENT" primitive.Identifier = BytesIO(encode(ref_identifier, True, True)) dimse_msg = C_GET_RQ() dimse_msg.primitive_to_message(primitive) pdvs = [] for fragment in dimse_msg.encode_msg(1, 16382): pdvs.append(fragment) cs_pdv = pdvs[0].presentation_data_value_list[0][1] ds_pdv = pdvs[1].presentation_data_value_list[0][1] assert cs_pdv == c_get_rq_cmd assert ds_pdv == c_get_rq_ds
def test_message_to_primitive_c_get(self): """Test converting C_GET_RQ to C_GET primitive.""" msg = C_GET_RQ() for data in [c_get_rq_cmd, c_get_rq_ds]: p_data = P_DATA() p_data.presentation_data_value_list.append([0, data]) msg.decode_msg(p_data) primitive = msg.message_to_primitive() assert isinstance(primitive, C_GET) assert isinstance(primitive.Identifier, BytesIO) assert primitive.AffectedSOPClassUID == UID( "1.2.840.10008.5.1.4.1.1.2") assert primitive.Priority == 2 assert primitive.MessageID == 7 ds = decode(primitive.Identifier, True, True) assert ds.QueryRetrieveLevel == "PATIENT" assert ds.PatientID == "*" msg = C_GET_RSP() for data in [c_get_rsp_cmd, c_get_rsp_ds]: p_data = P_DATA() p_data.presentation_data_value_list.append([0, data]) msg.decode_msg(p_data) primitive = msg.message_to_primitive() assert isinstance(primitive, C_GET) assert isinstance(primitive.Identifier, BytesIO) assert primitive.AffectedSOPClassUID == UID( "1.2.840.10008.5.1.4.1.1.2") assert primitive.Status == 65280 assert primitive.MessageIDBeingRespondedTo == 5 assert primitive.NumberOfRemainingSuboperations == 3 assert primitive.NumberOfCompletedSuboperations == 1 assert primitive.NumberOfFailedSuboperations == 2 assert primitive.NumberOfWarningSuboperations == 4 ds = decode(primitive.Identifier, True, True) assert ds.QueryRetrieveLevel == "PATIENT" assert ds.PatientID == "*"
def test_callback_receive_c_get(self): """Check callback for receiving DIMSE C-GET messages.""" # C-GET-RQ primitive = C_GET() primitive.MessageID = 7 primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' primitive.AffectedSOPInstanceUID = '1.2.392.200036.9116.2.6.1.48.' \ '1215709044.1459316254.522441' primitive.Priority = 0x02 primitive.MoveOriginatorApplicationEntityTitle = 'UNITTEST_SCP' primitive.MoveOriginatorMessageID = 3 primitive.Identifier = BytesIO() # No dataset msg = C_GET_RQ() msg.primitive_to_message(primitive) self.dimse.debug_receive_c_get_rq(msg) # Dataset ref_ds = Dataset() ref_ds.PatientID = 'Test1101' ref_ds.PatientName = "Tube HeNe" primitive.Identifier = BytesIO(encode(ref_ds, True, True)) msg = C_GET_RQ() msg.primitive_to_message(primitive) # Dataset self.dimse.debug_receive_c_get_rq(msg) # C-GET-RSP primitive = C_GET() primitive.MessageIDBeingRespondedTo = 7 primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' primitive.AffectedSOPInstanceUID = '1.2.392.200036.9116.2.6.1.48.' \ '1215709044.1459316254.522441' primitive.MoveOriginatorApplicationEntityTitle = 'UNITTEST_SCP' primitive.MoveOriginatorMessageID = 3 primitive.Identifier = BytesIO() primitive.NumberOfCompletedSuboperations = 1 primitive.NumberOfWarningSuboperations = 3 primitive.NumberOfFailedSuboperations = 4 # No dataset, remaining subops primitive.Status = 0x0000 # Must be for pending msg = C_GET_RSP() msg.primitive_to_message(primitive) self.dimse.debug_receive_c_get_rsp(msg) # Dataset ref_ds = Dataset() ref_ds.PatientID = 'Test1101' ref_ds.PatientName = "Tube HeNe" primitive.Identifier = BytesIO(encode(ref_ds, True, True)) primitive.NumberOfRemainingSuboperations = 2 msg = C_GET_RSP() msg.primitive_to_message(primitive) # Dataset self.dimse.debug_receive_c_get_rsp(msg) # C-CANCEL-GET-RQ self.dimse.debug_receive_c_cancel_rq(msg)