45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Thirdparty.Patient.Cqrs;
|
|
|
|
public class GetPatientListResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? AutoNumber { get; set; }
|
|
public string? Name { get; set; }
|
|
public string? PhoneNumber { get; set; }
|
|
public string? EmailAddress { get; set; }
|
|
public string? PatientGroupName { get; set; }
|
|
public string? PatientCategoryName { get; set; }
|
|
}
|
|
|
|
public record GetPatientListQuery() : IRequest<List<GetPatientListResponse>>;
|
|
|
|
public class GetPatientListHandler : IRequestHandler<GetPatientListQuery, List<GetPatientListResponse>>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetPatientListHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<List<GetPatientListResponse>> Handle(GetPatientListQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.Patient
|
|
.AsNoTracking()
|
|
.Include(x => x.PatientGroup)
|
|
.Include(x => x.PatientCategory)
|
|
.OrderBy(x => x.Name)
|
|
.Select(x => new GetPatientListResponse
|
|
{
|
|
Id = x.Id,
|
|
AutoNumber = x.AutoNumber,
|
|
Name = x.Name,
|
|
PhoneNumber = x.PhoneNumber,
|
|
EmailAddress = x.EmailAddress,
|
|
PatientGroupName = x.PatientGroup != null ? x.PatientGroup.Name : string.Empty,
|
|
PatientCategoryName = x.PatientCategory != null ? x.PatientCategory.Name : string.Empty
|
|
})
|
|
.ToListAsync(cancellationToken);
|
|
}
|
|
} |