SendCFindRequest Example for C#

//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 “int”
private void TestSendCFindRequest ( )
{
   const string UID_STUDY_ROOT_QUERY_FIND = "1.2.840.10008.5.1.4.1.2.2.1";   // Study Root Query/Retrieve Information Model - FIND
   int hPDU = 0;
   int nID = 0;
   bool b = false;
   short nRet = 0;
   short nVR = 0;
   string szUID = null;
   int x = 0;

   //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)
   {
      nRet = LEADDICOM1.FindUID(szUID);
      if (nRet == 0)
         MessageBox.Show("Abstract Syntax, " + LEADDICOM1.get_CurrentUID().Name + ", Not Supported by Association!");
      else
         MessageBox.Show("Abstract Syntax, " + szUID + ", Not Supported by Association!");
      return;
   }

   //create a find attribute data set
   LEADDICOM2.InitDS((int)LTDICLib.DicomClassConstants.DICOM_CLASS_UNKNOWN, 0);
   LEADDICOM2.ResetDS();

   //add the required fields for this seach
   LEADDICOM2.FindTag((int)   LTDICLib.DicomDataSetTagConstants1.TAG_QUERY_RETRIEVE_LEVEL);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants1.TAG_QUERY_RETRIEVE_LEVEL, nVR, false, 0);
   LEADDICOM2.StringValueCount = 1;
   LEADDICOM2.set_StringValues(0,"STUDY");   //we are searching at the study level
   LEADDICOM2.SetStringValue(1);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_DATE);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_DATE, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_TIME);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_TIME, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants1.TAG_ACCESSION_NUMBER);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants1.TAG_ACCESSION_NUMBER, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_NAME);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_NAME, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_ID);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_ID, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants5.TAG_STUDY_ID);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants5.TAG_STUDY_ID, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants5.TAG_STUDY_INSTANCE_UID);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants5.TAG_STUDY_INSTANCE_UID, nVR, false, 0);
   //optional tags LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_DESCRIPTION);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants1.TAG_STUDY_DESCRIPTION, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_BIRTH_DATE);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_BIRTH_DATE, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_SEX);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_SEX, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants2.TAG_OTHER_PATIENT_IDS);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants2.TAG_OTHER_PATIENT_IDS, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_BIRTH_DATE);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants2.TAG_ADDITIONAL_PATIENT_HISTORY);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants2.TAG_ADDITIONAL_PATIENT_HISTORY, nVR, false, 0);
   LEADDICOM2.FindTag((int)LTDICLib.DicomDataSetTagConstants5.TAG_NUMBER_OF_STUDY_RELATED_INSTANCES);
   nVR = LEADDICOM2.get_CurrentTag().VR;
   LEADDICOM2.InsertElement(false, (int)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, (short)nID, 1, szUID, (short)LTDICLib.DicomCommandSetMessagePriorities.COMMAND_PRIORITY_MEDIUM, LEADDICOM2.hDicomDS);
}