Esempio n. 1
0
        /**
         * Prints staff at a given Practice.
         */
        public static void printStaffAtPractice(DentalPractice practice)
        {
            List <Staff> staff           = DataSearching.getStaff();
            List <Staff> staffAtPractice = new List <Staff>();
            DentistNurse denNurseToPrint;

            try
            {
                staffAtPractice = staff.FindAll(staffMem => (staffMem.getPractice() is DentalPractice) && (staffMem.getPractice().Equals(practice))); //Returns a list of all staff with the given location.

                Console.WriteLine("Staff at {0}:", practice.getLocation());

                for (int i = 0; i < staffAtPractice.Count; i++)
                {
                    Console.Write("{0}: {1} - ", staffAtPractice[i].getUsername(), staffAtPractice[i].getName());

                    //Printing role
                    if (staffAtPractice[i] is Receptionist)
                    {
                        Console.WriteLine("Receptionist");
                    }
                    else
                    {
                        denNurseToPrint = (DentistNurse)staffAtPractice[i];  //Shortened version to select practioner type & write it
                        Console.WriteLine(denNurseToPrint.getPractitionerType());
                    }
                    ;
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        /**
         * Saves all treatment rooms.
         */
        public static void saveAllRooms(DentalPractice practice)
        {
            List <TreatmentRoom> rooms;
            StreamWriter         roomFile;
            string roomInfoPath; //Path to the specific Practice Rooms folder.
            string roomFilePath;

            try
            {
                rooms        = practice.getRooms();                                      //Gets lsit of rooms from give practice.
                roomInfoPath = practicePath + "\\" + practice.getLocation() + "\\Rooms"; //Determines the path of the directory where the given locations room files are stored.
                if (Directory.Exists(roomInfoPath))
                {
                    Directory.Delete(roomInfoPath, true);    //true tells Directory.Delete() to delete any contents within the folder.
                    Directory.CreateDirectory(roomInfoPath); //Recreates the empty Room directory.
                }
                Directory.CreateDirectory(roomInfoPath);     //Recreates the empty Room directory.

                roomInfoPath += "\\Room ";                   //Concatenates string, joins strings together.

                for (int i = 0; i < rooms.Count; i++)
                {
                    roomFilePath = roomInfoPath + (i + 1) + ".txt";
                    roomFile     = new StreamWriter(roomFilePath);
                    roomFile.WriteLine(rooms[i].getDentistId());
                    roomFile.WriteLine(rooms[i].getNurseId());
                    roomFile.Close();
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        /**
         * loads treatment rooms for a given location.
         */
        public static void loadTreatmentRooms(List <TreatmentRoom> rooms, DentalPractice practice)
        {
            string[]     treatmentRoomFiles;
            StreamReader treatmentRoomFile;                                                   //opens file to read
            string       roomPath = practicePath + "\\" + practice.getLocation() + "\\Rooms"; //Takes root directory and add the backslash to determine the path in the Rooms folder within locations folder.

            string assignedDentist;
            string assignedNurse;

            try
            {
                if (Directory.Exists(roomPath))                                                        //find whether it exsists
                {
                    treatmentRoomFiles = Directory.GetFiles(roomPath);                                 //Get files for stored in the rooms folder

                    for (int i = 0; i < treatmentRoomFiles.Length; i++)                                //Iterates over all the room files
                    {
                        treatmentRoomFile = new StreamReader(roomPath + "\\Room " + (i + 1) + ".txt"); //Opens up the first room file for the given location
                        assignedDentist   = treatmentRoomFile.ReadLine();                              //first line will be the dentist.
                        assignedNurse     = treatmentRoomFile.ReadLine();                              //second will be the nurse.
                        treatmentRoomFile.Close();

                        rooms.Add(new TreatmentRoom(i + 1, practice, assignedDentist, assignedNurse));
                    }
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        public static string patientPath  = rootPath + @"\" + MyDentistMgr.Default.PatientsPath;                                                     //creates a path to the patients directory

        /**
         * Saves a singe practice file.
         */
        public static void savePracticeFile(DentalPractice practice)
        {
            StreamWriter practiceFile; //writes a textfile to the computer, Reader reads
            string       practiceFilePath;

            try
            {
                practiceFilePath = practicePath + "\\" + practice.getLocation(); // \\ escape key for backslash, takes root directory and add the backslash to determine the path in the dental practice folder.
                if (!Directory.Exists(practiceFilePath))                         //Creates a folder for the practice if it does not exist already.
                {
                    Directory.CreateDirectory(practiceFilePath);
                    Directory.CreateDirectory(practiceFilePath + @"\Rooms");
                }

                practiceFile = new StreamWriter(practiceFilePath + @"\info.txt", false); //Give true as the second parameter to append to a file or false to overwrite.
                practiceFile.WriteLine(practice.getLocation());                          //First line is location.

                if (practice.getReceptionist() is Receptionist)
                {
                    practiceFile.WriteLine(practice.getReceptionist().getUsername()); //Receptionist is second line.
                }
                else
                {
                    practiceFile.WriteLine();
                }

                practiceFile.WriteLine(practice.getAddress()); //Address is third.
                practiceFile.Close();                          //closes streamwriter
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        /**
         * Prints rooms in a given practice.
         */
        public static void printRoomsAtPractice(DentalPractice practice)
        {
            List <TreatmentRoom> rooms = practice.getRooms();

            try
            {
                for (int i = 0; i < rooms.Count; i++) //iterates over room no.
                {
                    Console.WriteLine("Room: {0}", rooms[i].getRoomNumber());
                    if (rooms[i].getDentist() is DentistNurse)
                    {
                        Console.WriteLine("Dentist: {0} - {1}", rooms[i].getDentistId(), rooms[i].getDentist().getName()); //prints "Dentist: <username> - <name>"
                    }

                    if (rooms[i].getNurse() is DentistNurse)
                    {
                        Console.WriteLine("Nurse: {0} - {1}\n", rooms[i].getNurseId(), rooms[i].getNurse().getName()); //Same as above for nurse.
                    }
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
Esempio n. 6
0
        /**
         * Views a practice
         */
        public static void viewPractice(DentalPractice practice)
        {
            List <TreatmentRoom> rooms = practice.getRooms(); //geta all rooms at practice

            try
            {
                Console.Clear();
                Console.WriteLine(practice.getLocation());              //writes the name of specific pratice
                Console.WriteLine($"Address: {practice.getAddress()}"); //writes the address of the practice

                Console.Write("Receptionist: ");
                if (practice.getReceptionist() is Receptionist)              //Checks if receptionist is assigned
                {
                    Console.WriteLine(practice.getReceptionist().getName()); //writes the name of receptionist
                }
                else
                {
                    Console.WriteLine("Unassigned"); //if not
                }

                Console.WriteLine("\nRooms\n=====");

                for (int i = 0; i < rooms.Count; i++)    //iterates over room no.
                {
                    Console.WriteLine($"Room {i + 1}:"); //writes room no. adding +1 to index so more human friendly

                    Console.Write("Dentist: ");
                    if (rooms[i].getDentist() is DentistNurse)              //checks if dentist is assigned
                    {
                        Console.WriteLine(rooms[i].getDentist().getName()); //gets the assigned name of the dentist
                    }
                    else
                    {
                        Console.WriteLine("Unassigned");
                    }

                    Console.Write("Nurse: ");
                    if (rooms[i].getNurse() is DentistNurse)              //checks if nurse is assigned
                    {
                        Console.WriteLine(rooms[i].getNurse().getName()); //writes the name of the assigned nurse.
                    }
                    else
                    {
                        Console.WriteLine("Unassigned");
                    }
                }
                Console.ReadLine();
                Console.Clear();
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
Esempio n. 7
0
        /**
         * Prints patients at the given practice.
         */
        public static void printPatients(DentalPractice practice)
        {
            List <Patient> patients = practice.getPatients();

            try
            {
                for (int i = 0; i < patients.Count; i++)
                {
                    Console.WriteLine($"{patients[i].getId()}: {patients[i].getName()}");
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
Esempio n. 8
0
        /**
         * Prints rooms in a given practice.
         */
        public static void printRoomsAtPractice(DentalPractice practice)
        {
            List <TreatmentRoom> rooms = practice.getRooms();

            try
            {
                for (int i = 0; i < rooms.Count; i++)                         //iterates over room no.
                {
                    Console.WriteLine("Room: {0}", rooms[i].getRoomNumber()); //Writes rooms
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        /**
         * Finds a the practice with the given name.
         */
        public static DentalPractice findPractice(string location)
        {
            DentalPractice        practiceToFind;
            List <DentalPractice> practices = Application.appInstance.dentalPractices;

            try
            {
                practiceToFind = practices.Find(practice => practice.getLocation() == location); //The List.Find() function takes what is called a Predicate. which acts is basically a search filter. https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.find?view=netcore-3.1
            }
            catch (Exception e)
            {
                practiceToFind = new DentalPractice("", "", ""); //havent defined it outside, this is used to prevent an error
                GeneralFunctions.errorHandler(e);
            }
            return(practiceToFind);
        }
        /**
         * Prints patients at the given practice.
         */
        public static void printPatients(DentalPractice practice)
        {
            List <Patient> patients = practice.getPatients();

            try
            {
                for (int i = 0; i < patients.Count; i++)
                {
                    Console.WriteLine($"{patients[i].getId()}: {patients[i].getName()} - {patients[i].getContactNo()}\n{patients[i].getAddress()}\n"); //writes patient information from the desired practice
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
Esempio n. 11
0
        /**
         * Prints all appointments at a location for the current day.
         */
        public static void printDailyLocationAppointments(DentalPractice location)
        {
            List <Appointment> appointments = DataSearching.getDailyLocationAppointments(location); //gets the list of appointments for the given location

            try
            {
                for (int i = 0; i < appointments.Count; i++)                                                                                                                                  //iterate over the the appointments
                {
                    Console.WriteLine($"{appointments[i].getId()}: {appointments[i].getPatient().getName()} - Room {appointments[i].getRoom().getRoomNumber()} {appointments[i].getTime()}"); //prints appointments out ID, patient, name, Room no. and time
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        /**
         * Reorgasnises the rooms. Usually occurs following the removal of a room.
         */
        private void restructureRooms(DentalPractice practice)
        {
            List <TreatmentRoom> rooms = practice.getRooms();

            try
            {
                for (int i = 0; i < rooms.Count; i++)
                {
                    rooms[i].setRoomNumber(i + 1); //Sets the room number, and converts indext to a more human friendly number (room 1 = 1 instead 0)
                }
                DataIO.saveAllRooms(practice);     //Saves all rooms to files
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        /**
         * Gets all appointments at a given location.
         */
        public static List <Appointment> getAppointments(DentalPractice practice)
        {
            List <Patient>     patients     = practice.getPatients();    //Gets the patients within the practice/s
            List <Appointment> appointments = new List <Appointment>();; //Creates a list to store appointments.

            try
            {
                for (int i = 0; i < patients.Count; i++)                  //iterates on patients
                {
                    appointments.AddRange(patients[i].getAppointments()); //Adds all appointments for the patient to the appointments list. //addrange takes one list and adds another list to it
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
            return(appointments);
        }
        /**
         * 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);
            }
        }
        /**
         * Adds a room to the provided practice.
         */
        private void addRoomToPractice(DentalPractice practice)
        {
            TreatmentRoom newTreatmentRoom;
            int           roomNo;

            try
            {
                roomNo = practice.getRooms().Count + 1;                         //Adds +1 to current room no.

                newTreatmentRoom = new TreatmentRoom(roomNo, practice, "", ""); //"", "" are for the dentist & nurse
                manageRoom(newTreatmentRoom);                                   //Runs manageRoom to set up new treatment room
                practice.getRooms().Add(newTreatmentRoom);                      //Adds the treatment room to practice.
                DataIO.saveAllRooms(practice);                                  //writes to file
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        /**
         * Gets the daily appointments for a given location
         */
        public static List <Appointment> getDailyLocationAppointments(DentalPractice location)
        {
            List <Appointment> allAppointments = getAppointments(location); //gets the list of appointments at a location
            DateTime           currentDate     = DateTime.Now;              //Create a time object corresponding to the current time
            string             currentDateStr;

            List <Appointment> dailyAppointments; //List to store appointments on the day

            try
            {
                currentDateStr    = currentDate.ToString("D");                                                       //converts the date object to a string & deterimes format dd/mm/yyyy
                dailyAppointments = allAppointments.FindAll(appointment => appointment.getDate() == currentDateStr); //finds all the apppointments on the current date
            }
            catch (Exception e)
            {
                dailyAppointments = new List <Appointment>();
                GeneralFunctions.errorHandler(e);
            }
            return(dailyAppointments);
        }
        /**
         * Shows the practice editor.
         */
        private void showPracticeEditor()
        {
            DentalPractice practiceToAdd;
            string         location = "";
            string         address  = "";

            string receptionist;

            try
            {
                while (location == "") //Ensures a value is provided
                {
                    Console.Write("Location: ");
                    location = Console.ReadLine();
                    Console.Clear();
                }

                while (address == "")
                {
                    Console.Write("Address: ");
                    address = Console.ReadLine();
                    Console.Clear();
                }

                Console.Write("Receptionist: (leave blank to skip)");
                receptionist = Console.ReadLine();

                practiceToAdd = new DentalPractice(location, address, receptionist); //Creates practice with or without receptionist
                if (receptionist != "")                                              //check if receptionist is blank
                {
                    practiceToAdd.associateReceptionist();                           //Associates the receptionist with practice
                }
                Application.appInstance.dentalPractices.Add(practiceToAdd);          //Adds dental practice to the list
                DataIO.savePracticeFile(practiceToAdd);                              //Saves to file
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
 /*
 * Sets the practice 
 */
 public void setPractice(DentalPractice practice)
 {
     this.practice = practice;
 }
 /**
  * Checks a patient with the given id exists at the given practice.
  */
 public static bool patientExists(DentalPractice practice, string id)
 {
     return(practice.getPatients().Exists(patient => patient.getId() == id)); //Checks if a patient at the given location with the given id exists.
 }
 /**
  * gets a patient with the given id and given practice.
  */
 public static Patient findPatient(DentalPractice practice, string id)
 {
     return(practice.getPatients().Find(patient => patient.getId() == id)); //Returns the patient objects with the given patient ID
 }
 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);
 }