Ejemplo n.º 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());
            }
        }
Ejemplo n.º 2
0
        private void buttonOK_Click(object sender, System.EventArgs e)
        {
            try
            {
                string patid = textPatientId.Text;

                if (_Source.GetType() != ECGConverter.Instance.getType(_ManSys.FormatName))
                {
                    ECGConfig cfg = ECGConverter.Instance.getConfig(_ManSys.FormatName);

                    if (cfg != null)
                    {
                        Config cfgScreen = new Config(_ManSys.FormatName, cfg);

                        if (cfgScreen.ShowDialog(this) != DialogResult.OK)
                        {
                            return;
                        }
                    }
                }

                if ((patid != null) &&
                    (patid.Length == 0))
                {
                    patid = null;
                }

                int result = _ManSys.SaveECG(_Source, patid);

                if (result == 0)
                {
                    MessageBox.Show(this, "Sending of ECG to PACS was successfully completed.", "ECG send to PACS!", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    Close();
                }
                else
                {
                    string text = "Sending of ECG failed due to unknown reason!";

                    switch (result)
                    {
                    case 1:
                        text = "Sending of ECG failed due to bad configuration!";
                        break;

                    case 2:
                        text = "Sending of ECG failed because converting to DICOM failed!";
                        break;

                    case 3:
                        text = "Sending of ECG failed because of failure of connection!";
                        break;

                    case -1:
                        text = "Sending of ECG is not supported!";
                        break;

                    default:
                        text = "Sending of ECG failed for unknown reason!";
                        break;
                    }

                    MessageBox.Show(this, text, "Sending ECG failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }