commit 4105783ab9f76d37413e4a32c08b14e6a12cc856 Author: user Date: Sun Jul 12 15:08:43 2026 +0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..164fbde --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +# Build output +bin/ +obj/ + +# Build folders +Debug/ +Release/ +net*/ +publish/ + +# Visual Studio +.vs/ +*.user +*.suo +*.userosscache +*.sln.docstates + +# Rider / JetBrains +.idea/ +*.sln.iml + +# NuGet +*.nupkg +packages/ +.nuget/ + +# Logs +*.log + +# Database backups (если не нужны как часть проекта) +*.bak +*.tar + +# Temporary files +*.tmp +*.temp + +# OS files +.DS_Store +Thumbs.db + +# Screenshots / temporary images +# (уберите, если картинки нужны в документации) +# *.png +# *.jpg +# *.jpeg diff --git a/Register office/Register office.sln b/Register office/Register office.sln new file mode 100644 index 0000000..ceebd7e --- /dev/null +++ b/Register office/Register office.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36603.0 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Register office", "Register office\Register office.csproj", "{C8CBA323-4CD6-46D0-81AA-1C986EB50C6B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C8CBA323-4CD6-46D0-81AA-1C986EB50C6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8CBA323-4CD6-46D0-81AA-1C986EB50C6B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8CBA323-4CD6-46D0-81AA-1C986EB50C6B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8CBA323-4CD6-46D0-81AA-1C986EB50C6B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4BE06EF1-D35E-4B49-A77D-D46964AC9895} + EndGlobalSection +EndGlobal diff --git a/Register office/Register office/BaseClasses/UnionId.cs b/Register office/Register office/BaseClasses/UnionId.cs new file mode 100644 index 0000000..ee9403e --- /dev/null +++ b/Register office/Register office/BaseClasses/UnionId.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Register_office.BaseClasses +{ + internal interface IUnionId + { + public abstract object GetId(); + + } +} diff --git a/Register office/Register office/ExcelManager.cs b/Register office/Register office/ExcelManager.cs new file mode 100644 index 0000000..6c41010 --- /dev/null +++ b/Register office/Register office/ExcelManager.cs @@ -0,0 +1,70 @@ +using OfficeOpenXml; +using OfficeOpenXml.Drawing.Chart; +using System.ComponentModel; +using System.Diagnostics; +using System.Reflection; + +namespace Register_office +{ + internal class ExcelManager + { + public static void ExportToExcel(List data, string filePath) + { + ExcelPackage.License.SetNonCommercialOrganization("Grant"); + + using var package = new ExcelPackage(); + var worksheet = package.Workbook.Worksheets.Add("Отчёт"); + + // Получаем свойства класса + var properties = typeof(T).GetProperties(); + + // Заголовки (используем атрибут [DisplayName] или имя свойства) + for (int i = 0; i < properties.Length; i++) + { + var displayNameAttr = properties[i].GetCustomAttribute(); + worksheet.Cells[1, i + 1].Value = displayNameAttr?.DisplayName ?? properties[i].Name; + } + + // Данные + for (int i = 0; i < data.Count; i++) + { + for (int j = 0; j < properties.Length; j++) + { + worksheet.Cells[i + 2, j + 1].Value = properties[j].GetValue(data[i]); + } + } + + worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); + try + { + File.WriteAllBytes(filePath, package.GetAsByteArray()); + } + catch (Exception) + { + MessageBox.Show($"Не получилось сформировать отчет. Пожалуйста, закройте открытый файл отчета", + "Отчет о наличии ЛП в конце дня", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public static void OpenExcelFile(string filePath) + { + try + { + var process = new Process + { + StartInfo = new ProcessStartInfo(filePath) + { + UseShellExecute = true // Ключевой параметр! + } + }; + process.Start(); + } + catch (Exception ex) + { + MessageBox.Show($"Не удалось открыть файл: {ex.Message}", "Отчет о наличии ЛП в конце дня", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } +} diff --git a/Register office/Register office/Model/Analysis.cs b/Register office/Register office/Model/Analysis.cs new file mode 100644 index 0000000..ac1be66 --- /dev/null +++ b/Register office/Register office/Model/Analysis.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Register_office.Model +{ + internal class Analysis + { + [DisplayName("Пациент")] + [Column("Пациент")] + public string Patient { get; set; } + + [DisplayName("Обследование")] + [Column("Обследование")] + public string Examination { get; set; } + + [DisplayName("Результат")] + [Column("Результат")] + public string Result { get; set; } + } +} diff --git a/Register office/Register office/Model/Disease.cs b/Register office/Register office/Model/Disease.cs new file mode 100644 index 0000000..7ef6b48 --- /dev/null +++ b/Register office/Register office/Model/Disease.cs @@ -0,0 +1,31 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Windows.Forms.Design.Behavior; + +namespace Register_office.Model; + +public partial class Disease : IUnionId +{ + public object GetId() => DiseaseId; + + [Display(Name = "hide")] + public int DiseaseId { get; set; } + + [Display(Name = "Название")] + public string Name { get; set; } = null!; + + [Display(Name = "Код МКБ")] + public string IcdCode { get; set; } = null!; + + [Browsable(false)] + public virtual ICollection DiseaseSyndromes { get; set; } = new List(); + + [Browsable(false)] + public virtual ICollection HospitalAdmissions { get; set; } = new List(); + + [Browsable(false)] + public virtual ICollection HospitalDischarges { get; set; } = new List(); +} diff --git a/Register office/Register office/Model/DiseaseSyndrome.cs b/Register office/Register office/Model/DiseaseSyndrome.cs new file mode 100644 index 0000000..41718f5 --- /dev/null +++ b/Register office/Register office/Model/DiseaseSyndrome.cs @@ -0,0 +1,61 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class DiseaseSyndrome : IUnionId +{ + public object GetId() => DiseaseSyndromeId; + + public int DiseaseSyndromeId { get; set; } + + public int DiseaseId { get; set; } + + public int SyndromeId { get; set; } + + public virtual Disease Disease { get; set; } = null!; + + public virtual SyndromeType Syndrome { get; set; } = null!; +} + +internal class DiseaseSyndromeWrapper +{ + [Display(Name = "hide")] + public int DiseaseSyndromeId { get; set; } + + [Display(Name = "hide")] + public int DiseaseId { get; set; } + + [Display(Name = "hide")] + public int SyndromeId { get; set; } + + [Display(Name = "Заболевание")] + public string DiseaseName { get; set; } = null!; + + [Display(Name = "Синдром")] + public string SyndromeName { get; set; } = null!; + + public DiseaseSyndromeWrapper(DiseaseSyndrome src) + { + DiseaseSyndromeId = src.DiseaseSyndromeId; + DiseaseId = src.DiseaseId; + SyndromeId = src.SyndromeId; + DiseaseName = src.Disease.Name; + SyndromeName = src.Syndrome.Name; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (DiseaseSyndrome lst in src) + { + res.Add(new DiseaseSyndromeWrapper(lst)); + } + + return res; + } +} \ No newline at end of file diff --git a/Register office/Register office/Model/Doctor.cs b/Register office/Register office/Model/Doctor.cs new file mode 100644 index 0000000..d533782 --- /dev/null +++ b/Register office/Register office/Model/Doctor.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class Doctor +{ + [Display(Name = "hide")] + public int DoctorId { get; set; } + + [Display(Name = "Данные")] + public virtual Person DoctorNavigation { get; set; } = null!; + + [Browsable(false)] + public virtual ICollection Prescriptions { get; set; } = new List(); +} diff --git a/Register office/Register office/Model/DrugIntakeMethod.cs b/Register office/Register office/Model/DrugIntakeMethod.cs new file mode 100644 index 0000000..778b462 --- /dev/null +++ b/Register office/Register office/Model/DrugIntakeMethod.cs @@ -0,0 +1,21 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class DrugIntakeMethod : IUnionId +{ + public object GetId() => DrugIntakeMethodId; + + [Display(Name = "hide")] + public int DrugIntakeMethodId { get; set; } + + [Display(Name = "Название")] + public string Name { get; set; } = null!; + + [Browsable(false)] + public virtual ICollection DrugTypePrescriptions { get; set; } = new List(); +} diff --git a/Register office/Register office/Model/DrugType.cs b/Register office/Register office/Model/DrugType.cs new file mode 100644 index 0000000..59e5d92 --- /dev/null +++ b/Register office/Register office/Model/DrugType.cs @@ -0,0 +1,30 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class DrugType : IUnionId +{ + public object GetId() => DrugTypeId; + + [Display(Name = "hide")] + public int DrugTypeId { get; set; } + + [Display(Name = "Название на русском")] + public string InternationalNameRu { get; set; } = null!; + + [Display(Name = "Название на английском")] + public string? InternationalNameEn { get; set; } + + [Display(Name = "Название на латинском")] + public string? InternationalNameLa { get; set; } + + [Display(Name = "Брэнд")] + public string? BrandNameRu { get; set; } + + [Browsable(false)] + public virtual ICollection DrugTypePrescriptions { get; set; } = new List(); +} diff --git a/Register office/Register office/Model/DrugTypePrescription.cs b/Register office/Register office/Model/DrugTypePrescription.cs new file mode 100644 index 0000000..e03ea60 --- /dev/null +++ b/Register office/Register office/Model/DrugTypePrescription.cs @@ -0,0 +1,93 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class DrugTypePrescription : IUnionId +{ + public object GetId() => DrugPrescriptionId; + + public int DrugPrescriptionId { get; set; } + + public int PrescriptionId { get; set; } + + public int DrugTypeId { get; set; } + + public decimal Dose { get; set; } + + public int DoseUnitId { get; set; } + + public int IntakeMethodId { get; set; } + + public int DurationDays { get; set; } + + public virtual Unit DoseUnit { get; set; } = null!; + + public virtual DrugType DrugType { get; set; } = null!; + + public virtual DrugIntakeMethod IntakeMethod { get; set; } = null!; + + public virtual Prescription Prescription { get; set; } = null!; +} + +internal class DrugTypePrescriptionWrapper +{ + [Display(Name = "hide")] + public int DrugPrescriptionId { get; set; } + + [Display(Name = "hide")] + public int PrescriptionId { get; set; } + + [Display(Name = "hide")] + public int DrugTypeId { get; set; } + + [Display(Name = "Лекарства")] + public string DrugName { get; set; } = null!; + + [Display(Name = "Количество")] + public decimal Dose { get; set; } + + [Display(Name = "hide")] + public int DoseUnitId { get; set; } + + [Display(Name = "Единица изм.")] + public string UnitName { get; set; } = null!; + + [Display(Name = "hide")] + public int IntakeMethodId { get; set; } + + [Display(Name = "Способ приема")] + public string IntakeMethodName { get; set; } = null!; + + [Display(Name = "Длительность")] + public int DurationDays { get; set; } + + public DrugTypePrescriptionWrapper(DrugTypePrescription src) + { + DrugPrescriptionId = src.DrugPrescriptionId; + PrescriptionId = src.PrescriptionId; + DrugTypeId = src.DrugTypeId; + DrugName = src.DrugType.InternationalNameRu; + Dose = src.Dose; + DoseUnitId = src.DoseUnitId; + UnitName = src.DoseUnit.Name; + IntakeMethodId = src.IntakeMethodId; + IntakeMethodName = src.IntakeMethod.Name; + DurationDays = src.DurationDays; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (DrugTypePrescription lst in src) + { + res.Add(new DrugTypePrescriptionWrapper(lst)); + } + + return res; + } +} \ No newline at end of file diff --git a/Register office/Register office/Model/Enums.cs b/Register office/Register office/Model/Enums.cs new file mode 100644 index 0000000..51bc5fb --- /dev/null +++ b/Register office/Register office/Model/Enums.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Register_office.Model +{ + public enum ExaminationCategories + { + Physical, // физикальное обследование + Laboratory, // лабораторное обследование + Instrumental // инструментальное обследование + } + + public enum HospitalDischargeReasonEnum + { + Death, // смерть + Improvement, // улучшение состояния + Refusal // отказ от госпитализации или дальнейшего лечения + } + + public enum GenderEnum + { + Male, // мужчина + Female // женщина + } + +} diff --git a/Register office/Register office/Model/ExaminationType.cs b/Register office/Register office/Model/ExaminationType.cs new file mode 100644 index 0000000..6110b79 --- /dev/null +++ b/Register office/Register office/Model/ExaminationType.cs @@ -0,0 +1,33 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class ExaminationType : IUnionId +{ + public object GetId() => ExaminationTypeId; + + [Display(Name = "hide")] + public int ExaminationTypeId { get; set; } + + [Display(Name = "Название")] + public string Name { get; set; } = null!; + + [Display(Name = "Категория")] + public string Category { get; set; } = null!; + + [Browsable(false)] + public virtual ICollection ExaminationTypePrescriptions { get; set; } = new List(); + + [Browsable(false)] + public virtual ICollection ReferenceValues { get; set; } = new List(); + + [Browsable(false)] + public virtual Result? Result { get; set; } + + [Browsable(false)] + public virtual SyndromeExaminationType? SyndromeExaminationType { get; set; } +} diff --git a/Register office/Register office/Model/ExaminationTypePrescription.cs b/Register office/Register office/Model/ExaminationTypePrescription.cs new file mode 100644 index 0000000..cd5b237 --- /dev/null +++ b/Register office/Register office/Model/ExaminationTypePrescription.cs @@ -0,0 +1,70 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class ExaminationTypePrescription : IUnionId +{ + public object GetId() => ExaminationPrescriptionId; + + public int ExaminationPrescriptionId { get; set; } + + public int PrescriptionId { get; set; } + + public int? ResultId { get; set; } + + public int ExaminationTypeId { get; set; } + + public virtual ExaminationType ExaminationType { get; set; } = null!; + + public virtual Prescription Prescription { get; set; } = null!; + + public virtual Result? Result { get; set; } +} + +internal class ExaminationTypePrescriptionWrapper +{ + [Display(Name = "hide")] + public int ExaminationPrescriptionId { get; set; } + + [Display(Name = "hide")] + public int PrescriptionId { get; set; } + + [Display(Name = "hide")] + public int? ResultId { get; set; } + + [Display(Name = "hide")] + public int ExaminationTypeId { get; set; } + + [Display(Name = "Результат")] + public string Result { get; set; } = null!; + + [Display(Name = "Обследование")] + public string ExaminationName { get; set; } = null!; + + public ExaminationTypePrescriptionWrapper(ExaminationTypePrescription src) + { + ExaminationPrescriptionId = src.ExaminationPrescriptionId; + PrescriptionId = src.PrescriptionId; + ResultId = src.ResultId; + ExaminationTypeId = src.ExaminationTypeId; + if (src.Result != null) + Result = new ResultWrapper(src.Result).Result; + ExaminationName = src.ExaminationType.Name; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (ExaminationTypePrescription lst in src) + { + res.Add(new ExaminationTypePrescriptionWrapper(lst)); + } + + return res; + } +} diff --git a/Register office/Register office/Model/HospitalAdmission.cs b/Register office/Register office/Model/HospitalAdmission.cs new file mode 100644 index 0000000..3ed9f02 --- /dev/null +++ b/Register office/Register office/Model/HospitalAdmission.cs @@ -0,0 +1,71 @@ +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office; + +public partial class HospitalAdmission : IUnionId +{ + public object GetId() => HospitalAdmissionId; + + public int HospitalAdmissionId { get; set; } + + public int PatientId { get; set; } + + public int PreliminaryDiseaseId { get; set; } + + public DateTime AdmissionDatetime { get; set; } + + public virtual ICollection HospitalDischarges { get; set; } = new List(); + + public virtual Patient Patient { get; set; } = null!; + + public virtual Disease PreliminaryDisease { get; set; } = null!; +} + +internal class HospitalAdmissionWrapper +{ + [Display(Name = "hide")] + public int HospitalAdmissionId { get; set; } + + [Display(Name = "hide")] + public int PatientId { get; set; } + + [Display(Name = "hide")] + public int PreliminaryDiseaseId { get; set; } + + [Display(Name = "Пациент")] + public string PatientName { get; set; } = null!; + + [Display(Name = "Заболевание")] + public string DiseaseName { get; set; } = null!; + + [Display(Name = "Время")] + public DateTime AdmissionDatetime { get; set; } + + public HospitalAdmissionWrapper(HospitalAdmission src) + { + HospitalAdmissionId = src.HospitalAdmissionId; + PatientId = src.PatientId; + PreliminaryDiseaseId = src.PreliminaryDiseaseId; + DiseaseName = src.PreliminaryDisease.Name; + AdmissionDatetime = src.AdmissionDatetime; + Person p = src.Patient.PatientNavigation; + PatientName = p.LastName + " " + p.FirstName + " " + p.MiddleName; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (HospitalAdmission lst in src) + { + res.Add(new HospitalAdmissionWrapper(lst)); + } + + return res; + } +} \ No newline at end of file diff --git a/Register office/Register office/Model/HospitalDischarge.cs b/Register office/Register office/Model/HospitalDischarge.cs new file mode 100644 index 0000000..454bdb9 --- /dev/null +++ b/Register office/Register office/Model/HospitalDischarge.cs @@ -0,0 +1,75 @@ +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office; + +public partial class HospitalDischarge : IUnionId +{ + public object GetId() => HospitalDischargeId; + + public int HospitalDischargeId { get; set; } + + public int HospitalAdmissionId { get; set; } + + public DateTime DischargeDatetime { get; set; } + + public int FinalDiseaseId { get; set; } + + public string Reason { get; set; } = null!; + + public virtual Disease FinalDisease { get; set; } = null!; + + public virtual HospitalAdmission HospitalAdmission { get; set; } = null!; +} + +internal class HospitalDischargeWrapper +{ + [Display(Name = "hide")] + public int HospitalDischargeId { get; set; } + + [Display(Name = "hide")] + public int HospitalAdmissionId { get; set; } + + [Display(Name = "Пациент")] + public string PatientName { get; set; } = null!; + + [Display(Name = "Предв. заболевание")] + public string DiseasePrName { get; set; } = null!; + + [Display(Name = "Финал. заболевание")] + public string DiseaseFinName { get; set; } = null!; + + [Display(Name = "Время")] + public DateTime DischargeDatetime { get; set; } + + [Display(Name = "Причина завершения")] + public string Reason { get; set; } = null!; + + public HospitalDischargeWrapper(HospitalDischarge src) + { + HospitalAdmissionId = src.HospitalAdmissionId; + HospitalDischargeId = src.HospitalDischargeId; + DiseasePrName = src.HospitalAdmission.PreliminaryDisease.Name; + DiseaseFinName = src.FinalDisease.Name; + DischargeDatetime = src.DischargeDatetime; + Reason = src.Reason; + Person p = src.HospitalAdmission.Patient.PatientNavigation; + PatientName = p.LastName + " " + p.FirstName + " " + p.MiddleName; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (HospitalDischarge lst in src) + { + res.Add(new HospitalDischargeWrapper(lst)); + } + + return res; + } +} \ No newline at end of file diff --git a/Register office/Register office/Model/NumericResult.cs b/Register office/Register office/Model/NumericResult.cs new file mode 100644 index 0000000..e697f0e --- /dev/null +++ b/Register office/Register office/Model/NumericResult.cs @@ -0,0 +1,21 @@ +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; + +namespace Register_office; + +public partial class NumericResult : IUnionId +{ + public object GetId() => ResultId; + + public int ResultId { get; set; } + + public decimal Value { get; set; } + + public int UnitId { get; set; } + + public virtual Result Result { get; set; } = null!; + + public virtual Unit Unit { get; set; } = null!; +} diff --git a/Register office/Register office/Model/Patient.cs b/Register office/Register office/Model/Patient.cs new file mode 100644 index 0000000..7a3c723 --- /dev/null +++ b/Register office/Register office/Model/Patient.cs @@ -0,0 +1,72 @@ +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office; + +public partial class Patient +{ + public int PatientId { get; set; } + + public string PolicyNumber { get; set; } = null!; + + public virtual ICollection HospitalAdmissions { get; set; } = new List(); + + public virtual Person PatientNavigation { get; set; } = null!; + + public virtual ICollection Prescriptions { get; set; } = new List(); +} + +internal class PatientWrapper +{ + [Display(Name = "hide")] + public int PatientId { get; set; } + + [Display(Name = "Полис")] + public string PolicyNumber { get; set; } = null!; + + [Display(Name = "Отчество")] + public string LastName { get; set; } = null!; + + [Display(Name = "Имя")] + public string FirstName { get; set; } = null!; + + [Display(Name = "Фамилия")] + public string? MiddleName { get; set; } + + [Display(Name = "Дата рождения")] + public DateOnly BirthDate { get; set; } + + [Display(Name = "Адрес")] + public string Address { get; set; } = null!; + + [Display(Name = "Пол")] + public string Gender { get; set; } = null!; + + public PatientWrapper(Patient src) + { + PatientId = src.PatientId; + PolicyNumber = src.PolicyNumber; + Person p = src.PatientNavigation; + LastName = p.LastName; + FirstName = p.FirstName; + MiddleName = p.MiddleName; + BirthDate = p.BirthDate; + Address = p.Address; + Gender = p.Gender; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (Patient lst in src) + { + res.Add(new PatientWrapper(lst)); + } + + return res; + } +} \ No newline at end of file diff --git a/Register office/Register office/Model/Person.cs b/Register office/Register office/Model/Person.cs new file mode 100644 index 0000000..ff24d7f --- /dev/null +++ b/Register office/Register office/Model/Person.cs @@ -0,0 +1,40 @@ +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office; + +public partial class Person +{ + [Display(Name = "hide")] + public int PersonId { get; set; } + + [Display(Name = "Отчество")] + public string LastName { get; set; } = null!; + + [Display(Name = "Имя")] + public string FirstName { get; set; } = null!; + + [Display(Name = "Фамилия")] + public string? MiddleName { get; set; } + + [Display(Name = "Дата рождения")] + public DateOnly BirthDate { get; set; } + + [Display(Name = "Адрес")] + public string Address { get; set; } = null!; + + [Display(Name = "Пол")] + public string Gender { get; set; } = null!; + + [Browsable(false)] + public virtual Doctor? Doctor { get; set; } + + [Browsable(false)] + public virtual Patient? Patient { get; set; } + + [Browsable(false)] + public virtual Registrar? Registrar { get; set; } +} diff --git a/Register office/Register office/Model/Prescription.cs b/Register office/Register office/Model/Prescription.cs new file mode 100644 index 0000000..202992e --- /dev/null +++ b/Register office/Register office/Model/Prescription.cs @@ -0,0 +1,65 @@ +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office; + +public partial class Prescription : IUnionId +{ + public object GetId() => PrescriptionId; + + public int PrescriptionId { get; set; } + + public int PatientId { get; set; } + + public int DoctorId { get; set; } + + public virtual Doctor Doctor { get; set; } = null!; + + public virtual DrugTypePrescription? DrugTypePrescription { get; set; } + + public virtual ExaminationTypePrescription? ExaminationTypePrescription { get; set; } + + public virtual Patient Patient { get; set; } = null!; + + public virtual ProcedureTypePrescription? ProcedureTypePrescription { get; set; } +} + +internal class PrescriptionWrapper +{ + [Display(Name = "hide")] + public int PrescriptionId { get; set; } + + [Display(Name = "hide")] + public int PatientId { get; set; } + + [Display(Name = "hide")] + public int DoctorId { get; set; } + + [Display(Name = "Пациент")] + public string PatientName { get; set; } = null!; + + public PrescriptionWrapper(Prescription src) + { + PrescriptionId = src.PrescriptionId; + PatientId = src.PatientId; + DoctorId = src.DoctorId; + Person p = src.Patient.PatientNavigation; + PatientName = p.LastName + " " + p.FirstName + " " + p.MiddleName; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (Prescription lst in src) + { + res.Add(new PrescriptionWrapper(lst)); + } + + return res; + } +} diff --git a/Register office/Register office/Model/ProcedureType.cs b/Register office/Register office/Model/ProcedureType.cs new file mode 100644 index 0000000..6ebe6d3 --- /dev/null +++ b/Register office/Register office/Model/ProcedureType.cs @@ -0,0 +1,22 @@ +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office; + +public partial class ProcedureType : IUnionId +{ + public object GetId() => ProcedureTypeId; + + [Display(Name = "hide")] + public int ProcedureTypeId { get; set; } + + [Display(Name = "Название")] + public string Name { get; set; } = null!; + + [Browsable(false)] + public virtual ICollection ProcedureTypePrescriptions { get; set; } = new List(); +} diff --git a/Register office/Register office/Model/ProcedureTypePrescription.cs b/Register office/Register office/Model/ProcedureTypePrescription.cs new file mode 100644 index 0000000..2c77aba --- /dev/null +++ b/Register office/Register office/Model/ProcedureTypePrescription.cs @@ -0,0 +1,64 @@ +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office; + +public partial class ProcedureTypePrescription : IUnionId +{ + public object GetId() => ProcedurePrescriptionId; + + public int ProcedurePrescriptionId { get; set; } + + public int PrescriptionId { get; set; } + + public int ProcedureTypeId { get; set; } + + public DateTime ScheduledDatetime { get; set; } + + public virtual Prescription Prescription { get; set; } = null!; + + public virtual ProcedureType ProcedureType { get; set; } = null!; +} + +internal class ProcedureTypePrescriptionWrapper +{ + [Display(Name = "hide")] + public int ProcedurePrescriptionId { get; set; } + + [Display(Name = "hide")] + public int PrescriptionId { get; set; } + + [Display(Name = "hide")] + public int ProcedureTypeId { get; set; } + + [Display(Name = "Запланированное время")] + public DateTime ScheduledDatetime { get; set; } + + [Display(Name = "Процедура")] + public string ProcedureName { get; set; } = null!; + + public ProcedureTypePrescriptionWrapper(ProcedureTypePrescription src) + { + ProcedurePrescriptionId = src.ProcedurePrescriptionId; + PrescriptionId = src.PrescriptionId; + ProcedureTypeId = src.ProcedureTypeId; + ScheduledDatetime = src.ScheduledDatetime; + ProcedureName = src.ProcedureType.Name; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (ProcedureTypePrescription lst in src) + { + res.Add(new ProcedureTypePrescriptionWrapper(lst)); + } + + return res; + } +} diff --git a/Register office/Register office/Model/QualitativeResult.cs b/Register office/Register office/Model/QualitativeResult.cs new file mode 100644 index 0000000..99f33a1 --- /dev/null +++ b/Register office/Register office/Model/QualitativeResult.cs @@ -0,0 +1,16 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; + +namespace Register_office.Model; + +public partial class QualitativeResult : IUnionId +{ + public object GetId() => ResultId; + + public int ResultId { get; set; } + + public bool Value { get; set; } + + public virtual Result Result { get; set; } = null!; +} diff --git a/Register office/Register office/Model/ReferenceNumericValue.cs b/Register office/Register office/Model/ReferenceNumericValue.cs new file mode 100644 index 0000000..59ffe1c --- /dev/null +++ b/Register office/Register office/Model/ReferenceNumericValue.cs @@ -0,0 +1,63 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class ReferenceNumericValue : IUnionId +{ + public object GetId() => ReferenceValueId; + + public int ReferenceValueId { get; set; } + + public decimal? MinValue { get; set; } + + public decimal? MaxValue { get; set; } + + public int UnitId { get; set; } + + public virtual ReferenceValue ReferenceValue { get; set; } = null!; + + public virtual Unit Unit { get; set; } = null!; +} + +internal class ReferenceNumericValueWrapper +{ + [Display(Name = "hide")] + public int ReferenceValueId { get; set; } + + [Display(Name = "Мин.")] + public decimal? MinValue { get; set; } + + [Display(Name = "Макс.")] + public decimal? MaxValue { get; set; } + + [Display(Name = "hide")] + public int UnitId { get; set; } + + [Display(Name = "Единица изм.")] + public string UnitName { get; set; } = null!; + + public ReferenceNumericValueWrapper(ReferenceNumericValue src) + { + ReferenceValueId = src.ReferenceValueId; + MinValue = src.MinValue; + MaxValue = src.MaxValue; + UnitId = src.UnitId; + UnitName = src.Unit.Name; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (ReferenceNumericValue lst in src) + { + res.Add(new ReferenceNumericValueWrapper(lst)); + } + + return res; + } +} diff --git a/Register office/Register office/Model/ReferenceQualitativeValue.cs b/Register office/Register office/Model/ReferenceQualitativeValue.cs new file mode 100644 index 0000000..e0adeb5 --- /dev/null +++ b/Register office/Register office/Model/ReferenceQualitativeValue.cs @@ -0,0 +1,24 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class ReferenceQualitativeValue : IUnionId +{ + public object GetId() => ReferenceValueId; + + [Display(Name = "hide")] + public int ReferenceValueId { get; set; } + + [Display(Name = "Опис. наличия")] + public string DescriptionTrue { get; set; } = null!; + + [Display(Name = "Опис. отсутствия")] + public string DescriptionFalse { get; set; } = null!; + + [Browsable(false)] + public virtual ReferenceValue ReferenceValue { get; set; } = null!; +} diff --git a/Register office/Register office/Model/ReferenceValue.cs b/Register office/Register office/Model/ReferenceValue.cs new file mode 100644 index 0000000..07d9250 --- /dev/null +++ b/Register office/Register office/Model/ReferenceValue.cs @@ -0,0 +1,71 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class ReferenceValue : IUnionId +{ + public object GetId() => ReferenceValueId; + + public int ReferenceValueId { get; set; } + + public int ExaminationTypeId { get; set; } + + public int? AgeMin { get; set; } + + public int? AgeMax { get; set; } + + public string Gender { get; set; } = null!; + + public virtual ExaminationType ExaminationType { get; set; } = null!; + + public virtual ReferenceNumericValue? ReferenceNumericValue { get; set; } + + public virtual ReferenceQualitativeValue? ReferenceQualitativeValue { get; set; } +} + +internal class ReferenceValueWrapper +{ + [Display(Name = "hide")] + public int ReferenceValueId { get; set; } + + [Display(Name = "hide")] + public int ExaminationTypeId { get; set; } + + [Display(Name = "Мин. возраст")] + public int? AgeMin { get; set; } + + [Display(Name = "Макс. возраст")] + public int? AgeMax { get; set; } + + [Display(Name = "Обследование")] + public string ExaminationName { get; set; } = null!; + + [Display(Name = "Пол")] + public string Gender { get; set; } = null!; + + public ReferenceValueWrapper(ReferenceValue src) + { + ReferenceValueId = src.ReferenceValueId; + ExaminationTypeId = src.ExaminationTypeId; + AgeMin = src.AgeMin; + AgeMax = src.AgeMax; + ExaminationName = src.ExaminationType.Name; + Gender = src.Gender; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (ReferenceValue lst in src) + { + res.Add(new ReferenceValueWrapper(lst)); + } + + return res; + } +} diff --git a/Register office/Register office/Model/Registrar.cs b/Register office/Register office/Model/Registrar.cs new file mode 100644 index 0000000..ec897d4 --- /dev/null +++ b/Register office/Register office/Model/Registrar.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class Registrar +{ + [Display(Name = "hide")] + public int RegistrarId { get; set; } + + [Display(Name = "Данные")] + public virtual Person RegistrarNavigation { get; set; } = null!; +} diff --git a/Register office/Register office/Model/Result.cs b/Register office/Register office/Model/Result.cs new file mode 100644 index 0000000..a499a72 --- /dev/null +++ b/Register office/Register office/Model/Result.cs @@ -0,0 +1,61 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class Result : IUnionId +{ + public object GetId() => ResultId; + + public int ResultId { get; set; } + + public int ExaminationId { get; set; } + + public virtual ExaminationType Examination { get; set; } = null!; + + public virtual ICollection ExaminationTypePrescriptions { get; set; } = new List(); + + public virtual NumericResult? NumericResult { get; set; } + + public virtual QualitativeResult? QualitativeResult { get; set; } +} + +internal class ResultWrapper +{ + [Display(Name = "hide")] + public int ResultId { get; set; } + + [Display(Name = "hide")] + public int ExaminationId { get; set; } + + [Display(Name = "Обследование")] + public string Examination { get; set; } = null!; + + [Display(Name = "Результат")] + public string Result { get; set; } = null!; + + public ResultWrapper(Result src) + { + ResultId = src.ResultId; + ExaminationId = src.ExaminationId; + Examination = src.Examination.Name; + Result = src.NumericResult != null + ? src.NumericResult.Value + " " + src.NumericResult.Unit + : (src.QualitativeResult?.Value == true ? "Положительный" : "Отрициательный"); + } + + internal static List ToList(List src) + { + List res = []; + + foreach (Result lst in src) + { + res.Add(new ResultWrapper(lst)); + } + + return res; + } +} diff --git a/Register office/Register office/Model/SyndromeExaminationType.cs b/Register office/Register office/Model/SyndromeExaminationType.cs new file mode 100644 index 0000000..035d57c --- /dev/null +++ b/Register office/Register office/Model/SyndromeExaminationType.cs @@ -0,0 +1,55 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class SyndromeExaminationType : IUnionId +{ + public object GetId() => string.Concat(SyndromeId, ExaminationTypeId); + + public int SyndromeId { get; set; } + + public int ExaminationTypeId { get; set; } + + public virtual ExaminationType ExaminationType { get; set; } = null!; + + public virtual SyndromeType Syndrome { get; set; } = null!; +} + +internal class SyndromeExaminationTypeWrapper +{ + [Display(Name = "hide")] + public int SyndromeId { get; set; } + + [Display(Name = "hide")] + public int ExaminationTypeId { get; set; } + + [Display(Name = "Синдром")] + public string SyndromeName { get; set; } = null!; + + [Display(Name = "Обследование")] + public string ExaminationName { get; set; } = null!; + + public SyndromeExaminationTypeWrapper(SyndromeExaminationType src) + { + SyndromeId = src.SyndromeId; + ExaminationTypeId = src.ExaminationTypeId; + SyndromeName = src.Syndrome.Name; + ExaminationName = src.ExaminationType.Name; + } + + internal static List ToList(List src) + { + List res = []; + + foreach (SyndromeExaminationType lst in src) + { + res.Add(new SyndromeExaminationTypeWrapper(lst)); + } + + return res; + } +} diff --git a/Register office/Register office/Model/SyndromeType.cs b/Register office/Register office/Model/SyndromeType.cs new file mode 100644 index 0000000..d797ee5 --- /dev/null +++ b/Register office/Register office/Model/SyndromeType.cs @@ -0,0 +1,24 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class SyndromeType : IUnionId +{ + public object GetId() => SyndromeTypeId; + + [Display(Name = "hide")] + public int SyndromeTypeId { get; set; } + + [Display(Name = "Название")] + public string Name { get; set; } = null!; + + [Browsable(false)] + public virtual ICollection DiseaseSyndromes { get; set; } = new List(); + + [Browsable(false)] + public virtual SyndromeExaminationType? SyndromeExaminationType { get; set; } +} diff --git a/Register office/Register office/Model/Unit.cs b/Register office/Register office/Model/Unit.cs new file mode 100644 index 0000000..cb6b1b6 --- /dev/null +++ b/Register office/Register office/Model/Unit.cs @@ -0,0 +1,27 @@ +using Register_office.BaseClasses; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Register_office.Model; + +public partial class Unit : IUnionId +{ + public object GetId() => UnitId; + + [Display(Name = "hide")] + public int UnitId { get; set; } + + [Display(Name = "Название")] + public string Name { get; set; } = null!; + + [Browsable(false)] + public virtual ICollection DrugTypePrescriptions { get; set; } = new List(); + + [Browsable(false)] + public virtual ICollection NumericResults { get; set; } = new List(); + + [Browsable(false)] + public virtual ICollection ReferenceNumericValues { get; set; } = new List(); +} diff --git a/Register office/Register office/Program.cs b/Register office/Register office/Program.cs new file mode 100644 index 0000000..27d8a2f --- /dev/null +++ b/Register office/Register office/Program.cs @@ -0,0 +1,57 @@ +using Register_office.Properties; +using Register_office.View.LoginV; +using Register_office.View.MenuV; +using Register_office.View.RegistrationV; +using Register_office.ViewModel; + +namespace Register_office +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + if (!Init()) return; + Application.Run(new LoginForm()); + } + + private static bool Init() + { + GeneralViewModel.Instance.Initialize(); + while (!RegisterOfficeFactory.CanConnect) + { + MessageBox.Show(" ! " + + " ", + " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + + ConnectionParametersForm form = new(); + + { + form.tbHost.Text = Settings.Default.Host; + form.tbDataBase.Text = Settings.Default.Database; + form.tbUsername.Text = Settings.Default.Username; + form.tbPassword.Text = Settings.Default.Password; + } + + + if (form.ShowDialog() == DialogResult.OK) + { + Settings.Default.Host = form.tbHost.Text; + Settings.Default.Database = form.tbDataBase.Text; + Settings.Default.Username = form.tbUsername.Text; + Settings.Default.Password = form.tbPassword.Text; + Settings.Default.Save(); + } + else return false; + GeneralViewModel.Instance.Initialize(); + } + return true; + } + } +} \ No newline at end of file diff --git a/Register office/Register office/Properties/RegisterOfficeContext.cs b/Register office/Register office/Properties/RegisterOfficeContext.cs new file mode 100644 index 0000000..2aef8af --- /dev/null +++ b/Register office/Register office/Properties/RegisterOfficeContext.cs @@ -0,0 +1,556 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Register_office.Model; + +namespace Register_office.Properties; + +public partial class RegisterOfficeContext : DbContext +{ + public RegisterOfficeContext() + { + } + + public RegisterOfficeContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Diseases { get; set; } + + public virtual DbSet DiseaseSyndromes { get; set; } + + public virtual DbSet Doctors { get; set; } + + public virtual DbSet DrugIntakeMethods { get; set; } + + public virtual DbSet DrugTypes { get; set; } + + public virtual DbSet DrugTypePrescriptions { get; set; } + + public virtual DbSet ExaminationTypes { get; set; } + + public virtual DbSet ExaminationTypePrescriptions { get; set; } + + public virtual DbSet HospitalAdmissions { get; set; } + + public virtual DbSet HospitalDischarges { get; set; } + + public virtual DbSet NumericResults { get; set; } + + public virtual DbSet Patients { get; set; } + + public virtual DbSet People { get; set; } + + public virtual DbSet Prescriptions { get; set; } + + public virtual DbSet ProcedureTypes { get; set; } + + public virtual DbSet ProcedureTypePrescriptions { get; set; } + + public virtual DbSet QualitativeResults { get; set; } + + public virtual DbSet ReferenceNumericValues { get; set; } + + public virtual DbSet ReferenceQualitativeValues { get; set; } + + public virtual DbSet ReferenceValues { get; set; } + + public virtual DbSet Registrars { get; set; } + + public virtual DbSet Results { get; set; } + + public virtual DbSet SyndromeExaminationTypes { get; set; } + + public virtual DbSet SyndromeTypes { get; set; } + + public virtual DbSet Units { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) +#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263. + => optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=register_office;Username=postgres;Password=slavik242"); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder + .HasPostgresEnum("examination_categories_enum", new[] { "physical", "laboratory", "instrumental" }) + .HasPostgresEnum("gender_enum", new[] { "male", "female" }) + .HasPostgresEnum("hospital_discharge_reason_enum", new[] { "death", "improvement", "refusal" }) + .HasPostgresEnum("unit_context_enum", new[] { "examination", "medication" }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.DiseaseId).HasName("disease_pkey"); + + entity.ToTable("disease"); + + entity.HasIndex(e => e.IcdCode, "disease_icd_code_key").IsUnique(); + + entity.HasIndex(e => e.Name, "disease_name_key").IsUnique(); + + entity.Property(e => e.DiseaseId).HasColumnName("disease_id"); + entity.Property(e => e.IcdCode).HasColumnName("icd_code"); + entity.Property(e => e.Name).HasColumnName("name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.DiseaseSyndromeId).HasName("disease_syndrome_pkey"); + + entity.ToTable("disease_syndrome"); + + entity.HasIndex(e => new { e.DiseaseId, e.SyndromeId }, "disease_syndrome_disease_id_syndrome_id_key").IsUnique(); + + entity.Property(e => e.DiseaseSyndromeId).HasColumnName("disease_syndrome_id"); + entity.Property(e => e.DiseaseId).HasColumnName("disease_id"); + entity.Property(e => e.SyndromeId).HasColumnName("syndrome_id"); + + entity.HasOne(d => d.Disease).WithMany(p => p.DiseaseSyndromes) + .HasForeignKey(d => d.DiseaseId) + .HasConstraintName("disease_syndrome_disease_id_fkey"); + + entity.HasOne(d => d.Syndrome).WithMany(p => p.DiseaseSyndromes) + .HasForeignKey(d => d.SyndromeId) + .HasConstraintName("disease_syndrome_syndrome_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.DoctorId).HasName("doctor_pkey"); + + entity.ToTable("doctor"); + + entity.Property(e => e.DoctorId) + .ValueGeneratedNever() + .HasColumnName("doctor_id"); + + entity.HasOne(d => d.DoctorNavigation).WithOne(p => p.Doctor) + .HasForeignKey(d => d.DoctorId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("doctor_doctor_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.DrugIntakeMethodId).HasName("drug_intake_method_pkey"); + + entity.ToTable("drug_intake_method"); + + entity.HasIndex(e => e.Name, "drug_intake_method_name_key").IsUnique(); + + entity.Property(e => e.DrugIntakeMethodId).HasColumnName("drug_intake_method_id"); + entity.Property(e => e.Name).HasColumnName("name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.DrugTypeId).HasName("drug_type_pkey"); + + entity.ToTable("drug_type"); + + entity.HasIndex(e => e.BrandNameRu, "drug_type_brand_name_ru_key").IsUnique(); + + entity.HasIndex(e => e.InternationalNameEn, "drug_type_international_name_en_key").IsUnique(); + + entity.HasIndex(e => e.InternationalNameLa, "drug_type_international_name_la_key").IsUnique(); + + entity.HasIndex(e => e.InternationalNameRu, "drug_type_international_name_ru_key").IsUnique(); + + entity.Property(e => e.DrugTypeId).HasColumnName("drug_type_id"); + entity.Property(e => e.BrandNameRu).HasColumnName("brand_name_ru"); + entity.Property(e => e.InternationalNameEn).HasColumnName("international_name_en"); + entity.Property(e => e.InternationalNameLa).HasColumnName("international_name_la"); + entity.Property(e => e.InternationalNameRu).HasColumnName("international_name_ru"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.DrugPrescriptionId).HasName("drug_type_prescription_pkey"); + + entity.ToTable("drug_type_prescription"); + + entity.HasIndex(e => e.PrescriptionId, "drug_type_prescription_prescription_id_key").IsUnique(); + + entity.Property(e => e.DrugPrescriptionId).HasColumnName("drug_prescription_id"); + entity.Property(e => e.Dose).HasColumnName("dose"); + entity.Property(e => e.DoseUnitId).HasColumnName("dose_unit_id"); + entity.Property(e => e.DrugTypeId).HasColumnName("drug_type_id"); + entity.Property(e => e.DurationDays).HasColumnName("duration_days"); + entity.Property(e => e.IntakeMethodId).HasColumnName("intake_method_id"); + entity.Property(e => e.PrescriptionId).HasColumnName("prescription_id"); + + entity.HasOne(d => d.DoseUnit).WithMany(p => p.DrugTypePrescriptions) + .HasForeignKey(d => d.DoseUnitId) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("drug_type_prescription_dose_unit_id_fkey"); + + entity.HasOne(d => d.DrugType).WithMany(p => p.DrugTypePrescriptions) + .HasForeignKey(d => d.DrugTypeId) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("drug_type_prescription_drug_type_id_fkey"); + + entity.HasOne(d => d.IntakeMethod).WithMany(p => p.DrugTypePrescriptions) + .HasForeignKey(d => d.IntakeMethodId) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("drug_type_prescription_intake_method_id_fkey"); + + entity.HasOne(d => d.Prescription).WithOne(p => p.DrugTypePrescription) + .HasForeignKey(d => d.PrescriptionId) + .HasConstraintName("drug_type_prescription_prescription_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ExaminationTypeId).HasName("examination_type_pkey"); + + entity.ToTable("examination_type"); + + entity.HasIndex(e => e.Name, "examination_type_name_key").IsUnique(); + + entity.Property(e => e.ExaminationTypeId).HasColumnName("examination_type_id"); + entity.Property(e => e.Name).HasColumnName("name"); + entity.Property(e => e.Category).HasColumnName("category"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ExaminationPrescriptionId).HasName("examination_type_prescription_pkey"); + + entity.ToTable("examination_type_prescription"); + + entity.HasIndex(e => e.PrescriptionId, "examination_type_prescription_prescription_id_key").IsUnique(); + + entity.Property(e => e.ExaminationPrescriptionId).HasColumnName("examination_prescription_id"); + entity.Property(e => e.ExaminationTypeId).HasColumnName("examination_type_id"); + entity.Property(e => e.PrescriptionId).HasColumnName("prescription_id"); + entity.Property(e => e.ResultId).HasColumnName("result_id"); + + entity.HasOne(d => d.ExaminationType).WithMany(p => p.ExaminationTypePrescriptions) + .HasForeignKey(d => d.ExaminationTypeId) + .HasConstraintName("examination_type_prescription_examination_type_id_fkey"); + + entity.HasOne(d => d.Prescription).WithOne(p => p.ExaminationTypePrescription) + .HasForeignKey(d => d.PrescriptionId) + .HasConstraintName("examination_type_prescription_prescription_id_fkey"); + + entity.HasOne(d => d.Result).WithMany(p => p.ExaminationTypePrescriptions) + .HasForeignKey(d => d.ResultId) + .HasConstraintName("examination_type_prescription_result_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.HospitalAdmissionId).HasName("hospital_admission_pkey"); + + entity.ToTable("hospital_admission"); + + entity.Property(e => e.HospitalAdmissionId).HasColumnName("hospital_admission_id"); + entity.Property(e => e.AdmissionDatetime) + .HasColumnType("timestamp without time zone") + .HasColumnName("admission_datetime"); + entity.Property(e => e.PatientId).HasColumnName("patient_id"); + entity.Property(e => e.PreliminaryDiseaseId).HasColumnName("preliminary_disease_id"); + + entity.HasOne(d => d.Patient).WithMany(p => p.HospitalAdmissions) + .HasForeignKey(d => d.PatientId) + .HasConstraintName("hospital_admission_patient_id_fkey"); + + entity.HasOne(d => d.PreliminaryDisease).WithMany(p => p.HospitalAdmissions) + .HasForeignKey(d => d.PreliminaryDiseaseId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("hospital_admission_preliminary_disease_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.HospitalDischargeId).HasName("hospital_discharge_pkey"); + + entity.ToTable("hospital_discharge"); + + entity.Property(e => e.HospitalDischargeId).HasColumnName("hospital_discharge_id"); + entity.Property(e => e.DischargeDatetime) + .HasColumnType("timestamp without time zone") + .HasColumnName("discharge_datetime"); + entity.Property(e => e.FinalDiseaseId).HasColumnName("final_disease_id"); + entity.Property(e => e.HospitalAdmissionId).HasColumnName("hospital_admission_id"); + entity.Property(e => e.Reason).HasColumnName("reason"); + + entity.HasOne(d => d.FinalDisease).WithMany(p => p.HospitalDischarges) + .HasForeignKey(d => d.FinalDiseaseId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("hospital_discharge_final_disease_id_fkey"); + + entity.HasOne(d => d.HospitalAdmission).WithMany(p => p.HospitalDischarges) + .HasForeignKey(d => d.HospitalAdmissionId) + .HasConstraintName("hospital_discharge_hospital_admission_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ResultId).HasName("numeric_result_pkey"); + + entity.ToTable("numeric_result"); + + entity.Property(e => e.ResultId) + .ValueGeneratedNever() + .HasColumnName("result_id"); + entity.Property(e => e.UnitId).HasColumnName("unit_id"); + entity.Property(e => e.Value).HasColumnName("value"); + + entity.HasOne(d => d.Result).WithOne(p => p.NumericResult) + .HasForeignKey(d => d.ResultId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("numeric_result_result_id_fkey"); + + entity.HasOne(d => d.Unit).WithMany(p => p.NumericResults) + .HasForeignKey(d => d.UnitId) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("numeric_result_unit_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.PatientId).HasName("patient_pkey"); + + entity.ToTable("patient"); + + entity.Property(e => e.PatientId) + .ValueGeneratedNever() + .HasColumnName("patient_id"); + entity.Property(e => e.PolicyNumber).HasColumnName("policy_number"); + + entity.HasOne(d => d.PatientNavigation).WithOne(p => p.Patient) + .HasForeignKey(d => d.PatientId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("patient_patient_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.PersonId).HasName("person_pkey"); + + entity.ToTable("person"); + + entity.Property(e => e.PersonId).HasColumnName("person_id"); + entity.Property(e => e.Address).HasColumnName("address"); + entity.Property(e => e.BirthDate).HasColumnName("birth_date"); + entity.Property(e => e.FirstName).HasColumnName("first_name"); + entity.Property(e => e.LastName).HasColumnName("last_name"); + entity.Property(e => e.MiddleName).HasColumnName("middle_name"); + entity.Property(e => e.Gender).HasColumnName(name: "gender"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.PrescriptionId).HasName("prescription_pkey"); + + entity.ToTable("prescription"); + + entity.Property(e => e.PrescriptionId).HasColumnName("prescription_id"); + entity.Property(e => e.DoctorId).HasColumnName("doctor_id"); + entity.Property(e => e.PatientId).HasColumnName("patient_id"); + + entity.HasOne(d => d.Doctor).WithMany(p => p.Prescriptions) + .HasForeignKey(d => d.DoctorId) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("prescription_doctor_id_fkey"); + + entity.HasOne(d => d.Patient).WithMany(p => p.Prescriptions) + .HasForeignKey(d => d.PatientId) + .HasConstraintName("prescription_patient_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ProcedureTypeId).HasName("procedure_type_pkey"); + + entity.ToTable("procedure_type"); + + entity.HasIndex(e => e.Name, "procedure_type_name_key").IsUnique(); + + entity.Property(e => e.ProcedureTypeId).HasColumnName("procedure_type_id"); + entity.Property(e => e.Name).HasColumnName("name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ProcedurePrescriptionId).HasName("procedure_type_prescription_pkey"); + + entity.ToTable("procedure_type_prescription"); + + entity.HasIndex(e => e.PrescriptionId, "procedure_type_prescription_prescription_id_key").IsUnique(); + + entity.Property(e => e.ProcedurePrescriptionId).HasColumnName("procedure_prescription_id"); + entity.Property(e => e.PrescriptionId).HasColumnName("prescription_id"); + entity.Property(e => e.ProcedureTypeId).HasColumnName("procedure_type_id"); + entity.Property(e => e.ScheduledDatetime) + .HasColumnType("timestamp without time zone") + .HasColumnName("scheduled_datetime"); + + entity.HasOne(d => d.Prescription).WithOne(p => p.ProcedureTypePrescription) + .HasForeignKey(d => d.PrescriptionId) + .HasConstraintName("procedure_type_prescription_prescription_id_fkey"); + + entity.HasOne(d => d.ProcedureType).WithMany(p => p.ProcedureTypePrescriptions) + .HasForeignKey(d => d.ProcedureTypeId) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("procedure_type_prescription_procedure_type_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ResultId).HasName("qualitative_result_pkey"); + + entity.ToTable("qualitative_result"); + + entity.Property(e => e.ResultId) + .ValueGeneratedNever() + .HasColumnName("result_id"); + entity.Property(e => e.Value).HasColumnName("value"); + + entity.HasOne(d => d.Result).WithOne(p => p.QualitativeResult) + .HasForeignKey(d => d.ResultId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("qualitative_result_result_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ReferenceValueId).HasName("reference_numeric_value_pkey"); + + entity.ToTable("reference_numeric_value"); + + entity.Property(e => e.ReferenceValueId) + .ValueGeneratedNever() + .HasColumnName("reference_value_id"); + entity.Property(e => e.MaxValue).HasColumnName("max_value"); + entity.Property(e => e.MinValue).HasColumnName("min_value"); + entity.Property(e => e.UnitId).HasColumnName("unit_id"); + + entity.HasOne(d => d.ReferenceValue).WithOne(p => p.ReferenceNumericValue) + .HasForeignKey(d => d.ReferenceValueId) + .HasConstraintName("reference_numeric_value_reference_value_id_fkey"); + + entity.HasOne(d => d.Unit).WithMany(p => p.ReferenceNumericValues) + .HasForeignKey(d => d.UnitId) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("reference_numeric_value_unit_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ReferenceValueId).HasName("reference_qualitative_value_pkey"); + + entity.ToTable("reference_qualitative_value"); + + entity.HasIndex(e => new { e.DescriptionTrue, e.DescriptionFalse }, "reference_qualitative_value_description_true_description_fa_key").IsUnique(); + + entity.Property(e => e.ReferenceValueId) + .ValueGeneratedNever() + .HasColumnName("reference_value_id"); + entity.Property(e => e.DescriptionFalse).HasColumnName("description_false"); + entity.Property(e => e.DescriptionTrue).HasColumnName("description_true"); + + entity.HasOne(d => d.ReferenceValue).WithOne(p => p.ReferenceQualitativeValue) + .HasForeignKey(d => d.ReferenceValueId) + .HasConstraintName("reference_qualitative_value_reference_value_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ReferenceValueId).HasName("reference_value_pkey"); + + entity.ToTable("reference_value"); + + entity.Property(e => e.ReferenceValueId).HasColumnName("reference_value_id"); + entity.Property(e => e.AgeMax).HasColumnName("age_max"); + entity.Property(e => e.AgeMin).HasColumnName("age_min"); + entity.Property(e => e.ExaminationTypeId).HasColumnName("examination_type_id"); + entity.Property(e => e.Gender).HasColumnName("gender"); + + entity.HasOne(d => d.ExaminationType).WithMany(p => p.ReferenceValues) + .HasForeignKey(d => d.ExaminationTypeId) + .HasConstraintName("reference_value_examination_type_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.RegistrarId).HasName("registrar_pkey"); + + entity.ToTable("registrar"); + + entity.Property(e => e.RegistrarId) + .ValueGeneratedNever() + .HasColumnName("registrar_id"); + + entity.HasOne(d => d.RegistrarNavigation).WithOne(p => p.Registrar) + .HasForeignKey(d => d.RegistrarId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("registrar_registrar_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ResultId).HasName("result_pkey"); + + entity.ToTable("result"); + + entity.Property(e => e.ResultId).HasColumnName("result_id"); + entity.Property(e => e.ExaminationId).HasColumnName("examination_id"); + + entity.HasOne(d => d.Examination).WithOne(p => p.Result) + .HasForeignKey(d => d.ExaminationId) + .HasConstraintName("result_examination_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.SyndromeId).HasName("syndrome_examination_type_pkey"); + + entity.ToTable("syndrome_examination_type"); + + entity.HasIndex(e => e.ExaminationTypeId, "syndrome_examination_type_examination_type_id_key").IsUnique(); + + entity.Property(e => e.SyndromeId) + .ValueGeneratedNever() + .HasColumnName("syndrome_id"); + entity.Property(e => e.ExaminationTypeId).HasColumnName("examination_type_id"); + + entity.HasOne(d => d.ExaminationType).WithOne(p => p.SyndromeExaminationType) + .HasForeignKey(d => d.ExaminationTypeId) + .HasConstraintName("syndrome_examination_type_examination_type_id_fkey"); + + entity.HasOne(d => d.Syndrome).WithOne(p => p.SyndromeExaminationType) + .HasForeignKey(d => d.SyndromeId) + .HasConstraintName("syndrome_examination_type_syndrome_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.SyndromeTypeId).HasName("syndrome_type_pkey"); + + entity.ToTable("syndrome_type"); + + entity.HasIndex(e => e.Name, "syndrome_type_name_key").IsUnique(); + + entity.Property(e => e.SyndromeTypeId).HasColumnName("syndrome_type_id"); + entity.Property(e => e.Name).HasColumnName("name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.UnitId).HasName("unit_pkey"); + + entity.ToTable("unit"); + + entity.HasIndex(e => e.Name, "unit_name_key").IsUnique(); + + entity.Property(e => e.UnitId).HasColumnName("unit_id"); + entity.Property(e => e.Name).HasColumnName("name"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/Register office/Register office/Properties/RegisterOfficeFactory.cs b/Register office/Register office/Properties/RegisterOfficeFactory.cs new file mode 100644 index 0000000..2bd09a4 --- /dev/null +++ b/Register office/Register office/Properties/RegisterOfficeFactory.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore; +using Npgsql; +using Register_office.Properties; + +namespace Register_office.Properties +{ + internal class RegisterOfficeFactory + { + internal static bool CanConnect = false; + internal static RegisterOfficeContext Create(string username, string password) + { + var builder = new NpgsqlConnectionStringBuilder() + { + Host = Settings.Default.Host, + Database = Settings.Default.Database, + Username = username, + Password = password + }; + + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder.UseNpgsql(builder.ToString()); + + RegisterOfficeContext dbContext = new(optionsBuilder.Options); + CanConnect = dbContext.Database.CanConnect(); + + return dbContext; + } + } +} diff --git a/Register office/Register office/Properties/Settings.Designer.cs b/Register office/Register office/Properties/Settings.Designer.cs new file mode 100644 index 0000000..bb72def --- /dev/null +++ b/Register office/Register office/Properties/Settings.Designer.cs @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Register_office.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Host { + get { + return ((string)(this["Host"])); + } + set { + this["Host"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Database { + get { + return ((string)(this["Database"])); + } + set { + this["Database"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Username { + get { + return ((string)(this["Username"])); + } + set { + this["Username"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Password { + get { + return ((string)(this["Password"])); + } + set { + this["Password"] = value; + } + } + } +} diff --git a/Register office/Register office/Properties/Settings.settings b/Register office/Register office/Properties/Settings.settings new file mode 100644 index 0000000..d321c32 --- /dev/null +++ b/Register office/Register office/Properties/Settings.settings @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Register office/Register office/Register office.csproj b/Register office/Register office/Register office.csproj new file mode 100644 index 0000000..e8b7d0e --- /dev/null +++ b/Register office/Register office/Register office.csproj @@ -0,0 +1,91 @@ + + + + WinExe + net8.0-windows + Register_office + enable + true + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + True + True + Settings.settings + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + \ No newline at end of file diff --git a/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.Designer.cs b/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.Designer.cs new file mode 100644 index 0000000..0bdcca5 --- /dev/null +++ b/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.Designer.cs @@ -0,0 +1,158 @@ +namespace Register_office.View.TypesV +{ + partial class HospitalDischargeDataForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + cbDisease = new ComboBox(); + label1 = new Label(); + button2 = new Button(); + btnOK = new Button(); + dtpDischarge = new DateTimePicker(); + label6 = new Label(); + rtbReason = new RichTextBox(); + label2 = new Label(); + SuspendLayout(); + // + // cbDisease + // + cbDisease.DropDownStyle = ComboBoxStyle.DropDownList; + cbDisease.Font = new Font("Segoe UI", 12F); + cbDisease.FormattingEnabled = true; + cbDisease.Items.AddRange(new object[] { "Числовой", "Качественный" }); + cbDisease.Location = new Point(12, 37); + cbDisease.Name = "cbDisease"; + cbDisease.Size = new Size(341, 29); + cbDisease.TabIndex = 24; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(186, 25); + label1.TabIndex = 25; + label1.Text = "Финальный диагноз"; + // + // button2 + // + button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + button2.DialogResult = DialogResult.Cancel; + button2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + button2.Location = new Point(192, 271); + button2.Name = "button2"; + button2.Size = new Size(161, 42); + button2.TabIndex = 27; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // + // btnOK + // + btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + btnOK.DialogResult = DialogResult.OK; + btnOK.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnOK.Location = new Point(12, 271); + btnOK.Name = "btnOK"; + btnOK.Size = new Size(161, 42); + btnOK.TabIndex = 26; + btnOK.Text = "Добавить"; + btnOK.UseVisualStyleBackColor = true; + btnOK.Click += btnOK_Click; + // + // dtpDischarge + // + dtpDischarge.CustomFormat = "HH:mm dd.MM.yyyy"; + dtpDischarge.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + dtpDischarge.Format = DateTimePickerFormat.Custom; + dtpDischarge.Location = new Point(9, 97); + dtpDischarge.MinDate = new DateTime(1940, 1, 1, 0, 0, 0, 0); + dtpDischarge.Name = "dtpDischarge"; + dtpDischarge.Size = new Size(164, 29); + dtpDischarge.TabIndex = 28; + // + // label6 + // + label6.AutoSize = true; + label6.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label6.Location = new Point(9, 69); + label6.Name = "label6"; + label6.Size = new Size(164, 25); + label6.TabIndex = 29; + label6.Text = "Дата завершения"; + // + // rtbReason + // + rtbReason.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + rtbReason.Location = new Point(9, 157); + rtbReason.Name = "rtbReason"; + rtbReason.Size = new Size(341, 96); + rtbReason.TabIndex = 30; + rtbReason.Text = ""; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(9, 129); + label2.Name = "label2"; + label2.Size = new Size(202, 25); + label2.TabIndex = 31; + label2.Text = "Причина завершения"; + // + // HospitalDischargeDataForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(365, 325); + Controls.Add(label2); + Controls.Add(rtbReason); + Controls.Add(dtpDischarge); + Controls.Add(label6); + Controls.Add(button2); + Controls.Add(btnOK); + Controls.Add(cbDisease); + Controls.Add(label1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "HospitalDischargeDataForm"; + Text = "Завершение госпитализации"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + internal ComboBox cbDisease; + private Label label1; + private Button button2; + internal Button btnOK; + internal DateTimePicker dtpDischarge; + private Label label6; + private RichTextBox rtbReason; + private Label label2; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.cs b/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.cs new file mode 100644 index 0000000..23e303a --- /dev/null +++ b/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.cs @@ -0,0 +1,81 @@ +using Microsoft.EntityFrameworkCore; +using Register_office.Model; +using Register_office.ViewModel; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Register_office.View.TypesV +{ + public partial class HospitalDischargeDataForm : Form + { + private HospitalViewModel _viewModel; + private HospitalAdmission _hospitalAdmission; + + public HospitalDischargeDataForm(HospitalAdmission h, bool isForAdd = true) + { + Init(); + _hospitalAdmission = h; + if (!isForAdd) SetData(h); + } + + private void Init() + { + InitializeComponent(); + TopMost = true; + _viewModel = new(); + SetDataSourceToComboBoxes(); + dtpDischarge.Value = + dtpDischarge.MaxDate = DateTime.Now; + } + + private void SetData(HospitalAdmission ha) + { + HospitalDischarge hd = _viewModel.GetHospitalDischarge() + .First(x => x.HospitalAdmissionId == ha.HospitalAdmissionId); + cbDisease.SelectedValue = hd.FinalDiseaseId; + rtbReason.Text = hd.Reason; + dtpDischarge.Value = hd.DischargeDatetime; + + Text = "Просмотр завершения госпитализации"; + btnOK.Visible = cbDisease.Enabled = + rtbReason.Enabled = dtpDischarge.Enabled = false; + } + + private void SetDataSourceToComboBoxes() + { + cbDisease.DataSource = _viewModel.General.Context.Diseases + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.DiseaseId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbDisease.DisplayMember = "Name"; + cbDisease.ValueMember = "Id"; + } + + private void btnOK_Click(object sender, EventArgs e) + { + HospitalDischarge hd = new() + { + HospitalAdmissionId = _hospitalAdmission.HospitalAdmissionId, + DischargeDatetime = dtpDischarge.Value, + FinalDiseaseId = int.Parse(cbDisease.SelectedValue?.ToString() ?? "-1"), + Reason = rtbReason.Text + }; + if (_viewModel.AddHospital(hd) == -1) + { + DialogResult = DialogResult.None; + return; + } + + MessageBox.Show("Госпитализация успешно завершена", "Завершение госпитализации", + MessageBoxButtons.OK, MessageBoxIcon.Information); + Close(); + + } + } +} diff --git a/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.resx b/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/HospitalV/HospitalDischargeDataForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/HospitalV/HospitalForm.Designer.cs b/Register office/Register office/View/HospitalV/HospitalForm.Designer.cs new file mode 100644 index 0000000..19d6cec --- /dev/null +++ b/Register office/Register office/View/HospitalV/HospitalForm.Designer.cs @@ -0,0 +1,263 @@ +using Register_office.View; + +namespace Register_office.View.PatientV +{ + partial class HospitalForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + dtpArrive = new DateTimePicker(); + label6 = new Label(); + label3 = new Label(); + cbDisease = new ComboBox(); + label2 = new Label(); + cbPatient = new ComboBox(); + btnAddHospitalAdmission = new Button(); + btnUpdate = new Button(); + btnDelete = new Button(); + btnHospitalDischarge = new Button(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(dtpArrive); + splitContainer1.Panel1.Controls.Add(label6); + splitContainer1.Panel1.Controls.Add(label3); + splitContainer1.Panel1.Controls.Add(cbDisease); + splitContainer1.Panel1.Controls.Add(label2); + splitContainer1.Panel1.Controls.Add(cbPatient); + splitContainer1.Panel1.Controls.Add(btnAddHospitalAdmission); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnHospitalDischarge); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 125; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // dtpArrive + // + dtpArrive.CustomFormat = "HH:mm dd.MM.yyyy"; + dtpArrive.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + dtpArrive.Format = DateTimePickerFormat.Custom; + dtpArrive.Location = new Point(232, 78); + dtpArrive.MinDate = new DateTime(1940, 1, 1, 0, 0, 0, 0); + dtpArrive.Name = "dtpArrive"; + dtpArrive.Size = new Size(139, 25); + dtpArrive.TabIndex = 19; + // + // label6 + // + label6.AutoSize = true; + label6.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label6.Location = new Point(232, 58); + label6.Name = "label6"; + label6.Size = new Size(114, 17); + label6.TabIndex = 20; + label6.Text = "Дата поступления"; + // + // label3 + // + label3.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(12, 58); + label3.Name = "label3"; + label3.Size = new Size(127, 17); + label3.TabIndex = 18; + label3.Text = "Предварит. диагноз"; + // + // cbDisease + // + cbDisease.DropDownStyle = ComboBoxStyle.DropDownList; + cbDisease.FormattingEnabled = true; + cbDisease.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbDisease.Location = new Point(12, 78); + cbDisease.Name = "cbDisease"; + cbDisease.Size = new Size(211, 25); + cbDisease.TabIndex = 17; + // + // label2 + // + label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(12, 9); + label2.Name = "label2"; + label2.Size = new Size(57, 17); + label2.TabIndex = 16; + label2.Text = "Пациент"; + // + // cbPatient + // + cbPatient.DropDownStyle = ComboBoxStyle.DropDownList; + cbPatient.FormattingEnabled = true; + cbPatient.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbPatient.Location = new Point(12, 30); + cbPatient.Name = "cbPatient"; + cbPatient.Size = new Size(214, 25); + cbPatient.TabIndex = 15; + // + // btnAddHospitalAdmission + // + btnAddHospitalAdmission.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAddHospitalAdmission.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAddHospitalAdmission.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAddHospitalAdmission.Location = new Point(455, 73); + btnAddHospitalAdmission.Name = "btnAddHospitalAdmission"; + btnAddHospitalAdmission.Size = new Size(333, 33); + btnAddHospitalAdmission.TabIndex = 12; + btnAddHospitalAdmission.Text = "Добавить"; + btnAddHospitalAdmission.UseVisualStyleBackColor = true; + btnAddHospitalAdmission.Click += btnAddHospitalAdmission_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(455, 25); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(169, 33); + btnUpdate.TabIndex = 11; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(630, 25); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(158, 33); + btnDelete.TabIndex = 10; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnHospitalDischarge + // + btnHospitalDischarge.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnHospitalDischarge.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnHospitalDischarge.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnHospitalDischarge.Location = new Point(232, 25); + btnHospitalDischarge.Name = "btnHospitalDischarge"; + btnHospitalDischarge.Size = new Size(217, 33); + btnHospitalDischarge.TabIndex = 7; + btnHospitalDischarge.Text = "Завершить госпитализацию"; + btnHospitalDischarge.UseVisualStyleBackColor = true; + btnHospitalDischarge.Click += btnHospitalDischarge_Click; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 517); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // HospitalForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "HospitalForm"; + Text = "Госпитализации"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Button btnHospitalDischarge; + private Button btnDelete; + private Button btnAddHospitalAdmission; + private Button btnUpdate; + private Label label3; + private ComboBox cbDisease; + private Label label2; + private ComboBox cbPatient; + internal DateTimePicker dtpArrive; + private Label label6; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/HospitalV/HospitalForm.cs b/Register office/Register office/View/HospitalV/HospitalForm.cs new file mode 100644 index 0000000..18fb949 --- /dev/null +++ b/Register office/Register office/View/HospitalV/HospitalForm.cs @@ -0,0 +1,156 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.View.TypesV; +using Register_office.ViewModel; +using System.Data; +using System.Xml.Linq; + +namespace Register_office.View.PatientV +{ + public partial class HospitalForm : Form + { + private HospitalViewModel _viewModel; + private HospitalAdmission? _selectedHospital; + private string _columnIdName = "HospitalAdmissionId"; + + public HospitalForm() + { + Init(); + } + + public HospitalForm(Patient patient) + { + Init(); + dgv.DataSource = new SortableBindingList( + HospitalAdmissionWrapper.ToList(_viewModel.GetHospitalAdmission() + .Where(x => x.PatientId == patient.PatientId) + .ToList())); + } + + private void Init() + { + InitializeComponent(); + TopMost = true; + Text = "Госпитализации"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + dtpArrive.Value = + dtpArrive.MaxDate = DateTime.Now; + SetDataSourceToComboBoxes(); + UpdateDgv(); + UpdateElements(); + } + + private void SetDataSourceToComboBoxes() + { + cbDisease.DataSource = _viewModel.General.Context.Diseases + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.DiseaseId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbDisease.DisplayMember = "Name"; + cbDisease.ValueMember = "Id"; + + cbPatient.DataSource = _viewModel.General.Context.Patients + .Include(x => x.PatientNavigation) + .Select(x => new ComboBoxItem + { + Name = x.PatientNavigation.FirstName + " " + + x.PatientNavigation.FirstName + " " + + x.PatientNavigation.LastName, + Id = x.PatientId + }) + .OrderBy(cbi => cbi.Name).ToList(); + cbPatient.DisplayMember = "Name"; + cbPatient.ValueMember = "Id"; + } + + private void UpdateElements(bool enableButtons = false) + { + if (_selectedHospital != null) + { + cbPatient.SelectedValue = _selectedHospital.PatientId; + cbDisease.SelectedValue = _selectedHospital.PreliminaryDiseaseId; + dtpArrive.Value = _selectedHospital.AdmissionDatetime; + btnHospitalDischarge.Enabled = true; + btnHospitalDischarge.Text = _selectedHospital.HospitalDischarges.Any() + ? "Результаты госпитализации" + : "Завершить госпитализацию"; + } + + btnDelete.Enabled = btnUpdate.Enabled = btnHospitalDischarge.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedHospital = _viewModel.GetHospitalAdmission(id).FirstOrDefault(); + if (_selectedHospital != null) + UpdateElements(true); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedHospital != null) + { + _viewModel.DeleteHospital(_selectedHospital); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedHospital != null) + { + _selectedHospital.PatientId = int.Parse(cbPatient.SelectedValue?.ToString() ?? "-1"); + _selectedHospital.PreliminaryDiseaseId = int.Parse(cbDisease.SelectedValue?.ToString() ?? "-1"); + _selectedHospital.AdmissionDatetime = dtpArrive.Value; + _viewModel.Update(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAddHospitalAdmission_Click(object sender, EventArgs e) + { + HospitalAdmission _temp = new() + { + PatientId = int.Parse(cbPatient.SelectedValue?.ToString() ?? "-1"), + PreliminaryDiseaseId = int.Parse(cbDisease.SelectedValue?.ToString() ?? "-1"), + AdmissionDatetime = dtpArrive.Value + }; + _viewModel.AddHospital(_temp); + UpdateElements(); + UpdateDgv(); + } + + private void btnHospitalDischarge_Click(object sender, EventArgs e) + { + HospitalDischargeDataForm hdf; + + if (_selectedHospital.HospitalDischarges.Any()) + { + hdf = new(_selectedHospital, false); + hdf.ShowDialog(); + } + else + { + hdf = new(_selectedHospital); + if (hdf.ShowDialog() == DialogResult.OK) + { + btnHospitalDischarge.Text = "Результаты госпитализации"; + } + } + + } + } +} diff --git a/Register office/Register office/View/HospitalV/HospitalForm.resx b/Register office/Register office/View/HospitalV/HospitalForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/HospitalV/HospitalForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/MenuV/OnlyMenuForm.Designer.cs b/Register office/Register office/View/MenuV/OnlyMenuForm.Designer.cs new file mode 100644 index 0000000..a768e75 --- /dev/null +++ b/Register office/Register office/View/MenuV/OnlyMenuForm.Designer.cs @@ -0,0 +1,237 @@ +namespace Register_office.View.MenuV +{ + partial class OnlyMenuForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + лекарстваToolStripMenuItem = new ToolStripMenuItem(); + способыприемалекарствToolStripMenuItem = new ToolStripMenuItem(); + заболеваниеToolStripMenuItem1 = new ToolStripMenuItem(); + процедурыToolStripMenuItem = new ToolStripMenuItem(); + синдромыToolStripMenuItem = new ToolStripMenuItem(); + соответствиеЗаболеванийИСиндромовToolStripMenuItem = new ToolStripMenuItem(); + обследованияToolStripMenuItem = new ToolStripMenuItem(); + нормалиОбследованийToolStripMenuItem = new ToolStripMenuItem(); + CоответствиеСиндромовИОбследованийToolStripMenuItem = new ToolStripMenuItem(); + единицыИзмеренияToolStripMenuItem = new ToolStripMenuItem(); + сотрудникиToolStripMenuItem = new ToolStripMenuItem(); + пациентыToolStripMenuItem = new ToolStripMenuItem(); + добавитьПациентаToolStripMenuItem = new ToolStripMenuItem(); + toolStripSeparator1 = new ToolStripSeparator(); + назначенияToolStripMenuItem = new ToolStripMenuItem(); + госпитализацииToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + результатыАнализовToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, сотрудникиToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 33); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { лекарстваToolStripMenuItem, способыприемалекарствToolStripMenuItem, заболеваниеToolStripMenuItem1, процедурыToolStripMenuItem, синдромыToolStripMenuItem, соответствиеЗаболеванийИСиндромовToolStripMenuItem, обследованияToolStripMenuItem, нормалиОбследованийToolStripMenuItem, CоответствиеСиндромовИОбследованийToolStripMenuItem, единицыИзмеренияToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(142, 29); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // лекарстваToolStripMenuItem + // + лекарстваToolStripMenuItem.Name = "лекарстваToolStripMenuItem"; + лекарстваToolStripMenuItem.Size = new Size(462, 30); + лекарстваToolStripMenuItem.Text = "Лекарства..."; + лекарстваToolStripMenuItem.Click += лекарстваToolStripMenuItem_Click; + // + // способыприемалекарствToolStripMenuItem + // + способыприемалекарствToolStripMenuItem.Name = "способыприемалекарствToolStripMenuItem"; + способыприемалекарствToolStripMenuItem.Size = new Size(462, 30); + способыприемалекарствToolStripMenuItem.Text = "Способы приема лекарств..."; + способыприемалекарствToolStripMenuItem.Click += способыприемалекарствToolStripMenuItem_Click; + // + // заболеваниеToolStripMenuItem1 + // + заболеваниеToolStripMenuItem1.Name = "заболеваниеToolStripMenuItem1"; + заболеваниеToolStripMenuItem1.Size = new Size(462, 30); + заболеваниеToolStripMenuItem1.Text = "Заболевания..."; + заболеваниеToolStripMenuItem1.Click += заболеваниеToolStripMenuItem1_Click; + // + // процедурыToolStripMenuItem + // + процедурыToolStripMenuItem.Name = "процедурыToolStripMenuItem"; + процедурыToolStripMenuItem.Size = new Size(462, 30); + процедурыToolStripMenuItem.Text = "Процедуры..."; + процедурыToolStripMenuItem.Click += процедурыToolStripMenuItem_Click; + // + // синдромыToolStripMenuItem + // + синдромыToolStripMenuItem.Name = "синдромыToolStripMenuItem"; + синдромыToolStripMenuItem.Size = new Size(462, 30); + синдромыToolStripMenuItem.Text = "Синдромы..."; + синдромыToolStripMenuItem.Click += синдромыToolStripMenuItem_Click; + // + // соответствиеЗаболеванийИСиндромовToolStripMenuItem + // + соответствиеЗаболеванийИСиндромовToolStripMenuItem.Name = "соответствиеЗаболеванийИСиндромовToolStripMenuItem"; + соответствиеЗаболеванийИСиндромовToolStripMenuItem.Size = new Size(462, 30); + соответствиеЗаболеванийИСиндромовToolStripMenuItem.Text = "Соответствие заболеваний и синдромов..."; + соответствиеЗаболеванийИСиндромовToolStripMenuItem.Click += соответствиеЗаболеванийИСиндромовToolStripMenuItem_Click; + // + // обследованияToolStripMenuItem + // + обследованияToolStripMenuItem.Name = "обследованияToolStripMenuItem"; + обследованияToolStripMenuItem.Size = new Size(462, 30); + обследованияToolStripMenuItem.Text = "Обследования..."; + обследованияToolStripMenuItem.Click += обследованияToolStripMenuItem_Click; + // + // нормалиОбследованийToolStripMenuItem + // + нормалиОбследованийToolStripMenuItem.Name = "нормалиОбследованийToolStripMenuItem"; + нормалиОбследованийToolStripMenuItem.Size = new Size(462, 30); + нормалиОбследованийToolStripMenuItem.Text = "Нормали обследований..."; + нормалиОбследованийToolStripMenuItem.Click += нормалиОбследованийToolStripMenuItem_Click; + // + // CоответствиеСиндромовИОбследованийToolStripMenuItem + // + CоответствиеСиндромовИОбследованийToolStripMenuItem.Name = "CоответствиеСиндромовИОбследованийToolStripMenuItem"; + CоответствиеСиндромовИОбследованийToolStripMenuItem.Size = new Size(462, 30); + CоответствиеСиндромовИОбследованийToolStripMenuItem.Text = "Cоответствие синдромов и обследований..."; + CоответствиеСиндромовИОбследованийToolStripMenuItem.Click += CоответствиеСиндромовИОбследованийToolStripMenuItem_Click; + // + // единицыИзмеренияToolStripMenuItem + // + единицыИзмеренияToolStripMenuItem.Name = "единицыИзмеренияToolStripMenuItem"; + единицыИзмеренияToolStripMenuItem.Size = new Size(462, 30); + единицыИзмеренияToolStripMenuItem.Text = "Единицы измерения..."; + единицыИзмеренияToolStripMenuItem.Click += единицыИзмеренияToolStripMenuItem_Click; + // + // сотрудникиToolStripMenuItem + // + сотрудникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { пациентыToolStripMenuItem, добавитьПациентаToolStripMenuItem, toolStripSeparator1, назначенияToolStripMenuItem, госпитализацииToolStripMenuItem }); + сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem"; + сотрудникиToolStripMenuItem.Size = new Size(85, 29); + сотрудникиToolStripMenuItem.Text = "Работа"; + // + // пациентыToolStripMenuItem + // + пациентыToolStripMenuItem.Name = "пациентыToolStripMenuItem"; + пациентыToolStripMenuItem.Size = new Size(267, 30); + пациентыToolStripMenuItem.Text = "Пациенты..."; + пациентыToolStripMenuItem.Click += пациентыToolStripMenuItem_Click; + // + // добавитьПациентаToolStripMenuItem + // + добавитьПациентаToolStripMenuItem.Name = "добавитьПациентаToolStripMenuItem"; + добавитьПациентаToolStripMenuItem.Size = new Size(267, 30); + добавитьПациентаToolStripMenuItem.Text = "Добавить пациента..."; + добавитьПациентаToolStripMenuItem.Click += добавитьПациентаToolStripMenuItem_Click; + // + // toolStripSeparator1 + // + toolStripSeparator1.Name = "toolStripSeparator1"; + toolStripSeparator1.Size = new Size(264, 6); + // + // назначенияToolStripMenuItem + // + назначенияToolStripMenuItem.Name = "назначенияToolStripMenuItem"; + назначенияToolStripMenuItem.Size = new Size(267, 30); + назначенияToolStripMenuItem.Text = "Назначения..."; + назначенияToolStripMenuItem.Click += назначенияToolStripMenuItem_Click; + // + // госпитализацииToolStripMenuItem + // + госпитализацииToolStripMenuItem.Name = "госпитализацииToolStripMenuItem"; + госпитализацииToolStripMenuItem.Size = new Size(267, 30); + госпитализацииToolStripMenuItem.Text = "Госпитализации..."; + госпитализацииToolStripMenuItem.Click += госпитализацииToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { результатыАнализовToolStripMenuItem }); + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(88, 29); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // результатыАнализовToolStripMenuItem + // + результатыАнализовToolStripMenuItem.Name = "результатыАнализовToolStripMenuItem"; + результатыАнализовToolStripMenuItem.Size = new Size(267, 30); + результатыАнализовToolStripMenuItem.Text = "Результаты анализов"; + результатыАнализовToolStripMenuItem.Click += результатыАнализовToolStripMenuItem_Click; + // + // OnlyMenuForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 35); + Controls.Add(menuStrip1); + FormBorderStyle = FormBorderStyle.FixedSingle; + MainMenuStrip = menuStrip1; + MaximizeBox = false; + Name = "OnlyMenuForm"; + Text = "ИНФОРМАЦИОННАЯ СИСТЕМА \"РЕГИСТРАТУРА\""; + WindowState = FormWindowState.Maximized; + SizeChanged += Form_SizeChanged; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem заболеваниеToolStripMenuItem1; + private ToolStripMenuItem способыприемалекарствToolStripMenuItem; + private ToolStripMenuItem обследованияToolStripMenuItem; + private ToolStripMenuItem нормалиОбследованийToolStripMenuItem; + private ToolStripMenuItem сотрудникиToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem CоответствиеСиндромовИОбследованийToolStripMenuItem; + private ToolStripMenuItem пациентыToolStripMenuItem; + private ToolStripMenuItem назначенияToolStripMenuItem; + private ToolStripMenuItem результатыАнализовToolStripMenuItem; + private ToolStripMenuItem процедурыToolStripMenuItem; + private ToolStripMenuItem госпитализацииToolStripMenuItem; + private ToolStripMenuItem синдромыToolStripMenuItem; + private ToolStripMenuItem единицыИзмеренияToolStripMenuItem; + private ToolStripMenuItem лекарстваToolStripMenuItem; + private ToolStripMenuItem соответствиеЗаболеванийИСиндромовToolStripMenuItem; + private ToolStripMenuItem добавитьПациентаToolStripMenuItem; + private ToolStripSeparator toolStripSeparator1; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/MenuV/OnlyMenuForm.cs b/Register office/Register office/View/MenuV/OnlyMenuForm.cs new file mode 100644 index 0000000..e3a26dc --- /dev/null +++ b/Register office/Register office/View/MenuV/OnlyMenuForm.cs @@ -0,0 +1,149 @@ +using Register_office; +using Register_office.Model; +using Register_office.View.LoginV; +using Register_office.View.PatientV; +using Register_office.View.TypesV; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.MenuV +{ + public partial class OnlyMenuForm : Form + { + OnlyMenuViewModel _viewModel; + + public OnlyMenuForm() + { + InitializeComponent(); + _viewModel = new(); + SetFormByRole(); + } + + private void SetFormByRole() + { + if (_viewModel.General.DoctorId < 1) + { + справочникиToolStripMenuItem.Visible = + госпитализацииToolStripMenuItem.Visible = + отчетыToolStripMenuItem.Visible = false; + } + } + + private T ShowForm() where T : Form, new() + { + T? form = _viewModel.General.GetActivatedForm(); + + form ??= new(); + + form.Visible = true; + form.Show(); + return form; + } + + private void ReportAnalyses() + { + + List sales = _viewModel.GetReport(); + + string fileName = _viewModel.General.PathReport + "/Результаты анализов " + + DateOnly.FromDateTime(DateTime.Now) + ".xlsx"; + + ExcelManager.ExportToExcel(sales, fileName); + ExcelManager.OpenExcelFile(fileName); + } + + private void HideForms() + { + FormCollection formCollection = Application.OpenForms; + bool hide = false; + if (this.WindowState == FormWindowState.Minimized) + hide = false; + else if (this.WindowState == FormWindowState.Maximized) + hide = true; + + foreach (Form form in formCollection) + if (form.Name != this.Name && form.Name != new LoginForm().Name) + form.Visible = hide; + } + + private void Form_SizeChanged(object sender, EventArgs e) + { + HideForms(); + } + + private void заболеваниеToolStripMenuItem1_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void способыприемалекарствToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void обследованияToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void процедурыToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void нормалиОбследованийToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void синдромыToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void CоответствиеСиндромовИОбследованийToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void единицыИзмеренияToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void лекарстваToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void соответствиеЗаболеванийИСиндромовToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void пациентыToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void добавитьПациентаToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void назначенияToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void госпитализацииToolStripMenuItem_Click(object sender, EventArgs e) + { + ShowForm(); + } + + private void результатыАнализовToolStripMenuItem_Click(object sender, EventArgs e) + { + ReportAnalyses(); + } + } +} diff --git a/Register office/Register office/View/MenuV/OnlyMenuForm.resx b/Register office/Register office/View/MenuV/OnlyMenuForm.resx new file mode 100644 index 0000000..750d53a --- /dev/null +++ b/Register office/Register office/View/MenuV/OnlyMenuForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/PatientV/PatientDataForm.Designer.cs b/Register office/Register office/View/PatientV/PatientDataForm.Designer.cs new file mode 100644 index 0000000..69bfb39 --- /dev/null +++ b/Register office/Register office/View/PatientV/PatientDataForm.Designer.cs @@ -0,0 +1,281 @@ +namespace Register_office.View.PatientV +{ + partial class PatientDataForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + tbName = new TextBox(); + lblData = new Label(); + tbSurname = new TextBox(); + label3 = new Label(); + tbPatronymic = new TextBox(); + label4 = new Label(); + label6 = new Label(); + label7 = new Label(); + btnOK = new Button(); + button2 = new Button(); + dtpBirthday = new DateTimePicker(); + cbGender = new ComboBox(); + lblIdPerson = new Label(); + label5 = new Label(); + tbAddress = new TextBox(); + mtbPolicy = new MaskedTextBox(); + label2 = new Label(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 49); + label1.Name = "label1"; + label1.Size = new Size(91, 25); + label1.TabIndex = 0; + label1.Text = "Фамилия"; + // + // tbName + // + tbName.Font = new Font("Segoe UI", 12F); + tbName.Location = new Point(12, 137); + tbName.Name = "tbName"; + tbName.Size = new Size(398, 29); + tbName.TabIndex = 1; + tbName.KeyPress += TextBoxKeyPress; + // + // lblData + // + lblData.AutoSize = true; + lblData.Font = new Font("Segoe UI", 18F, FontStyle.Regular, GraphicsUnit.Point, 204); + lblData.Location = new Point(78, 9); + lblData.Name = "lblData"; + lblData.Size = new Size(233, 32); + lblData.TabIndex = 2; + lblData.Text = "Данные о пациенте"; + // + // tbSurname + // + tbSurname.Font = new Font("Segoe UI", 12F); + tbSurname.Location = new Point(12, 77); + tbSurname.Name = "tbSurname"; + tbSurname.Size = new Size(398, 29); + tbSurname.TabIndex = 0; + tbSurname.KeyPress += TextBoxKeyPress; + // + // label3 + // + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(12, 109); + label3.Name = "label3"; + label3.Size = new Size(49, 25); + label3.TabIndex = 3; + label3.Text = "Имя"; + // + // tbPatronymic + // + tbPatronymic.Font = new Font("Segoe UI", 12F); + tbPatronymic.Location = new Point(12, 197); + tbPatronymic.Name = "tbPatronymic"; + tbPatronymic.Size = new Size(398, 29); + tbPatronymic.TabIndex = 2; + tbPatronymic.KeyPress += TextBoxKeyPress; + // + // label4 + // + label4.AutoSize = true; + label4.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label4.Location = new Point(12, 169); + label4.Name = "label4"; + label4.Size = new Size(93, 25); + label4.TabIndex = 5; + label4.Text = "Отчество"; + // + // label6 + // + label6.AutoSize = true; + label6.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label6.Location = new Point(12, 289); + label6.Name = "label6"; + label6.Size = new Size(146, 25); + label6.TabIndex = 9; + label6.Text = "Дата рождения"; + // + // label7 + // + label7.AutoSize = true; + label7.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label7.Location = new Point(246, 289); + label7.Name = "label7"; + label7.Size = new Size(47, 25); + label7.TabIndex = 11; + label7.Text = "Пол"; + // + // btnOK + // + btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + btnOK.DialogResult = DialogResult.OK; + btnOK.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnOK.Location = new Point(12, 421); + btnOK.Name = "btnOK"; + btnOK.Size = new Size(161, 42); + btnOK.TabIndex = 7; + btnOK.Text = "Принять"; + btnOK.UseVisualStyleBackColor = true; + btnOK.Click += btnOK_Click; + // + // button2 + // + button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + button2.DialogResult = DialogResult.Cancel; + button2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + button2.Location = new Point(249, 421); + button2.Name = "button2"; + button2.Size = new Size(161, 42); + button2.TabIndex = 8; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // + // dtpBirthday + // + dtpBirthday.Font = new Font("Segoe UI", 12F); + dtpBirthday.Location = new Point(12, 317); + dtpBirthday.MinDate = new DateTime(1940, 1, 1, 0, 0, 0, 0); + dtpBirthday.Name = "dtpBirthday"; + dtpBirthday.Size = new Size(200, 29); + dtpBirthday.TabIndex = 4; + // + // cbGender + // + cbGender.DropDownStyle = ComboBoxStyle.DropDownList; + cbGender.Font = new Font("Segoe UI", 12F); + cbGender.FormattingEnabled = true; + cbGender.Items.AddRange(new object[] { "Мужчина", "Женщина" }); + cbGender.Location = new Point(246, 317); + cbGender.Name = "cbGender"; + cbGender.Size = new Size(161, 29); + cbGender.TabIndex = 5; + // + // lblIdPerson + // + lblIdPerson.AutoSize = true; + lblIdPerson.Location = new Point(229, 328); + lblIdPerson.Name = "lblIdPerson"; + lblIdPerson.Size = new Size(0, 15); + lblIdPerson.TabIndex = 21; + lblIdPerson.Visible = false; + // + // label5 + // + label5.AutoSize = true; + label5.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label5.Location = new Point(12, 229); + label5.Name = "label5"; + label5.Size = new Size(64, 25); + label5.TabIndex = 7; + label5.Text = "Адрес"; + // + // tbAddress + // + tbAddress.Font = new Font("Segoe UI", 12F); + tbAddress.Location = new Point(12, 257); + tbAddress.Name = "tbAddress"; + tbAddress.Size = new Size(398, 29); + tbAddress.TabIndex = 3; + // + // mtbPolicy + // + mtbPolicy.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + mtbPolicy.Location = new Point(12, 377); + mtbPolicy.Mask = "9999999999999999"; + mtbPolicy.Name = "mtbPolicy"; + mtbPolicy.Size = new Size(161, 29); + mtbPolicy.TabIndex = 24; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(12, 349); + label2.Name = "label2"; + label2.Size = new Size(67, 25); + label2.TabIndex = 23; + label2.Text = "Полис"; + // + // PatientDataForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(425, 475); + Controls.Add(mtbPolicy); + Controls.Add(label2); + Controls.Add(lblIdPerson); + Controls.Add(cbGender); + Controls.Add(dtpBirthday); + Controls.Add(button2); + Controls.Add(btnOK); + Controls.Add(label7); + Controls.Add(label6); + Controls.Add(tbAddress); + Controls.Add(label5); + Controls.Add(tbPatronymic); + Controls.Add(label4); + Controls.Add(tbSurname); + Controls.Add(label3); + Controls.Add(lblData); + Controls.Add(tbName); + Controls.Add(label1); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "PatientDataForm"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Данные пациента"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label3; + private Label label4; + private Label label6; + private Label label7; + private Button button2; + internal DateTimePicker dtpBirthday; + internal ComboBox cbGender; + internal TextBox tbName; + internal TextBox tbSurname; + internal TextBox tbPatronymic; + internal Label lblData; + internal Button btnOK; + internal Label lblIdPerson; + private Label label5; + internal TextBox tbAddress; + private MaskedTextBox mtbPolicy; + private Label label2; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/PatientV/PatientDataForm.cs b/Register office/Register office/View/PatientV/PatientDataForm.cs new file mode 100644 index 0000000..39ee470 --- /dev/null +++ b/Register office/Register office/View/PatientV/PatientDataForm.cs @@ -0,0 +1,120 @@ +using Register_office.Model; +using Register_office.ViewModel; + +namespace Register_office.View.PatientV +{ + public partial class PatientDataForm : Form + { + private PatientViewModel _viewModel; + + public PatientDataForm() + { + Init(); + } + + public PatientDataForm(Patient e) + { + Init(); + SetPatientData(e); + } + + private void Init() + { + InitializeComponent(); + TopMost = true; + _viewModel = new(); + SetDataSourceToComboBoxes(); + dtpBirthday.Value = + dtpBirthday.MaxDate = DateTime.Now; + } + + private void SetPatientData(Patient patient) + { + mtbPolicy.Text = patient.PolicyNumber; + Person p = patient.PatientNavigation; + tbSurname.Text = p.MiddleName; + tbName.Text = p.FirstName; + tbPatronymic.Text = p.LastName; + tbAddress.Text = p.Address; + dtpBirthday.Value = new(p.BirthDate, new()); + cbGender.Text = p.Gender; + + string patientName = string.Concat(tbSurname.Text, " ", + tbName.Text, " ", tbPatronymic.Text); + + Text = "Изменение данных"; + lblData.Dock = DockStyle.Top; + lblData.Text = patientName; + lblIdPerson.Text = p.PersonId.ToString(); + } + + private void SetDataSourceToComboBoxes() + { + cbGender.DataSource = new string[] { "Мужчина", "Женщина" }; + } + + private void TextBoxKeyPress(object sender, KeyPressEventArgs e) + { + // Разрешаем только буквы + if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar)) + { + e.Handled = true; // Блокируем ввод + } + } + + private void btnOK_Click(object sender, EventArgs e) + { + Person person = new(); + person = SetPersonData(person); + int id = person.PersonId; + + if (lblIdPerson.Text != "") + { + person = _viewModel.GetPerson(id).First(); + person = SetPersonData(person); + person.Patient.PolicyNumber = mtbPolicy.Text; + _viewModel.Update(); + } + else + { + id = _viewModel.AddPerson(person); + if (id == -1) + { + DialogResult = DialogResult.None; + return; + } + + Patient p = new() + { + PatientId = id, + PolicyNumber = mtbPolicy.Text + }; + if (!_viewModel.AddPatient(p)) + { + DialogResult = DialogResult.None; + return; + } + } + + MessageBox.Show("Пациент успешно добавлен", "Добавление пользователя", + MessageBoxButtons.OK, MessageBoxIcon.Information); + Close(); + + } + + private Person SetPersonData(Person p) + { + p.MiddleName = tbSurname.Text; + p.FirstName = tbName.Text; + p.LastName = tbPatronymic.Text; + p.Address = tbAddress.Text; + p.BirthDate = DateOnly.FromDateTime(dtpBirthday.Value); + p.Gender = cbGender.Text; + + if (lblIdPerson.Text != "") + p.PersonId = int.Parse(lblIdPerson.Text); + + return p; + } + } +} diff --git a/Register office/Register office/View/PatientV/PatientDataForm.resx b/Register office/Register office/View/PatientV/PatientDataForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/PatientV/PatientDataForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/PatientV/PatientForm.Designer.cs b/Register office/Register office/View/PatientV/PatientForm.Designer.cs new file mode 100644 index 0000000..fb322d8 --- /dev/null +++ b/Register office/Register office/View/PatientV/PatientForm.Designer.cs @@ -0,0 +1,181 @@ +using Register_office.View; + +namespace Register_office.View.PatientV +{ + partial class PatientForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + btnDelete = new Button(); + btnUpdate = new Button(); + btnHospital = new Button(); + btnPrescription = new Button(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(btnHospital); + splitContainer1.Panel1.Controls.Add(btnPrescription); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 70; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(619, 28); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(169, 33); + btnDelete.TabIndex = 10; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(449, 28); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(164, 33); + btnUpdate.TabIndex = 9; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // btnHospital + // + btnHospital.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnHospital.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnHospital.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnHospital.Location = new Point(12, 28); + btnHospital.Name = "btnHospital"; + btnHospital.Size = new Size(162, 33); + btnHospital.TabIndex = 7; + btnHospital.Text = "Госпитализации"; + btnHospital.UseVisualStyleBackColor = true; + btnHospital.Click += btnHospital_Click; + // + // btnPrescription + // + btnPrescription.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnPrescription.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnPrescription.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnPrescription.Location = new Point(180, 28); + btnPrescription.Name = "btnPrescription"; + btnPrescription.Size = new Size(162, 33); + btnPrescription.TabIndex = 5; + btnPrescription.Text = "Назначения"; + btnPrescription.UseVisualStyleBackColor = true; + btnPrescription.Click += btnPrescription_Click; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 572); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // PatientForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "PatientForm"; + Text = "Пациенты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Button btnHospital; + private Button btnPrescription; + private Button btnUpdate; + private Button btnDelete; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/PatientV/PatientForm.cs b/Register office/Register office/View/PatientV/PatientForm.cs new file mode 100644 index 0000000..514079c --- /dev/null +++ b/Register office/Register office/View/PatientV/PatientForm.cs @@ -0,0 +1,92 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; +using System.Xml.Linq; + +namespace Register_office.View.PatientV +{ + public partial class PatientForm : Form + { + private PatientViewModel _viewModel; + private Patient? _selectedPatient; + private string _columnIdName = "PatientId"; + private Patient _temp; + + public PatientForm() + { + InitializeComponent(); + TopMost = true; + Text = "Пациенты"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + btnPrescription.Visible = _viewModel.General.DoctorId != 0; + } + + private void UpdateElements(bool enableButtons = false) + { + if (_selectedPatient == null) + btnPrescription.Enabled = btnHospital.Enabled = false; + else + { + btnHospital.Enabled = _selectedPatient.HospitalAdmissions.Count != 0; + btnPrescription.Enabled = _selectedPatient.Prescriptions.Count != 0; + } + btnUpdate.Enabled = btnDelete.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedPatient = _viewModel.GetPatient(id).FirstOrDefault(); + if (_selectedPatient != null) + UpdateElements(true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedPatient != null) + { + PatientDataForm pf = new(_selectedPatient); + if (pf.ShowDialog() == DialogResult.OK) + { + UpdateElements(); + UpdateDgv(); + } + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedPatient != null) + { + _viewModel.DeletePatient(_selectedPatient); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnPrescription_Click(object sender, EventArgs e) + { + PrescriptionForm pf = new(_selectedPatient); + pf.ShowDialog(); + } + + private void btnHospital_Click(object sender, EventArgs e) + { + HospitalForm hf = new(_selectedPatient); + hf.ShowDialog(); + } + } +} diff --git a/Register office/Register office/View/PatientV/PatientForm.resx b/Register office/Register office/View/PatientV/PatientForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/PatientV/PatientForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/DrugDataForm.Designer.cs b/Register office/Register office/View/PrescriptionsV/DrugDataForm.Designer.cs new file mode 100644 index 0000000..48988b1 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/DrugDataForm.Designer.cs @@ -0,0 +1,244 @@ +namespace Register_office.View.PatientV +{ + partial class DrugDataForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label7 = new Label(); + btnOK = new Button(); + button2 = new Button(); + cbDrug = new ComboBox(); + cbPatient = new ComboBox(); + label1 = new Label(); + label5 = new Label(); + cbUnit = new ComboBox(); + label2 = new Label(); + nudDose = new NumericUpDown(); + cbIntakeMethod = new ComboBox(); + label3 = new Label(); + label4 = new Label(); + nudDurationDays = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)nudDose).BeginInit(); + ((System.ComponentModel.ISupportInitialize)nudDurationDays).BeginInit(); + SuspendLayout(); + // + // label7 + // + label7.AutoSize = true; + label7.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label7.Location = new Point(12, 69); + label7.Name = "label7"; + label7.Size = new Size(103, 25); + label7.TabIndex = 11; + label7.Text = "Лекарство"; + // + // btnOK + // + btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + btnOK.DialogResult = DialogResult.OK; + btnOK.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnOK.Location = new Point(12, 330); + btnOK.Name = "btnOK"; + btnOK.Size = new Size(161, 42); + btnOK.TabIndex = 3; + btnOK.Text = "Добавить"; + btnOK.UseVisualStyleBackColor = true; + btnOK.Click += btnOK_Click; + // + // button2 + // + button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + button2.DialogResult = DialogResult.Cancel; + button2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + button2.Location = new Point(249, 330); + button2.Name = "button2"; + button2.Size = new Size(161, 42); + button2.TabIndex = 4; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // + // cbDrug + // + cbDrug.DropDownStyle = ComboBoxStyle.DropDownList; + cbDrug.Font = new Font("Segoe UI", 12F); + cbDrug.FormattingEnabled = true; + cbDrug.Location = new Point(12, 97); + cbDrug.Name = "cbDrug"; + cbDrug.Size = new Size(398, 29); + cbDrug.TabIndex = 1; + // + // cbPatient + // + cbPatient.DropDownStyle = ComboBoxStyle.DropDownList; + cbPatient.Font = new Font("Segoe UI", 12F); + cbPatient.FormattingEnabled = true; + cbPatient.Items.AddRange(new object[] { "Мужчина", "Женщина" }); + cbPatient.Location = new Point(12, 37); + cbPatient.Name = "cbPatient"; + cbPatient.Size = new Size(398, 29); + cbPatient.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(87, 25); + label1.TabIndex = 23; + label1.Text = "Пациент"; + // + // label5 + // + label5.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label5.AutoSize = true; + label5.Font = new Font("Segoe UI", 14.25F); + label5.Location = new Point(224, 129); + label5.Name = "label5"; + label5.Size = new Size(186, 25); + label5.TabIndex = 28; + label5.Text = "Единица измерения"; + // + // cbUnit + // + cbUnit.DropDownStyle = ComboBoxStyle.DropDownList; + cbUnit.Font = new Font("Segoe UI", 12F); + cbUnit.FormattingEnabled = true; + cbUnit.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbUnit.Location = new Point(224, 157); + cbUnit.Name = "cbUnit"; + cbUnit.Size = new Size(186, 29); + cbUnit.TabIndex = 27; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 14.25F); + label2.Location = new Point(12, 129); + label2.Name = "label2"; + label2.Size = new Size(54, 25); + label2.TabIndex = 26; + label2.Text = "Доза"; + // + // nudDose + // + nudDose.DecimalPlaces = 2; + nudDose.Font = new Font("Segoe UI", 12F); + nudDose.Increment = new decimal(new int[] { 1, 0, 0, 65536 }); + nudDose.Location = new Point(12, 157); + nudDose.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + nudDose.Name = "nudDose"; + nudDose.Size = new Size(120, 29); + nudDose.TabIndex = 25; + nudDose.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // cbIntakeMethod + // + cbIntakeMethod.DropDownStyle = ComboBoxStyle.DropDownList; + cbIntakeMethod.Font = new Font("Segoe UI", 12F); + cbIntakeMethod.FormattingEnabled = true; + cbIntakeMethod.Location = new Point(12, 217); + cbIntakeMethod.Name = "cbIntakeMethod"; + cbIntakeMethod.Size = new Size(398, 29); + cbIntakeMethod.TabIndex = 29; + // + // label3 + // + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(12, 189); + label3.Name = "label3"; + label3.Size = new Size(148, 25); + label3.TabIndex = 30; + label3.Text = "Способ приема"; + // + // label4 + // + label4.AutoSize = true; + label4.Font = new Font("Segoe UI", 14.25F); + label4.Location = new Point(12, 249); + label4.Name = "label4"; + label4.Size = new Size(276, 25); + label4.TabIndex = 32; + label4.Text = "Длительность приема (в днях)"; + // + // nudDurationDays + // + nudDurationDays.Font = new Font("Segoe UI", 12F); + nudDurationDays.Location = new Point(12, 277); + nudDurationDays.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + nudDurationDays.Name = "nudDurationDays"; + nudDurationDays.Size = new Size(65, 29); + nudDurationDays.TabIndex = 31; + nudDurationDays.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // DrugDataForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(425, 384); + Controls.Add(label4); + Controls.Add(nudDurationDays); + Controls.Add(cbIntakeMethod); + Controls.Add(label3); + Controls.Add(label5); + Controls.Add(cbUnit); + Controls.Add(label2); + Controls.Add(nudDose); + Controls.Add(cbPatient); + Controls.Add(label1); + Controls.Add(cbDrug); + Controls.Add(button2); + Controls.Add(btnOK); + Controls.Add(label7); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "DrugDataForm"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Назначение лекарства"; + ((System.ComponentModel.ISupportInitialize)nudDose).EndInit(); + ((System.ComponentModel.ISupportInitialize)nudDurationDays).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label label7; + private Button button2; + internal ComboBox cbDrug; + internal Button btnOK; + internal ComboBox cbPatient; + private Label label1; + private Label label5; + private ComboBox cbUnit; + private Label label2; + private NumericUpDown nudDose; + internal ComboBox cbIntakeMethod; + private Label label3; + private Label label4; + private NumericUpDown nudDurationDays; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/DrugDataForm.cs b/Register office/Register office/View/PrescriptionsV/DrugDataForm.cs new file mode 100644 index 0000000..8c6033e --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/DrugDataForm.cs @@ -0,0 +1,124 @@ +using Microsoft.EntityFrameworkCore; +using Register_office.Model; +using Register_office.ViewModel; + +namespace Register_office.View.PatientV +{ + public partial class DrugDataForm : Form + { + private PrescriptionViewModel _viewModel; + private Prescription? _prescription; + + public DrugDataForm() + { + Init(); + } + + public DrugDataForm(Prescription p) + { + Init(); + SetData(p); + } + + private void Init() + { + InitializeComponent(); + TopMost = true; + _viewModel = new(); + SetDataSourceToComboBoxes(); + } + + private void SetData(Prescription prescription) + { + _prescription = prescription; + cbPatient.SelectedValue = prescription.PatientId; + cbDrug.SelectedValue = prescription.DrugTypePrescription.DrugTypeId; + cbUnit.SelectedValue = prescription.DrugTypePrescription.DoseUnitId; + nudDose.Value = prescription.DrugTypePrescription.Dose; + cbIntakeMethod.SelectedValue = prescription.DrugTypePrescription.IntakeMethodId; + nudDurationDays.Value = prescription.DrugTypePrescription.DurationDays; + + Text = "Просмотр процедуры"; + btnOK.Visible = cbPatient.Enabled = + cbIntakeMethod.Enabled = cbUnit.Enabled = + nudDose.Enabled = nudDurationDays.Enabled = + cbDrug.Enabled = false; + } + + private void SetDataSourceToComboBoxes() + { + cbDrug.DataSource = _viewModel.General.Context.DrugTypes + .Select(x => new ComboBoxItem { Name = x.InternationalNameRu, Id = x.DrugTypeId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbDrug.DisplayMember = "Name"; + cbDrug.ValueMember = "Id"; + + cbPatient.DataSource = _viewModel.General.Context.Patients + .Include(x => x.PatientNavigation) + .Select(x => new ComboBoxItem + { + Name = x.PatientNavigation.FirstName + " " + + x.PatientNavigation.FirstName + " " + + x.PatientNavigation.LastName, + Id = x.PatientId + }) + .OrderBy(cbi => cbi.Name).ToList(); + cbPatient.DisplayMember = "Name"; + cbPatient.ValueMember = "Id"; + + cbIntakeMethod.DataSource = _viewModel.General.Context.DrugIntakeMethods + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.DrugIntakeMethodId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbIntakeMethod.DisplayMember = "Name"; + cbIntakeMethod.ValueMember = "Id"; + + cbUnit.DataSource = _viewModel.General.Context.Units + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.UnitId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbUnit.DisplayMember = "Name"; + cbUnit.ValueMember = "Id"; + } + + private void btnOK_Click(object sender, EventArgs e) + { + Prescription p = new() + { + DoctorId = _viewModel.General.DoctorId, + PatientId = int.Parse(cbPatient.SelectedValue?.ToString() ?? "-1") + }; + + Prescription? prInDb = _viewModel.General.Context.Prescriptions + .FirstOrDefault(x => x.PatientId == p.PatientId && x.DoctorId == p.DoctorId); + int id = prInDb?.PrescriptionId ?? 0; + if (prInDb == null) + { + id = _viewModel.AddPrescription(p); + if (id == -1) + { + DialogResult = DialogResult.None; + return; + } + } + + DrugTypePrescription pr = new() + { + PrescriptionId = id, + DrugTypeId = int.Parse(cbDrug.SelectedValue?.ToString() ?? "0"), + DoseUnitId = int.Parse(cbUnit.SelectedValue?.ToString() ?? "0"), + IntakeMethodId = int.Parse(cbIntakeMethod.SelectedValue?.ToString() ?? "0"), + Dose = nudDose.Value, + DurationDays = (int)nudDurationDays.Value + }; + if (_viewModel.AddPrescription(pr) == -1) + { + DialogResult = DialogResult.None; + return; + } + + MessageBox.Show("Лекарство успешно назначено", "Назначение пользователю", + MessageBoxButtons.OK, MessageBoxIcon.Information); + Close(); + + } + } +} diff --git a/Register office/Register office/View/PrescriptionsV/DrugDataForm.resx b/Register office/Register office/View/PrescriptionsV/DrugDataForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/DrugDataForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.Designer.cs b/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.Designer.cs new file mode 100644 index 0000000..1372b32 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.Designer.cs @@ -0,0 +1,147 @@ +namespace Register_office.View.PatientV +{ + partial class ExaminationDataForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label7 = new Label(); + btnOK = new Button(); + button2 = new Button(); + cbExamination = new ComboBox(); + cbPatient = new ComboBox(); + label1 = new Label(); + btnResult = new Button(); + SuspendLayout(); + // + // label7 + // + label7.AutoSize = true; + label7.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label7.Location = new Point(12, 69); + label7.Name = "label7"; + label7.Size = new Size(139, 25); + label7.TabIndex = 11; + label7.Text = "Обследование"; + // + // btnOK + // + btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + btnOK.DialogResult = DialogResult.OK; + btnOK.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnOK.Location = new Point(12, 225); + btnOK.Name = "btnOK"; + btnOK.Size = new Size(161, 42); + btnOK.TabIndex = 3; + btnOK.Text = "Добавить"; + btnOK.UseVisualStyleBackColor = true; + btnOK.Click += btnOK_Click; + // + // button2 + // + button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + button2.DialogResult = DialogResult.Cancel; + button2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + button2.Location = new Point(249, 225); + button2.Name = "button2"; + button2.Size = new Size(161, 42); + button2.TabIndex = 4; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // + // cbExamination + // + cbExamination.DropDownStyle = ComboBoxStyle.DropDownList; + cbExamination.Font = new Font("Segoe UI", 12F); + cbExamination.FormattingEnabled = true; + cbExamination.Location = new Point(12, 97); + cbExamination.Name = "cbExamination"; + cbExamination.Size = new Size(398, 29); + cbExamination.TabIndex = 1; + // + // cbPatient + // + cbPatient.DropDownStyle = ComboBoxStyle.DropDownList; + cbPatient.Font = new Font("Segoe UI", 12F); + cbPatient.FormattingEnabled = true; + cbPatient.Items.AddRange(new object[] { "Мужчина", "Женщина" }); + cbPatient.Location = new Point(12, 37); + cbPatient.Name = "cbPatient"; + cbPatient.Size = new Size(398, 29); + cbPatient.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(87, 25); + label1.TabIndex = 23; + label1.Text = "Пациент"; + // + // btnResult + // + btnResult.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + btnResult.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnResult.Location = new Point(12, 155); + btnResult.Name = "btnResult"; + btnResult.Size = new Size(398, 42); + btnResult.TabIndex = 24; + btnResult.Text = "Результаты"; + btnResult.UseVisualStyleBackColor = true; + btnResult.Click += btnResult_Click; + // + // ExaminationDataForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(425, 279); + Controls.Add(btnResult); + Controls.Add(cbPatient); + Controls.Add(label1); + Controls.Add(cbExamination); + Controls.Add(button2); + Controls.Add(btnOK); + Controls.Add(label7); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "ExaminationDataForm"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Назначение обследования"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label label7; + private Button button2; + internal ComboBox cbExamination; + internal Button btnOK; + internal ComboBox cbPatient; + private Label label1; + internal Button btnResult; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.cs b/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.cs new file mode 100644 index 0000000..5c501ff --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.cs @@ -0,0 +1,130 @@ +using Microsoft.EntityFrameworkCore; +using Register_office.Model; +using Register_office.View.TypesV; +using Register_office.ViewModel; + +namespace Register_office.View.PatientV +{ + public partial class ExaminationDataForm : Form + { + private PrescriptionViewModel _viewModel; + private Prescription? _prescription; + bool _isResult; + public ExaminationDataForm() + { + Init(); + btnResult.Visible = false; + } + + public ExaminationDataForm(Prescription p) + { + Init(); + SetData(p); + } + + private void Init() + { + InitializeComponent(); + TopMost = true; + _viewModel = new(); + SetDataSourceToComboBoxes(); + } + + private void SetData(Prescription prescription) + { + _prescription = prescription; + cbPatient.SelectedValue = prescription.PatientId; + cbExamination.SelectedValue = prescription.ExaminationTypePrescription.ExaminationTypeId; + + Text = "Просмотр обследования"; + btnOK.Visible = cbPatient.Enabled = + cbExamination.Enabled = false; + + _isResult = prescription.ExaminationTypePrescription.ResultId != null; + btnResult.Text = _isResult + ? "Посмотреть результаты" + : "Добавить результаты"; + btnResult.Visible = true; + } + + private void SetDataSourceToComboBoxes() + { + cbExamination.DataSource = _viewModel.General.Context.ExaminationTypes + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.ExaminationTypeId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbExamination.DisplayMember = "Name"; + cbExamination.ValueMember = "Id"; + + cbPatient.DataSource = _viewModel.General.Context.Patients + .Include(x => x.PatientNavigation) + .Select(x => new ComboBoxItem + { + Name = x.PatientNavigation.FirstName + " " + + x.PatientNavigation.FirstName + " " + + x.PatientNavigation.LastName, + Id = x.PatientId + }) + .OrderBy(cbi => cbi.Name).ToList(); + cbPatient.DisplayMember = "Name"; + cbPatient.ValueMember = "Id"; + } + + private void btnOK_Click(object sender, EventArgs e) + { + Prescription p = new() + { + DoctorId = _viewModel.General.DoctorId, + PatientId = int.Parse(cbPatient.SelectedValue?.ToString() ?? "-1") + }; + + Prescription? prInDb = _viewModel.General.Context.Prescriptions + .FirstOrDefault(x => x.PatientId == p.PatientId && x.DoctorId == p.DoctorId); + int id = prInDb?.PrescriptionId ?? 0; + if (prInDb == null) + { + id = _viewModel.AddPrescription(p); + if (id == -1) + { + DialogResult = DialogResult.None; + return; + } + } + + ExaminationTypePrescription pr = new() + { + PrescriptionId = id, + ExaminationTypeId = int.Parse(cbExamination.SelectedValue?.ToString() ?? "0") + }; + if (_viewModel.AddPrescription(pr) == -1) + { + DialogResult = DialogResult.None; + return; + } + + MessageBox.Show("Обследование успешно назначено", "Назначение пользователю", + MessageBoxButtons.OK, MessageBoxIcon.Information); + Close(); + + } + + private void btnResult_Click(object sender, EventArgs e) + { + ResultDataForm rf; + if (!_isResult) + { + rf = new(_prescription.ExaminationTypePrescription); + if (rf.ShowDialog() == DialogResult.OK) + { + _isResult = true; + btnResult.Text = "Посмотреть результаты"; + } + } + else + { + rf = new(_prescription.ExaminationTypePrescription, false); + rf.ShowDialog(); + } + + } + } +} diff --git a/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.resx b/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ExaminationDataForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/PrescriptionForm.Designer.cs b/Register office/Register office/View/PrescriptionsV/PrescriptionForm.Designer.cs new file mode 100644 index 0000000..bb4aae6 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/PrescriptionForm.Designer.cs @@ -0,0 +1,258 @@ +using Register_office.View; + +namespace Register_office.View.PatientV +{ + partial class PrescriptionForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + label2 = new Label(); + btnProcedureShow = new Button(); + btnExaminationShow = new Button(); + btnDrugShow = new Button(); + label1 = new Label(); + btnProcedureAdd = new Button(); + btnDelete = new Button(); + btnExaminationAdd = new Button(); + btnDrugAdd = new Button(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(label2); + splitContainer1.Panel1.Controls.Add(btnProcedureShow); + splitContainer1.Panel1.Controls.Add(btnExaminationShow); + splitContainer1.Panel1.Controls.Add(btnDrugShow); + splitContainer1.Panel1.Controls.Add(label1); + splitContainer1.Panel1.Controls.Add(btnProcedureAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnExaminationAdd); + splitContainer1.Panel1.Controls.Add(btnDrugAdd); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 134; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // label2 + // + label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(12, 73); + label2.Name = "label2"; + label2.Size = new Size(80, 17); + label2.TabIndex = 16; + label2.Text = "Посмотреть"; + // + // btnProcedureShow + // + btnProcedureShow.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnProcedureShow.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnProcedureShow.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnProcedureShow.Location = new Point(348, 93); + btnProcedureShow.Name = "btnProcedureShow"; + btnProcedureShow.Size = new Size(162, 33); + btnProcedureShow.TabIndex = 15; + btnProcedureShow.Text = "Процедуру"; + btnProcedureShow.UseVisualStyleBackColor = true; + btnProcedureShow.Click += btnProcedureShow_Click; + // + // btnExaminationShow + // + btnExaminationShow.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnExaminationShow.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnExaminationShow.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnExaminationShow.Location = new Point(12, 93); + btnExaminationShow.Name = "btnExaminationShow"; + btnExaminationShow.Size = new Size(162, 33); + btnExaminationShow.TabIndex = 14; + btnExaminationShow.Text = "Обследование"; + btnExaminationShow.UseVisualStyleBackColor = true; + btnExaminationShow.Click += btnExaminationShow_Click; + // + // btnDrugShow + // + btnDrugShow.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDrugShow.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDrugShow.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDrugShow.Location = new Point(180, 93); + btnDrugShow.Name = "btnDrugShow"; + btnDrugShow.Size = new Size(162, 33); + btnDrugShow.TabIndex = 13; + btnDrugShow.Text = "Лекарство"; + btnDrugShow.UseVisualStyleBackColor = true; + btnDrugShow.Click += btnDrugShow_Click; + // + // label1 + // + label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 8); + label1.Name = "label1"; + label1.Size = new Size(66, 17); + label1.TabIndex = 12; + label1.Text = "Добавить"; + // + // btnProcedureAdd + // + btnProcedureAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnProcedureAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnProcedureAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnProcedureAdd.Location = new Point(348, 28); + btnProcedureAdd.Name = "btnProcedureAdd"; + btnProcedureAdd.Size = new Size(162, 33); + btnProcedureAdd.TabIndex = 11; + btnProcedureAdd.Text = "Процедуру"; + btnProcedureAdd.UseVisualStyleBackColor = true; + btnProcedureAdd.Click += btnProcedureAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(619, 28); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(169, 33); + btnDelete.TabIndex = 10; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnExaminationAdd + // + btnExaminationAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnExaminationAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnExaminationAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnExaminationAdd.Location = new Point(12, 28); + btnExaminationAdd.Name = "btnExaminationAdd"; + btnExaminationAdd.Size = new Size(162, 33); + btnExaminationAdd.TabIndex = 7; + btnExaminationAdd.Text = "Обследование"; + btnExaminationAdd.UseVisualStyleBackColor = true; + btnExaminationAdd.Click += btnExaminationAdd_Click; + // + // btnDrugAdd + // + btnDrugAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDrugAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDrugAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDrugAdd.Location = new Point(180, 28); + btnDrugAdd.Name = "btnDrugAdd"; + btnDrugAdd.Size = new Size(162, 33); + btnDrugAdd.TabIndex = 5; + btnDrugAdd.Text = "Лекарство"; + btnDrugAdd.UseVisualStyleBackColor = true; + btnDrugAdd.Click += btnDrugAdd_Click; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 508); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // PrescriptionForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "PrescriptionForm"; + Text = "Пациенты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Button btnExaminationAdd; + private Button btnDrugAdd; + private Button btnDelete; + private Button btnProcedureAdd; + private Label label1; + private Label label2; + private Button btnProcedureShow; + private Button btnExaminationShow; + private Button btnDrugShow; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/PrescriptionForm.cs b/Register office/Register office/View/PrescriptionsV/PrescriptionForm.cs new file mode 100644 index 0000000..259796a --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/PrescriptionForm.cs @@ -0,0 +1,124 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; +using System.Xml.Linq; + +namespace Register_office.View.PatientV +{ + public partial class PrescriptionForm : Form + { + private PrescriptionViewModel _viewModel; + private Prescription? _selectedPrescription; + private string _columnIdName = "PrescriptionId"; + + public PrescriptionForm() + { + Init(); + } + + public PrescriptionForm(Patient patient) + { + Init(); + dgv.DataSource = new SortableBindingList( + PrescriptionWrapper.ToList(_viewModel.General.Context.Prescriptions + .Where(x => x.PatientId == patient.PatientId) + .ToList())); + } + + private void Init() + { + InitializeComponent(); + TopMost = true; + Text = "Назначения"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + } + + private void UpdateElements(bool enableButtons = false) + { + if (_selectedPrescription == null) + btnDrugShow.Enabled = btnExaminationShow.Enabled = btnProcedureShow.Enabled = false; + else + { + btnDrugShow.Enabled = _selectedPrescription.DrugTypePrescription != null; + btnExaminationShow.Enabled = _selectedPrescription.ExaminationTypePrescription != null; + btnProcedureShow.Enabled = _selectedPrescription.ProcedureTypePrescription != null; + } + btnDelete.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedPrescription = _viewModel.General.Context.Prescriptions + .Include(x => x.ProcedureTypePrescription) + .Include(x => x.DrugTypePrescription) + .Include(x => x.ExaminationTypePrescription) + .Where(x => x.PrescriptionId == id).FirstOrDefault(); + if (_selectedPrescription != null) + UpdateElements(true); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedPrescription != null) + { + _viewModel.DeletePrescription(_selectedPrescription); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnProcedureAdd_Click(object sender, EventArgs e) + { + ProcedureDataForm pf = new(); + pf.ShowDialog(); + UpdateDgv(); + } + + private void btnProcedureShow_Click(object sender, EventArgs e) + { + ProcedureDataForm pf = new(_selectedPrescription); + pf.ShowDialog(); + } + + private void btnDrugAdd_Click(object sender, EventArgs e) + { + DrugDataForm pf = new(); + pf.ShowDialog(); + UpdateDgv(); + } + + private void btnDrugShow_Click(object sender, EventArgs e) + { + DrugDataForm pf = new(_selectedPrescription); + pf.ShowDialog(); + } + + private void btnExaminationAdd_Click(object sender, EventArgs e) + { + ExaminationDataForm pf = new(); + pf.ShowDialog(); + UpdateDgv(); + } + + private void btnExaminationShow_Click(object sender, EventArgs e) + { + ExaminationDataForm pf = new(_selectedPrescription); + pf.ShowDialog(); + } + } +} diff --git a/Register office/Register office/View/PrescriptionsV/PrescriptionForm.resx b/Register office/Register office/View/PrescriptionsV/PrescriptionForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/PrescriptionForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.Designer.cs b/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.Designer.cs new file mode 100644 index 0000000..5f63adf --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.Designer.cs @@ -0,0 +1,157 @@ +namespace Register_office.View.PatientV +{ + partial class ProcedureDataForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label6 = new Label(); + label7 = new Label(); + btnOK = new Button(); + button2 = new Button(); + dtpSchedule = new DateTimePicker(); + cbProcedure = new ComboBox(); + cbPatient = new ComboBox(); + label1 = new Label(); + SuspendLayout(); + // + // label6 + // + label6.AutoSize = true; + label6.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label6.Location = new Point(12, 139); + label6.Name = "label6"; + label6.Size = new Size(163, 25); + label6.TabIndex = 9; + label6.Text = "Дата проведения"; + // + // label7 + // + label7.AutoSize = true; + label7.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label7.Location = new Point(12, 69); + label7.Name = "label7"; + label7.Size = new Size(109, 25); + label7.TabIndex = 11; + label7.Text = "Процедура"; + // + // btnOK + // + btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + btnOK.DialogResult = DialogResult.OK; + btnOK.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnOK.Location = new Point(12, 225); + btnOK.Name = "btnOK"; + btnOK.Size = new Size(161, 42); + btnOK.TabIndex = 3; + btnOK.Text = "Добавить"; + btnOK.UseVisualStyleBackColor = true; + btnOK.Click += btnOK_Click; + // + // button2 + // + button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + button2.DialogResult = DialogResult.Cancel; + button2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + button2.Location = new Point(249, 225); + button2.Name = "button2"; + button2.Size = new Size(161, 42); + button2.TabIndex = 4; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // + // dtpSchedule + // + dtpSchedule.Font = new Font("Segoe UI", 12F); + dtpSchedule.Location = new Point(12, 167); + dtpSchedule.MinDate = new DateTime(1940, 1, 1, 0, 0, 0, 0); + dtpSchedule.Name = "dtpSchedule"; + dtpSchedule.Size = new Size(200, 29); + dtpSchedule.TabIndex = 2; + // + // cbProcedure + // + cbProcedure.DropDownStyle = ComboBoxStyle.DropDownList; + cbProcedure.Font = new Font("Segoe UI", 12F); + cbProcedure.FormattingEnabled = true; + cbProcedure.Location = new Point(12, 97); + cbProcedure.Name = "cbProcedure"; + cbProcedure.Size = new Size(398, 29); + cbProcedure.TabIndex = 1; + // + // cbPatient + // + cbPatient.DropDownStyle = ComboBoxStyle.DropDownList; + cbPatient.Font = new Font("Segoe UI", 12F); + cbPatient.FormattingEnabled = true; + cbPatient.Items.AddRange(new object[] { "Мужчина", "Женщина" }); + cbPatient.Location = new Point(12, 37); + cbPatient.Name = "cbPatient"; + cbPatient.Size = new Size(398, 29); + cbPatient.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(87, 25); + label1.TabIndex = 23; + label1.Text = "Пациент"; + // + // ProcedureDataForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(425, 279); + Controls.Add(cbPatient); + Controls.Add(label1); + Controls.Add(cbProcedure); + Controls.Add(dtpSchedule); + Controls.Add(button2); + Controls.Add(btnOK); + Controls.Add(label7); + Controls.Add(label6); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "ProcedureDataForm"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Назначение процедуры"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label label6; + private Label label7; + private Button button2; + internal DateTimePicker dtpSchedule; + internal ComboBox cbProcedure; + internal Button btnOK; + internal ComboBox cbPatient; + private Label label1; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.cs b/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.cs new file mode 100644 index 0000000..2fe0259 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.cs @@ -0,0 +1,108 @@ +using Microsoft.EntityFrameworkCore; +using Register_office.Model; +using Register_office.ViewModel; + +namespace Register_office.View.PatientV +{ + public partial class ProcedureDataForm : Form + { + private PrescriptionViewModel _viewModel; + private Prescription? _prescription; + + public ProcedureDataForm() + { + Init(); + } + + public ProcedureDataForm(Prescription p) + { + Init(); + SetData(p); + } + + private void Init() + { + InitializeComponent(); + TopMost = true; + _viewModel = new(); + SetDataSourceToComboBoxes(); + dtpSchedule.Value = + dtpSchedule.MinDate = DateTime.Now; + dtpSchedule.MaxDate = DateTime.Now.AddDays(180); + } + + private void SetData(Prescription prescription) + { + _prescription = prescription; + cbPatient.SelectedValue = prescription.PatientId; + dtpSchedule.Value = + dtpSchedule.MinDate = prescription.ProcedureTypePrescription.ScheduledDatetime; + cbProcedure.SelectedValue = prescription.ProcedureTypePrescription.ProcedureTypeId; + + Text = "Просмотр процедуры"; + btnOK.Visible = cbPatient.Enabled = + dtpSchedule.Enabled = cbProcedure.Enabled= false; + } + + private void SetDataSourceToComboBoxes() + { + cbProcedure.DataSource = _viewModel.General.Context.ProcedureTypes + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.ProcedureTypeId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbProcedure.DisplayMember = "Name"; + cbProcedure.ValueMember = "Id"; + + cbPatient.DataSource = _viewModel.General.Context.Patients + .Include(x => x.PatientNavigation) + .Select(x => new ComboBoxItem + { + Name = x.PatientNavigation.FirstName + " " + + x.PatientNavigation.FirstName + " " + + x.PatientNavigation.LastName, + Id = x.PatientId + }) + .OrderBy(cbi => cbi.Name).ToList(); + cbPatient.DisplayMember = "Name"; + cbPatient.ValueMember = "Id"; + } + + private void btnOK_Click(object sender, EventArgs e) + { + Prescription p = new() + { + DoctorId = _viewModel.General.DoctorId, + PatientId = int.Parse(cbPatient.SelectedValue?.ToString() ?? "-1") + }; + + Prescription? prInDb = _viewModel.General.Context.Prescriptions + .FirstOrDefault(x => x.PatientId == p.PatientId && x.DoctorId == p.DoctorId); + int id = prInDb?.PrescriptionId ?? 0; + if (prInDb == null) + { + id = _viewModel.AddPrescription(p); + if (id == -1) + { + DialogResult = DialogResult.None; + return; + } + } + + ProcedureTypePrescription pr = new() + { + PrescriptionId = id, + ProcedureTypeId = int.Parse(cbProcedure.SelectedValue?.ToString() ?? "0"), + ScheduledDatetime = dtpSchedule.Value + }; + if (_viewModel.AddPrescription(pr) == -1) + { + DialogResult = DialogResult.None; + return; + } + + MessageBox.Show("Процедура успешно назначена", "Назначение пользователю", + MessageBoxButtons.OK, MessageBoxIcon.Information); + Close(); + + } + } +} diff --git a/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.resx b/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ProcedureDataForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/ResultDataForm.Designer.cs b/Register office/Register office/View/PrescriptionsV/ResultDataForm.Designer.cs new file mode 100644 index 0000000..1467b15 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ResultDataForm.Designer.cs @@ -0,0 +1,217 @@ +namespace Register_office.View.TypesV +{ + partial class ResultDataForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + cbTypeResult = new ComboBox(); + label1 = new Label(); + button2 = new Button(); + btnOK = new Button(); + cbValue = new ComboBox(); + lblBool = new Label(); + lblUnit = new Label(); + cbUnit = new ComboBox(); + lblCount = new Label(); + nudCount = new NumericUpDown(); + cbExamination = new ComboBox(); + label2 = new Label(); + ((System.ComponentModel.ISupportInitialize)nudCount).BeginInit(); + SuspendLayout(); + // + // cbTypeResult + // + cbTypeResult.DropDownStyle = ComboBoxStyle.DropDownList; + cbTypeResult.Font = new Font("Segoe UI", 12F); + cbTypeResult.FormattingEnabled = true; + cbTypeResult.Items.AddRange(new object[] { "Числовой", "Качественный" }); + cbTypeResult.Location = new Point(12, 37); + cbTypeResult.Name = "cbTypeResult"; + cbTypeResult.Size = new Size(143, 29); + cbTypeResult.TabIndex = 24; + cbTypeResult.TextChanged += cbTypeResult_TextChanged; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(143, 25); + label1.TabIndex = 25; + label1.Text = "Тип результата"; + // + // button2 + // + button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + button2.DialogResult = DialogResult.Cancel; + button2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + button2.Location = new Point(192, 201); + button2.Name = "button2"; + button2.Size = new Size(161, 42); + button2.TabIndex = 27; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // + // btnOK + // + btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + btnOK.DialogResult = DialogResult.OK; + btnOK.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnOK.Location = new Point(12, 201); + btnOK.Name = "btnOK"; + btnOK.Size = new Size(161, 42); + btnOK.TabIndex = 26; + btnOK.Text = "Добавить"; + btnOK.UseVisualStyleBackColor = true; + btnOK.Click += btnOK_Click; + // + // cbValue + // + cbValue.DropDownStyle = ComboBoxStyle.DropDownList; + cbValue.Font = new Font("Segoe UI", 12F); + cbValue.FormattingEnabled = true; + cbValue.Items.AddRange(new object[] { "Положительный", "Отрицательный" }); + cbValue.Location = new Point(12, 97); + cbValue.Name = "cbValue"; + cbValue.Size = new Size(143, 29); + cbValue.TabIndex = 31; + // + // lblBool + // + lblBool.AutoSize = true; + lblBool.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + lblBool.Location = new Point(12, 69); + lblBool.Name = "lblBool"; + lblBool.Size = new Size(96, 25); + lblBool.TabIndex = 32; + lblBool.Text = "Результат"; + // + // lblUnit + // + lblUnit.AutoSize = true; + lblUnit.Font = new Font("Segoe UI", 14.25F); + lblUnit.Location = new Point(167, 129); + lblUnit.Name = "lblUnit"; + lblUnit.Size = new Size(186, 25); + lblUnit.TabIndex = 36; + lblUnit.Text = "Единица измерения"; + // + // cbUnit + // + cbUnit.DropDownStyle = ComboBoxStyle.DropDownList; + cbUnit.Font = new Font("Segoe UI", 12F); + cbUnit.FormattingEnabled = true; + cbUnit.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbUnit.Location = new Point(167, 157); + cbUnit.Name = "cbUnit"; + cbUnit.Size = new Size(186, 29); + cbUnit.TabIndex = 35; + // + // lblCount + // + lblCount.AutoSize = true; + lblCount.Font = new Font("Segoe UI", 14.25F); + lblCount.Location = new Point(12, 129); + lblCount.Name = "lblCount"; + lblCount.Size = new Size(114, 25); + lblCount.TabIndex = 34; + lblCount.Text = "Количество"; + // + // nudCount + // + nudCount.DecimalPlaces = 2; + nudCount.Font = new Font("Segoe UI", 12F); + nudCount.Increment = new decimal(new int[] { 1, 0, 0, 65536 }); + nudCount.Location = new Point(12, 157); + nudCount.Minimum = new decimal(new int[] { 100, 0, 0, int.MinValue }); + nudCount.Name = "nudCount"; + nudCount.Size = new Size(143, 29); + nudCount.TabIndex = 33; + // + // cbExamination + // + cbExamination.DropDownStyle = ComboBoxStyle.DropDownList; + cbExamination.Font = new Font("Segoe UI", 12F); + cbExamination.FormattingEnabled = true; + cbExamination.Items.AddRange(new object[] { "Числовой", "Качественный" }); + cbExamination.Location = new Point(167, 37); + cbExamination.Name = "cbExamination"; + cbExamination.Size = new Size(186, 29); + cbExamination.TabIndex = 37; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(167, 9); + label2.Name = "label2"; + label2.Size = new Size(139, 25); + label2.TabIndex = 38; + label2.Text = "Обследование"; + // + // ResultDataForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(365, 255); + Controls.Add(cbExamination); + Controls.Add(label2); + Controls.Add(lblUnit); + Controls.Add(cbUnit); + Controls.Add(lblCount); + Controls.Add(nudCount); + Controls.Add(cbValue); + Controls.Add(lblBool); + Controls.Add(button2); + Controls.Add(btnOK); + Controls.Add(cbTypeResult); + Controls.Add(label1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "ResultDataForm"; + Text = "Результаты"; + ((System.ComponentModel.ISupportInitialize)nudCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + internal ComboBox cbTypeResult; + private Label label1; + private Button button2; + internal Button btnOK; + internal ComboBox cbValue; + private Label lblBool; + private Label lblUnit; + private ComboBox cbUnit; + private Label lblCount; + private NumericUpDown nudCount; + internal ComboBox cbExamination; + private Label label2; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/PrescriptionsV/ResultDataForm.cs b/Register office/Register office/View/PrescriptionsV/ResultDataForm.cs new file mode 100644 index 0000000..db7bdae --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ResultDataForm.cs @@ -0,0 +1,161 @@ +using Microsoft.EntityFrameworkCore; +using Register_office.Model; +using Register_office.ViewModel; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Register_office.View.TypesV +{ + public partial class ResultDataForm : Form + { + private ResultViewModel _viewModel; + private ExaminationTypePrescription? _prescription; + bool _isNumericResult; + public ResultDataForm(ExaminationTypePrescription p, bool isForAdd = true) + { + Init(); + _prescription = p; + cbExamination.SelectedValue = p.ExaminationTypeId; + cbExamination.Enabled = false; + if (!isForAdd) SetData(p); + } + + private void Init() + { + InitializeComponent(); + TopMost = true; + _viewModel = new(); + SetDataSourceToComboBoxes(); + } + + private void SetData(ExaminationTypePrescription prescription) + { + _prescription = _viewModel.General.Context.ExaminationTypePrescriptions + .Include(x => x.Result) + .ThenInclude(y => y.NumericResult) + .Include(x => x.Result) + .ThenInclude(y => y.QualitativeResult) + .First(x => x.ExaminationPrescriptionId == prescription.ExaminationPrescriptionId); + _isNumericResult = _prescription.Result.QualitativeResult == null; + cbTypeResult.Text = _isNumericResult + ? "Числовой" + : "Качественный"; + if (_isNumericResult) + { + nudCount.Value = _prescription.Result.NumericResult.Value; + cbUnit.SelectedValue = _prescription.Result.NumericResult.UnitId; + + nudCount.Visible = cbUnit.Visible = + lblCount.Visible = lblUnit.Visible = true; + cbValue.Visible = lblBool.Visible = false; + } + else + { + cbValue.Text = _prescription.Result.QualitativeResult.Value + ? "Положительный" + : "Отрицательный"; + nudCount.Visible = cbUnit.Visible = + lblCount.Visible = lblUnit.Visible = false; + cbValue.Visible = lblBool.Visible = true; + } + + Text = "Просмотр результатов"; + btnOK.Visible = cbTypeResult.Enabled = + nudCount.Enabled = cbUnit.Enabled = + cbValue.Enabled = false; + } + + private void SetDataSourceToComboBoxes() + { + cbTypeResult.SelectedItem = cbTypeResult.Items[0]; + cbExamination.DataSource = _viewModel.General.Context.ExaminationTypes + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.ExaminationTypeId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbExamination.DisplayMember = "Name"; + cbExamination.ValueMember = "Id"; + + cbUnit.DataSource = _viewModel.General.Context.Units + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.UnitId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbUnit.DisplayMember = "Name"; + cbUnit.ValueMember = "Id"; + } + + private void btnOK_Click(object sender, EventArgs e) + { + Result r = new() + { + ExaminationId = int.Parse(cbExamination.SelectedValue?.ToString() ?? "-1") + }; + + int id = _viewModel.AddResult(r); + if (id == -1) + { + DialogResult = DialogResult.None; + return; + } + + if (cbTypeResult.Text == "Качественный") + { + QualitativeResult qr = new() + { + ResultId = id, + Value = cbValue.Text == "Положительный" + }; + if (_viewModel.AddResult(qr) == -1) + { + DialogResult = DialogResult.None; + _viewModel.DeleteResult(r); + return; + } + } + else + { + + NumericResult nr = new() + { + ResultId = id, + UnitId = int.Parse(cbUnit.SelectedValue?.ToString() ?? "0"), + Value = nudCount.Value + }; + if (_viewModel.AddResult(nr) == -1) + { + DialogResult = DialogResult.None; + _viewModel.DeleteResult(r); + return; + } + } + + _prescription.ResultId = id; + _viewModel.Update(); + + MessageBox.Show("Результаты успешно добавлены", "Результаты обследования", + MessageBoxButtons.OK, MessageBoxIcon.Information); + Close(); + + } + + private void cbTypeResult_TextChanged(object sender, EventArgs e) + { + if (cbTypeResult.Text == "Качественный") + { + nudCount.Visible = cbUnit.Visible = + lblCount.Visible = lblUnit.Visible = false; + cbValue.Visible = lblBool.Visible = true; + } + else + { + nudCount.Visible = cbUnit.Visible = + lblCount.Visible = lblUnit.Visible = true; + cbValue.Visible = lblBool.Visible = false; + } + } + } +} diff --git a/Register office/Register office/View/PrescriptionsV/ResultDataForm.resx b/Register office/Register office/View/PrescriptionsV/ResultDataForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/PrescriptionsV/ResultDataForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/RegistrationV/ConnectionParametersForm.Designer.cs b/Register office/Register office/View/RegistrationV/ConnectionParametersForm.Designer.cs new file mode 100644 index 0000000..3914edd --- /dev/null +++ b/Register office/Register office/View/RegistrationV/ConnectionParametersForm.Designer.cs @@ -0,0 +1,164 @@ +namespace Register_office.View.RegistrationV +{ + partial class ConnectionParametersForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + button1 = new Button(); + tbHost = new TextBox(); + label2 = new Label(); + tbDataBase = new TextBox(); + label1 = new Label(); + tbPassword = new TextBox(); + label3 = new Label(); + tbUsername = new TextBox(); + label4 = new Label(); + SuspendLayout(); + // + // button1 + // + button1.DialogResult = DialogResult.OK; + button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + button1.Location = new Point(12, 236); + button1.Name = "button1"; + button1.Size = new Size(75, 29); + button1.TabIndex = 2; + button1.Text = "ОК"; + button1.UseVisualStyleBackColor = true; + // + // tbHost + // + tbHost.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + tbHost.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbHost.Location = new Point(12, 33); + tbHost.Name = "tbHost"; + tbHost.Size = new Size(212, 29); + tbHost.TabIndex = 30; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(12, 9); + label2.Name = "label2"; + label2.Size = new Size(124, 21); + label2.TabIndex = 31; + label2.Text = "Владелец (Host)"; + // + // tbDataBase + // + tbDataBase.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + tbDataBase.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbDataBase.Location = new Point(12, 89); + tbDataBase.Name = "tbDataBase"; + tbDataBase.Size = new Size(212, 29); + tbDataBase.TabIndex = 32; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 65); + label1.Name = "label1"; + label1.Size = new Size(99, 21); + label1.TabIndex = 33; + label1.Text = "База данных"; + // + // tbPassword + // + tbPassword.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + tbPassword.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbPassword.Location = new Point(12, 201); + tbPassword.Name = "tbPassword"; + tbPassword.Size = new Size(212, 29); + tbPassword.TabIndex = 36; + tbPassword.UseSystemPasswordChar = true; + // + // label3 + // + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(12, 177); + label3.Name = "label3"; + label3.Size = new Size(63, 21); + label3.TabIndex = 37; + label3.Text = "Пароль"; + // + // tbUsername + // + tbUsername.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + tbUsername.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbUsername.Location = new Point(12, 145); + tbUsername.Name = "tbUsername"; + tbUsername.Size = new Size(212, 29); + tbUsername.TabIndex = 34; + // + // label4 + // + label4.AutoSize = true; + label4.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + label4.Location = new Point(12, 121); + label4.Name = "label4"; + label4.Size = new Size(151, 21); + label4.TabIndex = 35; + label4.Text = "Суперпользователь"; + // + // ConnectionParametersForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(236, 269); + Controls.Add(tbPassword); + Controls.Add(label3); + Controls.Add(tbUsername); + Controls.Add(label4); + Controls.Add(tbDataBase); + Controls.Add(label1); + Controls.Add(tbHost); + Controls.Add(label2); + Controls.Add(button1); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "ConnectionParametersForm"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Параметры подключения"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button button1; + internal TextBox tbHost; + private Label label2; + internal TextBox tbDataBase; + private Label label1; + internal TextBox tbPassword; + private Label label3; + internal TextBox tbUsername; + private Label label4; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/RegistrationV/ConnectionParametersForm.cs b/Register office/Register office/View/RegistrationV/ConnectionParametersForm.cs new file mode 100644 index 0000000..1c92e76 --- /dev/null +++ b/Register office/Register office/View/RegistrationV/ConnectionParametersForm.cs @@ -0,0 +1,10 @@ +namespace Register_office.View.RegistrationV +{ + public partial class ConnectionParametersForm : Form + { + public ConnectionParametersForm() + { + InitializeComponent(); + } + } +} diff --git a/Register office/Register office/View/RegistrationV/ConnectionParametersForm.resx b/Register office/Register office/View/RegistrationV/ConnectionParametersForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/RegistrationV/ConnectionParametersForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/RegistrationV/LoginForm.Designer.cs b/Register office/Register office/View/RegistrationV/LoginForm.Designer.cs new file mode 100644 index 0000000..f553530 --- /dev/null +++ b/Register office/Register office/View/RegistrationV/LoginForm.Designer.cs @@ -0,0 +1,121 @@ +namespace Register_office.View.LoginV +{ + partial class LoginForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + tbLogin = new TextBox(); + tbPassword = new TextBox(); + label2 = new Label(); + btnEntry = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 12F, FontStyle.Bold); + label1.Location = new Point(12, 23); + label1.Name = "label1"; + label1.Size = new Size(63, 21); + label1.TabIndex = 0; + label1.Text = "Логин:"; + // + // tbLogin + // + tbLogin.Font = new Font("Segoe UI", 12F, FontStyle.Bold); + tbLogin.Location = new Point(99, 20); + tbLogin.MaxLength = 20; + tbLogin.Name = "tbLogin"; + tbLogin.Size = new Size(131, 29); + tbLogin.TabIndex = 1; + tbLogin.Text = "Иванов Н.В."; + tbLogin.KeyDown += RegistrationForm_KeyDown; + // + // tbPassword + // + tbPassword.Font = new Font("Segoe UI", 12F, FontStyle.Bold); + tbPassword.Location = new Point(98, 61); + tbPassword.MaxLength = 20; + tbPassword.Name = "tbPassword"; + tbPassword.Size = new Size(131, 29); + tbPassword.TabIndex = 3; + tbPassword.Text = "Иванов123"; + tbPassword.UseSystemPasswordChar = true; + tbPassword.KeyDown += RegistrationForm_KeyDown; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 12F, FontStyle.Bold); + label2.Location = new Point(11, 64); + label2.Name = "label2"; + label2.Size = new Size(74, 21); + label2.TabIndex = 2; + label2.Text = "Пароль:"; + // + // btnEntry + // + btnEntry.BackColor = Color.LightBlue; + btnEntry.FlatStyle = FlatStyle.Flat; + btnEntry.Font = new Font("Segoe UI", 12F); + btnEntry.Location = new Point(54, 104); + btnEntry.Name = "btnEntry"; + btnEntry.Size = new Size(131, 31); + btnEntry.TabIndex = 4; + btnEntry.Text = "ВВОД"; + btnEntry.UseVisualStyleBackColor = false; + btnEntry.Click += btnEntry_Click; + // + // LoginForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(243, 147); + Controls.Add(btnEntry); + Controls.Add(tbPassword); + Controls.Add(label2); + Controls.Add(tbLogin); + Controls.Add(label1); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "LoginForm"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Авторизация пользователя"; + KeyDown += RegistrationForm_KeyDown; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox tbLogin; + private TextBox tbPassword; + private Label label2; + private Button btnEntry; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/RegistrationV/LoginForm.cs b/Register office/Register office/View/RegistrationV/LoginForm.cs new file mode 100644 index 0000000..2794a2b --- /dev/null +++ b/Register office/Register office/View/RegistrationV/LoginForm.cs @@ -0,0 +1,53 @@ +//using Register_office.View.MenuV; +using Register_office.ViewModel.LoginVM; +using Npgsql; +using Register_office.View.MenuV; + +namespace Register_office.View.LoginV +{ + internal partial class LoginForm : Form + { + private readonly LoginViewModel _viewModel; + + public LoginForm() + { + _viewModel = new(); + InitializeComponent(); + } + + /// + /// Входит в систему + /// + private void btnEntry_Click(object sender, EventArgs e) + { + try + { + // Проверяем логин и пароль + int personId = _viewModel.CheckEnter(tbLogin.Text, tbPassword.Text); + _viewModel.General.DoctorId = _viewModel.GetDoctorId(personId); + + Hide(); + OnlyMenuForm launchForm = new(); + launchForm.ShowDialog(); + + Close(); + } + catch (NpgsqlException ex) + { + MessageBox.Show(ex.Message.Split(':').Skip(1).FirstOrDefault()?.Trim(), + "Ошибка ввода данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// При нажатии enter - производит событие входа в систему + /// + private void RegistrationForm_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + btnEntry.PerformClick(); + } + } + } +} diff --git a/Register office/Register office/View/RegistrationV/LoginForm.resx b/Register office/Register office/View/RegistrationV/LoginForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/RegistrationV/LoginForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/DiseaseForm.Designer.cs b/Register office/Register office/View/TypesV/DiseaseForm.Designer.cs new file mode 100644 index 0000000..c8463c3 --- /dev/null +++ b/Register office/Register office/View/TypesV/DiseaseForm.Designer.cs @@ -0,0 +1,219 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class DiseaseForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + label2 = new Label(); + tbCodeICB = new TextBox(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + label1 = new Label(); + tbName = new TextBox(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(label2); + splitContainer1.Panel1.Controls.Add(tbCodeICB); + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(label1); + splitContainer1.Panel1.Controls.Add(tbName); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // label2 + // + label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(276, 9); + label2.Name = "label2"; + label2.Size = new Size(62, 17); + label2.TabIndex = 10; + label2.Text = "Код МКБ"; + // + // tbCodeICB + // + tbCodeICB.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbCodeICB.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbCodeICB.Location = new Point(276, 32); + tbCodeICB.Name = "tbCodeICB"; + tbCodeICB.Size = new Size(125, 27); + tbCodeICB.TabIndex = 9; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 72); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // label1 + // + label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 10); + label1.Name = "label1"; + label1.Size = new Size(65, 17); + label1.TabIndex = 1; + label1.Text = "Название"; + // + // tbName + // + tbName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbName.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbName.Location = new Point(12, 33); + tbName.Name = "tbName"; + tbName.Size = new Size(242, 27); + tbName.TabIndex = 0; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // DiseaseForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "DiseaseForm"; + Text = "Справочник"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private TextBox tbName; + private Label label1; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Label label2; + private TextBox tbCodeICB; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/DiseaseForm.cs b/Register office/Register office/View/TypesV/DiseaseForm.cs new file mode 100644 index 0000000..26545d3 --- /dev/null +++ b/Register office/Register office/View/TypesV/DiseaseForm.cs @@ -0,0 +1,83 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class DiseaseForm : Form + { + private TypeViewModel _viewModel; + private Disease? _selectedType; + private string _columnIdName = "DiseaseId"; + + public DiseaseForm() + { + InitializeComponent(); + Text = "Справочник заболеваний"; + TopMost = true; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + } + + private void UpdateElements(string name = "", string codeIcb = "", bool enableButtons = false) + { + tbName.Text = name; + tbCodeICB.Text = codeIcb; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.Diseases.Where(x => x.DiseaseId == id).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.Name, _selectedType.IcdCode, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.Name = tbName.Text; + _selectedType.IcdCode = tbCodeICB.Text; + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + Disease d = new() + { + Name = tbName.Text, + IcdCode = tbCodeICB.Text + }; + _viewModel.AddType(d); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/DiseaseForm.resx b/Register office/Register office/View/TypesV/DiseaseForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/DiseaseForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/DiseaseSyndromeForm.Designer.cs b/Register office/Register office/View/TypesV/DiseaseSyndromeForm.Designer.cs new file mode 100644 index 0000000..d61e609 --- /dev/null +++ b/Register office/Register office/View/TypesV/DiseaseSyndromeForm.Designer.cs @@ -0,0 +1,221 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class DiseaseSyndromeForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + label3 = new Label(); + btnAdd = new Button(); + cbDisease = new ComboBox(); + btnDelete = new Button(); + label2 = new Label(); + cbSyndrome = new ComboBox(); + btnUpdate = new Button(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(label3); + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(cbDisease); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(label2); + splitContainer1.Panel1.Controls.Add(cbSyndrome); + splitContainer1.Panel1.Controls.Add(btnUpdate); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // label3 + // + label3.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(232, 17); + label3.Name = "label3"; + label3.Size = new Size(87, 17); + label3.TabIndex = 14; + label3.Text = "Заболевание"; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 72); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // cbDisease + // + cbDisease.DropDownStyle = ComboBoxStyle.DropDownList; + cbDisease.FormattingEnabled = true; + cbDisease.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbDisease.Location = new Point(232, 37); + cbDisease.Name = "cbDisease"; + cbDisease.Size = new Size(211, 25); + cbDisease.TabIndex = 13; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // label2 + // + label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(12, 16); + label2.Name = "label2"; + label2.Size = new Size(62, 17); + label2.TabIndex = 12; + label2.Text = "Синдром"; + // + // cbSyndrome + // + cbSyndrome.DropDownStyle = ComboBoxStyle.DropDownList; + cbSyndrome.FormattingEnabled = true; + cbSyndrome.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbSyndrome.Location = new Point(12, 37); + cbSyndrome.Name = "cbSyndrome"; + cbSyndrome.Size = new Size(214, 25); + cbSyndrome.TabIndex = 11; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // DiseaseSyndromeForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "DiseaseSyndromeForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Label label3; + private ComboBox cbDisease; + private Label label2; + private ComboBox cbSyndrome; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/DiseaseSyndromeForm.cs b/Register office/Register office/View/TypesV/DiseaseSyndromeForm.cs new file mode 100644 index 0000000..1441817 --- /dev/null +++ b/Register office/Register office/View/TypesV/DiseaseSyndromeForm.cs @@ -0,0 +1,101 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class DiseaseSyndromeForm : Form + { + private TypeViewModel _viewModel; + private DiseaseSyndrome? _selectedType; + private DiseaseSyndrome _temp; + + public DiseaseSyndromeForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник соответствий заболеваний и синдромов"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + SetDataSourceToComboBoxes(); + UpdateElements(); + } + + private void SetDataSourceToComboBoxes() + { + cbDisease.DataSource = _viewModel.General.Context.Diseases + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.DiseaseId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbDisease.DisplayMember = "Name"; + cbDisease.ValueMember = "Id"; + + cbSyndrome.DataSource = _viewModel.General.Context.SyndromeTypes + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.SyndromeTypeId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbSyndrome.DisplayMember = "Name"; + cbSyndrome.ValueMember = "Id"; + } + + private void UpdateElements(int idDis = -1, int idSynd = -1, bool enableButtons = false) + { + cbDisease.SelectedValue = idDis; + cbSyndrome.SelectedValue = idSynd; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int idDis = int.Parse(selectedRow.Cells["DiseaseId"].Value.ToString() ?? ""); + int idSynd = int.Parse(selectedRow.Cells["SyndromeId"].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.DiseaseSyndromes + .Where(x => x.DiseaseId == idDis && x.SyndromeId == idSynd).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.DiseaseId, _selectedType.SyndromeId, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.DiseaseId = int.Parse(cbDisease.SelectedValue?.ToString() ?? "-1"); + _selectedType.SyndromeId = int.Parse(cbSyndrome.SelectedValue?.ToString() ?? "-1"); + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + _temp = new() + { + DiseaseId = int.Parse(cbDisease.SelectedValue?.ToString() ?? "-1"), + SyndromeId = int.Parse(cbSyndrome.SelectedValue?.ToString() ?? "-1") + }; + _viewModel.AddType(_temp); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/DiseaseSyndromeForm.resx b/Register office/Register office/View/TypesV/DiseaseSyndromeForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/DiseaseSyndromeForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/DrugIntakeMethodForm.Designer.cs b/Register office/Register office/View/TypesV/DrugIntakeMethodForm.Designer.cs new file mode 100644 index 0000000..66eb20a --- /dev/null +++ b/Register office/Register office/View/TypesV/DrugIntakeMethodForm.Designer.cs @@ -0,0 +1,193 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class DrugIntakeMethodForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + label1 = new Label(); + tbName = new TextBox(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(label1); + splitContainer1.Panel1.Controls.Add(tbName); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 72); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // label1 + // + label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 10); + label1.Name = "label1"; + label1.Size = new Size(65, 17); + label1.TabIndex = 1; + label1.Text = "Название"; + // + // tbName + // + tbName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbName.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbName.Location = new Point(12, 33); + tbName.Name = "tbName"; + tbName.Size = new Size(242, 27); + tbName.TabIndex = 0; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // DrugIntakeMethodForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "DrugIntakeMethodForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private TextBox tbName; + private Label label1; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/DrugIntakeMethodForm.cs b/Register office/Register office/View/TypesV/DrugIntakeMethodForm.cs new file mode 100644 index 0000000..875ad71 --- /dev/null +++ b/Register office/Register office/View/TypesV/DrugIntakeMethodForm.cs @@ -0,0 +1,79 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class DrugIntakeMethodForm : Form + { + private TypeViewModel _viewModel; + private DrugIntakeMethod? _selectedType; + private string _columnIdName = "DrugIntakeMethodId"; + public DrugIntakeMethodForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник способов приема лекарств"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + } + + private void UpdateElements(string name = "", bool enableButtons = false) + { + tbName.Text = name; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.DrugIntakeMethods.Where(x => x.DrugIntakeMethodId == id).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.Name, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.Name = tbName.Text; + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + DrugIntakeMethod t = new() + { + Name = tbName.Text + }; + _viewModel.AddType(t); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/DrugIntakeMethodForm.resx b/Register office/Register office/View/TypesV/DrugIntakeMethodForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/DrugIntakeMethodForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/DrugTypeForm.Designer.cs b/Register office/Register office/View/TypesV/DrugTypeForm.Designer.cs new file mode 100644 index 0000000..a1a616a --- /dev/null +++ b/Register office/Register office/View/TypesV/DrugTypeForm.Designer.cs @@ -0,0 +1,271 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class DrugTypeForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + label1 = new Label(); + tbNameRu = new TextBox(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + label2 = new Label(); + tbNameEn = new TextBox(); + label3 = new Label(); + tbNameLa = new TextBox(); + label4 = new Label(); + tbBrand = new TextBox(); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(label4); + splitContainer1.Panel1.Controls.Add(tbBrand); + splitContainer1.Panel1.Controls.Add(label3); + splitContainer1.Panel1.Controls.Add(tbNameLa); + splitContainer1.Panel1.Controls.Add(label2); + splitContainer1.Panel1.Controls.Add(tbNameEn); + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(label1); + splitContainer1.Panel1.Controls.Add(tbNameRu); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 84); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // label1 + // + label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 10); + label1.Name = "label1"; + label1.Size = new Size(91, 17); + label1.TabIndex = 1; + label1.Text = "Название (ру)"; + // + // tbNameRu + // + tbNameRu.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbNameRu.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbNameRu.Location = new Point(12, 33); + tbNameRu.Name = "tbNameRu"; + tbNameRu.Size = new Size(208, 27); + tbNameRu.TabIndex = 0; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // label2 + // + label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(226, 9); + label2.Name = "label2"; + label2.Size = new Size(103, 17); + label2.TabIndex = 6; + label2.Text = "Название (англ)"; + // + // tbNameEn + // + tbNameEn.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbNameEn.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbNameEn.Location = new Point(226, 32); + tbNameEn.Name = "tbNameEn"; + tbNameEn.Size = new Size(208, 27); + tbNameEn.TabIndex = 5; + // + // label3 + // + label3.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(12, 67); + label3.Name = "label3"; + label3.Size = new Size(96, 17); + label3.TabIndex = 8; + label3.Text = "Название (лат)"; + // + // tbNameLa + // + tbNameLa.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbNameLa.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbNameLa.Location = new Point(12, 90); + tbNameLa.Name = "tbNameLa"; + tbNameLa.Size = new Size(208, 27); + tbNameLa.TabIndex = 7; + // + // label4 + // + label4.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label4.AutoSize = true; + label4.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label4.Location = new Point(226, 67); + label4.Name = "label4"; + label4.Size = new Size(43, 17); + label4.TabIndex = 10; + label4.Text = "Брэнд"; + // + // tbBrand + // + tbBrand.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbBrand.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbBrand.Location = new Point(226, 90); + tbBrand.Name = "tbBrand"; + tbBrand.Size = new Size(208, 27); + tbBrand.TabIndex = 9; + // + // DrugTypeForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "DrugTypeForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private TextBox tbNameRu; + private Label label1; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Label label4; + private TextBox tbBrand; + private Label label3; + private TextBox tbNameLa; + private Label label2; + private TextBox tbNameEn; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/DrugTypeForm.cs b/Register office/Register office/View/TypesV/DrugTypeForm.cs new file mode 100644 index 0000000..200539f --- /dev/null +++ b/Register office/Register office/View/TypesV/DrugTypeForm.cs @@ -0,0 +1,93 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class DrugTypeForm : Form + { + private TypeViewModel _viewModel; + private DrugType? _selectedType; + private string _columnIdName = "DrugTypeId"; + private DrugType _temp; + + public DrugTypeForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник лекарств"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + } + + private void UpdateElements(string nameRu = "", string? nameEn = "", + string? nameLa = "", string? brand = "", bool enableButtons = false) + { + tbNameRu.Text = nameRu; + tbNameEn.Text = nameEn; + tbNameLa.Text = nameLa; + tbBrand.Text = brand; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.DrugTypes.Where(x => x.DrugTypeId == id).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.InternationalNameRu, + _selectedType.InternationalNameEn, _selectedType.InternationalNameLa, + _selectedType.BrandNameRu, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.InternationalNameRu = tbNameRu.Text; + _selectedType.InternationalNameEn = tbNameEn.Text.Trim() == "" ? null : tbNameEn.Text; + _selectedType.InternationalNameLa = tbNameLa.Text.Trim() == "" ? null : tbNameLa.Text; + _selectedType.BrandNameRu = tbBrand.Text.Trim() == "" ? null : tbBrand.Text; + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + _temp = new() + { + InternationalNameRu = tbNameRu.Text, + InternationalNameEn = tbNameEn.Text.Trim() == "" ? null : tbNameEn.Text, + InternationalNameLa = tbNameLa.Text.Trim() == "" ? null : tbNameLa.Text, + BrandNameRu = tbBrand.Text.Trim() == "" ? null : tbBrand.Text + }; + _viewModel.AddType(_temp); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/DrugTypeForm.resx b/Register office/Register office/View/TypesV/DrugTypeForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/DrugTypeForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/ExaminationTypeForm.Designer.cs b/Register office/Register office/View/TypesV/ExaminationTypeForm.Designer.cs new file mode 100644 index 0000000..558afd6 --- /dev/null +++ b/Register office/Register office/View/TypesV/ExaminationTypeForm.Designer.cs @@ -0,0 +1,220 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class ExaminationTypeForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + label2 = new Label(); + cbCategory = new ComboBox(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + label1 = new Label(); + tbName = new TextBox(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(label2); + splitContainer1.Panel1.Controls.Add(cbCategory); + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(label1); + splitContainer1.Panel1.Controls.Add(tbName); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // label2 + // + label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(260, 13); + label2.Name = "label2"; + label2.Size = new Size(70, 17); + label2.TabIndex = 6; + label2.Text = "Категория"; + // + // cbCategory + // + cbCategory.DropDownStyle = ComboBoxStyle.DropDownList; + cbCategory.FormattingEnabled = true; + cbCategory.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbCategory.Location = new Point(260, 34); + cbCategory.Name = "cbCategory"; + cbCategory.Size = new Size(192, 25); + cbCategory.TabIndex = 5; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 72); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // label1 + // + label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 10); + label1.Name = "label1"; + label1.Size = new Size(65, 17); + label1.TabIndex = 1; + label1.Text = "Название"; + // + // tbName + // + tbName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbName.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbName.Location = new Point(12, 33); + tbName.Name = "tbName"; + tbName.Size = new Size(242, 27); + tbName.TabIndex = 0; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // ExaminationTypeForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "ExaminationTypeForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private TextBox tbName; + private Label label1; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Label label2; + private ComboBox cbCategory; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/ExaminationTypeForm.cs b/Register office/Register office/View/TypesV/ExaminationTypeForm.cs new file mode 100644 index 0000000..f730baa --- /dev/null +++ b/Register office/Register office/View/TypesV/ExaminationTypeForm.cs @@ -0,0 +1,84 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class ExaminationTypeForm : Form + { + private TypeViewModel _viewModel; + private ExaminationType? _selectedType; + private string _columnIdName = "ExaminationTypeId"; + private ExaminationType _temp; + + public ExaminationTypeForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник обследований"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + } + + private void UpdateElements(string txt1 = "", string txt2 = "", bool enableButtons = false) + { + tbName.Text = txt1; + cbCategory.Text = txt2; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.ExaminationTypes.Where(x => x.ExaminationTypeId == id).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.Name, _selectedType.Category, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.Name = tbName.Text; + _selectedType.Category = cbCategory.Text; + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + _temp = new() + { + Name = tbName.Text, + Category = cbCategory.Text + }; + _viewModel.AddType(_temp); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/ExaminationTypeForm.resx b/Register office/Register office/View/TypesV/ExaminationTypeForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/ExaminationTypeForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/ProcedureTypeForm.Designer.cs b/Register office/Register office/View/TypesV/ProcedureTypeForm.Designer.cs new file mode 100644 index 0000000..d5941bf --- /dev/null +++ b/Register office/Register office/View/TypesV/ProcedureTypeForm.Designer.cs @@ -0,0 +1,193 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class ProcedureTypeForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + label1 = new Label(); + tbName = new TextBox(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(label1); + splitContainer1.Panel1.Controls.Add(tbName); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 72); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // label1 + // + label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 10); + label1.Name = "label1"; + label1.Size = new Size(65, 17); + label1.TabIndex = 1; + label1.Text = "Название"; + // + // tbName + // + tbName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbName.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbName.Location = new Point(12, 33); + tbName.Name = "tbName"; + tbName.Size = new Size(242, 27); + tbName.TabIndex = 0; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // DrugIntakeMethodForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "DrugIntakeMethodForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private TextBox tbName; + private Label label1; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/ProcedureTypeForm.cs b/Register office/Register office/View/TypesV/ProcedureTypeForm.cs new file mode 100644 index 0000000..1dced2b --- /dev/null +++ b/Register office/Register office/View/TypesV/ProcedureTypeForm.cs @@ -0,0 +1,81 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class ProcedureTypeForm : Form + { + private TypeViewModel _viewModel; + private ProcedureType? _selectedType; + private string _columnIdName = "ProcedureTypeId"; + private ProcedureType _temp; + + public ProcedureTypeForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник процедур"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + } + + private void UpdateElements(string name = "", bool enableButtons = false) + { + tbName.Text = name; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.ProcedureTypes.Where(x => x.ProcedureTypeId == id).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.Name, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.Name = tbName.Text; + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + _temp = new() + { + Name = tbName.Text + }; + _viewModel.AddType(_temp); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/ProcedureTypeForm.resx b/Register office/Register office/View/TypesV/ProcedureTypeForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/ProcedureTypeForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/ReferenceValueForm.Designer.cs b/Register office/Register office/View/TypesV/ReferenceValueForm.Designer.cs new file mode 100644 index 0000000..3f2dde3 --- /dev/null +++ b/Register office/Register office/View/TypesV/ReferenceValueForm.Designer.cs @@ -0,0 +1,291 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class ReferenceValueForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + btnOpen = new Button(); + label5 = new Label(); + label4 = new Label(); + nudAgeMax = new NumericUpDown(); + nudAgeMin = new NumericUpDown(); + label3 = new Label(); + cbGender = new ComboBox(); + label2 = new Label(); + cbExamination = new ComboBox(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)nudAgeMax).BeginInit(); + ((System.ComponentModel.ISupportInitialize)nudAgeMin).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(btnOpen); + splitContainer1.Panel1.Controls.Add(label5); + splitContainer1.Panel1.Controls.Add(label4); + splitContainer1.Panel1.Controls.Add(nudAgeMax); + splitContainer1.Panel1.Controls.Add(nudAgeMin); + splitContainer1.Panel1.Controls.Add(label3); + splitContainer1.Panel1.Controls.Add(cbGender); + splitContainer1.Panel1.Controls.Add(label2); + splitContainer1.Panel1.Controls.Add(cbExamination); + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // btnOpen + // + btnOpen.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnOpen.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnOpen.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnOpen.Location = new Point(260, 78); + btnOpen.Name = "btnOpen"; + btnOpen.Size = new Size(192, 33); + btnOpen.TabIndex = 15; + btnOpen.Text = "Открыть подробности"; + btnOpen.UseVisualStyleBackColor = true; + btnOpen.Click += btnOpen_Click; + // + // label5 + // + label5.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label5.AutoSize = true; + label5.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label5.Location = new Point(142, 63); + label5.Name = "label5"; + label5.Size = new Size(93, 17); + label5.TabIndex = 14; + label5.Text = "Макс. возраст"; + // + // label4 + // + label4.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label4.AutoSize = true; + label4.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label4.Location = new Point(21, 63); + label4.Name = "label4"; + label4.Size = new Size(88, 17); + label4.TabIndex = 13; + label4.Text = "Мин. возраст"; + // + // nudAgeMax + // + nudAgeMax.Location = new Point(142, 83); + nudAgeMax.Minimum = new decimal(new int[] { 1, 0, 0, int.MinValue }); + nudAgeMax.Name = "nudAgeMax"; + nudAgeMax.Size = new Size(96, 25); + nudAgeMax.TabIndex = 12; + // + // nudAgeMin + // + nudAgeMin.Location = new Point(21, 83); + nudAgeMin.Minimum = new decimal(new int[] { 1, 0, 0, int.MinValue }); + nudAgeMin.Name = "nudAgeMin"; + nudAgeMin.Size = new Size(96, 25); + nudAgeMin.TabIndex = 11; + // + // label3 + // + label3.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(260, 14); + label3.Name = "label3"; + label3.Size = new Size(32, 17); + label3.TabIndex = 10; + label3.Text = "Пол"; + // + // cbGender + // + cbGender.DropDownStyle = ComboBoxStyle.DropDownList; + cbGender.FormattingEnabled = true; + cbGender.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbGender.Location = new Point(260, 35); + cbGender.Name = "cbGender"; + cbGender.Size = new Size(192, 25); + cbGender.TabIndex = 9; + // + // label2 + // + label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(21, 14); + label2.Name = "label2"; + label2.Size = new Size(96, 17); + label2.TabIndex = 8; + label2.Text = "Обследование"; + // + // cbExamination + // + cbExamination.DropDownStyle = ComboBoxStyle.DropDownList; + cbExamination.FormattingEnabled = true; + cbExamination.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbExamination.Location = new Point(21, 35); + cbExamination.Name = "cbExamination"; + cbExamination.Size = new Size(214, 25); + cbExamination.TabIndex = 7; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 78); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 33); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // ReferenceValueForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "ReferenceValueForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)nudAgeMax).EndInit(); + ((System.ComponentModel.ISupportInitialize)nudAgeMin).EndInit(); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Label label2; + private ComboBox cbExamination; + private Label label3; + private ComboBox cbGender; + private Label label5; + private Label label4; + private NumericUpDown nudAgeMax; + private NumericUpDown nudAgeMin; + private Button btnOpen; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/ReferenceValueForm.cs b/Register office/Register office/View/TypesV/ReferenceValueForm.cs new file mode 100644 index 0000000..1060f31 --- /dev/null +++ b/Register office/Register office/View/TypesV/ReferenceValueForm.cs @@ -0,0 +1,110 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class ReferenceValueForm : Form + { + private TypeViewModel _viewModel; + private ReferenceValue? _selectedType; + private string _columnIdName = "ReferenceValueId"; + private ReferenceValue _temp; + + public ReferenceValueForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник нормалей обследований"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + SetDataSourceToComboBoxes(); + } + + private void SetDataSourceToComboBoxes() + { + cbExamination.DataSource = _viewModel.General.Context.ExaminationTypes + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.ExaminationTypeId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbExamination.DisplayMember = "Name"; + cbExamination.ValueMember = "Id"; + + cbGender.DataSource = new string[] { "Мужчина", "Женщина" }; + } + + private void UpdateElements(int examination = -1, string gender = "", + int? ageMin = null, int? ageMax = null, bool enableButtons = false) + { + cbExamination.SelectedValue = examination; + cbGender.Text = gender; + nudAgeMin.Value = ageMin ?? -1; + nudAgeMax.Value = ageMax ?? -1; + btnDelete.Enabled = btnUpdate.Enabled = btnOpen.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.ReferenceValues.Where(x => x.ReferenceValueId == id).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.ExaminationTypeId, _selectedType.Gender, + _selectedType.AgeMin, _selectedType.AgeMax, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.ExaminationTypeId = int.Parse(cbExamination.SelectedValue?.ToString() ?? "1"); + _selectedType.Gender = cbGender.Text; + _selectedType.AgeMin = nudAgeMin.Value == -1 ? null : (int)nudAgeMin.Value; + _selectedType.AgeMax = nudAgeMax.Value == -1 ? null : (int)nudAgeMax.Value; + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + _temp = new() + { + ExaminationTypeId = int.Parse(cbExamination.SelectedValue?.ToString() ?? "1"), + Gender = cbGender.Text, + AgeMin = nudAgeMin.Value == -1 ? null : (int)nudAgeMin.Value, + AgeMax = nudAgeMax.Value == -1 ? null : (int)nudAgeMax.Value, + }; + _viewModel.AddType(_temp); + UpdateElements(); + UpdateDgv(); + } + + private void btnOpen_Click(object sender, EventArgs e) + { + ReferenceValueQNForm f = new(_selectedType.ReferenceValueId); + f.ShowDialog(); + } + } +} diff --git a/Register office/Register office/View/TypesV/ReferenceValueForm.resx b/Register office/Register office/View/TypesV/ReferenceValueForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/ReferenceValueForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/ReferenceValueQNForm.Designer.cs b/Register office/Register office/View/TypesV/ReferenceValueQNForm.Designer.cs new file mode 100644 index 0000000..b662dcf --- /dev/null +++ b/Register office/Register office/View/TypesV/ReferenceValueQNForm.Designer.cs @@ -0,0 +1,214 @@ +namespace Register_office.View.TypesV +{ + partial class ReferenceValueQNForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + nudMinValue = new NumericUpDown(); + label4 = new Label(); + label1 = new Label(); + nudMaxValue = new NumericUpDown(); + rtbDescriptionTrue = new RichTextBox(); + label2 = new Label(); + label3 = new Label(); + rtbDescriptionFalse = new RichTextBox(); + btnCancel = new Button(); + btnSave = new Button(); + label5 = new Label(); + cbUnit = new ComboBox(); + ((System.ComponentModel.ISupportInitialize)nudMinValue).BeginInit(); + ((System.ComponentModel.ISupportInitialize)nudMaxValue).BeginInit(); + SuspendLayout(); + // + // nudMinValue + // + nudMinValue.DecimalPlaces = 2; + nudMinValue.Increment = new decimal(new int[] { 1, 0, 0, 65536 }); + nudMinValue.Location = new Point(12, 29); + nudMinValue.Minimum = new decimal(new int[] { 1, 0, 0, int.MinValue }); + nudMinValue.Name = "nudMinValue"; + nudMinValue.Size = new Size(120, 25); + nudMinValue.TabIndex = 0; + nudMinValue.Value = new decimal(new int[] { 1, 0, 0, int.MinValue }); + // + // label4 + // + label4.AutoSize = true; + label4.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label4.Location = new Point(12, 9); + label4.Name = "label4"; + label4.Size = new Size(96, 17); + label4.TabIndex = 14; + label4.Text = "Мин. значение"; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(153, 9); + label1.Name = "label1"; + label1.Size = new Size(101, 17); + label1.TabIndex = 16; + label1.Text = "Макс. значение"; + // + // nudMaxValue + // + nudMaxValue.DecimalPlaces = 2; + nudMaxValue.Increment = new decimal(new int[] { 1, 0, 0, 65536 }); + nudMaxValue.Location = new Point(153, 29); + nudMaxValue.Minimum = new decimal(new int[] { 1, 0, 0, int.MinValue }); + nudMaxValue.Name = "nudMaxValue"; + nudMaxValue.Size = new Size(120, 25); + nudMaxValue.TabIndex = 15; + nudMaxValue.Value = new decimal(new int[] { 1, 0, 0, int.MinValue }); + // + // rtbDescriptionTrue + // + rtbDescriptionTrue.Location = new Point(12, 87); + rtbDescriptionTrue.Name = "rtbDescriptionTrue"; + rtbDescriptionTrue.Size = new Size(436, 122); + rtbDescriptionTrue.TabIndex = 17; + rtbDescriptionTrue.Text = ""; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(12, 67); + label2.Name = "label2"; + label2.Size = new Size(119, 17); + label2.TabIndex = 18; + label2.Text = "Описание наличия"; + // + // label3 + // + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(12, 222); + label3.Name = "label3"; + label3.Size = new Size(132, 17); + label3.TabIndex = 20; + label3.Text = "Описание отсутствия"; + // + // rtbDescriptionFalse + // + rtbDescriptionFalse.Location = new Point(12, 242); + rtbDescriptionFalse.Name = "rtbDescriptionFalse"; + rtbDescriptionFalse.Size = new Size(436, 122); + rtbDescriptionFalse.TabIndex = 19; + rtbDescriptionFalse.Text = ""; + // + // btnCancel + // + btnCancel.Anchor = AnchorStyles.Bottom; + btnCancel.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnCancel.DialogResult = DialogResult.Cancel; + btnCancel.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnCancel.Location = new Point(286, 373); + btnCancel.Name = "btnCancel"; + btnCancel.Size = new Size(162, 33); + btnCancel.TabIndex = 22; + btnCancel.Text = "Отмена"; + btnCancel.UseVisualStyleBackColor = true; + // + // btnSave + // + btnSave.Anchor = AnchorStyles.Bottom; + btnSave.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnSave.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnSave.Location = new Point(12, 373); + btnSave.Name = "btnSave"; + btnSave.Size = new Size(162, 33); + btnSave.TabIndex = 21; + btnSave.Text = "Сохранить"; + btnSave.UseVisualStyleBackColor = true; + btnSave.Click += btnSave_Click; + // + // label5 + // + label5.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label5.AutoSize = true; + label5.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label5.Location = new Point(286, 8); + label5.Name = "label5"; + label5.Size = new Size(126, 17); + label5.TabIndex = 24; + label5.Text = "Единица измерения"; + // + // cbUnit + // + cbUnit.DropDownStyle = ComboBoxStyle.DropDownList; + cbUnit.FormattingEnabled = true; + cbUnit.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbUnit.Location = new Point(286, 28); + cbUnit.Name = "cbUnit"; + cbUnit.Size = new Size(162, 25); + cbUnit.TabIndex = 23; + // + // ReferenceValueQNForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(460, 418); + Controls.Add(label5); + Controls.Add(cbUnit); + Controls.Add(btnCancel); + Controls.Add(btnSave); + Controls.Add(label3); + Controls.Add(rtbDescriptionFalse); + Controls.Add(label2); + Controls.Add(rtbDescriptionTrue); + Controls.Add(label1); + Controls.Add(nudMaxValue); + Controls.Add(label4); + Controls.Add(nudMinValue); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Name = "ReferenceValueQNForm"; + Text = "Справочник нормалей для числовых и качественных обследований"; + ((System.ComponentModel.ISupportInitialize)nudMinValue).EndInit(); + ((System.ComponentModel.ISupportInitialize)nudMaxValue).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private NumericUpDown nudMinValue; + private Label label4; + private Label label1; + private NumericUpDown nudMaxValue; + private RichTextBox rtbDescriptionTrue; + private Label label2; + private Label label3; + private RichTextBox rtbDescriptionFalse; + private Button btnCancel; + private Button btnSave; + private Label label5; + private ComboBox cbUnit; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/ReferenceValueQNForm.cs b/Register office/Register office/View/TypesV/ReferenceValueQNForm.cs new file mode 100644 index 0000000..cfade1d --- /dev/null +++ b/Register office/Register office/View/TypesV/ReferenceValueQNForm.cs @@ -0,0 +1,109 @@ +using Register_office.Model; +using Register_office.ViewModel; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Register_office.View.TypesV +{ + public partial class ReferenceValueQNForm : Form + { + private TypeViewModel _viewModel; + private int _referenceValueId; + private ReferenceNumericValue? _referenceNumericValue; + private ReferenceQualitativeValue? _referenceQualitativeValue; + + public ReferenceValueQNForm(int referenceValueId) + { + InitializeComponent(); + TopMost = true; + _viewModel = new(); + _referenceValueId = referenceValueId; + _referenceNumericValue = _viewModel.General.Context.ReferenceNumericValues + .Where(x => x.ReferenceValueId == _referenceValueId).FirstOrDefault(); + _referenceQualitativeValue = _viewModel.General.Context.ReferenceQualitativeValues + .Where(x => x.ReferenceValueId == _referenceValueId).FirstOrDefault(); + SetDataSourceToComboBoxes(); + GetReferenceValues(); + } + + private void SetDataSourceToComboBoxes() + { + cbUnit.DataSource = _viewModel.General.Context.Units + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.UnitId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbUnit.DisplayMember = "Name"; + cbUnit.ValueMember = "Id"; + cbUnit.SelectedValue = -1; + } + + private void GetReferenceValues() + { + if (_referenceNumericValue != null) + { + nudMinValue.Value = _referenceNumericValue.MinValue ?? -1; + nudMaxValue.Value = _referenceNumericValue.MaxValue ?? -1; + cbUnit.SelectedValue = _referenceNumericValue.UnitId; + } + + if (_referenceQualitativeValue != null) + { + rtbDescriptionFalse.Text = _referenceQualitativeValue.DescriptionFalse; + rtbDescriptionTrue.Text = _referenceQualitativeValue.DescriptionTrue; + } + } + + private void btnSave_Click(object sender, EventArgs e) + { + if ((nudMinValue.Value >= 0 || nudMaxValue.Value >= 0) && cbUnit.Text != "") + { + if (_referenceNumericValue == null) + { + _referenceNumericValue = new() + { + ReferenceValueId = _referenceValueId, + MinValue = nudMinValue.Value < 0 ? null : (int)nudMinValue.Value, + MaxValue = nudMaxValue.Value < 0 ? null : (int)nudMaxValue.Value, + UnitId = int.Parse(cbUnit.SelectedValue?.ToString() ?? "1") + }; + _viewModel.AddType(_referenceNumericValue); + } + else + { + _referenceNumericValue.ReferenceValueId = _referenceValueId; + _referenceNumericValue.MinValue = nudMinValue.Value < 0 ? null : (int)nudMinValue.Value; + _referenceNumericValue.MaxValue = nudMaxValue.Value < 0 ? null : (int)nudMaxValue.Value; + _referenceNumericValue.UnitId = int.Parse(cbUnit.SelectedValue?.ToString() ?? "1"); + _viewModel.General.Context.SaveChanges(); + } + } + + if (rtbDescriptionFalse.Text.Trim() != "" && rtbDescriptionTrue.Text.Trim() != "") + { + if (_referenceQualitativeValue == null) + { + _referenceQualitativeValue = new() + { + ReferenceValueId = _referenceValueId, + DescriptionFalse = rtbDescriptionFalse.Text, + DescriptionTrue = rtbDescriptionTrue.Text + }; + _viewModel.AddType(_referenceQualitativeValue); + } + else + { + _referenceQualitativeValue.ReferenceValueId = _referenceValueId; + _referenceQualitativeValue.DescriptionFalse = rtbDescriptionFalse.Text; + _referenceQualitativeValue.DescriptionTrue = rtbDescriptionTrue.Text; + _viewModel.General.Context.SaveChanges(); + } + } + } + } +} diff --git a/Register office/Register office/View/TypesV/ReferenceValueQNForm.resx b/Register office/Register office/View/TypesV/ReferenceValueQNForm.resx new file mode 100644 index 0000000..4f24d55 --- /dev/null +++ b/Register office/Register office/View/TypesV/ReferenceValueQNForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.Designer.cs b/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.Designer.cs new file mode 100644 index 0000000..33ae913 --- /dev/null +++ b/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.Designer.cs @@ -0,0 +1,221 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class SyndromeExaminationTypeForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + label3 = new Label(); + cbExamination = new ComboBox(); + label2 = new Label(); + cbSyndrome = new ComboBox(); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(label3); + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(cbExamination); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(label2); + splitContainer1.Panel1.Controls.Add(cbSyndrome); + splitContainer1.Panel1.Controls.Add(btnUpdate); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 72); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // label3 + // + label3.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label3.AutoSize = true; + label3.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label3.Location = new Point(232, 17); + label3.Name = "label3"; + label3.Size = new Size(96, 17); + label3.TabIndex = 14; + label3.Text = "Обследование"; + // + // cbExamination + // + cbExamination.DropDownStyle = ComboBoxStyle.DropDownList; + cbExamination.FormattingEnabled = true; + cbExamination.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbExamination.Location = new Point(232, 37); + cbExamination.Name = "cbExamination"; + cbExamination.Size = new Size(211, 25); + cbExamination.TabIndex = 13; + // + // label2 + // + label2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label2.Location = new Point(12, 16); + label2.Name = "label2"; + label2.Size = new Size(62, 17); + label2.TabIndex = 12; + label2.Text = "Синдром"; + // + // cbSyndrome + // + cbSyndrome.DropDownStyle = ComboBoxStyle.DropDownList; + cbSyndrome.FormattingEnabled = true; + cbSyndrome.Items.AddRange(new object[] { "Физикальное", "Лабораторное", "Инструментальное" }); + cbSyndrome.Location = new Point(12, 37); + cbSyndrome.Name = "cbSyndrome"; + cbSyndrome.Size = new Size(214, 25); + cbSyndrome.TabIndex = 11; + // + // SyndromeExaminationTypeForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "SyndromeExaminationTypeForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + private Label label3; + private ComboBox cbExamination; + private Label label2; + private ComboBox cbSyndrome; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.cs b/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.cs new file mode 100644 index 0000000..d11c88c --- /dev/null +++ b/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.cs @@ -0,0 +1,101 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class SyndromeExaminationTypeForm : Form + { + private TypeViewModel _viewModel; + private SyndromeExaminationType? _selectedType; + private SyndromeExaminationType _temp; + + public SyndromeExaminationTypeForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник соответствий синдромов и обследований"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + SetDataSourceToComboBoxes(); + UpdateElements(); + } + + private void SetDataSourceToComboBoxes() + { + cbExamination.DataSource = _viewModel.General.Context.ExaminationTypes + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.ExaminationTypeId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbExamination.DisplayMember = "Name"; + cbExamination.ValueMember = "Id"; + + cbSyndrome.DataSource = _viewModel.General.Context.SyndromeTypes + .Select(x => new ComboBoxItem { Name = x.Name, Id = x.SyndromeTypeId }) + .OrderBy(cbi => cbi.Name).ToList(); + cbSyndrome.DisplayMember = "Name"; + cbSyndrome.ValueMember = "Id"; + } + + private void UpdateElements(int idExam = -1, int idSynd = -1, bool enableButtons = false) + { + cbExamination.SelectedValue = idExam; + cbSyndrome.SelectedValue = idSynd; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int idExam = int.Parse(selectedRow.Cells["ExaminationTypeId"].Value.ToString() ?? ""); + int idSynd = int.Parse(selectedRow.Cells["SyndromeId"].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.SyndromeExaminationTypes + .Where(x => x.ExaminationTypeId == idExam && x.SyndromeId == idSynd).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.ExaminationTypeId, _selectedType.SyndromeId, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.ExaminationTypeId = int.Parse(cbExamination.SelectedValue?.ToString() ?? "-1"); + _selectedType.SyndromeId = int.Parse(cbSyndrome.SelectedValue?.ToString() ?? "-1"); + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + _temp = new() + { + ExaminationTypeId = int.Parse(cbExamination.SelectedValue?.ToString() ?? "-1"), + SyndromeId = int.Parse(cbSyndrome.SelectedValue?.ToString() ?? "-1") + }; + _viewModel.AddType(_temp); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.resx b/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/SyndromeExaminationTypeForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/SyndromeTypeForm.Designer.cs b/Register office/Register office/View/TypesV/SyndromeTypeForm.Designer.cs new file mode 100644 index 0000000..5d8fad9 --- /dev/null +++ b/Register office/Register office/View/TypesV/SyndromeTypeForm.Designer.cs @@ -0,0 +1,193 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class SyndromeTypeForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + label1 = new Label(); + tbName = new TextBox(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(label1); + splitContainer1.Panel1.Controls.Add(tbName); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 72); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // label1 + // + label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 10); + label1.Name = "label1"; + label1.Size = new Size(65, 17); + label1.TabIndex = 1; + label1.Text = "Название"; + // + // tbName + // + tbName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbName.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbName.Location = new Point(12, 33); + tbName.Name = "tbName"; + tbName.Size = new Size(242, 27); + tbName.TabIndex = 0; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // DrugIntakeMethodForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "DrugIntakeMethodForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private TextBox tbName; + private Label label1; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/SyndromeTypeForm.cs b/Register office/Register office/View/TypesV/SyndromeTypeForm.cs new file mode 100644 index 0000000..0bceb3a --- /dev/null +++ b/Register office/Register office/View/TypesV/SyndromeTypeForm.cs @@ -0,0 +1,81 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class SyndromeTypeForm : Form + { + private TypeViewModel _viewModel; + private SyndromeType? _selectedType; + private string _columnIdName = "SyndromeTypeId"; + private SyndromeType _temp; + + public SyndromeTypeForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник синдромов"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + } + + private void UpdateElements(string name = "", bool enableButtons = false) + { + tbName.Text = name; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.SyndromeTypes.Where(x => x.SyndromeTypeId == id).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.Name, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.Name = tbName.Text; + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + _temp = new() + { + Name = tbName.Text + }; + _viewModel.AddType(_temp); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/SyndromeTypeForm.resx b/Register office/Register office/View/TypesV/SyndromeTypeForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/SyndromeTypeForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/UnitForm.Designer.cs b/Register office/Register office/View/TypesV/UnitForm.Designer.cs new file mode 100644 index 0000000..0b3d44c --- /dev/null +++ b/Register office/Register office/View/TypesV/UnitForm.Designer.cs @@ -0,0 +1,193 @@ +using Register_office.View; + +namespace Register_office.View.TypesV +{ + partial class UnitForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + splitContainer1 = new SplitContainer(); + btnAdd = new Button(); + btnDelete = new Button(); + btnUpdate = new Button(); + label1 = new Label(); + tbName = new TextBox(); + dgv = new DataGridView(); + cmsMedicineProductCost = new ContextMenuStrip(components); + cmsMedicineProduct = new ContextMenuStrip(components); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgv).BeginInit(); + SuspendLayout(); + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new Point(0, 0); + splitContainer1.Name = "splitContainer1"; + splitContainer1.Orientation = Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(btnAdd); + splitContainer1.Panel1.Controls.Add(btnDelete); + splitContainer1.Panel1.Controls.Add(btnUpdate); + splitContainer1.Panel1.Controls.Add(label1); + splitContainer1.Panel1.Controls.Add(tbName); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(dgv); + splitContainer1.Size = new Size(800, 647); + splitContainer1.SplitterDistance = 120; + splitContainer1.SplitterWidth = 5; + splitContainer1.TabIndex = 0; + // + // btnAdd + // + btnAdd.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnAdd.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnAdd.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnAdd.Location = new Point(458, 72); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(330, 33); + btnAdd.TabIndex = 3; + btnAdd.Text = "Добавить"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += btnAdd_Click; + // + // btnDelete + // + btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnDelete.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnDelete.Enabled = false; + btnDelete.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnDelete.Location = new Point(626, 33); + btnDelete.Name = "btnDelete"; + btnDelete.Size = new Size(162, 33); + btnDelete.TabIndex = 4; + btnDelete.Text = "Удалить"; + btnDelete.UseVisualStyleBackColor = true; + btnDelete.Click += btnDelete_Click; + // + // btnUpdate + // + btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + btnUpdate.AutoSizeMode = AutoSizeMode.GrowAndShrink; + btnUpdate.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + btnUpdate.Location = new Point(458, 32); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(162, 33); + btnUpdate.TabIndex = 1; + btnUpdate.Text = "Изменить"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // label1 + // + label1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + label1.Location = new Point(12, 10); + label1.Name = "label1"; + label1.Size = new Size(65, 17); + label1.TabIndex = 1; + label1.Text = "Название"; + // + // tbName + // + tbName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom; + tbName.Font = new Font("Segoe UI", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 204); + tbName.Location = new Point(12, 33); + tbName.Name = "tbName"; + tbName.Size = new Size(242, 27); + tbName.TabIndex = 0; + // + // dgv + // + dgv.AllowUserToAddRows = false; + dgv.AllowUserToDeleteRows = false; + dgv.AllowUserToOrderColumns = true; + dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgv.Dock = DockStyle.Fill; + dgv.Location = new Point(0, 0); + dgv.MultiSelect = false; + dgv.Name = "dgv"; + dgv.ReadOnly = true; + dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dgv.Size = new Size(800, 522); + dgv.TabIndex = 8; + dgv.SelectionChanged += dgv_SelectionChanged; + // + // cmsMedicineProductCost + // + cmsMedicineProductCost.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + cmsMedicineProductCost.Name = "cmsMedicineProductCost"; + cmsMedicineProductCost.Size = new Size(61, 4); + // + // cmsMedicineProduct + // + cmsMedicineProduct.Name = "contextMenuStrip1"; + cmsMedicineProduct.Size = new Size(61, 4); + // + // DrugIntakeMethodForm + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 647); + Controls.Add(splitContainer1); + Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204); + FormBorderStyle = FormBorderStyle.FixedSingle; + Name = "DrugIntakeMethodForm"; + Text = "Лекарственные препараты"; + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel1.PerformLayout(); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); + ResumeLayout(false); + } + + #endregion + + private SplitContainer splitContainer1; + private DataGridView dgv; + private TextBox tbName; + private Label label1; + private Button btnUpdate; + private Button btnDelete; + private Button btnAdd; + private ContextMenuStrip cmsMedicineProduct; + private ContextMenuStrip cmsMedicineProductCost; + } +} \ No newline at end of file diff --git a/Register office/Register office/View/TypesV/UnitForm.cs b/Register office/Register office/View/TypesV/UnitForm.cs new file mode 100644 index 0000000..8d969c3 --- /dev/null +++ b/Register office/Register office/View/TypesV/UnitForm.cs @@ -0,0 +1,81 @@ +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Register_office.Model; +using Register_office.ViewModel; +using System.Data; + +namespace Register_office.View.TypesV +{ + public partial class UnitForm : Form + { + private TypeViewModel _viewModel; + private Unit? _selectedType; + private string _columnIdName = "UnitId"; + private Unit _temp; + + public UnitForm() + { + InitializeComponent(); + TopMost = true; + Text = "Справочник единиц измерений"; + _viewModel = new(); + _viewModel.ConfigureSettingsDGV(dgv); + UpdateDgv(); + UpdateElements(); + } + + private void UpdateElements(string name = "", bool enableButtons = false) + { + tbName.Text = name; + btnDelete.Enabled = btnUpdate.Enabled = enableButtons; + } + + private void UpdateDgv() + { + _viewModel.SetDefaultDataSource(dgv); + } + + private void dgv_SelectionChanged(object sender, EventArgs e) + { + if (dgv.SelectedRows.Count != 0 && !dgv.CurrentRow.IsNewRow) + { + DataGridViewRow selectedRow = dgv.SelectedRows[0]; + int id = int.Parse(selectedRow.Cells[_columnIdName].Value.ToString() ?? ""); + _selectedType = _viewModel.General.Context.Units.Where(x => x.UnitId == id).FirstOrDefault(); + if (_selectedType != null) + UpdateElements(_selectedType.Name, true); + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _selectedType.Name = tbName.Text; + _viewModel.General.Context.SaveChanges(); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_selectedType != null) + { + _viewModel.DeleteType(_selectedType); + UpdateElements(); + UpdateDgv(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + _temp = new() + { + Name = tbName.Text + }; + _viewModel.AddType(_temp); + UpdateElements(); + UpdateDgv(); + } + } +} diff --git a/Register office/Register office/View/TypesV/UnitForm.resx b/Register office/Register office/View/TypesV/UnitForm.resx new file mode 100644 index 0000000..93017c2 --- /dev/null +++ b/Register office/Register office/View/TypesV/UnitForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 184, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/Register office/Register office/ViewModel/GeneralViewModel.cs b/Register office/Register office/ViewModel/GeneralViewModel.cs new file mode 100644 index 0000000..e4ec0fa --- /dev/null +++ b/Register office/Register office/ViewModel/GeneralViewModel.cs @@ -0,0 +1,113 @@ +using Register_office.Model; +using Register_office.Properties; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Register_office.ViewModel +{ + internal sealed class GeneralViewModel + { + private static readonly Lazy _instance = new(() => new GeneralViewModel()); + + private RegisterOfficeContext _context; + // Хранит все открытые формы + private FormCollection _fc; + + private string _pathReport = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + + private int _doctorId = 0; + + internal static GeneralViewModel Instance => _instance.Value; + internal RegisterOfficeContext Context => _context; + + public int DoctorId { get => _doctorId; set => _doctorId = value; } + public string PathReport { get => _pathReport; set => _pathReport = value; } + + private GeneralViewModel() { } + + public void Initialize() + { + _fc = Application.OpenForms; + _context = RegisterOfficeFactory + .Create(Settings.Default.Username, Settings.Default.Password); + if (RegisterOfficeFactory.CanConnect) + { + _context.Database.EnsureCreated(); + } + } + + /// + /// Настройка внешнего вида таблицы + /// + /// + internal void SetDefaultSettingsToDGV(DataGridView dgv) + { + dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dgv.ColumnHeadersDefaultCellStyle.Font = new Font("Segoe UI", 12, FontStyle.Bold); + dgv.RowsDefaultCellStyle.Font = new Font("Segoe UI", 11, FontStyle.Regular); + dgv.EnableHeadersVisualStyles = false; + dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.LightBlue; + dgv.AllowUserToOrderColumns = true; + } + + /// + /// Настройка имен столбцов DataGridView + /// + /// Класс таблицы БД + /// + internal void ConfigureGrid(DataGridView dgv) + { + // Получаем свойства модели с атрибутами Display + var properties = typeof(T).GetProperties() + .Where(p => p.GetCustomAttribute() != null); + + foreach (var prop in properties) + { + // Получаем свойства вложенной модели с атрибутами Display + var propertiesIn = prop.PropertyType.GetProperties() + .Where(p => p.GetCustomAttribute() != null); + if (propertiesIn.Any()) + foreach (var propIn in propertiesIn) + AddColumn(propIn, dgv); + else + AddColumn(prop, dgv); + } + } + private void AddColumn(PropertyInfo prop, DataGridView dgv) + { + var displayAttr = prop.GetCustomAttribute(); + + dgv.Columns.Add(new DataGridViewTextBoxColumn + { + HeaderText = displayAttr != null + ? displayAttr.Name // Берем название из атрибута + : prop.Name, + DataPropertyName = prop.Name, // Привязка к свойству + Name = prop.Name, // Техническое имя столбца + Visible = prop.Name.Contains("Id") ? false : true + }); + } + + internal T? GetActivatedForm() where T : Form + { + foreach (Form frm in _fc) + if (frm.Name == typeof(T).Name) + { + frm.Activate(); + return frm as T; + } + return default; + } + } + + internal class ComboBoxItem + { + public string Name { get; set; } = ""; + public int Id { get; set; } = -1; + } +} diff --git a/Register office/Register office/ViewModel/HospitalViewModel.cs b/Register office/Register office/ViewModel/HospitalViewModel.cs new file mode 100644 index 0000000..1578738 --- /dev/null +++ b/Register office/Register office/ViewModel/HospitalViewModel.cs @@ -0,0 +1,170 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Npgsql; +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Register_office.ViewModel +{ + internal class HospitalViewModel + { + private readonly GeneralViewModel _general; + + internal GeneralViewModel General => _general; + + public HospitalViewModel() + { + _general = GeneralViewModel.Instance; + } + + /// + /// Привязка данных к источникам данных таблицы + /// + /// + internal void SetDefaultDataSource(DataGridView dgv) where T : IUnionId + { + switch (typeof(T).Name) + { + case "HospitalAdmission": + dgv.DataSource = new SortableBindingList( + HospitalAdmissionWrapper.ToList(GetHospitalAdmission())); + break; + case "HospitalDischarge": + dgv.DataSource = new SortableBindingList( + HospitalDischargeWrapper.ToList(GetHospitalDischarge())); + break; + } + } + + /// + /// Настраивает таблицу под вывод данных + /// + /// + internal void ConfigureSettingsDGV(DataGridView dgv) + { + _general.SetDefaultSettingsToDGV(dgv); + _general.ConfigureGrid(dgv); + } + + public List GetHospitalAdmission(int? id = null) + { + List res = _general.Context.HospitalAdmissions + .Include(x => x.PreliminaryDisease) + .Include(x => x.Patient) + .ThenInclude(x => x.PatientNavigation) + .ToList(); + + if (id == null) + return res; + else + return res + .Where(item => item.HospitalAdmissionId == id) + .ToList(); + } + + public List GetHospitalDischarge(int? id = null) + { + List res = _general.Context.HospitalDischarges + .Include(x => x.FinalDisease) + .Include(x => x.HospitalAdmission) + .ThenInclude(x => x.Patient) + .ThenInclude(x => x.PatientNavigation) + .Include(x => x.HospitalAdmission) + .ThenInclude(x => x.PreliminaryDisease) + .ToList(); + + if (id == null) + return res; + else + return res + .Where(item => item.HospitalDischargeId == id) + .ToList(); + } + + public int AddHospital(T type) where T : IUnionId + { + try + { + switch (typeof(T).Name) + { + case "HospitalAdmission": + _general.Context.HospitalAdmissions.Add(type as HospitalAdmission); + break; + case "HospitalDischarge": + _general.Context.HospitalDischarges.Add(type as HospitalDischarge); + break; + } + + _general.Context.SaveChanges(); + } + catch (DbUpdateException ex) + { + DeleteHospital(type); + string message = ""; + if (ex.GetBaseException() is PostgresException pgException) + { + if (pgException.ConstraintName != null) + { + message = "Нарушено ограничение " + pgException.ConstraintName; + } + else + { + message = pgException.Message; + } + } + + MessageBox.Show(message, "Ошибка добавления", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return -1; + } + + return 0; + } + + public void DeleteHospital(T type) where T : IUnionId + { + switch (typeof(T).Name) + { + case "HospitalAdmission": + _general.Context.HospitalAdmissions.Remove(type as HospitalAdmission); + break; + case "HospitalDischarge": + _general.Context.HospitalDischarges.Remove(type as HospitalDischarge); + break; + } + _general.Context.SaveChanges(); + } + + public void Update() + { + try + { + _general.Context.SaveChanges(); + } + catch (DbUpdateException ex) + { + string message = ""; + if (ex.GetBaseException() is PostgresException pgException) + { + if (pgException.ConstraintName != null) + { + message = "Нарушено ограничение " + pgException.ConstraintName; + } + else + { + message = pgException.Message; + } + } + + MessageBox.Show(message, "Ошибка добавления", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Register office/Register office/ViewModel/LoginVM/LoginViewModel.cs b/Register office/Register office/ViewModel/LoginVM/LoginViewModel.cs new file mode 100644 index 0000000..c68c76d --- /dev/null +++ b/Register office/Register office/ViewModel/LoginVM/LoginViewModel.cs @@ -0,0 +1,43 @@ +using Microsoft.EntityFrameworkCore; +using Npgsql; + +namespace Register_office.ViewModel.LoginVM +{ + internal class LoginViewModel + { + private readonly GeneralViewModel _general; + + internal GeneralViewModel General => _general; + + public LoginViewModel() + { + _general = GeneralViewModel.Instance; + } + + /// + /// Проверяет логин и пароль на наличие и соответсствие в БД + /// + /// Логин пользователя + /// Пароль пользователя + /// + internal int CheckEnter(string login, string password) + { + login = login.Trim(); + password = password.Trim(); + return _general.Context.Database + .SqlQueryRaw("SELECT * FROM check_enter_in_person_account({0}, {1}) as Value", + login, password) + .AsEnumerable() + .First(); + } + + internal int GetDoctorId(int personId) + { + int id = _general.Context.Doctors + .Where(x => x.DoctorId == personId) + .Select(x => x.DoctorId) + .FirstOrDefault(); + return id; + } + } +} diff --git a/Register office/Register office/ViewModel/OnlyMenuViewModel.cs b/Register office/Register office/ViewModel/OnlyMenuViewModel.cs new file mode 100644 index 0000000..1de8141 --- /dev/null +++ b/Register office/Register office/ViewModel/OnlyMenuViewModel.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Npgsql; +using NpgsqlTypes; +using Register_office.Model; +using System.Collections.Generic; + +namespace Register_office.ViewModel +{ + internal class OnlyMenuViewModel + { + private readonly GeneralViewModel _general; + + internal GeneralViewModel General => _general; + + public OnlyMenuViewModel() + { + _general = GeneralViewModel.Instance; + } + + internal List GetReport() + { + List report = []; + switch (typeof(T).Name) + { + case "Analysis": + List temp = General.Context.Database + .SqlQueryRaw("SELECT * FROM get_results()") + .ToList(); + report = temp as List ?? []; + break; + } + + return report; + } + } +} diff --git a/Register office/Register office/ViewModel/PatientViewModel.cs b/Register office/Register office/ViewModel/PatientViewModel.cs new file mode 100644 index 0000000..0c96568 --- /dev/null +++ b/Register office/Register office/ViewModel/PatientViewModel.cs @@ -0,0 +1,169 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Npgsql; +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Register_office.ViewModel +{ + internal class PatientViewModel + { + private readonly GeneralViewModel _general; + + internal GeneralViewModel General => _general; + + public PatientViewModel() + { + _general = GeneralViewModel.Instance; + } + + /// + /// Привязка данных к источникам данных таблицы + /// + /// + internal void SetDefaultDataSource(DataGridView dgv) + { + dgv.DataSource = new SortableBindingList(PatientWrapper.ToList(GetPatient())); + } + + /// + /// Настраивает таблицу под вывод данных + /// + /// + internal void ConfigureSettingsDGV(DataGridView dgv) + { + _general.SetDefaultSettingsToDGV(dgv); + _general.ConfigureGrid(dgv); + } + + public List GetPatient(int? id = null) + { + List res = _general.Context.Patients + .Include(x => x.HospitalAdmissions) + .Include(x => x.Prescriptions) + .Include(x => x.PatientNavigation) + .ToList(); + + if (id == null) + return res; + else + return res + .Where(item => item.PatientId == id) + .ToList(); + } + + public List GetPerson(int? id = null) + { + List res = _general.Context.People + .Include(x => x.Patient) + .ToList(); + + if (id == null) + return res; + else + return res + .Where(item => item.PersonId == id) + .ToList(); + } + + public bool AddPatient(Patient patient) + { + try + { + _general.Context.Patients.Add(patient); + _general.Context.SaveChanges(); + return true; + } + catch (DbUpdateException ex) + { + DeletePatient(patient); + string message = ""; + if (ex.GetBaseException() is PostgresException pgException) + { + if (pgException.ConstraintName != null) + { + message = "Нарушено ограничение " + pgException.ConstraintName; + } + else + { + message = pgException.Message; + } + } + + MessageBox.Show(message, "Ошибка добавления", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + } + + public int AddPerson(Person person) + { + try + { + _general.Context.People.Add(person); + _general.Context.SaveChanges(); + return _general.Context.People.OrderByDescending(x => x.PersonId).First().PersonId; + } + catch (DbUpdateException ex) + { + _general.Context.People.Remove(person); + string message = ""; + if (ex.GetBaseException() is PostgresException pgException) + { + if (pgException.ConstraintName != null) + { + message = "Нарушено ограничение " + pgException.ConstraintName; + } + else + { + message = pgException.Message; + } + } + + MessageBox.Show(message, "Ошибка добавления", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return -1; + } + } + + public void Update() + { + try + { + _general.Context.SaveChanges(); + } + catch (DbUpdateException ex) + { + string message = ""; + if (ex.GetBaseException() is PostgresException pgException) + { + if (pgException.ConstraintName != null) + { + message = "Нарушено ограничение " + pgException.ConstraintName; + } + else + { + message = pgException.Message; + } + } + + MessageBox.Show(message, "Ошибка добавления", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public void DeletePatient(Patient p) + { + Person person = p.PatientNavigation; + _general.Context.Patients.Remove(p); + _general.Context.People.Remove(person); + _general.Context.SaveChanges(); + } + } +} diff --git a/Register office/Register office/ViewModel/PrescriptionViewModel.cs b/Register office/Register office/ViewModel/PrescriptionViewModel.cs new file mode 100644 index 0000000..0521e43 --- /dev/null +++ b/Register office/Register office/ViewModel/PrescriptionViewModel.cs @@ -0,0 +1,175 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Npgsql; +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Register_office.ViewModel +{ + internal class PrescriptionViewModel + { + private readonly GeneralViewModel _general; + + internal GeneralViewModel General => _general; + + public PrescriptionViewModel() + { + _general = GeneralViewModel.Instance; + } + + /// + /// Привязка данных к источникам данных таблицы + /// + /// + internal void SetDefaultDataSource(DataGridView dgv) where T : IUnionId + { + switch (typeof(T).Name) + { + case "Prescription": + dgv.DataSource = new SortableBindingList( + PrescriptionWrapper.ToList(_general.Context.Prescriptions + .Include(x => x.Patient) + .ThenInclude(y => y.PatientNavigation) + .Where(x => x.DoctorId == _general.DoctorId) + .ToList())); + break; + case "DrugTypePrescription": + dgv.DataSource = new SortableBindingList( + DrugTypePrescriptionWrapper.ToList(_general.Context.DrugTypePrescriptions + .Include(x => x.DoseUnit) + .Include(x => x.DrugType) + .Include(x => x.IntakeMethod) + .ToList())); + break; + case "ExaminationTypePrescription": + dgv.DataSource = new SortableBindingList( + ExaminationTypePrescriptionWrapper.ToList(_general.Context.ExaminationTypePrescriptions + .Include(x => x.ExaminationType) + .Include(x => x.Result) + .ToList())); + break; + case "ProcedureTypePrescription": + dgv.DataSource = new SortableBindingList( + ProcedureTypePrescriptionWrapper.ToList(_general.Context.ProcedureTypePrescriptions + .Include(x => x.ProcedureType) + .ToList())); + break; + } + } + + /// + /// Настраивает таблицу под вывод данных + /// + /// + internal void ConfigureSettingsDGV(DataGridView dgv) + { + _general.SetDefaultSettingsToDGV(dgv); + _general.ConfigureGrid(dgv); + } + + public List GetPrescription(int? id = null) where T : IUnionId + { + List res = []; + switch (typeof(T).Name) + { + case "Prescription": + res = _general.Context.Prescriptions as List ?? []; + break; + case "DrugTypePrescription": + res = _general.Context.DrugTypePrescriptions as List ?? []; + break; + case "ExaminationTypePrescription": + res = _general.Context.ExaminationTypePrescriptions as List ?? []; + break; + case "ProcedureTypePrescription": + res = _general.Context.ProcedureTypePrescriptions as List ?? []; + break; + } + + if (id == null) + return res; + else + return res + .Where(item => item.GetId().Equals(id)) + .ToList(); + } + + public void Update() + { + _general.Context.SaveChanges(); + } + + public int AddPrescription(T type) where T : IUnionId + { + try + { + switch (typeof(T).Name) + { + case "Prescription": + _general.Context.Prescriptions.Add(type as Prescription); + _general.Context.SaveChanges(); + return _general.Context.Prescriptions + .OrderByDescending(x => x.PrescriptionId).First().PrescriptionId; + case "DrugTypePrescription": + _general.Context.DrugTypePrescriptions.Add(type as DrugTypePrescription); + break; + case "ExaminationTypePrescription": + _general.Context.ExaminationTypePrescriptions.Add(type as ExaminationTypePrescription); + break; + case "ProcedureTypePrescription": + _general.Context.ProcedureTypePrescriptions.Add(type as ProcedureTypePrescription); + break; + } + + _general.Context.SaveChanges(); + } + catch (DbUpdateException ex) + { + DeletePrescription(type); + string message = ""; + if (ex.GetBaseException() is PostgresException pgException) + { + if (pgException.ConstraintName != null) + { + message = "Нарушено ограничение " + pgException.ConstraintName; + } + else + { + message = pgException.Message; + } + } + + MessageBox.Show(message, "Ошибка добавления", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return -1; + } + + return 0; + } + + public void DeletePrescription(T type) where T : IUnionId + { + switch (typeof(T).Name) + { + case "Prescription": + _general.Context.Prescriptions.Remove(type as Prescription); + break; + case "DrugTypePrescription": + _general.Context.DrugTypePrescriptions.Remove(type as DrugTypePrescription); + break; + case "ExaminationTypePrescription": + _general.Context.ExaminationTypePrescriptions.Remove(type as ExaminationTypePrescription); + break; + case "ProcedureTypePrescription": + _general.Context.ProcedureTypePrescriptions.Remove(type as ProcedureTypePrescription); + break; + } + _general.Context.SaveChanges(); + } + } +} diff --git a/Register office/Register office/ViewModel/ResultViewModel.cs b/Register office/Register office/ViewModel/ResultViewModel.cs new file mode 100644 index 0000000..abca08a --- /dev/null +++ b/Register office/Register office/ViewModel/ResultViewModel.cs @@ -0,0 +1,92 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Npgsql; +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Register_office.ViewModel +{ + internal class ResultViewModel + { + private readonly GeneralViewModel _general; + + internal GeneralViewModel General => _general; + + public ResultViewModel() + { + _general = GeneralViewModel.Instance; + } + + public void Update() + { + _general.Context.SaveChanges(); + } + + public int AddResult(T type) where T : IUnionId + { + try + { + switch (typeof(T).Name) + { + case "Result": + _general.Context.Results.Add(type as Result); + _general.Context.SaveChanges(); + return _general.Context.Results + .OrderByDescending(x => x.ResultId).First().ResultId; + case "NumericResult": + _general.Context.NumericResults.Add(type as NumericResult); + break; + case "QualitativeResult": + _general.Context.QualitativeResults.Add(type as QualitativeResult); + break; + } + + _general.Context.SaveChanges(); + } + catch (DbUpdateException ex) + { + DeleteResult(type); + string message = ""; + if (ex.GetBaseException() is PostgresException pgException) + { + if (pgException.ConstraintName != null) + { + message = "Нарушено ограничение " + pgException.ConstraintName; + } + else + { + message = pgException.Message; + } + } + + MessageBox.Show(message, "Ошибка добавления", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return -1; + } + + return 0; + } + + public void DeleteResult(T type) where T : IUnionId + { + switch (typeof(T).Name) + { + case "Result": + _general.Context.Results.Remove(type as Result); + break; + case "NumericResult": + _general.Context.NumericResults.Remove(type as NumericResult); + break; + case "QualitativeResult": + _general.Context.QualitativeResults.Remove(type as QualitativeResult); + break; + } + _general.Context.SaveChanges(); + } + } +} diff --git a/Register office/Register office/ViewModel/TypeViewModel.cs b/Register office/Register office/ViewModel/TypeViewModel.cs new file mode 100644 index 0000000..238de76 --- /dev/null +++ b/Register office/Register office/ViewModel/TypeViewModel.cs @@ -0,0 +1,251 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Npgsql; +using Register_office.BaseClasses; +using Register_office.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Register_office.ViewModel +{ + internal class TypeViewModel + { + private readonly GeneralViewModel _general; + + internal GeneralViewModel General => _general; + + public TypeViewModel() + { + _general = GeneralViewModel.Instance; + } + + + + /// + /// Привязка данных к источникам данных таблицы + /// + /// + internal void SetDefaultDataSource(DataGridView dgv) where T : IUnionId + { + switch (typeof(T).Name) + { + case "Disease": + dgv.DataSource = new SortableBindingList(_general.Context.Diseases.ToList()); + break; + case "DrugIntakeMethod": + dgv.DataSource = new SortableBindingList(_general.Context.DrugIntakeMethods.ToList()); + break; + case "DrugType": + dgv.DataSource = new SortableBindingList(_general.Context.DrugTypes.ToList()); + break; + case "DiseaseSyndrome": + dgv.DataSource = new SortableBindingList( + DiseaseSyndromeWrapper.ToList(_general.Context.DiseaseSyndromes + .Include(x => x.Disease) + .Include(x => x.Syndrome) + .ToList())); + break; + case "ExaminationType": + dgv.DataSource = new SortableBindingList(_general.Context.ExaminationTypes.ToList()); + break; + case "ProcedureType": + dgv.DataSource = new SortableBindingList(_general.Context.ProcedureTypes.ToList()); + break; + case "ReferenceValue": + dgv.DataSource = new SortableBindingList( + ReferenceValueWrapper.ToList(_general.Context.ReferenceValues + .Include(x => x.ExaminationType).ToList())); + break; + case "SyndromeExaminationType": + dgv.DataSource = new SortableBindingList( + SyndromeExaminationTypeWrapper.ToList(_general.Context.SyndromeExaminationTypes + .Include(x => x.ExaminationType) + .Include(x => x.Syndrome) + .ToList())); + break; + case "SyndromeType": + dgv.DataSource = new SortableBindingList(_general.Context.SyndromeTypes.ToList()); + break; + case "Unit": + dgv.DataSource = new SortableBindingList(_general.Context.Units.ToList()); + break; + } + } + + /// + /// Настраивает таблицу под вывод данных + /// + /// + internal void ConfigureSettingsDGV(DataGridView dgv) + { + _general.SetDefaultSettingsToDGV(dgv); + _general.ConfigureGrid(dgv); + } + + public List GetType(int? id = null) where T : IUnionId + { + List res = []; + switch (typeof(T).Name) + { + case "Disease": + res = _general.Context.Diseases as List ?? []; + break; + case "DrugIntakeMethod": + res = _general.Context.DrugIntakeMethods as List ?? []; + break; + case "DrugType": + res = _general.Context.DrugTypes as List ?? []; + break; + case "DiseaseSyndrome": + res = _general.Context.DiseaseSyndromes as List ?? []; + break; + case "ExaminationType": + res = _general.Context.ExaminationTypes as List ?? []; + break; + case "ProcedureType": + res = _general.Context.ProcedureTypes as List ?? []; + break; + case "ReferenceNumericValue": + res = _general.Context.ReferenceNumericValues as List ?? []; + break; + case "ReferenceQualitativeValue": + res = _general.Context.ReferenceQualitativeValues as List ?? []; + break; + case "ReferenceValue": + res = _general.Context.ReferenceValues as List ?? []; + break; + case "SyndromeExaminationType": + res = _general.Context.SyndromeExaminationTypes as List ?? []; + break; + case "SyndromeType": + res = _general.Context.SyndromeTypes as List ?? []; + break; + case "Unit": + res = _general.Context.Units as List ?? []; + break; + } + + if (id == null) + return res; + else + return res + .Where(item => item.GetId().Equals(id)) + .ToList(); + } + + public void AddType(T type) where T : IUnionId + { + try + { + switch (typeof(T).Name) + { + case "Disease": + _general.Context.Diseases.Add(type as Disease); + break; + case "DrugIntakeMethod": + _general.Context.DrugIntakeMethods.Add(type as DrugIntakeMethod); + break; + case "DrugType": + _general.Context.DrugTypes.Add(type as DrugType); + break; + case "DiseaseSyndrome": + _general.Context.DiseaseSyndromes.Add(type as DiseaseSyndrome); + break; + case "ExaminationType": + _general.Context.ExaminationTypes.Add(type as ExaminationType); + break; + case "ProcedureType": + _general.Context.ProcedureTypes.Add(type as ProcedureType); + break; + case "ReferenceNumericValue": + _general.Context.ReferenceNumericValues.Add(type as ReferenceNumericValue); + break; + case "ReferenceQualitativeValue": + _general.Context.ReferenceQualitativeValues.Add(type as ReferenceQualitativeValue); + break; + case "ReferenceValue": + _general.Context.ReferenceValues.Add(type as ReferenceValue); + break; + case "SyndromeExaminationType": + _general.Context.SyndromeExaminationTypes.Add(type as SyndromeExaminationType); + break; + case "SyndromeType": + _general.Context.SyndromeTypes.Add(type as SyndromeType); + break; + case "Unit": + _general.Context.Units.Add(type as Unit); + break; + } + + _general.Context.SaveChanges(); + } + catch (DbUpdateException ex) + { + DeleteType(type); + string message = ""; + if (ex.GetBaseException() is PostgresException pgException) + { + if (pgException.ConstraintName != null) + { + message = "Нарушено ограничение " + pgException.ConstraintName; + } + else + { + message = pgException.Message; + } + } + + MessageBox.Show(message, "Ошибка добавления", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + public void DeleteType(T type) where T : IUnionId + { + switch (typeof(T).Name) + { + case "Disease": + _general.Context.Diseases.Remove(type as Disease); + break; + case "DrugIntakeMethod": + _general.Context.DrugIntakeMethods.Remove(type as DrugIntakeMethod); + break; + case "DrugType": + _general.Context.DrugTypes.Remove(type as DrugType); + break; + case "DiseaseSyndrome": + _general.Context.DiseaseSyndromes.Remove(type as DiseaseSyndrome); + break; + case "ExaminationType": + _general.Context.ExaminationTypes.Remove(type as ExaminationType); + break; + case "ProcedureType": + _general.Context.ProcedureTypes.Remove(type as ProcedureType); + break; + case "ReferenceNumericValue": + _general.Context.ReferenceNumericValues.Remove(type as ReferenceNumericValue); + break; + case "ReferenceQualitativeValue": + _general.Context.ReferenceQualitativeValues.Remove(type as ReferenceQualitativeValue); + break; + case "ReferenceValue": + _general.Context.ReferenceValues.Remove(type as ReferenceValue); + break; + case "SyndromeExaminationType": + _general.Context.SyndromeExaminationTypes.Remove(type as SyndromeExaminationType); + break; + case "SyndromeType": + _general.Context.SyndromeTypes.Remove(type as SyndromeType); + break; + case "Unit": + _general.Context.Units.Remove(type as Unit); + break; + } + _general.Context.SaveChanges(); + } + } +} diff --git a/artifacts/gui/2025-12-07_18-27.png b/artifacts/gui/2025-12-07_18-27.png new file mode 100644 index 0000000..986c5b6 Binary files /dev/null and b/artifacts/gui/2025-12-07_18-27.png differ diff --git a/artifacts/gui/2025-12-07_18-28.png b/artifacts/gui/2025-12-07_18-28.png new file mode 100644 index 0000000..32a9a88 Binary files /dev/null and b/artifacts/gui/2025-12-07_18-28.png differ diff --git a/artifacts/gui/2025-12-07_18-52.png b/artifacts/gui/2025-12-07_18-52.png new file mode 100644 index 0000000..9076bc2 Binary files /dev/null and b/artifacts/gui/2025-12-07_18-52.png differ diff --git a/artifacts/gui/2025-12-07_18-53.png b/artifacts/gui/2025-12-07_18-53.png new file mode 100644 index 0000000..995f6d3 Binary files /dev/null and b/artifacts/gui/2025-12-07_18-53.png differ diff --git a/artifacts/gui/2025-12-07_18-53_1.png b/artifacts/gui/2025-12-07_18-53_1.png new file mode 100644 index 0000000..dda7865 Binary files /dev/null and b/artifacts/gui/2025-12-07_18-53_1.png differ diff --git a/artifacts/gui/2025-12-07_18-54.png b/artifacts/gui/2025-12-07_18-54.png new file mode 100644 index 0000000..ab1f17f Binary files /dev/null and b/artifacts/gui/2025-12-07_18-54.png differ diff --git a/artifacts/gui/2025-12-07_18-54_1.png b/artifacts/gui/2025-12-07_18-54_1.png new file mode 100644 index 0000000..47b2f16 Binary files /dev/null and b/artifacts/gui/2025-12-07_18-54_1.png differ diff --git a/artifacts/gui/2025-12-07_22-41.png b/artifacts/gui/2025-12-07_22-41.png new file mode 100644 index 0000000..a8f1f4f Binary files /dev/null and b/artifacts/gui/2025-12-07_22-41.png differ diff --git a/artifacts/gui/2025-12-07_22-45.png b/artifacts/gui/2025-12-07_22-45.png new file mode 100644 index 0000000..92b4c87 Binary files /dev/null and b/artifacts/gui/2025-12-07_22-45.png differ diff --git a/artifacts/gui/2025-12-07_22-45_1.png b/artifacts/gui/2025-12-07_22-45_1.png new file mode 100644 index 0000000..df2f637 Binary files /dev/null and b/artifacts/gui/2025-12-07_22-45_1.png differ diff --git a/artifacts/gui/2025-12-07_22-46.png b/artifacts/gui/2025-12-07_22-46.png new file mode 100644 index 0000000..e9ebd04 Binary files /dev/null and b/artifacts/gui/2025-12-07_22-46.png differ diff --git a/artifacts/gui/2025-12-07_22-46_1.png b/artifacts/gui/2025-12-07_22-46_1.png new file mode 100644 index 0000000..cf92e31 Binary files /dev/null and b/artifacts/gui/2025-12-07_22-46_1.png differ diff --git a/artifacts/gui/2025-12-07_22-47.png b/artifacts/gui/2025-12-07_22-47.png new file mode 100644 index 0000000..63797c9 Binary files /dev/null and b/artifacts/gui/2025-12-07_22-47.png differ diff --git a/backup_plain.sql b/backup_plain.sql new file mode 100644 index 0000000..867f333 --- /dev/null +++ b/backup_plain.sql @@ -0,0 +1,833 @@ +-- Перечисление для пола +CREATE TYPE gender_enum AS ENUM ( + 'male', -- мужчина + 'female' -- женщина +); + +-- Перечисление для типа обследования +CREATE TYPE examination_categories_enum AS ENUM ( + 'physical', -- физикальное обследование + 'laboratory', -- лабораторное обследование + 'instrumental' -- инструментальное обследование +); + +-- Перечисление для исхода госпитализации (выписка) +CREATE TYPE hospital_discharge_reason_enum AS ENUM ( + 'death', -- смерть + 'improvement', -- улучшение состояния + 'refusal' -- отказ от госпитализации или дальнейшего лечения +); + +-- Перечисление для контекста использования единицы измерения +CREATE TYPE unit_context_enum AS ENUM ( + 'examination', -- используется только для обследований (лабораторные, инструментальные, физикальные) + 'medication' -- используется только для лекарственных средств (дозировка, количество) +); + +-- Функция: нет двойных пробелов подряд +CREATE OR REPLACE FUNCTION no_double_space (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str !~ E'\s{2,}'; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: нет пробелов в начале и конце строки +CREATE OR REPLACE FUNCTION no_space_start_end (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str !~ E'^\s' + AND str !~ E'\s$'; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: нет пробелов вообще +CREATE OR REPLACE FUNCTION no_space (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str !~ E'\s'; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: длина строки в заданных границах +CREATE OR REPLACE FUNCTION str_length_between (str text, min_len int, max_len int) + RETURNS boolean + AS $$ +BEGIN + RETURN LENGTH(str) BETWEEN min_len AND max_len; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: стандартная проверка для слова +CREATE OR REPLACE FUNCTION default_word_check (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str IS NULL + OR no_space (str) + AND str_length_between (str, 1, 64); +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: стандартная проверка для строки +CREATE OR REPLACE FUNCTION default_str_check (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str IS NULL + OR no_double_space (str) + AND no_space_start_end (str) + AND str_length_between (str, 1, 128); +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Люди +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник людей +CREATE TABLE person ( + person_id serial PRIMARY KEY, + -- фамилия + last_name text NOT NULL CHECK (default_word_check (last_name)), + -- имя + first_name text NOT NULL CHECK (default_word_check (first_name)), + -- отчество + middle_name text CHECK (default_word_check (middle_name)), + -- дата рождения + birth_date date NOT NULL CHECK (birth_date <= CURRENT_DATE), + -- пол + gender text NOT NULL, + -- место жительства + address text NOT NULL CHECK (default_str_check (address)) +); + +-- Справочник пациентов +CREATE TABLE patient ( + patient_id int PRIMARY KEY REFERENCES person (person_id), + policy_number text NOT NULL CHECK (policy_number ~ '^[0-9]{16}$') +); + +-- Справочник врачей +CREATE TABLE doctor ( + doctor_id int PRIMARY KEY REFERENCES person (person_id) +); + +CREATE TABLE registrar ( + registrar_id int PRIMARY KEY REFERENCES person (person_id) +); + +-- Справочник единиц измерения для числовых результатов +CREATE TABLE unit ( + unit_id serial PRIMARY KEY, + name text NOT NULL CHECK (name ~ '^[а-яА-ЯёЁ%^/]+$' AND str_length_between (name, 1, 16)), + UNIQUE (name) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Назначения +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Базовая таблица назначения (TPT) +CREATE TABLE prescription ( + prescription_id serial PRIMARY KEY, + -- пациент + patient_id int NOT NULL REFERENCES patient (patient_id) ON DELETE CASCADE, + -- врач + doctor_id int NOT NULL REFERENCES doctor (doctor_id) ON DELETE RESTRICT +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Обследования +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник типов обследований (Общий анализ крови", "ЭКГ", "УЗИ печени") +CREATE TABLE examination_type ( + examination_type_id serial PRIMARY KEY, + -- название типа обследования (одно слово, без пробелов) + name text NOT NULL CHECK (default_word_check (name)), + -- категория обследования + category text NOT NULL, + UNIQUE (name) +); + +-- Общая таблица результатов обследований (TPT) +CREATE TABLE result ( + result_id serial PRIMARY KEY, + examination_id int NOT NULL REFERENCES examination_type (examination_type_id) ON DELETE CASCADE +); + +-- Журнал фактических обследований пациентов +CREATE TABLE examination_type_prescription ( + examination_prescription_id serial PRIMARY KEY, + prescription_id int NOT NULL REFERENCES prescription (prescription_id) ON DELETE CASCADE, + result_id int REFERENCES result (result_id) ON DELETE CASCADE, + -- тип обследования + examination_type_id int NOT NULL REFERENCES examination_type (examination_type_id) ON DELETE CASCADE, + UNIQUE (prescription_id) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Фактические результаты обследований +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- + +-- Числовой результат обследования пациента (только один на обследование) +CREATE TABLE numeric_result ( + -- обследование пациента + result_id int PRIMARY KEY REFERENCES result (result_id) ON DELETE CASCADE, + -- значение результата + value numeric NOT NULL, + -- единица измерения + unit_id int NOT NULL REFERENCES unit (unit_id) ON DELETE RESTRICT +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Нормальные результаты обследований +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Качественный результат обследования пациента (только один на обследование) +CREATE TABLE qualitative_result ( + -- обследование пациента + result_id int PRIMARY KEY REFERENCES result (result_id) ON DELETE CASCADE, + -- признак отклонения + value boolean NOT NULL +); + +-- Общая таблица для справочника референсных (нормальных) значений (TPT) +CREATE TABLE reference_value ( + reference_value_id serial PRIMARY KEY, + examination_type_id int NOT NULL REFERENCES examination_type (examination_type_id) ON DELETE CASCADE, + gender text, -- пол (если норма специфична) + age_min int, -- нижняя граница возраста (если есть зависимость) + age_max int, -- верхняя граница возраста (если есть зависимость) + CHECK ( + (age_min IS NULL OR age_max IS NULL) -- если один из параметров не задан, не сравниваем + OR (age_min < age_max) -- если оба заданы, min < max + ), + UNIQUE (examination_type_id, gender, age_min, age_max) +); + +-- Справочник референсных (нормальных) значений для числовых обследований +CREATE TABLE reference_numeric_value ( + reference_value_id int PRIMARY KEY REFERENCES reference_value (reference_value_id) ON DELETE CASCADE, + min_value numeric, + max_value numeric, + unit_id int NOT NULL REFERENCES unit (unit_id) ON DELETE RESTRICT +); + +-- Справочник референсных (нормальных) значений для качественных обследований +CREATE TABLE reference_qualitative_value ( + reference_value_id int PRIMARY KEY REFERENCES reference_value (reference_value_id) ON DELETE CASCADE, + description_true text NOT NULL CHECK (default_word_check (description_true)), + description_false text NOT NULL CHECK (default_word_check (description_false)), + UNIQUE (description_true, description_false) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Синдромы +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник синдромов +CREATE TABLE syndrome_type ( + syndrome_type_id serial PRIMARY KEY, + name text NOT NULL CHECK (default_word_check (name)), + UNIQUE (name) +); + +-- Соответствие синдромов и типов обследований (определяет, какое обследование позволяет определить синдром) +CREATE TABLE syndrome_examination_type ( + syndrome_id int PRIMARY KEY REFERENCES syndrome_type (syndrome_type_id) ON DELETE CASCADE, + examination_type_id int NOT NULL REFERENCES examination_type (examination_type_id) ON DELETE CASCADE, + UNIQUE (examination_type_id) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Болезни и диагнозы +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник заболеваний +CREATE TABLE disease ( + disease_id serial PRIMARY KEY, + -- русское наименование + name text NOT NULL CHECK (default_str_check (name)), + -- код МКБ в формате A12.3 + icd_code text NOT NULL CHECK (icd_code ~ '^[A-Z][0-9]{2}\.[0-9]$'), + UNIQUE (name), + UNIQUE (icd_code) +); + +-- Соответствие заболеваний и синдромов +CREATE TABLE disease_syndrome ( + disease_syndrome_id SERIAL PRIMARY KEY, + disease_id int NOT NULL REFERENCES disease (disease_id) ON DELETE CASCADE, + syndrome_id int NOT NULL REFERENCES syndrome_type (syndrome_type_id) ON DELETE CASCADE, + UNIQUE (disease_id, syndrome_id) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Госпитализация +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Госпитализация (начало) +CREATE TABLE hospital_admission ( + hospital_admission_id serial PRIMARY KEY, + -- пациент + patient_id int NOT NULL REFERENCES patient (patient_id) ON DELETE CASCADE, + -- предварительный диагноз + preliminary_disease_id int NOT NULL REFERENCES disease (disease_id), + -- дата и время поступления + admission_datetime timestamp NOT NULL CHECK (admission_datetime <= CURRENT_TIMESTAMP) +); + +-- Завершение госпитализации +CREATE TABLE hospital_discharge ( + hospital_discharge_id serial PRIMARY KEY, + hospital_admission_id int NOT NULL REFERENCES hospital_admission (hospital_admission_id) ON DELETE CASCADE, + -- дата и время выписки/смерти + discharge_datetime timestamp NOT NULL CHECK (discharge_datetime <= CURRENT_TIMESTAMP), + final_disease_id int NOT NULL REFERENCES disease (disease_id), + -- причина завершения + reason text NOT NULL +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Лекарства +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник способов приёма лекарств +CREATE TABLE drug_intake_method ( + drug_intake_method_id serial PRIMARY KEY, + -- наименование способа (например, "перорально", "внутримышечно", "внутривенно", "ингаляционно", "ректально") + name text NOT NULL CHECK (default_word_check (name)), + UNIQUE (name) +); + +-- Справочник лекарств +CREATE TABLE drug_type ( + drug_type_id serial PRIMARY KEY, + international_name_ru text NOT NULL CHECK (default_word_check (international_name_ru)), + international_name_en text CHECK (default_word_check (international_name_en)), + international_name_la text CHECK (default_word_check (international_name_la)), + brand_name_ru text CHECK (default_word_check (brand_name_ru)), + UNIQUE (international_name_ru), + UNIQUE (international_name_en), + UNIQUE (international_name_la), + UNIQUE (brand_name_ru) +); + +-- Журнал фактических назначений лекарств пациенту +CREATE TABLE drug_type_prescription ( + drug_prescription_id serial PRIMARY KEY, + prescription_id int NOT NULL REFERENCES prescription (prescription_id) ON DELETE CASCADE, + drug_type_id int NOT NULL REFERENCES drug_type (drug_type_id) ON DELETE RESTRICT, + -- количество вещества за приём + dose numeric NOT NULL CHECK (dose > 0), + -- единица измерения дозы + dose_unit_id int NOT NULL REFERENCES unit (unit_id) ON DELETE RESTRICT, + -- способ приёма + intake_method_id int NOT NULL REFERENCES drug_intake_method (drug_intake_method_id) ON DELETE RESTRICT, + -- длительность приёма (в днях) + duration_days int NOT NULL CHECK (duration_days > 0), + UNIQUE (prescription_id) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Процедуры (для пациента) +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник типов процедур +CREATE TABLE procedure_type ( + procedure_type_id serial PRIMARY KEY, + -- наименование процедуры (например, "физиотерапия") + name text NOT NULL CHECK (default_word_check (name)), + UNIQUE (name) +); + +-- Журнал фактических назначений процедур пациенту +CREATE TABLE procedure_type_prescription ( + procedure_prescription_id serial PRIMARY KEY, + prescription_id int NOT NULL REFERENCES prescription (prescription_id) ON DELETE CASCADE, + procedure_type_id int NOT NULL REFERENCES procedure_type (procedure_type_id) ON DELETE RESTRICT, + scheduled_datetime timestamp NOT NULL, + UNIQUE (prescription_id) +); + + +-- Общая функция возвращения всех госпитализаций и периодов пациента +CREATE OR REPLACE FUNCTION get_hospitalization_periods (p_patient_id int) + RETURNS TABLE ( + admission_datetime timestamp, + discharge_datetime timestamp + ) + AS $$ +BEGIN + RETURN QUERY + SELECT + ha.admission_datetime, + hd.discharge_datetime + FROM + hospital_admission ha + LEFT JOIN hospital_discharge hd ON ha.hospital_admission_id = hd.hospital_admission_id +WHERE + ha.patient_id = p_patient_id; +END; +$$ +LANGUAGE plpgsql; + +-- Триггер: запрещает новую госпитализацию при наличии незавершённой +CREATE OR REPLACE FUNCTION check_active_hospitalization () + RETURNS TRIGGER + AS $$ +DECLARE + open_hospitalization boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + get_hospitalization_periods (NEW.patient_id) + WHERE + discharge_datetime IS NULL) INTO open_hospitalization; + IF open_hospitalization THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10001: ACTIVE_HOSPITALIZATION_EXISTS'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +-- Триггер: запрещает перекрытие госпитализаций +CREATE OR REPLACE FUNCTION check_hospitalization_overlap () + RETURNS TRIGGER + AS $$ +DECLARE + overlap_found boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + get_hospitalization_periods (NEW.patient_id) + WHERE + discharge_datetime IS NOT NULL + AND NEW.admission_datetime < discharge_datetime + AND NEW.admission_datetime > admission_datetime) INTO overlap_found; + IF overlap_found THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10002: HOSPITALIZATION_OVERLAP'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +-- Подключение триггеров на hospital_admissions +CREATE TRIGGER trg_check_active_hospitalization + BEFORE INSERT ON hospital_admission + FOR EACH ROW + EXECUTE FUNCTION check_active_hospitalization (); + +CREATE TRIGGER trg_check_hospitalization_overlap + BEFORE INSERT ON hospital_admission + FOR EACH ROW + EXECUTE FUNCTION check_hospitalization_overlap (); + + +-- Проверка: выписка должна быть позже поступления +CREATE OR REPLACE FUNCTION check_discharge_after_admission () + RETURNS TRIGGER + AS $$ +DECLARE + admission_time timestamp; +BEGIN + SELECT + admission_datetime INTO admission_time + FROM + hospital_admission + WHERE + hospital_admission_id = NEW.hospital_admission_id; + IF NEW.discharge_datetime <= admission_time THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10003: DISCHARGE_BEFORE_ADMISSION'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +CREATE TRIGGER trg_check_discharge_after_admission + BEFORE INSERT OR UPDATE ON hospital_discharge + FOR EACH ROW + EXECUTE FUNCTION check_discharge_after_admission (); + +-- Триггер: нельзя создать выписку, если уже есть выписка по этой госпитализации +CREATE OR REPLACE FUNCTION check_unique_discharge () + RETURNS TRIGGER + AS $$ +DECLARE + discharge_count integer; +BEGIN + SELECT + COUNT(*) INTO discharge_count + FROM + hospital_discharge + WHERE + hospital_admission_id = NEW.hospital_admission_id + AND hospital_discharge_id <> COALESCE(NEW.hospital_discharge_id, -1); + IF discharge_count > 0 THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10004: DISCHARGE_ALREADY_EXISTS'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +CREATE TRIGGER trg_check_unique_discharge + BEFORE INSERT OR UPDATE ON hospital_discharge + FOR EACH ROW + EXECUTE FUNCTION check_unique_discharge (); + + + +-- Триггер: запрет на запись числового результата, если есть качественный по тому же обследованию +CREATE OR REPLACE FUNCTION check_numeric_result_uniqueness () + RETURNS TRIGGER + AS $$ +DECLARE + qualitative_exists boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + qualitative_result + WHERE + result_id = NEW.result_id) INTO qualitative_exists; + IF qualitative_exists THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10005: QUALITATIVE_RESULT_ALREADY_EXISTS_FOR_THIS_EXAMINATION'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +CREATE TRIGGER trg_check_numeric_result_uniqueness + BEFORE INSERT OR UPDATE ON numeric_result + FOR EACH ROW + EXECUTE FUNCTION check_numeric_result_uniqueness (); + + + +-- Триггер: запрет на запись качественного результата, если есть числовой по тому же обследованию +CREATE OR REPLACE FUNCTION check_qualitative_result_uniqueness () + RETURNS TRIGGER + AS $$ +DECLARE + numeric_exists boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + numeric_result + WHERE + result_id = NEW.result_id) INTO numeric_exists; + IF numeric_exists THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10006: NUMERIC_RESULT_ALREADY_EXISTS_FOR_THIS_EXAMINATION'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +CREATE TRIGGER trg_check_qualitative_result_uniqueness + BEFORE INSERT OR UPDATE ON qualitative_result + FOR EACH ROW + EXECUTE FUNCTION check_qualitative_result_uniqueness (); + + + +CREATE OR REPLACE FUNCTION get_results() +RETURNS TABLE ("Пациент" text, "Обследование" text, "Результат" varchar) +AS $$ +BEGIN + RETURN QUERY(SELECT pa.policy_number, et.name, COALESCE(qr.value::varchar, CONCAT(nr.value || ' ' || u.name)) + FROM patient pa + LEFT JOIN prescription pr + ON pa.patient_id = pr.patient_id + LEFT JOIN examination_type_prescription etp + ON pr.prescription_id = etp.prescription_id + LEFT JOIN examination_type et + ON et.examination_type_id = etp.examination_type_id + LEFT JOIN result r + ON etp.result_id = r.result_id + LEFT JOIN qualitative_result qr + ON r.result_id = qr.result_id + LEFT JOIN numeric_result nr + ON r.result_id = nr.result_id + LEFT JOIN unit u + ON nr.unit_id = u.unit_id + WHERE et.name IS NOT NULL); +END; +$$ LANGUAGE plpgsql; + + + + +CREATE EXTENSION IF NOT EXISTS pgcrypto; + + + +CREATE TABLE person_account( + person_id int NOT NULL UNIQUE REFERENCES person, + login varchar(60) NOT NULL, + password varchar NOT NULL, + CONSTRAINT empty_login CHECK (trim(login) <> '') +); + +CREATE OR REPLACE FUNCTION check_password(_password varchar(60)) +RETURNS void AS +$BODY$ +BEGIN + IF (trim(_password) = '') + THEN + RAISE EXCEPTION 'Пароль не может быть пустым!'; + END IF; + + IF (trim(_password) <> _password) + THEN + RAISE EXCEPTION 'Пароль должен быть без пробелов!'; + END IF; + + IF (length(_password) < 8) + THEN + RAISE EXCEPTION 'Пароль должен иметь больше 8 знаков!'; + END IF; + + IF (lower(_password) = _password OR _password !~ '[0-9]') + THEN + RAISE EXCEPTION 'Пароль должен иметь прописные и заглавные буквы, а также цифры!'; + END IF; + + IF ((SELECT COUNT(*) AS letter_count + FROM ( SELECT regexp_split_to_table(_password, '') AS letter) AS letters + GROUP BY letter + ORDER BY letter + LIMIT 1) >= length(_password)/2) + THEN + RAISE EXCEPTION 'Пароль не должен иметь больше половины одинаковых символов!'; + END IF; +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + +CREATE OR REPLACE FUNCTION create_person_account() +RETURNS TRIGGER AS $$ +DECLARE + role int; +BEGIN + PERFORM check_password(NEW.password); + NEW.password := crypt(NEW.password, gen_salt('bf')); + + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +-- Создаем триггер +CREATE TRIGGER trigger_create_account +BEFORE INSERT ON person_account +FOR EACH ROW +EXECUTE FUNCTION create_person_account(); + +CREATE OR REPLACE FUNCTION check_enter_in_person_account(_login varchar, _password varchar) +RETURNS int AS $$ +DECLARE + _hash_password varchar := null; + _person_id int; +BEGIN + -- Получаем person_id и проверяем авторизацию + SELECT pa.person_id, pa.password + INTO _person_id, _hash_password + FROM person_account pa + WHERE pa.login = _login + AND pa.password = crypt(_password, pa.password); + + -- Если запись не найдена + IF _person_id IS NULL THEN + RAISE EXCEPTION 'Неверный логин или пароль!'; + END IF; + + RETURN _person_id; +END; +$$ LANGUAGE plpgsql; + + +-- person +INSERT INTO public.person (person_id, middle_name, first_name, last_name, birth_date, gender, address) VALUES +(1, 'Иванов', 'Николай', 'Владимирович', '1954-10-26', 'male', 'ул. Чайковского, дом 32, квартира 46'), +(2, 'Сидоров', 'Владимир', 'Анатольевич', '1956-12-30', 'male', 'пр. Мира, дом 37, квартира 47'), +(3, 'Кузнецов', 'Пётр', 'Сергеевич', '1978-04-12', 'male', 'ул. Кирова, дом 29, квартира 55'), +(4, 'Петров', 'Иван', 'Владимирович', '2005-09-15', 'male', 'ул. Чайковского, дом 16, квартира 108'), +(5, 'Иванов', 'Николай', 'Андреевич', '1973-11-16', 'male', 'ул. Молодёжная, дом 28, квартира 41'), +(6, 'Иванов', 'Егор', 'Сергеевич', '1987-05-21', 'male', 'ул. Гагарина, дом 3, квартира 92'), +(8, 'апраоплр', 'апарспмориолтьмтич', 'выавпасрмо', '2001-11-28', 'Мужчина', 'вавпраоплдожропав'), +(7, 'впа', 'апр', 'авыпро', '2005-11-28', 'Женщина', 'впарплоро'); + +insert into doctor (doctor_id) +values (1), + (2), + (3); + +insert into registrar (registrar_id) +values (4), + (5), + (6); + +-- patient +INSERT INTO public.patient (patient_id, policy_number) VALUES +(7, '3456789787654322'), +(8, '1232567687654231'); + + +INSERT INTO person_account (person_id, login, password) +VALUES (1, 'Иванов Н.В.', 'Иванов123'), + (2, 'Сидоров В.А.', 'Сидоров123'), + (3, 'Кузнецов П.С.', 'Кузнецов123'), + (4, 'Петров И.В.', 'Петров123'), + (5, 'Иванов Н.А.', 'Иванов123'), + (6, 'Иванов Е.С.', 'Иванов123'); + +-- unit +INSERT INTO public.unit (unit_id, name) VALUES +(2, 'мг/л'), +(3, 'г/л'), +(4, 'ммоль/л'), +(5, 'мкмоль/л'), +(6, 'ед/л'), +(7, '%'), +(8, 'тыс/мкл'), +(9, 'мл'), +(10, 'мм'); + +-- disease +INSERT INTO public.disease (disease_id, name, icd_code) VALUES +(34, 'Губчатая энцефалопатия', 'A12.3'), +(35, 'Красная волчанка', 'A12.5'), +(29, 'Проказа', 'A12.4'), +(36, 'Грипп', 'A12.2'); + +-- syndrome_type +INSERT INTO public.syndrome_type (syndrome_type_id, name) VALUES +(1, 'Лихорадка'), +(2, 'Боль в груди'); + +-- disease_syndrome +INSERT INTO public.disease_syndrome (disease_syndrome_id, disease_id, syndrome_id) VALUES +(1, 29, 1); + +-- drug_intake_method +INSERT INTO public.drug_intake_method (drug_intake_method_id, name) VALUES +(2, 'Внутримышечно'); + +-- drug_type +INSERT INTO public.drug_type (drug_type_id, international_name_ru, international_name_en, international_name_la, brand_name_ru) VALUES +(3, 'Корвалол', NULL, NULL, NULL), +(2, 'Парацетамол', 'Paracetamol', NULL, NULL); + +-- drug_type_prescription +-- Таблица пустая + +-- examination_type +INSERT INTO public.examination_type (examination_type_id, name, category) VALUES +(2, 'ЭКГ', 'Физикальное'), +(3, 'ЭЭГ', 'Инструментальное'); + +-- reference_value +INSERT INTO public.reference_value (reference_value_id, examination_type_id, gender, age_min, age_max) VALUES +(4, 2, 'Мужчина', NULL, 18), +(5, 3, 'Женщина', NULL, 18); + +-- hospital_admission +INSERT INTO public.hospital_admission (hospital_admission_id, patient_id, preliminary_disease_id, admission_datetime) VALUES +(21, 8, 29, '2025-11-30 20:31:06.045'), +(30, 7, 35, '2025-11-30 20:45:06.045254'); + +-- hospital_discharge +INSERT INTO public.hospital_discharge (hospital_discharge_id, hospital_admission_id, discharge_datetime, final_disease_id, reason) VALUES +(1, 21, '2025-12-01 15:59:02.624121', 36, 'Ложная тревога'); + +-- result +INSERT INTO public.result (result_id, examination_id) VALUES +(5, 3), +(7, 3), +(8, 2), +(9, 3), +(10, 2); + +-- numeric_result +INSERT INTO public.numeric_result (result_id, value, unit_id) VALUES +(7, 1.00, 7), +(8, 1.00, 7), +(9, 12.00, 3), +(10, 1.00, 3); + +-- prescription +INSERT INTO public.prescription (prescription_id, patient_id, doctor_id) VALUES +(2, 8, 1), +(23, 7, 1), +(24, 7, 2); + +-- procedure_type +INSERT INTO public.procedure_type (procedure_type_id, name) VALUES +(3, 'Физиотерапия'); + +-- procedure_type_prescription +INSERT INTO public.procedure_type_prescription (procedure_prescription_id, prescription_id, procedure_type_id, scheduled_datetime) VALUES +(3, 2, 3, '2025-11-29 11:11:25.048055'); + +-- qualitative_result +INSERT INTO public.qualitative_result (result_id, value) VALUES +(5, true); + +-- reference_numeric_value +INSERT INTO public.reference_numeric_value (reference_value_id, min_value, max_value, unit_id) VALUES +(4, NULL, 1, 7); + +-- reference_qualitative_value +INSERT INTO public.reference_qualitative_value (reference_value_id, description_true, description_false) VALUES +(4, 'Отсутствует', 'Отсутствует'); + +-- examination_type_prescription +INSERT INTO public.examination_type_prescription (examination_prescription_id, prescription_id, result_id, examination_type_id) VALUES +(7, 2, 5, 3), +(11, 23, 9, 3), +(12, 24, 10, 2); + +-- syndrome_examination_type +INSERT INTO public.syndrome_examination_type (syndrome_id, examination_type_id) VALUES +(2, 3); \ No newline at end of file diff --git a/migrations/account.sql b/migrations/account.sql new file mode 100644 index 0000000..2e19b4f --- /dev/null +++ b/migrations/account.sql @@ -0,0 +1,94 @@ +CREATE EXTENSION IF NOT EXISTS pgcrypto; + + + +CREATE TABLE person_account( + person_id int NOT NULL UNIQUE REFERENCES person, + login varchar(60) NOT NULL, + password varchar NOT NULL, + CONSTRAINT empty_login CHECK (trim(login) <> '') +); + +CREATE OR REPLACE FUNCTION check_password(_password varchar(60)) +RETURNS void AS +$BODY$ +BEGIN + IF (trim(_password) = '') + THEN + RAISE EXCEPTION 'Пароль не может быть пустым!'; + END IF; + + IF (trim(_password) <> _password) + THEN + RAISE EXCEPTION 'Пароль должен быть без пробелов!'; + END IF; + + IF (length(_password) < 8) + THEN + RAISE EXCEPTION 'Пароль должен иметь больше 8 знаков!'; + END IF; + + IF (lower(_password) = _password OR _password !~ '[0-9]') + THEN + RAISE EXCEPTION 'Пароль должен иметь прописные и заглавные буквы, а также цифры!'; + END IF; + + IF ((SELECT COUNT(*) AS letter_count + FROM ( SELECT regexp_split_to_table(_password, '') AS letter) AS letters + GROUP BY letter + ORDER BY letter + LIMIT 1) >= length(_password)/2) + THEN + RAISE EXCEPTION 'Пароль не должен иметь больше половины одинаковых символов!'; + END IF; +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + +CREATE OR REPLACE FUNCTION create_person_account() +RETURNS TRIGGER AS $$ +DECLARE + role int; +BEGIN + PERFORM check_password(NEW.password); + NEW.password := crypt(NEW.password, gen_salt('bf')); + + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +-- Создаем триггер +CREATE TRIGGER trigger_create_account +BEFORE INSERT ON person_account +FOR EACH ROW +EXECUTE FUNCTION create_person_account(); + +CREATE OR REPLACE FUNCTION check_enter_in_person_account(_login varchar, _password varchar) +RETURNS int AS $$ +DECLARE + _hash_password varchar := null; + _person_id int; +BEGIN + -- Получаем person_id и проверяем авторизацию + SELECT pa.person_id, pa.password + INTO _person_id, _hash_password + FROM person_account pa + WHERE pa.login = _login + AND pa.password = crypt(_password, pa.password); + + -- Если запись не найдена + IF _person_id IS NULL THEN + RAISE EXCEPTION 'Неверный логин или пароль!'; + END IF; + + RETURN _person_id; +END; +$$ LANGUAGE plpgsql; + +INSERT INTO person_account (person_id, login, password) +VALUES (1, 'Иванов Н.В.', 'Иванов123'), + (2, 'Сидоров В.А.', 'Сидоров123'), + (3, 'Кузнецов П.С.', 'Кузнецов123'), + (4, 'Петров И.В.', 'Петров123'), + (5, 'Иванов Н.А.', 'Иванов123'), + (6, 'Иванов Е.С.', 'Иванов123'); \ No newline at end of file diff --git a/migrations/backup.sql b/migrations/backup.sql new file mode 100644 index 0000000..6a134d8 Binary files /dev/null and b/migrations/backup.sql differ diff --git a/migrations/backup_plain.sql b/migrations/backup_plain.sql new file mode 100644 index 0000000..40505b6 --- /dev/null +++ b/migrations/backup_plain.sql @@ -0,0 +1,2726 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 16.4 +-- Dumped by pg_dump version 16.4 + +-- Started on 2025-12-01 18:47:42 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- TOC entry 2 (class 3079 OID 185870) +-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public; + + +-- +-- TOC entry 5180 (class 0 OID 0) +-- Dependencies: 2 +-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions'; + + +-- +-- TOC entry 944 (class 1247 OID 177518) +-- Name: examination_categories_enum; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.examination_categories_enum AS ENUM ( + 'physical', + 'laboratory', + 'instrumental' +); + + +ALTER TYPE public.examination_categories_enum OWNER TO postgres; + +-- +-- TOC entry 941 (class 1247 OID 177512) +-- Name: gender_enum; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.gender_enum AS ENUM ( + 'male', + 'female' +); + + +ALTER TYPE public.gender_enum OWNER TO postgres; + +-- +-- TOC entry 947 (class 1247 OID 177526) +-- Name: hospital_discharge_reason_enum; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.hospital_discharge_reason_enum AS ENUM ( + 'death', + 'improvement', + 'refusal' +); + + +ALTER TYPE public.hospital_discharge_reason_enum OWNER TO postgres; + +-- +-- TOC entry 950 (class 1247 OID 177534) +-- Name: unit_context_enum; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.unit_context_enum AS ENUM ( + 'examination', + 'medication' +); + + +ALTER TYPE public.unit_context_enum OWNER TO postgres; + +-- +-- TOC entry 296 (class 1255 OID 180112) +-- Name: check_active_hospitalization(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.check_active_hospitalization() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE + open_hospitalization boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + get_hospitalization_periods (NEW.patient_id) + WHERE + discharge_datetime IS NULL) INTO open_hospitalization; + IF open_hospitalization THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = 'Госпитализация данного пациента еще не завершена'; + END IF; + RETURN NEW; +END; +$$; + + +ALTER FUNCTION public.check_active_hospitalization() OWNER TO postgres; + +-- +-- TOC entry 297 (class 1255 OID 180116) +-- Name: check_discharge_after_admission(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.check_discharge_after_admission() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE + admission_time timestamp; +BEGIN + SELECT + admission_datetime INTO admission_time + FROM + hospital_admission + WHERE + hospital_admission_id = NEW.hospital_admission_id; + IF NEW.discharge_datetime <= admission_time THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10003: DISCHARGE_BEFORE_ADMISSION'; + END IF; + RETURN NEW; +END; +$$; + + +ALTER FUNCTION public.check_discharge_after_admission() OWNER TO postgres; + +-- +-- TOC entry 294 (class 1255 OID 185907) +-- Name: check_enter_in_person_account(character varying, character varying); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.check_enter_in_person_account(_login character varying, _password character varying) RETURNS integer + LANGUAGE plpgsql + AS $$ +DECLARE + _hash_password varchar := null; + _person_id int; +BEGIN + -- Получаем person_id и проверяем авторизацию + SELECT pa.person_id, pa.password + INTO _person_id, _hash_password + FROM person_account pa + WHERE pa.login = _login + AND pa.password = crypt(_password, pa.password); + + -- Если запись не найдена + IF _person_id IS NULL THEN + RAISE EXCEPTION 'Неверный логин или пароль!'; + END IF; + + RETURN _person_id; +END; +$$; + + +ALTER FUNCTION public.check_enter_in_person_account(_login character varying, _password character varying) OWNER TO postgres; + +-- +-- TOC entry 295 (class 1255 OID 180113) +-- Name: check_hospitalization_overlap(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.check_hospitalization_overlap() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE + overlap_found boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + get_hospitalization_periods (NEW.patient_id) + WHERE + discharge_datetime IS NOT NULL + AND NEW.admission_datetime < discharge_datetime + AND NEW.admission_datetime > admission_datetime) INTO overlap_found; + IF overlap_found THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10002: HOSPITALIZATION_OVERLAP'; + END IF; + RETURN NEW; +END; +$$; + + +ALTER FUNCTION public.check_hospitalization_overlap() OWNER TO postgres; + +-- +-- TOC entry 292 (class 1255 OID 180120) +-- Name: check_numeric_result_uniqueness(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.check_numeric_result_uniqueness() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE + qualitative_exists boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + qualitative_result + WHERE + result_id = NEW.result_id) INTO qualitative_exists; + IF qualitative_exists THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10005: QUALITATIVE_RESULT_ALREADY_EXISTS_FOR_THIS_EXAMINATION'; + END IF; + RETURN NEW; +END; +$$; + + +ALTER FUNCTION public.check_numeric_result_uniqueness() OWNER TO postgres; + +-- +-- TOC entry 298 (class 1255 OID 185866) +-- Name: check_password(character varying); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.check_password(_password character varying) RETURNS void + LANGUAGE plpgsql + AS $$ +BEGIN + IF (trim(_password) = '') + THEN + RAISE EXCEPTION 'Пароль не может быть пустым!'; + END IF; + + IF (trim(_password) <> _password) + THEN + RAISE EXCEPTION 'Пароль должен быть без пробелов!'; + END IF; + + IF (length(_password) < 8) + THEN + RAISE EXCEPTION 'Пароль должен иметь больше 8 знаков!'; + END IF; + + IF (lower(_password) = _password OR _password !~ '[0-9]') + THEN + RAISE EXCEPTION 'Пароль должен иметь прописные и заглавные буквы, а также цифры!'; + END IF; + + IF ((SELECT COUNT(*) AS letter_count + FROM ( SELECT regexp_split_to_table(_password, '') AS letter) AS letters + GROUP BY letter + ORDER BY letter + LIMIT 1) >= length(_password)/2) + THEN + RAISE EXCEPTION 'Пароль не должен иметь больше половины одинаковых символов!'; + END IF; +END +$$; + + +ALTER FUNCTION public.check_password(_password character varying) OWNER TO postgres; + +-- +-- TOC entry 278 (class 1255 OID 180122) +-- Name: check_qualitative_result_uniqueness(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.check_qualitative_result_uniqueness() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE + numeric_exists boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + numeric_result + WHERE + result_id = NEW.result_id) INTO numeric_exists; + IF numeric_exists THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10006: NUMERIC_RESULT_ALREADY_EXISTS_FOR_THIS_EXAMINATION'; + END IF; + RETURN NEW; +END; +$$; + + +ALTER FUNCTION public.check_qualitative_result_uniqueness() OWNER TO postgres; + +-- +-- TOC entry 293 (class 1255 OID 180118) +-- Name: check_unique_discharge(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.check_unique_discharge() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE + discharge_count integer; +BEGIN + SELECT + COUNT(*) INTO discharge_count + FROM + hospital_discharge + WHERE + hospital_admission_id = NEW.hospital_admission_id + AND hospital_discharge_id <> COALESCE(NEW.hospital_discharge_id, -1); + IF discharge_count > 0 THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10004: DISCHARGE_ALREADY_EXISTS'; + END IF; + RETURN NEW; +END; +$$; + + +ALTER FUNCTION public.check_unique_discharge() OWNER TO postgres; + +-- +-- TOC entry 299 (class 1255 OID 185867) +-- Name: create_person_account(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.create_person_account() RETURNS trigger + LANGUAGE plpgsql + AS $$ +DECLARE + role int; +BEGIN + PERFORM check_password(NEW.password); + NEW.password := crypt(NEW.password, gen_salt('bf')); + + RETURN NEW; +END; +$$; + + +ALTER FUNCTION public.create_person_account() OWNER TO postgres; + +-- +-- TOC entry 291 (class 1255 OID 177549) +-- Name: default_str_check(text); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.default_str_check(str text) RETURNS boolean + LANGUAGE plpgsql IMMUTABLE + AS $$ +BEGIN + RETURN str IS NULL + OR no_double_space (str) + AND no_space_start_end (str) + AND str_length_between (str, 1, 128); +END; +$$; + + +ALTER FUNCTION public.default_str_check(str text) OWNER TO postgres; + +-- +-- TOC entry 290 (class 1255 OID 177548) +-- Name: default_word_check(text); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.default_word_check(str text) RETURNS boolean + LANGUAGE plpgsql IMMUTABLE + AS $$ +BEGIN + RETURN str IS NULL + OR no_space (str) + AND str_length_between (str, 1, 64); +END; +$$; + + +ALTER FUNCTION public.default_word_check(str text) OWNER TO postgres; + +-- +-- TOC entry 264 (class 1255 OID 180111) +-- Name: get_hospitalization_periods(integer); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.get_hospitalization_periods(p_patient_id integer) RETURNS TABLE(admission_datetime timestamp without time zone, discharge_datetime timestamp without time zone) + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN QUERY + SELECT + ha.admission_datetime, + hd.discharge_datetime + FROM + hospital_admission ha + LEFT JOIN hospital_discharge hd ON ha.hospital_admission_id = hd.hospital_admission_id +WHERE + ha.patient_id = p_patient_id; +END; +$$; + + +ALTER FUNCTION public.get_hospitalization_periods(p_patient_id integer) OWNER TO postgres; + +-- +-- TOC entry 327 (class 1255 OID 185911) +-- Name: get_results(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.get_results() RETURNS TABLE("Пациент" text, "Обследование" text, "Результат" character varying) + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN QUERY(SELECT pa.policy_number, et.name, COALESCE(qr.value::varchar, CONCAT(nr.value || ' ' || u.name)) + FROM patient pa + LEFT JOIN prescription pr + ON pa.patient_id = pr.patient_id + LEFT JOIN examination_type_prescription etp + ON pr.prescription_id = etp.prescription_id + LEFT JOIN examination_type et + ON et.examination_type_id = etp.examination_type_id + LEFT JOIN result r + ON etp.result_id = r.result_id + LEFT JOIN qualitative_result qr + ON r.result_id = qr.result_id + LEFT JOIN numeric_result nr + ON r.result_id = nr.result_id + LEFT JOIN unit u + ON nr.unit_id = u.unit_id + WHERE et.name IS NOT NULL); +END; +$$; + + +ALTER FUNCTION public.get_results() OWNER TO postgres; + +-- +-- TOC entry 285 (class 1255 OID 177544) +-- Name: no_double_space(text); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.no_double_space(str text) RETURNS boolean + LANGUAGE plpgsql IMMUTABLE + AS $$ +BEGIN + RETURN str !~ E'\s{2,}'; +END; +$$; + + +ALTER FUNCTION public.no_double_space(str text) OWNER TO postgres; + +-- +-- TOC entry 288 (class 1255 OID 177546) +-- Name: no_space(text); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.no_space(str text) RETURNS boolean + LANGUAGE plpgsql IMMUTABLE + AS $$ +BEGIN + RETURN str !~ E'\s'; +END; +$$; + + +ALTER FUNCTION public.no_space(str text) OWNER TO postgres; + +-- +-- TOC entry 286 (class 1255 OID 177545) +-- Name: no_space_start_end(text); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.no_space_start_end(str text) RETURNS boolean + LANGUAGE plpgsql IMMUTABLE + AS $_$ +BEGIN + RETURN str !~ E'^\s' + AND str !~ E'\s$'; +END; +$_$; + + +ALTER FUNCTION public.no_space_start_end(str text) OWNER TO postgres; + +-- +-- TOC entry 273 (class 1255 OID 180274) +-- Name: random_int(integer, integer); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.random_int(min_val integer, max_val integer) RETURNS integer + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN min_val + trunc(random() * (max_val - min_val + 1))::int; +END; +$$; + + +ALTER FUNCTION public.random_int(min_val integer, max_val integer) OWNER TO postgres; + +-- +-- TOC entry 289 (class 1255 OID 177547) +-- Name: str_length_between(text, integer, integer); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.str_length_between(str text, min_len integer, max_len integer) RETURNS boolean + LANGUAGE plpgsql IMMUTABLE + AS $$ +BEGIN + RETURN LENGTH(str) BETWEEN min_len AND max_len; +END; +$$; + + +ALTER FUNCTION public.str_length_between(str text, min_len integer, max_len integer) OWNER TO postgres; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- TOC entry 245 (class 1259 OID 179932) +-- Name: disease; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.disease ( + disease_id integer NOT NULL, + name text NOT NULL, + icd_code text NOT NULL, + CONSTRAINT disease_name_check CHECK (public.default_str_check(name)) +); + + +ALTER TABLE public.disease OWNER TO postgres; + +-- +-- TOC entry 244 (class 1259 OID 179931) +-- Name: disease_disease_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.disease_disease_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.disease_disease_id_seq OWNER TO postgres; + +-- +-- TOC entry 5181 (class 0 OID 0) +-- Dependencies: 244 +-- Name: disease_disease_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.disease_disease_id_seq OWNED BY public.disease.disease_id; + + +-- +-- TOC entry 247 (class 1259 OID 179947) +-- Name: disease_syndrome; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.disease_syndrome ( + disease_syndrome_id integer NOT NULL, + disease_id integer NOT NULL, + syndrome_id integer NOT NULL +); + + +ALTER TABLE public.disease_syndrome OWNER TO postgres; + +-- +-- TOC entry 246 (class 1259 OID 179946) +-- Name: disease_syndrome_disease_syndrome_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.disease_syndrome_disease_syndrome_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.disease_syndrome_disease_syndrome_id_seq OWNER TO postgres; + +-- +-- TOC entry 5182 (class 0 OID 0) +-- Dependencies: 246 +-- Name: disease_syndrome_disease_syndrome_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.disease_syndrome_disease_syndrome_id_seq OWNED BY public.disease_syndrome.disease_syndrome_id; + + +-- +-- TOC entry 223 (class 1259 OID 179728) +-- Name: doctor; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.doctor ( + doctor_id integer NOT NULL +); + + +ALTER TABLE public.doctor OWNER TO postgres; + +-- +-- TOC entry 249 (class 1259 OID 180014) +-- Name: drug_intake_method; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.drug_intake_method ( + drug_intake_method_id integer NOT NULL, + name text NOT NULL, + CONSTRAINT drug_intake_method_name_check CHECK (public.default_word_check(name)) +); + + +ALTER TABLE public.drug_intake_method OWNER TO postgres; + +-- +-- TOC entry 248 (class 1259 OID 180013) +-- Name: drug_intake_method_drug_intake_method_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.drug_intake_method_drug_intake_method_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.drug_intake_method_drug_intake_method_id_seq OWNER TO postgres; + +-- +-- TOC entry 5183 (class 0 OID 0) +-- Dependencies: 248 +-- Name: drug_intake_method_drug_intake_method_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.drug_intake_method_drug_intake_method_id_seq OWNED BY public.drug_intake_method.drug_intake_method_id; + + +-- +-- TOC entry 251 (class 1259 OID 180026) +-- Name: drug_type; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.drug_type ( + drug_type_id integer NOT NULL, + international_name_ru text NOT NULL, + international_name_en text, + international_name_la text, + brand_name_ru text, + CONSTRAINT drug_type_brand_name_ru_check CHECK (public.default_word_check(brand_name_ru)), + CONSTRAINT drug_type_international_name_en_check CHECK (public.default_word_check(international_name_en)), + CONSTRAINT drug_type_international_name_la_check CHECK (public.default_word_check(international_name_la)), + CONSTRAINT drug_type_international_name_ru_check CHECK (public.default_word_check(international_name_ru)) +); + + +ALTER TABLE public.drug_type OWNER TO postgres; + +-- +-- TOC entry 250 (class 1259 OID 180025) +-- Name: drug_type_drug_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.drug_type_drug_type_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.drug_type_drug_type_id_seq OWNER TO postgres; + +-- +-- TOC entry 5184 (class 0 OID 0) +-- Dependencies: 250 +-- Name: drug_type_drug_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.drug_type_drug_type_id_seq OWNED BY public.drug_type.drug_type_id; + + +-- +-- TOC entry 253 (class 1259 OID 180047) +-- Name: drug_type_prescription; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.drug_type_prescription ( + drug_prescription_id integer NOT NULL, + prescription_id integer NOT NULL, + drug_type_id integer NOT NULL, + dose numeric NOT NULL, + dose_unit_id integer NOT NULL, + intake_method_id integer NOT NULL, + duration_days integer NOT NULL, + CONSTRAINT drug_type_prescription_dose_check CHECK ((dose > (0)::numeric)), + CONSTRAINT drug_type_prescription_duration_days_check CHECK ((duration_days > 0)) +); + + +ALTER TABLE public.drug_type_prescription OWNER TO postgres; + +-- +-- TOC entry 252 (class 1259 OID 180046) +-- Name: drug_type_prescription_drug_prescription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.drug_type_prescription_drug_prescription_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.drug_type_prescription_drug_prescription_id_seq OWNER TO postgres; + +-- +-- TOC entry 5185 (class 0 OID 0) +-- Dependencies: 252 +-- Name: drug_type_prescription_drug_prescription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.drug_type_prescription_drug_prescription_id_seq OWNED BY public.drug_type_prescription.drug_prescription_id; + + +-- +-- TOC entry 230 (class 1259 OID 179778) +-- Name: examination_type; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.examination_type ( + examination_type_id integer NOT NULL, + name text NOT NULL, + category text NOT NULL, + CONSTRAINT examination_type_name_check CHECK (public.default_word_check(name)) +); + + +ALTER TABLE public.examination_type OWNER TO postgres; + +-- +-- TOC entry 229 (class 1259 OID 179777) +-- Name: examination_type_examination_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.examination_type_examination_type_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.examination_type_examination_type_id_seq OWNER TO postgres; + +-- +-- TOC entry 5186 (class 0 OID 0) +-- Dependencies: 229 +-- Name: examination_type_examination_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.examination_type_examination_type_id_seq OWNED BY public.examination_type.examination_type_id; + + +-- +-- TOC entry 234 (class 1259 OID 179804) +-- Name: examination_type_prescription; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.examination_type_prescription ( + examination_prescription_id integer NOT NULL, + prescription_id integer NOT NULL, + result_id integer, + examination_type_id integer NOT NULL +); + + +ALTER TABLE public.examination_type_prescription OWNER TO postgres; + +-- +-- TOC entry 233 (class 1259 OID 179803) +-- Name: examination_type_prescription_examination_prescription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.examination_type_prescription_examination_prescription_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.examination_type_prescription_examination_prescription_id_seq OWNER TO postgres; + +-- +-- TOC entry 5187 (class 0 OID 0) +-- Dependencies: 233 +-- Name: examination_type_prescription_examination_prescription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.examination_type_prescription_examination_prescription_id_seq OWNED BY public.examination_type_prescription.examination_prescription_id; + + +-- +-- TOC entry 259 (class 1259 OID 185812) +-- Name: hospital_admission; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.hospital_admission ( + hospital_admission_id integer NOT NULL, + patient_id integer NOT NULL, + preliminary_disease_id integer NOT NULL, + admission_datetime timestamp without time zone NOT NULL, + CONSTRAINT hospital_admission_admission_datetime_check CHECK ((admission_datetime <= CURRENT_TIMESTAMP)) +); + + +ALTER TABLE public.hospital_admission OWNER TO postgres; + +-- +-- TOC entry 258 (class 1259 OID 185811) +-- Name: hospital_admission_hospital_admission_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.hospital_admission_hospital_admission_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.hospital_admission_hospital_admission_id_seq OWNER TO postgres; + +-- +-- TOC entry 5188 (class 0 OID 0) +-- Dependencies: 258 +-- Name: hospital_admission_hospital_admission_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.hospital_admission_hospital_admission_id_seq OWNED BY public.hospital_admission.hospital_admission_id; + + +-- +-- TOC entry 261 (class 1259 OID 185830) +-- Name: hospital_discharge; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.hospital_discharge ( + hospital_discharge_id integer NOT NULL, + hospital_admission_id integer NOT NULL, + discharge_datetime timestamp without time zone NOT NULL, + final_disease_id integer NOT NULL, + reason text NOT NULL, + CONSTRAINT hospital_discharge_discharge_datetime_check CHECK ((discharge_datetime <= CURRENT_TIMESTAMP)) +); + + +ALTER TABLE public.hospital_discharge OWNER TO postgres; + +-- +-- TOC entry 260 (class 1259 OID 185829) +-- Name: hospital_discharge_hospital_discharge_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.hospital_discharge_hospital_discharge_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.hospital_discharge_hospital_discharge_id_seq OWNER TO postgres; + +-- +-- TOC entry 5189 (class 0 OID 0) +-- Dependencies: 260 +-- Name: hospital_discharge_hospital_discharge_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.hospital_discharge_hospital_discharge_id_seq OWNED BY public.hospital_discharge.hospital_discharge_id; + + +-- +-- TOC entry 235 (class 1259 OID 179827) +-- Name: numeric_result; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.numeric_result ( + result_id integer NOT NULL, + value numeric NOT NULL, + unit_id integer NOT NULL +); + + +ALTER TABLE public.numeric_result OWNER TO postgres; + +-- +-- TOC entry 222 (class 1259 OID 179715) +-- Name: patient; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.patient ( + patient_id integer NOT NULL, + policy_number text NOT NULL, + CONSTRAINT patient_policy_number_check CHECK ((policy_number ~ '^[0-9]{16}$'::text)) +); + + +ALTER TABLE public.patient OWNER TO postgres; + +-- +-- TOC entry 221 (class 1259 OID 179702) +-- Name: person; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.person ( + person_id integer NOT NULL, + middle_name text NOT NULL, + first_name text NOT NULL, + last_name text, + birth_date date NOT NULL, + gender text NOT NULL, + address text NOT NULL, + CONSTRAINT person_address_check CHECK (public.default_str_check(address)), + CONSTRAINT person_birth_date_check CHECK ((birth_date <= CURRENT_DATE)), + CONSTRAINT person_first_name_check CHECK (public.default_word_check(first_name)), + CONSTRAINT person_last_name_check CHECK (public.default_word_check(middle_name)), + CONSTRAINT person_middle_name_check CHECK (public.default_word_check(last_name)) +); + + +ALTER TABLE public.person OWNER TO postgres; + +-- +-- TOC entry 262 (class 1259 OID 185853) +-- Name: person_account; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.person_account ( + person_id integer NOT NULL, + login character varying(60) NOT NULL, + password character varying NOT NULL, + CONSTRAINT empty_login CHECK ((TRIM(BOTH FROM login) <> ''::text)) +); + + +ALTER TABLE public.person_account OWNER TO postgres; + +-- +-- TOC entry 220 (class 1259 OID 179701) +-- Name: person_person_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.person_person_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.person_person_id_seq OWNER TO postgres; + +-- +-- TOC entry 5190 (class 0 OID 0) +-- Dependencies: 220 +-- Name: person_person_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.person_person_id_seq OWNED BY public.person.person_id; + + +-- +-- TOC entry 228 (class 1259 OID 179761) +-- Name: prescription; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.prescription ( + prescription_id integer NOT NULL, + patient_id integer NOT NULL, + doctor_id integer NOT NULL +); + + +ALTER TABLE public.prescription OWNER TO postgres; + +-- +-- TOC entry 227 (class 1259 OID 179760) +-- Name: prescription_prescription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.prescription_prescription_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.prescription_prescription_id_seq OWNER TO postgres; + +-- +-- TOC entry 5191 (class 0 OID 0) +-- Dependencies: 227 +-- Name: prescription_prescription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.prescription_prescription_id_seq OWNED BY public.prescription.prescription_id; + + +-- +-- TOC entry 255 (class 1259 OID 180080) +-- Name: procedure_type; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.procedure_type ( + procedure_type_id integer NOT NULL, + name text NOT NULL, + CONSTRAINT procedure_type_name_check CHECK (public.default_word_check(name)) +); + + +ALTER TABLE public.procedure_type OWNER TO postgres; + +-- +-- TOC entry 257 (class 1259 OID 180092) +-- Name: procedure_type_prescription; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.procedure_type_prescription ( + procedure_prescription_id integer NOT NULL, + prescription_id integer NOT NULL, + procedure_type_id integer NOT NULL, + scheduled_datetime timestamp without time zone NOT NULL +); + + +ALTER TABLE public.procedure_type_prescription OWNER TO postgres; + +-- +-- TOC entry 256 (class 1259 OID 180091) +-- Name: procedure_type_prescription_procedure_prescription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.procedure_type_prescription_procedure_prescription_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.procedure_type_prescription_procedure_prescription_id_seq OWNER TO postgres; + +-- +-- TOC entry 5192 (class 0 OID 0) +-- Dependencies: 256 +-- Name: procedure_type_prescription_procedure_prescription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.procedure_type_prescription_procedure_prescription_id_seq OWNED BY public.procedure_type_prescription.procedure_prescription_id; + + +-- +-- TOC entry 254 (class 1259 OID 180079) +-- Name: procedure_type_procedure_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.procedure_type_procedure_type_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.procedure_type_procedure_type_id_seq OWNER TO postgres; + +-- +-- TOC entry 5193 (class 0 OID 0) +-- Dependencies: 254 +-- Name: procedure_type_procedure_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.procedure_type_procedure_type_id_seq OWNED BY public.procedure_type.procedure_type_id; + + +-- +-- TOC entry 236 (class 1259 OID 179844) +-- Name: qualitative_result; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.qualitative_result ( + result_id integer NOT NULL, + value boolean NOT NULL +); + + +ALTER TABLE public.qualitative_result OWNER TO postgres; + +-- +-- TOC entry 239 (class 1259 OID 179869) +-- Name: reference_numeric_value; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.reference_numeric_value ( + reference_value_id integer NOT NULL, + min_value numeric, + max_value numeric, + unit_id integer NOT NULL +); + + +ALTER TABLE public.reference_numeric_value OWNER TO postgres; + +-- +-- TOC entry 240 (class 1259 OID 179886) +-- Name: reference_qualitative_value; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.reference_qualitative_value ( + reference_value_id integer NOT NULL, + description_true text NOT NULL, + description_false text NOT NULL, + CONSTRAINT reference_qualitative_value_description_false_check CHECK (public.default_word_check(description_false)), + CONSTRAINT reference_qualitative_value_description_true_check CHECK (public.default_word_check(description_true)) +); + + +ALTER TABLE public.reference_qualitative_value OWNER TO postgres; + +-- +-- TOC entry 238 (class 1259 OID 179855) +-- Name: reference_value; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.reference_value ( + reference_value_id integer NOT NULL, + examination_type_id integer NOT NULL, + gender text, + age_min integer, + age_max integer, + CONSTRAINT reference_value_check CHECK (((age_min IS NULL) OR (age_max IS NULL) OR (age_min < age_max))) +); + + +ALTER TABLE public.reference_value OWNER TO postgres; + +-- +-- TOC entry 237 (class 1259 OID 179854) +-- Name: reference_value_reference_value_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.reference_value_reference_value_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.reference_value_reference_value_id_seq OWNER TO postgres; + +-- +-- TOC entry 5194 (class 0 OID 0) +-- Dependencies: 237 +-- Name: reference_value_reference_value_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.reference_value_reference_value_id_seq OWNED BY public.reference_value.reference_value_id; + + +-- +-- TOC entry 224 (class 1259 OID 179738) +-- Name: registrar; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.registrar ( + registrar_id integer NOT NULL +); + + +ALTER TABLE public.registrar OWNER TO postgres; + +-- +-- TOC entry 232 (class 1259 OID 179790) +-- Name: result; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.result ( + result_id integer NOT NULL, + examination_id integer NOT NULL +); + + +ALTER TABLE public.result OWNER TO postgres; + +-- +-- TOC entry 231 (class 1259 OID 179789) +-- Name: result_result_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.result_result_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.result_result_id_seq OWNER TO postgres; + +-- +-- TOC entry 5195 (class 0 OID 0) +-- Dependencies: 231 +-- Name: result_result_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.result_result_id_seq OWNED BY public.result.result_id; + + +-- +-- TOC entry 243 (class 1259 OID 179914) +-- Name: syndrome_examination_type; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.syndrome_examination_type ( + syndrome_id integer NOT NULL, + examination_type_id integer NOT NULL +); + + +ALTER TABLE public.syndrome_examination_type OWNER TO postgres; + +-- +-- TOC entry 242 (class 1259 OID 179903) +-- Name: syndrome_type; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.syndrome_type ( + syndrome_type_id integer NOT NULL, + name text NOT NULL, + CONSTRAINT syndrome_type_name_check CHECK (public.default_word_check(name)) +); + + +ALTER TABLE public.syndrome_type OWNER TO postgres; + +-- +-- TOC entry 241 (class 1259 OID 179902) +-- Name: syndrome_type_syndrome_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.syndrome_type_syndrome_type_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.syndrome_type_syndrome_type_id_seq OWNER TO postgres; + +-- +-- TOC entry 5196 (class 0 OID 0) +-- Dependencies: 241 +-- Name: syndrome_type_syndrome_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.syndrome_type_syndrome_type_id_seq OWNED BY public.syndrome_type.syndrome_type_id; + + +-- +-- TOC entry 226 (class 1259 OID 179749) +-- Name: unit; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.unit ( + unit_id integer NOT NULL, + name text NOT NULL, + CONSTRAINT unit_name_check CHECK (((name ~ '^[а-яА-ЯёЁ%^/]+$'::text) AND public.str_length_between(name, 1, 16))) +); + + +ALTER TABLE public.unit OWNER TO postgres; + +-- +-- TOC entry 225 (class 1259 OID 179748) +-- Name: unit_unit_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.unit_unit_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.unit_unit_id_seq OWNER TO postgres; + +-- +-- TOC entry 5197 (class 0 OID 0) +-- Dependencies: 225 +-- Name: unit_unit_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.unit_unit_id_seq OWNED BY public.unit.unit_id; + + +-- +-- TOC entry 4829 (class 2604 OID 179935) +-- Name: disease disease_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease ALTER COLUMN disease_id SET DEFAULT nextval('public.disease_disease_id_seq'::regclass); + + +-- +-- TOC entry 4830 (class 2604 OID 179950) +-- Name: disease_syndrome disease_syndrome_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease_syndrome ALTER COLUMN disease_syndrome_id SET DEFAULT nextval('public.disease_syndrome_disease_syndrome_id_seq'::regclass); + + +-- +-- TOC entry 4831 (class 2604 OID 180017) +-- Name: drug_intake_method drug_intake_method_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_intake_method ALTER COLUMN drug_intake_method_id SET DEFAULT nextval('public.drug_intake_method_drug_intake_method_id_seq'::regclass); + + +-- +-- TOC entry 4832 (class 2604 OID 180029) +-- Name: drug_type drug_type_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type ALTER COLUMN drug_type_id SET DEFAULT nextval('public.drug_type_drug_type_id_seq'::regclass); + + +-- +-- TOC entry 4833 (class 2604 OID 180050) +-- Name: drug_type_prescription drug_prescription_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type_prescription ALTER COLUMN drug_prescription_id SET DEFAULT nextval('public.drug_type_prescription_drug_prescription_id_seq'::regclass); + + +-- +-- TOC entry 4824 (class 2604 OID 179781) +-- Name: examination_type examination_type_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type ALTER COLUMN examination_type_id SET DEFAULT nextval('public.examination_type_examination_type_id_seq'::regclass); + + +-- +-- TOC entry 4826 (class 2604 OID 179807) +-- Name: examination_type_prescription examination_prescription_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type_prescription ALTER COLUMN examination_prescription_id SET DEFAULT nextval('public.examination_type_prescription_examination_prescription_id_seq'::regclass); + + +-- +-- TOC entry 4836 (class 2604 OID 185815) +-- Name: hospital_admission hospital_admission_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.hospital_admission ALTER COLUMN hospital_admission_id SET DEFAULT nextval('public.hospital_admission_hospital_admission_id_seq'::regclass); + + +-- +-- TOC entry 4837 (class 2604 OID 185833) +-- Name: hospital_discharge hospital_discharge_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.hospital_discharge ALTER COLUMN hospital_discharge_id SET DEFAULT nextval('public.hospital_discharge_hospital_discharge_id_seq'::regclass); + + +-- +-- TOC entry 4821 (class 2604 OID 179705) +-- Name: person person_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.person ALTER COLUMN person_id SET DEFAULT nextval('public.person_person_id_seq'::regclass); + + +-- +-- TOC entry 4823 (class 2604 OID 179764) +-- Name: prescription prescription_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.prescription ALTER COLUMN prescription_id SET DEFAULT nextval('public.prescription_prescription_id_seq'::regclass); + + +-- +-- TOC entry 4834 (class 2604 OID 180083) +-- Name: procedure_type procedure_type_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.procedure_type ALTER COLUMN procedure_type_id SET DEFAULT nextval('public.procedure_type_procedure_type_id_seq'::regclass); + + +-- +-- TOC entry 4835 (class 2604 OID 180095) +-- Name: procedure_type_prescription procedure_prescription_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.procedure_type_prescription ALTER COLUMN procedure_prescription_id SET DEFAULT nextval('public.procedure_type_prescription_procedure_prescription_id_seq'::regclass); + + +-- +-- TOC entry 4827 (class 2604 OID 179858) +-- Name: reference_value reference_value_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_value ALTER COLUMN reference_value_id SET DEFAULT nextval('public.reference_value_reference_value_id_seq'::regclass); + + +-- +-- TOC entry 4825 (class 2604 OID 179793) +-- Name: result result_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.result ALTER COLUMN result_id SET DEFAULT nextval('public.result_result_id_seq'::regclass); + + +-- +-- TOC entry 4828 (class 2604 OID 179906) +-- Name: syndrome_type syndrome_type_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.syndrome_type ALTER COLUMN syndrome_type_id SET DEFAULT nextval('public.syndrome_type_syndrome_type_id_seq'::regclass); + + +-- +-- TOC entry 4822 (class 2604 OID 179752) +-- Name: unit unit_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.unit ALTER COLUMN unit_id SET DEFAULT nextval('public.unit_unit_id_seq'::regclass); + + +-- +-- TOC entry 5157 (class 0 OID 179932) +-- Dependencies: 245 +-- Data for Name: disease; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.disease (disease_id, name, icd_code) FROM stdin; +34 Губчатая энцефалопатия A12.3 +35 Красная волчанка A12.5 +29 Проказа A12.4 +36 Грипп A12.2 +\. + + +-- +-- TOC entry 5159 (class 0 OID 179947) +-- Dependencies: 247 +-- Data for Name: disease_syndrome; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.disease_syndrome (disease_syndrome_id, disease_id, syndrome_id) FROM stdin; +1 29 1 +\. + + +-- +-- TOC entry 5135 (class 0 OID 179728) +-- Dependencies: 223 +-- Data for Name: doctor; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.doctor (doctor_id) FROM stdin; +1 +2 +3 +\. + + +-- +-- TOC entry 5161 (class 0 OID 180014) +-- Dependencies: 249 +-- Data for Name: drug_intake_method; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.drug_intake_method (drug_intake_method_id, name) FROM stdin; +2 Внутримышечно +\. + + +-- +-- TOC entry 5163 (class 0 OID 180026) +-- Dependencies: 251 +-- Data for Name: drug_type; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.drug_type (drug_type_id, international_name_ru, international_name_en, international_name_la, brand_name_ru) FROM stdin; +3 Корвалол \N \N \N +2 Парацетамол Paracetamol \N \N +\. + + +-- +-- TOC entry 5165 (class 0 OID 180047) +-- Dependencies: 253 +-- Data for Name: drug_type_prescription; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.drug_type_prescription (drug_prescription_id, prescription_id, drug_type_id, dose, dose_unit_id, intake_method_id, duration_days) FROM stdin; +\. + + +-- +-- TOC entry 5142 (class 0 OID 179778) +-- Dependencies: 230 +-- Data for Name: examination_type; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.examination_type (examination_type_id, name, category) FROM stdin; +2 ЭКГ Физикальное +3 ЭЭГ Инструментальное +\. + + +-- +-- TOC entry 5146 (class 0 OID 179804) +-- Dependencies: 234 +-- Data for Name: examination_type_prescription; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.examination_type_prescription (examination_prescription_id, prescription_id, result_id, examination_type_id) FROM stdin; +7 2 5 3 +11 23 9 3 +12 24 10 2 +\. + + +-- +-- TOC entry 5171 (class 0 OID 185812) +-- Dependencies: 259 +-- Data for Name: hospital_admission; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.hospital_admission (hospital_admission_id, patient_id, preliminary_disease_id, admission_datetime) FROM stdin; +21 8 29 2025-11-30 20:31:06.045 +30 7 35 2025-11-30 20:45:06.045254 +\. + + +-- +-- TOC entry 5173 (class 0 OID 185830) +-- Dependencies: 261 +-- Data for Name: hospital_discharge; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.hospital_discharge (hospital_discharge_id, hospital_admission_id, discharge_datetime, final_disease_id, reason) FROM stdin; +1 21 2025-12-01 15:59:02.624121 36 Ложная тревога +\. + + +-- +-- TOC entry 5147 (class 0 OID 179827) +-- Dependencies: 235 +-- Data for Name: numeric_result; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.numeric_result (result_id, value, unit_id) FROM stdin; +7 1.00 7 +8 1.00 7 +9 12.00 3 +10 1.00 3 +\. + + +-- +-- TOC entry 5134 (class 0 OID 179715) +-- Dependencies: 222 +-- Data for Name: patient; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.patient (patient_id, policy_number) FROM stdin; +7 3456789787654322 +8 1232567687654231 +\. + + +-- +-- TOC entry 5133 (class 0 OID 179702) +-- Dependencies: 221 +-- Data for Name: person; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.person (person_id, middle_name, first_name, last_name, birth_date, gender, address) FROM stdin; +1 Иванов Николай Владимирович 1954-10-26 male ул. Чайковского, дом 32, квартира 46 +2 Сидоров Владимир Анатольевич 1956-12-30 male пр. Мира, дом 37, квартира 47 +3 Кузнецов Пётр Сергеевич 1978-04-12 male ул. Кирова, дом 29, квартира 55 +4 Петров Иван Владимирович 2005-09-15 male ул. Чайковского, дом 16, квартира 108 +5 Иванов Николай Андреевич 1973-11-16 male ул. Молодёжная, дом 28, квартира 41 +6 Иванов Егор Сергеевич 1987-05-21 male ул. Гагарина, дом 3, квартира 92 +8 апраоплр апарспмориолтьмтич выавпасрмо 2001-11-28 Мужчина вавпраоплдожропав +7 впа апр авыпро 2005-11-28 Женщина впарплоро +\. + + +-- +-- TOC entry 5174 (class 0 OID 185853) +-- Dependencies: 262 +-- Data for Name: person_account; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.person_account (person_id, login, password) FROM stdin; +1 Иванов Н.В. $2a$06$nodiIbOsbvGGiNskCgoZve5M5ZNvf6vAUKVy9GKg2.zgt1H9ZBOoa +2 Сидоров В.А. $2a$06$46RFLNbgnecMJjhCzEWQD.90I42GPoKiQMunNKJ.sVx1jjhXcMrai +3 Кузнецов П.С. $2a$06$wN513CJW7sR/40ts3J07wuNYYm/RwAUWwiUX5jXCOL.EE1BGL0/7. +4 Петров И.В. $2a$06$zmh10qXthU9anqEX/ErdKekAeQdd2p54hozsc.VtYJIHLpRSJEmfq +5 Иванов Н.А. $2a$06$89cvKSGddsBwzXzbAWNbveEaoevnF7VIQxp1VSrvoTBuEXMZcFt6q +6 Иванов Е.С. $2a$06$JT.cB1.QUOgzZbnirrFSxO.WRNw0LvD6JvIXpHapKi5FDkO9yRily +\. + + +-- +-- TOC entry 5140 (class 0 OID 179761) +-- Dependencies: 228 +-- Data for Name: prescription; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.prescription (prescription_id, patient_id, doctor_id) FROM stdin; +2 8 1 +23 7 1 +24 7 2 +\. + + +-- +-- TOC entry 5167 (class 0 OID 180080) +-- Dependencies: 255 +-- Data for Name: procedure_type; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.procedure_type (procedure_type_id, name) FROM stdin; +3 Физиотерапия +\. + + +-- +-- TOC entry 5169 (class 0 OID 180092) +-- Dependencies: 257 +-- Data for Name: procedure_type_prescription; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.procedure_type_prescription (procedure_prescription_id, prescription_id, procedure_type_id, scheduled_datetime) FROM stdin; +3 2 3 2025-11-29 11:11:25.048055 +\. + + +-- +-- TOC entry 5148 (class 0 OID 179844) +-- Dependencies: 236 +-- Data for Name: qualitative_result; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.qualitative_result (result_id, value) FROM stdin; +5 t +\. + + +-- +-- TOC entry 5151 (class 0 OID 179869) +-- Dependencies: 239 +-- Data for Name: reference_numeric_value; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.reference_numeric_value (reference_value_id, min_value, max_value, unit_id) FROM stdin; +4 \N 1 7 +\. + + +-- +-- TOC entry 5152 (class 0 OID 179886) +-- Dependencies: 240 +-- Data for Name: reference_qualitative_value; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.reference_qualitative_value (reference_value_id, description_true, description_false) FROM stdin; +4 Отсутствует Отсутствует +\. + + +-- +-- TOC entry 5150 (class 0 OID 179855) +-- Dependencies: 238 +-- Data for Name: reference_value; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.reference_value (reference_value_id, examination_type_id, gender, age_min, age_max) FROM stdin; +4 2 Мужчина \N 18 +5 3 Женщина \N 18 +\. + + +-- +-- TOC entry 5136 (class 0 OID 179738) +-- Dependencies: 224 +-- Data for Name: registrar; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.registrar (registrar_id) FROM stdin; +4 +5 +6 +\. + + +-- +-- TOC entry 5144 (class 0 OID 179790) +-- Dependencies: 232 +-- Data for Name: result; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.result (result_id, examination_id) FROM stdin; +5 3 +7 3 +8 2 +9 3 +10 2 +\. + + +-- +-- TOC entry 5155 (class 0 OID 179914) +-- Dependencies: 243 +-- Data for Name: syndrome_examination_type; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.syndrome_examination_type (syndrome_id, examination_type_id) FROM stdin; +2 3 +\. + + +-- +-- TOC entry 5154 (class 0 OID 179903) +-- Dependencies: 242 +-- Data for Name: syndrome_type; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.syndrome_type (syndrome_type_id, name) FROM stdin; +1 Лихорадка +2 Боль в груди +\. + + +-- +-- TOC entry 5138 (class 0 OID 179749) +-- Dependencies: 226 +-- Data for Name: unit; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +COPY public.unit (unit_id, name) FROM stdin; +2 мг/л +3 г/л +4 ммоль/л +5 мкмоль/л +6 ед/л +7 % +8 тыс/мкл +9 мл +10 мм +\. + + +-- +-- TOC entry 5198 (class 0 OID 0) +-- Dependencies: 244 +-- Name: disease_disease_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.disease_disease_id_seq', 36, true); + + +-- +-- TOC entry 5199 (class 0 OID 0) +-- Dependencies: 246 +-- Name: disease_syndrome_disease_syndrome_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.disease_syndrome_disease_syndrome_id_seq', 2, true); + + +-- +-- TOC entry 5200 (class 0 OID 0) +-- Dependencies: 248 +-- Name: drug_intake_method_drug_intake_method_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.drug_intake_method_drug_intake_method_id_seq', 2, true); + + +-- +-- TOC entry 5201 (class 0 OID 0) +-- Dependencies: 250 +-- Name: drug_type_drug_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.drug_type_drug_type_id_seq', 3, true); + + +-- +-- TOC entry 5202 (class 0 OID 0) +-- Dependencies: 252 +-- Name: drug_type_prescription_drug_prescription_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.drug_type_prescription_drug_prescription_id_seq', 1, true); + + +-- +-- TOC entry 5203 (class 0 OID 0) +-- Dependencies: 229 +-- Name: examination_type_examination_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.examination_type_examination_type_id_seq', 3, true); + + +-- +-- TOC entry 5204 (class 0 OID 0) +-- Dependencies: 233 +-- Name: examination_type_prescription_examination_prescription_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.examination_type_prescription_examination_prescription_id_seq', 12, true); + + +-- +-- TOC entry 5205 (class 0 OID 0) +-- Dependencies: 258 +-- Name: hospital_admission_hospital_admission_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.hospital_admission_hospital_admission_id_seq', 31, true); + + +-- +-- TOC entry 5206 (class 0 OID 0) +-- Dependencies: 260 +-- Name: hospital_discharge_hospital_discharge_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.hospital_discharge_hospital_discharge_id_seq', 1, true); + + +-- +-- TOC entry 5207 (class 0 OID 0) +-- Dependencies: 220 +-- Name: person_person_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.person_person_id_seq', 8, true); + + +-- +-- TOC entry 5208 (class 0 OID 0) +-- Dependencies: 227 +-- Name: prescription_prescription_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.prescription_prescription_id_seq', 24, true); + + +-- +-- TOC entry 5209 (class 0 OID 0) +-- Dependencies: 256 +-- Name: procedure_type_prescription_procedure_prescription_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.procedure_type_prescription_procedure_prescription_id_seq', 7, true); + + +-- +-- TOC entry 5210 (class 0 OID 0) +-- Dependencies: 254 +-- Name: procedure_type_procedure_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.procedure_type_procedure_type_id_seq', 3, true); + + +-- +-- TOC entry 5211 (class 0 OID 0) +-- Dependencies: 237 +-- Name: reference_value_reference_value_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.reference_value_reference_value_id_seq', 5, true); + + +-- +-- TOC entry 5212 (class 0 OID 0) +-- Dependencies: 231 +-- Name: result_result_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.result_result_id_seq', 10, true); + + +-- +-- TOC entry 5213 (class 0 OID 0) +-- Dependencies: 241 +-- Name: syndrome_type_syndrome_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.syndrome_type_syndrome_type_id_seq', 2, true); + + +-- +-- TOC entry 5214 (class 0 OID 0) +-- Dependencies: 225 +-- Name: unit_unit_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres +-- + +SELECT pg_catalog.setval('public.unit_unit_id_seq', 10, true); + + +-- +-- TOC entry 4850 (class 2606 OID 180455) +-- Name: disease disease_icd_code_check; Type: CHECK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE public.disease + ADD CONSTRAINT disease_icd_code_check CHECK ((icd_code ~ '^[A-Z][0-9]{2}\.[0-9]$'::text)) NOT VALID; + + +-- +-- TOC entry 4910 (class 2606 OID 179945) +-- Name: disease disease_icd_code_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease + ADD CONSTRAINT disease_icd_code_key UNIQUE (icd_code); + + +-- +-- TOC entry 4912 (class 2606 OID 179943) +-- Name: disease disease_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease + ADD CONSTRAINT disease_name_key UNIQUE (name); + + +-- +-- TOC entry 4914 (class 2606 OID 179941) +-- Name: disease disease_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease + ADD CONSTRAINT disease_pkey PRIMARY KEY (disease_id); + + +-- +-- TOC entry 4916 (class 2606 OID 179954) +-- Name: disease_syndrome disease_syndrome_disease_id_syndrome_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease_syndrome + ADD CONSTRAINT disease_syndrome_disease_id_syndrome_id_key UNIQUE (disease_id, syndrome_id); + + +-- +-- TOC entry 4918 (class 2606 OID 179952) +-- Name: disease_syndrome disease_syndrome_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease_syndrome + ADD CONSTRAINT disease_syndrome_pkey PRIMARY KEY (disease_syndrome_id); + + +-- +-- TOC entry 4868 (class 2606 OID 179732) +-- Name: doctor doctor_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.doctor + ADD CONSTRAINT doctor_pkey PRIMARY KEY (doctor_id); + + +-- +-- TOC entry 4920 (class 2606 OID 180024) +-- Name: drug_intake_method drug_intake_method_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_intake_method + ADD CONSTRAINT drug_intake_method_name_key UNIQUE (name); + + +-- +-- TOC entry 4922 (class 2606 OID 180022) +-- Name: drug_intake_method drug_intake_method_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_intake_method + ADD CONSTRAINT drug_intake_method_pkey PRIMARY KEY (drug_intake_method_id); + + +-- +-- TOC entry 4924 (class 2606 OID 180045) +-- Name: drug_type drug_type_brand_name_ru_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type + ADD CONSTRAINT drug_type_brand_name_ru_key UNIQUE (brand_name_ru); + + +-- +-- TOC entry 4926 (class 2606 OID 180041) +-- Name: drug_type drug_type_international_name_en_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type + ADD CONSTRAINT drug_type_international_name_en_key UNIQUE (international_name_en); + + +-- +-- TOC entry 4928 (class 2606 OID 180043) +-- Name: drug_type drug_type_international_name_la_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type + ADD CONSTRAINT drug_type_international_name_la_key UNIQUE (international_name_la); + + +-- +-- TOC entry 4930 (class 2606 OID 180039) +-- Name: drug_type drug_type_international_name_ru_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type + ADD CONSTRAINT drug_type_international_name_ru_key UNIQUE (international_name_ru); + + +-- +-- TOC entry 4932 (class 2606 OID 180037) +-- Name: drug_type drug_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type + ADD CONSTRAINT drug_type_pkey PRIMARY KEY (drug_type_id); + + +-- +-- TOC entry 4934 (class 2606 OID 180056) +-- Name: drug_type_prescription drug_type_prescription_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type_prescription + ADD CONSTRAINT drug_type_prescription_pkey PRIMARY KEY (drug_prescription_id); + + +-- +-- TOC entry 4936 (class 2606 OID 180058) +-- Name: drug_type_prescription drug_type_prescription_prescription_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type_prescription + ADD CONSTRAINT drug_type_prescription_prescription_id_key UNIQUE (prescription_id); + + +-- +-- TOC entry 4878 (class 2606 OID 179788) +-- Name: examination_type examination_type_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type + ADD CONSTRAINT examination_type_name_key UNIQUE (name); + + +-- +-- TOC entry 4880 (class 2606 OID 179786) +-- Name: examination_type examination_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type + ADD CONSTRAINT examination_type_pkey PRIMARY KEY (examination_type_id); + + +-- +-- TOC entry 4884 (class 2606 OID 179809) +-- Name: examination_type_prescription examination_type_prescription_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type_prescription + ADD CONSTRAINT examination_type_prescription_pkey PRIMARY KEY (examination_prescription_id); + + +-- +-- TOC entry 4886 (class 2606 OID 179811) +-- Name: examination_type_prescription examination_type_prescription_prescription_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type_prescription + ADD CONSTRAINT examination_type_prescription_prescription_id_key UNIQUE (prescription_id); + + +-- +-- TOC entry 4946 (class 2606 OID 185818) +-- Name: hospital_admission hospital_admission_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.hospital_admission + ADD CONSTRAINT hospital_admission_pkey PRIMARY KEY (hospital_admission_id); + + +-- +-- TOC entry 4948 (class 2606 OID 185838) +-- Name: hospital_discharge hospital_discharge_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.hospital_discharge + ADD CONSTRAINT hospital_discharge_pkey PRIMARY KEY (hospital_discharge_id); + + +-- +-- TOC entry 4888 (class 2606 OID 179833) +-- Name: numeric_result numeric_result_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.numeric_result + ADD CONSTRAINT numeric_result_pkey PRIMARY KEY (result_id); + + +-- +-- TOC entry 4866 (class 2606 OID 179722) +-- Name: patient patient_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.patient + ADD CONSTRAINT patient_pkey PRIMARY KEY (patient_id); + + +-- +-- TOC entry 4950 (class 2606 OID 185860) +-- Name: person_account person_account_person_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.person_account + ADD CONSTRAINT person_account_person_id_key UNIQUE (person_id); + + +-- +-- TOC entry 4864 (class 2606 OID 179714) +-- Name: person person_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.person + ADD CONSTRAINT person_pkey PRIMARY KEY (person_id); + + +-- +-- TOC entry 4876 (class 2606 OID 179766) +-- Name: prescription prescription_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.prescription + ADD CONSTRAINT prescription_pkey PRIMARY KEY (prescription_id); + + +-- +-- TOC entry 4938 (class 2606 OID 180090) +-- Name: procedure_type procedure_type_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.procedure_type + ADD CONSTRAINT procedure_type_name_key UNIQUE (name); + + +-- +-- TOC entry 4940 (class 2606 OID 180088) +-- Name: procedure_type procedure_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.procedure_type + ADD CONSTRAINT procedure_type_pkey PRIMARY KEY (procedure_type_id); + + +-- +-- TOC entry 4942 (class 2606 OID 180097) +-- Name: procedure_type_prescription procedure_type_prescription_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.procedure_type_prescription + ADD CONSTRAINT procedure_type_prescription_pkey PRIMARY KEY (procedure_prescription_id); + + +-- +-- TOC entry 4944 (class 2606 OID 180099) +-- Name: procedure_type_prescription procedure_type_prescription_prescription_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.procedure_type_prescription + ADD CONSTRAINT procedure_type_prescription_prescription_id_key UNIQUE (prescription_id); + + +-- +-- TOC entry 4890 (class 2606 OID 179848) +-- Name: qualitative_result qualitative_result_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.qualitative_result + ADD CONSTRAINT qualitative_result_pkey PRIMARY KEY (result_id); + + +-- +-- TOC entry 4896 (class 2606 OID 179875) +-- Name: reference_numeric_value reference_numeric_value_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_numeric_value + ADD CONSTRAINT reference_numeric_value_pkey PRIMARY KEY (reference_value_id); + + +-- +-- TOC entry 4898 (class 2606 OID 179896) +-- Name: reference_qualitative_value reference_qualitative_value_description_true_description_fa_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_qualitative_value + ADD CONSTRAINT reference_qualitative_value_description_true_description_fa_key UNIQUE (description_true, description_false); + + +-- +-- TOC entry 4900 (class 2606 OID 179894) +-- Name: reference_qualitative_value reference_qualitative_value_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_qualitative_value + ADD CONSTRAINT reference_qualitative_value_pkey PRIMARY KEY (reference_value_id); + + +-- +-- TOC entry 4892 (class 2606 OID 185773) +-- Name: reference_value reference_value_examination_type_id_gender_age_min_age_max_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_value + ADD CONSTRAINT reference_value_examination_type_id_gender_age_min_age_max_key UNIQUE (examination_type_id, gender, age_min, age_max); + + +-- +-- TOC entry 4894 (class 2606 OID 179861) +-- Name: reference_value reference_value_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_value + ADD CONSTRAINT reference_value_pkey PRIMARY KEY (reference_value_id); + + +-- +-- TOC entry 4870 (class 2606 OID 179742) +-- Name: registrar registrar_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.registrar + ADD CONSTRAINT registrar_pkey PRIMARY KEY (registrar_id); + + +-- +-- TOC entry 4882 (class 2606 OID 179795) +-- Name: result result_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.result + ADD CONSTRAINT result_pkey PRIMARY KEY (result_id); + + +-- +-- TOC entry 4906 (class 2606 OID 179920) +-- Name: syndrome_examination_type syndrome_examination_type_examination_type_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.syndrome_examination_type + ADD CONSTRAINT syndrome_examination_type_examination_type_id_key UNIQUE (examination_type_id); + + +-- +-- TOC entry 4908 (class 2606 OID 179918) +-- Name: syndrome_examination_type syndrome_examination_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.syndrome_examination_type + ADD CONSTRAINT syndrome_examination_type_pkey PRIMARY KEY (syndrome_id); + + +-- +-- TOC entry 4902 (class 2606 OID 179913) +-- Name: syndrome_type syndrome_type_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.syndrome_type + ADD CONSTRAINT syndrome_type_name_key UNIQUE (name); + + +-- +-- TOC entry 4904 (class 2606 OID 179911) +-- Name: syndrome_type syndrome_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.syndrome_type + ADD CONSTRAINT syndrome_type_pkey PRIMARY KEY (syndrome_type_id); + + +-- +-- TOC entry 4872 (class 2606 OID 179759) +-- Name: unit unit_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.unit + ADD CONSTRAINT unit_name_key UNIQUE (name); + + +-- +-- TOC entry 4874 (class 2606 OID 179757) +-- Name: unit unit_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.unit + ADD CONSTRAINT unit_pkey PRIMARY KEY (unit_id); + + +-- +-- TOC entry 4984 (class 2620 OID 185849) +-- Name: hospital_admission trg_check_active_hospitalization; Type: TRIGGER; Schema: public; Owner: postgres +-- + +CREATE TRIGGER trg_check_active_hospitalization BEFORE INSERT ON public.hospital_admission FOR EACH ROW EXECUTE FUNCTION public.check_active_hospitalization(); + + +-- +-- TOC entry 4986 (class 2620 OID 185851) +-- Name: hospital_discharge trg_check_discharge_after_admission; Type: TRIGGER; Schema: public; Owner: postgres +-- + +CREATE TRIGGER trg_check_discharge_after_admission BEFORE INSERT OR UPDATE ON public.hospital_discharge FOR EACH ROW EXECUTE FUNCTION public.check_discharge_after_admission(); + + +-- +-- TOC entry 4985 (class 2620 OID 185850) +-- Name: hospital_admission trg_check_hospitalization_overlap; Type: TRIGGER; Schema: public; Owner: postgres +-- + +CREATE TRIGGER trg_check_hospitalization_overlap BEFORE INSERT ON public.hospital_admission FOR EACH ROW EXECUTE FUNCTION public.check_hospitalization_overlap(); + + +-- +-- TOC entry 4982 (class 2620 OID 180121) +-- Name: numeric_result trg_check_numeric_result_uniqueness; Type: TRIGGER; Schema: public; Owner: postgres +-- + +CREATE TRIGGER trg_check_numeric_result_uniqueness BEFORE INSERT OR UPDATE ON public.numeric_result FOR EACH ROW EXECUTE FUNCTION public.check_numeric_result_uniqueness(); + + +-- +-- TOC entry 4983 (class 2620 OID 180123) +-- Name: qualitative_result trg_check_qualitative_result_uniqueness; Type: TRIGGER; Schema: public; Owner: postgres +-- + +CREATE TRIGGER trg_check_qualitative_result_uniqueness BEFORE INSERT OR UPDATE ON public.qualitative_result FOR EACH ROW EXECUTE FUNCTION public.check_qualitative_result_uniqueness(); + + +-- +-- TOC entry 4987 (class 2620 OID 185852) +-- Name: hospital_discharge trg_check_unique_discharge; Type: TRIGGER; Schema: public; Owner: postgres +-- + +CREATE TRIGGER trg_check_unique_discharge BEFORE INSERT OR UPDATE ON public.hospital_discharge FOR EACH ROW EXECUTE FUNCTION public.check_unique_discharge(); + + +-- +-- TOC entry 4988 (class 2620 OID 185868) +-- Name: person_account trigger_create_account; Type: TRIGGER; Schema: public; Owner: postgres +-- + +CREATE TRIGGER trigger_create_account BEFORE INSERT ON public.person_account FOR EACH ROW EXECUTE FUNCTION public.create_person_account(); + + +-- +-- TOC entry 4969 (class 2606 OID 179955) +-- Name: disease_syndrome disease_syndrome_disease_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease_syndrome + ADD CONSTRAINT disease_syndrome_disease_id_fkey FOREIGN KEY (disease_id) REFERENCES public.disease(disease_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4970 (class 2606 OID 179960) +-- Name: disease_syndrome disease_syndrome_syndrome_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.disease_syndrome + ADD CONSTRAINT disease_syndrome_syndrome_id_fkey FOREIGN KEY (syndrome_id) REFERENCES public.syndrome_type(syndrome_type_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4952 (class 2606 OID 179733) +-- Name: doctor doctor_doctor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.doctor + ADD CONSTRAINT doctor_doctor_id_fkey FOREIGN KEY (doctor_id) REFERENCES public.person(person_id); + + +-- +-- TOC entry 4971 (class 2606 OID 180069) +-- Name: drug_type_prescription drug_type_prescription_dose_unit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type_prescription + ADD CONSTRAINT drug_type_prescription_dose_unit_id_fkey FOREIGN KEY (dose_unit_id) REFERENCES public.unit(unit_id) ON DELETE RESTRICT; + + +-- +-- TOC entry 4972 (class 2606 OID 180064) +-- Name: drug_type_prescription drug_type_prescription_drug_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type_prescription + ADD CONSTRAINT drug_type_prescription_drug_type_id_fkey FOREIGN KEY (drug_type_id) REFERENCES public.drug_type(drug_type_id) ON DELETE RESTRICT; + + +-- +-- TOC entry 4973 (class 2606 OID 180074) +-- Name: drug_type_prescription drug_type_prescription_intake_method_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type_prescription + ADD CONSTRAINT drug_type_prescription_intake_method_id_fkey FOREIGN KEY (intake_method_id) REFERENCES public.drug_intake_method(drug_intake_method_id) ON DELETE RESTRICT; + + +-- +-- TOC entry 4974 (class 2606 OID 180059) +-- Name: drug_type_prescription drug_type_prescription_prescription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.drug_type_prescription + ADD CONSTRAINT drug_type_prescription_prescription_id_fkey FOREIGN KEY (prescription_id) REFERENCES public.prescription(prescription_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4957 (class 2606 OID 179822) +-- Name: examination_type_prescription examination_type_prescription_examination_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type_prescription + ADD CONSTRAINT examination_type_prescription_examination_type_id_fkey FOREIGN KEY (examination_type_id) REFERENCES public.examination_type(examination_type_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4958 (class 2606 OID 179812) +-- Name: examination_type_prescription examination_type_prescription_prescription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type_prescription + ADD CONSTRAINT examination_type_prescription_prescription_id_fkey FOREIGN KEY (prescription_id) REFERENCES public.prescription(prescription_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4959 (class 2606 OID 179817) +-- Name: examination_type_prescription examination_type_prescription_result_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.examination_type_prescription + ADD CONSTRAINT examination_type_prescription_result_id_fkey FOREIGN KEY (result_id) REFERENCES public.result(result_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4977 (class 2606 OID 185819) +-- Name: hospital_admission hospital_admission_patient_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.hospital_admission + ADD CONSTRAINT hospital_admission_patient_id_fkey FOREIGN KEY (patient_id) REFERENCES public.patient(patient_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4978 (class 2606 OID 185824) +-- Name: hospital_admission hospital_admission_preliminary_disease_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.hospital_admission + ADD CONSTRAINT hospital_admission_preliminary_disease_id_fkey FOREIGN KEY (preliminary_disease_id) REFERENCES public.disease(disease_id); + + +-- +-- TOC entry 4979 (class 2606 OID 185844) +-- Name: hospital_discharge hospital_discharge_final_disease_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.hospital_discharge + ADD CONSTRAINT hospital_discharge_final_disease_id_fkey FOREIGN KEY (final_disease_id) REFERENCES public.disease(disease_id); + + +-- +-- TOC entry 4980 (class 2606 OID 185839) +-- Name: hospital_discharge hospital_discharge_hospital_admission_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.hospital_discharge + ADD CONSTRAINT hospital_discharge_hospital_admission_id_fkey FOREIGN KEY (hospital_admission_id) REFERENCES public.hospital_admission(hospital_admission_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4960 (class 2606 OID 180445) +-- Name: numeric_result numeric_result_result_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.numeric_result + ADD CONSTRAINT numeric_result_result_id_fkey FOREIGN KEY (result_id) REFERENCES public.result(result_id) NOT VALID; + + +-- +-- TOC entry 4961 (class 2606 OID 179839) +-- Name: numeric_result numeric_result_unit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.numeric_result + ADD CONSTRAINT numeric_result_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES public.unit(unit_id) ON DELETE RESTRICT; + + +-- +-- TOC entry 4951 (class 2606 OID 179723) +-- Name: patient patient_patient_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.patient + ADD CONSTRAINT patient_patient_id_fkey FOREIGN KEY (patient_id) REFERENCES public.person(person_id); + + +-- +-- TOC entry 4981 (class 2606 OID 185861) +-- Name: person_account person_account_person_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.person_account + ADD CONSTRAINT person_account_person_id_fkey FOREIGN KEY (person_id) REFERENCES public.person(person_id); + + +-- +-- TOC entry 4954 (class 2606 OID 179772) +-- Name: prescription prescription_doctor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.prescription + ADD CONSTRAINT prescription_doctor_id_fkey FOREIGN KEY (doctor_id) REFERENCES public.doctor(doctor_id) ON DELETE RESTRICT; + + +-- +-- TOC entry 4955 (class 2606 OID 179767) +-- Name: prescription prescription_patient_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.prescription + ADD CONSTRAINT prescription_patient_id_fkey FOREIGN KEY (patient_id) REFERENCES public.patient(patient_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4975 (class 2606 OID 180100) +-- Name: procedure_type_prescription procedure_type_prescription_prescription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.procedure_type_prescription + ADD CONSTRAINT procedure_type_prescription_prescription_id_fkey FOREIGN KEY (prescription_id) REFERENCES public.prescription(prescription_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4976 (class 2606 OID 180105) +-- Name: procedure_type_prescription procedure_type_prescription_procedure_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.procedure_type_prescription + ADD CONSTRAINT procedure_type_prescription_procedure_type_id_fkey FOREIGN KEY (procedure_type_id) REFERENCES public.procedure_type(procedure_type_id) ON DELETE RESTRICT; + + +-- +-- TOC entry 4962 (class 2606 OID 180450) +-- Name: qualitative_result qualitative_result_result_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.qualitative_result + ADD CONSTRAINT qualitative_result_result_id_fkey FOREIGN KEY (result_id) REFERENCES public.result(result_id) NOT VALID; + + +-- +-- TOC entry 4964 (class 2606 OID 179876) +-- Name: reference_numeric_value reference_numeric_value_reference_value_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_numeric_value + ADD CONSTRAINT reference_numeric_value_reference_value_id_fkey FOREIGN KEY (reference_value_id) REFERENCES public.reference_value(reference_value_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4965 (class 2606 OID 179881) +-- Name: reference_numeric_value reference_numeric_value_unit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_numeric_value + ADD CONSTRAINT reference_numeric_value_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES public.unit(unit_id) ON DELETE RESTRICT; + + +-- +-- TOC entry 4966 (class 2606 OID 179897) +-- Name: reference_qualitative_value reference_qualitative_value_reference_value_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_qualitative_value + ADD CONSTRAINT reference_qualitative_value_reference_value_id_fkey FOREIGN KEY (reference_value_id) REFERENCES public.reference_value(reference_value_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4963 (class 2606 OID 179864) +-- Name: reference_value reference_value_examination_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.reference_value + ADD CONSTRAINT reference_value_examination_type_id_fkey FOREIGN KEY (examination_type_id) REFERENCES public.examination_type(examination_type_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4953 (class 2606 OID 179743) +-- Name: registrar registrar_registrar_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.registrar + ADD CONSTRAINT registrar_registrar_id_fkey FOREIGN KEY (registrar_id) REFERENCES public.person(person_id); + + +-- +-- TOC entry 4956 (class 2606 OID 179798) +-- Name: result result_examination_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.result + ADD CONSTRAINT result_examination_id_fkey FOREIGN KEY (examination_id) REFERENCES public.examination_type(examination_type_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4967 (class 2606 OID 179926) +-- Name: syndrome_examination_type syndrome_examination_type_examination_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.syndrome_examination_type + ADD CONSTRAINT syndrome_examination_type_examination_type_id_fkey FOREIGN KEY (examination_type_id) REFERENCES public.examination_type(examination_type_id) ON DELETE CASCADE; + + +-- +-- TOC entry 4968 (class 2606 OID 179921) +-- Name: syndrome_examination_type syndrome_examination_type_syndrome_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.syndrome_examination_type + ADD CONSTRAINT syndrome_examination_type_syndrome_id_fkey FOREIGN KEY (syndrome_id) REFERENCES public.syndrome_type(syndrome_type_id) ON DELETE CASCADE; + + +-- Completed on 2025-12-01 18:47:43 + +-- +-- PostgreSQL database dump complete +-- + diff --git a/migrations/backup_tar.sql b/migrations/backup_tar.sql new file mode 100644 index 0000000..12a8651 Binary files /dev/null and b/migrations/backup_tar.sql differ diff --git a/migrations/copy_from_csv.sql b/migrations/copy_from_csv.sql new file mode 100644 index 0000000..411f34a --- /dev/null +++ b/migrations/copy_from_csv.sql @@ -0,0 +1,3 @@ +TRUNCATE TABLE units RESTART IDENTITY CASCADE; + +\copy units(name) FROM 'csv/units.csv' WITH (FORMAT csv, HEADER); diff --git a/migrations/csv/female_first_names.csv b/migrations/csv/female_first_names.csv new file mode 100644 index 0000000..d26a90c --- /dev/null +++ b/migrations/csv/female_first_names.csv @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/migrations/csv/female_last_names.csv b/migrations/csv/female_last_names.csv new file mode 100644 index 0000000..d3b0089 --- /dev/null +++ b/migrations/csv/female_last_names.csv @@ -0,0 +1,10 @@ + + + + + + + + +Ը + diff --git a/migrations/csv/female_middle_names.csv b/migrations/csv/female_middle_names.csv new file mode 100644 index 0000000..3c8516f --- /dev/null +++ b/migrations/csv/female_middle_names.csv @@ -0,0 +1,10 @@ + + + + + + +Ը + + + diff --git a/migrations/csv/male_first_names.csv b/migrations/csv/male_first_names.csv new file mode 100644 index 0000000..559afe9 --- /dev/null +++ b/migrations/csv/male_first_names.csv @@ -0,0 +1,10 @@ + + +ϸ + + + + + + + diff --git a/migrations/csv/male_last_names.csv b/migrations/csv/male_last_names.csv new file mode 100644 index 0000000..dadd04a --- /dev/null +++ b/migrations/csv/male_last_names.csv @@ -0,0 +1,10 @@ + + + + + + + + +Ը + diff --git a/migrations/csv/male_middle_names.csv b/migrations/csv/male_middle_names.csv new file mode 100644 index 0000000..fee232d --- /dev/null +++ b/migrations/csv/male_middle_names.csv @@ -0,0 +1,10 @@ + + + + + + +Ը + + + diff --git a/migrations/csv/streets.csv b/migrations/csv/streets.csv new file mode 100644 index 0000000..6bcac85 --- /dev/null +++ b/migrations/csv/streets.csv @@ -0,0 +1,10 @@ +. +. +. +. +. +. +. +. +. +. diff --git a/migrations/csv/units.csv b/migrations/csv/units.csv new file mode 100644 index 0000000..e454a32 --- /dev/null +++ b/migrations/csv/units.csv @@ -0,0 +1,10 @@ +name +мг/л +г/л +ммоль/л +мкмоль/л +ед/л +% +тыс/мкл +мл +мм \ No newline at end of file diff --git a/migrations/functions.sql b/migrations/functions.sql new file mode 100644 index 0000000..10c8759 --- /dev/null +++ b/migrations/functions.sql @@ -0,0 +1,72 @@ +-- Функция: нет двойных пробелов подряд +CREATE OR REPLACE FUNCTION no_double_space (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str !~ E'\s{2,}'; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: нет пробелов в начале и конце строки +CREATE OR REPLACE FUNCTION no_space_start_end (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str !~ E'^\s' + AND str !~ E'\s$'; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: нет пробелов вообще +CREATE OR REPLACE FUNCTION no_space (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str !~ E'\s'; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: длина строки в заданных границах +CREATE OR REPLACE FUNCTION str_length_between (str text, min_len int, max_len int) + RETURNS boolean + AS $$ +BEGIN + RETURN LENGTH(str) BETWEEN min_len AND max_len; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: стандартная проверка для слова +CREATE OR REPLACE FUNCTION default_word_check (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str IS NULL + OR no_space (str) + AND str_length_between (str, 1, 64); +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Функция: стандартная проверка для строки +CREATE OR REPLACE FUNCTION default_str_check (str text) + RETURNS boolean + AS $$ +BEGIN + RETURN str IS NULL + OR no_double_space (str) + AND no_space_start_end (str) + AND str_length_between (str, 1, 128); +END; +$$ +LANGUAGE plpgsql +IMMUTABLE; + diff --git a/migrations/insert_persons.sql b/migrations/insert_persons.sql new file mode 100644 index 0000000..0bc876d --- /dev/null +++ b/migrations/insert_persons.sql @@ -0,0 +1,134 @@ +-- Генерация целочисленного значения в диапазоне +CREATE OR REPLACE FUNCTION random_int (min_val int, max_val int) + RETURNS int + AS $$ +BEGIN + RETURN min_val + trunc(random() * (max_val - min_val + 1))::int; +END; +$$ +LANGUAGE plpgsql +VOLATILE; + +-- Генерация даты рождения в диапазоне +CREATE OR REPLACE FUNCTION random_date () + RETURNS date + AS $$ +DECLARE + from_date date := '1950-01-01'; + to_date date := '2010-12-31'; +BEGIN + RETURN from_date + random_int (0, to_date - from_date); +END; +$$ +LANGUAGE plpgsql +VOLATILE; + +-- Генерация адреса проживания +CREATE OR REPLACE FUNCTION random_address (street text) + RETURNS text + AS $$ +BEGIN + RETURN street || ', дом ' || random_int (1, 40) || ', квартира ' || random_int (40, 120); +END; +$$ +LANGUAGE plpgsql +VOLATILE; + +-- --- Подготовленные общие данные --- +CREATE TEMP TABLE streets ( + street text +); + +\copy streets FROM 'csv/streets.csv' (FORMAT csv); +-- --- Подготовленные данные для генерации мужских записей --- +CREATE TEMP TABLE male_last_names ( + last_name text +); + +\copy male_last_names FROM 'csv/male_last_names.csv' (FORMAT csv); +CREATE TEMP TABLE male_first_names ( + first_name text +); + +\copy male_first_names FROM 'csv/male_first_names.csv' (FORMAT csv); +CREATE TEMP TABLE male_middle_names ( + middle_name text +); + +\copy male_middle_names FROM 'csv/male_middle_names.csv' (FORMAT csv); +-- Подготовленные данные для генерации женских записей +CREATE TEMP TABLE female_last_names ( + last_name text +); + +\copy female_last_names FROM 'csv/female_last_names.csv' (FORMAT csv); +CREATE TEMP TABLE female_first_names ( + first_name text +); + +\copy female_first_names FROM 'csv/female_first_names.csv' (FORMAT csv); +CREATE TEMP TABLE female_middle_names ( + middle_name text +); + +\copy female_middle_names FROM 'csv/female_middle_names.csv' (FORMAT csv); +-- Генерация -- +-- Удаление старых данных +TRUNCATE TABLE persons RESTART IDENTITY CASCADE; + +-- Генерация записей +INSERT INTO persons (last_name, first_name, middle_name, birth_date, gender, address) +SELECT + last_name, + first_name, + middle_name, + random_date (), + gender_enum, + random_address (street) +FROM ( + -- Мужские записи + SELECT + ml.last_name, + mf.first_name, + mm.middle_name, + 'male'::gender_enum, + s.street + FROM + male_last_names ml + CROSS JOIN male_first_names mf + CROSS JOIN male_middle_names mm + CROSS JOIN streets s +UNION ALL +-- Женские записи +SELECT + fl.last_name, + ff.first_name, + fm.middle_name, + 'female'::gender_enum, + s.street +FROM + female_last_names fl + CROSS JOIN female_first_names ff + CROSS JOIN female_middle_names fm + CROSS JOIN streets s) all_people +ORDER BY + random(); + +DROP TABLE IF EXISTS streets; + +DROP TABLE IF EXISTS male_last_names; + +DROP TABLE IF EXISTS male_first_names; + +DROP TABLE IF EXISTS male_middle_names; + +DROP TABLE IF EXISTS female_last_names; + +DROP TABLE IF EXISTS female_first_names; + +DROP TABLE IF EXISTS female_middle_names; + +DROP FUNCTION IF EXISTS random_date (); + +DROP FUNCTION IF EXISTS random_address (TEXT); + diff --git a/migrations/reports.sql b/migrations/reports.sql new file mode 100644 index 0000000..008bfe4 --- /dev/null +++ b/migrations/reports.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE FUNCTION get_results() +RETURNS TABLE ("Пациент" text, "Обследование" text, "Результат" varchar) +AS $$ +BEGIN + RETURN QUERY(SELECT pa.policy_number, et.name, COALESCE(qr.value::varchar, CONCAT(nr.value || ' ' || u.name)) + FROM patient pa + LEFT JOIN prescription pr + ON pa.patient_id = pr.patient_id + LEFT JOIN examination_type_prescription etp + ON pr.prescription_id = etp.prescription_id + LEFT JOIN examination_type et + ON et.examination_type_id = etp.examination_type_id + LEFT JOIN result r + ON etp.result_id = r.result_id + LEFT JOIN qualitative_result qr + ON r.result_id = qr.result_id + LEFT JOIN numeric_result nr + ON r.result_id = nr.result_id + LEFT JOIN unit u + ON nr.unit_id = u.unit_id + WHERE et.name IS NOT NULL); +END; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/migrations/tables.sql b/migrations/tables.sql new file mode 100644 index 0000000..2aa4a67 --- /dev/null +++ b/migrations/tables.sql @@ -0,0 +1,286 @@ +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Люди +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник людей +CREATE TABLE person ( + person_id serial PRIMARY KEY, + -- фамилия + last_name text NOT NULL CHECK (default_word_check (last_name)), + -- имя + first_name text NOT NULL CHECK (default_word_check (first_name)), + -- отчество + middle_name text CHECK (default_word_check (middle_name)), + -- дата рождения + birth_date date NOT NULL CHECK (birth_date <= CURRENT_DATE), + -- пол + gender string NOT NULL, + -- место жительства + address text NOT NULL CHECK (default_str_check (address)) +); + +-- Справочник пациентов +CREATE TABLE patient ( + patient_id int PRIMARY KEY REFERENCES person (person_id), + policy_number text NOT NULL CHECK (policy_number ~ '^[0-9]{16}$') +); + +-- Справочник врачей +CREATE TABLE doctor ( + doctor_id int PRIMARY KEY REFERENCES person (person_id) +); + +CREATE TABLE registrar ( + registrar_id int PRIMARY KEY REFERENCES person (person_id) +); + +-- Справочник единиц измерения для числовых результатов +CREATE TABLE unit ( + unit_id serial PRIMARY KEY, + name text NOT NULL CHECK (name ~ '^[а-яА-ЯёЁ%^/]+$' AND str_length_between (name, 1, 16)), + UNIQUE (name) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Назначения +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Базовая таблица назначения (TPT) +CREATE TABLE prescription ( + prescription_id serial PRIMARY KEY, + -- пациент + patient_id int NOT NULL REFERENCES patient (patient_id) ON DELETE CASCADE, + -- врач + doctor_id int NOT NULL REFERENCES doctor (doctor_id) ON DELETE RESTRICT +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Обследования +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник типов обследований (Общий анализ крови", "ЭКГ", "УЗИ печени") +CREATE TABLE examination_type ( + examination_type_id serial PRIMARY KEY, + -- название типа обследования (одно слово, без пробелов) + name text NOT NULL CHECK (default_word_check (name)), + -- категория обследования + category text NOT NULL, + UNIQUE (name) +); + +-- Общая таблица результатов обследований (TPT) +CREATE TABLE result ( + result_id serial PRIMARY KEY, + examination_id int NOT NULL REFERENCES examination_type (examination_type_id) ON DELETE CASCADE, +); + +-- Журнал фактических обследований пациентов +CREATE TABLE examination_type_prescription ( + examination_prescription_id serial PRIMARY KEY, + prescription_id int NOT NULL REFERENCES prescription (prescription_id) ON DELETE CASCADE, + result_id int REFERENCES result (result_id) ON DELETE CASCADE, + -- тип обследования + examination_type_id int NOT NULL REFERENCES examination_type (examination_type_id) ON DELETE CASCADE, + UNIQUE (prescription_id) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Фактические результаты обследований +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- + +-- Числовой результат обследования пациента (только один на обследование) +CREATE TABLE numeric_result ( + -- обследование пациента + result_id int PRIMARY KEY REFERENCES result (result_id) ON DELETE CASCADE, + -- значение результата + value numeric NOT NULL, + -- единица измерения + unit_id int NOT NULL REFERENCES unit (unit_id) ON DELETE RESTRICT +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Нормальные результаты обследований +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Качественный результат обследования пациента (только один на обследование) +CREATE TABLE qualitative_result ( + -- обследование пациента + result_id int PRIMARY KEY REFERENCES result (result_id) ON DELETE CASCADE, + -- признак отклонения + value boolean NOT NULL +); + +-- Общая таблица для справочника референсных (нормальных) значений (TPT) +CREATE TABLE reference_value ( + reference_value_id serial PRIMARY KEY, + examination_type_id int NOT NULL REFERENCES examination_type (examination_type_id) ON DELETE CASCADE, + gender text, -- пол (если норма специфична) + age_min int, -- нижняя граница возраста (если есть зависимость) + age_max int, -- верхняя граница возраста (если есть зависимость) + CHECK ( + (age_min IS NULL OR age_max IS NULL) -- если один из параметров не задан, не сравниваем + OR (age_min < age_max) -- если оба заданы, min < max + ), + UNIQUE (examination_type_id, gender, age_min, age_max) +); + +-- Справочник референсных (нормальных) значений для числовых обследований +CREATE TABLE reference_numeric_value ( + reference_value_id int PRIMARY KEY REFERENCES reference_value (reference_value_id) ON DELETE CASCADE, + min_value numeric, + max_value numeric, + unit_id int NOT NULL REFERENCES unit (unit_id) ON DELETE RESTRICT +); + +-- Справочник референсных (нормальных) значений для качественных обследований +CREATE TABLE reference_qualitative_value ( + reference_value_id int PRIMARY KEY REFERENCES reference_value (reference_value_id) ON DELETE CASCADE, + description_true text NOT NULL CHECK (default_word_check (description_true)), + description_false text NOT NULL CHECK (default_word_check (description_false)), + UNIQUE (description_true, description_false) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Синдромы +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник синдромов +CREATE TABLE syndrome_type ( + syndrome_type_id serial PRIMARY KEY, + name text NOT NULL CHECK (default_word_check (name)), + UNIQUE (name) +); + +-- Соответствие синдромов и типов обследований (определяет, какое обследование позволяет определить синдром) +CREATE TABLE syndrome_examination_type ( + syndrome_id int PRIMARY KEY REFERENCES syndrome_type (syndrome_type_id) ON DELETE CASCADE, + examination_type_id int NOT NULL REFERENCES examination_type (examination_type_id) ON DELETE CASCADE, + UNIQUE (examination_type_id) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Болезни и диагнозы +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник заболеваний +CREATE TABLE disease ( + disease_id serial PRIMARY KEY, + -- русское наименование + name text NOT NULL CHECK (default_str_check (name)), + -- код МКБ в формате A12.3 + icd_code text NOT NULL CHECK (icd_code ~ '^[A-Z][0-9]{2}\.[0-9]$'), + UNIQUE (name), + UNIQUE (icd_code) +); + +-- Соответствие заболеваний и синдромов +CREATE TABLE disease_syndrome ( + disease_syndrome_id SERIAL PRIMARY KEY, + disease_id int NOT NULL REFERENCES disease (disease_id) ON DELETE CASCADE, + syndrome_id int NOT NULL REFERENCES syndrome_type (syndrome_type_id) ON DELETE CASCADE, + UNIQUE (disease_id, syndrome_id) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Госпитализация +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Госпитализация (начало) +CREATE TABLE hospital_admission ( + hospital_admission_id serial PRIMARY KEY, + -- пациент + patient_id int NOT NULL REFERENCES patient (patient_id) ON DELETE CASCADE, + -- предварительный диагноз + preliminary_disease_id int NOT NULL REFERENCES disease (disease_id), + -- дата и время поступления + admission_datetime timestamp NOT NULL CHECK (admission_datetime <= CURRENT_TIMESTAMP) +); + +-- Завершение госпитализации +CREATE TABLE hospital_discharge ( + hospital_discharge_id serial PRIMARY KEY, + hospital_admission_id int NOT NULL REFERENCES hospital_admission (hospital_admission_id) ON DELETE CASCADE, + -- дата и время выписки/смерти + discharge_datetime timestamp NOT NULL CHECK (discharge_datetime <= CURRENT_TIMESTAMP), + final_disease_id int NOT NULL REFERENCES disease (disease_id), + -- причина завершения + reason text NOT NULL +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Лекарства +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник способов приёма лекарств +CREATE TABLE drug_intake_method ( + drug_intake_method_id serial PRIMARY KEY, + -- наименование способа (например, "перорально", "внутримышечно", "внутривенно", "ингаляционно", "ректально") + name text NOT NULL CHECK (default_word_check (name)), + UNIQUE (name) +); + +-- Справочник лекарств +CREATE TABLE drug_type ( + drug_type_id serial PRIMARY KEY, + international_name_ru text NOT NULL CHECK (default_word_check (international_name_ru)), + international_name_en text CHECK (default_word_check (international_name_en)), + international_name_la text CHECK (default_word_check (international_name_la)), + brand_name_ru text CHECK (default_word_check (brand_name_ru)), + UNIQUE (international_name_ru), + UNIQUE (international_name_en), + UNIQUE (international_name_la), + UNIQUE (brand_name_ru) +); + +-- Журнал фактических назначений лекарств пациенту +CREATE TABLE drug_type_prescription ( + drug_prescription_id serial PRIMARY KEY, + prescription_id int NOT NULL REFERENCES prescription (prescription_id) ON DELETE CASCADE, + drug_type_id int NOT NULL REFERENCES drug_type (drug_type_id) ON DELETE RESTRICT, + -- количество вещества за приём + dose numeric NOT NULL CHECK (dose > 0), + -- единица измерения дозы + dose_unit_id int NOT NULL REFERENCES unit (unit_id) ON DELETE RESTRICT, + -- способ приёма + intake_method_id int NOT NULL REFERENCES drug_intake_method (drug_intake_method_id) ON DELETE RESTRICT, + -- длительность приёма (в днях) + duration_days int NOT NULL CHECK (duration_days > 0), + UNIQUE (prescription_id) +); + +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- Процедуры (для пациента) +-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = +-- +-- Справочник типов процедур +CREATE TABLE procedure_type ( + procedure_type_id serial PRIMARY KEY, + -- наименование процедуры (например, "физиотерапия") + name text NOT NULL CHECK (default_word_check (name)), + UNIQUE (name) +); + +-- Журнал фактических назначений процедур пациенту +CREATE TABLE procedure_type_prescription ( + procedure_prescription_id serial PRIMARY KEY, + prescription_id int NOT NULL REFERENCES prescription (prescription_id) ON DELETE CASCADE, + procedure_type_id int NOT NULL REFERENCES procedure_type (procedure_type_id) ON DELETE RESTRICT, + scheduled_datetime timestamp NOT NULL, + UNIQUE (prescription_id) +); + + + + + + +insert into doctor (doctor_id) +values (1), + (2), + (3); + +insert into registrar (registrar_id) +values (4), + (5), + (6); \ No newline at end of file diff --git a/migrations/triggers_hospital_admission.sql b/migrations/triggers_hospital_admission.sql new file mode 100644 index 0000000..8b3ca5e --- /dev/null +++ b/migrations/triggers_hospital_admission.sql @@ -0,0 +1,82 @@ +-- Общая функция возвращения всех госпитализаций и периодов пациента +CREATE OR REPLACE FUNCTION get_hospitalization_periods (p_patient_id int) + RETURNS TABLE ( + admission_datetime timestamp, + discharge_datetime timestamp + ) + AS $$ +BEGIN + RETURN QUERY + SELECT + ha.admission_datetime, + hd.discharge_datetime + FROM + hospital_admission ha + LEFT JOIN hospital_discharge hd ON ha.hospital_admission_id = hd.hospital_admission_id +WHERE + ha.patient_id = p_patient_id; +END; +$$ +LANGUAGE plpgsql; + +-- Триггер: запрещает новую госпитализацию при наличии незавершённой +CREATE OR REPLACE FUNCTION check_active_hospitalization () + RETURNS TRIGGER + AS $$ +DECLARE + open_hospitalization boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + get_hospitalization_periods (NEW.patient_id) + WHERE + discharge_datetime IS NULL) INTO open_hospitalization; + IF open_hospitalization THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10001: ACTIVE_HOSPITALIZATION_EXISTS'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +-- Триггер: запрещает перекрытие госпитализаций +CREATE OR REPLACE FUNCTION check_hospitalization_overlap () + RETURNS TRIGGER + AS $$ +DECLARE + overlap_found boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + get_hospitalization_periods (NEW.patient_id) + WHERE + discharge_datetime IS NOT NULL + AND NEW.admission_datetime < discharge_datetime + AND NEW.admission_datetime > admission_datetime) INTO overlap_found; + IF overlap_found THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10002: HOSPITALIZATION_OVERLAP'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +-- Подключение триггеров на hospital_admissions +CREATE TRIGGER trg_check_active_hospitalization + BEFORE INSERT ON hospital_admission + FOR EACH ROW + EXECUTE FUNCTION check_active_hospitalization (); + +CREATE TRIGGER trg_check_hospitalization_overlap + BEFORE INSERT ON hospital_admission + FOR EACH ROW + EXECUTE FUNCTION check_hospitalization_overlap (); + diff --git a/migrations/triggers_hospital_discharge.sql b/migrations/triggers_hospital_discharge.sql new file mode 100644 index 0000000..a2a90c5 --- /dev/null +++ b/migrations/triggers_hospital_discharge.sql @@ -0,0 +1,55 @@ +-- Проверка: выписка должна быть позже поступления +CREATE OR REPLACE FUNCTION check_discharge_after_admission () + RETURNS TRIGGER + AS $$ +DECLARE + admission_time timestamp; +BEGIN + SELECT + admission_datetime INTO admission_time + FROM + hospital_admission + WHERE + hospital_admission_id = NEW.hospital_admission_id; + IF NEW.discharge_datetime <= admission_time THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10003: DISCHARGE_BEFORE_ADMISSION'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +CREATE TRIGGER trg_check_discharge_after_admission + BEFORE INSERT OR UPDATE ON hospital_discharge + FOR EACH ROW + EXECUTE FUNCTION check_discharge_after_admission (); + +-- Триггер: нельзя создать выписку, если уже есть выписка по этой госпитализации +CREATE OR REPLACE FUNCTION check_unique_discharge () + RETURNS TRIGGER + AS $$ +DECLARE + discharge_count integer; +BEGIN + SELECT + COUNT(*) INTO discharge_count + FROM + hospital_discharge + WHERE + hospital_admission_id = NEW.hospital_admission_id + AND hospital_discharge_id <> COALESCE(NEW.hospital_discharge_id, -1); + IF discharge_count > 0 THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10004: DISCHARGE_ALREADY_EXISTS'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +CREATE TRIGGER trg_check_unique_discharge + BEFORE INSERT OR UPDATE ON hospital_discharge + FOR EACH ROW + EXECUTE FUNCTION check_unique_discharge (); + diff --git a/migrations/triggers_numeric_results.sql b/migrations/triggers_numeric_results.sql new file mode 100644 index 0000000..c7bd914 --- /dev/null +++ b/migrations/triggers_numeric_results.sql @@ -0,0 +1,29 @@ +-- Триггер: запрет на запись числового результата, если есть качественный по тому же обследованию +CREATE OR REPLACE FUNCTION check_numeric_result_uniqueness () + RETURNS TRIGGER + AS $$ +DECLARE + qualitative_exists boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + qualitative_result + WHERE + result_id = NEW.result_id) INTO qualitative_exists; + IF qualitative_exists THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10005: QUALITATIVE_RESULT_ALREADY_EXISTS_FOR_THIS_EXAMINATION'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +CREATE TRIGGER trg_check_numeric_result_uniqueness + BEFORE INSERT OR UPDATE ON numeric_result + FOR EACH ROW + EXECUTE FUNCTION check_numeric_result_uniqueness (); + diff --git a/migrations/triggers_qualitative_results.sql b/migrations/triggers_qualitative_results.sql new file mode 100644 index 0000000..3cc556a --- /dev/null +++ b/migrations/triggers_qualitative_results.sql @@ -0,0 +1,29 @@ +-- Триггер: запрет на запись качественного результата, если есть числовой по тому же обследованию +CREATE OR REPLACE FUNCTION check_qualitative_result_uniqueness () + RETURNS TRIGGER + AS $$ +DECLARE + numeric_exists boolean; +BEGIN + SELECT + EXISTS ( + SELECT + 1 + FROM + numeric_result + WHERE + result_id = NEW.result_id) INTO numeric_exists; + IF numeric_exists THEN + RAISE EXCEPTION + USING ERRCODE = 'P0001', MESSAGE = '10006: NUMERIC_RESULT_ALREADY_EXISTS_FOR_THIS_EXAMINATION'; + END IF; + RETURN NEW; +END; +$$ +LANGUAGE plpgsql; + +CREATE TRIGGER trg_check_qualitative_result_uniqueness + BEFORE INSERT OR UPDATE ON qualitative_result + FOR EACH ROW + EXECUTE FUNCTION check_qualitative_result_uniqueness (); + diff --git a/migrations/types.sql b/migrations/types.sql new file mode 100644 index 0000000..97c977b --- /dev/null +++ b/migrations/types.sql @@ -0,0 +1,26 @@ +-- Перечисление для пола +CREATE TYPE gender_enum AS ENUM ( + 'male', -- мужчина + 'female' -- женщина +); + +-- Перечисление для типа обследования +CREATE TYPE examination_categories_enum AS ENUM ( + 'physical', -- физикальное обследование + 'laboratory', -- лабораторное обследование + 'instrumental' -- инструментальное обследование +); + +-- Перечисление для исхода госпитализации (выписка) +CREATE TYPE hospital_discharge_reason_enum AS ENUM ( + 'death', -- смерть + 'improvement', -- улучшение состояния + 'refusal' -- отказ от госпитализации или дальнейшего лечения +); + +-- Перечисление для контекста использования единицы измерения +CREATE TYPE unit_context_enum AS ENUM ( + 'examination', -- используется только для обследований (лабораторные, инструментальные, физикальные) + 'medication' -- используется только для лекарственных средств (дозировка, количество) +); +