Update register_patient.py
Browse files- register_patient.py +9 -28
register_patient.py
CHANGED
|
@@ -10,18 +10,13 @@ def initialize_csv():
|
|
| 10 |
if not os.path.exists(patient_file_path):
|
| 11 |
with open(patient_file_path, mode='w', newline='') as file:
|
| 12 |
writer = csv.writer(file)
|
| 13 |
-
writer.writerow(["Patient ID", "Name", "Age
|
| 14 |
|
| 15 |
-
def register_patient(name,
|
| 16 |
"""Register a new patient and return the registration status."""
|
| 17 |
address = "Hyderabad"
|
| 18 |
initialize_csv() # Ensure the CSV is initialized
|
| 19 |
|
| 20 |
-
# Calculate age based on the selection
|
| 21 |
-
age_years = age_selection.get("Years", 0)
|
| 22 |
-
age_months = age_selection.get("Months", 0)
|
| 23 |
-
age_days = age_selection.get("Days", 0)
|
| 24 |
-
|
| 25 |
# Read the last Patient ID and increment it
|
| 26 |
with open(patient_file_path, mode='r') as file:
|
| 27 |
reader = csv.reader(file)
|
|
@@ -33,7 +28,7 @@ def register_patient(name, age_selection, gender, contact):
|
|
| 33 |
# Write the new patient details to the CSV file
|
| 34 |
with open(patient_file_path, mode='a', newline='') as file:
|
| 35 |
writer = csv.writer(file)
|
| 36 |
-
writer.writerow([new_id, name,
|
| 37 |
|
| 38 |
return f"Patient ID: {new_id}, Name: {name} registered successfully."
|
| 39 |
|
|
@@ -49,12 +44,10 @@ def create_gradio_interface():
|
|
| 49 |
# Define Gradio inputs
|
| 50 |
name = gr.Textbox(label="Patient Name", placeholder="Enter patient name")
|
| 51 |
|
| 52 |
-
# Age
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
age_selection = gr.CheckboxGroup(choices=["Years", "Months", "Days"], label="Select Age Unit(s)")
|
| 57 |
-
|
| 58 |
contact_number = gr.Textbox(label="Contact Number", placeholder="Enter contact number")
|
| 59 |
|
| 60 |
with gr.Column():
|
|
@@ -65,24 +58,12 @@ def create_gradio_interface():
|
|
| 65 |
result = gr.Textbox(label="Result", interactive=False)
|
| 66 |
|
| 67 |
# Define Register button
|
| 68 |
-
def on_register_click(name, age_selection, age_years, age_months, age_days, gender, contact_number):
|
| 69 |
-
# Create a dictionary to map the selected age units to their values
|
| 70 |
-
age_dict = {}
|
| 71 |
-
if "Years" in age_selection:
|
| 72 |
-
age_dict["Years"] = age_years
|
| 73 |
-
if "Months" in age_selection:
|
| 74 |
-
age_dict["Months"] = age_months
|
| 75 |
-
if "Days" in age_selection:
|
| 76 |
-
age_dict["Days"] = age_days
|
| 77 |
-
|
| 78 |
-
return register_patient(name, age_dict, gender, contact_number)
|
| 79 |
-
|
| 80 |
register_button = gr.Button("Register")
|
| 81 |
|
| 82 |
# Define the registration logic
|
| 83 |
register_button.click(
|
| 84 |
-
fn=
|
| 85 |
-
inputs=[name,
|
| 86 |
outputs=result
|
| 87 |
)
|
| 88 |
|
|
|
|
| 10 |
if not os.path.exists(patient_file_path):
|
| 11 |
with open(patient_file_path, mode='w', newline='') as file:
|
| 12 |
writer = csv.writer(file)
|
| 13 |
+
writer.writerow(["Patient ID", "Name", "Age", "Age Unit", "Gender", "Address", "Contact Number"])
|
| 14 |
|
| 15 |
+
def register_patient(name, age, age_unit, gender, contact):
|
| 16 |
"""Register a new patient and return the registration status."""
|
| 17 |
address = "Hyderabad"
|
| 18 |
initialize_csv() # Ensure the CSV is initialized
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Read the last Patient ID and increment it
|
| 21 |
with open(patient_file_path, mode='r') as file:
|
| 22 |
reader = csv.reader(file)
|
|
|
|
| 28 |
# Write the new patient details to the CSV file
|
| 29 |
with open(patient_file_path, mode='a', newline='') as file:
|
| 30 |
writer = csv.writer(file)
|
| 31 |
+
writer.writerow([new_id, name, age, age_unit, gender, address, contact])
|
| 32 |
|
| 33 |
return f"Patient ID: {new_id}, Name: {name} registered successfully."
|
| 34 |
|
|
|
|
| 44 |
# Define Gradio inputs
|
| 45 |
name = gr.Textbox(label="Patient Name", placeholder="Enter patient name")
|
| 46 |
|
| 47 |
+
# Age input with number and unit selection similar to gender buttons
|
| 48 |
+
age = gr.Number(label="Age", value=0)
|
| 49 |
+
age_unit = gr.Radio(["Years", "Months", "Days"], label="Age Unit", value="Years")
|
| 50 |
+
|
|
|
|
|
|
|
| 51 |
contact_number = gr.Textbox(label="Contact Number", placeholder="Enter contact number")
|
| 52 |
|
| 53 |
with gr.Column():
|
|
|
|
| 58 |
result = gr.Textbox(label="Result", interactive=False)
|
| 59 |
|
| 60 |
# Define Register button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
register_button = gr.Button("Register")
|
| 62 |
|
| 63 |
# Define the registration logic
|
| 64 |
register_button.click(
|
| 65 |
+
fn=register_patient,
|
| 66 |
+
inputs=[name, age, age_unit, gender, contact_number],
|
| 67 |
outputs=result
|
| 68 |
)
|
| 69 |
|