Ejemplo n.º 1
0
    public static void Main()
    {
        var hospital = new Hospital();

        string command = Console.ReadLine();

        while (command != "Output")
        {
            string[] tokens           = command.Split();
            var      department       = tokens[0];
            var      doctorFirstName  = tokens[1];
            var      doctorSecondName = tokens[2];
            var      patientName      = tokens[3];

            if (!hospital.Departments.Any(d => d.Type == department))
            {
                hospital.AddDepartment(new Department(department));
            }

            var patient = new Patient(patientName);
            var doctor  = new Doctor(doctorFirstName, doctorSecondName);
            hospital.AccommodatePatientWithHealingDoctor(patient, department, doctor);

            command = Console.ReadLine();
        }

        command = Console.ReadLine();
        while (command != "End")
        {
            string[] args = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);

            if (args.Length == 1)
            {
                Console.WriteLine(hospital.GetPatientsInDepartment(args[0]));
            }
            else if (args.Length == 2 && int.TryParse(args[1], out var room))
            {
                Console.WriteLine(hospital.GetPatientsInDepartmentRoom(args[0], room));
            }
            else
            {
                var currentDoctor = hospital.Doctors.FirstOrDefault(d => d.FirstName == args[0]);
                Console.WriteLine(currentDoctor.GetPatiens());
            }
            command = Console.ReadLine();
        }
    }
Ejemplo n.º 2
0
        public void Run()
        {
            Hospital hospital = new Hospital();
            string   command;

            while ((command = Console.ReadLine()) != "Output")
            {
                string[] tokens         = command.Split();
                string   departmentName = tokens[0];
                string   doctorName     = $"{tokens[1]} {tokens[2]}";
                string   patientName    = tokens[3];

                if (!(hospital.Departments.Any(n => n.Name == departmentName)))
                {
                    Department department = new Department(departmentName);
                    hospital.AddDepartment(department);
                }

                if (!(hospital.Doctors.Any(n => n.Name == doctorName)))
                {
                    Doctor doctor = new Doctor(doctorName);
                    hospital.AddDoctor(doctor);
                }

                Patient patient = new Patient(patientName);

                hospital.Departments.FirstOrDefault(n => n.Name == departmentName)
                .AddPatientToDepartment(patient);
                if (patient.Status == "Added")
                {
                    hospital.Doctors.FirstOrDefault(n => n.Name == doctorName).AddPatient(patient);
                }
            }

            while ((command = Console.ReadLine()) != "End")
            {
                string[] tokens = command.Split();

                if (tokens.Length == 1)
                {
                    string departmentName = tokens[0];
                    foreach (var department in hospital.Departments.Where(n => n.Name == departmentName))
                    {
                        foreach (var room in department.Rooms)
                        {
                            foreach (var patient in room.Patients)
                            {
                                Console.WriteLine(patient.Name);
                            }
                        }
                    }
                }
                else
                {
                    if (int.TryParse(tokens[1], out int result))
                    {
                        string departmentName = tokens[0];
                        int    roomNumber     = int.Parse(tokens[1]);

                        foreach (var department in hospital.Departments.Where(n => n.Name == departmentName))
                        {
                            foreach (var room in department.Rooms.Where(r => r.Number == roomNumber))
                            {
                                foreach (var patient in room.Patients.OrderBy(p => p.Name))
                                {
                                    Console.WriteLine(patient.Name);
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (var doctor in hospital.Doctors.Where(d => d.Name == command.TrimEnd()))
                        {
                            foreach (var patient in doctor.Patients.OrderBy(p => p.Name))
                            {
                                Console.WriteLine(patient.Name);
                            }
                        }
                    }
                }
            }
        }