using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Thirdparty.Patient.Cqrs; public class LookupPatientResponse { public List PatientGroups { get; set; } = new(); public List PatientCategories { get; set; } = new(); } public class LookupItem { public string? Id { get; set; } public string? Name { get; set; } } public record LookupPatientQuery() : IRequest; public class LookupPatientHandler : IRequestHandler { private readonly AppDbContext _context; public LookupPatientHandler(AppDbContext context) => _context = context; public async Task Handle(LookupPatientQuery request, CancellationToken cancellationToken) { var result = new LookupPatientResponse(); result.PatientGroups = await _context.PatientGroup .AsNoTracking() .OrderBy(x => x.Name) .Select(x => new LookupItem { Id = x.Id, Name = x.Name }) .ToListAsync(cancellationToken); result.PatientCategories = await _context.PatientCategory .AsNoTracking() .OrderBy(x => x.Name) .Select(x => new LookupItem { Id = x.Id, Name = x.Name }) .ToListAsync(cancellationToken); return result; } }