You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
import requests
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass
|
|
|
|
BASE_URL = "http://LOCALHOST:4000/REST"
|
|
FORMAT = '.json'
|
|
|
|
@dataclass
|
|
class RxCui():
|
|
id: str
|
|
|
|
def get_atc_class(self):
|
|
pass
|
|
def get_brandnames(self):
|
|
pass
|
|
|
|
|
|
|
|
|
|
def FindRxcuiByString(name: str, **kwargs) -> RxCui:
|
|
'''
|
|
Find a RxCUI by string based on a string
|
|
Defaults to searching RxNorm (i.e. drugs) using a best match option
|
|
'''
|
|
|
|
url = BASE_URL + "/rxcui" + FORMAT
|
|
query = {'allsrc':0, 'srclist':'RXNORM', 'search':2} | kwargs | {'name':name}
|
|
r = requests.get(url, params=query)
|
|
|
|
#extract RxCUIs
|
|
return [RxCui(x) for x in r.json()['idGroup']['rxnormId']]
|
|
|
|
|
|
def get_brands_from_ingredients(rxcui: RxCui):
|
|
'''
|
|
This is used to query for properties
|
|
'''
|
|
url = BASE_URL + "/brands" + FORMAT
|
|
r = requests.get(url, params={"ingredientids": rxcui.id})
|
|
j = r.json()
|
|
|
|
return [ AssociatedBrand(x,rxcui) for x in j['brandGroup']['conceptProperties']]
|
|
|
|
class AssociatedBrand():
|
|
def __init__(self,brand,ingredient: RxCui):
|
|
self.ingredient_rxcui = ingredient
|
|
self.brand_rxcui = RxCui(brand['rxcui'])
|
|
|
|
def get_rx_property(rxcui) |