Data-driven Identification of Urgent Surgical Procedures For Use in Epidemiological Studies in Trauma
Matthew Miller, Louise Jorm and Blanca Gallego
citation: Miller M, Jorm L, Gallego B. Data-driven identification of urgent surgical procedures for use in trauma outcomes measurement. Trauma Surg Acute Care Open. 2025;10:e001783. doi:10.1136/tsaco-2025-001783
The accompanying series of R scripts are used to create a list of urgent surgery from surgical booking priority. They can be used for all surgical patients, or limited to those admitted with trauma. Options are included to change the agreement cut off, consensus cut off, age group, and whether to use trauma-only or all surgical patients. Instructions are also given on how to alter the classification of urgency to suit bespoke definitions. R code to generate lists for specific age groups and genders are also provided.
Note: unfortunately the ACHI procedure code and ICD diagnosis code tables need to be obtained separately as we don't have a licence to distribute them here.
These scripts are written for an Australian study and modifications will be needed for other countries/hospitals. In particular:
- Trauma is defined here as any patient admitted with a diagnosis code from the ICD-10-AM (11th edition) Chapters 19 (Injury, Poisoning, and certain other consequences of external causes) and 20 (External causes of morbidity and mortality). Codes related to hospital complications are excluded as part of the script. This will need to be altered for international codes such as the ICD-10-CM in script 2.
- The procedure codes used in these scripts are for the Australian Classification of Health Interventions. To use ICD-10-AM procedure codes or ICD-11 Classification of Health Intervention codes you will need to modify script 2.
- The surgical priorities will be institution specific and will need updating and collapsing. In our institution these were: "<=15minutes-Immediate life threatening", "A-1hr Life threatening incl obstetric", "<=1hr-Life threatening conditions", "B-2hrs Highly critical organ/limb threat", "<=4hrs-Organ or limb threatening", "C-4hrs Critical", "<=8hrs-Non-critical but emergent" , "D-8hrs Urgent", "<=24hrs-Non critical, non-emergent", "E-24hrs Semi-Urgent", "<=72hrsCannot discharge before procedure", "F-72hrs Non-Urgent". You will need to modify script 1, starting around line 33, and change the case_when criteria. The right hand arguments must remain as "<1hr","<4hrs", "<8hrs", "<24hrs","<72hrs".
The tables below outline the columns in the databases, including names and levels, that are needed for the scripts to work. Examples using synthetic (fake) data are also given in the file repository.
| Column name | Description |
|---|---|
| study_id | Anonymised ID |
| sex | M, F |
| asa | "1 - Healthy" "2 - Mild Systemic Disease" "3 - Moderate to Severe Systemic Disease" "4 - Severe Systemic Disease" "5 - Moribund" "See anaesthetist record" "No anaesthetist" "6 - Organ Donor/Transplant" |
| age | In years |
| admit_dt_tm | POSIXct YMD HMS |
| case_date | Date |
| emerg_book_dt_tm | POSIXct YMD HMS |
| admit_to_book_pd | From script 1. "same day", "same week", "over 1 week" |
| specialty | Bespoke to your data |
| procedural_consultant | Alphanumeric from script 1 |
| planned_procedure | Free text |
| primary_procedure | Free text |
| emerg_priority | Bespoke from your data |
| emerg_priority_collapse | From script 1. Must be one of "<1hr","<4hrs", "<8hrs", "<24hrs","<72hrs" |
| episode_number | numeric |
| coded_primary_procedure | ACHI / Procedure code |
| episode_start_date | Date |
| additional_procedure_1 | ACHI / Procedure code |
| additional_procedure_2 | ACHI / Procedure code |
| additional_procedure_3 | ACHI / Procedure code |
| additional_procedure_4 | ACHI / Procedure code |
| additional_procedure_..... | ACHI / Procedure code. No limit on additional columns |
| principle_diagnosis | ICD code |
| additional_diagnosis_1 | ICD code |
| additional_diagnosis_2 | ICD code |
| additional_diagnosis_3 | ICD code |
| additional_diagnosis_4 | ICD code |
| additional_diagnosis_...... | ICD code. No limit on additional columns |
| Column name | Description |
|---|---|
| achi_proc_code | ACHI procedure code |
| procedure_text | text |
| block_number | Number (from ACHI block) |
| block_text | text |
| procedure_chapter | Text |
| procedure_sub_chapter | Text |
| icd10_ver | ICD-10 version |
| Column name | Description |
|---|---|
| four_dgt_no | ICD-10 four digit code |
| four_dgt_text | Text |
| three_dgt_no | ICD-10 three digit code |
| three_dgt_text | Text |
| diagnosis_chapter | Text |
| diagnosis_subchapter | Text |
Script 1. Preprocessing the data.
The script focusses on preprocessing and summarising data related to study admissions and procedural priorities, collapsing and categorising emergency priorities, and ensuring data security by hashing certain variables. The aim is to make the urgency factor levels consistent with the remaining scripts, to anonymise the procedural consultant and convert the admission time to "same day" or not categories for filtering later.
- Vector Definition:
- Defines a character vector
id_chrscontaining alphanumeric characters (0-9 and a-z), to be used in creating study IDs.Urgency Levels: - Defines a vector
urgency_levels_collapsedrepresenting collapsed urgency levels.
- Defines a character vector
- Reads Study Database:
- Reads a study database from an Excel file named "study_db.xlsx" into a data frame called
study_db.
- Reads a study database from an Excel file named "study_db.xlsx" into a data frame called
- Calculates Admission to Booking Period:
- Computes the time difference in hours between the columns
emerg_book_dt_tmandadmit_dt_tmand creates a new variableadmit_to_book_pdrepresenting the admission to booking period.
- Computes the time difference in hours between the columns
- Categorizes Booking Periods:
- Creates categories for the admission to booking period based on time duration ("same day," "same week," or "over 1 week").
- Frequency Table:
- Prints a frequency table for the variable
admit_to_book_pdto summarize the distribution of booking periods.
- Prints a frequency table for the variable
- Filters and Collapses Data:
- Filters the study database to include only cases with the admission to booking period as "same day."
- Groups the data by
study_id,age, andadmit_dt_tm. - Selects the first case within each group based on the
case_date. - Collapses emergency priorities into broader categories (e.g., "<1hr", "<4hrs") using the
emerg_priority_collapsevariable. - Converts
emerg_priority_collapseinto a factor variable with specified levels.
- Anonymise Procedural Consultant:
- changes the
procedural_consultantvariable to an alphanumeric character.
- changes the
This is divided into three parts.
processes procedure data, cleans and matches procedure descriptions.
- Loading Study Data:
- The study data is loaded into a variable named
study_db_all.
- The study data is loaded into a variable named
- Downloading ACHI and ICD Codes:
- ACHI codes are stored in the
achi_dbvariable. - ICD-1-AM codes are stored in the
icd_dbvariable.
- ACHI codes are stored in the
- Removing Unwanted Procedure Codes:
- Certain procedure codes related to anesthesia, airway management, ventilatory support, vascular access device, etc., are identified and removed from the
achi_db,combined into a single list calledcodes_to_remove.
- Certain procedure codes related to anesthesia, airway management, ventilatory support, vascular access device, etc., are identified and removed from the
- Extracting Primary Procedure Data:
- The primary procedure data is extracted from the
study_db_allvariable and stored instudy_db_coded_primary.
- The primary procedure data is extracted from the
- Matching Procedure Codes:
- Procedure codes are matched based on both planned and primary procedures as we had two columns that describe the booked procedure. You may need to use only the first one.
- Stopwords are removed, and text cleaning is performed on free-text descriptions.
- Common words between planned and actual procedures are identified for both planned and primary procedures.
- The resulting data frames are named
planned_achiandprimary_achi.
- Creating ACHI Coded Database:
- A new database (
achi_study_db) is created by combining the primary procedure data with planned procedures for each study. - Duplicate entries are removed, and the column is renamed as
booked_procedure. Thebooked_procedurecolumn is added back to the original study database (study_db_all) and unwanted codes specified incodes_to_removeare filtered out.
- A new database (
- Counting Procedure Additions:
- The number of procedures for each study is counted, and the maximum count is retained.
- The script prints the count of procedures for each study.
- Checking for missing Values:
- The script checks for missing values in the
booked_procedurecolumn. The final step involves filtering out rows where thebooked_procedurecolumn is missing.
- The script checks for missing values in the
is an R function, named get_list_of_procedures, summarising surgical procedure data. It has the following options:
| cohort | can be "all patients" or "trauma" . If all patients, then an extra step in the function classifies the patients as trauma or not for the final table. |
|---|---|
| agreement_threshold | 0-100 |
| consensus_threshold | 0-1 |
| urgency | can be 1,4,8,12,24 or 72 depending on the time period you are considering as urgent. For example, if it is all procedures booked within a 4-hour time period, then urgency = 4. |
| show_figures_tables | TRUE or FALSE if you want some summary information |
The steps are:
- Trauma Identification:
- The function starts by identifying trauma cases in the dataset. It uses specific diagnosis codes to classify episodes of care as trauma or non-trauma.
- The identified trauma study IDs are stored in the variable
trauma_study_ids.
- Filtering Dataset:
- The function then filters the original study database (
study_db) to include only cases with trauma study IDs (study_db_trauma).
- The function then filters the original study database (
- Main Functionality:
- The main functionality of the function is to create a table of procedures and urgency levels based on specified criteria such as agreement and consensus thresholds.
- It provides an option to filter data based on age range and urgency level.
- It calculates various statistics, including the number of unique procedures, unique booking proceduralists, and individual patients.
- It generates tables and figures summarizing the urgency levels, agreement, and consensus among proceduralists.
- It assesses the distribution of urgency levels across all booked procedures.
- Trauma Analysis (Optional):
- If the analysis is for the entire cohort (
cohort == "all patients"), the function further analyzes trauma cases within the dataset. - Trauma cases are identified based on diagnosis codes, and the results are added to the main dataframe.
- If the analysis is for the entire cohort (
- Primary Procedure Identification:
- The function identifies primary procedures by comparing booked procedures with a list of primary procedures.
- It calculates confidence intervals for the proportion of urgent cases and adds this information to the main dataframe.
runs the get_list_of_procedures function. Code is also provided to create urgency tables and save them to an excel workbook, and to create age group and gender specific lists.
- Run Procedure Analysis Function for Trauma:
- The
get_list_of_proceduresfunction is applied.
- The
- Join ACHI Code Descriptions:
- The resulting list of procedures (
full_list) is joined with the ACHI code descriptions (achi_text), providing additional information about each procedure.
- The resulting list of procedures (
- Filter Procedures by Urgency (Agreement and Consensus):
- Two subsets of procedures are created based on urgency classification:
full_list_urgent: Procedures classified as urgent by agreement.full_list_urgent_consensus: Procedures classified as urgent by consensus.
- Two subsets of procedures are created based on urgency classification:
- Frequency Tables for Trauma and Primary Procedures:
- Frequency tables are generated for trauma cases and primary procedures for both the agreement and consensus subsets.
- Generate Lists for Different Age Groups:
- Lists of procedures are generated for different age groups, including pediatrics (
paeds_list), adults (adult_list), and the elderly (elderly_list). - Urgent procedures for each age group are also identified and categorized.
- Lists of procedures are generated for different age groups, including pediatrics (
- Identify Differences in Procedures Between Age Groups:
- Differences in procedures between age groups are identified, and separate data frames are created to show procedures specific to each age group.
- Frequency Tables for Differences in Age Groups:
- Frequency tables are generated to show the distribution of procedures that are specific to age groups, considering trauma and primary procedure classifications.
- Generate Lists for Different Gender Groups:
- Lists of procedures are generated for male and female trauma patients.
- Write Results to Excel Workbook:
- The results, including urgent procedures, additional procedures by consensus, and various age and gender-specific lists, are written to an Excel workbook named "urgent_surgery_lists.xlsx."
This part produces demographic data and some regression analysis. The final part aims to analyse and visualise the distribution of urgency levels based on different consensus cutoffs in a trauma cohort, to help decide an appropriate consensus threshold.
- Study Group Selection:
- A trauma-only study group (
study_db_trauma) is created by filtering the original study database (study_db) to include only trauma cases.
- A trauma-only study group (
- Demographics Data Preparation:
- Unique entries of trauma study IDs are selected from the trauma-only database (
study_db_trauma). - Non-trauma patients are identified by subtracting trauma patients from the original study group.
- Unique entries of trauma study IDs are selected from the trauma-only database (
- ICD Code Processing:
- Injury and mechanism codes are combined, and specific codes are removed based on predefined sets (
ts,ys,us,xs). - Trauma identification is performed using injury and mechanism codes, and a new dataset (
trauma1) is created.
- Injury and mechanism codes are combined, and specific codes are removed based on predefined sets (
- Demographic Variables Selection:
- Relevant demographic variables are selected, including age, sex, ASA (American Society of Anesthesiologists) score, specialty, and emergency priority.
- Demographic Summary Statistics:
- Summary statistics and histograms are generated for age.
- Frequency tables are created for ASA score, trauma status, sex, and emergency priority.
- Specialty Data Processing:
- Specialty names are standardized, and a frequency table is generated.
- Urgent Specialty Analysis:
- A list of urgent specialty frequencies is created based on urgent procedures identified earlier.
- Results Export:
- Lists of specialty frequencies for urgent and entire study groups are saved to an Excel workbook (
specialty_lists.xlsx).
- Lists of specialty frequencies for urgent and entire study groups are saved to an Excel workbook (
- Procedure Selection for Regression:
- Procedures with a minimum number of raters and those with both male and female patients are identified.
- Multilevel Logistic Regression Models:
- Several logistic regression models are fitted, considering different fixed and random effects.
- Null model is assessed for Intraclass Correlation Coefficient (ICC).
- Models are compared using ANOVA.
- Odds Ratios Calculation:
- Odds ratios with confidence intervals are calculated and presented for significant predictors.
- ICD Code Processing for Entire Cohort:
- Similar ICD code processing is performed for the entire cohort (
study_db_all).
- Similar ICD code processing is performed for the entire cohort (
- Procedure Selection for Regression (Entire Cohort):
- Procedures with a minimum number of raters are identified.
- Multilevel Logistic Regression Models (Entire Cohort):
- Similar steps are followed as in the trauma cohort analysis.
- Odds Ratios Calculation (Entire Cohort):
- Similar odds ratios and confidence interval calculations are performed.
- A function named
table_of_nis defined to calculate and create a table of procedure counts based on specified agreement and consensus thresholds. - Two vectors (
a_thfor agreement thresholds andc_thfor consensus thresholds) are defined. - The
map2function is used to apply thetable_of_nfunction to all combinations of agreement and consensus thresholds, and the results are combined into a table (table_of_counts).
- Urgency levels (
<1hr,<4hrs,<8hrs,<24hrs,<72hrs) are defined. - Different consensus thresholds are evaluated (0.6, 0.65, 0.7, 0.75), and procedures meeting the urgent surgery criteria are filtered accordingly.
- The results are combined into a data frame (
consensus_plots) and visualized using density plots and jitter plots for each urgency level. - Two plots are generated: one displaying the distribution of proportion of responses for each urgency level by consensus cutoff, and another showing the distribution for each urgency level, with each point representing a surgical procedure.