28 lines
1.3 KiB
C#
28 lines
1.3 KiB
C#
using FluentValidation;
|
|
|
|
public class FhirPatientUpsertRequestValidator : AbstractValidator<FhirPatientUpsertRequest>
|
|
{
|
|
private static readonly HashSet<string> ValidGenders = new(StringComparer.OrdinalIgnoreCase)
|
|
{ "male", "female", "other", "unknown" };
|
|
|
|
public FhirPatientUpsertRequestValidator()
|
|
{
|
|
RuleFor(x => x.IdentifierSystem).NotEmpty().MaximumLength(500);
|
|
RuleFor(x => x.IdentifierValue).NotEmpty().MaximumLength(200);
|
|
RuleFor(x => x.FirstName).NotEmpty().MaximumLength(100);
|
|
RuleFor(x => x.LastName).NotEmpty().MaximumLength(100);
|
|
RuleFor(x => x.DateOfBirth).NotEmpty()
|
|
.LessThanOrEqualTo(DateOnly.FromDateTime(DateTime.UtcNow))
|
|
.WithMessage("Date of birth cannot be in the future.");
|
|
RuleFor(x => x.Gender).NotEmpty()
|
|
.Must(g => ValidGenders.Contains(g))
|
|
.WithMessage("Gender must be one of: male, female, other, unknown.");
|
|
RuleFor(x => x.BloodType).IsInEnum()
|
|
.When(x => x.BloodType is not null);
|
|
RuleFor(x => x.EmergencyContactName).MaximumLength(200)
|
|
.When(x => x.EmergencyContactName is not null);
|
|
RuleFor(x => x.EmergencyContactPhone).MaximumLength(20)
|
|
.When(x => x.EmergencyContactPhone is not null);
|
|
}
|
|
}
|