using HelperDB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace DocumentManagement
{
    /// 
    /// V_OperationRecordALL
    /// 
    public class PatientRecord
    {
        public int PatientId { get; set; }
        public int ApplyId { get; set; }
        public String HISPatientId { get; set; }
        public String VisitTimes { get; set; }
        public String MdrecNo { get; set; }
        public String ArchivesNo { get; set; }
        public String PatientName { get; set; }
        public String PatientName1 { get; set; }
        public String PatientDepName { get; set; }
        public String ApplyDepName { get; set; }
        public String PatientKind { get; set; }
        public String Sex { get; set; }
        public String BirthDay { get; set; }
        public String Age { get; set; }
        public String IdentityCard { get; set; }
        public String BMI { get; set; }
        public String Height { get; set; }
        public String Weight { get; set; }
        public String BloodType { get; set; }
        public String RHBloodType { get; set; }
        public String SickBed { get; set; }
        public String OperationType { get; set; }
        public String OrderOperationTime { get; set; }
        public String OrderOperationDate { get; set; }
        public String OperationDate { get; set; }
        public String OperationTimeLeight { get; set; }
        public String IsReturnOperation { get; set; }
        public String IsPlanReturnOperation { get; set; }
        public String ApplyDiagnoseInfoName { get; set; } 
        public String DiagnoseRemark { get; set; }
        public String ApplyOperationInfoName { get; set; }
        public String OperationRemark { get; set; }
        public String ApplyOperationLevelName { get; set; }
        public String ApplyOperationCutTypeName { get; set; }
        public String ApplyOperationPositionName { get; set; }
        public String ApplyAnaesthesiaMethodName { get; set; }
        public String Contagion { get; set; }
        public String ApplyOperationDoctor { get; set; }
        public String Assistant1 { get; set; }
        public String Assistant2 { get; set; }
        public String Assistant3 { get; set; }
        public String Intern { get; set; }
        public String Other { get; set; }
        public String ApplyTime { get; set; }
        public String ApplyOperatorName { get; set; }
        public String VerifyTime { get; set; }
        public String VerifyOperatorName { get; set; }
        public String PlanOperationTime { get; set; }
        public String OperationRoomId { get; set; }
        public String OperationRoom { get; set; }
        public String PlanOrder { get; set; }
        public String ApplyAnesthesiaDoctor { get; set; }
        public String InstrumentNurse { get; set; }
        public String TourNurse { get; set; }
        public String AnesthesiaDoctorSucceed { get; set; }
        public String InstrumentNurseSucceed { get; set; }
        public String TourNurseSucceed { get; set; }
        public String ASA { get; set; }
        public String HeartFunctionLevel { get; set; }
        public String IsFasting { get; set; }
        public String State { get; set; }
        public String InRoomTime { get; set; }
        public String OutRoomTime { get; set; }
        public String OperationBeginTime { get; set; }
        public String OperationEndTime { get; set; }
        public String AnesthesiaBeginTime { get; set; }
        public String AnesthesiaEndTime { get; set; }
        public String SpileInTime { get; set; }
        public String SpileOutTime { get; set; }
        public String OperationLevelName { get; set; }
        public String OpeAfterMode { get; set; }
        public String SpecialSituation { get; set; }
        public String PunctureBodyPosition { get; set; }
        public String PuncturePosition { get; set; }
        public String CatheterDepth { get; set; }
        public String NeedleSize { get; set; }
        public String NeedleDirection { get; set; }
        public String AnaesthesiaPlane { get; set; }
        public String AnaesthesiaEffect { get; set; }
        public String DiagnoseInfoName { get; set; }
        public String OperationInfoName { get; set; }
        public String AnaesthesiaMethodName { get; set; }
        public String OperationCutTypeName { get; set; }
        public String OperationBodyPositionName { get; set; }
        public String OperationPositionName { get; set; }
        public String OperationDoctor { get; set; }
        public String Assistant { get; set; }
        public String AnesthesiaDoctor { get; set; }
        public String Nurse { get; set; }
        public String Illdistrict { get; set; }
        public String Remarks { get; set; }
        public String SysDate { get; set; }
        public String SysTime { get; set; }
        public String OpeTime { get; set; }
        public String MedicalRecord { get; set; }
        public String MedicalHistory { get; set; }
        public String InHosDate { get; set; }
        public PatientLisResult LisResult { get; set; }
        public static PatientRecord GetPatientRecord(int patientId)
        {
            PatientRecord patient = new PatientRecord();
            #region 患者信息赋值
            DataTable dt = GetPatientSources(patientId);
            if (dt.Rows.Count > 0)
            {
                patient.PatientId = int.Parse(dt.Rows[0]["PatientId"].ToString());
                //patient.PatientId = int.Parse(dt.Rows[0]["PatientId"].ToString());
                patient.ApplyId = int.Parse(dt.Rows[0]["ApplyId"].ToString());
                patient.HISPatientId = dt.Rows[0]["HISPatientId"].ToString();
                patient.VisitTimes = dt.Rows[0]["VisitTimes"].ToString();
                patient.MdrecNo = dt.Rows[0]["MdrecNo"].ToString();
                patient.ArchivesNo = dt.Rows[0]["ArchivesNo"].ToString();
                patient.PatientName = dt.Rows[0]["PatientName"].ToString();
                patient.PatientName1 = dt.Rows[0]["PatientName"].ToString();
                patient.PatientKind = dt.Rows[0]["PatientKind"].ToString();
                patient.Sex = dt.Rows[0]["Sex"].ToString();
                patient.ApplyDepName = dt.Rows[0]["ApplyDepName"].ToString();
                patient.PatientDepName = dt.Rows[0]["PatientDepName"].ToString();
                patient.Age = dt.Rows[0]["Age"].ToString();
                patient.Height = dt.Rows[0]["Height"].ToString();
                patient.Weight = dt.Rows[0]["Weight"].ToString();
                patient.BMI = dt.Rows[0]["BMI"].ToString();
                try
                {
                    if (patient.BMI == "" && patient.Height != "" && patient.Weight != "" && patient.Weight != "卧床")
                    {
                        double hei = double.Parse(patient.Height) / 100;
                        double wei = double.Parse(patient.Weight);
                        double BMI = wei / hei / hei;
                        patient.BMI = Math.Floor(BMI).ToString();
                    }
                }
                catch (Exception)
                { 
                }
                patient.BirthDay = dt.Rows[0]["BirthDay"].ToString();
                patient.IdentityCard = dt.Rows[0]["IdentityCard"].ToString();
                patient.BloodType = dt.Rows[0]["BloodType"].ToString();
                patient.SickBed = dt.Rows[0]["SickBed"].ToString();
                patient.OperationType = dt.Rows[0]["OperationType"].ToString();
                patient.OrderOperationTime = dt.Rows[0]["OrderOperationTime"].ToString();
                patient.OrderOperationDate = dt.Rows[0]["OrderOperationDate"].ToString();
                patient.OperationTimeLeight = dt.Rows[0]["OperationTimeLeight"].ToString();
                patient.IsReturnOperation = dt.Rows[0]["IsReturnOperation"].ToString();
                patient.IsPlanReturnOperation = dt.Rows[0]["IsPlanReturnOperation"].ToString();
                patient.ApplyDiagnoseInfoName = dt.Rows[0]["ApplyDiagnoseInfoName"].ToString(); 
                patient.DiagnoseRemark = dt.Rows[0]["DiagnoseRemark"].ToString();
                patient.ApplyOperationInfoName = dt.Rows[0]["ApplyOperationInfoName"].ToString();
                patient.OperationRemark = dt.Rows[0]["OperationRemark"].ToString();
                patient.ApplyOperationLevelName = dt.Rows[0]["ApplyOperationLevelName"].ToString();
                patient.ApplyOperationCutTypeName = dt.Rows[0]["ApplyOperationCutTypeName"].ToString();
                patient.ApplyOperationPositionName = dt.Rows[0]["ApplyOperationPositionName"].ToString();
                patient.ApplyAnaesthesiaMethodName = dt.Rows[0]["ApplyAnaesthesiaMethodName"].ToString();
                patient.Contagion = dt.Rows[0]["Contagion"].ToString();
                patient.ApplyOperationDoctor = dt.Rows[0]["ApplyOperationDoctor"].ToString();
                patient.Assistant1 = dt.Rows[0]["Assistant1"].ToString();
                patient.Assistant2 = dt.Rows[0]["Assistant2"].ToString();
                patient.Assistant3 = dt.Rows[0]["Assistant3"].ToString();
                patient.Intern = dt.Rows[0]["Intern"].ToString();
                patient.Other = dt.Rows[0]["Other"].ToString();
                patient.ApplyTime = dt.Rows[0]["ApplyTime"].ToString();
                patient.ApplyOperatorName = dt.Rows[0]["ApplyOperatorName"].ToString();
                patient.VerifyOperatorName = dt.Rows[0]["VerifyOperatorName"].ToString();
                patient.PlanOperationTime = dt.Rows[0]["PlanOperationTime"].ToString();
                patient.OperationRoomId = dt.Rows[0]["OperationRoomId"].ToString();
                patient.OperationRoom = dt.Rows[0]["OperationRoom"].ToString();
                patient.PlanOrder = dt.Rows[0]["PlanOrder"].ToString();
                patient.ApplyAnesthesiaDoctor = dt.Rows[0]["ApplyAnesthesiaDoctor"].ToString();
                patient.InstrumentNurse = dt.Rows[0]["InstrumentNurse"].ToString();
                patient.TourNurse = dt.Rows[0]["TourNurse"].ToString();
                patient.AnesthesiaDoctorSucceed = dt.Rows[0]["AnesthesiaDoctorSucceed"].ToString();
                patient.InstrumentNurseSucceed = dt.Rows[0]["InstrumentNurseSucceed"].ToString();
                patient.TourNurseSucceed = dt.Rows[0]["TourNurseSucceed"].ToString();
                patient.ASA = dt.Rows[0]["ASA"].ToString();
                patient.HeartFunctionLevel = dt.Rows[0]["HeartFunctionLevel"].ToString();
                patient.IsFasting = dt.Rows[0]["IsFasting"].ToString();
                patient.State = dt.Rows[0]["State"].ToString();
                patient.InRoomTime = dt.Rows[0]["InRoomTime"].ToString();
                patient.OutRoomTime = dt.Rows[0]["OutRoomTime"].ToString();
                patient.OperationBeginTime = dt.Rows[0]["OperationBeginTime"].ToString();
                patient.OperationEndTime = dt.Rows[0]["OperationEndTime"].ToString();
                patient.AnesthesiaBeginTime = dt.Rows[0]["AnesthesiaBeginTime"].ToString();
                patient.AnesthesiaEndTime = dt.Rows[0]["AnesthesiaEndTime"].ToString();
                patient.SpileInTime = dt.Rows[0]["SpileInTime"].ToString();
                patient.SpileOutTime = dt.Rows[0]["SpileOutTime"].ToString();
                patient.OperationLevelName = dt.Rows[0]["OperationLevelName"].ToString();
                patient.SpecialSituation = dt.Rows[0]["SpecialSituation"].ToString();
                patient.AnaesthesiaPlane = dt.Rows[0]["AnaesthesiaPlane"].ToString();
                patient.DiagnoseInfoName = dt.Rows[0]["ApplyDiagnoseInfoName"].ToString();
                patient.OperationInfoName = dt.Rows[0]["OperationInfoName"].ToString();
                patient.AnaesthesiaMethodName = dt.Rows[0]["AnaesthesiaMethodName"].ToString();
                patient.OperationCutTypeName = dt.Rows[0]["OperationCutTypeName"].ToString();
                patient.OperationBodyPositionName = dt.Rows[0]["OperationBodyPositionName"].ToString();
                patient.OperationPositionName = dt.Rows[0]["OperationPositionName"].ToString();
                patient.OperationDoctor = dt.Rows[0]["OperationDoctor"].ToString();
                if (patient.OperationDoctor.Contains(","))
                    patient.OperationDoctor = patient.OperationDoctor.Split(',').ToList()[0];
                patient.Assistant = dt.Rows[0]["Assistant"].ToString();
                patient.AnesthesiaDoctor = dt.Rows[0]["AnesthesiaDoctor"].ToString();
                patient.Nurse = dt.Rows[0]["Nurse"].ToString();
                patient.Illdistrict = dt.Rows[0]["Illdistrict"].ToString();
                patient.Remarks = dt.Rows[0]["Remarks"].ToString();
                patient.SysDate = dt.Rows[0]["SysDate"].ToString();
                patient.SysTime = dt.Rows[0]["SysTime"].ToString();
                patient.OpeTime = dt.Rows[0]["OpeTime"].ToString();
                patient.MedicalRecord = dt.Rows[0]["MedicalRecord"].ToString();
                patient.MedicalHistory = dt.Rows[0]["MedicalHistory"].ToString();
                patient.InHosDate = dt.Rows[0]["InHosDate"].ToString();
            }
            patient.LisResult = PatientLisResult.GetLisResult(patient);
            #endregion
            return patient;
        }
        /// 
        /// 获取患者信息
        /// 
        /// 
        /// 
        /// 
        public static DataTable GetPatientSources(int patientId)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" select *");
                strSql.Append(" from V_OperationRecordALL where");
                strSql.Append("   PatientId = '" + patientId + "'");
                return DbHelperSQL.GetDataTable(strSql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}