static void DischargePatient() { string name; Console.WriteLine("What is the patients name?"); name = Console.ReadLine(); hospital.DischargePatient(hospital.FindPatientByName(name)); }
//Her laver vi en function der sætter en specifik læge sammen med en spicifik patient static void patient_doctor() { Console.WriteLine("Doctors name"); string doc = Console.ReadLine(); Console.WriteLine("Patients name"); string pat = Console.ReadLine(); hospital.test(doc, hospital.FindPatientByName(pat)); }
static void DischargePatient() { string name; Console.WriteLine("What is the patients name?"); // Asking for the patients name name = Console.ReadLine(); Patient person = hospital.FindPatientByName(name); // Finds patients name, by name hospital.DischargePatient(person); // It removes the patient }
// MainMenu is our primary menu, it gives us a set of options to choose from that alters the database or gives us feedback. Either way // it returns true or false static bool MainMenu() { // Starts out by clearing the console and writing introductory text Console.Clear(); Console.WriteLine("Welcome to {0}. You have the following options:", hospital.name); Console.WriteLine("1. Admit a patient to the hospital"); Console.WriteLine("2. Discharge a patient"); Console.WriteLine("3. See a list of all patients in the hospital"); Console.WriteLine("4. See a list of all doctors in the hospital"); Console.WriteLine("5. Assign a specific doctor to a specific patient"); Console.WriteLine("0. Quit the Program"); Console.WriteLine(); // takes a character and then runs it through a series of if-else checks that give an output for 0-5 var k = Console.ReadKey().KeyChar; Console.WriteLine(); // tells the system to call AdmitPatient() if (k == '1') { AdmitPatient(); } // Asks for the name of the patient and checks whether that patient is in the database. If that is the case the patient is discharged, // otherwise feedback is given but no database changes. else if (k == '2') { Console.WriteLine("What is the patients name?"); String input = Console.ReadLine(); try { hospital.DischargePatient(hospital.FindPatientByName(input)); Console.WriteLine("Patient discharged"); } catch { Console.WriteLine(" \n Beware!! Patient does not exist!!"); } } // Prints a list consisting of all patients that have been admitted to the hospital else if (k == '3') { Console.WriteLine("Here you can see all patients"); foreach (Patient p in hospital.patients) { Console.WriteLine(p.name); } } // Prints a list consisting of all doctors that work at the hospital else if (k == '4') { Console.WriteLine("Here you can see all doctors"); foreach (Doctor d in hospital.doctors) { Console.WriteLine(d.name); } } // Asks for the name of doctor and patient. After that it checks whether both are in the database. If they are it assigns the doctor to the // patient and puts the patient on the doctors list of patients. else if (k == '5') { Console.WriteLine("What is the name of the patient"); String patientName = Console.ReadLine(); Console.WriteLine("What is the name of the doctor"); String doctorName = Console.ReadLine(); Doctor localdoc = null; Patient localPatient = null; foreach (Doctor doc in hospital.doctors) { if (doc.name == doctorName) { localdoc = doc; } } foreach (Patient pat in hospital.patients) { if (pat.name == patientName) { localPatient = pat; } } if (localPatient != null && localdoc != null) { localPatient.AssignDoctor(localdoc); localdoc.assignedPatients.Add(localPatient); Console.WriteLine("Doctor and patient have been linked "); } else { Console.WriteLine("Patient or doctorname written wrong"); } } // this returns false which ends the while loop. else if (k == '0') { return(false); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); return(true); }
// start a loop that is true and running static bool MainMenu() { // en masse console.writeline med noget text der vil blive vidst hver gang programmet looper Console.Clear(); Console.WriteLine("Welcome to {0}. You have the following options:", hospital.name); Console.WriteLine("1. Admit a patient to the hospital"); Console.WriteLine("2. Discharge a patient"); Console.WriteLine("3. See a list of all patients in the hospital"); Console.WriteLine("4. See a list of all doctors in the hospital"); Console.WriteLine("5. Assign a specific doctor to a specific patient"); Console.WriteLine("0. Quit the Program"); Console.WriteLine(); // console.readkey virker sådan at du kan kun skrive et bogstav eller tal og den gemmer så den værdi til senere brug var k = Console.ReadKey().KeyChar; // tjekker om k er lig med 1 if (k == '1') { // starter functionen AdmitPatient, som er defineret sidst i koden AdmitPatient(); } else if (k == '2') { // definere en string til senere brug string navn; Console.WriteLine("Navnet på personen"); // siger at navn som er en string vi definerede længere oppe skal være lig med console.readline navn = Console.ReadLine(); // vi siger fjerne skal være lig med funktionen FindPatientByname(navn) Patient fjerne = hospital.FindPatientByName(navn); // kører funktionen DischargePatient fra hospital, hvor fjerne kommer med som værdi hospital.DischargePatient(fjerne); } // tjekker om k er lig med 3 else if (k == '3') { foreach (Patient i in hospital.patients) { Console.WriteLine(i.name); } } // tjekker om k er lig med 4 else if (k == '4') { foreach (Doctor i in hospital.doctors) { Console.WriteLine(i.name); } // kører funktionen DoktorList som er defineret længere nede DoktorList(); } // tjekker om k er lig med 5 else if (k == '5') { Doktorogpatientt(); } // tjekker om k er lig med 0 else if (k == '0') { // returner false hvilket gør at vores loop stopper og lukker programmet return(false); } // sender dig herhen hvis du skriver et bogstav i den første console.readkey Console.WriteLine("Press any key to continue..."); // skriv et tal eller bogstav Console.ReadKey(); // returner true hvilket vil sige programmet starter forfra igen return(true); }