drugs.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. $(function(){
  12. initPage();
  13. bindEvents();
  14. })
  15. function initPage(){
  16. var params = {
  17. id: fv_id
  18. };
  19. followupAPI.getFollowupDrugs(params).then(function(res){
  20. if(res.status == 200){
  21. var data = res.data.DRUG_LIST,
  22. regular = res.data.DRUG_COMPLIANCE_CODE || '',
  23. hasInsulin=[],
  24. noInsulin=[];
  25. $("[name=DRUG_COMPLIANCE_CODE]").val(regular);
  26. if(data.length>0){
  27. for(var i=0;i<data.length;i++){
  28. var unitInfo = _.findWhere(measure_unit_dict, {key: data[i].unit}),
  29. frequency = _.findWhere(recipe_frequency_dict, {key: data[i].frequency});
  30. data[i].unitName = unitInfo.name;
  31. data[i].frequencyName = frequency.name;
  32. if(data[i].drugsGroup == 'insulin'){//胰岛素药品
  33. hasInsulin.push(data[i])
  34. }else{
  35. noInsulin.push(data[i])
  36. }
  37. }
  38. }
  39. var hasInsulinLen = hasInsulin.length,
  40. noInsulinLen = noInsulin.length,
  41. noInsulinEmptyList = new Array(6 - noInsulinLen), //非胰岛素药品最多只能增加6种
  42. hasInsulinEmptyList = new Array(3 - hasInsulinLen); //胰岛素药品最多只能增加3种
  43. var html1 = template("drug_tmp", {dataList: noInsulin, emptyList: noInsulinEmptyList, isInsulin: false}),
  44. html2 = template("drug_tmp", {dataList: hasInsulin, emptyList: hasInsulinEmptyList, isInsulin: true});
  45. $("#table1 tbody").append(html1);
  46. $("#table2 tbody").append(html2);
  47. initDrugNameSuggestInput();
  48. initUnitInput();
  49. initFreqSuggestInput();
  50. }else{
  51. showErrorMsg(res.msg);
  52. }
  53. })
  54. }
  55. function bindEvents(){
  56. $(".link-red").on("click", function(){
  57. layer.confirm('您确定要清空用药信息吗?', {
  58. btn: ['是的','取消'], //按钮
  59. shade: false //不显示遮罩
  60. }, function(){
  61. //清空数据
  62. clearDrugsInfo();
  63. layer.close(layer.index);
  64. });
  65. });
  66. $("#getPrescription").on("click", function(){
  67. //弹出层是加载在top上的,目前项目的top层是index.html页面层。所以路径需要相对index.html页面
  68. top.layer.open({
  69. type: 2,
  70. type: 2,
  71. title: '<img src="img/shezi_tankuang_icon.png" class="mr10">用药记录',
  72. shadeClose: true,
  73. area: ['700px', '500px'],
  74. content: '/PC-prescription/page/followup/followup-prescriptions.html'+location.search
  75. });
  76. });
  77. $("#submitBtn").on("click", function(){
  78. //保存
  79. var complianceCode = $("[name=DRUG_COMPLIANCE_CODE]").val(),
  80. $trs1 = $("#table1 tbody tr"),
  81. $trs2 = $("#table2 tbody tr"),
  82. drugs = [];
  83. for(var i=0; i<6; i++){
  84. var $tr = $($trs1[i]),
  85. $drug = $tr.find(".j-drugName"),
  86. $dose = $tr.find(".dose"),
  87. $unit = $tr.find(".unit-select"),
  88. $freq = $tr.find(".frequency-select");
  89. var obj = {},
  90. drugsGroup = 'normal',
  91. drugsCode = $drug.attr("data-id"),
  92. drugsName = $drug.val(),
  93. frequency = $freq.attr("data-id"),
  94. unit = $unit.attr("data-id"),
  95. dose = $dose.val();
  96. if(drugsCode && drugsName && dose && unit && frequency){
  97. obj = {
  98. drugsGroup : 'normal',
  99. drugsCode : drugsCode,
  100. drugsName : drugsName,
  101. frequency : frequency,
  102. unit : unit,
  103. dose : dose
  104. };
  105. drugs.push(obj);
  106. }else if(drugsCode || drugsName || dose || unit || frequency){
  107. //如果药品信息中填写了部分,则需要将未填写的内容补全
  108. showWarningMsg("请补全未填写完成的药品信息");
  109. return false;
  110. }
  111. }
  112. for(var j=0; j<3; j++){
  113. var $tr = $($trs2[j]),
  114. $drug = $tr.find(".j-drugName"),
  115. $dose = $tr.find(".dose"),
  116. $unit = $tr.find(".unit-select"),
  117. $freq = $tr.find(".frequency-select");
  118. var obj = {},
  119. drugsGroup = 'insulin',
  120. drugsCode = $drug.attr("data-id"),
  121. drugsName = $drug.val(),
  122. frequency = $freq.attr("data-id"),
  123. unit = $unit.attr("data-id"),
  124. dose = $dose.val();
  125. if(drugsCode && drugsName && dose && unit && frequency){
  126. obj = {
  127. drugsGroup : 'normal',
  128. drugsCode : drugsCode,
  129. drugsName : drugsName,
  130. frequency : frequency,
  131. unit : unit,
  132. dose : dose
  133. };
  134. drugs.push(obj);
  135. }else if(drugsCode || drugsName || dose || unit || frequency){
  136. //如果药品信息中填写了部分,则需要将未填写的内容补全
  137. showWarningMsg("请补全未填写完成的药品信息");
  138. return false;
  139. }
  140. }
  141. if(complianceCode == "undefined"){
  142. complianceCode = "";
  143. }
  144. var followupProjectData = {'DRUG_COMPLIANCE_CODE': complianceCode};
  145. console.log(followupProjectData);
  146. var projectData = {
  147. id: fv_id,
  148. followupProject: pro_id,
  149. followupProjectData: JSON.stringify(followupProjectData)
  150. },
  151. drugData = {
  152. id: fv_id,
  153. drugsData: JSON.stringify(drugs)
  154. };
  155. Promise.all([
  156. followupAPI.saveFollowupProjectData(projectData),
  157. followupAPI.saveFollowupDrugs(drugData)
  158. ]).then(function(ress){
  159. if(ress[0].status == 200 && ress[1].status == 200){
  160. parent.goFollowupNextQuestionaire();
  161. }else if(ress[0].status != 200){
  162. showErrorMsg(ress[0].msg);
  163. }else if(ress[1].status != 200){
  164. showErrorMsg(ress[1].msg);
  165. }
  166. })
  167. })
  168. }
  169. function initDrugNameSuggestInput() {
  170. $("input.noInsulin").bsSuggest({
  171. url: APIService.server+'doctor/prescriptionInfo/findDictByName?isinsulin=1&name=',
  172. getDataMethod:'url',
  173. idField: "drugCode",
  174. keyField: "drugName",
  175. effectiveFields: ['drugName','drugFormat'],
  176. effectiveFieldsAlias:{drugName: "药品名称",drugFormat:"规格"},
  177. ignorecase: true,
  178. fnProcessData: function(res) {
  179. return {
  180. value: res.data
  181. }
  182. }
  183. }).on('onSetSelectValue', function (e, v) {
  184. var rowData = v.json;
  185. rowData = JSON.parse(rowData);
  186. var $tr = $(this).closest("tr"),
  187. $unit = $tr.find(".unit-select");
  188. $unit.val(rowData.physicDoseUnitName);
  189. $unit.attr("data-id", rowData.physicDoseUnit);
  190. });
  191. $("input.isInsulin").bsSuggest({
  192. url: APIService.server+'doctor/prescriptionInfo/findDictByName?isinsulin=2&name=',
  193. getDataMethod:'url',
  194. idField: "drugCode",
  195. keyField: "drugName",
  196. effectiveFields: ['drugName','drugFormat'],
  197. effectiveFieldsAlias:{drugName: "药品名称",drugFormat:"规格"},
  198. ignorecase: true,
  199. fnProcessData: function(res) {
  200. return {
  201. value: res.data
  202. }
  203. }
  204. }).on('onSetSelectValue', function (e, v) {
  205. var rowData = v.json;
  206. rowData = JSON.parse(rowData);
  207. var $tr = $(this).closest("tr"),
  208. $unit = $tr.find(".unit-select");
  209. $unit.val(rowData.physicDoseUnitName);
  210. $unit.attr("data-id", rowData.physicDoseUnit);
  211. })
  212. }
  213. function initFreqSuggestInput(){
  214. $("input.frequency-select").bsSuggest({
  215. data: {value: recipe_frequency_dict},
  216. idField: "key",
  217. keyField: "name",
  218. getDataMethod:'data',
  219. effectiveFields: ['name'],
  220. ignorecase: true
  221. })
  222. }
  223. function initUnitInput(){
  224. $("input.unit-select").bsSuggest({
  225. data: {value: measure_unit_dict},
  226. idField: "key",
  227. keyField: "name",
  228. getDataMethod:'data',
  229. effectiveFields: ['name'],
  230. ignorecase: true
  231. })
  232. }
  233. //清空药品信息
  234. function clearDrugsInfo(){
  235. var $trs = $(".drugs-tr");
  236. for(var i=0; i<9; i++){
  237. var $tr = $($trs[i]),
  238. $inputs = $tr.find("input"),
  239. len = $inputs.length;
  240. for(var j=0; j<len; j++){
  241. var $input = $($inputs[j]);
  242. $input.val("");
  243. $input.attr("data-id", "");
  244. }
  245. }
  246. }
  247. function fillDrugsInfo(){
  248. //从缓存中获取选中的药品信息
  249. var drugsData = window.sessionStorage.getItem("chooseDrugs");
  250. if(drugsData){
  251. drugsData = JSON.parse(drugsData);
  252. var len = drugsData.length;
  253. if(len == 0){
  254. return false;
  255. }
  256. //先将药品分类
  257. var insulinList = [],
  258. normalList = [];
  259. for(var i=0; i<len; i++){
  260. var obj = drugsData[i];
  261. if(obj.subjectClass.substr(0,2)=='010' && obj.name.indexOf('胰岛素')>0){
  262. //胰岛素药品
  263. insulinList.push(obj);
  264. }else{
  265. normalList.push(obj)
  266. }
  267. }
  268. //如果表格中药品名称没有填写的均可以被覆盖,如果已填写的药品与处方中的药品名称一致,设定为相同药品
  269. var $trs1 = $("#table1 tbody tr"),
  270. $trs2 = $("#table2 tbody tr"),
  271. len1 = normalList.length,
  272. len2 = insulinList.length;
  273. if(len1 > 0){
  274. //填充普通药品
  275. var index1 = 0;
  276. for(var i1=0; i1<6; i1++){
  277. var $tr = $($trs1[i1]),
  278. $drugName = $tr.find(".j-drugName"),
  279. $unit = $tr.find(".unit-select"),
  280. $frequency = $tr.find(".frequency-select");
  281. if($drugName.val() == ''){
  282. if(index1 < len1){
  283. var obj1 = normalList[index1];
  284. $drugName.val(obj1.drugName);
  285. $drugName.attr("data-id", obj1.drugCode);
  286. $tr.find(".dose").val(obj1.physicDose);
  287. $unit.val(obj1.physicDoseUnitName);
  288. $unit.attr("data-id", obj1.physicDoseUnit);
  289. index1 ++;
  290. }else{
  291. break;
  292. }
  293. }else{
  294. var name = $drugName.val();
  295. //如果已经填写了内容,则判断药品名称是否一样
  296. for(var j1=0; j1<len1; j1++){
  297. var obj1 = normalList[j1];
  298. if(name == obj1.drugName){
  299. //从列表中删除这个对象
  300. normalList.splice(j1, 1);
  301. len1 --;
  302. break;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. if(len2 >0){
  309. //填充胰岛素药品
  310. var index2 = 0;
  311. for(var i2=0; i2<6; i2++){
  312. var $tr = $($trs2[i2]),
  313. $drugName = $tr.find(".j-drugName"),
  314. $unit = $tr.find(".unit-select"),
  315. $frequency = $tr.find(".frequency-select");
  316. if($drugName.val() == ''){
  317. if(index2 < len2){
  318. var obj2 = insulinList[index2];
  319. $drugName.val(obj2.drugName);
  320. $drugName.attr("data-id", obj2.drugCode);
  321. $tr.find(".dose").val(obj2.physicDose);
  322. $unit.val(obj2.physicDoseUnitName);
  323. $unit.attr("data-id", obj2.physicDoseUnit);
  324. index2 ++;
  325. }else{
  326. break;
  327. }
  328. }else{
  329. var name = $drugName.val();
  330. //如果已经填写了内容,则判断药品名称是否一样
  331. for(var j2=0; j2<len2; j2++){
  332. var obj2 = normalList[j2];
  333. if(name == obj2.drugName){
  334. //从列表中删除这个对象
  335. insulinList.splice(j2, 1);
  336. len2 --;
  337. break;
  338. }
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. top.fillChooseDrugs = fillDrugsInfo;