How to create a streamlit frontend for saving medical information and link it with NFC Tag? [closed]

The purpose of the application will be to save medical information of the users and get it linked with NFC tag. I have taken medical id’s and there should be different medical id for each user.

The code that I have made is able to open streamlit application using VS Code.

import streamlit as st
import sqlite3
import nfc
from datetime import datetime

# Initialize SQLite database
conn = sqlite3.connect('medical_info.db', check_same_thread=False)
c = conn.cursor()
c.execute('''
    CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        nfc_tag_id TEXT UNIQUE,
        name TEXT,
        age INTEGER,
        blood_type TEXT,
        allergies TEXT,
        medications TEXT,
        medical_conditions TEXT,
        emergency_contact TEXT,
        insurance_info TEXT,
        last_checkup DATE
    )
''')

def save_medical_info(nfc_tag_id, name, age, blood_type, allergies, medications, conditions, contact, insurance, checkup):
    try:
        c.execute('''
            INSERT INTO users (nfc_tag_id, name, age, blood_type, allergies, medications, medical_conditions, emergency_contact, insurance_info, last_checkup)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
        ''', (nfc_tag_id, name, age, blood_type, allergies, medications, conditions, contact, insurance, checkup))
        conn.commit()
        st.success("Information saved successfully!")
    except sqlite3.IntegrityError:
        st.error("Error: NFC Tag ID already exists or invalid data")

def read_nfc_tag():
    try:
        # You may need to adjust 'usb', 'ttyACM0', or 'serial' based on your NFC reader connection
        connection_type = 'usb'  # Default to 'usb', adjust as needed

        if connection_type == 'usb':
            clf = nfc.ContactlessFrontend('usb')
        elif connection_type == 'ttyACM0':
            clf = nfc.ContactlessFrontend('ttyACM0')
        elif connection_type == 'serial':
            clf = nfc.ContactlessFrontend('serial')
        else:
            raise ValueError(f"Unsupported connection type: {connection_type}")

        tag = clf.connect(rdwr={'on-connect': lambda tag: False})
        tag_id = tag.identifier.decode('utf-8')
        st.write(f"Raw Tag ID: {tag.identifier}")
        return tag_id
    except Exception as e:
        st.error(f"Error reading NFC tag: {e}")
        return None

def main():
    st.title("Holistica World")

    nfc_tag_detected = False
    user_id = None

    if st.button("Search for NFC Tag"):
        user_id = read_nfc_tag()  # Try to read NFC tag
        if user_id:
            nfc_tag_detected = True
            st.write(f"NFC Tag ID: {user_id}")
        else:
            st.write("NFC tag not detected. Please enter information manually.")
            nfc_tag_detected = False

    with st.form(key='medical_info_form'):
        if not nfc_tag_detected:
            user_id = st.text_input("Enter User ID", value='')

        name = st.text_input("Name")
        age = st.number_input("Age", min_value=0)
        blood_type = st.text_input("Blood Type")
        allergies = st.text_input("Allergies")
        medications = st.text_input("Medications")
        conditions = st.text_input("Medical Conditions")
        contact = st.text_input("Emergency Contact")
        insurance = st.text_input("Insurance Info")
        checkup = st.date_input("Last Checkup Date")
        
        submit_button = st.form_submit_button("Save Information")
        
        if submit_button:
            # Save the new information
            save_medical_info(user_id if nfc_tag_detected else None, name, age, blood_type, allergies, medications, conditions, contact, insurance, checkup)

if __name__ == '__main__':
    main()

# Close the database connection when the app ends
conn.close()

I have a question that when I am clicking on Search for NFC tag, it is immediately display error of Error reading NFC tag: [Errno 19] No such device. So, I am entering manually. Can it be modified in such a way that when streamlit application opens, it will detect if any NFC tag or nfc is nearby, it will display else manually user will enter information and save it.

Please help.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật