aboutsummaryrefslogtreecommitdiffstats
path: root/97suifangqa/apps
diff options
context:
space:
mode:
Diffstat (limited to '97suifangqa/apps')
-rw-r--r--97suifangqa/apps/indicator/static/css/edit_history_data.css175
-rw-r--r--97suifangqa/apps/indicator/static/css/sheet_default.css2
-rw-r--r--97suifangqa/apps/indicator/static/javascripts/card_chart.js2
-rw-r--r--97suifangqa/apps/indicator/static/javascripts/edit_history_data.js228
-rw-r--r--97suifangqa/apps/indicator/templates/indicator/SheetDefault.html2
-rw-r--r--97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html147
-rw-r--r--97suifangqa/apps/indicator/templates/indicator/test.html9
-rw-r--r--97suifangqa/apps/indicator/tools.py76
-rw-r--r--97suifangqa/apps/indicator/views.py155
9 files changed, 631 insertions, 165 deletions
diff --git a/97suifangqa/apps/indicator/static/css/edit_history_data.css b/97suifangqa/apps/indicator/static/css/edit_history_data.css
index 12bf73b..9775539 100644
--- a/97suifangqa/apps/indicator/static/css/edit_history_data.css
+++ b/97suifangqa/apps/indicator/static/css/edit_history_data.css
@@ -1,6 +1,6 @@
#edit_history_data_container {
width: 588px;
- height: 164px;
+ height: 180px;
background-color: #FFFFFF;
border: 1px solid #94C721;
padding: 0 20px 0 20px;
@@ -29,34 +29,141 @@
color: #4A4A4A;
font-size: 14px;
}
-.edit_history_data_content .date_time {
- height: 55px;
- line-height: 55px;
+.edit_history_data_content .refer_range {
+ height: 26px;
+ line-height: 26px;
+ margin-top: 6px;
+ margin-bottom: 10px;
}
-.edit_history_data_content .date_time .time {
- margin-left: 27px;
+.edit_history_data_content .refer_range .refer_text {
+ margin-right: 8px;
}
-.edit_history_data_content .refer_range {
- height: 38px;
- line-height: 38px;
- margin-top: -6px;
+.edit_history_data_content .refer_range .refer_value {
+ margin-right: 8px;
+}
+.edit_history_data_content .edit_data {
+ line-height: 26px;
+}
+.edit_history_data_content .edit_data .date {
+ height: 26px;
+ line-height: 26px;
+}
+.edit_history_data_content .edit_data .date .date_text {
+ margin-right: 8px;
+}
+.edit_history_data_content .edit_data .data {
+ height: 26px;
+ line-height: 26px;
+}
+.edit_history_data_content .edit_data .data .prompt {
+ margin-right: 8px;
+}
+.edit_history_data_content .edit_data .state {
+ height: 26px;
+ line-height: 26px;
+ float: left;
+}
+.edit_history_data_content .edit_data .state .prompt {
+ margin-right: 8px;
+}
+.edit_history_data_content .edit_data .state .text {
+ font-weight: bold;
+}
+.edit_history_data_content .edit_data .state .normal {
+ background-color: #B8DB70;
+}
+.edit_history_data_content .edit_data .state .abnormal {
+ background-color: #FFB3B3;
+}
+.edit_history_data_content .edit_data .state .unknown {
+ background-color: #B3D9FF;
}
.edit_history_data_content .edit_data #edit_btn, .edit_history_data_content .editing_data #save_btn {
float: right;
- height: 24px;
+ height: 26px;
line-height: 22px;
padding: 1px 26px;
}
.edit_history_data_content .editing_data {
- height: 25px;
+ line-height: 26px;
display: none;
}
-.edit_history_data_content .editing_data .input_container {
+.edit_history_data_content .editing_data .date {
+ height: 26px;
+ line-height: 26px;
+ position: relative;
+ margin-bottom: 2px;
+}
+.edit_history_data_content .editing_data .date .date_text {
+ margin-right: 8px;
float: left;
}
-.edit_history_data_content .editing_data .input_container label {
+.edit_history_data_content .editing_data .date .datepicker_container {
+ width: 148px;
+ float: left;
position: relative;
- top: -1px;
+}
+.edit_history_data_content .editing_data .date .datepicker_container .valid {
+ border: 2px solid green;
+}
+.edit_history_data_content .editing_data .date .datepicker_container .invalid {
+ border: 2px solid red;
+}
+.edit_history_data_content .editing_data .date .datepicker {
+ background: #FFFFFF;
+ border: 1px solid #9C9C9C;
+ color: #B9B9B9;
+ width: 131px;
+ height: 17px;
+ line-height: 17px;
+ position: relative;
+ padding-top: 2px;
+ padding-bottom: 2px;
+}
+.edit_history_data_content .editing_data .date .ui-datepicker-trigger {
+ position: absolute;
+ top: 4px;
+ right: 8px;
+ cursor: pointer;
+}
+.edit_history_data_content .editing_data .data {
+ height: 26px;
+ line-height: 26px;
+ float: left;
+ top: 1px;
+}
+.edit_history_data_content .editing_data .data .prompt {
+ margin-right: 8px;
+ float: left;
+}
+.edit_history_data_content .editing_data .data input {
+ color: #5C5C5C;
+ background-color: #FFFFFF;
+ border: 1px solid #9C9C9C;
+}
+.edit_history_data_content .editing_data .data .valid {
+ border: 2px solid green;
+}
+.edit_history_data_content .editing_data .data .invalid {
+ border: 2px solid red;
+}
+.edit_history_data_content .editing_data .data .data_input {
+ width: 200px;
+ height: 17px;
+ line-height: 17px;
+ padding-top: 2px;
+ padding-bottom: 2px;
+ margin-right: 8px;
+}
+.edit_history_data_content .editing_data .input_container {
+ height: 26px;
+ line-height: 26px;
+ float: left;
+ top: 1px;
+}
+.edit_history_data_content .editing_data .input_container .prompt {
+ margin-right: 8px;
+ float: left;
}
.edit_history_data_content .editing_data .input_container input {
color: #5C5C5C;
@@ -64,7 +171,7 @@
border: 1px solid #9C9C9C;
}
.edit_history_data_content .editing_data .input_container .error {
- border: 1px solid red;
+ border: 2px solid red;
}
.edit_history_data_content .editing_data .input_container .edit_input_main {
width: 42px;
@@ -81,7 +188,11 @@
padding-bottom: 2px;
}
.edit_history_data_content .editing_data .add_minus_icon {
+ height: 26px;
+ line-height: 26px;
float: left;
+ padding-top: 1px;
+ padding-bottom: 1px;
margin-right: 8px;
}
.edit_history_data_content .editing_data .add_minus_icon .add_icon {
@@ -100,3 +211,35 @@
margin-top: 1px;
cursor: pointer;
}
+.edit_history_data_content .editing_data .data_unit {
+ height: 26px;
+ line-height: 26px;
+ margin-right: 8px;
+}
+.edit_history_data_content .editing_data .reason {
+ height: 26px;
+ line-height: 26px;
+ float: left;
+}
+.edit_history_data_content .editing_data .reason .prompt {
+ margin-right: 8px;
+ float: left;
+}
+.edit_history_data_content .editing_data .reason input {
+ color: #5C5C5C;
+ background-color: #FFFFFF;
+ border: 1px solid #9C9C9C;
+}
+.edit_history_data_content .editing_data .reason .valid {
+ border: 2px solid green;
+}
+.edit_history_data_content .editing_data .reason .invalid {
+ border: 2px solid red;
+}
+.edit_history_data_content .editing_data .reason .reason_input {
+ width: 330px;
+ height: 17px;
+ line-height: 17px;
+ padding-top: 2px;
+ padding-bottom: 2px;
+}
diff --git a/97suifangqa/apps/indicator/static/css/sheet_default.css b/97suifangqa/apps/indicator/static/css/sheet_default.css
index 2edf8dc..44fa6f5 100644
--- a/97suifangqa/apps/indicator/static/css/sheet_default.css
+++ b/97suifangqa/apps/indicator/static/css/sheet_default.css
@@ -105,6 +105,7 @@
position: absolute;
top: 2px;
right: 8px;
+ cursor: pointer;
}
.detail_card_info .chart {
height: 400px;
@@ -287,6 +288,7 @@
position: absolute;
top: 2px;
right: 8px;
+ cursor: pointer;
}
.index_card .edit_icon_container .edit_icon {
background: url("../images/pen_large.png") no-repeat;
diff --git a/97suifangqa/apps/indicator/static/javascripts/card_chart.js b/97suifangqa/apps/indicator/static/javascripts/card_chart.js
index a8fe9f1..8398345 100644
--- a/97suifangqa/apps/indicator/static/javascripts/card_chart.js
+++ b/97suifangqa/apps/indicator/static/javascripts/card_chart.js
@@ -362,12 +362,14 @@ function get_card_data_table(type, num, begin, end, append){
$("#detail_card_table tr").not(".first_line").remove();
// reset to enable button
$(".see_more_btn").removeAttr('disabled');
+ $(".see_more_btn").attr('value', '浏览更多记录');
}
//console.log('data_html: ', data_html);
$("#detail_card_table").append(data_html);
// disable button if has no more data
if (! dataJson.has_earlier) {
$(".see_more_btn").attr('disabled', 'disabled');
+ $(".see_more_btn").attr('value', '无更多记录');
}
}
});
diff --git a/97suifangqa/apps/indicator/static/javascripts/edit_history_data.js b/97suifangqa/apps/indicator/static/javascripts/edit_history_data.js
index 204f404..83a87e2 100644
--- a/97suifangqa/apps/indicator/static/javascripts/edit_history_data.js
+++ b/97suifangqa/apps/indicator/static/javascripts/edit_history_data.js
@@ -1,90 +1,146 @@
$(document).ready(function(){
- //点大叉,关闭弹层页面
- $(".edit_history_data_close").bind("click", function(){
- parent.TB_remove();
- return false;
- });
- $("#edit_btn").bind("click", function(){
- var this_edit_data_div = $(this).parent();
- var data_fir = $(this).siblings(".data_fir").text();
- var data_sec = $(this).siblings(".data_sec").text();
- var this_editing_data_div = this_edit_data_div.siblings(".editing_data");
- var input_container = this_editing_data_div.children(".input_container");
- input_container.children(".edit_input_main").val(parseInt(data_fir));
- input_container.children(".edit_input_sub").val(parseInt(data_sec));
- this_editing_data_div.show();
- this_edit_data_div.hide();
- return false;
- });
- //点击指数+1 icon
- $(".add_icon").bind("click", function(){
- var this_edit_input_sub = $(this).closest(".editing_data").children(".input_container").children(".edit_input_sub");
- var origin_value = parseInt(this_edit_input_sub.val());
- this_edit_input_sub.val(origin_value+1);
- return false;
- });
- //点击 指数-1 icon
- $(".minus_icon").bind("click", function(){
- var this_edit_input_sub = $(this).closest(".editing_data").children(".input_container").children(".edit_input_sub");
- var origin_value = parseInt(this_edit_input_sub.val());
- var after_value = origin_value-1;
- if(after_value >= 0){
- this_edit_input_sub.val(origin_value-1);
- }
- return false;
- });
- //编辑数据的底数验证:只允许两位小数,非空
- $(".edit_input_main").bind("keyup", function(){
- var val = $(this).val();
- val = val.replace(/[^\d.]/g,"");//清除"数字"和"."以外的字符
- val = val.replace(/^\./g,"");//验证第一个字符是数字而不是..
- val = val.replace(/\.{2,}/g,".");//只保留第一个. 清除多余的
- val = val.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
- val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
- $(this).val(val);
- return false;
- });
- //编辑数据的指数验证:只允许整数
- $(".edit_input_sub").bind("keyup", function(){
- $(this).val($(this).val().replace(/[^\d]/g, ''));
- return false;
- });
- $("#save_btn").bind("click", function(){
- var data_input_fir = $(".edit_input_main");
- var data_input_sec = $(".edit_input_sub");
- var data_input_fir_val = data_input_fir.val();
- var data_input_sec_val = data_input_sec.val();
-
- if(data_input_fir_val == '' || data_input_fir_val == 0){
- data_input_fir.addClass("error");
- }else{
- data_input_fir.removeClass("error");
- }
- if(data_input_sec_val == ''){
- data_input_sec.addClass("error");
- }else{
- data_input_sec.removeClass("error");
- }
- if($(".error").length > 0){
- return false;
- }
-
- var date = new Date();
- var time = date.getTime();
- $.ajax({
- type: 'get',
- url: indicator_url + 'ajax/edit_history_data',
- data: 'time='+time,
- success: function(data){
- if(data == 'success'){
- parent.TB_remove();
- parent.redraw_chart(parent.detail_chart, "2013-08-04", "2013-08-10"); //这边需要穿过来起始,结束时间,以便刷新图表和表格
- }
- }
- });
-
- return false;
- });
+ //点大叉,关闭弹层页面
+ $(".edit_history_data_close").bind("click", function(){
+ parent.TB_remove();
+ return false;
+ });
+ // jquery-ui: datepicker
+ $("#editing_date_picker").datepicker({
+ showOn: "both",
+ buttonImage: static_url + "images/calendar.png",
+ buttonImageOnly: true
+ });
+ // edit button
+ $("#edit_btn").bind("click", function(){
+ var this_edit_data_div = $(this).closest(".edit_data");
+ //var data_fir = $(this).siblings(".data_fir").text();
+ //var data_sec = $(this).siblings(".data_sec").text();
+ var data_fir = 0;
+ var data_sec = 0;
+ var this_editing_data_div = this_edit_data_div.siblings(".editing_data");
+ var input_container = this_editing_data_div.children(".input_container");
+ input_container.children(".edit_input_main").val(parseInt(data_fir));
+ input_container.children(".edit_input_sub").val(parseInt(data_sec));
+ this_editing_data_div.show();
+ this_edit_data_div.hide();
+ return false;
+ });
+ // save botton
+ $("#save_btn").bind("click", function(){
+ var data_input_fir = $(".edit_input_main");
+ var data_input_sec = $(".edit_input_sub");
+ var data_input_fir_val = data_input_fir.val();
+ var data_input_sec_val = data_input_sec.val();
+
+ if(data_input_fir_val == '' || data_input_fir_val == 0){
+ data_input_fir.addClass("error");
+ }else{
+ data_input_fir.removeClass("error");
+ }
+ if(data_input_sec_val == ''){
+ data_input_sec.addClass("error");
+ }else{
+ data_input_sec.removeClass("error");
+ }
+ if($(".error").length > 0){
+ return false;
+ }
+
+ var time = moment().valueOf();
+ $.ajax({
+ type: 'get',
+ url: indicator_url + 'ajax/edit_history_data',
+ data: 'time='+time,
+ success: function(data){
+ if(data == 'success'){
+ parent.TB_remove();
+ //parent.redraw_chart(parent.detail_chart, "2013-08-04", "2013-08-10"); //这边需要穿过来起始,结束时间,以便刷新图表和表格
+ }
+ }
+ });
+ return false;
+ });
+
+ // set datepicker 'date_input' value
+ var date_init = $.datepicker.parseDate('yy-mm-dd',
+ $(".date_input").attr('value'));
+ $(".date_input").datepicker("setDate", date_init);
+
+ // data validate {{{
+ // validate date
+ $(".date_input").focus(function() {
+ $(this).removeClass("valid invalid");
+ });
+ $(".date_input").change(function() {
+ var date_str = $(this).val();
+ var date_mm = moment(date_str, 'YYYY-MM-DD');
+ var today_mm = moment();
+ //console.log('date_str: ', date_str);
+ // date cannot beyond today
+ if (date_mm.isValid() && !date_mm.isAfter(today_mm)) {
+ $(this).removeClass("invalid");
+ $(this).addClass("valid");
+ }
+ else {
+ // date invalid
+ $(this).removeClass("valid");
+ $(this).addClass("invalid");
+ }
+ });
+ // validate data
+ $(".data_input").focus(function() {
+ $(this).removeClass("valid invalid");
+ });
+ $(".data_input").change(function() {
+ //$(this).removeClass("valid invalid");
+ });
+ // validate reason
+ $(".reason_input").focus(function() {
+ $(this).removeClass("valid invalid");
+ });
+ $(".reason_input").blur(function() {
+ var reason_str = $(this).val();
+ if (is_str_blank(reason_str)) {
+ // reason not given or blank
+ $(this).removeClass("valid");
+ $(this).addClass("invalid");
+ }
+ else {
+ // reason given and not blank
+ $(this).removeClass("invalid");
+ $(this).addClass("valid");
+ }
+ });
+ // }}}
+
+ //编辑数据的底数验证:只允许两位小数,非空
+ $(".edit_input_main").bind("keyup", function(){
+ var val = $(this).val();
+ val = val.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
+ val = val.replace(/^\./g,""); //验证第一个字符是数字而不是..
+ val = val.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
+ val = val.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
+ val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
+ $(this).val(val);
+ return false;
+ });
+ //编辑数据的指数验证:只允许整数
+ $(".edit_input_sub").bind("keyup", function(){
+ var val = $(this).val().replace(/[^\d]/g, '');
+ $(this).val(val);
+ return false;
+ });
});
+// help functions
+// check if a string is empty, null or undefined
+function is_str_empty(str) {
+ return (!str || 0 === str.length);
+}
+
+// check if a string is blank, null or undefined
+function is_str_blank(str) {
+ return (!str || /^\s*$/.test(str));
+}
+
// vim: set ts=4 sw=4 tw=0 fenc=utf-8 ft=javascript: //
diff --git a/97suifangqa/apps/indicator/templates/indicator/SheetDefault.html b/97suifangqa/apps/indicator/templates/indicator/SheetDefault.html
index 6b127d3..97f2d62 100644
--- a/97suifangqa/apps/indicator/templates/indicator/SheetDefault.html
+++ b/97suifangqa/apps/indicator/templates/indicator/SheetDefault.html
@@ -52,7 +52,7 @@
<!-- Highcharts related, draw records chart -->
<script type="text/javascript">
// default the language to English
- moment.lang('en')
+ moment.lang('en');
// default date format
var mm_date_fmt = "YYYY-MM-DD";
// default to show 30 days' data
diff --git a/97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html b/97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html
index cc82336..172aeb9 100644
--- a/97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html
+++ b/97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html
@@ -1,56 +1,135 @@
{% extends "base.html" %}
{% load static from staticfiles %}
+{% load dict_get %}
{% block title %}
编辑历史数据 | 随访工具 | 97 随访
{% endblock %}
{% block css %}
- <link rel="stylesheet" type="text/css" href="{% static "css/normalize.css" %}"/>
- <link rel="stylesheet" type="text/css" href="{% static "css/edit_history_data.css" %}"/>
+ <link rel="stylesheet" type="text/css" href="{% static "css/normalize.css" %}" />
+ <link rel="stylesheet" type="text/css" href="{% static "plugins/jquery-ui/themes/smoothness/jquery-ui.min.css" %}"/>
+ <link rel="stylesheet" type="text/css" href="{% static "css/edit_history_data.css" %}" />
{% endblock %}
{% block scripts %}
+ <script type="text/javascript" src="{% static "plugins/moment/moment.min.js" %}"></script>
+ <script type="text/javascript" src="{% static "plugins/moment/lang/zh-cn.js" %}"></script>
+ <script type="text/javascript" src="{% static "plugins/jquery-ui/ui/minified/jquery.ui.core.min.js" %}"></script>
+ <script type="text/javascript" src="{% static "plugins/jquery-ui/ui/minified/jquery.ui.datepicker.min.js" %}"></script>
+ <script type="text/javascript" src="{% static "plugins/jquery-ui/ui/minified/i18n/jquery.ui.datepicker-zh-CN.min.js" %}"></script>
<script type="text/javascript" src="{% static "javascripts/edit_history_data.js" %}"></script>
- <!-- set variables
- 'static_url': used in js to load staticfiles
- 'indicator_url': root url of 'apps/indicator'
- -->
- <script>
+ <script type="text/javascript">
+ // 'static_url': used in js to load staticfiles
+ // 'indicator_url': root url of 'apps/indicator'
var static_url = "{{ STATIC_URL }}";
var indicator_url = "/indicator/";
+
+ // default the language to English
+ moment.lang('en');
+ // default date format
+ var mm_date_fmt = "YYYY-MM-DD";
+
+ // indicator DATA_TYPES
+ var DATA_TYPES = {
+ 'INTEGER_TYPE': '{{ indicator_obj.INTEGER_TYPE }}',
+ 'FLOAT_TYPE': '{{ indicator_obj.FLOAT_TYPE }}',
+ 'RANGE_TYPE': '{{ indicator_obj.RANGE_TYPE }}',
+ 'FLOAT_RANGE_TYPE': '{{ indicator_obj.FLOAT_RANGE_TYPE }}',
+ 'PM_TYPE': '{{ indicator_obj.PM_TYPE }}'
+ };
</script>
{% endblock %}
{% block page %}
- <div id="edit_history_data_container">
- <div class="edit_history_data_title_line">
- <div class="edit_history_data_title">乙肝病毒核算定量(PCR)</div>
- <div class="edit_history_data_close"></div>
- </div>
- <div class="edit_history_data_content">
- <div class="date_time">
- <span>日期:2013-07-16</span>
- <span class="time">时间:11:20</span>
- </div>
- <div class="refer_range">参考范围:100 x 10^4 拷贝 /mL</div>
- <div class="edit_data">您的记录:<span class="data_fir">100</span> x 10^<span class="data_sec">4</span> 拷贝 /mL<input type="button" id="edit_btn" value="修改记录" /></div>
- <div class="editing_data">
- <div class="input_container">
- <label>修改记录:</label>
- <input class="edit_input_main" type="text" value="" autocomplete="off" /> x 10^
- <input class="edit_input_sub" type="text" value="" autocomplete="off" />
- </div>
- <div class="add_minus_icon">
- <div class="add_icon"></div>
- <div class="minus_icon"></div>
- </div>
- 拷贝 /mL
- <input type="button" id="save_btn" value="保存新记录" />
- </div>
- </div>
- </div>
+ <div id="edit_history_data_container">
+ <div class="edit_history_data_title_line">
+ <div class="edit_history_data_title">{{ indicator_obj.name }}</div>
+ <div class="edit_history_data_close"></div>
+ </div>
+ <div class="edit_history_data_content">
+ <div class="refer_range">
+ <span class="refer_text">{{ indicator_dict|dict_get:"ref_text" }}</span>
+ <span class="refer_value">{{ indicator_dict|dict_get:"ref_value"|safe }}</span>
+ <span class="data_unit">{% if indicator_dict|dict_get:"std_unit_symbol" %}({{ indicator_dict|dict_get:"std_unit_symbol" }}){% endif %}</span>
+ </div>
+ <div class="edit_data">
+ <div class="date">
+ <span class="date_text">化验日期</span>
+ <span class="date_value">{{ record_dict|dict_get:"date" }}</span>
+ </div>
+ <div class="data">
+ <span class="prompt">结果</span>
+ <span class="data_value">{{ record_dict|dict_get:"value_html"|safe }}</span>
+ <span class="data_unit">{% if record_dict|dict_get:"unit_symbol" %}({{ record_dict|dict_get:"unit_symbol" }}){% endif %}</span>
+ </div>
+ <div class="state">
+ <span class="prompt">状态</span>
+ {% if record_dict|dict_get:"is_normal" == None %}
+ {# 'is_normal': None #}
+ <span class="text unknown">未知</span>
+ {% elif not record_dict|dict_get:"is_normal" %}
+ {# 'is_normal': False #}
+ <span class="text abnormal">异常</span>
+ {% else %}
+ {# 'is_normal': True #}
+ <span class="text normal">正常</span>
+ {% endif %}
+ </div>
+ <input type="button" id="edit_btn" value="修改记录" />
+ </div>
+ <div class="editing_data">
+ <div class="date">
+ <div class="date_text">化验日期</div>
+ <div class="datepicker_container">
+ <!-- jquery-ui: datepicker -->
+ <input class="datepicker date_input" id="editing_date_picker" type="text" value="{{ record_dict|dict_get:"date" }}" />
+ </div>
+ </div>
+ <!--
+ <div class="input_container">
+ <div class="prompt">修改记录</div>
+ <input class="edit_input_main" type="text" value="" autocomplete="off" />
+ x10^
+ <input class="edit_input_sub" type="text" value="" autocomplete="off" />
+ </div>
+ <div class="add_minus_icon">
+ <div class="add_icon"></div>
+ <div class="minus_icon"></div>
+ </div>
+ -->
+ <div class="data data_type_{{ indicator_obj.dataType }}">
+ <div class="prompt">修改记录</div>
+ {% if indicator_obj.dataType == indicator_obj.INTEGER_TYPE %}
+ {# INTEGER_TYPE #}
+ TODO
+ {% elif indicator_obj.dataType == indicator_obj.FLOAT_TYPE %}
+ {# FLOAT_TYPE #}
+ <input class="data_input" type="text" value="" autocomplete="off" />
+ {% elif indicator_obj.dataType == indicator_obj.RANGE_TYPE %}
+ {# RANGE_TYPE #}
+ <input class="data_input" type="text" value="" autocomplete="off" />
+ {% elif indicator_obj.dataType == indicator_obj.FLOAT_RANGE_TYPE %}
+ {# FLOAT_RANGE_TYPE #}
+ <input class="data_input" type="text" value="" autocomplete="off" />
+ {% elif indicator_obj.dataType == indicator_obj.PM_TYPE %}
+ {# PM_TYPE #}
+ TODO
+ {% else %}
+ {# UNKNOWN TYPE #}
+ ERROR: unknown data type
+ {% endif %}
+ </div>
+ <div class="data_unit">{% if record_dict|dict_get:"unit_symbol" %}({{ record_dict|dict_get:"unit_symbol" }}){% endif %}</div>
+ <div class="reason">
+ <div class="prompt">修改原因</div>
+ <input class="reason_input" type="text" value="" />
+ </div>
+ <input type="button" id="save_btn" value="提交修改" />
+ </div> <!-- end: edting_data -->
+ </div> <!-- end: edit_history_data_content -->
+ </div>
{% endblock page %}
{# vim: set ts=2 sw=2 tw=0 fenc=utf-8 ft=htmldjango.html: #}
diff --git a/97suifangqa/apps/indicator/templates/indicator/test.html b/97suifangqa/apps/indicator/templates/indicator/test.html
index d7b349f..412eb17 100644
--- a/97suifangqa/apps/indicator/templates/indicator/test.html
+++ b/97suifangqa/apps/indicator/templates/indicator/test.html
@@ -39,6 +39,15 @@
<li>i</li>
{% endfor %}
</ul>
+
+ <h3>templates 'if' statement</h3>
+ {% if boolvar == None %}
+ None
+ {% elif not boolvar %}
+ False
+ {% else %}
+ True
+ {% endif %}
</body>
</html>
diff --git a/97suifangqa/apps/indicator/tools.py b/97suifangqa/apps/indicator/tools.py
index 7a74ac4..de3191b 100644
--- a/97suifangqa/apps/indicator/tools.py
+++ b/97suifangqa/apps/indicator/tools.py
@@ -509,13 +509,17 @@ def recommend_indicator(user_id, number):
# format_data {{{
-def format_data(indicator_obj, value=None, val_max=None, val_min=None):
+def format_data(indicator_obj, value=None, val_max=None, val_min=None, type="html"):
"""
format given data according to the dataType of given Indicator,
make it proper for django templates
e.g.:
if number very big, then display in 'exponent notation'
+ if 'type="html"', then return the html code for displaying
+ on the web page;
+ elif 'type="text"', then return the plain text format.
+
used in '.views.indicator_status()'
"""
# threshold to show a float number in scientific notation
@@ -526,15 +530,24 @@ def format_data(indicator_obj, value=None, val_max=None, val_min=None):
# regex to process exponent notation
rep = re.compile(r'^(?P<sign>[-+]?)(?P<num>\d\.\d+)[eE]\+?(?P<expminus>-?)0*(?P<exp>[1-9]+)$')
# range symbol (range: low $symbol$ high)
- range_sym = '&sim;'
+ range_sym_html = u'&sim;'
+ range_sym_text = u'~'
# default return value
value_str = u''
+ # check 'type'
+ if (type == "html") or (type == "text"):
+ pass
+ else:
+ print u'Error: unsupported type="%s"' % type
+ return None
+
# check given 'indicator_obj'
ind = indicator_obj
if not isinstance(ind, im.Indicator):
print u'Error: given indicator_obj NOT a instance of Indicator'
raise ValueError(u'Given indicator_obj NOT a instance of Indicator')
+ return None
# get dataType
dataType = ind.dataType
@@ -546,24 +559,38 @@ def format_data(indicator_obj, value=None, val_max=None, val_min=None):
value_str = u'INTEGER: %s' % value
elif dataType == ind.PM_TYPE:
if value == u'+':
- value_str = u'阳性(+)'
+ if type == "html":
+ value_str = u'阳性(+)'
+ else:
+ value_str = u'+'
else:
- value_str = u'阳性(-)'
+ if type == "html":
+ value_str = u'阳性(-)'
+ else:
+ value_str = u'-'
elif dataType in [ind.FLOAT_TYPE, ind.FLOAT_RANGE_TYPE]:
# process float number
value = float(value)
if value <= float_threshold:
- value_str = fix_fmt.format(value)
+ if type == "html":
+ value_str = fix_fmt.format(value)
+ else:
+ value_str = u"%s" % value
else:
value_expstr = exp_fmt.format(value)
# convert to html exponent format
m = rep.match(value_expstr)
- value_str = "%s%s&times;10<sup>%s%s</sup>" % (
- m.group('sign'), m.group('num'),
- m.group('expminus'), m.group('exp'))
+ if type == "html":
+ value_str = u"%s%s&times;10<sup>%s%s</sup>" % (
+ m.group('sign'), m.group('num'),
+ m.group('expminus'), m.group('exp'))
+ else:
+ value_str = u"%s%se%s%s" % (
+ m.group('sign'), m.group('num'),
+ m.group('expminus'), m.group('exp'))
else:
# unknown XXX
- pass
+ return None
elif (val_max is not None) and (val_min is not None):
# a) record range data; b) confine range.
# val_max
@@ -573,9 +600,14 @@ def format_data(indicator_obj, value=None, val_max=None, val_min=None):
val_max_expstr = exp_fmt.format(val_max)
# convert to html exponent format
m = rep.match(val_max_expstr)
- val_max_str = "%s%s&times;10<sup>%s%s</sup>" % (
- m.group('sign'), m.group('num'),
- m.group('expminus'), m.group('exp'))
+ if type == "html":
+ val_max_str = u"%s%s&times;10<sup>%s%s</sup>" % (
+ m.group('sign'), m.group('num'),
+ m.group('expminus'), m.group('exp'))
+ else:
+ val_max_str = u"%s%se%s%s" % (
+ m.group('sign'), m.group('num'),
+ m.group('expminus'), m.group('exp'))
# val_min
if val_min <= float_threshold:
val_min_str = fix_fmt.format(val_min)
@@ -583,14 +615,24 @@ def format_data(indicator_obj, value=None, val_max=None, val_min=None):
val_min_expstr = exp_fmt.format(val_min)
# convert to html exponent format
m = rep.match(val_min_expstr)
- val_min_str = "%s%s&times;10<sup>%s%s</sup>" % (
- m.group('sign'), m.group('num'),
- m.group('expminus'), m.group('exp'))
+ if type == "html":
+ val_min_str = u"%s%s&times;10<sup>%s%s</sup>" % (
+ m.group('sign'), m.group('num'),
+ m.group('expminus'), m.group('exp'))
+ else:
+ val_min_str = u"%s%se%s%s" % (
+ m.group('sign'), m.group('num'),
+ m.group('expminus'), m.group('exp'))
# value_str
- value_str = u'%s %s %s' % (val_min_str, range_sym, val_max_str)
+ if type == "html":
+ value_str = u'%s %s %s' % (val_min_str,
+ range_sym_html, val_max_str)
+ else:
+ value_str = u'%s %s %s' % (val_min_str,
+ range_sym_text, val_max_str)
else:
# other type??
- pass
+ return None
return value_str
# }}}
diff --git a/97suifangqa/apps/indicator/views.py b/97suifangqa/apps/indicator/views.py
index 6293938..4e810f3 100644
--- a/97suifangqa/apps/indicator/views.py
+++ b/97suifangqa/apps/indicator/views.py
@@ -472,7 +472,7 @@ def indicator_status(request):
human_max = confine.get('human_max')
human_min = confine.get('human_min')
ind['ref_value'] = format_data(ind_obj,
- val_max=human_max, val_min=human_min)
+ val_max=human_max, val_min=human_min, type="html")
# set 'std_unit_*'
ind['std_unit_name'] = confine.get('unit').get('name')
ind['std_unit_symbol'] = confine.get('unit').get('symbol')
@@ -480,7 +480,8 @@ def indicator_status(request):
ind['ref_text'] = u"参考值"
# ref_value
val_norm = confine.get('val_norm')
- ind['ref_value'] = format_data(ind_obj, value=val_norm)
+ ind['ref_value'] = format_data(ind_obj, value=val_norm,
+ type="html")
# std_unit
ind['std_unit_name'] = u""
ind['std_unit_symbol'] = u""
@@ -498,20 +499,24 @@ def indicator_status(request):
last_record = records[0]
if dataType in [ind_obj.INTEGER_TYPE, ind_obj.PM_TYPE,
ind_obj.FLOAT_TYPE]:
- value_str = format_data(ind_obj, value=last_record.value)
+ value_str = format_data(ind_obj,
+ value=last_record.value, type="html")
elif dataType == ind_obj.RANGE_TYPE:
value_str = format_data(ind_obj,
val_max=last_record.val_max,
- val_min=last_record.val_min)
+ val_min=last_record.val_min,
+ type="html")
elif dataType == ind_obj.FLOAT_RANGE_TYPE:
value = last_record.value
val_max = last_record.val_max
val_min = last_record.val_min
if value is not None:
- value_str = format_data(ind_obj, value=value)
+ value_str = format_data(ind_obj, value=value,
+ type="html")
elif (val_max is not None) and (val_min is not None):
value_str = format_data(ind_obj,
- val_max=val_max, val_min=val_min)
+ val_max=val_max, val_min=val_min,
+ type="html")
else:
value_str = u''
else:
@@ -669,7 +674,131 @@ def indicator_edithistorydata(request):
popup page to edit history data for an indicator
"""
template = 'indicator/popup/EditHistoryData.html'
- return render(request, template)
+ # check 'card_id' -> indicator_id
+ if request.GET.get('card_id') is not None:
+ card_id = request.GET.get('card_id')
+ try:
+ indicator_id = int(card_id)
+ ind_obj = im.Indicator.objects.get(id=indicator_id)
+ except ValueError:
+ print u'Error: Given card_id="%s" cannot convert to integer' % card_id
+ raise Http404
+ except im.Indicator.DoesNotExist:
+ print u'Error: Indicator id="%s" NOT exist' % indicator_id
+ raise Http404
+ else:
+ print u'Error: No card_id provided'
+ raise Http404
+ # check record 'date'
+ if request.GET.get('date'):
+ # 'date' given and not empty
+ date = request.GET.get('date')
+ try:
+ datetime_in = datetime.datetime.strptime(date, '%Y-%m-%d')
+ record_date = datetime_in.date()
+ except ValueError:
+ print u'Error: Given date="%s" invalid' % date
+ raise Http404
+ else:
+ print u'Error: "date" not given or empty'
+ raise Http404
+
+ # get indicator record
+ try:
+ record_obj = im.IndicatorRecord.objects.get(
+ indicator=ind_obj, date=record_date)
+ except im.IndicatorRecord.DoesNotExist:
+ print u'Error: no matching IndicatorRecord found'
+ raise Http404
+ except im.IndicatorRecord.MultipleObjectsReturned:
+ print u'Error: multiple matching IndicatorRecord found'
+ raise Http404
+
+ # process indicator and record data
+ # generate 'indicator_dict' and 'record_dict' # {{{
+ # check if 'indicator.is_ready()'
+ if not ind_obj.is_ready():
+ print u"Indicator id=%s is NOT ready yet!" % ind_obj.id
+ # the indicator is ready
+ dataType = ind_obj.dataType
+ # confine
+ confine = ind_obj.get_confine()
+ val_norm = confine.get('val_norm')
+ human_min = confine.get('human_min')
+ human_max = confine.get('human_max')
+ std_unit_name = confine.get('unit').get('name')
+ std_unit_symbol = confine.get('unit').get('symbol')
+ # record data
+ record_data_std = record_obj.get_data_std()
+ record_value = record_data_std['value']
+ record_val_min = record_data_std['val_min']
+ record_val_max = record_data_std['val_max']
+ record_unit_name = record_data_std.get('unit').get('name')
+ record_unit_symbol = record_data_std.get('unit').get('symbol')
+ record_is_normal = record_obj.is_normal()
+ # check dataType
+ if dataType == im.Indicator.INTEGER_TYPE:
+ ref_text = u"参考值"
+ ref_value = format_data(ind_obj, value=val_norm, type="html")
+ # TODO
+ record_value_html = u""
+ pass
+ elif dataType == im.Indicator.FLOAT_TYPE:
+ ref_text = u"参考范围"
+ ref_value = format_data(ind_obj,
+ val_max=human_max, val_min=human_min, type="html")
+ record_value_html = format_data(ind_obj, value=record_value,
+ type="html")
+ elif dataType == im.Indicator.RANGE_TYPE:
+ ref_text = u"参考范围"
+ ref_value = format_data(ind_obj,
+ val_max=human_max, val_min=human_min, type="html")
+ record_value_html = format_data(ind_obj,
+ val_min=record_val_min, val_max=record_val_max,
+ type="html")
+ elif dataType == im.Indicator.FLOAT_RANGE_TYPE:
+ ref_text = u"参考范围"
+ ref_value = format_data(ind_obj,
+ val_max=human_max, val_min=human_min, type="html")
+ # TODO
+ record_value_html = u""
+ pass
+ elif dataType == im.Indicator.PM_TYPE:
+ ref_text = u"参考值"
+ ref_value = format_data(ind_obj, value=val_norm, type="html")
+ # TODO
+ record_value_html = u""
+ pass
+ else:
+ ref_text = u"参考"
+ ref_value = None
+ std_unit_name = None
+ std_unit_symbol = None
+ record_value_html = None
+ # }}}
+
+ # template data
+ ind_dict = {
+ 'ref_text': ref_text,
+ 'ref_value': ref_value,
+ 'std_unit_name': std_unit_name,
+ 'std_unit_symbol': std_unit_symbol,
+ }
+ record_dict = {
+ 'date': record_date.isoformat(),
+ 'value_html': record_value_html,
+ 'unit_name': record_unit_name,
+ 'unit_symbol': record_unit_symbol,
+ 'is_normal': record_is_normal,
+ }
+ data = {
+ 'indicator_obj': ind_obj,
+ 'indicator_dict': ind_dict,
+ 'record_obj': record_obj,
+ 'record_dict': record_dict,
+ }
+ #
+ return render(request, template, data)
# }}}
@@ -969,8 +1098,8 @@ def ajax_get_card_data_table(request):
end = None
num = None
#
- if True:
- #if request.is_ajax():
+ #if True:
+ if request.is_ajax():
# get parameters {{{
# check card_id -> indicator_id
if request.GET.get('card_id') is not None:
@@ -1093,12 +1222,13 @@ def ajax_get_card_data_table(request):
elif dataType == im.Indicator.FLOAT_TYPE:
value = r['value']
r['value_html'] = format_data(ind_obj,
- value=value)
+ value=value, type="html")
elif dataType == im.Indicator.RANGE_TYPE:
val_min = r['val_min']
val_max = r['val_max']
r['value_html'] = format_data(ind_obj,
- val_min=val_min, val_max=val_max)
+ val_min=val_min, val_max=val_max,
+ type="html")
elif dataType == im.Indicator.FLOAT_RANGE_TYPE:
# TODO
r['value_html'] = ""
@@ -1169,11 +1299,14 @@ def test_view(request, **kwargs):
list = []
+ boolvar = False
+
data = {
'all_letters': all_letters,
'all_indicators': all_indicators,
'followed_indicators': followed_indicators,
'list': list,
+ 'boolvar': boolvar,
}
return render(request, template, data)