<jupyter_start><jupyter_text>Teamwork studyIn this notebook, we use the `teamwork` library to represent a care teams' collaborative experience as a network graph. We can then leverage the `networkx` library to calculate the average clustering coefficient for each care team in the dataset. Combining this care team collaboration data with patient discharge data, we can study the correlation between care team collaboration experience and patient outcomes.   Import libraries<jupyter_code>import pandas as pd
import time
import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
import os
import sys

# This allows us to import from src and utils
for dir in ['teamwork','utils']: sys.path.append(os.path.join(os.getcwd(), '..', dir))
import teamwork
import utils<jupyter_output><empty_output><jupyter_text>Read in EHR data and create study runner objectThe study runner is an iterable (generator) object<jupyter_code>#Get EHR notes data
notes_df = pd.read_csv(utils.notes_with_disposition_file, parse_dates=[2])

# set a 90 day window to find collaboration among care teams
WINDOW = 90

# identify care teams within 2 day increments 
STEP = 2

# create the study runner
get_care_dates = teamwork.TeamworkStudyRunner(notes_df, WINDOW, STEP)<jupyter_output><empty_output><jupyter_text>Gather data for each care team identified on each care dateThe `get_careteam_data` utility function uses the `care_team` network graphto calculate the cumulative experience and other metrics for the care team<jupyter_code># measure performance
start_time = time.perf_counter()

# flatten the experience data into a list
experience_data_list = [utils.get_careteam_data(care_team) for care_date in get_care_dates for care_team in care_date]

stop_time = time.perf_counter()<jupyter_output><empty_output><jupyter_text>Summarizing performance...<jupyter_code>print(f"It took {stop_time - start_time} seconds or {(stop_time - start_time) / 60} minutes"
      + f" to process a total of {len(notes_df.index)} notes. The study walked through the notes {STEP} days at a time"
      + f" to identify care teams and calculate care team experience within the previous {WINDOW} day window.")<jupyter_output>It took 118.00482139998348 seconds or 1.9667470233330582 minutes to process a total of 2721 notes. The study walked through the notes 2 days at a time to identify care teams and calculate care team experience within the previous 90 day window.<jupyter_text>Convert data into DataFrame for analysisTo study care team experience and patient outcomes, we need to tie in the patient info from discharge data<jupyter_code>experience_df = pd.DataFrame(experience_data_list, columns=utils.columns).drop_duplicates()

discharges_df = pd.read_csv(utils.discharges_with_disposition_file)

experience_master_df = experience_df.merge(discharges_df, left_on='discharge_id', right_on='id', copy=False)

print(experience_master_df.shape)<jupyter_output>(388, 12)<jupyter_text>Analysis can be performed on the resulting DataFrame to study the correlation between cumulative care team experience and patient outcomes<jupyter_code>def get_model(var):
    return sm.GLM.from_formula(f'disposition ~ {var} + age', family = sm.families.Binomial(), data=experience_master_df)

model = get_model('avg_clust')
result = model.fit()
result.summary() 
model = get_model('cumulative_experience')
result = model.fit()
result.summary() 
model = get_model('avg_cumulative_experience')
result = model.fit()
result.summary()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07292849035187288, 'fraction_numerical': 0.015607264472190692, 'mean_word_length': 6.389937106918239, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '235716', 'license': 'MIT', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1015, 'n_words': 368, 'path': 'notebooks/teamwork_study.ipynb', 'repo_name': 'gtdelong/teamwork', 'size': '3524'}