Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- public class Clinic
- {
- private Doctor _doctor = null;
- private Pacient _pacient;
- public List<Pacient> pacients = new List<Pacient>();
- public List<Doctor> doctors = new List<Doctor>();
- private SortedDictionary<int, Doctor> ot = new SortedDictionary<int, Doctor> ();
- public Doctor GetDoctorByCode(int code)
- {
- if (ot.ContainsKey(code))
- return ot[code];
- else
- return new Doctor("Wrong Code");
- }
- public void AddDoctor(string surname, string name, string secondName, ushort age)
- {
- _doctor = new Doctor(surname, name, secondName, age);
- doctors.Add(_doctor);
- ot.Add(_doctor.GetCode(), _doctor);
- }
- public void AddDoctor(string surname, string name, string secondName, ushort age,
- ushort qualification, ushort experience, ushort salary)
- {
- _doctor = new Doctor(surname, name, secondName, age, qualification, experience, salary);
- doctors.Add(_doctor);
- ot.Add(_doctor.GetCode(), _doctor);
- }
- public void AddPacient(string surname, string name, string secondName, ushort age)
- {
- _pacient = new Pacient(surname, name, secondName, age);
- pacients.Add(_pacient);
- }
- public void ShowDoctors()
- {
- foreach (Doctor v in doctors)
- Console.WriteLine(_doctor.Show());
- }
- }
- abstract public class Unit
- {
- public string name { get; set; }
- public string surname { get; set; }
- public string secondName { get; set; }
- public ushort age { get; set; }
- public Unit(string surname, string name, string secondName, ushort age)
- {
- this.name = name;
- this.surname = surname;
- this.secondName = secondName;
- this.age = age;
- }
- public Unit() { }
- virtual public string Show()
- {
- return null;
- }
- public void EditName(string name) => this.name = name;
- public void EditSurame(string surname) => this.surname = surname;
- public void EditSecondName(string secondName) => this.secondName = secondName;
- public void EditAge(ushort age) => this.age = age;
- }
- public class Time : IComparable<Time>
- {
- private ushort hour;
- private ushort min;
- public Time(Time a)
- {
- this.min = a.min;
- this.hour = a.hour;
- }
- public Time(int hour, int min)
- {
- this.hour = (ushort)hour;
- this.min = (ushort)min;
- }
- public Time(ushort hour, ushort min)
- {
- this.hour = hour;
- this.min = min;
- }
- public Time(string s)
- {
- string[] tmp = s.Split(':');
- hour = ushort.Parse(tmp[0]);
- min = ushort.Parse(tmp[1]);
- }
- public int CompareTo(Time b)
- {
- if (this < b)
- return -1;
- if (this > b)
- return 1;
- return 0;
- }
- public static bool operator >(Time a, Time b)
- {
- return b < a;
- }
- public static bool operator <(Time a, Time b)
- {
- if (a.hour < b.hour)
- return true;
- if (a.hour == b.hour
- && a.min < b.min)
- return true;
- return false;
- }
- public void AddMin(int min)
- {
- AddMin((ushort)min);
- }
- public void AddMin(ushort min)
- {
- this.min += min;
- if (this.min >= 60)
- {
- hour++;
- this.min -= 60;
- }
- if (hour == 24)
- hour = 0;
- }
- public ushort this[int idx]
- {
- get
- {
- if (idx == 0)
- return hour;
- else
- return min;
- }
- set
- {
- if (idx == 0)
- hour = value;
- else
- min = value;
- }
- }
- public override string ToString()
- {
- string m = ":";
- if (min < 10)
- m = ":0";
- string h = "";
- if (hour < 10)
- h = "0";
- return h + hour.ToString() + m + min.ToString();
- }
- }
- public class Date : IComparable<Date>
- {
- ushort day;
- ushort month;
- ushort year;
- public Date(Date b)
- {
- day = b.day;
- month = b.month;
- year = b.year;
- }
- public Date(ushort day, ushort month, ushort year)
- {
- this.day = day;
- this.month = month;
- this.year = year;
- }
- public Date(int day, int month, int year) : this((ushort)day, (ushort)month, (ushort)year)
- {
- }
- public int CompareTo(Date b)
- {
- if (this < b)
- return -1;
- if (this > b)
- return 1;
- return 0;
- }
- private int GetMonthCode()
- {
- switch (month)
- {
- case 1:
- case 10:
- return 1;
- case 5:
- return 2;
- case 8:
- return 3;
- case 2:
- case 3:
- case 11:
- return 4;
- case 6:
- return 5;
- case 9:
- case 12:
- return 6;
- case 4:
- case 7:
- return 0;
- default:
- return int.MaxValue;
- }
- }
- private int GetYearCode()
- {
- return (6 + (year % 100) + (year % 100) / 4) % 7;
- }
- public int GetDayOfWeek()
- {
- int tmp = day + GetMonthCode() + GetYearCode();
- int res = (tmp + 6) % 7;
- if (res == 0)
- res += 7;
- return res;
- }
- static public Date Now
- {
- get
- {
- DateTime tmp = DateTime.Now;
- return new Date(tmp.Day, tmp.Month, tmp.Year);
- }
- }
- public void AddDays(object value)
- {
- day += (ushort)((int)value);
- y:
- ushort max = 0;
- switch (month)
- {
- case 1:
- case 3:
- case 5:
- case 6:
- case 7:
- case 9:
- case 11:
- max = 31;
- break;
- default:
- max = 30;
- break;
- }
- if (month == 2 && (year % 4 == 0 && year % 100 != 0) ^ (year % 400 == 0))
- {
- max = 29;
- }
- else
- {
- max = 28;
- }
- if (day > max)
- {
- day = (ushort)(day - max);
- month++;
- if (month == 13)
- {
- year++;
- month = 1;
- goto y;
- }
- }
- }
- public static int CompareYear(Date a, Date b)
- {
- DateTime c = new DateTime(a.year, a.month, a.day);
- DateTime d = new DateTime(b.year, b.month, b.day);
- TimeSpan f = c - d;
- int countOfLeapYear = 0;
- for (int i = c.Year + 1; i <= d.Year; ++i)
- if ((i % 4 == 0 && i % 100 != 0) ^ (i % 400 == 0))
- countOfLeapYear++;
- return (f.Days + countOfLeapYear - 1) / 365;
- }
- public static bool operator <(Date a, Date b)
- {
- if (a.year < b.year)
- return true;
- if (a.year == b.year
- && a.month < b.month)
- return true;
- if (a.year == b.year
- && a.month == b.month
- && a.day < b.day)
- return true;
- return false;
- }
- public static bool operator >(Date a, Date b)
- {
- return b < a;
- }
- public override string ToString()
- {
- string d = "";
- if (day < 10)
- d = "0";
- string m = "";
- if (month < 10)
- m = "0";
- int yy = year % 100;
- string y = "";
- if (yy < 10)
- y = "0";
- return d + day + "." + m + month + "." + y + yy;
- }
- }
- public class Doctor : Unit
- {
- private int code;
- private static int idx = 0;
- private ushort qualification { get; set; } = 0;
- private ushort experience { get; set; } = 0;
- private ushort salary { get; set; } = 10000;
- private Date dateOfEmployment;//дата принятия на работу
- private readonly int was;//cтартовый опыт
- private ushort type = 0;
- private SortedDictionary<Date, SortedDictionary<Time, Pacient>> schedule
- = new SortedDictionary<Date, SortedDictionary<Time, Pacient>>();
- public Doctor(string specieal)
- {
- surname = specieal;
- idx--;
- }
- public Doctor(string surname, string name, string secondName, ushort age)
- : base(surname, name, secondName, age)
- {
- dateOfEmployment = Date.Now;
- was = experience;
- Refresh();
- code = idx++;
- }
- public Doctor() { }
- public Doctor(string surname, string name, string secondName, ushort age, ushort qualification,
- ushort experience, ushort salary) : this(surname, name, secondName, age)
- {
- this.qualification = qualification;
- this.experience = experience;
- this.salary = salary;
- dateOfEmployment = Date.Now;
- was = experience;
- Refresh();
- code = idx++;
- }
- public int GetCode() => code;
- private void Fill()
- {
- Date date = Date.Now;
- for (int i = 0; i < 31; ++i)
- {
- if (schedule.ContainsKey(date))
- continue;
- else
- {
- Date _date = new Date(date);
- Time time = new Time(8 + type * 6, 0);
- schedule.Add(_date, new SortedDictionary<Time, Pacient>());
- if (_date.GetDayOfWeek() < 6)
- {
- for (int j = 0; j < 15; ++j)
- {
- schedule[_date].Add(new Time(time), new Pacient());
- time.AddMin(20);
- }
- }
- }
- date.AddDays(1);
- }
- }
- private void Delete()
- {
- Date now = Date.Now;
- ICollection<Date> keys = schedule.Keys;
- foreach (Date v in keys)
- {
- if (v < now)
- schedule.Remove(v);
- else
- break;
- }
- }
- private void RefreshExperience()
- {
- experience = (ushort)(was + Date.CompareYear(Date.Now, dateOfEmployment));
- }
- public void Refresh()
- {
- Delete();
- Fill();
- RefreshExperience();
- }
- public (Date, Time) CloserDateTime()
- {
- (Date, Time) cur;
- ICollection<Date> keys = schedule.Keys;
- foreach (Date date in keys)
- {
- ICollection<Time> keysTime = schedule[date].Keys;
- foreach (Time time in keysTime)
- {
- if (schedule[date][time].IsEmpty())
- {
- return (date, time);
- }
- }
- }
- return (null, null);
- }
- public void Set(Date date, Time time, Pacient pacient)
- {
- if (schedule.ContainsKey(date)
- && schedule[date].ContainsKey(time)
- && schedule[date][time].IsEmpty())
- {
- schedule[date][time] = pacient;
- }
- else
- Console.WriteLine("ERROR");
- }
- public void GetSchedule(int n)
- {
- n = n > 30 ? 30 : n;
- Refresh();
- Date cur = Date.Now;
- Console.WriteLine(Show());
- Console.WriteLine(new string('=', 20));
- for (int i = 0; i < n; ++i)
- {
- Console.Write("======" + cur + "======" + "\n" + new string('=', 20) + "\n");
- if (cur.GetDayOfWeek() < 6)
- {
- int tabl = 0;//cчетчик табуляции
- foreach (var patient in schedule[cur])
- {
- tabl++;
- if (patient.Value.IsEmpty())
- {
- Console.Write(patient.Key + " ---- ");
- Console.Write("Empty");
- }
- else
- {
- Console.Write(patient.Key + " ---- ");
- Console.WriteLine(patient.Value.Info());
- tabl = 0;
- continue;
- }
- if (tabl % 4 == 0)
- Console.WriteLine();
- else
- Console.Write("\t");
- }
- }
- else
- {
- Console.Write("Holiday");
- }
- cur.AddDays(1);
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine(new string('=', 20));
- }
- }
- public void SetDateOfEmployment(Date date)
- {
- dateOfEmployment = date;
- RefreshExperience();
- }
- override public string Show()
- {
- string show = "Surname : " + surname + "\n" +
- "Name : " + name + "\n" +
- "SecondName : " + secondName + "\n" +
- "qualification : " + qualification + "\n" +
- "experience : " + experience + "\n";
- return show;
- }
- public void EditDoctorQualification(ushort qualification) => this.qualification = qualification;
- public void EditDoctorSalary(ushort salary) => this.salary = salary;
- }
- public class Request
- {
- public Date date;//when
- public Time time;
- public int doctorCode;
- public int pacientCode;
- public Request(Request request)
- {
- this.date = request.date;
- this.time = request.time;
- this.doctorCode = request.doctorCode;
- this.pacientCode = request.pacientCode;
- }
- public Request(Date date, Time time, int doctorCode, int pacientCode)
- {
- this.date = date;
- this.time = time;
- this.doctorCode = doctorCode;
- this.pacientCode = pacientCode;
- }
- }
- public class Pacient : Unit
- {
- private int code;
- private List<Request> history = new List<Request>();
- private static int idx = 0;
- public void AddRequest(Request req)
- {
- history.Add(req);
- }
- bool NULL = false;
- public Pacient()
- {
- NULL = true;
- }
- public Pacient(string special)
- {
- surname = special;
- idx--;
- }
- public Pacient(string surname, string name, string secondName, ushort age)
- : base(surname, name, secondName, age)
- {
- idx++;
- code = idx;
- }
- public bool IsEmpty() => NULL;
- public int GetCode() => code;
- override public string Show()
- {
- string show = "Surname : " + surname + "\n" +
- "Name : " + name + "\n" +
- "SecondName : " + secondName + "\n" +
- "Age : " + age + "\n";
- return show;
- }
- public void EnterToSchedule(Date date, Time time, Doctor doctor)
- {
- doctor.Set(date, time, this);
- history.Add(new Request(date, time, doctor.GetCode(), this.GetCode()));
- }
- public void EnterToCloserSchedule(Doctor doctor)
- {
- (Date, Time) a = doctor.CloserDateTime();
- if (a == (null, null))
- {
- Console.WriteLine("Not Enougth Empty Slot");
- return;
- }
- else
- doctor.Set(a.Item1, a.Item2, this);
- history.Add(new Request(a.Item1, a.Item2, doctor.GetCode(), this.GetCode()));
- }
- public string Info()
- {
- return surname + " " + name + " " + secondName + " ID : " + code.ToString();
- }
- public void ShowAllHistory(Clinic clinic)
- {
- ShowHistoryFromDate(new Date(1, 1, 2000), clinic);
- }
- public void ShowHistory(Clinic clinic)
- {
- ShowHistoryFromDate(Date.Now, clinic);
- }
- public void ShowHistoryFromDate(Date date, Clinic clinic)
- {
- Console.WriteLine(Show() + "\n--->History : \n" );
- string s = new string('=', 20);
- Console.WriteLine(s + "\n");
- foreach (Request req in history)
- {
- if (req.date < date)
- {
- continue;
- }
- else
- {
- Console.WriteLine("date :" + req.date);
- Console.WriteLine("time :" + req.time);
- Console.WriteLine("doctor :\n" + clinic.GetDoctorByCode(req.doctorCode).Show());
- Console.WriteLine(s);
- }
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Clinic a = new Clinic();
- a.AddDoctor("Чернышев", "Константин", "Владимирович", 20);
- a.AddDoctor("aba", "caba", "cadaba", 32);
- a.AddPacient("Попов", "Данил", "Валерьевич", 32);
- //a.doctors[0].EditDoctorSalary(15000);
- //a.ShowDoctors();
- //Console.WriteLine(a.pacients[0].code);
- Console.WriteLine(a.doctors[0].Show());
- a.doctors[0].SetDateOfEmployment(new Date(14, 03, 2019));
- a.pacients[0].EnterToCloserSchedule(a.doctors[0]);
- a.pacients[0].EnterToSchedule(new Date(17, 03, 2020), new Time(12, 00), a.doctors[0]);
- a.doctors[0].GetSchedule(5);
- a.pacients[0].ShowAllHistory(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement