body-record.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. (function() {
  2. var request = getRequest(),
  3. patient = request.patiCode || '';
  4. var tabIndex = 0,
  5. dayIndex = 0,
  6. statusIndex = 1;
  7. // 绘制折线图初始定义
  8. var ctx = document.getElementById('canvas').getContext("2d");
  9. var dataCanvas = {
  10. labels : [],
  11. datasets : [
  12. {
  13. fillColor : "rgba(220,220,220,0.5)",
  14. strokeColor : "rgba(220,220,220,1)",
  15. pointColor : "rgba(220,220,220,1)",
  16. pointStrokeColor : "#fff",
  17. data : []
  18. },
  19. {
  20. fillColor : "rgba(151,187,205,0.5)",
  21. strokeColor : "rgba(151,187,205,1)",
  22. pointColor : "rgba(151,187,205,1)",
  23. pointStrokeColor : "rgba(151,187,205,1)",
  24. data : []
  25. }
  26. ]
  27. },
  28. defaults = {
  29. scaleStartValue : 0,
  30. scaleShowLabels : true,
  31. datasetFill : false, // 是否填充数据集
  32. animation : true, // 是否执行动画
  33. animationSteps : 60, // 动画的时间
  34. animationEasing : "easeOutQuart", // 动画的特效
  35. onAnimationComplete : null // 动画完成时的执行函数
  36. };
  37. var myLineChart = null;
  38. // new Chart(ctx).Line(dataCanvas, defaults);
  39. $('.tab-record span').click(function() {
  40. tabIndex = $(this).index();
  41. // 初始化数据
  42. if(tabIndex == 1) {
  43. statusIndex = 0;
  44. $('.status-record').hide();
  45. } else {
  46. var ele = $('.status-record span').get(0);
  47. indexHover(ele);
  48. statusIndex = 1;
  49. $('.status-record').show();
  50. }
  51. indexHover(this);
  52. dayIndex = 0;
  53. var ele = $('.day-record span').get(0);
  54. indexHover(ele);
  55. canvasDataDefault();
  56. });
  57. $('.day-record span').click(function() {
  58. dayIndex = $(this).index();
  59. if(tabIndex == 0) {
  60. var ele = $('.status-record span').get(0);
  61. indexHover(ele);
  62. statusIndex = 1;
  63. }
  64. indexHover(this);
  65. canvasDataDefault();
  66. });
  67. $('.status-record span').click(function() {
  68. statusIndex = $(this).index() + 1;
  69. indexHover(this);
  70. canvasDataDefault();
  71. });
  72. // 点击指示特效
  73. function indexHover(ele) {
  74. $(ele).siblings().removeClass('f-hover');
  75. $(ele).addClass('f-hover');
  76. };
  77. // 绘图数据格式化
  78. function canvasDataDefault() {
  79. dataCanvas.labels = [];
  80. dataCanvas.datasets[0].data = [];
  81. dataCanvas.datasets[1].data = [];
  82. // 切换数据
  83. getBodyRecord(tabIndex, dayIndex, statusIndex);
  84. }
  85. // 时间推算
  86. function getDateFromCurrentDate(fromDate, dayInterval) {
  87. var curDate = new Date(Date.parse(fromDate.replace(/-/g, "/")));
  88. curDate.setDate(curDate.getDate() + dayInterval);
  89. var year = curDate.getFullYear();
  90. var month = (curDate.getMonth() + 1) < 10 ? "0" + (curDate.getMonth() + 1) : (curDate.getMonth() + 1);
  91. var day = curDate.getDate() < 10 ? "0" + curDate.getDate() : curDate.getDate();
  92. return year + "-" + month + "-" + day + " 00:00:00";
  93. };
  94. // 血糖标准
  95. function getNormalLevel(index) {
  96. return [
  97. [],
  98. [6.1, 3.9],
  99. [7.8, 4.4],
  100. [6.1, 3.9],
  101. [7.8, 4.4],
  102. [6.1, 3.9],
  103. [7.8, 4.4],
  104. [6.1, 3.9]
  105. ][index];
  106. };
  107. // 获取最后一条数据
  108. var dataLast = {patient: patient};
  109. var lastXT = '',
  110. lastXY = '';
  111. bodyRecordApis.getBodyRecoredLast({data: dataLast}).then(function(res){
  112. if(res.status == 200){
  113. if(!res.data.xt || !res.data.xy) {
  114. showWarningMsg("该居民无体征记录");
  115. return;
  116. }
  117. lastXT = res.data.xt.recordDate;
  118. lastXY = res.data.xy.recordDate;
  119. // 初始化执行
  120. getBodyRecord(tabIndex, dayIndex, statusIndex);
  121. }else{
  122. showWarningMsg(res.msg)
  123. }
  124. })
  125. // 获取数据
  126. function getBodyRecord(tab, day, statu) {
  127. if(!lastXT || !lastXY) {
  128. showWarningMsg("该居民无体征记录");
  129. return;
  130. };
  131. var xtMax = getNormalLevel(statusIndex)[0],
  132. xtMin = getNormalLevel(statusIndex)[1],
  133. xyMax = [139, 89],
  134. xymin = [90, 60],
  135. toNormal = 0,
  136. toHigh = 0,
  137. toLow = 0;
  138. $('.danwei').html(tab == 0 ? '单位(mmol/L)' : '单位(mmHg)');
  139. var dayNum = 0;
  140. switch(day) {
  141. case 0:
  142. dayNum = 7;break;
  143. case 1:
  144. dayNum = 30;break;
  145. case 2:
  146. dayNum = 90;break;
  147. case 3:
  148. dayNum = 365 / 2;break;
  149. }
  150. var type = (tab == 0 ? 1 : 2),
  151. startdate = (tab == 0 ? lastXT : lastXY),
  152. enddate = getDateFromCurrentDate(startdate, -dayNum);
  153. $('.data-record').html('<' + enddate.substr(0, 10) + '至' + startdate.substr(0,10) + '>');
  154. var recordData = {
  155. type: type,
  156. begin: enddate,
  157. end: startdate,
  158. gi_type: statu,
  159. patient: patient
  160. };
  161. // 获取体征记录
  162. bodyRecordApis.getBodyRecordData({data: recordData}).then(function(res){
  163. if(myLineChart) {// 如果构造过,解析
  164. myLineChart.destroy();
  165. }
  166. if(res.status == 200){
  167. var list = res.list,
  168. len = 0;
  169. if(list) {
  170. len = list.length;
  171. } else {
  172. showWarningMsg("当前状态下无居民体征记录");return;
  173. };
  174. list.reverse();
  175. for(var i = 0; i < len; i++) {
  176. if(len == 1) {
  177. dataCanvas.labels = [enddate.substr(5, 5), list[i].date.substr(5, 5)];
  178. dataCanvas.datasets[0].data = [null, list[i].value1];
  179. } else {
  180. dataCanvas.labels[i] = list[i].date.substr(5, 5);
  181. dataCanvas.datasets[0].data[i] = list[i].value1;
  182. }
  183. if(tabIndex == 1) {
  184. if(len == 1) {
  185. dataCanvas.datasets[1].data = [null, list[i].value2];
  186. } else {
  187. dataCanvas.datasets[1].data[i] = list[i].value2;
  188. }
  189. // 血压判断
  190. if(list[i].value1 > xyMax[0] || list[i].value2 > xyMax[1]) {
  191. ++toHigh;
  192. } else if(list[i].value1 < xyMin[0] || list[i].value2 < xyMin[1]) {
  193. ++toLow;
  194. } else {
  195. ++toNormal;
  196. }
  197. } else {
  198. // 血糖判断
  199. if(list[i].value1 > xtMax) {
  200. ++toHigh;
  201. } else if(list[i].value1 < xtMin) {
  202. ++toLow;
  203. } else {
  204. ++toNormal;
  205. };
  206. }
  207. }
  208. $('.is-ok').html("正常:" + toNormal + "次");
  209. $('.is-height').html("偏高:" + toHigh + "次");
  210. $('.is-low').html("偏低:" + toLow + "次");
  211. // 绘制图
  212. myLineChart = new Chart(ctx).Line(dataCanvas, defaults);
  213. }else{
  214. showWarningMsg(res.msg)
  215. }
  216. })
  217. }
  218. })(jQuery)