Exemple #1
0
        public void GivenValidTextMessageWithSingleCaseReport_MessageParsedToSingleCaseReport(
            string inputText,
            int expectedHealthRiskId,
            string expectedGender,
            int expectedAge)
        {
            var result = TextMessageContentParser.Parse(inputText) as SingleCaseReportContent;

            Assert.AreEqual(expectedHealthRiskId, result.HealthRiskId);
            Assert.AreEqual(expectedGender, result.Sex.ToString());
            Assert.AreEqual(expectedAge, result.Age);
        }
        //TODO: Add a test that ensure that the right count is put in the right property
        //TODO: This should possibly be process once, since it should only happen the first time a text message is recieved
        public void Process(TextMessageReceived @event)
        {
            //TODO: Handle if parsing fails and send TextMessageParseFailed event
            var caseReportContent = TextMessageContentParser.Parse(@event.Message);
            var dataCollector     = _dataCollectors.GetByPhoneNumber(@event.OriginNumber);

            if (caseReportContent.GetType() == typeof(SingleCaseReportContent))
            {
                var singlecaseReport = caseReportContent as SingleCaseReportContent;
                _eventEmitter.Emit(Feature, new CaseReportReceived
                {
                    Id = Guid.NewGuid(),
                    DataCollectorId       = dataCollector?.Id,
                    HealthRiskId          = _healthRisks.GetByReadableId(caseReportContent.HealthRiskId).Id,
                    NumberOfFemalesUnder5 =
                        singlecaseReport.Age <= 5 && singlecaseReport.Sex == Sex.Female ? 1 : 0,
                    NumberOfFemalesOver5 =
                        singlecaseReport.Age > 5 && singlecaseReport.Sex == Sex.Female ? 1 : 0,
                    NumberOfMalesUnder5 =
                        singlecaseReport.Age <= 5 && singlecaseReport.Sex == Sex.Male ? 1 : 0,
                    NumberOfMalesOver5 =
                        singlecaseReport.Age > 5 && singlecaseReport.Sex == Sex.Male ? 1 : 0,
                    Latitude  = @event.Latitude,
                    Longitude = @event.Longitude,
                    Timestamp = @event.Sent
                });
            }
            else
            {
                var report = caseReportContent as MultipleCaseReportContent;
                _eventEmitter.Emit(Feature, new CaseReportReceived
                {
                    Id = Guid.NewGuid(),
                    DataCollectorId       = dataCollector?.Id,
                    HealthRiskId          = _healthRisks.GetByReadableId(caseReportContent.HealthRiskId).Id,
                    NumberOfFemalesUnder5 = report.FemalesUnder5,
                    NumberOfFemalesOver5  = report.FemalesOver5,
                    NumberOfMalesUnder5   = report.MalesUnder5,
                    NumberOfMalesOver5    = report.MalesOver5,
                    Latitude  = @event.Latitude,
                    Longitude = @event.Longitude,
                    Timestamp = @event.Sent
                });
            }
            //TODO: emit AnonymousCaseReportRecieved
            //Or should both events be emitted?
            //if (dataCollector == null)
            //{

            //    return;
            //}
        }
Exemple #3
0
        public void GivenValidTextMessageWithSeveralCaseReports_MessageParsedToMultipleCaseReport(
            string inputText,
            int expectedHealthRiskId,
            int expectedMaleFiveOrUnder,
            int expectedMaleOverFive,
            int expectedFemaleFiveOrUnder,
            int expectedFemaleOverFive
            )
        {
            var result = TextMessageContentParser.Parse(inputText) as MultipleCaseReportContent;

            Assert.AreEqual(expectedHealthRiskId, result.HealthRiskId);
            Assert.AreEqual(expectedMaleFiveOrUnder, result.MalesUnder5);
            Assert.AreEqual(expectedMaleOverFive, result.MalesOver5);
            Assert.AreEqual(expectedFemaleFiveOrUnder, result.FemalesUnder5);
            Assert.AreEqual(expectedFemaleOverFive, result.FemalesOver5);
        }
Exemple #4
0
        //TODO: Add a test that ensure that the right count is put in the right property
        //TODO: This should possibly be process once, since it should only happen the first time a text message is recieved
        public void Process(TextMessageReceived @event)
        {
            var caseReportContent = TextMessageContentParser.Parse(@event.Message);
            var dataCollector     = _dataCollectors.GetByPhoneNumber(@event.OriginNumber);

            if (caseReportContent.GetType() == typeof(InvalidCaseReportContent))
            {
                //TODO: Handle if datacollector is unknown also. Different event?
                var invalidCaseReport = caseReportContent as InvalidCaseReportContent;
                _eventEmitter.Emit(Feature, new TextMessageParsingFailed
                {
                    Id = Guid.NewGuid(),
                    DataCollectorId     = dataCollector.Id,
                    Message             = @event.Message,
                    ParsingErrorMessage = invalidCaseReport.ErrorMessage
                });
            }
            else if (caseReportContent.GetType() == typeof(SingleCaseReportContent))
            {
                var singlecaseReport = caseReportContent as SingleCaseReportContent;
                var healthRisk       = _healthRisks.GetByReadableId(singlecaseReport.HealthRiskId);
                if (dataCollector == null)
                {
                    _eventEmitter.Emit(Feature, new AnonymousCaseReportRecieved
                    {
                        Id                    = Guid.NewGuid(),
                        PhoneNumber           = @event.OriginNumber,
                        HealthRiskId          = healthRisk.Id,
                        NumberOfFemalesUnder5 =
                            singlecaseReport.Age <= 5 && singlecaseReport.Sex == Sex.Female ? 1 : 0,
                        NumberOfFemalesOver5 =
                            singlecaseReport.Age > 5 && singlecaseReport.Sex == Sex.Female ? 1 : 0,
                        NumberOfMalesUnder5 =
                            singlecaseReport.Age <= 5 && singlecaseReport.Sex == Sex.Male ? 1 : 0,
                        NumberOfMalesOver5 =
                            singlecaseReport.Age > 5 && singlecaseReport.Sex == Sex.Male ? 1 : 0,
                        Latitude  = @event.Latitude,
                        Longitude = @event.Longitude,
                        Timestamp = @event.Sent
                    });
                    return;
                }
                _eventEmitter.Emit(Feature, new CaseReportReceived
                {
                    Id = Guid.NewGuid(),
                    DataCollectorId       = dataCollector.Id,
                    HealthRiskId          = healthRisk.Id,
                    NumberOfFemalesUnder5 =
                        singlecaseReport.Age <= 5 && singlecaseReport.Sex == Sex.Female ? 1 : 0,
                    NumberOfFemalesOver5 =
                        singlecaseReport.Age > 5 && singlecaseReport.Sex == Sex.Female ? 1 : 0,
                    NumberOfMalesUnder5 =
                        singlecaseReport.Age <= 5 && singlecaseReport.Sex == Sex.Male ? 1 : 0,
                    NumberOfMalesOver5 =
                        singlecaseReport.Age > 5 && singlecaseReport.Sex == Sex.Male ? 1 : 0,
                    Latitude  = @event.Latitude,
                    Longitude = @event.Longitude,
                    Timestamp = @event.Sent
                });
            }
            else
            {
                var report     = caseReportContent as MultipleCaseReportContent;
                var healthRisk = _healthRisks.GetByReadableId(report.HealthRiskId);
                if (dataCollector == null)
                {
                    _eventEmitter.Emit(Feature, new AnonymousCaseReportRecieved
                    {
                        Id                    = Guid.NewGuid(),
                        PhoneNumber           = @event.OriginNumber,
                        HealthRiskId          = healthRisk.Id,
                        NumberOfFemalesUnder5 = report.FemalesUnder5,
                        NumberOfFemalesOver5  = report.FemalesOver5,
                        NumberOfMalesUnder5   = report.MalesUnder5,
                        NumberOfMalesOver5    = report.MalesOver5,
                        Latitude              = @event.Latitude,
                        Longitude             = @event.Longitude,
                        Timestamp             = @event.Sent
                    });
                    return;
                }
                _eventEmitter.Emit(Feature, new CaseReportReceived
                {
                    Id = Guid.NewGuid(),
                    DataCollectorId       = dataCollector.Id,
                    HealthRiskId          = healthRisk.Id,
                    NumberOfFemalesUnder5 = report.FemalesUnder5,
                    NumberOfFemalesOver5  = report.FemalesOver5,
                    NumberOfMalesUnder5   = report.MalesUnder5,
                    NumberOfMalesOver5    = report.MalesOver5,
                    Latitude  = @event.Latitude,
                    Longitude = @event.Longitude,
                    Timestamp = @event.Sent
                });
            }
        }
Exemple #5
0
        public void GivenInvalidTextMessageWithSingleCaseReport_InvalidContenReturned(string inputText)
        {
            var result = TextMessageContentParser.Parse(inputText) as InvalidCaseReportContent;

            Assert.IsTrue(result.GetType() == typeof(InvalidCaseReportContent));
        }