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))); }
/// <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); }
public OmronECGFormat() { _Config = new ECGConfig(new string[] { "Patient ID", "Patient Lastname", "Patient 2nd Lastname", "Patient Firstname" }, 2, null); _Config["Patient ID"] = "NoPatientID"; _Config["Patient Lastname"] = "NoLastname"; }
public ISHNEFormat() { _InputStreamOffset = 0; _InputStream = null; _Signals = null; _Config = new ECGConfig(new string[] { "CRC Validation", "AVM Override" }, 1, null); _Config["CRC Validation"] = "true"; }
public SCPFormat() { _Config = new ECGConfig(new string[] { "Compression Type", "Difference Data Median", "Difference Data Rhythm", "QRS Subtraction", "Bimodal Comppression Rate", "Use Lead Measurements" }, 3, new ECGConfig.CheckConfigFunction(this._ConfigurationWorks)); _Config["Compression Type"] = EncodingType.DefaultHuffman.ToString(); _Config["Difference Data Median"] = "2"; _Config["Difference Data Rhythm"] = "2"; _Config["QRS Subtraction"] = "false"; _Config["Use Lead Measurements"] = "true"; }
public CSVFormat() { string[] poss = new string[] { "Use Buffered Stream" }; _Config = new ECGConfig(null, poss, null); _Config["Use Buffered Stream"] = "false"; Empty(); }
public CSVFormat() { string[] poss = new string[] { "Calculate Leads", "Use Buffered Stream" /*, "Filter Bottom Cutoff", "Filter Top Cutoff", "Filter Number of Sections"*/ }; _Config = new ECGConfig(null, poss, null); _Config["Calculate Leads"] = "false"; _Config["Use Buffered Stream"] = "false"; Empty(); }
/// <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);
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()); } }
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()); } }
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()); } }
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()); } }
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()); } }
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); } }