body-record.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. var xtMax = getNormalLevel(statusIndex)[0],
  108. xtMin = getNormalLevel(statusIndex)[1],
  109. xyMax = [139, 89],
  110. xyMin = [90, 60],
  111. toNormal = 0,
  112. toHigh = 0,
  113. toLow = 0;
  114. function judgeXTValue(value1) {
  115. // 血糖判断
  116. if(value1 > xtMax) {
  117. ++toHigh;
  118. } else if(value1 < xtMin) {
  119. ++toLow;
  120. } else {
  121. ++toNormal;
  122. };
  123. }
  124. function judgeXYValue(value1, value2) {
  125. // 血压判断
  126. if(value1 > xyMax[0] || value2 > xyMax[1]) {
  127. ++toHigh;
  128. } else if(value1 < xyMin[0] || value2 < xyMin[1]) {
  129. ++toLow;
  130. } else {
  131. ++toNormal;
  132. }
  133. }
  134. // 数据统计
  135. function totalStauts(zc, pg, pd) {
  136. $('.is-ok').html("正常:" + zc + "次");
  137. $('.is-height').html("偏高:" + pg + "次");
  138. $('.is-low').html("偏低:" + pd + "次");
  139. }
  140. // 获取最后一条数据
  141. var dataLast = {patient: patient};
  142. var lastXT = '',
  143. lastXY = '';
  144. bodyRecordApis.getBodyRecoredLast({data: dataLast}).then(function(res){
  145. if(res.status == 200){
  146. lastXT = res.data.xt ? res.data.xt.recordDate : null;
  147. lastXY = res.data.xy ? res.data.xy.recordDate : null;
  148. // 初始化执行
  149. getBodyRecord(tabIndex, dayIndex, statusIndex);
  150. }else{
  151. showWarningMsg(res.msg)
  152. }
  153. })
  154. // 获取数据
  155. function getBodyRecord(tab, day, statu) {
  156. toNormal = 0;
  157. toHigh = 0;
  158. toLow = 0;
  159. totalStauts(toNormal, toHigh, toLow);
  160. $('.danwei').html(tab == 0 ? '单位(mmol/L)' : '单位(mmHg)');
  161. var dayNum = 0;
  162. switch(day) {
  163. case 0:
  164. dayNum = 6;break;
  165. case 1:
  166. dayNum = 29;break;
  167. case 2:
  168. dayNum = 89;break;
  169. case 3:
  170. dayNum = 364 / 2;break;
  171. }
  172. var type = (tab == 0 ? 1 : 2),
  173. startdate = (tab == 0 ? lastXT : lastXY),
  174. enddate = null;
  175. if(startdate) {
  176. enddate = getDateFromCurrentDate(startdate, -dayNum);
  177. } else {
  178. showWarningMsg("当前状态下无居民体征记录");return;
  179. }
  180. $('.data-record').html('<' + enddate.substr(0, 10) + '至' + startdate.substr(0,10) + '>');
  181. var recordData = {
  182. type: type,
  183. begin: enddate,
  184. end: startdate,
  185. gi_type: statu,
  186. patient: patient
  187. };
  188. // 获取体征记录
  189. bodyRecordApis.getBodyRecordData({data: recordData}).then(function(res){
  190. if(myLineChart) {// 如果构造过,解析
  191. myLineChart.destroy();
  192. }
  193. if(res.status == 200){
  194. var list = res.list,
  195. len = 0;
  196. if(list) {
  197. len = list.length;
  198. } else {
  199. showWarningMsg("当前状态下无居民体征记录");return;
  200. };
  201. list.reverse();
  202. if(len == 1) {
  203. dataCanvas.labels = [enddate.substr(5, 5), list[0].date.substr(5, 5)];
  204. dataCanvas.datasets[0].data = [null, list[0].value1];
  205. if(tabIndex == 1) {
  206. dataCanvas.datasets[1].data = [null, list[0].value2];
  207. judgeXYValue(list[0].value1, list[0].value2)
  208. } else {
  209. dataCanvas.datasets[1].data = null
  210. judgeXTValue(list[0].value1)
  211. }
  212. } else {
  213. for(var i = 0; i < len; i++) {
  214. dataCanvas.labels[i] = list[i].date.substr(5, 5);
  215. dataCanvas.datasets[0].data[i] = list[i].value1;
  216. if(tabIndex == 1) {
  217. dataCanvas.datasets[1].data[i] = list[i].value2;
  218. judgeXYValue(list[i].value1, list[i].value2)
  219. } else {
  220. dataCanvas.datasets[1].data = null
  221. judgeXTValue(list[i].value1)
  222. }
  223. }
  224. }
  225. totalStauts(toNormal, toHigh, toLow);
  226. // 绘制图
  227. myLineChart = new Chart(ctx).Line(dataCanvas, defaults);
  228. }else{
  229. showWarningMsg(res.msg)
  230. }
  231. })
  232. }
  233. })(jQuery)