Esempio n. 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
Esempio n. 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);
        }
        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
Esempio n. 4
0
        public static ReportData <ProgressRow> build(Guid orgId, Guid projId, Guid?locId, DateTime?startDate, DateTime?endDate)
        {
            var repo    = new ReportsRepository();
            var riskMap = repo.projectRiskMap(orgId, projId);
            var clients = repo.findClients(projId, locId);

            int clientCount = 0;
            var progress    = new List <ProgressRow>();

            progress.Add(new ProgressRow("A"));
            progress.Add(new ProgressRow("B"));
            progress.Add(new ProgressRow("C"));
            progress.Add(new ProgressRow("D"));
            var totals = new ProgressRow("Total");

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

                var    client         = new Client(clientData, riskMap);
                var    riskAssessment = client.CurrentRiskAssessment;
                var    ta             = riskAssessment.ThemeAssessments.Where(t => t.Title.ToLower().Equals("personal circumstances")).First();
                string initialScore   = massageScore(ta.InitialScore);
                string highScore      = massageScore(ta.HighScore);

                progress[initialScore[0] - 'A'].Add(highScore);
                totals.Add(highScore);

                ++clientCount;
            } // foreach Client

            progress.Add(totals);
            ReportData <ProgressRow> reportData = new ReportData <ProgressRow>(progress);

            reportData.Put("clientCount", clientCount.ToString());
            reportData.Put("csvurl", Reports.csvUrl("pcprogress", orgId, projId, locId, startDate, endDate));
            return(reportData);
        } // buildProgressReport
        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
Esempio n. 7
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
    public static ReportData<Row> build(Guid orgId, Guid projId, Guid? locId, string field, DateTime? startDate, DateTime? endDate) {
      var repo = new ReportsRepository();
      var riskMap = repo.projectRiskMap(orgId, projId);
      var projectQs = repo.projectQuestions(projId);

      var classifier = howToClassify(projectQs, field);
      var rows = new List<Row>();
      var clientCount = 0;

      const int pageSize = 100;
      int page = 0;
      while (true) {
        var clients = repo.findClients(projId, locId).
                          OrderBy(c => c.Id).
                          Skip(page*pageSize).
                          Take(pageSize).
                          Include(c => c.Demographics).
                          Include(c => c.Address).
                          Include(c => c.ProjectAnswers).
                          ToList();

        if (clients.Count == 0)
          break;

        clients = clients.Where(c => Reports.activeBetweenDates(c, startDate, endDate)).ToList();

        foreach (var clientData in clients) {
          var client = new Client(clientData, riskMap, projectQs, null);

          ++clientCount;
          var classifications = classifier.classify(client, clientData.Notes);
          foreach (var classification in classifications) {
            var row = rows.SingleOrDefault(r => r.Label.ToLower() == classification.ToLower());
            if (row == null) {
              row = new Row(classification);
              rows.Add(row);
              rows.Sort((l, r) => l.Label.CompareTo(r.Label));
            } // if ...

            row.bump();
            foreach (var theme in client.CurrentRiskAssessment.ThemeAssessments) {
              var high = theme.HighScore;
              var current = theme.Score;

              bool improvedScore = high != null && !high.Equals(current);
              bool reducedRiskCount = theme.RiskCount < theme.HighRiskCount;

              row.bump(theme.Title, improvedScore, reducedRiskCount);
            } // foreach
          } // foreach
        } // foreach 
        ++page;
      } // page

      ReportData<Row> reportData = new ReportData<Row>(rows);
      reportData.Put("field", classifier.Label);
      reportData.Put("project", repo.projectName(projId));
      reportData.Put("location", repo.locationName(locId));
      reportData.Put("clientCount", clientCount.ToString());
      reportData.Put("csvurl", Reports.csvUrl("adhoc", orgId, projId, locId, startDate, endDate) + "&field=" + field);
      return reportData;
    } // build
Esempio n. 9
0
        public static ReportData <Row> build(Guid orgId, Guid projId, Guid?locationId, DateTime cutoff)
        {
            ReportsRepository repo       = new ReportsRepository();
            ClientRepository  clientRepo = new ClientRepository();

            List <Row> rows    = new List <Row>();
            var        clients = repo.findClients(projId, locationId).Where(c => c.Discharged != true);

            foreach (var client in clients)
            {
                DateTime?lastNote       = null;
                DateTime?lastAssessment = null;

                if (client.Notes != null && client.Notes.Count > 0)
                {
                    lastNote = client.Notes.
                               OrderByDescending(n => n.Timestamp).
                               Select(n => n.Timestamp).
                               First();
                }
                if (client.RiskAssessments != null && client.RiskAssessments.Count > 0)
                {
                    lastAssessment = client.RiskAssessments.
                                     OrderByDescending(n => n.Timestamp).
                                     Select(n => n.Timestamp).
                                     First();
                }

                DateTime?lastUpdate = mostRecent(lastNote, lastAssessment);

                if (!lastUpdate.HasValue)
                {
                    rows.Add(new Row(client.Id, client.Name, client.ReferenceId, null));
                    continue;
                }

                var lastUpdateDate = lastUpdate.Value.Date;
                if (lastUpdateDate.CompareTo(cutoff) < 0)
                {
                    rows.Add(new Row(client.Id, client.Name, client.ReferenceId, lastUpdate.Value));
                }
            }

            rows.Sort(
                delegate(Row lhs, Row rhs) {
                if (!lhs.LastActivity.HasValue)
                {
                    return(-1);
                }
                if (!rhs.LastActivity.HasValue)
                {
                    return(1);
                }
                return(lhs.LastActivity.Value.CompareTo(rhs.LastActivity.Value));
            }
                );

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

            reportData.Put("clientCount", rows.Count.ToString());
            reportData.Put("project", repo.projectName(projId));
            reportData.Put("location", repo.locationName(locationId));
            reportData.Put("cutoff", cutoff.ToLongDateString());
            reportData.Put("csvurl", Reports.csvUrl("actionrequired", orgId, projId, locationId, cutoff, null));

            return(reportData);
        } // build