// Update patient using the hoh info or not private bool InsertOrUpdatePatient(PatientRecord patient, bool useHOH, bool update) { SqlCommand command = new SqlCommand(); if (update) { if (useHOH) { command.CommandText = "UpdateNonHOHPatient"; } else { command.CommandText = "UpdateHOHPatient"; } } else { if (useHOH) { command.CommandText = "InsertNonHOHPatient"; } else { command.CommandText = "InsertHOHPatient"; } } command.Connection = connection; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@hcn", patient.HealthCardNumber)); command.Parameters.Add(new SqlParameter("@fname", patient.FirstName)); command.Parameters.Add(new SqlParameter("@lname", patient.LastName)); command.Parameters.Add(new SqlParameter("@initial", patient.MiddleInitial)); command.Parameters.Add(new SqlParameter("@dob", patient.DateOfBirth)); command.Parameters.Add(new SqlParameter("@sex", patient.Sex)); if (useHOH) { command.Parameters.Add(new SqlParameter("@hoh", patient.HeadOfHousehold)); } else { command.Parameters.Add(new SqlParameter("@phonearea", patient.AreaCode)); command.Parameters.Add(new SqlParameter("@phonenum", patient.PhoneNumber)); command.Parameters.Add(new SqlParameter("@addr1Street", patient.Address.StreetName)); command.Parameters.Add(new SqlParameter("@addr1HouseNum", patient.Address.HouseNumber)); command.Parameters.Add(new SqlParameter("@addr1Suffix", patient.Address.StreetSuffix)); command.Parameters.Add(new SqlParameter("@addrLine2", patient.Address.AddressLine2)); command.Parameters.Add(new SqlParameter("@city", patient.Address.City)); command.Parameters.Add(new SqlParameter("@province", patient.Address.Province)); } int result = ExecuteNonQueryProcedureWithReturn(command); bool retVal = false; if (result == 0) { retVal = true; } return(retVal); }
// Update patient info, NOT including a change to the health card number, must use the specific method for that public bool UpdateRecords(PatientRecord patient) { bool retVal = false; if (string.Equals(patient.HealthCardNumber, patient.HeadOfHousehold)) { // Want to update all fields retVal = InsertOrUpdatePatient(patient, false, true); } else { // Want to update fields except those related to HOH (address and phone number) retVal = InsertOrUpdatePatient(patient, true, true); } return(retVal); }
// Insert a new patient into the database, uses the patientrecord object public bool InsertNewRecord(PatientRecord patient) { bool retVal = false; // Check if the patient is the hoh if (string.Equals(patient.HealthCardNumber, patient.HeadOfHousehold)) { // Want to update all fields retVal = InsertOrUpdatePatient(patient, false, false); } else { // Want to insert fields using those related to HOH retVal = InsertOrUpdatePatient(patient, true, false); } return(retVal); }
static void Main(string[] args) { string testThis = "patient"; bool result; if (testThis == "patient") { PatientRecordsAccessor pr = new PatientRecordsAccessor(); pr.Connect("ems_admin", "qwerty"); PatientRecord rec1 = new PatientRecord(); rec1.HealthCardNumber = "6408383104"; rec1.HeadOfHousehold = rec1.HealthCardNumber; PatientRecord rec2 = new PatientRecord(); rec2.LastName = "Hernandez"; List <PatientRecord> list = pr.GetRecords(PatientRecordsAccessor.GETREQUEST.HEALTH_CARD_NUMBER, rec1.HealthCardNumber); if (list.Count > 0) { Console.WriteLine(list[0].FirstName); } else { Console.WriteLine("Failed."); } List <PatientRecord> list2 = pr.GetRecords(PatientRecordsAccessor.GETREQUEST.LASTNAME, rec2.LastName); if (list2 != null && list2.Count > 0) { Console.WriteLine(list2[0].FirstName); } else { Console.WriteLine("Failed."); } rec1.LastName = "NewLastName"; result = pr.UpdateRecords(rec1); if (result) { Console.WriteLine("Update hoh new last name ok."); } else { Console.WriteLine("Update hoh new last name FAILED."); } rec2.FirstName = "Mary"; rec2.HealthCardNumber = "1234567890"; rec2.HeadOfHousehold = "1868176460"; //result = pr.InsertNewRecord(rec2); //if (result) //{ // Console.WriteLine("Insert non-hoh info ok."); //} //else //{ // Console.WriteLine("Insert non-hoh info FAILED."); //} list = pr.GetRecords(PatientRecordsAccessor.GETREQUEST.HOH_REPORT, "1868176460"); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i].LastName); } } if (testThis == "appointment") { AppointmentRecordsAccessor ara = new AppointmentRecordsAccessor(); List <AppointmentRecord> lst = new List <AppointmentRecord>(); // Add a new appointment AppointmentRecord app = new AppointmentRecord(); app.PatientHCN = "8028261884"; app.AppointmentDate = new DateTime(2019, 4, 5); app.AppointmentTime = new TimeSpan(8, 0, 0); result = ara.InsertNewRecord(app); if (result) { Console.WriteLine("Added record."); } else { Console.WriteLine("Failed."); } // Cancel appointment result = ara.CancelAppointment(app.PatientHCN); if (result) { Console.WriteLine("Cancelled record."); } else { Console.WriteLine("Failed."); } // Cancel appointment result = ara.CancelAppointment(app.AppointmentDate, app.AppointmentTime); if (result) { Console.WriteLine("Cancelled record."); } else { Console.WriteLine("Failed."); } lst = ara.GetRecords(app.PatientHCN); if (lst.Count > 0) { Console.WriteLine(lst[0].PatientHCN); Console.WriteLine(lst[0].Status); } else { Console.WriteLine("Failed."); } } else if (testThis == "billing") { } Console.ReadKey(); }
// This takes private List <PatientRecord> GetPatientInfo(SqlCommand command) { List <PatientRecord> records = new List <PatientRecord>(); try { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { // Get ordinals for the columns required to fill the record, should i make these all constants int hcnPos = reader.GetOrdinal("Health_Number"); int fnPos = reader.GetOrdinal("First_Name"); int lnPos = reader.GetOrdinal("Last_Name"); int miPos = reader.GetOrdinal("M_Initial"); int dobPos = reader.GetOrdinal("Date_Birth"); int sxPos = reader.GetOrdinal("Sex_ID"); int hohPos = reader.GetOrdinal("Head_Of_Household"); int hnumPos = reader.GetOrdinal("House_Number"); int strNamePos = reader.GetOrdinal("Street_Name"); int suffPos = reader.GetOrdinal("Suffix"); int ad2Pos = reader.GetOrdinal("Address_Line_2"); int ciPos = reader.GetOrdinal("City_Name"); int proPos = reader.GetOrdinal("Province_Name"); int acPos = reader.GetOrdinal("Area_Code"); int pnPos = reader.GetOrdinal("Number"); if (reader.HasRows) { // Read each row, filling in the patient info while (reader.Read()) { PatientRecord rec = new PatientRecord(); rec.HealthCardNumber = GetSafeString(reader, hcnPos); rec.FirstName = GetSafeString(reader, fnPos); rec.LastName = GetSafeString(reader, lnPos); rec.MiddleInitial = GetSafeChar(reader, miPos); rec.DateOfBirth = GetSafeDateTime(reader, dobPos); rec.Sex = GetSafeChar(reader, sxPos); rec.HeadOfHousehold = GetSafeString(reader, hohPos); rec.Address.HouseNumber = GetSafeInt(reader, hnumPos); rec.Address.StreetName = GetSafeString(reader, strNamePos); rec.Address.StreetSuffix = GetSafeString(reader, suffPos); rec.Address.City = GetSafeString(reader, ciPos); rec.Address.Province = GetSafeString(reader, proPos); rec.AreaCode = GetSafeString(reader, acPos); rec.PhoneNumber = GetSafeString(reader, pnPos); // Add to list of records records.Add(rec); } } } // end using connection.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } finally { // this allows the exception to percolate... connection.Close(); } return(records); }