/// <summary> /// Get Heat Map for clients /// </summary> /// <param name="heatMapRequest"></param> /// <returns></returns> public string GetClientsHeatMap(ClientsHeatMapRequestViewModel heatMapRequest) { String json = string.Empty; string heatMapItemsJson = string.Empty; string heatMapJson = string.Empty; try { UserContext userContext = UserHelper.getUserContext(); if (heatMapRequest != null && heatMapRequest.EmployeeID == null) { heatMapRequest.EmployeeID = userContext.UserId; } ClientsHeatMapRequest request = BusinessMapper.MappingHeatMapViewModelToBusinessModel(heatMapRequest); HeatMapDetails heatMapDetails = _clientsHeatMapRepository.GetHeatMapForClients(request); if (heatMapDetails != null && heatMapDetails.ClientsHeatMapList != null && heatMapDetails.ClientsHeatMapList.Count > 0) { ClientsHeatMapResponse[] clientsHeatMapItemsArray = heatMapDetails.ClientsHeatMapList.ToArray(); List <IDictionary <string, object> > pivotArray = clientsHeatMapItemsArray.ToPivotArray(item => item.HeatMapItemName, item => item.ClientCode, items => items.Any() ? items.First().HeatMapItemNameDetail : new HeatMapItemDetail()); foreach (IDictionary <string, object> ele in pivotArray) { int? riskFactorScore = null; int? metricScore = null; List <object> metricRiskFactors = ele.Where(x => x.Key != "ClientCode").Select(x => x.Value).ToList(); List <HeatMapItemDetail> heatmapItems = new List <HeatMapItemDetail>(); foreach (HeatMapItemDetail item in metricRiskFactors) { if (item.Type == "RiskFactor" && item.Score != null) { if (riskFactorScore == null) { riskFactorScore = item.Score; } else { riskFactorScore += item.Score; } } if (item.Type == "Metric" && item.Score != null) { if (metricScore == null) { metricScore = item.Score; } else { metricScore += item.Score; } } } ClientsHeatMapResponse result = heatMapDetails.ClientsHeatMapList.First(c => c.ClientCode == (ele.ContainsKey("ClientCode") ? (string)ele["ClientCode"] : string.Empty)); if (result != null) { ele.Add("ChecklistMonthlyDate", result.ChecklistMonthlyDate != null ? result.ChecklistMonthlyDate.Value.ToString("MMM") : "N/A"); ele.Add("ChecklistWeeklyDate", result.ChecklistWeeklyDate != null ? result.ChecklistWeeklyDate.Value.ToString("dd MMM") : "N/A"); ele.Add("ClientName", result.ClientName); ele.Add("LTM", result.Ltm); ele.Add("MetricScore", metricScore); ele.Add("RiskFactorScore", riskFactorScore); ele.Add("Risk", result.Risk); ele.Add("RiskPercent", result.RiskPercentage); ele.Add("RiskPercentClass", result.RiskPercentage != null ? "risk_" + result.RiskPercentage : ""); ele.Add("SiteAcronym", result.SiteAcronym); ele.Add("Specialty", result.Specialty); ele.Add("BusinessUnitCode", result.BusinessUnitCode); ele.Add("SystemCode", result.SystemCode); string trendStatus = string.Empty; if (result.Trend != null) { trendStatus = result.Trend == result.Risk ? "trend_equal" : (result.Trend < result.Risk ? "fa-caret-down red_Trend" : "fa-caret-up green_Trend"); } ele.Add("Trend", trendStatus); } } heatMapJson = JsonConvert.SerializeObject(pivotArray, new KeyValuePairConverter()); } if (heatMapDetails != null && heatMapDetails.HeatMapItemTypeDetail != null && heatMapDetails.HeatMapItemTypeDetail.Count > 0) { heatMapItemsJson = JsonConvert.SerializeObject(heatMapDetails.HeatMapItemTypeDetail); } json = JsonConvert.SerializeObject(new { heatmaps = heatMapJson, heatmapItems = heatMapItemsJson }); return(json); } catch (Exception ex) { _logger.Log(ex, LogLevel.Error, ex.Message); return(null); } }
/// <summary> /// Get HeatMap ForClients & HeatMap Questions /// </summary> /// <param name="heatMapRequest"></param> /// <returns></returns> public HeatMapDetails GetHeatMapForClients(ClientsHeatMapRequest heatMapRequest) { try { HeatMapDetails heatMapDetails = new HeatMapDetails(); List <ClientsHeatMapResponse> heatmaps = new List <ClientsHeatMapResponse>(); List <HeatMapItemTypeDetail> heatmapItems = new List <HeatMapItemTypeDetail>(); string ConnectionString = ConfigurationExtensions.GetConnectionString(_Configuration, "M3PactConnection"); using (SqlConnection sqlConn = new SqlConnection(ConnectionString)) { using (SqlCommand sqlCmd = new SqlCommand(DomainConstants.GetHeatMapForApplicableClients, sqlConn)) { sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddWithValue("@EmployeeID", heatMapRequest.EmployeeID); sqlCmd.Parameters.AddWithValue("@BusinessUnitCode", heatMapRequest.BusinessUnitCode); sqlCmd.Parameters.AddWithValue("@SystemCode", heatMapRequest.SystemCode); sqlCmd.Parameters.AddWithValue("@SpecialtyCode", heatMapRequest.SpecialtyCode); sqlConn.Open(); SqlDataReader reader = sqlCmd.ExecuteReader(); while (reader.Read()) { ClientsHeatMapResponse clientsHeatMapResponse = new ClientsHeatMapResponse(); if (reader["ClientName"] != DBNull.Value) { clientsHeatMapResponse.ClientName = Convert.ToString(reader["ClientName"]); } if (reader["ClientCode"] != DBNull.Value) { clientsHeatMapResponse.ClientCode = Convert.ToString(reader["ClientCode"]); } if (reader["SpecialityName"] != DBNull.Value) { clientsHeatMapResponse.Specialty = Convert.ToString(reader["SpecialityName"]); } if (reader["SiteAcronym"] != DBNull.Value) { clientsHeatMapResponse.SiteAcronym = Convert.ToString(reader["SiteAcronym"]); } if (reader["BusinessUnitCode"] != DBNull.Value) { clientsHeatMapResponse.BusinessUnitCode = Convert.ToString(reader["BusinessUnitCode"]); } if (reader["SystemCode"] != DBNull.Value) { clientsHeatMapResponse.SystemCode = Convert.ToString(reader["SystemCode"]); } if (reader["LTM"] != DBNull.Value) { clientsHeatMapResponse.Ltm = Convert.ToDecimal(reader["LTM"]); } if (reader["HeatMapItemName"] != DBNull.Value) { clientsHeatMapResponse.HeatMapItemName = Convert.ToString(reader["HeatMapItemName"]); } if (reader["HeatMapItemNameScore"] != DBNull.Value) { clientsHeatMapResponse.HeatMapItemNameDetail.Score = Convert.ToInt32(reader["HeatMapItemNameScore"]); } if (reader["HeatMapItemType"] != DBNull.Value) { clientsHeatMapResponse.HeatMapItemNameDetail.Type = Convert.ToString(reader["HeatMapItemType"]); } if (reader["Risk"] != DBNull.Value) { clientsHeatMapResponse.Risk = Convert.ToInt32(reader["Risk"]); } if (reader["RiskPercentage"] != DBNull.Value) { clientsHeatMapResponse.RiskPercentage = Convert.ToInt32(reader["RiskPercentage"]); } if (reader["Trend"] != DBNull.Value) { clientsHeatMapResponse.Trend = Convert.ToInt32(reader["Trend"]); } if (reader["ChecklistWeeklyDate"] != DBNull.Value) { clientsHeatMapResponse.ChecklistWeeklyDate = Convert.ToDateTime(reader["ChecklistWeeklyDate"]); } if (reader["ChecklistMonthlyDate"] != DBNull.Value) { clientsHeatMapResponse.ChecklistMonthlyDate = Convert.ToDateTime(reader["ChecklistMonthlyDate"]); } if (reader["AlertLevel"] != DBNull.Value) { clientsHeatMapResponse.HeatMapItemNameDetail.AlertLevel = Convert.ToString(reader["AlertLevel"]); } if (reader["ActualValue"] != DBNull.Value) { clientsHeatMapResponse.HeatMapItemNameDetail.ActualValue = Convert.ToString(reader["ActualValue"]); } heatmaps.Add(clientsHeatMapResponse); } if (reader.NextResult()) { while (reader.Read()) { HeatMapItemTypeDetail heatmapItem = new HeatMapItemTypeDetail(); if (reader["HeatMapItemName"] != DBNull.Value) { heatmapItem.HeatMapItemName = Convert.ToString(reader["HeatMapItemName"]); } if (reader["HeatMapItemType"] != DBNull.Value) { heatmapItem.HeatMapItemType = Convert.ToString(reader["HeatMapItemType"]); } if (reader["HeatMapItemMeasureType"] != DBNull.Value) { heatmapItem.HeatMapItemMeasureType = Convert.ToString(reader["HeatMapItemMeasureType"]); } heatmapItems.Add(heatmapItem); } } heatMapDetails.ClientsHeatMapList = heatmaps; heatMapDetails.HeatMapItemTypeDetail = heatmapItems; } sqlConn.Close(); } return(heatMapDetails); } catch (Exception ex) { throw ex; } }