]> Softwares of Agnibho - librevax.git/commitdiff
Card ID race condition
authorAgnibho Mondal <mondal@agnibho.com>
Mon, 26 Feb 2024 21:24:51 +0000 (02:54 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Mon, 26 Feb 2024 21:24:51 +0000 (02:54 +0530)
librevax.py
templates/base.html
templates/patient-edit.html

index 41c87d9316596356f42233fad5530a38a415ef47..8e6363fb6c29ed3ff959bdc4ba0b64179a9ace5f 100644 (file)
@@ -378,7 +378,18 @@ def patient_edit(pid=None):
         if(pid is None):
             (ok, data)=patient.create(cursor, request.form)
             if(not ok):
-                raise Exception(data)
+                if(isinstance(data, sqlite3.IntegrityError)):
+                    data=request.form
+                    (ok, center)=multicenter.list(cursor)
+                    if(not ok):
+                        raise exception(center)
+                    (ok, last)=patient.last(cursor)
+                    if(not ok):
+                        raise Exception(last)
+                    data.lastCid=last["cid"]
+                    return render_template("patient-edit.html", data=data, center=center, action="uniq")
+                else:
+                    raise Exception(data)
             pid=data
         else:
             (ok, data)=patient.update(cursor, pid, request.form)
index 931794d8cde0c3009946a9ee80d8fb9f607e3c4a..459e2f2ee34e0fbc600d48b382e8678666664a81 100644 (file)
@@ -67,9 +67,5 @@ 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 3a4b3979f6ef5a56c11d2c8d008c365674565a2b..9fadb439f503f2494be80e90aba821ca5fe12f44 100644 (file)
@@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with Lib
 
 {% block content %}
 <div class="content">
-  <form method="post">
+  <form method="post" id="form-edit">
     <div class="mb-2 row">
       <label class="form-label col-sm-3">Card ID</label>
       <div class="col-sm-9">
@@ -91,6 +91,17 @@ You should have received a copy of the GNU General Public License along with Lib
     <button type="submit" class="btn btn-primary">Save</button>
   </form>
 </div>
+{% if data["lastCid"] %}
+<script>lastCid="{{data["lastCid"]}}"</script>
+<script src="/static/card-id.js"></script>
+{% endif %}
+{% if action=="uniq" %}
+<script>
+  if(confirm("Card ID already exists. Resubmit with new card ID?\n"+lastCid)){
+    document.getElementById("form-edit").submit()
+  }
+</script>
+{% endif %}
 <script>
   function insertByAge(){
     age=prompt("Enter age:")