public override List <ValidationResult> ValidateObservationDataJson(
            TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType, string json)
        {
            var validationResults = new List <ValidationResult>();

            try
            {
                var schema = JsonConvert.DeserializeObject <DiscreteObservationSchema>(json);
                var treatmentBMPAssessmentObservationTypeName = treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeName;
                if (!(schema.SingleValueObservations.Count > 0))
                {
                    validationResults.Add(new ValidationResult($"You must enter at least one observation for '{treatmentBMPAssessmentObservationTypeName}'."));
                }

                if (schema.SingleValueObservations.Any(x => x.ObservationValue == null))
                {
                    validationResults.Add(new ValidationResult($"Values for the observation '{treatmentBMPAssessmentObservationTypeName}' cannot be blank."));
                }
            }
            catch (Exception)
            {
                validationResults.Add(new ValidationResult("Schema invalid"));
            }

            return(validationResults);
        }
        public bool IsObservationComplete(TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
        {
            var treatmentBMPObservation = TreatmentBMPObservations.FirstOrDefault(x =>
                                                                                  x.TreatmentBMPAssessmentObservationTypeID ==
                                                                                  treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID);

            return(treatmentBMPObservation != null);
        }
        public string CalculateObservationValueForObservationType(TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
        {
            if (treatmentBMPAssessmentObservationType.TreatmentBMPTypeAssessmentObservationTypes.All(x => x.TreatmentBMPTypeID != TreatmentBMPTypeID))
            {
                return(ViewUtilities.NaString);
            }

            return(TreatmentBMPObservations?.SingleOrDefault(y => y.TreatmentBMPAssessmentObservationTypeID == treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID)?.FormattedObservationValueWithoutUnits(treatmentBMPAssessmentObservationType) ?? ViewUtilities.NotProvidedString);
        }
Example #4
0
        public bool OverrideScoreForFailingObservation(TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
        {
            var score = CalculateObservationScore();

            if ((score ?? 0) < 0.01)
            {
                return(true);
            }
            return(Math.Abs(score.Value - 2) < 0.01);
        }
Example #5
0
        public string FormattedObservationValueWithoutUnits(TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
        {
            var observationTypeCollectionMethod = treatmentBMPAssessmentObservationType.ObservationTypeSpecification.ObservationTypeCollectionMethod;
            var observationValue = observationTypeCollectionMethod.GetObservationValueFromObservationData(ObservationData).GetValueOrDefault();

            if (observationTypeCollectionMethod == ObservationTypeCollectionMethod.PassFail)
            {
                return(Math.Abs(observationValue - 5) < 0.0001 ? "Pass" : "Fail");
            }

            return($"{observationValue.ToString(CultureInfo.InvariantCulture)}");
        }
        public TreatmentBMPAssessmentObservationTypeSimple(TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType,
                                                           TreatmentBMPAssessment treatmentBMPAssessment, bool overrideAssessmentScoreIfFailing)
        {
            TreatmentBMPAssessmentObservationTypeID = treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID;
            HasBenchmarkAndThresholds = treatmentBMPAssessmentObservationType.GetHasBenchmarkAndThreshold();

            var unitDisplayName = treatmentBMPAssessmentObservationType.GetMeasurementUnitType() != null ? $" ({treatmentBMPAssessmentObservationType.GetMeasurementUnitType().LegendDisplayName})" : string.Empty;

            DisplayName = $"{treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeName}{unitDisplayName}";

            var benchmarkValue        = treatmentBMPAssessmentObservationType.GetBenchmarkValue(treatmentBMPAssessment.TreatmentBMP);
            var thresholdValue        = treatmentBMPAssessmentObservationType.GetThresholdValue(treatmentBMPAssessment.TreatmentBMP);
            var assessmentScoreWeight = treatmentBMPAssessmentObservationType.TreatmentBMPTypeAssessmentObservationTypes.SingleOrDefault(x => x.TreatmentBMPTypeID == treatmentBMPAssessment.TreatmentBMP.TreatmentBMPType.TreatmentBMPTypeID)?.AssessmentScoreWeight;

            var treatmentBMPObservation = treatmentBMPAssessment.TreatmentBMPObservations.SingleOrDefault(y => y.TreatmentBMPAssessmentObservationTypeID == treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID);

            TreatmentBMPObservationSimple = treatmentBMPObservation != null ? new TreatmentBMPObservationSimple(treatmentBMPObservation, overrideAssessmentScoreIfFailing) : null;

            var useUpperValue = treatmentBMPAssessmentObservationType.UseUpperValueForThreshold(benchmarkValue, TreatmentBMPObservationSimple?.ObservationValue);

            ThresholdValueInObservedUnits = treatmentBMPAssessmentObservationType.GetThresholdValueInBenchmarkUnits(benchmarkValue, thresholdValue, useUpperValue) ?? 0;
            BenchmarkValue = benchmarkValue ?? 0;
            Weight         = assessmentScoreWeight?.ToStringShortPercent() ?? "pass/fail";
        }
Example #7
0
        public static TreatmentBMPTypeAssessmentObservationType GetTreatmentBMPTypeObservationType(this TreatmentBMPType treatmentBMPType, TreatmentBMPAssessmentObservationType TreatmentBMPAssessmentObservationType)
        {
            var TreatmentBMPTypeAssessmentObservationType = treatmentBMPType.GetTreatmentBMPTypeObservationTypeOrDefault(TreatmentBMPAssessmentObservationType);

            Check.Assert(TreatmentBMPTypeAssessmentObservationType != null,
                         $"The Observation Type '{TreatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeName}' is not applicable to the Treatment BMP Type '{treatmentBMPType.TreatmentBMPTypeName}'.");
            return(TreatmentBMPTypeAssessmentObservationType);
        }
 public abstract string ViewSchemaDetailUrl(TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType);
 public abstract List <ValidationResult> ValidateObservationDataJson(
     TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType, string json);
Example #10
0
 public abstract string GetBenchmarkAndThresholdUrl(TreatmentBMP treatmentBMP, TreatmentBMPAssessmentObservationType TreatmentBMPAssessmentObservationType);
 public static HtmlString GetDisplayNameAsUrl(this TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
 {
     return(treatmentBMPAssessmentObservationType != null?UrlTemplate.MakeHrefString(treatmentBMPAssessmentObservationType.GetDetailUrl(), treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeName) : new HtmlString(null));
 }
 /// <summary>
 /// Creates a "blank" object of this type and populates primitives with defaults
 /// </summary>
 public static TreatmentBMPObservation CreateNewBlank(TreatmentBMPAssessment treatmentBMPAssessment, TreatmentBMPTypeAssessmentObservationType treatmentBMPTypeAssessmentObservationType, TreatmentBMPType treatmentBMPType, TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
 {
     return(new TreatmentBMPObservation(treatmentBMPAssessment, treatmentBMPTypeAssessmentObservationType, treatmentBMPType, treatmentBMPAssessmentObservationType, default(string)));
 }
 /// <summary>
 /// Creates a "blank" object of this type and populates primitives with defaults
 /// </summary>
 public static TreatmentBMPBenchmarkAndThreshold CreateNewBlank(TreatmentBMP treatmentBMP, TreatmentBMPTypeAssessmentObservationType treatmentBMPTypeAssessmentObservationType, TreatmentBMPType treatmentBMPType, TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
 {
     return(new TreatmentBMPBenchmarkAndThreshold(treatmentBMP, treatmentBMPTypeAssessmentObservationType, treatmentBMPType, treatmentBMPAssessmentObservationType, default(double), default(double)));
 }
 public static string GetDetailUrl(this TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
 {
     return(treatmentBMPAssessmentObservationType == null ? "" : DetailUrlTemplate.ParameterReplace(treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID));
 }
 public override string ViewSchemaDetailUrl(TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
 {
     return(SitkaRoute <TreatmentBMPAssessmentObservationTypeController> .BuildUrlFromExpression(c => c.DiscreteDetailSchema(treatmentBMPAssessmentObservationType)));
 }
Example #16
0
 /// <summary>
 /// Creates a "blank" object of this type and populates primitives with defaults
 /// </summary>
 public static TreatmentBMPTypeAssessmentObservationType CreateNewBlank(TreatmentBMPType treatmentBMPType, TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
 {
     return(new TreatmentBMPTypeAssessmentObservationType(treatmentBMPType, treatmentBMPAssessmentObservationType, default(bool)));
 }
Example #17
0
 /// <summary>
 /// Constructor for building a new object with MinimalConstructor required fields, using objects whenever possible
 /// </summary>
 public TreatmentBMPTypeAssessmentObservationType(TreatmentBMPType treatmentBMPType, TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType, bool overrideAssessmentScoreIfFailing) : this()
 {
     // Mark this as a new object by setting primary key with special value
     this.TreatmentBMPTypeAssessmentObservationTypeID = ModelObjectHelpers.MakeNextUnsavedPrimaryKeyValue();
     this.TreatmentBMPTypeID = treatmentBMPType.TreatmentBMPTypeID;
     this.TreatmentBMPType   = treatmentBMPType;
     treatmentBMPType.TreatmentBMPTypeAssessmentObservationTypes.Add(this);
     this.TreatmentBMPAssessmentObservationTypeID = treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID;
     this.TreatmentBMPAssessmentObservationType   = treatmentBMPAssessmentObservationType;
     treatmentBMPAssessmentObservationType.TreatmentBMPTypeAssessmentObservationTypes.Add(this);
     this.OverrideAssessmentScoreIfFailing = overrideAssessmentScoreIfFailing;
 }
Example #18
0
        public static TreatmentBMPTypeAssessmentObservationType GetTreatmentBMPTypeObservationTypeOrDefault(this TreatmentBMPType treatmentBMPType, TreatmentBMPAssessmentObservationType TreatmentBMPAssessmentObservationType)
        {
            var TreatmentBMPTypeAssessmentObservationType = HttpRequestStorage.DatabaseEntities.TreatmentBMPTypeAssessmentObservationTypes.SingleOrDefault(
                x => x.TreatmentBMPTypeID == treatmentBMPType.TreatmentBMPTypeID && x.TreatmentBMPAssessmentObservationTypeID == TreatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID);

            return(TreatmentBMPTypeAssessmentObservationType);
        }
Example #19
0
 public bool IsBenchmarkAndThresholdCompleteForObservationType(TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
 {
     return(TreatmentBMPBenchmarkAndThresholds.SingleOrDefault(x =>
                                                               x.TreatmentBMPAssessmentObservationTypeID == treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID) != null);
 }
 /// <summary>
 /// Constructor for building a new object with MinimalConstructor required fields, using objects whenever possible
 /// </summary>
 public TreatmentBMPBenchmarkAndThreshold(TreatmentBMP treatmentBMP, TreatmentBMPTypeAssessmentObservationType treatmentBMPTypeAssessmentObservationType, TreatmentBMPType treatmentBMPType, TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType, double benchmarkValue, double thresholdValue) : this()
 {
     // Mark this as a new object by setting primary key with special value
     this.TreatmentBMPBenchmarkAndThresholdID = ModelObjectHelpers.MakeNextUnsavedPrimaryKeyValue();
     this.TreatmentBMPID = treatmentBMP.TreatmentBMPID;
     this.TreatmentBMP   = treatmentBMP;
     treatmentBMP.TreatmentBMPBenchmarkAndThresholds.Add(this);
     this.TreatmentBMPTypeAssessmentObservationTypeID = treatmentBMPTypeAssessmentObservationType.TreatmentBMPTypeAssessmentObservationTypeID;
     this.TreatmentBMPTypeAssessmentObservationType   = treatmentBMPTypeAssessmentObservationType;
     treatmentBMPTypeAssessmentObservationType.TreatmentBMPBenchmarkAndThresholds.Add(this);
     this.TreatmentBMPTypeID = treatmentBMPType.TreatmentBMPTypeID;
     this.TreatmentBMPType   = treatmentBMPType;
     treatmentBMPType.TreatmentBMPBenchmarkAndThresholds.Add(this);
     this.TreatmentBMPAssessmentObservationTypeID = treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID;
     this.TreatmentBMPAssessmentObservationType   = treatmentBMPAssessmentObservationType;
     treatmentBMPAssessmentObservationType.TreatmentBMPBenchmarkAndThresholds.Add(this);
     this.BenchmarkValue = benchmarkValue;
     this.ThresholdValue = thresholdValue;
 }
Example #21
0
 public override string GetBenchmarkAndThresholdUrl(TreatmentBMP treatmentBMP, TreatmentBMPAssessmentObservationType TreatmentBMPAssessmentObservationType)
 {
     return(SitkaRoute <TreatmentBMPBenchmarkAndThresholdController> .BuildUrlFromExpression(c => c.EditBenchmarkAndThreshold(treatmentBMP, TreatmentBMPAssessmentObservationType)));
 }
 /// <summary>
 /// Constructor for building a new object with MinimalConstructor required fields, using objects whenever possible
 /// </summary>
 public TreatmentBMPObservation(TreatmentBMPAssessment treatmentBMPAssessment, TreatmentBMPTypeAssessmentObservationType treatmentBMPTypeAssessmentObservationType, TreatmentBMPType treatmentBMPType, TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType, string observationData) : this()
 {
     // Mark this as a new object by setting primary key with special value
     this.TreatmentBMPObservationID = ModelObjectHelpers.MakeNextUnsavedPrimaryKeyValue();
     this.TreatmentBMPAssessmentID  = treatmentBMPAssessment.TreatmentBMPAssessmentID;
     this.TreatmentBMPAssessment    = treatmentBMPAssessment;
     treatmentBMPAssessment.TreatmentBMPObservations.Add(this);
     this.TreatmentBMPTypeAssessmentObservationTypeID = treatmentBMPTypeAssessmentObservationType.TreatmentBMPTypeAssessmentObservationTypeID;
     this.TreatmentBMPTypeAssessmentObservationType   = treatmentBMPTypeAssessmentObservationType;
     treatmentBMPTypeAssessmentObservationType.TreatmentBMPObservations.Add(this);
     this.TreatmentBMPTypeID = treatmentBMPType.TreatmentBMPTypeID;
     this.TreatmentBMPType   = treatmentBMPType;
     treatmentBMPType.TreatmentBMPObservations.Add(this);
     this.TreatmentBMPAssessmentObservationTypeID = treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID;
     this.TreatmentBMPAssessmentObservationType   = treatmentBMPAssessmentObservationType;
     treatmentBMPAssessmentObservationType.TreatmentBMPObservations.Add(this);
     this.ObservationData = observationData;
 }
Example #23
0
 public override string GetBenchmarkAndThresholdUrl(TreatmentBMP treatmentBMP, TreatmentBMPAssessmentObservationType TreatmentBMPAssessmentObservationType)
 {
     throw new NotImplementedException();
 }
 public static void DeleteTreatmentBMPAssessmentObservationType(this IQueryable <TreatmentBMPAssessmentObservationType> treatmentBMPAssessmentObservationTypes, TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationTypeToDelete)
 {
     DeleteTreatmentBMPAssessmentObservationType(treatmentBMPAssessmentObservationTypes, new List <TreatmentBMPAssessmentObservationType> {
         treatmentBMPAssessmentObservationTypeToDelete
     });
 }
 public static string GetEditUrl(this TreatmentBMPAssessmentObservationType treatmentBMPAssessmentObservationType)
 {
     return(EditUrlTemplate.ParameterReplace(treatmentBMPAssessmentObservationType.TreatmentBMPAssessmentObservationTypeID));
 }