Ejemplo n.º 1
0
        public static ReportData <ICollection <Referral> > build(Guid orgId, Guid projId, Guid?locId, DateTime?startDate, DateTime?endDate)
        {
            ReportsRepository repo = new ReportsRepository();

            var clients = repo.findClients(projId, locId);

            var active        = 0;
            var assessments   = 0;
            var sessions      = 0;
            var dna           = 0;
            var discharged    = 0;
            var referralsFrom = new GatherReferrals();
            var referralsTo   = new GatherReferrals();

            foreach (var client in clients)
            {
                if (!Reports.activeBetweenDates(client, startDate, endDate))
                {
                    continue;
                }

                var registeredDate = client.registeredOn();
                if (!registeredDate.HasValue || Reports.inBounds(registeredDate.Value, startDate, endDate))
                {
                    ++assessments;
                    var referredBy = client.referredBy();
                    if (referredBy != null)
                    {
                        referralsFrom.Add(referredBy.Text);
                    }
                }

                ISet <DateTime> sessionDates = new HashSet <DateTime>();
                foreach (var note in client.Notes)
                {
                    var date = note.Timestamp.Date;
                    if (Reports.outOfBounds(date, startDate, endDate))
                    {
                        continue;
                    }
                    sessionDates.Add(date);

                    if (note.Type == NoteType.Referral)
                    {
                        referralsTo.Add(Reports.referralTo(note));
                    }
                }
                foreach (var riskAssessment in client.RiskAssessments)
                {
                    var date = riskAssessment.Timestamp.Date;
                    if (Reports.outOfBounds(date, startDate, endDate))
                    {
                        continue;
                    }
                    sessionDates.Add(date);
                }

                sessions += sessionDates.Count;
                dna      += client.Notes.
                            Where(n => n.Type == NoteType.DidNotAttend).
                            Where(n => Reports.inBounds(n.Timestamp, startDate, endDate)).
                            Count();
                if (client.Discharged == true)
                {
                    ++discharged;
                }
                else
                {
                    ++active;
                }
            } // for ...

            if (endDate.HasValue)
            {
                endDate = endDate.Value.AddDays(-1);
            }
            var rows = new List <ICollection <Referral> >();

            rows.Add(referralsFrom.Referrals);
            rows.Add(referralsTo.Referrals);
            ReportData <ICollection <Referral> > reportData = new ReportData <ICollection <Referral> >(rows);

            reportData.Put("project", repo.projectName(projId));
            reportData.Put("location", repo.locationName(locId));
            reportData.Put("startDate", Reports.formatDate(startDate));
            reportData.Put("endDate", Reports.formatDate(endDate));
            reportData.Put("assessments", assessments.ToString());
            reportData.Put("active", active.ToString());
            reportData.Put("discharged", discharged.ToString());
            reportData.Put("sessions", sessions.ToString());
            reportData.Put("dna", dna.ToString());
            reportData.Put("csvurl", Reports.csvUrl("activityreport", orgId, projId, locId, startDate, endDate));
            return(reportData);
        } // build
Ejemplo n.º 2
0
        public static ReportData <ThemeRow> build(Guid orgId, Guid projId, Guid?locId, DateTime?startDate, DateTime?endDate)
        {
            ProjectOrganisationRepository poRepo = new ProjectOrganisationRepository();
            RiskMapRepository             rmRepo = new RiskMapRepository(orgId);
            ClientRepository clientRepo          = new ClientRepository();

            ProjectOrganisation po      = poRepo.Get(orgId);
            Project             project = poRepo.FindProject(orgId, projId);
            RiskMap             riskMap = rmRepo.RiskMap(project.RiskFramework);
            IList <ClientData>  clients = clientRepo.ProjectClientData(projId, locId);

            IDictionary <Guid, ResolutionRow> report = new Dictionary <Guid, ResolutionRow>();

            foreach (var risk in riskMap.Risks)
            {
                report.Add(risk.Id, new ResolutionRow(risk));
            }

            HashSet <Guid> clientsSeen = new HashSet <Guid>();

            foreach (var client in clients)
            {
                if (client.RiskAssessments == null || client.RiskAssessments.Count == 0)
                {
                    continue;
                }
                foreach (var rad in client.RiskAssessments)
                {
                    if (Reports.outOfBounds(rad.Timestamp, startDate, endDate))
                    {
                        continue;
                    }
                    foreach (var riskId in rad.Risks())
                    {
                        ResolutionRow row = report[riskId];
                        row.Open(client);
                    }
                    foreach (var riskId in rad.ResolvedRisks())
                    {
                        ResolutionRow row = report[riskId];
                        row.Close(client);
                    }

                    clientsSeen.Add(client.Id);
                } // foreach RiskAssessment
            }     // foreach Client

            IList <ThemeRow> themes = new List <ThemeRow>();

            foreach (var theme in riskMap.AllThemes())
            {
                var catRows = buildCatRows(theme, riskMap, report);
                themes.Add(new ThemeRow(theme, catRows));
            } // foreach

            ReportData <ThemeRow> reportData =
                new ReportData <ThemeRow>(themes);

            reportData.Put("clientCount", clientsSeen.Count.ToString());
            reportData.Put("csvurl", Reports.csvUrl("resolution", orgId, projId, locId, startDate, endDate));

            return(reportData);
        } // resolutionReport