예제 #1
0
        public JsonResult Delays(string delayType, int?patientId)
        {
            ApptDelayCurrData apptsData = null;

            try
            {
                apptsData = clinicService.GetCurrAppointmentDelays(delayType, patientId);
            }
            catch (Exception ex)
            {
                //TODO: Handle exception
            }

            return(Json(apptsData, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public ApptDelayCurrData GetCurrAppointmentDelays(string delayType, int?patientId)
        {
            List <ApptDelayItem> currMonthData = new List <ApptDelayItem>();
            List <ApptDelayItem> currWeekData  = null;
            DataSet           dataset          = new DataSet();
            DataTable         dtApptDelays;
            DateTime          monthStartDate, monthEndDate, weekStartDate, weekEndDate, currDate;
            ApptDelayCurrData response = null;

            currDate = DateTime.Now;

            weekStartDate  = currDate.AddDays(-(int)currDate.DayOfWeek).Date;
            weekEndDate    = weekStartDate.AddDays(7).AddSeconds(-1);
            monthStartDate = new DateTime(currDate.Year, currDate.Month, 1);
            monthEndDate   = monthStartDate.AddMonths(1).AddDays(-1);

            monthEndDate = (currDate.Day <= monthEndDate.Day) ? currDate : monthEndDate;
            weekEndDate  = (currDate.Day <= weekEndDate.Day) ? currDate : weekEndDate;

            using (SqlConnection conn = new SqlConnection(connString))
            {
                SqlCommand cmd = new SqlCommand("dashboard_get_appointment_delays", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@fromDate", SqlDbType.DateTime).Value = monthStartDate;
                cmd.Parameters.Add("@toDate", SqlDbType.DateTime).Value   = monthEndDate;
                if (!string.IsNullOrEmpty(delayType))
                {
                    cmd.Parameters.Add("@delayType", SqlDbType.NVarChar).Value = delayType;
                }
                if (patientId != null)
                {
                    cmd.Parameters.Add("@patientId", SqlDbType.NVarChar).Value = patientId.Value;
                }
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                cmd.Connection = conn;
                adapter.Fill(dataset);

                dtApptDelays = dataset.Tables[0];

                foreach (DataRow row in dtApptDelays.Rows)
                {
                    currMonthData.Add(new ApptDelayItem
                    {
                        TotalDelays = Convert.ToInt32(row["TotalDelays"]),
                        Date        = Convert.ToDateTime(row["CreatedOn"])
                    });
                }
            }

            if (currMonthData != null)
            {
                currWeekData = currMonthData.FindAll(a => a.Date >= weekStartDate && a.Date <= weekEndDate);
            }

            response = new ApptDelayCurrData();
            response.CurrentWeekData = new ApptDelayData {
                Data = currWeekData, StartDate = weekStartDate, EndDate = weekEndDate
            };
            response.CurrentMonthData = new ApptDelayData {
                Data = currMonthData, StartDate = monthStartDate, EndDate = monthEndDate
            };

            return(response);
        }