questionaires.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. var request = getRequest(),
  2. fv_id = request.fv_id,
  3. pro_id = request.pro_id,
  4. title = request.title,
  5. fv_class = request.fv_class,
  6. patiCode = request.patiCode;
  7. var docInfo = window.localStorage.getItem('docInfo');
  8. if(docInfo){
  9. docInfo = JSON.parse(docInfo);
  10. }
  11. var requiredFields=[];
  12. var project_data = gTemplate[pro_id]; //获得模板中的数据显示
  13. $(function(){
  14. if(pro_id == 9){
  15. $("#submitBtn").text("保存");
  16. }
  17. getProjectData();
  18. bindEvents();
  19. });
  20. function getProjectData(){
  21. var params = {
  22. id: fv_id,
  23. followupProject: pro_id
  24. }
  25. followupAPI.getFollowupProjectData(params).then(function(res){
  26. if(res.status == 200){
  27. if(pro_id == 5){
  28. if(fv_class == 1){//高血压
  29. project_data = _.pick(project_data, 'HYP_FOLLOWUP_TYPE_CODE', 'HYP_COMPLICATION_DETAIL');
  30. }else if(fv_class == 2){//糖尿病
  31. project_data = _.pick(project_data, 'DIA_FOLLOWUP_TYPE_CODE', 'DIA_COMPLICATION_DETAIL');
  32. }
  33. }
  34. for(key in project_data){
  35. project_data[key].value = res.data?res.data[key]:'';
  36. if(project_data[key].type==4 || project_data[key].type==3) {
  37. if(project_data[key].value){
  38. project_data[key].valueLength = project_data[key].value.length;
  39. }
  40. }
  41. if(project_data[key].type==5){
  42. var isRequired = project_data[key].required;
  43. for(var i = 0; i<project_data[key].items.length; i++){
  44. var it = project_data[key].items[i];
  45. it.value = res.data ? res.data[it.name]:'';
  46. if(isRequired){
  47. var isEmpty = it.value == "" ? true : false;
  48. requiredFields.push({
  49. name: it.name,
  50. type: it.type,
  51. textType: it.textType
  52. });
  53. }
  54. }
  55. }else{
  56. //非并联控件的field的required的处理
  57. if(project_data[key].required){
  58. var isEmpty = project_data[key].value == "" ? true : false;
  59. requiredFields.push({
  60. name: key,
  61. type: project_data[key].type,
  62. textType: project_data[key].textType
  63. });
  64. }
  65. }
  66. }
  67. var html = template("item", {
  68. data:project_data,
  69. followupClass:fv_class,
  70. pro_id: pro_id,
  71. title: decodeURI(title)
  72. });
  73. $("#question_form .form-info").append(html);
  74. if(pro_id == 7){//控制目标
  75. $("input[name=CONTROL_CONSTITUTOR]").val(docInfo.name);
  76. }
  77. $(".q-note-"+pro_id).removeClass("hidden");
  78. initChosen();
  79. initDatePicker();
  80. initPopover();
  81. checkBtnEnable();
  82. }else{
  83. showErrorMsg(res.msg);
  84. }
  85. });
  86. }
  87. function initChosen(){
  88. $(".my_select_box").chosen({
  89. disable_search: true,
  90. inherit_select_classes: true, //将设定的样式添加到插件的控件中
  91. disable_search_threshold: 10,
  92. no_results_text: "",
  93. width: "100%"
  94. });
  95. }
  96. function initDatePicker(){
  97. $(".date").datepicker({
  98. format: 'yyyy-mm-dd',
  99. language: 'zh-CN',
  100. autoclose: true,
  101. todayHighlight: 1,
  102. todayBtn: 'linked',
  103. });
  104. }
  105. function initPopover(){
  106. var $inputs = $("input"),
  107. len = $inputs.length;
  108. for(i=0; i<len; i++){
  109. var $item = $($inputs[i]),
  110. name = $item.attr("name");
  111. switch(name){
  112. case "BP_U": //血压
  113. case "BP_D": //血压
  114. case "CONTROL_BP_U": //目标血压
  115. case "CONTROL_BP_D": //目标血压
  116. $item.popover({
  117. content: '<a onclick="getHistory(\''+name+'\', this)">从居民血压记录中获取</a>',
  118. html: true,
  119. placement: 'bottom',
  120. trigger: 'focus',
  121. delay: {hide: 300}
  122. });
  123. break;
  124. case "BS_FPG": //空腹血糖
  125. case "NO_BS_FPG": //餐后血糖
  126. case "RANDOM_BLOOD_SUGAR": //随机血糖
  127. case "CONTROL_BS_FPG":
  128. case "CONTROL_NO_BS_FPG":
  129. $item.popover({
  130. content: '<a onclick="getHistory(\''+name+'\', this)">从居民血糖记录中获取</a>',
  131. html: true,
  132. placement: 'bottom',
  133. trigger: 'focus',
  134. delay: {hide: 300}
  135. });
  136. break;
  137. case "HEIGHT":
  138. case "WEIGHT":
  139. $item.popover({
  140. content: '<a onclick="getHistory(\''+name+'\', this)">从居民身高体重记录中获取</a>',
  141. html: true,
  142. placement: 'bottom',
  143. trigger: 'focus',
  144. delay: {hide: 300}
  145. });
  146. break;
  147. default:
  148. break;
  149. }
  150. }
  151. }
  152. //获得历史记录 type: BP - 血压,
  153. function getHistory(type, el){
  154. console.log(type);
  155. var colObj = {},
  156. reqType = 0,
  157. tableId = "",
  158. modalTitle = "";
  159. switch(type){
  160. case "BP_U": //血压
  161. case "BP_D": //血压
  162. case "CONTROL_BP_U": //目标血压
  163. case "CONTROL_BP_D":
  164. reqType = 2;
  165. tableId = "bp_table";
  166. modalTitle = "血压记录";
  167. colObj = {
  168. colNames: ["记录时间", "血压", "操作"],
  169. colModel: [
  170. {name: 'time', index: 'time', width: '150', align: 'center'},
  171. {name: '', index: '', width: '150', align: 'center',
  172. formatter: function(val, op, row){
  173. return row.sys + ' / ' + row.dia+ ' mmHg';
  174. }},
  175. {name: '', index: '', width: '100', align: 'center',
  176. formatter: function(val, op, row){
  177. return '<a onclick="fillHistoryData(\''+type+'\', '+ row.sys +', '+ row.dia +')">填入随访记录</a>';
  178. }}
  179. ]
  180. };
  181. break;
  182. case 'HEIGHT':
  183. case 'WEIGHT':
  184. reqType = 3;
  185. tableId = "weight_table";
  186. modalTitle = "身高体重记录";
  187. colObj = {
  188. colNames: ["记录时间", "身高", "体重", "操作"],
  189. colModel: [
  190. {name: 'time', index: 'time', width: '150', align: 'center'},
  191. {name: 'height', index: 'height', width: '100', align: 'center',
  192. formatter: function(val, op, row){
  193. return val + ' cm';
  194. }},
  195. {name: 'weight', index: 'weight', width: '100', align: 'center',
  196. formatter: function(val, op, row){
  197. return val + ' Kg';
  198. }},
  199. {name: '', index: '', width: '100', align: 'center',
  200. formatter: function(val, op, row){
  201. return '<a onclick="fillHistoryData(\''+type+'\','+row.height+','+row.weight+')">填入随访记录</a>';;
  202. }}
  203. ]
  204. };
  205. break;
  206. case "BS_FPG": //空腹血糖
  207. case "NO_BS_FPG": //餐后血糖
  208. case "RANDOM_BLOOD_SUGAR": //随机血糖
  209. case "CONTROL_BS_FPG":
  210. case "CONTROL_NO_BS_FPG":
  211. reqType = 1;
  212. tableId = "bs_table";
  213. modalTitle = "血糖记录";
  214. colObj = {
  215. colNames: ["记录时间", "血糖", "操作"],
  216. colModel: [
  217. {name: 'time', index: 'time', width: '150', align: 'center'},
  218. {name: 'gi', index: 'gi', width: '150', align: 'center',
  219. formatter: function(val, op, row){
  220. return row.gi + ' mmol/L';
  221. }},
  222. {name: '', index: '', width: '100', align: 'center',
  223. formatter: function(val, op, row){
  224. return '<a onclick="fillHistoryData(\''+type+'\', '+ row.gi +')">填入随访记录</a>';
  225. }}
  226. ]
  227. };
  228. break;
  229. }
  230. colObj.ajaxGridOptions = {
  231. data: {
  232. patient:patiCode,
  233. type: reqType,
  234. page:0,
  235. pagesize: 10
  236. }
  237. };
  238. $("#modal-title").text(modalTitle);
  239. if($("#"+tableId).length == 0){
  240. var html = '<table id="'+tableId+'"></table>';
  241. $("#myModal .modal-body").empty().append(html);
  242. fillHistoryTable(colObj, true, tableId);
  243. }else{
  244. fillHistoryTable(colObj, false, tableId);
  245. }
  246. }
  247. //填充血压历史记录数据
  248. function fillHistoryTable(colObj, isInit, tableId){
  249. console.log(colObj);
  250. var option = {
  251. height: '400px',
  252. rowNum: 10,
  253. rowList : [ 10, 20, 30 ],
  254. jsonReader: {
  255. root: 'data'
  256. },
  257. viewrecords: true,
  258. hidegrid: false
  259. };
  260. $.extend(true, option, followupAPI.getHistoryTableObj);
  261. $.extend(true, option, colObj);
  262. if(isInit){
  263. $("#"+tableId).jqGrid(option);
  264. }else{
  265. $("#"+tableId).clearGridData();
  266. $("#"+tableId).jqGrid('setGridParam', colObj);
  267. $("#"+tableId).trigger("reloadGrid");
  268. }
  269. $("#myModal").modal('toggle');
  270. }
  271. //将选中的历史信息填写到随访记录中
  272. function fillHistoryData(type, val1, val2){
  273. switch(type){
  274. case 'BP_D':
  275. case 'BP_U':
  276. $("input[name=BP_D]").val(val1);
  277. $("input[name=BP_U]").val(val2);
  278. break;
  279. case 'HEIGHT':
  280. case 'WEIGHT':
  281. $("#HEIGHT").val(val1);
  282. $("#WEIGHT").val(val2);
  283. var w = parseFloat(val2),
  284. h = parseFloat(val1);
  285. var BMI = w/(h/100 * h/100);
  286. if(!isNaN(BMI)){
  287. $("input[name=BMI]").val(BMI.toFixed(2));
  288. }
  289. break;
  290. case 'CONTROL_BP_D':
  291. case 'CONTROL_BP_U':
  292. $("input[name=CONTROL_BP_D]").val(val1);
  293. $("input[name=CONTROL_BP_U]").val(val2);
  294. break;
  295. default:
  296. $("input[name="+type+"]").val(val1);
  297. break;
  298. }
  299. checkBtnEnable();
  300. $("#myModal").modal('toggle');
  301. }
  302. //判断按钮是否可执行
  303. function checkBtnEnable(){
  304. //先判断是否存在必填项目,如果没有必填项目,则至少需要填写一个
  305. var disabled = true;
  306. if(requiredFields.length == 0){
  307. var $inputs = $("input"),
  308. input_len = $inputs.length,
  309. $textarea = $("textarea"),
  310. textarea_len = $textarea.length,
  311. $select = $("select"),
  312. select_len = $select.length;
  313. for(var i=0; i<input_len; i++){
  314. var $item = $($inputs[i]),
  315. textType = $item.attr("type"),
  316. value = $item.val();
  317. if(textType == "radio"){
  318. if($item.prop("checked")){
  319. disabled = false;
  320. break;
  321. }
  322. }else if(textType == "checkbox"){
  323. if($item.prop("checked")){
  324. disabled = false;
  325. break;
  326. }
  327. }else{
  328. if(value.length > 0){
  329. disabled = false;
  330. break;
  331. }
  332. }
  333. }
  334. }else{
  335. for(var i=0; i<requiredFields.length; i++){
  336. var item = requiredFields[i],
  337. value; //目前只有下拉框、输入框、textarea
  338. if(item.type == 4){
  339. value = $("textarea[name="+item.name+"]").val();
  340. if(value.length > 0){
  341. disabled = false;
  342. }else{
  343. disabled = true;
  344. break;
  345. }
  346. }else if(item.type == 2){ //radio
  347. value = $("input[name="+item.name+"]").val();
  348. if(value.length > 0){
  349. disabled = false;
  350. }else{
  351. disabled = true;
  352. break;
  353. }
  354. }else if(item.type == 1){
  355. if(item.textType == 'select'){
  356. value = $("select[name="+item.name+"]").val();
  357. if(value != "undefined"){
  358. disabled = false;
  359. }else{
  360. disabled = true;
  361. break;
  362. }
  363. }else{
  364. value = $("input[name="+item.name+"]").val();
  365. if(value.length > 0){
  366. disabled = false;
  367. }else{
  368. disabled = true;
  369. break;
  370. }
  371. }
  372. }
  373. }
  374. }
  375. if(disabled){
  376. $("#submitBtn").addClass("disabled");
  377. }else{
  378. $("#submitBtn").removeClass("disabled");
  379. }
  380. }
  381. function submitForm(){
  382. if($("#submitBtn").hasClass("disabled")){
  383. return false;
  384. }
  385. if(pro_id == 3) { // 实验室检查,空腹血糖、餐后血糖、随机血糖、三项需必填一项
  386. var bsValue = $('input[name="BS_FPG"]').val()
  387. || $('input[name="NO_BS_FPG"]').val()
  388. || $('input[name="RANDOM_BLOOD_SUGAR"]').val()
  389. if(!bsValue) {
  390. showWarningMsg("血糖必填一项");
  391. return false;
  392. }
  393. }
  394. var data = {};
  395. $("#question_form").serializeArray().map(function(x){
  396. data[x.name]=x.value;
  397. });
  398. if(pro_id == 7){
  399. data.CONTROL_CONSTITUTOR_DOCTORCODE = docInfo.code;
  400. }
  401. var params = {
  402. id: fv_id,
  403. followupProject:pro_id,
  404. followupProjectData: JSON.stringify(data)
  405. };
  406. followupAPI.saveFollowupProjectData(params).then(function(res){
  407. // var projectName = ['症状', '体征', '实验室检查', '生活方式指导', '评价', '用药情况', '控制目标', '健康教育', '转诊'];
  408. if(res.status == 200){
  409. // var title = projectName[pro_id];
  410. // pro_id ++;
  411. if(pro_id > 9){
  412. //保存成功后不做任何操作。
  413. }else{
  414. //控制tab页面,跳转选中下一个tab
  415. parent.goFollowupNextQuestionaire();
  416. }
  417. }else{
  418. showErrorMsg(res.msg);
  419. }
  420. });
  421. return false;
  422. }
  423. function bindEvents(){
  424. //监听表单数据信息变化
  425. $("#question_form").on("change", "input", function(){
  426. //先判断数字键盘不能输入负数
  427. var textType = $(this).attr("type");
  428. if(textType == "number"){
  429. this.value = this.value.replace(/\-/g,"");
  430. }
  431. checkBtnEnable();
  432. var name = $(this).attr("name");
  433. //计算BMI值 体质指数(BMI)=体重(kg)÷身高^2(m)
  434. switch(name){
  435. case "WEIGHT":
  436. case "WEIGHT_EXP":
  437. case "HEIGHT":
  438. var w = parseFloat($("input[name=WEIGHT]").val()),
  439. ex_w = parseFloat($("input[name=WEIGHT_EXP]").val()),
  440. h = parseFloat($("input[name=HEIGHT]").val());
  441. var BMI = w/(h/100 * h/100),
  442. EX_BMI = ex_w/(h/100 * h/100);
  443. if(!isNaN(BMI)){
  444. $("input[name=BMI]").val(BMI.toFixed(2));
  445. }
  446. if(!isNaN(EX_BMI)){
  447. $("input[name=BMI_EXP]").val(EX_BMI.toFixed(2));
  448. }
  449. break;
  450. }
  451. });
  452. $("#question_form").on("keypress", "input[type=number]", function(event){
  453. if(event.keyCode == 45){
  454. event.preventDefault();
  455. }
  456. })
  457. //监听下拉框的变化
  458. $("#question_form").on("change", "select", function(){
  459. checkBtnEnable();
  460. });
  461. //监听输入框内容变化
  462. $("#question_form").on("keyup", "textarea", function(){
  463. checkBtnEnable();
  464. var text = $(this).val(),
  465. len = text.length,
  466. $p = $(this).siblings();
  467. $p.find(".other-count").text(len);
  468. });
  469. }