示例#1
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(LastActiveUpdated @event, EventSourceId dataCollectorId)
        {
            var dataCollector = _dataCollectors.GetById(dataCollectorId);

            dataCollector.LastActive = @event.LastActive;
            _dataCollectors.Update(dataCollector);
        }
        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);
            }
        }
示例#4
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);
        }
        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);
        }
示例#6
0
        public void Process(SmsGatewayNumberAssigned @event)
        {
            var smsGateway = _repository.GetById(@event.Id);

            smsGateway.PhoneNumber = @event.PhoneNumber;

            _repository.Update(smsGateway);
        }
        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);
        }
示例#8
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);
        }
示例#9
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);
        }
示例#10
0
        public void Process(HealthRiskModified @event)
        {
            var healthRisk = _healthRisks.GetById(@event.Id);

            healthRisk.Name = @event.Name;
            _healthRisks.Update(healthRisk);
        }
示例#11
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);
                }
            }
        }
示例#12
0
        public void Process(AlertClosed @event)
        {
            var alert = _items.GetById(@event.AlertNumber);

            alert.Status = AlertStatus.Closed;
            _items.Update(alert);
        }
示例#13
0
        public void Process(AlertRuleUpdated @event)
        {
            var rule = _repositoryForAlertRule.GetById(@event.Id);

            rule.HealthRiskName = @event.AlertRuleName;
            _repositoryForAlertRule.Update(rule);
        }
示例#14
0
 public void Process(HealthRiskModified @event)
 {
     _healthRisks.Update(new HealthRisk {
         Id   = @event.Id,
         Name = @event.Name
     });
 }
示例#15
0
        public void Process(ProjectUpdated @event)
        {
            var project = _projects.GetById(@event.Id);

            project.Name = @event.Name;
            _projects.Update(project);
        }
示例#16
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);
            }
        }
示例#17
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);
        }
        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)_)),
            });
        }
示例#20
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);
        }
示例#21
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);
 }
示例#22
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);
        }
示例#23
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);
            }
        }
示例#24
0
        public async void Process(InstallationRegistered @event)
        {
            await _lock.WaitAsync();

            var installationsList = GetOrCreateGlobalInstallationsList();

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

            var repositoriesList = GetOrCreateGlobalRepositoriesList();

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

            var installation = GetOrCreateInstallationById(@event.InstallationId);

            installation.Repositories = new List <RepositoryFullName>(@event.Repositories.Select(_ => (RepositoryFullName)_));
            _repositoryForInstallationRepositories.Update(installation);

            _lock.Release();
        }
示例#25
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);
        }
        public void Process(ItemDone evt)
        {
            var completions = _taskCompletions.GetById(evt.ListId);

            if (completions == null)
            {
                completions = new TaskCompletions
                {
                    Id             = evt.ListId,
                    TaskCompletion = new Dictionary <TodoText, DateTime>
                    {
                        [evt.Text] = DateTime.UtcNow
                    }
                };

                _taskCompletions.Insert(completions);
            }
            else
            {
                completions.TaskCompletion[evt.Text] = DateTime.UtcNow;

                _taskCompletions.Update(completions);
            }
        }
示例#27
0
        public void Process(KeyMessageAddedToHealthRisk @event)
        {
            var healthRisk = _repository.GetById(@event.HealthRiskId);

            healthRisk.KeyMessages = new List <KeyMessage>(healthRisk.KeyMessages)
            {
                new KeyMessage
                {
                    Id       = @event.KeyMessageId,
                    Message  = @event.Message,
                    Language = @event.Language
                }
            };
            _repository.Update(healthRisk);
        }
示例#28
0
        public void UpdateTotalReports()
        {
            var totalReports = _totalReports.GetById(Constants.TotalReportsID);

            if (totalReports != null)
            {
                totalReports.Reports++;
                _totalReports.Update(totalReports);
            }
            else
            {
                _totalReports.Insert(new TotalReports()
                {
                    Id      = Constants.TotalReportsID,
                    Reports = 1
                });
            }
        }
示例#29
0
        private void UpdateCaseReportLast4Weeks(CaseReportForMap caseReportMap, Day day, HealthRiskNumber healthRiskNumber)
        {
            var caseReportsLast4Weeks = _caseReportRepositoryLast4Weeks.GetById(day);

            if (caseReportsLast4Weeks == null)
            {
                caseReportsLast4Weeks = new CaseReportsLast4Weeks()
                {
                    Id = day,
                    CaseReportsPerHealthRisk = new Dictionary <HealthRiskNumber, IList <CaseReportForMap> > {
                    }
                };
                caseReportsLast4Weeks.CaseReportsPerHealthRisk[healthRiskNumber] = new List <CaseReportForMap> {
                    caseReportMap
                };
                _caseReportRepositoryLast4Weeks.Insert(caseReportsLast4Weeks);
            }
            else
            {
                UpdateCaseReportsPerHealthRisk(caseReportsLast4Weeks.CaseReportsPerHealthRisk, caseReportMap, healthRiskNumber);
                _caseReportRepositoryLast4Weeks.Update(caseReportsLast4Weeks);
            }
        }
示例#30
0
        public void Process(CaseReportReceived @event)
        {
            var dataCollector = _dataCollectors.GetById(@event.DataCollectorId);

            if (dataCollector.InTraining)
            {
                return;                           // don't inlcude training data
            }
            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);
                }
            }
        }