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)); }