NetReceiveNGetRequest Example for VB.NET

'LEADDICOMNet1 is a predefined LEADDicomNet object
'LEADDICOM1 is a DICOM Dataset defined outside this method
'LEADDICOM2 is a DICOM Dataset defined outside this method
'This example uses the predefined variable "TreeView1" of type "TreeView" from ".NET Framework".
Private Sub LEADDICOMNet1_NetReceiveNGetRequest(ByVal hNet As Integer, ByVal nPresentationID As Short, ByVal nMessageID As Short, ByVal pszClass As String, ByVal pszInstance As String) Handles LEADDICOMNet1.NetReceiveNGetRequest
   Dim nRet As Short
   Dim NewNode As System.Windows.Forms.TreeNode
   Dim szReply As String
   Dim szName As String

   NewNode = New System.Windows.Forms.TreeNode("Command Set - " & "N-GET-REQUEST")
   TreeView1.Nodes.Add(NewNode)
   NewNode.EnsureVisible()

   NewNode.Nodes.Add("Presentation ID: " & CStr(nPresentationID))
   NewNode.Nodes.Add("Message ID: " & CStr(nMessageID))
   nRet = LEADDICOM1.FindUID(pszClass)
   If (nRet = 0) Then
      szName = LEADDICOM1.CurrentUID.Name
      NewNode.Nodes.Add("Affected SOP Class: " & szName & " - " & pszClass)
   Else
      NewNode.Nodes.Add("Affected SOP Class: " & pszClass)
   End If
   NewNode.Nodes.Add("Affected SOP Instance: " & pszInstance)

   'this function will fill the values the data set elements in LEADDICOM2.hDicomDS
   nRet = PerformNGETCommand(pszClass, pszInstance)

   If (nRet <> LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS) Then
   nRet = LTDNCLib.DicomCommandStatusConstants.COMMAND_STATUS_NO_SUCH_OBJECT_INSTANCE

   'send a response
   LEADDICOMNet1.SendNGetResponse(hNet, nPresentationID, nMessageID, pszClass, pszInstance, nRet, LEADDICOM2.hDicomDS)
End Sub


'LEADDICOMNet1 is a predefined LEADDicomNet object
'LEADDICOM1 is a DICOM Dataset defined outside this method
'LEADDICOM2 is a DICOM Dataset defined outside this method
Private Function PerformNGETCommand(ByRef pszClass As String, ByRef pszInstance As String) As Short
   Dim nRet As Short
   Dim nTag As Integer
   Dim x As Integer
   Dim nVR As Short
   'this sample simply loads a fixed data set 'here, a server should check the class and instance against
   'all SOP classes it manages, and then fill out hDS from the
   'correctly matching instance, if one is found
   nRet = LEADDICOM1.LoadDS("e:\images\dicom16.dic", 0)
   LEADDICOM2.InitDS(LTDICLib.DicomClassConstants.DICOM_CLASS_UNKNOWN, 0)
   LEADDICOM2.ResetDS()
   If (nRet = 0) Then
      LEADDICOM1.MoveFirstElement(False)
   Else
      PerformNGETCommand = nRet
      Exit Function
   End If

   For x = 0 To LEADDICOMNet1.RequestAttributeCount - 1
      'get each element
      nTag = LEADDICOMNet1.RequestAttributes(x)
      LEADDICOM1.FindTag(nTag)
      nVR = LEADDICOM1.CurrentTag.VR
      nRet = LEADDICOM1.FindFirstElement(nTag, False)
      'in this sample, if we don't find the requested tag, we
      'do not return an empty element!
      If (nRet = 0) Then
         'copy the element value
         LEADDICOM1.GetConvertValue()
         LEADDICOM2.InsertElement(False, nTag, nVR, False, 0)
         LEADDICOM2.StringValueCount = 1
         LEADDICOM2.StringValues(0) = LEADDICOM1.StringValues(0)
         LEADDICOM2.SetConvertValue()
      End If
   Next
   PerformNGETCommand = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS
End Function