]>
Softwares of Agnibho - simpleipd.git/blob - www/res/calc.js
58eaa6eec9bf55534c7863f1374f898d58e7fe0b
1 function entrySort(i
, j
){
13 var clinical
={pr
:[], rr
:[], temperature
:[], spo2
:[], sbp
:[], dbp
:[]};
16 var clinDict
={pr
: "Pulse Rate", rr
: "Respiratory Rate", temperature
: "Temperature", spo2
: "SpO2", sbp
: "Systolic BP", dbp
: "Diastolic BP"}
18 $(document
).ready(function(){
19 var ctx1
=$("#clinChart")[0].getContext("2d");
20 var ctx2
=$("#reportsChart")[0].getContext("2d");
21 var ctx3
=$("#drugsChart")[0].getContext("2d");
22 $.getJSON("chart.php?pid="+pid
+"&get=nursing", function(data
){
24 $.each(data
, function(num
, entry
){
26 stamp
=new Date(entry
.date
+" "+entry
.time
);
27 if(entry
.io_from
!="" && entry
.io_to
!=""){
28 start
=new Date(entry
.date
+" "+entry
.io_from
);
29 end
=new Date(entry
.date
+" "+entry
.io_to
);
30 if(!isNaN(start
.getTime()) && !isNaN(end
.getTime())){
31 if(end
.getTime()-start
.getTime()>24*60*60*1000){
38 start
.setDate(start
.getDate()-1);
40 io
.push({start
: start
, end
: end
, in: entry
.intake
, out
: entry
.output
});
45 clinical
.pr
.push([stamp
, entry
.pr
]);
48 clinical
.rr
.push([stamp
, entry
.rr
]);
50 if(entry
.temperature
){
51 clinical
.temperature
.push([stamp
, entry
.temperature
]);
54 clinical
.spo2
.push([stamp
, entry
.spo2
]);
57 clinical
.sbp
.push([stamp
, entry
.bp
.split("/")[0]]);
60 clinical
.dbp
.push([stamp
, entry
.bp
.split("/")[1]]);
67 io
.forEach(function(i
){
68 if(ioGap
<(24*60*60*1000)){
69 ioBuff
=ioGap
+(i
.end
.getTime()-i
.start
.getTime());
70 if(ioBuff
>(24*60*60*1000)){
71 frac
=((24*60*60*1000)-ioGap
)/(ioBuff
-ioGap
);
72 ioGap
=(24*60*60*1000);
78 approxIn
=approxIn
+(Number(i
.in)*frac
);
79 approxOut
=approxOut
+(Number(i
.out
)*frac
);
81 $(".ioGap").each(function(){
82 $(this).text(Math
.round(ioGap
/3600000));
84 $("#approxIn").text(Math
.round(approxIn
));
85 $("#approxOut").text(Math
.round(approxOut
));
86 $("#ioData").removeClass("d-none");
89 $("#ioInconsistent").text(flag
);
90 $("#ioAlert").removeClass("d-none");
95 $.getJSON("chart.php?pid="+pid
+"&get=physician", function(data
){
96 $.each(data
, function(num
, entry
){
97 stamp
=new Date(entry
.date
+" "+entry
.time
);
99 clinical
.pr
.push([stamp
, entry
.pr
]);
102 clinical
.rr
.push([stamp
, entry
.rr
]);
104 if(entry
.temperature
){
105 clinical
.temperature
.push([stamp
, entry
.temperature
]);
108 clinical
.spo2
.push([stamp
, entry
.spo2
]);
111 clinical
.sbp
.push([stamp
, entry
.bp
.split("/")[0]]);
114 clinical
.dbp
.push([stamp
, entry
.bp
.split("/")[1]]);
117 Object
.keys(clinical
).forEach(function(i
){
118 clinical
[i
].sort(entrySort
);
119 $("#clinVar").html($("#clinVar").html()+"<option value="+i
+">"+clinDict
[i
]+"</option>");
123 $.getJSON("chart.php?pid="+pid
+"&get=reports", function(data
){
125 $.each(data
, function(num
, entry
){
127 ajax
=$.getJSON("forms/"+entry
.form
+".schema.json", function(data
){
128 stamp
=new Date(entry
.date
+" "+entry
.time
);
129 Object
.keys(entry
).forEach(function(i
){
130 name
=entry
.form
+"-"+i
;
131 if(entry
[i
] && !isNaN(entry
[i
])){
132 if(!Array
.isArray(reports
[name
])){
133 reportsDict
[name
]=data
.properties
[i
].description
;
136 reports
[name
].push([stamp
, entry
[i
]]);
140 ajaxArray
.push(ajax
);
143 $.when
.apply($,ajaxArray
).then(function(){
144 reports
=Object
.keys(reports
).sort().reduce(function(obj
, key
){
145 obj
[key
]=reports
[key
];
148 Object
.keys(reports
).forEach(function(i
){
149 reports
[i
].sort(entrySort
);
150 $("#reportsVar").html($("#reportsVar").html()+"<option value="+i
+">"+reportsDict
[i
]+"</option>");
155 $.getJSON("chart.php?pid="+pid
+"&get=treatment", function(data
){
156 $.each(data
, function(num
, entry
){
158 treat
[0]=entry
.drug
+" "+entry
.dose
+" "+entry
.route
+" "+entry
.frequency
;
159 treat
[1]=$.parseJSON(entry
.administer
);
160 treatment
[entry
.drug
]=treat
;
162 Object
.keys(treatment
).forEach(function(i
){
163 $("#drugVar").html($("#drugVar").html()+"<option>"+i
+"</option>");
168 $("#clinVar").change(function(){
169 $("#clinData").html("");
170 param
=$("#clinVar").val();
171 data
={labels
: [], datasets
: [{ label
:clinDict
[param
], data
: [], fill
: false, borderColor
: "rgb(75, 192, 192)", tension
: 0.1 }]};
172 clinical
[param
].forEach(function(i
){
173 data
.labels
.push(i
[0].toLocaleString());
174 data
.datasets
[0].data
.push(i
[1]);
175 $("#clinData").html($("#clinData").html()+"<tr><td>"+i
[0].toLocaleString()+"</td><td>"+i
[1]+"</td></tr>");
180 if(data
.datasets
[0].data
.length
>1){
181 clinChart
=new Chart(ctx1
, {
187 $("#reportsVar").change(function(){
188 $("#reportsData").html("");
189 param
=$("#reportsVar").val();
190 data
={labels
: [], datasets
: [{ label
: reportsDict
[param
], data
: [], fill
: false, borderColor
: "rgb(75, 192, 192)", tension
: 0.1 }]};
191 reports
[param
].forEach(function(i
){
192 data
.labels
.push(i
[0].toLocaleString());
193 data
.datasets
[0].data
.push(i
[1]);
194 $("#reportsData").html($("#reportsData").html()+"<tr><td>"+i
[0].toLocaleString()+"</td><td>"+i
[1]+"</td></tr>");
196 reportsChart
.destroy();
198 if(data
.datasets
[0].data
.length
>1){
199 reportsChart
=new Chart(ctx2
, {
206 $("#drugVar").change(function(){
207 param
=$("#drugVar").val();
208 data
={labels
: [], datasets
: [{ label
: param
, data
: [], backgroundColor
: "rgb(75, 192, 192)"}]};
209 $("#drugData1").html(treatment
[param
][0]);
210 $("#drugData2").html("");
211 treatment
[param
][1].forEach(function(i
){
212 // HARDCODED FIX FOR CORRUPTED DATA DUE TO PREVIOUS BUG
216 // PLAN TO REMOVE IN FUTURE
218 data
.datasets
[0].data
.push({x
:d
.getFullYear()+("0"+d
.getMonth()).slice(-2)+("0"+d
.getDate()).slice(-2), y
:(24-d
.getHours())});
219 $("#drugData2").html($("#drugData2").html()+" <span class='badge badge-success'>"+d
.toLocaleString()+"</span>");
222 drugsChart
.destroy();
224 if(data
.datasets
[0].data
.length
>0){
225 drugsChart
=new Chart(ctx3
, {
230 pointHoverRadius
: 10,
236 callback: function(val
, index
){
237 if(Number
.isInteger(val
)){
239 return new Date(val
.slice(0,4)+"-"+val
.slice(4,6)+"-"+val
.slice(6,8)).toLocaleDateString();
249 callback: function(val
, index
){
250 return (24-val
)+":00";