private void LoadList(IList<MeasurementInstanceModel> measurements) { Items.Clear (); foreach (var entry in measurements) { var item = new MeasurementDashboardItemViewModel () { Subject = entry.Subject.Name, LastRecordedDate = entry.DateRecorded, MeasurementName = entry.Definition.Name, MeasurementDefinitionId = entry.MeasurementDefinitionId }; if(entry.MeasurementGroups != null && entry.MeasurementGroups.Any()) { item.MeasurementGroups = new ObservableCollection<MeasurementItemGroupViewModel> (); var g = new MeasurementItemGroupViewModel (); item.MeasurementGroups.Add (g); g.MeasurementItems = new ObservableCollection<MeasurementItemViewModel> (); foreach (var group in entry.MeasurementGroups) { g.DefinitionName = group.MeasurementGroupDefinitionModel.Name; g.MeasurementItems.Add (new MeasurementItemViewModel () { Name = group.MeasurementGroupDefinitionModel.Name, Uom = group.Unit.Abbreviation, Value = group.Value }); } } Items.Add (item); } }
private void LoadFromDefinition(int definitionId, int subjectId) { var definition = _definitionRepository.GetAllWithChildren (predicate: (w) => w.Id == definitionId, orderBy: (o) => o.Id, descending: false, skip: null, count: null).FirstOrDefault (); //get the subject var subjectName = _subjectRepository.GetAll (w => w.Id == subjectId).Select (s => s.Name).FirstOrDefault (); DateTimeCaptured = DateTime.Now; MeasurementGroup = new MeasurementItemGroupViewModel () { DefinitionId = definition.Id, DefinitionName = definition.Name, SubjectId = subjectId, SubjectName = subjectName, MeasurementType = "MeasurementEntry", MeasurementItems = new ObservableCollection<MeasurementItemViewModel> () }; foreach (var group in definition.MeasurementGroupDefinitions) { MeasurementGroup.MeasurementItems.Add (new MeasurementItemViewModel () { DefinitionId = group.Id, Name = group.Name, Uom = group.DefaultUnit.Abbreviation, UomId = group.DefaultUnitId, Value = 0 }); } }
public void Load(int id) { IList<MeasurementInstanceModel> measurements = new List<MeasurementInstanceModel> (); var profile = _profileRepository.GetAllWithChildren (p => p.MeasurementSubjectId == id, o => o.Id, null, null, null).FirstOrDefault(); if (profile != null) { using(var scope = App.AutoFacContainer.BeginLifetimeScope ()) { foreach (var def in profile.ProfileMeasurementDefinitions) { var query = scope.ResolveKeyed<IPredefinedQuery<MeasurementInstanceModel>> (def.MeasurementTypeModel.Name); var result = query.Query ((new List<object>() {id, def.MeasurementDefinitionId}).ToArray()); if (result != null) { measurements.Add (result); } else { measurements.Add (new MeasurementInstanceModel () {MeasurementDefinitionId = def.MeasurementDefinitionId, MeasurementSubjectId = id, Subject = Subjects.FirstOrDefault(f => f.Id == id), Definition = _definitionRepository.GetAll(p => p.Id == def.MeasurementDefinitionId).FirstOrDefault()}); } } } } Items.Clear (); foreach (var entry in measurements) { var item = new MeasurementDashboardItemViewModel () { Subject = entry.Subject.Name, MeasurementSubjectId = entry.MeasurementSubjectId, LastRecordedDate = entry.DateRecorded, MeasurementName = entry.Definition.Name, MeasurementDefinitionId = entry.MeasurementDefinitionId }; if (entry.MeasurementGroups != null && entry.MeasurementGroups.Any ()) { item.MeasurementGroups = new ObservableCollection<MeasurementItemGroupViewModel> (); var g = new MeasurementItemGroupViewModel (); item.MeasurementGroups.Add (g); g.MeasurementItems = new ObservableCollection<MeasurementItemViewModel> (); foreach (var group in entry.MeasurementGroups) { g.DefinitionName = group.MeasurementGroupDefinitionModel.Name; g.MeasurementItems.Add (new MeasurementItemViewModel () { Name = group.MeasurementGroupDefinitionModel.Name, Uom = group.Unit.Abbreviation, Value = group.Value }); } } Items.Add (item); } }
private void Load(Tuple<int, int> parameter) { Items.Clear (); var measurementTypes = new List<string> () { "Average", "Minimum observed", "Maximum observed", "Last Entry" }; IList<MeasurementInstanceModel> measurements = new List<MeasurementInstanceModel> (); using(var scope = App.AutoFacContainer.BeginLifetimeScope ()) { foreach (var type in measurementTypes) { var query = scope.ResolveKeyed<IPredefinedQuery<MeasurementInstanceModel>> (type); var result = query.Query ((new List<object>() {parameter.Item1, parameter.Item2}).ToArray()); if (result != null) { var str = result.Definition.Name; MeasurementName = str; result.Definition.Name = type; measurements.Add (result); } } } foreach (var entry in measurements) { var item = new MeasurementDashboardItemViewModel () { Subject = entry.Subject.Name, MeasurementSubjectId = entry.MeasurementSubjectId, LastRecordedDate = entry.DateRecorded, MeasurementName = entry.Definition.Name, MeasurementDefinitionId = entry.MeasurementDefinitionId }; if(entry.MeasurementGroups != null && entry.MeasurementGroups.Any()) { item.MeasurementGroups = new ObservableCollection<MeasurementItemGroupViewModel> (); var g = new MeasurementItemGroupViewModel (); item.MeasurementGroups.Add (g); g.MeasurementItems = new ObservableCollection<MeasurementItemViewModel> (); foreach (var group in entry.MeasurementGroups) { g.DefinitionName = group.MeasurementGroupDefinitionModel.Name; g.MeasurementItems.Add (new MeasurementItemViewModel () { Name = group.MeasurementGroupDefinitionModel.Name, Uom = group.Unit.Abbreviation, Value = group.Value }); } } Items.Add (item); } }