Example #1
0
        internal static ParsedReport ParseSingleReport(string reportMessage)
        {
            var singleReportMatch   = SingleReportRegex.Match(reportMessage);
            var healthRiskCodeMatch = singleReportMatch.Groups["healthRiskCode"].Value;
            var sexMatch            = singleReportMatch.Groups["sex"].Value;
            var ageGroupMatch       = singleReportMatch.Groups["ageGroup"].Value;

            var healthRiskCode = int.Parse(healthRiskCodeMatch);
            var sex            = int.Parse(sexMatch);
            var ageGroup       = int.Parse(ageGroupMatch);

            var parsedReport = new ParsedReport
            {
                HealthRiskCode = healthRiskCode,
                ReportType     = ReportType.Single,
                ReportedCase   =
                {
                    CountMalesBelowFive     = sex == Male && ageGroup == BelowFive
                        ? 1
                        : 0,
                    CountMalesAtLeastFive   = sex == Male && ageGroup == AtLeastFive
                        ? 1
                        : 0,
                    CountFemalesBelowFive   = sex == Female && ageGroup == BelowFive
                        ? 1
                        : 0,
                    CountFemalesAtLeastFive = sex == Female && ageGroup == AtLeastFive
                        ? 1
                        : 0
                }
            };

            return(parsedReport);
        }
Example #2
0
        internal static ParsedReport ParseAggregatedReport(string reportMessage)
        {
            var aggregatedReportMatch   = AggregatedReportRegex.Match(reportMessage);
            var healthRiskCodeMatch     = aggregatedReportMatch.Groups["healthRiskCode"].Value;
            var malesBelowFiveMatch     = aggregatedReportMatch.Groups["malesBelowFive"].Value;
            var malesAtLeastFiveMatch   = aggregatedReportMatch.Groups["malesAtLeastFive"].Value;
            var femalesBelowFiveMatch   = aggregatedReportMatch.Groups["femalesBelowFive"].Value;
            var femalesAtLeastFiveMatch = aggregatedReportMatch.Groups["femalesAtLeastFive"].Value;

            var healthRiskCode     = int.Parse(healthRiskCodeMatch);
            var malesBelowFive     = int.Parse(malesBelowFiveMatch);
            var malesAtLeastFive   = int.Parse(malesAtLeastFiveMatch);
            var femalesBelowFive   = int.Parse(femalesBelowFiveMatch);
            var femalesAtLeastFive = int.Parse(femalesAtLeastFiveMatch);

            var parsedReport = new ParsedReport
            {
                HealthRiskCode = healthRiskCode,
                ReportType     = ReportType.Aggregate,
                ReportedCase   =
                {
                    CountMalesBelowFive     = malesBelowFive,
                    CountMalesAtLeastFive   = malesAtLeastFive,
                    CountFemalesBelowFive   = femalesBelowFive,
                    CountFemalesAtLeastFive = femalesAtLeastFive
                }
            };

            return(parsedReport);
        }
Example #3
0
        internal ParsedReport ParseEventReport(string reportMessage)
        {
            var eventReportMatch = EventReportRegex.Match(reportMessage);
            var eventCodeMatch   = eventReportMatch.Groups["eventCode"].Value;

            var eventCode = int.Parse(eventCodeMatch);

            var parsedReport = new ParsedReport
            {
                HealthRiskCode = eventCode,
                ReportType     = ReportType.Statement
            };

            return(parsedReport);
        }
Example #4
0
        internal static ParsedReport ParseDcpReport(string reportMessage)
        {
            var dcpReportMatch                = DcpReportRegex.Match(reportMessage);
            var healthRiskCodeMatch           = dcpReportMatch.Groups["healthRiskCode"].Value;
            var malesBelowFiveMatch           = dcpReportMatch.Groups["malesBelowFive"].Value;
            var malesAtLeastFiveMatch         = dcpReportMatch.Groups["malesAtLeastFive"].Value;
            var femalesBelowFiveMatch         = dcpReportMatch.Groups["femalesBelowFive"].Value;
            var femalesAtLeastFiveMatch       = dcpReportMatch.Groups["femalesAtLeastFive"].Value;
            var referredToHealthFacilityMatch = dcpReportMatch.Groups["referredToHealthFacility"].Value;
            var diedInOrpMatch                = dcpReportMatch.Groups["diedInOrp"].Value;
            var cameFromOtherVillageMatch     = dcpReportMatch.Groups["cameFromOtherVillage"].Value;

            var healthRiskCode           = int.Parse(healthRiskCodeMatch);
            var malesBelowFive           = int.Parse(malesBelowFiveMatch);
            var malesAtLeastFive         = int.Parse(malesAtLeastFiveMatch);
            var femalesBelowFive         = int.Parse(femalesBelowFiveMatch);
            var femalesAtLeastFive       = int.Parse(femalesAtLeastFiveMatch);
            var referredToHealthFacility = int.Parse(referredToHealthFacilityMatch);
            var diedInOrp            = int.Parse(diedInOrpMatch);
            var cameFromOtherVillage = int.Parse(cameFromOtherVillageMatch);

            var parsedReport = new ParsedReport
            {
                HealthRiskCode = healthRiskCode,
                ReportType     = ReportType.DataCollectionPoint,
                ReportedCase   =
                {
                    CountMalesBelowFive     = malesBelowFive,
                    CountMalesAtLeastFive   = malesAtLeastFive,
                    CountFemalesBelowFive   = femalesBelowFive,
                    CountFemalesAtLeastFive = femalesAtLeastFive
                },
                DataCollectionPointCase =
                {
                    ReferredCount          = referredToHealthFacility,
                    DeathCount             = diedInOrp,
                    FromOtherVillagesCount = cameFromOtherVillage
                }
            };

            return(parsedReport);
        }
Example #5
0
        public void ValidateReport_WhenProjectHealthRiskDoesNotExist_ShouldThrowException()
        {
            // Arrange
            var projectHealthRisks      = new List <ProjectHealthRisk>();
            var projectHealthRisksDbSet = projectHealthRisks.AsQueryable().BuildMockDbSet();

            _nyssContextMock.ProjectHealthRisks.Returns(projectHealthRisksDbSet);

            var parsedReport = new ParsedReport {
                HealthRiskCode = 1
            };
            var dataCollector = new DataCollector {
                Project = new Project {
                    Id = 1
                }
            };

            // Assert
            Should.Throw <ReportValidationException>(async() => await _smsEagleHandler.ValidateReport(parsedReport, dataCollector));
        }
Example #6
0
        public void ValidateReport_WhenReportIsNotCorrect_ShouldThrowException(ReportType reportType, DataCollectorType dataCollectorType, HealthRiskType healthRiskType)
        {
            // Arrange
            var projectId          = 1;
            var healthRiskCode     = 1;
            var projectHealthRisks = new List <ProjectHealthRisk>
            {
                new ProjectHealthRisk
                {
                    Project = new Project {
                        Id = projectId
                    },
                    HealthRisk = new HealthRisk
                    {
                        HealthRiskType = healthRiskType,
                        HealthRiskCode = healthRiskCode
                    }
                }
            };
            var projectHealthRisksDbSet = projectHealthRisks.AsQueryable().BuildMockDbSet();

            _nyssContextMock.ProjectHealthRisks.Returns(projectHealthRisksDbSet);

            var parsedReport = new ParsedReport
            {
                ReportType     = reportType,
                HealthRiskCode = healthRiskCode
            };
            var dataCollector = new DataCollector
            {
                DataCollectorType = dataCollectorType,
                Project           = new Project {
                    Id = projectId
                }
            };

            // Assert
            Should.Throw <ReportValidationException>(async() => await _smsEagleHandler.ValidateReport(parsedReport, dataCollector));
        }
Example #7
0
        public async Task <ProjectHealthRisk> ValidateReport(ParsedReport parsedReport, DataCollector dataCollector)
        {
            var projectHealthRisk = await _nyssContext.ProjectHealthRisks
                                    .Include(phr => phr.HealthRisk)
                                    .SingleOrDefaultAsync(phr => phr.HealthRisk.HealthRiskCode == parsedReport.HealthRiskCode &&
                                                          phr.Project.Id == dataCollector.Project.Id);

            if (projectHealthRisk == null)
            {
                throw new ReportValidationException($"A health risk with code '{parsedReport.HealthRiskCode}' is not listed in project with id '{dataCollector.Project.Id}'.",
                                                    ReportErrorType.HealthRiskNotFound);
            }

            switch (dataCollector.DataCollectorType)
            {
            case DataCollectorType.Human:
                if (parsedReport.ReportType != ReportType.Single &&
                    parsedReport.ReportType != ReportType.Aggregate &&
                    parsedReport.ReportType != ReportType.Statement)
                {
                    throw new ReportValidationException($"A data collector of type '{DataCollectorType.Human}' can only send a report of type " +
                                                        $"'{ReportType.Single}', '{ReportType.Aggregate}', '{ReportType.Statement}'.");
                }

                break;

            case DataCollectorType.CollectionPoint:
                if (parsedReport.ReportType != ReportType.DataCollectionPoint &&
                    parsedReport.ReportType != ReportType.Statement)
                {
                    throw new ReportValidationException($"A data collector of type '{DataCollectorType.CollectionPoint}' can only send a report of type " +
                                                        $"'{ReportType.DataCollectionPoint}', '{ReportType.Statement}.");
                }

                break;

            default:
                throw new ReportValidationException($"A data collector of type '{dataCollector.DataCollectorType}' is not supported.");
            }

            switch (parsedReport.ReportType)
            {
            case ReportType.Single:
                if (projectHealthRisk.HealthRisk.HealthRiskType != HealthRiskType.Human)
                {
                    throw new ReportValidationException($"A report of type '{ReportType.Single}' has to be related to '{HealthRiskType.Human}' health risk only.");
                }

                break;

            case ReportType.Aggregate:
                if (projectHealthRisk.HealthRisk.HealthRiskType != HealthRiskType.Human)
                {
                    throw new ReportValidationException($"A report of type '{ReportType.Aggregate}' has to be related to '{HealthRiskType.Human}' health risk only.");
                }

                break;

            case ReportType.Statement:
                if (projectHealthRisk.HealthRisk.HealthRiskType != HealthRiskType.NonHuman &&
                    projectHealthRisk.HealthRisk.HealthRiskType != HealthRiskType.UnusualEvent &&
                    projectHealthRisk.HealthRisk.HealthRiskType != HealthRiskType.Activity)
                {
                    throw new ReportValidationException(
                              $"A report of type '{ReportType.Statement}' has to be related to '{HealthRiskType.NonHuman}' or '{HealthRiskType.UnusualEvent}' or '{HealthRiskType.Activity}' event only.");
                }

                break;

            case ReportType.DataCollectionPoint:
                if (projectHealthRisk.HealthRisk.HealthRiskType != HealthRiskType.Human)
                {
                    throw new ReportValidationException(
                              $"A report of type '{ReportType.DataCollectionPoint}' has to be related to '{HealthRiskType.Human}', '{HealthRiskType.NonHuman}', " +
                              $"'{HealthRiskType.UnusualEvent}', '{HealthRiskType.Activity}' event only.");
                }

                break;

            default:
                throw new ReportValidationException($"A report of type '{parsedReport.ReportType}' is not supported.");
            }

            return(projectHealthRisk);
        }