using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase; using HL_FristAidPlatform_Models; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HL_FristAidPlatform_DataBase { public class T_Service_CriticalPregnant_BasicInfoDB : BaseDB, IT_Service_CriticalPregnant_BasicInfo { public SqlSugarClient db = GetClient(); /// /// 根据患者GUID查询得到一个对象实体 /// public T_Service_CriticalPregnant_BasicInfo GetByPatientGUID(string patientGUID) { return db.Queryable().Where(it => it.PatientGuid == patientGUID && it.DeleteFlag == 0).First(); } /// /// 增加一条数据 /// /// /// public T_Service_CriticalPregnant_BasicInfo AddBasicInfo(T_Service_CriticalPregnant_BasicInfo model) { return db.Insertable(model).ExecuteReturnEntity(); } /// /// 更新一条数据 /// public int UpdateBasicInfo(T_Service_CriticalPregnant_BasicInfo model) { return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } /// /// 增加一条数据 /// /// /// public T_Service_CriticalPregnan_Time AddTime(T_Service_CriticalPregnan_Time model) { return db.Insertable(model).ExecuteReturnEntity(); } /// /// 更新一条数据 /// public int UpdateTime(T_Service_CriticalPregnan_Time model) { return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } public T_Service_CriticalPregnan_Time GetTimeByPatientGUID(string patientGUID) { return db.Queryable().Where(it => it.PatientGuid == patientGUID && it.DeleteFlag == 0).First(); } /// /// 高危孕产妇患者列表 /// /// /// /// /// /// /// /// /// /// public TableModel GetCriticalPregnantsList(string hospitalGuid, long systemModelId, string startTime, string endTime, string name, int ageOne, int ageTwo, string comehospitalway, string grade, int state, int pageIndex, int pageSize) { int totalNumber = 0; TableModel t = new TableModel(); List list = new List(); list = db.Queryable((a, b,c) => new JoinQueryInfos(JoinType.Left, a.GUID == b.PatientGuid,JoinType.Left,a.GUID==c.PatientGUID)) .Where((a, b) => a.HospitalGuid == hospitalGuid && a.SystemModuleID == systemModelId && a.DeleteFlag == 0) .WhereIF(!SqlFunc.IsNullOrEmpty(startTime), (a, b,c) => a.CreationDate >= SqlFunc.ToDate(startTime)) .WhereIF(!SqlFunc.IsNullOrEmpty(endTime), (a, b, c) => a.CreationDate <= SqlFunc.ToDate(endTime).AddDays(1)) .WhereIF(!SqlFunc.IsNullOrEmpty(name), (a, b, c) => a.Name.Contains(name)) .WhereIF(ageOne > 0, (a, b, c) => a.Age >= ageOne) .WhereIF(ageTwo > 0, (a, b, c) => a.Age <= ageTwo) .WhereIF(!SqlFunc.IsNullOrEmpty(comehospitalway), (a, b, c) => b.ComeHospitalWay == comehospitalway) .WhereIF(!SqlFunc.IsNullOrEmpty(grade), (a, b, c) => c.Grade ==int.Parse(grade)) .WhereIF(state > -1, (a, b, c) => a.EmergencyState == state) .OrderBy((a, b, c) => a.CreationDate, OrderByType.Desc) .Select((a, b, c) => new CriticalPregnantModel() { GUID = a.GUID, Name = a.Name, Age = a.Age, EmergencyState = a.EmergencyState, CreationDate = a.CreationDate, ComeHospitalWay = b.ComeHospitalWay, Grade = SqlFunc.Subqueryable().Where(s => s.PatientGUID == c.PatientGUID).Select(s => s.Grade), Attack_Time = b.Attack_Time, ABOBloodType = b.ABOBloodType, RhBloodType = b.RhBloodType, GestationalWeeks = b.GestationalWeeks, ExpectedDateOfConfinement = b.ExpectedDateOfConfinement }).ToPageList(pageIndex, pageSize, ref totalNumber); t.Code = 0; t.PageCount = list.Count; t.TotalNumber = totalNumber; t.Data = list; t.Msg = "成功"; return t; } /// /// 获取病例个数统计 /// /// /// /// public CaseDataModel GetCaseDataModel(string hospitalGuid, long systemModelId) { CaseDataModel model = new CaseDataModel(); var oneClass = db.Queryable() .Where(i => i.HospitalGuid == hospitalGuid && i.SystemModuleID == systemModelId && i.DeleteFlag == 0) .Select(i => new { i.GUID, i.CreationDate }) .ToList(); if (oneClass != null) { DateTime dt = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); model.ToDayCount = oneClass.Where(i => i.CreationDate >= dt && i.CreationDate <= dt.AddDays(1)).Count(); DateTime startQuarter = dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day); DateTime endQuarter = startQuarter.AddMonths(3).AddDays(-1); model.QuarterCount = oneClass.Where(i => i.CreationDate >= startQuarter && i.CreationDate <= endQuarter).Count(); DateTime startMonth = dt.AddDays(1 - dt.Day); DateTime endMonth = startMonth.AddMonths(1).AddDays(-1); model.MonthCount = oneClass.Where(i => i.CreationDate >= startMonth && i.CreationDate <= endMonth).Count(); DateTime startYear = new DateTime(dt.Year, 1, 1); DateTime endYear = new DateTime(dt.Year, 12, 31); model.YearCount = oneClass.Where(i => i.CreationDate >= startYear && i.CreationDate <= endYear).Count(); model.TotalCount = oneClass.Count(); model.TotalCount = oneClass.Count(); } return model; } } }