SendCFindRequest 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 "nFileCount" of type "Integer"
Private Sub TestSendCFindRequest ( )
   Const UID_STUDY_ROOT_QUERY_FIND As String = "1.2.840.10008.5.1.4.1.2.2.1"
   ' Study Root Query/Retrieve Information Model - FIND
   Dim hPDU As Integer
   Dim nID As Integer
   Dim b As Boolean
   Dim nRet As Short
   Dim nVR As Short
   Dim szUID As String
   Dim x As Integer
   'this example sends a command that will find all STUDIES on a called AE that
   'supports the Study Root Query/Retrieve Information Model - FIND SOP Class
   'send a Find request to the server
   hPDU = LEADDICOMNet1.GetAssociate(LEADDICOMNet1.hNet)
   szUID = UID_STUDY_ROOT_QUERY_FIND
   nID = LEADDICOMNet1.FindPresentationAbstract (hPDU, szUID)
   If (nID = 0) Then
      nRet = LEADDICOM1.FindUID(szUID)
      If (nRet = 0) Then
         MessageBox.Show("Abstract Syntax, " & LEADDICOM1.CurrentUID.Name & ", Not Supported by Association!")
      Else
         MessageBox.Show("Abstract Syntax, " & szUID & ", Not Supported by Association!")
      End If
      Exit Sub
   End If
   'create a find attribute data set
   LEADDICOM2.InitDS(LTDICLib.DicomClassConstants.DICOM_CLASS_UNKNOWN, 0)
   LEADDICOM2.ResetDS()
   'add the required fields for this seach
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants1.TAG_QUERY_RETRIEVE_LEVEL)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement (False, LTDICLib.DicomDataSetTagConstants1.TAG_QUERY_RETRIEVE_LEVEL, nVR, False, 0)
   LEADDICOM2.StringValueCount = 1
   LEADDICOM2.StringValues(0) = "STUDY"
   'we are searching at the study level
   LEADDICOM2.SetStringValue(1)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_DATE)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_DATE, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_TIME)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_TIME, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants1.TAG_ACCESSION_NUMBER)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants1.TAG_ACCESSION_NUMBER, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_NAME)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_NAME, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_ID)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_ID, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants5.TAG_STUDY_ID)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants5.TAG_STUDY_ID, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants5.TAG_STUDY_INSTANCE_UID)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants5.TAG_STUDY_INSTANCE_UID, nVR, False, 0)
   'optional tags
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_DESCRIPTION)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_DESCRIPTION, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_BIRTH_DATE)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_BIRTH_DATE, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_SEX)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_SEX, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants2.TAG_OTHER_PATIENT_IDS)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants2.TAG_OTHER_PATIENT_IDS, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_BIRTH_DATE)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_BIRTH_DATE, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants2.TAG_ADDITIONAL_PATIENT_HISTORY)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants2.TAG_ADDITIONAL_PATIENT_HISTORY, nVR, False, 0)
   LEADDICOM2.FindTag(LTDICLib.DicomDataSetTagConstants5.TAG_NUMBER_OF_STUDY_RELATED_INSTANCES)
   nVR = LEADDICOM2.CurrentTag.VR
   LEADDICOM2.InsertElement(False, LTDICLib.DicomDataSetTagConstants5.TAG_NUMBER_OF_STUDY_RELATED_INSTANCES, nVR, False, 0)
   'now, send the command set and data set
   'nFileCount is used to track the current CFindRequest responses count.
   nFileCount = 0
   LEADDICOMNet1.SendCFindRequest(LEADDICOMNet1.hNet, nID, 1, szUID, LTDICLib.DicomCommandSetMessagePriorities.COMMAND_PRIORITY_MEDIUM, LEADDICOM2.hDicomDS)
End Sub