| | | 1 | | using LifeChart.Application.DTOs; |
| | | 2 | | using LifeChart.Application.Interfaces; |
| | | 3 | | using LifeChart.Domain.Entries; |
| | | 4 | | using LifeChart.Domain.Medications; |
| | | 5 | | |
| | | 6 | | namespace LifeChart.Application.UseCases.Pdf; |
| | | 7 | | |
| | | 8 | | public class ExportPdfUseCase |
| | | 9 | | { |
| | | 10 | | private readonly IDailyEntryRepository _entryRepository; |
| | | 11 | | private readonly IMedicationRepository _medicationRepository; |
| | | 12 | | private readonly IPdfRenderer _renderer; |
| | | 13 | | |
| | 0 | 14 | | public ExportPdfUseCase( |
| | 0 | 15 | | IDailyEntryRepository entryRepository, |
| | 0 | 16 | | IMedicationRepository medicationRepository, |
| | 0 | 17 | | IPdfRenderer renderer) |
| | | 18 | | { |
| | 0 | 19 | | _entryRepository = entryRepository; |
| | 0 | 20 | | _medicationRepository = medicationRepository; |
| | 0 | 21 | | _renderer = renderer; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | public async Task<byte[]> ExecuteAsync(DateOnly from, DateOnly to) |
| | | 25 | | { |
| | 0 | 26 | | var entries = (await _entryRepository.GetRangeAsync(from, to)) |
| | 0 | 27 | | .Select(e => new DailyEntryDto( |
| | 0 | 28 | | e.Date, e.Mood.Value, e.Functionality.Value, |
| | 0 | 29 | | e.SleepHours.Value, e.MedicationTaken, |
| | 0 | 30 | | e.MenstrualCycle, e.Symptoms, e.Notes, e.IsHypomanic)) |
| | 0 | 31 | | .ToList() |
| | 0 | 32 | | .AsReadOnly(); |
| | | 33 | | |
| | 0 | 34 | | var medications = (await _medicationRepository.GetAllActiveAsync()) |
| | 0 | 35 | | .Select(m => new MedicationDto( |
| | 0 | 36 | | m.Id, m.Name, m.Dosage, |
| | 0 | 37 | | m.MinStock, m.CurrentStock, m.IsStockLow, |
| | 0 | 38 | | m.IntakeTimes |
| | 0 | 39 | | .Select(i => new IntakeTimeDto(i.Time.ToString("HH:mm"), i.DoseCount)) |
| | 0 | 40 | | .ToList() |
| | 0 | 41 | | .AsReadOnly())) |
| | 0 | 42 | | .ToList() |
| | 0 | 43 | | .AsReadOnly(); |
| | | 44 | | |
| | 0 | 45 | | var chartData = new ChartDataDto( |
| | 0 | 46 | | entries |
| | 0 | 47 | | .Select(e => new ChartPointDto(e.Date, e.Mood, e.Functionality, e.IsHypomanic)) |
| | 0 | 48 | | .ToList() |
| | 0 | 49 | | .AsReadOnly(), |
| | 0 | 50 | | from, to); |
| | | 51 | | |
| | 0 | 52 | | return await _renderer.RenderAsync( |
| | 0 | 53 | | new PdfReportData(chartData, entries, medications, from, to)); |
| | 0 | 54 | | } |
| | | 55 | | } |