prescription-adjustment.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. $(function(){
  2. var request = getRequest(),
  3. teamCode = request.id,
  4. isLeader = isTeamLeader(),
  5. prescriptionCode = request.code;
  6. var medicineFreqData = [];
  7. var usageDict = [];
  8. var isChangeDiagnosis = 0; //判断是否改变疾病类型
  9. var $main = $('#main');
  10. template.helper('toJson',function(o) {
  11. if(o) {
  12. return JSON.stringify(o)
  13. }
  14. return "";
  15. })
  16. Promise.all([
  17. prescriptionDetailApis.getContinuedPrescriptionAsDoctor({
  18. data: {
  19. code: prescriptionCode, // 续方CODE
  20. type: isLeader?1:2 // 是否为团队长,1:是,2:否
  21. }
  22. }),
  23. prescriptionDetailApis.getRateList({data:{}}),
  24. prescriptionDetailApis.getUsageDict({data:{}}),
  25. prescriptionDetailApis.getReasonByType({data: {type:1}})
  26. ]).then(function(responses) {
  27. var prescriptionInfo = responses[0].data;
  28. var reasonTypes = responses[3].data;
  29. $main.html(template('detailTmpl', $.extend({},prescriptionInfo, {reasonTypes:reasonTypes})))
  30. medicineFreqData = responses[1].data
  31. usageDict = responses[2].data
  32. showDiagnosisBtn()
  33. bindEvents()
  34. initDiagnosisSuggestInput()
  35. initDrugNameSuggestInput()
  36. initFreqSuggestInput()
  37. initDaySuggestInput()
  38. initUsageSuggestInput()
  39. calcWorldWithTextarea()
  40. }).catch(function(e) {
  41. console && console.error(e)
  42. })
  43. function showDiagnosisBtn() {
  44. if($('#diagnosis li').length >= 3) {
  45. $('#addDiagnosisBtn').hide()
  46. } else {
  47. $('#addDiagnosisBtn').show()
  48. }
  49. }
  50. function bindEvents() {
  51. $('#addDrugBtn').click(function() {
  52. var html = template('drugTmpl',{})
  53. $('#drugs').append(html)
  54. initDrugNameSuggestInput()
  55. initFreqSuggestInput()
  56. initDaySuggestInput()
  57. initUsageSuggestInput()
  58. })
  59. $('#adjustReason').on('click','li',function() {
  60. if($(this).hasClass('active')) {
  61. $(this).removeClass('active')
  62. } else {
  63. $(this).addClass('active')
  64. }
  65. setAdjustReason()
  66. })
  67. $('#drugs').on('click','.icon-shanchu',function() {
  68. $(this).closest('.ibox-content').remove();
  69. }).on('click','.icon-jianshao',function() {
  70. var $input = $(this).closest('li').find('input').eq(0);
  71. var amount = parseFloat($input.val()||'0')
  72. if(amount > 0) {
  73. if($input.hasClass('j-medi-single')) {
  74. $input.val(amount - 0.25)
  75. } else {
  76. $input.val(amount - 1)
  77. }
  78. } else {
  79. $input.val(0)
  80. }
  81. var $box = $(this).closest('.ibox-content')
  82. countMediSum($box)
  83. }).on('click','.icon-xinzeng',function() {
  84. var $input = $(this).closest('li').find('input').eq(0);
  85. var amount = parseFloat($input.val()||'0')
  86. if($input.hasClass('j-medi-single')) {
  87. $input.val(amount + 0.25)
  88. } else {
  89. $input.val(amount + 1)
  90. }
  91. var $box = $(this).closest('.ibox-content')
  92. countMediSum($box)
  93. }).on('blur', 'input.j-medi-single, input.j-selDate, input.j-selFreq',function() {
  94. var $box = $(this).closest('.ibox-content')
  95. if(!$(this).val().trim()) {
  96. $(this).attr('data-code','')
  97. $sum = $box.find('.j-sumMedicine')
  98. $sum.attr('data-num','')
  99. $sum.text('')
  100. }
  101. countMediSum($box)
  102. })
  103. $('.diagnosis-wrap').on('click',function() {
  104. $('#placeholdText').hide()
  105. $('#diagnosisInput').show()
  106. $('#diagnosisInput').focus()
  107. })
  108. $('#addDiagnosisBtn').on('click',function() {
  109. $(this).hide();
  110. $('.diagnosis-wrap').show();
  111. setTimeout(function() {
  112. $('#diagnosisInput').click()
  113. },100)
  114. })
  115. $('#diagnosisInput').on('blur keydown',function(e) {
  116. if(e.type == 'keydown' && e.keyCode == 13) {
  117. $('#diagnosisInput').blur()
  118. } else {
  119. if(e.type == 'blur') {
  120. var name = $('#diagnosisInput').val()
  121. var code = $('#diagnosisInput').attr('data-code')
  122. var isSelected = $('#diagnosis li[data-code="'+ code +'"]').length>0?true:false // 该诊断结果是否已选择
  123. $('#placeholdText').show()
  124. $('#diagnosisInput').hide()
  125. if(name && code && !isSelected) {
  126. isChangeDiagnosis = 1;
  127. var html = template('diagnosisTmpl', {data:{name: name,code:code}})
  128. $('#diagnosis').append(html)
  129. }
  130. $('#diagnosisInput').val('')
  131. $('#diagnosisInput').attr('data-code','')
  132. showDiagnosisBtn()
  133. $('.diagnosis-wrap').hide()
  134. }
  135. }
  136. })
  137. $('#diagnosis').on('click', '.fa-close' ,function() {
  138. $(this).closest('li').remove()
  139. isChangeDiagnosis = 1;
  140. showDiagnosisBtn()
  141. })
  142. $('#backBtn').on('click',function() {
  143. history.go(-1);
  144. })
  145. $('#confirmBtn').click(function(){
  146. var $sum = $(".j-sumMedicine");
  147. if($sum.length > 0){
  148. for(var i=0;i<$sum.length;i++){
  149. var $box = $sum.eq(i).closest('.ibox-content')
  150. var $method = $box.find('.j-method')
  151. if(! $sum.eq(i).attr('data-num') || !$method.val() || !$method.attr('data-id')){
  152. showErrorMsg('请完善药品信息')
  153. return
  154. }
  155. }
  156. }else{
  157. showErrorMsg('请添加药品')
  158. return ;
  159. }
  160. var msgArr = [],
  161. $box = $('#drugs .ibox-content');
  162. for(var i=0;i<$box.length;i++){
  163. var data = {};
  164. var saveData = JSON.parse($box.eq(i).attr('data-json'));
  165. data.prescriptionCode = prescriptionCode;
  166. data.drugCode = saveData.drugCode;
  167. data.drugName = $box.eq(i).find('.j-drugName').val().replace(/\(/,'(').replace(/\)/,')');
  168. data.drugRate = $box.eq(i).find('.j-selFreq').attr('data-code');
  169. data.drugRateName = $box.eq(i).find('.j-selFreq').val();
  170. data.drugFormat=saveData.drugFormat.replace(/\(/,'(').replace(/\)/,')');
  171. data.subjectClass = saveData.subjectClass; //$box.eq(i).attr('data-class');
  172. data.isRefrigerate = saveData.isRefrigerate==2?1:0 //$box.eq(i).attr('data-storage')==2?1:0;
  173. data.physicAmount = "";
  174. data.physicAmountUnit = saveData.physicAmountUnit;
  175. data.physicAmountUnitName = saveData.physicAmountUnitName;
  176. data.physicDose = $box.eq(i).find('.j-medi-single').val().trim();
  177. data.physicDoseUnit = $box.eq(i).find('.j-dose-unit').attr('data-unit');
  178. data.physicDoseUnitName = $box.eq(i).find('.j-dose-unit').text();
  179. data.drugNumUnit = $box.eq(i).find('.j-sumMedicine').attr('data-unit');//取当次用量单位
  180. data.drugNumUnitName = $box.eq(i).find('.j-sumMedicine').attr('data-name');
  181. data.drugUsage= $box.eq(i).find('.j-method').attr('data-id');
  182. data.usageName= $box.eq(i).find('.j-method').val();
  183. data.num= $box.eq(i).find(".j-sumMedicine").attr('data-num');//取总量
  184. data.dayCount=$box.eq(i).find('.j-selDate').val();
  185. msgArr.push(data);
  186. }
  187. //调整CODE
  188. var reasonCode= _.map($('#adjustReason li.active'),function(el) {
  189. return $(el).attr('data-code')
  190. }).join(',')
  191. var params= {
  192. code:prescriptionCode,
  193. infos:JSON.stringify(msgArr),
  194. reason:$('#adjustReasonTextarea').val().trim()?$('#adjustReasonTextarea').val().trim():'-',
  195. reasonCode:reasonCode,
  196. diagnosis:(function(){
  197. // TODO
  198. var diagnosis = [];
  199. if(isChangeDiagnosis) {
  200. diagnosis = _.map($('#diagnosis li'),function(el) {
  201. var data = JSON.parse($(el).attr('data-json'))
  202. return {
  203. code: data.code,
  204. name: data.name
  205. }
  206. })
  207. return JSON.stringify(diagnosis)
  208. }
  209. return ""
  210. })()
  211. }
  212. if($('#diagnosis li').length == 0) {
  213. showErrorMsg('请添加诊断结果')
  214. return ;
  215. }
  216. prescriptionDetailApis.updatePresInfo({
  217. data: params
  218. }).then(function(res) {
  219. if(res.status == 200){
  220. showSuccessMsg("保存成功")
  221. setTimeout(function() {
  222. location.reload(true)
  223. }, 2000)
  224. } else {
  225. showErrorMsg(res.msg || "保存失败")
  226. }
  227. })
  228. })
  229. }
  230. function setAdjustReason() {
  231. var reasons = _.map($('#adjustReason li.active'),function(el) {
  232. return $.trim($(el).text())
  233. });
  234. // if(reasons && reasons.length) {
  235. $('#adjustReasonTextarea').val(reasons.join(','))
  236. $('#adjustReasonTextarea').focus()
  237. // }
  238. }
  239. function initDiagnosisSuggestInput() {
  240. $('#diagnosisInput').bsSuggest({
  241. url: APIService.server+'doctor/prescriptionInfo/getIcd10Info?nameKey=',
  242. getDataMethod:'url',
  243. idField: "code",
  244. keyField: "name",
  245. effectiveFields: ['name'],
  246. ignorecase: true,
  247. fnProcessData: function(res) {
  248. return {
  249. value: res.data
  250. }
  251. }
  252. }).on('onSetSelectValue', function (e, v) {
  253. $(this).attr('data-code', v.id)
  254. })
  255. }
  256. function initDrugNameSuggestInput() {
  257. $("input.j-drugName").bsSuggest({
  258. url: APIService.server+'doctor/prescriptionInfo/findDictByName?name=',
  259. getDataMethod:'url',
  260. idField: "drugCode",
  261. keyField: "drugName",
  262. effectiveFields: ['drugName','drugFormat'],
  263. effectiveFieldsAlias:{drugName: "药品名称",drugFormat:"规格"},
  264. ignorecase: true,
  265. fnProcessData: function(res) {
  266. return {
  267. value: res.data
  268. }
  269. }
  270. }).on('onSetSelectValue', function (e, v) {
  271. var $box = $(this).closest('.ibox-content'),
  272. $single = $box.find(".j-medi-single"),
  273. $doseUnit = $box.find('.j-dose-unit'),
  274. $freq = $box.find(".j-selFreq"),
  275. $date = $box.find(".j-selDate"),
  276. $sum = $box.find('.j-sumMedicine'),
  277. $method = $box.find('.j-method'),
  278. $format = $box.find(".j-format");
  279. var json = v.json;
  280. $box.attr('data-json',json);
  281. json = JSON.parse(json);
  282. $single.val(json.physicDose)
  283. $single.attr('data-code', json.physicDoseUnit)
  284. $doseUnit.text(json.physicDoseUnitName)
  285. $doseUnit.attr('data-unit', json.physicDoseUnit)
  286. $freq.val(json.drugRateName||"")
  287. $freq.attr('data-code', json.drugRate)
  288. $date.val(json.dayCount||"")
  289. $format.text(json.drugFormat);
  290. $sum.text('')
  291. $method.val('')
  292. $method.attr('data-code','')
  293. })
  294. }
  295. function initFreqSuggestInput() {
  296. $("input.j-selFreq").bsSuggest({
  297. data: {value: medicineFreqData},
  298. idField: "code",
  299. keyField: "name",
  300. getDataMethod:'data',
  301. effectiveFields: ['name'],
  302. ignorecase: true
  303. }).on('onSetSelectValue', function (e, v) {
  304. $(this).attr('data-code', v.id)
  305. var $box = $(this).closest('.ibox-content')
  306. countMediSum($box)
  307. })
  308. }
  309. function initDaySuggestInput() {
  310. $("input.j-selDate").bsSuggest({
  311. data: {value: _.map(_.range(1, 31),function(v) {
  312. return {
  313. day: v
  314. }
  315. })},
  316. idField: "day",
  317. keyField: "day",
  318. getDataMethod:'data',
  319. effectiveFields: ['day'],
  320. ignorecase: true
  321. }).on('onSetSelectValue', function (e, v) {
  322. var $box = $(this).closest('.ibox-content')
  323. countMediSum($box)
  324. })
  325. }
  326. function initUsageSuggestInput() {
  327. $("input.j-method").bsSuggest({
  328. data: {value: usageDict},
  329. idField: "code",
  330. keyField: "name",
  331. getDataMethod:'data',
  332. effectiveFields: ['name'],
  333. ignorecase: true
  334. }).on('onSetSelectValue', function (e, v) {
  335. // console.log(e);
  336. })
  337. }
  338. //计算药品总量
  339. function countMediSum($box){
  340. var single = $box.find(".j-medi-single").val(),
  341. freq = $box.find(".j-selFreq").attr('data-code'),
  342. date = $box.find(".j-selDate").val(),
  343. $sum = $box.find('.j-sumMedicine'),
  344. $info = JSON.parse($box.attr('data-json')),
  345. dispPackUntuckFlag = $info.dispPackUntuckFlag, //门诊包装可拆标志 0不可拆,1可拆
  346. dispQuantityUntuckFlag = $info.dispQuantityUntuckFlag; //门诊数量可拆标志 0不可拆,1可拆
  347. if(!single || !freq || !date) {
  348. return ;
  349. } else {
  350. single = single.trim();
  351. freq = freq.trim();
  352. date = date.trim();
  353. }
  354. if(single && freq && date){
  355. prescriptionDetailApis.drugToRate({data:{code: freq}}).then(function(res){
  356. if(res.status == 200){
  357. var rate = res.data.rate
  358. var num = single*rate*date
  359. var sum="";
  360. if($info.pakeSpec){
  361. //新增药品
  362. // sum = Math.ceil(num/$info.minDose)
  363. // $sum.text(sum+$info.drugNumUnitName)
  364. // $sum.attr('data-num',sum)
  365. // $sum.attr('data-name',$info.drugNumUnitName);
  366. // $sum.attr('data-unit',$info.drugNumUnit);
  367. if(!dispPackUntuckFlag && !dispQuantityUntuckFlag){
  368. sum = Math.ceil((Math.ceil(single / $info.minDose) * rate * date) / $info.pakeSpec);
  369. $sum.text(sum + $info.packUnitName)
  370. $sum.attr('data-num', sum * $info.pakeSpec)
  371. $sum.attr('data-name', $info.drugNumUnitName);
  372. $sum.attr('data-unit', $info.drugNumUnit);
  373. }else{
  374. if(dispQuantityUntuckFlag){
  375. //ceil(剂量数量*频次*天数/最小剂量)
  376. sum = Math.ceil(num / $info.minDose);
  377. if(dispPackUntuckFlag){
  378. //可拆包
  379. $sum.text(sum + $info.drugNumUnitName)
  380. $sum.attr('data-num', sum)
  381. $sum.attr('data-name', $info.drugNumUnitName);
  382. $sum.attr('data-unit', $info.drugNumUnit);
  383. }else{
  384. //不可拆包
  385. sum = Math.ceil(sum / $info.pakeSpec);
  386. $sum.text(sum + $info.packUnitName)
  387. $sum.attr('data-num', sum * $info.pakeSpec)
  388. $sum.attr('data-name', $info.drugNumUnitName);
  389. $sum.attr('data-unit', $info.drugNumUnit);
  390. }
  391. }else if(dispPackUntuckFlag){
  392. //可拆包: 单元数量(ceil(次剂量/最小单位))*频次*天数
  393. sum = Math.ceil(single / $info.minDose) * rate * date;
  394. $sum.text(sum + $info.drugNumUnitName)
  395. $sum.attr('data-num', sum)
  396. $sum.attr('data-name', $info.drugNumUnitName);
  397. $sum.attr('data-unit', $info.drugNumUnit);
  398. }
  399. }
  400. $box.attr('data-class',$info.subjectClass);
  401. }else{
  402. //请求药品信息
  403. var drugCode = $info.drugCode;
  404. prescriptionDetailApis.getPhysicInfo({data:{code: drugCode}}).then(function(res){
  405. if(res.status == 200){
  406. var msg = res.data[0]
  407. $box.attr('data-storage',msg.storageConditions);//冷藏
  408. $box.attr('data-class',msg.subjectClass);
  409. if(!msg.dispPackUntuckFlag && !msg.dispQuantityUntuckFlag){
  410. sum = Math.ceil((Math.ceil(single / msg.minDose) * rate * date)/msg.packSpec)
  411. $sum.text(sum + msg.packUnitName)
  412. $sum.attr('data-num', sum * msg.packSpec)
  413. $sum.attr('data-name', msg.quantityUnitName);
  414. $sum.attr('data-unit', msg.quantityUnit);
  415. }else{
  416. if(msg.dispQuantityUntuckFlag){
  417. //ceil(剂量数量*频次*天数/最小剂量)
  418. sum = Math.ceil(num / msg.minDose);
  419. if(msg.dispPackUntuckFlag){
  420. $sum.text( sum + msg.quantityUnitName)
  421. $sum.attr('data-num', sum)
  422. $sum.attr('data-name', msg.quantityUnitName);
  423. $sum.attr('data-unit', msg.quantityUnit);
  424. }else{
  425. //不可拆包
  426. sum = Math.ceil(sum / msg.packSpec);
  427. $sum.text(sum + msg.packUnitName)
  428. $sum.attr('data-num', sum * msg.packSpec)
  429. $sum.attr('data-name', msg.quantityUnitName);
  430. $sum.attr('data-unit', msg.quantityUnit);
  431. }
  432. }else if(msg.dispPackUntuckFlag){
  433. //可拆包: 单元数量(ceil(次剂量/最小单位))*频次*天数
  434. sum = Math.ceil(single / msg.minDose) * rate * date;
  435. $sum.text(sum + msg.quantityUnitName)
  436. $sum.attr('data-num', sum)
  437. $sum.attr('data-name', msg.quantityUnitName);
  438. $sum.attr('data-unit', msg.quantityUnit);
  439. }
  440. }
  441. }
  442. })
  443. }
  444. }
  445. })
  446. }
  447. }
  448. })