static void CreateTestData (SQLiteConnection db) { var js = new MeasurementSubjectModel () { Name = "JS"}; if (db.Table<MeasurementSubjectModel> ().Count (c => c.Name == "JS") == 0) { db.Insert (js); } else { js = db.Table<MeasurementSubjectModel> ().Where (w => w.Name == "JS").FirstOrDefault (); } var jsProfile = new ProfileModel () { MeasurementSubjectId = js.Id}; var jp = db.Query<ProfileModel> ("SELECT P.* FROM ProfileModel as P JOIN MeasurementSubjectModel AS s ON p.MeasurementSubjectId == s.Id WHERE s.Name == ?", "JS"); if(jp.Count == 0) { db.Insert (jsProfile); var v = new ProfileMeasurementDefinitionModel () { MeasurementFrequencyId = 3, MeasurementDefinitionId = 1, ProfileId = jsProfile.Id, MeasureTypeId = 2 }; db.Insert (v); db.Insert(new ProfileMeasurementDefinitionModel () { MeasurementFrequencyId = 4 , MeasurementDefinitionId = 2 , ProfileId = jsProfile.Id, MeasureTypeId = 7 }); db.Insert (new ProfileMeasurementDefinitionModel () { MeasurementFrequencyId = 3 , MeasurementDefinitionId = 3 , ProfileId = jsProfile.Id, MeasureTypeId = 2 }); } else { jsProfile = jp.FirstOrDefault (); db.GetChildren (jsProfile, true); } var stella = new MeasurementSubjectModel () { Name = "Stella" }; if (db.Table<MeasurementSubjectModel> ().Count (c => c.Name == "Stella") == 0) { db.Insert (stella); }else { stella = db.Table<MeasurementSubjectModel> ().Where (w => w.Name == "Stella").FirstOrDefault (); } var stellaProfile = new ProfileModel () { MeasurementSubjectId = stella.Id }; var sp = db.Query<ProfileModel> ("SELECT P.* FROM ProfileModel as P JOIN MeasurementSubjectModel AS s ON p.MeasurementSubjectId == s.Id WHERE s.Name == ?", "Stella"); if(sp.Count == 0) { db.Insert (stellaProfile); var v = new ProfileMeasurementDefinitionModel () { MeasurementFrequencyId = 3, MeasurementDefinitionId = 1, ProfileId = stellaProfile.Id, MeasureTypeId = 2 }; var c = db.Insert (v); db.Insert(new ProfileMeasurementDefinitionModel () { MeasurementFrequencyId = 4 , MeasurementDefinitionId = 2 , ProfileId = stellaProfile.Id, MeasureTypeId = 7 }); db.Insert (new ProfileMeasurementDefinitionModel () { MeasurementFrequencyId = 3 , MeasurementDefinitionId = 3 , ProfileId = stellaProfile.Id, MeasureTypeId = 2 }); } else { stellaProfile = sp.FirstOrDefault (); db.GetChildren (stellaProfile, true); } var isabelle = new MeasurementSubjectModel () { Name = "Isabelle" }; if (db.Table<MeasurementSubjectModel> ().Count (c => c.Name == "Isabelle") == 0) { db.Insert (isabelle); }else { isabelle = db.Table<MeasurementSubjectModel> ().Where (w => w.Name == "Isabelle").FirstOrDefault (); } var jsBloodPressure = new MeasurementInstanceModel () {DateRecorded = DateTime.Now, MeasurementSubjectId = js.Id, MeasurementDefinitionId = 1 }; var jsBloodPressure2 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-1), MeasurementSubjectId = js.Id, MeasurementDefinitionId = 1 }; var jsBloodPressure3 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-2), MeasurementSubjectId = js.Id, MeasurementDefinitionId = 1 }; if (db.Table<MeasurementInstanceModel> ().Count (w => w.MeasurementSubjectId == js.Id && w.MeasurementDefinitionId == 1) == 0) { db.Insert (jsBloodPressure); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBloodPressure.Id, MeasurementGroupDefinitionId = 1, UnitId = 1, Value = 120 }); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBloodPressure.Id, MeasurementGroupDefinitionId = 2, UnitId = 1, Value = 80 }); db.Insert (jsBloodPressure2); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBloodPressure2.Id, MeasurementGroupDefinitionId = 1, UnitId = 1, Value = 123 }); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBloodPressure2.Id, MeasurementGroupDefinitionId = 2, UnitId = 1, Value = 84 }); db.Insert (jsBloodPressure3); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBloodPressure3.Id, MeasurementGroupDefinitionId = 1, UnitId = 1, Value = 117 }); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBloodPressure3.Id, MeasurementGroupDefinitionId = 2, UnitId = 1, Value = 78 }); } var jsBpm = new MeasurementInstanceModel () {DateRecorded = DateTime.Now, MeasurementSubjectId = js.Id, MeasurementDefinitionId = 3 }; var jsBpm2 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-1), MeasurementSubjectId = js.Id, MeasurementDefinitionId = 3 }; var jsBpm3 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-2), MeasurementSubjectId = js.Id, MeasurementDefinitionId = 3 }; if (db.Table<MeasurementInstanceModel> ().Count (w => w.MeasurementSubjectId == js.Id && w.MeasurementDefinitionId == 3) == 0) { db.Insert (jsBpm); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBpm.Id, MeasurementGroupDefinitionId = 4, UnitId = 5, Value = 72 }); db.Insert (jsBpm2); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBpm2.Id, MeasurementGroupDefinitionId = 4, UnitId = 5, Value = 80 }); db.Insert (jsBpm3); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsBpm3.Id, MeasurementGroupDefinitionId = 4, UnitId = 5, Value = 69 }); } var jsW = new MeasurementInstanceModel () {DateRecorded = DateTime.Now, MeasurementSubjectId = js.Id, MeasurementDefinitionId = 2 }; var jsW2 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-1), MeasurementSubjectId = js.Id, MeasurementDefinitionId = 2 }; var jsW3 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-2), MeasurementSubjectId = js.Id, MeasurementDefinitionId = 2 }; if (db.Table<MeasurementInstanceModel> ().Count (w => w.MeasurementSubjectId == js.Id && w.MeasurementDefinitionId == 2) == 0) { db.Insert (jsW); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsW.Id, MeasurementGroupDefinitionId = 3, UnitId = 4, Value = 175 }); db.Insert (jsW2); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsW2.Id, MeasurementGroupDefinitionId = 3, UnitId = 4, Value = 177 }); db.Insert (jsW3); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = jsW3.Id, MeasurementGroupDefinitionId = 3, UnitId = 4, Value = 174 }); } var stellaBloodPressure = new MeasurementInstanceModel () {DateRecorded = DateTime.Now, MeasurementSubjectId = stella.Id, MeasurementDefinitionId = 1 }; var stellaBloodPressure2 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-1), MeasurementSubjectId = stella.Id, MeasurementDefinitionId = 1 }; var stellaBloodPressure3 = new MeasurementInstanceModel () {DateRecorded = DateTime.Now.AddDays(-2), MeasurementSubjectId = stella.Id, MeasurementDefinitionId = 1 }; if (db.Table<MeasurementInstanceModel> ().Count (w => w.MeasurementSubjectId == stella.Id && w.MeasurementDefinitionId == 1) == 0) { db.Insert (stellaBloodPressure); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = stellaBloodPressure.Id, MeasurementGroupDefinitionId = 1, UnitId = 1, Value = 120 }); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = stellaBloodPressure.Id, MeasurementGroupDefinitionId = 2, UnitId = 1, Value = 80 }); db.Insert (stellaBloodPressure2); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = stellaBloodPressure2.Id, MeasurementGroupDefinitionId = 1, UnitId = 1, Value = 123 }); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = stellaBloodPressure2.Id, MeasurementGroupDefinitionId = 2, UnitId = 1, Value = 84 }); db.Insert (stellaBloodPressure3); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = stellaBloodPressure3.Id, MeasurementGroupDefinitionId = 1, UnitId = 1, Value = 117 }); db.Insert (new MeasurementGroupInstanceModel () { MeasurementInstanceId = stellaBloodPressure3.Id, MeasurementGroupDefinitionId = 2, UnitId = 1, Value = 78 }); } }
private void InsertMeasurement() { var measurement = new MeasurementInstanceModel (); measurement.DateRecorded = DateTimeCaptured; measurement.Definition = new MeasurementDefinitionModel () { Id = MeasurementGroup.DefinitionId }; measurement.Subject = new MeasurementSubjectModel () {Id = MeasurementGroup.SubjectId}; measurement.MeasurementGroups = new List<MeasurementGroupInstanceModel>(); foreach(var measure in MeasurementGroup.MeasurementItems) { measurement.MeasurementGroups.Add (new MeasurementGroupInstanceModel () { MeasurementGroupDefinitionModel = new MeasurementGroupDefinitionModel () { Id = measure.DefinitionId }, Value = measure.Value, Unit = new MeasurementUnitModel () { Id = measure.UomId }, }); } _instanceRepository.Add(measurement); _instanceRepository.Session.Save (); Messenger.Default.Send<NotificationMessage> (new NotificationMessage("Loading:Dashboard"), "Loading:Dashboard"); }