API to check healthcare professionals' eligibility for TEMFC, using CNES data scraping, automatic validation, and real-time response via SSE.
🔗 Production URL: https://temfc-backend.onrender.com
Determine if a professional is eligible for TEMFC by analyzing their CNES links, based on complex rules like contract type, CBO, schedule, and establishment type.
- Flask + Gunicorn
- Web Scraping with Selenium + Chrome Headless
- Server-Sent Events (SSE)
- PostgreSQL (Tembo Cloud)
- Docker
- GitHub Actions (CI/CD)
- Automated testing with Pytest
- ✅ REST API accepting CPF and name
- ⏳ Real-time response using SSE
- 🧪 Unit and integration tests with Pytest marks
- 🐳 Fully Dockerized
- 📄 Automatic scraping and parsing of professional records
- 🔍 Validations: CBO, contract type, facility type, working hours
- 📈 CI/CD with automatic deploy to Render
TEMFC-backend/
├── src/
│ ├── app.py
│ ├── config/
│ ├── core/
│ ├── errors/
│ ├── interfaces/
│ ├── repositories/
│ ├── routes/
│ ├── utils/
├── tests/
├── .env.example
├── Dockerfile
├── pytest.ini
├── requirements.txt
├── README.md
└── .github/workflows/cd.yml
- Python 3.11+
- Google Chrome installed
- PostgreSQL running (Tembo or local)
git clone https://github.com/victortsrodrigues/TEMFC-backend.git
cd TEMFC-backend
Create a .env
file:
DB_HOST=your_host
DB_PORT=5432
DB_NAME=postgres
DB_USER=postgres
DB_PASSWORD=your_secure_password
.env
. Add it to .gitignore
.
pip install -r requirements.txt
python src/main.py
Then open: http://localhost:5000
docker build -t temfc-backend .
docker run --rm -p 5000:5000 --shm-size="256mb" --env-file .env temfc-backend
python -m pytest -m unit
python -m pytest -m integration
Tests are marked with @pytest.mark.unit
and @pytest.mark.integration
.
Full CI/CD pipeline:
- Runs unit and integration tests
- Builds and pushes Docker image
- Triggers deploy via Render Deploy Hook
Pipeline file: .github/workflows/ci-cd.yml
POST /
with CPF and name- Launches CNES scraping using Selenium
- Parses and validates data based on TEMFC rules
- Sends result back in real-time using SSE
- Compatible CBO (e.g., 2231XX)
- Minimum weekly working hours
- Valid establishment type
- Valid month overlap
{
"name": "Random Professional",
"valid_months": 48,
"status": "ELIGIBLE",
"pending_months": 0,
"details": {
"semesters_40": 8,
"semesters_30": 0,
"semesters_20": 0
}
}
{
"name": "Another Random Professional",
"valid_months": 44,
"status": "NOT ELIGIBLE",
"pending_months": 4,
"details": {
"semesters_40": 7,
"semesters_30": 0,
"semesters_20": 0
}
}
Pull requests are welcome!
For major changes, please open an issue first to discuss what you'd like to change.
To contribute:
- Fork the repository
- Create a feature branch
- Commit your changes with clear messages
- Ensure tests are included if applicable
- Open a pull request
MIT © Victor Rodrigues