public PhysicianPartnerResultExportModel SetSpiroData(PhysicianPartnerResultExportModel model, SpiroTestResult testResult)
        {
            if (testResult.Finding != null)
            {
                model.SpiroResult = testResult.Finding.Label;
            }

            model.SpiroPoorEffort  = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.PoorEffort);
            model.SpiroRestrictive = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Restrictive);
            model.SpiroObstructive = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Obstructive);


            model.SpiroTechnicallyLimitedButReadable = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.TechnicallyLimitedbutReadable);
            model.SpiroRepeatStudyUnreadable         = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RepeatStudy);

            model.SpiroUnabletoScreen = testResult.UnableScreenReason != null && testResult.UnableScreenReason.Count > 0 ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            if ((testResult.ResultStatus != null && testResult.ResultStatus.SelfPresent) || (testResult.PhysicianInterpretation != null && testResult.PhysicianInterpretation.IsCritical))
            {
                model.SpiroCritical = PhysicianPartnerResultExportHelper.YesString;
            }
            else
            {
                model.SpiroCritical = PhysicianPartnerResultExportHelper.NoString;
            }

            if (testResult.PhysicianInterpretation != null)
            {
                model.SpiroPhysicianNotes = testResult.PhysicianInterpretation.Remarks;
            }

            return(model);
        }
        public PhysicianPartnerResultExportModel SetAaaData(PhysicianPartnerResultExportModel model, PpAaaTestResult testResult)
        {
            if (testResult.Finding != null)
            {
                model.AaaResult = testResult.Finding.Label;
            }

            model.AaaLargestSagittalMeasurement = testResult.AortaSize != null ? testResult.AortaSize.Reading != null?testResult.AortaSize.Reading.ToString() : "" : "";

            model.AaaLargestSagittalLocation = string.Join(",", testResult.AortaRangeSaggitalView != null ? testResult.AortaRangeSaggitalView.Select(s => s.Label).ToArray() : new[] { "" });


            model.AaaLargestTransverseMeasurement1 = testResult.TransverseView != null ? testResult.TransverseView.FirstValue != null?testResult.TransverseView.FirstValue.Reading.ToString() : "" : "";

            model.AaaLargestTransverseMeasurement2 = testResult.TransverseView != null ? testResult.TransverseView.SecondValue != null?testResult.TransverseView.SecondValue.Reading.ToString() : "" : "";


            model.AaaLargestMeasurementTransverseLocation = string.Join(",", testResult.AortaRangeTransverseView != null ? testResult.AortaRangeTransverseView.Select(s => s.Label).ToArray() : new[] { "" });


            model.AaaAorticDissection = testResult.AorticDissection != null ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            model.AaaPlaque = testResult.Plaque != null ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            model.AaaThrombus = testResult.Thrombus != null ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            if (testResult.IncidentalFindings != null && testResult.IncidentalFindings.Count > 0)
            {
                model.AaaAorticStenosis = PhysicianPartnerResultExportHelper.YesString;
            }
            else
            {
                model.AaaAorticStenosis = PhysicianPartnerResultExportHelper.NoString;
            }

            model.AaaTechnicallyLimitedButReadable = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.TechnicallyLimitedbutReadable);
            model.AaaRepeatStudyUnreadable         = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RepeatStudy);

            model.AaaUnabletoScreen = testResult.UnableScreenReason != null && testResult.UnableScreenReason.Count > 0 ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            if ((testResult.ResultStatus != null && testResult.ResultStatus.SelfPresent) || (testResult.PhysicianInterpretation != null && testResult.PhysicianInterpretation.IsCritical))
            {
                model.AaaCritical = PhysicianPartnerResultExportHelper.YesString;
            }
            else
            {
                model.AaaCritical = PhysicianPartnerResultExportHelper.NoString;
            }

            if (testResult.PhysicianInterpretation != null)
            {
                model.AaaPhysicianNotes = testResult.PhysicianInterpretation.Remarks;
            }

            var aaaDiagnosisCodes = new System.Collections.Generic.List <OrderedPair <string, string> >();

            if (testResult.DiagnosisCode != null)
            {
                foreach (var diagnosisCode in PhysicianPartnerResultExportHelper.AaaDiagnosisCodes)
                {
                    if (testResult.DiagnosisCode.Reading.Contains(diagnosisCode))
                    {
                        aaaDiagnosisCodes.Add(new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.YesString));
                    }
                    else
                    {
                        aaaDiagnosisCodes.Add(new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.NoString));
                    }
                }
            }
            else
            {
                aaaDiagnosisCodes.AddRange(PhysicianPartnerResultExportHelper.AaaDiagnosisCodes.Select(diagnosisCode => new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.NoString)));
            }

            model.AaaDiagnosisCodes = aaaDiagnosisCodes;

            return(model);
        }
        public PhysicianPartnerResultExportModel SetEchoData(PhysicianPartnerResultExportModel model, PpEchocardiogramTestResult testResult)
        {
            if (testResult.Finding != null)
            {
                model.EchoResult = testResult.Finding.Label;
            }

            if (testResult.EstimatedEjactionFraction != null)
            {
                model.EchoEstimatedEjectionFraction = testResult.EstimatedEjactionFraction.Label;
            }

            model.EchoValveAortic = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Aortic);

            if (testResult.AorticRegurgitation != null)
            {
                model.EchoValveAorticRegurgitation = testResult.AorticRegurgitation.Label;
            }

            if (testResult.AorticMorphology != null && testResult.AorticMorphology.Count > 0)
            {
                model.EchoValveAorticMorphologySclerosis = testResult.AorticMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.Sclerosis).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

                model.EchoValveAorticMorphologyStenosis = testResult.AorticMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.Stenosis).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

                model.EchoValveAorticMorphologyBicuspidAv = testResult.AorticMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.BicuspidAv).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
            }
            else
            {
                model.EchoValveAorticMorphologySclerosis  = PhysicianPartnerResultExportHelper.NoString;
                model.EchoValveAorticMorphologyStenosis   = PhysicianPartnerResultExportHelper.NoString;
                model.EchoValveAorticMorphologyBicuspidAv = PhysicianPartnerResultExportHelper.NoString;
            }
            if (testResult.AoticVelocity != null)
            {
                model.EchoValveAorticMorphologyVelocity = testResult.AoticVelocity.Reading;
            }

            model.EchoValveMitral = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Mitral);

            if (testResult.MitralRegurgitation != null)
            {
                model.EchoValveMitralRegurgitation = testResult.MitralRegurgitation.Label;
            }

            if (testResult.MitralMorphology != null && testResult.MitralMorphology.Count > 0)
            {
                model.EchoValveMitralMorphologySclerosis = testResult.MitralMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.Sclerosis).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

                model.EchoValveMitralMorphologyStenosis = testResult.MitralMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.Stenosis).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

                model.EchoValveMitralMorphologyMitralProlapse = testResult.MitralMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.MitralProlapse).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
            }
            else
            {
                model.EchoValveMitralMorphologySclerosis      = PhysicianPartnerResultExportHelper.NoString;
                model.EchoValveMitralMorphologyStenosis       = PhysicianPartnerResultExportHelper.NoString;
                model.EchoValveMitralMorphologyMitralProlapse = PhysicianPartnerResultExportHelper.NoString;
            }

            if (testResult.MitralPT != null)
            {
                model.EchoValveMitralMorphologyP12T = testResult.MitralPT.Reading;
            }


            model.EchoValvePulmonic = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Pulmonic);

            if (testResult.PulmonicRegurgitation != null)
            {
                model.EchoValvePulmonicRegurgitation = testResult.PulmonicRegurgitation.Label;
            }

            if (testResult.PulmonicMorphology != null && testResult.PulmonicMorphology.Count > 0)
            {
                model.EchoValvePulmonicMorphologySclerosis = testResult.PulmonicMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.Sclerosis).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

                model.EchoValvePulmonicMorphologyStenosis = testResult.PulmonicMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.Stenosis).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
            }
            else
            {
                model.EchoValvePulmonicMorphologySclerosis = PhysicianPartnerResultExportHelper.NoString;
                model.EchoValvePulmonicMorphologyStenosis  = PhysicianPartnerResultExportHelper.NoString;
            }

            if (testResult.PulmonicVelocity != null)
            {
                model.EchoValvePulmonicMorphologyVelocity = testResult.PulmonicVelocity.Reading;
            }

            model.EchoValveTricuspid = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Tricuspid);

            if (testResult.TricuspidRegurgitation != null)
            {
                model.EchoValveTricuspidRegurgitation = testResult.TricuspidRegurgitation.Label;
            }

            if (testResult.TricuspidMorphology != null && testResult.TricuspidMorphology.Count > 0)
            {
                model.EchoValveTricuspidMorphologySclerosis = testResult.TricuspidMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.Sclerosis).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

                model.EchoValveTricuspidMorphologyStenosis = testResult.TricuspidMorphology.Where(am => am.Id == PhysicianPartnerResultExportHelper.Stenosis).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
            }
            else
            {
                model.EchoValveTricuspidMorphologySclerosis = PhysicianPartnerResultExportHelper.NoString;
                model.EchoValveTricuspidMorphologyStenosis  = PhysicianPartnerResultExportHelper.NoString;
            }

            if (testResult.TricuspidPap != null)
            {
                model.EchoValveTricuspidMorphologyPap = testResult.TricuspidPap.Reading;
            }

            if (testResult.TricuspidVelocity != null)
            {
                model.EchoValveTricuspidMorphologyVelocity = testResult.TricuspidVelocity.Reading;
            }

            model.EchoValveTricuspidMorphologyHigh35MmHgGreater = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.MorphologyTricuspidHighOrGreater);
            model.EchoValveTricuspidMorphologyNormal            = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.MorphologyTricuspidNormal);

            model.EchoDiastolicDysfunction = testResult.DiastolicDysfunction != null ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            if (testResult.DistolicDysfunctionFinding != null)
            {
                model.EchoDiastolicDysfunctionGrade = testResult.DistolicDysfunctionFinding.Label;
            }


            model.EchoPericardialEffusion = testResult.PericardialEffusion != null ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            if (testResult.PericardialEffusionFinding != null && testResult.PericardialEffusionFinding.Count > 0)
            {
                model.EchoPericardialEffusionPhysiologic = testResult.PericardialEffusionFinding.Where(am => am.Id == PhysicianPartnerResultExportHelper.Trival).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
                model.EchoPericardialEffusionSmall       = testResult.PericardialEffusionFinding.Where(am => am.Id == PhysicianPartnerResultExportHelper.Small).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
                model.EchoPericardialEffusionModerate    = testResult.PericardialEffusionFinding.Where(am => am.Id == PhysicianPartnerResultExportHelper.Moderate).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
                model.EchoPericardialEffusionLarge       = testResult.PericardialEffusionFinding.Where(am => am.Id == PhysicianPartnerResultExportHelper.Large).Select(am => am).Any() ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
            }
            else
            {
                model.EchoPericardialEffusionPhysiologic = PhysicianPartnerResultExportHelper.NoString;
                model.EchoPericardialEffusionSmall       = PhysicianPartnerResultExportHelper.NoString;
                model.EchoPericardialEffusionModerate    = PhysicianPartnerResultExportHelper.NoString;
                model.EchoPericardialEffusionLarge       = PhysicianPartnerResultExportHelper.NoString;
            }

            model.EchoVentricularEnlargement                = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.VentricularEnlargement);
            model.EchoVentricularEnlargementLeft            = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.LeftVentricularEnlargment);
            model.EchoVentricularEnlargementLeftMeasurement = testResult.LeftAtrialEnlargmentValue != null ? testResult.LeftAtrialEnlargmentValue.Reading : "";
            model.EchoVentricularEnlargementRight           = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RightVentricularEnlargment);
            model.EchoVentricularEnlargementRightMeasurment = testResult.RightVentricularEnlargmentValue != null ? testResult.RightVentricularEnlargmentValue.Reading : "";

            model.EchoAorticRoot                   = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.AorticRoot);
            model.EchoAorticRootSclerotic          = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Sclerotic);
            model.EchoAorticRootCalcified          = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Calcified);
            model.EchoAorticRootEnlarged           = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Enlarged);
            model.EchoAorticRootEnlargedMeasurment = testResult.EnlargedValue != null ? testResult.EnlargedValue.Reading : "";

            model.EchoVentricularHypertrophy                = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.VentricularHypertrophy);
            model.EchoVentricularHypertrophyLeft            = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.LeftVHypertrophy);
            model.EchoVentricularHypertrophyLeftMeasurment  = testResult.LeftVHypertrophyValue != null ? testResult.LeftVHypertrophyValue.Reading : "";
            model.EchoVentricularHypertorophyRight          = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RightVHypertrophy);
            model.EchoVentricularHypertrophyRightMeasurment = testResult.RightVHypertrophyValue != null ? testResult.RightVHypertrophyValue.Reading : "";
            model.EchoVentricularHypertrophyIVSH            = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.IvshHypertrophy);
            model.EchoVentricularHypertrophyIVSHMeasurment  = testResult.IvshHypertrophyValue != null ? testResult.IvshHypertrophyValue.Reading : "";

            model.EchoAtrialEnlargement                 = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.AtrialEnlargement);
            model.EchoAtrialEnlargementLeft             = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.LeftAtrialEnlargment);
            model.EchoAtrialEnlargementLeftMeasurement  = testResult.LeftAtrialEnlargmentValue != null ? testResult.LeftAtrialEnlargmentValue.Reading : "";
            model.EchoAtrialEnlargementRight            = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RightAtrialEnlargment);
            model.EchoAtrialEnlargementRightMeasurement = testResult.RightAtrialEnlargmentValue != null ? testResult.RightAtrialEnlargmentValue.Reading : "";

            model.EchoArrythmia = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Arrythmia);

            model.EchoArrythmiaAFib     = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.AFib);
            model.EchoArrythmiaAFlutter = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.AFlutter);
            model.EchoArrythmiaPAC      = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.PAC);
            model.EchoArrythmiaPVC      = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.PVC);

            model.EchoArrythmiaASD     = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.ASD);
            model.EchoArrythmiaPFO     = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.PFO);
            model.EchoArrythmiaFlailAS = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.FlailAS);

            model.EchoWallMotionAnormalityHypokinetic = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Hypokinetic);
            model.EchoWallMotionAnormalityAkinetic    = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Akinetic);
            model.EchoWallMotionAnormalityDyskinetic  = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Dyskinetic);
            model.EchoWallMotionAnormalityAnerior     = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Anterior);
            model.EchoWallMotionAnormalityPosterior   = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Posterior);
            model.EchoWallMotionAnormalityApical      = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Apical);
            model.EchoWallMotionAnormalitySeptal      = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Septal);
            model.EchoWallMotionAnormalityLateral     = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Lateral);
            model.EchoWallMotionAnormalityInferior    = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Inferior);


            model.EchoVSD            = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.VSD);
            model.EchoSAM            = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SAM);
            model.EchoLVOTO          = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.LVOTO);
            model.EchoManualAnnularC = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.MitralAnnularCa);

            model.EchoRestrictedLeafletMotion          = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RestrictedLeafletMotion);
            model.EchoRestrictedLeafletMotionAortic    = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RestrictedLeafletMotionAortic);
            model.EchoRestrictedLeafletMotionMitral    = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RestrictedLeafletMotionMitral);
            model.EchoRestrictedLeafletMotionPulmonic  = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RestrictedLeafletMotionPulmonic);
            model.EchoRestrictedLeafletMotionTricuspid = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RestrictedLeafletMotionTricuspid);

            model.EchoTechnicallyLimitedButReadable = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.TechnicallyLimitedbutReadable);
            model.EchoRepeatStudyUnreadable         = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RepeatStudyUnreadable);

            model.EchoUnableToScreen = testResult.UnableScreenReason != null && testResult.UnableScreenReason.Count > 0 ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            if ((testResult.ResultStatus != null && testResult.ResultStatus.SelfPresent) || (testResult.PhysicianInterpretation != null && testResult.PhysicianInterpretation.IsCritical))
            {
                model.EchoCritical = PhysicianPartnerResultExportHelper.YesString;
            }
            else
            {
                model.EchoCritical = PhysicianPartnerResultExportHelper.NoString;
            }

            if (testResult.PhysicianInterpretation != null)
            {
                model.EchoPhysicianNotes = testResult.PhysicianInterpretation.Remarks;
            }

            var echoDiagnosisCodes = new System.Collections.Generic.List <OrderedPair <string, string> >();

            if (testResult.DiagnosisCode != null)
            {
                foreach (var diagnosisCode in PhysicianPartnerResultExportHelper.EchoDiagnosisCodes)
                {
                    if (testResult.DiagnosisCode.Reading.Contains(diagnosisCode))
                    {
                        echoDiagnosisCodes.Add(new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.YesString));
                    }
                    else
                    {
                        echoDiagnosisCodes.Add(new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.NoString));
                    }
                }
            }
            else
            {
                echoDiagnosisCodes.AddRange(PhysicianPartnerResultExportHelper.EchoDiagnosisCodes.Select(diagnosisCode => new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.NoString)));
            }

            model.EchoDiagnosisCodes = echoDiagnosisCodes;

            return(model);
        }
        public PhysicianPartnerResultExportModel SetLeadData(PhysicianPartnerResultExportModel model, LeadTestResult testResult)
        {
            if (testResult.RightResultReadings != null)
            {
                if (testResult.RightResultReadings.Finding != null)
                {
                    model.LeadRightResult = testResult.RightResultReadings.Finding.Label;
                }

                if (testResult.RightResultReadings.CFAPSV != null && testResult.RightResultReadings.CFAPSV.Reading != null && testResult.RightResultReadings.CFAPSV.Reading.HasValue)
                {
                    model.LeadRightCfaMeasurement = testResult.RightResultReadings.CFAPSV.Reading.Value.ToString("00.00");
                }

                if (testResult.RightResultReadings.PSFAPSV != null && testResult.RightResultReadings.PSFAPSV.Reading != null && testResult.RightResultReadings.PSFAPSV.Reading.HasValue)
                {
                    model.LeadRightPsfaMeasurement = testResult.RightResultReadings.PSFAPSV.Reading.Value.ToString("00.00");
                }
            }

            if (testResult.LeftResultReadings != null)
            {
                if (testResult.LeftResultReadings.Finding != null)
                {
                    model.LeadLeftResult = testResult.LeftResultReadings.Finding.Label;
                }

                if (testResult.LeftResultReadings.CFAPSV != null && testResult.LeftResultReadings.CFAPSV.Reading != null && testResult.LeftResultReadings.CFAPSV.Reading.HasValue)
                {
                    model.LeadLeftCfaMeasurement = testResult.LeftResultReadings.CFAPSV.Reading.Value.ToString("00.00");
                }

                if (testResult.LeftResultReadings.PSFAPSV != null && testResult.LeftResultReadings.PSFAPSV.Reading != null && testResult.LeftResultReadings.PSFAPSV.Reading.HasValue)
                {
                    model.LeadLeftPsfaMeasurement = testResult.LeftResultReadings.PSFAPSV.Reading.Value.ToString("00.00");
                }
            }

            model.LeadUnuauallyLowVelocityRight = testResult.LowVelocityRight != null ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
            model.LeadUnuauallyLowVelocityLeft  = testResult.LowVelocityLeft != null ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;



            model.LeadTechnicallyLimitedButReadable = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.TechnicallyLimitedbutReadable);
            model.LeadRepeatStudyUnreadable         = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RepeatStudy);

            model.LeadUnabletoScreen = testResult.UnableScreenReason != null && testResult.UnableScreenReason.Count > 0 ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;

            if ((testResult.ResultStatus != null && testResult.ResultStatus.SelfPresent) || (testResult.PhysicianInterpretation != null && testResult.PhysicianInterpretation.IsCritical))
            {
                model.LeadCritical = PhysicianPartnerResultExportHelper.YesString;
            }
            else
            {
                model.LeadCritical = PhysicianPartnerResultExportHelper.NoString;
            }

            if (testResult.PhysicianInterpretation != null)
            {
                model.LeadPhysicianNotes = testResult.PhysicianInterpretation.Remarks;
            }

            var leadDiagnosisCodes = new System.Collections.Generic.List <OrderedPair <string, string> >();

            if (testResult.DiagnosisCode != null)
            {
                foreach (var diagnosisCode in PhysicianPartnerResultExportHelper.LeadDiagnosisCodes)
                {
                    if (testResult.DiagnosisCode.Reading.Contains(diagnosisCode))
                    {
                        leadDiagnosisCodes.Add(new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.YesString));
                    }
                    else
                    {
                        leadDiagnosisCodes.Add(new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.NoString));
                    }
                }
            }
            else
            {
                leadDiagnosisCodes.AddRange(PhysicianPartnerResultExportHelper.LeadDiagnosisCodes.Select(diagnosisCode => new OrderedPair <string, string>(diagnosisCode, PhysicianPartnerResultExportHelper.NoString)));
            }

            model.LeadDiagnosisCodes = leadDiagnosisCodes;

            return(model);
        }
        public void Create(IEnumerable <EventCustomerResultEntity> eventCustomerResultEntities, IEnumerable <OrderedPair <long, long> > orgRoleUserIdUserIdPairs, IEnumerable <UserEntity> userEntities,
                           IEnumerable <Address> addresses, IEnumerable <CustomerProfileEntity> customerProfileEntities, IEnumerable <EventsEntity> eventsEntities, IEnumerable <CustomerHealthInfoEntity> customerHealthInfoEntities,
                           IEnumerable <OrderedPair <long, long> > eventIdPodIdPairs, IEnumerable <PodDetailsEntity> podDetailsEntities, IEnumerable <OrderedPair <long, long> > eventIdHospitalPartnerIdPairs, IEnumerable <OrderedPair <long, string> > hospitalPartnerIdNamePairs,
                           IEnumerable <EventCustomerBasicBioMetricEntity> basicBioMetricEntities, IEnumerable <EventCustomersEntity> eventCustomersEntities, IEnumerable <EventAppointmentEntity> eventAppointmentEntities,
                           IEnumerable <HospitalPartnerCustomerEntity> hospitalPartnerCustomerEntities, IEnumerable <OrderedPair <long, string> > careCoordinatorIdNamePair, IEnumerable <CustomerPrimaryCarePhysicianEntity> primaryCarePhysicianEntities)
        {
            long totalRecords = eventCustomerResultEntities.Count();
            long counter      = 1;

            _logger.Info("Total Records : " + totalRecords);

            var fileName = _destinationDirectory + string.Format(@"\ResultExport_{0}.csv", DateTime.Now.Date.ToString("yyyyMMdd"));;

            WriteCsvHeader(fileName);

            foreach (var eventCustomerResultEntity in eventCustomerResultEntities)
            {
                try
                {
                    _logger.Info(string.Format("Creating Model for event {0} and customer {1}", eventCustomerResultEntity.EventId, eventCustomerResultEntity.CustomerId));

                    var userId = orgRoleUserIdUserIdPairs.Where(oru => oru.FirstValue == eventCustomerResultEntity.CustomerId).Select(oru => oru.SecondValue).Single();

                    var user = userEntities.Where(u => u.UserId == userId).Select(u => u).Single();

                    var address = addresses.Where(a => a.Id == user.HomeAddressId).Select(a => a).Single();

                    var customer = customerProfileEntities.Where(cp => cp.CustomerId == eventCustomerResultEntity.CustomerId).Select(cp => cp).Single();

                    var eventData = eventsEntities.Where(e => e.EventId == eventCustomerResultEntity.EventId).Select(e => e).Single();

                    var podIds = eventIdPodIdPairs.Where(ep => ep.FirstValue == eventData.EventId).Select(ep => ep.SecondValue).ToArray();

                    var podName = string.Join(",", podDetailsEntities.Where(pd => podIds.Contains(pd.PodId)).Select(pd => pd.Name).ToArray());

                    var hospitalPartnerId = eventIdHospitalPartnerIdPairs.Where(ehp => ehp.FirstValue == eventData.EventId).Select(ehp => ehp.SecondValue).SingleOrDefault();

                    var hopitalPartnerName = hospitalPartnerIdNamePairs.Where(hp => hp.FirstValue == hospitalPartnerId).Select(hp => hp.SecondValue).SingleOrDefault();

                    var eventCustomer = eventCustomersEntities.Where(ec => ec.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(ec => ec).Single();

                    var eventAppointment = eventAppointmentEntities.Where(ea => ea.AppointmentId == eventCustomer.AppointmentId).Select(ea => ea).Single();

                    var primaryCarePhysician = primaryCarePhysicianEntities.Where(pcp => pcp.CustomerId == eventCustomerResultEntity.CustomerId).Select(pcp => pcp).FirstOrDefault();

                    var basicBimetric = basicBioMetricEntities.Where(bb => bb.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(bb => bb).FirstOrDefault();

                    var hafAnswers = customerHealthInfoEntities.Where(chi => chi.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(chi => chi).ToArray();

                    var isNewResultFlow = eventData.EventDate >= _settings.ResultFlowChangeDate;

                    var answers = new List <OrderedPair <long, string> >();

                    foreach (var question in PhysicianPartnerResultExportHelper.Questions)
                    {
                        var hafAnswer = hafAnswers.Where(ha => ha.CustomerHealthQuestionId == question.FirstValue).Select(ha => ha).FirstOrDefault();

                        if (hafAnswer != null)
                        {
                            answers.Add(new OrderedPair <long, string>(question.FirstValue, hafAnswer.HealthQuestionAnswer));
                        }
                        else
                        {
                            if (question.FirstValue == 47)
                            {
                                answers.Add(new OrderedPair <long, string>(question.FirstValue, "NA"));
                            }
                            else
                            {
                                answers.Add(new OrderedPair <long, string>(question.FirstValue, "No"));
                            }
                        }
                    }

                    var age = string.Empty;
                    if (user.Dob.HasValue)
                    {
                        var now = DateTime.Now;
                        var checkCurrentLeapYear = new DateTime(now.Year, 3, 1);
                        var birth = user.Dob.Value;
                        var checkBirthLeapYear = new DateTime(birth.Year, 3, 1);

                        var currentDayOfYear = now.DayOfYear;
                        if (checkCurrentLeapYear.DayOfYear == 61 && now.Month >= checkCurrentLeapYear.Month && checkBirthLeapYear.DayOfYear != 61)
                        {
                            currentDayOfYear = now.DayOfYear - 1;
                        }
                        else if (checkCurrentLeapYear.DayOfYear != 61 && now.Month >= checkCurrentLeapYear.Month && checkBirthLeapYear.DayOfYear == 61)
                        {
                            currentDayOfYear = now.DayOfYear + 1;
                        }

                        var years  = now.Year - birth.Year - ((currentDayOfYear < birth.DayOfYear) ? 1 : 0);
                        var months = (12 + now.Month - birth.Month - ((now.Day < birth.Day) ? 1 : 0)) % 12;
                        var days   = now.Day - birth.Day;
                        if (days < 0)
                        {
                            days = new DateTime(now.Year, now.Month, 1).AddDays(-1).AddDays(days).Day;
                        }

                        age = years.ToString();
                    }
                    var ssn = "N/A";
                    if (!string.IsNullOrEmpty(user.Ssn))
                    {
                        ssn = _cryptographyService.Decrypt(user.Ssn);
                        if (ssn.Length >= 9)
                        {
                            ssn = ssn.Substring(0, 3) + "-" + ssn.Substring(3, 2) + "-" + ssn.Substring(ssn.Length - 4);
                        }
                    }

                    var model = new PhysicianPartnerResultExportModel
                    {
                        CustomerId            = customer.CustomerId,
                        FirstName             = user.FirstName,
                        LastName              = user.LastName,
                        Address1              = address.StreetAddressLine1,
                        City                  = address.City,
                        State                 = address.State,
                        Zip                   = address.ZipCode.Zip,
                        Dob                   = user.Dob,
                        Age                   = age,
                        Height                = customer.Height,
                        Weight                = customer.Weight > 0 ? customer.Weight.ToString() : "",
                        Gender                = customer.Gender,
                        Race                  = customer.Race != "-1" ? customer.Race : "",
                        Email                 = user.Email1,
                        Phone                 = user.PhoneHome,
                        Ssn                   = ssn,
                        MemberId              = string.IsNullOrEmpty(customer.InsuranceId) ? "" : customer.InsuranceId,
                        Hicn                  = string.IsNullOrEmpty(customer.Hicn) ? "" : customer.Hicn,
                        EventId               = eventData.EventId,
                        EventDate             = eventData.EventDate,
                        Pod                   = podName,
                        HospitalPartner       = hopitalPartnerName,
                        Hipaa                 = ((RegulatoryState)eventCustomer.Hipaastatus).GetDescription(),
                        CheckinTime           = eventAppointment.CheckinTime.HasValue ? eventAppointment.CheckinTime.Value.ToShortTimeString() : "",
                        CheckoutTime          = eventAppointment.CheckoutTime.HasValue ? eventAppointment.CheckoutTime.Value.ToShortTimeString() : "",
                        HealthAssesmentAnswer = answers,
                        ResultSummary         = eventCustomerResultEntity.ResultSummary.HasValue ? ((ResultInterpretation)eventCustomerResultEntity.ResultSummary).GetDescription() : ""
                    };
                    if (primaryCarePhysician != null)
                    {
                        model.PrimaryPhysicianName = new Name(primaryCarePhysician.FirstName, primaryCarePhysician.MiddleName, primaryCarePhysician.LastName).FullName;
                    }
                    if (hospitalPartnerId > 0)
                    {
                        model.PartnerRelease = eventCustomer.PartnerRelease > 0 ? ((RegulatoryState)eventCustomer.PartnerRelease).GetDescription() : "";
                        var hospitalPartnerCustomer = hospitalPartnerCustomerEntities.LastOrDefault(hpc => hpc.EventId == eventCustomerResultEntity.EventId && hpc.CustomerId == eventCustomerResultEntity.CustomerId);
                        model.CareCoordinatorStatus = hospitalPartnerCustomer != null
                                     ? ((HospitalPartnerCustomerStatus)hospitalPartnerCustomer.Status).GetDescription()
                                     : HospitalPartnerCustomerStatus.NotCalled.GetDescription();
                        model.CareCoordinatorOutcome = hospitalPartnerCustomer != null
                                                           ? ((HospitalPartnerCustomerOutcome)hospitalPartnerCustomer.Outcome).GetDescription()
                                                           : HospitalPartnerCustomerOutcome.NotScheduledNotInterested.GetDescription();
                        model.CareCoordinator = hospitalPartnerCustomer != null
                                                    ? careCoordinatorIdNamePair.First(cc => cc.FirstValue == hospitalPartnerCustomer.CareCoordinatorOrgRoleUserId).SecondValue
                                                    : "N/A";

                        model.CareCoordinatorNotes = hospitalPartnerCustomer != null
                                                         ? hospitalPartnerCustomer.Notes
                                                         : "";
                    }
                    else
                    {
                        model.PartnerRelease         = "N/A";
                        model.CareCoordinatorStatus  = "N/A";
                        model.CareCoordinatorOutcome = "N/A";
                        model.CareCoordinator        = "N/A";
                        model.CareCoordinatorNotes   = "N/A";
                    }

                    if (model.EventId > 0)
                    {
                        var theEvent = _eventRepository.GetById(model.EventId);
                        if (theEvent.AccountId.HasValue && theEvent.AccountId > 0)
                        {
                            var organization = _organizationRepository.GetOrganizationbyId(theEvent.AccountId.Value);
                            model.CorporateAccount = organization.Name;
                        }

                        if (theEvent.HostId > 0)
                        {
                            var host = _hostRepository.GetHostForEvent(theEvent.Id);
                            model.EventLocation = host.OrganizationName + " @ " + host.Address;
                        }
                    }

                    if (basicBimetric != null)
                    {
                        model.BloodPressure           = (basicBimetric.SystolicPressure.HasValue ? basicBimetric.SystolicPressure.Value.ToString() : "0") + "/" + (basicBimetric.DiastolicPressure.HasValue ? basicBimetric.DiastolicPressure.Value.ToString() : "0");
                        model.IsAbnormalBloodPressure = basicBimetric.IsBloodPressureElevated.HasValue && basicBimetric.IsBloodPressureElevated.Value ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
                    }
                    ITestResultRepository testResultRepository;

                    var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.PPEcho);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Echo data.");

                        testResultRepository = new PpEchocardiogramTestRepository();
                        var echoTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId, isNewResultFlow);
                        if (echoTestResult != null)
                        {
                            model = _echoFactory.SetEchoData(model, echoTestResult as PpEchocardiogramTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.PPAAA);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting AAA data.");

                        testResultRepository = new PpAaaTestRepository();
                        var aaaTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId, isNewResultFlow);
                        if (aaaTestResult != null)
                        {
                            model = _aaaFactory.SetAaaData(model, aaaTestResult as PpAaaTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.Lead);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Lead data.");

                        testResultRepository = new LeadTestRepository();
                        var leadTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId, isNewResultFlow);
                        if (leadTestResult != null)
                        {
                            model = _leadFactory.SetLeadData(model, leadTestResult as LeadTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.Spiro);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Spiro data.");

                        testResultRepository = new SpiroTestRepository();
                        var spiroTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId, isNewResultFlow);
                        if (spiroTestResult != null)
                        {
                            model = _spiroFactory.SetSpiroData(model, spiroTestResult as SpiroTestResult);
                        }
                    }

                    WriteCsv(model, fileName);
                    _logger.Info(counter + " completed out of " + totalRecords);

                    //if (counter > 10)
                    //    break;
                    counter++;
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("\n\nFor Event {0} and Customer {1} \n Error:{2}", eventCustomerResultEntity.EventId, eventCustomerResultEntity.CustomerId, ex.Message));
                }
            }
        }
        private void WriteCsv(PhysicianPartnerResultExportModel model, string fileName)
        {
            var fs           = new FileStream(fileName, FileMode.Append);
            var streamWriter = new StreamWriter(fs);

            try
            {
                var members = (typeof(PhysicianPartnerResultExportModel)).GetMembers();
                var values  = new List <string>();
                foreach (var memberInfo in members)
                {
                    if (memberInfo.MemberType != MemberTypes.Property)
                    {
                        continue;
                    }

                    var propInfo = (memberInfo as PropertyInfo);
                    if (propInfo != null)
                    {
                        if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <OrderedPair <long, string> >))
                        {
                            foreach (var question in PhysicianPartnerResultExportHelper.Questions)
                            {
                                if (model.HealthAssesmentAnswer != null && model.HealthAssesmentAnswer.Any())
                                {
                                    var answer = model.HealthAssesmentAnswer.Where(a => a.FirstValue == question.FirstValue).FirstOrDefault();

                                    values.Add(EscapeString(answer.SecondValue));
                                }
                                else
                                {
                                    values.Add(string.Empty);
                                }
                            }
                            continue;
                        }

                        if (propInfo.PropertyType == typeof(IEnumerable <OrderedPair <string, string> >))
                        {
                            if (memberInfo.Name == "EchoDiagnosisCodes")
                            {
                                if (model.EchoDiagnosisCodes != null)
                                {
                                    values.AddRange(model.EchoDiagnosisCodes.Select(code => EscapeString(code.SecondValue)));
                                }
                                else
                                {
                                    values.AddRange(PhysicianPartnerResultExportHelper.EchoDiagnosisCodes.Select(code => string.Empty));
                                }
                            }
                            else if (memberInfo.Name == "AaaDiagnosisCodes")
                            {
                                if (model.AaaDiagnosisCodes != null)
                                {
                                    values.AddRange(model.AaaDiagnosisCodes.Select(code => EscapeString(code.SecondValue)));
                                }
                                else
                                {
                                    values.AddRange(PhysicianPartnerResultExportHelper.AaaDiagnosisCodes.Select(code => string.Empty));
                                }
                            }
                            else if (memberInfo.Name == "LeadDiagnosisCodes")
                            {
                                if (model.LeadDiagnosisCodes != null)
                                {
                                    values.AddRange(model.LeadDiagnosisCodes.Select(code => EscapeString(code.SecondValue)));
                                }
                                else
                                {
                                    values.AddRange(PhysicianPartnerResultExportHelper.LeadDiagnosisCodes.Select(code => string.Empty));
                                }
                            }
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }


                    bool            isHidden  = false;
                    FormatAttribute formatter = null;

                    var attributes = propInfo.GetCustomAttributes(false);
                    if (!attributes.IsNullOrEmpty())
                    {
                        foreach (var attribute in attributes)
                        {
                            if (attribute is HiddenAttribute)
                            {
                                isHidden = true;
                                break;
                            }
                            if (attribute is FormatAttribute)
                            {
                                formatter = (FormatAttribute)attribute;
                            }
                        }
                    }

                    if (isHidden)
                    {
                        continue;
                    }
                    var obj = propInfo.GetValue(model, null);
                    if (obj == null)
                    {
                        values.Add(string.Empty);
                    }
                    else if (formatter != null)
                    {
                        values.Add(EscapeString(formatter.ToString(obj)));
                    }
                    else
                    {
                        values.Add(EscapeString(obj.ToString()));
                    }
                }

                streamWriter.Write(string.Join(PhysicianPartnerResultExportHelper.Delimiter, values.ToArray()) + Environment.NewLine);
            }
            catch (Exception ex)
            {
                _logger.Error("While creating CSV File : " + ex.Message + "\n\t" + ex.StackTrace + "\n\n");
            }
            finally
            {
                streamWriter.Close();
                streamWriter.Dispose();
                fs.Close();
                fs.Dispose();
            }
        }