Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- namespace AnarchyHospital
- {
- internal class Program
- {
- static void Main()
- {
- Hospital hospital = new Hospital();
- hospital.Work();
- }
- }
- public class Hospital
- {
- private const string ExitCommand = "Exit";
- private readonly Manager _manager;
- private readonly List<Patient> _patients;
- public Hospital()
- {
- _manager = new Manager();
- _patients = _manager.Fill();
- }
- public void Work()
- {
- _manager.ShowPatients(_patients);
- Console.WriteLine("\nPress something for menu..");
- Console.ReadKey();
- bool isWorking = true;
- while (isWorking)
- {
- Console.Clear();
- string typeSort = ProcessMenu();
- if (typeSort.ToLower() == ExitCommand.ToLower())
- {
- isWorking = false;
- }
- else if (Validate(typeSort))
- {
- List<Patient> sortedPatients = _manager.SortPatients(_patients, typeSort);
- _manager.ShowPatients(sortedPatients);
- }
- Console.WriteLine("\nPress something..");
- Console.ReadKey();
- }
- }
- private string ProcessMenu()
- {
- Console.WriteLine($"Select command: " +
- $"\nsort by name - {Manager.NameSortCommand}" +
- $"\nsort by age - {Manager.AgeSortCommand}" +
- $"\nor the name of the disease to bring out patients with this disease" +
- $"\n\"{ExitCommand}\" for exit");
- Console.WriteLine($"\nList of all diseases that patients have: {string.Join(", ", _manager.GetAllDiseases(_patients))}");
- return Console.ReadLine();
- }
- private bool Validate(string typeSort)
- {
- if (typeSort == Manager.NameSortCommand)
- {
- return true;
- }
- else if (typeSort == Manager.AgeSortCommand)
- {
- return true;
- }
- else if (_manager.GetAllDiseases(_patients).Contains(typeSort.ToLower()))
- {
- return true;
- }
- Console.WriteLine("\nUnknown command or disease. Press something..");
- Console.ReadKey();
- return false;
- }
- }
- public class Manager
- {
- public const string NameSortCommand = "1";
- public const string AgeSortCommand = "2";
- public List<Patient> Fill()
- {
- PatientFactory patientFactory = new PatientFactory();
- return patientFactory.Create().ToList();
- }
- public void ShowPatients(List<Patient> patients)
- {
- foreach (Patient patient in patients)
- {
- string name = $"{patient.Name} {patient.Surname}";
- string age = patient.Age.ToString();
- string disease = string.Join(", ", patient.GetDiseases());
- string tabulation = "\t";
- int maxLength = 15;
- if (name.Length <= maxLength)
- {
- tabulation += tabulation;
- }
- Console.WriteLine($"{name}{tabulation}age: {age}\t\tdiagnostic: {disease}");
- }
- }
- public List<string> GetAllDiseases(List<Patient> patients)
- {
- List<string> diseaseList = new List<string>();
- foreach (Patient patient in patients)
- {
- diseaseList.AddRange(patient.GetDiseases().ToList().Except(diseaseList).ToList());
- }
- return diseaseList;
- }
- public List<Patient> SortPatients(List<Patient> patients, string typeSort)
- {
- List<Patient> selectedPatients = null;
- switch (typeSort)
- {
- case NameSortCommand:
- selectedPatients = patients.OrderBy(patient => patient.Surname).ToList();
- break;
- case AgeSortCommand:
- selectedPatients = patients.OrderBy(patient => patient.Age).ToList();
- break;
- default:
- selectedPatients = patients.Where(patient => patient.GetDiseases().Contains(typeSort)).ToList();
- break;
- }
- return selectedPatients.ToList();
- }
- }
- public class PatientFactory
- {
- private readonly ListProvider _listProvider;
- private readonly Random _random;
- public PatientFactory()
- {
- _listProvider = new ListProvider();
- _random = new Random();
- }
- public List<Patient> Create()
- {
- List<Patient> patients = new List<Patient>();
- int patientsCount = 20;
- for (int i = 0; i < patientsCount; i++)
- {
- patients.Add(new Patient(GetName(_listProvider.GetName()), GetName(_listProvider.GetSurname()), GetAge(), GetDisease()));
- }
- return patients;
- }
- private string GetName(List<string> values)
- {
- string value = values[_random.Next(values.Count)];
- return value;
- }
- private List<string> GetDisease()
- {
- int minDiseaseCount = 1;
- int maxDiseaseCount = 3;
- List<string> diseases = new List<string>();
- for (int i = 0; i < _random.Next(minDiseaseCount, maxDiseaseCount + 1);)
- {
- string disease = _listProvider.GetDisease()[_random.Next(_listProvider.GetDisease().Count)];
- if (diseases.Contains(disease) == false)
- {
- diseases.Add(disease);
- i++;
- }
- }
- return diseases;
- }
- private int GetAge()
- {
- int minAge = 1;
- int maxAge = 90;
- int age = _random.Next(minAge, maxAge);
- return age;
- }
- }
- public class ListProvider
- {
- private readonly List<string> _names;
- private readonly List<string> _surnames;
- private readonly List<string> _disease;
- public ListProvider()
- {
- _names = new List<string>{"Aleksandr", "Nikolaj", "Ivan", "Sergej", "Vladimir", "Mikhail", "Vasilij", "Aleksej", "Andrej", "Dmitrij", "Viktor", "Yurij", "Petr", "Anatolij", "Pavel", "Igor", "Evgenij", "Oleg", "Valerij", "Vitalij", "Grigorij",
- "Fedor", "Boris", "Gennadij", "Leonid", "Konstantin", "Vyacheslav", "Georgij", "Denis", "Valentin", "Maksim", "Vadim",
- "Roman", "Ilya", "Ruslan", "Stepan", "Semen", "Anton", "Eduard", "Stanislav"};
- _surnames = new List<string> {"Ivanov", "Kuznetsov", "Smirnov", "Popov", "Petrov", "Vasilev", "Kozlov", "Novikov", "Sokolov", "Volkov", "Fedorov", "Mikhajlov", "Semenov", "Pavlov", "Morozov", "Zajtsev", "Stepanov", "Andreev", "Egorov", "Nikitin",
- "Zakharov", "Makarov", "Alekseev", "Yakovlev", "Kovalenko", "Nikolaev", "Solovev", "Bondarenko", "Kovalev", "Lebedev",
- "Shevchenko", "Vorobev", "Romanov", "Sergeev", "Grigorev", "Kiselev", "Kravchenko", "Baranov", "Kuzmin", "Frolov"};
- _disease = new List<string> { "bronchitis", "diabetes", "migraine", "asthma", "allergy" };
- }
- public List<string> GetName()
- {
- return _names.ToList();
- }
- public List<string> GetSurname()
- {
- return _surnames.ToList();
- }
- public List<string> GetDisease()
- {
- return _disease.ToList();
- }
- }
- public class Patient
- {
- private readonly List<string> _diseases;
- public Patient(string name, string surname, int age, List<string> diseases)
- {
- Name = name;
- Surname = surname;
- Age = age;
- _diseases = diseases;
- }
- public string Name { get; private set; }
- public string Surname { get; private set; }
- public int Age { get; private set; }
- public List<string> GetDiseases()
- {
- return _diseases.ToList();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement