예제 #1
0
        public static void Main(string[] args)
        {
            List <IDpair> idPairs = new List <IDpair>();
            var           IDlist  = new List <string>();

            if (args.Length == 1)
            {
                IDlist = args[0].Split(';').ToList();
            }
            else
            {
                throw new Exception("Wrong number of inputs");
            }


            // Split in pairs
            foreach (string line in IDlist)
            {
                idPairs.Add(new IDpair(line));
            }

            // Create all required entities
            //var me = new Entity("EvilDICOMC", "10.0.129.139", 50401);
            //var me = Entity.CreateLocal("DCMGRBC", 51167);
            var me  = Entity.CreateLocal("DCMGRBer", 50400);
            var scu = new DICOMSCU(me);

            //var scp = new DICOMSCP
            Entity   reciever = new Entity(AEtitle, ipadress, port);
            DICOMSCP scp      = new DICOMSCP(reciever);
            //var scpEntity = Entity.CreateLocal("EvilDICOM", 50400);
            //var scpEntity = new Entity("EvilDICOM", "10.0.129.139", 50400);
            //var scp = new FileWriterSCP(scpEntity, outPath);
            //var scp = new DICOMSCP(scpEntity);
            //scp.SupportedAbstractSyntaxes = AbstractSyntax.ALL_RADIOTHERAPY_STORAGE;
            //scp.ListenForIncomingAssociations(true);
            //var logger = new ConsoleLogger(scp.Logger, ConsoleColor.Red);
            var    qb    = new QueryBuilder(scu, daemon);
            ushort msgId = 1;

            // Loop over ID pairs and pull files from ARIA OIS to finalPath
            foreach (IDpair idPair in idPairs)
            {
                try
                {
                    //qb.SendImage(new EvilDICOM.Network.DIMSE.IOD.CFindImageIOD() { PatientId = idPair.Id, SOPInstanceUID = idPair.Uid }, "EvilDICOM", ref msgId);
                    CFindImageIOD iod = new CFindImageIOD()
                    {
                        PatientId = idPair.Id, SOPInstanceUID = idPair.Uid
                    };
                    scu.SendCMoveImage(daemon, iod, scp.ApplicationEntity.AeTitle, ref msgId);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message + "\n" + idPair.Uid);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Instructs a C-MOVE operation for an image from the SCP of the QueryBuilder to the input AETitle
        /// </summary>
        /// <param name="ir">the C Find iod of the a query (get ImageUids())</param>
        /// <param name="receivingAETitle">the AE title to send the image to (from the SCP of this query builder)</param>
        /// <param name="msgId">the message id for this image. It will be incremented for looping operations within this method</param>
        /// <returns>a C-MOVE response for this operation</returns>
        public CMoveResponse SendImage(CFindImageIOD ir, string receivingAETitle, ref ushort msgId)
        {
            var resp = _scu.SendCMoveImage(_scp, ir, receivingAETitle, ref msgId);

            return(resp);
        }
예제 #3
0
        static int Execute(MainSettings settings)
        {
            // start by sending mail
            sendMail.Program.send(settings.MAILTO, "MIQA_xBot initiated", "Export to MIQA will begin now.", settings.MAIL_USER, settings.MAIL_DOMAIN, settings.SMTP_SERVER);

            List <CFindImageIOD> iods = new List <CFindImageIOD>();
            Entity daemon             = Entity.CreateLocal(settings.DBDAEMON_AETITLE, settings.DBDAEMON_PORT);

            // define the local service class
            var me  = Entity.CreateLocal(settings.SCU_AETITLE, settings.SCU_PORT);
            var scu = new DICOMSCU(me);

            // define the query builder
            var    qb    = new QueryBuilder(scu, daemon);
            ushort msgId = 1;

            // read the xml file
            string xml   = File.ReadAllText(settings.XporterPath);
            Xports xPort = xml.ParseXML <Xports>();

            // define the recievr
            //Entity reciever = new Entity(xPort.Xporter.AEtitle, getIP(xPort.Xporter.ipstring), xPort.Xporter.port);
            Entity   reciever = new Entity(xPort.Xporter.AEtitle, xPort.Xporter.getIP(), xPort.Xporter.port);
            DICOMSCP scp      = new DICOMSCP(reciever);

            // Query plan
            DataTable plans = new DataTable();

            if (!String.IsNullOrEmpty(xPort.Xporter.SQLstring))
            {
                SqlInterface.Connect(settings);
                plans = xPort.Query(settings.LAG_DAYS);
                SqlInterface.Disconnect();
            }

            // loop through plans
            foreach (DataRow row in plans.Rows)
            {
                var patId   = (string)row["PatientId"];
                var planUID = (string)row["UID"];
                iods.Add(new CFindImageIOD()
                {
                    PatientId = patId, SOPInstanceUID = planUID
                });
                // loop through items and query based on type
                foreach (string item in xPort.Xporter.include.ToList())
                {
                    string itemSqlString = string.Empty;
                    switch (item)
                    {
                    case "planDose":
                        itemSqlString = "select distinct UID = DoseMatrix.DoseUID from DoseMatrix where DoseMatrix.PlanSetupSer = " + (Int64)row["PlanSer"];
                        break;

                    case "fieldDoses":
                        itemSqlString = "select distinct UID = DoseMatrix.DoseUID from DoseMatrix, Radiation where Radiation.PlanSetupSer = " + (Int64)row["PlanSer"] + " and DoseMatrix.RadiationSer = Radiation.RadiationSer";
                        break;

                    case "slices":
                        itemSqlString = "select UID=Slice.SliceUID from Slice, Image, StructureSet, PlanSetup where PlanSetup.PlanSetupSer=" + (Int64)row["PlanSer"] + " and StructureSet.StructureSetSer=PlanSetup.StructureSetSer and Image.ImageSer=StructureSet.ImageSer and Slice.SeriesSer=Image.SeriesSer";
                        break;

                    case "structures":
                        itemSqlString = "select UID=StructureSet.StructureSetUID from PlanSetup, StructureSet where PlanSetup.PlanSetupSer=" + (Int64)row["PlanSer"] + " and StructureSet.StructureSetSer=PlanSetup.StructureSetSer";
                        break;

                    case "images":
                        itemSqlString = "select UID=Slice.SliceUID from Slice, ImageSlice, Radiation where Radiation.PlanSetupSer = " + (Int64)row["PlanSer"] + " and ImageSlice.ImageSer = Radiation.RefImageSer and Slice.SliceSer = ImageSlice.SliceSer";
                        break;

                    case "records":
                        itemSqlString = "select UID=TreatmentRecord.TreatmentRecordUID from TreatmentRecord, RTPlan where RTPlan.PlanSetupSer= " + (Int64)row["PlanSer"] + " and TreatmentRecord.RTPlanSer=RTPlan.RTPlanSer";
                        break;

                    default:
                        itemSqlString = String.Empty;
                        break;
                    }
                    if (!String.IsNullOrEmpty(itemSqlString))
                    {
                        DataTable includeItem = SqlInterface.Query(itemSqlString);
                        foreach (DataRow itemRow in includeItem.Rows)
                        {
                            iods.Add(new CFindImageIOD()
                            {
                                PatientId = patId, SOPInstanceUID = (string)itemRow["UID"]
                            });
                        }
                    }
                }
            }

            if (xPort.Xporter.active)
            {
                Console.WriteLine(iods.Count.ToString());
                // Remove duplicate UIDs
                if (!xPort.Xporter.allowDoublets)
                {
                    iods = ListHandler.Unique(iods);
                }

                Console.WriteLine(iods.Count.ToString());
                foreach (var iod in iods)
                {
                    // Send it
                    scu.SendCMoveImage(daemon, iod, xPort.Xporter.AEtitle, ref msgId);
                    // We need this to pump messages in debugging
                    Console.WriteLine(iod.SOPInstanceUID.ToString());
                }
            }

            // overwrite lastActivity
            if (plans.Rows.Count > 0)
            {
                // Get last date encountered
                DateTime lastPlan = (DateTime)plans.Rows[plans.Rows.Count - 1]["MAXDate"];
                xPort.Xporter.lastActivity = lastPlan.ToString("yyyy-MM-dd");

                // write xml
                using (FileStream fs = new FileStream(settings.XporterPath, FileMode.Create))
                {
                    XmlSerializer _xSer = new XmlSerializer(typeof(Xports));

                    _xSer.Serialize(fs, xPort);
                }
            }
            if (xPort.Xporter.active)
            {
                return(plans.Rows.Count);
            }
            else
            {
                return(0);
            }
        }
예제 #4
0
        static void Execute()
        {
            List <CFindImageIOD> iods = new List <CFindImageIOD>();
            // define the DB Deamon entity
            Entity daemon = Entity.CreateLocal(AEtitleDB, portDB);

            // define the local service class
            var me  = Entity.CreateLocal("EvilDICOMC", 50400);
            var scu = new DICOMSCU(me);

            // define the query builder
            var    qb    = new QueryBuilder(scu, daemon);
            ushort msgId = 1;

            // xml Deserialize
            string xml   = File.ReadAllText(Settings.xPorterPath);
            var    xport = xml.ParseXML <xports>();

            // Define the reciever
            Entity   reciever = new Entity(xport.xporter.AEtitle, xport.xporter.ipstring, xport.xporter.port);
            DICOMSCP scp      = new DICOMSCP(reciever);

            // Query plan
            DataTable plans = new DataTable();

            if (!String.IsNullOrEmpty(xport.xporter.SQLstring))
            {
                SqlInterface.Connect();
                plans = xport.Query();
                SqlInterface.Disconnect();
            }

            // loop through plans
            foreach (DataRow row in plans.Rows)
            {
                var patId = ((string)row["PatientId"]);
                // Remove special characters from patId
                byte[] patIdBytes;
                patIdBytes = Encoding.GetEncoding("ISO-8859-8").GetBytes(patId);
                patId      = Encoding.UTF8.GetString(patIdBytes);
                var    ImageUID = (string)row["ImageUID"];
                var    RefUID   = (string)row["RefUID"];
                double MU       = (double)row["MU"];

                iods.Add(new CFindImageIOD()
                {
                    PatientId = patId, SOPInstanceUID = ImageUID
                });
                iods.Add(new CFindImageIOD()
                {
                    PatientId = patId, SOPInstanceUID = RefUID
                });

                if (xport.xporter.active)
                {
                    // Generate linking text file
                    string[] content = { ImageUID, RefUID, MU.ToString(), Settings.DoseCrit, Settings.DistCrit, Settings.DoseThreshold, Settings.LocalDose, Settings.AcceptCrit };
                    File.WriteAllLines(ImageUID + ".dat", content);

                    // SFTP it
                    SFTP.Send(ImageUID + ".dat");

                    // Delte file
                    File.Delete(ImageUID + ".dat");
                }
            }


            // change lastActivity
            if (plans.Rows.Count > 0)
            {
                DateTime lastPlan = (DateTime)plans.Rows[plans.Rows.Count - 1]["DateTime"];
                xport.xporter.lastActivity = lastPlan.ToString("yyyy-MM-dd HH:mm:ss.fff");
                // write xml
                using (FileStream fs = new FileStream(Settings.xPorterPath, FileMode.Create))
                {
                    XmlSerializer _xSer = new XmlSerializer(typeof(xports));

                    _xSer.Serialize(fs, xport);
                }
            }

            // if active send
            if (xport.xporter.active)
            {
                Console.WriteLine(iods.Count.ToString());
                // Remove duplicate UIDs
                if (!xport.xporter.allowDoublets)
                {
                    iods = ListHandler.Unique(iods);
                }

                Console.WriteLine(iods.Count.ToString());
                foreach (var iod in iods)
                {
                    // Send it
                    scu.SendCMoveImage(daemon, iod, xport.xporter.AEtitle, ref msgId);
                    // Add logging

                    // verify file recieved
                    var recieved = SFTP.Verify("RI." + iod.SOPInstanceUID + ".dcm");
                    if (!recieved)
                    {
                        throw new FileNotFoundException("CMove Operation not verified.");
                    }
                }
            }
        }