Exemple #1
0
        public static bool Decide(
            ref GuidelineCalculationRequestViewModel data,
            IEnumerable <GuidelineCalculationRequestViewModel> dataset,
            DependentDecision decision,
            AnalyteGuideline guideline)
        {
            if (decision == DependentDecision.ExistingValue)
            {
                return(true);
            }

            if (guideline.ValueType == Constants.EquationValueType)
            {
                foreach (var analyte in ExtractDependAnalyteNames(guideline.GuidelineValue))
                {
                    var result = FindDependValue(
                        ref data, dataset,
                        analyte,
                        dic[analyte]
                        );
                    if (!result)
                    {
                        return(false);
                    }
                }


                return(true);
            }

            return(true);
        }
        public IEnumerable <GuidelineCalculationResultViewModel> Calculate(
            IEnumerable <GuidelineCalculationRequestViewModel> dataset,
            IEnumerable <AnalyteGuideline> guidelines,
            DependentDecision dependentDecision)
        {
            var unitConverter = new UnitValueConverter();
            var data          = new List <GuidelineCalculationResultViewModel>();

            for (var i = 0; i < dataset.Count(); i++)
            {
                var currentPoint = dataset.ElementAt(i);
                var result       = currentPoint.ToResult();

                var matchedGuideline = guidelines.FirstOrDefault(x => x.AnalyteName == currentPoint.Analyte);
                if (matchedGuideline == null)
                {
                    data.Add(result);
                    continue;
                }

                var isDependentFound = DependentDecider.Decide(ref currentPoint, dataset, dependentDecision, matchedGuideline);
                if (!isDependentFound)
                {
                    data.Add(result);
                    continue;
                }

                var guidelineValue = this.CalculateGuidelineValue(currentPoint, matchedGuideline);
                if (!String.IsNullOrEmpty(guidelineValue.Guideline))
                {
                    result.GuidelineValueString = guidelineValue.GuidelineValueString;
                    var parsedOption   = (ComparisonOperation)Enum.Parse(typeof(ComparisonOperation), matchedGuideline.ComparisonOperation);
                    var valueToCompare = unitConverter.Convert(result.Value, result.Unit, matchedGuideline.Unit);
                    result.IsExceedance  = CalculateIfExcessGuideline(guidelineValue, valueToCompare, parsedOption);
                    result.GuidelineUnit = matchedGuideline.Unit;
                }
                data.Add(result);
            }


            return(data);
        }