Introduction
The Med Agenda API is a RESTful web service that provides comprehensive medical consultation management capabilities. It enables seamless integration for scheduling appointments, managing patient records, doctor profiles, diagnoses, and administrative functions.Base URL
The API is accessible at the following base URL:SERVER_PORT environment variable.
API Architecture
RESTful Design
The Med Agenda API follows REST (Representational State Transfer) architectural principles:- Resource-based: Each endpoint represents a specific resource (patients, doctors, consultations, etc.)
- HTTP Methods: Standard HTTP methods (GET, POST, PUT, DELETE) for CRUD operations
- Stateless: Each request contains all information needed to process it
- Uniform Interface: Consistent naming conventions and response structures
Response Format
All API responses are returned in JSON format with appropriate HTTP status codes.Success Response Example
Error Response Example
HTTP Status Codes
The API uses standard HTTP status codes to indicate the success or failure of requests:| Status Code | Description |
|---|---|
200 OK | Request successful, resource returned or operation completed |
201 Created | Resource successfully created |
204 No Content | Request successful, no content to return |
400 Bad Request | Invalid request parameters or missing required fields |
401 Unauthorized | Authentication failed - invalid credentials |
404 Not Found | Requested resource does not exist |
500 Internal Server Error | Server encountered an unexpected error |
Error Handling
The API implements consistent error handling across all endpoints:Authentication Errors
When login credentials are invalid, the API returns a401 Unauthorized status:
Resource Not Found
When a requested resource doesn’t exist, the API returns a404 Not Found status:
Validation Errors
For invalid or incomplete data, the API returns a400 Bad Request status:
Security Configuration
The Med Agenda API implements the following security measures:- Password Encryption: All passwords are encrypted using BCrypt hashing algorithm
- CORS Protection: Cross-Origin Resource Sharing is configured to allow requests from authorized origins:
http://localhost:5173(development)https://final-project-poo2.vercel.app(production)
- CSRF Protection: Disabled for API endpoints to support stateless authentication
- Database Security: PostgreSQL database with SSL support
Available Endpoints
The Med Agenda API provides the following resource endpoints:Authentication
- POST
/admin/login- Admin authentication - POST
/patients/login- Patient authentication - POST
/doctor/login- Doctor authentication
Patient Management
- POST
/patients/create- Create new patient - GET
/patients/{cpf}- Get patient by CPF - GET
/patients/list- List all patients - PUT
/patients/update/{cpf}- Update patient information - DELETE
/patients/delete/{cpf}- Delete patient
Doctor Management
- POST
/doctor/create- Create new doctor - GET
/doctor- List all doctors - GET
/doctor/search- Search doctors by various criteria - GET
/doctor/consultations/{crm}- Get doctor’s consultation schedule - PUT
/doctor/{crm}- Update doctor information - DELETE
/doctor/{crm}- Delete doctor
Consultation Management
- POST
/consultations/create- Schedule new consultation - GET
/consultations/{id}- Get consultation by ID - GET
/consultations/all- List all consultations - GET
/consultations/patient-history/{cpf}- Get patient’s consultation history - PUT
/consultations/update- Update consultation details - DELETE
/consultations/{id}- Cancel consultation
Diagnosis Management
- POST
/diagnosis- Create diagnosis for consultation - GET
/diagnosis/consultation/{id}- Get diagnosis by consultation ID
Admin Management
- POST
/admin/create- Create new admin user - GET
/admin/{id}- Get admin by ID - DELETE
/admin/{id}- Delete admin user
CID Management
- GET
/cid- List all CID codes - GET
/cid/{code}- Get specific CID code - POST
/cid/refresh- Refresh CID database from DATASUS - POST
/cid/refresh-local- Load CID codes from local file - DELETE
/cid/{code}- Delete specific CID code - DELETE
/cid- Delete all CID codes
Health News
- GET
/api/news- Get latest health news articles
AI Assistant
- POST
/api/chat- Chat with AI assistant (auto-context) - POST
/api/chat/with-context- Chat with full medical knowledge base
Database Configuration
The API connects to a PostgreSQL database with the following default configuration:- Host:
localhost:5432 - Database:
postgres - SSL Mode: Disabled for local development
- Connection Pool: Maximum 10 connections
- Hibernate DDL: Auto-update schema
Rate Limiting
Currently, the API does not implement rate limiting. All authenticated requests are processed without throttling.For production deployments, consider implementing rate limiting to prevent abuse and ensure fair resource allocation.
Content Type
All requests and responses useapplication/json content type unless otherwise specified. Ensure your requests include the appropriate Content-Type header:
Next Steps
Authentication
Learn how to authenticate users and manage sessions
Patient API
Manage patient records and medical history
Doctor API
Manage doctor profiles and schedules
Consultations
Schedule and manage medical consultations