예제 #1
0
        public IEnumerable <EventCustomerScreeningAggregate> Parse()
        {
            var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>();

            var directoryPath = GetFolderPathfor(_resultOutputPath);

            if (string.IsNullOrEmpty(directoryPath))
            {
                return(null);
            }

            foreach (var filePath in Directory.GetFiles(directoryPath))
            {
                _isSpiroFile = false;
                // IsEkgIppeFile = false;

                if (Path.GetExtension(filePath).ToLower().Contains("pdf"))
                {
                    var fileName = Path.GetFileName(filePath);

                    if (fileName.ToLower().StartsWith(SpiroFilePrefix.ToLower()))
                    {
                        _isSpiroFile = true;
                    }

                    //if (fileName.ToLower().StartsWith(EkgIppeFilePreFix.ToLower()))
                    //    IsEkgIppeFile = true;

                    var customerIdString = "";

                    if (_isSpiroFile)
                    {
                        var tempFileName = fileName.Substring(fileName.IndexOf("_") + 1);
                        customerIdString = tempFileName.Substring(0, tempFileName.IndexOf("_"));
                    }
                    //else if (IsEkgIppeFile)
                    //{
                    //    if (fileName.ToLower().StartsWith(EkgIppeFilePreFix.ToLower()))
                    //    {
                    //        var tempFileName = fileName.Substring(fileName.IndexOf("_") + 1);
                    //        customerIdString = tempFileName.Substring(0, tempFileName.IndexOf("_"));
                    //    }
                    //    else
                    //        customerIdString = fileName.Substring(0, fileName.IndexOf("_"));
                    //}
                    else
                    {
                        if (fileName.ToLower().StartsWith(EkgFilePrefix.ToLower()))
                        {
                            var tempFileName = fileName.Substring(fileName.IndexOf("_") + 1);
                            customerIdString = tempFileName.Substring(0, tempFileName.IndexOf("_"));
                        }
                        else
                        {
                            customerIdString = fileName.Substring(0, fileName.IndexOf("_"));
                        }
                    }

                    long customerId = 0;
                    if (!long.TryParse(customerIdString, out customerId))
                    {
                        _logger.Info("CustomerId not found on Pdf file" + filePath);
                        continue;
                    }

                    bool isSpiroTestPurchasedByCustomer    = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Spiro);
                    bool isAwvSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSpiro);

                    bool isEkgTestPurchasedByCustomer        = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.EKG);
                    bool isAwvEkgTestPurchasedByCustomer     = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkg);
                    bool isAwvEkgIppeTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkgIPPE);

                    try
                    {
                        if (_isSpiroFile)
                        {
                            if (!isSpiroTestPurchasedByCustomer && !isAwvSpiroTestPurchasedByCustomer)
                            {
                                _logger.Info("Spiro is not availed by CustomerId[" + customerId + "].\n");
                                continue;
                            }
                        }
                        else
                        {
                            if (!isEkgTestPurchasedByCustomer && !isAwvEkgTestPurchasedByCustomer && !isAwvEkgIppeTestPurchasedByCustomer)
                            {
                                _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "].\n");
                                continue;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (_isSpiroFile)
                        {
                            _logger.Info("Spiro is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace);
                        }
                        else
                        {
                            _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace);
                        }
                        continue;
                    }

                    try
                    {
                        TestType   testType;
                        TestResult testResult = null;
                        if (_isSpiroFile)
                        {
                            testType = TestType.Spiro;

                            if (isAwvSpiroTestPurchasedByCustomer)
                            {
                                testType = TestType.AwvSpiro;
                            }

                            string folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath;

                            var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString(), false);

                            if (resultMedia != null)
                            {
                                if (isAwvSpiroTestPurchasedByCustomer)
                                {
                                    testResult = new AwvSpiroTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                }
                                else if (isSpiroTestPurchasedByCustomer)
                                {
                                    testResult = new SpiroTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                }
                                _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult);

                                _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.Schiller);

                                _logger.Info(string.Concat("\nParsing succeeded for Spiro for Customer Id: ", customerId, "\n"));
                            }
                        }
                        else
                        {
                            testType = TestType.EKG;

                            if (isAwvEkgIppeTestPurchasedByCustomer) //&& IsEkgIppeFile
                            {
                                testType = TestType.AwvEkgIPPE;
                            }
                            else if (isAwvEkgTestPurchasedByCustomer)
                            {
                                testType = TestType.AwvEkg;
                            }

                            string folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath;

                            var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString());

                            if (resultMedia != null)
                            {
                                switch (testType)
                                {
                                case TestType.EKG:
                                    testResult = new EKGTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;

                                case TestType.AwvEkg:
                                    testResult = new AwvEkgTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;

                                case TestType.AwvEkgIPPE:
                                    testResult = new AwvEkgIppeTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;
                                }

                                _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult);
                                _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.Schiller);

                                _logger.Info(string.Concat("\nParsing succeeded for EKG  for Customer Id: ", customerId, "\n"));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (_isSpiroFile)
                        {
                            _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                            _resultParserHelper.AddResultArchiveLog(ex.Message, isAwvSpiroTestPurchasedByCustomer ? TestType.AwvSpiro : TestType.Spiro, customerId, MedicalEquipmentTag.Schiller, false);
                        }
                        else
                        {
                            _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                            _resultParserHelper.AddResultArchiveLog(ex.Message, isAwvEkgIppeTestPurchasedByCustomer ? TestType.AwvEkgIPPE : isAwvEkgTestPurchasedByCustomer ? TestType.AwvEkg : TestType.EKG, customerId, MedicalEquipmentTag.Schiller, false);
                        }
                    }
                }
            }
            return(eventCustomerAggregates);
        }
        public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestEntity)
        {
            var customerEventReadingEntities = customerEventScreeningTestEntity.CustomerEventReading.ToList();
            var testResult = new AwvEkgIppeTestResult(customerEventScreeningTestEntity.CustomerEventScreeningTestId);

            if (customerEventScreeningTestEntity.TestMedia != null && customerEventScreeningTestEntity.TestMedia.Count > 0)
            {
                var fileEntityCollection = customerEventScreeningTestEntity.FileCollectionViaTestMedia.ToList();
                var testMediaEntity      = customerEventScreeningTestEntity.TestMedia.FirstOrDefault();
                testResult.ResultImage = new ResultMedia(testMediaEntity.MediaId);

                testResult.ResultImage.File      = GetFileObjectfromEntity(testMediaEntity.FileId, fileEntityCollection);
                testResult.ResultImage.Thumbnail = testMediaEntity.ThumbnailFileId != null ? new File(testMediaEntity.ThumbnailFileId.Value) : null;

                if (testMediaEntity.IsManual)
                {
                    testResult.ResultImage.ReadingSource = ReadingSource.Manual;
                }
                else
                {
                    testResult.ResultImage.ReadingSource = ReadingSource.Automatic;
                }
            }

            var customerEventTestStandardFindingEntities = customerEventScreeningTestEntity.CustomerEventTestStandardFinding.ToList();

            var testResultService    = new TestResultService();
            var standardFindings     = testResultService.GetAllStandardFindings <int?>((int)TestType.AwvEkgIPPE);
            var bundleBranchFindings = testResultService.GetAllStandardFindings <int?>((int)TestType.AwvEkgIPPE, (int)ReadingLabels.BundleBranchBlock);
            var infarctionFindings   = testResultService.GetAllStandardFindings <int?>((int)TestType.AwvEkgIPPE, (int)ReadingLabels.InfarctionPattern);

            var standardFindingTestReadingEntities =
                customerEventScreeningTestEntity.
                StandardFindingTestReadingCollectionViaCustomerEventTestStandardFinding.ToList();

            customerEventTestStandardFindingEntities.ForEach(customerEventTestStandardFindingEntity =>
            {
                var standardFindingTestReadingEntity = standardFindingTestReadingEntities.Find(entity => entity.StandardFindingTestReadingId == customerEventTestStandardFindingEntity.StandardFindingTestReadingId);
                if (standardFindingTestReadingEntity == null)
                {
                    return;
                }

                var standardFindingEntity = standardFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault();
                if (standardFindingEntity != null)
                {
                    testResult.Finding = new StandardFinding <int?>(standardFindingEntity.Id)
                    {
                        CustomerEventStandardFindingId =
                            customerEventTestStandardFindingEntity.
                            CustomerEventTestStandardFindingId,
                        Label =
                            standardFindingEntity.Label,
                        MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue),
                        MinValue = Convert.ToInt32(standardFindingEntity.MinValue)
                    };
                    return;
                }

                standardFindingEntity = bundleBranchFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault();
                if (standardFindingEntity != null)
                {
                    var finding = new StandardFinding <int>(standardFindingEntity.Id)
                    {
                        CustomerEventStandardFindingId =
                            customerEventTestStandardFindingEntity.
                            CustomerEventTestStandardFindingId,
                        Label =
                            standardFindingEntity.Label,
                        MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue),
                        MinValue = Convert.ToInt32(standardFindingEntity.MinValue)
                    };
                    if (testResult.BundleBranchBlockFinding == null)
                    {
                        testResult.BundleBranchBlockFinding = new List <StandardFinding <int> >();
                    }
                    testResult.BundleBranchBlockFinding.Add(finding);
                    return;
                }

                standardFindingEntity = infarctionFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault();
                if (standardFindingEntity != null)
                {
                    var finding = new StandardFinding <int>(standardFindingEntity.Id)
                    {
                        CustomerEventStandardFindingId =
                            customerEventTestStandardFindingEntity.
                            CustomerEventTestStandardFindingId,
                        Label =
                            standardFindingEntity.Label,
                        MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue),
                        MinValue = Convert.ToInt32(standardFindingEntity.MinValue)
                    };
                    if (testResult.InfarctionPatternFinding == null)
                    {
                        testResult.InfarctionPatternFinding = new List <StandardFinding <int> >();
                    }
                    testResult.InfarctionPatternFinding.Add(finding);
                    return;
                }
            });


            testResult.PRInterval  = CreateResultReadingforNullableDecimal((int)ReadingLabels.PRInterval, customerEventReadingEntities);
            testResult.QRSDuration = CreateResultReadingforNullableDecimal((int)ReadingLabels.QRSDuration, customerEventReadingEntities);
            testResult.QTcInterval = CreateResultReadingforNullableDecimal((int)ReadingLabels.QTcInterval, customerEventReadingEntities);

            testResult.PRTAxis          = new PRTAxis();
            testResult.PRTAxis.PFront   = CreateResultReadingforNullableInt((int)ReadingLabels.PRTAxisPFront, customerEventReadingEntities);
            testResult.PRTAxis.QRSFront = CreateResultReadingforNullableInt((int)ReadingLabels.PRTAxisQRSFront, customerEventReadingEntities);
            testResult.PRTAxis.TFront   = CreateResultReadingforNullableInt((int)ReadingLabels.PRTAxisTFront, customerEventReadingEntities);

            testResult.QTDispersion = CreateResultReadingforNullableInt((int)ReadingLabels.QTDispersion, customerEventReadingEntities);
            testResult.QTInterval   = CreateResultReadingforNullableDecimal((int)ReadingLabels.QTInterval, customerEventReadingEntities);
            testResult.RRInterval   = CreateResultReadingforNullableInt((int)ReadingLabels.RRInterval, customerEventReadingEntities);
            testResult.VentRate     = CreateResultReadingforNullableInt((int)ReadingLabels.VentRate, customerEventReadingEntities);

            testResult.SinusRythm         = CreateResultReading((int)ReadingLabels.SinusRythm, customerEventReadingEntities);
            testResult.SinusArrythmia     = CreateResultReading((int)ReadingLabels.SinusArrythmia, customerEventReadingEntities);
            testResult.SinusBradycardia   = CreateResultReading((int)ReadingLabels.SinusBradycardia, customerEventReadingEntities);
            testResult.Mild               = CreateResultReading((int)ReadingLabels.Mild, customerEventReadingEntities);
            testResult.Marked             = CreateResultReading((int)ReadingLabels.Marked, customerEventReadingEntities);
            testResult.SinusTachycardia   = CreateResultReading((int)ReadingLabels.SinusTachycardia, customerEventReadingEntities);
            testResult.AtrialFibrillation = CreateResultReading((int)ReadingLabels.AtrialFibrillation, customerEventReadingEntities);
            testResult.AtrialFlutter      = CreateResultReading((int)ReadingLabels.AtrialFlutter, customerEventReadingEntities);
            testResult.SVT                           = CreateResultReading((int)ReadingLabels.SVT, customerEventReadingEntities);
            testResult.PACs                          = CreateResultReading((int)ReadingLabels.PACs, customerEventReadingEntities);
            testResult.PVCs                          = CreateResultReading((int)ReadingLabels.PVCs, customerEventReadingEntities);
            testResult.QRSWidening                   = CreateResultReading((int)ReadingLabels.QRSWidening, customerEventReadingEntities);
            testResult.LeftAxis                      = CreateResultReading((int)ReadingLabels.LeftAxis, customerEventReadingEntities);
            testResult.RightAxis                     = CreateResultReading((int)ReadingLabels.RightAxis, customerEventReadingEntities);
            testResult.AbnormalAxis                  = CreateResultReading((int)ReadingLabels.AbnormalAxis, customerEventReadingEntities);
            testResult.Left                          = CreateResultReading((int)ReadingLabels.Left, customerEventReadingEntities);
            testResult.Right                         = CreateResultReading((int)ReadingLabels.Right, customerEventReadingEntities);
            testResult.HeartBlock                    = CreateResultReading((int)ReadingLabels.HeartBlock, customerEventReadingEntities);
            testResult.TypeI                         = CreateResultReading((int)ReadingLabels.TypeI, customerEventReadingEntities);
            testResult.TypeII                        = CreateResultReading((int)ReadingLabels.TypeII, customerEventReadingEntities);
            testResult.FirstDegreeBlock              = CreateResultReading((int)ReadingLabels.FirstDegreeBlock, customerEventReadingEntities);
            testResult.SecondDegreeBlock             = CreateResultReading((int)ReadingLabels.SecondDegreeBlock, customerEventReadingEntities);
            testResult.ThirdDegreeCompleteHeartBlock = CreateResultReading((int)ReadingLabels.ThirdDegreeCompleteHeartBlock, customerEventReadingEntities);
            testResult.Artifact                      = CreateResultReading((int)ReadingLabels.Artifact, customerEventReadingEntities);

            testResult.BundleBranchBlock           = CreateResultReading((int)ReadingLabels.BundleBranchBlock, customerEventReadingEntities);
            testResult.LeftAnteriorFasicularBlock  = CreateResultReading((int)ReadingLabels.LeftAnteriorFasicularBlock, customerEventReadingEntities);
            testResult.VentricularHypertrophy      = CreateResultReading((int)ReadingLabels.VentricularHypertrophy, customerEventReadingEntities);
            testResult.LeftVentricularHypertrophy  = CreateResultReading((int)ReadingLabels.LeftVHypertrophy, customerEventReadingEntities);
            testResult.RightVentricularHypertrophy = CreateResultReading((int)ReadingLabels.RightVHypertrophy, customerEventReadingEntities);
            testResult.ProlongedQTInterval         = CreateResultReading((int)ReadingLabels.ProlongedQTInterval, customerEventReadingEntities);
            testResult.IschemicSTTChanges          = CreateResultReading((int)ReadingLabels.IschemicSTTChanges, customerEventReadingEntities);
            testResult.NonSpecificSTTChanges       = CreateResultReading((int)ReadingLabels.NonSpecificSTTChanges, customerEventReadingEntities);
            testResult.PoorRWaveProgression        = CreateResultReading((int)ReadingLabels.PoorRWaveProgression, customerEventReadingEntities);
            testResult.InfarctionPattern           = CreateResultReading((int)ReadingLabels.InfarctionPattern, customerEventReadingEntities);
            testResult.AtypicalQWaveLead           = CreateResultReading((int)ReadingLabels.AtypicalQWaveLead, customerEventReadingEntities);
            testResult.AtrialEnlargement           = CreateResultReading((int)ReadingLabels.AtrialEnlargement, customerEventReadingEntities);
            testResult.LeftAtrialEnlargement       = CreateResultReading((int)ReadingLabels.LeftAtrialEnlargment, customerEventReadingEntities);
            testResult.RightAtrialEnlargement      = CreateResultReading((int)ReadingLabels.RightAtrialEnlargment, customerEventReadingEntities);
            testResult.RepolarizationVariant       = CreateResultReading((int)ReadingLabels.RepolarizationVariant, customerEventReadingEntities);
            testResult.PacerRythm = CreateResultReading((int)ReadingLabels.PacerRythm, customerEventReadingEntities);
            testResult.SupraventricularArrythmia = CreateResultReading((int)ReadingLabels.SupraventricularArrythmia, customerEventReadingEntities);

            testResult.ReversedLeads = CreateResultReading((int)ReadingLabels.ReversedLeads, customerEventReadingEntities);
            testResult.RepeatStudy   = CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities);
            testResult.ComparetoEkg  = CreateResultReading((int)ReadingLabels.ComparetoEkg, customerEventReadingEntities);

            testResult.LowVoltage      = CreateResultReading((int)ReadingLabels.LowVoltage, customerEventReadingEntities);
            testResult.LimbLeads       = CreateResultReading((int)ReadingLabels.LimbLeads, customerEventReadingEntities);
            testResult.PrecordialLeads = CreateResultReading((int)ReadingLabels.PrecordialLeads, customerEventReadingEntities);

            return(testResult);
        }
예제 #3
0
        public void CopyOverAwvEkgIppeGraph(long eventId, long customerId, string saveFilePath, AwvEkgIppeTestResult testResult)
        {
            if (testResult == null || testResult.ResultImage == null)
            {
                return;
            }
            var destinationDirectory = Path.GetDirectoryName(saveFilePath);

            var supportDestDirectoryPath = destinationDirectory + @"\" + StringforMediaDirectory;

            if (!Directory.Exists(supportDestDirectoryPath))
            {
                Directory.CreateDirectory(supportDestDirectoryPath);
            }

            string input = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath +
                           testResult.ResultImage.File.Path;

            using (Image img = Image.FromFile(input))
            {
                //rotate the picture by 90 degrees and re-save the picture as a Jpeg
                img.RotateFlip(RotateFlipType.Rotate270FlipNone);
                img.Save(supportDestDirectoryPath + "\\" + testResult.ResultImage.File.Path, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
예제 #4
0
        public IEnumerable <EventCustomerScreeningAggregate> Parse()
        {
            var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>();

            var directoryPath = GetFolderPathfor(_resultOutputPath);

            if (string.IsNullOrEmpty(directoryPath))
            {
                return(null);
            }

            foreach (var filePath in DirectoryOperationsHelper.GetFiles(directoryPath))
            {
                if (Path.GetExtension(filePath).ToLower().Contains("pdf"))
                {
                    _logger.Info("Parsing file : " + filePath);
                    var  fileName = Path.GetFileName(filePath);
                    bool isSpiro  = false;
                    var  fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                    isSpiro = fileNameWithoutExtension.ToLower().EndsWith(SpiroFilePrefix);


                    var searchPattern = fileName.Substring(0, GetIndexOfNthOccurence(fileName, '_', 5)) + "*" + (isSpiro ? "_spiro.pdf" : "_ecg.pdf");

                    var versionedFiles = DirectoryOperationsHelper.GetFiles(directoryPath, searchPattern).Select(Path.GetFileName);;

                    var latestVersion = versionedFiles.OrderByDescending(x => x).First();

                    if (Path.GetFileName(filePath) != latestVersion)
                    {
                        _logger.Info("A more recent version of this file is present : " + latestVersion);
                        continue;
                    }

                    var customerIdString = fileName.IndexOf("_") > 0 ? fileName.Substring(0, fileName.IndexOf("_")) : fileName;

                    long customerId;

                    if (!long.TryParse(customerIdString, out customerId))
                    {
                        _logger.Info("Customer ID not found on Pdf file : " + filePath);
                        continue;
                    }

                    if (!isSpiro)
                    {
                        bool isEkgTestPurchasedByCustomer        = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.EKG);
                        bool isAwvEkgTestPurchasedByCustomer     = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkg);
                        bool isAwvEkgIppeTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkgIPPE);

                        try
                        {
                            if (!isEkgTestPurchasedByCustomer && !isAwvEkgTestPurchasedByCustomer && !isAwvEkgIppeTestPurchasedByCustomer)
                            {
                                _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "].\n");
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace);
                            continue;
                        }

                        try
                        {
                            TestResult testResult = null;
                            var        testType   = TestType.EKG;

                            if (isAwvEkgIppeTestPurchasedByCustomer) //&& IsEkgIppeFile
                            {
                                testType = TestType.AwvEkgIPPE;
                            }
                            else if (isAwvEkgTestPurchasedByCustomer)
                            {
                                testType = TestType.AwvEkg;
                            }

                            var folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath;

                            var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString());
                            resultMedia.ReadingSource = ReadingSource.Automatic;

                            if (resultMedia != null)
                            {
                                switch (testType)
                                {
                                case TestType.EKG:
                                    testResult = new EKGTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;

                                case TestType.AwvEkg:
                                    testResult = new AwvEkgTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;

                                case TestType.AwvEkgIPPE:
                                    testResult = new AwvEkgIppeTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;
                                }

                                _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult);
                                _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.CardioCard);

                                _logger.Info(string.Concat("\nParsing succeeded for EKG  for Customer Id: ", customerId, "\n"));
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                            _resultParserHelper.AddResultArchiveLog(ex.Message, isAwvEkgIppeTestPurchasedByCustomer ? TestType.AwvEkgIPPE : isAwvEkgTestPurchasedByCustomer ? TestType.AwvEkg : TestType.EKG, customerId, MedicalEquipmentTag.CardioCard, false);
                        }
                    }
                    else if (isSpiro)
                    {
                        bool isSpiroTestPurchasedByCustomer    = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Spiro);
                        bool isAwvSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSpiro);

                        try
                        {
                            if (!isSpiroTestPurchasedByCustomer && !isAwvSpiroTestPurchasedByCustomer)
                            {
                                _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "].\n");
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace);
                            continue;
                        }

                        try
                        {
                            TestResult testResult = null;
                            var        testType   = TestType.Spiro;

                            if (isAwvSpiroTestPurchasedByCustomer)
                            {
                                testType = TestType.AwvSpiro;
                            }

                            var folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath;

                            var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString(), false);
                            resultMedia.ReadingSource = ReadingSource.Automatic;

                            if (resultMedia != null)
                            {
                                switch (testType)
                                {
                                case TestType.Spiro:
                                    testResult = new SpiroTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;

                                case TestType.AwvSpiro:
                                    testResult = new AwvSpiroTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;
                                }

                                _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult);
                                _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.CardioCard);

                                _logger.Info(string.Concat("\nParsing succeeded for SPIRO/AWVSPIRO  for Customer Id: ", customerId, "\n"));
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                            _resultParserHelper.AddResultArchiveLog(ex.Message, isSpiroTestPurchasedByCustomer ? TestType.Spiro : TestType.AwvSpiro, customerId, MedicalEquipmentTag.CardioCard, false);
                        }
                    }
                }
            }
            return(eventCustomerAggregates);
        }