Esempio n. 1
0
 static String stampa(DCXOBJ currObj, int elementNumber)
 {
     try {
         currElem = currObj.getElementByTag(elementNumber);
     } catch (Exception e) { Console.WriteLine(e.Message); } //Tag Not Found
     return(elementName(elementNumber) + ": " + currElem.Value + " | ");
 }
Esempio n. 2
0
 public override void serverConnection(DCXREQ req, Association serverino, DCXOBJ query)
 {
     queryResults = req.Query(serverino.myAET,
                              serverino.TargetAET,
                              serverino.TargetIp,
                              serverino.TargetPort,
                              "1.2.840.10008.5.1.4.1.2.1.1",
                              query);
 }
Esempio n. 3
0
 public override void serverConnection(DCXREQ req, Association serverino, DCXOBJ moveQuery)
 {
     req.MoveAndStore(
         serverino.myAET,      // The AE title that issue the C-MOVE
         serverino.TargetAET,  // The PACS AE title
         serverino.TargetIp,   // The PACS IP address
         serverino.TargetPort, // The PACS listener port
         serverino.myAET,      // The AE title to send the
         moveQuery,            // The matching criteria
         serverino.myPort,     // The port to receive the results
         accepter);            // The accepter to handle the results
 }
Esempio n. 4
0
        // todo after server answered:

        /*
         * // if query result object not empty
         * public bool tryReadResults()
         * {
         *  bool ret = false;
         *  try { queryResults.Get(); ret = true; }
         *  catch (Exception) { errorMessage("Query effettuata, ma il risultato della query è vuoto"); }
         *  return ret;
         * }
         *  // then save results into map
         * public void saveResults()
         * {
         *  DCXOBJ querySingleResult = new DCXOBJ();
         *  logOutput("Tutti i risultati:");
         *  for (; !queryResults.AtEnd(); queryResults.Next())
         *  {
         *      querySingleResult = queryResults.Get();
         *  }
         * }
         */
        // for each key in the map
        public List <string> storeSingleResult(DCXOBJ currObj)
        {
            List <string> returnValues = new List <string>();

            foreach (int dicomTagNumber in searchMap.Keys) // es. patientName, patientID,..)
            {
                // store found values into returnMap
                returnValues = returnMap[dicomTagNumber];
                returnValues.Add(extractValue(currObj, dicomTagNumber));
                returnMap[dicomTagNumber] = returnValues;
            }
            return(returnValues);
        }
Esempio n. 5
0
        void OnQueryResponseRecieved(DCXOBJ queryResult)
        {
            // raise event for window
            try
            {
                List <string> ret = storeSingleResult(queryResult);
                numResults++;
                logOutput(ret[0]);
                //RaiseEvent(numResults, ret);
            }


            catch (Exception)
            { errorMessage("La ricerca non ha prodotto risultati."); }
        }
Esempio n. 6
0
        // to do before calling server
        public static DCXOBJ encodeQuery(Dictionary <int, string> searchMap)
        {
            DCXOBJ obj = new DCXOBJ();
            DCXELM el  = new DCXELM();

            foreach (var pair in searchMap)
            {
                el.Init(pair.Key); // ad esempio (int)QueryRetrieveLevel
                if (pair.Value != "")
                {
                    el.Value = pair.Value; // ad esempio "STUDY"
                }
                obj.insertElement(el);
            }
            return(obj);
        }
Esempio n. 7
0
        public static String extractValue(DCXOBJ currObj, int dicomTagNumber)
        {
            string ret      = "";
            DCXELM currElem = new DCXELM();

            try
            {
                currElem = currObj.getElementByTag(dicomTagNumber);
                ret      = currElem.Value;
            }
            catch (Exception)
            {
                errorMessage("Nel risultato della query non è contenuto il tag DICOM '"
                             + dicomTagName(dicomTagNumber) + "'");
            }
            return(ret);
        }
Esempio n. 8
0
 private string TryGetString(DCXOBJ obj, DICOM_TAGS_ENUM tag)
 {
     try
     {
         DCXELM e = obj.getElementByTag((int)tag);
         if (e != null && e.Value != null)
         {
             return(obj.getElementByTag((int)tag).Value.ToString());
         }
         else
         {
             return("N/A");
         }
     }
     catch (COMException)
     {
         return("N/A");
     }
 }
Esempio n. 9
0
        public bool tryQueryServer(Association serverino, string type)
        {
            bool ret = false;

            leggiCampiQuery(searchMap, type);
            DCXOBJ query = encodeQuery(searchMap);

            setCallbackDelegate(req);

            logOutput("Launching " + type + " command:");

            try
            {
                serverConnection(req, serverino, query);
                ret = true;
            }
            catch (System.Runtime.InteropServices.COMException)
            { errorMessage("Impossibile connettersi al server"); }

            return(ret);
        }
Esempio n. 10
0
        // evento: arrivato il file (lo controllo e rispondo se è ok)
        private void OnStoreDoneEventHandler(string filename, bool status, ref bool accept)
        {
            // if status, file saved!
            if (!status)
            {
                errorCount++;
                errorMessage("errore nel salvataggio del file!");
            }

            // check if file already exists
            string sop_instance_uid = null;
            DCXOBJ o = new DCXOBJ();

            o.openFile(filename);
            DCXELM e = o.getElementByTag((int)DICOM_TAGS_ENUM.sopInstanceUID);

            if (e != null)
            {
                sop_instance_uid = e.Value.ToString();
            }
            ReleaseComObject(e);
            ReleaseComObject(o);

            if (sop_instance_uid != null)
            {
                String destinationFilename = storageDirectory + sop_instance_uid + ".dcm";
                if (!File.Exists(destinationFilename))
                {
                    File.Move(filename, destinationFilename);
                }
                else
                {
                    errorMessage("file gia esiste");
                    File.Delete(filename);
                }
            }
            accept = true;
        }
Esempio n. 11
0
        public static void moveAndStore(Association ass, Selector sel)
        {
            // Create an object with the query matching criteria (Identifier)
            DCXOBJ query = fillData(sel);

            // Create an accepter to handle the incomming association
            DCXACC accepter = new DCXACC();

            accepter.StoreDirectory = @"C:/Users/daniele/Desktop/provaDicom";
            Directory.CreateDirectory(accepter.StoreDirectory);

            // Create a requester and run the query
            DCXREQ requester = new DCXREQ();

            requester.MoveAndStore(
                ass.myAET,      // The AE title that issue the C-MOVE
                ass.TargetAET,  // The PACS AE title
                ass.TargetIp,   // The PACS IP address
                ass.TargetPort, // The PACS listener port
                ass.myAET,      // The AE title to send the
                query,          // The matching criteria
                104,            // The port to receive the results
                accepter);      // The accepter to handle the results
        }
Esempio n. 12
0
        private void LoadResultsToGrid(DCXOBJIterator it)
        {
            DCXOBJ currObj = null;

            try
            {
                DataTable rq = new DataTable("RQ");
                DataRow   rqRow;

                rq.Columns.Add(new DataColumn("Accession Number", typeof(string)));
                rq.Columns.Add(new DataColumn("Patient ID", typeof(string)));
                rq.Columns.Add(new DataColumn("Patient Name", typeof(string)));
                rq.Columns.Add(new DataColumn("Patient BirthDate", typeof(string)));
                rq.Columns.Add(new DataColumn("Patient Sex", typeof(string)));
                rq.Columns.Add(new DataColumn("Patient Weight", typeof(string)));
                rq.Columns.Add(new DataColumn("Modality", typeof(string)));
                rq.Columns.Add(new DataColumn("Fecha", typeof(string)));
                rq.Columns.Add(new DataColumn("Time", typeof(string)));
                //rq.Columns.Add(new DataColumn("Physician Reading Study", typeof(string)));
                rq.Columns.Add(new DataColumn("Referring Physician", typeof(string)));

                // Iterate over the query results
                for (; !it.AtEnd(); it.Next())
                {
                    currObj = it.Get();
                    rqRow   = rq.NewRow();
                    rqRow["Accession Number"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.AccessionNumber);
                    rqRow["Patient ID"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.patientID);
                    rqRow["Patient Name"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.patientName);
                    rqRow["Patient BirthDate"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.PatientBirthDate);
                    rqRow["Patient Sex"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.PatientSex);
                    rqRow["Patient Weight"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.PatientsWeight);
                    rqRow["Modality"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.Modality);
                    rqRow["Fecha"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.ScheduledProcedureStepStartDate);
                    rqRow["Time"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.ScheduledProcedureStepStartTime);
                    rqRow["Referring Physician"] =
                        TryGetString(currObj, DICOM_TAGS_ENUM.ReferringPhysicianName);

                    rq.Rows.Add(rqRow);
                }

                dataTable = rq;

                //// Bind the master data connector

                RefrescarDataGrid();
            }
            finally
            {
                ReleaseComObject(currObj);
            }
        }
Esempio n. 13
0
        public static String find(Association ass, Selector sel)
        {
            DCXOBJ obj = fillData(sel);
            String ret = "";
            // Create the requester object
            DCXREQ req = new DCXREQ();
            // send the query
            DCXOBJIterator it = req.Query(ass.myAET,
                                          ass.TargetAET,
                                          ass.TargetIp,
                                          ass.TargetPort,
                                          "1.2.840.10008.5.1.4.1.2.1.1",
                                          obj);
            DCXOBJ currObj = null;

            try
            { int index = 1;
              // Iterate over the query results
              for (; !it.AtEnd(); it.Next())
              {
                  currObj = it.Get();
                  string message = "";

                  message += stampa(currObj, (int)DICOM_TAGS_ENUM.patientName);

                  if (level == "STUDY" || level == "SERIES" || level == "IMAGE")
                  {
                      message += stampa(currObj, (int)DICOM_TAGS_ENUM.StudyDescription);
                  }

                  if (level == "SERIES" || level == "IMAGE")
                  {
                      message += stampa(currObj, (int)DICOM_TAGS_ENUM.SeriesDescription);
                  }

                  if (level == "IMAGE")
                  {
                      message += stampa(currObj, (int)DICOM_TAGS_ENUM.sopClassUid);
                      message += stampa(currObj, (int)DICOM_TAGS_ENUM.sopInstanceUID);
                  }

                  if (level == "STUDY")
                  {
                      message += stampa(currObj, (int)DICOM_TAGS_ENUM.studyInstanceUID);
                  }

                  if (level == "SERIES")
                  {
                      message += stampa(currObj, (int)DICOM_TAGS_ENUM.seriesInstanceUID);

                      if (index == 1)     // l'UID della serie è il primo dello studio
                      // non uso la funzione stampa, se no mi aggiunge altro testo oltre all'id
                      {
                          try   { currElem = currObj.getElementByTag((int)DICOM_TAGS_ENUM.seriesInstanceUID); }
                          catch (Exception e) { Console.WriteLine(e.Message); }   //Tag Not Found
                          ret = currElem.Value;
                          Console.WriteLine(ret);
                      }
                  }
                  index++;
                  Console.WriteLine(message);
              }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(ret);
        }
Esempio n. 14
0
 /* Callback when a response from the called ae for the query command is recieved */
 public void OnQueryResponseRecievedAction(DCXOBJ obj)
 {
     // Do something
     ReleaseComObject(obj);
 }
Esempio n. 15
0
        static DCXOBJ fillData(Selector sel)
        {
            DCXOBJ obj = new DCXOBJ();
            DCXELM el  = new DCXELM();

            level = sel.QueryRetrieveLevel;

            el.Init((int)DICOM_TAGS_ENUM.QueryRetrieveLevel);
            el.Value = level;
            obj.insertElement(el);

            el.Init((int)DICOM_TAGS_ENUM.patientName);
            if (sel.patientName != "")
            {
                el.Value = sel.patientName;
            }
            obj.insertElement(el);

            if (level == "STUDY" || level == "SERIES" || level == "IMAGE")
            {
                el.Init((int)DICOM_TAGS_ENUM.StudyDescription);
                obj.insertElement(el);
            }

            if (level == "SERIES" || level == "IMAGE")
            {
                el.Init((int)DICOM_TAGS_ENUM.SeriesDescription);
                obj.insertElement(el);
            }

            if (level == "IMAGE")
            {
                el.Init((int)DICOM_TAGS_ENUM.sopClassUid);
                if (sel.sopClassUid != "")
                {
                    el.Value = sel.sopClassUid;
                }
                obj.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.sopInstanceUID);
                if (sel.sopInstanceUID != "")
                {
                    el.Value = sel.sopInstanceUID;
                }
                obj.insertElement(el);
            }

            if (level == "STUDY" || level == "SERIES")
            {
                el.Init((int)DICOM_TAGS_ENUM.studyInstanceUID);
                if (sel.studyInstanceUID != "")
                {
                    el.Value = sel.studyInstanceUID;
                }
                obj.insertElement(el);
            }

            if (level == "SERIES")
            {
                el.Init((int)DICOM_TAGS_ENUM.seriesInstanceUID);
                obj.insertElement(el);
            }

            return(obj);
        }
Esempio n. 16
0
        public void Query()
        {
            DCXOBJIterator it  = null;
            DCXREQ         req = new DCXREQClass();
            DCXOBJ         rp  = new DCXOBJ();
            DCXELM         el  = new DCXELM();

            try
            {
                //el.Init((int)DICOM_TAGS_ENUM.studyInstanceUID);
                //rp.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.AccessionNumber);
                // el.Value = "34*";
                rp.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.PatientsName);
                rp.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.patientID);
                rp.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.PatientBirthDate);
                rp.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.PatientSex);
                rp.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.PatientsWeight);
                rp.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.Modality);
                rp.insertElement(el);

                // A lot of code to handle all the cases of date and time matching
                // that eventually goes into the elements: ScheduledProcedureStepStartDate and ScheduledProcedureStepStartTime
                el.Init((int)DICOM_TAGS_ENUM.ScheduledProcedureStepSequence);
                rp.insertElement(el);

                //el.Init((int)DICOM_TAGS_ENUM.ScheduledProcedureStepStartDate);
                //rp.insertElement(el);

                //el.Init((int)DICOM_TAGS_ENUM.NameOfPhysiciansReadingStudy);
                //rp.insertElement(el);

                el.Init((int)DICOM_TAGS_ENUM.ReferringPhysicianName);
                rp.insertElement(el);

                // Connect the requester object's callback to our method
                req.OnQueryResponseRecieved += new IDCXREQEvents_OnQueryResponseRecievedEventHandler(OnQueryResponseRecievedAction);

                rp.Dump("query.txt");

                // send the query command
                it = req.Query(config.localAETitle,
                               config.targetAETitle,
                               config.serverIp,
                               config.serverPort,
                               "1.2.840.10008.5.1.4.31",  /// Modality Worklist SOP Class
                               rp);

                LoadResultsToGrid(it);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Query failed: " + ex.Message);
            }
            finally
            {
                ReleaseComObject(req);
                ReleaseComObject(rp);
                ReleaseComObject(it);
                ReleaseComObject(el);
            }
        }
Esempio n. 17
0
 public abstract void serverConnection(DCXREQ req, Association serverino, DCXOBJ query);
Esempio n. 18
0
 /* Callback when a response from the called ae for the move command is recieved */
 public void OnMoveResponseRecievedAction(bool status, DCXOBJ obj)
 {
     // Do something
     ReleaseComObject(obj);
 }