drugs.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. var self,
  2. pro_id,
  3. followupClass,
  4. patientCode,
  5. fv_id;
  6. mui.plusReady(function() {
  7. self = plus.webview.currentWebview();
  8. fv_id = self.followup_id;//编号
  9. pro_id = self.project_id;//项目顺序 6
  10. patientCode = self.patientCode;
  11. followupClass = self.followupClass;//高糖类型
  12. //获取用药信息
  13. plus.nativeUI.showWaiting();
  14. sendGet("/doctor/followup/getFollowupProjectData", {id: fv_id,followupProject: pro_id},function(){
  15. plus.nativeUI.closeWaiting()
  16. mui.toast("请求失败")
  17. },function(res){
  18. plus.nativeUI.closeWaiting()
  19. if(res.status == 200){
  20. if(res.data){
  21. regular = res.data.DRUG_COMPLIANCE_CODE
  22. var typeObj = {1:'规律服药', 2:'间断服药', 3:'不服药'};
  23. $('#compliance_code').val(typeObj[regular])
  24. $('#compliance_code').attr('data-id',regular)
  25. nextSendQuery(false)
  26. }else{
  27. nextSendQuery(true)
  28. }
  29. }else{
  30. mui.toast("获取数据失败")
  31. }
  32. })
  33. function nextSendQuery(boolen){
  34. sendPost("doctor/followup/drugs/getFollowupDrugs",{id:fv_id}, function(){
  35. plus.nativeUI.closeWaiting()
  36. mui.toast("请求失败")
  37. }, function(res){
  38. if(res.status == 200){
  39. var data = res.data.DRUG_LIST,
  40. hasInsulin=[],
  41. noInsulin=[];
  42. if(data.length>0){
  43. for(var i=0;i<data.length;i++){
  44. if(data[i].drugsGroup == 'insulin'){//胰岛素药品
  45. hasInsulin.push(data[i])
  46. }else{
  47. noInsulin.push(data[i])
  48. }
  49. }
  50. mediTemplate(hasInsulin,1,true);
  51. mediTemplate(noInsulin,0,true);
  52. monitorNum()
  53. startDose();
  54. plus.nativeUI.closeWaiting();
  55. }else{
  56. if(boolen){//保存无药品,不再请求接口
  57. var params={
  58. type:1,
  59. isRenewal:2,
  60. recipeNo:0,
  61. diagnosisCode:followupClass=='1,2'?3:followupClass,
  62. patientCode:patientCode
  63. }
  64. sendPost("doctor/prescriptionInfo/getPrescriptionInfos",params, function(){
  65. plus.nativeUI.closeWaiting()
  66. mui.toast("请求失败")
  67. }, function(res){
  68. plus.nativeUI.closeWaiting();
  69. if(res.status == 200){
  70. if( res.data.length>0 && res.data[0].prescriptionInfo.length>0){
  71. var content = res.data[0].prescriptionInfo;
  72. var hasArr=[],
  73. allArr=content,
  74. noArr=[];
  75. $.map(allArr,function(o,i){
  76. o.drugsName = o.drugName;
  77. o.drugsCode = o.drugCode;
  78. o.frequency = o.drugRate;
  79. o.dose = o.physicDose;
  80. o.unit = o.physicDoseUnit;
  81. var subjectClass = o.subjectClass;
  82. var name = o.drugsName;
  83. if(subjectClass.substr(0,2)=='010' && name.indexOf('胰岛素')>0){
  84. hasArr.push(o)
  85. }else{
  86. noArr.push(o)
  87. }
  88. })
  89. mediTemplate(noArr,0,true);
  90. mediTemplate(hasArr,1,true);
  91. addMedicineUnit($('.j-selUnit'),false);
  92. addMedicineFreq($('.j-selFreq'),false);
  93. monitorNum()
  94. startDose();
  95. }else{
  96. mediTemplate([],true);
  97. startDose();
  98. }
  99. }else{
  100. mui.toast("获取数据失败")
  101. }
  102. },'get')
  103. }else{
  104. mediTemplate([],true);
  105. startDose();
  106. }
  107. }
  108. }else{
  109. mui.toast("获取数据失败")
  110. }
  111. },'get')
  112. }
  113. function mediTemplate(arr,num,state){
  114. var medi_html = template('medi_tmp',{data:$.map(arr,function(o,index){
  115. o.jsonVal = JSON.stringify(o);
  116. return o })
  117. })
  118. if(num>=0){
  119. if(state){
  120. $(".j-showList").eq(num).html(medi_html);
  121. }else{
  122. $(".j-showList").eq(num).append(medi_html);
  123. }
  124. }else{
  125. if(state){
  126. $(".j-showList").html(medi_html);
  127. }else{
  128. $(".j-showList").append(medi_html);
  129. }
  130. }
  131. }
  132. function startDose(){
  133. $('#mainContain').show()
  134. //填充服药依从性的下拉内容
  135. var type_keys = ['1','2','3'],
  136. type_vals = ['规律服药','间断服药','不服药'];
  137. $('#compliance_code').mobiscroll({
  138. theme: 'ios',
  139. lang: 'zh',
  140. customWheels: true,
  141. wheels: [
  142. [{
  143. keys: type_keys,
  144. values: type_vals
  145. }]
  146. ],
  147. onSelect: function(valueText, inst) {
  148. var dd = eval("[" + valueText + "]");
  149. $(this).val(dd[0].values);
  150. $(this).attr('data-id',dd[0].keys);
  151. }
  152. });
  153. bindEvents();
  154. addMedicineUnit($('.j-selUnit'),false);
  155. addMedicineFreq($('.j-selFreq'),false);
  156. //添加药品
  157. window.addEventListener("addMedicine", function(){
  158. var content = JSON.parse(plus.storage.getItem("chooseMedicineList"));
  159. var type = plus.storage.getItem("medicineType")*1
  160. var arr=[];
  161. arr.push(content)
  162. $.map(arr,function(o,i){
  163. o.drugsName = o.drugName;
  164. o.drugsCode = o.drugCode;
  165. return o
  166. })
  167. mediTemplate(arr,type,false);
  168. addMedicineUnit($(".j-showList").eq(type).find('.j-selUnit:last'),true)
  169. addMedicineFreq($(".j-showList").eq(type).find('.j-selFreq:last'),true)
  170. monitorNum()
  171. plus.storage.removeItem("chooseMedicineList")
  172. plus.storage.removeItem("medicineType")
  173. })
  174. //模板添加药品
  175. window.addEventListener("addMediMsg", function(){
  176. var content = JSON.parse(plus.storage.getItem("medicineData"));
  177. var hasArr=[],
  178. allArr=content,
  179. noArr=[];
  180. $.map(allArr,function(o,i){
  181. o.drugsName = o.drugName;
  182. o.drugsCode = o.drugCode;
  183. o.frequency = o.drugRate;
  184. o.dose = o.physicDose;
  185. o.unit = o.physicDoseUnit;
  186. var subjectClass = o.subjectClass;
  187. var name = o.drugsName;
  188. if(subjectClass.substr(0,2)=='010' && name.indexOf('胰岛素')>0){
  189. hasArr.push(o)
  190. }else{
  191. noArr.push(o)
  192. }
  193. })
  194. mediTemplate(noArr,0,true);
  195. mediTemplate(hasArr,1,true);
  196. monitorNum()
  197. addMedicineUnit($('.j-selUnit'),false);
  198. addMedicineFreq($('.j-selFreq'),false);
  199. plus.storage.removeItem("medicineData")
  200. })
  201. }
  202. })
  203. function bindEvents(){
  204. //删除
  205. $("#mainContain").on('click','.j-delete',function(){
  206. var $this = $(this).closest('.cc-ul');
  207. $this.remove();
  208. monitorNum()
  209. })
  210. //添加药品
  211. $('.cc-add-drug').click(function(){
  212. mui.openWindow({
  213. id: "add_drug",
  214. url: "add_drug.html",
  215. extras: {
  216. classes:$(this).attr('data-id')
  217. }
  218. })
  219. })
  220. //清空药品
  221. $('.j-clean').click(function(){
  222. $(this).closest('.dr-section').find('.j-showList').empty()
  223. monitorNum()
  224. })
  225. //提交
  226. $('#confirm').click(function(e){
  227. e.stopPropagation();
  228. if(checkOk()){
  229. plus.nativeUI.showWaiting();
  230. var msgArr = [],
  231. $list = $('.j-showList').eq(1).find('.cc-ul'),//有胰岛素
  232. $nolist = $('.j-showList').eq(0).find('.cc-ul');//无胰岛素
  233. for(var i=0;i<$list.length;i++){
  234. var data = {};
  235. data.drugsCode = $list.eq(i).find('.j-medi-name').attr('data-id');
  236. data.drugsName = $list.eq(i).find('.j-medi-name').val();
  237. data.drugsGroup = 'insulin';
  238. data.frequency = $list.eq(i).find('.j-selFreq').attr('data-code');
  239. data.unit = $list.eq(i).find('.j-selUnit').attr('data-code');
  240. data.dose = $list.eq(i).find('.j-medi-single').val().trim();
  241. msgArr.push(data);
  242. }
  243. for(var i=0;i<$nolist.length;i++){
  244. var data = {};
  245. data.drugsCode = $nolist.eq(i).find('.j-medi-name').attr('data-id');
  246. data.drugsName = $nolist.eq(i).find('.j-medi-name').val();
  247. data.drugsGroup = 'normal';
  248. data.frequency = $nolist.eq(i).find('.j-selFreq').attr('data-code');
  249. data.unit = $nolist.eq(i).find('.j-selUnit').attr('data-code');
  250. data.dose = $nolist.eq(i).find('.j-medi-single').val().trim();
  251. msgArr.push(data);
  252. }
  253. sendPost("doctor/followup/drugs/saveFollowupDrugs",{drugsData:JSON.stringify(msgArr),id:fv_id}, function(){
  254. plus.nativeUI.closeWaiting();
  255. mui.toast("请求失败");
  256. }, function(res){
  257. if(res.status == 200){
  258. var params = {};
  259. params.id = fv_id;
  260. params.followupProject = pro_id;
  261. var data = {'DRUG_COMPLIANCE_CODE':$("#compliance_code").attr("data-id")};
  262. params.followupProjectData = JSON.stringify(data);
  263. sendPost('doctor/followup/saveFollowupProjectData',params,function(){
  264. plus.nativeUI.closeWaiting();
  265. mui.toast("请求失败");
  266. }, function(res){
  267. plus.nativeUI.closeWaiting();
  268. if(res.status == 200){
  269. mui.toast("保存成功");
  270. var preWebview = plus.webview.getWebviewById('fvDetail'),
  271. curWebview = plus.webview.currentWebview();
  272. mui.fire(preWebview,"refresh");
  273. setTimeout(function(){
  274. curWebview.close();
  275. },1000)
  276. }else{
  277. mui.toast("保存失败");
  278. }
  279. })
  280. }else{
  281. plus.nativeUI.closeWaiting();
  282. mui.toast("保存失败");
  283. }
  284. })
  285. }
  286. })
  287. // $("#mainContain").on("change",".j-medi-single",function(){
  288. // var $val = $(this).val().trim()
  289. // var reg = /^[0-9]+(.[0-9]{1,5})?$/;
  290. // if($val && reg.test($val)){
  291. //
  292. // }else{
  293. // $(this).val('')
  294. // }
  295. // })
  296. //居民用药记录
  297. $('.dr-getmsg').click(function(){
  298. mui.openWindow({
  299. id: "history_medication",
  300. url: "history_medication.html",
  301. extras: {
  302. patientCode:patientCode,
  303. followupClass:followupClass
  304. }
  305. })
  306. })
  307. }
  308. //用药频率
  309. function addMedicineFreq($id,newADD){
  310. for(i=0; i<$id.length; i++){
  311. var html = '<option disabled selected></option>';
  312. //取频率code
  313. if(newADD){
  314. var obj = JSON.parse($id.closest('.j-showList').find('.cc-ul:last').attr('data-info'));
  315. }else{
  316. var obj = JSON.parse($id.closest('.j-showList').find('.cc-ul').eq(i).attr('data-info'));
  317. }
  318. var code = obj.frequency
  319. for(var key in recipe_frequency_dict){
  320. if(key == code){
  321. html += '<option selected value="'+key+'">'+recipe_frequency_dict[key]+'</option>';
  322. }else{
  323. html += '<option value="'+key+'">'+recipe_frequency_dict[key]+'</option>';
  324. }
  325. }
  326. $id.eq(i).html(html);
  327. $id.eq(i).mobiscroll().select({
  328. theme: 'ios',
  329. lang: 'zh',
  330. display: 'bottom',
  331. placeholder:'请选择用药频次',
  332. rows:7,
  333. onSelect: function ( valueText, inst) {
  334. $(this).closest('.j-selFreq').attr('data-code',inst._tempValue);
  335. $(this).closest('.j-selFreq').attr('data-name',valueText);
  336. }
  337. })
  338. }
  339. }
  340. //用药单位
  341. function addMedicineUnit($id,newADD){
  342. for(i=0; i<$id.length; i++){
  343. var html = '<option disabled selected></option>';
  344. //取频率code
  345. if(newADD){
  346. var obj = JSON.parse($id.closest('.j-showList').find('.cc-ul:last').attr('data-info'));
  347. }else{
  348. var obj = JSON.parse($id.closest('.j-showList').find('.cc-ul').eq(i).attr('data-info'));
  349. }
  350. var code = obj.unit
  351. for(var key in measure_unit_dict){
  352. if(key == code){
  353. html += '<option selected value="'+key+'">'+measure_unit_dict[key]+'</option>';
  354. }else{
  355. html += '<option value="'+key+'">'+measure_unit_dict[key]+'</option>';
  356. }
  357. }
  358. $id.eq(i).html(html);
  359. $id.eq(i).mobiscroll().select({
  360. theme: 'ios',
  361. lang: 'zh',
  362. display: 'bottom',
  363. placeholder:'请选择单位',
  364. rows:7,
  365. onSelect: function ( valueText, inst) {
  366. $(this).closest('.j-selUnit').attr('data-code',inst._tempValue);
  367. $(this).closest('.j-selUnit').attr('data-name',valueText);
  368. }
  369. })
  370. }
  371. }
  372. //监测药品数量
  373. function monitorNum(){
  374. if($('.dr-section').eq(0).find('.j-showList .cc-ul').length >=6){
  375. $('.dr-section').eq(0).find('.dr-add').hide();
  376. }else{
  377. $('.dr-section').eq(0).find('.dr-add').show();
  378. }
  379. if($('.dr-section').eq(1).find('.j-showList .cc-ul').length >=3){
  380. $('.dr-section').eq(1).find('.dr-add').hide();
  381. }else{
  382. $('.dr-section').eq(1).find('.dr-add').show();
  383. }
  384. }
  385. //检查完整
  386. function checkOk(){
  387. var num = $('.cc-ul').length
  388. var selected = $('#compliance_code').attr('data-id')
  389. if(selected!=""){
  390. if(num>0){
  391. for(var i=0;i<num;i++){
  392. var $this = $('.cc-ul').eq(i);
  393. if($this.find('.j-medi-single').val() && $this.find('.j-selUnit').attr('data-code') && $this.find('.j-selFreq').attr('data-code')){
  394. if(i==(num-1)){
  395. //检测重复
  396. var arr=[]
  397. for(var j=0;j<num;j++){
  398. arr.push($('.cc-ul').eq(j).find('.j-medi-name').attr('data-id'));
  399. }
  400. var newArr = _.uniq(arr)
  401. if(newArr.length == arr.length){
  402. return true
  403. }else{
  404. mui.toast('药品出现重复')
  405. return false
  406. }
  407. }
  408. }else{
  409. mui.toast('请完善药品信息')
  410. return false
  411. }
  412. }
  413. }else{
  414. // mui.toast('请添加药品')
  415. return true
  416. }
  417. }else{
  418. mui.toast('请选择服药依从性')
  419. return false
  420. }
  421. }