Skip to content

Algorithm to Identify Patients at Risk of Post-TKA Opioid Dependence

Key findings

  • Orthopedic surgeons at Massachusetts General Hospital used machine learning to develop five different types of computer algorithms for predicting prolonged prescribing of opioids after total knee arthroplasty (TKA)
  • Each algorithm was tested against data on 2,508 patients who had undergone TKA
  • The predictions of a stochastic gradient boosting model on postoperative opioid prescribing were better than those based only on preoperative opioid use
  • Age, history of preoperative opioid use, marital status, diagnosis of diabetes and preoperative use of certain medications were predictive of prolonged opioid prescribing after TKA

The opioid crisis is of particular concern to orthopedic surgeons, the leading prescribers of opioids among surgical subspecialties. Use of opioid medications after orthopedic procedures has been linked to susceptibility to long-term abuse and addiction.

Previously, researchers at Massachusetts General Hospital developed a computer algorithm that helps surgeons preoperatively determine which patients are at increased risk of opioid dependence after total hip arthroplasty, as published in The Journal of Arthroplasty. Now, Akhil Katakam, MBA, surgical research fellow, and Hany S. Bedair, MD, surgeon in the Center for Hip and Knee Replacement in Department of Orthopedic Surgery at Massachusetts General Hospital, and colleagues have developed a similar tool for patients undergoing total knee arthroplasty (TKA). Their report appears in the Journal of Orthopaedics.

Study Design

The researchers identified 12,542 adults who underwent primary elective TKA for osteoarthritis at Mass General between January 1, 2000, and March 1, 2018. Of those, 10,034 patients (80%) served as a training set for algorithm development and the other 2,508 were the testing set.

Five different types of machine learning algorithms were developed. Each was tested for its ability to predict prolonged postoperative prescribing of opioids, defined as continuous opioid prescriptions in the 30 days after surgery, days 30 to 90 and days 90 to 180.

Algorithm Performance

A stochastic gradient boosting (SGBa) model performed best in terms of discrimination, calibration and overall performance. Its predictions about postoperative opioid prescribing were better than those based only on the preoperative opioid use of patients in the testing set.

Predictive Variables

The following factors contributed to the SGB model's ability to make predictions at the individual patient level:

  • Age
  • History of preoperative opioid use
  • Marital status
  • Diagnosis of diabetes
  • Use of certain medications preoperatively (antidepressants, benzodiazepines, nonsteroidal anti-inflammatory drugs, gabapentin or beta-agonists)

Variables examined that did not predict prolonged opioid prescribing were patient demographics, discharge location, laboratory values, insurance status and neighborhood characteristics.

Clinical Applications

The computerized tool still needs to be validated. If it is, clinicians could enter details on particular patients to learn their risk of prolonged opioid use after TKA. As necessary, providers could then intensify their counseling and education efforts, consider limiting postoperative opioid prescriptions to less than 90 days and consider alternative pain management strategies.

Learn more about the Center for Hip and Knee Replacement

Refer a patient to the Department of Orthopaedics


One month after patellofemoral knee arthroplasty, the percentage of patients using opioids for pain relief was about the same as after total knee arthroplasty and significantly higher than among patients who had medial unicompartmental knee arthroplasty.


Preoperative opioid use was associated with poorer patient-reported outcomes after total hip arthroplasty as well as longer hospital stays and higher rates of discharge to a rehabilitation facility.