From e2e33b8bf997df88b79a640493d9705563d3537d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Ates?= Date: Mon, 9 Nov 2015 16:32:42 +0100 Subject: [PATCH] Js to populate not checked alerts in controlbar. --- src/biomon/static/biomon/js/biomon.js | 96 +++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/biomon/static/biomon/js/biomon.js b/src/biomon/static/biomon/js/biomon.js index b1992b9..99f5c85 100644 --- a/src/biomon/static/biomon/js/biomon.js +++ b/src/biomon/static/biomon/js/biomon.js @@ -19,6 +19,10 @@ (function($) { $(function() { + + var + _alerts_not_checked_url = "/alerts/livedata_provider/episodes_not_checked?"; + /* Common settings */ @@ -27,6 +31,8 @@ window.location.href=$(this).attr('target'); }); $("select").selectmenu(); + $('div#controlbar').hide(); + $('div#content-1').css({height: "100%"}); /* Refresh datetime in header @@ -57,5 +63,95 @@ } }, }); + + var _after; + function _build_alert_block(alert){ + var + seq_id = alert[0], + level = alert[3][0], + metric = alert[3][1], + operator = alert[3][2], + threshold = alert[3][3], + duration = alert[4], + start_date = alert[1], + end_date = alert[2], + checked = alert[6], + id = alert[7], + patient_id = alert[8], + patient_display_name = alert[9], + patient_monitoring_place = alert[10]; + content = '
' + + '

' + patient_display_name + '

' + + '

' + patient_monitoring_place + '

' + + '

'; + + if ( metric == 'HR' ){ + content += ''; + } else if ( metric == 'T' ){ + content += ''; + } else { + content += ''; + } + content += ' ' + operator + ' ' + threshold + + '

' + + '
'; + return content; + }; + function _refresh_all_alerts(){ + var target = _alerts_not_checked_url; + if (_after) { + /* Encode date in iso format */ + target += $.param({after: _after}) + '&' + } + target = UTILS.fresh_query(target); + var not_checked = []; + function get_not_checked(target) { + return $.ajax({ + type: 'Get', + url: target, + success: function(data) { + not_checked = data.slice(); + }, + error: function() { + UTILS.show_message(gettext("Database offline.")); + } + }) + } + + function run(){ + $.when(get_not_checked(target)).done(function(a1){ + var content = '' + if ( not_checked.length ){ + _after = not_checked[0][2]; + for ( var i = 0; i < not_checked.length; i++ ) { + content += _build_alert_block(not_checked[i]); + } + $('div#controlbar').empty(); + $('div#controlbar').append(content); + $('div#content-1').animate({ + height: "88%", + }, 300, "linear", function() { + $('div#controlbar').fadeIn(); + } + ); + } else { + $('div#controlbar').fadeOut(500, function(){ + $('div#content-1').animate({ + height: "100%", + }, 300, "linear"); + }); + } + }); + } + run() + setTimeout(function(){ + _refresh_all_alerts(); + }, 2000); + }; + _refresh_all_alerts(); + $(document).on('click', 'div.alert-message', function(e) { + window.location.href = '/patient/' + $(this).attr('patient-id'); + }); }) })(jQuery);