public void AddPatient(Patient patient) { Patients.Add(patient); }
//------------- Public Methods --------------- public void Run() { while (true) { string command = Console.ReadLine(); if (command == "Output") { break; } string[] tokens = command.Split(); string departmentName = tokens[0]; string doctorFirstName = tokens[1]; string doctorLastName = tokens[2]; string patientName = tokens[3]; Department department = this.hospital.Departments.FirstOrDefault(d => d.Name == departmentName); if (department == null) { department = new Department(departmentName); Doctor doctor = new Doctor(doctorFirstName, doctorLastName); Patient patient = new Patient(patientName); department.AddDoctor(doctor); doctor.AddPatient(patient); department.AddPatient(patient); this.hospital.AddDepartment(department); } else { Doctor doctor = department.Doctors.FirstOrDefault(d => d.FirstName == doctorFirstName && d.LastName == d.LastName); Patient patient = new Patient(patientName); if (doctor == null) { doctor = new Doctor(doctorFirstName, doctorLastName); } department.AddDoctor(doctor); doctor.AddPatient(patient); department.AddPatient(patient); } } string[] commands = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); Department selectedDepartment = this.hospital.Departments.FirstOrDefault(d => d.Name == commands[0]); if (commands.Length == 1) { if (selectedDepartment != null) { foreach (Room room in selectedDepartment.Rooms) { foreach (Bed bed in room.Beds.Where(b => b.IsOccupied)) { Console.WriteLine(bed.Patient.Name); } } } } else if (commands.Length == 2) { if (selectedDepartment != null && int.TryParse(commands[1], out int roomNumber)) { List <string> patients = new List <string>(); Room selectedRoom = selectedDepartment.Rooms[roomNumber - 1]; foreach (Bed bed in selectedRoom.Beds.Where(b => b.IsOccupied)) { patients.Add(bed.Patient.Name); } Console.WriteLine(String.Join(Environment.NewLine, patients.OrderBy(p => p))); } else { List <string> patients = new List <string>(); foreach (Department department in this.hospital.Departments.Where(d => d.Doctors.Count != 0)) { Doctor selectedDoctor = department.Doctors.FirstOrDefault(d => d.FirstName == commands[0] && d.LastName == commands[1]); if (selectedDoctor != null) { selectedDoctor.Patients.ToList().ForEach(p => patients.Add(p.Name)); } } Console.WriteLine(String.Join(Environment.NewLine, patients.OrderBy(p => p))); } } }
public static void Main() { var departments = new List <Department>(); var doctors = new List <Doctor>(); string command = Console.ReadLine(); while (command != "Output") { string[] inputArgs = command.Split(); var departamentName = inputArgs[0]; var doctorsName = $"{inputArgs[1]} {inputArgs[2]}"; var currentPatient = new Patient(inputArgs[3]); if (!doctors.Any(d => d.Name == doctorsName)) { doctors.Add(new Doctor(doctorsName)); } if (!departments.Any(d => d.Name == departamentName)) { departments.Add(new Department(departamentName)); } bool hasFreeBeds = departments.Find(d => d.Name == departamentName).Patients.Count() < 60; if (hasFreeBeds) { doctors.Find(d => d.Name == doctorsName).Patients.Add(currentPatient); currentPatient.Room = departments.Find(d => d.Name == departamentName).Patients.Count() / 3 + 1; departments.Find(d => d.Name == departamentName).Patients.Add(currentPatient); } command = Console.ReadLine(); } command = Console.ReadLine(); while (command != "End") { string[] printArgs = command.Split(); if (printArgs.Length == 1) { Console.WriteLine(string.Join(Environment.NewLine, departments.Find(d => d.Name == printArgs[0]).Patients)); } else if (printArgs.Length == 2 && int.TryParse(printArgs[1], out int room)) { Console.WriteLine(string.Join(Environment.NewLine, departments.Find(d => d.Name == printArgs[0]) .Patients.Where(p => p.Room == room) .OrderBy(p => p.Name))); } else { Console.WriteLine(string.Join(Environment.NewLine, doctors.Find(d => d.Name == command).Patients.OrderBy(p => p.Name))); } command = Console.ReadLine(); } }