コード例 #1
0
ファイル: SCPFormat.cs プロジェクト: zxy30/ECGToolkit
        /// <summary>
        /// Function to convert to SCP.
        /// </summary>
        /// <param name="src">an ECG file to convert</param>
        /// <param name="dst">SCP file returned</param>
        /// <returns>0 on success</returns>
        public static int ToSCP(IECGFormat src, ECGConfig cfg, out IECGFormat dst)
        {
            dst = null;
            if (src != null)
            {
                dst = new SCPFormat();

                if ((cfg != null) &&
                    ((dst.Config == null) ||
                     !dst.Config.Set(cfg)))
                {
                    return(1);
                }

                int err = ECGConverter.Convert(src, dst);
                if (err != 0)
                {
                    return(err);
                }

                ((SCPFormat)dst).setPointers();

                return(0);
            }
            return(1);
        }
コード例 #2
0
        float[] GetSecondLead(string fileName)
        {
            IECGFormat format = null;

            var fmt = "SCP-ECG";

            IECGReader reader = ECGConverter.Instance.getReader(fmt);
            ECGConfig  cfg    = ECGConverter.Instance.getConfig(fmt);

            format = reader.Read(fileName, 0, cfg);

            Signals _CurrentSignal;

            format.Signals.getSignals(out _CurrentSignal);

            if (_CurrentSignal != null)
            {
                for (int i = 0, en = _CurrentSignal.NrLeads; i < en; i++)
                {
                    ECGTool.NormalizeSignal(_CurrentSignal[i].Rhythm, _CurrentSignal.RhythmSamplesPerSecond);
                }
            }

            Signals sig = _CurrentSignal.CalculateTwelveLeads();

            return(Array.ConvertAll(sig.GetLeads()[1].Rhythm, x => (float)(x)));
        }
コード例 #3
0
ファイル: SaveToECGMS.cs プロジェクト: zxy30/ECGToolkit
        public SaveToECGMS(IECGFormat src, ECGConversion.ECGManagementSystem.IECGManagementSystem manSys)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            _Source = src;
            _ManSys = manSys;
        }
コード例 #4
0
        private void buttonOK_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (listECG.SelectedIndex >= 0)
                {
                    _SelectedECG = _ManSys.getECG(_ECGList[listECG.SelectedIndex]);

                    if ((_SelectedECG != null) &&
                        _SelectedECG.Works())
                    {
                        Close();
                    }
                    else
                    {
                        MessageBox.Show(this, "Opening of ECG from Management System failed!", "Opening ECG failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #5
0
 /// <summary>
 /// Function to save an ECG to an ECG Management System.
 /// </summary>
 /// <param name="ecg">ECG file to save</param>
 /// <param name="patid">patient id to store to</param>
 /// <param name="cfg">configuration to set towards</param>
 /// <returns>
 /// -1 if not supported
 /// 0 if successfull
 /// 1 if improperly configured
 /// 2 if can't convert to correct format
 /// 3 if saving has failed
 /// > 3 if specific failure.
 /// </returns>
 public abstract int SaveECG(IECGFormat ecg, string patid, ECGConfig cfg);
コード例 #6
0
 /// <summary>
 /// Function to save an ECG to an ECG Management System.
 /// </summary>
 /// <param name="ecg">ECG file to save</param>
 /// <param name="patid">patient id to store to</param>
 /// <returns>
 /// -1 if not supported
 /// 0 if successfull
 /// 1 if improperly configured
 /// 2 if can't convert to correct format
 /// 3 if saving has failed
 /// > 3 if specific failure.
 /// </returns>
 public int SaveECG(IECGFormat ecg, string patid)
 {
     return(SaveECG(ecg, patid, null));
 }
コード例 #7
0
 /// <summary>
 /// Function to save an ECG to an ECG Management System.
 /// </summary>
 /// <param name="ecg">ECG file to save</param>
 /// <returns>
 /// -1 if not supported
 /// 0 if successfull
 /// 1 if improperly configured
 /// 2 if can't convert to correct format
 /// 3 if saving has failed
 /// > 3 if specific failure.
 /// </returns>
 public int SaveECG(IECGFormat ecg)
 {
     return(SaveECG(ecg, null, null));
 }
コード例 #8
0
ファイル: ECGTool.cs プロジェクト: zxy30/ECGToolkit
        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());
            }
        }
コード例 #9
0
ファイル: ECGTool.cs プロジェクト: zxy30/ECGToolkit
        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());
            }
        }
コード例 #10
0
        public void Run()
        {
            try
            {
                if (!converter.waitForFormatSupport("PDF"))
                {
                    Console.Error.WriteLine("Error: PDF plug-in is not available!");

                    return;
                }

                if (_NoArgs)
                {
                    Help();
                }
                else if (_BadArgs)
                {
                    Error();
                    Help();
                }
                else
                {
                    UnknownECGReader reader = new UnknownECGReader();

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

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

                        return;
                    }

                    ECGConfig config = converter.getConfig("PDF");

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

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

                        return;
                    }

                    IECGFormat dst = null;

                    converter.Convert(src, "PDF", config, out dst);

                    if ((dst == null) ||
                        !dst.Works())
                    {
                        Console.Error.WriteLine("Error: Creating PDF failed!");

                        return;
                    }

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

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

                    string outfile = Path.GetTempFileName();

                    ECGWriter.Write(dst, outfile, true);

                    if (ECGWriter.getLastError() != 0)
                    {
                        Console.Error.WriteLine("Error: {0}", ECGWriter.getLastErrorMessage());

                        return;
                    }

                    if (!PrintPdf(outfile, _Silence))
                    {
                        Console.Error.WriteLine("Error: Using acrobat to print failed!");

                        return;
                    }

                    try
                    {
                        File.Delete(outfile);
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.ToString());
            }
        }