health-record.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. var patientCode = "",
  2. self = null,
  3. tagType = '';//tab标签初始
  4. var $tizhengList = $('#tizhengList'),
  5. $baojianList = $('#baojianList');
  6. var xuetangRecord = null,
  7. xuyaRecord = null,
  8. tizhongRecord = null,
  9. yaoweiRecord = null,
  10. yundongRecord = null,
  11. yongyaoRecord = null,
  12. yinshiRecord = null,
  13. tzSta = false,
  14. xtdt = '',
  15. xydt = '',
  16. tzdt = '',
  17. ywdt = '',
  18. yddt = '',
  19. yydt = '',
  20. ysdt = '';
  21. var xuetangDuring = ['','早餐前', '早餐后', '午餐前', '午餐后', '晚餐前', '晚餐后', '睡前'];
  22. mui.plusReady(function() {
  23. self = plus.webview.currentWebview();
  24. tagType = self.tagType?self.tagType:0;
  25. patientCode = self.patientCode;
  26. bindEvents();
  27. if(tagType == 1){
  28. $('.j-tab-select li').eq(1).addClass('hit');
  29. $('.pt-tab-list').eq(1).addClass('hit');
  30. $('.icon-share').hide();
  31. $('.header-group').hide();
  32. }else{
  33. $('.j-tab-select li').eq(0).addClass('hit');
  34. $('.pt-tab-list').eq(0).addClass('hit');
  35. }
  36. //体征记录
  37. getRecentDataPromise().then(function(res) {
  38. xuetangRecord = _.find(res.data,function(o){
  39. var d = new Date(o.recordDate.replace(/\-/g, "/"));
  40. o.recordDate = d.getFullYear() + '-' + checkDate(d.getMonth() + 1) + '-' + checkDate(d.getDate());
  41. return o.type =="1";
  42. }) || {};
  43. xuyaRecord = _.find(res.data,function(o) {
  44. return o.type =="2";
  45. }) || {};
  46. tizhongRecord = _.find(res.data,function(o) {
  47. return o.type =="3";
  48. }) || {};
  49. yaoweiRecord = _.find(res.data,function(o) {
  50. return o.type =="4";
  51. }) || {};
  52. var xuetangValue = "";
  53. var xuetangValueIndex;
  54. var during = _.find(xuetangDuring,function(v,i){
  55. xuetangValue = xuetangRecord['value'+[i]];
  56. xuetangValueIndex = i;
  57. return i>0&&xuetangValue;
  58. });
  59. xtdt = xuetangRecord.recordDate || '';
  60. xydt = xuyaRecord.recordDate || '';
  61. tzdt = tizhongRecord.recordDate || '';
  62. ywdt = yaoweiRecord.recordDate || '';
  63. var duringIndex = xuetangRecord.value2 ? xuetangRecord.value2 : 0;
  64. return {
  65. //血糖中,value1返回最新的值,value2表示当前值对应的时间段的值(1-7)
  66. xuetang: $.extend({},xuetangRecord,{
  67. during: duringIndex ? xuetangDuring[duringIndex] : '',
  68. value: xuetangValue,
  69. levelClazz: (function() {
  70. // 不同时间段对应不同的血糖范围
  71. // var levels = [[],[7.0, 3.9],[11.1, 4.0],
  72. // [7.0, 3.9],[11.1, 4.4],
  73. // [7.0, 3.9],[11.1, 4.4],
  74. // [7.0, 3.9]][xuetangValueIndex];
  75. var levels = [[],[7.0, 3.9],[11.1, 4.0],
  76. [7.0, 3.9],[11.1, 4.0],
  77. [7.0, 3.9],[11.1, 4.0],
  78. [7.0, 3.9]][duringIndex]
  79. return getLevelClazz(xuetangValue, levels[0],levels[1])
  80. })(),
  81. recordType: getRecordType(xuetangRecord.deviceSn)
  82. }),
  83. xueya: $.extend({},xuyaRecord,{
  84. levelClazz: getLevelClazz(xuyaRecord.value1, 139, 90)||getLevelClazz(xuyaRecord.value2, 89, 60),
  85. recordType: getRecordType(xuyaRecord.deviceSn)
  86. }),
  87. tizhong: $.extend({},tizhongRecord,{
  88. recordType: getRecordType(tizhongRecord.deviceSn)
  89. }),
  90. yaowei: $.extend({},yaoweiRecord,{
  91. recordType: getRecordType(yaoweiRecord.deviceSn)
  92. })
  93. }
  94. }).then(function(data) {
  95. var html = template('tizheng_list_temp',data);
  96. $tizhengList.html(html)
  97. }).then(function() {
  98. //保健记录
  99. getBJRecentDataPromise().then(function (res){
  100. yundongRecord = res.data.sprot;
  101. yongyaoRecord = res.data.medication;
  102. yinshiRecord = res.data.diet;
  103. yddt = yundongRecord.recordDate;
  104. yydt = yongyaoRecord.recordDate;
  105. ysdt = yinshiRecord.recordDate;
  106. return {
  107. yundong: (function () {
  108. yundongRecord.recordType = getBJRecordType(yundongRecord.source);
  109. return yundongRecord;
  110. })(),
  111. yongyao: (function () {
  112. yongyaoRecord.recordType = getBJRecordType(yongyaoRecord.source);
  113. return yongyaoRecord;
  114. })() ,
  115. yinshi: (function () {
  116. yinshiRecord.recordType = getBJRecordType(yinshiRecord.source);
  117. return yinshiRecord;
  118. })()
  119. };
  120. }).then(function (data) {
  121. var html = template('baojian_list_tmp',data);
  122. $baojianList.html(html);
  123. }).then(function(){
  124. // getEquipments()
  125. })
  126. })
  127. .catch(function(e) {
  128. console && console.error(e)
  129. })
  130. })
  131. function getEquipments(){
  132. var params = {
  133. page:1,
  134. pagesize:100,
  135. patient:patientCode
  136. }
  137. sendGet("doctor/device/PatientDeviceList",params,function(){
  138. mui.toast('请求失败')
  139. },function(res){
  140. if(res.status==200){
  141. if(res.data&&res.data.length>0){
  142. $("#equip-list").empty();
  143. $(".div-no-info").hide();
  144. for(var i in res.data){
  145. showList(res.data[i]);
  146. }
  147. $("#equip-list").show();
  148. }else{
  149. sendGet("doctor/is_patient_signed",{patient:patientCode},function(res){
  150. mui.toast("请求失败");
  151. },function(res){
  152. if(res.status==200){
  153. if(res.data==1){
  154. $(".div-tishi-info").html("该居民还未绑定体征设备");
  155. }else{
  156. $(".div-tishi-info").html("您还未帮该居民绑定过体征设备");
  157. }
  158. $(".div-no-info").show();
  159. $("#equip-list").hide();
  160. }else{
  161. mui.toast("签约关系获取失败");
  162. }
  163. })
  164. }
  165. }else{
  166. mui.toast("加载设备列表失败")
  167. }
  168. })
  169. }
  170. function showList(rowData){
  171. var img='xuetangyi_icon.png';
  172. if(rowData.categoryCode==2){
  173. img='xueyaji_icon.png';
  174. }
  175. var bindUser ="患者绑定";
  176. if(!!rowData.doctor){
  177. bindUser = rowData.doctorName;
  178. }
  179. var showDomLi = '<li class="inp" device-id="'+rowData.deviceId+'" data-type="'+rowData.categoryCode+'" data-id="'+rowData.id+'" data-role="'+rowData.role+'">'+
  180. '<div class="icon-div">'+
  181. '<img src="'+rowData.devicePhoto+'">'+
  182. '</div>'+
  183. '<div class="div-content">'+rowData.deviceName+'</div>'+
  184. '<div class="div-sn"><span class="bullspan">&bull; </span>绑定时间:'+rowData.czrq+'</div>'+
  185. '<div class="div-sn2"><span class="bullspan">&bull;</span> 绑定人:'+bindUser+'</div>'+
  186. '</li>';
  187. $("#equip-list").append(showDomLi);
  188. }
  189. function getBJRecordType(isDevice) {
  190. return isDevice === 0 ? "手动记录" : isDevice == 1 ? "设备上传" : '';
  191. }
  192. function checkDate (v) {
  193. return (v < 10 ? '0' + v : v);
  194. }
  195. //获取最新的体征记录
  196. function getRecentDataPromise() {
  197. return new Promise(function(resolve, reject) {
  198. sendGet("doctor/health_index/last", {patient:patientCode}, function (res) {
  199. resolve(res)
  200. }, function(res){
  201. if(res.status == 200) {
  202. resolve(res)
  203. } else {
  204. mui.toast('数据查询失败')
  205. }
  206. })
  207. })
  208. }
  209. //获取最新保健记录
  210. function getBJRecentDataPromise () {
  211. return new Promise(function( resolve, reject){
  212. sendGet("doctor/health_record/recent", {patient:patientCode}, function (res) {
  213. resolve(res)
  214. }, function(res){
  215. if(res.status == 200) {
  216. resolve(res)
  217. } else {
  218. mui.toast('数据查询失败')
  219. }
  220. })
  221. })
  222. }
  223. function getLevelClazz(value,max,min) {
  224. if(!value||(!max && !min)) {
  225. return '';
  226. }
  227. var value = parseFloat(value);
  228. if(value < min) {
  229. return 'low';
  230. } else if(value > max) {
  231. return 'high';
  232. } else {
  233. return ''
  234. }
  235. }
  236. function bindEvents() {
  237. $("#tzyj_btn").on("click", function() {
  238. mui.openWindow('../../huanzhe/html/tzyj.html', 'tzyj', {
  239. extras: {
  240. code: patientCode
  241. }
  242. })
  243. })
  244. //标签切换
  245. $(".pt-tab li").click(function() {
  246. var id = $(this).attr("id");
  247. $(".pt-tab li").removeClass("hit");
  248. $(this).addClass("hit");
  249. if(id == "tizhengLi") {
  250. $("#tizhengList").show();
  251. $("#baojianList").hide();
  252. $("#equipment").hide();
  253. $('.icon-share').show();
  254. $('.header-group').show();
  255. }else if(id == "healthLi"){
  256. $("#tizhengList").hide();
  257. $("#baojianList").show();
  258. $("#equipment").hide();
  259. $('.icon-share').show();
  260. $('.header-group').show();
  261. }else if(id == "equipLi"){
  262. $("#tizhengList").hide();
  263. $("#baojianList").hide();
  264. $("#equipment").show();
  265. $('.icon-share').hide();
  266. $('.header-group').hide();
  267. }
  268. })
  269. $(".icon-share").on("click", function() {
  270. var msg = {
  271. "title": "健康记录",
  272. "id": patientCode,
  273. "type": 1,
  274. "content": "这是" + self.patientName + "的历史体征指标及保健记录,请点击查看"
  275. }
  276. mui.openWindow({
  277. url: "../../message/html/zhuanfa.html",
  278. id: "zhuanfa.html",
  279. extras: {
  280. imMessages: [{
  281. content: JSON.stringify(msg),
  282. type: 4
  283. }]
  284. }
  285. })
  286. })
  287. $('#tizhengList').on('click','li',function() {
  288. var index = $(this).index();
  289. var dat = new Date(),
  290. nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
  291. if(index == 0) {
  292. mui.openWindow('../html/xuetang-view.html', 'xuetang-view.html', {
  293. extras: {
  294. code: patientCode,
  295. dateT: (xtdt || nowD)
  296. }
  297. });
  298. }
  299. if(index == 1) {
  300. mui.openWindow('../html/xueya-view.html', 'xueya-view.html', {
  301. extras: {
  302. code: patientCode,
  303. dateT: (xydt || nowD)
  304. }
  305. });
  306. }
  307. if(index == 3) {
  308. mui.openWindow('../html/tizhong-view.html', 'tizhong-view.html', {
  309. extras: {
  310. code: patientCode,
  311. dateT: (tzdt || nowD)
  312. }
  313. });
  314. }
  315. if(index == 2) {
  316. mui.openWindow('../html/yaowei-view.html', 'yaowei-view.html', {
  317. extras: {
  318. code: patientCode,
  319. dateT: (ywdt || nowD)
  320. }
  321. });
  322. }
  323. })
  324. $('#baojianList').on('click','li',function() {
  325. var index = $(this).index();
  326. var dat = new Date(),
  327. nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
  328. if(index == 0) {
  329. mui.openWindow('../html/yundong-view.html', 'yundong-view.html', {
  330. extras: {
  331. code: patientCode,
  332. dateT: (yddt || nowD)
  333. }
  334. });
  335. }
  336. if(index == 1) {
  337. mui.openWindow('../html/yongyao-view.html', 'yongyao-view.html', {
  338. extras: {
  339. code: patientCode,
  340. dateT: (yydt || nowD)
  341. }
  342. });
  343. }
  344. if(index == 2) {
  345. mui.openWindow('../html/yinshi-view.html', 'yinshi-view.html', {
  346. extras: {
  347. code: patientCode,
  348. dateT: (ysdt || nowD)
  349. }
  350. });
  351. }
  352. })
  353. //**************体征设备
  354. //新增按钮事件
  355. $(".div-add-btn").on("click",function(){
  356. $(this).hide();
  357. if($(this).hasClass("active")){
  358. $(".modal-overlay").trigger("click");
  359. }else{
  360. $(this).addClass("active");
  361. $(".modal-overlay").addClass("modal-overlay-visible");
  362. $(".div-dialog-content").show();
  363. }
  364. })
  365. //点击遮罩事件
  366. $(".modal-overlay").on("click",function(){
  367. $(".modal-overlay").removeClass("modal-overlay-visible");
  368. $(".div-dialog-content").hide();
  369. $(".div-add-btn").removeClass("active");
  370. $(".div-add-btn").show();
  371. })
  372. //取消事件
  373. $(".quxiao").on("click",function(){
  374. $(".modal-overlay").trigger("click");
  375. })
  376. //点击血糖仪事件
  377. $(".xuetangyi-icon").on("click",function(){
  378. $(".quxiao").click();
  379. mui.openWindow('../../wdsb/html/list-xuetangyi.html', 'list-xuetangyi.html', {
  380. extras: {
  381. category_code: 1,
  382. patient:patientCode
  383. }
  384. })
  385. })
  386. //点击血压计事件
  387. $(".xueyaji-icon").on("click",function(){
  388. $(".quxiao").click();
  389. mui.openWindow('../../wdsb/html/list-xueyaji.html', 'list-xueyaji.html', {
  390. extras: {
  391. category_code: 2,
  392. patient:patientCode
  393. }
  394. })
  395. })
  396. //绑定编辑和删除事件
  397. $("#equip-list").on("click","li",function(){
  398. var code = $(this).attr("data-id");
  399. var deviceId = $(this).attr("device-id");
  400. var type = $(this).attr("data-type");
  401. var role = $(this).attr("data-role");
  402. if(type==1){
  403. mui.openWindow('../../wdsb/html/view-xuetangyi.html', 'view-xuetangyi.html', {
  404. extras: {
  405. deviceId: deviceId,
  406. dataId:code,
  407. patient:patientCode,
  408. role:role
  409. }
  410. })
  411. }else if(type==2){
  412. mui.openWindow('../../wdsb/html/view-xueyaji.html', 'view-xueyaji.html', {
  413. extras: {
  414. deviceId: deviceId,
  415. dataId:code,
  416. patient:patientCode,
  417. role:role
  418. }
  419. })
  420. }
  421. })
  422. }
  423. function getRecordType(isDevice) {
  424. return isDevice === null ? "手动记录" : isDevice != null ? "设备上传" : '';
  425. }
  426. var html = template('tizheng_list_temp',{
  427. xuetang:{},
  428. xueya:{},
  429. tizhong:{},
  430. yaowei:{}
  431. });
  432. $tizhengList.html(html);
  433. //页面局部刷新
  434. window.addEventListener("refreshEquipment", function(){
  435. getEquipments()
  436. })