/// <summary> /// 删除医院 /// </summary> /// <param name="id">医院ID</param> /// <returns>是否删除成功</returns> public static bool DeleteHospital(int id) { bool isSuccess = false; using (MedicalBaseEntities context = new MedicalBaseEntities()) { try { List <Hospital> hospitalList = new List <Hospital>(); hospitalList = (from p in context.Hospitals where p.ID == id select p).ToList <Hospital>(); if (hospitalList.Count > 0) { context.DeleteObject(hospitalList[0]); context.SaveChanges(); isSuccess = true; } } catch { isSuccess = false; } } return(isSuccess); }
/// <summary> /// 清除所有日志信息 /// </summary> /// <returns>是否清除成功</returns> public bool ClearLogs() { bool isSuccess = false; try { using (System.Transactions.TransactionScope transactionScope = new System.Transactions.TransactionScope()) { using (MedicalBaseEntities context = new MedicalBaseEntities()) { foreach (var item in context.Log_Login) { context.DeleteObject(item); } context.SaveChanges(); } transactionScope.Complete(); } isSuccess = true; } catch { isSuccess = false; } return(isSuccess); }
/// <summary> /// 修改用户密码 /// </summary> /// <param name="name">用户名</param> /// <param name="newPassword">新密码</param> /// <returns>是否修改成功</returns> public static bool UpdateUserPassword(string name, string newPassword) { byte[] bytes = System.Text.Encoding.Default.GetBytes(newPassword); string strPassword = Convert.ToBase64String(bytes); bool isSucess = false; using (MedicalBaseEntities context = new MedicalBaseEntities()) { try { List <User> userList = new List <User>(); userList = (from p in context.Users where p.UserName == name select p).ToList <User>(); if (userList.Count > 0) { userList[0].UserName = name; userList[0].Password = strPassword; context.Users.ApplyCurrentValues(userList[0]); context.SaveChanges(); isSucess = true; } } catch (Exception ex) { isSucess = false; } } return(isSucess); }
/// <summary> /// 修改医院信息 /// </summary> /// <param name="name">医院名称</param> /// <param name="newHostpitalName">新医院名称</param> /// <param name="newDesciption">新医院描述</param> /// <returns>是否修改成功</returns> public static bool UpdateHospital(string name, string newHostpitalName, string newDesciption) { bool isSuccess = false; using (MedicalBaseEntities context = new MedicalBaseEntities()) { try { List <Hospital> hospitalList = new List <Hospital>(); hospitalList = (from p in context.Hospitals where p.HospitalName == name select p).ToList <Hospital>(); if (hospitalList.Count > 0) { hospitalList[0].Description = newDesciption; hospitalList[0].HospitalName = newHostpitalName; context.Hospitals.ApplyCurrentValues(hospitalList[0]); // context.Hospitals.AddObject(hospitalList[0]); context.SaveChanges(); isSuccess = true; } } catch { isSuccess = false; } } return(isSuccess); }
/// <summary> /// 删除用户 /// </summary> /// <param name="ID">用户ID</param> /// <returns>是否删除成功</returns> public static bool DeleteUser(int ID) { bool isSuccess = false; using (MedicalBaseEntities context = new MedicalBaseEntities()) { try { List <User> userList = new List <User>(); userList = (from p in context.Users where p.ID == ID select p).ToList <User>(); if (userList != null && userList.Count > 0) { context.DeleteObject(userList[0]); context.SaveChanges(); // context.CascadingDeleteOnSubmit(user); } isSuccess = true; } catch { isSuccess = false; } } return(isSuccess); }
/// <summary> /// 创建一家医院 /// </summary> /// <param name="name">医院名称</param> /// <param name="RegionName">医院所在区域</param> /// <param name="desciption">医院描述</param> /// <param name="message">相关信息</param> /// <returns>是否创建成功</returns> public static bool CreateHospital(string name, string RegionName, string desciption, out string message) { message = string.Empty; bool isSuccess = false; if (string.IsNullOrWhiteSpace(RegionName)) { return(false); } using (MedicalBaseEntities context = new MedicalBaseEntities()) { try { List <Hospital> hospitalList = new List <Hospital>(); hospitalList = (from p in context.Hospitals select p).ToList <Hospital>(); var hos = SiteManagement.GetHospital(name); if (hos == null) { Region region = GetRegion(RegionName); if (region == null) { return(false); } var newHospital = new Hospital(); newHospital.Description = desciption; newHospital.HospitalName = name; newHospital.RegionID = region.ID; // context.Hospitals.ApplyCurrentValues(newHospital); context.Hospitals.AddObject(newHospital); context.SaveChanges(); isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { // 出错信息返回 message = ex.Message.ToString(); isSuccess = false; } } return(isSuccess); }
/// <summary> /// 批量修改模板 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <param name="context">元数据</param> /// <param name="TEntity">具体类型</param> public static void CascadingDeleteOnSubmit <T>(this MedicalBaseEntities context, T TEntity) where T : class { if (context.Connection.State == ConnectionState.Closed) { context.Connection.Open(); } var entityType = TEntity.GetType(); var entityProperties = TEntity.GetType().GetProperties(); var associationProperties = entityProperties.Where( c => c.PropertyType.BaseType.Name == "RelatedEnd"); if (associationProperties.Count() != 0) { foreach (var _asso in associationProperties) { var _items = _asso.GetValue(TEntity, null); IEnumerable enumerable = (IEnumerable)_items; List <object> list = new List <object>(); foreach (var o in enumerable) { list.Add(o); } for (int i = 0; i < list.Count; i++) { object o = list[i]; CascadingDeleteOnSubmit(context, o); } } } try { var entityKeyObject = TEntity.GetType().GetProperty("EntityKey").GetValue(TEntity, null); var entityContainerName = entityKeyObject.GetType().GetProperty("EntityContainerName").GetValue(entityKeyObject, null); var entityKeyName = entityKeyObject.GetType().GetProperty("EntitySetName").GetValue(entityKeyObject, null); System.Data.EntityKeyMember[] KeyMembers = (System.Data.EntityKeyMember[])entityKeyObject.GetType().GetProperty("EntityKeyValues").GetValue(entityKeyObject, null); IEnumerable <KeyValuePair <string, object> > entityKeyValues = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>(KeyMembers[0].Key, KeyMembers[0].Value) }; string EntityKeyName = entityContainerName + "." + entityKeyName; EntityKey key = new EntityKey(EntityKeyName, entityKeyValues); var forDelete = context.GetObjectByKey(key); context.DeleteObject(forDelete); context.SaveChanges(); } catch (Exception ex) { throw ex; } }
/// <summary> /// 登陆信息写入日志 /// </summary> /// <param name="userID">用户ID</param> /// <param name="hospitalID">医院ID</param> /// <param name="detail">详细登陆信息</param> public static void WriteLogLogin(int userID, int hospitalID, string detail) { using (MedicalBaseEntities context = new MedicalBaseEntities()) { List <Log_Login> loginList = new List <Log_Login>(); loginList = (from p in context.Log_Login select p).ToList <Log_Login>(); var login = new Log_Login(); login.LoginDate = System.DateTime.UtcNow; login.UserID = userID; login.HospitalID = hospitalID; login.Detail = detail; context.Log_Login.AddObject(login); context.SaveChanges(); } }
/// <summary> /// 删除患者病例信息 /// </summary> /// <param name="reportIDList">病例列表</param> /// <returns>返回是否删除成功</returns> public bool RemoveReportSummationByReportID(string[] reportIDList) { bool isSucceed = false; try { using (System.Transactions.TransactionScope transactionScope = new System.Transactions.TransactionScope()) { using (MedicalBaseEntities context = new MedicalBaseEntities()) { foreach (var item in reportIDList) { int reportID = 0; try { reportID = Int32.Parse(item); } catch { return(false); } // 获得待删除的信息 Report_Summation reportToDelete = (from p in context.Report_Summation where p.ID == reportID select p).FirstOrDefault(); if (reportToDelete != null) { context.Report_Summation.DeleteObject(reportToDelete); context.SaveChanges(); } } } isSucceed = true; transactionScope.Complete(); } } catch (Exception) { isSucceed = false; } return(isSucceed); }
/// <summary> /// 修改医院信息 /// </summary> /// <param name="name">医院名称</param> /// <param name="newHostpitalName">新医院名称</param> /// <param name="newDesciption">新医院描述</param> /// <param name="message">返回信息</param> /// <returns>是否修改成功</returns> public static bool UpdateHospital(string name, string newHostpitalName, string newDesciption, out string message) { bool isSuccess = false; message = string.Empty; Hospital hos = GetHospital(newHostpitalName); if (hos != null) { message = "此医院: " + newDesciption + " 已经存在!"; return(false); } using (MedicalBaseEntities context = new MedicalBaseEntities()) { try { List <Hospital> hospitalList = new List <Hospital>(); hospitalList = (from p in context.Hospitals where p.HospitalName == name select p).ToList <Hospital>(); if (hospitalList.Count > 0) { hospitalList[0].Description = newDesciption; hospitalList[0].HospitalName = newHostpitalName; context.Hospitals.ApplyCurrentValues(hospitalList[0]); // context.Hospitals.AddObject(hospitalList[0]); context.SaveChanges(); isSuccess = true; } } catch (Exception ex) { message = "Error: " + ex.Message.ToString(); isSuccess = false; } } return(isSuccess); }
/// <summary> /// 修改用户密码 /// </summary> /// <param name="name">用户姓名</param> /// <param name="oringinalPassword">原始密码</param> /// <param name="newPassword">新密码</param> public static void UpdateUserPassword(string name, string oringinalPassword, string newPassword) { byte[] bytes = System.Text.Encoding.Default.GetBytes(oringinalPassword); string strPassword = Convert.ToBase64String(bytes); bytes = System.Text.Encoding.Default.GetBytes(newPassword); string strNewPassword = Convert.ToBase64String(bytes); using (MedicalBaseEntities context = new MedicalBaseEntities()) { List <User> userList = new List <User>(); userList = (from p in context.Users where p.UserName == name && p.Password == strPassword select p).ToList <User>(); if (userList.Count > 0) { userList[0].UserName = name; userList[0].Password = strNewPassword; context.Users.ApplyCurrentValues(userList[0]); context.SaveChanges(); } } }
/// <summary> /// 插入病例信息到数据库中 /// </summary> /// <param name="person">患者的个人基本信息</param> /// <param name="reportBinLiBanSuiZhuangTai">患者的疾病伴随状态信息</param> /// <param name="reportChuBuZhengDuan">患者的初步诊断信息</param> /// <param name="reportFuZhuYongYao">患者的辅助用药信息</param> /// <param name="reportJinMaiRongShuan">患者的静脉溶栓信息</param> /// <param name="reportJiWangBingShi">患者的既往病史信息</param> /// <param name="reportJieRuZhiLiao">患者的介入治疗信息</param> /// <param name="reportWeiJinXingJingMaiRongSuanLiYou">患者的未进行静脉溶栓的原因</param> /// <param name="reportWeiJinXingJiZhenGuanMaiJieRuZhiLiao">患者未进行急诊冠脉介入治疗的原因</param> /// <param name="reportZhuSuAndXianBingShi">患者的主诉和现病史信息</param> /// <param name="reportLinChuangZhuangGui">患者的临床转归信息</param> /// <param name="reportLinChuangZhengZhuang">患者的主诉和现病史信息</param> /// <param name="reportSummation">患者的基本信息</param> /// <param name="reportID">患者的病例ID</param> public void InsertReportSummation( Person person, Report_JiBingBanSuiZhuangTai reportBinLiBanSuiZhuangTai, Report_ChuBuZhenDuan reportChuBuZhengDuan, Report_FuZhuYongYao reportFuZhuYongYao, Report_JingMaiRongShuan reportJinMaiRongShuan, Report_JiWangBingShi reportJiWangBingShi, Report_JieRuZhiLiao reportJieRuZhiLiao, Report_WeiJinXingJingMaiRongSuanLiYou reportWeiJinXingJingMaiRongSuanLiYou, Report_WeiJinXingJiZhenGuanMaiJieRuZhiLiao reportWeiJinXingJiZhenGuanMaiJieRuZhiLiao, Report_ZhuSuAndXianBingShi reportZhuSuAndXianBingShi, Report_LinChuangZhuanGui reportLinChuangZhuangGui, Report_ZhuSuAndXianBingShi reportLinChuangZhengZhuang, Report_Summation reportSummation, out int reportID) { try { using (System.Transactions.TransactionScope transactionScope = new System.Transactions.TransactionScope()) { using (MedicalBaseEntities context = new MedicalBaseEntities()) { #region 患者的个人基本信息处理 Person personInDB = (from p in context.People where p.ID == person.ID select p).FirstOrDefault(); if (personInDB == null) { context.People.AddObject(person); } else { context.People.ApplyCurrentValues(person); } context.SaveChanges(); #endregion 患者的个人基本信息处理 #region 患者的疾病伴随状态信息处理 Report_JiBingBanSuiZhuangTai reportBinLiBanSuiZhuangTaiInDB = (from p in context.Report_JiBingBanSuiZhuangTai where p.ID == reportBinLiBanSuiZhuangTai.ID select p).FirstOrDefault(); if (reportBinLiBanSuiZhuangTaiInDB == null) { context.Report_JiBingBanSuiZhuangTai.AddObject(reportBinLiBanSuiZhuangTai); } else { context.Report_JiBingBanSuiZhuangTai.ApplyCurrentValues(reportBinLiBanSuiZhuangTai); } context.SaveChanges(); #endregion 患者的疾病伴随状态信息处理 #region 患者的初步诊断信息处理 Report_ChuBuZhenDuan reportChuBuZhengDuanInDB = (from p in context.Report_ChuBuZhenDuan where p.ID == reportChuBuZhengDuan.ID select p).FirstOrDefault(); if (reportChuBuZhengDuanInDB == null) { context.Report_ChuBuZhenDuan.AddObject(reportChuBuZhengDuan); } else { context.Report_ChuBuZhenDuan.ApplyCurrentValues(reportChuBuZhengDuan); } context.SaveChanges(); #endregion 患者的初步诊断信息处理 #region 患者的辅助用药信息处理 Report_FuZhuYongYao reportFuZhuYongYaoInDB = (from p in context.Report_FuZhuYongYao where p.ID == reportFuZhuYongYao.ID select p).FirstOrDefault(); if (reportFuZhuYongYaoInDB == null) { context.Report_FuZhuYongYao.AddObject(reportFuZhuYongYao); } else { context.Report_FuZhuYongYao.ApplyCurrentValues(reportFuZhuYongYao); } context.SaveChanges(); #endregion 患者的辅助用药信息处理 #region 患者的静脉溶栓信息处理 Report_JingMaiRongShuan reportJinMaiRongShuanInDB = (from p in context.Report_JingMaiRongShuan where p.ID == reportJinMaiRongShuan.ID select p).FirstOrDefault(); if (reportJinMaiRongShuanInDB == null) { context.Report_JingMaiRongShuan.AddObject(reportJinMaiRongShuan); } else { context.Report_JingMaiRongShuan.ApplyCurrentValues(reportJinMaiRongShuan); } context.SaveChanges(); #endregion 患者的静脉溶栓信息处理 #region 患者的既往病史信息处理 Report_JiWangBingShi reportJiWangBingShiInDB = (from p in context.Report_JiWangBingShi where p.ID == reportJiWangBingShi.ID select p).FirstOrDefault(); if (reportJiWangBingShiInDB == null) { context.Report_JiWangBingShi.AddObject(reportJiWangBingShi); } else { context.Report_JiWangBingShi.ApplyCurrentValues(reportJiWangBingShi); } context.SaveChanges(); #endregion 患者的既往病史信息处理 #region 患者的主诉和现病史信息处理 Report_ZhuSuAndXianBingShi reportLinChuangZhengZhuangInDB = (from p in context.Report_ZhuSuAndXianBingShi where p.ID == reportLinChuangZhengZhuang.ID select p).FirstOrDefault(); if (reportLinChuangZhengZhuangInDB == null) { context.Report_ZhuSuAndXianBingShi.AddObject(reportLinChuangZhengZhuang); } else { context.Report_ZhuSuAndXianBingShi.ApplyCurrentValues(reportLinChuangZhengZhuang); } context.SaveChanges(); #endregion 患者的主诉和现病史信息处理 #region 患者的介入治疗信息处理 Report_JieRuZhiLiao reportJieRuZhiLiaoInDB = (from p in context.Report_JieRuZhiLiao where p.ID == reportJieRuZhiLiao.ID select p).FirstOrDefault(); if (reportJieRuZhiLiaoInDB == null) { context.Report_JieRuZhiLiao.AddObject(reportJieRuZhiLiao); } else { context.Report_JieRuZhiLiao.ApplyCurrentValues(reportJieRuZhiLiao); } context.SaveChanges(); #endregion 患者的介入治疗信息处理 #region 患者的未进行静脉溶栓的原因处理 Report_WeiJinXingJingMaiRongSuanLiYou reportWeiJinXingJingMaiRongSuanLiYouInDB = (from p in context.Report_WeiJinXingJingMaiRongSuanLiYou where p.ID == reportWeiJinXingJingMaiRongSuanLiYou.ID select p).FirstOrDefault(); if (reportWeiJinXingJingMaiRongSuanLiYouInDB == null) { context.Report_WeiJinXingJingMaiRongSuanLiYou.AddObject(reportWeiJinXingJingMaiRongSuanLiYou); } else { context.Report_WeiJinXingJingMaiRongSuanLiYou.ApplyCurrentValues(reportWeiJinXingJingMaiRongSuanLiYou); } context.SaveChanges(); #endregion 患者的未进行静脉溶栓的原因处理 #region 患者未进行急诊冠脉介入治疗的原因处理 Report_WeiJinXingJiZhenGuanMaiJieRuZhiLiao reportWeiJinXingJiZhenGuanMaiJieRuZhiLia = (from p in context.Report_WeiJinXingJiZhenGuanMaiJieRuZhiLiao where p.ID == reportWeiJinXingJiZhenGuanMaiJieRuZhiLiao.ID select p).FirstOrDefault(); if (reportWeiJinXingJiZhenGuanMaiJieRuZhiLia == null) { context.Report_WeiJinXingJiZhenGuanMaiJieRuZhiLiao.AddObject(reportWeiJinXingJiZhenGuanMaiJieRuZhiLiao); } else { context.Report_WeiJinXingJiZhenGuanMaiJieRuZhiLiao.ApplyCurrentValues(reportWeiJinXingJiZhenGuanMaiJieRuZhiLiao); } context.SaveChanges(); #endregion 患者未进行急诊冠脉介入治疗的原因处理 #region 患者的主诉和现病史信息处理 Report_ZhuSuAndXianBingShi rreportZhuSuAndXianBingShiInDB = (from p in context.Report_ZhuSuAndXianBingShi where p.ID == reportZhuSuAndXianBingShi.ID select p).FirstOrDefault(); if (rreportZhuSuAndXianBingShiInDB == null) { context.Report_ZhuSuAndXianBingShi.AddObject(reportZhuSuAndXianBingShi); } else { context.Report_ZhuSuAndXianBingShi.ApplyCurrentValues(reportZhuSuAndXianBingShi); } context.SaveChanges(); #endregion 患者的主诉和现病史信息处理 #region 患者的临床转归信息处理 Report_LinChuangZhuanGui reportTreatResultInDB = (from p in context.Report_LinChuangZhuanGui where p.ID == reportLinChuangZhuangGui.ID select p).FirstOrDefault(); if (reportTreatResultInDB == null) { context.Report_LinChuangZhuanGui.AddObject(reportLinChuangZhuangGui); } else { context.Report_LinChuangZhuanGui.ApplyCurrentValues(reportLinChuangZhuangGui); } context.SaveChanges(); #endregion 患者的临床转归信息处理 #region 患者的基本信息处理 Report_Summation reportSummationInDB = (from p in context.Report_Summation where p.ID == reportSummation.ID select p).FirstOrDefault(); if (reportSummationInDB == null) { context.Report_Summation.AddObject(reportSummation); } else { context.Report_Summation.ApplyCurrentValues(reportSummation); } context.SaveChanges(); reportID = reportSummation.ID; #endregion 患者的基本信息处理 } transactionScope.Complete(); } } catch (Exception) { throw; } }
/// <summary> /// 创建用户 /// </summary> /// <param name="name">用户名称</param> /// <param name="password">密码</param> /// <param name="hospitalID">医院ID</param> /// <param name="roleID">角色信息</param> /// <param name="errorMessage">错误信息</param> /// <returns>是否创建成功</returns> public static bool CreateUser(string name, string password, int hospitalID, int roleID, ref string errorMessage) { bool isSuccess = false; byte[] bytes = System.Text.Encoding.Default.GetBytes(password); string strPassword = Convert.ToBase64String(bytes); using (MedicalBaseEntities context = new MedicalBaseEntities()) { try { List <User> userList = new List <User>(); userList = (from p in context.Users where p.UserName == name select p).ToList <User>(); if (userList.Count == 0) { List <SiteUser> siteUser = GetAllUserByHospitalID(hospitalID, roleID); if (siteUser != null && roleID == 2) { if (siteUser.Count > 0) { errorMessage = siteUser[0].Hospital.HospitalName + ": 已经存在一个管理员,此次不能再添加新管理员!!"; return(false); } } else if (siteUser != null && roleID == 3) { if (siteUser.Count > 3) { errorMessage = siteUser[0].Hospital.HospitalName + ": 已经达到用户使用上限,此次不能再添加新用户!!"; return(false); } } // 增加用户基本信息 Person newPerson = new Person(); newPerson.ID = Guid.NewGuid(); newPerson.Name = name; newPerson.CreateDate = System.DateTime.UtcNow; newPerson.UpdatedDate = System.DateTime.UtcNow; context.People.AddObject(newPerson); context.SaveChanges(); // 增加用户 User newUser = new User(); newUser.PersonID = newPerson.ID; newUser.UserName = name; newUser.Password = strPassword; newUser.HospitalID = hospitalID; newUser.RoleID = roleID; context.Users.AddObject(newUser); context.SaveChanges(); isSuccess = true; } else { errorMessage = "此用户已存在!!"; return(false); } } catch (Exception ex) { errorMessage = ex.Message.ToString(); isSuccess = false; } } return(isSuccess); }