} // build private static bool inBounds(Client client, DateTime? startDate, DateTime? endDate) { foreach (var timeline in client.Timeline) { var d = timeline.Datestamp; if (Reports.inBounds(d, startDate, endDate)) return true; } // foreach return false; } // inBounds
public static ReportData<Row> build(Guid orgId, Guid projId, Guid? locId, DateTime? startDate, DateTime? endDate) { var repo = new ReportsRepository(); var riskMap = repo.projectRiskMap(orgId, projId); var rows = new List<Row>(); var clients = repo.findClients(projId, locId); var clientsDischarged = 0; var clientsActive = 0; var clientsAssessed = 0; foreach (var clientData in clients) { if (!Reports.activeBetweenDates(clientData, startDate, endDate)) continue; if (clientData.Discharged == true) ++clientsDischarged; else ++clientsActive; var registeredDate = clientData.registeredOn(); if (registeredDate.HasValue && Reports.inBounds(registeredDate.Value, startDate, endDate)) ++clientsAssessed; var client = new Client(clientData, riskMap); foreach(var theme in client.CurrentRiskAssessment.ThemeAssessments) { var row = rows.SingleOrDefault(r => r.Theme == theme.Title); if (row == null) { row = new Row(theme.Title); rows.Add(row); rows.Sort((l, r) => l.Theme.CompareTo(r.Theme)); } // if ... if (client.Discharged != null) row.discharged(theme); else row.current(theme); } // foreach } // foreach if (endDate.HasValue) endDate = endDate.Value.AddDays(-1); var reportData = new ReportData<Row>(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("clientsActive", clientsActive.ToString()); reportData.Put("clientsDischarged", clientsDischarged.ToString()); reportData.Put("clientsAssessed", clientsAssessed.ToString()); reportData.Put("csvurl", Reports.csvUrl("commissioners", orgId, projId, locId, startDate, endDate)); return reportData; } // build
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