Exemple #1
0
        private void SetProperties(int indicatorId, int siteId, t_observation observation, bool loadChildren)
        {
            IndicatorId = indicatorId;
            SiteId      = siteId;
            t_observation_entry firstEntry = observation?.entries?.FirstOrDefault();

            CreatedBy = firstEntry?.createdby?.full_name;
            CreatedOn = firstEntry?.created_date;
            UpdatedBy = firstEntry?.updateby?.full_name;
            UpdatedOn = firstEntry?.updated_date;

            // Observation entries.
            Entries = StoredProcedures.GetObservations(IndicatorId, SiteId, BeginDate);

            if (loadChildren)
            {
                // Aim and Indicator
                Indicator = new Indicator(IndicatorId, false);
                Aim       = new Aim(Indicator.AimId, false);

                // Other Aim Indicators
                // NOTE: Don't use UserAssignedObjects here. Only show active aims/indicators.
                var aims =
                    Context.t_indicator.Find(indicatorId).aim.activity.aims
                    .Where(e => e.active == true).OrderBy(e => e.sort);
                AimsAndIndicators = new List <Tuple <string, int, string> >();
                foreach (var aim in aims)
                {
                    AimsAndIndicators.Add(new Tuple <string, int, string>("Aim", aim.aim_id, aim.get_name_translated(CurrentLanguageId)));
                    foreach (var ind in aim.indicators.Where(e => e.active == true).OrderBy(e => e.sort))
                    {
                        AimsAndIndicators.Add(new Tuple <string, int, string>("Indicator", ind.indicator_id, ind.get_name_translated(CurrentLanguageId)));
                    }
                }

                // Populate date period selector's initial set of date periods.
                DatePeriods =
                    ObservationDatePeriod.GetDatePeriods(IndicatorId, siteId, BeginDate, null)
                    .ToDictionary(k => k.BeginDate.ToString("yyyy-MM-dd"), v => v);

                // One-time population of min/max tolerance dictionary.

                MinMaxTolerance = GetMinMaxTolerance();

                // Child collections.
                Changes     = observation?.changes?.OrderBy(e => e.start_date).Select(e => new ObservationChange(e)).ToList();
                Attachments = observation?.attachments?.Select(e => new ObservationAttachment(e)).Where(a => (a.Active == true) ||
                                                                                                        (a.CreatedByUserId == CurrentUserId) ||
                                                                                                        (CurrentUser.IsInRole(BusinessLayer.Identity.Role.SystemAdministrator))).ToList();
                Comments = observation?.comments?.OrderBy(e => e.created_date).Select(e => new ObservationComment(e)).ToList();
                History  = observation?.change_history?.OrderBy(e => e.change_history_id).Select(e => new ObservationHistory(e)).ToList();

                using (Entity context = new Entity())
                    Sexes = context.t_sex.OrderBy(e => e.sex_id).ToDictionary(e => e.sex_code, e => e.sex_description);
            }
        }
Exemple #2
0
        private void SetProperties(t_indicator entity, bool loadChildren, bool loadParent, bool translate)
        {
            ActivityId   = entity.aim?.activity_id ?? -1; // Refactor as nullable int when possible.
            AimId        = entity.aim_id;
            IndicatorId  = entity.indicator_id;
            TypeFieldId  = entity.indicator_type_fieldid;
            TypeValue    = entity.indicator_type?.value;
            GroupFieldId = entity.group_fieldid;
            GroupValue   = entity.indicator_group?.value;
            DataCollectionFrequencyFieldId = entity.data_collection_frequency_fieldid;
            DataCollectionFrequencyValue   = entity.data_collection_frequency?.value;
            SamplingFieldId    = entity.sampling_fieldid;
            ReportClassFieldId = entity.report_class_fieldid;
            ReportClassValue   = entity.report_class?.value;
            SamplingValue      = entity.sampling?.value;
            ChangeVariable     = entity.change_variable;
            DisaggregateBySex  = entity.disaggregate_by_sex;
            DisaggregateByAge  = entity.disaggregate_by_age;
            if (DisaggregateByAge)
            {
                AgeRanges =
                    entity.indicator_age_ranges
                    .OrderBy(e => e.indicator_age_range_id)
                    .ToDictionary(e => Convert.ToString(e.indicator_age_range_id), e => e.age_range);
            }
            else
            {
                AgeRanges = new Dictionary <string, string>();
            }
            TargetPerformance        = entity.target_performance;
            ThresholdGoodPerformance = entity.threshold_good_performance;
            ThresholdPoorPerformance = entity.threshold_poor_performance;
            IncreaseIsGood           = entity.increase_is_good;
            RatePerFieldId           = entity.rate_per_fieldid;
            RatePerValue             = entity.rate_per?.value;
            Active = entity.active;
            Sort   = entity.sort;

            if (translate)
            {
                Definition            = entity.get_definition_translated(CurrentLanguageId);
                Name                  = entity.get_name_translated(CurrentLanguageId);
                NumeratorName         = entity.get_numerator_name_translated(CurrentLanguageId);
                NumeratorDefinition   = entity.get_numerator_definition_translated(CurrentLanguageId);
                NumeratorSource       = entity.get_numerator_source_translated(CurrentLanguageId);
                DenominatorName       = entity.get_denominator_name_translated(CurrentLanguageId);
                DenominatorDefinition = entity.get_denominator_definition_translated(CurrentLanguageId);
                DenominatorSource     = entity.get_denominator_source_translated(CurrentLanguageId);
                //

                DataCollectionFrequencyValue = entity.get_data_frequency_translated(CurrentLanguageId, DataCollectionFrequencyValue);
            }
            else
            {
                Definition            = entity.definition;
                Name                  = entity.name;
                NumeratorName         = entity.numerator_name;
                NumeratorDefinition   = entity.numerator_definition;
                NumeratorSource       = entity.numerator_source;
                DenominatorName       = entity.denominator_name;
                DenominatorDefinition = entity.denominator_definition;
                DenominatorSource     = entity.denominator_source;
            }

            if (loadParent)
            {
                Aim = new Aim(AimId, false);
            }

            if (loadChildren)
            {
                ActivityAims =
                    UserAssignedObjects.GetAims(entity.aim.activity.aims, CurrentUser)
                    .Select(e => new Tuple <int?, string>(e.aim_id, e.get_name_translated(CurrentLanguageId)))
                    .ToList();
                Sites =
                    entity.aim.activity.sites
                    .Select(e => new ActivitySite(e))
                    .ToList();
                HasObservations = entity.observations?.Any() ?? false;
                OtherIndicators =
                    UserAssignedObjects.GetIndicators(entity.aim.indicators, CurrentUser)
                    .Where(e => e.indicator_id != IndicatorId)
                    .Select(e => new Indicator(e, false, true))
                    .ToList();
            }
        }