Исправление: получение отчета по нескольким лекарствам и пациентам
This commit is contained in:
parent
abd474d67d
commit
c823a62a24
@ -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 medicine = _medicineStorage.GetElement(new MedicineSearchModel { Id = model.MedicineId});
|
|
||||||
if (medicine == null)
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
// получаем рецепты и процедуры, в которых используется лекарство
|
|
||||||
var treatmentsInRecipes = _recipeStorage.GetFullList().Where(x => x.RecipeMedicines.ContainsKey(medicine.Id)).SelectMany(x => x.RecipeTreatments.Keys).Distinct();
|
|
||||||
var procedures = _procedureStorage.GetFullList().Where(x => x.ProcedureMedicines.ContainsKey(medicine.Id)).Select(x => x.Id);
|
|
||||||
// пациенты могут получать лекарство как через процедуры, так и через рецепты, поэтому объединим оба варианта
|
|
||||||
var treatments = _treatmentStorage.GetFullList().Where(x => (x.TreatmentProcedures.Keys.Intersect(procedures).Any() || treatmentsInRecipes.Contains(x.Id))).Select(x => x.Id);
|
|
||||||
|
|
||||||
// получаем список пациентов, которые связаны с найденными лечениями
|
|
||||||
var patients = _patientStorage.GetFullList().Where(x => x.TreatmentId.HasValue).Where(x => treatments.Contains(x.TreatmentId!.Value));
|
|
||||||
|
|
||||||
var record = new ReportPatientsMedicinesViewModel
|
var record = new ReportPatientsMedicinesViewModel
|
||||||
{
|
{
|
||||||
MedicineName = medicine.Name,
|
MedicineName = medicine.Name,
|
||||||
Patients = new List<string>()
|
Patients = new List<Tuple<string, string, string?, DateTime>>()
|
||||||
};
|
};
|
||||||
foreach (var patient in patients)
|
// пациенты могут получать лекарство как через процедуры, так и через рецепты
|
||||||
{
|
// получаем рецепты и процедуры, в которых используется лекарство
|
||||||
record.Patients.Add($"{patient.Surname} {patient.Name} {patient.Patronymic} {patient.BirthDate}");
|
var treatmentsInRecipesWithMedicine = recipes
|
||||||
}
|
.Where(x => x.RecipeMedicines.ContainsKey(medicine.Id))
|
||||||
|
.SelectMany(x => x.RecipeTreatments.Keys).Distinct();
|
||||||
|
var proceduresWithMedicine = procedures
|
||||||
|
.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);
|
||||||
|
|
||||||
return record;
|
// получаем список пациентов, которые связаны с найденными лечениями
|
||||||
|
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();
|
||||||
|
|
||||||
|
list.Add(record);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ReportPrescriptionProcedureViewModel> GetPrescriptionProcedures(ReportBindingModel model)
|
public List<ReportPrescriptionProcedureViewModel> GetPrescriptionProcedures(ReportBindingModel model)
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user