Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pigeonflight
Last active January 7, 2023 08:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigeonflight/2282bfde697dbd81999e22fba64317ad to your computer and use it in GitHub Desktop.
Save pigeonflight/2282bfde697dbd81999e22fba64317ad to your computer and use it in GitHub Desktop.
ICD-11 Code Interpreter . This python script passes an ICD-11 code cluster and returns the interpretation (in English only at the moment)

Assumptions

You have Python. You've installed the requests library. You have docker on your machine.

Usage

  1. Launch the ICD-11 docker container
docker run -p 80:80  --env "acceptLicense=true" --env "saveAnalytics=true" --env "includeIp=false" whoicd/icd11_sw_1904_mms_en
  1. Download the script
wget https://gist.githubusercontent.com/pigeonflight/2282bfde697dbd81999e22fba64317ad/raw/33a589e1847669f8e40ff72314520f37975e901c/icd11-code-interpreter.py
  1. Try the script with a sample code cluster
 python icd11-code-interpreter.py "ND56.2&XA7R53&XA2T04"

You should see output similar to this:

[{'code': 'ND56.2', 'description': 'Fracture of unspecified body region'}, {'code': 'XA7R53', 'description': 'Bones of the upper extremity'}, {'code': 'XA2T04', 'description': 'Bones of the lower extremity'}]

Try generating other code clusters using the ICD-11 online coding tool

Todo

The plan is to rework this script to integrate with the Tryton platform.

import requests
import sys
#uri = 'http://localhost/icd/release/11/2019-04/mms/codeinfo/'
base_uri = 'http://localhost/icd/release/11/2019-04/mms/codeinfo/{}'
mms_uri = 'http://localhost/icd/release/11/2019-04/mms{}'
cluster_output = []
last_splitter = ""
try:
sample_cluster_code = sys.argv[1]
except IndexError:
sample_cluster_code = "ND56.2&XA7R53&XA2T04/PC30&XE7K0"
# HTTP header fields to set
headers = {
'Accept': 'application/json',
'Accept-Language': 'en',
'API-Version': 'v2'}
def code_to_description(code):
uri = base_uri.format(code)
req = requests.get(uri, headers=headers, verify=False)
output = req.json()
stem = output['stemId'].split('/mms')[-1]
stem_uri = mms_uri.format(stem)
req = requests.get(stem_uri, headers=headers, verify=False)
output = req.json()
return output['title']['@value']
def cluster_walker(cluster):
global cluster_output
global last_splitter
# does list contain / codes
if "/" in cluster:
last_splitter = "/"
cluster_list = cluster.split('/')
for item in cluster_list:
cluster_walker(item)
elif "&X" in cluster:
last_splitter = "&"
cluster_list = cluster.split('&')
for item in cluster_list:
cluster_walker(item)
else:
cluster_output.append({'code':cluster,'description':code_to_description(cluster)})
cluster_walker(sample_cluster_code)
print(cluster_output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment