About this course
<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="600" height="400" 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>