/** * Allows the user to create an appointment. */ private void createAppointment() { string response = ""; int responseInt; string[] roomOptions = new string[practice.getRooms().Count]; //Creates an array to store the room options to be printed when requesting user input Patient patient; TreatmentRoom room; bool inMenu = true; Appointment aptmtToAdd; DateTime dateTime; try { for(int i = 0; i < practice.getRooms().Count; i ++) //determines available practices. { roomOptions[i] = $"{i + 1} - {practice.getRooms()[i].getDentist().getName()}/{practice.getRooms()[i].getNurse().getName()}"; //Adds an option to be displayed when requesting a room. formatt: <roomNo> - <dentist>/<Nurse> } while(inMenu) { Console.Clear(); DataPrinting.printPatients(practice); response = GeneralFunctions.getOptionalInput("Patient: ", false); if(response != "") { if (DataSearching.patientExists(practice, response)) //check patient exsist { patient = DataSearching.findPatient(practice, response); //Finds patient at a practice based on given ID. responseInt = GeneralFunctions.getRequiredSelection("Room: ", roomOptions) - 1; //Requests user for the appointment and takes response and subtracts one to conver to index. room = practice.getRooms()[responseInt]; dateTime = GeneralFunctions.getDateTimeInput(); aptmtToAdd = new Appointment(patient, room, dateTime); patient.getAppointments().Add(aptmtToAdd); DataIO.saveAppointment(aptmtToAdd); //save to files } else { Console.WriteLine("Patient not found."); } } else { inMenu = false; } } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Prompts the user for a patient to remove. */ private void removePatient() { string response = ""; Patient patientToRemove; bool validResponse = false; try { do { DataPrinting.printPatients(practice);//show patients based on practices response = GeneralFunctions.getOptionalInput("Patient to remove: ", false); //boolean to skip if (response != "") { if (DataSearching.patientExists(practice, response)) //check patient exists with given ID { File.Delete(DataIO.patientPath + "\\" + response + ".txt"); //Deletes the patient file. patientToRemove = DataSearching.findPatient(practice, response); //Finds the patient with the given ID practice.getPatients().Remove(patientToRemove);//Remove the patient from the practice. validResponse = true; } else { Console.WriteLine("Patient does not exist."); } } else { validResponse = true; } } while (!validResponse); } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Allows user to remove an appointment. */ private void removeAppointment() //Accesible by the class and does not return a value. { string response = "";//Use input Appointment apptToRemove; Patient apptOwner; bool inMenu = true; bool invalidResponse = true; string apptPath = ""; try { while (inMenu) { DataPrinting.printPatients(practice); response = GeneralFunctions.getOptionalInput("Select Patient: ", false); //breaks loop to appointments menu if(response != "") //not equal to blank { if(DataSearching.patientExists(practice, response))//Checks patient exsists based on given ID { apptOwner = DataSearching.findPatient(practice, response); //sets patient as apptOwner with given ID invalidResponse = true; //Runs next while loop while (invalidResponse) { DataPrinting.printAppointments(apptOwner); //Shows appointment of apptOwner response = GeneralFunctions.getOptionalInput("Appointment: ", false); //Request appointment to delete or option to cancel if (response != "") { if (DataSearching.appointmentExists(apptOwner, response)) //Checks if appointment exsists based on given ID { apptToRemove = DataSearching.findAppointment(apptOwner, response); //Gets the appointment with that ID apptPath = $"{DataIO.patientPath}\\{apptOwner.getId()}\\Appointments\\{apptToRemove.getId()}"; //Determines the path to the appointments directory apptOwner.getAppointments().Remove(apptToRemove); //Gets the list of appointments and removes the given appointment. Directory.Delete(apptPath, true); //path to appointments, true = allowing you to deletes all the folders content. invalidResponse = false; } else { Console.WriteLine("Invalid appointment id."); } } else { invalidResponse = false; } } } else { Console.WriteLine("Patient does not exist."); } } else { inMenu = false; } } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }