Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        public ECGTool()
        {
            CheckVersion.OnNewVersion += new ECGConversion.CheckVersion.NewVersionCallback(CheckVersion_OnNewVersion);

            converter = ECGConverter.Instance;

            Init();
        }
Esempio n. 3
0
        public override IECGFormat Read(Stream input, int offset, ECGConfig cfg)
        {
            IECGFormat ret = null;

            LastError = 0;

            if ((input != null) &&
                input.CanRead &&
                input.CanSeek)
            {
                long pos = input.Position;
                int  i   = 0;

                ECGConverter converter = ECGConverter.Instance;
                for (; i < converter.getNrSupportedFormats(); i++)
                {
                    if (converter.hasUnknownReaderSupport(i))
                    {
                        try
                        {
                            ret = converter.getFormat(i);

                            if ((ret != null) &&
                                ret.CheckFormat(input, offset + converter.getExtraOffset(i)))
                            {
                                ret.Read(input, offset + converter.getExtraOffset(i));
                                if (ret.Works())
                                {
                                    break;
                                }
                            }

                            input.Position = pos;
                        }
                        catch {}

                        if (ret != null)
                        {
                            ret.Dispose();
                            ret = null;
                        }
                    }
                }

                if (i == converter.getNrSupportedFormats())
                {
                    LastError = 2;
                }
            }
            else
            {
                LastError = 1;
            }

            return(ret);
        }
Esempio n. 4
0
        public void setLeadConfiguration(string[] myLeadConfig)
        {
            if (myLeadConfig.Length != LeadConfiguration.Length)
            {
                LeadConfiguration = new LeadType[myLeadConfig.Length];
            }

            for (int i = 0; i < myLeadConfig.Length; i++)
            {
                LeadConfiguration[i] = (LeadType)ECGConverter.EnumParse(typeof(LeadType), myLeadConfig[i], true);
            }
        }
Esempio n. 5
0
        public override IECGFormat Read(byte[] buffer, int offset, ECGConfig cfg)
        {
            IECGFormat ret = null;

            LastError = 0;

            if (buffer != null)
            {
                int i = 0;

                ECGConverter converter = ECGConverter.Instance;
                for (; i < converter.getNrSupportedFormats(); i++)
                {
                    if (converter.hasUnknownReaderSupport(i))
                    {
                        try
                        {
                            ret = converter.getFormat(i);

                            if ((ret != null) &&
                                ret.CheckFormat(buffer, offset + converter.getExtraOffset(i)))
                            {
                                ret.Read(buffer, offset + converter.getExtraOffset(i));
                                if (ret.Works())
                                {
                                    break;
                                }
                            }
                        }
                        catch {}

                        if (ret != null)
                        {
                            ret.Dispose();
                            ret = null;
                        }
                    }
                }

                if (i == converter.getNrSupportedFormats())
                {
                    LastError = 2;
                }
            }
            else
            {
                LastError = 1;
            }

            return(ret);
        }
Esempio n. 6
0
        public void Init()
        {
            CheckVersion.OnNewVersion += new ECGConversion.CheckVersion.NewVersionCallback(CheckVersion_OnNewVersion);
            converter = ECGConverter.Instance;

            _NoArgs = true;
            _Error  = null;

            _InFile       = null;
            _InFileOffset = 0;

            _Anonymize = false;
            _Silence   = false;
            _PatientId = null;
            _Config.Clear();
        }
Esempio n. 7
0
        public override int Write(Stream output)
        {
            try
            {
                System.IO.StreamWriter sw = new StreamWriter(output);

                int ret = ECGConverter.ToExcelTxt(this, sw, '\t', _UseBufferedStream);

                sw.Flush();

                return(ret);
            }
            catch
            {
            }

            return(1);
        }
Esempio n. 8
0
        public bool _ConfigurationWorks()
        {
            try
            {
                ECGConverter.EnumParse(typeof(EncodingType), _Config["Compression Type"], true);

                int ddm = int.Parse(_Config["Difference Data Median"]),
                    ddr = int.Parse(_Config["Difference Data Rhythm"]);

                if ((ddm >= 0) &&
                    (ddm <= 2) &&
                    (ddr >= 0) &&
                    (ddr <= 2) &&
                    ((_Config["Use Lead Measurements"] == null) ||
                     (string.Compare(_Config["Use Lead Measurements"], "true", true) == 0) ||
                     (string.Compare(_Config["Use Lead Measurements"], "false", true) == 0)))
                {
                    string temp1 = _Config["Bimodal Comppression Rate"];

                    if (temp1 == null)
                    {
                        return(true);
                    }

                    int temp2 = int.Parse(temp1);

                    switch (temp2)
                    {
                    case 1:
                    case 2:
                    case 4:
                        return(true);

                    default:
                        break;
                    }
                }
            }
            catch {}

            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// Conver to this supported format.
        /// </summary>
        /// <param name="src">source format.</param>
        /// <param name="cfg">configuration to set format to</param>
        /// <param name="dst">output of destination format.</param>
        /// <returns>0 on successful</returns>
        public int Convert(IECGFormat src, ECGConfig cfg, out IECGFormat dst)
        {
            dst = null;

            if (_FormatType == null)
            {
                return(1);
            }

            if (_ConvertFunction.Length == 0)
            {
                dst = (IECGFormat)Activator.CreateInstance(_FormatType);

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

                return(ECGConverter.Convert(src, dst) << 2);
            }

            try
            {
                object[] args = new object[] { src, cfg, null };

                int ret = (int)_FormatType.GetMethod(_ConvertFunction).Invoke(null, args);

                if (args[2] != null)
                {
                    dst = (IECGFormat)args[2];
                }

                return(ret << 2);
            }
            catch
            {
            }

            return(1);
        }
Esempio n. 10
0
        public override int Write(Stream output)
        {
            Signals tempSigs = null;
            Signals calcSigs = null;

            try
            {
                System.IO.StreamWriter sw = new StreamWriter(output);

                if (_CalculateLeads &&
                    (this._Sigs != null))
                {
                    calcSigs = _Sigs.CalculateFifteenLeads();

                    if (calcSigs == null)
                    {
                        calcSigs = _Sigs.CalculateTwelveLeads();
                    }

                    if (calcSigs != null)
                    {
                        tempSigs = _Sigs;
                        _Sigs    = calcSigs;
                    }
                }

                int ret = ECGConverter.ToExcelTxt(this, sw, '\t', _UseBufferedStream);

                sw.Flush();

                return(ret);
            }
            catch {}

            if (tempSigs != null)
            {
                _Sigs = tempSigs;
            }

            return(1);
        }