Files
2026-07-21 13:52:43 +07:00

45 lines
1.4 KiB
C#

using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.Patient.Cqrs;
public class LookupPatientResponse
{
public List<LookupItem> PatientGroups { get; set; } = new();
public List<LookupItem> PatientCategories { get; set; } = new();
}
public class LookupItem
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public record LookupPatientQuery() : IRequest<LookupPatientResponse>;
public class LookupPatientHandler : IRequestHandler<LookupPatientQuery, LookupPatientResponse>
{
private readonly AppDbContext _context;
public LookupPatientHandler(AppDbContext context) => _context = context;
public async Task<LookupPatientResponse> 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;
}
}