From: Agnibho Mondal Date: Wed, 10 Jan 2024 20:08:15 +0000 (+0530) Subject: New CID by JS X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=6261daade388db204723d09ace69e3e6eb2430b9;p=librevax.git New CID by JS --- diff --git a/etc/__init__.py b/etc/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/etc/cid.py.example b/etc/cid.py.example deleted file mode 100644 index 47b5a18..0000000 --- a/etc/cid.py.example +++ /dev/null @@ -1,7 +0,0 @@ -from datetime import datetime - -def new(last): - try: - return int(last)+1 - except Exception as e: - return datetime.now().strftime("%Y%m%d")+"0001" diff --git a/librevax.py b/librevax.py index 98955eb..8444187 100644 --- a/librevax.py +++ b/librevax.py @@ -11,8 +11,6 @@ from datetime import datetime import json, sqlite3 import advice, auth, inventory, multicenter, patient, personnel, transaction, vaccination -from config import cid - app=Flask(__name__) app.config.from_file("config/config.json", load=json.load) @@ -358,10 +356,10 @@ def patient_view(action, pid=None): else: raise Exception("Invalid parameter") elif(action=="new"): - (ok, last)=patient.list(cursor) + (ok, last)=patient.last(cursor) if(not ok): - raise exception(last) - data={"cid": cid.new(last)} + raise Exception(last) + data={"lastCid": last["cid"]} (ok, center)=multicenter.list(cursor) if(not ok): raise exception(center) diff --git a/patient.py b/patient.py index c553db1..8286581 100644 --- a/patient.py +++ b/patient.py @@ -75,9 +75,10 @@ def note(cursor, pid, data): def last(cursor, col=None, mid=""): try: if(col=="cid"): - result=cursor.execute("SELECT * FROM patients ORDER BY ? DESC LIMIT 1 AND mid LIKE ?", (cid, "%"+mid+"%")) + result=cursor.execute("SELECT * FROM patients WHERE mid LIKE ? ORDER BY cid DESC LIMIT 1", ("%"+mid+"%",)) else: - result=cursor.execute("SELECT * FROM patients ORDER BY ? DESC LIMIT 1 AND mid LIKE ?", (pid, "%"+mid+"%")) + result=cursor.execute("SELECT * FROM patients WHERE mid LIKE ? ORDER BY pid DESC LIMIT 1", ("%"+mid+"%",)) return (True, result.fetchone()) except Exception as e: + raise(e) return (False, e) diff --git a/static/card-id.js b/static/card-id.js new file mode 100644 index 0000000..b6827ee --- /dev/null +++ b/static/card-id.js @@ -0,0 +1,12 @@ +arr=lastCid.trim().split(/(\d+)/) +console.log(arr) +for(i=arr.length; i>0; i--){ + n=Number.parseInt(arr[i]) + if(!Number.isNaN(n)){ + n++ + arr[i]=n + break + } +} +lastCid=arr.join("") +document.getElementById("cid").value=lastCid diff --git a/templates/base.html b/templates/base.html index 459e2f2..931794d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -67,5 +67,9 @@ You should have received a copy of the GNU General Public License along with Lib + {% if data and data["lastCid"] %} + + + {% endif %} diff --git a/templates/patient-edit.html b/templates/patient-edit.html index a68d229..d9ef882 100644 --- a/templates/patient-edit.html +++ b/templates/patient-edit.html @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with Lib
- +