예제 #1
0
        /// <inheritdoc/>
        public void Process(TextMessage message)
        {
            var parsingResult   = _textMessageParser.Parse(message);
            var dataCollectorId = _dataCollectors.GetIdByPhoneNumber(message.OriginNumber);
            var unknown         = dataCollectorId == DataCollectorId.NotSet;

            var caseReportId  = Guid.NewGuid();
            var caseReporting = _caseReportingRepository.Get(caseReportId);

            if (!parsingResult.IsValid)
            {
                ReportInvalidMessage(message, parsingResult, dataCollectorId, unknown, caseReporting);
                return;
            }

            // Todo: Should we have a validation check if we actually get a health risk id
            var healthRiskId = _healthRisks.GetIdFromReadableId(parsingResult.Numbers[0]);

            if (!parsingResult.HasMultipleCases)
            {
                var sex = (Sex)parsingResult.Numbers[1];
                var age = parsingResult.Numbers[2];
                ReportSingle(message, dataCollectorId, caseReporting, healthRiskId, sex, age, unknown);
            }
            else
            {
                var malesUnder5   = parsingResult.Numbers[1];
                var malesOver5    = parsingResult.Numbers[2];
                var femalesUnder5 = parsingResult.Numbers[3];
                var femalesOver5  = parsingResult.Numbers[4];

                ReportMultiple(message, dataCollectorId, unknown, caseReporting, healthRiskId, malesUnder5, malesOver5, femalesUnder5, femalesOver5);
            }
        }