CoolFace
Apppublic

segestic/HealthBlock

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
app.py188 linesDownload Raw Back to root
1import streamlit as st2from pytezos import pytezos3import pandas as pd4 5pytezos = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet', key='edsk3MrRkoidY2SjEgufvi44orvyjxgZoy4LhaJNTNcddWykW6SssL')6contract = pytezos.contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV')7 8def welcome():9    return "Welcome To Decentralised Medical Records"10 11def addUser():12  name = st.text_input("Enter Full Name of the Patient")13  email = st.text_input("Enter Email of the Patient")14  number = st.number_input("Enter the Contact Number", step=1, min_value=1)15  age = st.number_input("Enter Age", step=1, min_value=18)16  gender = st.radio("Enter Gender", ('Male', 'Female'))17  #Hid = st.text_input("Enter your Unique Hospital Id")18  #hospital=st.text_input("Enter the Hospital details")19 20 21  if st.button("Register Patient"):22    a = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet', key='edsk3MrRkoidY2SjEgufvi44orvyjxgZoy4LhaJNTNcddWykW6SssL')23    contract = a.contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV')24 25    contract.addUser(email = email, name = name, age = age, gender = gender,  number = number).with_amount(0).as_transaction().fill().sign().inject()   26 27 28def ViewPatientRecord():29  Hid = st.text_input("Enter Unique Hospital Id of Patient")30  if st.button("View Records"):31    usds = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet').contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV')32    #print (usds.storage())#debug33    #print(list(usds.storage().keys())[0])34 35    #if email is in storage... print record36    if Hid in list(usds.storage().keys()):37        st.text(usds.storage())38        #print(usds.storage())39        #st.text(list(usds.storage().keys())[0])40        #st.text(list(usds.storage().values()))41    else: 42        st.text('Not Found')43    #st.text(usds.storage[email]['Record']())44    45    46####################WIDGETS START ##################################47 48def filters_widgets(df, columns=None, allow_single_value_widgets=False):49    # Parse the df and get filter widgets based for provided columns50    if not columns: #if columns not provided, use all columns to create widgets51        columns=df.columns.tolist()52    if allow_single_value_widgets:53        threshold=054    else:55        threshold=156    widget_dict = {}57    filter_widgets = st.container()58    filter_widgets.warning(59        "After selecting filters press the 'Apply Filters' button at the bottom.")60    if not allow_single_value_widgets:61        filter_widgets.markdown("Only showing columns that contain more than 1 unique value.")62    with filter_widgets.form(key="data_filters"):63        not_showing = [] 64        for y in df[columns]:65            if str(y) in st.session_state: #update value from session state if exists66                selected_opts = st.session_state[str(y)]67            else: #if doesnt exist use all values as defaults68                selected_opts = df[y].unique().tolist()69            if len(df[y].unique().tolist()) > threshold: #checks if above threshold70                widget_dict[y] = st.multiselect(71                    label=str(y),72                    options=df[y].unique().tolist(),73                    default=selected_opts,74                    key=str(y),75                )76            else:#if doesnt pass threshold77                not_showing.append(y)78        if not_showing:#if the list is not empty, show this warning79            st.warning(80                f"Not showing filters for {' '.join(not_showing)} since they only contain one unique value."81            )82        submit_button = st.form_submit_button("Apply Filters")83    #reset button to return all unselected values back84    reset_button = filter_widgets.button(85        "Reset All Filters",86        key="reset_buttons",87        on_click=reset_filter_widgets_to_default,88        args=(df, columns),89    )90    filter_widgets.warning(91        "Dont forget to apply filters by pressing 'Apply Filters' at the bottom."92    )    93 94def reset_filter_widgets_to_default(df, columns):95    for y in df[columns]:96        if str(y) in st.session_state:97            del st.session_state[y]98            99####################WIDGETS END##################################100               101def main():102    103    st.set_page_config(page_title="Decentralised Health Vaccine Records")104   105    st.title("Blockchain Based Medical Records")106    st.markdown(107        """<div style="background-color:#e1f0fa;padding:10px">108                    <h1 style='text-align: center; color: #304189;font-family:Helvetica'><strong>109                    Vaccine Data </strong></h1></div><br>""",110        unsafe_allow_html=True,111    )112 113 114    st.markdown(115        """<p style='text-align: center;font-family:Helvetica;'>116                   This project greatly decreases any chances of misuse or the manipulation of the medical Records</p>""",117        unsafe_allow_html=True,118    )119 120    st.sidebar.title("Choose your entry point")121    st.sidebar.markdown("Select the entry point accordingly:")122 123    algo = st.sidebar.selectbox(124        "Select the Option", options=[125          "Register Patient",126          "View Patient Data"127          ]128    )129 130    if algo == "Register Patient":131        addUser()132    if algo == "View Patient Data":133        ViewPatientRecord()    134        135        136    st.write ('\n')137    st.write ('\n')138    st.write ('\n')139 140    141    #ledger start142    #get ledger data 143    144    st.subheader("Blockchain Ledger")145    st.write("Click to explore Blockchain ledger [link](https://ghostnet.tzkt.io/KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV/operations/)")146    147    148    ledger_data = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet').contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV').storage() #.values()149    150    for x in ledger_data:151    	ledger = ledger_data.values()152 153    try:154    	df = pd.DataFrame(ledger, index=[0])155    	#filters_widgets(df)156    except:157        df = pd.DataFrame(ledger)#, index=[0])158        #filters_widgets(df)159    # Display the dataframe as a table160    st.write(df)	161 162 163 164if __name__ == "__main__":165    main() #streamlit-start166    import subprocess167    import uvicorn168    169    subprocess.run("uvicorn api.main:app --host 0.0.0.0 --port 7860", shell=True) 170    171    172    173    ############end table/ledger174   175#if __name__ == "__main__":176  #main()177 178  179  180#comments181      #ledger = {'age': 18, 'gender': 'Female', 'hospital': '', 'name': 'tesuser1', 'number': 41414, 'v1': False, 'v1Date': 0, 'v2': False, 'v2Date': 0}182    183#    data = [184#        {"Name": "Alice", "Age": 25, "City": "New York"},185#        {"Name": "Bob", "Age": 30, "City": "Paris"},186#        {"Name": "Charlie", "Age": 35, "City": "London"}187#    ]188