From 13f4d91366e3d33e2683a449e27a130313cade4a Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 19 May 2024 16:31:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/PatientLogic.cs | 3 +- .../BusinessLogics/VisitLogic.cs | 16 ++- .../Models/Patient.cs | 7 + .../ViewModels/PatientViewModel.cs | 2 + .../Storages/DoctorStorage.cs | 4 +- .../Storages/PatientStorage.cs | 4 +- Medical/MedicalView/FormMain.Designer.cs | 134 +++++++++--------- Medical/MedicalView/FormMain.cs | 75 ++++++++-- Medical/MedicalView/Visits/FormVisit.cs | 23 ++- 9 files changed, 180 insertions(+), 88 deletions(-) diff --git a/Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs b/Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs index ea5d7f4..9721771 100644 --- a/Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs +++ b/Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs @@ -53,7 +53,8 @@ namespace MedicalBusinessLogic.BusinessLogics Gender = model.Gender, Birthday = model.Birthday, Weight = model.Weight, - Height = model.Height + Height = model.Height, + Age = model.GetAge() }; } } diff --git a/Medical/MedicalBusinessLogic/BusinessLogics/VisitLogic.cs b/Medical/MedicalBusinessLogic/BusinessLogics/VisitLogic.cs index d4511b0..58bb637 100644 --- a/Medical/MedicalBusinessLogic/BusinessLogics/VisitLogic.cs +++ b/Medical/MedicalBusinessLogic/BusinessLogics/VisitLogic.cs @@ -11,16 +11,19 @@ namespace MedicalBusinessLogic.BusinessLogics private readonly IStorage _patientStorage; private readonly IStorage _doctorStorage; private readonly IStorage _diagnoseStorage; + private readonly IStorage _specializationStorage; public VisitLogic( ILogger> logger, IStorage storage, IStorage patientStorage, IStorage doctorStorage, - IStorage diagnoseStorage) : base(logger, storage) + IStorage diagnoseStorage, + IStorage specializationStorage) : base(logger, storage) { _patientStorage = patientStorage; _doctorStorage = doctorStorage; _diagnoseStorage = diagnoseStorage; + _specializationStorage = specializationStorage; } protected override bool CheckModelBySearchModel(Visit model, VisitSearchModel searchModel) @@ -53,6 +56,17 @@ namespace MedicalBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } + var patient = _patientStorage.Get(model.PatientId); + var doctor = _doctorStorage.Get(model.DoctorId); + var specialization = _specializationStorage.Get(doctor.SpecializationId); + if (patient.GetAge() < 18 && !specialization.IsPediatric) + { + throw new InvalidOperationException("Нельзя записать ребенка к взрослому врачу"); + } + if (patient.GetAge() >= 18 && !specialization.IsTherapeutic) + { + throw new InvalidOperationException("Нельзя записать взрослого к детскому врачу"); + } if (!modelUpdate && ReadList(new VisitSearchModel { DoctorId = model.DoctorId, Date = model.Date, diff --git a/Medical/MedicalDatabaseContracts/Models/Patient.cs b/Medical/MedicalDatabaseContracts/Models/Patient.cs index 92c4a47..fc9eed1 100644 --- a/Medical/MedicalDatabaseContracts/Models/Patient.cs +++ b/Medical/MedicalDatabaseContracts/Models/Patient.cs @@ -8,5 +8,12 @@ namespace MedicalDatabaseContracts.Models public DateTime Birthday { get; set; } public int Weight { get; set; } public int Height { get; set; } + public int GetAge() + { + var today = DateTime.Today; + int age = today.Year - Birthday.Year; + if (Birthday.Date > today.AddYears(-age)) age--; + return age; + } } } diff --git a/Medical/MedicalDatabaseContracts/ViewModels/PatientViewModel.cs b/Medical/MedicalDatabaseContracts/ViewModels/PatientViewModel.cs index 3b24408..8914777 100644 --- a/Medical/MedicalDatabaseContracts/ViewModels/PatientViewModel.cs +++ b/Medical/MedicalDatabaseContracts/ViewModels/PatientViewModel.cs @@ -12,6 +12,8 @@ namespace MedicalDatabaseContracts.ViewModels public int Weight { get; set; } [DisplayName("Рост, см")] public int Height { get; set; } + [DisplayName("Возраст")] + public int Age { get; set; } public override string ToString() { return GetFIO() + ", " + Birthday.ToShortDateString(); diff --git a/Medical/MedicalPostgresqlDatabase/Storages/DoctorStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/DoctorStorage.cs index cb98154..60e4f64 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/DoctorStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/DoctorStorage.cs @@ -16,7 +16,7 @@ namespace MedicalPostgresqlDatabase.Storages Id = Convert.ToInt32(reader.GetValue(PRIMARY_KEY_COLUMN_NAME)), Name = Convert.ToString(reader.GetValue("name")), Surname = Convert.ToString(reader.GetValue("surname")), - Patronymic = Convert.ToString(reader.GetValue("patronymic")), + Patronymic = reader.GetValue("patronymic") is DBNull ? null : Convert.ToString(reader.GetValue("patronymic")), PhoneNumber = Convert.ToString(reader.GetValue("phone_number")), SpecializationId = Convert.ToInt32(reader.GetValue("specialization_id")) }; @@ -29,7 +29,7 @@ namespace MedicalPostgresqlDatabase.Storages { PRIMARY_KEY_COLUMN_NAME, item.Id }, { "name", item.Name }, { "surname", item.Surname }, - { "patronymic", item.Patronymic ?? string.Empty }, + { "patronymic", item.Patronymic }, { "phone_number", item.PhoneNumber }, { "specialization_id", item.SpecializationId } }; diff --git a/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs index 7078a12..6079f1f 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs @@ -16,7 +16,7 @@ namespace MedicalPostgresqlDatabase.Storages Id = Convert.ToInt32(reader.GetValue(PRIMARY_KEY_COLUMN_NAME)), Name = Convert.ToString(reader.GetValue("name")), Surname = Convert.ToString(reader.GetValue("surname")), - Patronymic = Convert.ToString(reader.GetValue("patronymic")), + Patronymic = reader.GetValue("patronymic") is DBNull ? null : Convert.ToString(reader.GetValue("patronymic")), PhoneNumber = Convert.ToString(reader.GetValue("phone_number")), Gender = Convert.ToString(reader.GetValue("gender")), Birthday = Convert.ToDateTime(reader.GetValue("birthday")), @@ -32,7 +32,7 @@ namespace MedicalPostgresqlDatabase.Storages { PRIMARY_KEY_COLUMN_NAME, item.Id }, { "name", item.Name }, { "surname", item.Surname }, - { "patronymic", item.Patronymic ?? string.Empty }, + { "patronymic", item.Patronymic }, { "phone_number", item.PhoneNumber }, { "gender", item.Gender }, { "birthday", item.Birthday }, diff --git a/Medical/MedicalView/FormMain.Designer.cs b/Medical/MedicalView/FormMain.Designer.cs index 222745d..d7c7a20 100644 --- a/Medical/MedicalView/FormMain.Designer.cs +++ b/Medical/MedicalView/FormMain.Designer.cs @@ -33,18 +33,18 @@ специализацииToolStripMenuItem = new ToolStripMenuItem(); диагнозыToolStripMenuItem = new ToolStripMenuItem(); врачиToolStripMenuItem = new ToolStripMenuItem(); - пациентыToolStripMenuItem1 = new ToolStripMenuItem(); + PatientsToolStripMenuItem = new ToolStripMenuItem(); + RefreshToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); panel = new Panel(); + buttonClearSearch = new Button(); + buttonDeleteAllData = new Button(); buttonGenerateRandomData = new Button(); - buttonEdit = new Button(); buttonDelete = new Button(); buttonAdd = new Button(); - dateTimePicker1 = new DateTimePicker(); - comboBoxDoctor = new ComboBox(); + comboBoxPatient = new ComboBox(); statusStrip = new StatusStrip(); toolStripStatusLabel = new ToolStripStatusLabel(); - buttonDeleteAllData = new Button(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); panel.SuspendLayout(); @@ -54,17 +54,17 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пациентыToolStripMenuItem1 }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, RefreshToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Padding = new Padding(7, 3, 0, 3); - menuStrip.Size = new Size(1012, 30); + menuStrip.Size = new Size(1000, 30); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip1"; // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { специализацииToolStripMenuItem, диагнозыToolStripMenuItem, врачиToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { специализацииToolStripMenuItem, диагнозыToolStripMenuItem, врачиToolStripMenuItem, PatientsToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -90,12 +90,19 @@ врачиToolStripMenuItem.Text = "Врачи"; врачиToolStripMenuItem.Click += DoctorsToolStripMenuItem_Click; // - // пациентыToolStripMenuItem1 + // PatientsToolStripMenuItem // - пациентыToolStripMenuItem1.Name = "пациентыToolStripMenuItem1"; - пациентыToolStripMenuItem1.Size = new Size(94, 24); - пациентыToolStripMenuItem1.Text = "Пациенты"; - пациентыToolStripMenuItem1.Click += PatientsToolStripMenuItem1_Click; + PatientsToolStripMenuItem.Name = "PatientsToolStripMenuItem"; + PatientsToolStripMenuItem.Size = new Size(203, 26); + PatientsToolStripMenuItem.Text = "Пациенты"; + PatientsToolStripMenuItem.Click += PatientsToolStripMenuItem_Click; + // + // RefreshToolStripMenuItem + // + RefreshToolStripMenuItem.Name = "RefreshToolStripMenuItem"; + RefreshToolStripMenuItem.Size = new Size(92, 24); + RefreshToolStripMenuItem.Text = "Обновить"; + RefreshToolStripMenuItem.Click += RefreshToolStripMenuItem_Click; // // dataGridView // @@ -111,51 +118,58 @@ dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 25; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(1012, 331); + dataGridView.Size = new Size(1000, 331); dataGridView.TabIndex = 1; // // panel // + panel.Controls.Add(buttonClearSearch); panel.Controls.Add(buttonDeleteAllData); panel.Controls.Add(buttonGenerateRandomData); - panel.Controls.Add(buttonEdit); panel.Controls.Add(buttonDelete); panel.Controls.Add(buttonAdd); - panel.Controls.Add(dateTimePicker1); - panel.Controls.Add(comboBoxDoctor); + panel.Controls.Add(comboBoxPatient); panel.Dock = DockStyle.Top; panel.Location = new Point(0, 30); panel.Margin = new Padding(3, 4, 3, 4); panel.Name = "panel"; - panel.Size = new Size(1012, 39); + panel.Size = new Size(1000, 39); panel.TabIndex = 2; // + // buttonClearSearch + // + buttonClearSearch.Location = new Point(360, 4); + buttonClearSearch.Name = "buttonClearSearch"; + buttonClearSearch.Size = new Size(94, 29); + buttonClearSearch.TabIndex = 7; + buttonClearSearch.Text = "Сбросить"; + buttonClearSearch.UseVisualStyleBackColor = true; + buttonClearSearch.Click += buttonClearSearch_Click; + // + // buttonDeleteAllData + // + buttonDeleteAllData.Location = new Point(852, 2); + buttonDeleteAllData.Name = "buttonDeleteAllData"; + buttonDeleteAllData.Size = new Size(143, 31); + buttonDeleteAllData.TabIndex = 6; + buttonDeleteAllData.Text = "Очистить базу"; + buttonDeleteAllData.UseVisualStyleBackColor = true; + buttonDeleteAllData.Click += buttonDeleteAllData_Click; + // // buttonGenerateRandomData // - buttonGenerateRandomData.Location = new Point(716, 5); + buttonGenerateRandomData.Location = new Point(711, 2); buttonGenerateRandomData.Name = "buttonGenerateRandomData"; - buttonGenerateRandomData.Size = new Size(135, 29); + buttonGenerateRandomData.Size = new Size(135, 31); buttonGenerateRandomData.TabIndex = 5; buttonGenerateRandomData.Text = "Сгенерировать"; buttonGenerateRandomData.UseVisualStyleBackColor = true; buttonGenerateRandomData.Click += buttonGenerateRandomData_Click; // - // buttonEdit - // - buttonEdit.Anchor = AnchorStyles.Left; - buttonEdit.Location = new Point(478, 3); - buttonEdit.Margin = new Padding(3, 4, 3, 4); - buttonEdit.Name = "buttonEdit"; - buttonEdit.Size = new Size(86, 31); - buttonEdit.TabIndex = 4; - buttonEdit.Text = "Изменить"; - buttonEdit.UseVisualStyleBackColor = true; - buttonEdit.Click += buttonEdit_Click; - // // buttonDelete // buttonDelete.Anchor = AnchorStyles.Left; - buttonDelete.Location = new Point(570, 3); + buttonDelete.Location = new Point(601, 2); buttonDelete.Margin = new Padding(3, 4, 3, 4); buttonDelete.Name = "buttonDelete"; buttonDelete.Size = new Size(86, 31); @@ -167,7 +181,7 @@ // buttonAdd // buttonAdd.Anchor = AnchorStyles.Left; - buttonAdd.Location = new Point(385, 3); + buttonAdd.Location = new Point(509, 2); buttonAdd.Margin = new Padding(3, 4, 3, 4); buttonAdd.Name = "buttonAdd"; buttonAdd.Size = new Size(86, 31); @@ -176,25 +190,18 @@ buttonAdd.UseVisualStyleBackColor = true; buttonAdd.Click += buttonAdd_Click; // - // dateTimePicker1 + // comboBoxPatient // - dateTimePicker1.Anchor = AnchorStyles.Left; - dateTimePicker1.Location = new Point(207, 4); - dateTimePicker1.Margin = new Padding(3, 4, 3, 4); - dateTimePicker1.Name = "dateTimePicker1"; - dateTimePicker1.Size = new Size(158, 27); - dateTimePicker1.TabIndex = 1; - // - // comboBoxDoctor - // - comboBoxDoctor.Anchor = AnchorStyles.Left; - comboBoxDoctor.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxDoctor.FormattingEnabled = true; - comboBoxDoctor.Location = new Point(3, 4); - comboBoxDoctor.Margin = new Padding(3, 4, 3, 4); - comboBoxDoctor.Name = "comboBoxDoctor"; - comboBoxDoctor.Size = new Size(196, 28); - comboBoxDoctor.TabIndex = 0; + comboBoxPatient.Anchor = AnchorStyles.Left; + comboBoxPatient.AutoCompleteMode = AutoCompleteMode.SuggestAppend; + comboBoxPatient.AutoCompleteSource = AutoCompleteSource.ListItems; + comboBoxPatient.FormattingEnabled = true; + comboBoxPatient.Location = new Point(3, 5); + comboBoxPatient.Margin = new Padding(3, 4, 3, 4); + comboBoxPatient.Name = "comboBoxPatient"; + comboBoxPatient.Size = new Size(351, 28); + comboBoxPatient.TabIndex = 0; + comboBoxPatient.SelectedIndexChanged += comboBoxPatient_SelectedIndexChanged; // // statusStrip // @@ -202,7 +209,7 @@ statusStrip.Items.AddRange(new ToolStripItem[] { toolStripStatusLabel }); statusStrip.Location = new Point(0, 379); statusStrip.Name = "statusStrip"; - statusStrip.Size = new Size(1012, 22); + statusStrip.Size = new Size(1000, 22); statusStrip.TabIndex = 3; statusStrip.Text = "statusStrip1"; // @@ -211,28 +218,18 @@ toolStripStatusLabel.Name = "toolStripStatusLabel"; toolStripStatusLabel.Size = new Size(0, 16); // - // buttonDeleteAllData - // - buttonDeleteAllData.Location = new Point(857, 5); - buttonDeleteAllData.Name = "buttonDeleteAllData"; - buttonDeleteAllData.Size = new Size(143, 29); - buttonDeleteAllData.TabIndex = 6; - buttonDeleteAllData.Text = "Очистить базу"; - buttonDeleteAllData.UseVisualStyleBackColor = true; - buttonDeleteAllData.Click += buttonDeleteAllData_Click; - // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1012, 401); + ClientSize = new Size(1000, 401); Controls.Add(statusStrip); Controls.Add(panel); Controls.Add(dataGridView); Controls.Add(menuStrip); MainMenuStrip = menuStrip; Margin = new Padding(3, 4, 3, 4); - MinimumSize = new Size(683, 438); + MinimumSize = new Size(683, 448); Name = "FormMain"; Text = "Записи посещений"; Load += FormMain_Load; @@ -255,15 +252,16 @@ private DataGridView dataGridView; private ToolStripMenuItem специализацииToolStripMenuItem; private Panel panel; - private DateTimePicker dateTimePicker1; - private ComboBox comboBoxDoctor; + private ComboBox comboBoxPatient; private ToolStripMenuItem пациентыToolStripMenuItem1; private Button buttonDelete; private Button buttonAdd; - private Button buttonEdit; private StatusStrip statusStrip; private ToolStripStatusLabel toolStripStatusLabel; private Button buttonGenerateRandomData; private Button buttonDeleteAllData; + private ToolStripMenuItem RefreshToolStripMenuItem; + private ToolStripMenuItem PatientsToolStripMenuItem; + private Button buttonClearSearch; } } \ No newline at end of file diff --git a/Medical/MedicalView/FormMain.cs b/Medical/MedicalView/FormMain.cs index 16ee077..154bb19 100644 --- a/Medical/MedicalView/FormMain.cs +++ b/Medical/MedicalView/FormMain.cs @@ -14,18 +14,21 @@ namespace MedicalView.Visits { private readonly ILogger _logger; private readonly ILogic _visitLogic; - public FormMain(ILogger logger, ILogic visitLogic) + private readonly ILogic _patientLogic; + public FormMain(ILogger logger, ILogic visitLogic, ILogic patientLogic) { InitializeComponent(); dataGridView.CellDoubleClick += buttonEdit_Click; dataGridView.CellContentDoubleClick += buttonEdit_Click; _logger = logger; _visitLogic = visitLogic; + _patientLogic = patientLogic; } private void FormMain_Load(object sender, EventArgs e) { - LoadData(); + LoadPatients(); + //LoadData(); } private void DiagnosesToolStripMenuItem_Click(object sender, EventArgs e) @@ -55,22 +58,21 @@ namespace MedicalView.Visits } } - private void PatientsToolStripMenuItem1_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormPatients)); - if (service is FormPatients form) - { - form.ShowDialog(); - } - } - protected virtual void LoadData() { SetStatusStripText("Загрузка списка..."); try { double elapsed; - var items = _visitLogic.ReadList(out elapsed); + + VisitSearchModel? searchModel = null; + + if (comboBoxPatient.SelectedIndex != -1) + { + searchModel = new VisitSearchModel { PatientId = (comboBoxPatient.SelectedItem as PatientViewModel).Id }; + } + + var items = _visitLogic.ReadList(out elapsed, searchModel); dataGridView.DataSource = items; foreach (DataGridViewTextBoxColumn column in dataGridView.Columns) @@ -103,6 +105,10 @@ namespace MedicalView.Visits var service = Program.ServiceProvider?.GetService(typeof(FormVisit)); if (service is FormVisit form) { + if (comboBoxPatient.SelectedIndex != -1) + { + form.PatientId = (comboBoxPatient.SelectedItem as PatientViewModel).Id; + } if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -176,5 +182,50 @@ namespace MedicalView.Visits } } } + + private void RefreshToolStripMenuItem_Click(object sender, EventArgs e) + { + LoadPatients(); + //LoadData(); + } + + private void PatientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPatients)); + if (service is FormPatients form) + { + form.ShowDialog(); + LoadPatients(); + } + } + + private void comboBoxPatient_SelectedIndexChanged(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadPatients() + { + var patients = _patientLogic.ReadList(); + int? selectedPatientId = null; + if (comboBoxPatient.SelectedItem != null) + { + selectedPatientId = (comboBoxPatient.SelectedItem as PatientViewModel).Id; + } + comboBoxPatient.DataSource = patients; + if (selectedPatientId != null) + { + comboBoxPatient.SelectedIndex = patients.FindIndex(x => x.Id == selectedPatientId); + } + else + { + comboBoxPatient.SelectedIndex = -1; + } + } + + private void buttonClearSearch_Click(object sender, EventArgs e) + { + comboBoxPatient.SelectedIndex = -1; + } } } diff --git a/Medical/MedicalView/Visits/FormVisit.cs b/Medical/MedicalView/Visits/FormVisit.cs index 385a665..b1d94a5 100644 --- a/Medical/MedicalView/Visits/FormVisit.cs +++ b/Medical/MedicalView/Visits/FormVisit.cs @@ -15,6 +15,7 @@ namespace MedicalView.Visits private readonly ILogic _doctorLogic; private readonly ILogic _patientLogic; private readonly ILogic _specLogic; + public int? PatientId { get; set; } public FormVisit( ILogger logger, ILogic visitLogic, @@ -44,6 +45,19 @@ namespace MedicalView.Visits MessageBox.Show("Выберите врача", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + var patient = _patientLogic.ReadElement((comboBoxPatient.SelectedItem as PatientViewModel).Id); + var doctor = _doctorLogic.ReadElement((comboBoxDoctor.SelectedItem as DoctorViewModel).Id); + var specialization = _specLogic.ReadElement(doctor.SpecializationId); + if (patient.Age < 18 && !specialization.IsPediatric) + { + MessageBox.Show("Нельзя записать ребенка к взрослому врачу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (patient.Age >= 18 && !specialization.IsTherapeutic) + { + MessageBox.Show("Нельзя записать взрослого к детскому врачу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Сохранение модели приема"); try { @@ -51,8 +65,8 @@ namespace MedicalView.Visits { Id = ModelId ?? 0, Comment = textBoxComment.Text, - PatientId = (comboBoxPatient.SelectedItem as PatientViewModel).Id, - DoctorId = (comboBoxDoctor.SelectedItem as DoctorViewModel).Id, + PatientId = patient.Id, + DoctorId = doctor.Id, DiagnoseId = comboBoxDiagnose.SelectedItem != null ? (comboBoxDiagnose.SelectedItem as DiagnoseViewModel).Id : null, Date = DateOnly.FromDateTime(datePicker.Value), Time = TimeOnly.FromDateTime(timePicker.Value) @@ -87,6 +101,11 @@ namespace MedicalView.Visits comboBoxPatient.DataSource = patients; comboBoxPatient.SelectedIndex = -1; + if (PatientId.HasValue) + { + comboBoxPatient.SelectedIndex = patients.FindIndex(x => x.Id == PatientId); + } + comboBoxDoctor.DataSource = doctors; comboBoxDoctor.SelectedIndex = -1;