basilefuchs commited on
Commit
fb6ade0
·
1 Parent(s): b4ea3b9

feat cache

Browse files
.gitignore CHANGED
@@ -1 +1,2 @@
1
- .venv/
 
 
1
+ .venv/
2
+ __pycache__/
src/ingest/__init__.py ADDED
File without changes
src/ingest/load_data.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import polars as pl
3
+ import requests
4
+
5
+ GRIST_URL = "https://grist.numerique.gouv.fr/o/dim-chu-brest/api/docs/5ZXqTKBiHTD2qqUj6GVPtp"
6
+
7
+ @st.cache_data
8
+ def load_grist(table: str)->pl.DataFrame:
9
+ records = requests.get(f"{GRIST_URL}/tables/{table}/records").json()["records"]
10
+ return pl.DataFrame(records).drop("id").unnest("fields")
src/page/acte.py CHANGED
@@ -1,15 +1,10 @@
1
- import requests
2
- import unidecode
3
- import polars as pl
4
  import streamlit as st
 
 
 
5
 
6
 
7
- GRIST_URL = "https://grist.numerique.gouv.fr/o/dim-chu-brest/api/docs/5ZXqTKBiHTD2qqUj6GVPtp" # ou ton serveur
8
- TABLE = "Actes_classants"
9
-
10
- records = requests.get(f"{GRIST_URL}/tables/{TABLE}/records").json()["records"]
11
-
12
- acte = pl.DataFrame(records).drop("id").unnest("fields")
13
 
14
  names = {
15
  "CODE_ACTE": "Code acte",
@@ -19,7 +14,7 @@ names = {
19
  }
20
 
21
  items = (
22
- acte.filter(pl.col("LIBELLE_CARACTERISTIQUE").is_not_null())["LIBELLE_CARACTERISTIQUE"]
23
  .unique()
24
  .str.to_titlecase()
25
  .sort()
@@ -37,7 +32,7 @@ exp = unidecode.unidecode(exp)
37
  selection = col3.multiselect("Filtre(s) :", options=items, default=[])
38
 
39
  _temp = (
40
- acte.filter(
41
  (pl.col("CODE_ACTE").str.contains(r"(?i)" + exp))
42
  | (pl.col("LIBELLE_ACTE").str.contains(r"(?i)" + exp))
43
  | (pl.col("LIBELLE_CARACTERISTIQUE").str.contains(r"(?i)" + exp))
@@ -48,7 +43,7 @@ _temp = (
48
  )
49
 
50
  df = (
51
- acte.join(_temp, on="CODE_ACTE", how="inner")
52
  .with_columns(
53
  pl.lit(1).alias("flag"),
54
  )
@@ -62,7 +57,7 @@ df = (
62
  )
63
 
64
  if selection:
65
- _temp = acte.filter((pl.col("LIBELLE_CARACTERISTIQUE").is_in(selection))).select("CODE_ACTE").unique()
66
  df = df.join(_temp, on="CODE_ACTE", how="inner").rename(names)
67
 
68
  st.dataframe(df.to_pandas(), hide_index=True, width='stretch')
 
 
 
 
1
  import streamlit as st
2
+ import polars as pl
3
+ import unidecode
4
+ from ingest.load_data import load_grist
5
 
6
 
7
+ data = load_grist("Actes_classants")
 
 
 
 
 
8
 
9
  names = {
10
  "CODE_ACTE": "Code acte",
 
14
  }
15
 
16
  items = (
17
+ data.filter(pl.col("LIBELLE_CARACTERISTIQUE").is_not_null())["LIBELLE_CARACTERISTIQUE"]
18
  .unique()
19
  .str.to_titlecase()
20
  .sort()
 
32
  selection = col3.multiselect("Filtre(s) :", options=items, default=[])
33
 
34
  _temp = (
35
+ data.filter(
36
  (pl.col("CODE_ACTE").str.contains(r"(?i)" + exp))
37
  | (pl.col("LIBELLE_ACTE").str.contains(r"(?i)" + exp))
38
  | (pl.col("LIBELLE_CARACTERISTIQUE").str.contains(r"(?i)" + exp))
 
43
  )
44
 
45
  df = (
46
+ data.join(_temp, on="CODE_ACTE", how="inner")
47
  .with_columns(
48
  pl.lit(1).alias("flag"),
49
  )
 
57
  )
58
 
59
  if selection:
60
+ _temp = data.filter((pl.col("LIBELLE_CARACTERISTIQUE").is_in(selection))).select("CODE_ACTE").unique()
61
  df = df.join(_temp, on="CODE_ACTE", how="inner").rename(names)
62
 
63
  st.dataframe(df.to_pandas(), hide_index=True, width='stretch')
src/page/bacteries.py CHANGED
@@ -1,15 +1,11 @@
1
- import requests
2
- import unidecode
3
  import polars as pl
4
  import streamlit as st
 
 
5
 
6
 
7
- GRIST_URL = "https://grist.numerique.gouv.fr/o/dim-chu-brest/api/docs/5ZXqTKBiHTD2qqUj6GVPtp" # ou ton serveur
8
- TABLE = "Bacteries"
9
-
10
- records = requests.get(f"{GRIST_URL}/tables/{TABLE}/records").json()["records"]
11
-
12
- data = pl.DataFrame(records).drop("id").unnest("fields").select("Bacterie", "Code_bacterie", "Code_si_sepsis").sort("Bacterie")
13
 
14
  st.title("Bactéries CIM-10")
15
 
 
1
+ from json import load
 
2
  import polars as pl
3
  import streamlit as st
4
+ import unidecode
5
+ from ingest.load_data import load_grist
6
 
7
 
8
+ data = load_grist("Bacteries").select("Bacterie", "Code_bacterie", "Code_si_sepsis").sort("Bacterie")
 
 
 
 
 
9
 
10
  st.title("Bactéries CIM-10")
11
 
src/page/ctxt.py CHANGED
@@ -1,18 +1,11 @@
1
- import requests
2
- import unidecode
3
- import polars as pl
4
  import streamlit as st
 
5
 
6
 
7
- GRIST_URL = "https://grist.numerique.gouv.fr/o/dim-chu-brest/api/docs/5ZXqTKBiHTD2qqUj6GVPtp" # ou ton serveur
8
- TABLE = "Ctxt"
9
-
10
- records = requests.get(f"{GRIST_URL}/tables/{TABLE}/records").json()["records"]
11
-
12
- ctxt = pl.DataFrame(records).drop("id").unnest("fields").sort(pl.col("Code_CIM_10"))
13
 
14
  st.title("Contexte patient")
15
 
16
- st.dataframe(ctxt.to_pandas(), hide_index=True, width='stretch')
17
 
18
  st.divider()
 
 
 
 
1
  import streamlit as st
2
+ from ingest.load_data import load_grist
3
 
4
 
5
+ data = load_grist("Ctxt").sort("Code_CIM_10")
 
 
 
 
 
6
 
7
  st.title("Contexte patient")
8
 
9
+ st.dataframe(data.to_pandas(), hide_index=True, width='stretch')
10
 
11
  st.divider()
src/page/intox.py CHANGED
@@ -1,18 +1,11 @@
1
- import requests
2
- import unidecode
3
- import polars as pl
4
  import streamlit as st
 
 
 
5
 
6
 
7
- GRIST_URL = "https://grist.numerique.gouv.fr/o/dim-chu-brest/api/docs/5ZXqTKBiHTD2qqUj6GVPtp" # ou ton serveur
8
- TABLE1 = "Intox_data"
9
- TABLE2 = "Intox_data2"
10
-
11
- records1 = requests.get(f"{GRIST_URL}/tables/{TABLE1}/records").json()["records"]
12
- records2 = requests.get(f"{GRIST_URL}/tables/{TABLE2}/records").json()["records"]
13
-
14
- cim10 = pl.DataFrame(records1).drop("id").unnest("fields").sort("SUBSTANCE")
15
- data = pl.DataFrame(records2).drop("id").unnest("fields").sort("Nom")
16
 
17
  data = data.with_columns(
18
  pl.col("Nom")
 
 
 
 
1
  import streamlit as st
2
+ import polars as pl
3
+ import unidecode
4
+ from ingest.load_data import load_grist
5
 
6
 
7
+ cim10 = load_grist("Intox_data").sort("SUBSTANCE")
8
+ data = load_grist("Intox_data2").sort("Nom")
 
 
 
 
 
 
 
9
 
10
  data = data.with_columns(
11
  pl.col("Nom")