Ejemplo n.º 1
0
        public OpenFromECGMS(IECGManagementSystem ms)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            _ManSys = ms;
        }
Ejemplo n.º 2
0
        public void Run()
        {
            try
            {
                if (_NoArgs)
                {
                    Help();
                }
                else if (_BadArgs)
                {
                    Error();
                    Help();
                }
                else
                {
                    if (_InType != null)
                    {
                        converter.waitForLoadingAllPlugins();
                    }

                    IECGReader reader = _InType == null ? new UnknownECGReader() : converter.getReader(_InType);

                    if (reader == null)
                    {
                        Console.Error.WriteLine("Error: no reader provided by input type!");

                        return;
                    }

                    ECGConfig config1 = ECGConverter.Instance.getConfig(_InType);

                    if (config1 != null)
                    {
                        for (int i = 0; i < _Config.Count; i++)
                        {
                            config1[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i);
                        }
                    }

                    IECGFormat src = reader.Read(_InFile, _InFileOffset, config1);

                    if (src == null ||
                        !src.Works())
                    {
                        Console.Error.WriteLine("Error: {0}", reader.getErrorMessage());

                        return;
                    }

                    if ((_BufferedSecondsToLoad > 0) ||
                        (_BufferedOffsetToLoad > 0))
                    {
                        ECGConversion.ECGSignals.Signals sigs = null;

                        if ((src.Signals.getSignals(out sigs) == 0) &&
                            sigs.IsBuffered)
                        {
                            ECGConversion.ECGSignals.BufferedSignals bs = (ECGConversion.ECGSignals.BufferedSignals)sigs;

                            int start = 0,
                                end   = 0;

                            start = bs.RealRhythmStart + (_BufferedOffsetToLoad * bs.RhythmSamplesPerSecond);
                            end   = (_BufferedSecondsToLoad == int.MaxValue) ? _BufferedSecondsToLoad : start + (_BufferedSecondsToLoad * bs.RhythmSamplesPerSecond);

                            if (start > bs.RealRhythmEnd)
                            {
                                start = bs.RealRhythmEnd;
                            }

                            if (end > bs.RealRhythmEnd)
                            {
                                end = bs.RealRhythmEnd;
                            }

                            if (start < end)
                            {
                                bs.LoadSignal(start, end);

                                src.Signals.setSignals(bs);
                            }
                        }
                    }

                    IECGManagementSystem manSys = _OutFile == null ? null : converter.getECGManagementSystem(_OutType);

                    config1 = ECGConverter.Instance.getConfig(manSys == null ? _OutType : manSys.FormatName);

                    ECGConfig config2 = manSys == null ? null : manSys.Config;

                    for (int i = 0; i < _Config.Count; i++)
                    {
                        if (config1 != null)
                        {
                            config1[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i);
                        }

                        if (config2 != null)
                        {
                            config2[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i);
                        }
                    }

                    if ((config1 != null) &&
                        !config1.ConfigurationWorks())
                    {
                        Console.Error.WriteLine("Error: Bad Configuration for ECG Format!");

                        return;
                    }

                    if ((config2 != null) &&
                        !config2.ConfigurationWorks())
                    {
                        Console.Error.WriteLine("Error: Bad Configuration for ECG Management System!");

                        return;
                    }

                    if (manSys == null)
                    {
                        IECGFormat dst = src.GetType() == ECGConverter.Instance.getType(_OutType) ? src : null;

                        if (dst == null)
                        {
                            if ((src.Demographics != null) &&
                                (src.Demographics.PatientID == null))
                            {
                                src.Demographics.PatientID = _PatientId;
                            }

                            ECGConverter.Instance.Convert(src, _OutType, config1, out dst);
                        }

                        if ((dst == null) ||
                            !dst.Works())
                        {
                            Console.Error.WriteLine("Error: Conversion Failed!");

                            return;
                        }

                        if (_Anonymize)
                        {
                            dst.Anonymous();
                        }

                        if ((_PatientId != null) &&
                            (dst.Demographics != null))
                        {
                            dst.Demographics.PatientID = _PatientId;
                        }

                        ECGWriter.Write(dst, _OutFile, true);

                        if (ECGWriter.getLastError() != 0)
                        {
                            Console.Error.WriteLine("Error: {0}", ECGWriter.getLastErrorMessage());
                        }
                    }
                    else
                    {
                        if (manSys.ConfiguredToSave())
                        {
                            if (_Anonymize)
                            {
                                src.Anonymous();
                            }

                            manSys.SaveECG(src, _PatientId, config1);
                        }
                        else
                        {
                            Console.Error.WriteLine("Error: Not configured to store!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.ToString());
            }
        }
Ejemplo n.º 3
0
        private void Help()
        {
            try
            {
                converter.waitForLoadingAllPlugins();

                bool bHelp = true;

                if ((_OutType != null) &&
                    !_BadArgs)
                {
                    ECGConfig
                        cfg1 = null,
                        cfg2 = null;

                    IECGFormat format = converter.getFormat(_OutType);

                    if (format != null)
                    {
                        bHelp = false;

                        cfg1 = format.Config;
                    }
                    else
                    {
                        IECGManagementSystem manSys = converter.getECGManagementSystem(_OutType);

                        if (manSys != null)
                        {
                            bHelp = false;

                            cfg1 = manSys.Config;
                            cfg2 = converter.getFormat(manSys.FormatName).Config;
                        }
                    }

                    if (bHelp)
                    {
                        _Error = "Unknown type!";
                        Error();
                    }
                    else
                    {
                        int nrItems = cfg1 != null ? cfg1.NrConfigItems : 0;

                        if (cfg2 != null)
                        {
                            nrItems += cfg1.NrConfigItems;
                        }

                        if (nrItems == 0)
                        {
                            Console.WriteLine("Exporting type {0} has got zero configuration items!", _OutType);
                            Console.WriteLine();
                        }
                        else
                        {
                            Console.WriteLine("Exporting type {0} has got the following configuration items:", _OutType);

                            nrItems = cfg1 != null ? cfg1.NrConfigItems : 0;

                            for (int i = 0; i < nrItems; i++)
                            {
                                string
                                    name = cfg1[i],
                                    def  = cfg1[name];

                                Console.Write("  {0}", name);
                                if (def != null)
                                {
                                    Console.Write(" (default value: \"");
                                    Console.Write(def);
                                    Console.Write("\")");
                                }
                                Console.WriteLine();
                            }

                            nrItems = cfg2 != null ? cfg2.NrConfigItems : 0;

                            for (int i = 0; i < nrItems; i++)
                            {
                                string
                                    name = cfg2[i],
                                    def  = cfg2[name];

                                Console.Write("  {0}", name);
                                if (def != null)
                                {
                                    Console.Write(" (default value: \"");
                                    Console.Write(def);
                                    Console.Write("\")");
                                }
                                Console.WriteLine();
                            }
                        }
                    }
                }

                if (bHelp)
                {
                    string outputTypes, outputECGMS;

                    StringBuilder sb = new StringBuilder();

                    foreach (string str in converter.getSupportedFormatsList())
                    {
                        if (sb.Length != 0)
                        {
                            sb.Append(", ");
                        }

                        sb.Append(str);
                    }

                    outputTypes = sb.ToString();

                    sb = new StringBuilder();

                    foreach (string str in converter.getSupportedManagementSystemsList())
                    {
                        if (converter.hasECGManagementSystemSaveSupport(str))
                        {
                            if (sb.Length != 0)
                            {
                                sb.Append(", ");
                            }

                            sb.Append(str);
                        }
                    }

                    outputECGMS = sb.Length == 0 ? "(none)" : sb.ToString();

                    Console.WriteLine("Usage: ECGTool [-A] [-P patid] [-I intype] [-bsl nrsec] [-bol nrsec] [-C \"var=val\" [...]] filein [offset] outtype fileout");
                    Console.WriteLine("       ECGTool [-A] [-P patid] [-I intype] [-bsl nrsec] [-bol nrsec] [-C \"var=val\" [...]] filein [offset] outecgms");
                    Console.WriteLine("       ECGTool -h [outtype | outecgms | intype]");
                    Console.WriteLine();
                    Console.WriteLine("  filein     path to input file");
                    Console.WriteLine("  offset     offset in input file");
                    Console.WriteLine("  outtype    type of ouput file: {0}", outputTypes);
                    Console.WriteLine("  fileout    path for output file");
                    Console.WriteLine("  outecgms   type of output ECG Management System: {0}", outputECGMS);
                    Console.WriteLine("  -A         anonymize output");
                    Console.WriteLine("  -P patid   specifiy a Patient ID for ECG");
                    Console.WriteLine("  -I intype  specify an input type");
                    Console.WriteLine("  -bsl nrsec buffered seconds to load (add to value: s, m, h, d or w) or use: all");
                    Console.WriteLine("  -bol nrsec buffered seconds offset to load (add to value: s, m, h, d or w)");
                    Console.WriteLine("  -C var=val providing a configuration item");
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.ToString());
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            int bufferedSecondsToLoad = 0,
                bufferedOffsetToLoad  = 0;
            bool   Anonymize          = false;
            string patid = null;

            try
            {
                CheckVersion.OnNewVersion += new ECGConversion.CheckVersion.NewVersionCallback(CheckVersion_OnNewVersion);

                ECGConverter.Instance.waitForECGManagementSystemSupport("PACS");

                IECGManagementSystem pacs = ECGConverter.Instance.getECGManagementSystem("PACS");


                if (pacs == null)
                {
                    Console.Error.WriteLine("Error: DICOM plugin not available!");

                    return;
                }

                ECGConfig cfg = ECGConverter.Instance.getConfig(pacs.FormatName);

                // A normal parameters list.
                ArrayList al = new ArrayList();

                // first get all the configuration parameters.
                for (int i = 0; i < args.Length; i++)
                {
                    if (string.Compare(args[i], "-A") == 0)
                    {
                        // this will anonymize a ECG
                        Anonymize = true;
                    }
                    else if (args[i].StartsWith("-P"))
                    {
                        // Set the Patient ID of the ECG.
                        if (args[i].Length == 2)
                        {
                            if (args.Length == ++i)
                            {
                                Console.Error.WriteLine("Error: Bad Arguments!");

                                al.Clear();

                                break;
                            }

                            patid = args[i];
                        }
                        else
                        {
                            patid = args[i].Substring(2, args[i].Length - 2);
                        }
                    }
                    else if (args[i].StartsWith("-aet"))
                    {
                        // set AE Title of this SCU.
                        if (args[i].Length == 4)
                        {
                            if (args.Length == ++i)
                            {
                                Console.Error.WriteLine("Error: Bad Arguments!");

                                al.Clear();

                                break;
                            }

                            pacs.Config["AESCU"] = args[i];
                        }
                        else
                        {
                            pacs.Config["AESCU"] = args[i].Substring(4, args[i].Length - 4);
                        }
                    }
                    else if (args[i].StartsWith("-aec"))
                    {
                        // set AE Title of the called SCP.
                        if (args[i].Length == 4)
                        {
                            if (args.Length == ++i)
                            {
                                Console.Error.WriteLine("Error: Bad Arguments!");

                                al.Clear();

                                break;
                            }

                            pacs.Config["AESCP"] = args[i];
                        }
                        else
                        {
                            pacs.Config["AESCP"] = args[i].Substring(4, args[i].Length - 4);
                        }
                    }
                    else if (args[i].StartsWith("-C"))
                    {
                        // Add additional configuration items.
                        string[] temp = null;

                        if (args[i].Length == 2)
                        {
                            if (args.Length == ++i)
                            {
                                Console.Error.WriteLine("Error: Bad Arguments!");

                                al.Clear();

                                break;
                            }

                            temp = args[i].Split('=');
                        }
                        else
                        {
                            temp = args[i].Substring(2, args[i].Length - 2).Split('=');
                        }

                        if ((temp == null) ||
                            (cfg == null))
                        {
                            Console.Error.WriteLine("Error: Bad Arguments!");

                            al.Clear();

                            break;
                        }
                        else
                        {
                            cfg[temp[0]] = temp[1];
                        }
                    }
                    else if (args[i].StartsWith("-bsl"))
                    {
                        string val = null;

                        // set the nr of seconds to load for buffered signals.
                        if (args[i].Length == 4)
                        {
                            if (args.Length == ++i)
                            {
                                Console.Error.WriteLine("Error: Bad Arguments!");

                                al.Clear();

                                break;
                            }

                            val = args[i];
                        }
                        else
                        {
                            val = args[i].Substring(4, args[i].Length - 4);
                        }

                        if (val != null)
                        {
                            if (string.Compare(val, "all", true) == 0)
                            {
                                bufferedSecondsToLoad = int.MaxValue;
                            }
                            else
                            {
                                try
                                {
                                    char B = val[val.Length - 1];

                                    int nA = 0,
                                        nB = 1;

                                    if (char.ToLower(B) == 's')
                                    {
                                        nB  = 1;
                                        val = val.Substring(0, val.Length - 1);
                                    }
                                    else if (char.ToLower(B) == 'm')
                                    {
                                        nB  = 60;
                                        val = val.Substring(0, val.Length - 1);
                                    }
                                    else if (char.ToLower(B) == 'h')
                                    {
                                        nB  = 3600;
                                        val = val.Substring(0, val.Length - 1);
                                    }
                                    else if (char.ToLower(B) == 'd')
                                    {
                                        nB  = 86400;
                                        val = val.Substring(0, val.Length - 1);
                                    }
                                    else if (char.ToLower(B) == 'w')
                                    {
                                        nB  = 604800;
                                        val = val.Substring(0, val.Length - 1);
                                    }

                                    nA = int.Parse(val);

                                    bufferedSecondsToLoad = nA * nB;
                                }
                                catch
                                {
                                    Console.Error.WriteLine("Error: Bad Arguments!");

                                    al.Clear();

                                    break;
                                }
                            }
                        }
                    }
                    else if (args[i].StartsWith("-bol"))
                    {
                        string val = null;

                        // set the nr of seconds to load for buffered signals.
                        if (args[i].Length == 4)
                        {
                            if (args.Length == ++i)
                            {
                                Console.Error.WriteLine("Error: Bad Arguments!");

                                al.Clear();

                                break;
                            }

                            val = args[i];
                        }
                        else
                        {
                            val = args[i].Substring(4, args[i].Length - 4);
                        }

                        if (val != null)
                        {
                            try
                            {
                                char B = val[val.Length - 1];

                                int nA = 0,
                                    nB = 1;

                                if (char.ToLower(B) == 's')
                                {
                                    nB  = 1;
                                    val = val.Substring(0, val.Length - 1);
                                }
                                else if (char.ToLower(B) == 'm')
                                {
                                    nB  = 60;
                                    val = val.Substring(0, val.Length - 1);
                                }
                                else if (char.ToLower(B) == 'h')
                                {
                                    nB  = 3600;
                                    val = val.Substring(0, val.Length - 1);
                                }
                                else if (char.ToLower(B) == 'd')
                                {
                                    nB  = 86400;
                                    val = val.Substring(0, val.Length - 1);
                                }
                                else if (char.ToLower(B) == 'w')
                                {
                                    nB  = 604800;
                                    val = val.Substring(0, val.Length - 1);
                                }

                                nA = int.Parse(val);

                                bufferedOffsetToLoad = nA * nB;
                            }
                            catch
                            {
                                Console.Error.WriteLine("Error: Bad Arguments!");

                                al.Clear();

                                break;
                            }
                        }
                    }
                    else
                    {
                        // add to the normal parameters list.
                        al.Add(args[i]);
                    }
                }

                // Three or Four normal parameters are accepted!.
                if ((al.Count == 3) ||
                    (al.Count == 4))
                {
                    if (!pacs.ConfiguredToSave() ||
                        ((cfg != null) &&
                         !cfg.ConfigurationWorks()))
                    {
                        Console.Error.WriteLine("Error: Bad Configuration!");

                        return;
                    }

                    ECGConversion.IECGFormat src = null;

                    int offset = 0,
                        i      = 0;

                    string file = (string)al[i++];

                    if (al.Count == 4)
                    {
                        try
                        {
                            offset = int.Parse((string)al[i++]);
                        }
                        catch
                        {
                            Console.Error.WriteLine("Error: incorrect offset!");

                            return;
                        }
                    }

                    UnknownECGReader reader = new ECGConversion.UnknownECGReader();
                    src = reader.Read(file, offset);

                    if ((src == null) ||
                        !src.Works())
                    {
                        Console.Error.WriteLine("Error: Couldn't open ECG from specified file!");

                        return;
                    }

                    if ((bufferedSecondsToLoad > 0) ||
                        (bufferedOffsetToLoad > 0))
                    {
                        ECGConversion.ECGSignals.Signals sigs = null;

                        if ((src.Signals.getSignals(out sigs) == 0) &&
                            sigs.IsBuffered)
                        {
                            ECGConversion.ECGSignals.BufferedSignals bs = (ECGConversion.ECGSignals.BufferedSignals)sigs;

                            int start = 0,
                                end   = 0;

                            start = bs.RealRhythmStart + (bufferedOffsetToLoad * bs.RhythmSamplesPerSecond);
                            end   = (bufferedSecondsToLoad == int.MaxValue) ? bufferedSecondsToLoad : start + (bufferedSecondsToLoad * bs.RhythmSamplesPerSecond);

                            if (start > bs.RealRhythmEnd)
                            {
                                start = bs.RealRhythmEnd;
                            }

                            if (end > bs.RealRhythmEnd)
                            {
                                end = bs.RealRhythmEnd;
                            }

                            if (start < end)
                            {
                                bs.LoadSignal(start, end);

                                src.Signals.setSignals(bs);
                            }
                        }
                    }

                    if (Anonymize)
                    {
                        src.Anonymous();
                    }

                    pacs.Config["Server"] = (string)al[i++];
                    pacs.Config["Port"]   = (string)al[i++];

                    if (pacs.SaveECG(src, patid, cfg) != 0)
                    {
                        Console.Error.WriteLine("Storing of ECG failed!");
                    }
                }
                else
                {
                    // Provide a help message.
                    if (al.Count != 0)
                    {
                        Console.Error.WriteLine("Error: Bad Arguments!");
                    }

                    Console.WriteLine("Usage: ECGStoreSCU [-A] [-P patid] [-aet name] [-aec name] [-bsl nrsec] [-bol nrsec] {0}file [offset] host port", cfg == null ? "" : "[-C var=val] ");
                    Console.WriteLine();
                    Console.WriteLine("  file       path to input file");
                    Console.WriteLine("  offset     offset in input file");
                    Console.WriteLine("  server     hostname of DICOM peer");
                    Console.WriteLine("  port       tcp/ip port number of peer");
                    Console.WriteLine("  -A         anonymize output");
                    Console.WriteLine("  -P patid   specifiy a Patient ID for ECG");
                    Console.WriteLine("  -aet name  calling AE Title");
                    Console.WriteLine("  -aec name  called AE Title");
                    Console.WriteLine("  -bsl nrsec buffered seconds to load (add to value: s, m, h, d or w) or use: all");
                    Console.WriteLine("  -bol nrsec buffered seconds offset to load (add to value: s, m, h, d or w)");

                    if (cfg != null)
                    {
                        Console.WriteLine("  -C var=val providing a configuration item");
                        Console.WriteLine();
                        Console.WriteLine("Exporting type {0} has got the following configuration items:", pacs.FormatName);

                        int nrItems = cfg.NrConfigItems;

                        for (int i = 0; i < nrItems; i++)
                        {
                            string
                                name = cfg[i],
                                def  = cfg[name];

                            Console.Write("  {0}", name);
                            if (def != null)
                            {
                                Console.Write(" (default value: \"");
                                Console.Write(def);
                                Console.Write("\")");
                            }
                            Console.WriteLine();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.ToString());
            }
        }