Исправление: получение отчета по нескольким лекарствам и пациентам

This commit is contained in:
prodigygirl 2023-04-07 22:18:57 +04:00
parent abd474d67d
commit c823a62a24
4 changed files with 40 additions and 33 deletions

View File

@ -27,37 +27,43 @@ namespace HospitalBusinessLogic
_recipeStorage = recipeStorage; _recipeStorage = recipeStorage;
} }
public ReportPatientsMedicinesViewModel GetMedicinePatients(ReportBindingModel model) public List<ReportPatientsMedicinesViewModel> GetMedicinePatients(ReportBindingModel model)
{ {
if (!model.MedicineId.HasValue) var list = new List<ReportPatientsMedicinesViewModel>();
var medicines = _medicineStorage.GetFullList().Where(x => model.Medicines.Contains(x.Id));
var recipes = _recipeStorage.GetFullList();
var procedures = _procedureStorage.GetFullList();
var treatments = _treatmentStorage.GetFullList();
var patients = _patientStorage.GetFullList();
foreach (var medicine in medicines)
{ {
return new(); var record = new ReportPatientsMedicinesViewModel
} {
var medicine = _medicineStorage.GetElement(new MedicineSearchModel { Id = model.MedicineId}); MedicineName = medicine.Name,
if (medicine == null) Patients = new List<Tuple<string, string, string?, DateTime>>()
{ };
return new(); // пациенты могут получать лекарство как через процедуры, так и через рецепты
} // получаем рецепты и процедуры, в которых используется лекарство
// получаем рецепты и процедуры, в которых используется лекарство var treatmentsInRecipesWithMedicine = recipes
var treatmentsInRecipes = _recipeStorage.GetFullList().Where(x => x.RecipeMedicines.ContainsKey(medicine.Id)).SelectMany(x => x.RecipeTreatments.Keys).Distinct(); .Where(x => x.RecipeMedicines.ContainsKey(medicine.Id))
var procedures = _procedureStorage.GetFullList().Where(x => x.ProcedureMedicines.ContainsKey(medicine.Id)).Select(x => x.Id); .SelectMany(x => x.RecipeTreatments.Keys).Distinct();
// пациенты могут получать лекарство как через процедуры, так и через рецепты, поэтому объединим оба варианта var proceduresWithMedicine = procedures
var treatments = _treatmentStorage.GetFullList().Where(x => (x.TreatmentProcedures.Keys.Intersect(procedures).Any() || treatmentsInRecipes.Contains(x.Id))).Select(x => x.Id); .Where(x => x.ProcedureMedicines.ContainsKey(medicine.Id))
.Select(x => x.Id);
// объединим оба варианта
var treatmentsWithMedicine = treatments
.Where(x => x.TreatmentProcedures.Keys.Intersect(proceduresWithMedicine).Any() || treatmentsInRecipesWithMedicine.Contains(x.Id))
.Select(x => x.Id);
// получаем список пациентов, которые связаны с найденными лечениями // получаем список пациентов, которые связаны с найденными лечениями
var patients = _patientStorage.GetFullList().Where(x => x.TreatmentId.HasValue).Where(x => treatments.Contains(x.TreatmentId!.Value)); record.Patients = patients
.Where(x => x.TreatmentId.HasValue)
.Where(x => treatmentsWithMedicine.Contains(x.TreatmentId!.Value))
.Select(x => new Tuple<string, string, string?, DateTime>(x.Surname, x.Name, x.Patronymic, x.BirthDate)).ToList();
var record = new ReportPatientsMedicinesViewModel list.Add(record);
{
MedicineName = medicine.Name,
Patients = new List<string>()
};
foreach (var patient in patients)
{
record.Patients.Add($"{patient.Surname} {patient.Name} {patient.Patronymic} {patient.BirthDate}");
} }
return list;
return record;
} }
public List<ReportPrescriptionProcedureViewModel> GetPrescriptionProcedures(ReportBindingModel model) public List<ReportPrescriptionProcedureViewModel> GetPrescriptionProcedures(ReportBindingModel model)

View File

@ -1,4 +1,5 @@
using System; using HospitalDataModels.Models;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -11,7 +12,7 @@ namespace HospitalContracts.BindingModels
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
// выбранные лекарства
public int? MedicineId { get; set; } public List<int> Medicines { get; set; } = new();
} }
} }

View File

@ -10,7 +10,7 @@ namespace HospitalContracts.BusinessLogicContracts
/// Получение списка пациентов с указанием, какие они используют лекарства при лечении /// Получение списка пациентов с указанием, какие они используют лекарства при лечении
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
ReportPatientsMedicinesViewModel GetMedicinePatients(ReportBindingModel reportBinding); List<ReportPatientsMedicinesViewModel> GetMedicinePatients(ReportBindingModel reportBinding);
/// <summary> /// <summary>
/// Получение списка поступлений лекарств и процедур, в которых использованы данные лекарства /// Получение списка поступлений лекарств и процедур, в которых использованы данные лекарства
/// </summary> /// </summary>

View File

@ -10,6 +10,6 @@ namespace HospitalContracts.ViewModels
{ {
public string MedicineName { get; set; } = string.Empty; public string MedicineName { get; set; } = string.Empty;
public List<string> Patients { get; set; } = new(); // TODO: может как-то по-другому надо хранить информацию по пациенту? public List<Tuple<string, string, string?, DateTime>> Patients { get; set; } = new();
} }
} }