Ejemplo n.º 1
0
        /// <summary>
        /// 根据治疗单 生成数据
        /// </summary>
        /// <param name="visitDate"></param>
        /// <param name="visitNo"></param>
        private void CreateData(DateTime visitDate, int visitNo)
        {
            //QualityResultApp resultApp = new QualityResultApp();
            var listSourse = _patVisitApp.GetList().Where(t => t.F_VisitDate == visitDate && (visitNo == 0 || t.F_VisitNo == visitNo) && t.F_DialysisStartTime != null && t.F_DialysisEndTime != null);
            var listTarget = GetList(visitDate, visitNo);
            //查询不包含的数据
            var c = (from r in listSourse
                     where !listTarget.Any(t => t.F_Vid == r.F_Id)
                     select r).ToList();

            //没有 返回
            if (c.Count == 0)
            {
                return;
            }
            //患者列表
            var patientList = from r in _patientApp.GetQueryable()
                              where c.Any(t => t.F_Pid == r.F_Id)
                              select new
            {
                r.F_Id,
                r.F_Name,
                r.F_Gender,
                r.F_DialysisNo
            };

            var bedList = from b in _dialysisMachineApp.GetQueryable()
                          select new
            {
                b.F_Id,
                b.F_GroupName,
                b.F_DialylisBedNo,
                b.F_MachineName,
                b.F_MachineNo,
                b.F_ShowOrder
            };
            //生成记录
            var addEntityList = new List <MachineProcessEntity>();

            foreach (var item in c)
            {
                var entity = new MachineProcessEntity
                {
                    F_Pid       = item.F_Pid,
                    F_Vid       = item.F_Id,
                    F_VisitDate = item.F_VisitDate,
                    F_VisitNo   = item.F_VisitNo,
                    F_Option1   = false,
                    F_Option2   = false,
                    F_Option3   = false,
                    F_Option4   = false,
                    //F_Option5 = false,
                    F_GroupName     = item.F_GroupName,
                    F_DialylisBedNo = item.F_DialysisBedNo
                };
                var p = patientList.FirstOrDefault(t => t.F_Id == item.F_Pid);
                if (p != null)
                {
                    entity.F_PName      = p.F_Name;
                    entity.F_PGender    = p.F_Gender;
                    entity.F_DialylisNo = p.F_DialysisNo;
                }
                else
                {
                    continue;
                }
                var b = bedList.FirstOrDefault(t => t.F_GroupName == item.F_GroupName && t.F_DialylisBedNo == item.F_DialysisBedNo);
                if (b != null)
                {
                    entity.F_MachineName = b.F_MachineName;
                    entity.F_MachineNo   = b.F_MachineNo;
                    entity.F_ShowOrder   = b.F_ShowOrder;
                    entity.F_Mid         = b.F_Id;
                }
                else
                {
                    continue;
                }
                entity.Create();
                entity.F_EnabledMark = true;
                addEntityList.Add(entity);
            }
            if (addEntityList.Count > 0)
            {
                //保存记录
                _service.Insert(addEntityList);
            }
            //更新记录
        }
        /// <summary>
        /// 检验结果汇总信息
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>

        public async Task <IActionResult> GetLisResultSumJson(string keyValue)
        {
            var json      = keyValue.ToJObject();
            var startDate = json.Value <DateTime>("startDate");
            var endDate   = json.Value <DateTime>("endDate");
            var itemCode  = json.Value <string>("itemCode");
            var list      = await _qualityResultApp.GetListByItemCode(startDate, endDate.AddDays(1), itemCode);

            var output = new LisResultStatisticsOutput();

            if (list.Count == 0)
            {
                return(Error("无检验数据"));
            }
            //读取分段信息
            var partitions = _qualityItemApp.GetPartitionList(itemCode).ToList();

            if (!partitions.Any())
            {
                return(Error("未设置分段信息"));
            }
            var partitionList = partitions.Select(t => new
            {
                OrderNo    = t.F_OrderNo,
                LowerCheck = t.F_LowerCheck,
                LowerValue = t.F_LowerValue.ToFloat(3),
                UpperCheck = t.F_UpperCheck,
                UpperValue = t.F_UpperValue.ToFloat(3),
                FilterType = (t.F_LowerValue != null && t.F_UpperValue == null) ? 1
                                : (t.F_LowerValue != null && t.F_UpperValue != null) ? 2
                                : (t.F_LowerValue == null && t.F_UpperValue != null) ? 3
                                : -1,
                FilterValue = (t.F_LowerValue != null && t.F_UpperValue == null) ? (t.F_LowerCheck ? "<=" + t.F_LowerValue.ToFloat(3) : "<" + t.F_LowerValue.ToFloat(3)) // 小于或小于等于最小值
                          : (t.F_LowerValue != null && t.F_UpperValue != null) ?
                              (!t.F_LowerCheck && !t.F_UpperCheck) ? (">" + t.F_LowerValue.ToFloat(3) + "  <" + t.F_UpperValue.ToFloat(3))                               //两者之间  ,四种情况
                                    : (t.F_LowerCheck && !t.F_UpperCheck) ? (">=" + t.F_LowerValue.ToFloat(3) + "  <" + t.F_UpperValue.ToFloat(3))
                                    : (!t.F_LowerCheck && t.F_UpperCheck) ? (">" + t.F_LowerValue.ToFloat(3) + "  <=" + t.F_UpperValue.ToFloat(3))
                                    : (">=" + t.F_LowerValue.ToFloat(3) + "  <=" + t.F_UpperValue.ToFloat(3))
                          : (t.F_LowerValue == null && t.F_UpperValue != null) ? (t.F_UpperCheck ? ">=" + t.F_UpperValue.ToFloat(3) : ">" + t.F_UpperValue.ToFloat(3))  //大于或大于等于最大值
                          : ""
            }).Where(t => t.FilterType > 0).OrderBy(t => t.OrderNo).ToList();

            //pie title data
            output.Title = startDate.ToChineseDateString() + " 至 " + endDate.ToChineseDateString() + list[0].F_ItemName + "统计数据"; //+ "(" + list[0].F_ItemCode + ")"
            //var qualityCode = list[0].F_ItemCode.ToUpper();

            var detailList = from r in list
                             join p in _patientApp.GetQueryable() on r.F_Pid equals p.F_Id
                             select new
            {
                r.F_Id,
                p.F_Name,
                p.F_Gender,
                p.F_BirthDay,
                r.F_ReportTime,
                r.F_ItemCode,
                r.F_ItemName,
                r.F_Result,
                r.F_Unit,
                r.F_Memo
            };

            //if (qualityCode.Equals("HGB")) //血常规统计 规则
            if (true) //血常规统计 规则
            {
                foreach (var item in detailList)
                {
                    GridDataModel model = new GridDataModel
                    {
                        F_Id         = item.F_Id,
                        F_Name       = item.F_Name,
                        F_Gender     = item.F_Gender,
                        F_BirthDay   = item.F_BirthDay,
                        F_ReportTime = item.F_ReportTime,
                        F_ItemCode   = item.F_ItemCode,
                        F_ItemName   = item.F_ItemName,
                        F_Result     = item.F_Result.ToFloat(2),
                        F_Unit       = item.F_Unit,
                        F_Memo       = item.F_Memo
                    };
                    if (model.F_BirthDay != null)
                    {
                        model.F_AgeDesc = ((int)((DateTime.Now - (DateTime)model.F_BirthDay).TotalDays / 365)).ToString() + "岁";
                    }
                    var find = partitionList.FirstOrDefault(
                        t => (t.FilterType == 1 && (t.LowerCheck ? t.LowerValue >= model.F_Result : t.LowerValue > model.F_Result)) ||
                        (t.FilterType == 2 && ((t.LowerCheck ? t.LowerValue <= model.F_Result : t.LowerValue < model.F_Result) &&
                                               (t.UpperCheck ? t.UpperValue >= model.F_Result : t.UpperValue > model.F_Result))) ||
                        (t.FilterType == 3 && (t.UpperCheck ? model.F_Result >= t.UpperValue : model.F_Result > t.UpperValue))
                        );
                    model.FilterValue = find?.FilterValue;
                    output.GridData.Add(model);
                }
                var rangeCount = 1;
                foreach (var item in partitionList)
                {
                    output.RangeData.Add(new KeyValuePair <int, string>(rangeCount++, item.FilterValue));
                    var findCount = output.GridData.Count(t => t.FilterValue == item.FilterValue);
                    output.PieData.Add(new KeyValuePair <string, float>(item.FilterValue, (findCount * 100 / list.Count).ToFloat(2)));
                    if (findCount > 0)
                    {
                        output.UlData.Add(new KeyValuePair <string, int>(item.FilterValue, findCount));
                    }
                }

                output.NormalRange = partitionList[0].FilterValue;

                //趋势图  最近6个月
                //var rows =
                var trendDateStart = DateTime.Parse(DateTime.Now.AddMonths(-6).ToString("yyyy-MM-01")); //6个月前 1号
                var trendDateEnd   = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01"));               //本月前 1号
                var rows           = from r in await _qualityResultApp.GetTrendList(trendDateStart, trendDateEnd, itemCode)
                                     select new
                {
                    ReportTime  = r.F_ReportTime,
                    Pid         = r.F_Pid,
                    ReportMonth = r.F_ReportTime.ToDateString().Substring(0, 7),
                    Result      = r.F_Result.ToFloat(2)
                };
                //rows.OrderBy(t => t.ReportTime);
                foreach (var item in rows.GroupBy(t => t.ReportMonth))
                {
                    TrendDataModel dataModel = new TrendDataModel
                    {
                        MonthDesc = item.Key
                    };
                    List <float> templist = new List <float>();
                    foreach (var ele in item.GroupBy(t => t.Pid))
                    {
                        templist.Add(ele.OrderByDescending(t => t.ReportTime).First().Result);
                    }

                    foreach (var child in partitionList)
                    {
                        int count = 0;

                        if (child.FilterType == 1)
                        {
                            count = templist.Count(t => child.LowerCheck ? t <= child.LowerValue : t < child.LowerValue);
                        }
                        else if (child.FilterType == 2)
                        {
                            count = templist.Count(t => (child.LowerCheck ? t >= child.LowerValue : t > child.LowerValue) && (child.UpperCheck ? t <= child.UpperValue : t < child.UpperValue));
                        }
                        else if (child.FilterType == 3)
                        {
                            count = templist.Count(t => child.UpperCheck ? t >= child.LowerValue : t > child.LowerValue);
                        }
                        else
                        {
                            continue;
                        }
                        dataModel.Value.Add(new KeyValuePair <string, float>(child.FilterValue, (count * 100 / templist.Count).ToFloat(2)));
                    }
                    output.TrendData.Add(dataModel);
                }
                output.TrendData = output.TrendData.OrderBy(t => t.MonthDesc).ToList();
            }

            return(Content(output.ToJson()));
        }
Ejemplo n.º 3
0
        public IActionResult GetSummaryJson(string keyValue)
        {
            BloodPressOutput output = new BloodPressOutput();

            var json      = keyValue.ToJObject();
            var startDate = json.Value <DateTime>("startDate");
            var endDate   = json.Value <DateTime>("endDate");
            var pid       = json.Value <string>("pid");

            var list = from r in _patVisitApp.GetList().Where(t => t.F_Pid == pid && t.F_DialysisEndTime != null && t.F_VisitDate >= startDate && t.F_VisitDate <= endDate && t.F_EnabledMark != false)
                       join p in _patientApp.GetQueryable() on r.F_Pid equals p.F_Id
                       select new
            {
                id        = r.F_Id,
                visitDate = r.F_VisitDate.ToDate(),
                pid       = p.F_Id,
                name      = p.F_Name,
                dayOfWeek = r.F_VisitDate.ToDate().DayOfWeek == DayOfWeek.Sunday ? 7
                                       : r.F_VisitDate.ToDate().DayOfWeek == DayOfWeek.Monday ? 1
                                       : r.F_VisitDate.ToDate().DayOfWeek == DayOfWeek.Tuesday ? 2
                                       : r.F_VisitDate.ToDate().DayOfWeek == DayOfWeek.Wednesday ? 3
                                       : r.F_VisitDate.ToDate().DayOfWeek == DayOfWeek.Thursday ? 4
                                       : r.F_VisitDate.ToDate().DayOfWeek == DayOfWeek.Friday ? 5
                                       : r.F_VisitDate.ToDate().DayOfWeek == DayOfWeek.Saturday ? 6
                                       : 0,
                ssy = r.F_SystolicPressure.ToFloat(2),
                szy = r.F_DiastolicPressure.ToFloat(2)
            };

            var count = list.Count();

            //无数据返回
            if (count == 0)
            {
                return(Content(output.ToJson()));
            }
            var firstDay    = list.OrderBy(t => t.visitDate).First().visitDate.Date;
            var firstMonday = firstDay.AddDays(
                firstDay.DayOfWeek == DayOfWeek.Monday ? 0
                : firstDay.DayOfWeek == DayOfWeek.Tuesday ? -1
                : firstDay.DayOfWeek == DayOfWeek.Wednesday ? -2
                : firstDay.DayOfWeek == DayOfWeek.Thursday ? -3
                : firstDay.DayOfWeek == DayOfWeek.Friday ? -4
                : firstDay.DayOfWeek == DayOfWeek.Saturday ? -5
                : firstDay.DayOfWeek == DayOfWeek.Sunday ? -6
                : 0
                );
            var computerList = from r in list
                               select new
            {
                weekIndex = ((int)((r.visitDate - firstMonday).TotalDays)) / 7 + 1,
                sort      = Math.Abs(r.dayOfWeek.ToFloat(1) - 3.5),
                r.id,
                r.pid,
                r.name,
                r.ssy,
                r.szy,
                desc = r.ssy + " / " + r.szy
            };


            foreach (var item in computerList.GroupBy(t => t.weekIndex))
            {
                output.WeekList.Add(item.Key);

                foreach (var child in item.GroupBy(t => t.pid))
                {
                    if (output.Patients.IndexOf(child.Key) < 0)
                    {
                        output.Patients.Add(child.Key);
                    }
                    var choosedItem = child.OrderBy(t => t.sort).FirstOrDefault();
                    if (choosedItem != null)
                    {
                        var temp = new BloodPressDatas
                        {
                            WeekIndex = item.Key,
                            Id        = choosedItem.id,
                            Pid       = choosedItem.pid,
                            Name      = choosedItem.name
                        };
                        if (choosedItem.ssy == 0f)
                        {
                            continue;
                        }
                        else
                        {
                            temp.Ssy  = choosedItem.ssy.ToString();
                            temp.Szy  = choosedItem.szy.ToString();
                            temp.Desc = choosedItem.desc;
                            if (choosedItem.ssy >= 160)
                            {
                                temp.Range = ">160";
                            }
                            else if (choosedItem.ssy >= 140)
                            {
                                temp.Range = "140-160";
                            }
                            else
                            {
                                temp.Range = "<140";
                            }
                        }
                        output.WeekDatas.Add(temp);
                    }
                }
            }
            output.WeekList.Sort();
            return(Content(output.ToJson()));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据治疗单 生成数据
        /// </summary>
        /// <param name="visitDate"></param>
        private async Task CreateDataAsync(DateTime visitDate)
        {
            //QualityResultApp resultApp = new QualityResultApp();
            var listSourse = _visitApp.GetList().Where(t => t.F_VisitDate == visitDate && t.F_DialysisStartTime != null && t.F_DialysisEndTime != null);
            var listTarget = await GetList(visitDate);

            //查询不包含的数据
            var c = from r in listSourse
                    where listTarget.All(t => t.F_Vid != r.F_Id)
                    select r;
            //查询化验结果 尿素 UREA
            var lisResltList = (from r in _resultApp.GetList()
                                where listSourse.Any(t => t.F_Pid == r.F_Pid) &&
                                r.F_ReportTime >= visitDate &&
                                r.F_ReportTime < visitDate.AddDays(1) &&
                                r.F_ItemCode == "UREA"
                                select new
            {
                r.F_Pid,
                r.F_ReportTime,
                r.F_Result
            }).ToList();
            //患者列表
            var patientList = _patientApp.GetQueryable().Where(r => listSourse.Any(t => t.F_Pid == r.F_Id))
                              .Select(r => new { r.F_Id, r.F_Name, r.F_Gender, r.F_DialysisNo });
            //生成记录
            var addEntityList = new List <ProcessFlowEntity>();

            foreach (var item in c)
            {
                var entity = new ProcessFlowEntity
                {
                    F_Pid        = item.F_Pid,
                    F_Vid        = item.F_Id,
                    F_VisitDate  = item.F_VisitDate,
                    F_VisitNo    = item.F_VisitNo,
                    F_PreWeight  = item.F_WeightTQ,
                    F_PostWeight = item.F_WeightTH,
                    F_TotalHours = (item.F_DialysisEndTime.ToDate() - item.F_DialysisStartTime.ToDate()).TotalHours.ToFloat(1)
                };
                var p = patientList.FirstOrDefault(t => t.F_Id == item.F_Pid);
                if (p != null)
                {
                    entity.F_PName      = p.F_Name;
                    entity.F_PGender    = p.F_Gender;
                    entity.F_DialylisNo = p.F_DialysisNo;
                }
                var lis = lisResltList.FindAll(t => t.F_Pid == item.F_Pid).OrderBy(t => t.F_ReportTime).ToList();
                if (lis.Count > 0)
                {
                    entity.F_PreUrea = lis[0].F_Result.ToFloat(2);
                    if (lis.Count > 1)
                    {
                        entity.F_PostUrea = lis[1].F_Result.ToFloat(2);
                    }
                }
                if (entity.F_PreWeight != null && entity.F_PostWeight != null && entity.F_PreUrea != null && entity.F_PostUrea != null)
                {
                    var preWeight  = entity.F_PreWeight.ToFloat(2);
                    var postWeight = entity.F_PostWeight.ToFloat(2);
                    if (preWeight > postWeight)
                    {
                        var preUrea  = entity.F_PreUrea.ToFloat(2);
                        var postUrea = entity.F_PostUrea.ToFloat(2);
                        if (preUrea > postUrea)
                        {
                            var duration = entity.F_TotalHours.ToFloat(1);
                            if (duration > 0)
                            {
                                //计算Kt/V
                                entity.F_Result = (-Math.Log(postUrea / preUrea - 0.008 * duration) + (4 - 3.5 * postUrea / preUrea) * (preWeight - postWeight) / postWeight).ToFloat(2);
                            }
                        }
                    }
                }
                entity.Create();
                entity.F_EnabledMark = true;
                addEntityList.Add(entity);
            }
            if (addEntityList.Count > 0)
            {
                //保存记录
                _service.Insert(addEntityList);
            }
            //更新记录
            var u = from r in listTarget
                    where r.F_PreUrea == null || r.F_PreWeight == null || r.F_PostUrea == null || r.F_PostWeight == null
                    select r;

            foreach (var item in u)
            {
                bool isModified = false;
                if (item.F_PreUrea == null || item.F_PostUrea == null)
                {
                    var lis = lisResltList.FindAll(t => t.F_Pid == item.F_Pid).OrderBy(t => t.F_ReportTime).ToList();
                    if (lis.Count > 0)
                    {
                        if (item.F_PreUrea == null)
                        {
                            item.F_PreUrea = lis[0].F_Result.ToFloat(2);
                            isModified     = true;
                        }
                        if (lis.Count > 1)
                        {
                            if (item.F_PostUrea == null)
                            {
                                item.F_PostUrea = lis[1].F_Result.ToFloat(2);
                                isModified      = true;
                            }
                        }
                    }
                }
                if (item.F_PreWeight == null || item.F_PostWeight == null)
                {
                    var find = listSourse.FirstOrDefault(t => t.F_Pid == item.F_Pid);
                    if (item.F_PreWeight == null)
                    {
                        item.F_PreWeight = find.F_WeightTQ;
                        isModified       = true;
                    }
                    if (item.F_PostWeight == null)
                    {
                        item.F_PreWeight = find.F_WeightTH;
                        isModified       = true;
                    }
                }
                if (item.F_PreWeight != null && item.F_PostWeight != null && item.F_PreUrea != null && item.F_PostUrea != null)
                {
                    var preWeight  = item.F_PreWeight.ToFloat(2);
                    var postWeight = item.F_PostWeight.ToFloat(2);
                    if (preWeight > postWeight)
                    {
                        var preUrea  = item.F_PreUrea.ToFloat(2);
                        var postUrea = item.F_PostUrea.ToFloat(2);
                        if (preUrea > postUrea)
                        {
                            var duration = item.F_TotalHours.ToFloat(1);
                            if (duration > 0)
                            {
                                //计算Kt/V
                                item.F_Result = (-Math.Log(postUrea / preUrea - 0.008 * duration) + (4 - 3.5 * postUrea / preUrea) * (preWeight - postWeight) / postWeight).ToFloat(2);
                                isModified    = true;
                            }
                        }
                    }
                }
                if (isModified)
                {
                    _service.Update(item);
                }
            }
        }