public void Process(ItemCreated evt)
        {
            var taskList = _repositoryForTaskList.GetById(evt.ListId);

            if (taskList == null)
            {
                taskList = new TaskList
                {
                    Id    = evt.ListId,
                    Tasks = new []
                    {
                        new TodoTask
                        {
                            Text = evt.Text,
                        }
                    }
                };

                _repositoryForTaskList.Insert(taskList);
            }
            else
            {
                taskList.Tasks.Add(new TodoTask
                {
                    Text = evt.Text,
                });

                _repositoryForTaskList.Update(taskList);
            }
        }
Example #2
0
        public void Process(TrainingReportReceived @event, EventSourceId caseReportId)
        {
            var dataCollector = _dataCollectors.GetById(@event.DataCollectorId);
            var healthRisk    = _healthRisks.GetById(@event.HealthRiskId);

            var report = new TrainingReport(caseReportId.Value)
            {
                Status                   = CaseReportStatus.Success,
                Message                  = @event.Message,
                DataCollectorId          = dataCollector.Id,
                DataCollectorDisplayName = dataCollector.DisplayName,
                DataCollectorDistrict    = dataCollector.District,
                DataCollectorRegion      = dataCollector.Region,
                DataCollectorVillage     = dataCollector.Village,
                Location                 = dataCollector.Location,
                Origin                   = @event.Origin,

                HealthRiskId = healthRisk.Id,
                HealthRisk   = healthRisk.Name,

                NumberOfMalesUnder5          = @event.NumberOfMalesUnder5,
                NumberOfMalesAged5AndOlder   = @event.NumberOfMalesAged5AndOlder,
                NumberOfFemalesUnder5        = @event.NumberOfFemalesUnder5,
                NumberOfFemalesAged5AndOlder = @event.NumberOfFemalesAged5AndOlder,
                Timestamp = @event.Timestamp,
            };

            _trainingReports.Insert(report);
        }
Example #3
0
        public void Process(HealthRiskModified @event)
        {
            var healthRisk = _healthRisks.GetById(@event.Id);

            healthRisk.Name = @event.Name;
            _healthRisks.Update(healthRisk);
        }
Example #4
0
        public void Process(ItemCreated evt)
        {
            var allLists = _repositoryForAvailableLists.GetById(default(Guid));

            if (allLists != null)
            {
                if (!allLists.Lists.Any(list => list == evt.ListId))
                {
                    allLists.Lists.Add(evt.ListId);
                    _repositoryForAvailableLists.Update(allLists);
                }
            }
            else
            {
                allLists = new AvailableLists
                {
                    Id    = default(Guid),
                    Lists = new ListId[]
                    {
                        evt.ListId
                    }
                };

                _repositoryForAvailableLists.Insert(allLists);
            }
        }
        public void Process(InstallationRepositoriesUpdateReceived @event)
        {
            var repositoriesList = _repositoryForRepositoriesList.GetById(0);

            @event.RepositoriesAdded.ForEach(name => {
                if (!repositoriesList.Repositories.Contains(name))
                {
                    repositoriesList.Repositories.Add(name);
                }
            });
            @event.RepositoriesRemoved.ForEach(name => {
                repositoriesList.Repositories.Remove(name);
            });
            _repositoryForRepositoriesList.Update(repositoriesList);

            var installation = _repositoryForInstallationRepositories.GetById(@event.InstallationId);

            @event.RepositoriesAdded.ForEach(name => {
                if (!installation.Repositories.Contains(name))
                {
                    installation.Repositories.Add(name);
                }
            });
            @event.RepositoriesRemoved.ForEach(name => {
                installation.Repositories.Remove(name);
            });
            _repositoryForInstallationRepositories.Update(installation);
        }
Example #6
0
        public void Process(SmsGatewayNumberAssigned @event)
        {
            var smsGateway = _repository.GetById(@event.Id);

            smsGateway.PhoneNumber = @event.PhoneNumber;

            _repository.Update(smsGateway);
        }
Example #7
0
        public void Process(HealthRiskModified @event)
        {
            var healthRisk = _repository.GetById(@event.Id);

            healthRisk.Name             = @event.Name;
            healthRisk.CaseDefinition   = @event.CaseDefinition;
            healthRisk.HealthRiskNumber = @event.HealthRiskNumber;
            _repository.Update(healthRisk);
        }
        public void Process(DataCollectorUserInformationChanged @event, EventSourceId dataCollectorId)
        {
            var dataCollector = _dataCollectors.GetById(dataCollectorId.Value);

            dataCollector.Region      = @event.Region;
            dataCollector.District    = @event.District;
            dataCollector.DisplayName = @event.DisplayName;
            _dataCollectors.Update(dataCollector);
        }
Example #9
0
 public void Process(AlertRuleUpdated @event)
 {
     var alertRule = _alertRules.GetById(@event.Id);
     alertRule.AlertRuleName = @event.AlertRuleName;
     alertRule.DistanceBetweenCasesInMeters = @event.DistanceBetweenCasesInMeters;
     alertRule.HealthRiskId = @event.HealthRiskId;
     alertRule.NumberOfCasesThreshold = @event.NumberOfCasesThreshold;
     alertRule.ThresholdTimeframeInHours = @event.ThresholdTimeframeInHours;
     _alertRules.Update(alertRule);
 }
Example #10
0
        public void Process(DataCollectorUserInformationChanged @event)
        {
            var dataCollector = _dataCollectors.GetById(@event.DataCollectorId);

            dataCollector.Region      = @event.Region;
            dataCollector.District    = @event.District;
            dataCollector.Village     = "";
            dataCollector.DisplayName = @event.DisplayName;

            _dataCollectors.Update(dataCollector);
        }
Example #11
0
        public void Process(AutomaticReplyDefined @event)
        {
            var reply = _automaticReplies.GetById(@event.Id);

            reply.Language  = @event.Language;
            reply.Message   = @event.Message;
            reply.ProjectId = @event.ProjectId;
            reply.Type      = (AutomaticReplyType)@event.Type;

            _automaticReplies.Update(reply);
        }
Example #12
0
 public void Process(AlertOpened @event)
 {
     foreach (var reportId in @event.Reports)
     {
         var report = _availableReports.GetById(reportId);
         if (report != null)
         {
             _availableReports.Delete(report);
         }
     }
 }
Example #13
0
        public void InsertPerHealthRiskAndRegionForDay(CaseReport report, HealthRisk healthRisk, District district)
        {
            var numberOfReports = report.NumberOfFemalesAged5AndOlder
                                  + report.NumberOfFemalesUnder5
                                  + report.NumberOfMalesAged5AndOlder
                                  + report.NumberOfMalesUnder5;
            var region = _regions.GetById(district.RegionId);
            var day    = Day.From(report.Timestamp);

            var reportsPerHealthRisk = _caseReportsPerHealthRiskPerDay.GetById(day);

            if (reportsPerHealthRisk == null)
            {
                reportsPerHealthRisk = new CaseReportsPerHealthRiskPerDay()
                {
                    Id                   = day,
                    Timestamp            = report.Timestamp,
                    ReportsPerHealthRisk = new Dictionary <HealthRiskName, Dictionary <RegionName, int> >()
                    {
                        { healthRisk.Name, new Dictionary <RegionName, int>()
                          {
                              { region.Name, numberOfReports }
                          } }
                    }
                };

                _caseReportsPerHealthRiskPerDay.Insert(reportsPerHealthRisk);
            }
            else
            {
                if (reportsPerHealthRisk.ReportsPerHealthRisk.TryGetValue(healthRisk.Name, out Dictionary <RegionName, int> reportsPerRegion))
                {
                    if (reportsPerRegion.TryGetValue(region.Name, out int totalReports))
                    {
                        reportsPerRegion[region.Name] = totalReports + numberOfReports;
                    }
                    else
                    {
                        reportsPerRegion.Add(region.Name, numberOfReports);
                    }
                    reportsPerHealthRisk.ReportsPerHealthRisk[healthRisk.Name] = reportsPerRegion;
                }
                else
                {
                    reportsPerHealthRisk.ReportsPerHealthRisk.Add(healthRisk.Name, new Dictionary <RegionName, int>()
                    {
                        { region.Name, numberOfReports }
                    });
                }

                _caseReportsPerHealthRiskPerDay.Update(reportsPerHealthRisk);
            }
        }
Example #14
0
        public void Process(AlertOpened @event)
        {
            var rule = _repositoryForAlertRule.GetById(@event.AlertRuleId);

            _repositoryForAlert.Insert(new Alert()
            {
                Id             = @event.AlertId,
                AlertNumber    = @event.AlertNumber,
                AlertRuleId    = @event.AlertRuleId,
                HealthRiskName = rule.HealthRiskName
            });
        }
Example #15
0
        public void Process(ProjectUpdated @event)
        {
            var project = _projects.GetById(@event.Id);

            project.NationalSociety     = _nationalSocieties.GetById(@event.NationalSocietyId);
            project.DataOwner           = _users.GetById(@event.DataOwnerId);
            project.Name                = @event.Name;
            project.SurveillanceContext = @event.SurveillanceContext;
            project.SmsProxy            = @event.SmsProxy;

            _projects.Update(project);
        }
Example #16
0
        public void Process(DataCollectorUserInformationChanged @event, EventSourceId dataCollectorId)
        {
            var dataCollector = _dataCollectors.GetById(dataCollectorId.Value);

            dataCollector.FullName    = @event.FullName;
            dataCollector.DisplayName = @event.DisplayName;
            dataCollector.Sex         = (Sex)@event.Sex;
            dataCollector.YearOfBirth = @event.YearOfBirth;
            dataCollector.District    = @event.District;
            dataCollector.Region      = @event.Region;

            _dataCollectors.Update(dataCollector);
        }
Example #17
0
        public void Process(AutomaticReplyKeyMessageDefined @event)
        {
            var keyMessage = _keyMessages.GetById(@event.Id);

            keyMessage.Id           = @event.Id;
            keyMessage.Type         = (AutomaticReplyKeyMessageType)@event.Type;
            keyMessage.Language     = @event.Language;
            keyMessage.Message      = @event.Message;
            keyMessage.ProjectId    = @event.ProjectId;
            keyMessage.HealthRiskId = @event.HealthRiskId;

            _keyMessages.Update(keyMessage);
        }
Example #18
0
        void CreateOrUpdateCaseReports(Day day, HealthRiskId id, Action <CaseReportsLast4WeeksForHealthRisk> update)
        {
            var aggregatedReports = _caseReportsLastWeeksPerHealthRisk.GetById(day);

            if (aggregatedReports == null)
            {
                aggregatedReports = new CaseReportsLast4WeeksPerHealthRisk
                {
                    Id = day,
                    CaseReportsPerHealthRisk = new Dictionary <HealthRiskId, CaseReportsLast4WeeksForHealthRisk>()
                };
                _caseReportsLastWeeksPerHealthRisk.Insert(aggregatedReports);
            }

            if (!aggregatedReports.CaseReportsPerHealthRisk.ContainsKey(id))
            {
                aggregatedReports.CaseReportsPerHealthRisk[id] = new CaseReportsLast4WeeksForHealthRisk
                {
                    Days0to6   = 0,
                    Days7to13  = 0,
                    Days14to20 = 0,
                    Days21to27 = 0
                };
            }

            var aggregatedReportsForHealthRisk = aggregatedReports.CaseReportsPerHealthRisk[id];

            update(aggregatedReportsForHealthRisk);

            _caseReportsLastWeeksPerHealthRisk.Update(aggregatedReports);
        }
Example #19
0
        public void Process(CaseReportReceived @event)
        {
            var healthRiskName      = _healthRisks.GetById(@event.HealthRiskId)?.Name ?? "Unknown";
            var recieved            = Day.From(@event.Timestamp);
            var numberOfCaseReports = @event.NumberOfFemalesUnder5 + @event.NumberOfFemalesAged5AndOlder + @event.NumberOfMalesUnder5 + @event.NumberOfMalesAged5AndOlder;

            for (var days = 0; days < 7; days++)
            {
                CreateOrUpdateCaseReports(recieved + days, @event.HealthRiskId, _ => {
                    _.HealthRiskName = healthRiskName;
                    _.Days0to6      += numberOfCaseReports;
                });
            }
            for (var days = 7; days < 14; days++)
            {
                CreateOrUpdateCaseReports(recieved + days, @event.HealthRiskId, _ => {
                    _.HealthRiskName = healthRiskName;
                    _.Days7to13     += numberOfCaseReports;
                });
            }
            for (var days = 14; days < 21; days++)
            {
                CreateOrUpdateCaseReports(recieved + days, @event.HealthRiskId, _ => {
                    _.HealthRiskName = healthRiskName;
                    _.Days14to20    += numberOfCaseReports;
                });
            }
            for (var days = 21; days < 28; days++)
            {
                CreateOrUpdateCaseReports(recieved + days, @event.HealthRiskId, _ => {
                    _.HealthRiskName = healthRiskName;
                    _.Days21to27    += numberOfCaseReports;
                });
            }
        }
Example #20
0
        public void Process(DefaultAutomaticReplyKeyMessageDefined @event)
        {
            var message = _defaultKeyMessages.GetById(@event.Id);

            if (message == null)
            {
                message = new DefaultAutomaticReplyKeyMessage(@event.Id)
                {
                    Type         = (AutomaticReplyKeyMessageType)@event.Type,
                    Language     = @event.Language,
                    Message      = @event.Message,
                    HealthRiskId = @event.HealthRiskId
                };

                _defaultKeyMessages.Insert(message);
            }
            else
            {
                message.Type         = (AutomaticReplyKeyMessageType)@event.Type;
                message.Language     = @event.Language;
                message.Message      = @event.Message;
                message.HealthRiskId = @event.HealthRiskId;

                _defaultKeyMessages.Update(message);
            }
        }
Example #21
0
        public void Process(ProjectCreated @event)
        {
            var project = new Project
            {
                Id = @event.Id,
                NationalSociety     = _nationalSocieties.GetById(@event.NationalSocietyId),
                DataOwner           = _users.GetById(@event.DataOwnerId),
                Name                = @event.Name,
                SurveillanceContext = @event.SurveillanceContext,
                HealthRisks         = new ProjectHealthRisk[0],
                DataVerifiers       = new User[0],
                SmsProxy            = ""
            };

            _projects.Insert(project);
        }
Example #22
0
        public void Process(CaseReportReceived @event)
        {
            // Each day contains a health risk dictionary
            // Each healthrisk in the healthrisk dictionary contains two collections of case-reports from 7 and 30 days
            var totalCases            = @event.NumberOfFemalesAged5AndOlder + @event.NumberOfFemalesUnder5 + @event.NumberOfMalesAged5AndOlder + @event.NumberOfMalesUnder5;
            var locationForCaseReport = new Location(@event.Latitude, @event.Longitude);
            var healthRiskId          = @event.HealthRiskId;
            var healthRiskName        = _healthRisks.GetById(healthRiskId).Name;

            var dayOfCaseReport = Day.From(@event.Timestamp);
            var timeLimit30Days = dayOfCaseReport + 30;
            var timeLimit7Days  = dayOfCaseReport + 7;

            // Insert or update casereport depending on if it is in the list of not
            for (Day day = dayOfCaseReport; day < timeLimit30Days; day++)
            {
                var caseReport = new CaseReportForMap()
                {
                    NumberOfPeople = totalCases,
                    Location       = locationForCaseReport
                };

                if (day < timeLimit7Days)
                {
                    UpdateCaseReportLast7Days(caseReport, day, healthRiskName);
                }
                UpdateCaseReportLast30Days(caseReport, day, healthRiskName);
            }
        }
Example #23
0
        public void Process(CaseReportReceived @event)
        {
            var dataCollector = _dataCollectors.GetById(@event.DataCollectorId);

            if (dataCollector.InTraining)
            {
                return;                           // don't include training data
            }
            // Each day contains a health risk dictionary
            // Each healthrisk in the healthrisk dictionary contains two collections of case-reports from 7 and 30 days
            var totalCases            = @event.NumberOfFemalesAged5AndOlder + @event.NumberOfFemalesUnder5 + @event.NumberOfMalesAged5AndOlder + @event.NumberOfMalesUnder5;
            var locationForCaseReport = new Location(@event.Latitude, @event.Longitude);
            var healthRisk            = _healthRisks.GetById(@event.HealthRiskId);

            var dayOfCaseReport = Day.From(@event.Timestamp);
            var timeLimit4Weeks = dayOfCaseReport + 28;
            var timeLimit7Days  = dayOfCaseReport + 7;

            // Insert or update casereport depending on if it is in the list of not
            for (Day day = dayOfCaseReport; day < timeLimit4Weeks; day++)
            {
                var caseReport = new CaseReportForMap()
                {
                    HealthRiskName = healthRisk.Name,
                    NumberOfPeople = totalCases,
                    Location       = locationForCaseReport
                };

                if (day < timeLimit7Days)
                {
                    UpdateCaseReportLast7Days(caseReport, day, healthRisk.HealthRiskNumber);
                }
                UpdateCaseReportLast4Weeks(caseReport, day, healthRisk.HealthRiskNumber);
            }
        }
Example #24
0
        public void Process(DataCollectorVillageChanged @event, EventSourceId dataCollectorId)
        {
            var village = _repositoryForVillage.Query.FirstOrDefault(_ => _.Name == @event.Village);

            if (village == null)
            {
                var dataCollector = _dataCollectors.GetById(dataCollectorId);
                var district      = _repositoryForDistrict.Query.FirstOrDefault(_ => _.Name == dataCollector.District);
                _repositoryForVillage.Insert(new Village()
                {
                    Id         = Guid.NewGuid(),
                    Name       = @event.Village,
                    DistrictId = district.Id
                });
            }
        }
Example #25
0
        void TriggerAlerts(
            Read.AlertRules.AlertRule alertRule,
            Domain.Alerts.Alerts root,
            AvailableReport incommingReport) 
        {
            var openAlert = _openAlertsRepository.GetById(alertRule.HealthRiskId);
            if(openAlert != null)
            {
                root.AddReportToAlert(incommingReport.Id, openAlert.AlertId);
                return;
            }

            int casesThreshold = alertRule.NumberOfCasesThreshold;
            int healthRiskNumber = alertRule.HealthRiskId;
            TimeSpan alertRuleInterval = new TimeSpan(alertRule.ThresholdTimeframeInHours, 0, 0);

            DateTimeOffset horizon = DateTimeOffset.UtcNow - alertRuleInterval;
            var reportIds = _reportRepository.Query.Where(
                c => c.Timestamp >= horizon && c.HealthRiskNumber == healthRiskNumber)
                .Select(_ => _.Id.Value).ToList();

            if(reportIds.Count() >= casesThreshold)
            {
                root.OpenAlert(
                    Guid.NewGuid(),
                    alertRule.Id,
                    reportIds
                );
            }
            

        }
Example #26
0
        public void Process(ProjectUpdated @event)
        {
            var project = _projects.GetById(@event.Id);

            project.Name = @event.Name;
            _projects.Update(project);
        }
Example #27
0
        public void Process(AlertClosed @event)
        {
            var alert = _items.GetById(@event.AlertNumber);

            alert.Status = AlertStatus.Closed;
            _items.Update(alert);
        }
Example #28
0
        public void Process(CaseReportReceived @event)
        {
            var today = Day.From(@event.Timestamp);

            for (var day = today; day < today + 7; day++)
            {
                var totals = _caseReportTotalsRepository.GetById(day);
                if (totals != null)
                {
                    totals.FemalesUnder5 += @event.NumberOfFemalesUnder5;
                    totals.MalesUnder5   += @event.NumberOfMalesUnder5;
                    totals.FemalesOver5  += @event.NumberOfFemalesAged5AndOlder;
                    totals.MalesOver5    += @event.NumberOfMalesAged5AndOlder;

                    _caseReportTotalsRepository.Update(totals);
                }
                else
                {
                    totals = new CaseReportTotals()
                    {
                        Id            = day,
                        FemalesUnder5 = @event.NumberOfFemalesUnder5,
                        MalesUnder5   = @event.NumberOfMalesUnder5,
                        FemalesOver5  = @event.NumberOfFemalesAged5AndOlder,
                        MalesOver5    = @event.NumberOfMalesAged5AndOlder
                    };

                    _caseReportTotalsRepository.Insert(totals);
                }
            }
        }
        public void InsertPerHealthRiskAndRegionForComing4Weeks(CaseReport caseReport, HealthRisk healthRisk, District district)
        {
            // Insert by health risk and region
            var today    = Day.From(caseReport.Timestamp);
            var region   = _regions.GetById(district.RegionId);
            var numCases = caseReport.NumberOfMalesUnder5
                           + caseReport.NumberOfMalesAged5AndOlder
                           + caseReport.NumberOfFemalesUnder5
                           + caseReport.NumberOfFemalesAged5AndOlder;

            for (var day = 0; day < 28; day++)
            {
                var dayReport = _caseReportsPerRegionLast4Weeks.GetById(day + today);
                if (dayReport != null)
                {
                    var healthRiskForDay = dayReport.HealthRisks.FirstOrDefault(d => d.Id == caseReport.HealthRiskId);
                    if (healthRiskForDay != null)
                    {
                        var regionForHealthRisk = healthRiskForDay.Regions.FirstOrDefault(r => r.Name == region.Name);
                        if (regionForHealthRisk != null)
                        {
                            InsertNumCases(regionForHealthRisk, day, numCases);
                        }
                        else
                        {
                            healthRiskForDay.Regions.Add(AddRegionWithCases(region.Name, day, numCases));
                        }
                    }
                    else
                    {
                        dayReport.HealthRisks.Add(new HealthRisksInRegionsLast4Weeks()
                        {
                            Id             = caseReport.HealthRiskId,
                            HealthRiskName = healthRisk.Name,
                            Regions        = new[] { AddRegionWithCases(region.Name, day, numCases) }
                        });
                    }
                    _caseReportsPerRegionLast4Weeks.Update(dayReport);
                }
                else
                {
                    dayReport = new CaseReportsPerRegionLast4Weeks()
                    {
                        Id          = day + today,
                        HealthRisks = new[]
                        {
                            new HealthRisksInRegionsLast4Weeks()
                            {
                                Id             = caseReport.HealthRiskId,
                                HealthRiskName = healthRisk.Name,
                                Regions        = new [] { AddRegionWithCases(region.Name, day, numCases) }
                            }
                        }
                    };
                    _caseReportsPerRegionLast4Weeks.Insert(dayReport);
                }
            }
            ;
        }
        public void Process(InstallationRegistered @event)
        {
            var installationsList = _repositoryForInstallationsList.GetById(0);

            installationsList.Installations.Add(@event.InstallationId);
            _repositoryForInstallationsList.Update(installationsList);

            var repositoriesList = _repositoryForRepositoriesList.GetById(0);

            @event.Repositories.ForEach(name => repositoriesList.Repositories.Add(name));
            _repositoryForRepositoriesList.Update(repositoriesList);

            _repositoryForInstallationRepositories.Insert(new InstallationRepositories {
                Id           = @event.InstallationId,
                Repositories = new List <RepositoryFullName>(@event.Repositories.Select(_ => (RepositoryFullName)_)),
            });
        }