Spaces:
Sleeping
Sleeping
File size: 8,080 Bytes
893ed02 6e8dad4 c069834 2d31353 da3de0a 2d31353 95a0a03 2d31353 95a0a03 4e27e6a 2d31353 4e27e6a da3de0a 2d31353 4e27e6a da3de0a 4e27e6a 95a0a03 4e27e6a 95a0a03 4e27e6a 95a0a03 3d6b7f5 4e27e6a 3d6b7f5 4e27e6a 95a0a03 6e8dad4 4e27e6a 2d31353 95a0a03 6e8dad4 2d31353 4e27e6a da3de0a 95a0a03 8f89163 2d31353 95a0a03 4e27e6a 95a0a03 4e27e6a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
import streamlit as st
import pandas as pd
import numpy as np
# Seed for reproducibility
np.random.seed(42)
# Function to generate synthetic BreastCancer data
def generate_breast_cancer_data(num_patients):
primary_keys = [f"PPK_{i+1:05d}" for i in range(num_patients)]
ages = []
menopausal_status = []
tumor_sizes = []
lymph_nodes = []
grades = []
stages = []
er_status = []
pr_status = []
her2_status = []
ki67_level = []
tnbc_status = []
brca_mutation = []
overall_health = []
genomic_score = []
treatment = []
for i in range(num_patients):
age = int(np.random.normal(60, 10))
age = max(30, min(age, 80))
ages.append(age)
menopausal = "Post-menopausal" if age >= 50 else "Pre-menopausal"
menopausal_status.append(menopausal)
tumor_size = round(np.random.lognormal(mean=0.7, sigma=0.5), 2)
tumor_sizes.append(tumor_size)
lymph_node = (
"Positive"
if (tumor_size > 2.0 and np.random.rand() < 0.6)
or (tumor_size <= 2.0 and np.random.rand() < 0.3)
else "Negative"
)
lymph_nodes.append(lymph_node)
grade = np.random.choice([1, 2, 3], p=[0.1, 0.4, 0.5] if tumor_size > 2.0 else [0.3, 0.5, 0.2])
grades.append(grade)
if tumor_size <= 2.0 and lymph_node == "Negative":
stage = "I"
elif (tumor_size > 2.0 and tumor_size <= 5.0) and lymph_node == "Negative":
stage = "II"
elif lymph_node == "Positive" or tumor_size > 5.0:
stage = "III"
else:
stage = "II"
if np.random.rand() < 0.05:
stage = "IV"
stages.append(stage)
er = np.random.choice(["Positive", "Negative"], p=[0.75, 0.25])
pr = "Positive" if er == "Positive" and np.random.rand() > 0.1 else "Negative"
er_status.append(er)
pr_status.append(pr)
her2 = np.random.choice(["Positive", "Negative"], p=[0.3, 0.7] if grade == 3 else [0.15, 0.85])
her2_status.append(her2)
ki67 = "High" if grade == 3 and np.random.rand() < 0.8 else "Low"
ki67_level.append(ki67)
tnbc = "Positive" if er == "Negative" and pr == "Negative" and her2 == "Negative" else "Negative"
tnbc_status.append(tnbc)
brca = "Positive" if (tnbc == "Positive" or age < 40) and np.random.rand() < 0.2 else "Negative"
brca_mutation.append(brca)
health = "Good" if age < 65 and np.random.rand() < 0.9 else "Poor"
overall_health.append(health)
recurrence_score = (
np.random.choice(["Low", "Intermediate", "High"], p=[0.6, 0.3, 0.1])
if er == "Positive" and her2 == "Negative"
else "N/A"
)
genomic_score.append(recurrence_score)
if stage in ["I", "II"]:
if tnbc == "Positive":
treat = "Surgery, Chemotherapy, and Radiation Therapy"
elif er == "Positive" and recurrence_score != "N/A":
if recurrence_score == "High":
treat = "Surgery, Chemotherapy, Hormone Therapy, and Radiation Therapy"
elif recurrence_score == "Intermediate":
treat = "Surgery, Consider Chemotherapy, Hormone Therapy, and Radiation Therapy"
else:
treat = "Surgery, Hormone Therapy, and Radiation Therapy"
elif her2 == "Positive":
treat = "Surgery, HER2-Targeted Therapy, Chemotherapy, and Radiation Therapy"
else:
treat = "Surgery, Chemotherapy, and Radiation Therapy"
elif stage == "III":
treat = (
"Neoadjuvant Chemotherapy, Surgery, Radiation Therapy"
+ (", HER2-Targeted Therapy" if her2 == "Positive" else "")
+ (", Hormone Therapy" if er == "Positive" else "")
)
else:
treat = "Systemic Therapy (Palliative Care)"
treatment.append(treat)
breast_cancer_data = {
"PRIMARY_PERSON_KEY": primary_keys,
"Age": ages,
"Menopausal Status": menopausal_status,
"Tumor Size (cm)": tumor_sizes,
"Lymph Node Involvement": lymph_nodes,
"Tumor Grade": grades,
"Tumor Stage": stages,
"ER Status": er_status,
"PR Status": pr_status,
"HER2 Status": her2_status,
"Ki-67 Level": ki67_level,
"TNBC Status": tnbc_status,
"BRCA Mutation": brca_mutation,
"Overall Health": overall_health,
"Genomic Recurrence Score": genomic_score,
"Treatment": treatment,
}
return pd.DataFrame(breast_cancer_data)
# Function to generate Members from BreastCancer
def generate_members_from_breast_cancer(breast_cancer_df):
return pd.DataFrame({
"MEMBER_ID": breast_cancer_df["PRIMARY_PERSON_KEY"],
"PRIMARY_PERSON_KEY": breast_cancer_df["PRIMARY_PERSON_KEY"],
"MEM_GENDER": ["F"] * len(breast_cancer_df),
"MEM_ETHNICITY": np.random.choice(["Hispanic", "Non-Hispanic", None], len(breast_cancer_df)),
"MEM_RACE": np.random.choice(["White", "Black", "Asian", None], len(breast_cancer_df)),
"MEM_STATE": np.random.choice(["MI", "HI", "CA"], len(breast_cancer_df)),
"MEM_ZIP3": np.random.randint(100, 999, len(breast_cancer_df)),
})
# Function to generate Enrollments from BreastCancer
def generate_enrollments_from_breast_cancer(breast_cancer_df):
return pd.DataFrame({
"PRIMARY_PERSON_KEY": breast_cancer_df["PRIMARY_PERSON_KEY"],
"MEM_STAT": np.random.choice(["ACTIVE", "INACTIVE"], len(breast_cancer_df)),
"PAYER_LOB": np.random.choice(["MEDICAID", "COMMERCIAL", "MEDICARE"], len(breast_cancer_df)),
"PAYER_TYPE": np.random.choice(["PPO", "HMO"], len(breast_cancer_df)),
"RELATION": np.random.choice(["SUBSCRIBER", "DEPENDENT"], len(breast_cancer_df)),
})
# Function to generate Services from BreastCancer
def generate_services(num_services, primary_keys):
return pd.DataFrame({
"PRIMARY_PERSON_KEY": np.random.choice(primary_keys, num_services),
"SERVICE_SETTING": np.random.choice(["OUTPATIENT", "INPATIENT"], num_services),
"PROC_CODE": np.random.randint(1000, 9999, num_services),
"SERVICE_DATE": pd.date_range(start="2023-01-01", periods=num_services).to_numpy(),
"AMOUNT_BILLED": np.random.uniform(500, 15000, num_services),
"AMOUNT_PAID": np.random.uniform(500, 15000, num_services),
"CLAIM_STATUS": np.random.choice(["PAID", "DENIED", "PENDING"], num_services),
"RELATION": np.random.choice(["SUBSCRIBER", "DEPENDENT"], num_services),
})
# Main Streamlit App
st.title("Synthetic Medical Data Generator")
# Sliders
num_patients = st.slider("Number of Breast Cancer Patients to Generate", 10, 1000, 100)
num_services = st.slider("Number of Services to Generate", 10, 2000, 500)
if st.button("Generate Data"):
breast_cancer_df = generate_breast_cancer_data(num_patients)
members_df = generate_members_from_breast_cancer(breast_cancer_df)
enrollments_df = generate_enrollments_from_breast_cancer(breast_cancer_df)
services_df = generate_services(num_services, breast_cancer_df["PRIMARY_PERSON_KEY"].tolist())
# Display and download data
st.subheader("Breast Cancer Data")
st.dataframe(breast_cancer_df.head())
st.download_button("Download Breast Cancer Data", breast_cancer_df.to_csv(index=False), "breast_cancer.csv")
st.subheader("Members Data")
st.dataframe(members_df.head())
st.download_button("Download Members Data", members_df.to_csv(index=False), "members.csv")
st.subheader("Enrollments Data")
st.dataframe(enrollments_df.head())
st.download_button("Download Enrollments Data", enrollments_df.to_csv(index=False), "enrollments.csv")
st.subheader("Services Data")
st.dataframe(services_df.head())
st.download_button("Download Services Data", services_df.to_csv(index=False), "services.csv")
|