]> Softwares of Agnibho - librevax.git/commitdiff
New CID by JS
authorAgnibho Mondal <mondal@agnibho.com>
Wed, 10 Jan 2024 20:08:15 +0000 (01:38 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Wed, 10 Jan 2024 20:08:15 +0000 (01:38 +0530)
etc/__init__.py [deleted file]
etc/cid.py.example [deleted file]
librevax.py
patient.py
static/card-id.js [new file with mode: 0644]
templates/base.html
templates/patient-edit.html

diff --git a/etc/__init__.py b/etc/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/etc/cid.py.example b/etc/cid.py.example
deleted file mode 100644 (file)
index 47b5a18..0000000
+++ /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"
index 98955eb7d8a2a62dee7efe5eab7b4d92fbc07f0b..8444187e10d0b6b7140a9d287d96c47e8f71f97f 100644 (file)
@@ -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)
index c553db1fb01a12cea013b2d263a5ef828a2d7d71..82865818c1021921ac15e0268cd72e1911f8bd7c 100644 (file)
@@ -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 (file)
index 0000000..b6827ee
--- /dev/null
@@ -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
index 459e2f2ee34e0fbc600d48b382e8678666664a81..931794d8cde0c3009946a9ee80d8fb9f607e3c4a 100644 (file)
@@ -67,5 +67,9 @@ You should have received a copy of the GNU General Public License along with Lib
     </div>
     <script src="/static/bootstrap/js/bootstrap.bundle.min.js"></script>
     <script src="/static/script.js"></script>
+    {% if data and data["lastCid"] %}
+    <script>lastCid="{{data["lastCid"]}}"</script>
+    <script src="/static/card-id.js"></script>
+    {% endif %}
   </body>
 </html>
index a68d2296773ffd268ee8aa0e97377ff24491f91a..d9ef882de542c8000c7d39fcb9499f3dba113d3b 100644 (file)
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with Lib
     <div class="mb-2 row">
       <label class="form-label col-sm-3">Card ID</label>
       <div class="col-sm-9">
-        <input name="cid" placeholder="Card ID" required class="form-control" value="{{data["cid"]}}">
+        <input id="cid" name="cid" placeholder="Card ID" required class="form-control" value="{{data["cid"]}}">
       </div>
     </div>
     <div class="mb-2 row">