Metadata-Version: 2.4
Name: raxtik-synth
Version: 0.1.0
Summary: Synthetic pharmacovigilance (PV) data generation infrastructure for CIOMS, MedWatch, and ICH E2B adverse event safety cases.
Author: Prateek Dagar
License: AGPL-3.0-only
Project-URL: Homepage, https://github.com/raxtik-org/raxtik-synth
Project-URL: Documentation, https://raxtik-synth.readthedocs.io/
Project-URL: Repository, https://github.com/raxtik-org/raxtik-synth.git
Project-URL: Issues, https://github.com/raxtik-org/raxtik-synth/issues
Project-URL: Changelog, https://github.com/raxtik-org/raxtik-synth/blob/main/CHANGELOG.md
Keywords: pharmacovigilance,synthetic-data,adverse-events,cioms,cioms-1,medwatch,medwatch-3500a,ich-e2b,e2b-r3,drug-safety,clinical-safety,faers,icsr,healthcare-ai,ocr,nlp
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.1.7
Requires-Dist: pydantic>=2.0.0
Requires-Dist: faker>=26.0.0
Requires-Dist: pandas>=2.0.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: openpyxl>=3.1.5
Requires-Dist: pycountry>=24.6.1
Provides-Extra: faers
Requires-Dist: raxtik-etl>=0.1.0; python_version >= "3.11" and extra == "faers"
Dynamic: license-file

# Raxtik Synth

[![CI](https://github.com/raxtik-org/raxtik-synth/actions/workflows/ci.yml/badge.svg)](https://github.com/raxtik-org/raxtik-synth/actions/workflows/ci.yml)
[![Docs](https://img.shields.io/badge/docs-ReadTheDocs-blue.svg)](https://raxtik-synth.readthedocs.io/)
[![codecov](https://codecov.io/gh/raxtik-org/raxtik-synth/branch/main/graph/badge.svg)](https://codecov.io/gh/raxtik-org/raxtik-synth)
[![PyPI version](https://img.shields.io/pypi/v/raxtik-synth.svg)](https://pypi.org/project/raxtik-synth/)
[![Python Versions](https://img.shields.io/pypi/pyversions/raxtik-synth.svg)](https://pypi.org/project/raxtik-synth/)
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)

`raxtik-synth` is an open-source Python library for generating realistic synthetic pharmacovigilance (PV) data. It provides structured adverse-event cases, patient demographics, medicinal products, clinical reactions, reporters, outcomes, and unstructured narratives for developing, testing, and evaluating safety systems.

The generated datasets are **synthetic and privacy-preserving by design**, enabling robust pipeline development, model benchmarking, and QA without dealing with sensitive Protected Health Information (PHI).

---

## 🎯 Use Cases

* **Pharmacovigilance Pipeline Testing:** Simulate complete safety datasets for end-to-end ingestion, validation, and analytics pipeline verification.
* **Regulatory Form Generation (Downstream):** Provide rich, schema-valid synthetic cases to document renderers (such as `raxtik-forms`) to test layout boundaries and overflow handling on standard CIOMS I and MedWatch 3500A documents.
* **AI & Document Extraction Benchmarking:** Train and evaluate OCR, Document Layout Analysis, and LLM-based structured data extraction models on diverse synthetic medical scenarios.
* **Empirical Data Grounding:** Seed synthetic cases with authentic co-occurrence patterns, dosages, and outcomes sampled from FDA FAERS safety data via `raxtik-etl`.

---

## 🛠️ Project Structure

```text
raxtik-synth/
├── pyproject.toml         # Package definition and dependencies
├── README.md              # Project documentation
├── src/
│   └── raxtik_synth/
│       ├── __init__.py
│       ├── cli.py         # Command-line interface to generate datasets
│       ├── generators/    # Domain generators (patient, drug, event, narrative, reporter)
│       ├── models/        # Pydantic data models (BFC/E2B aligned)
│       └── sources/       # Empirical data sources (FAERS via raxtik-etl)
└── tests/                 # Unit and integration test suites
```

---

## 📦 Installation

### Core Package

Install `raxtik-synth` using pip:

```bash
pip install raxtik-synth
```

Or using `uv`:

```bash
uv pip install raxtik-synth
```

### Optional FAERS Integration

To enable empirical case sampling grounded in FDA FAERS datasets:

```bash
pip install "raxtik-synth[faers]"
```

For local development in editable mode:

```bash
pip install -e ".[faers]"
```

---

## 💻 Command-Line Interface (CLI)

Generate synthetic safety cases directly from the terminal:

```bash
# Print a single case to stdout
raxtik-synth

# Generate 10 reproducible cases and export to JSON
raxtik-synth --count 10 --seed 42 --output cases.json

# Generate line-delimited JSON (JSONL) for bulk streaming / ML training
raxtik-synth -n 100 -s 42 -o dataset.jsonl
```

---

## 🚀 Basic Python Usage

```python
from raxtik_synth.generators import CaseGenerator

# Generate a reproducible adverse event case payload
generator = CaseGenerator(seed=42)
case = generator.generate_case()

print(case.model_dump_json(indent=2))
```

---

## 🧬 Regulatory & Clinical Data Models (E2B-Aligned)

`raxtik-synth` implements **E2B(R2/R3)-aligned synthetic data models** informed by the **Backward and Forward Compatibility (BFC v2.02)** specification covering **CIOMS I**, **FDA Form 3500A (MedWatch)**, and **ICH E2B (R2/R3)**:

* **Patient (`Patient`)**: Demographics, explicit **CIOMS Box 2 Initials** (`initials`), death details, and pre-existing conditions (`medical_history`).
* **Products (`Product`)**: Suspect and concomitant medications, indications, dosage regimens, routes, lot numbers, and therapy dates.
* **Reactions (`Reaction` & `SeriousnessCriteria`)**: MedDRA Preferred Terms (PT), Lower Level Terms (LLT), onset dates, dechallenge/rechallenge outcomes, and ICH seriousness criteria.
* **Laboratory Investigations (`LabTest`)**: CIOMS Box 12 / E2B Section F.r test results, reference ranges (`normal_low`, `normal_high`), units, and clinical comments.
* **Clinical Context**:
  * **`ParentInfo`** (Section D.10): For parent-child / in-utero exposure reports.
  * **`StudyInfo`** (Section C.5): Clinical study protocols, phases, and sponsor numbers.
  * **`DeviceDetails`** (Section G.k): Medical devices and drug-device combination products.
  * **`CausalityAssessment`** (Section G.k.9.i.2.r): Drug-event causality determinations (e.g. WHO-UMC).
* **Clinical Narrative (`CaseNarrative`)**: Unstructured case narrative text and structured medical history items (`MedicalHistoryItem` for CIOMS Box 13).

---

## ⚡ Integration with `raxtik-etl` (FDA FAERS Data)

`raxtik-synth` supports optional empirical data integration through **`raxtik-etl`**, enabling synthetic PV datasets informed by real-world FAERS distributions:

```python
# Optional empirical data integration through raxtik-etl
try:
    from raxtik_synth.sources.faers import FAERSSource

    # Initialize data source grounded in empirical FAERS package
    source = FAERSSource(period="2004Q1")
    # case = source.generate_case()
except (ImportError, FileNotFoundError):
    pass
```

Interactive demonstrations and benchmarks are available in [`notebooks/raxtik_faers_integration_demo.ipynb`](notebooks/raxtik_faers_integration_demo.ipynb).


---

## 👥 Contributors

Contributions are welcome! Please see [contributor.md](contributor.md) for the list of people who have contributed to this project.
