using DevExpress.XtraEditors; using HL_FristAidPlatform_DTO; using HL_FristAidPlatform_Public; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Reflection; using System.Windows.Forms; namespace HL_FristAidPlatform_DynamicElectrocardiogram { public partial class Form_CheckInECGPatient : XtraForm { public Form_CheckInECGPatient() { InitializeComponent(); } /// /// 加载 /// /// /// private void Form_CheckInECGPatient_Load(object sender, EventArgs e) { GetEcgPatientList(); BindData(); } #region 绑定数据 /// /// 绑定数据 /// private void BindData() { BindSystemModule(); BindAmbulance(1); BindWristStrap(0); } /// /// 绑定所属系统模块 /// private void BindSystemModule() { try { string Url = string.Format("/api/admin/T_SYS_SystemModule/GetRightListByHospitalID?hospitalID={0}&isHaveTimeAxis=0", Information.Hospital.ID); DataTable ResultDT = DBHelpClass.Get(Url); if (ResultDT != null && ResultDT.Rows.Count > 0) { DataTable BindData = new DataTable(); BindData.Columns.Add("ID", Type.GetType("System.String")); BindData.Columns.Add("SystemName", Type.GetType("System.String")); BindData.Columns.Add("IconData", Type.GetType("System.Byte[]")); foreach (DataRow item in ResultDT.Rows) { DataRow newRow = BindData.NewRow(); newRow["ID"] = item["ID"]; newRow["SystemName"] = item["ShortName"] + "患者"; if (!string.IsNullOrEmpty(PublicClass.ToString(item["IconData"], ""))) { newRow["IconData"] = Convert.FromBase64String(item["IconData"].ToString()); } else { newRow["IconData"] = null; } BindData.Rows.Add(newRow); } listBox_SystemModule.DataSource = BindData; listBox_SystemModule.ValueMember = "ID"; listBox_SystemModule.DisplayMember = "SystemName"; } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定所属系统模块:\r\n" + ex); } } /// /// 绑定标签卡 /// /// 状态-1:全部0:空闲1:使用中2:维护中 private void BindWristStrap(int state) { try { string Url = string.Format("/api/base/T_Base_WristStrap?status={0}&deleteFlag=0", state); DataTable WristStrapDT = DBHelpClass.Get(Url); PublicClass.SetLookUpList(LUEdit_WristStrap, WristStrapDT, "ID", "Alias", true, "请选择"); } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定标签卡:\r\n" + ex); } } /// /// 绑定当前院区空闲的急救车 /// /// 急救车状态-1、全部,1、空闲,2、出车中,3、维修中,4、已报废 private void BindAmbulance(int state) { try { string Url = string.Format("/api/base/T_Base_Ambulance/GetListForState?state={0}&hospitalGuid={1}", state, Information.Hospital.GUID); DataTable ResultDT = DBHelpClass.Get(Url); PublicClass.SetLookUpList(lookUpEdit_Ambulance, ResultDT, "GUID", "PlateNumber", true, "请选择"); } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定当前院区空闲的急救车:\r\n" + ex); } } #endregion /// /// 获取当前心电患者列表 /// private void GetEcgPatientList() { try { if (PublicHelp.IsConnectNetwork()) { DataTable BindDT = new DataTable(); string guid = Guid.NewGuid().ToString(); string summary = Information.Hospital.Ecg_Summary; string encryption = Util.Encryption(summary); string authorKey = Information.Hospital.Ecg_AuthorKey; string appId = Information.Hospital.Ecg_AppId; string token = Information.Hospital.Ecg_Token; string Url = "http://113.200.102.99:20018/api/mPublicEDataBs";//Information.Hospital.Ecg_URL; string postText = "header[authorKey]=" + authorKey + "&header[appId]=" + appId + "&header[token]=" + token + "&header[ssid]" + "=" + guid + "&header[service]=GETACTIVEWARDPRO&header[summary]=" + encryption; var strJson = Util.ECGPostEncoding(Url, postText); EcgRoot rootObject = JsonConvert.DeserializeObject(strJson); if (rootObject.Result != null) { if (rootObject.Result.Count > 0) { BindDT = ListToDataTable(rootObject.Result); } } gridControl_List.DataSource = BindDT;//显示结果 } else { XtraMessageBox.Show("无法连接到Internet,因此无法获取急救车上患者信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "获取当前心电患者列表:\r\n" + ex); } } /// /// 选中行 /// /// /// private void gridControl_List_MouseClick(object sender, MouseEventArgs e) { try { #region 绑定详情 if (gridView_List.DataRowCount > 0) { int selectRow = gridView_List.GetSelectedRows()[0]; //标签卡号 string nid = PublicClass.ToString(gridView_List.GetRowCellValue(selectRow, "nid"), "").ToUpper(); LUEdit_WristStrap.Text = nid; } #endregion } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定详情:\r\n" + ex); } } /// /// 确认签入 /// /// /// private void btn_CheckIn_Click(object sender, EventArgs e) { try { if (gridView_List.DataRowCount > 0) { int selectRow = gridView_List.GetSelectedRows()[0]; //心电合同编号 string Wid = PublicClass.ToString(gridView_List.GetRowCellValue(selectRow, "wid"), ""); if (!string.IsNullOrEmpty(Wid)) { //设备编号 string Devid = PublicClass.ToString(gridView_List.GetRowCellValue(selectRow, "devid"), ""); //患者姓名 string Cname = PublicClass.ToString(gridView_List.GetRowCellValue(selectRow, "cname"), ""); //患者性别 string Sex = PublicClass.ToString(gridView_List.GetRowCellValue(selectRow, "sex"), ""); int SexCode = 0; switch (Sex) { case "男": SexCode = 1; break; case "女": SexCode = 2; break; default: SexCode = 0; break; } //患者年龄 int Age = PublicClass.ToInt32(gridView_List.GetRowCellValue(selectRow, "age"), 0); //身份证号码 string Ccno = PublicClass.ToString(gridView_List.GetRowCellValue(selectRow, "ccno"), ""); #region 保存信息 //验证 if (!DataVerification()) return; #region 保存患者信息 List list_Patient = new List(); T_Service_PatientDTO model_Patient = new T_Service_PatientDTO(); string Url = "api/service/T_Service_Patient"; //患者编号 model_Patient.GUID = Guid.NewGuid().ToString(); //所属系统模块 model_Patient.SystemModuleID = PublicClass.ToInt64(listBox_SystemModule.SelectedValue, 0); //所属院区编号 model_Patient.HospitalGuid = Information.Hospital.GUID; //创建人编号 model_Patient.CreatorID = Information.User.ID; //创建人 model_Patient.Creator = Information.User.FullName; //创建时间 model_Patient.CreationDate = PublicClass.DateTimeNow(); //编辑时间 model_Patient.EditTime = PublicClass.DateTimeNow(); //档案归属日期 model_Patient.RegisterTime = PublicClass.DateTimeNow(); //是否三无人员 model_Patient.Category = 0; //姓名 model_Patient.Name = Cname; //性别 model_Patient.Gender = SexCode; //年龄 model_Patient.Age = Age; //证件类型 model_Patient.Credentials_Type = "1"; //证件号码 model_Patient.IdentityCard = Ccno; #region 默认字段赋值 //急救状态 model_Patient.EmergencyState = 0; //绕行方式 1:未绕行 2:单绕 3:双绕 4:三绕 model_Patient.IsGreenChannel = (int)Enumerate.CircumferenceMode.未绕行; //是否上传到胸痛数据平台1是0否 model_Patient.CCPC_State = 0; //填报状态 model_Patient.Status = 1; //溶栓治疗 0:无 1:有 默认否 model_Patient.Thrombolysis = "0"; //是否介入治疗 0:否 1:是 默认否 model_Patient.Interventional_Therapy = "0"; #endregion //备注 model_Patient.Note = ""; //标签卡 long WristStrapID = PublicClass.ToInt64(LUEdit_WristStrap.EditValue, -1); model_Patient.WristStrapID = WristStrapID == -1 ? 0 : WristStrapID; //急救车 string AmbulanceGuid = PublicClass.ToString(lookUpEdit_Ambulance.EditValue, ""); model_Patient.AmbulanceGuid = AmbulanceGuid == "" ? "" : AmbulanceGuid; //心电合同号 model_Patient.WardshipId = Wid; //心电回执ID model_Patient.RecId = ""; //心电设备号 model_Patient.EqmtNo = Devid; //病案操作更新日志 model_Patient.Operation_Log = string.Format("{0} 由 {1} 创建了患者病案\r\n", DateTime.Now.ToString(PublicClass.TimeToString), Information.User.FullName); #endregion list_Patient.Add(model_Patient); ClientFactory httpClient = new HttpClientFactory(); Client client = httpClient.VisitFactory(); //访问 ListEntity t = client.Post(Url, list_Patient); #endregion if (t.Success) { //新增后更改标签卡和急救车的占用状态 #region 修改标签卡状态 Url = "/api/base/T_Base_WristStrap/UpdateStatus"; List listWristStrap = new List(); T_Base_WristStrapDTO modelWristStrap = new T_Base_WristStrapDTO(); modelWristStrap.ID = WristStrapID; modelWristStrap.CreationDate = PublicClass.DateTimeNow(); modelWristStrap.Status = 1;//使用中 listWristStrap.Add(modelWristStrap); //初始化两个工厂 ClientFactory httpClientWristStrap = new HttpClientFactory(); Client clientWristStrap = httpClientWristStrap.VisitFactory(); //访问 ListEntity tWristStrap = clientWristStrap.Post(Url, listWristStrap); #endregion #region 更改急救车信息 Url = "api/base/T_Base_Ambulance/UpdateState"; List listAmbulance = new List(); T_Base_AmbulanceDTO modelAmbulance = new T_Base_AmbulanceDTO(); modelAmbulance.GUID = AmbulanceGuid; modelAmbulance.State = 2; modelAmbulance.CreationDate = PublicClass.DateTimeNow(); listAmbulance.Add(modelAmbulance); //初始化两个工厂 ClientFactory httpClientAmbulance = new HttpClientFactory(); Client clientAmbulance = httpClientAmbulance.VisitFactory(); //访问 clientAmbulance.Post(Url, listAmbulance); #endregion XtraMessageBox.Show(string.Format("签入【急救车病人】信息成功!"), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } else { XtraMessageBox.Show("保存失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { XtraMessageBox.Show("请在上方列表先选择病人!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { XtraMessageBox.Show("当前没有急救病人!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "确认签入:\r\n" + ex); } } /// /// 数据有效性验证 /// private bool DataVerification() { string Cur_SystemModuleID = PublicClass.ToString(listBox_SystemModule.SelectedValue, "0"); if (Cur_SystemModuleID == "0") { XtraMessageBox.Show("请选择患者类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); listBox_SystemModule.Focus(); return false; } string AmbulanceGuid = PublicClass.ToString(lookUpEdit_Ambulance.EditValue, "-1"); if (AmbulanceGuid == "-1") { XtraMessageBox.Show("请选择急救车牌号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); lookUpEdit_Ambulance.Focus(); return false; } return true; } /// /// 将泛类型集合List类转换成DataTable /// /// 泛类型集合 /// public static DataTable ListToDataTable(List entitys) { //检查实体集合不能为空 if (entitys == null || entitys.Count < 1) { throw new Exception("需转换的集合为空"); } //取出第一个实体的所有Propertie Type entityType = entitys[0].GetType(); PropertyInfo[] entityProperties = entityType.GetProperties(); //生成DataTable的structure //生产代码中,应将生成的DataTable结构Cache起来,此处略 DataTable dt = new DataTable(); for (int i = 0; i < entityProperties.Length; i++) { dt.Columns.Add(entityProperties[i].Name); } //将所有entity添加到DataTable中 foreach (object entity in entitys) { //检查所有的的实体都为同一类型 if (entity.GetType() != entityType) { throw new Exception("要转换的集合元素类型不一致"); } object[] entityValues = new object[entityProperties.Length]; for (int i = 0; i < entityProperties.Length; i++) { entityValues[i] = entityProperties[i].GetValue(entity, null); } dt.Rows.Add(entityValues); } return dt; } #region 实体 /// /// /// public class ResultItem { /// /// 设备编号 /// public string wid { get; set; } /// /// 设备ID /// public string devid { get; set; } /// /// 患者姓名 /// public string cname { get; set; } /// /// 患者性别 /// public string sex { get; set; } /// /// 患者年龄 /// public string age { get; set; } /// /// 患者身份证号码 /// public string ccno { get; set; } /// /// 标签编号 /// public string nid { get; set; } } public class Header { /// /// /// public string errorCode { get; set; } /// /// 成功 /// public string errorMsg { get; set; } /// /// /// public string resultCode { get; set; } } public class EcgRoot { /// /// /// public List Result { get; set; } /// /// /// public Header header { get; set; } } #endregion } }