<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ healthcaredata - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ healthcaredata - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 01 Dec 2026 21:32:48 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/healthcaredata/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Standardize Healthcare Data Using OMOP CDM and PySpark ]]>
                </title>
                <description>
                    <![CDATA[ Healthcare data comes from various systems like electronic health records (EHRs), laboratory systems, pharmacies, medical imaging systems, and billing applications. And each system may use different d ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-standardize-healthcare-data-using-omop-cdm-and-pyspark/</link>
                <guid isPermaLink="false">6b0ef9214de318dc98dd0ba7</guid>
                
                    <category>
                        <![CDATA[ healthcaredata ]]>
                    </category>
                
                    <category>
                        <![CDATA[ omop ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PySpark ]]>
                    </category>
                
                    <category>
                        <![CDATA[ dataengineering ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HealthcareAI ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Data standardization ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Lakshmi Mahabaleshwara ]]>
                </dc:creator>
                <pubDate>Tue, 01 Dec 2026 16:43:13 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/91984fb5-8e94-42ee-99ec-d90ab9bd974c.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Healthcare data comes from various systems like electronic health records (EHRs), laboratory systems, pharmacies, medical imaging systems, and billing applications. And each system may use different data structures, naming conventions, and clinical coding standards.</p>
<p>For example, consider two hospitals storing information about patients diagnosed with type 2 diabetes.</p>
<table>
<thead>
<tr>
<th>Hospital A</th>
<th>Hospital B</th>
</tr>
</thead>
<tbody><tr>
<td>patient_id</td>
<td>patient_number</td>
</tr>
<tr>
<td>diagnosis_date</td>
<td>condition_start_date</td>
</tr>
<tr>
<td>diagnosis_code</td>
<td>clinical_code</td>
</tr>
<tr>
<td>E11.9 (ICD-10-CM)</td>
<td>44054006 (SNOMED CT)</td>
</tr>
</tbody></table>
<p>How do we combine data from these hospitals to conduct clinical research or build healthcare AI applications?</p>
<p>The Observational Medical Outcomes Partnership Common Data Model (OMOP CDM) addresses this problem by providing a common structure and standardized clinical vocabularies.</p>
<p>In this tutorial, we'll build an ETL pipeline using PySpark to transform synthetic healthcare data into OMOP CDM tables, validate the transformed data, and perform clinical analytics.</p>
<p>We'll use the synthetic healthcare dataset generated in my previous freeCodeCamp tutorial, <a href="https://www.freecodecamp.org/news/how-to-generate-synthetic-healthcare-data-using-synthea-a-hands-on-tutorial">How to Generate Synthetic Healthcare Data Using Synthea – A Hands-On Tutorial</a>. If you haven't generated the dataset yet, I recommend following that tutorial before proceeding.</p>
<p>You can follow along with the accompanying <a href="https://github.com/lakshmi-mahabaleshwara/healthtech-playground/blob/main/omop-cdm/synthea_to_omop.ipynb">Jupyter notebook</a>, which contains the complete implementation.</p>
<h3 id="heading-what-well-cover">What We'll Cover:</h3>
<ul>
<li><a href="#heading-prerequisites">Prerequisites</a></li>
<li><a href="#heading-what-is-omop-cdm">What is OMOP CDM?</a><ul>
<li><a href="#heading-structural-standardization">Structural Standardization</a></li>
<li><a href="#heading-semantic-standardization">Semantic Standardization</a></li>
</ul>
</li>
<li><a href="#heading-understanding-the-omop-common-data-model">Understanding the OMOP Common Data Model</a><ul>
<li><a href="#heading-what-are-clinical-vocabularies-and-athena">What Are Clinical Vocabularies and ATHENA?</a></li>
<li><a href="#heading-how-to-download-omop-standardized-vocabularies-from-athena">How to Download OMOP Standardized Vocabularies from ATHENA</a></li>
</ul>
</li>
<li><a href="#heading-how-to-build-the-healthcare-data-standardization-pipeline">How to Build the Healthcare Data Standardization Pipeline</a><ul>
<li><a href="#heading-step-1-set-up-the-development-environment">Step 1: Set Up the Development Environment</a></li>
<li><a href="#heading-step-2-load-and-explore-the-synthea-dataset">Step 2: Load and Explore the Synthea Dataset</a></li>
<li><a href="#heading-step-3-load-the-omop-standardized-vocabularies">Step 3: Load the OMOP Standardized Vocabularies</a></li>
<li><a href="#heading-step-4-map-clinical-codes-to-omop-standard-concepts">Step 4: Map Clinical Codes to OMOP Standard Concepts</a></li>
<li><a href="#heading-step-5-how-to-transform-patient-data-into-the-person-table">Step 5: How to Transform Patient Data into the PERSON Table</a></li>
<li><a href="#heading-step-6-transform-the-remaining-clinical-tables">Step 6: Transform the Remaining Clinical Tables</a></li>
<li><a href="#heading-step-7-how-to-validate-the-standardized-healthcare-data">Step 7: How to Validate the Standardized Healthcare Data</a></li>
<li><a href="#heading-step-8-how-to-save-the-omop-tables-in-parquet-format">Step 8: How to Save the OMOP Tables in Parquet Format</a></li>
<li><a href="#heading-step-9-how-to-perform-clinical-analytics-using-omop-cdm">Step 9: How to Perform Clinical Analytics Using OMOP CDM</a></li>
</ul>
</li>
<li><a href="#heading-conclusion">Conclusion</a></li>
<li><a href="#heading-references-for-the-article">References for the article</a></li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To follow along with this tutorial, you should have a basic understanding of Python, SQL, and DataFrame operations. We'll use Synthea, OMOP CDM v5.4, OHDSI ATHENA, PySpark, and Jupyter Notebook.</p>
<p>The entire pipeline runs locally, so you don't need access to real patient data or cloud infrastructure.</p>
<h2 id="heading-what-is-omop-cdm">What is OMOP CDM?</h2>
<p>OMOP CDM stands for <strong>Observational Medical Outcomes Partnership Common Data Model</strong>. It's an open data model maintained by the Observational Health Data Sciences and Informatics (OHDSI) community.</p>
<p>It enables healthcare data from different sources to be represented consistently for clinical research and analytics.</p>
<p>OMOP addresses two types of data standardization: structural and semantic.</p>
<h3 id="heading-structural-standardization">Structural Standardization</h3>
<p>Different healthcare systems may store patient information using different table names, column names, and data types. OMOP provides a common structure for representing this information.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69fd77e89f93a850a46d376f/d0f37893-3aca-4e70-bec4-63c0dda563b9.png" alt="Two hospitals with different patient table structures and column names are mapped to a common OMOP CDM PERSON table, standardizing patient identifiers and birth date fields." style="display: block;" width="600" height="400" loading="lazy">

<p>Regardless of the source structure, the transformed data follows a common model.</p>
<h3 id="heading-semantic-standardization">Semantic Standardization</h3>
<p>Having the same table structure isn't enough if hospitals use different clinical codes to represent the same medical condition. OMOP uses standardized vocabularies to ensure that clinical information can be interpreted consistently across systems. This process is known as semantic standardization.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69fd77e89f93a850a46d376f/217d20c4-2e6d-4afd-9d26-44825294dc39.png" alt="Clinical codes for type 2 diabetes from two hospitals using ICD-10-CM and SNOMED CT are mapped through OMOP standardized vocabularies to a common concept ID in the CONDITION_OCCURRENCE table." style="display: block;" width="600" height="400" loading="lazy">

<h2 id="heading-understanding-the-omop-common-data-model">Understanding the OMOP Common Data Model</h2>
<p>OMOP CDM organizes healthcare data into several categories, including clinical data, healthcare system data, health economics, standardized vocabularies, and metadata.</p>
<p>For this tutorial, we'll focus primarily on clinical data.</p>
<table>
<thead>
<tr>
<th>OMOP Table</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td><code>PERSON</code></td>
<td>Patient demographic information</td>
</tr>
<tr>
<td><code>VISIT_OCCURRENCE</code></td>
<td>Healthcare encounters, such as hospital admissions and outpatient visits</td>
</tr>
<tr>
<td><code>CONDITION_OCCURRENCE</code></td>
<td>Diseases, diagnoses, signs and symptoms</td>
</tr>
<tr>
<td><code>DRUG_EXPOSURE</code></td>
<td>Medications prescribed or administered</td>
</tr>
<tr>
<td><code>PROCEDURE_OCCURRENCE</code></td>
<td>Medical and surgical procedures</td>
</tr>
<tr>
<td><code>MEASUREMENT</code></td>
<td>Laboratory results, vital signs, and other measurements</td>
</tr>
<tr>
<td><code>OBSERVATION</code></td>
<td>Other clinical facts, such as smoking status or family history</td>
</tr>
<tr>
<td><code>OBSERVATION_PERIOD</code></td>
<td>Periods during which patient events can be captured</td>
</tr>
</tbody></table>
<p>These tables are connected through identifiers such as <code>person_id</code> and <code>visit_occurrence_id</code>, allowing us to connect a patient's encounters, diagnoses, medications, and laboratory results.</p>
<p>You can explore the complete data model in the official <a href="https://ohdsi.github.io/CommonDataModel/cdm54.html">OMOP CDM v5.4 documentation</a>.</p>
<h3 id="heading-what-are-clinical-vocabularies-and-athena">What Are Clinical Vocabularies and ATHENA?</h3>
<p>A clinical vocabulary is a standardized collection of medical terms and codes used to represent healthcare information.</p>
<p>Some commonly used clinical vocabularies include SNOMED CT for diagnoses and clinical findings, LOINC for laboratory tests, RxNorm for medications, and UCUM for measurement units.</p>
<p>OMOP brings these vocabularies together and assigns each concept a unique identifier called <code>concept_id</code>.</p>
<p><a href="https://athena.ohdsi.org">ATHENA</a> is OHDSI's platform for exploring and downloading these standardized vocabularies. We'll use the downloaded vocabulary files as reference data in our ETL pipeline.</p>
<h3 id="heading-how-to-download-omop-standardized-vocabularies-from-athena">How to Download OMOP Standardized Vocabularies from ATHENA</h3>
<p>Create an account on <a href="https://athena.ohdsi.org">ATHENA</a>, and navigate to the vocabulary download section.</p>
<ol>
<li>Select SNOMED CT, LOINC, RxNorm, RxNorm Extension, UCUM, and the supporting vocabularies for demographics, visit types, and clinical record types.</li>
<li>Create a bundle named <code>synthea_omop_vocabulary</code>. For this tutorial, I'm using release <code>v20260829</code>. Leave the Delta from Older Version option unchecked to download the complete bundle.</li>
<li>Once downloaded, extract the ZIP file. We'll primarily use <code>CONCEPT.csv</code>, which contains clinical concepts, and <code>CONCEPT_RELATIONSHIP.csv</code>, which contains relationships and mappings between concepts.</li>
</ol>
<p>Although these files have a <code>.csv</code> extension, they're tab-separated.</p>
<p><strong>Note</strong>: Due to vocabulary-specific licensing restrictions, the downloaded vocabulary files aren't included in the GitHub repository. Download them directly from ATHENA after accepting the applicable licensing terms.</p>
<h2 id="heading-how-to-build-the-healthcare-data-standardization-pipeline">How to Build the Healthcare Data Standardization Pipeline</h2>
<p>Now that you understand OMOP CDM and have downloaded the standardized vocabularies, let's build our ETL pipeline using PySpark.</p>
<p>The pipeline has four main stages, as shown below: ingestion, transformation, validation, and storage.</p>
<h3 id="heading-step-1-set-up-the-development-environment">Step 1: Set Up the Development Environment</h3>
<p>Create the following directory structure:</p>
<pre><code class="language-plaintext">omop-cdm/
├── synthea_to_omop.ipynb
├── requirements.txt
├── .gitignore
└── data/
    ├── synthea/
    ├── vocabulary/
    └── omop/
</code></pre>
<p>The <code>synthea</code> directory contains the source healthcare data, the <code>vocabulary</code> directory contains the downloaded OMOP standardized vocabularies, and the <code>omop</code> directory will contain the transformed healthcare data.</p>
<p>Ensure that Python and a compatible Java version are installed on your machine. Install the required dependencies:</p>
<pre><code class="language-python">python -m pip install notebook pyspark pandas matplotlib
</code></pre>
<p>Launch Jupyter Notebook:</p>
<pre><code class="language-python">jupyter notebook
</code></pre>
<p>Let's start by initializing a Spark session.</p>
<pre><code class="language-python">from pyspark.sql import SparkSession
from pyspark.sql import functions as F
from pathlib import Path

spark = (
    SparkSession.builder
    .appName("SyntheaToOMOP")
    .master("local[*]")
    .getOrCreate()
)

spark
</code></pre>
<p>Define the paths for our source data, vocabulary files, and transformed data.</p>
<pre><code class="language-python">DATA_DIR = Path("data")

SYNTHEA_DIR = DATA_DIR / "synthea"
VOCABULARY_DIR = DATA_DIR / "vocabulary"
OMOP_DIR = DATA_DIR / "omop"
</code></pre>
<h3 id="heading-step-2-load-and-explore-the-synthea-dataset">Step 2: Load and Explore the Synthea Dataset</h3>
<p>Copy the CSV files generated using Synthea into the <code>data/synthea/</code> directory. For this tutorial, we'll work with six source tables: <strong>patients, encounters, conditions, medications, procedures,</strong> and <strong>observations.</strong></p>
<p>Let's load these files into PySpark DataFrames.</p>
<pre><code class="language-python">source_tables = [
    "patients",
    "encounters",
    "conditions",
    "medications",
    "procedures",
    "observations"
]

synthea = {}

for table in source_tables:
    synthea[table] = (
        spark.read
        .option("header", True)
        .csv(str(SYNTHEA_DIR / f"{table}.csv"))
    )
</code></pre>
<p>We initially load the CSV columns as strings. This helps preserve clinical codes and identifiers without losing leading zeros or introducing unintended type conversions.</p>
<p>Let's check the number of records in each table.</p>
<pre><code class="language-python">for table, df in synthea.items():
    print(f"{table}: {df.count():,} records")
</code></pre>
<p>The record counts may vary depending on the synthetic dataset used.</p>
<p>Let's explore the patient data.</p>
<pre><code class="language-python">synthea["patients"].printSchema()

synthea["patients"].select(
    "Id",
    "BIRTHDATE",
    "GENDER",
    "RACE",
    "ETHNICITY"
).show(5, truncate=False)
</code></pre>
<p>Similarly, let's examine the conditions table.</p>
<pre><code class="language-python">synthea["conditions"].select(
    "PATIENT",
    "START",
    "CODE",
    "DESCRIPTION"
).show(5, truncate=False)
</code></pre>
<p>Notice that each condition has a clinical code and a description. In the following sections, we'll use OMOP standardized vocabularies to map these clinical codes to standard concept IDs.</p>
<h3 id="heading-step-3-load-the-omop-standardized-vocabularies">Step 3: Load the OMOP Standardized Vocabularies</h3>
<p>Now that we've loaded the Synthea dataset, let's load the standardized vocabulary files downloaded from ATHENA.</p>
<p>For our transformation, we'll primarily use two vocabulary tables:</p>
<ul>
<li>CONCEPT: Contains clinical codes, concept identifiers, vocabulary names, and clinical domains.</li>
<li>CONCEPT_RELATIONSHIP: Contains relationships between clinical concepts, including mappings from source concepts to standard concepts. Since the ATHENA vocabulary files are tab separated, we specify <code>\t</code> as the delimiter when loading them into PySpark.</li>
</ul>
<pre><code class="language-python">concept = (
    spark.read
    .option("header", True)
    .option("sep", "\t")
    .csv(str(VOCABULARY_DIR / "CONCEPT.csv"))
    .withColumn("concept_id", F.col("concept_id").cast("int"))
)

concept_relationship = (
    spark.read
    .option("header", True)
    .option("sep", "\t")
    .csv(str(VOCABULARY_DIR / "CONCEPT_RELATIONSHIP.csv"))
    .withColumn("concept_id_1", F.col("concept_id_1").cast("int"))
    .withColumn("concept_id_2", F.col("concept_id_2").cast("int"))
)
</code></pre>
<p>Let's explore a few records from the <code>CONCEPT</code> table.</p>
<pre><code class="language-python">concept.select(
    "concept_id",
    "concept_name",
    "domain_id",
    "vocabulary_id",
    "concept_code",
    "standard_concept"
).show(5, truncate=False)
</code></pre>
<p>Now that we have loaded both the source healthcare data and the standardized vocabularies, let's see how we can map clinical codes from Synthea to OMOP standard concepts.</p>
<h3 id="heading-step-4-map-clinical-codes-to-omop-standard-concepts">Step 4: Map Clinical Codes to OMOP Standard Concepts</h3>
<p>One of the most important steps in our healthcare data standardization pipeline is clinical vocabulary mapping.</p>
<p>For example, Synthea represents type 2 diabetes mellitus using the SNOMED CT code <code>44054006</code>. OMOP CDM represents the same clinical concept using a unique concept identifier.</p>
<p>Let's look up this clinical code in the <code>CONCEPT</code> table.</p>
<pre><code class="language-python">concept.filter(
    (F.col("vocabulary_id") == "SNOMED") &amp;
    (F.col("concept_code") == "44054006")
).select(
    "concept_id",
    "concept_name",
    "domain_id",
    "standard_concept"
).show(truncate=False)
</code></pre>
<p>The corresponding concept is:</p>
<table>
<thead>
<tr>
<th>Attribute</th>
<th>Value</th>
</tr>
</thead>
<tbody><tr>
<td>concept_id</td>
<td>201826</td>
</tr>
<tr>
<td>concept_name</td>
<td>Type 2 diabetes mellitus</td>
</tr>
<tr>
<td>domain_id</td>
<td>Condition</td>
</tr>
<tr>
<td>standard_concept</td>
<td>S</td>
</tr>
</tbody></table>
<p>Here, <code>S</code> indicates that the concept is already a standard OMOP concept.</p>
<p>But not every clinical code maps directly to a standard concept. Some source concepts belong to non-standard vocabularies and need to be mapped using the <code>CONCEPT_RELATIONSHIP</code> table.</p>
<h4 id="heading-understanding-the-maps-to-relationship">Understanding the "Maps to" Relationship</h4>
<p>OMOP uses a relationship called <code>Maps to</code> to associate source concepts with their corresponding standard concepts.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69fd77e89f93a850a46d376f/b27c76a7-21be-464e-be7c-eb4c0df79118.png" alt="Flowchart showing how source clinical codes are mapped to OMOP standard concept IDs using the CONCEPT and CONCEPT_RELATIONSHIP tables, with the mapped concept's clinical domain determining the target OMOP table." style="display: block;" width="600" height="400" loading="lazy">

<p>Let's identify valid standard concepts.</p>
<pre><code class="language-python">standard = concept.filter(
    (F.col("standard_concept") == "S") &amp;
    (
        F.col("invalid_reason").isNull() |
        (F.col("invalid_reason") == "")
    )
)
</code></pre>
<p>Next, extract valid <code>Maps to</code> relationships.</p>
<pre><code class="language-python">links = concept_relationship.filter(
    (F.col("relationship_id") == "Maps to") &amp;
    (
        F.col("invalid_reason").isNull() |
        (F.col("invalid_reason") == "")
    )
)
</code></pre>
<p>Using these DataFrames, we create a reusable vocabulary lookup that maps source clinical codes to their corresponding standard concept IDs and clinical domains.</p>
<p>The complete lookup implementation is available in the accompanying Jupyter notebook.</p>
<p>Once the lookup is created, we can reuse it across different clinical tables.</p>
<pre><code class="language-python">def map_codes(df):
    return (
        df.join(
            lookup,
            ["vocab", "code"],
            "left"
        )
        .fillna(
            0,
            subset=[
                "source_concept_id",
                "standard_id"
            ]
        )
    )
</code></pre>
<p>When a clinical code can't be mapped, we assign a concept ID of <code>0</code>, indicating that no matching concept has been identified. These records should be tracked for further review.</p>
<p>Now that we have a reusable mechanism for clinical vocabulary mapping, let's start transforming our Synthea healthcare data into OMOP CDM tables, beginning with the <code>PERSON</code> table.</p>
<h3 id="heading-step-5-how-to-transform-patient-data-into-the-person-table">Step 5: How to Transform Patient Data into the PERSON Table</h3>
<p>The <code>PERSON</code> table is the central clinical table in OMOP CDM. It contains demographic information about patients whose healthcare records are represented in the dataset.</p>
<p>Every patient is assigned a unique <code>person_id</code>, which is referenced by other clinical tables.</p>
<p>Synthea represents patient identifiers using UUIDs. OMOP CDM uses integer identifiers. So we need to create a mapping between the original patient identifier and the standardized OMOP patient identifier. This mapping is often referred to as an <strong>identity crosswalk.</strong></p>
<p>Let's create the patient identity crosswalk using PySpark.</p>
<pre><code class="language-python">from pyspark.sql import Window

patients = synthea["patients"]

patient_mapping = (
    patients
    .select("Id")
    .distinct()
    .withColumn(
        "person_id",
        F.row_number().over(
            Window.orderBy("Id")
        )
    )
)
</code></pre>
<p>We'll reuse this mapping when transforming encounters, diagnoses, procedures, medications, and observations.</p>
<p>For this tutorial, sorted row numbers are sufficient because we're processing a fixed dataset. In a production pipeline, the identifier mapping should be persisted so that existing patient identifiers remain stable when new records are added.</p>
<p><strong>Source-to-Target Mapping</strong></p>
<p>Before transforming the data, let's understand how Synthea patient attributes map to OMOP attributes.</p>
<table>
<thead>
<tr>
<th>Synthea column</th>
<th>OMOP column</th>
<th>Transformation</th>
</tr>
</thead>
<tbody><tr>
<td>ID</td>
<td>person_id</td>
<td>Integer identifier mapping</td>
</tr>
<tr>
<td>ID</td>
<td>person_source_value</td>
<td>Preserve source identifier</td>
</tr>
<tr>
<td>BIRTHDATE</td>
<td>year_of_birth</td>
<td>Extract year</td>
</tr>
<tr>
<td>BIRTHDATE</td>
<td>month_of_birth</td>
<td>Extract month</td>
</tr>
<tr>
<td>BIRTHDATE</td>
<td>day_of_birth</td>
<td>Extract day</td>
</tr>
<tr>
<td>GENDER</td>
<td>gender_concept_id</td>
<td>Concept mapping</td>
</tr>
<tr>
<td>RACE</td>
<td>race_concept_id</td>
<td>Concept mapping</td>
</tr>
<tr>
<td>ETHNICITY</td>
<td>ethnicity_concept_id</td>
<td>Concept mapping</td>
</tr>
</tbody></table>
<p>This process of defining how source columns are transformed into target columns is known as source-to-target mapping.</p>
<p>The following code demonstrates the structural transformation of patient identifiers and birth dates.</p>
<pre><code class="language-python">person_demo = (
    patients
    .join(patient_mapping, "Id")
    .withColumn(
        "birth_date",
        F.to_date("BIRTHDATE")
    )
    .select(
        "person_id",
        F.year("birth_date").alias("year_of_birth"),
        F.month("birth_date").alias("month_of_birth"),
        F.dayofmonth("birth_date").alias("day_of_birth"),
        F.col("Id").alias("person_source_value")
    )
)

person_demo.show(5, truncate=False)
</code></pre>
<h3 id="heading-step-6-transform-the-remaining-clinical-tables">Step 6: Transform the Remaining Clinical Tables</h3>
<p>We can follow a similar approach to transform the remaining Synthea tables into OMOP CDM tables.</p>
<p>The following table summarizes the source-to-target mappings for our pipeline.</p>
<table>
<thead>
<tr>
<th>Synthea Source Table</th>
<th>OMOP Target Table</th>
</tr>
</thead>
<tbody><tr>
<td>encounters.csv</td>
<td>VISIT_OCCURRENCE</td>
</tr>
<tr>
<td>conditions.csv</td>
<td>CONDITION_OCCURRENCE</td>
</tr>
<tr>
<td>medications.csv</td>
<td>DRUG_EXPOSURE</td>
</tr>
<tr>
<td>procedures.csv</td>
<td>PROCEDURE_OCCURRENCE</td>
</tr>
<tr>
<td>observations.csv</td>
<td>MEASUREMENT</td>
</tr>
<tr>
<td>observations.csv</td>
<td>OBSERVATION</td>
</tr>
<tr>
<td>Patient visit and clinical event history</td>
<td>OBSERVATION_PERIOD</td>
</tr>
</tbody></table>
<p>For each transformation, we follow a similar approach:</p>
<ul>
<li>Define the source-to-target column mappings.</li>
<li>Map patient and encounter identifiers to maintain relationships across tables.</li>
<li>Map source clinical codes to OMOP standard concepts.</li>
<li>Identify the appropriate target table based on the clinical domain.</li>
<li>Transform column names, data types, and values according to the OMOP CDM specification.</li>
<li>Preserve original source values for traceability.</li>
</ul>
<p>The complete implementation is available in the accompanying <a href="https://github.com/lakshmi-mahabaleshwara/healthtech-playground/blob/main/omop-cdm/synthea_to_omop.ipynb">Jupyter notebook</a>.</p>
<h4 id="heading-understanding-clinical-domain-distribution">Understanding Clinical Domain Distribution</h4>
<p>One aspect of OMOP CDM is that a single source table can map to multiple target tables.</p>
<p>For example, Synthea stores laboratory results, vital signs, and other clinical findings in <code>observations.csv</code>. OMOP separates these records based on their clinical meaning.</p>
<p>The <code>MEASUREMENT</code> table captures results such as blood glucose, blood pressure, and body mass index, while the <code>OBSERVATION</code> table captures other clinical facts, such as family and social history.</p>
<p>We determine the target table using the <code>domain_id</code> of the mapped standard concept.</p>
<p>The following chart shows the clinical domain distribution obtained after running vocabulary mapping on our Synthea dataset.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69fd77e89f93a850a46d376f/894ff378-e893-4549-a2bf-4974e14a4484.png" alt="Stacked horizontal bar chart showing the percentage distribution of OMOP clinical domains across Synthea source tables, highlighting how conditions, procedures, and observations map to multiple clinical domains, while medications map entirely to the Drug domain." style="display: block;" width="600" height="400" loading="lazy">

<p>Records from <code>procedures.csv</code> are distributed across several domains, including Procedure, Measurement, and Observation.</p>
<p>This is why healthcare data standardization is more than a one-to-one table transformation. The clinical meaning of each record determines where it belongs in the standardized data model.</p>
<p>Unmapped concepts and records belonging to unsupported domains are captured separately for further review. Since a source record may map to multiple standard concepts, these distributions represent mapped rows instead of unique source records.</p>
<h3 id="heading-step-7-how-to-validate-the-standardized-healthcare-data">Step 7: How to Validate the Standardized Healthcare Data</h3>
<p>Before saving the transformed data, we need to verify that it follows the expected OMOP structure and maintains relationships between clinical records.</p>
<p>Our pipeline performs the following data quality checks:</p>
<ul>
<li><strong>Primary key uniqueness</strong>: Ensures that identifiers are unique.</li>
<li><strong>Referential integrity</strong>: Verifies that clinical records reference valid patients and encounters.</li>
<li><strong>Vocabulary validation</strong>: Ensures that mapped concepts belong to the appropriate clinical domains.</li>
<li><strong>Temporal validation</strong>: Checks for inconsistent clinical dates.</li>
<li><strong>Data reconciliation</strong>: Tracks successfully transformed and unmapped records.</li>
</ul>
<p>For example, we can verify that every patient has a unique <code>person_id</code>.</p>
<pre><code class="language-python">duplicate_patients = (
    person.groupBy("person_id")
    .count()
    .filter(F.col("count") &gt; 1)
)

assert duplicate_patients.count() == 0
</code></pre>
<p>Similarly, a left anti join helps us identify condition records that don't reference a valid patient.</p>
<pre><code class="language-python">orphan_conditions = condition_occurrence.join(
    person.select("person_id"),
    "person_id",
    "left_anti"
)

assert orphan_conditions.count() == 0
</code></pre>
<p>The remaining validation checks are implemented in the accompanying Jupyter notebook.</p>
<h3 id="heading-step-8-how-to-save-the-omop-tables-in-parquet-format">Step 8: How to Save the OMOP Tables in Parquet Format</h3>
<p>Once the validation checks pass, we can save the transformed OMOP tables in Parquet format for downstream analytics.</p>
<p>Apache Parquet is an open-source, columnar file format designed for efficient data storage and analytical processing.</p>
<p>Imagine a healthcare dataset with patient IDs, birth dates, diagnoses, and medications. Parquet stores data column by column, like organizing information into separate folders by category.</p>
<p>If we only need to analyze patient diagnoses, Parquet allows us to read the relevant columns without reading the entire dataset. This reduces the amount of data processed and improves query performance. Parquet also supports efficient data compression, reducing storage requirements.</p>
<p>To learn more about how Parquet works and its benefits, refer to my article <a href="https://coderlegion.com/30266/understanding-parquet-file-format">Understanding the Parquet File Format</a>.</p>
<pre><code class="language-python">for table_name, df in omop_tables.items():
    df.write.mode("overwrite").parquet(
        f"data/omop/{table_name}"
    )
</code></pre>
<p>Each OMOP table is stored in a separate directory and can be loaded independently without rerunning the ETL pipeline.</p>
<pre><code class="language-python">person = spark.read.parquet("data/omop/person")
</code></pre>
<h3 id="heading-step-9-how-to-perform-clinical-analytics-using-omop-cdm">Step 9: How to Perform Clinical Analytics Using OMOP CDM</h3>
<p>Now that our healthcare data follows a common structure and uses standardized concepts, we can query it using Spark SQL.</p>
<p>Let's identify the most frequently recorded conditions based on the number of unique patients.</p>
<pre><code class="language-python">for table_name, df in omop_tables.items():
    df.createOrReplaceTempView(table_name)

concept.createOrReplaceTempView("concept")

spark.sql("""
    SELECT
        c.concept_name,
        COUNT(DISTINCT co.person_id) AS patient_count
    FROM condition_occurrence co
    JOIN concept c
        ON co.condition_concept_id = c.concept_id
    GROUP BY
        c.concept_id,
        c.concept_name
    ORDER BY patient_count DESC
    LIMIT 10
""").show(truncate=False)
</code></pre>
<p>The query returns the most frequently recorded standardized conditions based on the number of unique patients.</p>
<p>If another hospital transforms its data into the same OMOP model, we can reuse this query without changing it to accommodate the original source schema. This is one of the key benefits of healthcare data standardization.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial, we built a healthcare data standardization pipeline using Synthea, OMOP CDM, ATHENA, and PySpark. We explored clinical vocabulary mapping, transformed healthcare records into standardized OMOP tables, and validated the resulting data.</p>
<p>While we used synthetic data, the same principles apply when integrating data from real-world healthcare systems. Production implementations require additional considerations such as local clinical codes, missing data, patient privacy, and more comprehensive validation.</p>
<p>I hope this tutorial helps you get started with healthcare data standardization and understand how OMOP CDM can provide a foundation for clinical research, healthcare analytics, and AI applications.</p>
<h2 id="heading-references-for-the-article">References for the article</h2>
<ul>
<li><a href="https://ohdsi.github.io/CommonDataModel/cdm54.html">OMOP CDM v5.4 Documentation</a></li>
<li><a href="https://ohdsi.github.io/TheBookOfOhdsi">The Book of OHDSI</a></li>
<li><a href="https://athena.ohdsi.org">OHDSI ATHENA</a></li>
<li><a href="https://github.com/synthetichealth/synthea">Synthea</a></li>
<li><a href="https://github.com/OHDSI/ETL-Synthea">OHDSI ETL-Synthea Reference Implementation</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Generate Synthetic Healthcare Data Using Synthea: A Hands On Tutorial ]]>
                </title>
                <description>
                    <![CDATA[ Healthcare generates huge amounts of data every day, from patient visits and lab results to diagnoses, medications, and medical imaging. For developers and data engineers building healthcare applicati ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-generate-synthetic-healthcare-data-using-synthea-a-hands-on-tutorial/</link>
                <guid isPermaLink="false">6aff718ab7bbd995ee693880</guid>
                
                    <category>
                        <![CDATA[ SyntheticHealthcareData ]]>
                    </category>
                
                    <category>
                        <![CDATA[ healthcaredata ]]>
                    </category>
                
                    <category>
                        <![CDATA[ dataengineering ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HealthcareAI ]]>
                    </category>
                
                    <category>
                        <![CDATA[ healthtech ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Lakshmi Mahabaleshwara ]]>
                </dc:creator>
                <pubDate>Thu, 19 Nov 2026 22:00:42 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/17f495db-a70b-427b-a69d-4b200d573081.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Healthcare generates huge amounts of data every day, from patient visits and lab results to diagnoses, medications, and medical imaging.</p>
<p>For developers and data engineers building healthcare applications, access to realistic patient data is essential. Whether you are building a healthcare analytics pipeline, testing an Electronic Health Record (EHR) system, or experimenting with machine learning, you need data that reflects how healthcare systems actually work.</p>
<p>But there is a challenge: real patient data is sensitive, highly regulated, and often difficult to access. So how can we develop and test healthcare applications without exposing real patient information? One solution is to generate synthetic healthcare data.</p>
<p>In this tutorial, you will learn how to use Synthea, an open-source synthetic patient generator, to create realistic patient records. We'll generate a population of approximately 100 patients, explore the resulting healthcare datasets using Python, and reconstruct a patient's clinical history.</p>
<p>By the end, you will have your own synthetic healthcare dataset that you can use for learning, testing, and prototyping.</p>
<p>I have also included a <a href="https://github.com/lakshmi-mahabaleshwara/healthtech-playground/blob/main/explore_synthea_healthcare_data.ipynb?utm_source=chatgpt.com">companion Jupyter notebook</a> that you can use to explore the generated data with Python, visualize clinical events, and understand a synthetic patient's healthcare journey.</p>
<h3 id="heading-what-well-cover">What We'll Cover:</h3>
<ul>
<li><a href="#heading-1-what-is-synthetic-healthcare-data">1. What Is Synthetic Healthcare Data?</a><ul>
<li><a href="#heading-synthetic-data-vs-de-identified-data">Synthetic data vs. de-identified data</a></li>
<li><a href="#heading-why-is-synthetic-healthcare-data-useful">Why is synthetic healthcare data useful?</a></li>
</ul>
</li>
<li><a href="#heading-2-what-is-synthea">2. What Is Synthea?</a><ul>
<li><a href="#heading-what-data-can-synthea-generate">What data can Synthea generate?</a></li>
</ul>
</li>
<li><a href="#heading-3-prerequisites">3. Prerequisites</a><ul>
<li><a href="#heading-check-your-java-installation">Check your Java installation</a></li>
</ul>
</li>
<li><a href="#heading-4-how-to-install-synthea">4. How to Install Synthea</a><ul>
<li><a href="#heading-step-1-clone-the-repository">Step 1: Clone the repository</a></li>
<li><a href="#heading-step-2-build-the-project">Step 2: Build the project</a></li>
<li><a href="#heading-step-3-check-the-available-commands">Step 3: Check the available commands</a></li>
</ul>
</li>
<li><a href="#heading-5-how-to-generate-100-synthetic-patients">5. How to Generate 100 Synthetic Patients</a><ul>
<li><a href="#heading-why-use-a-random-seed">Why use a random seed?</a></li>
<li><a href="#heading-where-are-the-generated-files">Where are the generated files?</a></li>
<li><a href="#heading-why-did-synthea-generate-more-than-100-patients">Why did Synthea generate more than 100 patients?</a></li>
</ul>
</li>
<li><a href="#heading-6-understanding-the-generated-healthcare-dataset">6. Understanding the Generated Healthcare Dataset</a><ul>
<li><a href="#heading-understanding-the-csv-relationships">Understanding the CSV relationships</a></li>
<li><a href="#heading-how-are-these-files-connected">How are these files connected?</a></li>
</ul>
</li>
<li><a href="#heading-7-how-to-explore-synthetic-healthcare-data-with-python">7. How to Explore Synthetic Healthcare Data with Python</a><ul>
<li><a href="#heading-step-1-install-pandas">Step 1: Install Pandas</a></li>
<li><a href="#heading-step-2-load-the-datasets">Step 2: Load the datasets</a></li>
<li><a href="#heading-step-3-examine-patient-records">Step 3: Examine patient records</a></li>
<li><a href="#heading-step-4-explore-encounters">Step 4: Explore encounters</a></li>
<li><a href="#heading-step-5-explore-clinical-observations">Step 5: Explore clinical observations</a></li>
</ul>
</li>
<li><a href="#heading-8-reconstructing-a-patients-clinical-journey">8. Reconstructing a Patient's Clinical Journey</a><ul>
<li><a href="#heading-step-1-select-a-patient">Step 1: Select a patient</a></li>
<li><a href="#heading-step-2-examine-the-patients-demographics">Step 2: Examine the patient's demographics</a></li>
<li><a href="#heading-step-3-find-the-patients-encounters">Step 3: Find the patient's encounters</a></li>
<li><a href="#heading-step-4-examine-their-conditions">Step 4: Examine their conditions</a></li>
<li><a href="#heading-step-5-examine-their-observations">Step 5: Examine their observations</a></li>
</ul>
</li>
<li><a href="#heading-9-how-to-validate-your-synthetic-healthcare-dataset">9. How to Validate Your Synthetic Healthcare Dataset</a><ul>
<li><a href="#heading-check-for-duplicate-patient-identifiers">Check for duplicate patient identifiers</a></li>
<li><a href="#heading-check-whether-encounters-reference-valid-patients">Check whether encounters reference valid patients</a></li>
<li><a href="#heading-examine-missing-values">Examine missing values</a></li>
</ul>
</li>
<li><a href="#heading-10-limitations-of-synthetic-healthcare-data">10. Limitations of Synthetic Healthcare Data</a><ul>
<li><a href="#heading-1-synthetic-data-isnt-real-clinical-evidence">1. Synthetic data isn't real clinical evidence</a></li>
<li><a href="#heading-2-simulated-patterns-may-differ-from-real-world-patterns">2. Simulated patterns may differ from real-world patterns</a></li>
<li><a href="#heading-3-synthetic-data-isnt-automatically-ready-for-machine-learning">3. Synthetic data isn't automatically ready for machine learning</a></li>
<li><a href="#heading-4-the-generated-population-depends-on-configuration">4. The generated population depends on configuration</a></li>
</ul>
</li>
<li><a href="#heading-11-conclusion">11. Conclusion</a></li>
</ul>
<h2 id="heading-1-what-is-synthetic-healthcare-data">1. What Is Synthetic Healthcare Data?</h2>
<p>Synthetic healthcare data is artificially generated information designed to resemble real healthcare records without representing actual patients.</p>
<p>For example, a synthetic patient might have:</p>
<ul>
<li>Demographic information such as age and gender</li>
<li>A history of primary care visits</li>
<li>Diagnosed medical conditions</li>
<li>Lab test results</li>
<li>Prescribed medications</li>
<li>Procedures and hospital visits</li>
</ul>
<p>These records are generated using simulation models and predefined rules and not copied from real patient histories.</p>
<h3 id="heading-synthetic-data-vs-de-identified-data">Synthetic Data vs. De-identified Data</h3>
<p>It's important to understand the difference between these two types of data.</p>
<p><strong>De-identified data</strong> starts with real patient records and removes or transforms identifying information, such as names, addresses, and other personal identifiers.</p>
<p><strong>Synthetic data</strong>, on the other hand, is generated artificially. It doesn't directly represent an actual patient's medical history.</p>
<p>Synthetic data offers another way to create development and testing datasets without relying on actual patient records. But synthetic data isn't automatically statistically representative, clinically accurate, or free from bias.</p>
<h3 id="heading-why-is-synthetic-healthcare-data-useful">Why is Synthetic Healthcare Data Useful?</h3>
<p>Developers and researchers can use synthetic data in a variety of ways. It lets them develop and test healthcare applications, build data ingestion and transformation pipelines, and experiment with healthcare data models</p>
<p>They can also use it to test interoperability between healthcare systems, prototype analytics and machine learning workflows, and learn more about certain healthcare concepts and data relationships.</p>
<p>For this tutorial, we'll focus on generating structured healthcare data and understanding how the records relate to one another.</p>
<h2 id="heading-2-what-is-synthea">2. What Is Synthea?</h2>
<p><a href="https://github.com/synthetichealth/synthea">Synthea</a> is an open-source synthetic patient population simulator developed by MITRE.</p>
<p>Instead of generating random rows of patient information, Synthea simulates patient lifecycles. It models healthcare events over time, including medical conditions, clinical encounters, medications, procedures, and laboratory observations.</p>
<p>For example, a simulated patient might develop a medical condition, visit a healthcare provider, undergo testing, and receive medication. These events become part of that patient's longitudinal health record.</p>
<p>Synthea uses configurable clinical modules and population characteristics to generate these histories.</p>
<h3 id="heading-what-data-can-synthea-generate">What Data Can Synthea Generate?</h3>
<p>Synthea can generate many types of data, including:</p>
<table>
<thead>
<tr>
<th>Healthcare data</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>Patients</td>
<td>Demographics and patient identifiers</td>
</tr>
<tr>
<td>Encounters</td>
<td>Hospital visits, outpatient consultations, and emergency visits</td>
</tr>
<tr>
<td>Conditions</td>
<td>Diagnoses and clinical findings</td>
</tr>
<tr>
<td>Observations</td>
<td>Laboratory results, vital signs, and clinical measurements</td>
</tr>
<tr>
<td>Medications</td>
<td>Medication prescriptions and history</td>
</tr>
<tr>
<td>Procedures</td>
<td>Clinical procedures and interventions</td>
</tr>
<tr>
<td>Allergies</td>
<td>Recorded allergies</td>
</tr>
<tr>
<td>Immunizations</td>
<td>Vaccination records</td>
</tr>
<tr>
<td>Imaging studies</td>
<td>Medical imaging study metadata</td>
</tr>
<tr>
<td>Claims</td>
<td>Healthcare billing and insurance data</td>
</tr>
</tbody></table>
<p>Synthea supports several export formats, including <strong>CSV</strong> (which is useful for data analysis, SQL databases, and data engineering), <strong>HL7 FHIR</strong> (a standard for exchanging healthcare information between systems, commonly represented as JSON resources), and <strong>C-CDA</strong> (an XML-based format for exchanging clinical documents).</p>
<p>We'll use CSV in this tutorial because it's easy to explore with Python and can be imported into relational databases.</p>
<h2 id="heading-3-prerequisites">3. Prerequisites</h2>
<p>Before getting started, you'll need:</p>
<ul>
<li>Java Development Kit (JDK) 17 or newer</li>
<li>Git</li>
<li>A terminal or command-line environment</li>
<li>Python 3, for the exploration section</li>
<li>Basic familiarity with CSV files and Python</li>
</ul>
<p>Synthea recommends supported long-term-support Java versions, such as Java 17 or 25.</p>
<p>I'll demonstrate the commands using macOS, but the same general workflow works on Linux and Windows.</p>
<h3 id="heading-check-your-java-installation">Check Your Java Installation</h3>
<p>Open Terminal and run:</p>
<pre><code class="language-bash">java -version
</code></pre>
<p>You should see an installed Java version, for example:</p>
<pre><code class="language-shell">openjdk version "17.x.x"
</code></pre>
<p>Make sure you're using a JDK rather than only a Java Runtime Environment.</p>
<p>If Java isn't installed, download a compatible JDK before proceeding.</p>
<p>You can also check Git:</p>
<pre><code class="language-bash">git --version
</code></pre>
<p>And Python:</p>
<pre><code class="language-bash">python3 --version
</code></pre>
<h2 id="heading-4-how-to-install-synthea">4. How to Install Synthea</h2>
<p>Let's download the Synthea source code from its official GitHub repository.</p>
<h3 id="heading-step-1-clone-the-repository">Step 1: Clone the Repository</h3>
<p>Open your terminal and execute:</p>
<pre><code class="language-bash">git clone https://github.com/synthetichealth/synthea.git
</code></pre>
<p>This downloads the Synthea project into a local directory.</p>
<p>Navigate into it:</p>
<pre><code class="language-bash">cd synthea
</code></pre>
<h3 id="heading-step-2-build-the-project">Step 2: Build the Project</h3>
<p>Synthea is written in Java and uses Gradle for building the application.</p>
<p>Run:</p>
<pre><code class="language-bash">./gradlew build
</code></pre>
<p>The included Gradle wrapper handles the required Gradle version, so you don't need to install Gradle separately.</p>
<p>The first build may take some time because Gradle needs to download dependencies. When the build completes successfully, you're ready to generate patients.</p>
<p>On Windows, you can use <code>gradlew.bat</code> instead of <code>./gradlew</code>.</p>
<h3 id="heading-step-3-check-the-available-commands">Step 3: Check the Available Commands</h3>
<p>Run:</p>
<pre><code class="language-bash">./run_synthea -h
</code></pre>
<p>This displays the available command-line options.</p>
<p>Some important options are:</p>
<table>
<thead>
<tr>
<th>Argument</th>
<th>Purpose</th>
</tr>
</thead>
<tbody><tr>
<td><code>-p</code></td>
<td>Target population size</td>
</tr>
<tr>
<td><code>-s</code></td>
<td>Random seed</td>
</tr>
<tr>
<td><code>-r</code></td>
<td>Simulation reference date</td>
</tr>
<tr>
<td><code>-a</code></td>
<td>Patient age range</td>
</tr>
<tr>
<td><code>-g</code></td>
<td>Gender filter</td>
</tr>
<tr>
<td><code>-o</code></td>
<td>Population overflow setting</td>
</tr>
</tbody></table>
<p>You can also modify configuration properties directly through command-line arguments.</p>
<p>We'll use these options in the next step.</p>
<h2 id="heading-5-how-to-generate-100-synthetic-patients">5. How to Generate 100 Synthetic Patients</h2>
<p>Now we'll generate our first synthetic healthcare population.</p>
<p>From your Synthea directory, execute:</p>
<pre><code class="language-bash">./run_synthea -s 12345 -p 100 \
  --exporter.csv.export=true
</code></pre>
<p>Let's understand what the command does.</p>
<ul>
<li><code>-s 12345</code> sets the random seed used during data generation. Using a fixed seed helps make experiments reproducible.</li>
<li><code>-p 100</code> requests a population size of 100 patients.</li>
<li><code>--exporter.csv.export=true</code> enables the CSV exporter.</li>
</ul>
<p>This last option is important. Synthea's default configuration doesn't enable CSV export, so running it without this setting may leave you with FHIR files and metadata but no <code>csv</code> directory.</p>
<h3 id="heading-why-use-a-random-seed">Why Use a Random Seed?</h3>
<p>Suppose you're building a data engineering pipeline and repeatedly testing your transformations.</p>
<p>You want your input dataset to remain stable between runs. Using a fixed seed helps achieve this. For stronger reproducibility, also pin the Synthea version and fix the simulation's reference date.</p>
<p>For example, you can add:</p>
<pre><code class="language-bash">-r 20261001
</code></pre>
<p>This sets the simulation reference date to October 1, 2026.</p>
<p>Reproducibility also depends on the generator version and configuration, and not every generated field is necessarily invariant across execution environments.</p>
<h3 id="heading-where-are-the-generated-files">Where Are the Generated Files?</h3>
<p>After Synthea finishes, you should see an output directory:</p>
<pre><code class="language-text">synthea/
│
├── output/
│   ├── csv/
│   ├── fhir/
│   └── metadata/
│
├── src/
├── gradlew
└── run_synthea
</code></pre>
<p>The files of interest are inside:</p>
<pre><code class="language-text">output/csv/
</code></pre>
<p>You can list them using:</p>
<pre><code class="language-bash">ls output/csv
</code></pre>
<p>Depending on your version and configuration, you'll find files such as:</p>
<pre><code class="language-text">patients.csv
encounters.csv
conditions.csv
observations.csv
medications.csv
procedures.csv
allergies.csv
immunizations.csv
careplans.csv
imaging_studies.csv
claims.csv
providers.csv
organizations.csv
</code></pre>
<p>Each CSV represents a different part of the simulated healthcare ecosystem.</p>
<h3 id="heading-why-did-synthea-generate-more-than-100-patients">Why Did Synthea Generate More Than 100 Patients?</h3>
<p>Here's something interesting I noticed during my experiment. I requested a population of 100, but Synthea generated <strong>115 patient records</strong>.</p>
<p>This happens because Synthea normally uses population overflow when generating its target population. The simulation may generate additional people when patients die before the reference date, so the exported records can include more than the requested number.</p>
<p>If you need exactly 100 generated patient records, you can disable overflow:</p>
<pre><code class="language-bash">./run_synthea -s 12345 -p 100 \
  -o false \
  --exporter.csv.export=true
</code></pre>
<p>But this changes how the target population is constructed. In particular, the demographics of the surviving population might no longer match the original population targets as closely.</p>
<p>For this tutorial, we'll keep the default behavior because it gives us a more representative example of how Synthea models a population.</p>
<h2 id="heading-6-understanding-the-generated-healthcare-dataset">6. Understanding the Generated Healthcare Dataset</h2>
<p>Before analyzing anything, let's see how much data we've generated.</p>
<p>Run:</p>
<pre><code class="language-bash">wc -l output/csv/*.csv
</code></pre>
<p>This counts the number of lines in each CSV file.</p>
<p>Here's a selection from my generated dataset:</p>
<table>
<thead>
<tr>
<th>File</th>
<th align="right">Records</th>
</tr>
</thead>
<tbody><tr>
<td>patients.csv</td>
<td align="right">115</td>
</tr>
<tr>
<td>encounters.csv</td>
<td align="right">5,985</td>
</tr>
<tr>
<td>conditions.csv</td>
<td align="right">4,070</td>
</tr>
<tr>
<td>observations.csv</td>
<td align="right">75,004</td>
</tr>
<tr>
<td>medications.csv</td>
<td align="right">4,454</td>
</tr>
<tr>
<td>procedures.csv</td>
<td align="right">16,777</td>
</tr>
<tr>
<td>imaging_studies.csv</td>
<td align="right">504</td>
</tr>
</tbody></table>
<p>These figures come from one simulation run. Your results may differ depending on the version, seed, reference date, and configuration.</p>
<p>Notice something important: we generated a relatively small population, but it produced thousands of clinical events.</p>
<p>That's because a patient may have multiple healthcare encounters over their lifetime, and each encounter can generate several conditions, observations, medications, or procedures.</p>
<h3 id="heading-understanding-the-csv-relationships">Understanding the CSV Relationships</h3>
<p>Let's look at six important files.</p>
<h4 id="heading-1-patientscsv">1. patients.csv</h4>
<p>Contains demographic and identifying information for each synthetic patient.</p>
<p>Some columns include:</p>
<pre><code class="language-text">Id
BIRTHDATE
DEATHDATE
GENDER
RACE
ETHNICITY
CITY
STATE
</code></pre>
<p>The <code>Id</code> column uniquely identifies a synthetic patient.</p>
<h4 id="heading-2-encounterscsv">2. encounters.csv</h4>
<p>Contains information about healthcare visits.</p>
<p>Important columns include:</p>
<pre><code class="language-text">Id
START
STOP
PATIENT
ENCOUNTERCLASS
DESCRIPTION
</code></pre>
<p>An encounter represents an interaction between a patient and the healthcare system. Examples include outpatient visits, emergency encounters, and hospital admissions.</p>
<p>The <code>PATIENT</code> column links each encounter back to a patient in <code>patients.csv</code>.</p>
<h4 id="heading-3-conditionscsv">3. conditions.csv</h4>
<p>Contains clinical conditions and diagnoses.</p>
<p>For example:</p>
<pre><code class="language-text">START
STOP
PATIENT
ENCOUNTER
SYSTEM
CODE
DESCRIPTION
</code></pre>
<p>The <code>SYSTEM</code> and <code>CODE</code> columns identify the terminology system and clinical concept.</p>
<h4 id="heading-4-observationscsv">4. observations.csv</h4>
<p>Contains clinical measurements, laboratory results, and other recorded observations.</p>
<p>Some columns include:</p>
<pre><code class="language-text">DATE
PATIENT
ENCOUNTER
CATEGORY
CODE
DESCRIPTION
VALUE
UNITS
TYPE
</code></pre>
<p>Observations might include blood pressure, heart rate, glucose levels, or laboratory test results.</p>
<p>An important detail is that not every observation value is numeric. Some observations contain text.</p>
<h4 id="heading-5-medicationscsv">5. medications.csv</h4>
<p>Contains medication-related records associated with patients and encounters.</p>
<h4 id="heading-6-procedurescsv">6. procedures.csv</h4>
<p>Contains records of procedures performed during clinical care.</p>
<h3 id="heading-how-are-these-files-connected">How Are These Files Connected?</h3>
<p>Here's the simplified view.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69fd77e89f93a850a46d376f/6e648bdb-f11b-4d2a-97a9-c39e2b423585.png" alt="Simplified healthcare data relationship diagram showing how patient records connect to encounters, conditions, observations, medications, and procedures through PATIENT and ENCOUNTER identifiers." style="display: block;" width="1238" height="483" loading="lazy">

<p>The two key identifiers you'll see frequently are:</p>
<ul>
<li><code>PATIENT</code>: Links a record to a patient.</li>
<li><code>ENCOUNTER</code>: Links a clinical event to a healthcare encounter.</li>
</ul>
<p>These relationships let us reconstruct a longitudinal patient history from multiple tables.</p>
<p>If you want to understand every column, the official <a href="https://github.com/synthetichealth/synthea/wiki/CSV-File-Data-Dictionary">Synthea CSV Data Dictionary</a> is a useful reference.</p>
<h2 id="heading-7-how-to-explore-synthetic-healthcare-data-with-python">7. How to Explore Synthetic Healthcare Data with Python</h2>
<p>Now that we have generated the dataset, let's explore it. We'll use Pandas because it provides a straightforward way to work with structured healthcare data.</p>
<h3 id="heading-step-1-install-pandas">Step 1: Install Pandas</h3>
<p>From the Synthea directory, create a Python virtual environment:</p>
<pre><code class="language-bash">python3 -m venv .venv
source .venv/bin/activate
</code></pre>
<p>On Windows, activate the virtual environment using the appropriate script for your shell.</p>
<p>Then install Pandas:</p>
<pre><code class="language-bash">python -m pip install pandas
</code></pre>
<h3 id="heading-step-2-load-the-datasets">Step 2: Load the Datasets</h3>
<p>Create a file called:</p>
<pre><code class="language-text">explore_synthea.py
</code></pre>
<p>Add the following Python code:</p>
<pre><code class="language-python">from pathlib import Path
import pandas as pd

csv_dir = Path("output/csv")

files = [
    "patients",
    "encounters",
    "conditions",
    "observations",
    "medications",
    "procedures",
]

tables = {
    name: pd.read_csv(
        csv_dir / f"{name}.csv",
        low_memory=False
    )
    for name in files
}

for name, df in tables.items():
    print(f"{name}: {len(df):,} records")
</code></pre>
<p>Run the script:</p>
<pre><code class="language-python">python explore_synthea.py
</code></pre>
<p>You should see the number of records in each dataset.</p>
<p>We're counting data rows here, so unlike <code>wc -l</code>, the header isn't included.</p>
<h3 id="heading-step-3-examine-patient-records">Step 3: Examine Patient Records</h3>
<p>Let's look at the patient table:</p>
<pre><code class="language-python">patients = tables["patients"]

print(patients.shape)
print(patients.columns.tolist())
</code></pre>
<p>We can select a smaller set of columns:</p>
<pre><code class="language-python">patient_view = patients[
    ["Id", "BIRTHDATE", "GENDER", "CITY", "STATE"]
]

print(patient_view.head())
</code></pre>
<p>Although the original data is synthetic, I prefer not to display unnecessary fields such as simulated Social Security numbers, passport numbers, or full addresses. <strong>Only use the fields needed for a particular purpose.</strong></p>
<h3 id="heading-step-4-explore-encounters">Step 4: Explore Encounters</h3>
<p>Let's examine the encounters table:</p>
<pre><code class="language-python">encounters = tables["encounters"]

print(
    encounters[
        ["Id", "PATIENT", "START", "ENCOUNTERCLASS"]
    ].head()
)
</code></pre>
<p>We can also examine encounter categories:</p>
<pre><code class="language-python">print(
    encounters["ENCOUNTERCLASS"].value_counts()
)
</code></pre>
<p>This helps us understand the different types of healthcare visits represented in our dataset.</p>
<h3 id="heading-step-5-explore-clinical-observations">Step 5: Explore Clinical Observations</h3>
<p>Let's examine the observations table:</p>
<pre><code class="language-python">observations = tables["observations"]

print(
    observations[
        ["DESCRIPTION", "VALUE", "UNITS"]
    ].head(10)
)
</code></pre>
<p>To see the most frequently recorded observations:</p>
<pre><code class="language-python">print(
    observations["DESCRIPTION"]
    .value_counts()
    .head(10)
)
</code></pre>
<p>This is where healthcare data becomes interesting.</p>
<p>The contains demographic information, but it also contains measurements and clinical events recorded over time.</p>
<p>For healthcare analytics and AI, understanding what each measurement represents is as important as understanding its numerical value.</p>
<h2 id="heading-8-reconstructing-a-patients-clinical-journey">8. Reconstructing a Patient's Clinical Journey</h2>
<p>We've explored the tables independently. But what happens when we want to understand one patient's healthcare history?</p>
<p>A patient might visit a physician several times, receive multiple diagnoses, undergo laboratory tests, and receive medication.</p>
<p>That information is distributed across different CSV files. Let's bring some of it together.</p>
<h3 id="heading-step-1-select-a-patient">Step 1: Select a Patient</h3>
<p>For our example, let's choose the patient with the most recorded encounters.</p>
<p>Add this code to the script:</p>
<pre><code class="language-plaintext">patient_id = (
    encounters["PATIENT"]
    .value_counts()
    .idxmax()
)

print("Selected patient:", patient_id)
</code></pre>
<p>We're selecting this patient because a larger number of visits gives us more events to explore. It doesn't necessarily mean the patient has more severe health conditions.</p>
<h3 id="heading-step-2-examine-the-patients-demographics">Step 2: Examine the Patient's Demographics</h3>
<pre><code class="language-plaintext">patient = patients[
    patients["Id"] == patient_id
]

print(
    patient[
        ["BIRTHDATE", "GENDER", "CITY", "STATE"]
    ]
)
</code></pre>
<h3 id="heading-step-3-find-the-patients-encounters">Step 3: Find the Patient's Encounters</h3>
<pre><code class="language-plaintext">patient_encounters = encounters[
    encounters["PATIENT"] == patient_id
].copy()

patient_encounters["START"] = pd.to_datetime(
    patient_encounters["START"],
    utc=True
)

patient_encounters = (
    patient_encounters
    .sort_values("START")
)

print(
    patient_encounters[
        ["START", "ENCOUNTERCLASS", "DESCRIPTION"]
    ].head(15)
)
</code></pre>
<p>Now we can see the patient's visits in chronological order.</p>
<h3 id="heading-step-4-examine-their-conditions">Step 4: Examine Their Conditions</h3>
<pre><code class="language-plaintext">conditions = tables["conditions"]

patient_conditions = conditions[
    conditions["PATIENT"] == patient_id
]

print(
    patient_conditions[
        ["START", "DESCRIPTION"]
    ].sort_values("START").head(15)
)
</code></pre>
<h3 id="heading-step-5-examine-their-observations">Step 5: Examine Their Observations</h3>
<pre><code class="language-plaintext">patient_observations = observations[
    observations["PATIENT"] == patient_id
]

print(
    patient_observations[
        ["DATE", "DESCRIPTION", "VALUE", "UNITS"]
    ].sort_values("DATE").tail(15)
)
</code></pre>
<p>We have now explored several pieces of one synthetic patient's medical history.</p>
<p>A patient's healthcare journey rarely exists in one table. Understanding it requires connecting different clinical events across time.</p>
<p>A single encounter may have several observations and multiple conditions, so joining both tables without considering their relationships can multiply records unexpectedly.</p>
<p>For this introductory example, examining each event type separately is easier to follow.</p>
<h2 id="heading-9-how-to-validate-your-synthetic-healthcare-dataset">9. How to Validate Your Synthetic Healthcare Dataset</h2>
<p>Before using any generated dataset, it's good practice to understand its structure and check important assumptions.</p>
<h3 id="heading-check-for-duplicate-patient-identifiers">Check for Duplicate Patient Identifiers</h3>
<pre><code class="language-plaintext">duplicate_ids = (
    patients["Id"].duplicated().sum()
)

print("Duplicate patient IDs:", duplicate_ids)
</code></pre>
<p>Patient identifiers should be unique within <code>patients.csv</code>.</p>
<h3 id="heading-check-whether-encounters-reference-valid-patients">Check Whether Encounters Reference Valid Patients</h3>
<pre><code class="language-plaintext">invalid_encounters = encounters[
    ~encounters["PATIENT"].isin(patients["Id"])
]

print(
    "Encounters referencing unknown patients:",
    len(invalid_encounters)
)
</code></pre>
<p>This verifies a basic relational integrity constraint.</p>
<h3 id="heading-examine-missing-values">Examine Missing Values</h3>
<pre><code class="language-plaintext">print(
    observations.isna().sum()
    .sort_values(ascending=False)
    .head(10)
)
</code></pre>
<p>Missing values don't always mean bad data. For example, Synthea can generate quality-of-life observations that aren't associated with a particular encounter. These records may legitimately have an empty <code>ENCOUNTER</code> field.</p>
<p>We should understand why something is missing before deciding whether to remove or replace it. This is especially important when working with healthcare data.</p>
<h2 id="heading-10-limitations-of-synthetic-healthcare-data">10. Limitations of Synthetic Healthcare Data</h2>
<p>Synthetic healthcare data is extremely useful, but it's important to understand what it can and can't represent.</p>
<h3 id="heading-1-synthetic-data-isnt-real-clinical-evidence">1. Synthetic Data Isn't Real Clinical Evidence</h3>
<p>Synthea simulates healthcare events using predefined models and rules.</p>
<p>The resulting data can look realistic, but it shouldn't be assumed to reproduce the full complexity of actual patient populations.</p>
<h3 id="heading-2-simulated-patterns-may-differ-from-real-world-patterns">2. Simulated Patterns May Differ from Real-world Patterns</h3>
<p>Real healthcare data can contain inconsistencies introduced by clinical workflows, patient behavior, billing practices, interoperability failures, and documentation differences.</p>
<p>Synthetic datasets may not capture all these complexities.</p>
<h3 id="heading-3-synthetic-data-isnt-automatically-ready-for-machine-learning">3. Synthetic Data Isn't Automatically Ready for Machine Learning</h3>
<p>Generating data is only the first step. Before developing a machine learning model, you may still need to:</p>
<ul>
<li>Validate clinical concepts and coding systems</li>
<li>Handle missing and inconsistent data</li>
<li>Integrate related datasets</li>
<li>Define the prediction target</li>
<li>Engineer meaningful features</li>
<li>Evaluate data representativeness and potential bias</li>
</ul>
<p>A model that performs well on synthetic data may not generalize to real clinical settings.</p>
<h3 id="heading-4-the-generated-population-depends-on-configuration">4. The Generated Population Depends on Configuration</h3>
<p>Synthea's clinical modules, population characteristics, reference date, and export settings can affect the generated records.</p>
<p>For reproducible experiments, document these settings along with the Synthea version and seed.</p>
<h2 id="heading-11-conclusion">11. Conclusion</h2>
<p>In this tutorial, we generated a synthetic healthcare population using Synthea and explored the resulting patient records.</p>
<p>You learned how to:</p>
<ul>
<li>Install and configure Synthea</li>
<li>Generate a synthetic patient population</li>
<li>Export healthcare records as CSV files</li>
<li>Understand patients, encounters, conditions, observations, and medications</li>
<li>Explore the data using Python and Pandas</li>
<li>Reconstruct a synthetic patient's clinical history</li>
<li>Perform basic dataset validation</li>
</ul>
<p>Tools like Synthea give developers a practical way to explore relationships in healthcare data without relying on access to real patient records.</p>
<p>The dataset we have generated can now serve as a starting point for building healthcare data pipelines, testing database designs, experimenting with interoperability standards, and exploring healthcare analytics.</p>
<p>Additional resources</p>
<ul>
<li><a href="https://synthetichealth.github.io/synthea/">Synthea Official Website</a></li>
<li><a href="https://github.com/synthetichealth/synthea">Synthea GitHub Repository</a></li>
<li><a href="https://github.com/synthetichealth/synthea/wiki/CSV-File-Data-Dictionary">Synthea CSV Data Dictionary</a></li>
<li><a href="https://github.com/synthetichealth/synthea/blob/master/src/main/resources/synthea.properties">Synthea Configuration</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
