]> Softwares of Agnibho - simpleipd.git/commitdiff
Added basic chart
authorAgnibho Mondal <mondal@agnibho.com>
Fri, 28 May 2021 11:57:19 +0000 (17:27 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Fri, 28 May 2021 11:57:19 +0000 (17:27 +0530)
access.json
www/chart.php [new file with mode: 0644]
www/res/calc.js [new file with mode: 0644]

index 8136e38a4e20ce6227a9736acbabff0e8951d996..065b9de564f668ec2ac948468ce1cdf05bfa4b0a 100644 (file)
         "tech": "view",
         "clerk": "view"
     },
+    "chart": {
+        "admin": "view",
+        "visiting": "view",
+        "resident": "view",
+        "nursing": "view",
+        "lab": "view",
+        "tech": "view",
+        "clerk": "view"
+    },
     "printdata": {
         "admin": "view",
         "visiting": "view",
diff --git a/www/chart.php b/www/chart.php
new file mode 100644 (file)
index 0000000..073357a
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+require(dirname(__DIR__)."/require.php");
+
+if(isSet($_GET["pid"])){
+  $pid=$_GET["pid"];
+  if(!empty($_GET["get"]) && $_GET["get"]=="nursing"){
+    $nursing=[];
+    $nursingArray=$db->getAllData($pid, "nursing");
+    while($item=$nursingArray->fetchArray()){
+      array_push($nursing, json_decode($item["data"]));
+    }
+    echo json_encode($nursing);
+    exit();
+  }
+  if(!empty($_GET["get"]) && $_GET["get"]=="physician"){
+    $physician=[];
+    $physicianArray=$db->getAllData($pid, "physician");
+    while($item=$physicianArray->fetchArray()){
+      array_push($physician, json_decode($item["data"]));
+    }
+    echo json_encode($physician);
+    exit();
+  }
+  if(!empty($_GET["get"]) && $_GET["get"]=="reports"){
+    $reports=[];
+    $reportsArray=$db->getAllData($pid, "reports");
+    while($item=$reportsArray->fetchArray()){
+      array_push($reports, json_decode($item["data"]));
+    }
+    echo json_encode($reports);
+    exit();
+  }
+  if(!empty($_GET["get"]) && $_GET["get"]=="treatment"){
+    $treatment=[];
+    $treatmentArray=$db->getDrugs($pid);
+    while($item=$treatmentArray->fetchArray()){
+      if($item["omit"]==0){
+        array_push($treatment, $item);
+      }
+    }
+    echo json_encode($treatment);
+    exit();
+  }
+}
+?>
+<!DOCTYPE html>
+<html>
+  <head>
+    <?php include(CONFIG_LIB."head.php");?>
+    <title>View Info</title>
+  </head>
+  <body>
+    <div class="container">
+      <?php include(CONFIG_LIB."top.php");?>
+      <div class="alert alert-warning"><p>This page contains experimental features. Please double check for the time being.</p></div>
+      <h1>Patient Data</h1>
+      <?php echo getInfo($pid);?>
+      <hr>
+      <div class="alert alert-light d-none" id="ioAlert">Possible inconsistent intake output data. (<span id="ioInconsistency"></span>)</div>
+      <div class="card d-none" id="ioData">
+        <div class="card-body">
+          <h4 class="card-heading">Intake/Output</h4>
+          <ul>
+            <li>Approximate <span class="ioGap"></span> hours intake: <span id="approxIn"></span> ml</li>
+            <li>Approximate <span class="ioGap"></span> hours output: <span id="approxOut"></span> ml</li>
+          </ul>
+        </div>
+      </div>
+      <table class="table">
+        <thead>
+          <tr><th>Time</th><th><select id="clinVar"><option disabled selected>--select--</option></select></th></tr>
+        </thead>
+        <tbody id="clinData">
+        </tbody>
+      </table>
+      <table class="table">
+        <thead>
+          <tr><th>Time</th><th><select id="reportsVar"><option disabled selected>--select--</option></select></th></tr>
+        </thead>
+        <tbody id="reportsData">
+        </tbody>
+      </table>
+      <table class="table">
+        <tr><td><select id="drugVar"><option disabled selected>--select--</option></select></td><td id="drugData1"></td><td id="drugData2"></td></tr>
+      </table>
+      <?php include(CONFIG_LIB."foot.php");?>
+      <script>var pid="<?php echo $pid;?>"</script>
+      <script src="res/calc.js"></script>
+    </div>
+  </body>
+</html>
diff --git a/www/res/calc.js b/www/res/calc.js
new file mode 100644 (file)
index 0000000..ebd31c2
--- /dev/null
@@ -0,0 +1,168 @@
+function entrySort(i, j){
+  if(i[0]==j[0]){
+    return 0;
+  }
+  else if(i[0]>j[0]){
+    return -1;
+  }
+  else{
+    return 1;
+  }
+}
+var io=[];
+var clinical={pr:[], rr:[], spo2:[], sbp:[], dbp:[]};
+var reports={};
+var treatment={};
+$(document).ready(function(){
+  $.getJSON("chart.php?pid="+pid+"&get=nursing", function(data){
+    flag="";
+    $.each(data, function(num, entry){
+      // INTAKE-OUTPUT
+      stamp=moment(entry.date+" "+entry.time);
+      if(entry.io_from!="" && entry.io_to!=""){
+        start=moment(entry.date+" "+entry.io_from);
+        end=moment(entry.date+" "+entry.io_to);
+        if(start.isValid() && end.isValid()){
+          if(end.format("X")-start.format("X")>24*60*60){
+            flag=entry.date;
+          }
+          if(start==end){
+            flag=entry.date;
+          }
+          if(start>end){
+            start.subtract(1, "days");
+          }
+          io.push({start: start, end: end, in: entry.intake, out: entry.output});
+        }
+      }
+      // CLINICAL
+      if(entry.pr){
+        clinical.pr.push([stamp, entry.pr]);
+      }
+      if(entry.rr){
+        clinical.rr.push([stamp, entry.rr]);
+      }
+      if(entry.spo2){
+        clinical.spo2.push([stamp, entry.spo2]);
+      }
+      if(entry.bp){
+        clinical.sbp.push([stamp, entry.bp.split("/")[0]]);
+      }
+      if(entry.bp){
+        clinical.dbp.push([stamp, entry.bp.split("/")[1]]);
+      }
+    });
+    // INTAKE-OUTPUT
+    approxIn=0;
+    approxOut=0;
+    ioGap=0;
+    io.forEach(function(i){
+      if(ioGap<(24*60*60)){
+        ioBuff=ioGap+(i.end.format("X")-i.start.format("X"));
+        if(ioBuff>(24*60*60)){
+          frac=(24-ioGap)/(ioBuff-ioGap);
+          ioGap=(24*60*60);
+        }
+        else{
+          frac=1;
+          ioGap=ioBuff;
+        }
+        approxIn=approxIn+(Number(i.in)*frac);
+        approxOut=approxOut+(Number(i.out)*frac);
+        if(flag==""){
+          $(".ioGap").each(function(){
+            $(this).text(ioGap/3600);
+          });
+          $("#approxIn").text(approxIn);
+          $("#approxOut").text(approxOut);
+          $("#ioData").removeClass("d-none");
+        }
+        else{
+          $("#ioInconsistent").text(flag);
+          $("#ioAlert").removeClass("d-none");
+        }
+      }
+    });
+    // CLINICAL
+    $.getJSON("chart.php?pid="+pid+"&get=physician", function(data){
+      $.each(data, function(num, entry){
+        stamp=moment(entry.date+" "+entry.time);
+        if(entry.pr){
+          clinical.pr.push([stamp, entry.pr]);
+        }
+        if(entry.rr){
+          clinical.rr.push([stamp, entry.rr]);
+        }
+        if(entry.spo2){
+          clinical.spo2.push([stamp, entry.spo2]);
+        }
+        if(entry.bp){
+          clinical.sbp.push([stamp, entry.bp.split("/")[0]]);
+        }
+        if(entry.bp){
+          clinical.dbp.push([stamp, entry.bp.split("/")[1]]);
+        }
+      });
+      clinical.pr.sort(entrySort);
+      Object.keys(clinical).forEach(function(i){
+        $("#clinVar").html($("#clinVar").html()+"<option>"+i+"</option>");
+      });
+    });
+    // REPORTS
+    $.getJSON("chart.php?pid="+pid+"&get=reports", function(data){
+      $.each(data, function(num, entry){
+        stamp=moment(entry.date+" "+entry.time);
+        Object.keys(entry).forEach(function(i){
+          if(entry[i] && !isNaN(entry[i])){
+            if(!Array.isArray(reports[i])){
+              reports[i]=[];
+            }
+            reports[i].push([stamp, entry[i]]);
+          }
+        });
+      });
+      reports=Object.keys(reports).sort().reduce(function(obj, key){
+          obj[key]=reports[key];
+          return obj;
+        },{});
+      Object.keys(reports).forEach(function(i){
+        $("#reportsVar").html($("#reportsVar").html()+"<option>"+i+"</option>");
+      });
+    });
+    // TREATMENT
+    $.getJSON("chart.php?pid="+pid+"&get=treatment", function(data){
+      $.each(data, function(num, entry){
+        treat=[];
+        treat[0]=entry.drug+" "+entry.dose+" "+entry.route+" "+entry.frequency;
+        treat[1]=$.parseJSON(entry.administer);
+        treatment[entry.drug]=treat;
+      });
+      Object.keys(treatment).forEach(function(i){
+        $("#drugVar").html($("#drugVar").html()+"<option>"+i+"</option>");
+      });
+    });
+  });
+  // EVENTS
+  $("#clinVar").change(function(){
+    $("#clinData").html("");
+    param=$("#clinVar").val();
+    clinical[param].forEach(function(i){
+      $("#clinData").html($("#clinData").html()+"<tr><td>"+i[0].format("MMM D, HH:mm")+"</td><td>"+i[1]+"</td></tr>");
+    });
+  });
+  $("#reportsVar").change(function(){
+    $("#reportsData").html("");
+    param=$("#reportsVar").val();
+    reports[param].forEach(function(i){
+      $("#reportsData").html($("#reportsData").html()+"<tr><td>"+i[0].format("MMM D, HH:mm")+"</td><td>"+i[1]+"</td></tr>");
+    });
+  });
+  $("#drugVar").change(function(){
+    param=$("#drugVar").val();
+    $("#drugData1").html(treatment[param][0]);
+    $("#drugData2").html("");
+    treatment[param][1].forEach(function(i){
+      $("#drugData2").html($("#drugData2").html()+" <span class='badge badge-success'>"+moment(i*1000).format("MMM D HH:mm")+"</span>");
+    });
+  });
+});