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