health-profile.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // 基本信息(包括userAgent、上个页面传递的数据)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. var $profileItemList = $('.lin-sel-group'),
  6. // 搜索无结果时显示
  7. $noResultWrap = $('#no_result_wrap'),
  8. $selectedProfileName = $('#selected_profile_name'),
  9. $pageContent = $('.page-content');
  10. // 分页查询当前页数
  11. var curPage = 1,
  12. // iscroll 滚动条实例
  13. iscroller;
  14. // 获取基本信息(包括userAgent、上个页面传递的数据)
  15. var getBaseInfoPromise = function() {
  16. // 登录的相关信息
  17. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  18. return {
  19. userAgent: userAgent,
  20. eventInfo: baseEnv.webview.eventInfo,
  21. patiInfo: baseEnv.webview.patiInfo
  22. }
  23. },
  24. // 获取基础环境信息
  25. getBaseEnvPromise = function () {
  26. var env = {
  27. webview: plus&&plus.webview.currentWebview()
  28. };
  29. return Promise.resolve().then(function(res) {
  30. return env;
  31. });
  32. },
  33. // 初始化就诊事件列表
  34. initProfileList = function() {
  35. var catalog = baseInfo.eventInfo.CATALOG,
  36. list = [];
  37. // TODO 临时排除
  38. var except = ["0102","0111","0132","0116"];
  39. if(catalog) {
  40. _.mapObject(catalog, function(name, key) {
  41. if(!_.contains(except,$.trim(key))) {
  42. list.push({code: key, name: name})
  43. }
  44. });
  45. // TODO 临时添加档案类型列表
  46. list.push({code: '0201', name: "住院诊疗基本信息"},{code: '0211', name: "住院病案首页"},{code: '0214', name: "长期医嘱"},{code: '0215', name: "临时医嘱"},{code: '0216', name: "住院手术记录"},{code: '0213', name: "出院小结"},{code: '0212', name: "入院病历记录"})
  47. var html = template("profile_item_tmpl", {list: list});
  48. $profileItemList.append(html);
  49. }
  50. var $first = $profileItemList.find("li").eq(0),
  51. name = $.trim($first.attr("data-name")),
  52. code = $.trim($first.attr("data-code"));
  53. $first.addClass('checked');
  54. if(name&&code) {
  55. $selectedProfileName.text(name);
  56. getProfileTemplateHtml(code);
  57. }
  58. },
  59. showProfileItemSel = function() {
  60. var isShow = isShow || $('.lin-mask:hidden').length != 0;
  61. $('.lin-mask').toggle(isShow);
  62. $profileItemList.toggle(isShow);
  63. },
  64. getProfileTemplateHtml = function(tempalteCode){
  65. plus.nativeUI.showWaiting();
  66. var patiInfo = baseInfo.patiInfo,
  67. eventInfo = baseInfo.eventInfo;
  68. var templateRequest = new Promise(function(resolve, reject) {
  69. mui.ajax('../template/'+tempalteCode+'.html',
  70. { dataType: 'html',
  71. type:'GET',
  72. error: function(xht, type, throwErr) {
  73. mui.toast("档案模板获取失败。");
  74. plus.nativeUI.closeWaiting();
  75. },
  76. success: function(html) {
  77. resolve(html);
  78. }
  79. })
  80. }),
  81. profileDataRequest = getReqPromise(healthProfileServer+"wlyy_service/record/healthData",{
  82. strSSID: patiInfo.ssc, // 健康卡号
  83. strEvent: eventInfo.EVENT, // 事件ID
  84. strCatalog: tempalteCode, // 档案类型
  85. strSerial: "1" // 该类别顺序号,默认填1
  86. },'GET');
  87. Promise.all([templateRequest,profileDataRequest]).then(function(datas){
  88. plus.nativeUI.closeWaiting();
  89. var html = datas[0],
  90. profileRes = datas[1];
  91. $pageContent.html(html);
  92. if(profileRes.status == 200) {
  93. var xmlToJson = window["dsXmlToJson"+tempalteCode],
  94. jsonData = {};
  95. if(xmlToJson && $.isFunction(xmlToJson)) {
  96. // xml 转 json
  97. if((typeof profileRes.data=='string')&&profileRes.data.constructor==String) {
  98. // 去除携带的脚本内容
  99. profileRes.data = profileRes.data.replace(/<script[^>]*?>[\s\S]*?<\/script>/ig,'');
  100. jsonData = xmlToJson(profileRes.data.replace(/<\?xml .*\?>/,''));
  101. }
  102. }
  103. renderProfileTemplate($.extend(true,{},jsonData));
  104. } else {
  105. mui.toast(profileRes.msg);
  106. }
  107. }).catch(function(e) { console && console.error(e); plus.nativeUI.closeWaiting(); });
  108. },
  109. renderProfileTemplate = function(data) {
  110. $pageContent.removeAttr('avalonctrl').attr('ms-controller',"viewController");
  111. var vm = avalon.define($.extend({},{"$id": "viewController"},data));
  112. avalon.scan();
  113. },
  114. // 绑定页面事件
  115. bindEvents = function () {
  116. $('.demo-comtop h1').on('click', showProfileItemSel);
  117. $('.lin-mask').on('click', showProfileItemSel);
  118. $profileItemList.on('click', 'li', function(){
  119. var code = $.trim($(this).attr("data-code")),
  120. name = $.trim($(this).attr("data-name"));
  121. getProfileTemplateHtml(code);
  122. $selectedProfileName.text(name);
  123. showProfileItemSel(undefined, false);
  124. if(!$(this).hasClass('checked')){
  125. $(this).addClass('checked').siblings().removeClass('checked');
  126. }
  127. });
  128. };
  129. // 页面业务处理流程开始
  130. new Promise(function(resolve, reject) {
  131. mui.plusReady(function() {
  132. // plus已经准备好,可以往下执行
  133. resolve(true);
  134. });
  135. }).then(function() {
  136. // 获取基础环境信息
  137. return getBaseEnvPromise().then(function(env) {
  138. baseEnv = env;
  139. }).then(function() {
  140. // 获取登录医生信息
  141. baseInfo = getBaseInfoPromise();
  142. initProfileList();
  143. // 绑定页面事件
  144. bindEvents();
  145. })
  146. }).catch(function(e) {
  147. plus.nativeUI.closeWaiting();
  148. console && console.error(e);
  149. });