/** * gets a valid practice. */ private string getValidLocation() { bool validLocation = false; string location = ""; do { location = GeneralFunctions.getOptionalInput("Location: ", true, DataPrinting.printPractices); //requests a location from a user, while printing the list of practices out. if (location != "") //If location is not null { if (DataSearching.practiceExists(location)) //Check the pratice provided exsists. { validLocation = true; //Changes bool value, marks given location is valid. } else { Console.WriteLine("Invalid Location"); } } else { validLocation = true; } }while (!validLocation); //While valid location is false, run loop. return(location); }
public void setPractice(string location) { if (DataSearching.practiceExists(location)) { practice = DataSearching.findPractice(location); } }
/** * Removes a user from the system. */ private void removeUser() { List <User> users = Application.appInstance.users; string response = ""; bool inMenu = true; User userToRemove; try { while (inMenu) { response = GeneralFunctions.getOptionalInput("User: "******"") { if (DataSearching.userExists(response)) //Checks if user exists with given response. { userToRemove = DataSearching.findUser(response); //Find users matching with response DataIO.deleteUserFile(userToRemove); //Delete the user in the file users.Remove(userToRemove); //Remove the user from the list } } else { inMenu = false; } } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Shows the staff manager allowing admins to assign staff to locations. */ private void showStaffMgr() { string response; bool inMenu; try { inMenu = true; do { DataPrinting.printPractices(); //Find practices and show them Console.Write("Location to manage: (enter empty location to exit)"); response = Console.ReadLine(); Console.Clear(); if (response == "") { inMenu = false; } else if (DataSearching.practiceExists(response)) //Checks if practice exsists with given practice { managePractice(DataSearching.findPractice(response)); //finds practice based on given response } else { Console.WriteLine("Location does not exist."); } }while (inMenu); } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * 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); } }
/* * Promts the user for a username and password. if nothing is entered in the username, will exit the loop. */ private bool loginUser() { bool active = true; // feeds back to Application to determine if the system should keep requesting credentials or exit. bool invalidCredentials = true; string username; // holds the username following input. string password; // Holds the password following input. try { do { Console.Write("Username: "******""; //checks to see if username is not empty and stores the boolean result in the active variable. if (active) { Console.Write("Password: "******"Invalid credentials"); } } else { break; //Exits out of loop when active is false. } }while (invalidCredentials); } catch (Exception e) { GeneralFunctions.errorHandler(e); } return(active); }
/** * gets the Receptionist object from the receptionistId. */ public void associateReceptionist() //Void for the return type of variable/object { try { if (receptionistId != "") { receptionist = (Receptionist)DataSearching.findUser(receptionistId); //Because we are taking from a list of Users and wish to assign this to a Receptionist, it must be casted back. } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Removes a practice. */ private void removePractice() { List <DentalPractice> practices = Application.appInstance.dentalPractices; List <TreatmentRoom> associatedRooms; string response = ""; DentalPractice practiceToRemove; bool inMenu = true; try { do { Console.Write("Practice to remove (leave blank to cancel): "); response = Console.ReadLine(); Console.Clear(); inMenu = (response != ""); if (inMenu) { if (practices.Exists(practice => practice.getLocation() == response)) //Checks to see the given practice exists. { practiceToRemove = DataSearching.findPractice(response); //Finds practice based on response associatedRooms = practiceToRemove.getRooms(); for (int i = 0; i < associatedRooms.Count; i++) //Iterates over every room { deleteRoom(associatedRooms[i], false); //Deletes all rooms } practices.Remove(practiceToRemove); //Removes pratice from the list } else { Console.WriteLine("Practice not found."); } } }while (inMenu); } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Manages a practice */ private void managePractice(DentalPractice practice) { bool inMenu; string receptionist = ""; Receptionist recObj; try { inMenu = true; do { DataPrinting.printReceptionists(); //Prints out all receptionists Console.Write($"Receptionist for {practice.getLocation()}: "); //Request receptionist based on location. receptionist = Console.ReadLine(); Console.Clear(); if (receptionist == "") { inMenu = false; } else if (DataSearching.userExists(receptionist)) //Checks receptionist exsist { recObj = (Receptionist)DataSearching.findUser(receptionist); //Finds receptionist based on previous check. recObj.setPractice(practice); //Sets Practice to recpetionist practice.setReceptionist(recObj); // sets receptionist on the practice DataIO.saveUser(recObj); //saves file DataIO.savePracticeFile(practice); //saving file inMenu = false; } else { Console.WriteLine("User does not exist"); } }while (inMenu); } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Shows the room editor. */ private void showRoomEditor() { bool inMenu; string response = ""; DentalPractice practiceToAddRoom; try { inMenu = true; while (inMenu) { DataPrinting.printPractices(); Console.WriteLine("Practice to add room to: (Leave blank to cancel)"); response = Console.ReadLine(); Console.Clear(); if (response != "") { if (DataSearching.practiceExists(response)) //uses response to find the practices that are a valid response { practiceToAddRoom = DataSearching.findPractice(response); // takes response and gets pratice with the given response and location addRoomToPractice(practiceToAddRoom); //run method to add practice } else { Console.WriteLine("Practice does not exist."); } } 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); } }
/** * displays appointments and allows user to add notes. */ private void showAppointments() { List <Appointment> appointments = DataSearching.getPractitionerAppointments(this); //this refers to instance of object, Gets the list of appointments for the current logged in practioner. w string response = ""; bool inMenu = true; try { while (inMenu) { Console.Clear(); DataPrinting.printPractitionerAppointments(this); //Prints Appointments based on the current logged in Practioner. response = GeneralFunctions.getOptionalInput("Add note to appointment: ", false); if (response != "") { if (appointments.Exists(appointment => appointment.getId() == response)) //finds defined condition, acts as a search filter, has been explained in a different a usertype .cs { addNote(appointments.Find(appointment => appointment.getId() == response)); } else { Console.WriteLine("Appointment not found."); } } else { inMenu = false; } } } 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); } }
/** * Shows the room managing interface. */ private void showRoomMgr() { string response; int responseInt; bool inMenu; DentalPractice practice; List <TreatmentRoom> rooms; try { inMenu = true; bool invalidPractice; bool invalidRoom; while (inMenu) { invalidPractice = true; while (invalidPractice && inMenu) //Selecting a location and room. { DataPrinting.printPractices(); //Show practices Console.Write("Practice: (leave blank to cancel)"); response = Console.ReadLine(); Console.Clear(); if (response == "") { inMenu = false; //if blank, allows loop to break. } else if (DataSearching.practiceExists(response)) //Checks if it is a valid response { invalidPractice = false; invalidRoom = true; practice = DataSearching.findPractice(response); //Gets practice with given ID rooms = practice.getRooms(); //Gets list of rooms while (invalidRoom && inMenu) //Selecting a room { DataPrinting.printRoomsAtPractice(practice); //Prints rooms based on practice location Console.WriteLine("Room to manage: (leave blank to cancel)"); response = Console.ReadLine(); if (response == "") { invalidRoom = false; } if (int.TryParse(response, out responseInt)) { if (responseInt > 0 && responseInt <= rooms.Count) { manageRoom(rooms[responseInt - 1]); //Brings up interface for managing a room. indexing rooms list -1. } } } } else { Console.WriteLine("Location not found"); } } } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Provides an interface allowing admin to Remove a room. */ private void removeRoom() { string response; int responseInt; bool inMenu; bool invalidResponse; DentalPractice practiceToRemoveFrom; TreatmentRoom roomToRemove; try { inMenu = true; while (inMenu) { DataPrinting.printPractices(); Console.Write("Practice to remove room from: (leave blank to cancel)"); response = Console.ReadLine(); Console.Clear(); if (response != "") { if (DataSearching.practiceExists(response)) //Checks for valid user response { practiceToRemoveFrom = DataSearching.findPractice(response); //Gets practice with given ID invalidResponse = true; while (inMenu && invalidResponse) { DataPrinting.printRoomsAtPractice(practiceToRemoveFrom); //Shows all rooms in the given practice Console.Write("Select room to remove: (leave blank to cancel)"); response = Console.ReadLine(); Console.Clear(); if (response != "") { if (int.TryParse(response, out responseInt)) //Converts value to int as responseInt { if (responseInt > 0 && responseInt <= practiceToRemoveFrom.getRooms().Count) //Checking if response is greater than 0 or less than or equal the given amount of rooms. { roomToRemove = practiceToRemoveFrom.getRooms()[responseInt - 1]; deleteRoom(roomToRemove, true); //Removes the room } else { Console.WriteLine("Invalid room"); } } else { Console.WriteLine("Enter a number."); } } else { invalidResponse = false;//Breaks loop } } } else { Console.WriteLine("Practice not found."); } } else { inMenu = false; } } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Allocates dentists and nurses to the room. */ public void associateStaff() { dentist = (DentistNurse)DataSearching.findUser(dentistId); //Finds the user with the provided ID to set as rooms the dentist. nurse = (DentistNurse)DataSearching.findUser(nurseId); }
public Staff(string username, string password, string name, string location): base(username, password, name) //calls the constructor of the parent class, inheritance. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/base { practice = DataSearching.findPractice(location); }
/** * Adds a user to the system. */ private void addUser() { string username; string password; string name; int role; string location = ""; User userToAdd; List <User> users = Application.appInstance.users; DentalPractice practice; try { //Input to create user username = GeneralFunctions.getRequiredInput("Username: "******"Password: "******"Name: "); role = GeneralFunctions.getRequiredSelection("Role: ", new string[] { "Administrator", "Receptionist", "Dentist", "Nurse" }); //Passes a string to label the input and a string array of available options. if (role != 1) // if not administrator. { location = getValidLocation(); } switch (role) { case 1: userToAdd = new Administrator(username, password, name); users.Add(userToAdd); //Adds to the Users DataIO.saveUser(userToAdd); //Saves to files break; case 2: userToAdd = new Receptionist(username, password, name, location); users.Add(userToAdd); DataIO.saveUser(userToAdd); if (location != "") { practice = DataSearching.findPractice(location); //Uses location string to find practice practice.setReceptionist((Receptionist)userToAdd); //Sets the receptionist at the practice to the new user. } break; case 3: userToAdd = new DentistNurse(username, password, name, location, "Dentist"); //Creates a new user and sets practioner type to Dentist users.Add(userToAdd); DataIO.saveUser(userToAdd); break; case 4: userToAdd = new DentistNurse(username, password, name, location, "Nurse"); //Creates a new user and sets practioner type to Nurse users.Add(userToAdd); DataIO.saveUser(userToAdd); break; default: break; } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Shows the interface to manage a room. */ private void manageRoom(TreatmentRoom room) { string response; bool invalidResponse; Staff userToCheck; DentistNurse userToAssign; try { invalidResponse = true; while (invalidResponse) // Prints all staff at practice. { DataPrinting.printStaffAtPractice(room.getPractice()); Console.Write("Dentist to assign: (Enter nothing to skip)"); response = Console.ReadLine(); Console.Clear(); if (response != "") { if (DataSearching.userExists(response)) //Validates the response { userToCheck = (Staff)DataSearching.findUser(response); //Find staff users with the given username response. if (userToCheck is DentistNurse) { userToAssign = (DentistNurse)DataSearching.findUser(response); //Checks wether they are dentist or nurse and find them usign findUser method if (userToAssign.getPractitionerType() != "Dentist") //if not equal to dentist { Console.WriteLine("Selected staff is not dentist."); } else { room.setDentist(userToAssign); // sets the given room to the dentist user. invalidResponse = false; } } else { Console.WriteLine("Selected staff is not dentist."); } } else { Console.WriteLine("user does not exist."); } } else { invalidResponse = false; } } invalidResponse = true; while (invalidResponse) // Selecting the Nurse. works the same as Dentist { DataPrinting.printStaffAtPractice(room.getPractice()); Console.Write("Nurse to assign: (Enter nothing to skip)"); response = Console.ReadLine(); Console.Clear(); if (response != "") { if (DataSearching.userExists(response)) { userToCheck = (Staff)DataSearching.findUser(response); if (userToCheck is DentistNurse) { userToAssign = (DentistNurse)DataSearching.findUser(response); if (userToAssign.getPractitionerType() != "Nurse") { Console.WriteLine("Selected staff is not nurse."); } else { room.setNurse(userToAssign); invalidResponse = false; } } else { Console.WriteLine("Selected staff is not nurse."); } } else { Console.WriteLine("user does not exist."); } } else { invalidResponse = false; } } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }