Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,6 +56,11 @@ df2 = pd.read_csv('cohort_cc_adm_diag.csv')
|
|
| 56 |
df3 = pd.read_csv('cohort_past_history_12072022.csv')
|
| 57 |
df3.sort_values(by='CHARTDATE',ascending = False, inplace=True)
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# combining both data into one
|
| 60 |
df = pd.merge(df, df2, on=['HADM_ID','SUBJECT_ID'])
|
| 61 |
|
|
@@ -65,6 +70,7 @@ del df2
|
|
| 65 |
# Remove decimal point from Admission ID
|
| 66 |
df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 67 |
df3['HADM_ID'] = df3['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
|
|
|
| 68 |
df3['INDEX_HADM_ID'] = df3['INDEX_HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 69 |
df3["CHARTDATE_HADM_ID"] = df3["CHARTDATE"].astype(str) +' ('+ df3["HADM_ID"] +')'
|
| 70 |
df3["DIAGNOSIS"] = df3["DIAGNOSIS"].str.capitalize()
|
|
@@ -84,6 +90,10 @@ df3.rename(columns={'SUBJECT_ID':'Patient_ID',
|
|
| 84 |
'HADM_ID':'PAST_Admission_ID',
|
| 85 |
'INDEX_HADM_ID':'Admission_ID'}, inplace = True)
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
#Filter selection
|
| 88 |
st.sidebar.header("Search for Patient:")
|
| 89 |
|
|
@@ -116,6 +126,12 @@ AdmissionChiefCom = original_text['Admission_Chief_Complaint'].values
|
|
| 116 |
diagnosis =original_text['DIAGNOSIS'].values
|
| 117 |
reference_text = original_text['Reference_text'].values
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
|
| 121 |
##========= Buttons to the 5 tabs ======== Temp disabled Discharge Plan and Social Notes
|
|
@@ -156,7 +172,7 @@ with st.container():
|
|
| 156 |
with col7:
|
| 157 |
#st.date_input('Select Admission Date') # To replace with a dropdown filter instead
|
| 158 |
#st.selectbox('Past Episodes',pastHistoryEp)
|
| 159 |
-
pastHistory = st.selectbox('Select Past History Admission', pastHistoryEpDate)
|
| 160 |
|
| 161 |
if btnPastHistory:
|
| 162 |
|
|
@@ -165,8 +181,8 @@ if btnPastHistory:
|
|
| 165 |
"Patient_ID == @patient & CHARTDATE_HADM_ID == @pastHistory"
|
| 166 |
)
|
| 167 |
runtext = historyAdmission['hospital_course_processed'].values[0]
|
| 168 |
-
|
| 169 |
-
|
| 170 |
runtext =st.text_area(inputNote, str(original_text2)[1:-1], height=300)
|
| 171 |
|
| 172 |
|
|
@@ -315,7 +331,8 @@ def run_model(input_text):
|
|
| 315 |
|
| 316 |
col1, col2 = st.columns([1,1])
|
| 317 |
|
| 318 |
-
|
|
|
|
| 319 |
with col1:
|
| 320 |
st.button('Summarize')
|
| 321 |
run_model(runtext)
|
|
@@ -341,7 +358,29 @@ if not(btnPastHistory): #to not show summary and references text for Past Histor
|
|
| 341 |
st.markdown('**NER**')
|
| 342 |
with st.expander("See NER Details"):
|
| 343 |
st.markdown(ent_html, unsafe_allow_html=True)
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
# ===== Adding the Disease/Chemical into a list =====
|
| 346 |
problem_entities = list(dedupe([t for t in doc0.ents if t.label_ == 'DISEASE']))
|
| 347 |
medication_entities = list(dedupe([t for t in doc0.ents if t.label_ == 'CHEMICAL']))
|
|
|
|
| 56 |
df3 = pd.read_csv('cohort_past_history_12072022.csv')
|
| 57 |
df3.sort_values(by='CHARTDATE',ascending = False, inplace=True)
|
| 58 |
|
| 59 |
+
# Loading in Daily Narrative
|
| 60 |
+
df4 = pd.read_csv('24hourevents.csv')
|
| 61 |
+
df4.sort_values(by=['SUBJECT_ID','HADM_ID','STORETIME'],ascending = False, inplace=True)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
# combining both data into one
|
| 65 |
df = pd.merge(df, df2, on=['HADM_ID','SUBJECT_ID'])
|
| 66 |
|
|
|
|
| 70 |
# Remove decimal point from Admission ID
|
| 71 |
df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 72 |
df3['HADM_ID'] = df3['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 73 |
+
df4['HADM_ID'] = df4['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 74 |
df3['INDEX_HADM_ID'] = df3['INDEX_HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 75 |
df3["CHARTDATE_HADM_ID"] = df3["CHARTDATE"].astype(str) +' ('+ df3["HADM_ID"] +')'
|
| 76 |
df3["DIAGNOSIS"] = df3["DIAGNOSIS"].str.capitalize()
|
|
|
|
| 90 |
'HADM_ID':'PAST_Admission_ID',
|
| 91 |
'INDEX_HADM_ID':'Admission_ID'}, inplace = True)
|
| 92 |
|
| 93 |
+
df4.rename(columns={'SUBJECT_ID':'Patient_ID',
|
| 94 |
+
'HADM_ID':'Admission_ID'}, inplace = True)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
#Filter selection
|
| 98 |
st.sidebar.header("Search for Patient:")
|
| 99 |
|
|
|
|
| 126 |
diagnosis =original_text['DIAGNOSIS'].values
|
| 127 |
reference_text = original_text['Reference_text'].values
|
| 128 |
|
| 129 |
+
#dailyNoteChange = df4['_24_Hour_Events'].loc[(df4['Patient_ID'] == patient) & (df3['Admission_ID']== HospitalAdmission)]
|
| 130 |
+
dailyNoteChange =df4[['STORETIME','_24_Hour_Events']].loc[(df4['Patient_ID'] == patient) & (df4['Admission_ID']==HospitalAdmission) & df4['_24_Hour_Events'].notnull()]
|
| 131 |
+
|
| 132 |
+
dailyNoteChange.rename(columns={'STORETIME':'Time of Record',
|
| 133 |
+
'_24_Hour_Events':'Note Changes'}, inplace = True)
|
| 134 |
+
|
| 135 |
|
| 136 |
|
| 137 |
##========= Buttons to the 5 tabs ======== Temp disabled Discharge Plan and Social Notes
|
|
|
|
| 172 |
with col7:
|
| 173 |
#st.date_input('Select Admission Date') # To replace with a dropdown filter instead
|
| 174 |
#st.selectbox('Past Episodes',pastHistoryEp)
|
| 175 |
+
pastHistory = st.selectbox('Select Past History Admission', pastHistoryEpDate, format_func=lambda x: 'Select an option' if x == '' else x)
|
| 176 |
|
| 177 |
if btnPastHistory:
|
| 178 |
|
|
|
|
| 181 |
"Patient_ID == @patient & CHARTDATE_HADM_ID == @pastHistory"
|
| 182 |
)
|
| 183 |
runtext = historyAdmission['hospital_course_processed'].values[0]
|
| 184 |
+
|
| 185 |
+
if not(btnPastHistory) and not(btnDailyNarrative):
|
| 186 |
runtext =st.text_area(inputNote, str(original_text2)[1:-1], height=300)
|
| 187 |
|
| 188 |
|
|
|
|
| 331 |
|
| 332 |
col1, col2 = st.columns([1,1])
|
| 333 |
|
| 334 |
+
#to not show summary and references text for Past History and Daily Narrative
|
| 335 |
+
if not(btnPastHistory) and not(btnDailyNarrative):
|
| 336 |
with col1:
|
| 337 |
st.button('Summarize')
|
| 338 |
run_model(runtext)
|
|
|
|
| 358 |
st.markdown('**NER**')
|
| 359 |
with st.expander("See NER Details"):
|
| 360 |
st.markdown(ent_html, unsafe_allow_html=True)
|
| 361 |
+
if btnDailyNarrative:
|
| 362 |
+
with st.container():
|
| 363 |
+
st.markdown('Daily notes:')
|
| 364 |
+
st.text_area('to input last day note','')
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
with st.container():
|
| 368 |
+
# hide_table_row_index = """
|
| 369 |
+
# <style>
|
| 370 |
+
# thead tr th:first-child {display:none}
|
| 371 |
+
# tbody th {display:none}
|
| 372 |
+
# </style>
|
| 373 |
+
# """
|
| 374 |
+
#
|
| 375 |
+
# # Inject CSS with Markdown
|
| 376 |
+
# st.markdown(hide_table_row_index, unsafe_allow_html=True)
|
| 377 |
+
# st.table(dailyNoteChange)
|
| 378 |
+
styler = dailyNoteChange.style.hide_index()
|
| 379 |
+
st.write(styler.to_html(), unsafe_allow_html=True)
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
#else:
|
| 383 |
+
if btnPastHistory:
|
| 384 |
# ===== Adding the Disease/Chemical into a list =====
|
| 385 |
problem_entities = list(dedupe([t for t in doc0.ents if t.label_ == 'DISEASE']))
|
| 386 |
medication_entities = list(dedupe([t for t in doc0.ents if t.label_ == 'CHEMICAL']))
|