/// <summary> /// /// </summary> /// <param name="drugIssuance">drug issuance id</param> /// <param name="medicationHistory">empty medicationHistory viewmodel</param> /// <returns>MedicationHistory view with data-Category,name,startDate and endDate</returns> private MedicationHistoryVm GetMedicationHistoryObject(int drugIssuance, MedicationHistoryVm medicationHistory) { StringBuilder stringJson = new StringBuilder(); //using (SqlConnection dbConnection = new SqlConnection("Data Source= WANJIKU\\NEWSQLEXPRESS; Initial Catalog =HPCareDBContext; Integrated Security=SSPI")) using (SqlConnection dbConnection = new SqlConnection("Data Source=SQL5025.myASP.NET;Initial Catalog=DB_A0ADFA_HPCareDBContext;User Id=DB_A0ADFA_HPCareDBContext_admin;Password=hpcare2016;")) { DbCommand dbCommand = dbConnection.CreateCommand(); dbCommand.CommandType = CommandType.Text; string query = " SELECT DrugCategories.description, Drugs.Drug_name, DrugIssuances.Medication_end_date,DrugIssuances.Medication_start_date, DrugIssuances.DrugIssuance_id FROM DrugIssuances ,Drugs,DrugCategories where DrugIssuances.IssuedDrug_Drug_id = Drug_id and Drugs.Category_category_id = DrugCategories.category_id and DrugIssuance_id =" + drugIssuance; dbCommand.CommandText = query; dbConnection.Open(); DbDataReader dbDataReader = dbCommand.ExecuteReader(); while (dbDataReader.Read()) { if (stringJson.Length != 0) { stringJson.Append(","); } medicationHistory.Drugcategory = dbDataReader.GetString(0); medicationHistory.DrugName = dbDataReader.GetString(1); medicationHistory.EndDate = dbDataReader.GetDateTime(2); medicationHistory.StartDate = dbDataReader.GetDateTime(3); medicationHistory.Issance_ID = drugIssuance; } dbDataReader.Close(); } return(medicationHistory); }
/// <summary> /// Accesses the get patient medication history. /// </summary> /// <param name="idPatient">The identifier patient.</param> private void AccessGetPatientMedicationHistory(int idPatient) { using (SqlConnection connection = new SqlConnection("Data Source=SQL5025.myASP.NET;Initial Catalog=DB_A0ADFA_HPCareDBContext;User Id=DB_A0ADFA_HPCareDBContext_admin;Password=hpcare2016;")) { SqlCommand command = new SqlCommand("SELECT Drug_Name, drugcategories.description, Medication_Start_date, Medication_end_date FROM Patient INNER " + " JOIN ClinicRegistryManagers ON Patient.User_id = ClinicRegistryManagers.Clinic_patient_User_id INNER JOIN Users ON Patient.User_id = Users.User_id INNER " + " JOIN Users AS Users_1 ON Patient.User_id = Users_1.User_id CROSS JOIN Drugs INNER JOIN DrugCategories ON Drugs.Category_category_id = " + " DrugCategories.category_id INNER JOIN DrugIssuances ON Drugs.Drug_id = DrugIssuances.IssuedDrug_Drug_id and users.user_id = " + idPatient + "; ", connection); command.CommandType = CommandType.Text; command.Connection = connection; connection.Open(); DbDataReader dbDataReader = command.ExecuteReader(); MedicationHistoryVm viewModel; while (dbDataReader.Read()) { viewModel = new MedicationHistoryVm { DrugName = dbDataReader.GetString(0), Drugcategory = dbDataReader.GetString(1), StartDate = dbDataReader.GetDateTime(2), EndDate = dbDataReader.GetDateTime(3) }; patientMedicationHistory.Add(viewModel); } } }
/// <summary> /// Returns an medications associated to the clinicRegistry/patient /// </summary> /// <returns>List of medications view model</returns> public List <MedicationHistoryVm> GetPatientMedicationHistory() { List <MedicationHistoryVm> medicationHistoryList = new List <MedicationHistoryVm>(); MedicationHistoryVm medHistory; List <DrugIssuance> drugIssuancesIDs = new List <DrugIssuance>(); foreach (ClinicRegistryManager registry in GetPatientClinicalRegisties()) { foreach (DrugManager manager in GetDrugManagers(registry.ClinicRegistryManagerId)) { foreach (DrugIssuance issuance in GetListIssuances(manager)) { medHistory = new MedicationHistoryVm(); GetMedicationHistoryObject(issuance.DrugIssuance_id, medHistory); medicationHistoryList.Add(medHistory); } } } return(medicationHistoryList); }