StableVersion4.3/HL_FristAidPlatform_DataBase/Service/T_Service_ChestPain_AddDB.cs

206 lines
12 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.Text;
using System.Threading.Tasks;
namespace HL_FristAidPlatform_DataBase
{
public class T_Service_ChestPain_AddDB : BaseDB, IT_Service_ChestPain_Add
{
public SqlSugarClient db = GetClient();
/// <summary>
/// 新增或者修改
/// </summary>
/// <param name="patient"></param>
/// <param name="prehospital"></param>
/// <param name="firstAIDInfo"></param>
/// <returns></returns>
public string UpdateOrInsert(T_Service_Patient patient, T_Service_ChestPain_FirstAIDInfo firstAIDInfo, T_Service_ChestPain_TreatmentInfo _ChestPain_TreatmentInfo, T_Service_ChestPain_TreatmentPCIInfo _ChestPain_TreatmentPCIInfo, T_Service_ChestPain_OutComeInfo _ChestPain_OutComeInfo)
{
try
{
db.Ado.BeginTran();
if (SqlFunc.IsNullOrEmpty(patient.GUID))
{
patient.CreationDate = DateTime.Now;
patient.RegisterTime = DateTime.Now;
patient.GUID = Guid.NewGuid().ToString();
db.Insertable(patient).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
if (SqlFunc.IsNullOrEmpty(firstAIDInfo.GUID))
{
firstAIDInfo.GUID = Guid.NewGuid().ToString();
firstAIDInfo.PatientGuid = patient.GUID;
db.Insertable(firstAIDInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
if (SqlFunc.IsNullOrEmpty(_ChestPain_TreatmentInfo.GUID))
{
_ChestPain_TreatmentInfo.GUID = Guid.NewGuid().ToString();
_ChestPain_TreatmentInfo.PatientGuid = patient.GUID;
db.Insertable(_ChestPain_TreatmentInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
if (SqlFunc.IsNullOrEmpty(_ChestPain_TreatmentPCIInfo.GUID))
{
_ChestPain_TreatmentPCIInfo.GUID = Guid.NewGuid().ToString();
_ChestPain_TreatmentPCIInfo.PatientGuid = patient.GUID;
db.Insertable(_ChestPain_TreatmentPCIInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
if (SqlFunc.IsNullOrEmpty(_ChestPain_OutComeInfo.GUID))
{
_ChestPain_OutComeInfo.GUID = Guid.NewGuid().ToString();
_ChestPain_OutComeInfo.PatientGuid = patient.GUID;
db.Insertable(_ChestPain_OutComeInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
if (patient.WristStrapID > 0)
{
T_Base_WristStrap wristStrap = new T_Base_WristStrap();
wristStrap = db.Queryable<T_Base_WristStrap>().Where(i => i.ID == patient.WristStrapID).First();
if (wristStrap != null)
{
wristStrap.Status = 1;
db.Updateable(wristStrap).UpdateColumns(it => new { it.Status }).ExecuteCommand();
}
}
}
else
{
db.Updateable(patient).IgnoreColumns(it => new { it.ID, it.Creator, it.CreatorID }).ExecuteCommand();
db.Updateable(firstAIDInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
db.Updateable(_ChestPain_TreatmentInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
db.Updateable(_ChestPain_TreatmentPCIInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
db.Updateable(_ChestPain_OutComeInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
db.Ado.CommitTran();
return patient.GUID.ToString();
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.Info(ex.Message);
return "";
}
}
public string InsertTriage(T_Service_ChestPain_FirstAIDInfo firstAIDInfo, T_Service_ChestPain_TreatmentInfo _ChestPain_TreatmentInfo, T_Service_ChestPain_TreatmentPCIInfo _ChestPain_TreatmentPCIInfo, T_Service_ChestPain_OutComeInfo _ChestPain_OutComeInfo)
{
try
{
db.Ado.BeginTran();
if (SqlFunc.IsNullOrEmpty(firstAIDInfo.PatientGuid))
{
if (SqlFunc.IsNullOrEmpty(firstAIDInfo.PatientGuid))
{
firstAIDInfo.GUID = Guid.NewGuid().ToString();
firstAIDInfo.PatientGuid = firstAIDInfo.PatientGuid;
db.Insertable(firstAIDInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
if (SqlFunc.IsNullOrEmpty(_ChestPain_TreatmentInfo.GUID))
{
_ChestPain_TreatmentInfo.GUID = Guid.NewGuid().ToString();
_ChestPain_TreatmentInfo.PatientGuid = firstAIDInfo.PatientGuid;
db.Insertable(_ChestPain_TreatmentInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
if (SqlFunc.IsNullOrEmpty(_ChestPain_TreatmentPCIInfo.GUID))
{
_ChestPain_TreatmentPCIInfo.GUID = Guid.NewGuid().ToString();
_ChestPain_TreatmentPCIInfo.PatientGuid = firstAIDInfo.PatientGuid;
db.Insertable(_ChestPain_TreatmentPCIInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
if (SqlFunc.IsNullOrEmpty(_ChestPain_OutComeInfo.GUID))
{
_ChestPain_OutComeInfo.GUID = Guid.NewGuid().ToString();
_ChestPain_OutComeInfo.PatientGuid = firstAIDInfo.PatientGuid;
db.Insertable(_ChestPain_OutComeInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand();
}
}
db.Ado.CommitTran();
return firstAIDInfo.PatientGuid.ToString();
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.Info(ex.Message);
return "";
}
}
/// <summary>
/// 根据患者GUID获取数据
/// </summary>
public T_Service_ChestPain_AddModel GetByPatientGuid(string PatientGuid)
{
return db.Queryable<T_Service_Patient, T_Service_ChestPain_FirstAIDInfo, T_Service_ChestPain_FirstAIDInfo>((Patient, Prehospital, FirstAIDInfo) => new JoinQueryInfos(
JoinType.Left, Patient.GUID == Prehospital.PatientGuid,
JoinType.Left, Patient.GUID == FirstAIDInfo.PatientGuid))
.Where(Patient => Patient.GUID == PatientGuid)
.Select((Patient, Prehospital, FirstAIDInfo) =>
new T_Service_ChestPain_AddModel()
{
GUID = Patient.GUID,
Province = SqlFunc.Subqueryable<T_Base_Province>().Where(s => s.ProvinceName == Patient.Province).Select(s => s.ProvinceCode),
City = SqlFunc.Subqueryable<T_Base_City>().InnerJoin<T_Base_Province>((a, b) => a.ProvinceCode == b.ProvinceCode && b.ProvinceName == Patient.Province && a.CityName == Patient.City).Select(a => a.CityCode),
Area = SqlFunc.Subqueryable<T_Base_County>().InnerJoin<T_Base_City>((a, b) => a.CityCode == b.CityCode && b.CityName == Patient.City && a.CountyName == Patient.Area).Select(a => a.CountyCode),
Attack_Address = Patient.Attack_Address,
Name = Patient.Name,
Category = Patient.Category,
Gender = Patient.Gender,
Birthday = Patient.Birthday,
Credentials_Type = Patient.Credentials_Type,
IdentityCard = Patient.IdentityCard,
Nation = Patient.Nation,
MobilePhone = Patient.MobilePhone,
Address = Patient.Address,
WristStrapID = Patient.WristStrapID,
EqmtNo = Patient.EqmtNo,
ComeHosptialWay = FirstAIDInfo.CW_Coming_Way_Code,
CW_120_Help_Time = FirstAIDInfo.CW_120_Help_Time,
CW_120_Is_Trans_Hospital = FirstAIDInfo.CW_120_Is_Trans_Hospital,
CW_120_IS_DIRECT_CONDUIT_ROOM = FirstAIDInfo.CW_120_IS_DIRECT_CONDUIT_ROOM,
CW_ZY_Trans_Type = FirstAIDInfo.CW_ZY_Trans_Type,
CW_YNFB_First_MC_Time = FirstAIDInfo.CW_YNFB_First_MC_Time,
//转院首次接触
CW_ZY_First_MC_Time = FirstAIDInfo.CW_ZY_First_MC_Time,
CW_ZY_Arrived_Hospital_Time = FirstAIDInfo.CW_ZY_Arrived_Hospital_Time,
//自行来院
CW_ZXLY_First_MC_Time = FirstAIDInfo.CW_ZXLY_First_MC_Time,
CW_ZXLY_Arrived_Hospital_Time = FirstAIDInfo.CW_ZXLY_Arrived_Hospital_Time,
Attack_Time = FirstAIDInfo.Attack_Time.ToString(),
TimeOfOnset = int.Parse(Prehospital.Is_Null_Attack_Detail_Time),
OnsetTimeInterval = Prehospital.Attack_Zone,
CW_120_Ambulance_Department = FirstAIDInfo.CW_120_Ambulance_Department,
CW_ZY_Trans_Hospital_Name = FirstAIDInfo.CW_ZY_Trans_Hospital_Name,
CW_ZY_First_Doctor_Name = FirstAIDInfo.CW_ZY_First_Doctor_Name,
CW_ZY_Transfer_Time = FirstAIDInfo.CW_ZY_Transfer_Time,
CW_ZY_Leave_Outhospital_Time = FirstAIDInfo.CW_ZY_Leave_Outhospital_Time,
CW_ZY_Admission_Time = FirstAIDInfo.CW_ZY_Admission_Time,
CW_ZY_Outhospital_Visit_Time = FirstAIDInfo.CW_ZY_Outhospital_Visit_Time,
CW_ZY_IS_TRANS_HOSPITAL = FirstAIDInfo.CW_ZY_IS_TRANS_HOSPITAL,
CW_ZY_IS_DIRECT_CONDUIT_ROOM = FirstAIDInfo.CW_ZY_IS_DIRECT_CONDUIT_ROOM,
CW_ZXLY_First_Doctor_Name = FirstAIDInfo.CW_ZXLY_First_Doctor_Name,
CW_ZXLY_First_Doctor_Time = FirstAIDInfo.CW_ZXLY_First_Doctor_Time,
CW_YNFB_Attack_Department = FirstAIDInfo.CW_YNFB_Attack_Department,
CW_YNFB_First_Doctor_Name = FirstAIDInfo.CW_YNFB_First_Doctor_Name,
CW_YNFB_Consultation_Time = FirstAIDInfo.CW_YNFB_Consultation_Time,
CW_YNFB_Leave_Department_Time = FirstAIDInfo.CW_YNFB_Leave_Department_Time,
IllnessLevel= Patient.IllnessLevel
}).First();
}
}
}