{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import requests\n", "import xml.etree.ElementTree\n", "import time\n", "import os\n", "import csv\n", "\n", "import pandas" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def get_rxnorm_ingredients(rxcui):\n", " \"\"\"\n", " Return a generator of RxNorm ingredients related to the provided RxNorm concept.\n", " Each ingredient is a (rxcui, name, umlscui) tuple. This function calls the\n", " RxNormAPI as documented here:\n", " http://rxnav.nlm.nih.gov/RxNormAPIs.html#uLink=RxNorm_REST_getAllRelatedInfo\n", " \"\"\"\n", " base_uri = 'http://rxnav.nlm.nih.gov/REST'\n", " url = '{base_uri}/rxcui/{rxcui}/allrelated'.format(base_uri = base_uri, rxcui = rxcui)\n", " response = requests.get(url)\n", " tree = xml.etree.ElementTree.fromstring(response.text)\n", " xml_ingredients = tree.findall(\"./allRelatedGroup/conceptGroup[tty='IN']/conceptProperties\")\n", " for xml_ingredient in xml_ingredients:\n", " assert xml_ingredient.findtext('tty') == 'IN'\n", " yield tuple(xml_ingredient.findtext(tag) for tag in ['rxcui', 'name', 'umlscui'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | medication | \n", "medication_definition_id | \n", "indications | \n", "rxcui | \n", "score | \n", "rank | \n", "nAtoms | \n", "name | \n", "synonym | \n", "tty | \n", "language | \n", "suppress | \n", "umlscui | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | \n", "4-Aminopyridine Powder | \n", "108483 | \n", "1 | \n", "897018 | \n", "67 | \n", "5 | \n", "12 | \n", "dalfampridine | \n", "NaN | \n", "IN | \n", "ENG | \n", "N | \n", "C0000477 | \n", "
2 | \n", "Abilify 1 MG/ML Oral Solution | \n", "123191 | \n", "2 | \n", "544412 | \n", "100 | \n", "1 | \n", "7 | \n", "aripiprazole 1 MG/ML Oral Solution [Abilify] | \n", "Abilify 1 MG/ML Oral Solution | \n", "SBD | \n", "ENG | \n", "N | \n", "C1586223 | \n", "
3 | \n", "Abilify 10 MG Oral Tablet | \n", "104197 | \n", "11 | \n", "352307 | \n", "100 | \n", "1 | \n", "16 | \n", "aripiprazole 10 MG Oral Tablet [Abilify] | \n", "Abilify 10 MG Oral Tablet | \n", "SBD | \n", "ENG | \n", "N | \n", "C1169930 | \n", "