health-record.js 12 KB

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