Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -131,13 +131,13 @@ fields0: List[Field] = [
|
|
| 131 |
other_params={'labels': mentioned_y_n}, mandatory=True),
|
| 132 |
]),
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
]
|
| 142 |
fields1: List[Field] = [
|
| 143 |
Field(type="container", title="#### True-To-Patient-Prompt Features", children=[
|
|
@@ -490,6 +490,11 @@ def prime_rupture_markers_from_saved(index: int, data_collected: dict | None):
|
|
| 490 |
st.session_state[primed_flag] = True
|
| 491 |
|
| 492 |
def validate_current_page(fields: List[Field], index: int) -> bool:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
ok = True
|
| 494 |
|
| 495 |
def walk(nodes: List[Field], following_required: bool = False):
|
|
@@ -658,7 +663,7 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 658 |
st.session_state.following_mandatory = True
|
| 659 |
|
| 660 |
if f.mandatory or st.session_state.following_mandatory:
|
| 661 |
-
f.title += " :
|
| 662 |
f.help = None
|
| 663 |
|
| 664 |
value = st.session_state[key] if key in st.session_state else \
|
|
@@ -780,7 +785,7 @@ def prep_and_save_data(index, skip_sample, completed: bool):
|
|
| 780 |
'user_id': st.session_state.user_id,
|
| 781 |
'index': st.session_state.current_index,
|
| 782 |
**(st.session_state.data.iloc[index][COLS_TO_SAVE].to_dict() if 0 <= index < len(st.session_state.data) else {}),
|
| 783 |
-
|
| 784 |
'skip': skip_sample,
|
| 785 |
'completed': completed,
|
| 786 |
}
|
|
@@ -879,7 +884,6 @@ if user_id_from_url and not st.session_state.get("user_id"):
|
|
| 879 |
# current index
|
| 880 |
if 'current_index' not in st.session_state:
|
| 881 |
start_index = get_start_index()
|
| 882 |
-
|
| 883 |
if start_index < len(st.session_state.data)-1:
|
| 884 |
st.session_state.current_index = start_index
|
| 885 |
else:
|
|
@@ -894,6 +898,7 @@ if get_param_from_url('show_extra_fields'):
|
|
| 894 |
else:
|
| 895 |
fields1 += url_conditional_fields
|
| 896 |
|
|
|
|
| 897 |
def add_validated_submit(fields, message):
|
| 898 |
st.session_state.form_displayed = st.session_state.current_index
|
| 899 |
if st.form_submit_button("Submit"):
|
|
@@ -934,9 +939,9 @@ elif st.session_state.current_index < len(st.session_state.data):
|
|
| 934 |
show_fields(STEPS[step])
|
| 935 |
|
| 936 |
# Action buttons
|
| 937 |
-
c1, c2, c3 = st.columns([
|
| 938 |
with c1:
|
| 939 |
-
label = "
|
| 940 |
if st.button(label):
|
| 941 |
if validate_current_page(STEPS[step], st.session_state.current_index):
|
| 942 |
is_last_page = (step == total_steps - 1)
|
|
@@ -962,6 +967,8 @@ elif st.session_state.current_index < len(st.session_state.data):
|
|
| 962 |
st.rerun()
|
| 963 |
elif st.session_state.current_index == len(st.session_state.data):
|
| 964 |
st.write(f"**Thank you for taking part in this study!** \n ")
|
|
|
|
|
|
|
| 965 |
|
| 966 |
# Navigation buttons
|
| 967 |
#if 0 < st.session_state.current_index < len(st.session_state.data):
|
|
@@ -984,4 +991,3 @@ st.markdown(
|
|
| 984 |
}
|
| 985 |
</style>""", unsafe_allow_html=True
|
| 986 |
)
|
| 987 |
-
|
|
|
|
| 131 |
other_params={'labels': mentioned_y_n}, mandatory=True),
|
| 132 |
]),
|
| 133 |
|
| 134 |
+
Field(type="container", title="#### Rupture Markers", children=[
|
| 135 |
+
Field(type="expander", title="**Overview of rupture markers** *(expand)*", children=[
|
| 136 |
+
Field(type="markdown", title="", other_params={"path": "rupture_marker_overview.md"}),
|
| 137 |
+
]),
|
| 138 |
+
Field(name="rupture_marker", type="rupture_markers",
|
| 139 |
+
title="Select rupture markers noted in the session, include line numbers where rupture is found.", mandatory=False),
|
| 140 |
+
]),
|
| 141 |
]
|
| 142 |
fields1: List[Field] = [
|
| 143 |
Field(type="container", title="#### True-To-Patient-Prompt Features", children=[
|
|
|
|
| 490 |
st.session_state[primed_flag] = True
|
| 491 |
|
| 492 |
def validate_current_page(fields: List[Field], index: int) -> bool:
|
| 493 |
+
"""
|
| 494 |
+
Walk the field tree and verify mandatory inputs are filled.
|
| 495 |
+
Honors `following_mandatory_values`: if a field's value is in that list,
|
| 496 |
+
subsequent siblings become mandatory.
|
| 497 |
+
"""
|
| 498 |
ok = True
|
| 499 |
|
| 500 |
def walk(nodes: List[Field], following_required: bool = False):
|
|
|
|
| 663 |
st.session_state.following_mandatory = True
|
| 664 |
|
| 665 |
if f.mandatory or st.session_state.following_mandatory:
|
| 666 |
+
f.title += " :red[* required!]" if (validation_error and not SHOW_VALIDATION_ERROR_MESSAGE) else' :red[*]'
|
| 667 |
f.help = None
|
| 668 |
|
| 669 |
value = st.session_state[key] if key in st.session_state else \
|
|
|
|
| 785 |
'user_id': st.session_state.user_id,
|
| 786 |
'index': st.session_state.current_index,
|
| 787 |
**(st.session_state.data.iloc[index][COLS_TO_SAVE].to_dict() if 0 <= index < len(st.session_state.data) else {}),
|
| 788 |
+
**{k: st.session_state[k + str(index)] for k in st.session_state.data_inputs_keys},
|
| 789 |
'skip': skip_sample,
|
| 790 |
'completed': completed,
|
| 791 |
}
|
|
|
|
| 884 |
# current index
|
| 885 |
if 'current_index' not in st.session_state:
|
| 886 |
start_index = get_start_index()
|
|
|
|
| 887 |
if start_index < len(st.session_state.data)-1:
|
| 888 |
st.session_state.current_index = start_index
|
| 889 |
else:
|
|
|
|
| 898 |
else:
|
| 899 |
fields1 += url_conditional_fields
|
| 900 |
|
| 901 |
+
|
| 902 |
def add_validated_submit(fields, message):
|
| 903 |
st.session_state.form_displayed = st.session_state.current_index
|
| 904 |
if st.form_submit_button("Submit"):
|
|
|
|
| 939 |
show_fields(STEPS[step])
|
| 940 |
|
| 941 |
# Action buttons
|
| 942 |
+
c1, c2, c3 = st.columns([5,3,2])
|
| 943 |
with c1:
|
| 944 |
+
label = "**:red[Submit]**" if step < total_steps - 1 else "**:red[Submit & next session]**"
|
| 945 |
if st.button(label):
|
| 946 |
if validate_current_page(STEPS[step], st.session_state.current_index):
|
| 947 |
is_last_page = (step == total_steps - 1)
|
|
|
|
| 967 |
st.rerun()
|
| 968 |
elif st.session_state.current_index == len(st.session_state.data):
|
| 969 |
st.write(f"**Thank you for taking part in this study!** \n ")
|
| 970 |
+
# if st.button("Previous"):
|
| 971 |
+
# navigate(-2)
|
| 972 |
|
| 973 |
# Navigation buttons
|
| 974 |
#if 0 < st.session_state.current_index < len(st.session_state.data):
|
|
|
|
| 991 |
}
|
| 992 |
</style>""", unsafe_allow_html=True
|
| 993 |
)
|
|
|