Spaces:
Build error
Build error
| import streamlit as st | |
| from pytezos import pytezos | |
| import pandas as pd | |
| pytezos = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet', key='edsk3MrRkoidY2SjEgufvi44orvyjxgZoy4LhaJNTNcddWykW6SssL') | |
| contract = pytezos.contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV') | |
| def welcome(): | |
| return "Welcome To Decentralised Medical Records" | |
| def addUser(): | |
| name = st.text_input("Enter Full Name of the Patient") | |
| email = st.text_input("Enter Email of the Patient") | |
| number = st.number_input("Enter the Contact Number", step=1, min_value=1) | |
| age = st.number_input("Enter Age", step=1, min_value=18) | |
| gender = st.radio("Enter Gender", ('Male', 'Female')) | |
| #Hid = st.text_input("Enter your Unique Hospital Id") | |
| #hospital=st.text_input("Enter the Hospital details") | |
| if st.button("Register Patient"): | |
| a = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet', key='edsk3MrRkoidY2SjEgufvi44orvyjxgZoy4LhaJNTNcddWykW6SssL') | |
| contract = a.contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV') | |
| contract.addUser(email = email, name = name, age = age, gender = gender, number = number).with_amount(0).as_transaction().fill().sign().inject() | |
| def ViewPatientRecord(): | |
| Hid = st.text_input("Enter Unique Hospital Id of Patient") | |
| if st.button("View Records"): | |
| usds = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet').contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV') | |
| #print (usds.storage())#debug | |
| #print(list(usds.storage().keys())[0]) | |
| #if email is in storage... print record | |
| if Hid in list(usds.storage().keys()): | |
| st.text(usds.storage()) | |
| #print(usds.storage()) | |
| #st.text(list(usds.storage().keys())[0]) | |
| #st.text(list(usds.storage().values())) | |
| else: | |
| st.text('Not Found') | |
| #st.text(usds.storage[email]['Record']()) | |
| ####################WIDGETS START ################################## | |
| def filters_widgets(df, columns=None, allow_single_value_widgets=False): | |
| # Parse the df and get filter widgets based for provided columns | |
| if not columns: #if columns not provided, use all columns to create widgets | |
| columns=df.columns.tolist() | |
| if allow_single_value_widgets: | |
| threshold=0 | |
| else: | |
| threshold=1 | |
| widget_dict = {} | |
| filter_widgets = st.container() | |
| filter_widgets.warning( | |
| "After selecting filters press the 'Apply Filters' button at the bottom.") | |
| if not allow_single_value_widgets: | |
| filter_widgets.markdown("Only showing columns that contain more than 1 unique value.") | |
| with filter_widgets.form(key="data_filters"): | |
| not_showing = [] | |
| for y in df[columns]: | |
| if str(y) in st.session_state: #update value from session state if exists | |
| selected_opts = st.session_state[str(y)] | |
| else: #if doesnt exist use all values as defaults | |
| selected_opts = df[y].unique().tolist() | |
| if len(df[y].unique().tolist()) > threshold: #checks if above threshold | |
| widget_dict[y] = st.multiselect( | |
| label=str(y), | |
| options=df[y].unique().tolist(), | |
| default=selected_opts, | |
| key=str(y), | |
| ) | |
| else:#if doesnt pass threshold | |
| not_showing.append(y) | |
| if not_showing:#if the list is not empty, show this warning | |
| st.warning( | |
| f"Not showing filters for {' '.join(not_showing)} since they only contain one unique value." | |
| ) | |
| submit_button = st.form_submit_button("Apply Filters") | |
| #reset button to return all unselected values back | |
| reset_button = filter_widgets.button( | |
| "Reset All Filters", | |
| key="reset_buttons", | |
| on_click=reset_filter_widgets_to_default, | |
| args=(df, columns), | |
| ) | |
| filter_widgets.warning( | |
| "Dont forget to apply filters by pressing 'Apply Filters' at the bottom." | |
| ) | |
| def reset_filter_widgets_to_default(df, columns): | |
| for y in df[columns]: | |
| if str(y) in st.session_state: | |
| del st.session_state[y] | |
| ####################WIDGETS END################################## | |
| def main(): | |
| st.set_page_config(page_title="Decentralised Health Vaccine Records") | |
| st.title("Blockchain Based Medical Records") | |
| st.markdown( | |
| """<div style="background-color:#e1f0fa;padding:10px"> | |
| <h1 style='text-align: center; color: #304189;font-family:Helvetica'><strong> | |
| Vaccine Data </strong></h1></div><br>""", | |
| unsafe_allow_html=True, | |
| ) | |
| st.markdown( | |
| """<p style='text-align: center;font-family:Helvetica;'> | |
| This project greatly decreases any chances of misuse or the manipulation of the medical Records</p>""", | |
| unsafe_allow_html=True, | |
| ) | |
| st.sidebar.title("Choose your entry point") | |
| st.sidebar.markdown("Select the entry point accordingly:") | |
| algo = st.sidebar.selectbox( | |
| "Select the Option", options=[ | |
| "Register Patient", | |
| "View Patient Data" | |
| ] | |
| ) | |
| if algo == "Register Patient": | |
| addUser() | |
| if algo == "View Patient Data": | |
| ViewPatientRecord() | |
| st.write ('\n') | |
| st.write ('\n') | |
| st.write ('\n') | |
| #ledger start | |
| #get ledger data | |
| st.subheader("Blockchain Ledger") | |
| st.write("Click to explore Blockchain ledger [link](https://ghostnet.tzkt.io/KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV/operations/)") | |
| ledger_data = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet').contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV').storage() #.values() | |
| for x in ledger_data: | |
| ledger = ledger_data.values() | |
| try: | |
| df = pd.DataFrame(ledger, index=[0]) | |
| #filters_widgets(df) | |
| except: | |
| df = pd.DataFrame(ledger)#, index=[0]) | |
| #filters_widgets(df) | |
| # Display the dataframe as a table | |
| st.write(df) | |
| ############end table/ledger | |
| if __name__ == "__main__": | |
| main() | |
| #comments | |
| #ledger = {'age': 18, 'gender': 'Female', 'hospital': '', 'name': 'tesuser1', 'number': 41414, 'v1': False, 'v1Date': 0, 'v2': False, 'v2Date': 0} | |
| # data = [ | |
| # {"Name": "Alice", "Age": 25, "City": "New York"}, | |
| # {"Name": "Bob", "Age": 30, "City": "Paris"}, | |
| # {"Name": "Charlie", "Age": 35, "City": "London"} | |
| # ] | |