-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_backend.py
134 lines (123 loc) · 8.35 KB
/
upload_backend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import streamlit as st
from firebase_helpers import save_image
from Styles import upload_markdown
import uuid
from helper_functions import (
select_main_type, select_view, select_main_region, select_gender,
select_subregion, select_sub_subregion, select_sub_sub_subregion,
select_sub_sub_sub_subregion, select_finger, select_complications,
select_associated_conditions, ao_classification, neer_classification, gartland_classification
)
# Function to handle file uploads
def handle_file_upload(uploaded_file):
if uploaded_file.size > 15 * 1024 * 1024:
st.error("A kép mérete nem lehet nagyobb, mint 15 MB.")
return None
else:
return uploaded_file
def confirm_and_upload_data(upload_data):
if upload_data['age'] == "NA":
age_group = st.radio("Kérem válassza ki az életkori csoportot", ["Gyermek", "Felnőtt"])
upload_data['age_group'] = age_group
st.markdown('---')
st.markdown('<div class="confirmation-title">Kérlek, a feltöltéshez erősítsd meg a következő adatokat:</div>', unsafe_allow_html=True)
cols = st.columns(2)
with cols[0]:
if upload_data["patient_id"]:
st.markdown(f'**<span class="highlight">Beteg azonosító:</span>** {upload_data["patient_id"]}', unsafe_allow_html=True)
if upload_data["main_type"]:
st.markdown(f'**<span class="highlight">Típus:</span>** {upload_data["main_type"]}', unsafe_allow_html=True)
if upload_data["sub_type"]:
st.markdown(f'**<span class="highlight">Specifikus típus:</span>** {upload_data["sub_type"]}', unsafe_allow_html=True)
if upload_data["sub_sub_type"]:
st.markdown(f'**<span class="highlight">Legspecifikusabb típus:</span>** {upload_data["sub_sub_type"]}', unsafe_allow_html=True)
if upload_data["gender"]:
st.markdown(f'**<span class="highlight">Nem:</span>** {upload_data["gender"]}', unsafe_allow_html=True)
if upload_data["age"] != "NA":
st.markdown(f'**<span class="highlight">Életkor:</span>** {upload_data["age"]}', unsafe_allow_html=True)
with cols[1]:
if upload_data["view"]:
st.markdown(f'**<span class="highlight">Nézet:</span>** {upload_data["view"]}', unsafe_allow_html=True)
if upload_data["sub_view"]:
st.markdown(f'**<span class="highlight">Specifikus nézet:</span>** {upload_data["sub_view"]}', unsafe_allow_html=True)
if upload_data["sub_sub_view"]:
st.markdown(f'**<span class="highlight">Legspecifikusabb nézet:</span>** {upload_data["sub_sub_view"]}', unsafe_allow_html=True)
if upload_data["age_group"]:
st.markdown(f'**<span class="highlight">Életkori Csoport:</span>** {upload_data["age_group"]}', unsafe_allow_html=True)
if upload_data["comment"]:
st.markdown(f'**<span class="highlight">Megjegyzés:</span>** {upload_data["comment"]}', unsafe_allow_html=True)
if upload_data["complications"]:
st.markdown(f'**<span class="highlight">Komplikációk:</span>** {", ".join(upload_data["complications"])}', unsafe_allow_html=True)
if upload_data["associated_conditions"]:
st.markdown(f'**<span class="highlight">Társuló Kórállapotok:</span>** {", ".join(upload_data["associated_conditions"])}', unsafe_allow_html=True)
st.markdown('### Kiválasztott régiók', unsafe_allow_html=True)
cols = st.columns(2)
for idx, region in enumerate(upload_data["regions"]):
col = cols[idx % 2]
with col:
st.markdown(f"**<span class='highlight'>Régió {idx + 1}:</span>**", unsafe_allow_html=True)
if region['main_region']:
st.markdown(f"**<span class='highlight'>Fő régió:</span>** {region['main_region']}", unsafe_allow_html=True)
if region['side']:
st.markdown(f"**<span class='highlight'>Oldal:</span>** {region['side']}", unsafe_allow_html=True)
if region['sub_region']:
st.markdown(f"**<span class='highlight'>Alrégió:</span>** {region['sub_region']}", unsafe_allow_html=True)
if region['sub_sub_region']:
st.markdown(f"**<span class='highlight'>Részletes régió:</span>** {region['sub_sub_region']}", unsafe_allow_html=True)
if region['sub_sub_sub_region']:
st.markdown(f"**<span class='highlight'>Legpontosabb régió:</span>** {region['sub_sub_sub_region']}", unsafe_allow_html=True)
if region['finger']:
st.markdown(f"**<span class='highlight'>Ujj:</span>** {region['finger']}", unsafe_allow_html=True)
if region['sub_sub_sub_sub_region']:
st.markdown(f"**<span class='highlight'>Legrészletesebb régió:</span>** {region['sub_sub_sub_sub_region']}", unsafe_allow_html=True)
if region.get("classification"):
for classification_name, details in region["classification"].items():
if "name" in details:
st.markdown(f"**<span class='highlight'>Osztályozás ({classification_name}):</span>** {details['name']}", unsafe_allow_html=True)
if "severity" in details:
st.markdown(f"**<span class='highlight'>Súlyosság:</span>** {details['severity']}", unsafe_allow_html=True)
if "severity_value" in details:
st.markdown(f"**<span class='highlight'>Súlyosság értéke:</span>** {details['severity_value']}", unsafe_allow_html=True)
if "subseverity" in details:
st.markdown(f"**<span class='highlight'>Alsúlyosság:</span>** {details['subseverity']}", unsafe_allow_html=True)
if "subseverity_value" in details:
st.markdown(f"**<span class='highlight'>Alsúlyosság értéke:</span>** {details['subseverity_value']}", unsafe_allow_html=True)
if "subsubseverity" in details:
st.markdown(f"**<span class='highlight'>Alalsúlyosság:</span>** {details['subsubseverity']}", unsafe_allow_html=True)
if "subsubseverity_value" in details:
st.markdown(f"**<span class='highlight'>Alalsúlyosság értéke:</span>** {details['subsubseverity_value']}", unsafe_allow_html=True)
if "subsubsubseverity" in details:
st.markdown(f"**<span class='highlight'>Alalalsúlyosság:</span>** {details['subsubsubseverity']}", unsafe_allow_html=True)
if "subsubsubseverity_value" in details:
st.markdown(f"**<span class='highlight'>Alalalsúlyosság értéke:</span>** {details['subsubsubseverity_value']}", unsafe_allow_html=True)
st.markdown('---')
with st.container():
# Add a button for confirming and uploading
if st.button("Megerősít és Feltölt", key="confirm_upload", help="Kattintson a feltöltés megerősítéséhez"):
if upload_data: # Check if upload_data exists and is not empty
try:
save_image(
patient_id=upload_data["patient_id"],
files=upload_data["files"],
main_type=upload_data["main_type"],
sub_type=upload_data["sub_type"],
sub_sub_type=upload_data["sub_sub_type"],
view=upload_data["view"],
sub_view=upload_data["sub_view"],
sub_sub_view=upload_data["sub_sub_view"],
gender=upload_data["gender"], # Gender added here
age=upload_data["age"],
age_group=upload_data["age_group"],
comment=upload_data["comment"],
complications=upload_data["complications"],
associated_conditions=upload_data["associated_conditions"],
regions=upload_data["regions"]
)
st.success("Kép sikeresen feltöltve!")
st.session_state["confirm_data"] = None
st.experimental_set_query_params(scroll_to="confirmation")
except Exception as e:
st.error(f"Hiba a kép mentésekor: {e}")
st.session_state["confirm_data"] = None
else:
st.error("Nincs feltöltendő adat!")