# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] id="SymssfV7IcQ7"
# ![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)

# + [markdown] id="MCjxEZg_IfJo"
# [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/Certification_Trainings/Healthcare/11.Pretrained_Clinical_Pipelines.ipynb)

# + [markdown] id="v4uN8ZP_Itdo"
# # 11. Pretrained_Clinical_Pipelines

# + [markdown] id="YcrO6BlfIwEV"
# ## Colab Setup

# + id="sDxBKvHjIc5B"
import json

from google.colab import files

license_keys = files.upload()

with open(list(license_keys.keys())[0]) as f:
    license_keys = json.load(f)

# + id="R6iawCF1hDtv" executionInfo={"status": "ok", "timestamp": 1617889661677, "user_tz": -180, "elapsed": 125500, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}}
# %%capture
for k,v in license_keys.items(): 
    # %set_env $k=$v

# !wget https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-workshop/master/jsl_colab_setup.sh
# !bash jsl_colab_setup.sh -p 2.4.4

# + id="xzNgN33jNHTe" colab={"base_uri": "https://localhost:8080/"} executionInfo={"status": "ok", "timestamp": 1617889681495, "user_tz": -180, "elapsed": 142327, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="ff464671-6656-4639-eff8-468dd1585056"
import json
import os
from pyspark.ml import Pipeline
from pyspark.sql import SparkSession

from sparknlp.annotator import *
from sparknlp_jsl.annotator import *
from sparknlp.base import *
import sparknlp_jsl
import sparknlp

params = {"spark.driver.memory":"16G",
"spark.kryoserializer.buffer.max":"2000M",
"spark.driver.maxResultSize":"2000M"}

spark = sparknlp_jsl.start(license_keys['SECRET'],params=params)

print ("Spark NLP Version :", sparknlp.version())
print ("Spark NLP_JSL Version :", sparknlp_jsl.version())

# + [markdown] id="9CzSCbXSKLSC"
#
# <b>  if you want to work with Spark 2.3 </b>
# ```
# import os
#
# # Install java
# # # ! apt-get update -qq
# # # ! apt-get install -y openjdk-8-jdk-headless -qq > /dev/null
#
# # # !wget -q https://archive.apache.org/dist/spark/spark-2.3.0/spark-2.3.0-bin-hadoop2.7.tgz
#
# # # !tar xf spark-2.3.0-bin-hadoop2.7.tgz
# # # !pip install -q findspark
#
# os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"
# os.environ["PATH"] = os.environ["JAVA_HOME"] + "/bin:" + os.environ["PATH"]
# os.environ["SPARK_HOME"] = "/content/spark-2.3.0-bin-hadoop2.7"
# # # ! java -version
#
# import findspark
# findspark.init()
# from pyspark.sql import SparkSession
#
# # # ! pip install --ignore-installed -q spark-nlp==2.7.5
# import sparknlp
#
# spark = sparknlp.start(spark23=True)
# ```

# + [markdown] id="hmhC6kMHKYyh"
# ## Pretrained Pipelines

# + [markdown] id="dLFDvuupKeGH"
# In order to save you from creating a pipeline from scratch, Spark NLP also has a pre-trained pipelines that are already fitted using certain annotators and transformers according to various use cases.
#
# Here is the list of clinical pre-trained pipelines: 
#
# > These clinical pipelines are trained with `embeddings_healthcare_100d` and accuracies might be 1-2% lower than `embeddings_clinical` which is 200d.
#
# **1.   explain_clinical_doc_carp** :
#
# > a pipeline with `ner_clinical`, `assertion_dl`, `re_clinical` and `ner_posology`. It will extract clinical and medication entities, assign assertion status and find relationships between clinical entities.
#
# **2.   explain_clinical_doc_era** :
#
# > a pipeline with `ner_clinical_events`, `assertion_dl` and `re_temporal_events_clinical`. It will extract clinical entities, assign assertion status and find temporal relationships between clinical entities.
#
# **3.   recognize_entities_posology** :
#
# > a pipeline with `ner_posology`. It will only extract medication entities.
#
#
# ** Since 3rd pipeline is already a subset of 1st and 2nd pipeline, we will only cover the first two pipelines in this notebook.
#
# **4.   explain_clinical_doc_ade** :
#
# > a pipeline for `Adverse Drug Events (ADE)` with `ner_ade_biobert`, `assertiondl_biobert` and `classifierdl_ade_conversational_biobert`. It will extract `ADE` and `DRUG` clinical entities, assign assertion status to `ADE` entities, and then assign ADE status to a text (`True` means ADE, `False` means not related to ADE).
#
# **letter codes in the naming conventions:**
#
# > c : ner_clinical
#
# > e : ner_clinical_events
#
# > r : relation extraction
#
# > p : ner_posology
#
# > a : assertion
#
# > ade : adverse drug events
#
# **Relation Extraction types:**
#
# `re_clinical` >> TrIP (improved), TrWP (worsened), TrCP (caused problem), TrAP (administered), TrNAP (avoided), TeRP (revealed problem), TeCP (investigate problem), PIP (problems related)
#
# `re_temporal_events_clinical` >> `AFTER`, `BEFORE`, `OVERLAP`
#

# + [markdown] id="pK2Tt0ZuRy2B"
# ## 1.explain_clinical_doc_carp 
#
# a pipeline with ner_clinical, assertion_dl, re_clinical and ner_posology. It will extract clinical and medication entities, assign assertion status and find relationships between clinical entities.

# + id="Y1di9iuJMiXl"
from sparknlp.pretrained import PretrainedPipeline

# + colab={"base_uri": "https://localhost:8080/"} id="4rg3oe37R1wX" executionInfo={"status": "ok", "timestamp": 1617830337044, "user_tz": -180, "elapsed": 106518, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="75402fc0-f794-4d93-b698-fdf796922a51"
pipeline = PretrainedPipeline('explain_clinical_doc_carp', 'en', 'clinical/models')

# + colab={"base_uri": "https://localhost:8080/"} id="V7OaKtxjvA7f" executionInfo={"status": "ok", "timestamp": 1617830341328, "user_tz": -180, "elapsed": 872, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="76dd44d8-9ac4-4c66-9182-e0f773664b1e"
pipeline.model.stages

# + id="d9eRK3IKUurq"
# Load pretrained pipeline from local disk:

# >> pipeline_local = PretrainedPipeline.from_disk('/root/cache_pretrained/explain_clinical_doc_carp_en_2.5.5_2.4_1597841630062')

# + colab={"base_uri": "https://localhost:8080/"} id="3xmhwW2MVKYa" executionInfo={"status": "ok", "timestamp": 1617830357065, "user_tz": -180, "elapsed": 3540, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="1ade5f87-e409-49fd-c1a0-08854c89d1a4"
text ="""A 28-year-old female with a history of gestational diabetes mellitus, used to take metformin 1000 mg two times a day, presented with a one-week history of polyuria , polydipsia , poor appetite , and vomiting .
She was seen by the endocrinology service and discharged on 40 units of insulin glargine at night, 12 units of insulin lispro with meals.
"""

annotations = pipeline.annotate(text)

annotations.keys()


# + colab={"base_uri": "https://localhost:8080/", "height": 669} id="X4z-RbyZVvgR" executionInfo={"status": "ok", "timestamp": 1617830360621, "user_tz": -180, "elapsed": 1140, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="09b709c2-127b-445b-bc45-f31def259e41"
import pandas as pd

rows = list(zip(annotations['tokens'], annotations['clinical_ner_tags'], annotations['ner_tags'], annotations['pos_tags'], annotations['dependencies']))

df = pd.DataFrame(rows, columns = ['tokens','clinical_ner_tags','posology_ner_tags','POS_tags','dependencies'])

df.head(20)

# + colab={"base_uri": "https://localhost:8080/", "height": 173} id="5Hlwc2M2Xl_y" executionInfo={"status": "ok", "timestamp": 1617830405175, "user_tz": -180, "elapsed": 3063, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="dc165a34-4cef-49b6-c3fe-75d64145052f"
text = 'Patient has a headache for the last 2 weeks and appears anxious when she walks fast. No alopecia noted. She denies pain'

result = pipeline.fullAnnotate(text)[0]

chunks=[]
entities=[]
status=[]

for n,m in zip(result['clinical_ner_chunks'],result['assertion']):
    
    chunks.append(n.result)
    entities.append(n.metadata['entity']) 
    status.append(m.result)
        
df = pd.DataFrame({'chunks':chunks, 'entities':entities, 'assertion':status})

df

# + colab={"base_uri": "https://localhost:8080/", "height": 514} id="wF9PCC18Y7eE" executionInfo={"status": "ok", "timestamp": 1617830413797, "user_tz": -180, "elapsed": 1432, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "01037434825541536598"}} outputId="ceb2c8a6-abfe-49fa-89f1-8dfd737e74ef"
text = """
The patient was prescribed 1 unit of Advil for 5 days after meals. The patient was also 
given 1 unit of Metformin daily.
He was seen by the endocrinology service and she was discharged on 40 units of insulin glargine at night , 
12 units of insulin lispro with meals , and metformin 1000 mg two times a day.
"""

result = pipeline.fullAnnotate(text)[0]

chunks=[]
entities=[]
begins=[]
ends=[]

for n in result['ner_chunks']:
    
    chunks.append(n.result)
    begins.append(n.begin)
    ends.append(n.end)
    entities.append(n.metadata['entity']) 
        
df = pd.DataFrame({'chunks':chunks, 'begin':begins, 'end':ends, 'entities':entities})

df

# + id="oFLWugWaViPU"
import pandas as pd

def get_relations_df (results, col='relations'):
  rel_pairs=[]
  for rel in results[0][col]:
      rel_pairs.append((
          rel.result, 
          rel.metadata['entity1'], 
          rel.metadata['entity1_begin'],
          rel.metadata['entity1_end'],
          rel.metadata['chunk1'], 
          rel.metadata['entity2'],
          rel.metadata['entity2_begin'],
          rel.metadata['entity2_end'],
          rel.metadata['chunk2'], 
          rel.metadata['confidence']
      ))

  rel_df = pd.DataFrame(rel_pairs, columns=['relation','entity1','entity1_begin','entity1_end','chunk1','entity2','entity2_begin','entity2_end','chunk2', 'confidence'])

  rel_df.confidence = rel_df.confidence.astype(float)
  
  return rel_df



# + colab={"base_uri": "https://localhost:8080/", "height": 371} id="lRkeOb4RZwJS" executionInfo={"status": "ok", "timestamp": 1617830553422, "user_tz": -180, "elapsed": 1923, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="5c2c00eb-fff4-4042-f1b8-9b6f0e2258d8"
text ="""A 28-year-old female with a history of gestational diabetes mellitus, used to take metformin 1000 mg two times a day, presented with a one-week history of polyuria , polydipsia , poor appetite , and vomiting .
She was seen by the endocrinology service and discharged on 40 units of insulin glargine at night, 12 units of insulin lispro with meals.
"""

annotations = pipeline.fullAnnotate(text)

rel_df = get_relations_df (annotations, 'clinical_relations')

rel_df

# + colab={"base_uri": "https://localhost:8080/", "height": 566} id="IlFpX8Qm8zNw" executionInfo={"status": "ok", "timestamp": 1617830589273, "user_tz": -180, "elapsed": 2362, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="ae0a2ab9-92d2-4741-bba7-7b48313b2722"
text ="""
he patient was initially admitted for starvation ketosis , as she reported poor oral intake for three days prior to admission . 
However , serum chemistry obtained six hours after presentation revealed her glucose was 186 mg/dL , the anion gap was still elevated at 21 , serum bicarbonate was 16 mmol/L , triglyceride level peaked at 2050 mg/dL , and lipase was 52 U/L . The β-hydroxybutyrate level was obtained and found to be elevated at 5.29 mmol/L - the original sample was centrifuged and the chylomicron layer removed prior to analysis due to interference from turbidity caused by lipemia again . The patient was treated with an insulin drip for euDKA and HTG with a reduction in the anion gap to 13 and triglycerides to 1400 mg/dL , within 24 hours . Her euDKA was thought to be precipitated by her respiratory tract infection in the setting of SGLT2 inhibitor use . The patient was seen by the endocrinology service and she was discharged on 40 units of insulin glargine at night , 12 units of insulin lispro with meals , and metformin 1000 mg two times a day . It was determined that all SGLT2 inhibitors should be discontinued indefinitely . 
"""

annotations = pipeline.fullAnnotate(text)

rel_df = get_relations_df (annotations, 'clinical_relations')

rel_df[rel_df.confidence>0.9]


# + [markdown] id="ljp4EmCxaDNd"
# ## **2.   explain_clinical_doc_era** 
#
# > a pipeline with `ner_clinical_events`, `assertion_dl` and `re_temporal_events_clinical`. It will extract clinical entities, assign assertion status and find temporal relationships between clinical entities.
#
#

# + colab={"base_uri": "https://localhost:8080/"} id="BMWEfu1QuXY5" executionInfo={"status": "ok", "timestamp": 1617830690474, "user_tz": -180, "elapsed": 87788, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="8b3e60d3-b3b1-43ed-b184-055f0d613bd5"
era_pipeline = PretrainedPipeline('explain_clinical_doc_era', 'en', 'clinical/models')

# + colab={"base_uri": "https://localhost:8080/"} id="xWhFRqvpvIOl" executionInfo={"status": "ok", "timestamp": 1617830720851, "user_tz": -180, "elapsed": 912, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="adb55807-d576-48cb-863b-c9b3004f9e19"
era_pipeline.model.stages

# + id="O9cTLFNUaQNU"
text ="""She is admitted to The John Hopkins Hospital 2 days ago with a history of gestational diabetes mellitus diagnosed. She denied pain and any headache.
She was seen by the endocrinology service and she was discharged on 03/02/2018 on 40 units of insulin glargine, 
12 units of insulin lispro, and metformin 1000 mg two times a day. She had close follow-up with endocrinology post discharge. 
"""

result = era_pipeline.fullAnnotate(text)[0]


# + colab={"base_uri": "https://localhost:8080/"} id="1igwWvsgu7z6" executionInfo={"status": "ok", "timestamp": 1617831121605, "user_tz": -180, "elapsed": 752, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="8de6f206-16f7-4f8d-c2a2-69ac864db605"
result.keys()

# + colab={"base_uri": "https://localhost:8080/", "height": 638} id="6rejwSLjyW8S" executionInfo={"status": "ok", "timestamp": 1617831273299, "user_tz": -180, "elapsed": 603, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="22243af6-a6c5-421a-a094-8fffe88b8155"
import pandas as pd

chunks=[]
entities=[]
begins=[]
ends=[]

for n in result['clinical_ner_chunks']:
    
    chunks.append(n.result)
    begins.append(n.begin)
    ends.append(n.end)
    entities.append(n.metadata['entity']) 
        
df = pd.DataFrame({'chunks':chunks, 'begin':begins, 'end':ends, 'entities':entities})

df

# + colab={"base_uri": "https://localhost:8080/", "height": 545} id="2pKbjUxEv9z3" executionInfo={"status": "ok", "timestamp": 1617831289854, "user_tz": -180, "elapsed": 908, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="50662d67-df67-438e-d310-463a578c07f3"
chunks=[]
entities=[]
status=[]

for n,m in zip(result['clinical_ner_chunks'],result['assertion']):
    
    chunks.append(n.result)
    entities.append(n.metadata['entity']) 
    status.append(m.result)
        
df = pd.DataFrame({'chunks':chunks, 'entities':entities, 'assertion':status})

df

# + colab={"base_uri": "https://localhost:8080/", "height": 700} id="FqN66c0Ou59s" executionInfo={"status": "ok", "timestamp": 1617831311091, "user_tz": -180, "elapsed": 1503, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="e95849ce-9d9f-40d9-ab9f-d9752709a14c"
annotations = era_pipeline.fullAnnotate(text)

rel_df = get_relations_df (annotations, 'clinical_relations')

rel_df


# + id="gqaVtu8xv3kT" colab={"base_uri": "https://localhost:8080/"} executionInfo={"status": "ok", "timestamp": 1617831405696, "user_tz": -180, "elapsed": 1294, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="18e0e194-d23f-4521-ab80-78bb0144242f"
annotations[0]['clinical_relations']

# + [markdown] id="TFBWJmXlMue8"
# ## 3.explain_clinical_doc_ade 
#
# A pipeline for `Adverse Drug Events (ADE)` with `ner_ade_healthcare`, and `classifierdl_ade_biobert`. It will extract `ADE` and `DRUG` clinical entities, and then assign ADE status to a text(`Negative` means ADE, `Neutral` means not related to ADE).

# + colab={"base_uri": "https://localhost:8080/"} id="oYaFInzXM0Gw" executionInfo={"status": "ok", "timestamp": 1617831478438, "user_tz": -180, "elapsed": 57991, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="aa224f11-2a16-4a62-efda-bc6ac7563d33"
ade_pipeline = PretrainedPipeline('explain_clinical_doc_ade', 'en', 'clinical/models')

# + colab={"base_uri": "https://localhost:8080/"} id="76WiwihdPf9T" executionInfo={"status": "ok", "timestamp": 1617831489711, "user_tz": -180, "elapsed": 3224, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="f860c0dc-ef61-4761-dfb4-bb1344be4b8c"
ade_pipeline.fullAnnotate("I feel a bit drowsy & have a little blurred vision, so far no gastric problems.")[0]['class'][0].metadata

# + colab={"base_uri": "https://localhost:8080/", "height": 292} id="9xHqsx4aOQQY" executionInfo={"status": "ok", "timestamp": 1617831518222, "user_tz": -180, "elapsed": 2359, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="8d279afa-bf9f-4dbb-a298-de4e6d09a522"
text = "I feel a bit drowsy & have a little blurred vision, so far no gastric problems. I have been on Arthrotec 50 for over 10 years on and off, only taking it when I needed it. Due to my arthritis getting progressively worse, to the point where I am in tears with the agony, gp's started me on 75 twice a day and I have to take it every day for the next month to see how I get on, here goes. So far its been very good, pains almost gone, but I feel a bit weird, didn't have that when on 50."

import pandas as pd

chunks = []
entities = []
begin =[]
end = []

print ('sentence:', text)
print()

result = ade_pipeline.fullAnnotate(text)

print ('ADE status:', result[0]['class'][0].result)

print ('prediction probability>> True : ', result[0]['class'][0].metadata['True'], \
        'False: ', result[0]['class'][0].metadata['False'])

for n in result[0]['ner_chunk']:

    begin.append(n.begin)
    end.append(n.end)
    chunks.append(n.result)
    entities.append(n.metadata['entity']) 

df = pd.DataFrame({'chunks':chunks, 'entities':entities,
                'begin': begin, 'end': end})

df


# + [markdown] id="u3ZaUbUkiF77"
# #### with AssertionDL

# + colab={"base_uri": "https://localhost:8080/", "height": 210} id="P9UcxSIBg9C-" executionInfo={"status": "ok", "timestamp": 1617831584382, "user_tz": -180, "elapsed": 2124, "user": {"displayName": "muhammet \u015fanta\u015f", "photoUrl": "", "userId": "01037434825541536598"}} outputId="8603b23a-548b-44a0-9f66-5afafb224500"
import pandas as pd

text = 'I was on Voltaren for about 4 years and all of the sudden had a minor stroke and had blood clots that traveled to my eye. I had every test in the book done at the hospital, and they couldnt find anything. I was completley healthy! I am thinking it was from the voltaren. I have been off of the drug for 8 months now, and have never felt better. I started eating healthy and working out and that has help alot. I can now sleep all thru the night. I wont take this again. If I have the back pain, I will pop a tylonol instead.'

print (text)

light_result = ade_pipeline.fullAnnotate(text)[0]

chunks=[]
entities=[]
status=[]

for n,m in zip(light_result['ass_ner_chunk'],light_result['assertion']):
    
    chunks.append(n.result)
    entities.append(n.metadata['entity']) 
    status.append(m.result)
        
df = pd.DataFrame({'chunks':chunks, 'entities':entities, 'assertion':status})

df

# + [markdown] id="WJUJhRsDN0P4"
# ## 4.ICD10CM to Snomed Code
#
# This pretrained pipeline maps ICD10CM codes to SNOMED codes without using any text data. You’ll just feed a comma or white space delimited ICD10CM codes and it will return the corresponding SNOMED codes as a list. For the time being, it supports 132K Snomed codes and will be augmented & enriched in the next releases.

# + id="URlYyaQnPA1E"
icd_snomed_pipeline = PretrainedPipeline("icd10cm_snomed_mapping", "en", "clinical/models")

# + colab={"base_uri": "https://localhost:8080/"} id="jhqXGDTSTaEW" outputId="6af91f63-79c7-4965-8b5b-bedd09a6c73d"
icd_snomed_pipeline.model.stages

# + colab={"base_uri": "https://localhost:8080/"} id="pExgipi5O7vY" outputId="30105360-6471-418e-9ee4-fa39b9394017"
icd_snomed_pipeline.annotate('M89.50 I288 H16269')

# + [markdown] id="hrgvx5lTXwEt"
# **ICD10CM ---------- Details** 
#
# M89.50 -----------------  Osteolysis, unspecified site  
# I288 ----------------------  Other diseases of pulmonary vessels  
# H16269 ----------------  Vernal keratoconjunctivitis, with limbar and corneal involvement, unspecified eye  
#
# **SNOMED ----------- Details**  
#
# 733187009 ---------- Osteolysis following surgical procedure on skeletal system  
# 449433008 ---------- Diffuse stenosis of left pulmonary artery  
# 51264003 ------------ Limbal AND/OR corneal involvement in vernal conjunctivitis

# + [markdown] id="kG1whe5KPVH5"
# ## 5.Snomed to ICD10CM Code
# This pretrained pipeline maps SNOMED codes to ICD10CM codes without using any text data. You'll just feed a comma or white space delimited SNOMED codes and it will return the corresponding candidate ICD10CM codes as a list (multiple ICD10 codes for each Snomed code). For the time being, it supports 132K Snomed codes and 30K ICD10 codes and will be augmented & enriched in the next releases.

# + id="Gk5fU0J0Rzw0"
snomed_icd_pipeline = PretrainedPipeline("snomed_icd10cm_mapping","en","clinical/models")

# + colab={"base_uri": "https://localhost:8080/"} id="m85pQn8lSJ8l" outputId="b2793aae-8955-4b72-a272-c2e704121241"
snomed_icd_pipeline.model.stages

# + colab={"base_uri": "https://localhost:8080/"} id="AivemfSaRdjD" outputId="4d1206c5-9774-44ba-84b5-662a247b67d2"
snomed_icd_pipeline.annotate('733187009 449433008 51264003')

# + [markdown] id="W618yxZYbs5U"
#
# **SNOMED ----------- Details**  
#
# 733187009 ---------- Osteolysis following surgical procedure on skeletal system  
# 449433008 ---------- Diffuse stenosis of left pulmonary artery  
# 51264003 ------------ Limbal AND/OR corneal involvement in vernal conjunctivitis  
#
#
# **ICDM10CM -------- Details**  
#
# M89.59 ------------------	Osteolysis, multiple sites  
# M89.50 ------------------ Osteolysis, unspecified site  
# M96.89 ------------------ Other intraoperative and postprocedural complications and disorders of the musculoskeletal system  
#
# Q25.6 ---------------------	Stenosis of pulmonary artery    
# I28.8 ---------------------- Other diseases of pulmonary vessels  
#
# H10.45 ------------------- Other chronic allergic conjunctivitis  
# H10.1 --------------------- Acute atopic conjunctivitis  
# H16.269 ----------------- Vernal keratoconjunctivitis, with limbar and corneal involvement, unspecified eye
#   

StarcoderdataJupyterScriptsDedupFiltered