Пример #1
0
        private void AddPatientToRoom(Department departament, Patient patient)
        {
            Room availableRoom = departament.Rooms.FirstOrDefault(r => r.Count < maxCapacity);

            availableRoom.AddPatient(patient);
            departament.AddPatient(patient);
        }
Пример #2
0
        private static void CreateDoctorsAndDepartments(List <Doctor> doctors, List <Department> departments)
        {
            string command = Console.ReadLine();

            while (command != "Output")
            {
                string[] commandInList = command.Split();
                var      departament   = commandInList[0];
                var      firstName     = commandInList[1];
                var      secondName    = commandInList[2];
                var      patient       = commandInList[3];

                var currDoctor = new Doctor(firstName, secondName);

                if (!doctors.Any(x => x.FirstName == firstName && x.SecondName == secondName))
                {
                    doctors.Add(currDoctor);
                }
                else
                {
                    foreach (var doctor in doctors)
                    {
                        if (doctor.FirstName == currDoctor.FirstName && doctor.SecondName == currDoctor.SecondName)
                        {
                            currDoctor = doctor;
                            break;
                        }
                    }
                }

                var currDepartment = new Department(departament);

                if (departments.All(x => x.Name != departament))
                {
                    departments.Add(currDepartment);
                }

                else
                {
                    foreach (var dep in departments)
                    {
                        if (dep.Name == currDepartment.Name)
                        {
                            currDepartment = dep;
                            break;
                        }
                    }
                }
                if (currDepartment.IsntFull())
                {
                    var currPatient = new Patient(patient);
                    currDoctor.Patients.Add(currPatient);
                    currDepartment.AddPatient(currPatient);
                }
                command = Console.ReadLine();
            }
        }
Пример #3
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)));
                }
            }
        }