Overview
Data Transfer Objects (DTOs) are used throughout the API to define the structure of data sent to and received from the endpoints. This page documents all DTOs available in the system.All DTOs are implemented as C# records in the
preliminarServicios.Models.Dtos namespace, providing immutable data structures with built-in validation.Patient DTOs
CreatePacienteDto
Used for creating and updating patient records. Location:Models/Dtos/CreatePacienteDto.cs
Structure:
Patient’s first nameValidation:
- Required
- Length: 3-100 characters
- Pattern:
^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$(letters and spaces only) - Error: “El nombre solo puede contener letras y espacios”
Patient’s last nameValidation:
- Required
- Length: 3-100 characters
- Pattern:
^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$(letters and spaces only) - Error: “El apellido solo puede contener letras y espacios”
Patient’s national identity documentValidation:
- Required
- Pattern:
^\d{8}$(exactly 8 digits) - Error: “El DNI debe tener exactamente 8 dígitos.”
Patient’s email addressValidation:
- Required
- Must be valid email format
- Error: “El correo electrónico no es válido.”
Patient’s phone number (optional)Validation:
- Optional (nullable)
- Must match phone format if provided
Patient’s date of birthValidation:
- Required
- Format: ISO 8601 date (YYYY-MM-DD)
PacienteResumenDto
Compact patient summary used in appointment listings. Location:Models/Dtos/PacienteResumenDto.cs
Structure:
Patient’s unique identifier
Patient’s full name (concatenated first and last name)
Patient’s national identity document
Doctor DTOs
CreateMedicoDto
Used for creating and updating doctor records. Location:Models/Dtos/CreateMedicoDto.cs
Structure:
Doctor’s first nameValidation:
- Required
- Length: 3-100 characters
- Pattern:
^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$(letters and spaces only) - Error: “El nombre solo puede contener letras y espacios”
Doctor’s last nameValidation:
- Required
- Length: 3-100 characters
- Pattern:
^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$(letters and spaces only) - Error: “El apellido solo puede contener letras y espacios”
Doctor’s professional license numberValidation:
- Required
- Must be unique
Doctor’s phone number (optional)Validation:
- Optional (nullable)
- Must match phone format if provided
MedicoResumenDto
Compact doctor summary used in appointment listings, includes specialty information. Location:Models/Dtos/MedicoResumenDto.cs
Structure:
Doctor’s unique identifier
Doctor’s full name (concatenated first and last name)
Name of the doctor’s medical specialty
Specialty DTOs
CreateEspecialidadDto
Used for creating and updating medical specialties. Location:Models/Dtos/CreateEspecialidadDto.cs
Structure:
Name of the medical specialtyValidation:
- Required
- Length: 3-100 characters
- Pattern:
^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$(letters and spaces only) - Error: “El nombre solo puede contener letras y espacios”
- Must be unique
Appointment DTOs
CreateCitaDto
Used for creating and updating appointment records. Location:Models/Dtos/CreateCitaDto.cs
Structure:
ID of the patient for this appointmentValidation:
- Required
- Must reference an existing patient
ID of the doctor for this appointmentValidation:
- Required
- Must reference an existing doctor
Cost of the appointmentValidation:
- Required
- Range: 0 to double.MaxValue
- Error: “El costo debe ser un número positivo.”
Reason or purpose for the appointmentValidation:
- Required
Start date and time of the appointmentValidation:
- Required
- Format: ISO 8601 DateTime
End date and time of the appointmentValidation:
- Required
- Format: ISO 8601 DateTime
Additional notes or observations (optional)Validation:
- Optional (nullable)
CitaDto
Enriched appointment DTO with embedded patient and doctor summaries. Location:Models/Dtos/CitaDto.cs
Structure:
Appointment’s unique identifier
Summary of the patient information
Summary of the doctor information
Date and time of the appointment
Reason for the appointment
Status of the appointment (Pendiente, Confirmada, Cancelada, Completada)
Entity Models vs DTOs
Key Differences
DTOs are used for data transfer between client and server, while Entities represent the database schema and domain models.
| Aspect | DTOs | Entities |
|---|---|---|
| Purpose | Data transfer, validation | Database mapping, business logic |
| Location | Models/Dtos/ | Models/Entities/ |
| Type | Record classes (immutable) | Classes (mutable) |
| Validation | Data annotations | Required/optional modifiers |
| ID Field | Not included in Create DTOs | Always included |
| Relationships | Foreign key IDs | May include navigation properties |
When to Use Each
Use DTOs for:- API request bodies (POST, PUT)
- Returning simplified data structures
- Aggregating data from multiple entities
- Hiding sensitive fields
- Database operations
- Business logic
- Data persistence
- Internal application state
Validation Attributes
All DTOs use C# Data Annotations for validation:Common Attributes
[Required]- Field cannot be null or empty[Length(min, max)]- String length constraints[RegularExpression(pattern)]- Pattern matching[EmailAddress]- Valid email format[Phone]- Valid phone format[Range(min, max)]- Numeric range validation