Diff of /generating_data.ipynb [000000] .. [ba27f9]

Switch to side-by-side view

--- a
+++ b/generating_data.ipynb
@@ -0,0 +1,89 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "04c762a0-d289-4e23-b0f3-3ea6b3aa2e32",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import pandas as pd\n",
+    "import numpy as np\n",
+    "\n",
+    "# Patients table\n",
+    "np.random.seed(0)\n",
+    "num_rows = 10000\n",
+    "patients = pd.DataFrame({\n",
+    "    'patient_id': np.arange(1, num_rows + 1),\n",
+    "    'age': np.random.randint(18, 85, num_rows),\n",
+    "    'gender': np.random.choice(['Male', 'Female'], num_rows),\n",
+    "    'admission_date': pd.date_range('2020-01-01', periods=num_rows),\n",
+    "    'discharge_date': pd.date_range('2020-01-15', periods=num_rows)\n",
+    "})\n",
+    "\n",
+    "# Diagnoses table\n",
+    "diagnoses = pd.DataFrame({\n",
+    "    'diagnosis_id': np.arange(1, num_rows + 1),\n",
+    "    'patient_id': patients['patient_id'],\n",
+    "    'icd_code': np.random.choice(['A00-B99', 'C00-D49', 'D50-D89', 'E00-E89', 'F00-F99'], num_rows),\n",
+    "    'diagnosis_date': [pd.date_range(row['admission_date'], row['discharge_date'])[np.random.randint(0, len(pd.date_range(row['admission_date'], row['discharge_date']))) - 1] for index, row in patients.iterrows()]\n",
+    "})\n",
+    "\n",
+    "# Medications table\n",
+    "medications = pd.DataFrame({\n",
+    "    'medication_id': np.arange(1, num_rows + 1),\n",
+    "    'patient_id': patients['patient_id'],\n",
+    "    'medication_name': np.random.choice(['Medication A', 'Medication B', 'Medication C', 'Medication D', 'Medication E'], num_rows),\n",
+    "    'start_date': [pd.date_range(row['admission_date'], row['discharge_date'])[np.random.randint(0, len(pd.date_range(row['admission_date'], row['discharge_date']))) - 1] for index, row in patients.iterrows()]\n",
+    "})\n",
+    "\n",
+    "medications = medications.merge(patients[['patient_id', 'admission_date', 'discharge_date']], on='patient_id')\n",
+    "\n",
+    "medications['end_date'] = [pd.date_range(row['start_date'], row['discharge_date'])[np.random.randint(0, len(pd.date_range(row['start_date'], row['discharge_date']))) - 1] if len(pd.date_range(row['start_date'], row['discharge_date'])) > 1 else row['discharge_date'] for index, row in medications.iterrows()]\n",
+    "\n",
+    "# Lab results table\n",
+    "lab_results = pd.DataFrame({\n",
+    "    'lab_result_id': np.arange(1, num_rows + 1),\n",
+    "    'patient_id': patients['patient_id'],\n",
+    "    'lab_test': np.random.choice(['Lab Test A', 'Lab Test B', 'Lab Test C', 'Lab Test D', 'Lab Test E'], num_rows),\n",
+    "    'result_value': np.random.uniform(100, 300, num_rows),\n",
+    "    'result_date': [pd.date_range(row['admission_date'], row['discharge_date'])[np.random.randint(0, len(pd.date_range(row['admission_date'], row['discharge_date']))) - 1] for index, row in patients.iterrows()]\n",
+    "})\n",
+    "\n",
+    "# Readmission risk table\n",
+    "readmission_risk = pd.DataFrame({\n",
+    "    'patient_id': patients['patient_id'],\n",
+    "    'readmission_risk': np.random.choice([0, 1], num_rows)\n",
+    "})\n",
+    "\n",
+    "# Save data to CSV files\n",
+    "patients.to_csv('patients2.csv', index=False)\n",
+    "diagnoses.to_csv('diagnoses2.csv', index=False)\n",
+    "medications.to_csv('medications2.csv', index=False)\n",
+    "lab_results.to_csv('lab_results2.csv', index=False)\n",
+    "readmission_risk.to_csv('readmission_risk2.csv', index=False)"
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3 (ipykernel)",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.9.18"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}