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_DownwardReferralDB : BaseDB, IT_Service_DownwardReferral
{
public SqlSugarClient db = GetClient();
///
/// 胸痛患者转诊信息
///
///
///
public ChestPatientReferralModel GetPatientReferralOfChest(string patientGuid)
{
ChestPatientReferralModel model = new ChestPatientReferralModel();
model = db.Queryable
((a, b, c, d, e) => new JoinQueryInfos(
JoinType.Left, a.GUID == b.PatientGuid,
JoinType.Left, a.GUID == c.PatientGuid,
JoinType.Left, a.GUID == d.PatientGuid,
JoinType.Left, a.HospitalGuid == e.GUID))
.Where((a, b, c, d, e) => a.GUID == patientGuid && a.DeleteFlag == 0)
.Select((a, b, c, d, e) => new ChestPatientReferralModel()
{
HospitalGuid = a.HospitalGuid,
PatientGuid = a.GUID,
Name = a.Name,
Gender = a.Gender,
Age = a.Age,
Phone = a.MobilePhone,
Inpatient_ID = b.Inpatient_ID,
Medical_Insurance_Type = b.Medical_Insurance_Type,
LeaveTime = d.LeaveTime != "" ? d.LeaveTime: SqlFunc.ToDate(c.Hand_Time).ToString("yyyy-MM-dd") ,
IllnessExplain = d.IllnessExplain,
HospitalSummary = d.HospitalSummary,
TreatmentPlan = d.TreatmentPlan,
SendHospital = d.SendHospital != "" ? d.SendHospital: c.Hospital_Name ,
DesignatedHospital = d.DesignatedHospital,
PatientSignature = d.PatientSignature,
ReferringDoctorSignature = d.ReferringDoctorSignature,
LeaveHospital = e.Name,
}).First();
return model;
}
///
/// 创伤患者转诊信息
///
///
///
public TraumaPatientReferralModel GetPatientReferralOfTrauma(string patientGuid)
{
TraumaPatientReferralModel model = new TraumaPatientReferralModel();
model = db.Queryable
((a, b, c, d,e) => new JoinQueryInfos(
JoinType.Left, a.GUID == b.PatientGuid,
JoinType.Left, a.GUID == c.PatientGuid,
JoinType.Left, a.HospitalGuid == d.GUID,
JoinType.Left,a.GUID==e.PatientGuid))
.Where((a, b, c, d,e) => a.GUID == patientGuid && a.DeleteFlag == 0)
.Select((a, b, c, d,e) => new TraumaPatientReferralModel()
{
HospitalGuid = a.HospitalGuid,
PatientGuid = a.GUID,
Name = a.Name,
Gender = a.Gender,
Age = a.Age,
Phone = a.EmergencyContactPhone,
OutpatientID = e.OutpatientID,
MPDSType = b.MPDSType,
MPDSContent=b.MPDSContent,
LeaveTime = c.LeaveTime,
IllnessExplain = c.IllnessExplain,
HospitalSummary = c.HospitalSummary,
TreatmentPlan = c.TreatmentPlan,
SendHospital = c.SendHospital,
DesignatedHospital = c.DesignatedHospital,
PatientSignature = c.PatientSignature,
ReferringDoctorSignature = c.ReferringDoctorSignature,
LeaveHospital = d.Name,
}).First();
return model;
}
///
/// 保存下转转诊信息
///
///
///
public bool SavePatientReferralInfo(T_Service_DownwardReferral model)
{
if (SqlFunc.IsNullOrEmpty(model.GUID))
{
model.GUID = Guid.NewGuid().ToString();
return db.Insertable(model).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand() == 1 ? true : false;
}
else
{
return db.Updateable(model).IgnoreColumns(it => new { it.ID }).ExecuteCommand() == 1 ? true : false;
}
}
///
///
///
///
///
public T_Service_DownwardReferral GetInfoByGUID(string patientGuid)
{
return db.Queryable().Where(i => i.PatientGuid == patientGuid && i.DeleteFlag == 0).First();
}
}
}