Ejemplo n.º 1
0
        public static void Main()
        {
            departments = new List <Department>();
            doctors     = new List <Doctor>();

            string command = Console.ReadLine();

            while (command != "Output")
            {
                string[] commandArgs = command.Split();

                var departamentName = commandArgs[0];
                var firstName       = commandArgs[1];
                var secondName      = commandArgs[2];
                var patient         = commandArgs[3];

                Department department = GetDepartment(departamentName);
                Doctor     doctor     = GetDoctor(firstName, secondName);

                bool containsFreeSpace = department.Rooms.Sum(x => x.Patients.Count) < 60;

                if (containsFreeSpace)
                {
                    int targetRoom = 0;

                    doctor.Patients.Add(patient);

                    for (int room = 0; room < department.Rooms.Count; room++)
                    {
                        if (department.Rooms[room].Patients.Count < 3)
                        {
                            targetRoom = room;
                            break;
                        }
                    }
                    department.Rooms[targetRoom].Patients.Add(patient);
                }

                command = Console.ReadLine();
            }

            command = Console.ReadLine();

            while (command != "End")
            {
                string[] args = command.Split();

                if (args.Length == 1)
                {
                    var department = GetDepartment(args[0]);

                    foreach (var room in department.Rooms.Where(x => x.Patients.Count > 0))
                    {
                        foreach (var patient in room.Patients)
                        {
                            Console.WriteLine(patient);
                        }
                    }
                }

                else if (args.Length == 2 && int.TryParse(args[1], out int room))
                {
                    var department = GetDepartment(args[0]);

                    foreach (var name in department.Rooms[room - 1].Patients.OrderBy(x => x))
                    {
                        Console.WriteLine(name);
                    }
                }

                else
                {
                    Doctor doctor = GetDoctor(args[0], args[1]);

                    foreach (var patient in doctor.Patients.OrderBy(x => x))
                    {
                        Console.WriteLine(patient);
                    }
                }
                command = Console.ReadLine();
            }
        }
Ejemplo n.º 2
0
        //------------- 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)));
                }
            }
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            departments = new List <Department>();
            doctors     = new List <Doctor>();

            while (true)
            {
                var input = Console.ReadLine()
                            .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                if (input[0] == "Output")
                {
                    break;
                }

                var departmentName = input[0];
                var doctorName     = input[1] + ' ' + input[2];
                var patient        = input[3];

                Department department   = GetDepartment(departmentName);
                Doctor     doctor       = GetDoctor(doctorName);
                bool       hasFreeSpace = department.Rooms.Sum(r => r.Patients.Count) < 60;

                for (int room = 0; room < department.Rooms.Count; room++)
                {
                    if (department.Rooms[room].Patients.Count < 3)
                    {
                        department.Rooms[room].Patients.Add(patient);
                        doctor.Patients.Add(patient);
                        break;
                    }
                }
            }

            while (true)
            {
                var command = Console.ReadLine()
                              .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                if (command[0] == "End")
                {
                    break;
                }

                else if (command.Length == 1)
                {
                    string     departmentName = command[0];
                    Department department     = GetDepartment(departmentName);

                    foreach (var room in department.Rooms.Where(r => r.Patients.Count > 0))
                    {
                        PrintPatients(room.Patients);
                    }
                }

                else if (int.TryParse(command[1], out int room))
                {
                    string     departmentName = command[0];
                    Department department     = GetDepartment(departmentName);
                    int        roomNumber     = int.Parse(command[1]) - 1;
                    var        patients       = department.Rooms[roomNumber]
                                                .Patients
                                                .OrderBy(p => p)
                                                .ToList();

                    PrintPatients(patients);
                }

                else
                {
                    var doctorName = command[0] + ' ' + command[1];
                    var doctor     = GetDoctor(doctorName);
                    var patients   = doctor
                                     .Patients
                                     .OrderBy(p => p)
                                     .ToList();

                    PrintPatients(patients);
                }
            }
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            List <Doctor>     doctors     = new List <Doctor>();
            List <Department> departments = new List <Department>();

            string command = Console.ReadLine();

            while (command != "Output")
            {
                string[] properties  = command.Split();
                var      departament = new Department(properties[0]);
                var      doctor      = new Doctor(properties[1], properties[2]);
                var      patient     = new Patient(properties[3]);
                var      count       = 1;



                var searchedDoctor = doctors.FirstOrDefault(d => d.FirstName + d.SureName == doctor.FirstName + doctor.SureName);

                if (searchedDoctor == null)
                {
                    doctors.Add(doctor);
                    searchedDoctor = doctor;
                }



                var searcheDepartment = departments.FirstOrDefault(d => d.Name == departament.Name);

                if (searcheDepartment == null)
                {
                    departments.Add(departament);
                    searcheDepartment = departament;
                }

                for (int stai = 0; stai < 20; stai++)
                {
                    var room = new Room(count);

                    searcheDepartment.Rooms.Add(room);

                    count++;
                }

                bool freeBeds = searcheDepartment.Capacity < 60;
                if (freeBeds)
                {
                    searchedDoctor.Patients.Add(patient);
                    foreach (var item in searcheDepartment.Rooms)
                    {
                        if (item.Patients.Count < item.Capacity)
                        {
                            item.Patients.Add(patient);

                            break;
                        }
                    }
                }

                command = Console.ReadLine();
            }

            command = Console.ReadLine();

            while (command != "End")
            {
                string[] args = command.Split();

                if (args.Length == 1)
                {
                    Console.WriteLine(departments.FirstOrDefault(x => x.Name == args[0]).ToString());
                }
                else if (args.Length == 2 && int.TryParse(args[1], out int room))
                {
                    var rooms = departments.FirstOrDefault(x => x.Name == args[0]).Rooms.FirstOrDefault(r => r.Id == room);

                    foreach (var patient in rooms.Patients.OrderBy(p => p.Name))
                    {
                        Console.WriteLine(patient.ToString());
                    }
                }
                else
                {
                    var doctor = doctors.FirstOrDefault(x => x.FirstName + x.SureName == args[0] + args[1]);

                    foreach (var patient in doctor.Patients.OrderBy(p => p.Name))
                    {
                        Console.WriteLine(patient.ToString());
                    }
                }
                command = Console.ReadLine();
            }
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            doctors     = new List <Doctor>();
            departments = new List <Department>();


            string command;

            while ((command = Console.ReadLine()) != "Output")
            {
                string[] info           = command.Split();
                var      departmentName = info[0];
                var      firstName      = info[1];
                var      lastName       = info[2];
                var      patient        = info[3];
                var      fullName       = firstName + lastName;

                Doctor     doctor     = GetDoctor(firstName, lastName);
                Department department = GetDepartment(departmentName);

                bool isFreeBeds = department.Rooms.Sum(r => r.Patients.Count()) < 60;
                if (isFreeBeds)
                {
                    doctor.Patients.Add(patient);

                    int targetRoom = 0;
                    for (int room = 0; room < department.Rooms.Count; room++)
                    {
                        if (department.Rooms[room].Patients.Count < 3)
                        {
                            targetRoom = room;
                            break;
                        }
                    }
                    department.Rooms[targetRoom].Patients.Add(patient);
                }
            }

            while ((command = Console.ReadLine()) != "End")
            {
                string[] args = command.Split();
                if (args.Length == 1)
                {
                    GetDepartment(args[0]).Rooms
                    .Where(r => r.Patients.Count > 0)
                    .ToList()
                    .ForEach(r => r.Patients
                             .ForEach(Console.WriteLine));
                }
                else if (args.Length == 2 && int.TryParse(args[1], out int room))
                {
                    GetDepartment(args[0]).Rooms[room - 1].Patients
                    .OrderBy(n => n)
                    .ToList()
                    .ForEach(Console.WriteLine);
                }
                else
                {
                    GetDoctor(args[0], args[1]).Patients
                    .OrderBy(n => n)
                    .ToList()
                    .ForEach(Console.WriteLine);
                }
            }
        }