public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestsEntity)
        {
            var customerEventReadingEntities = customerEventScreeningTestsEntity.CustomerEventReading.ToList();

            var testResult = new FloChecABITestResult(customerEventScreeningTestsEntity.CustomerEventScreeningTestId)
            {
                LeftResultReadings  = new FloChecABIReadings(),
                RightResultReadings = new FloChecABIReadings(),
                PencilDopplerUsed   = this.CreateResultReading((int)ReadingLabels.PencilDopplerUsed, customerEventReadingEntities),

                RepeatStudy = this.CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities)
            };


            testResult.RightResultReadings.ABI = CreateResultReadingforNullableDecimal((int)ReadingLabels.RightABI, customerEventReadingEntities);
            testResult.LeftResultReadings.ABI  = CreateResultReadingforNullableDecimal((int)ReadingLabels.LeftABI, customerEventReadingEntities);

            testResult.RightResultReadings.BFI = CreateResultReadingforNullableDecimal((int)ReadingLabels.RightHandBFI, customerEventReadingEntities);
            testResult.LeftResultReadings.BFI  = CreateResultReadingforNullableDecimal((int)ReadingLabels.LeftHandBFI, customerEventReadingEntities);

            if (customerEventScreeningTestsEntity.TestMedia != null && customerEventScreeningTestsEntity.TestMedia.Count > 0)
            {
                var fileEntityCollection = customerEventScreeningTestsEntity.FileCollectionViaTestMedia.ToList();
                var testMediaEntity      = customerEventScreeningTestsEntity.TestMedia.FirstOrDefault();

                testResult.ResultImage = new ResultMedia(testMediaEntity.MediaId)
                {
                    File          = GetFileObjectfromEntity(testMediaEntity.FileId, fileEntityCollection),
                    Thumbnail     = testMediaEntity.ThumbnailFileId != null ? new File(testMediaEntity.ThumbnailFileId.Value) : null,
                    ReadingSource = testMediaEntity.IsManual ? ReadingSource.Manual : ReadingSource.Automatic
                };
            }

            var standardFindings         = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.FloChecABI);
            var standardFindingsLeftAbi  = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.FloChecABI, (int)ReadingLabels.LeftABI);
            var standardFindingsRightAbi = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.FloChecABI, (int)ReadingLabels.RightABI);

            var testResultService = new TestResultService();

            StandardFinding <decimal> leftResultFinding, rightResultFinding;

            leftResultFinding = rightResultFinding = null;

            if (standardFindings == null || standardFindings.Count < 1)
            {
                standardFindings = standardFindingsLeftAbi;
            }

            int findingId = 0;

            if (testResult.LeftResultReadings.ABI != null)
            {
                findingId         = testResultService.GetCalculatedStandardFinding(testResult.LeftResultReadings.ABI.Reading, (int)TestType.FloChecABI, standardFindingsLeftAbi != null && standardFindingsLeftAbi.Count() > 0 ? (int?)ReadingLabels.LeftABI : null);
                leftResultFinding = standardFindings.Where(f => f.Id == findingId).SingleOrDefault();
            }

            if (testResult.RightResultReadings.ABI != null)
            {
                findingId          = testResultService.GetCalculatedStandardFinding(testResult.RightResultReadings.ABI.Reading, (int)TestType.FloChecABI, standardFindingsRightAbi != null && standardFindingsRightAbi.Count() > 0 ? (int?)ReadingLabels.RightABI : null);
                rightResultFinding = standardFindings.Where(f => f.Id == findingId).SingleOrDefault();
            }
            if (standardFindingsLeftAbi == null || standardFindingsLeftAbi.Count() < 1)
            {
                var customerEventTestStandardFindingEntity = customerEventScreeningTestsEntity.CustomerEventTestStandardFinding.FirstOrDefault();

                if (customerEventTestStandardFindingEntity != null)
                {
                    var standardFindingTestReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventTestStandardFinding.LastOrDefault();

                    var standardFindingEntity = standardFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault();

                    if (standardFindingEntity != null)
                    {
                        testResult.Finding = new StandardFinding <decimal>(standardFindingEntity.Id)
                        {
                            CustomerEventStandardFindingId = customerEventTestStandardFindingEntity.CustomerEventTestStandardFindingId,
                            Label    = standardFindingEntity.Label,
                            MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue),
                            MinValue = Convert.ToInt32(standardFindingEntity.MinValue)
                        };
                    }
                }
                else
                {
                    testResult.Finding = GetFindingToConsider(leftResultFinding, rightResultFinding);

                    if (testResult.Finding != null)
                    {
                        var standardFinding = standardFindings.Find(finding => finding.Id == testResult.Finding.Id);
                        if (standardFinding != null)
                        {
                            testResult.Finding = standardFinding;
                        }
                    }
                }
            }
            else
            {
                var testReadingLAbiReading = customerEventReadingEntities.Where(customerEventReading => customerEventReading.TestReading.ReadingId == (int)ReadingLabels.LeftABI).SingleOrDefault();
                var testReadingRAbiReading = customerEventReadingEntities.Where(customerEventReading => customerEventReading.TestReading.ReadingId == (int)ReadingLabels.RightABI).SingleOrDefault();

                if (testReadingLAbiReading != null && testReadingLAbiReading.StandardFindingTestReadingId != null)
                {
                    var standardFindingReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventReading.ToList().Find(stdFindingTestReading =>
                                                                                                                                                                   stdFindingTestReading.TestId == (int)TestType.FloChecABI && stdFindingTestReading.ReadingId == (int)ReadingLabels.LeftABI);

                    if (standardFindingReadingEntity != null)
                    {
                        testResult.LeftResultReadings.Finding = new StandardFinding <decimal>(standardFindingReadingEntity.StandardFindingId);
                    }
                }
                else if (leftResultFinding != null)
                {
                    testResult.LeftResultReadings.Finding = leftResultFinding;
                }

                if (testResult.LeftResultReadings.Finding != null)
                {
                    testResult.LeftResultReadings.Finding = standardFindings.Where(sf => sf.Id == testResult.LeftResultReadings.Finding.Id).SingleOrDefault();
                }

                //-----------------------------------------------------------------------------------
                if (testReadingRAbiReading != null && testReadingRAbiReading.StandardFindingTestReadingId != null)
                {
                    var standardFindingReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventReading.ToList().Find(stdFindingTestReading =>
                                                                                                                                                                   stdFindingTestReading.TestId == (int)TestType.FloChecABI && stdFindingTestReading.ReadingId == (int)ReadingLabels.RightABI);

                    if (standardFindingReadingEntity != null)
                    {
                        testResult.RightResultReadings.Finding = new StandardFinding <decimal>(standardFindingReadingEntity.StandardFindingId);
                    }
                }
                else if (rightResultFinding != null)
                {
                    testResult.RightResultReadings.Finding = rightResultFinding;
                }

                if (testResult.RightResultReadings.Finding != null)
                {
                    testResult.RightResultReadings.Finding = standardFindings.Where(sf => sf.Id == testResult.RightResultReadings.Finding.Id).SingleOrDefault();
                }
            }

            return(testResult);
        }
        public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestsEntity)
        {
            var customerEventReadingEntities = customerEventScreeningTestsEntity.CustomerEventReading.ToList();

            var testResult = new PADTestResult(customerEventScreeningTestsEntity.CustomerEventScreeningTestId)
            {
                LeftResultReadings  = new PadTestReadings(),
                RightResultReadings = new PadTestReadings(),
                PressureReadings    = new CardiovisionPressureReadings(),
                SystolicHighestArm  = this.CreateResultReadingforNullableInt((int)ReadingLabels.SystolicHighestArm, customerEventReadingEntities),
                PencilDopplerUsed   = this.CreateResultReading((int)ReadingLabels.PencilDopplerUsed, customerEventReadingEntities),
                RepeatStudy         = this.CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities)
            };

            testResult.RightResultReadings.SystolicArm     = CreateResultReadingforNullableInt((int)ReadingLabels.SystolicRArm, customerEventReadingEntities);
            testResult.RightResultReadings.SystolicAnkle   = CreateResultReadingforNullableInt((int)ReadingLabels.SystolicRAnkle, customerEventReadingEntities);
            testResult.RightResultReadings.ABI             = CreateResultReadingforNullableDecimal((int)ReadingLabels.RightABI, customerEventReadingEntities);
            testResult.RightResultReadings.UnabletoOcclude = this.CreateResultReading((int)ReadingLabels.RightUnabletoOcclude, customerEventReadingEntities);

            testResult.LeftResultReadings.SystolicArm     = CreateResultReadingforNullableInt((int)ReadingLabels.SystolicLArm, customerEventReadingEntities);
            testResult.LeftResultReadings.SystolicAnkle   = CreateResultReadingforNullableInt((int)ReadingLabels.SystolicLAnkle, customerEventReadingEntities);
            testResult.LeftResultReadings.ABI             = CreateResultReadingforNullableDecimal((int)ReadingLabels.LeftABI, customerEventReadingEntities);
            testResult.LeftResultReadings.UnabletoOcclude = this.CreateResultReading((int)ReadingLabels.LeftUnabletoOcclude, customerEventReadingEntities);


            var standardFindings         = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.PAD);
            var standardFindingsLeftAbi  = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.PAD, (int)ReadingLabels.LeftABI);
            var standardFindingsRightAbi = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.PAD, (int)ReadingLabels.RightABI);

            var testResultService = new TestResultService();

            StandardFinding <decimal> leftResultFinding, rightResultFinding;

            leftResultFinding = rightResultFinding = null;

            if (standardFindings == null || standardFindings.Count < 1)
            {
                standardFindings = standardFindingsLeftAbi;
            }

            int findingId = 0;

            if (testResult.LeftResultReadings.ABI != null)
            {
                findingId         = testResultService.GetCalculatedStandardFinding(testResult.LeftResultReadings.ABI.Reading, (int)TestType.PAD, standardFindingsLeftAbi != null && standardFindingsLeftAbi.Count() > 0 ? (int?)ReadingLabels.LeftABI : null);
                leftResultFinding = standardFindings.Where(f => f.Id == findingId).SingleOrDefault();
            }

            if (testResult.RightResultReadings.ABI != null)
            {
                findingId          = testResultService.GetCalculatedStandardFinding(testResult.RightResultReadings.ABI.Reading, (int)TestType.PAD, standardFindingsRightAbi != null && standardFindingsRightAbi.Count() > 0 ? (int?)ReadingLabels.RightABI : null);
                rightResultFinding = standardFindings.Where(f => f.Id == findingId).SingleOrDefault();
            }
            if (standardFindingsLeftAbi == null || standardFindingsLeftAbi.Count() < 1)
            {
                var customerEventTestStandardFindingEntity = customerEventScreeningTestsEntity.CustomerEventTestStandardFinding.FirstOrDefault();

                if (customerEventTestStandardFindingEntity != null)
                {
                    var standardFindingTestReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventTestStandardFinding.LastOrDefault();

                    var standardFindingEntity = standardFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault();

                    if (standardFindingEntity != null)
                    {
                        testResult.Finding = new StandardFinding <decimal>(standardFindingEntity.Id)
                        {
                            CustomerEventStandardFindingId = customerEventTestStandardFindingEntity.CustomerEventTestStandardFindingId,
                            Label    = standardFindingEntity.Label,
                            MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue),
                            MinValue = Convert.ToInt32(standardFindingEntity.MinValue)
                        };
                    }
                }
                else
                {
                    testResult.Finding = GetFindingToConsider(leftResultFinding, rightResultFinding);

                    if (testResult.Finding != null)
                    {
                        var standardFinding = standardFindings.Find(finding => finding.Id == testResult.Finding.Id);
                        if (standardFinding != null)
                        {
                            testResult.Finding = standardFinding;
                        }
                    }
                }
            }
            else
            {
                var testReadingLAbiReading = customerEventReadingEntities.Where(customerEventReading => customerEventReading.TestReading.ReadingId == (int)ReadingLabels.LeftABI).SingleOrDefault();
                var testReadingRAbiReading = customerEventReadingEntities.Where(customerEventReading => customerEventReading.TestReading.ReadingId == (int)ReadingLabels.RightABI).SingleOrDefault();

                if (testReadingLAbiReading != null && testReadingLAbiReading.StandardFindingTestReadingId != null)
                {
                    var standardFindingReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventReading.ToList().Find(stdFindingTestReading =>
                                                                                                                                                                   stdFindingTestReading.TestId == (int)TestType.PAD && stdFindingTestReading.ReadingId == (int)ReadingLabels.LeftABI);

                    if (standardFindingReadingEntity != null)
                    {
                        testResult.LeftResultReadings.Finding = new StandardFinding <decimal>(standardFindingReadingEntity.StandardFindingId);
                    }
                }
                else if (leftResultFinding != null)
                {
                    testResult.LeftResultReadings.Finding = leftResultFinding;
                }

                if (testResult.LeftResultReadings.Finding != null)
                {
                    testResult.LeftResultReadings.Finding = standardFindings.Where(sf => sf.Id == testResult.LeftResultReadings.Finding.Id).SingleOrDefault();
                }

                //-----------------------------------------------------------------------------------
                if (testReadingRAbiReading != null && testReadingRAbiReading.StandardFindingTestReadingId != null)
                {
                    var standardFindingReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventReading.ToList().Find(stdFindingTestReading =>
                                                                                                                                                                   stdFindingTestReading.TestId == (int)TestType.PAD && stdFindingTestReading.ReadingId == (int)ReadingLabels.RightABI);

                    if (standardFindingReadingEntity != null)
                    {
                        testResult.RightResultReadings.Finding = new StandardFinding <decimal>(standardFindingReadingEntity.StandardFindingId);
                    }
                }
                else if (rightResultFinding != null)
                {
                    testResult.RightResultReadings.Finding = rightResultFinding;
                }

                if (testResult.RightResultReadings.Finding != null)
                {
                    testResult.RightResultReadings.Finding = standardFindings.Where(sf => sf.Id == testResult.RightResultReadings.Finding.Id).SingleOrDefault();
                }
            }


            return(testResult);
        }