/**
         * 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);
            }
        }
Beispiel #3
0
        private void ModalDialog_AddBarcode_OKModal(object sender, RoutedEventArgs e)
        {
            ChildControl.AddPrintingBarcode ucontrol = ModalDialog_AddBarcode.Children[0] as ChildControl.AddPrintingBarcode;
            DataPrinting dataPrinting = ucontrol.DataContext as DataPrinting;

            if (dataPrinting.Printing.Code == null)
            {
                return;
            }
            DataListPrinting dataContext = DataContext as DataListPrinting;

            dataContext.ListPrinting.Add(new BarCodePrinting(dataPrinting.Printing));
            RefeshItems();
        }
        /**
         * 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);
            }
        }
        /**
         * Main menu for a DentistNurse.
         */
        public override void showMainMenu() //override from User.cs & defined
        {
            int response;

            try
            {
                loggedIn = true;
                while (loggedIn)
                {
                    Console.Clear();
                    response = GeneralFunctions.getRequiredSelection("Main Menu", new string[] { "View Patients", "Appointments", "Log out" }); //Selection for menu

                    switch (response)
                    {
                    case 1:
                        Console.Clear();
                        DataPrinting.printPatients(practice);     //Prints all Patients
                        Console.WriteLine("Press Enter to continue.");
                        Console.ReadLine();
                        break;

                    case 2:
                        showAppointments();
                        break;

                    case 3:
                        loggedIn = false;
                        break;

                    default:
                        break;
                    }
                }
            }
            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 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);
            }
        }
        /**
         * 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);
            }
        }
        /**
         * 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);
            }
        }