Overview
Med Agenda’s patient management system handles patient registration, authentication, profile updates, and medical history tracking. The system uses CPF (Brazilian tax ID) as the primary identifier and implements secure password hashing with BCrypt.Patient Data Model
The patient entity stores comprehensive information about each patient:Patient.java:8-49
cpf: 11-digit Brazilian tax ID (primary key)email: Unique email for authenticationpassword: BCrypt-hashed passwordname: Patient’s full namedateOfBirth: Date of birth (validated to ensure 18+ age)address: Residential addressmedicalHistory: Medical background and conditionshistoricoConsultas: One-to-many relationship with consultations
Patient Registration
New patient registration includes automatic password hashing for security.PatientService.java:29-33
API Endpoint
PatientController.java:33-45
POST /patients/create
Request Body:
Patient Authentication
The system uses email and password for authentication with BCrypt verification.PatientService.java:35-41
Login Endpoint
PatientController.java:24-31
POST /patients/login
Patient Validation
Med Agenda enforces strict validation rules for patient data:PatientValidator.java:6-29
- Patients must be at least 18 years old
- CPF must be exactly 11 digits
- Date of birth cannot be in the future
Updating Patient Information
Patients can update their profile with validation enforcement.PatientService.java:51-71
PUT /patients/update/{cpf}
Querying Patients
Get Patient by CPF
PatientService.java:43-45
GET /patients/{cpf}
Get All Patients
PatientService.java:47-49
GET /patients/list
Deleting Patients
PatientService.java:74-80
DELETE /patients/delete/{cpf}
Patient Medical History Tracking
Patients have a one-to-many relationship with consultations, enabling complete history tracking:Patient.java:34-36
- Viewing all past consultations for a patient
- Tracking diagnoses across multiple visits
- Analyzing treatment patterns over time
Search and Filtering
The repository supports multiple search strategies:Patient Registration Flow
Security Considerations
- Password Hashing: All passwords are hashed using BCrypt before storage
- Unique Constraints: Both CPF and email must be unique
- Validation: Strict validation on CPF format and age requirements
- Lazy Loading: Consultation history is lazily loaded to improve performance
- JSON Ignore: Password field should be ignored in API responses (security best practice)
Data Storage
Patient Information Stored:- Personal identification (CPF, name)
- Contact information (email, address)
- Date of birth and calculated age
- Complete medical history
- Encrypted password for authentication
- Linked consultation records
Best Practices
- Always validate patient data before saving
- Never return password hashes in API responses
- Use CPF as the primary identifier for consistency
- Validate age requirement (18+) during registration and updates
- Store medical history as text for flexibility
- Implement cascade deletion carefully to preserve medical records