Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request 11/1 #1

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ PROJECT.org*
.Rhistory
**/*.Rds
results/
.Rproj.user
main.R
manuscript1.Rmd
Binary file added Examensarbete.docx
Binary file not shown.
Binary file added Project timeline_ trauma-ofi-icu.pdf
Binary file not shown.
2,974 changes: 2,965 additions & 9 deletions bibliography.bib

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions functions/Deceased.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#Använd tidigare kod för OFI för att få rätt kohort - finns i table1.R

# Convert DateTime_ArrivalAtHospital and DeceasedDate to Date format
ofi$DateTime_ArrivalAtHospital <- as.Date(ofi$DateTime_ArrivalAtHospital)
ofi$DeceasedDate <- as.Date(ofi$DeceasedDate)
# Calculate the difference in days
ofi$days_to_deceased <- as.numeric(ofi$DeceasedDate - ofi$DateTime_ArrivalAtHospital)
# Calculate the difference in days
ofi$days_to_deceased <- as.numeric(ofi$DeceasedDate - ofi$DateTime_ArrivalAtHospital)
# Count patients deceased within 1 day and 2 days
deceased_within_1_day <- sum(ofi$days_to_deceased == 1, na.rm = TRUE)
deceased_within_2_days <- sum(ofi$days_to_deceased <= 2 & ofi$days_to_deceased > 0, na.rm = TRUE)

# Print the results
cat("Patients deceased within 1 day:", deceased_within_1_day, "\n")
cat("Patients deceased within 2 days:", deceased_within_2_days, "\n")
388 changes: 383 additions & 5 deletions functions/example_function.R

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions functions/flowchart.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

#FLOWCHART: included/excluded
#install.packages("Gmisc")
library(Gmisc, quietly = TRUE)
library(glue)
#install.packages("htmlTable")
library(htmlTable)
library(grid)
library(magrittr)

org_cohort <- boxGrob(glue("Total patient cases in trauma quality database",
"n = {pop}",
pop = txtInt(14022),
.sep = "\n"))
eligible <- boxGrob(glue("Eligible",
"n = {pop}",
pop = txtInt(1742),
.sep = "\n"))
included <- boxGrob(glue("Included (n = {incl}):",
"- OFI: {ofi1}",
"- No OFI: {ofi2}",
ofi1 = 143,
ofi2 = 1306,
incl = txtInt(1449),
.sep = "\n"),
just = "left")
excluded <- boxGrob(glue("Excluded (n = {tot}):",
" - Not admitted to the ICU: {icu}",
" - Patients < 15 years: {age}",
" - Dead on arrival: {doa}",
" - No data on OFI: {ofi}",
tot = 12278,
icu = 14022-2679,
age = 2679-2676,
doa = 2676-2670,
ofi = 2670-1742,
.sep = "\n"),
just = "left")
excluded1 <- boxGrob(glue("Excluded: missing data (n = {x})",
x = 1742 - 1449,
.sep = "\n"),
just = "left")

grid.newpage()
vert <- spreadVertical(org_cohort,
eligible = eligible,
included = included)

# Move excluded box
excluded <- moveBox(excluded,
x = 0.8,
y = 0.7)

excluded1 <- moveBox(excluded1,
x = 0.8,
y = 0.4)

#Defining small arrow
small_arrow <- arrow(length = unit(0.1, "inches"), type = "closed")

# Connect boxes vertically
for (i in 1:(length(vert) - 1)) {
connectGrob(vert[[i]], vert[[i + 1]], type = "vert", arrow = small_arrow) %>%
print
}

# Connect excluded box horizontally
connectGrob(vert$eligible, excluded, type = "L", arrow = small_arrow)
connectGrob(vert$included, excluded1, type = "L", arrow = small_arrow)

# Print boxes
vert
excluded
excluded1

201 changes: 201 additions & 0 deletions functions/ofi_categories.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@

# Load necessary libraries
library(dplyr)
library(stringr)
library(gtsummary)
library(gt)

# Select different OFIs
ofi_categories <- ofi %>%
select(Problemomrade_.FMP, Sex, Age, Intubation, RTS, ISS, TimeFCT, OnDuty, daysinICU,
ASApreinjury, Survival, OpportunityForImprovement)

# Translating OFIs and identifying NAs
ofi_categories$Problemomrade_.FMP <- str_replace_all(
str_to_lower(ofi_categories$Problemomrade_.FMP),
c(
"ok" = NA_character_,
"nej" = NA_character_,
"inget problemområde" = NA_character_,
"föredömligt handlagd" = NA_character_,
"dokumetation" = "Documentation",
"handläggning" = "Patient management",
"logistik/teknik" = "Logistics/technical",
"lång tid till op" = "Delay to surgery",
"lång tid till dt" = "Delay to CT",
"kompetens brist" = "Competence",
"kommunikation" = "Communication",
"kommunikation+missad skada" = "Communication + missed injury",
"handläggning/logistik" = "Patient management/logistics",
"handläggning+dokumentation" = "Patient management + documentation",
"handläggning prehosp" = "Prehospital management",
"traumakriterier/styrning" = "Trauma criteria/guidelines",
"tertiär survey" = "Tertiary survey",
"bristande rutin" = "Inadequate routine",
"annat" = "Other",
"missad skada" = "Missed injury",
"resurs" = "Resources",
"triage på akm" = "Triage in the ED",
"triage på akutmottagningen" = "Triage in the ED",
"vårdnivå" = "Level of care",
"vårdnivå\\+\r\nmissade skador" = "Level of care + missed injury",
"handläggning\r\ndokumentation" = "Patient management + documentation"
)
)

ofi_categories$Problemomrade_.FMP <- ifelse(ofi_categories$Problemomrade_.FMP == "Patient management/logistik", "Patient management/logistics", ofi_categories$Problemomrade_.FMP)
ofi_categories$Problemomrade_.FMP <- ifelse(ofi_categories$Problemomrade_.FMP == "Level of care+ missade skador", "Level of care + missed injuries", ofi_categories$Problemomrade_.FMP)

# Assign broad categories based on translated OFIs
ofi_categories <- ofi_categories %>%
mutate(
BroadCategory = case_when(
Problemomrade_.FMP %in% c("Missed injury", "Tertiary survey") ~ "Missed diagnosis",
Problemomrade_.FMP %in% c("Delay to surgery", "Delay to CT") ~ "Delay in treatment",
Problemomrade_.FMP %in% c("Triage in the ED", "Level of care", "Patient management", "Communication") ~ "Clinical judgement error",
Problemomrade_.FMP %in% c("Documentation") ~ "Documentation Issues",
Problemomrade_.FMP %in% c("Technical error") ~ "Technical error",
Problemomrade_.FMP %in% c("Trauma criteria/guidelines", "Inadequate routine") ~ "Inadequate protocols",
Problemomrade_.FMP %in% c("Competence", "Resources", "Logistics/technical") ~ "Inadequate resources",
Problemomrade_.FMP %in% c("Other", "Patient management/logistics", "Prehospital management", "Level of care + missed injury") ~ "Other errors",
TRUE ~ "Other errors"
)
)

# Handle NA values in the Intubation column
ofi_categories <- ofi_categories %>%
mutate(Intubation = ifelse(is.na(Intubation), "Unknown", Intubation))

# Remove rows where any variable other than Problemomrade_.FMP is NA
clean <- ofi_categories %>%
filter(if_all(c(Sex, Age, Intubation, RTS, ISS, TimeFCT, OnDuty, daysinICU, ASApreinjury, Survival, OpportunityForImprovement), ~ !is.na(.)))

# Create a combined column for BroadCategory and Problemomrade_.FMP
clean <- clean %>%
mutate(Category = paste(BroadCategory, Problemomrade_.FMP, sep = ": ")) %>%
select(Category, OpportunityForImprovement)

# Filter to include only rows with Opportunity for Improvement
clean <- clean %>%
filter(OpportunityForImprovement == "Opportunity for improvement")

# Create a summary table
table_ofic <- clean %>%
tbl_summary(by = OpportunityForImprovement,
statistic = list(
all_categorical() ~ "{n}"
),
missing = "ifany",
missing_text = "Missing",
digits = all_continuous() ~ 0
) %>%
bold_labels() %>%
modify_caption("<div style='text-align: left; font-weight: bold; color: black'>Table 1. Opportunities for improvement categories on the patient cohort of the study</div>") %>%
modify_table_styling(
columns = label,
rows = label == "Clinical judgement error: Communication",
footnote = "[active] failures in communication with parties outside the treating team, e.g. consultants, receiving unit etc., did not consult neurosurgeon before transfer"
) %>%
modify_table_styling(
columns = label,
rows = label == "Clinical judgement error: Level of care",
footnote = "pt transferred to inappropriate level of care given available information/protocols (not due to lack of resources), pt transferred to IMCU rather than ICU"
) %>%
modify_table_styling(
columns = label,
rows = label == "Clinical judgement error: Patient management",
footnote = "[active] failure to perform the appropriate exams and interventions in appropriate order and time given available information/protocols (not due to lack of resources) sent pt to CT with inadequately secured airway"
) %>%
modify_table_styling(
columns = label,
rows = label == "Clinical judgement error: Triage in the ED",
footnote = "[active] pt assigned inappropriate level given available information/protocols, failure to activate trauma team, ED = emergency department"
) %>%
modify_table_styling(
columns = label,
rows = label == "Delay in treatment: Delay to CT",
footnote = "[active] failure to perform computed tomography when indicated/in protocols"
) %>%
modify_table_styling(
columns = label,
rows = label == "Delay in treatment: Delay to surgery",
footnote = "[active] failure to move pt to OR within an appropriate time, let's monitor this pt further before deciding on surgery"
) %>%
modify_table_styling(
columns = label,
rows = label == "Inadequate protocols: Trauma criteria/guidelines",
footnote = "[passive] maladapted protocols/guidelines, the trauma team activation protocol should assign this pt level 1"
) %>%
modify_table_styling(
columns = label,
rows = label == "Inadequate resources: Logistics/technical",
footnote = "[passive] required equipment was unavailable/out of service, IT system was down making pt records unavailable"
) %>%
modify_table_styling(
columns = label,
rows = label == "Inadequate resources: Resources",
footnote = "[passive] insufficient available resources (not active errors such as failure to activate backup team), no OR was available"
) %>%
modify_table_styling(
columns = label,
rows = label == "Missed diagnosis: Missed injury",
footnote = "[active] failure to identify injury that should have been identified given available information, reasonable clinical judgment and protocols (includes missed injuries due to skipped exam"
) %>%
modify_table_styling(
columns = label,
rows = label == "Missed diagnosis: Tertiary survey",
footnote = "[active] failure to perform tertiary survey within appropriate time when indicated/in protocols"
) %>%
modify_table_styling(
columns = label,
rows = label == "Other errors: Level of care+ missade skador",
footnote = "[active] pt transferred to inappropriate level of care given available information/protocols (not due to lack of resources), pt transferred to IMCU rather than ICU"
) %>%
modify_table_styling(
columns = label,
rows = label == "Other errors: Patient management/logistics",
footnote = "[other] name implies interaction with systems"
) %>%
modify_table_styling(
columns = label,
rows = label == "Category",
footnote = "Definitions of categories of opportunities for improvements used"
) %>%
print()





# lookup to categorize ofi
# MISSED INJURY
# Missed injury (active failure): failure to identify injury despite adequate information. Includes misinterpretation of imagery etc.
# Examples: surveys, radiology, explorative procedures
# DELAYED TREATMENT
# Delay in treatment (active failure): inappropriate delay from arrival/assessment to treatment causing pt harm. Does **not** include delays due to clinical judgment errors, i.e. "I don't think a DT is needed".
# Examples: failure to activate trauma team, delay in hemorrhage control, delay in moving to OR, failure to activate backup surgical team, ddelay in moving from ED to OR, OR unavailable, ddelay to angio, delay in performing intervention, delay in intubation, delay due to interhospital transfer, delay in interhospital transfer, initial transfer to wrong department
# CLINICAL JUDGMENT ERROR
# Clinical judgment error (active failure): inappropriate plan of actions/management, given available information, causing pt harm.
# Examples: Inadequate monitoring, medication errors, wrong level of care/unit, wrong protocol/procedure applied, wrong treatment
# TECHNICAL ERROR (SKILL)
# Technical error (active failure): inadequate performance of intervention/procedure causing pt harm.
# INADEQUATE PROTOCOLS
# Inadequate protocols (passive failure): inadequate protocols/guidelines etc. leading to pt harm.
# "Inadequate protocols" = c(
# "bristande rutin" # [passive] no/maladapted formalized routine for type cases, "no guidelines for pediatric multitrauma"
# INADEQUATE RESOURCES
# Inadequate resources (passive failure): lack of resources leading to pt harm.
# Examples: lack of trauma/backup team, lack of equipment/training etc.
# "Inadequate resources" = c(
# "kompetens brist", # [passive] required competence not available, "no neurosurgeon on site/available"
# ),
# OTHER
# Anything else.
# "Other errors" = c(
# "annat", # [other]
# "handläggning prehosp", # [other] unclear
# "neurokirurg" # [other] unclear




Loading