- Install dependencies:
pip install -r requirements.txt- Set up API keys (for hospital payment plan features):
# Copy the example environment file
cp .env.example .env
# Edit .env and add your API keys:
# - Get SerpApi key at https://serpapi.com/ (100 free searches/month)Start the development server:
python app.pyThe API will be available at http://localhost:5000
- GET
/health- Check API status
- GET
/api/items- Get all items - GET
/api/items/<id>- Get a specific item - POST
/api/items- Create a new item - PUT
/api/items/<id>- Update an item - DELETE
/api/items/<id>- Delete an item
- POST
/api/hospital/payment-plans- Search for hospital payment plan documents
- POST
/api/insurance/extract- Extract structured data from a base64-encoded insurance ID image
curl http://localhost:5000/api/itemscurl -X POST http://localhost:5000/api/items \
-H "Content-Type: application/json" \
-d '{"name": "My Item", "description": "Item description"}'curl -X PUT http://localhost:5000/api/items/1 \
-H "Content-Type: application/json" \
-d '{"name": "Updated Name"}'curl -X DELETE http://localhost:5000/api/items/1curl -X POST http://localhost:5000/api/insurance/extract \
-H "Content-Type: application/json" \
-d '{
"image_base64": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ..."
}'Response:
{
"member_name": "JOHN DOE",
"member_id": "XYZ123456789",
"group_number": "987654",
"insurer_name": "Blue Cross Blue Shield",
"plan_name": "PPO Silver",
"deductible": "$1,000 IND / $2,000 FAM",
"oopm": "$4,000 IND / $8,000 FAM",
"rx_bin": "610014",
"rx_pcn": "BCBS",
"rx_group": "RX1234",
"...": "..."
}curl -X POST http://localhost:5000/api/hospital/payment-plans \
-H "Content-Type: application/json" \
-d '{
"hospital_name": "Cleveland Clinic",
"limit": 10
}'Response:
{
"success": true,
"hospital_name": "Cleveland Clinic",
"results_found": 10,
"results": [
{
"hospital_name": "Cleveland Clinic",
"title": "Financial Assistance Application",
"url": "https://my.clevelandclinic.org/...",
"description": "Apply for financial assistance...",
"document_type": "pdf"
}
]
}curl -X POST http://localhost:5000/api/hospital/payment-plans \
-H "Content-Type: application/json" \
-d '{
"hospital_name": "Johns Hopkins",
"limit": 10,
"serp_api_key": "your_serpapi_key_here"
}'- ✅ Full CRUD operations (Items API)
- ✅ JSON request/response handling
- ✅ Error handling with proper HTTP status codes
- ✅ Input validation
- ✅ Decorators for common patterns
- ✅ Health check endpoint
- ✅ In-memory storage (for demo - replace with a database)
- ✅ Well-organized and commented code
- ✅ Automated document discovery - Uses SerpApi to search Google for payment plan PDFs and webpages
- ✅ Smart search queries - Targets payment plans, financial assistance, charity care documents
- ✅ Structured output - Returns hospital name, URL, document type, description
- ✅ API key management - Supports environment variables or request-level API keys
- ✅ US hospital focus - Configured for US-based hospital searches
- ✅ Free tier compatible - Works with free SerpApi (100 searches/month)
1. User Request → Flask API
↓
2. SerpApi Search → Google results for hospital + "payment plan" / "financial assistance"
↓
3. Return Structured JSON → Hospital name, URLs, document types, descriptions
app.py- Flask API with endpoints for items, hospital payment plans, and insurance extractionvision_ocr_api.py- Module for insurance extraction using Groq's vision LLMpayment_plan.py- Core module withHospitalPaymentPlanFinderclassrequirements.txt- Python dependencies.env- API keys (create from.env.example)FLASK_API_GUIDE.md- This guide
- Visit https://serpapi.com/
- Sign up for free account (100 searches/month)
- Copy your API key
- Add to
.env:SERP_API_KEY=your_key_here
- Visit https://console.groq.com/
- Sign up and create an API key
- Add to
.env:GROQ_API_KEY=your_key_here
import requests
response = requests.post(
'http://localhost:5000/api/hospital/payment-plans',
json={
'hospital_name': 'Stanford Health Care',
'limit': 10
}
)
data = response.json()
print(f"Found {data['results_found']} results")
for result in data['results']:
print(f"\nTitle: {result['title']}")
print(f"URL: {result['url']}")
print(f"Type: {result['document_type']}")
print(f"Description: {result['description']}")# Run the payment_plan.py module directly
python payment_plan.py "Massachusetts General Hospital"- Replace in-memory storage with a database (SQLAlchemy + SQLite/PostgreSQL)
- Add authentication/authorization (JWT tokens, OAuth)
- Add logging (Python logging module or cloud logging)
- Add input validation with Marshmallow or Pydantic
- Add tests with pytest
- Deploy to production with Gunicorn + Nginx
- Database storage - Cache search results to reduce API calls
- Batch processing - Queue multiple hospitals for processing
- Document extraction - Add PDF and webpage content extraction for detailed analysis
- Advanced analysis - Use NLP/LLMs to extract specific payment terms, eligibility criteria
- Dashboard - Create front-end to browse and compare hospital payment plans
- Notifications - Alert when new payment plan documents are published
- Export options - Generate CSV/Excel reports of payment plan comparisons
- State/region filtering - Search hospitals by geographic area
- Document versioning - Track changes to payment policies over time
- Ensure
.envfile exists withSERP_API_KEY=your_key - Or pass
serp_api_keyin the request JSON
- SerpApi free tier: 100 searches/month (4 queries per hospital × 25 hospitals max)
- Wait until next month or upgrade plan
- Run
pip install -r requirements.txt - Ensure you're in the correct virtual environment
# Install gunicorn
pip install gunicorn
# Run with 4 worker processes
gunicorn -w 4 -b 0.0.0.0:5000 app:appFROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "app:app"]# Set debug to False
export FLASK_ENV=production
# Set API keys
export SERP_API_KEY=your_production_key
# Optional: Set rate limiting
export MAX_REQUESTS_PER_MINUTE=60This Flask API template includes:
- SerpApi integration for Google search results
Built for finding hospital payment plan documents to improve healthcare price transparency.