0% found this document useful (0 votes)
10 views12 pages

EHR System Structure and Analysis Guide

The document outlines a series of tutorials focused on healthcare analytics, including the structure of Electronic Health Records (EHR) using the MIMIC-III dataset, exploratory data analysis on the PIMA Indians Diabetes dataset, and image segmentation techniques applied to medical images. Each tutorial aims to educate on analyzing healthcare data, identifying structured and unstructured fields, and visualizing data distributions. The tutorials include practical coding examples and visual outputs to enhance understanding of the concepts.

Uploaded by

71762132037
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

EHR System Structure and Analysis Guide

The document outlines a series of tutorials focused on healthcare analytics, including the structure of Electronic Health Records (EHR) using the MIMIC-III dataset, exploratory data analysis on the PIMA Indians Diabetes dataset, and image segmentation techniques applied to medical images. Each tutorial aims to educate on analyzing healthcare data, identifying structured and unstructured fields, and visualizing data distributions. The tutorials include practical coding examples and visual outputs to enhance understanding of the concepts.

Uploaded by

71762132037
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Coimbatore Institute of Technology

Department of Computing – Data Science – IX Semester


21MDS93 – Healthcare Analytics
Tutorial –1
Name: Saivarshini S
ROLL NO: 71762132037
DATE: 20.06.2025
STRUCTURE AND COMPONENTS OF AN EHR SYSTEM
AIM:
To understand the structure of Electronic Health Records (EHR) by analysing anonymized ICU
patient data from the MIMIC-III Demo dataset, identifying structured and unstructured fields, and
summarizing components such as demographics, diagnoses, prescriptions, and clinical notes.

INTRODUCTION:
Electronic Health Records (EHRs) are digital representations of a patient's clinical history. These
records include patient demographics, admission details, diagnoses, prescriptions, and clinical
observations. In this tutorial, we utilize the MIMIC-III demo dataset, which contains both structured
(tabular) and unstructured (free-text) clinical data from ICU patients, to explore and understand the
structure and fields of an EHR system.

DATASET DESCRIPTION:
MIMIC-III Demo contains the following CSV files:
File Name Description
[Link] Patient demographic details
[Link] Admission details including time and type
DIAGNOSES_ICD.csv Diagnoses coded using ICD-9
[Link] Drug prescription records
[Link] Unstructured clinical notes
[Link] Time-stamped charted events (e.g., vitals, labs)

1. Study a simple EHR Layout:


Code:
import pandas as pd
patients = pd.read_csv("[Link]")
admissions = pd.read_csv("[Link]")
noteevents = pd.read_csv("[Link]")
chartevents = pd.read_csv("[Link]")
diagnoses = pd.read_csv("DIAGNOSES_ICD.csv")
prescriptions = pd.read_csv("[Link]")
print("Patients Table:")
print(patients[['subject_id', 'gender', 'dob']].head())
print("\nAdmissions Table:")
print(admissions[['subject_id', 'hadm_id', 'admittime', 'dischtime', 'admission_type']].head())
print("\nClinical Notes:")
print(noteevents[['subject_id', 'chartdate', 'category', 'text']].head())
print("\nVitals (CHARTEVENTS):")
print(chartevents[['subject_id', 'charttime', 'valuenum', 'valueuom']].head())
print("\nDiagnoses:")
print(diagnoses[['subject_id', 'hadm_id', 'icd9_code']].head())
print("\nPrescriptions:")
print(prescriptions[['subject_id', 'drug', 'startdate', 'enddate']].head())

Output:
2. Identify structured vs unstructured fields
Code:
structured_fields = {
"PATIENTS": [Link](),
"ADMISSIONS": [Link](),
"CHARTEVENTS": [Link](),
"DIAGNOSES_ICD": [Link](),
"PRESCRIPTIONS": [Link]()
}
unstructured_fields = {
"NOTEEVENTS": ["text"]
}
print("Structured Fields")
for table, fields in structured_fields.items():
print(f"{table}: {fields}")
print("\nUnstructured Fields")
for table, fields in unstructured_fields.items():
print(f"{table}: {fields}")

Output:

Structured Fields :

PATIENTS: ['row_id', 'subject_id', 'gender', 'dob', 'dod', 'dod_hosp', 'dod_ssn', 'expire_flag']

ADMISSIONS: ['row_id', 'subject_id', 'hadm_id', 'admittime', 'dischtime', 'deathtime',


'admission_type', 'admission_location', 'discharge_location', 'insurance', 'language', 'religion',
'marital_status', 'ethnicity', 'edregtime', 'edouttime', 'diagnosis', 'hospital_expire_flag',
'has_chartevents_data']

CHARTEVENTS: ['row_id', 'subject_id', 'hadm_id', 'icustay_id', 'itemid', 'charttime', 'storetime', 'cgid',


'value', 'valuenum', 'valueuom', 'warning', 'error', 'resultstatus', 'stopped']

DIAGNOSES_ICD: ['row_id', 'subject_id', 'hadm_id', 'seq_num', 'icd9_code']

PRESCRIPTIONS: ['row_id', 'subject_id', 'hadm_id', 'icustay_id', 'startdate', 'enddate', 'drug_type',


'drug', 'drug_name_poe', 'drug_name_generic', 'formulary_drug_cd', 'gsn', 'ndc', 'prod_strength',
'dose_val_rx', 'dose_unit_rx', 'form_val_disp', 'form_unit_disp', 'route']

Unstructured Fields

NOTEEVENTS: ['text']
3. Create a summary of EHR components:

Code:

import pandas as pd

data = [

{"Component": "Demographics", "Source": "PATIENTS", "Type": "Structured", "Fields": "gender,


dob"},

{"Component": "Admissions", "Source": "ADMISSIONS", "Type": "Structured", "Fields":


"admittime, dischtime"},

{"Component": "Vitals", "Source": "CHARTEVENTS", "Type": "Structured", "Fields": "charttime,


valuenum, valueuom"},

{"Component": "Diagnoses", "Source": "DIAGNOSES_ICD", "Type": "Structured", "Fields":


"icd9_code"},

{"Component": "Prescriptions", "Source": "PRESCRIPTIONS", "Type": "Structured", "Fields":


"drug, startdate"},

{"Component": "Clinical Notes", "Source": "NOTEEVENTS", "Type": "Unstructured", "Fields":


"text"}

df_summary = [Link](data)

print(df_summary)

Output:
Tutorial – 2

DATASET EXPLORATION: BASIC ANALYTICS ON HEALTHCARE DATASET

AIM:

To perform exploratory data analysis (EDA) on a healthcare dataset by computing summary


statistics, identifying missing values, and visualizing the data distribution using various plot
types.

INTRODUCTION:

Exploratory Data Analysis (EDA) is an essential step in understanding the patterns and
characteristics of a dataset before performing predictive modeling or hypothesis testing. In
this tutorial, we use the PIMA Indians Diabetes Dataset, which contains medical records of
female patients of Pima Indian heritage, to analyze and visualize the data distribution,
calculate basic statistics, and identify data quality issues.

DATASET DESCRIPTION:

The dataset consists of the following columns:

 Pregnancies: Number of times pregnant


 Glucose: Plasma glucose concentration
 BloodPressure: Diastolic blood pressure (mm Hg)
 SkinThickness: Triceps skin fold thickness (mm)
 Insulin: 2-Hour serum insulin (mu U/ml)
 BMI: Body mass index (weight in kg/(height in m)^2)
 DiabetesPedigreeFunction: Diabetes pedigree function
 Age: Age in years
 Outcome: Class variable (0 = non-diabetic, 1 = diabetic)

Link: Diabetes

Code:

import pandas as pd
df = pd.read_csv("[Link]")

print("First 5 Rows of the Dataset ")

print([Link]())

print("\n Mean of Numeric Columns ")

print([Link](numeric_only=True))

print("\n Median of Numeric Columns ")

print([Link](numeric_only=True))
print("\n Missing Values Per Column ")

print([Link]().sum())

columns_to_check = ['Glucose', 'BloodPressure', 'SkinThickness', 'Insulin', 'BMI']

print("\nZero Values in Critical Columns ")

for col in columns_to_check:

zero_count = (df[col] == 0).sum()

print(f"{col}: {zero_count} zero values")

import seaborn as sns

import [Link] as plt

[Link](style="whitegrid")

[Link](figsize=(6, 4))

[Link](x='Outcome', data=df, palette='Set2')

[Link]("Diabetes Outcome Distribution")

[Link]("Outcome (0 = No Diabetes, 1 = Diabetes)")

[Link]("Count")

[Link]()
df['AgeGroup'] = [Link](df['Age'], bins=[20, 30, 40, 50, 60, 70, 80], labels=["20-30", "31-
40", "41-50", "51-60", "61-70", "71-80"])

[Link](figsize=(6,6))

age_group_counts = df['AgeGroup'].value_counts().sort_index()

[Link](age_group_counts, labels=age_group_counts.index, autopct='%1.1f%%',


startangle=140)

[Link]("Patient Age Group Distribution")

[Link]('equal')

[Link]()
[Link](figsize=(8, 5))

[Link](df['Glucose'], bins=15, color='skyblue', edgecolor='black')

[Link]("Glucose Level Distribution")

[Link]("Glucose")

[Link]("Number of Patients")

[Link](True)

[Link]()
Tutorial-3

IMAGE SEGMENTATION WITH PYTHON (MEDICAL IMAGE)

AIM:

To apply basic image segmentation techniques on a medical image using thresholding (Otsu’s
method) to identify and visualize the Region of Interest (ROI), such as a brain tumor.

INTRODUCTION:

Medical image segmentation is an essential task in healthcare analytics and diagnostics. It


helps in isolating structures such as tumors, tissues, or organs from medical scans. This
tutorial uses a grayscale brain MRI image and applies Otsu’s thresholding to segment the
tumor region from the background.

DATASET/IMAGE DESCRIPTION:

We use a sample grayscale MRI scan image of the human brain containing a tumor. The
image is loaded in grayscale format and processed using OpenCV.

Link: Lung cancer Dataset

Code:

import cv2

import [Link] as plt

image = [Link]("[Link]",
cv2.IMREAD_GRAYSCALE)

[Link](figsize=(6,6))

[Link](image, cmap='gray')

[Link]("Original Brain MRI")

[Link]('off')

[Link]()
blurred = [Link](image, (5, 5), 0)

_, segmented = [Link](blurred, 0, 255, cv2.THRESH_BINARY +


cv2.THRESH_OTSU)

[Link](figsize=(6,6))

[Link](segmented, cmap='gray')

[Link]("Segmented Brain MRI (Otsu Threshold)")

[Link]('off')

[Link]()
contours, _ = [Link](segmented, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)

contour_image = [Link]()

[Link](contour_image, contours, -1, (0, 255, 0), 2)

[Link](figsize=(6,6))

[Link](contour_image, cmap='gray')

[Link]("Identified ROI (Contours)")

[Link]('off')

[Link]()

You might also like