From 5c0ee92a6baf706e34fd0a0e9b77eef7401bbcab Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Fri, 12 Jan 2024 02:16:16 +0530 Subject: [PATCH] Show patient age --- librevax.py | 14 +++++++++++++- templates/patient-view.html | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/librevax.py b/librevax.py index 988c8e8..41c87d9 100644 --- a/librevax.py +++ b/librevax.py @@ -714,9 +714,21 @@ def format_date(date): else: dt=datetime.strptime(date, "%Y-%m-%d") return dt.strftime("%b %d, %Y") - except Exception: + except Exception as e: return date +@app.template_filter("calculate_age") +def calculate_age(dob): + try: + today=datetime.today() + try: + born=datetime.strptime(dob, "%Y-%m-%d") + except ValueError: + born=datetime.strptime(dob, "%Y") + return today.year-born.year-((today.month, today.day)<(born.month, born.day)) + except Exception as e: + return "" + def init_db(): with app.app_context(): db=get_db() diff --git a/templates/patient-view.html b/templates/patient-view.html index dd0f48b..ccba911 100644 --- a/templates/patient-view.html +++ b/templates/patient-view.html @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with Lib Card ID{{data["cid"]}} Name{{data["name"]}} Date of Birth{{data["dob"]}} + Age{{data["dob"]|calculate_age}} Sex{{data["sex"]}} Address{{data["address"]}} Contact{{data["contact"]}} -- 2.39.5