raxtik-source-faers 0.1.0.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. raxtik_source_faers/__init__.py +75 -0
  2. raxtik_source_faers/_version.py +1 -0
  3. raxtik_source_faers/adapter.py +412 -0
  4. raxtik_source_faers/builder.py +51 -0
  5. raxtik_source_faers/client.py +134 -0
  6. raxtik_source_faers/constants.py +67 -0
  7. raxtik_source_faers/fetcher.py +141 -0
  8. raxtik_source_faers/mappings/common.py +99 -0
  9. raxtik_source_faers/mappings/s1_legacy.py +292 -0
  10. raxtik_source_faers/mappings/s2_migration.py +255 -0
  11. raxtik_source_faers/mappings/s3_modern.py +256 -0
  12. raxtik_source_faers/parser.py +69 -0
  13. raxtik_source_faers/reference/__init__.py +43 -0
  14. raxtik_source_faers/reference/age_groups.py +76 -0
  15. raxtik_source_faers/reference/age_units.py +76 -0
  16. raxtik_source_faers/reference/countries.py +2828 -0
  17. raxtik_source_faers/reference/cumulative_dose_units.py +716 -0
  18. raxtik_source_faers/reference/dechallenge.py +54 -0
  19. raxtik_source_faers/reference/dose_frequencies.py +263 -0
  20. raxtik_source_faers/reference/drug_name_sources.py +32 -0
  21. raxtik_source_faers/reference/duration_units.py +98 -0
  22. raxtik_source_faers/reference/occupations.py +65 -0
  23. raxtik_source_faers/reference/outcomes.py +87 -0
  24. raxtik_source_faers/reference/rechallenge.py +54 -0
  25. raxtik_source_faers/reference/report_sources.py +87 -0
  26. raxtik_source_faers/reference/report_types.py +65 -0
  27. raxtik_source_faers/reference/roles.py +99 -0
  28. raxtik_source_faers/reference/sex.py +46 -0
  29. raxtik_source_faers/reference/weight_units.py +43 -0
  30. raxtik_source_faers/signatures/resolver.py +101 -0
  31. raxtik_source_faers-0.1.0.dev1.dist-info/METADATA +214 -0
  32. raxtik_source_faers-0.1.0.dev1.dist-info/RECORD +35 -0
  33. raxtik_source_faers-0.1.0.dev1.dist-info/WHEEL +4 -0
  34. raxtik_source_faers-0.1.0.dev1.dist-info/entry_points.txt +5 -0
  35. raxtik_source_faers-0.1.0.dev1.dist-info/licenses/LICENSE +661 -0
@@ -0,0 +1,87 @@
1
+ """Official FDA Report Source Classifications (RPSR_COD)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import List
6
+
7
+ from raxtik_etl.reference.codes import ReferenceCodeEntry
8
+
9
+ FDA_REPORT_SOURCES_REFERENCE: List[ReferenceCodeEntry] = [
10
+ ReferenceCodeEntry(
11
+ "FGN",
12
+ "Foreign",
13
+ "Foreign regulatory agency or international report",
14
+ "FDA_CDER",
15
+ "FAERS_QDE_README",
16
+ "1.0.0",
17
+ "2004Q1",
18
+ None,
19
+ True,
20
+ ),
21
+ ReferenceCodeEntry(
22
+ "SDY",
23
+ "Clinical Study",
24
+ "Clinical trial or post-marketing surveillance study",
25
+ "FDA_CDER",
26
+ "FAERS_QDE_README",
27
+ "1.0.0",
28
+ "2004Q1",
29
+ None,
30
+ True,
31
+ ),
32
+ ReferenceCodeEntry(
33
+ "LIT",
34
+ "Literature",
35
+ "Published scientific journal or literature report",
36
+ "FDA_CDER",
37
+ "FAERS_QDE_README",
38
+ "1.0.0",
39
+ "2004Q1",
40
+ None,
41
+ True,
42
+ ),
43
+ ReferenceCodeEntry(
44
+ "HP",
45
+ "Health Professional",
46
+ "Voluntary report from physician, pharmacist, or healthcare worker",
47
+ "FDA_CDER",
48
+ "FAERS_QDE_README",
49
+ "1.0.0",
50
+ "2004Q1",
51
+ None,
52
+ True,
53
+ ),
54
+ ReferenceCodeEntry(
55
+ "CSM",
56
+ "Consumer",
57
+ "Voluntary report from consumer, patient, or family member",
58
+ "FDA_CDER",
59
+ "FAERS_QDE_README",
60
+ "1.0.0",
61
+ "2004Q1",
62
+ None,
63
+ True,
64
+ ),
65
+ ReferenceCodeEntry(
66
+ "CR",
67
+ "Company Representative",
68
+ "Report submitted via manufacturer field representative",
69
+ "FDA_CDER",
70
+ "FAERS_QDE_README",
71
+ "1.0.0",
72
+ "2004Q1",
73
+ None,
74
+ True,
75
+ ),
76
+ ReferenceCodeEntry(
77
+ "UF",
78
+ "User Facility",
79
+ "Hospital, clinic, or healthcare facility report",
80
+ "FDA_CDER",
81
+ "FAERS_QDE_README",
82
+ "1.0.0",
83
+ "2004Q1",
84
+ None,
85
+ True,
86
+ ),
87
+ ]
@@ -0,0 +1,65 @@
1
+ """Official FDA Report Type Codes (REPT_COD)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import List
6
+
7
+ from raxtik_etl.reference.codes import ReferenceCodeEntry
8
+
9
+ FDA_REPORT_TYPES_REFERENCE: List[ReferenceCodeEntry] = [
10
+ ReferenceCodeEntry(
11
+ "EXP",
12
+ "Expedited (15-Day)",
13
+ "15-day expedited report submitted by manufacturer for serious, unexpected adverse events",
14
+ "FDA_CDER",
15
+ "FAERS_QDE_ASC_NTS",
16
+ "1.0.0",
17
+ "2004Q1",
18
+ None,
19
+ True,
20
+ ),
21
+ ReferenceCodeEntry(
22
+ "PER",
23
+ "Periodic",
24
+ "Periodic non-expedited safety report submitted by manufacturer under periodic reporting requirements",
25
+ "FDA_CDER",
26
+ "FAERS_QDE_ASC_NTS",
27
+ "1.0.0",
28
+ "2004Q1",
29
+ None,
30
+ True,
31
+ ),
32
+ ReferenceCodeEntry(
33
+ "DIR",
34
+ "Direct",
35
+ "Direct voluntary report submitted to FDA by healthcare professionals, consumers, or user facilities",
36
+ "FDA_CDER",
37
+ "FAERS_QDE_ASC_NTS",
38
+ "1.0.0",
39
+ "2004Q1",
40
+ None,
41
+ True,
42
+ ),
43
+ ReferenceCodeEntry(
44
+ "5DAY",
45
+ "5-Day (Combination Product)",
46
+ "5-day report submitted for drug-device combination products under 21 CFR Part 4",
47
+ "FDA_CDER",
48
+ "FAERS_QDE_ASC_NTS",
49
+ "1.0.0",
50
+ "2022Q3",
51
+ None,
52
+ True,
53
+ ),
54
+ ReferenceCodeEntry(
55
+ "30DAY",
56
+ "30-Day (Combination Product)",
57
+ "30-day report submitted for drug-device combination products under 21 CFR Part 4",
58
+ "FDA_CDER",
59
+ "FAERS_QDE_ASC_NTS",
60
+ "1.0.0",
61
+ "2022Q3",
62
+ None,
63
+ True,
64
+ ),
65
+ ]
@@ -0,0 +1,99 @@
1
+ """Official FDA Drug Role Codes (ROLE_COD)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import List
6
+
7
+ from raxtik_etl.reference.codes import ReferenceCodeEntry
8
+
9
+ FDA_ROLES_REFERENCE: List[ReferenceCodeEntry] = [
10
+ ReferenceCodeEntry(
11
+ "PS",
12
+ "Primary Suspect",
13
+ "Primary suspect drug identified as causing adverse event",
14
+ "FDA_CDER",
15
+ "FAERS_QDE_README",
16
+ "1.0.0",
17
+ "2004Q1",
18
+ None,
19
+ True,
20
+ ),
21
+ ReferenceCodeEntry(
22
+ "SS",
23
+ "Secondary Suspect",
24
+ "Secondary suspect drug suspected of contributing",
25
+ "FDA_CDER",
26
+ "FAERS_QDE_README",
27
+ "1.0.0",
28
+ "2004Q1",
29
+ None,
30
+ True,
31
+ ),
32
+ ReferenceCodeEntry(
33
+ "C",
34
+ "Concomitant",
35
+ "Concomitant drug taken concurrently by patient",
36
+ "FDA_CDER",
37
+ "FAERS_QDE_README",
38
+ "1.0.0",
39
+ "2004Q1",
40
+ None,
41
+ True,
42
+ ),
43
+ ReferenceCodeEntry(
44
+ "I",
45
+ "Interacting",
46
+ "Drug suspected of causing a drug-drug interaction",
47
+ "FDA_CDER",
48
+ "FAERS_QDE_README",
49
+ "1.0.0",
50
+ "2004Q1",
51
+ None,
52
+ True,
53
+ ),
54
+ # Historical AERS legacy numeric representations (S1 era)
55
+ ReferenceCodeEntry(
56
+ "1",
57
+ "Primary Suspect (Legacy)",
58
+ "Legacy numeric code for Primary Suspect",
59
+ "FDA_CDER",
60
+ "AERS_DOCUMENTATION",
61
+ "1.0.0",
62
+ "2004Q1",
63
+ "2012Q3",
64
+ False,
65
+ ),
66
+ ReferenceCodeEntry(
67
+ "2",
68
+ "Secondary Suspect (Legacy)",
69
+ "Legacy numeric code for Secondary Suspect",
70
+ "FDA_CDER",
71
+ "AERS_DOCUMENTATION",
72
+ "1.0.0",
73
+ "2004Q1",
74
+ "2012Q3",
75
+ False,
76
+ ),
77
+ ReferenceCodeEntry(
78
+ "3",
79
+ "Concomitant (Legacy)",
80
+ "Legacy numeric code for Concomitant",
81
+ "FDA_CDER",
82
+ "AERS_DOCUMENTATION",
83
+ "1.0.0",
84
+ "2004Q1",
85
+ "2012Q3",
86
+ False,
87
+ ),
88
+ ReferenceCodeEntry(
89
+ "4",
90
+ "Interacting (Legacy)",
91
+ "Legacy numeric code for Interacting",
92
+ "FDA_CDER",
93
+ "AERS_DOCUMENTATION",
94
+ "1.0.0",
95
+ "2004Q1",
96
+ "2012Q3",
97
+ False,
98
+ ),
99
+ ]
@@ -0,0 +1,46 @@
1
+ """Official FDA / ICH Patient Sex Codes (GNDR_COD / SEX)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import List
6
+
7
+ from raxtik_etl.reference.codes import ReferenceCodeEntry
8
+
9
+ FDA_SEX_REFERENCE: List[ReferenceCodeEntry] = [
10
+ ReferenceCodeEntry(
11
+ "M", "Male", "Male patient", "FDA_CDER", "FAERS_QDE_ASC_NTS", "1.0.0", "2004Q1", None, True
12
+ ),
13
+ ReferenceCodeEntry(
14
+ "F",
15
+ "Female",
16
+ "Female patient",
17
+ "FDA_CDER",
18
+ "FAERS_QDE_ASC_NTS",
19
+ "1.0.0",
20
+ "2004Q1",
21
+ None,
22
+ True,
23
+ ),
24
+ ReferenceCodeEntry(
25
+ "UNK",
26
+ "Unknown",
27
+ "Patient sex unknown at time of report",
28
+ "FDA_CDER",
29
+ "FAERS_QDE_ASC_NTS",
30
+ "1.0.0",
31
+ "2004Q1",
32
+ None,
33
+ True,
34
+ ),
35
+ ReferenceCodeEntry(
36
+ "NS",
37
+ "Not Specified",
38
+ "Patient sex not specified by reporter (legacy)",
39
+ "FDA_CDER",
40
+ "AERS_DOCUMENTATION",
41
+ "1.0.0",
42
+ "2004Q1",
43
+ "2012Q3",
44
+ False,
45
+ ),
46
+ ]
@@ -0,0 +1,43 @@
1
+ """Official FDA Patient Weight Unit Codes (WT_COD)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import List
6
+
7
+ from raxtik_etl.reference.codes import ReferenceCodeEntry
8
+
9
+ FDA_WEIGHT_UNITS_REFERENCE: List[ReferenceCodeEntry] = [
10
+ ReferenceCodeEntry(
11
+ "KG",
12
+ "Kilograms",
13
+ "Weight measured in kilograms",
14
+ "FDA_CDER",
15
+ "FAERS_QDE_ASC_NTS",
16
+ "1.0.0",
17
+ "2004Q1",
18
+ None,
19
+ True,
20
+ ),
21
+ ReferenceCodeEntry(
22
+ "LBS",
23
+ "Pounds",
24
+ "Weight measured in pounds (avoirdupois)",
25
+ "FDA_CDER",
26
+ "FAERS_QDE_ASC_NTS",
27
+ "1.0.0",
28
+ "2004Q1",
29
+ None,
30
+ True,
31
+ ),
32
+ ReferenceCodeEntry(
33
+ "GMS",
34
+ "Grams",
35
+ "Weight measured in grams",
36
+ "FDA_CDER",
37
+ "FAERS_QDE_ASC_NTS",
38
+ "1.0.0",
39
+ "2004Q1",
40
+ None,
41
+ True,
42
+ ),
43
+ ]
@@ -0,0 +1,101 @@
1
+ """Fail-Closed Signature Resolver for FDA Quarterly ASCII Archives."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ import zipfile
7
+ from dataclasses import dataclass
8
+ from enum import StrEnum
9
+ from typing import Optional
10
+
11
+ DEFAULT_DELIMITER = "$"
12
+
13
+
14
+ class ArchiveSignature(StrEnum):
15
+ """Verified FDA Quarterly ASCII Schema Signatures."""
16
+
17
+ S1 = "S1" # Legacy AERS (2004Q1 - 2012Q3)
18
+ S2 = "S2" # FAERS Migration (2012Q4 - 2014Q2)
19
+ S3 = "S3" # Modern FAERS & AEMS (2014Q3 - Present)
20
+
21
+
22
+ @dataclass(frozen=True)
23
+ class SignatureRule:
24
+ """Declarative signature matching rule based on column sets."""
25
+
26
+ signature: ArchiveSignature
27
+ required_columns: frozenset[str]
28
+ any_of_columns: frozenset[str] = frozenset()
29
+
30
+ def matches(self, columns: set[str]) -> bool:
31
+ """Check if archive columns satisfy rule requirements."""
32
+ if not self.required_columns.issubset(columns):
33
+ return False
34
+ if self.any_of_columns and not bool(self.any_of_columns & columns):
35
+ return False
36
+ return True
37
+
38
+
39
+ # Declarative signature rules evaluated in priority order
40
+ SIGNATURE_RULES: tuple[SignatureRule, ...] = (
41
+ # S1: Characterized by ISR as primary key and CASE as case key (2004Q1 - 2012Q3)
42
+ SignatureRule(
43
+ signature=ArchiveSignature.S1,
44
+ required_columns=frozenset({"isr", "case"}),
45
+ ),
46
+ # S2: Characterized by PRIMARYID, CASEID, CASEVERSION, and GNDR_COD (2012Q4 - 2014Q2)
47
+ SignatureRule(
48
+ signature=ArchiveSignature.S2,
49
+ required_columns=frozenset({"primaryid", "caseid", "gndr_cod"}),
50
+ ),
51
+ # S3: Modern FAERS & AEMS (2014Q3 - Present, including 2025/2026+)
52
+ SignatureRule(
53
+ signature=ArchiveSignature.S3,
54
+ required_columns=frozenset({"primaryid", "caseid"}),
55
+ any_of_columns=frozenset({"sex", "age_grp", "auth_num"}),
56
+ ),
57
+ )
58
+
59
+
60
+ def detect_archive_signature(
61
+ zf: zipfile.ZipFile,
62
+ data_period: Optional[str] = None,
63
+ delimiter: str = DEFAULT_DELIMITER,
64
+ ) -> ArchiveSignature:
65
+ """Detects whether an archive matches Signature S1, S2, or S3 using strict header inspection.
66
+
67
+ Args:
68
+ zf: Open ZipFile instance containing FAERS extract files.
69
+ data_period: Temporal quarter identifier (e.g. '2004Q1', '2025Q1').
70
+ delimiter: Column delimiter used in extract files (default '$').
71
+
72
+ Returns:
73
+ Detected signature identifier (ArchiveSignature enum: S1, S2, or S3).
74
+
75
+ Raises:
76
+ ValueError: If archive headers do not match any verified historical signature,
77
+ or if the DEMO table is missing.
78
+ """
79
+ file_list = zf.namelist()
80
+ demo_files = [
81
+ f for f in file_list if re.search(r"(?:^|[/\\])DEMO[^/\\]*\.txt$", f, re.IGNORECASE)
82
+ ]
83
+ if not demo_files:
84
+ raise ValueError(
85
+ f"Invalid FAERS archive: No DEMO table found in {data_period or 'archive'}"
86
+ )
87
+
88
+ with zf.open(demo_files[0]) as f:
89
+ header_line = f.readline().decode("utf-8", errors="ignore").strip()
90
+
91
+ columns = {c.strip().lower() for c in header_line.split(delimiter) if c.strip()}
92
+
93
+ for rule in SIGNATURE_RULES:
94
+ if rule.matches(columns):
95
+ return rule.signature
96
+
97
+ raise ValueError(
98
+ f"Unrecognized FDA ASCII schema signature for data period {data_period or 'unknown'}. "
99
+ f"Detected DEMO columns: {sorted(list(columns))[:10]}... "
100
+ f"Ensure archive matches S1 (ISR), S2 (PRIMARYID+GNDR_COD), or S3 (PRIMARYID+SEX)."
101
+ )
@@ -0,0 +1,214 @@
1
+ Metadata-Version: 2.5
2
+ Name: raxtik-source-faers
3
+ Version: 0.1.0.dev1
4
+ Summary: Official FDA FAERS/AEMS data connector, parser, and extractor for raxtik-etl
5
+ Project-URL: Homepage, https://github.com/raxtik-org/raxtik-source-faers
6
+ Project-URL: Documentation, https://raxtik-source-faers.readthedocs.io
7
+ Project-URL: Repository, https://github.com/raxtik-org/raxtik-source-faers
8
+ Project-URL: Issues, https://github.com/raxtik-org/raxtik-source-faers/issues
9
+ Author: Raxtik Team
10
+ License: AGPL-3.0-or-later
11
+ License-File: LICENSE
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Healthcare Industry
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Programming Language :: Python :: 3.15
24
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
25
+ Requires-Python: >=3.11
26
+ Requires-Dist: certifi>=2026.10.19
27
+ Requires-Dist: duckdb>=1.1.0
28
+ Requires-Dist: raxtik-etl>=0.1.0.dev1
29
+ Requires-Dist: requests>=2.31.0
30
+ Requires-Dist: rich>=13.0.0
31
+ Requires-Dist: tqdm>=4.66.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pre-commit>=4.0.0; extra == 'dev'
34
+ Requires-Dist: pyrefly>=1.4.0; extra == 'dev'
35
+ Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
36
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
37
+ Requires-Dist: ruff>=0.5.0; extra == 'dev'
38
+ Requires-Dist: tox-uv>=1.11.0; extra == 'dev'
39
+ Requires-Dist: tox>=4.0.0; extra == 'dev'
40
+ Requires-Dist: typos>=1.30.0; extra == 'dev'
41
+ Provides-Extra: docs
42
+ Requires-Dist: myst-parser>=5.1.0; extra == 'docs'
43
+ Requires-Dist: sphinx-autodoc-typehints>=3.6.1; extra == 'docs'
44
+ Requires-Dist: sphinx-copybutton>=0.5.2; extra == 'docs'
45
+ Requires-Dist: sphinx-rtd-theme>=3.1.0; extra == 'docs'
46
+ Requires-Dist: sphinx>=9.0.4; extra == 'docs'
47
+ Requires-Dist: sphinxcontrib-mermaid>=2.1.0; extra == 'docs'
48
+ Description-Content-Type: text/markdown
49
+
50
+ # raxtik-source-faers
51
+
52
+ [![CI](https://github.com/raxtik-org/raxtik-source-faers/actions/workflows/ci.yml/badge.svg)](https://github.com/raxtik-org/raxtik-source-faers/actions/workflows/ci.yml)
53
+ [![codecov](https://codecov.io/gh/raxtik-org/raxtik-source-faers/branch/main/graph/badge.svg)](https://codecov.io/gh/raxtik-org/raxtik-source-faers)
54
+ [![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL_3.0-blue.svg)](./LICENSE)
55
+
56
+ Official FDA FAERS/AERS data source connector, signature resolver, and canonical extractor for `raxtik-etl`.
57
+
58
+ ---
59
+
60
+ ## 🏛 Overview
61
+
62
+ `raxtik-source-faers` is an independent plugin that implements the `SourceAdapter` protocol for `raxtik-etl`. It isolates all FDA-specific archive formats, legacy ASCII quirks, and historical schema evolution from the canonical data platform:
63
+
64
+ - **Fail-closed signature resolution**: Accurately classifies releases into **S1**, **S2**, or **S3** schemas.
65
+ - **Raw ASCII extract staging**: Safely parses `$`-delimited text files, embedded line-breaks, and historical field aliases.
66
+ - **Reference codelists**: Embedded clinical lookup tables for FDA CDER routes, dosage forms, and reporter roles.
67
+ - **Zero-core coupling**: Registers via Python standard entry points without requiring any FAERS-specific logic inside `raxtik-etl`.
68
+
69
+ ---
70
+
71
+ ## 🔍 Historical Signatures Handled
72
+
73
+ | Signature | Date Range | Primary Keys | Distinguishing Features |
74
+ | :--- | :--- | :--- | :--- |
75
+ | **`S1`** | 2004Q1 – 2012Q3 | `ISR`, `CASE` | Legacy AERS: `FOLL_SEQ`, `GNDR_COD`. Missing modern columns (`PROD_AI`, `AUTH_NUM`). |
76
+ | **`S2`** | 2012Q4 – 2014Q2 | `PRIMARYID`, `CASEID` | Migration Era: Transitional columns (`gndr_cod`, `lot_nbr`, `outc_code`). |
77
+ | **`S3`** | 2014Q3 – Present | `PRIMARYID`, `CASEID` | Modern FAERS/AEMS: `SEX`, `PROD_AI`, `AUTH_NUM`, `LIT_REF`, `DRUG_REC_ACT`. |
78
+
79
+ Signature detection is **fail-closed**: any unrecognized or malformed archive raises an explicit `ValueError` rather than silently defaulting to modern schemas.
80
+
81
+ ---
82
+
83
+ ## 🏛️ Canonical Data Model & Schema Mapping
84
+
85
+ The raw FDA ASCII files (`DEMO`, `DRUG`, `REAC`, `OUTC`, `INDI`, `THER`, `RPSR`) are projected into the unified canonical star-schema:
86
+
87
+ ### Entity Relationships & Composite Keys
88
+
89
+ | Table | Entity / Domain | Primary Key (Composite) | Foreign Key Relationship | Description |
90
+ | :--- | :--- | :--- | :--- | :--- |
91
+ | **`demo`** | Case Submissions & Demographics | `primary_id` | *(Root submission table)* | Patient age in decimal years, weight in kg, sex, country, receipt date. |
92
+ | **`drug`** | Drug Products & Regimens | `(primary_id, drug_seq)` | `primary_id` → `demo.primary_id` | Reported brand name, active substance, route, form, role code (`PS`, `SS`, `C`, `I`). |
93
+ | **`reac`** | Adverse Reactions | `(primary_id, reported_reaction_term)` | `primary_id` → `demo.primary_id` | MedDRA Preferred Terms (PT) describing adverse events. |
94
+ | **`outc`** | Patient Outcomes | `(primary_id, outc_code)` | `primary_id` → `demo.primary_id` | Clinical outcomes: Death (`DE`), Hospitalization (`HO`), Disability (`DS`), etc. |
95
+ | **`indi`** | Therapy Indications | `(primary_id, indi_drug_seq, reported_indication_term)` | `(primary_id, indi_drug_seq)` → `drug(primary_id, drug_seq)` | Medical conditions for which medications were prescribed. |
96
+ | **`ther`** | Therapy Timelines | `(primary_id, dsg_drug_seq)` | `(primary_id, dsg_drug_seq)` → `drug(primary_id, drug_seq)` | Therapy start date, end date, and duration in days. |
97
+ | **`rpsr`** | Report Sources | `(primary_id, rpsr_code)` | `primary_id` → `demo.primary_id` | Reporting channel: Health Professional (`HP`), Consumer (`CSM`), Study (`SDY`), etc. |
98
+ | **`cases`** | Authoritative Deduplicated View | `case_id` | Derived from `demo` | Precomputed deterministic resolution to latest report version per `case_id`. |
99
+
100
+ 📖 **Visual Entity-Relationship Diagram**:
101
+ - 📊 **[Full Interactive ER Diagram (Mermaid)](ER_DIAGRAM.md)**
102
+ - 🌐 **[raxtik-etl Docs: Canonical Data Model](https://raxtik-etl.readthedocs.io/en/latest/schema/canonical_data_model.html)**
103
+ - 📚 **[raxtik-source-faers Architecture](https://raxtik-source-faers.readthedocs.io/en/latest/architecture.html)**
104
+
105
+ ---
106
+
107
+ ## 📦 Installation
108
+
109
+ Install alongside `raxtik-etl`:
110
+
111
+ ```bash
112
+ pip install raxtik-source-faers raxtik-etl
113
+ ```
114
+
115
+ Once installed, `raxtik-etl` automatically discovers the FAERS connector and provides the specialized `FAERS` dataset client.
116
+
117
+ ---
118
+
119
+ ## 🚀 Usage
120
+
121
+ ### 1. Direct Hugging Face Loading & Streaming
122
+ Query precompiled quarterly packages from 2004Q1 through 2026Q3:
123
+
124
+ ```python
125
+ from raxtik_etl import FAERS
126
+
127
+ # 1. Default (Fastest): Downloads once, caches locally, queries in milliseconds
128
+ with FAERS.from_hf("2024Q1") as faers:
129
+ cases = faers.cases(limit=100)
130
+ print(cases)
131
+
132
+ # 2. Zero-Disk Streaming: Streams directly over HTTPS without local downloads
133
+ with FAERS.from_hf("2024Q1", remote=True) as faers:
134
+ cases = faers.cases(limit=100)
135
+ print(cases)
136
+ ```
137
+
138
+ ### 2. Remote Querying via DuckDB (Zero Local Storage)
139
+ Query precompiled datasets on Hugging Face Hub over HTTPS without downloading full files to disk.
140
+
141
+ #### Option A: Remote DuckDB `ATTACH` (Single File URL, Full Schema & Views)
142
+ ```python
143
+ import duckdb
144
+
145
+ con = duckdb.connect()
146
+ # httpfs is DuckDB's native C++ extension (no pip install required)
147
+ con.execute("INSTALL httpfs; LOAD httpfs;")
148
+
149
+ # 1 single URL attaches all 7 tables and the precomputed cases view
150
+ db_url = "https://huggingface.co/datasets/raxtik-org/faers-safety-database/resolve/main/bronze/2024/faers_2024Q1.duckdb"
151
+ con.execute(f"ATTACH '{db_url}' AS faers (READ_ONLY);")
152
+
153
+ con.execute("""
154
+ SELECT d.reported_drug_name, COUNT(*) AS report_count
155
+ FROM faers.drug d
156
+ JOIN faers.reac r ON d.primary_id = r.primary_id
157
+ WHERE d.role_code = 'PS' AND r.reported_reaction_term = 'Myocardial infarction'
158
+ GROUP BY d.reported_drug_name ORDER BY report_count DESC LIMIT 5;
159
+ """).show()
160
+ ```
161
+ > *Note: Initial ATTACH takes ~10s to load catalog metadata over HTTP, after which subsequent queries execute directly.*
162
+
163
+ #### Option B: Remote Parquet Scanning (Column Range Requests)
164
+ ```python
165
+ import duckdb
166
+
167
+ con = duckdb.connect()
168
+ con.execute("INSTALL httpfs; LOAD httpfs;")
169
+
170
+ con.execute("""
171
+ SELECT d.reported_drug_name, COUNT(*) AS report_count
172
+ FROM 'https://huggingface.co/datasets/raxtik-org/faers-safety-database/resolve/main/bronze/2024/faers_2024Q1.parquet/drug.parquet' d
173
+ JOIN 'https://huggingface.co/datasets/raxtik-org/faers-safety-database/resolve/main/bronze/2024/faers_2024Q1.parquet/reac.parquet' r
174
+ ON d.primary_id = r.primary_id
175
+ WHERE d.role_code = 'PS' AND r.reported_reaction_term = 'Myocardial infarction'
176
+ GROUP BY d.reported_drug_name ORDER BY report_count DESC LIMIT 5;
177
+ """).show()
178
+ ```
179
+
180
+ ### 3. Download Quarterly FDA Archives
181
+ ```python
182
+ from raxtik_source_faers import download_quarterly_archive
183
+
184
+ # Downloads and verifies official quarterly FDA archive zip
185
+ zip_path = download_quarterly_archive(year=2024, quarter=1, dest_dir="data/raw")
186
+ print(f"Downloaded to {zip_path}")
187
+ ```
188
+
189
+ ### 4. Extract into Canonical DuckDB via Adapter
190
+ ```python
191
+ import duckdb
192
+ from pathlib import Path
193
+ from raxtik_etl.sources.protocol import SourceArtifact
194
+ from raxtik_source_faers import FAERSAdapter
195
+
196
+ con = duckdb.connect("my_database.duckdb")
197
+ adapter = FAERSAdapter()
198
+
199
+ artifact = SourceArtifact(path=Path("data/raw/faers_ascii_2024q1.zip"), release="2024Q1")
200
+
201
+ result = adapter.extract_and_load(con, artifact)
202
+ print(f"Extracted {result.row_counts['demo']} reports under signature {result.signature_id}")
203
+ ```
204
+
205
+ ---
206
+
207
+ ## 👥 Contributors
208
+
209
+ See **[CONTRIBUTORS.md](CONTRIBUTORS.md)** for all project contributors.
210
+
211
+ ---
212
+
213
+ ## 📄 License
214
+ Licensed under the [GNU Affero General Public License v3.0 (AGPL-3.0)](./LICENSE).