yougandar commited on
Commit
fa4452f
·
verified ·
1 Parent(s): 53ce837

Update register_patient.py

Browse files
Files changed (1) hide show
  1. 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 (Years)", "Age (Months)", "Age (Days)", "Gender", "Address", "Contact Number"])
14
 
15
- def register_patient(name, age_selection, 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
- # 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, age_years, age_months, age_days, gender, address, contact])
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 inputs using checkboxes
53
- age_years = gr.Number(label="Age (Years)", value=0)
54
- age_months = gr.Number(label="Age (Months)", value=0)
55
- age_days = gr.Number(label="Age (Days)", value=0)
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=on_register_click,
85
- inputs=[name, age_selection, age_years, age_months, age_days, gender, contact_number],
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