commit
5a8da9d4e6
2 changed files with 104 additions and 0 deletions
@ -0,0 +1,51 @@ |
||||
import requests |
||||
import json |
||||
import tabula |
||||
import re |
||||
import streamlit as st |
||||
|
||||
def get_substance(x): |
||||
'Returns the substance of the drug.' |
||||
l = x.split('\r') |
||||
s = re.search(r'\w+', l[-1]).group() |
||||
return s.lower() |
||||
|
||||
# Get the pdf with prescriptions from the user. |
||||
pdf = st.file_uploader(label='Ladda upp din läkemedelslista', type='pdf') |
||||
|
||||
if pdf: |
||||
|
||||
# Extract table from prescription pdf. |
||||
area = [111, 20, 528, 822] |
||||
df = tabula.read_pdf(pdf, pages='all', area=area, lattice=True)[0] |
||||
df.columns = ['Uthämtat datum', 'Uthämtat läkemedel', 'Användning', 'Förskrivet av', 'Uthämtad mängd', 'Läkemedelsgrupp'] |
||||
df.dropna(axis=0, inplace=True) |
||||
df['substance'] = df['Uthämtat läkemedel'].apply(lambda x: get_substance(x)) |
||||
|
||||
# Make list of precripted substances. |
||||
substances = df.substance.tolist() |
||||
|
||||
substances_id_list = [] |
||||
for substance in substances: |
||||
# Get data for the substance. |
||||
data = requests.get(f'https://janusmed.se/api/search/input/{substance}').json() |
||||
data = data[0] # Only first is interesting(?) when searching on substances. |
||||
|
||||
# Add the substance ID to the list of substances. |
||||
substance_id = data['nslId'] #TODO Kan finnas flera!? |
||||
substances_id_list.append(substance_id) |
||||
|
||||
# Create URL for janusmed.se |
||||
substances_id_url_list = '&nslIds='.join(substances_id_list) |
||||
url = 'https://janusmed.se/interaktioner?nplIds=' + substances_id_url_list |
||||
|
||||
# Show text with URL to janusmed. |
||||
st.markdown(f''' |
||||
:grey[*Följ [den här länken]({url}) för att se om dina |
||||
läkemedel går bra ihop eller om det kan finnas något |
||||
du skulle kunna prata med din läkare om. Nedan kan du se en förhandsvisning.*] |
||||
''') |
||||
|
||||
# View janusmed.se in an iframe. |
||||
st.components.v1.iframe(url, height=600, scrolling=True) |
||||
|
||||
@ -0,0 +1,53 @@ |
||||
altair==4.2.2 |
||||
attrs==22.2.0 |
||||
backports.zoneinfo==0.2.1 |
||||
blinker==1.5 |
||||
cachetools==5.3.0 |
||||
certifi==2022.12.7 |
||||
charset-normalizer==3.1.0 |
||||
click==8.1.3 |
||||
decorator==5.1.1 |
||||
distro==1.8.0 |
||||
entrypoints==0.4 |
||||
gitdb==4.0.10 |
||||
GitPython==3.1.31 |
||||
idna==3.4 |
||||
importlib-metadata==6.1.0 |
||||
importlib-resources==5.12.0 |
||||
Jinja2==3.1.2 |
||||
jsonschema==4.17.3 |
||||
markdown-it-py==2.2.0 |
||||
MarkupSafe==2.1.2 |
||||
mdurl==0.1.2 |
||||
numpy==1.24.2 |
||||
packaging==23.0 |
||||
pandas==1.5.3 |
||||
Pillow==9.4.0 |
||||
pkgutil_resolve_name==1.3.10 |
||||
protobuf==3.20.3 |
||||
pyarrow==11.0.0 |
||||
pydeck==0.8.0 |
||||
Pygments==2.14.0 |
||||
Pympler==1.0.1 |
||||
pyrsistent==0.19.3 |
||||
python-dateutil==2.8.2 |
||||
python-decouple==3.8 |
||||
pytz==2023.2 |
||||
pytz-deprecation-shim==0.1.0.post0 |
||||
requests==2.28.2 |
||||
rich==13.3.3 |
||||
semver==2.13.0 |
||||
six==1.16.0 |
||||
smmap==5.0.0 |
||||
streamlit==1.20.0 |
||||
streamlit-aggrid==0.3.4.post3 |
||||
tabula-py==2.7.0 |
||||
toml==0.10.2 |
||||
toolz==0.12.0 |
||||
tornado==6.2 |
||||
typing_extensions==4.5.0 |
||||
tzdata==2023.2 |
||||
tzlocal==4.3 |
||||
urllib3==1.26.15 |
||||
validators==0.20.0 |
||||
zipp==3.15.0 |
||||
Loading…
Reference in new issue