Пример #1
0
    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
Пример #2
0
        public static ReportData <Row> build(Guid orgId, Guid projId, Guid?locId, DateTime?startDate, DateTime?endDate)
        {
            var repo = new ReportsRepository();

            var reportData = new ReportData <Row>(new List <Row>());

            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("csvurl", Reports.csvUrl("export", orgId, projId, locId, startDate, endDate));
            return(reportData);
        }
Пример #3
0
        public static ReportData <Row> build(Guid orgId, Guid projId, Guid?locId, DateTime refDate)
        {
            var repo    = new ReportsRepository();
            var riskMap = repo.projectRiskMap(orgId, projId);
            var clients = repo.findClients(projId, locId);

            var startDate = refDate.AddDays(-30);

            var newClients        = new List <ClientData>();
            var currentClients    = new List <ClientData>();
            var dischargedClients = new List <ClientData>();

            foreach (var client in clients)
            {
                if (isNew(client, startDate, refDate))
                {
                    newClients.Add(client);
                }
                else if (isDischarged(client, startDate, refDate))
                {
                    dischargedClients.Add(client);
                }
                else if (isCurrent(client, startDate, refDate))
                {
                    currentClients.Add(client);
                }
            } // foreach

            reduceTo10(newClients);
            reduceTo10(currentClients);
            reduceTo10(dischargedClients);

            var rows = new List <Row>();

            rows.Add(new Row(newClients));
            rows.Add(new Row(currentClients));
            rows.Add(new Row(dischargedClients));

            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("refDate", Reports.formatDate(refDate));
            reportData.Put("csvurl", Reports.csvUrl("audit", orgId, projId, locId, refDate, null));
            return(reportData);
        } // build
        public static ReportData <Row> build(Guid orgId, Guid projId, DateTime?startDate, DateTime?endDate)
        {
            var repo     = new ReportsRepository();
            var allRisks = new RiskMapRepository(orgId).RisksCurrentAndDeleted();

            var clients = repo.findClients(projId, null).Include(c => c.Address);
            var rows    = new List <Row>();

            foreach (var client in clients)
            {
                if (!Reports.activeBetweenDates(client, startDate, endDate))
                {
                    continue;
                }
                if (client.RiskAssessments == null || client.RiskAssessments.Count == 0)
                {
                    continue;
                }

                var postCode = Reports.firstPartOfPostCode(client);
                foreach (var rad in client.RiskAssessments)
                {
                    var row = findRow(rows, postCode);
                    row.bump();
                    var assessed = rad.Risks().Select(riskId => allRisks.Where(r => r.Id == riskId).Single().Title).ToList();
                    row.assessed(assessed);
                    var resolved = rad.ResolvedRisks().Select(riskId => allRisks.Where(r => r.Id == riskId).Single().Title).ToList();
                    row.resolved(resolved);
                    var managed = rad.ManagedRisks().Select(riskId => allRisks.Where(r => r.Id == riskId).Single().Title).ToList();
                    row.managed(managed);
                } // foreach RiskAssessment
            }     // foreach Client

            rows.Sort((lhs, rhs) => postCodeOrder(lhs.PostCode, rhs.PostCode));

            var reportData = new ReportData <Row>(rows);

            reportData.Put("project", repo.projectName(projId));
            reportData.Put("startDate", Reports.formatDate(startDate));
            reportData.Put("endDate", Reports.formatDate(endDate));
            reportData.Put("csvurl", Reports.csvUrl("opendata", orgId, projId, null, 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
Пример #6
0
        public static void buildCSV(StreamWriter csv, Guid orgId, Guid projId, Guid?locId, DateTime?startDate, DateTime?endDate)
        {
            var repo      = new ReportsRepository();
            var riskMap   = repo.projectRiskMap(orgId, projId);
            var projectQs = repo.projectQuestions(projId);

            csv.WriteLine("Project," + repo.projectName(projId));
            csv.WriteLine("Location," + repo.locationName(locId));
            csv.WriteLine("Start Date," + Reports.formatDate(startDate));
            csv.WriteLine("End Date," + Reports.formatDate(endDate));


            csv.Write("Name,");
            csv.Write("Ref Id,");
            csv.Write("Post Code,");
            csv.Write("In area of deprivation,");
            csv.Write("Referred by,");
            csv.Write("Project,");
            csv.Write("Location,");
            csv.Write("Date of birth,");
            csv.Write("Disability,");
            csv.Write("Disability Type,");
            csv.Write("Employment Status,");
            csv.Write("Ethnic Origin,");
            csv.Write("Gender,");
            csv.Write("Household Income,");
            csv.Write("Household Type,");
            csv.Write("Housing Type,");
            csv.Write("Marital Status,");
            csv.Write("Registration Date,");
            foreach (var q in projectQs)
            {
                csv.Write(q.Question + ",");
            }
            foreach (var t in riskMap.AllThemes())
            {
                csv.Write("Initial " + t + " score,");
            }
            foreach (var t in riskMap.AllThemes())
            {
                csv.Write("Highest " + t + " score,");
            }
            foreach (var t in riskMap.AllThemes())
            {
                csv.Write("Current " + t + " score,");
            }
            csv.Write("Discharge Date");
            csv.WriteLine();

            const int pageSize = 200;
            int       page     = 0;

            while (true)
            {
                var clientDatas = repo.findClients(projId, locId).
                                  OrderBy(c => c.Id).
                                  Skip(page * pageSize).
                                  Take(pageSize).
                                  Include(c => c.Address).
                                  Include(c => c.Demographics).
                                  Include(c => c.ProjectAnswers).ToList();
                if (clientDatas.Count == 0)
                {
                    break;
                }

                var clients = new List <Client>();
                foreach (var cd in clientDatas)
                {
                    if (!Reports.activeBetweenDates(cd, startDate, endDate))
                    {
                        continue;
                    }
                    clients.Add(new Client(cd, riskMap, projectQs, null));
                } // foreach

                foreach (var client in clients)
                {
                    try {
                        var riskAssessment = client.CurrentRiskAssessment;

                        csv.Write(client.Name + ",");
                        csv.Write(client.ReferenceId + ",");
                        csv.Write(client.Address.PostCode + ",");
                        csv.Write(client.Address.IsInDeprivedArea + ",");
                        csv.Write(referredBy(client.referredBy()) + ",");
                        csv.Write(repo.projectName(client.ProjectId) + ",");
                        csv.Write(repo.locationName(client.LocationId) + ",");

                        var demographics = client.Demographics;
                        if (demographics == null)
                        {
                            demographics = new DemographicData();
                        }

                        csv.Write(Reports.formatDate(demographics.Dob) + ",");
                        csv.Write(demographics.Disability + ",");
                        csv.Write(demographics.DisabilityType + ",");
                        csv.Write(demographics.EmploymentStatus + ",");
                        csv.Write(demographics.EthnicOrigin + ",");
                        csv.Write(demographics.Gender + ",");
                        csv.Write(demographics.HouseholdIncome + ",");
                        csv.Write(demographics.HouseholdType + ",");
                        csv.Write(demographics.HousingType + ",");
                        csv.Write(demographics.MaritalStatus + ",");
                        csv.Write(Reports.formatDate(client.registeredOn()) + ",");
                        foreach (var pq in client.Questions)
                        {
                            csv.Write(pq.Answer + ",");
                        }

                        var ra = client.CurrentRiskAssessment;
                        // Initial scores
                        foreach (var t in ra.ThemeAssessments)
                        {
                            csv.Write(t.InitialScore + ",");
                        }
                        // High scores
                        foreach (var t in ra.ThemeAssessments)
                        {
                            csv.Write(t.HighScore + ",");
                        }
                        // Current scores
                        foreach (var t in ra.ThemeAssessments)
                        {
                            csv.Write(t.Score + ",");
                        }

                        // Discharge Date
                        csv.Write(Reports.formatDate(client.Discharged));
                    } catch (Exception e) {
                        csv.Write("Error exporting - " + e.Message);
                    }
                    csv.WriteLine();
                    csv.Flush();
                } // foreach Client
                ++page;
            }     // while(true)

            csv.Close();
        }