StableVersion4.3/HL_FristAidPlatform_DataBase/Service/T_Service_ChestPain_Patient...

107 lines
6.0 KiB
C#

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.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace HL_FristAidPlatform_DataBase
{
public class T_Service_ChestPain_PatientLogDB : BaseDB, IT_Service_ChestPain_PatientLog
{
public SqlSugarClient db = GetClient();
/// <summary>
/// 获取患者列表
/// </summary>
/// <param name="hospitalGuid"></param>
/// <param name="systemId"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public PatientLogModel GetPatientLogList(string hospitalGuid, long systemId, string startTime, string endTime)
{
PatientLogModel model = new PatientLogModel();
List<PatientLogInfo> list = new List<PatientLogInfo>();
List<List<string>> dataList = new List<List<string>>();
list = db.Queryable<T_Service_Patient, T_Service_ChestPain_FirstAIDInfo, T_Service_ChestPain_TreatmentInfo, T_Service_ChestPain_OutComeInfo>
((a, b, c, d) => new JoinQueryInfos(JoinType.Left, a.GUID == b.PatientGuid,
JoinType.Left, a.GUID == c.PatientGuid,
JoinType.Left, a.GUID == d.PatientGuid))
.Where((a, b, c, d) => a.HospitalGuid == hospitalGuid && a.SystemModuleID == systemId && a.DeleteFlag == 0)
.WhereIF(!SqlFunc.IsNullOrEmpty(startTime), (a, b, c, d) => a.CreationDate >= Convert.ToDateTime(startTime))
.WhereIF(!SqlFunc.IsNullOrEmpty(endTime), (a, b, c, d) => a.CreationDate < Convert.ToDateTime(endTime).AddDays(1))
.OrderBy((a, b, c, d) => a.CreationDate, OrderByType.Asc)
.Select((a, b, c, d) => new PatientLogInfo()
{
Name = a.Name,
Gender = SqlFunc.IF(a.Gender == 0).Return("未知").ElseIF(a.Gender == 1).Return("男").End("女"),
Age = a.Age.ToString(),
First_MC_Time = SqlFunc.IF(b.CW_Coming_Way_Code == "1").Return(b.CW_120_First_MC_Time).ElseIF(b.CW_Coming_Way_Code == "2").Return(b.CW_ZY_First_MC_Time).ElseIF(b.CW_Coming_Way_Code == "3").Return(b.CW_ZXLY_First_MC_Time).ElseIF(b.CW_Coming_Way_Code == "4").Return(b.CW_YNFB_First_MC_Time).End(""),
CP_Diagnosis_Code = SqlFunc.IF(c.CP_Diagnosis_Code == "1").Return("STEMI").ElseIF(c.CP_Diagnosis_Code == "2").Return("NSTEMI").ElseIF(c.CP_Diagnosis_Code == "3").Return("UA").ElseIF(c.CP_Diagnosis_Code == "4").Return("主动脉夹层").ElseIF(c.CP_Diagnosis_Code == "5").Return("肺动脉栓塞").ElseIF(c.CP_Diagnosis_Code == "6").Return("非ACS心源性胸痛").ElseIF(c.CP_Diagnosis_Code == "7").Return("其它非心源性胸痛").ElseIF(c.CP_Diagnosis_Code == "8").Return("待查").End(""),
First_Doctor_Name = SqlFunc.IF(b.CW_Coming_Way_Code == "1").Return(b.CW_120_First_Doctor_Name).ElseIF(b.CW_Coming_Way_Code == "2").Return(b.CW_ZY_First_Doctor_Name).ElseIF(b.CW_Coming_Way_Code == "3").Return(b.CW_ZXLY_First_Doctor_Name).ElseIF(b.CW_Coming_Way_Code == "4").Return(b.CW_YNFB_First_Doctor_Name).End(""),
OutCome_Code = SqlFunc.IF(d.OutCome_Code == "1").Return("出院").ElseIF(d.OutCome_Code == "2").Return("转送到其他医院").ElseIF(d.OutCome_Code == "3").Return("转送到其他科室").ElseIF(d.OutCome_Code == "4").Return("死亡").End("")
}).ToList();
if (list != null && list.Count > 0)
{
for (int i = 0; i < list.Count(); i++)
{
if (!string.IsNullOrEmpty(list[i].First_MC_Time))
list[i].First_MC_Time = Convert.ToDateTime(list[i].First_MC_Time).ToString("yyyy-MM-dd HH:mm");
if (!string.IsNullOrEmpty(list[i].First_MC_Time) && list[i].First_MC_Time == "1900-01-01 00:00")
list[i].First_MC_Time = "";
List<string> data = new List<string>();
data.Add(list[i].Name);
data.Add(list[i].Gender);
data.Add(list[i].Age);
data.Add(list[i].First_MC_Time);
data.Add(list[i].CP_Diagnosis_Code);
data.Add(list[i].First_Doctor_Name);
data.Add(list[i].OutCome_Code);
dataList.Add(data);
}
}
List<string> titleList = new List<string>();
Type patientLog = typeof(PatientLogInfo);
PropertyInfo[] properties = patientLog.GetProperties();
foreach (PropertyInfo property in properties)
{
//string propertyName = property.Name;//变量名称
//string propertyComment = GetPropertyComment(property);//变量注释
var comments = property.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true);
if (comments.Length > 0)
{
titleList.Add(((System.ComponentModel.DescriptionAttribute)comments[0]).Description);
}
}
model.Title = titleList;
model.DateList = dataList;
model.PatientLogList = list;
return model;
}
/// <summary>
/// 读取方法
/// </summary>
/// <param name="property"></param>
/// <returns></returns>
public static string GetPropertyComment(PropertyInfo property)
{
var comments = property.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true);
if (comments.Length > 0)
{
return ((System.ComponentModel.DescriptionAttribute)comments[0]).Description;
}
return string.Empty;
}
}
}