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
Пример #2
0
    } // demographicData


    private static List<string> referralTo(List<NoteData> notes) {
      return notes.Where(n => n.Type == NoteType.Referral).Select(n => Reports.referralTo(n)).ToList();
    }