using DevExpress.Xpo; using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase; using HL_FristAidPlatform_Models; using SqlSugar; using System; using System.Collections.Generic; namespace HL_FristAidPlatform_DataBase { /// /// 社区乡镇人群随访表 /// public class T_Service_Apoplexy_CommunityDB : BaseDB, IT_Service_Apoplexy_Community { public SqlSugarClient db = GetClient(); public int ChangeStyle(string patientGUID, string flag) { T_Service_Apoplexy_Community_BaseInfo model = new T_Service_Apoplexy_Community_BaseInfo(); model.PatientGUID = patientGUID; model.Flag = flag; int count = 0; var class1 = db.Queryable().First(it => it.PatientGUID == patientGUID && it.Flag == flag && it.DeleteFlag == 0); var class2 = db.Queryable().First(it => it.PatientGUID == patientGUID && it.Flag == flag && it.DeleteFlag == 0); var class3 = db.Queryable().First(it => it.PatientGUID == patientGUID && it.Flag == flag && it.DeleteFlag == 0); var class4 = db.Queryable().First(it => it.PatientGUID == patientGUID && it.Flag == flag && it.DeleteFlag == 0); var class5 = db.Queryable().First(it => it.PatientGUID == patientGUID && it.Flag == flag && it.DeleteFlag == 0); var class6 = db.Queryable().First(it => it.PatientGUID == patientGUID && it.Flag == flag && it.DeleteFlag == 0); if (class1 != null) { count++; } if (class2 != null) { count++; } if (class3 != null) { count++; } if (class4 != null) { count++; } if (class5 != null) { count++; } if (class6 != null) { count++; } if (count == 6) { //已完成 model.IsCompleted = 1; db.Updateable(model).UpdateColumns(it => new { it.IsCompleted }).Where(it => it.PatientGUID == model.PatientGUID && it.Flag == model.Flag).ExecuteCommand(); } else if (count < 6 && count > 0) { //进行中 model.IsCompleted = 2; db.Updateable(model).UpdateColumns(it => new { it.IsCompleted }).Where(it => it.PatientGUID == model.PatientGUID && it.Flag == model.Flag).ExecuteCommand(); } return count; } #region 基本信息 /// /// 增加一条数据 /// /// /// public T_Service_Apoplexy_Community_BaseInfo AddBaseInfo(T_Service_Apoplexy_Community_BaseInfo model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Insertable(model).ExecuteReturnEntity(); } /// /// 更新一条数据 /// public int UpdateBaseInfo(T_Service_Apoplexy_Community_BaseInfo model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } /// /// 社区乡镇随访接口内容 /// /// /// public List GetCommunityFollowUp(string hospitalGuid) { List list = new List(); DateTime date = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); list = db.Queryable((a, b) => new JoinQueryInfos(JoinType.Left, a.GUID == b.PatientGUID)) .Where((a, b) => b.CreationDate > date && b.CreationDate < date.AddDays(1)) .Select((a, b) => new KeyValue { key = a.Name }).ToList(); return list; } /// /// 根据患者GUID和flag查询数据 /// T_Service_ApoplexyScreenInfo /// /// /// public T_Service_Apoplexy_Community_BaseInfoModel GetBaseInfoByPatientGuidAndFlag(string patientGuid, string flag) { T_Service_Apoplexy_Community_BaseInfoModel model = new T_Service_Apoplexy_Community_BaseInfoModel(); var oneClass = db.Queryable().First(it => it.GUID == patientGuid && it.DeleteFlag == 0); var twoClass = db.Queryable().First(it => it.PatientGUID == patientGuid && it.Flag == flag && it.DeleteFlag == 0); model.Name = oneClass.Name; model.IDCard = oneClass.IDCard; if (twoClass != null) { model.ID = twoClass.ID; model.GUID = twoClass.GUID; model.PatientGUID = twoClass.PatientGUID; model.CreationDate = twoClass.CreationDate; model.FollowupUnitName = twoClass.FollowupUnitName; model.FollowupPerson = twoClass.FollowupPerson; model.ContactNumber = twoClass.ContactNumber; model.InvestigationTime = twoClass.InvestigationTime; model.Flag = twoClass.Flag; model.Investigationmethod = twoClass.Investigationmethod; model.Isself = twoClass.Isself; model.Relationship = twoClass.Relationship; model.RelationshipOther = twoClass.RelationshipOther; model.LossOfVisit = twoClass.LossOfVisit; model.LossOfVisitReason = twoClass.LossOfVisitReason; model.LossOfVisitReasonOther = twoClass.LossOfVisitReasonOther; model.Death = twoClass.Death; model.DeathTime = twoClass.DeathTime; model.DeathReason = twoClass.DeathReason; model.DeathReasonOther = twoClass.DeathReasonOther; model.CerebralApoplexy = twoClass.CerebralApoplexy; model.CreatorID = twoClass.CreatorID; model.DeleteFlag = twoClass.DeleteFlag; } return model; } public bool SaveBaseInfo(T_Service_ApoplexyScreenInfo screenInfo, T_Service_Apoplexy_Community_BaseInfo baseInfo) { try { db.Ado.BeginTran(); db.Updateable(screenInfo).UpdateColumns(it => new { it.Name, it.IDCard, it.Gender, it.Age }).Where(it => it.GUID == screenInfo.GUID).ExecuteCommand(); if (SqlFunc.IsNullOrEmpty(baseInfo.GUID)) { baseInfo.GUID = Guid.NewGuid().ToString(); db.Insertable(baseInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } else { db.Updateable(baseInfo).IgnoreColumns(ignoreAllNullColumns: true).Where(it => it.PatientGUID == baseInfo.PatientGUID && it.Flag == baseInfo.Flag).ExecuteCommand(); } db.Ado.CommitTran(); return true; } catch (Exception ex) { db.Ado.RollbackTran(); Help.WriteErrorLog("保存基本信息", ex.ToString()); return false; } } public T_Service_Apoplexy_Community_BaseInfo GetBaseInfoByPatientGuidAndFlag1(string patientGuid, string flag) { return db.Queryable().First(it => it.PatientGUID == patientGuid && it.Flag == flag && it.DeleteFlag == 0); } #endregion #region 随访期间生活方式 /// /// 增加一条数据 /// /// /// public T_Service_Apoplexy_Community_LifeStyle AddLifeStyle(T_Service_Apoplexy_Community_LifeStyle model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Insertable(model).ExecuteReturnEntity(); } /// /// 更新一条数据 /// public int UpdateLifeStyle(T_Service_Apoplexy_Community_LifeStyle model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } /// /// 根据患者GUID和flag查询数据 /// /// /// /// public T_Service_Apoplexy_Community_LifeStyle GetLifeStyleByPatientGuidAndFlag(string patientGuid, string flag) { return db.Queryable().First(it => it.PatientGUID == patientGuid && it.Flag == flag && it.DeleteFlag == 0); } #endregion #region 随访期间主要病史及控制情况 /// /// 增加一条数据 /// /// /// public T_Service_Apoplexy_Community_MedicalHistory AddMedicalHistory(T_Service_Apoplexy_Community_MedicalHistory model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Insertable(model).ExecuteReturnEntity(); } /// /// 更新一条数据 /// public int UpdateMedicalHistory(T_Service_Apoplexy_Community_MedicalHistory model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } /// /// 根据患者GUID和flag查询数据 /// /// /// /// public T_Service_Apoplexy_Community_MedicalHistory GetMedicalHistoryByPatientGuidAndFlag(string patientGuid, string flag) { return db.Queryable().First(it => it.PatientGUID == patientGuid && it.Flag == flag && it.DeleteFlag == 0); } #endregion #region 本次随访期间血管病变的外科手术或介入治疗情况 /// /// 增加一条数据 /// /// /// public T_Service_Apoplexy_Community_Surgery AddSurgery(T_Service_Apoplexy_Community_Surgery model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Insertable(model).ExecuteReturnEntity(); } /// /// 更新一条数据 /// public int UpdateSurgery(T_Service_Apoplexy_Community_Surgery model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } /// /// 根据患者GUID和flag查询数据 /// /// /// /// public T_Service_Apoplexy_Community_Surgery GetSurgeryByPatientGuidAndFlag(string patientGuid, string flag) { return db.Queryable().First(it => it.PatientGUID == patientGuid && it.Flag == flag && it.DeleteFlag == 0); } #endregion #region 体格检查(高危人群 12 个月随访必做) /// /// 增加一条数据 /// /// /// public T_Service_Apoplexy_Community_PhysicalExamination AddPhysicalExamination(T_Service_Apoplexy_Community_PhysicalExamination model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Insertable(model).ExecuteReturnEntity(); } /// /// 更新一条数据 /// public int UpdatePhysicalExamination(T_Service_Apoplexy_Community_PhysicalExamination model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } /// /// 根据患者GUID和flag查询数据 /// /// /// /// public T_Service_Apoplexy_Community_PhysicalExamination GetPhysicalExaminationByPatientGuidAndFlag(string patientGuid, string flag) { return db.Queryable().First(it => it.PatientGUID == patientGuid && it.Flag == flag && it.DeleteFlag == 0); } #endregion #region 实验室检查(高危人群 12 个月随访必填 /// /// 增加一条数据 /// /// /// public T_Service_Apoplexy_Community_LaboratoryExamination AddLaboratoryExamination(T_Service_Apoplexy_Community_LaboratoryExamination model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Insertable(model).ExecuteReturnEntity(); } /// /// 更新一条数据 /// public int UpdateLaboratoryExamination(T_Service_Apoplexy_Community_LaboratoryExamination model) { ChangeStyle(model.PatientGUID, model.Flag); return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } /// /// 根据患者GUID和flag查询数据 /// /// /// /// public T_Service_Apoplexy_Community_LaboratoryExamination GetLaboratoryExaminationByPatientGuidAndFlag(string patientGuid, string flag) { return db.Queryable().First(it => it.PatientGUID == patientGuid && it.Flag == flag && it.DeleteFlag == 0); } #endregion } }