public List <Disease> GetDisease() { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT diseases.* FROM remedies JOIN diseases_remedies ON (remedies.id = diseases_remedies.remedies_id) JOIN diseases ON (diseases_remedies.diseases_id = diseases.id) WHERE remedies.id = @RemedyId;", conn); SqlParameter remedyIdParameter = new SqlParameter(); remedyIdParameter.ParameterName = "@RemedyId"; remedyIdParameter.Value = this.GetId(); cmd.Parameters.Add(remedyIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); List <Disease> diseases = new List <Disease> { }; while (rdr.Read()) { int id = rdr.GetInt32(0); string name = rdr.GetString(1); string symtoms = rdr.GetString(2); string image = rdr.GetString(3); int category_id = rdr.GetInt32(4); Disease newDisease = new Disease(name, symtoms, image, category_id, id); diseases.Add(newDisease); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(diseases); }
public static Disease Find(int id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM diseases WHERE id = @id;", conn); SqlParameter IdPara = new SqlParameter("@id", id.ToString()); cmd.Parameters.Add(IdPara); SqlDataReader rdr = cmd.ExecuteReader(); int foundid = 0; string name = null; string symtoms = null; string image = null; int category_id = 0; while (rdr.Read()) { foundid = rdr.GetInt32(0); name = rdr.GetString(1); symtoms = rdr.GetString(2); image = rdr.GetString(3); category_id = rdr.GetInt32(4); } Disease foundDisease = new Disease(name, symtoms, image, category_id, foundid); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(foundDisease); }
public void Test_GetDisease_RetrieveAllDiseaseWithinCategoryDisease() { //Arrange CategoryDisease testCategoryDisease = new CategoryDisease("flu"); testCategoryDisease.Save(); Disease firstDisease = new Disease("cold", "running nose", "image1", testCategoryDisease.GetId()); firstDisease.Save(); Disease secondDisease = new Disease("fever", "hot", "image2", testCategoryDisease.GetId()); secondDisease.Save(); //Act List <Disease> testDiseaseList = new List <Disease> { firstDisease, secondDisease }; List <Disease> resultDiseaseList = testCategoryDisease.GetDisease(); //Assert Assert.Equal(testDiseaseList, resultDiseaseList); }
public void Delete_DeletesDiseaseAssociationsFromDatabase_DiseaseList() { //Arrange Disease testDisease = new Disease("cold", "running nose", "image1", 1); testDisease.Save(); Remedy testRemedy = new Remedy("orange", "yellow sour fruit", "kinda sweet", "image2", 1); testRemedy.Save(); //Act testDisease.AddRemedy(testRemedy); testDisease.Delete(); List <Disease> resultRemedyDisease = Disease.GetAll(); List <Disease> testRemedyDisease = new List <Disease> { }; //Assert Assert.Equal(testRemedyDisease, resultRemedyDisease); }
public void Test_Delete_DeleteCategoryDiseaseFromDatabase() { //Arrange string name1 = "flu"; CategoryDisease testCategoryDisease1 = new CategoryDisease(name1); testCategoryDisease1.Save(); string name2 = "cancer"; CategoryDisease testCategoryDisease2 = new CategoryDisease(name2); testCategoryDisease2.Save(); Disease Disease1 = new Disease("cold", "running nose", "image1", testCategoryDisease1.GetId()); Disease1.Save(); Disease Disease2 = new Disease("fever", "hot", "image2", testCategoryDisease2.GetId()); Disease2.Save(); //Act testCategoryDisease1.Delete(); List <CategoryDisease> resultCategoryDisease = CategoryDisease.GetAll(); List <CategoryDisease> testCategoryDisease = new List <CategoryDisease> { testCategoryDisease2 }; List <Disease> resultDisease = Disease.GetAll(); List <Disease> DiseaseList = new List <Disease> { Disease2 }; //Assert Assert.Equal(testCategoryDisease, resultCategoryDisease); Assert.Equal(DiseaseList, resultDisease); }
public void Test_Update_UpdatesDiseaseInDatabase() { //Arrange Disease testDisease = new Disease("cold", "running nose", "image1", 1); testDisease.Save(); string newName = "fever"; string newSymtoms = "Very hot"; string newImage = "image2"; int newCategoryId = 2; //Act testDisease.Update("fever", "Very hot", "image2", 2); string result1 = testDisease.GetName(); string result2 = testDisease.GetSymtoms(); string result3 = testDisease.GetImage(); int result4 = testDisease.GetCategoryId(); //Assert Assert.Equal(newName, result1); Assert.Equal(newSymtoms, result2); Assert.Equal(newImage, result3); Assert.Equal(newCategoryId, result4); }
public void Test_ReturnsAllDiseases_DiseaseList() { Remedy testRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); testRemedy.Save(); Disease testDisease1 = new Disease("cold", "running nose", "image1", 1); testDisease1.Save(); Disease testDisease2 = new Disease("flu", "sick", "image1", 2); testDisease2.Save(); testRemedy.AddDisease(testDisease1); testRemedy.AddDisease(testDisease2); List <Disease> result = testRemedy.GetDisease(); List <Disease> testList = new List <Disease> { testDisease1, testDisease2 }; Assert.Equal(testList, result); }
public void Dispose() { CategoryDisease.DeleteAll(); Remedy.DeleteAll(); Disease.DeleteAll(); }
public Prescription(String patient, Doctor doctor, String disease) { this.doctor = doctor; this.patient = new Patient(patient); this.disease = new Disease(disease); }
public Prescription(Patient patient, String doctor, String disease) { this.doctor = new Doctor(doctor); this.patient = patient; this.disease = new Disease(disease); }
public HomeModule() { Get["/"] = _ => { return(View["index.cshtml"]); }; Get["/ailments"] = _ => { List <Disease> AllAilments = Disease.GetAll(); return(View["ailments.cshtml", AllAilments]); }; Get["/remedies"] = _ => { List <Remedy> AllRemedies = Remedy.GetAll(); return(View["remedies.cshtml", AllRemedies]); }; Get["/admin"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/remedy"] = _ => { string name = Request.Form["remedy-name"]; string description = Request.Form["remedy-description"]; string side_effect = Request.Form["remedy-side-effect"]; string image = Request.Form["remedy-image"]; int category_id = int.Parse(Request.Form["remedy-category-id"]); Remedy newRemedy = new Remedy(name, description, side_effect, image, category_id); Console.WriteLine(newRemedy.GetImage()); newRemedy.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/disease"] = _ => { string name = Request.Form["disease-name"]; string symptom = Request.Form["disease-symptom"]; string image = Request.Form["disease-image"]; int category_id = int.Parse(Request.Form["disease-category-id"]); Disease newDisease = new Disease(name, symptom, image, category_id); newDisease.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/remedy/category"] = _ => { string name = Request.Form["remedy-category-name"]; CategoryRemedy newCategoryRemedy = new CategoryRemedy(name); newCategoryRemedy.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/disease/category"] = _ => { string name = Request.Form["disease-category-name"]; CategoryDisease newCategoryDisease = new CategoryDisease(name); newCategoryDisease.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/addRemediesToDisease"] = _ => { string disease_id = Request.Form["disease_id"]; Disease foundDisease = Disease.Find(int.Parse(disease_id)); string remedies = Request.Form["treatment"]; string[] remedyArray = remedies.Split(','); foreach (string remedy_id in remedyArray) { Remedy foundRemedy = Remedy.Find(int.Parse(remedy_id)); foundDisease.AddRemedy(foundRemedy); } Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/diseaseCategory/delete/{id}"] = parameters => { CategoryDisease category = CategoryDisease.Find(parameters.id); return(View["category_disease_delete.cshtml", category]); }; Delete["/admin/diseaseCategory/delete/{id}"] = parameters => { CategoryDisease chosenCategoryDisease = CategoryDisease.Find(parameters.id); chosenCategoryDisease.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/remedyCategory/delete/{id}"] = parameters => { CategoryRemedy category = CategoryRemedy.Find(parameters.id); return(View["category_remedy_delete.cshtml", category]); }; Delete["/admin/remedyCategory/delete/{id}"] = parameters => { CategoryRemedy chosenCategoryRemedy = CategoryRemedy.Find(parameters.id); chosenCategoryRemedy.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/remedy/delete/{id}"] = parameters => { Remedy chosen = Remedy.Find(parameters.id); return(View["remedy_delete.cshtml", chosen]); }; Delete["/admin/remedy/delete/{id}"] = parameters => { Remedy chosenRemedy = Remedy.Find(parameters.id); chosenRemedy.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/disease/delete/{id}"] = parameters => { Disease chosen = Disease.Find(parameters.id); return(View["disease_delete.cshtml", chosen]); }; Delete["/admin/disease/delete/{id}"] = parameters => { Disease chosenDisease = Disease.Find(parameters.id); chosenDisease.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/diseaseCategory/edit/{id}"] = parameter => { CategoryDisease SelectedCategoryDisease = CategoryDisease.Find(parameter.id); return(View["edit_category_disease.cshtml", SelectedCategoryDisease]); }; Patch["/admin/diseaseCategory/edit/{id}"] = parameter => { CategoryDisease SelectedCategoryDisease = CategoryDisease.Find(parameter.id); SelectedCategoryDisease.Update(Request.Form["edit-name"]); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/remedyCategory/edit/{id}"] = parameter => { CategoryRemedy SelectedCategoryRemedy = CategoryRemedy.Find(parameter.id); return(View["edit_category_remedy.cshtml", SelectedCategoryRemedy]); }; Patch["/admin/remedyCategory/edit/{id}"] = parameter => { CategoryRemedy SelectedCategoryRemedy = CategoryRemedy.Find(parameter.id); SelectedCategoryRemedy.Update(Request.Form["edit-name"]); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/disease/edit/{id}"] = parameter => { Dictionary <string, object> model = new Dictionary <string, object>(); Disease SelectedDisease = Disease.Find(parameter.id); var AllCategoryDisease = CategoryDisease.GetAll(); model.Add("SelectedDisease", SelectedDisease); model.Add("AllCategoryDisease", AllCategoryDisease); return(View["edit_disease.cshtml", model]); }; Patch["/admin/disease/edit/{id}"] = parameter => { Disease SelectedDisease = Disease.Find(parameter.id); SelectedDisease.Update(Request.Form["edit-name"], Request.Form["edit-symptom"], Request.Form["edit-image"], Request.Form["edit-category-id"]); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/remedy/edit/{id}"] = parameter => { Dictionary <string, object> model = new Dictionary <string, object>(); Remedy SelectedRemedy = Remedy.Find(parameter.id); var AllCategoryRemedy = CategoryRemedy.GetAll(); model.Add("SelectedRemedy", SelectedRemedy); model.Add("AllCategoryRemedy", AllCategoryRemedy); return(View["edit_remedy.cshtml", model]); }; Patch["/admin/remedy/edit/{id}"] = parameter => { Remedy SelectedRemedy = Remedy.Find(parameter.id); SelectedRemedy.Update(Request.Form["edit-name"], Request.Form["edit-description"], Request.Form["edit-sideEffect"], Request.Form["edit-image"], Request.Form["edit-category-id"]); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/ailments"] = _ => { List <Disease> AllDiseases = Disease.GetAll(); return(View["ailments.cshtml", AllDiseases]); }; Get["/remedies"] = _ => { List <Remedy> AllRemedies = Remedy.GetAll(); return(View["remedies.cshtml", AllRemedies]); }; Get["/remedies/{id}"] = parameters => { Remedy foundRemedy = Remedy.Find(parameters.id); List <Disease> DiseaseList = foundRemedy.GetDisease(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("foundRemedy", foundRemedy); model.Add("DiseaseList", DiseaseList); return(View["remedy.cshtml", model]); }; Get["/ailments/{id}"] = parameters => { Disease foundDisease = Disease.Find(parameters.id); List <Remedy> RemedyList = foundDisease.GetRemedy(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("foundDisease", foundDisease); model.Add("remedyList", RemedyList); return(View["ailment.cshtml", model]); }; Get["/categoryRemedy"] = _ => { List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); return(View["categoryRemedy_all.cshtml", AllCategoryRemedy]); }; Get["/categoryRemedy/{id}"] = parameters => { CategoryRemedy foundCategoryRemedy = CategoryRemedy.Find(parameters.id); List <Remedy> RemedyList = foundCategoryRemedy.GetRemedy(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("foundCategoryRemedy", foundCategoryRemedy); model.Add("RemedyList", RemedyList); return(View["category_remedy.cshtml", model]); }; Get["/categoryDisease"] = _ => { List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); return(View["categoryDisease_all.cshtml", AllCategoryDisease]); }; Get["/categoryDisease/{id}"] = parameters => { CategoryDisease foundCategoryDisease = CategoryDisease.Find(parameters.id); List <Disease> DiseaseList = foundCategoryDisease.GetDisease(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("foundCategoryDisease", foundCategoryDisease); model.Add("DiseaseList", DiseaseList); return(View["category_disease.cshtml", model]); }; Get["/search"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); List <Remedy> remedies = new List <Remedy> { }; List <Disease> diseases = new List <Disease> { }; model.Add("remedies", remedies); model.Add("diseases", diseases); return(View["search.cshtml", model]); }; Post["/search"] = _ => { List <Remedy> remedies = new List <Remedy> { }; List <Disease> diseases = new List <Disease> { }; Dictionary <string, object> model = new Dictionary <string, object>(); string searchString = Request.Form["search-field"]; string category = Request.Form["category"]; if (category == "Remedy") { remedies = Remedy.SearchRemedy(searchString); } else if (category == "Disease") { diseases = Disease.SearchDisease(searchString); } model.Add("remedies", remedies); model.Add("diseases", diseases); return(View["search.cshtml", model]); }; }