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,84 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class CreateMedicalRecordRequest
{
public DateTime? RecordDate { get; set; }
public string? PatientId { get; set; }
public string? EmployeeId { get; set; }
public string? Subjective { get; set; }
public string? Objective { get; set; }
public string? Assessment { get; set; }
public string? Planning { get; set; }
public string? BloodPressure { get; set; }
public string? Temperature { get; set; }
public string? HeartRate { get; set; }
public string? Weight { get; set; }
public string? Height { get; set; }
public MedicalRecordStatus Status { get; set; }
public string? Description { get; set; }
public string? MedicalRecordGroupId { get; set; }
public string? MedicalRecordCategoryId { get; set; }
}
public class CreateMedicalRecordResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
}
public record CreateMedicalRecordCommand(CreateMedicalRecordRequest Data) : IRequest<CreateMedicalRecordResponse>;
public class CreateMedicalRecordHandler : IRequestHandler<CreateMedicalRecordCommand, CreateMedicalRecordResponse>
{
private readonly AppDbContext _context;
public CreateMedicalRecordHandler(AppDbContext context) => _context = context;
public async Task<CreateMedicalRecordResponse> Handle(CreateMedicalRecordCommand request, CancellationToken cancellationToken)
{
var entityName = nameof(Data.Entities.MedicalRecord);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"MR/{{Year}}/{{Month}}/",
ct: cancellationToken
);
var entity = new Data.Entities.MedicalRecord
{
AutoNumber = autoNo,
RecordDate = request.Data.RecordDate ?? DateTime.Now,
PatientId = request.Data.PatientId,
EmployeeId = request.Data.EmployeeId,
Subjective = request.Data.Subjective,
Objective = request.Data.Objective,
Assessment = request.Data.Assessment,
Planning = request.Data.Planning,
BloodPressure = request.Data.BloodPressure,
Temperature = request.Data.Temperature,
HeartRate = request.Data.HeartRate,
Weight = request.Data.Weight,
Height = request.Data.Height,
Status = request.Data.Status,
Description = request.Data.Description,
MedicalRecordGroupId = request.Data.MedicalRecordGroupId,
MedicalRecordCategoryId = request.Data.MedicalRecordCategoryId
};
_context.MedicalRecord.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateMedicalRecordResponse
{
Id = entity.Id,
AutoNumber = entity.AutoNumber
};
}
}
@@ -0,0 +1,53 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class CreateMedicalRecordValidator : AbstractValidator<CreateMedicalRecordRequest>
{
public CreateMedicalRecordValidator()
{
RuleFor(x => x.RecordDate)
.NotEmpty().WithMessage("Record Date is required");
RuleFor(x => x.PatientId)
.NotEmpty().WithMessage("Patient is required");
RuleFor(x => x.EmployeeId)
.NotEmpty().WithMessage("Examining Doctor is required");
RuleFor(x => x.MedicalRecordGroupId)
.NotEmpty().WithMessage("Medical Record Group is required");
RuleFor(x => x.MedicalRecordCategoryId)
.NotEmpty().WithMessage("Medical Record Category is required");
RuleFor(x => x.Assessment)
.NotEmpty().WithMessage("Assessment (Diagnosis) is required")
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Subjective)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Objective)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Planning)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.BloodPressure)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Temperature)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.HeartRate)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Weight)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Height)
.MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public record DeleteMedicalRecordByIdRequest(string Id);
public record DeleteMedicalRecordByIdCommand(DeleteMedicalRecordByIdRequest Data) : IRequest<bool>;
public class DeleteMedicalRecordByIdHandler : IRequestHandler<DeleteMedicalRecordByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteMedicalRecordByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteMedicalRecordByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.MedicalRecord
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.MedicalRecord.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,80 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class GetMedicalRecordByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public DateTime? RecordDate { get; set; }
public string? PatientId { get; set; }
public string? PatientName { get; set; }
public string? EmployeeId { get; set; }
public string? EmployeeName { get; set; }
public string? Subjective { get; set; }
public string? Objective { get; set; }
public string? Assessment { get; set; }
public string? Planning { get; set; }
public string? BloodPressure { get; set; }
public string? Temperature { get; set; }
public string? HeartRate { get; set; }
public string? Weight { get; set; }
public string? Height { get; set; }
public MedicalRecordStatus Status { get; set; }
public string? Description { get; set; }
public string? MedicalRecordGroupId { get; set; }
public string? MedicalRecordCategoryId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetMedicalRecordByIdQuery(string Id) : IRequest<GetMedicalRecordByIdResponse?>;
public class GetMedicalRecordByIdHandler : IRequestHandler<GetMedicalRecordByIdQuery, GetMedicalRecordByIdResponse?>
{
private readonly AppDbContext _context;
public GetMedicalRecordByIdHandler(AppDbContext context) => _context = context;
public async Task<GetMedicalRecordByIdResponse?> Handle(GetMedicalRecordByIdQuery request, CancellationToken cancellationToken)
{
return await _context.MedicalRecord
.AsNoTracking()
.Include(x => x.Patient)
.Include(x => x.Employee)
.Where(x => x.Id == request.Id)
.Select(x => new GetMedicalRecordByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
RecordDate = x.RecordDate,
PatientId = x.PatientId,
PatientName = x.Patient != null ? x.Patient.Name : string.Empty,
EmployeeId = x.EmployeeId,
EmployeeName = x.Employee != null ? x.Employee.Name : string.Empty,
Subjective = x.Subjective,
Objective = x.Objective,
Assessment = x.Assessment,
Planning = x.Planning,
BloodPressure = x.BloodPressure,
Temperature = x.Temperature,
HeartRate = x.HeartRate,
Weight = x.Weight,
Height = x.Height,
Status = x.Status,
Description = x.Description,
MedicalRecordGroupId = x.MedicalRecordGroupId,
MedicalRecordCategoryId = x.MedicalRecordCategoryId,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,52 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class GetMedicalRecordListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public DateTime? RecordDate { get; set; }
public string? PatientName { get; set; }
public string? EmployeeName { get; set; }
public string? Assessment { get; set; }
public MedicalRecordStatus Status { get; set; }
public string? MedicalRecordGroupName { get; set; }
public string? MedicalRecordCategoryName { get; set; }
}
public record GetMedicalRecordListQuery() : IRequest<List<GetMedicalRecordListResponse>>;
public class GetMedicalRecordListHandler : IRequestHandler<GetMedicalRecordListQuery, List<GetMedicalRecordListResponse>>
{
private readonly AppDbContext _context;
public GetMedicalRecordListHandler(AppDbContext context) => _context = context;
public async Task<List<GetMedicalRecordListResponse>> Handle(GetMedicalRecordListQuery request, CancellationToken cancellationToken)
{
return await _context.MedicalRecord
.AsNoTracking()
.Include(x => x.Patient)
.Include(x => x.Employee)
.Include(x => x.MedicalRecordGroup)
.Include(x => x.MedicalRecordCategory)
.OrderByDescending(x => x.RecordDate)
.Select(x => new GetMedicalRecordListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
RecordDate = x.RecordDate,
PatientName = x.Patient != null ? x.Patient.Name : string.Empty,
EmployeeName = x.Employee != null ? x.Employee.Name : string.Empty,
Assessment = x.Assessment,
Status = x.Status,
MedicalRecordGroupName = x.MedicalRecordGroup != null ? x.MedicalRecordGroup.Name : string.Empty,
MedicalRecordCategoryName = x.MedicalRecordCategory != null ? x.MedicalRecordCategory.Name : string.Empty
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,78 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
using Indotalent.Shared.Utils;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class LookupMedicalRecordResponse
{
public List<LookupItem> MedicalRecordGroups { get; set; } = new();
public List<LookupItem> MedicalRecordCategories { get; set; } = new();
public List<LookupItem> Patients { get; set; } = new();
public List<LookupItem> Doctors { get; set; } = new();
public List<StatusLookupItem> Statuses { get; set; } = new();
}
public class LookupItem
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public class StatusLookupItem
{
public int Value { get; set; }
public string? Name { get; set; }
}
public record LookupMedicalRecordQuery() : IRequest<LookupMedicalRecordResponse>;
public class LookupMedicalRecordHandler : IRequestHandler<LookupMedicalRecordQuery, LookupMedicalRecordResponse>
{
private readonly AppDbContext _context;
public LookupMedicalRecordHandler(AppDbContext context) => _context = context;
public async Task<LookupMedicalRecordResponse> Handle(LookupMedicalRecordQuery request, CancellationToken cancellationToken)
{
var result = new LookupMedicalRecordResponse();
result.MedicalRecordGroups = await _context.MedicalRecordGroup
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.MedicalRecordCategories = await _context.MedicalRecordCategory
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.Patients = await _context.Patient
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.Doctors = await _context.Employee
.AsNoTracking()
.Where(x => x.Name!.StartsWith("Dr.") || x.JobTitle!.Contains("Practitioner") || x.JobTitle!.Contains("Surgeon"))
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.Statuses = Enum.GetValues(typeof(MedicalRecordStatus))
.Cast<MedicalRecordStatus>()
.Select(x => new StatusLookupItem
{
Value = (int)x,
Name = x.ToString()
})
.ToList();
return result;
}
}
@@ -0,0 +1,84 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class UpdateMedicalRecordRequest
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public DateTime? RecordDate { get; set; }
public string? PatientId { get; set; }
public string? EmployeeId { get; set; }
public string? Subjective { get; set; }
public string? Objective { get; set; }
public string? Assessment { get; set; }
public string? Planning { get; set; }
public string? BloodPressure { get; set; }
public string? Temperature { get; set; }
public string? HeartRate { get; set; }
public string? Weight { get; set; }
public string? Height { get; set; }
public MedicalRecordStatus Status { get; set; }
public string? Description { get; set; }
public string? MedicalRecordGroupId { get; set; }
public string? MedicalRecordCategoryId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateMedicalRecordResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateMedicalRecordCommand(UpdateMedicalRecordRequest Data) : IRequest<UpdateMedicalRecordResponse>;
public class UpdateMedicalRecordHandler : IRequestHandler<UpdateMedicalRecordCommand, UpdateMedicalRecordResponse>
{
private readonly AppDbContext _context;
public UpdateMedicalRecordHandler(AppDbContext context) => _context = context;
public async Task<UpdateMedicalRecordResponse> Handle(UpdateMedicalRecordCommand request, CancellationToken cancellationToken)
{
var entity = await _context.MedicalRecord
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdateMedicalRecordResponse { Id = request.Data.Id, Success = false };
}
entity.RecordDate = request.Data.RecordDate;
entity.PatientId = request.Data.PatientId;
entity.EmployeeId = request.Data.EmployeeId;
entity.Subjective = request.Data.Subjective;
entity.Objective = request.Data.Objective;
entity.Assessment = request.Data.Assessment;
entity.Planning = request.Data.Planning;
entity.BloodPressure = request.Data.BloodPressure;
entity.Temperature = request.Data.Temperature;
entity.HeartRate = request.Data.HeartRate;
entity.Weight = request.Data.Weight;
entity.Height = request.Data.Height;
entity.Status = request.Data.Status;
entity.Description = request.Data.Description;
entity.MedicalRecordGroupId = request.Data.MedicalRecordGroupId;
entity.MedicalRecordCategoryId = request.Data.MedicalRecordCategoryId;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateMedicalRecordResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,56 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Medical.MedicalRecord.Cqrs;
public class UpdateMedicalRecordValidator : AbstractValidator<UpdateMedicalRecordRequest>
{
public UpdateMedicalRecordValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.RecordDate)
.NotEmpty().WithMessage("Record Date is required");
RuleFor(x => x.PatientId)
.NotEmpty().WithMessage("Patient is required");
RuleFor(x => x.EmployeeId)
.NotEmpty().WithMessage("Examining Doctor is required");
RuleFor(x => x.MedicalRecordGroupId)
.NotEmpty().WithMessage("Medical Record Group is required");
RuleFor(x => x.MedicalRecordCategoryId)
.NotEmpty().WithMessage("Medical Record Category is required");
RuleFor(x => x.Assessment)
.NotEmpty().WithMessage("Assessment (Diagnosis) is required")
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Subjective)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Objective)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.Planning)
.MaximumLength(GlobalConsts.StringLengthMedium);
RuleFor(x => x.BloodPressure)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Temperature)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.HeartRate)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Weight)
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Height)
.MaximumLength(GlobalConsts.StringLengthShort);
}
}