Files
HealthAppRepository/src/PatientProfileService/Application/PatientApplicationService.cs
T

30 lines
1.1 KiB
C#

using PatientProfileService.Contracts;
using PatientProfileService.Domain;
namespace PatientProfileService.Application;
public sealed class PatientApplicationService(PatientRepository repository)
{
public Task<Patient> CreatePatientAsync(CreatePatientRequest request, CancellationToken cancellationToken)
{
ArgumentException.ThrowIfNullOrWhiteSpace(request.Name);
if (request.DateOfBirth is null)
throw new ArgumentException("A date of birth is required.", nameof(request));
// The documented TIMESTAMP columns store UTC without a time-zone component.
var now = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Unspecified);
return repository.SaveAsync(new Patient
{
PatientId = Guid.NewGuid(),
Name = request.Name,
DateOfBirth = request.DateOfBirth.Value,
ContactInfo = request.ContactInfo,
CreatedAt = now,
UpdatedAt = now
}, cancellationToken);
}
public Task<Patient?> GetPatientAsync(Guid patientId, CancellationToken cancellationToken) =>
repository.FindByIdAsync(patientId, cancellationToken);
}