]> Softwares of Agnibho - pdosage.git/commitdiff
Added update function
authorAgnibho Mondal <mail@agnibho.com>
Sat, 10 Dec 2016 16:43:32 +0000 (22:13 +0530)
committerAgnibho Mondal <mail@agnibho.com>
Sat, 10 Dec 2016 16:43:32 +0000 (22:13 +0530)
.gitignore
index.html
prepare.js
src/data/furosemide.json [new file with mode: 0644]
src/main.js
src/routine.js

index af1f85fe00dbe03e5a5ec3312081c5016da5f231..fc561ecc3057f50255705a0be622f0b434e8818a 100644 (file)
@@ -3,4 +3,4 @@ node_modules/
 dist/
 npm-debug.log
 todo.org
-src/dosage.json
\ No newline at end of file
+src/data.json
\ No newline at end of file
index 77a01d7b7ff111ed31e7b6052832fea3f5afb6dc..517db77f07d30e97e77f044fd50a1fd658e8086b 100755 (executable)
@@ -31,6 +31,9 @@
        <link rel="icon" href="dist/logo.png">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+       <script>
+        var VERSION="0.0.1";
+       </script>
        <style>
         .loader {
             position: absolute;
     <body>
        <div class="loader"></div>
        <div class="container" style="display:none">
+           <div id="notify" style="position:fixed;margin:10px;z-index:10;display:none">
+               <div id="notify-alert" class="alert alert-info alert-dismissible">
+                   <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
+                   <h4><span id="notify-text"></span> <a id="notify-link" href="#" class="btn btn-success btn-lg">Download</a></h4>
+               </div>
+           </div>
            <div class="text-primary">
                <div class="jumbotron">
                    <h1>PDosage</h1>
index 89f2a67dfa6cdc878a3948ed4e12fedc22cdca53..f6a0b79659ea4683270f6443569d45ab6b771fc1 100644 (file)
@@ -1,7 +1,9 @@
 var DATA_SRC="./src/data/";
-var DATA_FILE="./src/dosage.json";
+var DATA_FILE="./src/data.json";
 var fs=require("fs");
 
+var bigData={id:"com.agnibho.com.pdosage.data", timestamp: Date.now(), version: 0, dosage:[]};
+
 if(process.argv[2]=="watch"){
     fs.watch(DATA_SRC, jsonCat);
 }
@@ -11,12 +13,11 @@ else{
 
 function jsonCat(){
     console.log("Joining JSON data files");
-    var bigData=[]
     var files=fs.readdirSync(DATA_SRC);
     for(var i=0; i<files.length; i++){
        if(files[i].indexOf(".")!==0){
            try{
-               bigData=bigData.concat(JSON.parse(fs.readFileSync(DATA_SRC+files[i], "utf8")));
+               bigData.dosage=bigData.dosage.concat(JSON.parse(fs.readFileSync(DATA_SRC+files[i], "utf8")));
            }
            catch(e){
                console.log(e);
diff --git a/src/data/furosemide.json b/src/data/furosemide.json
new file mode 100644 (file)
index 0000000..8e6b8f4
--- /dev/null
@@ -0,0 +1,98 @@
+{
+    "name": "Furosemide",
+    "form": [
+       {
+           "mode": "Oral",
+           "gen": true,
+           "dose": [
+               {
+                   "perKg": [
+                       2,
+                       6
+                   ],
+                   "limit": [
+                       40,
+                       80
+                   ],
+                   "unit": "mg",
+                   "txt": "per day q 12 hr"
+               },
+               {
+                   "perKg": [
+                       1,
+                       2
+                   ],
+                   "limit": [
+                       40,
+                       80
+                   ],
+                   "unit": "mg",
+                   "txt": "per dose q 6-8 hr in emergency"
+               }
+           ]
+       },
+       {
+           "mode": "Oral",
+           "gen": true,
+           "range": [
+               {
+                   "min": "12y",
+                   "dose": {
+                       "val": 250,
+                       "unit": "mg",
+                       "txt": "q 6 hr in oliguria, max 2gm/dose"
+                   }
+               }
+           ]
+       },
+       {
+           "mode": "IV",
+           "gen": true,
+           "dose": {
+               "perKg": [
+                   1,
+                   3
+               ],
+               "limit": [
+                   20,
+                   40
+               ],
+               "unit": "mg",
+               "txt": "per day",
+               "comment": "@ 0.1-1.0 mg/kg/hr"
+           }
+       },
+       {
+           "mode": "Tab",
+           "content": "40mg",
+           "dose": {
+               "perKg": [
+                   2,
+                   6
+               ],
+               "limit": [
+                   1,
+                   2
+               ],
+               "unit": "tab",
+               "txt": "per day"
+           }
+       },
+       {
+           "mode": "IV",
+           "content": "10mg/ml",
+           "dose": {
+               "perKg": [
+                   0.2,
+                   0.6
+               ],
+               "limit": [
+                   4,
+                   8
+               ],
+               "unit": "ml",
+               "txt": "per day"
+           }
+       }
+    ]
+}
index 914247c4b4bff912dd23c0a4bc8d180f27ed7ff8..178404b0ce098d0de67041eecef3bc1ae59f5886 100644 (file)
@@ -37,7 +37,7 @@ import "bootstrap-validator";
 
 //Backend files
 import Dosage from "./dosage.js";
-import data from "./dosage.json";
+import data from "./data.json";
 
 //Vue Components
 import Vue from "vue";
@@ -48,7 +48,6 @@ import CalculatorView from "./CalculatorView.vue";
 import AboutView from "./AboutView.vue";
 
 //Start app
-var dosage=new Dosage(data);
 new Vue({
     el: "#app",
     components: {
@@ -60,7 +59,7 @@ new Vue({
     },
     data: {
        patient: {age: {y:null, m:null, d:null}, wt:null},
-       dosage: dosage,
+       dosage: "",
        favs: "[]"
     },
     created:function(){
@@ -72,6 +71,13 @@ new Vue({
                this.favs=["Paracetamol", "Levosalbutamol", "Domperidone", "Drotaverine", "Ranitidine"];
            }
        }
+       try{
+           this.dosage=new Dosage(JSON.parse(localStorage.getItem("pdosage_data")).dosage);
+       }
+       catch(e){
+           this.dosage=new Dosage(data.dosage);
+           localStorage.setItem("pdosage_data", data);
+       }
     }
 });
 
index 26f2aef51d8867596903270625dc1210e7465b80..f334d446678932fa587370a0a96792a83bb0d2bf 100644 (file)
@@ -29,6 +29,9 @@ $(document).ready(function(){
     $(".loader").remove();
     $(".container").fadeIn();
 
+    //Insert version code
+    $(".version").text(VERSION);
+
     //Update copyright
     $(".copyright").each(function(){
        if(new Date().getFullYear()>$(this).data("start")){
@@ -46,24 +49,63 @@ $(document).ready(function(){
            this.dispatchEvent(new Event("input"));
        });
     });
-    
-    //Change focus after number input
-    $(".jump-focus").on("input", function(){
-       if($(this).val().length == $(this).prop("maxlength")){
-           var all=$("input").toArray();
-           var i=all.indexOf(this)+1;
-           $(all[i]).focus().select();
-       }
+
+    //Notifications
+    $(window).resize(function(){
+       $("#notify").width($(".container").width()-20);
+    });
+    $(window).scroll(function(){
+       $("#notify").width($(".container").width()-20);
     });
 
-    //Defocus after input finished
-    $(".stop-focus").on("input", function(){
-       if($(this).val().length == $(this).prop("maxlength")){
-           $(this).blur();
-           var target=$($(this).data("ref"));
-           $("html, body").animate({
-               scrollTop: $(target).offset().top
-           }, 1000);
+    //Parse app info from server
+    $.get("https://code.agnibho.com/pdosage/info.json", function(data){
+       var vCurr=VERSION.split(".").map(Number);
+       var vLtst=data.latest.split(".").map(Number);
+       
+       if(isBiggerThan(data.latest, VERSION)){
+           $("#notify").slideDown();
+           $("#notify").width($(".container").width()-20);
+           $("#notify-text").text("A new version of PDosage is available.");
+           if(document.URL.indexOf("http://")==-1 && document.URL.indexOf("https://")==-1){
+               if(/(android)/i.test(navigator.userAgent)){
+                   $("#notify-link").attr("href", data.apk);
+                   $("#notify-link").text("Download");
+               }
+               else{
+                   $("#notify-link").attr("href", data.url);
+                   $("#notify-link").text("Load");
+               }
+           }
+           else{
+               $("#notify-link").attr("href", data.url);
+               $("#notify-link").text("Load");
+           }
+       }
+       
+       try{
+           if(data.data.latest>JSON.parse(localStorage.getItem("pdosage_data")).version){
+               $.get(data.data.src, function(d){
+                   localStorage.setItem("pdosage_data", JSON.stringify(d));
+               });
+           }
        }
+       catch(e){}
     });
+
+    //Compare versions
+    function isBiggerThan(v1, v2){
+       while(v1.length<v2.length){
+           v1.push(0);
+       }
+       while(v2.length<v1.length){
+           v2.push(0);
+       }
+       for(var i=0; i<v1.length; i++){
+           if(v1[i]>v2[i]){
+               return true;
+           }
+       }
+       return false;
+    }
 });