An enterprise-grade, document processing microservice built natively with FastAPI and AWS Bedrock Data Automation (BDA). This system automates the ingestion, validation, and structured entity extraction of unstructured Medical Intake Forms (PDFs) stored securely in Amazon S3, converting raw files into validated, schema-compliant JSON payloads.
In healthcare administration, manually reviewing and processing patient intake forms, insurance documents, and medical histories introduces severe operational bottlenecks and human error.
This microservice provides an end-to-end automated solution:
- Ingestion: Securely reference medical intake documents deposited in Amazon S3 buckets.
- AI-Powered Extraction: Leverages AWS Bedrock Data Automation using highly specific clinical data blueprints.
- Structured Outputs: Automatically parses unstructured form text into machine-readable JSON containing patient demographics, insurance identifiers, and historical clinical data, reducing administrative processing cycle times by up to 85%.
This project strictly adheres to a 3-Tier Layered Clean Architecture pattern to ensure complete decoupling of network protocols, business workflows, and external infrastructure clients.
graph TD
Client[HTTP POST /process] --> Route[routes/routed.py]
Route -->|Validates Pydantic Request| Service[services/service.py]
Service -->|Workflow Orchestration| ClientLayer[client/client.py]
ClientLayer -->|boto3 Control Plane| AWS_BDA[AWS Bedrock Blueprints]
ClientLayer -->|boto3 Runtime Plane| AWS_BDA_Runtime[AWS BDA Execution Engine]
ClientLayer -->|boto3 Storage Plane| AWS_S3[(Amazon S3 Storage)]
Utilizes Astral's uv, a fast Python package installer and resolver, replacing standard pip workflows. This ensures deterministic, rapid workspace initialization and sub-second dependency tree compilations for deployment pipelines.
Leverages FastAPI's asynchronous design and native Pydantic integration to enforce strict request-response data validation contracts. This guarantees that inbound S3 URIs are well-formed before hitting downstream infrastructure, while self-documenting the entire API via interactive OpenAPI/Swagger docs.
The service layer implements conflict recovery when handling underlying cloud assets. If multi-tenant instances trigger concurrent execution requests, the system traps AWS ConflictException signatures and dynamically cascades to lookup fallbacks, guaranteeing zero workflow downtime.
- Python 3.10+
- uv installed (
curl -LsSf https://astral.sh/uv/install.sh | shorbrew install uv) - AWS Account with explicit permissions for
bedrock-data-automationands3operations
Clone the repository:
git clone https://github.com/dharaneedharan-v/BDA
cd BDA Create a virtual environment and install dependencies using uv:
# Creates .venv and installs requirements dynamically at lightning speed
uv venv
source .venv/bin/activate # On Windows use: .venv\Scripts\activate
uv pip install -r requirements.txtConfigure your environment variables (.env):
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_DEFAULT_REGION=us-east-1Spin up the development server:
uv run main.pyThe interactive API documentation will be available at:
http://127.0.0.1:8000/docs
Endpoint
POST /api/v1/processContent-Type
application/json
{
"s3_uri": "s3://your-healthcare-bucket/intakes/patient_intake_04.pdf"
}{
"status": "success",
"data": "{\n \"patient_name\": \"Jane Doe\",\n \"date_of_birth\": \"1992-08-24\",\n \"medical_history\": \"NKA, Hypertension managed with Lisinopril\",\n \"insurance_provider\": \"Blue Cross Blue Shield\",\n \"policy_number\": \"XEH98471023\"\n}"
}BDA
├─── src
│ ├─── client
│ │ └─── client_bda.py
│ ├─── migrations
│ │ ├─── factory
│ │ │ └─── factory.py
│ │ ├─── __init__.py
│ │ ├─── create_tables.py
│ │ └─── seeder.py
│ ├─── models
│ │ ├─── __init__.py
│ │ └─── models.py
│ ├─── repositories
│ │ ├─── schema
│ │ │ └─── schema.py
│ │ ├─── __init__.py
│ │ ├─── Database.py
│ │ └─── repository.py
│ ├─── routes
│ │ ├─── __init__.py
│ │ └─── routes.py
│ ├─── services
│ │ ├─── __init__.py
│ │ └─── service.py
│ ├─── utils
│ │ ├─── exceptions
│ │ │ ├─── custom_exception.py
│ │ │ ├─── error_code.py
│ │ │ ├─── error.py
│ │ │ └─── global_exception.py
│ │ ├─── logger
│ │ │ └─── log.py
│ │ ├─── __init__.py
│ │ └─── helpers.py
│ ├─── __init__.py
│ └─── settings.py
├─── .env.local
├─── .gitignore
├─── .python-version
├─── folder.py
├─── main.py
├─── pyproject.toml
├─── README.md
└─── requirements.txt