public void DownloadInfectionStatisticsFile(int year, string templateFile)
        {
            var response = this.GetInfectionStatisticsData(year);
            SheetParameterContainer sheetParameterContainer = new SheetParameterContainer()
            {
                SheetName = "统计总表"
            };

            dynamic[] categorys = new dynamic[] {
                new { category = "001", rowIndex = 7 },     //上呼吸道感染人次
                new { category = "002", rowIndex = 9 },     //下呼吸道感染人次
                new { category = "003", rowIndex = 14 },    //使用导尿管感染人次
                new { category = "004", rowIndex = 17 },    //未使用导尿管感染人次
                new { category = "005", rowIndex = 19 },    //疥疮感染人次
                // new { category = "usedPipe", rowIndex = 13 },   //使用导尿管人日数
            };
            List <ElementFormatter> elementFormatters = new List <ElementFormatter>();

            // 生成年份参数
            sheetParameterContainer.ParameterList.Add(new Parameter()
            {
                Name = "year", RowIndex = 0, ColumnIndex = 1
            });
            elementFormatters.Add(new CellFormatter(sheetParameterContainer["year"], year));

            for (int i = 0; i < categorys.Length; i++)
            {
                var item = categorys[i];
                elementFormatters.Add(NewTableFormatter(response, sheetParameterContainer, item.rowIndex, item.category));
            }

            #region 住民总人日数
            int row = 2, col = 0;
            int queryMonth = 0;
            IReportManageService reportManageService = IOCContainer.Instance.Resolve <IReportManageService>();

            var dbSet = unitOfWork.GetRepository <LTC_IPDREG>().dbSet.Where(o => o.ORGID == orgId && (o.IPDFLAG == "I") && o.INDATE.HasValue && ((DateTime)o.INDATE).Year == year).AsQueryable();
            var ipd   = (from a in dbSet
                         let Year = SqlFunctions.DatePart("Year", (DateTime)a.INDATE)
                                    let Month = SqlFunctions.DatePart("Month", (DateTime)a.INDATE)
                                                group a by new { Year, Month } into g
                         where g.Key.Year == year
                         select new StatisticItem {
                Year = g.Key.Year, Month = g.Key.Month, Total = g.Count()
            });
            var ipdRegList = ipd.ToList();
            int maxMonth   = 0;
            if (ipdRegList != null && ipdRegList.Count > 0)
            {
                maxMonth = ipdRegList.OrderByDescending(s => s.Month).FirstOrDefault().Month;
            }

            for (int j = 1; j <= 12; j++)
            {
                decimal leaveHospTotal = 0;
                decimal unPlanIpdTotal = 0;
                col = j;
                if (col > maxMonth)
                {
                    queryMonth = 0;
                }
                else
                {
                    queryMonth = col;
                }

                decimal total =
                    unitOfWork.GetRepository <LTC_IPDREG>()
                    .dbSet.Count(
                        o =>
                        o.ORGID == orgId && (o.IPDFLAG == "I") && o.INDATE.HasValue &&
                        ((DateTime)o.INDATE).Year == year && ((DateTime)o.INDATE).Month <= queryMonth);

                decimal ipdRegInTotal = total * DateTime.DaysInMonth(year, j);                                                         //当月在院住民总人日数

                decimal ipdRegOutTotal = reportManageService.OutLeaveUnPlanTotal(year, col, reportManageService.GetIpdOutTotal(year)); //当月结案的人日次数

                if (ipdRegInTotal == 0 && ipdRegOutTotal == 0)
                {
                    leaveHospTotal = 0;
                    unPlanIpdTotal = 0;
                }
                else
                {
                    leaveHospTotal = reportManageService.OutLeaveUnPlanTotal(year, col, reportManageService.GetLeaveHospTotal(year)); // 当月请假的人日次数
                    unPlanIpdTotal = reportManageService.OutLeaveUnPlanTotal(year, col, reportManageService.GetUnPlanIpdTotal(year)); //当月非计划住院人日次数
                }
                decimal ipdRegCount = ipdRegInTotal + ipdRegOutTotal - leaveHospTotal - unPlanIpdTotal;                               //当月住民总人日数
                elementFormatters.Add(new CellFormatter(new Parameter()
                {
                    Name = string.Format("{0}_{1}", row, col), RowIndex = row, ColumnIndex = col
                }, ipdRegCount));
            }
            #endregion

            #region 使用导尿管人日数

            row = 13;
            for (int j = 1; j <= 12; j++)
            {
                decimal sTotal = 0;
                col = j;
                if (col <= maxMonth)
                {
                    sTotal = reportManageService.OutLeaveUnPlanTotal(year, col, reportManageService.GetUsedPipeDaysTotal(year));
                }
                else
                {
                    sTotal = 0;
                }

                elementFormatters.Add(new CellFormatter(new Parameter()
                {
                    Name = string.Format("{0}_{1}", row, col), RowIndex = row, ColumnIndex = col
                }, sTotal));
            }
            #endregion
            ExportHelper.ExportToWeb(templateFile, Path.GetFileName(templateFile), new SheetFormatter("统计总表", elementFormatters.Where(it => it != null).ToArray()));
        }
Beispiel #2
0
        protected override void Operation(WordDocument doc)
        {
            doc.ReplaceText("Org", GetOrgName(SecurityHelper.CurrentPrincipal.OrgId));
            DateTime now = StartDate;

            doc.ReplaceText("year", now.Year.ToString());
            doc.ReplaceText("month", now.Month.ToString());
            IReportManageService reportManageService = IOCContainer.Instance.Resolve <IReportManageService>();
            decimal total         = reportManageService.GetResidentTotal(now);
            decimal ipdRegInTotal = total * DateTime.DaysInMonth(now.Year, now.Month);                                          //当月在院住民总人日数

            decimal ipdRegOutTotal = OutLeaveUnPlanTotal(now.Year, now.Month, reportManageService.GetIpdOutTotal(now.Year));    //当月结案的人日次数
            decimal leaveHospTotal = OutLeaveUnPlanTotal(now.Year, now.Month, reportManageService.GetLeaveHospTotal(now.Year)); // 当月请假的人日次数
            decimal unPlanIpdTotal = OutLeaveUnPlanTotal(now.Year, now.Month, reportManageService.GetUnPlanIpdTotal(now.Year)); //当月非计划住院人日次数
            decimal ipdRegCount    = ipdRegInTotal + ipdRegOutTotal - leaveHospTotal - unPlanIpdTotal;                          //当月住民总人日数

            if (ipdRegCount == 0)
            {
                doc.ReplaceText("UTotal", "0");
                doc.ReplaceText("STotal", "0");
                doc.ReplaceText("CTotal", "0");
                doc.ReplaceText("NTotal", "0");
                doc.ReplaceText("RTotal", "0");
                doc.ReplaceText("N0", "0");
                doc.ReplaceText("N1", "0");
                doc.ReplaceText("N2", "0");
                doc.ReplaceText("N3", "0");
                doc.ReplaceText("N4", "0");
                doc.ReplaceText("N5", "0");
                doc.ReplaceText("R0", "0");
                doc.ReplaceText("R1", "0");
                doc.ReplaceText("R2", "0");
                doc.ReplaceText("R3", "0");
                doc.ReplaceText("R4", "0");
                doc.ReplaceText("R5", "0");
                doc.ReplaceText("CompareNum", "");
                doc.ReplaceText("ReasonInfo", "");
                doc.ReplaceText("CompareState", "");
                return;
            }
            doc.ReplaceText("CTotal", ipdRegCount.ToString("#0"));

            var     list       = reportManageService.GetInfection(now);
            var     lastList   = reportManageService.GetInfection(now.AddMonths(-1));
            decimal nTotal     = list.Sum(o => o.Total);
            decimal lastnTotal = lastList.Sum(o => o.Total);

            if (nTotal == 0)
            {
                doc.ReplaceText("NTotal", "0");
                doc.ReplaceText("RTotal", "0");
            }
            else
            {
                doc.ReplaceText("NTotal", nTotal.ToString("#0"));
                doc.ReplaceText("RTotal", (nTotal / ipdRegCount * 100).ToString("#0.0"));
            }

            if (nTotal < lastnTotal)
            {
                doc.ReplaceText("CompareNum", "较上月有所减少,");
            }
            else if (nTotal == lastnTotal)
            {
                doc.ReplaceText("CompareNum", "较上月相同,");
            }
            else if (nTotal > lastnTotal)
            {
                doc.ReplaceText("CompareNum", "较上月有所增加,");
            }

            // 使用导尿管(膀胱)人日数
            decimal blTotal = OutLeaveUnPlanTotal(now.Year, now.Month, reportManageService.GetUsedPipeDaysTotal(now.Year, "002"));
            // 使用导尿管(尿道)人日数
            decimal urTotal = OutLeaveUnPlanTotal(now.Year, now.Month, reportManageService.GetUsedPipeDaysTotal(now.Year, "003"));

            decimal sTotal = blTotal + urTotal;   //使用导尿管人日数

            decimal uTotal = ipdRegCount - sTotal;

            doc.ReplaceText("STotal", sTotal.ToString("#0"));
            doc.ReplaceText("UTotal", uTotal.ToString("#0"));
            var keys    = new[] { "001", "002", "003", "004", "005" };
            var msgInfo = string.Empty;

            for (int i = 0; i < 5; i++)
            {
                if (nTotal == 0)
                {
                    doc.ReplaceText("N" + i, "0");
                    doc.ReplaceText("R" + i, "0");
                    msgInfo += "";
                    continue;
                }
                var obj = list.FirstOrDefault(o => o.Type == keys[i]);
                if (obj != null)
                {
                    if (i == 2)
                    {
                        doc.ReplaceText("N" + i, obj.Total.ToString());
                        doc.ReplaceText("R" + i, sTotal != 0 ? (obj.Total / sTotal * 100).ToString("#0.0") : "0");
                        msgInfo += obj.Total == 0 ? "" : (",当月使用存留导尿管泌尿道感染人次" + obj.Total.ToString() + "位");
                    }
                    else if (i == 3)
                    {
                        doc.ReplaceText("N" + i, obj.Total.ToString());
                        doc.ReplaceText("R" + i, uTotal != 0 ? (obj.Total / uTotal * 100).ToString("#0.0") : "0");
                        msgInfo += obj.Total == 0 ? "" : (",当月未使用存留导尿管泌尿道感染人次" + obj.Total.ToString() + "位");
                    }
                    else
                    {
                        doc.ReplaceText("N" + i, obj.Total.ToString());
                        doc.ReplaceText("R" + i, (obj.Total / ipdRegCount * 100).ToString("#0.0"));
                    }
                }
                else
                {
                    doc.ReplaceText("N" + i, "0");
                    doc.ReplaceText("R" + i, "0");
                    msgInfo += "";
                }
            }

            var non1 = list.Where(o => o.Type == "001" || o.Type == "002").Sum(o => o.Total);

            msgInfo += non1 == 0 ? "" : (",当月呼吸道感染人次" + non1.ToString() + "位");

            var n5 = list.Where(o => o.Type == "003" || o.Type == "004").Sum(o => o.Total);

            doc.ReplaceText("N5", n5.ToString());
            doc.ReplaceText("R5", n5 != 0 ? (n5 / ipdRegCount * 100).ToString("#0.0") : "0");
            msgInfo += n5 == 0 ? "" : (",当月泌尿道感染人次" + non1.ToString() + "位");

            var n4 = list.Where(o => o.Type == "005").Sum(o => o.Total);

            msgInfo += n4 == 0 ? "" : (",当月皮肤感染人次" + n4.ToString() + "位");

            doc.ReplaceText("ReasonInfo", msgInfo);
        }