A FastAPI-based application for managing patient information and medical notes with AI-powered analysis and summary generation using Google's Gemini API.
ASC Health is a comprehensive medical records system that enables healthcare providers to:
- Manage Patients: Create, read, update, and delete patient records with demographic information
- Store Medical Notes: Upload and store medical notes in various formats (text, documents, etc.)
- Extract SOAP Components: Automatically extract Subjective, Objective, Assessment, and Plan (SOAP) components from medical notes using AI
- Generate Summaries: Create AI-powered summaries of patient medical histories tailored to specific audiences
- Track Processing Status: Monitor the status of note processing (created, success, error)
- 🏥 Patient Management: Full CRUD operations with filtering and sorting capabilities
- 📝 Medical Notes: Support for multiple file formats and plain text input
- 🤖 AI-Powered Analysis: Leverages Google's Gemini API for intelligent note extraction
- 📊 SOAP Format Support: Automatic extraction of SOAP components from clinical notes
- 🔍 Advanced Search: Filter patients by name and date of birth
- 📄 Pagination: Efficient handling of large datasets
- 📱 RESTful API: Comprehensive API with Swagger/OpenAPI documentation
- Docker and Docker Compose
- Google Gemini API Key
- Python 3.12+ (for local development)
git clone <repository-url>
cd aschealthCreate a .env file in the project root with your Gemini API key:
GEMINI_API_KEY=your_gemini_api_key_here
GEMINI_MODEL=gemini-3-flash-preview
ENVIRONMENT=localStart the entire application stack (API + PostgreSQL) with a single command:
docker-compose up -dThis will:
- Build the FastAPI application Docker image
- Start the PostgreSQL database
- Initialize the database with schema and seed data
- Expose the API on
http://localhost:8000 - Expose PostgreSQL on
localhost:5432
Once the application is running, open your browser and navigate to:
http://localhost:8000/docs
You'll see the interactive Swagger UI where you can:
- View all available endpoints
- Test API operations directly
- See request/response schemas
- Try out different parameters
For an alternative API documentation view, visit:
http://localhost:8000/redoc
Retrieve all patients with pagination, filtering, and sorting
Query Parameters:
offset(int): Number of records to skip (default: 0)limit(int): Maximum records to return (default: 100, max: 100)filter_name(string): Filter by patient name (case-insensitive)filter_birth_date(date): Filter by birth datesort_by(string): Sort field (id, name, birth_date)descending(bool): Sort in descending order
Example:
curl "http://localhost:8000/patients?limit=10&filter_name=Diego&sort_by=name"Get a specific patient by ID
Create a new patient
Request Body:
{
"name": "John Doe",
"birth_date": "1990-01-15"
}Update an existing patient
Delete a patient
Create a new medical note for a patient
Supports:
- File upload:
multipart/form-datawith file - Plain text:
text/plainin request body
Optional Parameters:
noted_at(datetime): Timestamp for the note (defaults to current UTC time)
Example (Text):
curl -X POST "http://localhost:8000/patients/1/notes" \
-H "Content-Type: text/plain" \
-d "SOAP Note content here..."Example (File):
curl -X POST "http://localhost:8000/patients/1/notes" \
-F "file=@note.txt"Retrieve all notes for a patient
Delete a specific note
Generate an AI-powered summary of patient's medical history
Query Parameters:
audience(string): Target audience for the summary (e.g., "medical students", "patients")verbose(bool): Generate more detailed summary
Example:
curl "http://localhost:8000/patients/1/summary?audience=medical%20students&verbose=true"Root endpoint
Response:
ASC Health
Health check endpoint
Response:
{
"status": "OK"
}Prometheus metrics endpoint
Exposes application metrics in Prometheus format for monitoring and alerting.
Metrics Tracked:
- Request count by method, path, and status code
- Request latency/duration (histogram)
- Request size and response size
- HTTP exceptions
Response Format:
# HELP http_requests_total Total HTTP requests
# TYPE http_requests_total counter
http_requests_total{method="GET",path="/patients",status_code="200"} 42.0
# HELP http_request_duration_seconds HTTP request latency in seconds
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{le="0.005",method="GET",path="/patients"} 5.0
...
Example Usage with Curl:
curl http://localhost:8000/metrics-
Navigate to Swagger: Open
http://localhost:8000/docs -
Expand an Endpoint: Click on any endpoint to expand its details
-
Try It Out: Click the "Try it out" button
-
Fill in Parameters: Enter required path, query, or body parameters
-
Execute: Click "Execute" to send the request
-
View Response: See the response status code, headers, and body
-
Create a Patient:
- Open POST /patients
- Click "Try it out"
- Enter patient data:
{ "name": "Jane Smith", "birth_date": "1985-06-20" } - Click Execute
- Note the returned patient ID
-
Upload a Medical Note:
- Open POST /patients/{patient_id}/notes
- Replace
{patient_id}with the ID from step 1 - Click "Try it out"
- Enter note content or upload a file
- Click Execute
-
Generate Summary:
- Open GET /patients/{patient_id}/summary
- Replace
{patient_id}with the patient ID - Optionally set
audienceandverboseparameters - Click Execute
Install dependencies with PDM:
pdm installpdm run pytestpdm run ruff check .
pdm run black .ASC Health includes built-in Prometheus instrumentation through prometheus-fastapi-instrumentator. This automatically tracks and exposes application metrics.
The application automatically collects the following metrics:
- HTTP Requests: Total requests by method, path, and status code
- Request Duration: Latency distribution (histogram) for all endpoints
- Request/Response Size: Request and response body sizes
- HTTP Exceptions: Tracking of errors and exceptions
Prometheus metrics are exposed at the /metrics endpoint:
curl http://localhost:8000/metricsTo scrape and visualize metrics, you can run Prometheus alongside ASC Health.
Add to docker-compose.yml:
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'Create prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'aschealth'
static_configs:
- targets: ['localhost:8000']
metrics_path: '/metrics'Once Prometheus is running, access the dashboard at:
http://localhost:9090
Example Queries:
# Total requests per endpoint
rate(http_requests_total[5m])
# Average request duration per endpoint
rate(http_request_duration_seconds_sum[5m]) / rate(http_requests_total[5m])
# Error rate
rate(http_requests_total{status_code=~"5.."}[5m])
# Requests per second
rate(http_requests_total[1m])
For advanced visualization, connect Prometheus as a data source to Grafana:
- Add Prometheus data source:
http://prometheus:9090 - Create dashboards to visualize:
- Request rates and latency
- Error rates
- API endpoint performance
- System health metrics
Install dependencies with PDM:
pdm installpdm run pytestpdm run ruff check .
pdm run black .aschealth/
├── controllers/ # API endpoint handlers
│ ├── infra.py # Health check endpoints
│ └── patients.py # Patient and note management
├── model/ # Database models
│ ├── patient.py # Patient entity
│ └── note.py # Medical note entity
├── dtos/ # Data transfer objects
│ ├── patient.py # Patient request/response models
│ ├── note.py # Note request/response models
│ └── infra.py # Infrastructure models
├── dependencies/ # Dependency injection
│ ├── api.py # API dependencies (GenAI client)
│ └── datasource.py # Database dependencies
├── config.py # Application configuration
└── main.py # FastAPI app initialization
init_db/
├── schema.sql # Database schema
└── seed.sql # Sample data
tests/
├── controllers/ # API endpoint tests
├── test_factories/ # Test data factories
└── conftest.py # Pytest configuration
Check Docker logs:
docker-compose logs api
docker-compose logs postgresEnsure postgres-data directory has correct permissions:
chmod -R 755 postgres-data/Verify the database is running:
docker-compose psIf needed, restart the services:
docker-compose down
docker-compose up -dVerify your API key:
- Check
.envfile has correct key format - Ensure API is enabled in Google Cloud Console
- Verify account has sufficient quota
| Variable | Description | Default |
|---|---|---|
GEMINI_API_KEY |
Google Gemini API Key | Required |
GEMINI_MODEL |
Gemini model to use | gemini-3-flash-preview |
ENVIRONMENT |
Deployment environment | local |
DATABASE_DSN |
PostgreSQL connection string | Auto-configured |
{
"id": 1,
"name": "John Doe",
"birth_date": "1990-01-15"
}{
"total": 5,
"items": [
{
"id": 1,
"name": "John Doe",
"birth_date": "1990-01-15"
}
]
}{
"id": 1,
"patient_id": 1,
"status": "CREATED",
"noted_at_utc": "2024-01-15T10:30:00",
"note": null,
"subjective": null,
"objective": null,
"assessment": null,
"plan": null
}{
"id": 1,
"name": "John Doe",
"birth_date": "1990-01-15",
"summary": "Patient has a history of hypertension and is currently on statin therapy..."
}docker-compose logs -f api
docker-compose logs -f postgresdocker-compose downdocker-compose down -vdocker-compose restartAccess PostgreSQL directly (if needed):
docker-compose exec postgres psql -U aschealth -d aschealthCommon commands:
-- List all patients
SELECT * FROM patient;
-- List all notes
SELECT * FROM note;
-- Get notes for a specific patient
SELECT * FROM note WHERE patient_id = 1;When contributing to ASC Health:
- Add comprehensive docstrings to all functions and classes
- Include unit tests for new features
- Update this README with any new endpoints or features
- Follow the existing code style and structure
This project is part of the ASC Health system.
For issues or questions, please check the Docker logs and verify your environment setup:
docker-compose logs