StableVersion4.3/HL_FristAidPlatform_Apoplexy/Screen/UserControl/UC_PhysicaAndECG.cs

395 lines
14 KiB
C#

using DevExpress.XtraEditors;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_Public;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HL_FristAidPlatform_Apoplexy
{
public partial class UC_PhysicaAndECG : UserControl
{
public string patientGuid;
public string flag;
public string ecgFile;
public UC_PhysicaAndECG(string _patientGuid, string _flag)
{
InitializeComponent();
patientGuid = _patientGuid;
flag = _flag;
}
private void UC_PhysicaAndECG_Load(object sender, EventArgs e)
{
GetScreenPhysicalFitness();
}
/// <summary>
/// 获取体格检测及心电图
/// </summary>
public void GetScreenPhysicalFitness()
{
ScreenPhysicalFitnessDTO dto = new ScreenPhysicalFitnessDTO();
string url = string.Format("api/service/T_Service_ApoplexyScreen/GetScreenPhysicalFitness?patientGuid={0}&flag={1}", patientGuid, flag);
dto = DBHelpClass.GetDateModel<ScreenPhysicalFitnessDTO>(url);
if (dto != null)
{
ecgFile = dto.ECGFile == null ? null : dto.ECGFile.ToString();
txt_SignScreener.Text = dto.SignScreener;
time_SignInspectionTime.TimeValue = SetTimeValue(dto.SignInspectionTime);
txt_Height.Text = dto.Height;
txt_Weight.Text = dto.Weight;
txt_BMI.Text = dto.BMI;
txt_Waistline.Text = dto.Waistline;
txt_MeasurementScreener.Text = dto.MeasurementScreener;
time_MeasurementInspectionTime.TimeValue = SetTimeValue(dto.MeasurementInspectionTime);
txt_SBPOne.Text = dto.SBPOne;
txt_DBPOne.Text = dto.DBPOne;
txt_PulseOne.Text = dto.PulseOne;
txt_SBPTwo.Text = dto.SBPTwo;
txt_DBPTwo.Text = dto.DBPTwo;
txt_PulseTwo.Text = dto.PulseTwo;
txt_StethoscopeScreener.Text = dto.StethoscopeScreener;
time_StethoscopeInspectionTime.TimeValue = SetTimeValue(dto.StethoscopeInspectionTime);
radio_CardiacMurmur.EditValue = dto.CardiacMurmur;
radio_Rhythm.EditValue = dto.Rhythm;
time_ECGInspectionTime.TimeValue = SetTimeValue(dto.ECGInspectionTime);
txt_ECGScreener.Text = dto.ECGScreener;
radio_InspectionResults.EditValue = dto.InspectionResults;
radio_AbnormalResults.EditValue = dto.AbnormalResults;
txt_ECGConclusion.Text = dto.ECGConclusion;
if (ecgFile != null && ecgFile.Length > 0)
{
bylbl_ecg.Visible = true;
}
else
{
bylbl_ecg.Visible = false;
}
}
}
/// <summary>
/// 保存体格检测及心电图
/// </summary>
public void SaveScreenPhysicalFitness()
{
try
{
ScreenPhysicalFitnessDTO dto = new ScreenPhysicalFitnessDTO();
List<ScreenPhysicalFitnessDTO> list = new List<ScreenPhysicalFitnessDTO>();
dto.ECGConclusion = txt_ECGConclusion.Text;
dto.ECGFile = ecgFile;
dto.Flag = flag;
dto.PatientGUID = patientGuid;
dto.SignScreener = txt_SignScreener.Text.Trim();
dto.SignInspectionTime = GetTimeValue(time_SignInspectionTime);
dto.Height = txt_Height.Text.Trim();
dto.Weight = txt_Weight.Text.Trim();
dto.BMI = txt_BMI.Text.Trim();
dto.Waistline = txt_Waistline.Text.Trim();
dto.MeasurementScreener = txt_MeasurementScreener.Text.Trim();
dto.MeasurementInspectionTime = GetTimeValue(time_MeasurementInspectionTime);
dto.SBPOne = txt_SBPOne.Text.Trim();
dto.DBPOne = txt_DBPOne.Text.Trim();
dto.PulseOne = txt_PulseOne.Text.Trim();
dto.SBPTwo = txt_SBPTwo.Text.Trim();
dto.DBPTwo = txt_DBPTwo.Text.Trim();
dto.PulseTwo = txt_PulseTwo.Text.Trim();
dto.StethoscopeScreener = txt_StethoscopeScreener.Text.Trim();
dto.StethoscopeInspectionTime = GetTimeValue(time_StethoscopeInspectionTime);
dto.CardiacMurmur = GetEditValue(radio_CardiacMurmur);
dto.Rhythm = GetEditValue(radio_Rhythm);
dto.ECGInspectionTime = GetTimeValue(time_ECGInspectionTime);
dto.ECGScreener = txt_ECGScreener.Text.Trim();
dto.InspectionResults = GetEditValue(radio_InspectionResults);
dto.AbnormalResults = GetEditValue(radio_AbnormalResults);
dto.CreateID = Information.User.ID;
list.Add(dto);
string Url = "api/service/T_Service_ApoplexyScreen/SaveScreenPhysicalFitness";
//初始化两个工厂
ClientFactory<ScreenPhysicalFitnessDTO> httpClient = new HttpClientFactory<ScreenPhysicalFitnessDTO>();
Client<ScreenPhysicalFitnessDTO> client = httpClient.VisitFactory();
//访问
ListEntity<ScreenPhysicalFitnessDTO> t = client.Post(Url, list);
if (t.Success)
{
if (!string.IsNullOrEmpty(t.DataString))
{
if (t.DataString.Contains("Success"))
{
JObject jo = (JObject)JsonConvert.DeserializeObject(t.DataString);
string msg = jo["Msg"].ToString();
if (!string.IsNullOrEmpty(msg))
{
XtraMessageBox.Show(msg);
GetScreenPhysicalFitness();
}
}
else
{
string msg1 = t.DataString.Replace("/", "").Replace(@"\", "").Replace("\"", "");
XtraMessageBox.Show(msg1);
}
}
else
{
XtraMessageBox.Show("保存失败");
}
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取单选组件value
/// </summary>
/// <param name="radio"></param>
/// <returns></returns>
public string GetEditValue(RadioGroup radio)
{
string value = "";
if (radio.SelectedIndex > -1 && radio.EditValue.ToString() != null)
value = radio.EditValue.ToString();
return value;
}
/// <summary>
/// 获取时间组件value
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public string GetTimeValue(TimeControl time)
{
string value = "";
if (!string.IsNullOrEmpty(time.TimeValue))
value = Convert.ToDateTime(time.TimeValue).ToString("yyyy-MM-dd");
return value;
}
/// <summary>
/// 设置组件TimeValue
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public string SetTimeValue(string time)
{
string value = "";
if (!string.IsNullOrEmpty(time))
value = time;
return value;
}
/// <summary>
/// 危急值预警:文字变色
/// </summary>
/// <param name="text"></param>
/// <param name="value1"></param>
/// <param name="value2"></param>
public void CriticalValue(TextEdit text, int value1, int value2)
{
if (!string.IsNullOrEmpty(text.Text))
{
if (int.Parse(text.Text) < value1 || int.Parse(text.Text) > value2)
{
text.ForeColor = Color.Red;
}
else
{
text.ForeColor = Color.Black;
}
}
}
private void txt_SBPOne_EditValueChanged(object sender, EventArgs e)
{
CriticalValue(txt_SBPOne, 90, 139);
}
private void txt_DBPOne_EditValueChanged(object sender, EventArgs e)
{
CriticalValue(txt_DBPOne, 60, 89);
}
private void txt_PulseOne_EditValueChanged(object sender, EventArgs e)
{
CriticalValue(txt_PulseOne, 60, 100);
}
private void txt_SBPTwo_EditValueChanged(object sender, EventArgs e)
{
CriticalValue(txt_SBPTwo, 90, 139);
}
private void txt_DBPTwo_EditValueChanged(object sender, EventArgs e)
{
CriticalValue(txt_DBPTwo, 60, 89);
}
private void txt_PulseTwo_EditValueChanged(object sender, EventArgs e)
{
CriticalValue(txt_PulseTwo, 60, 100);
}
private void bylbl_ecg_Click(object sender, EventArgs e)
{
byte[] image = Convert.FromBase64String(ecgFile);
HL_FristAidPlatform_MultiSystemPublic.Form_ImageShow frm = new HL_FristAidPlatform_MultiSystemPublic.Form_ImageShow(image);
frm.ShowDialog();
}
private void sbutton_ECG_Click(object sender, EventArgs e)
{
#region
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Image Files(*.JPG;*.PNG;*.JPEG;;*.BMP)|*.JPG;*.PNG;;*.BMP;*.JPEG";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
int Config109 = PublicClass.ToInt32(PublicClassForDataBase.Config109, 5);
string FileName = openFileDialog.FileName;
if (PublicClass.GetFileSize(FileName) <= Config109)
{
FileInfo file = new FileInfo(FileName);
Bitmap bitmap = new Bitmap(FileName);
ecgFile = file.Extension;
if (ecgFile.ToLower() == ".png")
{
ecgFile = PublicClass.Png2String(bitmap);
}
else
{
ecgFile = PublicClass.Jpeg2String(bitmap);
}
bylbl_ecg.Visible = true;
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "上传心电图:\r\n" + ex);
}
#endregion
}
}
/// <summary>
/// 身高
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txt_Height_EditValueChanged(object sender, EventArgs e)
{
string pattern = @"^[-+]?\d+(\.\d+)?$";
bool isMatch = Regex.IsMatch(txt_BMI.Text, pattern);
if (isMatch)
{
double bmi = BMItxt();
if (bmi == 0)
{
txt_BMI.Text = "";
}
else
{
txt_BMI.Text = bmi.ToString("0.00") + "";
}
}
}
/// <summary>
/// 体重
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txt_Weight_EditValueChanged(object sender, EventArgs e)
{
string pattern = @"^[-+]?\d+(\.\d+)?$";
bool isMatch = Regex.IsMatch(txt_BMI.Text, pattern);
if (isMatch)
{
double bmi = BMItxt();
if (bmi == 0)
{
txt_BMI.Text = "";
}
else
{
txt_BMI.Text = bmi.ToString("0.00") + "";
}
}
}
/// <summary>
/// BMI
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txt_BMI_EditValueChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txt_BMI.Text + ""))
{
if (double.Parse(txt_BMI.Text.ToString()) > 23.9 || double.Parse(txt_BMI.Text.ToString()) < 18.5)
{
txt_BMI.ForeColor = Color.Red;
}
else
{
txt_BMI.ForeColor = Color.Black;
}
}
}
public double BMItxt()
{
double bmi = 0;
double height = 0;
double weight = 0;
if (!string.IsNullOrEmpty(txt_Height.Text.Trim() + ""))
{
if (double.Parse(txt_Height.Text.Trim()) > 0)
{
height = double.Parse(txt_Height.Text.Trim()) / 100;
}
}
if (!string.IsNullOrEmpty(txt_Weight.Text.Trim() + ""))
{
if (double.Parse(txt_Weight.Text.Trim()) > 0)
{
weight = double.Parse(txt_Weight.Text.Trim());
}
}
if (height > 0 && weight > 0)
{
bmi = weight / (height * height);
}
return bmi;
}
}
}