]> Softwares of Agnibho - librevax.git/commitdiff
Show patient age
authorAgnibho Mondal <mondal@agnibho.com>
Thu, 11 Jan 2024 20:46:16 +0000 (02:16 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Thu, 11 Jan 2024 20:46:16 +0000 (02:16 +0530)
librevax.py
templates/patient-view.html

index 988c8e8a98049d6d0233fb73370a37ecadf6c772..41c87d9316596356f42233fad5530a38a415ef47 100644 (file)
@@ -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()
index dd0f48bbbb36902dea1614cad1ffa064b23feab3..ccba911d46d2ad52ed43f9ce10a380ed5a930702 100644 (file)
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with Lib
     <tr><th>Card ID</th><td>{{data["cid"]}}</td></tr>
     <tr><th>Name</th><td>{{data["name"]}}</td></tr>
     <tr><th>Date of Birth</th><td>{{data["dob"]}}</td></tr>
+    <tr><th>Age</th><td>{{data["dob"]|calculate_age}}</td></tr>
     <tr><th>Sex</th><td>{{data["sex"]}}</td></tr>
     <tr><th>Address</th><td>{{data["address"]}}</td></tr>
     <tr><th>Contact</th><td>{{data["contact"]}}</td></tr>