Пример #1
0
        public JsonResult GetSummaryForYearJM(int hospitalId, int epiYear)
        {
            int      nSemaActual;
            DateTime dSEHoy;
            List <Dictionary <string, int> > summaryPerYear = new List <Dictionary <string, int> >();
            DateTime dFech = PAHOClassUtilities.fechaInicioPrimeraSemanaEpidemiologica(epiYear);

            if (DateTime.Today.Year == epiYear)
            {
                nSemaActual = PAHOClassUtilities.NumeroActualSE();
                dSEHoy      = dFech.AddDays((nSemaActual - 1) * 7).AddDays(6);
            }
            else
            {
                nSemaActual = PAHOClassUtilities.semanasAnioEpidemiologico(epiYear);
                dSEHoy      = PAHOClassUtilities.fechaInicioPrimeraSemanaEpidemiologica(epiYear);
                dSEHoy      = dSEHoy.AddDays(-1);
            }

            //****
            string hospitalIDs = "";
            IQueryable <Institution> institutions = null;
            var user = UserManager.FindById(User.Identity.GetUserId());

            if (user.Institution is Hospital || user.Institution is AdminInstitution)
            {
                if (user.Institution.AccessLevel == AccessLevel.Country)
                {
                    institutions = db.Institutions
                                   .Where(i => i.CountryID == user.Institution.CountryID && i.ILI == true).OrderBy(n => n.FullName);
                }
                else if (user.Institution.AccessLevel == AccessLevel.Area)      // Jamaica: Parish
                {
                    institutions = db.Institutions
                                   .Where(i => i.AreaID == user.Institution.AreaID && i.ILI == true).OrderBy(n => n.FullName);
                }
                else
                {
                    institutions = db.Institutions.OfType <Hospital>()
                                   .Where(i => i.ID == user.Institution.ID).OrderBy(n => n.FullName);
                }

                foreach (var inst in institutions)
                {
                    hospitalIDs += inst.ID.ToString() + ",";
                }
                hospitalIDs = hospitalIDs.Substring(0, hospitalIDs.Length - 1);
            }

            //****
            Dictionary <string, int> aILICaseTG = new Dictionary <string, int>();
            Dictionary <string, int> aILISampTG = new Dictionary <string, int>();
            Dictionary <string, int> aTotVisiTG = new Dictionary <string, int>();

            int countryId  = (int)user.Institution.CountryID;
            int weekFrom   = 1;
            var consString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            using (var con = new SqlConnection(consString))
            {
                using (var command = new SqlCommand("Summary_ILI_TotalByEW", con)
                {
                    CommandType = CommandType.StoredProcedure, CommandTimeout = 600
                })
                {
                    command.Parameters.Clear();
                    command.Parameters.Add("@Country_ID", SqlDbType.Int).Value       = countryId;
                    command.Parameters.Add("@Year_case", SqlDbType.Int).Value        = epiYear;
                    command.Parameters.Add("@Hospital_ID", SqlDbType.NVarChar).Value = hospitalIDs;
                    command.Parameters.Add("@weekFrom", SqlDbType.Int).Value         = weekFrom;
                    command.Parameters.Add("@weekTo", SqlDbType.Int).Value           = nSemaActual;

                    con.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string cAnio = reader.GetValue(0).ToString();
                            string cWE   = reader.GetValue(1).ToString();

                            aILICaseTG.Add(cAnio + cWE, (int)reader.GetValue(2));
                            aILISampTG.Add(cAnio + cWE, (int)reader.GetValue(3));
                            aTotVisiTG.Add(cAnio + cWE, (int)reader.GetValue(4));
                        }
                    }

                    command.Parameters.Clear();
                    con.Close();
                }
            }

            //****
            for (int i = nSemaActual; i >= 1; i--)
            {
                Dictionary <string, int> dictionary = new Dictionary <string, int>();
                var ColILICasesST        = 0;
                var ColILISamplesTakenST = 0;
                var ColTotalVisitsST     = 0;

                DateTime WeekendDate = DateTime.UtcNow;

                var casesummary = db.CaseSummariesJM.FirstOrDefault(s => s.HospitalId == hospitalId && s.EW == i && s.EpiYear == epiYear);
                if (casesummary == null)
                {
                    DateTime vFeIn = dFech.AddDays(7 * (i - 1));
                    DateTime vFeFi = vFeIn.AddDays(6);

                    if (WeekendDate >= vFeIn && WeekendDate <= vFeFi)
                    {
                        WeekendDate = vFeFi;
                    }
                    else
                    {
                        if (vFeFi < WeekendDate)
                        {
                            WeekendDate = dFech.AddDays(7 * (i - 1) + 6);
                        }
                        else
                        {
                            WeekendDate = dSEHoy;
                        }
                    }
                }
                else
                {
                    var casesummaryDetails = casesummary.CaseSummaryDetailJM.ToArray();
                    WeekendDate = casesummary.WeekendDate;
                    foreach (CaseSummaryDetailJM casesummaryDetail in casesummaryDetails)
                    {
                        ColILICasesST        += casesummaryDetail.ILICases;
                        ColILISamplesTakenST += casesummaryDetail.ILISamplesTaken;
                        ColTotalVisitsST     += casesummaryDetail.TotalVisits;
                    }
                }
                dictionary.Add("EpiWeek", i);
                dictionary.Add("ColILICasesST", ColILICasesST);
                dictionary.Add("ColILISamplesTakenST", ColILISamplesTakenST);
                dictionary.Add("ColTotalVisitsST", ColTotalVisitsST);
                Int32 unixTimestamp = (Int32)(WeekendDate.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                dictionary.Add("WeekendDate", unixTimestamp);
                dictionary.Add("EpiYear", epiYear);
                //****
                dictionary.Add("ColILICaseGroup", aILICaseTG[epiYear.ToString() + i.ToString()]);
                dictionary.Add("ColILISampGroup", aILISampTG[epiYear.ToString() + i.ToString()]);
                dictionary.Add("ColTotVisiGroup", aTotVisiTG[epiYear.ToString() + i.ToString()]);

                //****
                summaryPerYear.Add(dictionary);
            }

            //System.Diagnostics.Debug.WriteLine("F2->" + DateTime.Now.ToString());     //=> OKOK
            return(Json(summaryPerYear, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetSummaryForYear(int hospitalId, int epiYear)
        {
            int      nSemaActual;
            DateTime dSEHoy;
            List <Dictionary <string, int> > summaryPerYear = new List <Dictionary <string, int> >();
            DateTime dFech = PAHOClassUtilities.fechaInicioPrimeraSemanaEpidemiologica(epiYear);

            if (DateTime.Today.Year == epiYear)
            {
                nSemaActual = PAHOClassUtilities.NumeroActualSE();
                dSEHoy      = dFech.AddDays((nSemaActual - 1) * 7).AddDays(6);
            }
            else
            {
                nSemaActual = PAHOClassUtilities.semanasAnioEpidemiologico(epiYear);
                dSEHoy      = PAHOClassUtilities.fechaInicioPrimeraSemanaEpidemiologica(epiYear);
                dSEHoy      = dSEHoy.AddDays(-1);
            }

            for (int i = nSemaActual; i >= 1; i--)
            {
                Dictionary <string, int> dictionary = new Dictionary <string, int>();
                var      ColETINumST     = 0;
                var      ColETIDenoST    = 0;
                var      ColETINumEmerST = 0;
                var      ColHospTST      = 0;
                var      ColUCITST       = 0;
                var      ColFalleTST     = 0;
                var      ColHospSARITST  = 0;       //#### CAFQ: 181101
                var      ColUCISARITST   = 0;       //#### CAFQ: 181101
                var      ColFalleSARITST = 0;       //#### CAFQ: 181101
                var      ColNeuTST       = 0;
                var      ColCCSARITST    = 0;
                var      ColVentTST      = 0;
                DateTime StartDateOfWeek = DateTime.UtcNow;

                var casesummary = db.CaseSummaries.FirstOrDefault(s => s.HosiptalId == hospitalId && s.EW == i && s.EpiYear == epiYear);
                if (casesummary == null)
                {
                    DateTime vFeIn = dFech.AddDays(7 * (i - 1));
                    DateTime vFeFi = vFeIn.AddDays(6);

                    if (StartDateOfWeek >= vFeIn && StartDateOfWeek <= vFeFi)
                    {
                        StartDateOfWeek = vFeFi;
                    }
                    else
                    {
                        if (vFeFi < StartDateOfWeek)
                        {
                            StartDateOfWeek = dFech.AddDays(7 * (i - 1) + 6);
                        }
                        else
                        {
                            StartDateOfWeek = dSEHoy;
                        }
                    }
                }
                else
                {
                    var casesummaryDetails = casesummary.CaseSummaryDetails.ToArray();
                    StartDateOfWeek = casesummary.StartDateOfWeek;
                    foreach (CaseSummaryDetail casesummaryDetail in casesummaryDetails)
                    {
                        ColETINumST     += casesummaryDetail.ETINumST;
                        ColETIDenoST    += casesummaryDetail.ETIDenoST;
                        ColETINumEmerST += casesummaryDetail.ETINumEmerST;
                        ColHospTST      += casesummaryDetail.HospST;
                        ColUCITST       += casesummaryDetail.UCIST;
                        ColFalleTST     += casesummaryDetail.DefST;
                        ColHospSARITST  += casesummaryDetail.HospSARIST;            //#### CAFQ: 181101
                        ColUCISARITST   += casesummaryDetail.UCISARIST;             //#### CAFQ: 181101
                        ColFalleSARITST += casesummaryDetail.DefSARIST;             //#### CAFQ: 181101
                        ColNeuTST       += casesummaryDetail.NeuST.HasValue ? casesummaryDetail.NeuST.Value : 0;
                        //ColCCSARITST += casesummaryDetail.CCSARIST.HasValue ? casesummaryDetail.CCSARIST.Value : 0;
                        ColCCSARITST += casesummaryDetail.CCSARIST.Value;
                        ColVentTST   += casesummaryDetail.VentST.HasValue ? casesummaryDetail.VentST.Value : 0;
                    }
                }
                dictionary.Add("EpiWeek", i);
                dictionary.Add("ColHospTST", ColHospTST);
                dictionary.Add("ColUCITST", ColUCITST);
                dictionary.Add("ColFalleTST", ColFalleTST);
                dictionary.Add("ColHospSARITST", ColHospSARITST);           //#### CAFQ: 181101
                dictionary.Add("ColUCISARITST", ColUCISARITST);             //#### CAFQ: 181101
                dictionary.Add("ColFalleSARITST", ColFalleSARITST);         //#### CAFQ: 181101
                dictionary.Add("ColETINumST", ColETINumST);
                dictionary.Add("ColETIDenoST", ColETIDenoST);
                dictionary.Add("ColETINumEmerST", ColETINumEmerST);
                dictionary.Add("ColNeuTST", ColNeuTST);
                dictionary.Add("ColCCSARITST", ColCCSARITST);
                dictionary.Add("ColVentTST", ColVentTST);
                Int32 unixTimestamp = (Int32)(StartDateOfWeek.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                dictionary.Add("StartDateOfWeek", unixTimestamp);
                dictionary.Add("EpiYear", epiYear);
                //dictionary.Add("HospitalId", hospitalId);

                summaryPerYear.Add(dictionary);
            }

            return(Json(summaryPerYear, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public JsonResult GetSummaryForYearJM(int hospitalId)
        {
            var epiYear    = DateTime.Now.Year.ToString();
            int intEpiYear = Int32.Parse(epiYear);
            List <Dictionary <string, int> > summaryPerYear = new List <Dictionary <string, int> >();
            ///////DateTime dFech = fechaInicioPrimeraSemanaEpidemiologica(DateTime.UtcNow.Year);
            DateTime dFech       = PAHOClassUtilities.fechaInicioPrimeraSemanaEpidemiologica(DateTime.Today.Year);
            int      nSemaActual = PAHOClassUtilities.NumeroActualSE();
            //dFech = dFech.AddDays(6);
            DateTime dSEHoy;

            dSEHoy = dFech.AddDays((nSemaActual - 1) * 7).AddDays(6);

            //#### Fecha fin de SE del dia de hoy

            /*DateTime dSEHoy;
             * DateTime dHoy = DateTime.Now.Date;
             * dSEHoy = dHoy;
             *
             * for (int i = 52; i >= 1; i--)
             * {
             *  DateTime vSeIn = dFech.AddDays(7 * (i - 1));
             *  DateTime vSeFi = vSeIn.AddDays(6);
             *  if (dHoy >= vSeIn && dHoy <= vSeFi)
             *  {
             *      dSEHoy = vSeFi;
             *      break;
             *  }
             * }*/
            //####

            //for (int i = 1; i <= 52; i++)
            //for (int i = 52; i >= 1; i--)
            for (int i = nSemaActual; i >= 1; i--)
            {
                Dictionary <string, int> dictionary = new Dictionary <string, int>();
                var ColILICasesST        = 0;
                var ColILISamplesTakenST = 0;
                var ColTotalVisitsST     = 0;

                DateTime WeekendDate = DateTime.UtcNow;

                var casesummary = db.CaseSummariesJM.FirstOrDefault(s => s.HospitalId == hospitalId && s.EW == i && s.EpiYear == intEpiYear);
                if (casesummary == null)
                {
                    DateTime vFeIn = dFech.AddDays(7 * (i - 1));
                    DateTime vFeFi = vFeIn.AddDays(6);

                    if (WeekendDate >= vFeIn && WeekendDate <= vFeFi)
                    {
                        WeekendDate = vFeFi;
                    }
                    else
                    {
                        if (vFeFi < WeekendDate)
                        {
                            WeekendDate = dFech.AddDays(7 * (i - 1) + 6);
                        }
                        else
                        {
                            WeekendDate = dSEHoy;
                        }
                    }
                }
                else
                {
                    //var casesummaryDetails = casesummary.CaseSummaryDetailJM.ToArray();
                    var casesummaryDetails = casesummary.CaseSummaryDetailJM.ToArray();
                    WeekendDate = casesummary.WeekendDate;
                    foreach (CaseSummaryDetailJM casesummaryDetail in casesummaryDetails)
                    {//casesummaryDetails
                        ColILICasesST        += casesummaryDetail.ILICases;
                        ColILISamplesTakenST += casesummaryDetail.ILISamplesTaken;
                        ColTotalVisitsST     += casesummaryDetail.TotalVisits;
                    }
                }
                dictionary.Add("EpiWeek", i);
                dictionary.Add("ColILICasesST", ColILICasesST);
                dictionary.Add("ColILISamplesTakenST", ColILISamplesTakenST);
                dictionary.Add("ColTotalVisitsST", ColTotalVisitsST);
                Int32 unixTimestamp = (Int32)(WeekendDate.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                dictionary.Add("WeekendDate", unixTimestamp);
                dictionary.Add("EpiYear", intEpiYear);
                summaryPerYear.Add(dictionary);
            }
            return(Json(summaryPerYear, JsonRequestBehavior.AllowGet));
        }