diff --git a/RxMix/RxMixInABox.py b/RxMix/RxMixInABox.py new file mode 100644 index 0000000..7980097 --- /dev/null +++ b/RxMix/RxMixInABox.py @@ -0,0 +1,56 @@ +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_all_properties(rxcui_list: RxCui,*prop_category): + ''' + This is used to query for properties + ''' + for rxcui in rxcui_list: + url = BASE_URL + "/rxcui/" + rxcui.id + "/allProperties" + FORMAT + r = requests.get(url, params={"prop": prop_category}) + j = r.json() + yield j + +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']) \ No newline at end of file