Exemple #1
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());
            }
        }
Exemple #2
0
        private void Help()
        {
            try
            {
                string outputTypes, outputECGMS;

                converter.waitForLoadingAllPlugins();
                ECGConfig cfg = converter.getConfig("PDF");

                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: ECGPrint [-A] [-S] [-P patid] {0} filein [offset]", ((cfg == null) ? "" : "[-C \"var=val\" [...]]"));
                Console.WriteLine("       ECGPrint -h");
                Console.WriteLine();
                Console.WriteLine("  filein     path to input file");
                Console.WriteLine("  offset     offset in input file (optional)");
                Console.WriteLine("  -A         anonymize output");
                Console.WriteLine("  -S         silently print");
                Console.WriteLine("  -h         provides this help message");
                Console.WriteLine("  -P patid   specifiy a Patient ID for ECG");

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

                    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());
            }
        }