private PatientsWithSpecificResponseData GetData(PatientsWithSpecificResponseParameters parameters)
        {
            var returnData = new PatientsWithSpecificResponseData();

            using (var connection = _connectionFactory.CreateConnection())
            {
                var reportDtos = connection.Query <PatientsWithSpecificResponseDto>(GetQuery(parameters)).ToList();
                if (!reportDtos.Any())
                {
                    return(null);
                }
                var data = reportDtos.Select(
                    reportDto => new PatientsWithSpecificResponseDataObject
                {
                    ResponseType          = reportDto.ResponseType,
                    IsCode                = reportDto.IsCode,
                    CodeValue             = reportDto.CodeValue,
                    Age                   = reportDto.PatientAge,
                    Gender                = reportDto.GenderCode.Substring(0, 1),
                    PatientName           = reportDto.PatientFirstName + " " + reportDto.PatientLastName,
                    AssessmentDate        = reportDto.LastModifiedTime.ToShortDateString(),
                    PatientKey            = reportDto.PatientKey,
                    AssessmentInstanceKey = reportDto.AssessmentInstanceKey,
                    AssessmentName        = _resourcesManager.GetResourceManagerByName(reportDto.AssessmentName).GetString("_" + reportDto.AssessmentCode),
                    ItemDefinitionCode    = reportDto.ItemDefinitionCode,
                    Question              = _resourcesManager.GetResourceManagerByName(reportDto.AssessmentName).GetString("_" + reportDto.ItemDefinitionCode),
                    Response              = GetResponseValue(reportDto)
                }).ToList();
                returnData.Data = data;
            }
            return(returnData);
        }
        private string GetResponsesForHeader(PatientsWithSpecificResponseData source, string itemDefinitionCode)
        {
            var newLine   = string.Empty;
            var returnStr = string.Empty;

            foreach (var re in source.LocalizedQuestionResponses.Where(a => a.ItemDefinitionCode == itemDefinitionCode).SelectMany(response => response.LocalizedResponses))
            {
                returnStr += newLine + re;
                newLine    = Environment.NewLine;
            }
            return(returnStr);
        }
        private XRTableRow GetHeaderRow(PatientsWithSpecificResponseData source)
        {
            var headerFont   = new Font("Times New Roman", 13F);
            var trHeader     = new XRTableRow();
            var tdNameHeader = new XRTableCell
            {
                Text          = source.HeaderName,
                CanGrow       = true,
                Borders       = BorderSide.Bottom,
                BorderWidth   = 3,
                BorderColor   = Color.DarkGray,
                TextAlignment = TextAlignment.BottomLeft,
                Font          = headerFont,
                SizeF         = new Size(NameHeaderWidth, Height),
            };

            trHeader.Cells.Add(tdNameHeader);
            var tdAgeHeader = new XRTableCell
            {
                Text          = source.HeaderAge,
                CanGrow       = true,
                Borders       = BorderSide.Bottom,
                BorderWidth   = 3,
                BorderColor   = Color.DarkGray,
                TextAlignment = TextAlignment.BottomCenter,
                Font          = headerFont,
                SizeF         = new Size(AgeHeaderWidth, Height),
            };

            trHeader.Cells.Add(tdAgeHeader);
            var tdGenderHeader = new XRTableCell
            {
                Text          = source.HeaderGender,
                CanGrow       = true,
                Borders       = BorderSide.Bottom,
                BorderWidth   = 3,
                BorderColor   = Color.DarkGray,
                TextAlignment = TextAlignment.BottomCenter,
                Font          = headerFont
            };

            trHeader.Cells.Add(tdGenderHeader);
            var tdAssessmentDateHeader = new XRTableCell
            {
                Text          = source.HeaderAssessmentDate,
                CanGrow       = true,
                Borders       = BorderSide.Bottom,
                BorderWidth   = 3,
                BorderColor   = Color.DarkGray,
                TextAlignment = TextAlignment.BottomCenter,
                Font          = headerFont
            };

            trHeader.Cells.Add(tdAssessmentDateHeader);
            var tdGivenResponseHeader = new XRTableCell
            {
                Text          = source.HeaderGivenResponse,
                CanGrow       = true,
                Borders       = BorderSide.Bottom,
                BorderWidth   = 3,
                BorderColor   = Color.DarkGray,
                TextAlignment = TextAlignment.BottomCenter,
                Font          = headerFont
            };

            trHeader.Cells.Add(tdGivenResponseHeader);

            var tdViewHeader = new XRTableCell
            {
                Text          = source.HeaderViewAssessment,
                CanGrow       = true,
                Borders       = BorderSide.Bottom,
                BorderWidth   = 3,
                BorderColor   = Color.DarkGray,
                TextAlignment = TextAlignment.BottomCenter,
                Font          = headerFont
            };

            trHeader.Cells.Add(tdViewHeader);
            return(trHeader);
        }
        private XRTable AddQuestionResponse(PatientsWithSpecificResponseDataObject data, int questionCount, PatientsWithSpecificResponseData source)
        {
            var cellFont = new Font("Times New Roman", 12F);
            var tdBlank  = new XRTableCell {
                Text = " ", Multiline = true, CanGrow = true, SizeF = new Size(500, 60), Font = cellFont
            };
            var cellFontBold = new Font("Times New Roman", 12F, FontStyle.Bold);
            var tb           = new XRTable {
                Tag = "TableBreak", CanGrow = true, WidthF = 880
            };
            var trHeader = new XRTableRow();
            var trData   = new XRTableRow();

            var trBlankTop = new XRTableRow {
                HeightF = 60, CanGrow = true
            };

            trBlankTop.Cells.Add(tdBlank);
            trBlankTop.Cells.Add(tdBlank);
            tb.Rows.Add(trBlankTop);

            var tdQuestionNumber = new XRTableCell {
                Text = source.HeaderQuestion + " " + questionCount, SizeF = new Size(500, 25), Font = cellFontBold
            };

            trHeader.Cells.Add(tdQuestionNumber);
            var tdSpecificResponseHeader = new XRTableCell {
                Text = source.HeaderSpecificResponseValue, SizeF = new Size(380, 25), Font = cellFontBold
            };

            trHeader.Cells.Add(tdSpecificResponseHeader);
            tb.Rows.Add(trHeader);

            var tdQuestion = new XRTableCell {
                Text = data.Question, Multiline = true, CanGrow = true, SizeF = new Size(500, 25), Font = cellFont
            };

            trData.Cells.Add(tdQuestion);
            var tdResponse = new XRTableCell
            {
                Text      = GetResponsesForHeader(source, data.ItemDefinitionCode),
                Multiline = true,
                CanGrow   = true,
                SizeF     = new Size(380, 25),
                Font      = cellFont
            };

            trData.Cells.Add(tdResponse);
            tb.Rows.Add(trData);

            var trBlankBottom = new XRTableRow {
                HeightF = 60, CanGrow = true
            };

            trBlankBottom.Cells.Add(tdBlank);
            trBlankBottom.Cells.Add(tdBlank);
            tb.Rows.Add(trBlankBottom);
            return(tb);
        }
        private void SetStrings(PatientsWithSpecificResponseData data, PatientsWithSpecificResponseParameters reportParams, string reportName)
        {
            if (reportParams == null || data == null)
            {
                return;
            }

            var originalReportName = reportName;
            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;
            }
            data.StartDate = start;
            data.EndDate   = end;
            reportName     = ReportNames.PatientsWithSpecificResponse;
            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;
            }
            var assessment = _resourcesManager.GetResourceManagerByName(reportName).GetString("All");

            if (!string.IsNullOrWhiteSpace(reportParams.AssessmentName))
            {
                assessment = GetAssessmentNames(data);
            }
            data.AssessmentParameter    = _resourcesManager.GetResourceManagerByName(reportName).GetString("Assessment") + ": " + assessment;
            data.DateRangeParameter     = _resourcesManager.GetResourceManagerByName(reportName).GetString("DateRange") + ": " + dateRange;
            data.AgeGroupParameter      = _resourcesManager.GetResourceManagerByName(reportName).GetString("AgeGroup") + ": " + ageRange;
            data.GenderParameter        = _resourcesManager.GetResourceManagerByName(reportName).GetString("Gender") + ": " + gender;
            data.TotalQuestionsForQuery = _resourcesManager.GetResourceManagerByName(reportName).GetString("TotalQuestionsForQuery") +
                                          ": " + data.Data.GroupBy(a => a.ItemDefinitionCode).Select(group => group.First()).Count();
            data.TotalNumberOfSpecifiedResults = _resourcesManager.GetResourceManagerByName(reportName).GetString("TotalNumberOfSpecificResults") +
                                                 ": " + data.Data.Count();
            data.TotalNumberOfPatients = _resourcesManager.GetResourceManagerByName(reportName).GetString("TotalNumberOfPatients") +
                                         ": " + data.Data.GroupBy(a => a.PatientKey).Select(group => group.First()).Count();
            data.TotalNumberOfAssessmentsDuringTimeFrame =
                _resourcesManager.GetResourceManagerByName(reportName).GetString("TotalNumberOfAssessmentsDuringTimeFrame") +
                ": " + GetTotalNumberOfAssessmentsDuringTimePeriod(data.StartDate, data.EndDate);
            data.LocalizedQuestionResponses = GetQuestionResponsesFromResource(reportParams);

            data.ReportName = _resourcesManager.GetResourceManagerByName(reportName).GetString("ReportName" + originalReportName);

            data.HeaderQuestion = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderQuestion");
            data.HeaderSpecificResponseValue = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderSpecificResponse");
            data.HeaderName           = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderName");
            data.HeaderAge            = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderAge");
            data.HeaderGender         = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderGender");
            data.HeaderAssessmentName = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderAssessmentName");
            data.HeaderAssessmentDate = _resourcesManager.GetResourceManagerByName(reportName).GetString("AssessmentDate");
            data.HeaderGivenResponse  = _resourcesManager.GetResourceManagerByName(reportName).GetString("GivenResponse");
            data.HeaderViewAssessment = _resourcesManager.GetResourceManagerByName(reportName).GetString("HeaderViewAssessment");
        }
 private string GetAssessmentNames(PatientsWithSpecificResponseData data)
 {
     return(string.Join(",", data.Data.Select(a => a.AssessmentName).Distinct()));
 }