Idea

Inverness


In [3]:
import inverness
model = inverness.Model('model_all/').load()


load done in 12.12 seconds

Standard imports


In [4]:
from IPython.core.display import display, HTML
from matplotlib import pyplot as plt
from tqdm import tqdm
import pandas as pd
import re
pd.set_option('display.max_rows', 100)

Helper functions


In [104]:
def score_text(text, criteria):
    """"""
    total = 0
    value = 1
    for c in criteria:
        if type(c) in (int,float):
            value = c
        else:
            c = c.replace('_',r'\b')
            matches = re.findall(c,text,re.I)
            total += value if matches else 0
            #total += value*len(matches)
    return total


def score_results(i_d_lists, criteria, mark=None):
    """"""
    results = []
    for i,d in zip(*i_d_lists):
        doc = model.get_doc(i)
        text = model.doc_to_text(doc).replace('\n',' ').replace('\r',' ')
        s = score_text(text, criteria)
        text = highlight(text, criteria, mark)
        rec = s,d,i,text,doc
        results += [rec]
    results.sort(key=lambda x:(-x[0],x[1]))
    return results


def score_queries(queries, criteria, N=50):
    """"""
    by_score = []
    for query in queries:
        q = model.text_to_dense(query)
        i_d = model.dense_ann_query(q,N)
        results = score_results(i_d, criteria)
        score = agg_results(results)
        by_score += [(score,query)]
    by_score.sort()
    return by_score

# TODO styles: mark_color/bold/text_color
def highlight(text, criteria, mark=None):
    """"""
    group_id = 0
    for c in criteria:
        if type(c) in (int,float):
            group_id += 1
        else:
            c = c.replace('_',r'\b')
            c = f'({c}\\w*)'
            if mark and group_id in mark:
                text = re.sub(c, '<mark style="background-color: #FFFF00">\\1</mark>', text, flags=re.I)
            else:
                text = re.sub(c, '<b>\\1</b>', text, flags=re.I)
    return text


# L2 score
def agg_results(results):
    """"""
    scores = [x[0] for x in results]
    return sum([x*x for x in scores])**0.5


# TODO break title into multiple lines
def plot_results(results,title=''):
    """"""
    scores = [x[0] for x in results]
    scores.sort(reverse=True)
    plt.plot(scores)
    if title: plt.title(title)
    score = agg_results(results)
    plt.figtext(0.4, 1, f"L2 score: {score:.02f}")
    plt.show()

# TEST
highlight("this is a test of this function",['thi',5,'_is'],mark=[1])


Out[104]:
'<b>this</b> <mark style="background-color: #FFFF00">is</mark> a test of <b>this</b> function'

Outcomes data for COVID-19 after mechanical ventilation adjusted for age

Scoring criteria


In [83]:
criteria = [
    5,'mechanical','ventilat',
    2,'adjust','_age','years','_old',
    2,'surviv','discharge','extubate','died','dead','death','mortality','Kaplan-Meier',
    1,'duration','_day','\d+ patients',
    2,'figure','table',
]

# TODO criteria display style
mark = [2,3]

Query selection


In [78]:
queries = [
        'results after mechnical ventilation discharged dead died',
        'results after mechnical ventilation discharged dead died survived survivors adjusted age years old',
        'results after mechnical ventilation discharged died survived survivors extubated adjusted',
        'results after mechnical ventilation discharged dead died survived survivors adjusted age years old',
        'results after mechnical ventilation discharged died survived extubated adjusted',
        'results after mechnical ventilation discharged died survived extubated adjusted age',
        'outcomes after mechnical ventilation discharged died survived extubated adjusted',
        'results outcomes after mechnical ventilation discharged died survived extubated adjusted age',
        'results outcomes after mechnical ventilation discharged died survived extubated adjusted',
]

for score,query in score_queries(queries, criteria, 50):
    print(f"{score:10.02f} -- {query}")


     44.31 -- results after mechnical ventilation discharged dead died survived survivors adjusted age years old
     44.31 -- results after mechnical ventilation discharged dead died survived survivors adjusted age years old
     94.86 -- results after mechnical ventilation discharged died survived extubated adjusted age
    104.51 -- results after mechnical ventilation discharged dead died
    110.89 -- results outcomes after mechnical ventilation discharged died survived extubated adjusted age
    116.46 -- results after mechnical ventilation discharged died survived extubated adjusted
    119.23 -- results after mechnical ventilation discharged died survived survivors extubated adjusted
    119.60 -- outcomes after mechnical ventilation discharged died survived extubated adjusted
    123.27 -- results outcomes after mechnical ventilation discharged died survived extubated adjusted

Final query


In [90]:
query = 'results outcomes after mechnical ventilation \n discharged died survived extubated adjusted'

Query the model


In [107]:
K = 50
q = model.text_to_dense(query)
i_d_lists = model.dense_ann_query(q, K)
results = score_results(i_d_lists, criteria, mark)
plot_results(results, title=query)


Display results


In [106]:
N = 10
for s,d,i,text,doc in results[:N]:
    display(HTML(f"{s} :: {d:.03f} :: {i}<br>{text}"))


27 :: 0.207 :: 1817665
In the analysis of adult population, a total of 262 patients were admitted to ICUs and received mechanical ventilation during the study period. The mean age of those patients was 57 (SD 21) years, and the majority were male (64%). Of 262 patients, 98 patients died after receiving mechanical ventilation. Thus, the overall mortality for patients admitted to ICUs and receiving mechanical ventilation during the study period was 37%, with a median survival time in the ICU of 11 days (IQR 6-20 days). Because the average duration of mechanical ventilation was 11 days, the analysis was restricted to within 30 days of receiving mechanical ventilation. The mortality rate was 27.3 per 1000-person years (95% CI 22.4 to 33.2). The Kaplan-Meier survival curves for 30-day ICU mortality is shown in Figure 2. At the end of 30 days after receiving the mechanical ventilation, the overall survival rate was 82% after the fifth day and 75% after the tenth day of receiving the mechanical ventilation. Results Figure 2: Kaplan-Meier curves of the probability of survival over time for adult mechanical ventilated patients (N=262) admitted to the intensive care unit between 2016-2018.
27 :: 0.207 :: 1729272
In the analysis of adult population, a total of 262 patients were admitted to ICUs and received mechanical ventilation during the study period. The mean age of those patients was 57 (SD 21) years, and the majority were male (64%). Of 262 patients, 98 patients died after receiving mechanical ventilation. Thus, the overall mortality for patients admitted to ICUs and receiving mechanical ventilation during the study period was 37%, with a median survival time in the ICU of 11 days (IQR 6-20 days). Because the average duration of mechanical ventilation was 11 days, the analysis was restricted to within 30 days of receiving mechanical ventilation. The mortality rate was 27.3 per 1000-person years (95% CI 22.4 to 33.2). The Kaplan-Meier survival curves for 30-day ICU mortality is shown in Figure 2 . At the end of 30 days after receiving the mechanical ventilation, the overall survival rate was 82% after the fifth day and 75% after the tenth day of receiving the mechanical ventilation. Kaplan-Meier curves of the probability of survival over time for adult mechanical ventilated patients (N=262) admitted to the intensive care unit between 2016-2018.
27 :: 0.233 :: 152787
The overall ICU mortality rate was 74.2 % (n = 23). The median ICU and hospital lengths of stay were 9 (IQR: 4-16) and 12 (IQR: 4-16) days, respectively. The major causes of death were hypoxemic respiratory failure (52.2 %) and refractory septic shock (26.1 %). One patient died from sudden cardiac arrest after ICU discharge but while still in the hospital. Furthermore, one patient died within 1 year after discharge from the ICU because of septic shock related to an infected wound. Only one patient was lost to follow-up after hospital discharge. The SOFA score and Glasgow Coma Scale (GCS) increased markedly over the first 2 weeks in the ICU in the whole cohort, while other parameters of organ function remained largely unchanged (Additional file 3). Compared with those who were discharged alive from the ICU, nonsurvivors were older, had higher APACHE II and SOFA scores on admission to the ICU, and were more likely to require invasive mechanical ventilation and vasopressor therapy and to have been ventilated using highfrequency oscillation (Tables 1 and 2 , and Additional files 1 and 2). Nonsurvivors had a persistently low PaO2/FiO 2 throughout the first 2 weeks in the ICU, whereas survivors showed a slight increase over time (Fig. 2) . After adjustment for the severity of illness and the degree of organ dysfunction, the need for vasopressors was the only independent risk factor for death in the ICU (OR 18.33, 95 % confidence interval 1.11-302.1, P 0.04) (Additional file 4). Morbidity and mortality Characteristics of patients on admission to the intensive care unit APACHE acute physiology and chronic health evaluation, COPD chronic obstructive pulmonary disease, ICU intensive care unit, IQR interquartile range, NA not applicable, SD standard deviation, SOFA sequential organ failure assessment Box plot representing the time course of PaO2/FiO2 according to ICU outcome. *P < 0.005 compared to survivors
26 :: 0.202 :: 1817668
In this analysis, a total of 175 patients were admitted to ICUs and received mechanical ventilation during the study period. Most of the patients were below 1 month (89% of the whole population) and 59% were boys. A total of 30 (17%) of this study population died after the date of mechanical ventilation with a median survival time of 16 days (IQR 7-37 days). The mortality rate was 9.9 per 1000-person years (95%, CI 6.96 to 14.25). The Kaplan-Meier survival curves for 30-day ICU mortality as shown in Figure 3. The curve shows that by the end of one month, 75% of patients on mechanical ventilation are still alive. The characteristic of the population as demonstrated in Table 3. The main source of the admission of those neonates was labor and delivery by C-section, with the mean gestational week being 32 (SD 5) weeks. Prematurity with respiratory problems (50%) was the main recorded cause of the initiation of mechanical ventilation, followed by respiratory distress syndrome (37%). The majority of admissions to ICUs were premature. Neonates who received mechanical ventilation within the first month of their life and who were born extremely preterm had a high mortality rate after the initiation of mechanical ventilation. A total of 169 (96%) of the neonates were intubated in ICU while only 3% had already been intubated before their ICU admission. Variables related to mechanical ventilation parameters on day one of mechanical ventilation are presented in Table 3. For the results of the univariate analysis of factors associated with mortality among this population, Table 4 shows that neonates who received mechanical ventilation within the first month of life and who were born extremely preterm had a high mortality rate after the initiation of mechanical ventilation. In addition, those neonates who had respiratory distress syndrome as the cause of initiating the mechanical ventilation had a high rate of mortality; however, the univariate analysis showed no significant association. Neonates who had congenital anomalies as the cause of receiving mechanical ventilation were more likely to have a lower survival rate (OR 13, 95% CI 2.68-62.8). Results Table 3: Demographic, clinical characteristics, and initial ventilator modes of the pediatric patients on the inanition of the mechanical ventilation in the ICU between 2016-2018 (N=175). Table 3: Demographic, clinical characteristics, and initial ventilator modes of the pediatric patients on the inanition of the mechanical ventilation in the ICU between 2016-2018 (N=175). Table 4: The univariate analysis of factors associated with mortality among adult patients who admitted to ICU and received mechanical ventilation between 2016-2018. Figure 3: Kaplan-Meier curves of the probability of survival overtime for pediatric mechanical ventilated patients (N=175) admitted to the intensive care unit between 2016-2108.
26 :: 0.213 :: 1729275
In this analysis, a total of 175 patients were admitted to ICUs and received mechanical ventilation during the study period. Most of the patients were below 1 month (89% of the whole population) and 59% were boys. A total of 30 (17%) of this study population died after the date of mechanical ventilation with a median survival time of 16 days (IQR 7-37 days). The mortality rate was 9.9 per 1000-person years (95%, CI 6.96 to 14.25). The Kaplan-Meier survival curves for 30-day ICU mortality as shown in Figure 3 . The curve shows that by the end of one month, 75% of patients on mechanical ventilation are still alive. The characteristic of the population as demonstrated in Table 3 . The main source of the admission of those neonates was labor and delivery by C-section, with the mean gestational week being 32 (SD 5) weeks. Prematurity with respiratory problems (50%) was the main recorded cause of the initiation of mechanical ventilation, followed by respiratory distress syndrome (37%). The majority of admissions to ICUs were premature. Neonates who received mechanical ventilation within the first month of their life and who were born extremely preterm had a high mortality rate after the initiation of mechanical ventilation. A total of 169 (96%) of the neonates were intubated in ICU while only 3% had already been intubated before their ICU admission. Variables related to mechanical ventilation parameters on day one of mechanical ventilation are presented in Table 3 . For the results of the univariate analysis of factors associated with mortality among this population, Table 4 shows that neonates who received mechanical ventilation within the first month of life and who were born extremely preterm had a high mortality rate after the initiation of mechanical ventilation. In addition, those neonates who had respiratory distress syndrome as the cause of initiating the mechanical ventilation had a high rate of mortality; however, the univariate analysis showed no significant association. Neonates who had congenital anomalies as the cause of receiving mechanical ventilation were more likely to have a lower survival rate (OR 13, 95% CI 2.68-62.8). Demographic Demographic The univariate analysis of factors associated with mortality among adult patients who admitted to ICU and received mechanical ventilation between 2016-2018. Values are presented as numbers and percentage (%). CI -confidence interval mortality, as 72% such patients died in ICUs. Kaplan-Meier curves of the probability of survival overtime for pediatric mechanical ventilated patients (N=175) admitted to the intensive care unit between 2016-2108.
24 :: 0.204 :: 1431100
Duration of corticosteroid treatment was 21.2 ± 6.1 days (range 11-28). All but one patient improved lung function, were extubated, and discharged alive from the ICU. The ICU nonsurvivor was a 46-year-old male smoker with a history of alcohol abuse, admitted with septic shock and severe ARDS, negative H1N1 RT-PCR, dysfunction of five vital organs (APACHE II and SOFA scores 20 and 16, respectively), failed to improve lung injury score by day 7 of ARDS, and died on ICU day 15 with progression of MODS. One hospital nonsurvivor, a 60-year-old moderately obese (BMI [35) female with COPD, positive H1N1 RT-PCR, without shock at study entry, was extubated after 7 days of mechanical ventilation and died after ICU discharge as a result of cardiac arrest (electromechanical dissociation) preceded by sudden onset of severe dyspnea. Pulmonary embolism was suspected, but autopsy was not obtained. Hospital mortality in patients with and without shock was similar (12.5 vs. 20%). All hospital survivors were discharged home without oxygen supplementation and were alive at day 60. At the physician discretion, outpatient tapering was continued in all those with severe ARDS (5.3 ± 2.8 days) and in four without severe ARDS (3.4 ± 3.2 days). Results
24 :: 0.204 :: 1617486
Duration of corticosteroid treatment was 21.2 ± 6.1 days (range 11–28). All but one patient improved lung function, were extubated, and discharged alive from the ICU. The ICU nonsurvivor was a 46-year-old male smoker with a history of alcohol abuse, admitted with septic shock and severe ARDS, negative H1N1 RT-PCR, dysfunction of five vital organs (APACHE II and SOFA scores 20 and 16, respectively), failed to improve lung injury score by day 7 of ARDS, and died on ICU day 15 with progression of MODS. One hospital nonsurvivor, a 60-year-old moderately obese (BMI >35) female with COPD, positive H1N1 RT-PCR, without shock at study entry, was extubated after 7 days of mechanical ventilation and died after ICU discharge as a result of cardiac arrest (electromechanical dissociation) preceded by sudden onset of severe dyspnea. Pulmonary embolism was suspected, but autopsy was not obtained. Hospital mortality in patients with and without shock was similar (12.5 vs. 20%). All hospital survivors were discharged home without oxygen supplementation and were alive at day 60. At the physician discretion, outpatient tapering was continued in all those with severe ARDS (5.3 ± 2.8 days) and in four without severe ARDS (3.4 ± 3.2 days). Results
24 :: 0.247 :: 1114333
The median time from illness onset (ie, before admission) to discharge was 22·0 days (IQR 18·0-25·0), whereas the median time to death was 18·5 days (15·0-22·0; table 2). 32 patients required invasive mechanical ventilation, of whom 31 (97%) died. The median time from illness onset to invasive mechanical ventilation was 14·5 days (12·0-19·0). Extracorporeal membrane oxygenation was used in three patients, none of whom survived. Sepsis was the most frequently observed complication, followed by respiratory failure, ARDS, heart failure, and septic shock (table 2). Half of non-survivors experienced a secondary infection, and ventilator-associated pneumonia occurred in ten (31%) of 32 patients requiring invasive mechanical ventilation. The frequency of complications were higher in non-survivors than survivors (table 2) . In univariable analysis, odds of in-hospital death was higher in patients with diabetes or coronary heart disease (table 3) . Age, lymphopenia, leucocytosis, and elevated ALT, lactate dehydrogenase, high-sensitivity cardiac troponin I, creatine kinase, d-dimer, serum ferritin, IL-6, prothrombin time, creatinine, and procalcitonin were also associated with death (table 3) . Results Treatments and outcomes Risk factors associated with in-hospital death Risk factors associated with in-hospital death
23 :: 0.196 :: 330000
The primary outcome, weaning duration, defined from the first day of randomization to the day the patient was successfully weaned, was shorter with trach collar than with pressure support: 15 versus 19 days. Patients were considered weaning successes when they breathed without ventilator assistance for at least 5 days. A Cox proportional hazards model revealed that the rate of successful weaning was 1.43 times faster with trach collar than with pressure support. Mortality was equivalent in the two arms, but, of course, the study was not powered to detect a difference in mortality. Of the entire 500 randomized and non-randomized patients, 54 % were alive at 6 months after enrollment and 45 % were alive at 12 months. This survival rate is surprisingly high. To put the numbers in perspective, 1-year survival in older (66 years) patients ventilated in an ICU was approximately 40 % [64, 65] . That is, the LTACH patients in the study of Jubran et al., who were ventilated for 67 days, had a 1-year mortality comparable to ICU patients who were ventilated for 9 days. Indeed, 72 % of the 260 patients who had been weaned by discharge were alive at 12 months. Conclusion Longterm mortality and quality of life after prolonged mechanical ventilation Survival and quality of life: short-term versus long-term ventilator patients
23 :: 0.207 :: 485080
The primary outcome, weaning duration, defined from the first day of randomization to the day the patient was successfully weaned, was shorter with trach collar than with pressure support: 15 versus 19 days. Patients were considered weaning successes when they breathed without ventilator assistance for at least 5 days. A Cox proportional hazards model revealed that the rate of successful weaning was 1.43 times faster with trach collar than with pressure support. Mortality was equivalent in the two arms, but, of course, the study was not powered to detect a difference in mortality. Of the entire 500 randomized and non-randomized patients, 54 % were alive at 6 months after enrollment and 45 % were alive at 12 months. This survival rate is surprisingly high. To put the numbers in perspective, 1-year survival in older (66 years) patients ventilated in an ICU was approximately 40 % [64, 65]. That is, the LTACH patients in the study of Jubran et al., who were ventilated for 67 days, had a 1-year mortality comparable to ICU patients who were ventilated for 9 days. Indeed, 72 % of the 260 patients who had been weaned by discharge were alive at 12 months. Weaning in long-term acute care hospitals in the United States Hospitals (Martin Tobin, Amal Jubran) ::: Conclusion Long-term mortality and quality of life after prolonged mechanical ventilation Survival and quality of life: short-term versus long-term ventilator patients

In [ ]: