-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_history.py
68 lines (54 loc) · 1.84 KB
/
user_history.py
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
import json
from datetime import datetime
import os
from flask import redirect, url_for
FOLDER_PATH = "static/user_data"
def load_user_history(phone_number):
print("phone_number: ", phone_number)
filename = f"{FOLDER_PATH}/user_history_{phone_number}.json"
if os.path.exists(filename):
print("filename: ", filename)
with open(filename, "r") as f:
return json.load(f)
# return {
# "entries": [],
# "fname": "N/A",
# "lname": "N/A",
# "age": "N/A",
# "gender": "N/A",
# "height": "N/A",
# "weight": "N/A",
# "current_call": []
# }
print("phone_number: ", phone_number)
return {
"entries": [],
"fname": "Nathan",
"lname": "Zhao",
"age": "30",
"gender": "Other",
"height": "170",
"weight": "70",
"current_call": [],
"username": phone_number,
"password": "password",
"phone_number": phone_number,
}
def save_user_history(phone_number, user_history):
print("Saving user history...")
filename = f"{FOLDER_PATH}/user_history_{phone_number}.json"
with open(filename, "w") as f:
json.dump(user_history, f, indent=2)
print("User history saved successfully")
def add_entry_to_history(user_history, new_info):
user_history["current_call"].extend(new_info)
def update_user_info(user_history, key, value):
user_history[key] = value
def finalize_call(user_history):
if user_history["current_call"]:
current_time = datetime.now().strftime("%m/%d/%Y %I:%M%p")
user_history["entries"].append({current_time: user_history["current_call"]})
user_history["current_call"] = [] # Clear the current call information
return redirect(
url_for("medical_record", phone_number=user_history["phone_number"][1:])
)