Spaces:
Build error
Build error
File size: 6,600 Bytes
e3b9b11 6600632 e3b9b11 6600632 e3b9b11 e692e9d e3b9b11 d7df43c 34132a7 e3b9b11 e692e9d e3b9b11 |
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
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)
if __name__ == "__main__":
main() #streamlit-start
import subprocess
import uvicorn
subprocess.run("uvicorn api.main:app --host 0.0.0.0 --port 7860", shell=True)
############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"}
# ]
|