public Response <List <DTO.ConversationMessageReturnDTO> > GetMessages(int ChannelID, int CurrentPage, int PageSize) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { int totalCount = 0; Response <List <DTO.ConversationMessageReturnDTO> > result = new Response <List <DTO.ConversationMessageReturnDTO> >(); var query = from message in db.Set <ConversationMessage>().AsQueryable().Where(a => a.IsDeleted == false) where message.ConversationRoomID == ChannelID group message by message.MessageSeq into gps select new DTO.ConversationMessageReturnDTO() { MsgSeq = gps.Key, FromAccount = gps.FirstOrDefault().UserID, ToGroupId = gps.FirstOrDefault().ConversationRoomID.ToString(), MsgTime = gps.FirstOrDefault().MessageTime, MsgBody = gps.OrderBy(a => a.MessageIndex).Select(a => a.MessageContent).ToList(), }; query = query.OrderBy(a => new { a.MsgTime }); var fTotal = query.FutureCount(); var fList = query.Skip((CurrentPage - 1) * PageSize).Take(PageSize).Future(); totalCount = fTotal.Value; result.Data = fList.ToList(); result.Total = totalCount; return(result); } }
/// <summary> /// 获取医生列表 /// 日期:2016年7月29日 /// </summary> /// <param name="PageIndex">页码</param> /// <param name="PageSize">分页大小</param> /// <returns></returns> public Response <List <DTO.HospitalDto> > GetPageList( int PageIndex = 1, int PageSize = int.MaxValue, string Keyword = "" ) { Keyword = Keyword + ""; using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var query = from hosp in db.Hospitals orderby hosp.ModifyTime descending where Keyword == "" || (Keyword != "" && (hosp.HospitalName.Contains(Keyword) || hosp.Intro.Contains(Keyword))) select new DTO.HospitalDto { Address = hosp.Address, Email = hosp.Email, HospitalID = hosp.HospitalID, HospitalName = hosp.HospitalName, ImageUrl = hosp.ImageUrl, Intro = hosp.Intro, License = hosp.License, LogoUrl = hosp.LogoUrl, PostCode = hosp.PostCode, Telephone = hosp.Telephone }; Response <List <DTO.HospitalDto> > result = new Response <List <HospitalDto> >(); int total = 0; result.Data = query.Pager(out total, PageIndex, PageSize); result.Total = total; return(result); } }
/// <summary> /// 获取会员电子病历列表 /// </summary> /// <param name="PageIndex">页码</param> /// <param name="PageSize">分页大小</param> /// <returns></returns> public Response <List <UserMemberEMRDTO> > GetPatientEMRPageList( string memberId, int pageIndex = 1, int pageSize = int.MaxValue, string keyword = null ) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var query = from m in db.UserMemberEMRs join a in db.UserMembers on m.MemberID equals a.MemberID where m.MemberID == memberId && m.IsDeleted == false orderby m.Date descending select new UserMemberEMRDTO { UserMemberEMRID = m.UserMemberEMRID, MemberID = m.MemberID, MemberName = a.MemberName, Date = m.Date, EMRName = m.EMRName, HospitalName = m.HospitalName }; if (!string.IsNullOrEmpty(keyword)) { query = query.Where(m => m.EMRName.Contains(keyword)); } Response <List <UserMemberEMRDTO> > result = new Response <List <UserMemberEMRDTO> >(); int total = 0; result.Data = query.Pager(out total, pageIndex, pageSize); result.Total = total; return(result); } }
/// <summary> /// 更新一条记录 /// 日期:2016年7月29日 /// </summary> /// <param name="model"></param> /// <returns></returns> public virtual bool Update(TEntity model) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { return(this.PreUpdate(db, model).SaveChanges() > 0 ? true : false); } }
/// <summary> /// 获取患者历史就诊记录 /// </summary> /// <param name="request"></param> /// <returns></returns> public Response <List <DTO.UserOPDRegisterDTO> > GetPatientVisitList(string OPDRegisterID, string MemberID, int PageIndex, int PageSize) { using (DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var query = from opd in db.Set <UserOPDRegister>().Where(a => a.IsDeleted == false && (a.OPDRegisterID != OPDRegisterID || string.IsNullOrEmpty(OPDRegisterID)) && a.MemberID == MemberID) join room in db.Set <Entity.ConversationRoom>() on opd.OPDRegisterID equals room.ServiceID join medi in db.Set <UserMedicalRecord>().Where(a => a.IsDeleted == false && a.MemberID == MemberID) on opd.OPDRegisterID equals medi.OPDRegisterID into medileftjoin from mediifEmpty in medileftjoin.DefaultIfEmpty() join doctor in db.Set <XuHos.Entity.Doctor>().Where(a => a.IsDeleted == false) on opd.DoctorID equals doctor.DoctorID join dept in db.Set <HospitalDepartment>().Where(a => a.IsDeleted == false) on doctor.DepartmentID equals dept.DepartmentID join hosp in db.Set <Hospital>().Where(a => a.IsDeleted == false) on doctor.HospitalID equals hosp.HospitalID orderby room.BeginTime descending select new DTO.UserOPDRegisterDTO { OPDRegisterID = opd.OPDRegisterID, RegDate = opd.RegDate, OPDDate = opd.OPDDate, OPDType = opd.OPDType, OPDBeginTime = opd.OPDBeginTime, OPDEndTime = opd.OPDEndTime, Room = new DTO.ConversationRoomDTO() { TotalTime = room.TotalTime, Enable = room.Enable, Duration = room.Duration, ChargingState = room.ChargingState, RoomState = room.RoomState, //状态 ChannelID = room.ChannelID, //房间号码 EndTime = room.EndTime, //结束时间 Priority = room.Priority }, UserMedicalRecord = new UserMedicalRecordDTO() { PastMedicalHistory = mediifEmpty.PastMedicalHistory, PreliminaryDiagnosis = mediifEmpty.PreliminaryDiagnosis, PresentHistoryIllness = mediifEmpty.PresentHistoryIllness, Sympton = mediifEmpty.Sympton, Advised = mediifEmpty.Advised, AllergicHistory = mediifEmpty.AllergicHistory }, Doctor = new DTO.DoctorDto() { DoctorName = doctor.DoctorName, DepartmentName = doctor.DepartmentName, DoctorID = doctor.DoctorID, DepartmentID = doctor.DepartmentID, HospitalID = hosp.HospitalID, HospitalName = hosp.HospitalName } }; query = query.OrderByDescending(t => t.OPDDate); Response <List <DTO.UserOPDRegisterDTO> > result = new Response <List <DTO.UserOPDRegisterDTO> >(); int Total = 0; result.Data = query.Pager <DTO.UserOPDRegisterDTO>(out Total, PageIndex, PageSize); result.Total = Total; return(result); } }
/// <summary> /// 获取记录数(不含已删除) /// 作者:曾璐 /// </summary> /// <param name="where">查询条件</param> /// <returns></returns> public int Count(Expression <Func <TEntity, bool> > where) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { return(db.Set <TEntity>().Where(where).Where(a => a.IsDeleted == false).Count()); } }
/// <summary> /// 通过主键获取一条记录(不含已删除) /// 日期:2016年7月29日 /// </summary> /// <param name="ID">主键</param> /// <returns></returns> public virtual TEntity Single(string ID, List <Expression <Func <TEntity, object> > > includes = null) { if (_PK.Count <= 0) { throw new Exception("没有设置主键"); } if (_PK.Count > 1) { throw new Exception("不支持复合主键"); } using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { IQueryable <TEntity> cities = db.Set <TEntity>(); ParameterExpression param = Expression.Parameter(typeof(TEntity), "TEntity"); Expression left = Expression.Property(param, typeof(TEntity).GetProperty(_PK[0])); Expression right = Expression.Constant(ID); Expression filter = Expression.Equal(left, right); var query = db.Set <TEntity>().Where(Expression.Lambda <Func <TEntity, bool> >(filter, param)).Where(a => a.IsDeleted == false); if (includes != null) { query = includes.Aggregate(query, (current, include) => current.Include(include)); } var result = query.SingleOrDefault(); return(result); } }
/// <summary> /// 通过表达式删除记录(物理删除) /// 日期:2016年7月29日 /// </summary> /// <param name="where">查询条件</param> /// <returns></returns> public bool Delete(Expression <Func <TEntity, bool> > where) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { return(db.Set <TEntity>().Where(where).Delete() > 0 ? true : false); } }
/// <summary> /// 更新一条记录(部分更新) /// 日期:2016年7月29日 /// </summary> /// <param name="updateExpress">更新表达式)</param> /// <returns></returns> public virtual bool Update(Expression <Func <TEntity, bool> > where, Expression <Func <TEntity, TEntity> > updateExpress) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { return(db.Set <TEntity>().Where(where).Update(updateExpress) > 0 ? true : false); } }
public Response <List <ResponseHospitalBaseDTO> > GetCooperativeHospitals( int PageIndex = 1, int PageSize = int.MaxValue, string Keyword = "") { Keyword = Keyword + ""; using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var query = from hosp in db.Hospitals orderby hosp.ModifyTime descending where hosp.IsCooperation == true && hosp.IsShowInWeb == true && hosp.IsDeleted == false && (Keyword == "" || (Keyword != "" && (hosp.HospitalName.Contains(Keyword) || hosp.Intro.Contains(Keyword)))) select new DTO.ResponseHospitalBaseDTO { HospitalID = hosp.HospitalID, HospitalName = hosp.HospitalName, LogoUrl = hosp.LogoUrl, ImageUrl = hosp.ImageUrl, ListImageUrl = hosp.ListImageUrl, Mp4Url = hosp.Mp4Url }; Response <List <ResponseHospitalBaseDTO> > result = new Response <List <ResponseHospitalBaseDTO> >(); int total = 0; result.Data = query.Pager(out total, PageIndex, PageSize); result.Total = total; return(result); } }
/// <summary> /// 新增一条记录 /// 日期:2016年7月29日 /// </summary> /// <param name="model"></param> /// <returns></returns> public virtual bool Insert(params TEntity[] model) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { return(this.PreInsert(db, model).SaveChanges() > 0 ? true : false); } }
/// <summary> /// 获取分页 /// 日期:2016年7月29日 /// </summary> /// <typeparam name="TResult">返回结果类型</typeparam> /// <typeparam name="TKey">排序类型</typeparam> /// <param name="where">插叙条件</param> /// <param name="orderBy">排序</param> /// <param name="select">返回结果映射</param> /// <param name="PageIndex">页码</param> /// <param name="PageSize">分页大小</param> /// <returns></returns> public virtual List <TEntity> Select( out int totalCount, int?PageIndex = 0, int?PageSize = 10, List <Expression <Func <TEntity, object> > > includes = null, Expression <Func <TEntity, bool> > where = null, Expression <Func <TEntity, object> > orderBy = null) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { List <TEntity> result = new List <TEntity>(); var query = db.Set <TEntity>().AsQueryable().Where(a => a.IsDeleted == false); if (includes != null) { query = includes.Aggregate(query, (current, include) => current.Include(include)); } #region 增加查询条件 if (where != null) { //许光丽 修改 (上面已经是 db.Set<TEntity>() 了) //query = db.Set<TEntity>().Where(where); query = query.Where(where); } #endregion #region 设置排序 if (orderBy != null) { query = query.OrderByDescending(orderBy); } else { query = query.OrderByDescending(a => new { a.CreateTime }); } #endregion #region 设置分页 if (PageSize.HasValue && PageIndex.HasValue) { var fTotal = query.FutureCount(); var fList = query.Skip((PageIndex.Value - 1) * PageSize.Value).Take(PageSize.Value).Future(); totalCount = fTotal.Value; return(fList.ToList()); } else { var fTotal = query.FutureCount(); var fList = query.Future(); totalCount = fTotal.Value; return(fList.ToList()); } #endregion } }
/// <summary> /// 开 /// </summary> /// <param name="OutID"></param> /// <param name="TableName"></param> /// <returns></returns> public bool Exists(string OutID, string TableName, XuHos.Common.Enum.EnumDereplicationType DereplicationType) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var id = db.SysDereplications.Where(a => a.OutID == OutID && a.TableName == TableName && a.DereplicationType == DereplicationType).Select(i => i.SysDereplicationID).FirstOrDefault(); return(string.IsNullOrEmpty(id) ? false : true); } }
public bool IsChildFor(string parentOrgID, string childOrgID) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var p = db.Hospitals.Where(hosp => !hosp.IsDeleted && hosp.HospitalID == parentOrgID).Select(hosp => hosp.Path).FirstOrDefault(); var c = db.Hospitals.Where(hosp => !hosp.IsDeleted && hosp.HospitalID == childOrgID).Select(hosp => hosp.Path).FirstOrDefault(); return(c?.StartsWith(p ?? "--NOT_EXISTS--") ?? false); } }
/// <summary> /// 获取会员电子病历列表 /// </summary> /// <param name="PageIndex">页码</param> /// <param name="PageSize">分页大小</param> /// <returns></returns> public Response <List <UserMemberEMRDTO> > GetDoctorMemberEMRs( string doctorID, string memberID, string doctormemberID, int pageIndex = 1, int pageSize = int.MaxValue, string keyword = null ) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var query = from m in db.UserMemberEMRs join a in db.UserMembers on m.MemberID equals a.MemberID join b in db.DoctorMembers on m.MemberID equals b.MemberID join userfile in db.UserFiles.Where(a => a.IsDeleted == false).GroupBy(a => a.OutID) on m.UserMemberEMRID equals userfile.Key into leftJoinUserFiles from userfileIfEmpty in leftJoinUserFiles.DefaultIfEmpty() where b.DoctorID == doctorID && m.IsDeleted == false orderby m.Date descending select new UserMemberEMRDTO { UserMemberEMRID = m.UserMemberEMRID, MemberID = m.MemberID, DoctorMemberID = b.DoctorMemberID, MemberName = a.MemberName, Date = m.Date, EMRName = m.EMRName, HospitalName = m.HospitalName, Remark = m.Remark, Files = userfileIfEmpty.OrderBy(a => a.CreateTime).Select(a => new UserFileDTO { FileUrl = a.FileUrl, }).ToList() }; if (!string.IsNullOrEmpty(doctormemberID)) { query = query.Where(m => m.DoctorMemberID == doctormemberID); } if (!string.IsNullOrEmpty(memberID)) { query = query.Where(m => m.MemberID == memberID); } if (!string.IsNullOrEmpty(keyword)) { query = query.Where(m => m.EMRName.Contains(keyword)); } Response <List <UserMemberEMRDTO> > result = new Response <List <UserMemberEMRDTO> >(); int total = 0; result.Data = query.Pager(out total, pageIndex, pageSize); result.Total = total; return(result); } }
public string[] GetChildrenIDList(string orgId, EnumOrgType?type = null) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var root = db.Hospitals.Where(x => x.HospitalID == orgId).Select(x => x.Path).FirstOrDefault(); var q = db.Hospitals.Where(x => x.Path.StartsWith(root)); if (type.HasValue) { q = q.Where(x => x.OrgType == type); } return(q.Select(x => x.HospitalID).ToArray()); } }
/// <summary> /// 通过表达式获取一条记录(不含已删除) /// 日期:2016年7月29日 /// </summary> /// <param name="where">查询条件</param> /// <returns></returns> public TEntity Single(Expression <Func <TEntity, bool> > where, List <Expression <Func <TEntity, object> > > includes = null) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var query = db.Set <TEntity>().Where(where).Where(a => a.IsDeleted == false); if (includes != null) { query = includes.Aggregate(query, (current, include) => current.Include(include)); } var result = query.FirstOrDefault(); return(result); } }
/// <summary> /// 通过主键判断记录是否存在(不含已删除) /// 日期:2016年7月29日 /// </summary> /// <param name="ID">主键</param> /// <returns></returns> public virtual bool Exists(string ID) { if (_PK.Count <= 0) { throw new Exception("没有设置主键"); } if (_PK.Count > 1) { throw new Exception("不支持复合主键"); } using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { IQueryable <TEntity> cities = db.Set <TEntity>(); ParameterExpression param = Expression.Parameter(typeof(TEntity), "TEntity"); Expression left = Expression.Property(param, typeof(TEntity).GetProperty(_PK[0])); Expression right = Expression.Constant(ID); Expression filter = Expression.Equal(left, right); return(db.Set <TEntity>().Where(Expression.Lambda <Func <TEntity, bool> >(filter, param)).Where(a => a.IsDeleted == false).Count() > 0 ? true : false); } }
public bool Done(string SysDereplicationID, bool Success) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { SysDereplication derep = db.SysDereplications.Where(a => a.SysDereplicationID == SysDereplicationID).FirstOrDefault(); if (derep != null) { if (Success) { derep.SuccessCount++; } else { derep.FailCount++; } return(db.SaveChanges() > 0); } } return(false); }
public bool Done(string OutID, string TableName, XuHos.Common.Enum.EnumDereplicationType DereplicationType, bool Success) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { SysDereplication derep = db.SysDereplications.Where(a => a.OutID == OutID && a.TableName == TableName && a.DereplicationType == DereplicationType).FirstOrDefault(); if (derep != null) { if (Success) { derep.SuccessCount++; } else { derep.FailCount++; } return(db.SaveChanges() > 0); } } return(false); }
/// <summary> /// 开 /// </summary> /// <param name="OutID"></param> /// <param name="TableName"></param> /// <returns></returns> public string Begin(string OutID, string TableName, XuHos.Common.Enum.EnumDereplicationType DereplicationType) { using (XuHos.DAL.EF.DBEntities db = new DAL.EF.DBEntities()) { var derep = new SysDereplication() { OutID = OutID, TableName = TableName, SysDereplicationID = Guid.NewGuid().ToString("N"), SuccessCount = 0, FailCount = 0, DereplicationType = DereplicationType }; db.SysDereplications.Add(derep); if (db.SaveChanges() > 0) { return(derep.SysDereplicationID); } } return(""); }