removed (reasonably successful) attempt at using API. I favor migrading db tables
parent
97af862419
commit
f5788051f7
@ -1,56 +0,0 @@
|
|||||||
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'])
|
|
||||||
Loading…
Reference in New Issue