ISEbd-21 Hairullov B.A. Lab_Work_03 #5
@ -6,11 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RegistrationPatientsPolyclinic.Entities.Enums;
|
||||
|
||||
[Flags] // Flag - атрибут, его значения будут комбинироваться, например, если мы создадим объект от соотрудника,
|
||||
// то его поле DoctorPost, то мы в него занесем только один из возможных вариантов(None, Junior, Senior, Head)
|
||||
// а по атрибуту Flags позволяет хранить несколько записей
|
||||
// ВАЖНО!!! Чтобы в перечеслении значения были степени двойки
|
||||
// битовое объединение
|
||||
[Flags]
|
||||
public enum Diagnosis
|
||||
{
|
||||
None = 0,
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RegistrationPatientsPolyclinic.Entities;
|
||||
|
||||
public class MedicalHistory // сущность пополнения, наподобие FeedReplenushment
|
||||
public class MedicalHistory
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
|
@ -10,14 +10,13 @@ public class Patient
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string First_Name { get; private set; } = string .Empty; // string.Empty - означает, что по умолчанию это свойство будет содержать пустую строку, а не null(то же самое "")
|
||||
public string First_Name { get; private set; } = string .Empty;
|
||||
|
||||
public string Last_Name { get; private set; } = string.Empty;
|
||||
|
||||
public string ContactNumber { get; private set; }
|
||||
|
||||
|
||||
// ТУТ СДЕЛАЕМ СТАТИСТИЧЕСКИЙ МЕТОД, который будет отвечать за создание объекта
|
||||
|
||||
public static Patient CreateEntity(int id, string first_Name, string last_Name, string contactNumber)
|
||||
{
|
||||
|
@ -57,12 +57,6 @@ namespace RegistrationPatientsPolyclinic.Forms
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
|
||||
/*
|
||||
CreateEntity(0,
|
||||
Convert.ToInt32(comboBoxPacient.Text),
|
||||
Convert.ToInt32(row.Cells["ColumnDoctor"].Value), (Diagnosis)row.Cells["ColumnDiagnosis"].Value,
|
||||
(Status)row.Cells["ColumnStatus"].Value, ColumnDrug);
|
||||
*/
|
||||
|
||||
_medicalHistoryRepository.CreateMedicalHistory(MedicalHistory.CreateEntity(0, (int)comboBoxPacient.SelectedValue!,
|
||||
(int)comboBoxDoctor.SelectedValue!, CreateListMedicalHistoryFromDataGrid()));
|
||||
|
@ -38,19 +38,7 @@ internal class ChartReport
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
// Получаем все медицинские истории за указанную дату
|
||||
var medicalHistories = _medicalHistoryRepository.ReadMedicalHistory(dateTime, dateTime);
|
||||
|
||||
// Группируем по идентификатору пациента и считаем количество посещений
|
||||
return medicalHistories
|
||||
.GroupBy(mh => mh.PatientId)
|
||||
.Select(g => (Caption: $"Patient {g.Key}", Value: (double)g.Count()))
|
||||
.ToList();
|
||||
}
|
||||
*/
|
||||
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
var medicalHistories = _medicalHistoryRepository.ReadMedicalHistory(null, null, null, null);
|
||||
|
@ -29,35 +29,35 @@ internal class PdfBuilder
|
||||
DefineStyles(); // настройка стиля
|
||||
}
|
||||
|
||||
public PdfBuilder AddHeader(string header) // Заголовок, header - это текст заголовка
|
||||
public PdfBuilder AddHeader(string header)
|
||||
{
|
||||
_document.AddSection().AddParagraph(header, "NormalBold"); // документу добавляется секция добавляется параграф
|
||||
_document.AddSection().AddParagraph(header, "NormalBold");
|
||||
return this;
|
||||
}
|
||||
|
||||
public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) // метод добавления диаграммы круговой
|
||||
public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data)
|
||||
{
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
var chart = new Chart(ChartType.Pie2D);
|
||||
var series = chart.SeriesCollection.AddSeries(); // добавляем серию
|
||||
var series = chart.SeriesCollection.AddSeries();
|
||||
series.Add(data.Select(x => x.Value).ToArray());
|
||||
var xseries = chart.XValues.AddXSeries(); // добавляем подписи
|
||||
var xseries = chart.XValues.AddXSeries();
|
||||
xseries.Add(data.Select(x => x.Caption).ToArray());
|
||||
chart.DataLabel.Type = DataLabelType.Percent; // вывод ввиде прицентов
|
||||
chart.DataLabel.Type = DataLabelType.Percent;
|
||||
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
|
||||
chart.Width = Unit.FromCentimeter(16); // ширина и высота
|
||||
chart.Width = Unit.FromCentimeter(16);
|
||||
chart.Height = Unit.FromCentimeter(12);
|
||||
chart.TopArea.AddParagraph(title); // заголовок добавляется
|
||||
chart.XAxis.MajorTickMark = TickMarkType.Outside; // настраиваем где у нас будут подписи
|
||||
chart.YAxis.MajorTickMark = TickMarkType.Outside; // настраиваем где у нас будут подписи
|
||||
chart.TopArea.AddParagraph(title);
|
||||
chart.XAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.HasMajorGridlines = true;
|
||||
chart.PlotArea.LineFormat.Width = 1;
|
||||
chart.PlotArea.LineFormat.Visible = true;
|
||||
chart.TopArea.AddLegend(); // где у нас будет легенда
|
||||
_document.LastSection.Add(chart); // в документ добавляем нашу таблицу
|
||||
chart.TopArea.AddLegend();
|
||||
_document.LastSection.Add(chart);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,6 @@ internal class TableReport
|
||||
}
|
||||
}
|
||||
|
||||
/// ВНИЗУ БЫЛ ПРАВИЛЬНЫЙ
|
||||
|
||||
|
||||
private List<string[]> GetData(int drugId, DateTime startDate, DateTime endDate)
|
||||
|
@ -10,13 +10,8 @@ using DocumentFormat.OpenXml.Packaging;
|
||||
|
||||
namespace RegistrationPatientsPolyclinic.Reports;
|
||||
|
||||
/// <summary>
|
||||
/// Построитель Ворда
|
||||
/// </summary>
|
||||
internal class WordBuilder
|
||||
{
|
||||
// Создание заголовка, вставить некий параграф с текстом
|
||||
// Потребуется сделать табличку
|
||||
private readonly string _filePath;
|
||||
private readonly Document _document;
|
||||
private readonly Body _body;
|
||||
@ -38,13 +33,13 @@ internal class WordBuilder
|
||||
|
||||
public WordBuilder AddHeader(string header)
|
||||
{
|
||||
// код ставки заголовка в документ Word
|
||||
var paragraph = _body.AppendChild(new Paragraph()); // в body добавляем новый элемент дочерний это будет параграф
|
||||
var run = paragraph.AppendChild(new Run()); // добавление блока
|
||||
// жирный шрифт
|
||||
|
||||
var paragraph = _body.AppendChild(new Paragraph());
|
||||
var run = paragraph.AppendChild(new Run());
|
||||
|
||||
var runProperties = run.AppendChild(new RunProperties());
|
||||
runProperties.AppendChild(new Bold());
|
||||
// добавляем текст
|
||||
|
||||
run.AppendChild(new Text(header));
|
||||
return this;
|
||||
|
||||
@ -52,7 +47,7 @@ internal class WordBuilder
|
||||
|
||||
public WordBuilder AddParagraph(string text)
|
||||
{
|
||||
// код ставки параграфа
|
||||
|
||||
|
||||
var paragraph = _body.AppendChild(new Paragraph());
|
||||
var run = paragraph.AppendChild(new Run());
|
||||
@ -61,12 +56,8 @@ internal class WordBuilder
|
||||
}
|
||||
|
||||
public WordBuilder AddTable(int[] widths, List<string[]> data)
|
||||
{ // int[] width - будет передаваться массив intов
|
||||
// Табличка в Word состоит из 3-ех блоков
|
||||
// 1-ый блок: свойство . Здесь будем задавать границы
|
||||
// 2-ой блок: колонки или Grid там передадим информацию по колонкам, какие колонки и какая у каждого ширина
|
||||
// 3-ий блок: строчки, заполняем строчки с данными
|
||||
// widths - ширина колонок
|
||||
{
|
||||
|
||||
if (widths == null || widths.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(widths));
|
||||
@ -75,14 +66,13 @@ internal class WordBuilder
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.Any(x => x.Length != widths.Length)) // использьем LinQ метод Any
|
||||
if (data.Any(x => x.Length != widths.Length))
|
||||
{
|
||||
throw new InvalidOperationException("widths.Length != data.Length");
|
||||
}
|
||||
// создаем таблицу
|
||||
// 1-ый блок свойства
|
||||
|
||||
var table = new Table();
|
||||
table.AppendChild(new TableProperties( // мы здесь задаем границы
|
||||
table.AppendChild(new TableProperties(
|
||||
new TableBorders(
|
||||
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
@ -93,27 +83,23 @@ internal class WordBuilder
|
||||
)
|
||||
));
|
||||
|
||||
// Заголовок
|
||||
// идем заполнять строчки,
|
||||
var tr = new TableRow();
|
||||
for (var j = 0; j < widths.Length; ++j)
|
||||
{
|
||||
tr.Append(new TableCell( // первая строчка, TableCell - это ячейка
|
||||
new TableCellProperties(new TableCellWidth() // в первой строчке в свойствах проставлем ширину Width = widths[j].ToString()
|
||||
tr.Append(new TableCell(
|
||||
new TableCellProperties(new TableCellWidth()
|
||||
{
|
||||
Width =
|
||||
widths[j].ToString() // заполняем ширину ячейки
|
||||
widths[j].ToString()
|
||||
}),
|
||||
new Paragraph(new Run(new RunProperties(new Bold()), new // заголовок делаем что у нас он жирный Bold(), это шапка каждой таблицы
|
||||
Text(data.First()[j]))))); // Через LinQ метод вытаскиваем First, некий Text data.First() - берем элемент из первой строки
|
||||
new Paragraph(new Run(new RunProperties(new Bold()), new
|
||||
Text(data.First()[j])))));
|
||||
}
|
||||
table.Append(tr); // заполнили первую строчку добавили в табличку
|
||||
|
||||
// Данные
|
||||
// теперь просто заполняем данные
|
||||
table.Append(data.Skip(1).Select(x => // LinQ метод data.Skip(1) - пропускаем первую запись, которая у нас шапка таблицы
|
||||
new TableRow(x.Select(y => new TableCell(new Paragraph(new // а для всех остальных мы берем элемент data(список)
|
||||
Run(new Text(y)))))))); // и основе каждого списка создаем объект TableRow, которого через x.Select заполняет ячейки
|
||||
table.Append(tr);
|
||||
|
||||
table.Append(data.Skip(1).Select(x =>
|
||||
new TableRow(x.Select(y => new TableCell(new Paragraph(new
|
||||
Run(new Text(y))))))));
|
||||
_body.Append(table);
|
||||
return this;
|
||||
}
|
||||
@ -121,7 +107,7 @@ internal class WordBuilder
|
||||
|
||||
public void Build()
|
||||
{
|
||||
// элемент какой будет все создавать
|
||||
|
||||
using var wordDocument = WordprocessingDocument.Create(_filePath, WordprocessingDocumentType.Document);
|
||||
var mainPart = wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = _document;
|
||||
|
@ -10,9 +10,9 @@ namespace RegistrationPatientsPolyclinic.Repositories;
|
||||
|
||||
public interface IDrugMedicalHistory
|
||||
{
|
||||
IEnumerable<DrugMedicalHistory> ReadDragMedicalHistory(int? drugId, string description); // чтение всего
|
||||
IEnumerable<DrugMedicalHistory> ReadDragMedicalHistory(int? drugId, string description);
|
||||
|
||||
void CreateDrugMedicalHistory(DrugMedicalHistory drugHistory); // создание объекта
|
||||
void CreateDrugMedicalHistory(DrugMedicalHistory drugHistory);
|
||||
|
||||
void DeleteDrugMedicalHistory(int Id);
|
||||
}
|
||||
|
@ -11,15 +11,10 @@ public interface IMedicalHistoryRepository
|
||||
{
|
||||
|
||||
IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null,
|
||||
int? DoctorId = null); // по этим параметрам можно не весь список читать, а только какую то часть
|
||||
int? DoctorId = null);
|
||||
|
||||
|
||||
/*
|
||||
IEnumerable<TempDrugMedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null,
|
||||
int? DoctorId = null); // по этим параметрам можно не весь список читать, а только какую то часть
|
||||
|
||||
*/
|
||||
void CreateMedicalHistory(MedicalHistory medicalHistory); // объекь будет заносится в список
|
||||
void CreateMedicalHistory(MedicalHistory medicalHistory);
|
||||
|
||||
|
||||
void DeletemedicalHistory(int id);
|
||||
|
@ -7,18 +7,15 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RegistrationPatientsPolyclinic.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Операцию read (чтение) разобьем на 2 метода: получение коллекции и получений одной записи по идентификатору.
|
||||
/// </summary>
|
||||
public interface IPatientRepository
|
||||
{
|
||||
IEnumerable<Patient> ReadPatient(); // метод получения всего списка (в данном случае пациентов)
|
||||
IEnumerable<Patient> ReadPatient();
|
||||
|
||||
Patient ReadPatientById(int id); // получение по id
|
||||
Patient ReadPatientById(int id);
|
||||
|
||||
void CreatPatient(Patient patient); // метод для того чтобы добавить в существующую коллекцию пациента
|
||||
void CreatPatient(Patient patient);
|
||||
|
||||
void UpdatePatient(Patient patient); // метод на изменение
|
||||
void UpdatePatient(Patient patient);
|
||||
|
||||
void DeletePatient(int id);
|
||||
}
|
||||
|
@ -112,52 +112,7 @@ WHERE Id=@id";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM MedicalHistory";
|
||||
var medicalHistory =
|
||||
connection.Query<MedicalHistory>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(medicalHistory));
|
||||
return medicalHistory;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
/*
|
||||
public IEnumerable<TempDrugMedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT mh.*, dmh.DrugId, dmh.Description
|
||||
FROM MedicalHistory mh
|
||||
INNER JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id";
|
||||
var medicalHistory =
|
||||
connection.Query<TempDrugMedicalHistory>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(medicalHistory));
|
||||
return medicalHistory;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user