using FluentValidation; public class FhirPatientUpsertRequestValidator : AbstractValidator { private static readonly HashSet 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); } }