initial commit

This commit is contained in:
2026-07-21 13:52:43 +07:00
commit f0e6f38940
881 changed files with 66309 additions and 0 deletions
@@ -0,0 +1,63 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public class CreatePatientContactRequest
{
public string? Name { get; set; }
public string? Title { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public string? Description { get; set; }
public string? PatientId { get; set; }
}
public class CreatePatientContactResponse
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public record CreatePatientContactCommand(CreatePatientContactRequest Data) : IRequest<CreatePatientContactResponse>;
public class CreatePatientContactHandler : IRequestHandler<CreatePatientContactCommand, CreatePatientContactResponse>
{
private readonly AppDbContext _context;
public CreatePatientContactHandler(AppDbContext context) => _context = context;
public async Task<CreatePatientContactResponse> Handle(CreatePatientContactCommand request, CancellationToken cancellationToken)
{
var entityName = nameof(Data.Entities.PatientContact);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.PatientContact
{
AutoNumber = autoNo,
Name = request.Data.Name,
Title = request.Data.Title,
PhoneNumber = request.Data.PhoneNumber,
EmailAddress = request.Data.EmailAddress,
Description = request.Data.Description,
PatientId = request.Data.PatientId
};
_context.PatientContact.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreatePatientContactResponse
{
Id = entity.Id,
Name = entity.Name
};
}
}
@@ -0,0 +1,20 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public class CreatePatientContactValidator : AbstractValidator<CreatePatientContactRequest>
{
public CreatePatientContactValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Contact Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.PatientId)
.NotEmpty().WithMessage("Patient is required");
RuleFor(x => x.EmailAddress)
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public record DeletePatientContactByIdRequest(string Id);
public record DeletePatientContactByIdCommand(DeletePatientContactByIdRequest Data) : IRequest<bool>;
public class DeletePatientContactByIdHandler : IRequestHandler<DeletePatientContactByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeletePatientContactByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeletePatientContactByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.PatientContact
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.PatientContact.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,53 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public class GetPatientContactByIdResponse
{
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? Description { get; set; }
public string? PatientId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetPatientContactByIdQuery(string Id) : IRequest<GetPatientContactByIdResponse?>;
public class GetPatientContactByIdHandler : IRequestHandler<GetPatientContactByIdQuery, GetPatientContactByIdResponse?>
{
private readonly AppDbContext _context;
public GetPatientContactByIdHandler(AppDbContext context) => _context = context;
public async Task<GetPatientContactByIdResponse?> Handle(GetPatientContactByIdQuery request, CancellationToken cancellationToken)
{
return await _context.PatientContact
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetPatientContactByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Name = x.Name,
Title = x.Title,
PhoneNumber = x.PhoneNumber,
EmailAddress = x.EmailAddress,
Description = x.Description,
PatientId = x.PatientId,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy,
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,44 @@
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);
}
}
@@ -0,0 +1,38 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public class LookupPatientContactResponse
{
public List<LookupItem> Patients { get; set; } = new();
}
public class LookupItem
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public record LookupPatientContactQuery() : IRequest<LookupPatientContactResponse>;
public class LookupPatientContactHandler : IRequestHandler<LookupPatientContactQuery, LookupPatientContactResponse>
{
private readonly AppDbContext _context;
public LookupPatientContactHandler(AppDbContext context) => _context = context;
public async Task<LookupPatientContactResponse> Handle(LookupPatientContactQuery request, CancellationToken cancellationToken)
{
var result = new LookupPatientContactResponse();
result.Patients = await _context.Patient
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
return result;
}
}
@@ -0,0 +1,62 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public class UpdatePatientContactRequest
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? Title { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public string? Description { get; set; }
public string? PatientId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdatePatientContactResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdatePatientContactCommand(UpdatePatientContactRequest Data) : IRequest<UpdatePatientContactResponse>;
public class UpdatePatientContactHandler : IRequestHandler<UpdatePatientContactCommand, UpdatePatientContactResponse>
{
private readonly AppDbContext _context;
public UpdatePatientContactHandler(AppDbContext context) => _context = context;
public async Task<UpdatePatientContactResponse> Handle(UpdatePatientContactCommand request, CancellationToken cancellationToken)
{
var entity = await _context.PatientContact
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdatePatientContactResponse { Id = request.Data.Id, Success = false };
}
entity.Name = request.Data.Name;
entity.Title = request.Data.Title;
entity.PhoneNumber = request.Data.PhoneNumber;
entity.EmailAddress = request.Data.EmailAddress;
entity.Description = request.Data.Description;
entity.PatientId = request.Data.PatientId;
await _context.SaveChangesAsync(cancellationToken);
return new UpdatePatientContactResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,23 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public class UpdatePatientContactValidator : AbstractValidator<UpdatePatientContactRequest>
{
public UpdatePatientContactValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Contact Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.PatientId)
.NotEmpty().WithMessage("Patient is required");
RuleFor(x => x.EmailAddress)
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
}
}