{"id":1333,"date":"2021-12-09T06:10:14","date_gmt":"2021-12-09T06:10:14","guid":{"rendered":"https:\/\/salarydistribution.com\/machine-learning\/2021\/12\/09\/clinical-text-mining-using-the-amazon-comprehend-medical-new-snomed-ct-api\/"},"modified":"2021-12-09T06:10:14","modified_gmt":"2021-12-09T06:10:14","slug":"clinical-text-mining-using-the-amazon-comprehend-medical-new-snomed-ct-api","status":"publish","type":"post","link":"https:\/\/salarydistribution.com\/machine-learning\/2021\/12\/09\/clinical-text-mining-using-the-amazon-comprehend-medical-new-snomed-ct-api\/","title":{"rendered":"Clinical text mining using the Amazon Comprehend Medical new SNOMED CT API"},"content":{"rendered":"<div id=\"\">\n<p>Mining medical concepts from written clinical text, such as patient encounters, plays an important role in clinical analytics and decision-making applications, such as population analytics for providers, pre-authorization for payers, and adverse-event detection for pharma companies. Medical concepts contain medical conditions, medications, procedures, and other clinical events. Extracting medical concepts is a complicated process due to the specialist knowledge required and the broad use of synonyms in the medical field. Furthermore, to make detected concepts useful for large-scale analytics and decision-making applications, they have to be codified. This is a process where a specialist looks up matching codes from a medical ontology, often containing tens to hundreds of thousands of concepts.<\/p>\n<p>To solve these problems, <a href=\"https:\/\/aws.amazon.com\/comprehend\/medical\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Comprehend Medical<\/a> provides a fast and accurate way to automatically extract medical concepts from the written text found in clinical documents. You can now also use a new feature to automatically standardize and link detected concepts to the SNOMED CT (Systematized Nomenclature of Medicine\u2014Clinical Terms) ontology. SNOMED CT provides a comprehensive clinical healthcare terminology and accompanying clinical hierarchy, and is used to encode medical conditions, procedures, and other medical concepts to enable big data applications.<\/p>\n<p>This post details how to use the new SNOMED CT API to link SNOMED CT codes to medical concepts (or entities) in natural written text that can then be used to accelerate research and clinical application building. After reading this post, you will be able to detect and extract medical terms from unstructured clinical text, map them to the SNOMED CT ontology (US edition), retrieve and manipulate information from a clinical database, including electronic health record (EHR) systems, and map SNOMED CT concepts to other ontologies using the <a href=\"https:\/\/www.ohdsi.org\/data-standardization\/the-common-data-model\/\" target=\"_blank\" rel=\"noopener noreferrer\">Observational Medical Outcomes Partnership (OMOP) Common Data Model (CDM<\/a>) if your EHR system uses an ontology other than SNOMED CT.<\/p>\n<h2>Solution overview<\/h2>\n<p>Amazon Comprehend Medical is a HIPAA-eligible natural language processing (NLP) service that uses machine learning (ML) to extract clinical data from unstructured medical text\u2014no ML experience required\u2014and automatically map them to SNOMED CT, ICD10, or RxNorm ontologies with a simple API call. You can then add the ontology codes to your EHR database to augment patient data or link to other ontologies as desired through OMOP CDM. For this post, we demonstrate the solution workflow as shown in the following diagram with code based on the example sentence \u201cPatient X was diagnosed with insomnia.\u201d<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-31626\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/12\/08\/1-6269-Flowchart.jpg\" alt=\"\" width=\"800\" height=\"128\"><\/p>\n<p>To use clinical concept codes based on a text input, we detect and extract clinical terms, connect to the clinical data base, transform SNOMED code to OMOP CDM code, and use them within our records.<\/p>\n<p>For this post, we use the <a href=\"https:\/\/www.ohdsi.org\/data-standardization\/the-common-data-model\/\" target=\"_blank\" rel=\"noopener noreferrer\">OMOP CDM<\/a> as a database schema as an example. Historically, healthcare institutions in different regions and countries use their own terminologies and classifications for their own purposes, which prevents the interoperability of the systems. While SNOMED CT standardizes medical concepts with a clinical hierarchy, the OMOP CDM provides a standardization mechanism to move from one ontology to another, with an accompanying data model. The OMOP CDM standardizes the format and content of observational data so that standardized applications, tools and methods can be applied across different datasets. In addition, the OMOP CDM makes it easier to convert codes from one vocabulary to another by having maps between medical concepts in different hierarchical ontologies and vocabularies. The ontologies hierarchy is set such that descendants are more specific than ascendants. For example, non-small cell lung cancer is a descendent of malignant neoplastic disease. This allows querying and retrieving concepts and all their hierarchical descendants, and also enables interoperability between ontologies.<\/p>\n<p>We demonstrate implementing this solution with the following steps:<\/p>\n<ol>\n<li>Extract concepts with Amazon Comprehend Medical SNOMED CT and link them to the SNOMED CT (US edition) ontology.<\/li>\n<li>Connecting to the OMOP CDM.<\/li>\n<li>Map the SNOMED CT code to OMOP CDM concept IDs.<\/li>\n<li>Use the structured information to perform the following actions:\n<ol type=\"a\">\n<li>Retrieve the number of patients with the disease.<\/li>\n<li>Traverse the ontology.<\/li>\n<li>Map to other ontologies.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>Prerequisites<\/h2>\n<p>Before you get started, make sure you have the following:<\/p>\n<ul>\n<li>Access to an AWS account.<\/li>\n<li>Permissions to create an <a href=\"http:\/\/aws.amazon.com\/cloudformation\" target=\"_blank\" rel=\"noopener noreferrer\">AWS CloudFormation<\/a>.<\/li>\n<li>Permissions to call Amazon Comprehend Medical from <a href=\"https:\/\/aws.amazon.com\/sagemaker\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon SageMaker<\/a>.<\/li>\n<li>Permissions to query <a href=\"http:\/\/aws.amazon.com\/redshift\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Redshift<\/a> from SageMaker.<\/li>\n<li>The <a href=\"https:\/\/www.snomed.org\/snomed-ct\/get-snomed\" target=\"_blank\" rel=\"noopener noreferrer\">SNOMED CT license<\/a>. SNOMED International is a strong member-owned and driven organization with free use of SNOMED CT within the member\u2019s territory. Members manage the release, distribution, and sub-licensing of SNOMED CT and other products of the association within their territory.<\/li>\n<\/ul>\n<p>This post assumes that you have an OMOP CDM database set up in Amazon Redshift. See <a href=\"https:\/\/aws.amazon.com\/blogs\/big-data\/creating-data-science-environments-on-aws-for-health-analysis-using-ohdsi\/\" target=\"_blank\" rel=\"noopener noreferrer\">Create data science environments on AWS for health analysis using OHDSI<\/a> to set up a sample OMOP CDM in your AWS account using CloudFormation templates.<\/p>\n<h2>Extract concepts with Amazon Comprehend Medical SNOMED CT<\/h2>\n<p>You can extract SNOMED CT codes using Amazon Comprehend Medical with two lines of code. Assume you have a document, paragraph, or sentence:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">clinical_note = \"Patient X was diagnosed with insomnia.\"<\/code><\/pre>\n<\/p><\/div>\n<p>First, we instantiate the Amazon Comprehend Medical client in <a href=\"https:\/\/boto3.amazonaws.com\/v1\/documentation\/api\/latest\/guide\/quickstart.html\" target=\"_blank\" rel=\"noopener noreferrer\">boto3<\/a>. Then, we simply call Amazon Comprehend Medical\u2019s SNOMED CT API:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">import boto3\ncm_client = boto3.client(\"comprehendmedical\")\nresponse = cm_client.infer-snomedct(Text=clinical_note)\n<\/code><\/pre>\n<\/p><\/div>\n<p>Done! In our example, the response is as follows:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-json\">{'Characters': {'OriginalTextCharacters': 38},\n 'Entities': [{'Attributes': [],\n               'BeginOffset': 29,\n               'Category': 'MEDICAL_CONDITION',\n               'EndOffset': 37,\n               'Id': 0,\n               'SNOMEDCTConcepts': [{'Code': '193462001',\n                                     'Description': 'Insomnia (disorder)',\n                                     'Score': 0.7997841238975525},\n                                    {'Code': '191997003',\n                                     'Description': 'Persistent insomnia '\n                                                    '(disorder)',\n                                     'Score': 0.6464713215827942},\n                                    {'Code': '762348004',\n                                     'Description': 'Acute insomnia (disorder)',\n                                     'Score': 0.6253700256347656},\n                                    {'Code': '59050008',\n                                     'Description': 'Initial insomnia '\n                                                    '(disorder)',\n                                     'Score': 0.6112624406814575},\n                                    {'Code': '24121004',\n                                     'Description': 'Insomnia disorder related '\n                                                    'to another mental '\n                                                    'disorder (disorder)',\n                                     'Score': 0.6014388203620911}],\n               'Score': 0.9989109039306641,\n               'Text': 'insomnia',\n               'Traits': [{'Name': 'DIAGNOSIS', 'Score': 0.7624053359031677}],\n               'Type': 'DX_NAME'}],\n 'ModelVersion': '0.0.1',\n 'ResponseMetadata': {'HTTPHeaders': {'content-length': '873',\n                                      'content-type': 'application\/x-amz-json-1.1',\n                                      'date': 'Mon, 20 Sep 2021 18:32:04 GMT',\n                                      'x-amzn-requestid': 'e9188a79-3884-4d3e-b73e-4f63ed831b0b'},\n                      'HTTPStatusCode': 200,\n                      'RequestId': 'e9188a79-3884-4d3e-b73e-4f63ed831b0b',\n                      'RetryAttempts': 0},\n 'SNOMEDCTDetails': {'Edition': 'US',\n                     'Language': 'en',\n                     'VersionDate': '20200901'}}\n<\/code><\/pre>\n<\/p><\/div>\n<p>The response contains the following:<\/p>\n<ul>\n<li><strong>Characters<\/strong> \u2013 Total number of characters. In this case, we have 38 characters.<\/li>\n<li><strong>Entities<\/strong> \u2013 List of detected medical concepts, or entities, from Amazon Comprehend Medical. The main elements in each entity are:\n<ul>\n<li><strong>Text<\/strong> \u2013 Original text from the input data.<\/li>\n<li><strong>BeginOffset and EndOffset<\/strong> \u2013The beginning and ending location of the text in the input note, respectively.<\/li>\n<li><strong>Category<\/strong> \u2013 Category of the detected entity. For example, <code>MEDICAL_CONDITION<\/code> for medical condition.<\/li>\n<li><strong>SNOMEDCTConcepts<\/strong> \u2013 Top five predicted SNOMED CT concept codes with the model\u2019s confidence scores (in descending order). Each linked concept code has the following:\n<ul>\n<li><strong>Code<\/strong> \u2013 SNOMED CT concept code.<\/li>\n<li><strong>Description<\/strong> \u2013 SNOMED CT concept description.<\/li>\n<li><strong>Score<\/strong> \u2013 Confidence score of the linked SNOMED CT concept.<\/li>\n<\/ul>\n<\/li>\n<li><strong>ModelVersion<\/strong> \u2013 Version of the model used for the inference.<\/li>\n<li><strong>ResponseMetadata<\/strong> \u2013 API call metadata.<\/li>\n<li><strong>SNOMEDCTDetails<\/strong> \u2013 Edition, language, and date of the SNOMED CT version used.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>For more information, refer to the <a href=\"https:\/\/docs.aws.amazon.com\/comprehend-medical\/latest\/dev\/ontology-snomed-ct.html\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Comprehend Medical Developer Guide<\/a>. By default, the API links detected entities to the SNOMED CT US edition. To request support for your edition, for example the UK edition, contact us via AWS Support or the <a href=\"https:\/\/forums.aws.amazon.com\/forum.jspa?forumID=319\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Comprehend Medical forum<\/a>.<\/p>\n<p>In our example, Amazon Comprehend Medical identifies \u201cinsomnia\u201d as a clinical term and provides five ordered SNOMED CT concepts and code that we might be referring to in the sentence. In this example, Amazon Comprehend Medical correctly identifies the clinical term as the most likely option. Therefore, the next step is to extract the response. See the following code:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">#Get top predicted SNOMED CT Concept\npred_snomed = response['Entities'][0]['SNOMEDCTConcepts'][0]\n<\/code><\/pre>\n<\/p><\/div>\n<p>The content of <code>pred_snomed<\/code> is as follows, with its predicted SNOMED concept code, concept description, and prediction score (probability):<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-json\">{\n 'Description': 'Insomnia (disorder)',\n 'Code': '193462001',\n 'Score': 0.803254246711731\n}\n<\/code><\/pre>\n<\/p><\/div>\n<p>We have identified clinical terms in our text and linked them to SNOMED CT concepts. We can now use SNOMED CT\u2019s hierarchical structure and relations to other ontologies to accelerate clinical analytics and decision-making application development.<\/p>\n<p>Before we access the database, let\u2019s define some utility functions that are helpful in our operations. First, we must import the necessary Python packages:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">import pandas\nimport psycopg2\n<\/code><\/pre>\n<\/p><\/div>\n<p>The following code is a function to connect to the Amazon Redshift database:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-python\">def connect_to_db(redshift_parameters, user, password):\n    \"\"\"Connect to database and returns connection\n    Args:\n        redshift_parameters (dict): Redshift connection parameters.\n        user (str): Redshift user required to connect. \n        password (str): Password associated to the user\n    Returns:\n        Connection: boto3 redshift connection \n    \"\"\"\n\n    try:\n        conn = psycopg2.connect(\n            host=redshift_parameters[\"url\"],\n            port=redshift_parameters[\"port\"],\n            user=user,\n            password=password,\n            database=redshift_parameters[\"database\"],\n        )\n\n        return conn\n\n    except psycopg2.Error:\n        raise ValueError(\"Failed to open database connection.\")\n<\/code><\/pre>\n<\/p><\/div>\n<p>The following code is a function to run a given query on the Amazon Redshift database:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-python\">def execute_query(cursor, query, limit=None):\n    \"\"\"Execute query\n    Args:\n        cursor (boto3 cursor): boto3 object pointing and with established connection to Redshift.\n        query (str): SQL query.\n        limit (int): Limit of rows returned by the data frame. Default to 'None' for no limit\n    Returns:\n        pd.DataFrame: Data Frame with the query results.\n    \"\"\"\n    try:\n        cursor.execute(query)\n    except:\n        return None\n\n    columns = [c.name for c in cursor.description]\n    results = cursor.fetchall()\n    if limit:\n        results = results[:limit]\n\n    out = pd.DataFrame(results, columns=columns)\n\n    return out\n<\/code><\/pre>\n<\/p><\/div>\n<p>In the next sections, we connect to the database and run our queries.<\/p>\n<h2>Connect to the OMOP CDM<\/h2>\n<p>EHRs are often stored in databases using a specific ontology. In our case, we use the OMOP CDM, which contains a large number of ontologies (SNOMED, ICD10, RxNorm, and more), but you can extend the solution to other data models by modifying the queries. The first step is to connect to Amazon Redshift where the EHR data is stored.<\/p>\n<p>Let\u2019s define the variables used to connect the database. You must substitute the placeholder values in the following code within with your actual values based on your Amazon Redshift database:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-code\">#Connect to Amazon Redshift Database\nREDSHIFT_PARAMS = {\n                    \"url\": \"<em><span>&lt;database-url&gt;<\/span><\/em>\", \n                    \"port\": \"<em><span>&lt;database-port&gt;<\/span><\/em>\",\n                    \"database\": \"<em><span>&lt;database-name&gt;<\/span><\/em>\",\n                  }\nREDSHIFT_USER = \"<em><span>&lt;user-name&gt;<\/span><\/em>\"\nREDSHIFT_PASSWORD = \"<em><span>&lt;user-password&gt;<\/span><\/em>\"\n\nconn = connect_to_db(REDSHIFT_PARAMS, REDSHIFT_USER, REDSHIFT_PASSWORD)\ncursor = conn.cursor()\n<\/code><\/pre>\n<\/p><\/div>\n<h2>Map the SNOMED CT code to OMOP CDM concept IDs<\/h2>\n<p>The OMOP CDM uses its own concept IDs as data model identifiers across ontologies. Those differ from specific ontology codes such as SNOMED CT\u2019s codes, but you can retrieve them from SNOMED CT codes using pre-built OMOP CDM maps. To retrieve the <code>concept_id<\/code> of SNOMED CT code <code>193462001<\/code>, we use the following query:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">query1 = f\"\nSELECT DISTINCT concept_id \nFROM cmsdesynpuf23m.concept \nWHERE vocabulary_id='SNOMED' AND concept_code='{pred_snomed['Code']}';\n\"\n\nout_df = execute_query(cursor, query1)\nconcept_id = out_df['concept_id'][0]\nprint(concept_id)\n<\/code><\/pre>\n<\/p><\/div>\n<p>The output OMOP CDM <code>concept_id<\/code> is <code>436962<\/code>. The concept ID uniquely identifies a given medical concept in the OMOP CDM database and is used as a primary key in the concept table. This enables linking of each code with patient information in other tables.<\/p>\n<h2>Use the structured information map from the SNOMED CT code to OMOP CDM concept ID<\/h2>\n<p>Now that we have OMOP\u2019s <code>concept_id<\/code>, we can run many queries from the database. When we find the particular concept, we can use it for different use cases. For example, we can use it to query population statistics with a given condition, traverse ontologies to bridge operability gaps, and extract the unique hierarchical structure of concepts to achieve the right queries. In this section, we walk you through a few examples.<\/p>\n<h3>Retrieve the number of patients with a disease<\/h3>\n<p>The first example is retrieving the total number of patients with the <code>insomnia<\/code> condition that we linked to its appropriate ontology concept using Amazon Comprehend Medical. The following code formulates and runs the corresponding SQL query:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">query2 = f\"\nSELECT COUNT(DISTINCT person_id) \nFROM cmsdesynpuf23m.condition_occurrence \nWHERE condition_concept_id='{concept_id}';\n\"\nout_df = execute_query(cursor, query2)\nprint(out_df)\n<\/code><\/pre>\n<\/p><\/div>\n<p>In our sample records described in the prerequisites section, the total number of patients in the database that have been diagnosed with insomnia are 26,528.<\/p>\n<h3>Traverse the ontology<\/h3>\n<p>One of the advantages of using SNOMED CT is that we can exploit its hierarchical taxonomy. Let\u2019s illustrate how via some examples.<\/p>\n<h4>Ancestors: Going up the hierarchy<\/h4>\n<p>First, let\u2019s find the immediate ancestors and descendants of the concept <code>insomnia<\/code>. We use <code>concept_ancestor<\/code> and <code>concept<\/code> tables to get the parent (ancestor) and children (descendants) of the given concept code. The following code is the SQL statement to output the parent information:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">query3 = f\"\nSELECT DISTINCT concept_code, concept_name \nFROM cmsdesynpuf23m.concept \nWHERE concept_id IN (SELECT ancestor_concept_id \nFROM cmsdesynpuf23m.concept_ancestor \nWHERE descendant_concept_id='{concept_id}' AND max_levels_of_separation=1);\n\"\nout_df = execute_query(cursor, query3)\nprint(out_df)\n<\/code><\/pre>\n<\/p><\/div>\n<p>In the preceding example, we used <code>max_levels_of_separation=1<\/code> to limit concept codes that are immediate ancestors. You can increase the number to get more in the hierarchy. The following table summarizes our results.<\/p>\n<table border=\"1px\" cellpadding=\"10px\">\n<tbody>\n<tr>\n<td width=\"106\"><span><strong>concept_code<\/strong><\/span><\/td>\n<td width=\"284\"><span><strong>concept_name<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td width=\"106\">44186003<\/td>\n<td width=\"284\">Dyssomnia<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">194437008<\/td>\n<td width=\"284\">Disorders of initiating and maintaining sleep<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>SNOMED CT offers a <a href=\"https:\/\/confluence.ihtsdotools.org\/display\/DOCGLOSS\/polyhierarchy#:~:text=The%20subtype%20relationships%20of%20SNOMED,to%20or%20from%20other%20nodes.&amp;text=This%20type%20of%20hierarchy%20is%20therefore%20known%20as%20a%20directed%20acyclic%20graph.\" target=\"_blank\" rel=\"noopener noreferrer\">polyhierarchical classification<\/a>, which means a concept can have more than one parent. This hierarchy is also called a directed acyclic graph (DAG).<\/p>\n<h4>Descendants: Going down the hierarchy<\/h4>\n<p>We can use a similar logic to retrieve the children of the code <code>insomnia<\/code>:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">query4 = f\"SELECT DISTINCT concept_code, concept_name \nFROM cmsdesynpuf23m.concept \nWHERE concept_id IN (SELECT descendant_concept_id \nFROM cmsdesynpuf23m.concept_ancestor \nWHERE ancestor_concept_id='{concept_id}' AND max_levels_of_separation=1);\n\"\nout_df = execute_query(cursor, query4)\nprint(out_df)\n<\/code><\/pre>\n<\/p><\/div>\n<p>As a result, we get 26 descendant codes; the following table shows the first 10 rows.<\/p>\n<table border=\"1px\" cellpadding=\"10px\">\n<tbody>\n<tr>\n<td><span><strong>concept_code<\/strong><\/span><\/td>\n<td><span><strong>concept_name<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td width=\"144\">24121004<\/td>\n<td width=\"370\">Insomnia disorder related to another mental disorder<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">191997003<\/td>\n<td width=\"370\">Persistent insomnia<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">198437004<\/td>\n<td width=\"370\">Menopausal sleeplessness<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">88982005<\/td>\n<td width=\"370\">Rebound insomnia<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">90361000119105<\/td>\n<td width=\"370\">Behavioral insomnia of childhood<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">41975002<\/td>\n<td width=\"370\">Insomnia with sleep apnea<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">268652009<\/td>\n<td width=\"370\">Transient insomnia<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">81608000<\/td>\n<td width=\"370\">Insomnia disorder related to known organic factor<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">162204000<\/td>\n<td width=\"370\">Late insomnia<\/td>\n<\/tr>\n<tr>\n<td width=\"144\">248256006<\/td>\n<td width=\"370\">Not getting enough sleep<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We can then use these codes to query a broader set of patients (parent concept) or a more specific one (child concept).<\/p>\n<p>Finding the concept in the appropriate hierarchy level is important, because if not accounted for appropriately, you might get wrong statistical answers from your queries. For example, in the preceding use case, let\u2019s say that you want to find the number of patients with insomnia that is only related with not getting enough sleep. Using the parent concept for the general insomnia gives you a different answer than when specifying the descendant concept code only related with not getting enough sleep.<\/p>\n<h3>Map to other ontologies<\/h3>\n<p>We can also map the SNOMED concept code to other ontologies such as ICD10CM for conditions and RxNorm for medications. Because insomnia is condition, let\u2019s find the corresponding ICD10 concept codes for the given insomnia\u2019s SNOMED concept code. The following code is the SQL statement and function to find the ICD10 concept codes:<\/p>\n<div class=\"hide-language\">\n<pre class=\"unlimited-height-code\"><code class=\"lang-python\">query5 = f\"\nSELECT DISTINCT concept_code, concept_name, vocabulary_id \nFROM cmsdesynpuf23m.concept \nWHERE vocabulary_id='ICD10CM' AND \nconcept_id IN (SELECT concept_id_2 \nFROM cmsdesynpuf23m.concept_relationship \nWHERE concept_id_1='{concept_id}' AND relationship_id='Mapped from');\n\"\nout_df = execute_query(cursor, query5)\nprint(out_df)\n<\/code><\/pre>\n<\/p><\/div>\n<p>The following table lists the corresponding ICD10 concept codes with their descriptions.<\/p>\n<table border=\"1px\" cellpadding=\"10px\">\n<tbody>\n<tr>\n<td><span><strong>concept_code<\/strong><\/span><\/td>\n<td><span><strong>concept_name<\/strong><\/span><\/td>\n<td><span><strong>vocabulary_id<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td width=\"143\">G47.0<\/td>\n<td width=\"225\">Insomnia<\/td>\n<td width=\"194\">ICD10CM<\/td>\n<\/tr>\n<tr>\n<td width=\"143\">G47.00<\/td>\n<td width=\"225\">Insomnia, unspecified<\/td>\n<td width=\"194\">ICD10CM<\/td>\n<\/tr>\n<tr>\n<td width=\"143\">G47.09<\/td>\n<td width=\"225\">Other insomnia<\/td>\n<td width=\"194\">ICD10CM<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>When we\u2019re done running SQL queries, let\u2019s close the connection to the database:<\/p>\n<h2>Conclusion<\/h2>\n<p>Now that you have reviewed this example, you\u2019re ready to apply Amazon Comprehend Medical on your clinical text to extract and link SNOMED CT concepts. We also provided concrete examples of how to use this information with your medical records using an OMOP CDM database to run SQL queries and get patient information related with the medical concepts. Finally, we also showed how to extract the different hierarchies of medical concepts and convert SNOMED CT concepts to other standardized vocabularies such as ICD10CM.<\/p>\n<p>The <a href=\"https:\/\/aws.amazon.com\/ml-solutions-lab\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon ML Solutions Lab<\/a> pairs your team with ML experts to help you identify and implement your organization\u2019s highest value ML opportunities. If you\u2019d like help accelerating your use of ML in your products and processes, please contact the Amazon ML Solutions Lab.<\/p>\n<hr>\n<h3>About the Author<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-19373 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2020\/12\/03\/Tesfagabir-Meharizghi.jpg\" alt=\"\" width=\"100\" height=\"133\"><b>Tesfagabir Meharizghi\u00a0<\/b>is a Data Scientist at the\u00a0<a href=\"https:\/\/aws.amazon.com\/ml-solutions-lab\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon ML Solutions Lab<\/a> where he helps customers across different industries accelerate their use of machine learning and AWS Cloud services to solve their business challenges.<\/p>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-22624 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/03\/11\/Miguel-Romero-Calvo.jpg\" alt=\"\" width=\"100\" height=\"133\"><\/strong><strong>Miguel Romero Calvo<\/strong> is an Applied Scientist at the\u00a0<a class=\"c-link\" href=\"https:\/\/aws.amazon.com\/ml-solutions-lab\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-stringify-link=\"https:\/\/aws.amazon.com\/ml-solutions-lab\/\" data-sk=\"tooltip_parent\" data-remove-tab-index=\"true\">Amazon ML Solutions Lab<\/a> where he partners with AWS internal teams and strategic customers to accelerate their business through ML and cloud adoption.<\/p>\n<p><strong><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/11\/03\/Lin-Lee-Cheong.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-30386 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2021\/11\/03\/Lin-Lee-Cheong.jpg\" alt=\"\" width=\"100\" height=\"125\"><\/a>Lin Lee Cheong\u00a0<\/strong>is a Senior Scientist and Manager with the Amazon ML Solutions Lab team at Amazon Web Services. She works with strategic AWS customers to explore and apply artificial intelligence and machine learning to discover new insights and solve complex problems.<\/p>\n<p>       <!-- '\"` -->\n      <\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/aws.amazon.com\/blogs\/machine-learning\/clinical-text-mining-using-the-amazon-comprehend-medical-new-snomed-ct-api\/<\/p>\n","protected":false},"author":0,"featured_media":1334,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1333"}],"collection":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/comments?post=1333"}],"version-history":[{"count":0,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media\/1334"}],"wp:attachment":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/categories?post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/tags?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}