Beispiel #1
0
        //检查是否有异常指标
        public bool IsExceptionData(List <PatientsData> datas, Dal.Patient patient)
        {
            PatientInfo patientInfo = new PatientInfo();
            var         hospitalId  = "";

            if (patient.Hospital != null)
            {
                hospitalId = patient.Hospital.Id.ToString();
            }
            var indicator   = patientInfo.GetIndicatorInfo(hospitalId, patient.Id);
            var isException = false;

            datas.ForEach(a =>
            {
                var currentInfoListDto = Mapper.Map <CurrentInfoListDto>(a);
                //var currentInfoListDto =
                //   new CurrentInfoListDto() {DataCode = a.DataCode, Unit = a.Unit, DataValue = a.DataValue};
                patientInfo.IndicatorJudge(indicator, currentInfoListDto);
                if (!currentInfoListDto.IsNomoal)
                {
                    isException = true;
                }
            });
            return(isException);
        }
        public ResultPakage <ReportAndHistoryReturnDto> GetReportByPatient(string year, Dal.Patient patient)
        {
            var db = new Db();
            var reportAndHistoryReturnDto = new ReportAndHistoryReturnDto();

            var reportHistoryReturnDtos = new List <ReportHistoryReturnDto>();

            var repotList = new List <ReportDto>();

            reportAndHistoryReturnDto.ReportHistory = reportHistoryReturnDtos;
            reportAndHistoryReturnDto.ReportItem    = repotList;


            var startDate = year + "-" + "01" + "-" + "01";
            var endDate   = year + "-" + "12" + "-" + "31";
            //查询病人历史的数据
            //病人当年的所有的报告信息
            var reportData = db.Reports
                             .Where(a => a.ReportDate.CompareTo(startDate) > 0 && a.ReportDate.CompareTo(endDate) < 0 && a.PatientId == patient.Id)
                             .Select(a => new
            {
                a.CreateTime,
                a.ReportType,
                a.ReportDate,
                a.ImageUrl,
                a.ImageUrl1,
                a.ImageUrl2,
                a.ImageUrl3,
                a.ImageUrl4,
                a.ImageUrl5,
                a.ImageUrl6,
                a.ImageUrl7,
                a.ImageUrl8
            }).ToList();

            reportData.ForEach(a =>
            {
                List <string> images = new List <string>();
                if (!string.IsNullOrEmpty(a.ImageUrl))
                {
                    images.Add(a.ImageUrl);
                }
                if (!string.IsNullOrEmpty(a.ImageUrl1))
                {
                    images.Add(a.ImageUrl1);
                }
                if (!string.IsNullOrEmpty(a.ImageUrl2))
                {
                    images.Add(a.ImageUrl2);
                }
                if (!string.IsNullOrEmpty(a.ImageUrl3))
                {
                    images.Add(a.ImageUrl3);
                }
                if (!string.IsNullOrEmpty(a.ImageUrl4))
                {
                    images.Add(a.ImageUrl4);
                }
                if (!string.IsNullOrEmpty(a.ImageUrl5))
                {
                    images.Add(a.ImageUrl5);
                }
                if (!string.IsNullOrEmpty(a.ImageUrl6))
                {
                    images.Add(a.ImageUrl6);
                }
                if (!string.IsNullOrEmpty(a.ImageUrl7))
                {
                    images.Add(a.ImageUrl7);
                }
                if (!string.IsNullOrEmpty(a.ImageUrl8))
                {
                    images.Add(a.ImageUrl8);
                }

                var reportDto        = new ReportDto();
                reportDto.ReportDate = a.ReportDate;
                reportDto.ReportType = PatientInfo.GetNameByReportType(a.ReportType ?? 0);
                reportDto.ImageUrl   = a.ImageUrl;
                reportDto.ImageUrls  = images;
                repotList.Add(reportDto);
            });



            reportAndHistoryReturnDto.ReportItem = repotList.OrderByDescending(a => DateTime.Parse(a.ReportDate)).ToList();


            //获取当年的所有指标记录,如果一天中有重复的则取最新的一次结果
            //排除文本类型的报告,因为图标不支持文本类型报告的显示
            var pro = (int)PatientsDataType.Pro;
            var ery = (int)PatientsDataType.ERY;
            var leu = (int)PatientsDataType.LEU;

            var reportDetailDatas = db.PatientsDatas
                                    .Where(a => a.PatientId == patient.Id && a.Report.PatientId == patient.Id && a.DataCode != pro && a.DataCode != ery && a.DataCode != leu && a.ReportId != 1)
                                    .GroupBy(b => new { b.RecordDate, b.DataCode }).Select(c => new
            {
                RecordDate = c.Max(x => x.RecordDate),
                RecordTime = c.Max(x => x.RecordTime),
                DataCode   = c.Max(x => x.DataCode),
                DataValue  = c.Max(x => x.DataValue),
                CreateTime = c.Max(x => x.CreateTime)
            }).ToList();

            //var reportDetailDatas = db.Reports.Where(a => a.ReportDate.CompareTo(startDate) > 0 && a.ReportDate.CompareTo(endDate) < 0 && a.PatientId == patient.Id)
            //                               .SelectMany(a => a.PatientsDatas.GroupBy(b=>new {b.RecordDate,b.DataCode})
            //                                        .Select(c => new { RecordDate = c.Max(x => x.RecordDate), RecordTime =c.Max(x=>x.RecordTime), DataCode = c.Max(x => x.DataCode), DataValue = c.Max(x => x.DataValue), CreateTime = c.Max(x => x.CreateTime) })).ToList();

            PatientInfo pt = new PatientInfo();
            //缓存性能优化处
            var indicate = pt.GetIndicatorInfo();

            //根据指标类型进行数据分类
            reportDetailDatas.GroupBy(a => a.DataCode).ForEach(a =>
            {
                var historyDto = new ReportHistoryReturnDto();
                var Xxdata     = new List <string>();
                var Values     = new List <string>();
                a.OrderBy(b => b.RecordTime).ForEach(item =>
                {
                    Xxdata.Add(item.RecordDate);
                    Values.Add(item.DataValue);
                    historyDto.Name    = PatientInfo.GetNameByCode(item.DataCode ?? 9);
                    var firstOrDefault = indicate.FirstOrDefault(b => b.DataCode == item.DataCode);
                    if (firstOrDefault != null)
                    {
                        historyDto.UnitName = firstOrDefault.Unit;
                    }
                    else
                    {
                        historyDto.UnitName = "未配置";
                    }

                    historyDto.DataCode = "code" + item.DataCode;
                });
                historyDto.Values = Values;
                historyDto.Xdata  = Xxdata;
                reportHistoryReturnDtos.Add(historyDto);
            });

            return(Util.ReturnOkResult(reportAndHistoryReturnDto));
        }
        private ResultPakage <GetMyRecordHistoryDto> GetMyRecordHistoryByPaitient(Dal.Patient patient)
        {
            var db  = new Db();
            var dto = new GetMyRecordHistoryDto();
            //查询当前日期7天之内的数据
            var startDate = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");

            //病人最近7天的所有的报告信息,每天只取一个记录,且该记录为一天中最新的一个
            var reportDetailDatas = db.PatientsDatas.Where(a => a.PatientId == patient.Id && a.ReportId == null && a.RecordDate.CompareTo(startDate) > 0)
                                    .Select(c => new
            {
                c.RecordDate,
                c.RecordTime,
                c.DataCode,
                c.DataValue,
                c.CreateTime,
                c.FormType
            }).OrderBy(a => a.RecordDate).ThenBy(a => a.RecordTime).ToList();

            //组装7天的数据。如没有数据则使用null代替,图标判断null会不生成图形
            var SystolicPressure      = new List <string>();
            var DiastolicPressure     = new List <string>();
            var HeartRate             = new List <string>();
            var FastingBloodGlucose   = new List <string>();
            var BreakfastBloodGlucose = new List <string>();
            var LunchBloodGlucose     = new List <string>();
            var DinnerBloodGlucose    = new List <string>();
            var RandomBloodGlucose    = new List <string>();
            var Weight      = new List <string>();
            var UrineVolume = new List <string>();
            var BMI         = new List <string>();
            var Date        = new List <string>();

            dto.Date = Date;
            for (var i = 29; i > -1; i--)
            {
                var currentDay       = DateTime.Now.AddDays(-i).ToString("yyyy-MM-dd");
                var systolicPressure = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.DataCode == (int)PatientsDataType.SystolicPressure).Select(a => a.DataValue).Max();
                SystolicPressure.Add(systolicPressure);

                var diastolicPressure = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.DataCode == (int)PatientsDataType.DiastolicPressure).Select(a => a.DataValue).Max();
                DiastolicPressure.Add(diastolicPressure);

                var heartRate = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.DataCode == (int)PatientsDataType.HeartRate).Select(a => a.DataValue).Max();
                HeartRate.Add(heartRate);

                var fastingBloodGlucose = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.FormType == (int)PatientsDataFormType.FastingBloodGlucose).Select(a => a.DataValue).Max();
                FastingBloodGlucose.Add(fastingBloodGlucose);

                var breakfastBloodGlucose = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.FormType == (int)PatientsDataFormType.BreakfastBloodGlucose).Select(a => a.DataValue).Max();
                BreakfastBloodGlucose.Add(breakfastBloodGlucose);

                var lunchBloodGlucose = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.FormType == (int)PatientsDataFormType.LunchBloodGlucose).Select(a => a.DataValue).Max();
                LunchBloodGlucose.Add(lunchBloodGlucose);

                var dinnerBloodGlucose = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.FormType == (int)PatientsDataFormType.DinnerBloodGlucose).Select(a => a.DataValue).Max();
                DinnerBloodGlucose.Add(dinnerBloodGlucose);

                var randomBloodGlucose = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.DataCode == (int)PatientsDataType.RBG).Select(a => a.DataValue).Max();
                RandomBloodGlucose.Add(randomBloodGlucose);

                var weight = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.DataCode == (int)PatientsDataType.Weight).Select(a => a.DataValue).Max();
                Weight.Add(weight);

                var urineVolume = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.DataCode == (int)PatientsDataType.UrineVolume).Select(a => a.DataValue).Max();
                UrineVolume.Add(urineVolume);

                var bmi = reportDetailDatas.Where(a => a.RecordDate == currentDay && a.DataCode == (int)PatientsDataType.BMI).Select(a => a.DataValue).Max();
                BMI.Add(bmi);

                Date.Add(DateTime.Now.AddDays(-i).ToString("dd"));
            }

            dto.SystolicPressure = SystolicPressure;
            if (dto.SystolicPressure.All(a => a == null))
            {
                dto.SystolicPressure.Clear();
            }
            dto.DiastolicPressure = DiastolicPressure;
            if (dto.DiastolicPressure.All(a => a == null))
            {
                dto.DiastolicPressure.Clear();
            }
            dto.HeartRate = HeartRate;
            if (dto.HeartRate.All(a => a == null))
            {
                dto.HeartRate.Clear();
            }
            dto.FastingBloodGlucose = FastingBloodGlucose;
            if (dto.FastingBloodGlucose.All(a => a == null))
            {
                dto.FastingBloodGlucose.Clear();
            }
            dto.BreakfastBloodGlucose = BreakfastBloodGlucose;
            if (dto.BreakfastBloodGlucose.All(a => a == null))
            {
                dto.BreakfastBloodGlucose.Clear();
            }
            dto.LunchBloodGlucose = LunchBloodGlucose;
            if (dto.LunchBloodGlucose.All(a => a == null))
            {
                dto.LunchBloodGlucose.Clear();
            }
            dto.DinnerBloodGlucose = DinnerBloodGlucose;
            if (dto.DinnerBloodGlucose.All(a => a == null))
            {
                dto.DinnerBloodGlucose.Clear();
            }
            dto.RandomBloodGlucose = RandomBloodGlucose;
            if (dto.RandomBloodGlucose.All(a => a == null))
            {
                dto.RandomBloodGlucose.Clear();
            }
            dto.Weight = Weight;
            if (dto.Weight.All(a => a == null))
            {
                dto.Weight.Clear();
            }
            dto.UrineVolume = UrineVolume;
            if (dto.UrineVolume.All(a => a == null))
            {
                dto.UrineVolume.Clear();
            }
            dto.BMI = BMI;
            if (dto.BMI.All(a => a == null))
            {
                dto.BMI.Clear();
            }
            return(Util.ReturnOkResult(dto));
        }