public override void ProcessRawData() { try { Log.Trace("Begin Process Data"); //Lưu lại Data Log.Trace(StringData); string pTestDate; string pMonth = new string[] {}.ToString(); //Kiểm tra nếu chưa kết thúc nhận dữ liệu if (!StringData.EndsWith(DeviceHelper.ETX.ToString(CultureInfo.InvariantCulture))) { return; } string[] strResult = StringData.Split(DeviceHelper.CR); TestResult.TestDate = strResult[0].Substring(1, 9).Trim(); pMonth = strResult[0].Substring(4, 3); pTestDate = GetMonth(pMonth); TestResult.TestDate = string.Format("{0}/{1}/{2}{3}", TestResult.TestDate.Substring(0, 2), pTestDate, DateTime.Now.Year.ToString(CultureInfo.InvariantCulture).Substring(0, 2), TestResult.TestDate.Substring(7, 2)); TestResult.Barcode = strResult[1].Trim(); if (TestResult.Barcode.Equals("")) { TestResult.Barcode = "0"; } AddResult(new ResultItem("WBC", strResult[2].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("RBC", strResult[10].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("HGB", strResult[11].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("HCT", strResult[12].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("MCV", strResult[13].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("MCH", strResult[14].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("MCHC", strResult[15].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("PLT", strResult[17].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("%LY", strResult[3].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("%MO", strResult[4].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("%GR", strResult[5].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("#LY", strResult[6].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("#MO", strResult[7].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("#GR", strResult[8].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("#EO", strResult[9].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("RDW", strResult[16].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("PCT", strResult[18].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("MPV", strResult[19].Replace("L", "").Replace("H", "").Trim())); AddResult(new ResultItem("PDW", strResult[20].Replace("L", "").Replace("H", "").Trim())); Log.Debug("Import Result for barcode:" + TestResult.Barcode); ImportResults(); Log.Debug("Import Result Success"); } catch (Exception ex) { Log.Error(string.Format("{0} /n {1}", "Lỗi Trong quá trình xử lý dữ liệu", ex)); } finally { ClearData(); } }
public override void ProcessRawData() { try { Log.Trace("Begin Process Data"); //Lưu lại Data Log.Trace("RawData:\n{0}", StringData); //Kiểm tra nếu là kí tự STX thì nhận dữ liệu if ( !(StringData.StartsWith(DeviceHelper.STX.ToString()) && StringData.EndsWith(DeviceHelper.ETX.ToString()))) { Log.Trace("Dữ liệu không hợp lệ"); return; } string[] rawData = StringData.Split(DeviceHelper.CR); //Lấy ngày: TestResult.TestDate = string.Format("{0}/{1}/{2}", rawData[17], rawData[16], rawData[15]); //Lấy barcode: TestResult.Barcode = rawData[22].Trim(); //Add Kết quả: AddResult(new ResultItem("WBC", rawData[23].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("NE%", rawData[24].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("LY%", rawData[25].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("MO%", rawData[26].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("EO%", rawData[27].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("BA%", rawData[28].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("NE", rawData[29].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("LY", rawData[30].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("MO", rawData[31].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("EO", rawData[32].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("BA", rawData[33].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("RBC", rawData[34].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("HGB", rawData[35].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("HCT", rawData[36].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("MCV", rawData[37].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("MCH", rawData[38].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("MCHC", rawData[39].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("RDW", rawData[40].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("PLT", rawData[41].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); AddResult(new ResultItem("MPV", rawData[43].Replace("*", "").Replace("H", "").Replace("L", "").Trim())); Log.Trace("Begin Import Result"); Log.Trace(ImportResults() ? "Import Result Success" : "Error while import result"); } catch (Exception ex) { Log.Error(string.Format("Error while process data {0}", ex)); } finally { ClearData(); } }
public override void ProcessRawData() { try { string pTestDate, pday; string pMonth = new string[] {}.ToString(); //Kiểm tra nếu chưa kết thúc nhận dữ liệu if (!StringData.EndsWith(DeviceHelper.ETX.ToString(CultureInfo.InvariantCulture))) { return; } Log.Trace("Begin Process Data"); Log.Trace(DeviceHelper.CRLF + StringData); string[] strResult = StringData.Split(DeviceHelper.CR); TestResult.TestDate = strResult[0].Substring(1, 9).Trim(); pMonth = strResult[0].Substring(4, 3); //pTestDate = GetMonth(pMonth); pTestDate = DeviceHelper.GetMonth(pMonth); TestResult.TestDate = string.Format("{0}/{1}/20{2}", TestResult.TestDate.Substring(0, 2), pTestDate, TestResult.TestDate.Substring(7, 2)); TestResult.Barcode = strResult[1].Trim(); if (TestResult.Barcode.Equals("")) { TestResult.Barcode = "0"; } AddResult(new ResultItem("WBC", strResult[2].Replace("L", "").Replace("H", "").Trim(), "10^9/L")); AddResult(new ResultItem("RBC", strResult[10].Replace("L", "").Replace("H", "").Trim(), "10^12/L")); AddResult(new ResultItem("HGB", strResult[11].Replace("L", "").Replace("H", "").Trim(), "g/L")); AddResult(new ResultItem("HCT", strResult[12].Replace("L", "").Replace("H", "").Trim(), "%")); AddResult(new ResultItem("MCV", strResult[13].Replace("L", "").Replace("H", "").Trim(), "fL")); AddResult(new ResultItem("MCH", strResult[14].Replace("L", "").Replace("H", "").Trim(), "Pg")); AddResult(new ResultItem("MCHC", strResult[15].Replace("L", "").Replace("H", "").Trim(), "g/L")); AddResult(new ResultItem("PLT", strResult[17].Replace("L", "").Replace("H", "").Trim(), "10^3/uL")); AddResult(new ResultItem("%LY", strResult[3].Replace("L", "").Replace("H", "").Trim(), "%")); AddResult(new ResultItem("%MO", strResult[4].Replace("L", "").Replace("H", "").Trim(), "%")); AddResult(new ResultItem("%GR", strResult[5].Replace("L", "").Replace("H", "").Trim(), "%")); AddResult(new ResultItem("#LY", strResult[6].Replace("L", "").Replace("H", "").Trim(), "10^9/L")); AddResult(new ResultItem("#MO", strResult[7].Replace("L", "").Replace("H", "").Trim(), "10^9/L")); AddResult(new ResultItem("#GR", strResult[8].Replace("L", "").Replace("H", "").Trim(), "10^9/L")); AddResult(new ResultItem("#EO", strResult[9].Replace("L", "").Replace("H", "").Trim(), "10^9/L")); AddResult(new ResultItem("RDW", strResult[16].Replace("L", "").Replace("H", "").Trim(), "%CV")); AddResult(new ResultItem("PCT", strResult[18].Replace("L", "").Replace("H", "").Trim(), "%")); AddResult(new ResultItem("MPV", strResult[19].Replace("L", "").Replace("H", "").Trim(), "fL")); AddResult(new ResultItem("PDW", strResult[20].Replace("L", "").Replace("H", "").Trim(), "%")); ImportResults(); Log.Debug("Import Result Success For barocde:{0}", TestResult.Barcode); } catch (Exception ex) { //File.AppendAllText(@"C:\NIHONKODEN-ERROR.txt", ex.ToString()); } finally { ClearData(); } }
private bool ValidData() { if (StringData.EndsWith(DeviceHelper.ETX.ToString(CultureInfo.InvariantCulture))) { SendByte((byte)DeviceHelper.ACK); return(true); } return(false); }
public override void ProcessRawData() { //SendStringData("OK"); SendBytesData(ByteData); if (StringData.EndsWith("$")) { ClearData(); } }
public override void ProcessRawData() { Log.Trace("Begin Process Data"); //Lưu lại Data Log.Trace(StringData); try { if (!StringData.EndsWith(DeviceHelper.CRLF)) { return; } string[] allPatient = DeviceHelper.DeleteAllBlankLine(StringData, DeviceHelper.CRLF); foreach (string patient in allPatient) { string[] result = DeviceHelper.DeleteAllBlankLine(patient, ' '); TestResult.TestSequence = result[0]; TestResult.Barcode = Convert.ToInt32(result[1]).ToString(CultureInfo.InvariantCulture); TestResult.TestDate = DateTime.Now.ToString("dd/MM/yyyy"); AddResult(new ResultItem("K", result[3])); AddResult(new ResultItem("Na", result[4])); AddResult(new ResultItem("Cl", result[5])); double iCa = -999999; try { iCa = Convert.ToDouble(result[6]); } catch (Exception) { iCa = -999999; } AddResult(new ResultItem("iCa", result[6])); AddResult(new ResultItem("PH", result[7])); if (iCa != -999999) { AddResult(new ResultItem("TCa", Math.Round(iCa * 1.953, 2).ToString(CultureInfo.InvariantCulture))); } Log.Debug("Import Result for barcode:" + TestResult.Barcode); ImportResults(); Log.Debug("Import Result Success"); } } catch (Exception ex) { Log.Error(string.Format("Exception while processing data:{0}", ex)); } finally { ClearData(); } }
/// <summary> /// Xử lý sau kkhi nhận được dữ liệu /// </summary> public override void ProcessRawData() { try { // Kiểm tra dữ liệu xem có đủ không ? if (!StringData.EndsWith(DeviceHelper.ETX.ToString())) { return; } Log.Trace("Begin Process Data"); Log.Trace(DeviceHelper.CRLF + StringData); //Lấy về dữ liệu của các bệnh nhân string[] arrPatients = DeviceHelper.SeperatorRawData(StringData, DeviceHelper.STX, DeviceHelper.ETX); Log.Trace("Result has {0} Patients", arrPatients.Length); //Duyệt qua mảng xử lý dữ liệu của từng bệnh nhân foreach (string patient in arrPatients) { var rawdata = patient.Split(','); var tempDate = rawdata[4].Substring(1).Split('-'); TestResult.TestDate = string.Format("{0}/{1}/{2}", tempDate[2], tempDate[1], tempDate[0]); string barcode = rawdata[10].Substring(1).Trim(); TestResult.Barcode = barcode; string testValue = rawdata[11].Trim(); try { testValue = Convert.ToDouble(testValue).ToString(); } catch (Exception) { } TestResult.Add(new ResultItem("HbA1C", testValue)); Log.Debug(string.Format("Import Result For barocde:{0}", barcode)); Log.Debug(ImportResults() ? string.Format("Import Result Success") : string.Format("Error while import result")); } } catch (Exception ex) { Log.Error("Error while processing data {0}Error:{1}", DeviceHelper.CRLF, ex.ToString()); } finally { ClearData(); } }
public override void ProcessRawData() { try { Log.Trace("Begin Process Data"); Log.Trace("Raw Data:\r\n{0}", StringData); if (!StringData.EndsWith(DeviceHelper.ETX.ToString())) { return; } // Lấy ra kết quả của bệnh nhân string[] allResultPatients = DeviceHelper.SeperatorRawData(StringData, DeviceHelper.STX, DeviceHelper.ETX); Log.Trace("Result has {0} Patients", allResultPatients.Length); // Xử lý từng kết quả của bệnh nhân. foreach (string patient in allResultPatients) { // Loại bỏ những dấu * ở đầu dòng và ngắt dòng theo ký tự CRLF string[] result = DeviceHelper.DeleteAllBlankLine(patient, DeviceHelper.CRLF, true); // Lấy ra PatientID int rowIndex = GetRowIndex(result, "NO"); TestResult.Barcode = result[rowIndex].Split()[2].Trim(); string[] tempDate = result[rowIndex + 1].Split()[0].Split('-'); // Lấy ngày TestResult.TestDate = string.Format("{0}/{1}/{2}", tempDate[2].Trim(), tempDate[1].Trim(), tempDate[0].Substring(4, 4).Trim()); rowIndex = GetFirstResultIndex(result); // Lọc kết quả và xử lý kết quả theo bệnh nhân. for (int i = rowIndex; i < result.Length - 1; i++) { AddResult(GetResultItemFromString(result[i])); } Log.Debug("Begin Import Result For barocde:{0}", TestResult.Barcode); Log.Trace(ImportResults() ? "Import Result Success" : "Error Import Result"); } Log.Trace("Finish Process Data"); ClearData(); } catch (Exception ex) { Log.Error("Error while processing data: {0}", ex.ToString()); ClearData(); } }
public override void ProcessRawData() { try { //Nếu ký tự kết thúc khác EOT thi gửi ACK để confirm dữ liệu đã được nhận if ( !(StringData.EndsWith(DeviceHelper.ETX.ToString(CultureInfo.InvariantCulture)) || StringData.EndsWith(DeviceHelper.EOT.ToString(CultureInfo.InvariantCulture)))) { return; } Log.Trace("Begin Process Data"); //Lưu lại Data Log.Trace(DeviceHelper.CRLF + StringData); //Kết thúc khi nhận được EOT và tiến hành xử lý DL SendStringData(DeviceHelper.ACK.ToString(CultureInfo.InvariantCulture)); string[] allPatients = DeviceHelper.DeleteAllBlankLine(StringData, DeviceHelper.STX); Log.Trace("Result has {0} Patients", allPatients.Length); //Duyệt theo từng dòng foreach (string patient in allPatients) { string tempPatient = patient; //Nếu đúng với các ký tự bắt đầu thì xử lý: if (Validdata(patient)) { TestResult.TestDate = DateTime.Now.ToString("dd/MM/yyyy"); TestResult.Barcode = tempPatient.Substring(12, 11).Trim(); tempPatient = tempPatient.Substring(24); while (tempPatient.Length > 9) { string result = tempPatient.Substring(0, 9); string testName = result.Substring(0, 2).Trim(); string testValue = result.Substring(2, 7).Trim(); //Xử lý các ký tự thừa trong kết quả //Loại bỏ dấu "$" testValue = testValue.Replace("$", ""); //Loại bỏ các chữ cái in hoa và in thường trong chuỗi kết quả for (byte i = 65; i <= 90; i++) { testValue = testValue.Replace(Convert.ToChar(i).ToString(CultureInfo.InvariantCulture), "") .Replace(Convert.ToChar(i + 32).ToString(CultureInfo.InvariantCulture), ""); } //Thêm kết quả mới TestResult.Add(new ResultItem(testName, testValue)); Log.Debug("Add new Result: TestName = {0}, TestValue = {1}", testName, testValue); //Cắt bỏ các dữ liệu vừa được xử lý tempPatient = tempPatient.Substring(9); //Xử lý các thông số tính toán double iHdlc = -1, iTrig = -1, iChol = -1, iAlb = -1, iProT = -1, iBilt = -1, iBild = -1, iCa = -1; foreach (ResultItem item in TestResult.Items) { //BIL-Toàn phần if (item.TestName.Equals("10")) { iBilt = TryToConvertToDouble(item.TestValue); if (iBilt > 50) { iBilt = Math.Round(iBilt, 0); item.TestValue = iBilt.ToString(CultureInfo.InvariantCulture); } } //BIL-Trực tiếp if (item.TestName.Equals("11")) { iBild = TryToConvertToDouble(item.TestValue); if (iBild > 50) { iBild = Math.Round(iBild, 0); item.TestValue = iBild.ToString(CultureInfo.InvariantCulture); } } //Protein-T if (item.TestName.Equals("4")) { iProT = TryToConvertToDouble(item.TestValue); } //ALB if (item.TestName.Equals("5")) { iAlb = TryToConvertToDouble(item.TestValue); } //CHOL if (item.TestName.Equals("2")) { iChol = TryToConvertToDouble(item.TestValue); } //Trig if (item.TestName.Equals("3")) { iTrig = TryToConvertToDouble(item.TestValue); } //HDLC if (item.TestName.Equals("16")) { iHdlc = TryToConvertToDouble(item.TestValue); } //Ca if (item.TestName.Equals("15")) { iCa = TryToConvertToDouble(item.TestValue); } } //Tính toán //Bil-Gián tiếp: if ((iBild > 0) && (iBilt > 0)) { testName = "47"; testValue = (iBilt - iBild).ToString(CultureInfo.InvariantCulture); TestResult.Add(new ResultItem(testName, testValue)); Log.Debug("Add new Calculated Result: TestName = {0}, TestValue = {1}", testName, testValue); } //Globumin,Tỷ số A/G if ((iProT > 0) && (iAlb > 0)) { //Globumin testName = "51"; testValue = (iProT - iAlb).ToString(CultureInfo.InvariantCulture); TestResult.Add(new ResultItem(testName, testValue)); Log.Debug("Add new Calculated Result: TestName = {0}, TestValue = {1}", testName, testValue); //Tỷ số A/G testName = "49"; testValue = (iAlb / (iProT - iAlb)).ToString(CultureInfo.InvariantCulture); TestResult.Add(new ResultItem(testName, testValue)); Log.Debug("Add new Calculated Result: TestName = {0}, TestValue = {1}", testName, testValue); } //LDLC: if ((iChol > 0) && (iHdlc > 0) && (iTrig > 0)) { testName = "50"; testValue = iTrig <= 4.5 ? (iChol - (iTrig / 2.2 + iHdlc)).ToString(CultureInfo.InvariantCulture) : "HTĐ"; TestResult.Add(new ResultItem(testName, testValue)); Log.Debug("Add new Calculated Result: TestName = {0}, TestValue = {1}", testName, testValue); } //CA-Ion if (iCa > 0) { testName = "caion"; testValue = (iCa * 0.53).ToString(CultureInfo.InvariantCulture); TestResult.Add(new ResultItem(testName, testValue)); Log.Debug("Add new Calculated Result: TestName = {0}, TestValue = {1}", testName, testValue); } } } Log.Debug("Begin Importdata"); ImportResults(); Log.Debug("Finish Imported result"); ClearData(); } //System.IO.File.WriteAllText(@"C:\Hitachi717_Input.txt",StringData); } catch (Exception ex) { ClearData(); throw ex; } }
public override void ProcessRawData() { try { //Nếu ký tự kết thúc bằng CR thì tiến hành xử lý if (!StringData.EndsWith(DeviceHelper.ETX.ToString(CultureInfo.InvariantCulture))) { return; } Log.Trace("Begin Process Data"); Log.Trace(DeviceHelper.CRLF + StringData); SendStringData(DeviceHelper.ACK.ToString(CultureInfo.InvariantCulture)); //string[] allPatients = DeviceHelper.DeleteAllBlankLine(StringData, DeviceHelper.CRLF); string[] allPatients = DeviceHelper.SeperatorRawData(StringData, DeviceHelper.STX, DeviceHelper.ETX); Log.Trace("Result has {0} Patients", allPatients.Length); //Duyệt theo từng dòng foreach (string patient in allPatients) { string tempPatient = patient; //Nếu đúng với các ký tự bắt đầu thì xử lý: if (!Validdata(patient)) { continue; } TestResult.Barcode = patient.Substring(13, 15).Trim(); TestResult.TestDate = patient.Substring(31, 6).Trim(); TestResult.TestDate = string.Format("{0}/{1}/{2}{3}", TestResult.TestDate.Substring(2, 2), TestResult.TestDate.Substring(0, 2), DateTime.Now.Year.ToString(CultureInfo.InvariantCulture).Substring(0, 2), TestResult.TestDate.Substring(4, 2)); //Nếu số lượng kết quả =0 chuyển xử lý kết quả sau int totalTest = Convert.ToInt32(tempPatient.Substring(42, 2).Trim()); if (totalTest == 0) { continue; } tempPatient = tempPatient.Substring(44); int testCount = 1; while ((tempPatient.Length > 9) && (testCount <= totalTest)) { testCount++; string result = tempPatient.Substring(0, 10); string testName = result.Substring(0, 3).Trim(); string testValue = result.Substring(3, 7).Trim(); //Xử lý các ký tự thừa trong kết quả //Loại bỏ dấu "$" testValue = testValue.Replace("$", ""); testValue = testValue.Replace("!", ""); testValue = testValue.Replace("%", ""); //Loại bỏ các chữ cái in hoa và in thường trong chuỗi kết quả for (byte i = 65; i <= 90; i++) { testValue = testValue.Replace(Convert.ToChar(i).ToString(CultureInfo.InvariantCulture), "") .Replace(Convert.ToChar(i + 32).ToString(CultureInfo.InvariantCulture), ""); } //Thêm kết quả mới //Nếu tên xét nghiệm khác rỗng thì insert if (!string.IsNullOrEmpty(testName.Trim())) { TestResult.Add(new ResultItem(testName, testValue)); Log.Debug("Add new Result: TestName = {0}, TestValue = {1}", testName, testValue); } //Cắt bỏ các dữ liệu vừa được xử lý tempPatient = tempPatient.Substring(10); } Log.Debug("Begin Import Result For barocde:{0}", TestResult.Barcode); ImportResults(); Log.Debug("Import Result Success"); } ClearData(); } catch (Exception ex) { ClearData(); Log.Error("Error while processing data, Error:{0}", ex.ToString()); } }
///// <summary> ///// Thư mục lưu ảnh nhận được ///// Thư mục này lấy trong SystemParam ///// </summary> ////private string _destImagePath = string.Empty; ///// <summary> ///// Thư mục lưu đường dẫn ảnh do máy Xt trả ra ///// Thư mục này được lưu trên máy XT và cấu hình qua file ///// </summary> ////private string _sourceImagePath = string.Empty; /// <summary> /// Tên file lưu đường dẫn /// Đường dẫn này lưu vào dòng số 1 /// </summary> //private string _xt4000IconfigFileName = "_Xt-4000iConfig.txt"; #endregion /// <summary> /// Xử lý sau kkhi nhận được dữ liệu /// </summary> public override void ProcessData() { try { // Kiểm tra kết thúc dữ liệu if (!StringData.EndsWith(string.Format("L|1|N{0}", DeviceHelper.CR))) { Log.Trace("Du lieu nhan dc:\r\n{0}", StringData); Log.Trace("Dek du data, thoat ra lam tiep"); return; } //// Nạp thông tin cấu hình //// Kiểm tra file cấu hình có tồn tại hay không? //// Nếu không tồn tại thì tạo file mới //if (!File.Exists(_xt4000IconfigFileName)) //{ // File.WriteAllText(_xt4000IconfigFileName, // string.Format("\r\nDòng 1: Đường dẫn của thư mục chứa ảnh trên máy XT-400i")); //} //else //{ // _sourceImagePath = File.ReadAllLines(_xt4000IconfigFileName)[0]; // _destImagePath = DeviceHelper.GetImageFolder(); // if (!_destImagePath.EndsWith(Path.DirectorySeparatorChar.ToString())) // _destImagePath = string.Format("{0}{1}", _destImagePath, Path.DirectorySeparatorChar); // if (!_sourceImagePath.EndsWith(Path.DirectorySeparatorChar.ToString())) // _sourceImagePath = string.Format("{0}{1}", _sourceImagePath, Path.DirectorySeparatorChar); //} Log.Trace("Begin Process Data"); //Lưu lại Data Log.Trace(StringData); //Lấy về dữ liệu của các bệnh nhân IEnumerable <string> arrPatients = SeparatorData(StringData); //Duyệt qua mảng xử lý dữ liệu của từng bệnh nhân foreach (string patient in arrPatients) { IEnumerable <string> resultArray = null; string[] records = patient.Split(DeviceHelper.CR); foreach (string record in records) { string[] temp; if (record.StartsWith("P")) { temp = record.Split('|'); if (temp.Length > 4) { TestResult.Barcode = temp[4].Trim(); Log.Debug("Barcode:{0}", TestResult.Barcode); } } else if (record.StartsWith("O")) { temp = record.Split('|'); //Lấy barcode xét nghiệm resultArray = from s in temp[4].Split("\\".ToCharArray()) select s.Split('^')[4]; try { if (TestResult.Barcode.Trim() == "") { string strTempbarcode = temp[3].Split('^')[2].Trim(); TestResult.Barcode = strTempbarcode == "" ? "0000" : strTempbarcode; Log.Debug("Barcode:{0}", TestResult.Barcode); } } catch (Exception) { TestResult.Barcode = "0000"; Log.Debug("Barcode:{0}", TestResult.Barcode); } } else if (record.StartsWith("R")) { try { temp = record.Split('|'); //Lấy về ngày tháng làm xét nghiệm if (String.IsNullOrEmpty(TestResult.TestDate)) { string tempDate = temp[12]; TestResult.TestDate = string.Format("{0}/{1}/{2}", tempDate.Substring(6, 2), tempDate.Substring(4, 2), tempDate.Substring(0, 4)); } string strTestName = temp[2].Split('^')[4].Trim(); bool testInclude = (from s in resultArray where s == strTestName select s).Any(); if (!testInclude) { continue; } string strTestValue = temp[3].Trim(); string strTestUnit = temp[4].Trim(); if (strTestName == "HGB") { try { strTestValue = Math.Round(Convert.ToDouble(strTestValue) * 10, 3).ToString(); } catch { } } else if (strTestName == "MCHC") { try { strTestValue = Math.Round(Convert.ToDouble(strTestValue) * 10, 3).ToString(); } catch (Exception) { } } //else if (strTestName == "HCT") //{ // try // { // strTestValue = Math.Round(Convert.ToDouble(strTestValue)/100, 3).ToString(); // } // catch (Exception) // { // } //} AddResult(new ResultItem(strTestName, strTestValue, strTestUnit)); } catch (Exception ex) { Log.Error("Error while processing data Error: {0}", ex); } } } // Lưu các ảnh thu được: ////// Kiểm tra nếu các thư mục lưu ảnh tồn tại ////if (Directory.Exists(_destImagePath) && Directory.Exists(_sourceImagePath)) ////{ //// IEnumerable<string> lstImg = from r in records //// let header = r.Split('|')[0] //// where //// header.StartsWith("R") && //// r.Split('|')[3].ToUpper().EndsWith(".PNG") //// select r; //// foreach (string s in lstImg) //// { //// try //// { //// string[] temp = s.Split('|'); //// string strTestName = temp[2].Split('^')[4].Trim(); //// string strTestValue = temp[3].Trim(); //// string[] x = strTestValue.Split('&'); //// strTestValue = x[x.Length - 1]; //// // Copy Image //// string sourceFileName = string.Format("{0}{2}{1}{3}", _sourceImagePath, //// Path.DirectorySeparatorChar, x[2], strTestValue); //// string destFileName = string.Format("{0}{1}", _destImagePath, strTestValue); //// if (File.Exists(sourceFileName)) File.Copy(sourceFileName, destFileName, true); //// Log.Debug("Copy file Success: {0} to {1}", sourceFileName, destFileName); //// AddResult(new ResultItem(strTestName, destFileName)); //// } //// catch (Exception ex) //// { //// Log.Error("Error while copy image to folder - Error:{0}", ex.ToString()); //// } //// } ////} ////else ////{ //// Log.Error("Image Folder is not available - could not copy Image"); ////} Log.Trace("Begin Import Result"); Log.Trace(ImportResults() ? "Import Result Success" : "Error While Import result"); } ClearData(); } catch (Exception ex) { Log.Error("Error while processing data Error: {0}", ex); ClearData(); } }
/// <summary> /// Xử lý sau kkhi nhận được dữ liệu /// </summary> public override void ProcessData() { try { // Kiểm tra kết thúc dữ liệu if (!StringData.EndsWith(string.Format("L|1|N{0}", DeviceHelper.CR))) { Log.Trace("Du lieu nhan dc:\r\n{0}", StringData); Log.Trace("Dek du data, thoat ra lam tiep"); return; } //Khai báo mảng kết quả. var arrResultName = new[] { "pH", "PCO2", "PO2", "Na", "K", "Cl", "iCa", "tHb", "SO2", "Hct", "Temperature", "Baro", "cHCO3", "SO2(c)", "BE", "BB", "PAO2", "AG", "pHt", "PCO2t", "PO2t", "PAO2t", "a/AO2t", "FIO2", "H+t" }; Log.Trace("Begin Process Data"); //Lưu lại Data Log.Trace(StringData); //Lấy về dữ liệu của các bệnh nhân IEnumerable <string> arrPatients = SeparatorData(StringData); //Duyệt qua mảng xử lý dữ liệu của từng bệnh nhân foreach (string patient in arrPatients) { string[] records = patient.Split(DeviceHelper.CR); foreach (string record in records) { string[] temp; if (record.StartsWith("P")) { temp = record.Split('|'); if (temp.Length > 4) { TestResult.Barcode = temp[3].Trim(); Log.Debug("Barcode:{0}", TestResult.Barcode); } } else if (record.StartsWith("R")) { try { temp = record.Split('|'); //Lấy về ngày tháng làm xét nghiệm if (String.IsNullOrEmpty(TestResult.TestDate)) { string tempDate = temp[12]; TestResult.TestDate = string.Format("{0}/{1}/{2}", tempDate.Substring(6, 2), tempDate.Substring(4, 2), tempDate.Substring(0, 4)); } string strTestName = temp[2].Split('^')[3].Trim(); if (!arrResultName.Contains(strTestName)) { continue; } string strTestValue = temp[3].Trim(); string strTestUnit = temp[4].Trim(); AddResult(new ResultItem(strTestName, strTestValue, strTestUnit)); } catch (Exception ex) { Log.Error("Error while processing result string:\r\n{1}\r\n Error Detail: {0}", ex, record); } } } Log.Trace("Begin Import Result"); Log.Trace(ImportResults() ? "Import Result Success" : "Error While Import result"); } ClearData(); } catch (Exception ex) { Log.Error("Error while processing data Error: {0}", ex); ClearData(); } }
public override void ProcessRawData() { try { //Nếu ký tự kết thúc bằng CR thì tiến hành xử lý if ((StringData.EndsWith(DeviceHelper.CR.ToString(CultureInfo.InvariantCulture))) || (StringData.EndsWith(DeviceHelper.CRLF))) { Log.Trace("Begin Process Data"); Log.Trace(DeviceHelper.CRLF + StringData); SendStringData(DeviceHelper.ACK.ToString(CultureInfo.InvariantCulture)); string[] allPatients = DeviceHelper.DeleteAllBlankLine(StringData, DeviceHelper.CR); Log.Trace("Result has {0} Patients", allPatients.Length); //Duyệt theo từng dòng foreach (string patient in allPatients) { string tempPatient = patient; //Nếu đúng với các ký tự bắt đầu thì xử lý: if (Validdata(patient)) { TestResult.TestDate = DateTime.Now.ToString("dd/MM/yyyy"); TestResult.Barcode = tempPatient.Substring(10, 16).Trim(); tempPatient = tempPatient.Substring(40); while (tempPatient.Length > 9) { string result = tempPatient.Substring(0, 9); string testName = result.Substring(0, 2).Trim(); string testValue = result.Substring(2, 7).Trim(); //Xử lý các ký tự thừa trong kết quả //Loại bỏ dấu "$" testValue = testValue.Replace("$", "").Replace("!", ""); //Loại bỏ các chữ cái in hoa và in thường trong chuỗi kết quả for (byte i = 65; i <= 90; i++) { testValue = testValue.Replace(Convert.ToChar(i).ToString(CultureInfo.InvariantCulture), ""). Replace(Convert.ToChar(i + 32).ToString(CultureInfo.InvariantCulture), ""); } //Thêm kết quả mới TestResult.Add(new ResultItem(testName, testValue)); //Cắt bỏ các dữ liệu vừa được xử lý tempPatient = tempPatient.Substring(9); //////////////Xử lý các thông số tính toán ////////////double iHdlc = -1, iTrig = -1, iChol = -1, iAlb = -1, iProT = -1, iBilt = -1, iBild = -1; ////////////foreach (ResultItem item in TestResult.Items) ////////////{ //////////// //BIL-Toàn phần //////////// if (item.TestName.Equals("10")) iBilt = TryToConvertToDouble(item.TestValue); //////////// //BIL-Trực tiếp //////////// if (item.TestName.Equals("11")) iBild = TryToConvertToDouble(item.TestValue); //////////// //Protein-T //////////// if (item.TestName.Equals("12")) iProT = TryToConvertToDouble(item.TestValue); //////////// //ALB //////////// if (item.TestName.Equals("15")) iAlb = TryToConvertToDouble(item.TestValue); //////////// //CHOL //////////// if (item.TestName.Equals("17")) iChol = TryToConvertToDouble(item.TestValue); //////////// //Trig //////////// if (item.TestName.Equals("16")) iTrig = TryToConvertToDouble(item.TestValue); //////////// //HDLC //////////// if (item.TestName.Equals("18")) iHdlc = TryToConvertToDouble(item.TestValue); ////////////} //////////////Tính toán //////////////Bil-Gián tiếp: ////////////if ((iBild > 0) && (iBilt > 0)) ////////////{ //////////// testName = "47"; //////////// testValue = (iBilt - iBild).ToString(); //////////// TestResult.Add(new ResultItem(testName, testValue)); ////////////} //////////////Globumin,Tỷ số A/G ////////////if ((iProT > 0) && (iAlb > 0)) ////////////{ //////////// //Globumin //////////// testName = "51"; //////////// testValue = (iProT - iAlb).ToString(); //////////// TestResult.Add(new ResultItem(testName, testValue)); //////////// //Tỷ số A/G //////////// testName = "49"; //////////// testValue = (iAlb/(iProT - iAlb)).ToString(); //////////// TestResult.Add(new ResultItem(testName, testValue)); ////////////} //////////////LDLC: ////////////if ((iChol > 0) && (iHdlc > 0) && (iTrig > 0)) ////////////{ //////////// testName = "50"; //////////// testValue = (iChol - (iTrig/2.2 + iHdlc)).ToString(); //////////// TestResult.Add(new ResultItem(testName, testValue)); ////////////} } ImportResults(); Log.Debug("Import Result Success For barocde:{0}", TestResult.Barcode); } } ClearData(); } } catch (Exception ex) { ClearData(); throw ex; } }
public override void ProcessRawData() { try { Log.Trace("Begin Process Data"); Log.Debug("Raw Data: {0}{1}", DeviceHelper.CRLF, StringData); if (!StringData.EndsWith(string.Format("{0}{0}", DeviceHelper.CRLF))) { return; } string[] strResutl = DeviceHelper.DeleteAllBlankLine(StringData, DeviceHelper.CRLF.ToCharArray()); //TestResult.TestDate = strResutl[5].Substring(0, 9).Trim(); string pTempTestDate = strResutl[strResutl.Length - 1].Substring(0, 9).Trim(); string[] tmpDate = pTempTestDate.Split('-'); string pTestDate = tmpDate[0]; pTestDate = GetMonth(pTestDate); TestResult.TestDate = string.Format("{0}/{1}/20{2}", tmpDate[1], pTestDate, tmpDate[2]); //Tìm chuỗi ID# - Nếu không có => Barcode = "" int iDrowNumber = GetRowIndex(strResutl, "ID#"); // Nếu kô tìm thấy => Barcode = "" nếu có lấy ID if (iDrowNumber == -1) { TestResult.Barcode = ""; iDrowNumber = GetRowIndex(strResutl, "SAMPLE"); if (iDrowNumber != -1) { TestResult.TestSequence = strResutl[iDrowNumber].Substring(6).Trim(); } } else { TestResult.Barcode = strResutl[iDrowNumber].Substring(3).Trim(); } // Trường hợp có kết quả thì xử lý if (iDrowNumber != -1) { // Nếu dòng thứ 2 có chứa CL thì lấy kết quả 1 dòng if (strResutl[iDrowNumber + 1].IndexOf("Cl") > 0) { string temResult = strResutl[iDrowNumber + 1]; AddResult(new ResultItem(temResult.Substring(0, 2).Trim(), temResult.Substring(2, 6).Trim())); AddResult(new ResultItem(temResult.Substring(9, 2).Trim(), temResult.Substring(11, 6).Trim())); AddResult(new ResultItem(temResult.Substring(17, 2).Trim(), temResult.Substring(19).Trim())); } else { string temResult = strResutl[iDrowNumber + 1]; AddResult(new ResultItem(temResult.Substring(0, 2).Trim(), temResult.Substring(2, 6).Trim())); AddResult(new ResultItem(temResult.Substring(9, 2).Trim(), temResult.Substring(11).Trim())); temResult = strResutl[iDrowNumber + 2]; AddResult(new ResultItem(temResult.Substring(0, 2).Trim(), temResult.Substring(2, 5).Trim())); //AddResult(new ResultItem(temResult.Substring(8, 2).Trim(), temResult.Substring(2, 6).Trim())); } } Log.Debug("Begin Import Result"); Log.Debug(ImportResults() ? "Import Result success" : "Error While Import Result"); ClearData(); } catch (Exception) { //throw ex; Log.Error("Co loi khi xu ly du lieu"); } }