private PatientScoreRangeData GetData(PatientScoreRangeParameters parameters) { using (var connection = _connectionFactory.CreateConnection()) { var reportDtos = connection.Query <PatientScoreRangeDto>(GetQuery(parameters)).ToList(); if (!reportDtos.Any()) { return(null); } var returnData = new PatientScoreRangeData(); var data = reportDtos.Select( reportDto => new PatientScoreRangeDataObject { Age = reportDto.PatientAge, AssessmentDate = reportDto.ScoreDate.ToShortDateString(), Change = reportDto.ScoreChange, Gender = reportDto.PatientGender, PatientName = reportDto.PatientFirstName + " " + reportDto.PatientLastName, Score = reportDto.AssessmentScore, PatientKey = reportDto.PatientKey, AssessmentInstanceKey = reportDto.AssessmentInstanceKey, AssessmentName = reportDto.AssessmentName }).ToList(); returnData.Data = data; return(returnData); } }
private string GetQuery(PatientScoreRangeParameters parameters) { const string Query = @"SELECT [AssessmentInstanceKey] ,[PatientKey] ,[AssessmentName] ,[AssessmentScore] ,[ScoreDate] ,[PatientBirthDate] ,[PatientFirstName] ,[PatientLastName] ,[PatientGender] ,[ScoreChange] ,FLOOR((CAST (GetDate() AS INTEGER) - CAST(PatientBirthDate AS INTEGER)) / 365.25) AS PatientAge FROM [ReportModule].[PatientScoreRangeReport] WHERE AssessmentCode = '{0}' {1} {2} {3} {4} ORDER BY PatientFirstName, PatientLastName, ScoreDate DESC"; const string ScoreDateWhereString = " AND (ScoreDate >= '{0}' AND ScoreDate <= DATEADD(day,1, '{1}'))"; var startDate = parameters.StartDate; var endDate = parameters.EndDate; if (parameters.TimePeriod != null) { parameters.TimePeriod.GetRange(out startDate, out endDate); } var scoreDateWhere = string.Format(ScoreDateWhereString, startDate.GetValueOrDefault().ToShortDateString(), endDate.GetValueOrDefault().ToShortDateString()); const string AgeWhereString = @"AND FLOOR((CAST (GetDate() AS INTEGER) - CAST(PatientBirthDate AS INTEGER)) / 365.25) >= {0} AND FLOOR((CAST (GetDate() AS INTEGER) - CAST(PatientBirthDate AS INTEGER)) / 365.25) <= {1}"; var ageWhere = string.Empty; if (parameters.AgeRangeLow != null && parameters.AgeRangeHigh != null) { ageWhere = string.Format(AgeWhereString, parameters.AgeRangeLow, parameters.AgeRangeHigh); } const string GenderWhereString = "AND PatientGender = '{0}'"; var genderWhere = string.Empty; if (!string.IsNullOrWhiteSpace(parameters.Gender)) { genderWhere = string.Format(GenderWhereString, parameters.Gender); } var assessmentScoreWhere = GetScoreTypeParameterString(parameters); var finalQuery = string.Format(Query, parameters.AssessmentDefinitionCode, assessmentScoreWhere, scoreDateWhere, ageWhere, genderWhere); return(finalQuery); }
private string GetScoreTypeValue(PatientScoreRangeParameters parameters) { var returnValue = string.Empty; if (parameters.ScoreType.GetType() == typeof(ScoreTypeInt)) { const string ReturnIntValue = "{0} to {1}"; var scoreInt = (ScoreTypeInt)parameters.ScoreType; returnValue = string.Format(ReturnIntValue, scoreInt.RiskStart, scoreInt.RiskEnd); } if (parameters.ScoreType.GetType() == typeof(ScoreTypeBoolean)) { var returnIntValue = PatientScoreRange.IsAtRisk + "{0}"; var scoreBool = (ScoreTypeBoolean)parameters.ScoreType; returnValue = string.Format(returnIntValue, scoreBool.IsAtRisk); } return(returnValue); }
private string GetScoreTypeParameterString(PatientScoreRangeParameters parameters) { const string AssessmentScoreIntWhereString = " AND AssessmentScore >= {0} AND AssessmentScore <= {1}"; const string AssessmentScoreBoolWhereString = " AND AssessmentScore = '{0}'"; var assessmentScoreWhere = string.Empty; if (parameters.ScoreType.GetType() == typeof(ScoreTypeInt)) { var scoreInt = (ScoreTypeInt)parameters.ScoreType; assessmentScoreWhere = string.Format(AssessmentScoreIntWhereString, scoreInt.RiskStart, scoreInt.RiskEnd); } else if (parameters.ScoreType.GetType() == typeof(ScoreTypeBoolean)) { var scoreBool = (ScoreTypeBoolean)parameters.ScoreType; assessmentScoreWhere = string.Format(AssessmentScoreBoolWhereString, scoreBool.IsAtRisk); } return(assessmentScoreWhere); }
private void SetStrings(PatientScoreRangeData data, PatientScoreRangeParameters reportParams, string reportName) { if (reportParams == null || data == null) { return; } var start = reportParams.StartDate; var end = reportParams.EndDate; var dateRange = start.GetValueOrDefault().ToShortDateString() + " - " + end.GetValueOrDefault().ToShortDateString(); if (reportParams.TimePeriod != null) { reportParams.TimePeriod.GetRange(out start, out end); dateRange = reportParams.TimePeriod.DisplayName; } var ageRange = _resourcesManager.GetResourceManagerByName(reportName).GetString("NA"); if (reportParams.AgeRangeLow != null && reportParams.AgeRangeHigh != null) { ageRange = reportParams.AgeRangeLow + " - " + reportParams.AgeRangeHigh; } var gender = _resourcesManager.GetResourceManagerByName(reportName).GetString("NA"); if (!string.IsNullOrWhiteSpace(reportParams.Gender)) { gender = reportParams.Gender; } data.AssessmentParameter = _resourcesManager.GetResourceManagerByName(reportName).GetString("Assessment") + ": " + reportParams.AssessmentName; data.DateRangeParameter = _resourcesManager.GetResourceManagerByName(reportName).GetString("DateRange") + ": " + dateRange; data.RiskCategoryParameter = _resourcesManager.GetResourceManagerByName(reportName).GetString("RiskCategory") + ": " + GetScoreTypeValue(reportParams); data.AgeGroupParameter = _resourcesManager.GetResourceManagerByName(reportName).GetString("AgeGroup") + ": " + ageRange; data.GenderParameter = _resourcesManager.GetResourceManagerByName(reportName).GetString("Gender") + ": " + gender; data.ReportName = _resourcesManager.GetResourceManagerByName(reportName).GetString("ReportName"); data.HeaderName = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderName"); data.HeaderAge = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderAge"); data.HeaderGender = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderGender"); data.HeaderScore = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderScore"); data.HeaderChart = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderChart"); data.HeaderChange = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderChange"); data.HeaderDate = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderDate"); data.HeaderViewAssessment = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderViewAssessment"); }