Overview
The Patient Management feature enables administrators to register, update, and manage patient records in the Clínica Vitalis system. Each patient is associated with a social work (insurance provider) for billing and coverage purposes.Data Model
Patients are stored with the following structure:Patient States
Patients can have one of two states:- Activo/a (Active): Patient can schedule appointments
- Inactivo/a (Inactive): Patient record is archived or suspended
Key Features
Register New Patient
Administrators can register new patients with comprehensive validation:Enter Personal Information
Provide the patient’s name, surname, DNI (minimum 7 digits), birthdate, and gender.
Select Social Work
Choose the patient’s insurance provider (social work) from active options in the system.
Each patient must have a unique DNI. The system prevents duplicate registrations using the same identification number.
Validation Rules
Strict validation is enforced frombackend/routes/patients.ts:29-52:
Search and Filter Patients
The system provides flexible search capabilities to quickly find patient records: Search by:- Name (partial match)
- Surname (partial match)
- DNI (partial match)
- Gender
- Social Work ID (insurance provider)
- Patient state (active/inactive)
View Patient Details
When retrieving patient information, the system provides:- Complete patient demographic data
- Associated social work (insurance) information
- Current patient state
- Contact information for communication
Update Patient Records
Administrators can modify patient information as needed:Validate Changes
The system validates all fields, ensuring DNI uniqueness (excluding the current patient).
When updating a patient’s DNI, the system checks that the new DNI doesn’t belong to another patient in the system.
Data Integrity
Database Constraints
The patient model includes important constraints defined inbackend/models/patients.ts:
API Endpoints
GET /api/patients
Retrieve all patients with optional filters.
Query Parameters:
search- Search term for name, surname, or DNIgender- Filter by gendersocialWorkId- Filter by insurance providerstate- Filter by patient state
GET /api/patients/:id
Retrieve a specific patient by ID.
Response:
POST /api/patients
Create a new patient (Admin only).
Required Fields:
- name, surname, dni, birthdate, gender, address, phone, email, socialWorkId
PATCH /api/patients/:id
Update a patient record (Admin only).
Required Fields:
- All fields from POST plus
state
Security and Access Control
All patient management operations require JWT authentication. Create and update operations are restricted to users with administrator privileges.
- GET requests: Authenticated users only
- POST/PATCH requests: Administrator role required
Database Relationships
Patients are connected to:- Social Works (Many-to-One): Each patient belongs to one insurance provider
- Appointments (One-to-Many): Each patient can have multiple appointments
Workflow Example
Here’s a typical patient registration workflow:Collect Information
Reception staff collects patient’s personal information, DNI, and insurance details.
Create Record
Administrator creates the patient record through the system with validated information.
Best Practices
- Always verify DNI before registration to prevent duplicates
- Validate social work exists and is active before assigning to a patient
- Use state management instead of deleting patient records for data integrity
- Keep contact information updated to ensure effective patient communication
- Filter by active state when showing patients for appointment scheduling
- Protect patient data according to healthcare privacy regulations
