neerajkalyank commited on
Commit
2da3bf0
1 Parent(s): 36eef5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -10
app.py CHANGED
@@ -18,16 +18,50 @@ def save_data(data):
18
  with open("data.json", "w") as file:
19
  json.dump(data, file)
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  # Patient Registration Tab
22
  def registration_interface(name, father_name, age, phone, address, pincode):
23
- # Get today's date
24
- today = datetime.now()
25
- # Generate patient ID with last 5 digits of the phone number
26
- patient_id = f"{today.year}{today.month:02d}{today.day:02d}{str(phone)[-5:]}"
27
 
28
- # Proceed with the rest of the function
29
- data = load_data()
30
- data[patient_id] = {
 
 
31
  "name": name,
32
  "father_name": father_name,
33
  "age": age,
@@ -37,11 +71,11 @@ def registration_interface(name, father_name, age, phone, address, pincode):
37
  "tests": [],
38
  "total_cost": 0
39
  }
40
- save_data(data)
 
 
41
  return f"Patient Registered. Patient ID: {patient_id}"
42
 
43
-
44
-
45
  # Tests Selection Tab
46
  def test_interface(categories):
47
  available_tests = get_tests_by_category(categories)
 
18
  with open("data.json", "w") as file:
19
  json.dump(data, file)
20
 
21
+ # Load data and last sequence
22
+ def load_data():
23
+ try:
24
+ with open("data.json", "r") as file:
25
+ data = json.load(file)
26
+ return data.get("patients", {}), data.get("last_sequence", {"year": None, "month": None, "number": 0})
27
+ except FileNotFoundError:
28
+ return {}, {"year": None, "month": None, "number": 0}
29
+
30
+ # Save data and last sequence
31
+ def save_data(patients, last_sequence):
32
+ with open("data.json", "w") as file:
33
+ json.dump({"patients": patients, "last_sequence": last_sequence}, file)
34
+
35
+ # Generate patient ID
36
+ def generate_patient_id(phone, last_sequence):
37
+ today = datetime.now()
38
+ current_year = today.year
39
+ current_month = today.month
40
+
41
+ # Check if year or month has changed
42
+ if last_sequence["year"] != current_year or last_sequence["month"] != current_month:
43
+ # Reset sequence for new year/month
44
+ last_sequence["year"] = current_year
45
+ last_sequence["month"] = current_month
46
+ last_sequence["number"] = 1
47
+ else:
48
+ # Increment sequence number
49
+ last_sequence["number"] += 1
50
+
51
+ # Format patient ID
52
+ patient_id = f"{current_year}{current_month:02d}{last_sequence['number']:05d}"
53
+ return patient_id
54
+
55
  # Patient Registration Tab
56
  def registration_interface(name, father_name, age, phone, address, pincode):
57
+ # Load data and sequence info
58
+ patients, last_sequence = load_data()
 
 
59
 
60
+ # Generate patient ID
61
+ patient_id = generate_patient_id(phone, last_sequence)
62
+
63
+ # Add patient details to data
64
+ patients[patient_id] = {
65
  "name": name,
66
  "father_name": father_name,
67
  "age": age,
 
71
  "tests": [],
72
  "total_cost": 0
73
  }
74
+
75
+ # Save data and updated sequence
76
+ save_data(patients, last_sequence)
77
  return f"Patient Registered. Patient ID: {patient_id}"
78
 
 
 
79
  # Tests Selection Tab
80
  def test_interface(categories):
81
  available_tests = get_tests_by_category(categories)