prescription-adjustment.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. var json = v.json;
  279. $box.attr('data-json',json)
  280. $single.val(json.physicDose)
  281. $single.attr('data-code', json.physicDoseUnit)
  282. $doseUnit.text(json.physicDoseUnitName)
  283. $doseUnit.attr('data-unit', json.physicDoseUnit)
  284. $freq.val(json.drugRateName||"")
  285. $freq.attr('data-code', json.drugRate)
  286. $date.val(json.dayCount||"")
  287. $sum.text('')
  288. $method.val('')
  289. $method.attr('data-code','')
  290. })
  291. }
  292. function initFreqSuggestInput() {
  293. $("input.j-selFreq").bsSuggest({
  294. data: {value: medicineFreqData},
  295. idField: "code",
  296. keyField: "name",
  297. getDataMethod:'data',
  298. effectiveFields: ['name'],
  299. ignorecase: true
  300. }).on('onSetSelectValue', function (e, v) {
  301. $(this).attr('data-code', v.id)
  302. var $box = $(this).closest('.ibox-content')
  303. countMediSum($box)
  304. })
  305. }
  306. function initDaySuggestInput() {
  307. $("input.j-selDate").bsSuggest({
  308. data: {value: _.map(_.range(1, 31),function(v) {
  309. return {
  310. day: v
  311. }
  312. })},
  313. idField: "day",
  314. keyField: "day",
  315. getDataMethod:'data',
  316. effectiveFields: ['day'],
  317. ignorecase: true
  318. }).on('onSetSelectValue', function (e, v) {
  319. var $box = $(this).closest('.ibox-content')
  320. countMediSum($box)
  321. })
  322. }
  323. function initUsageSuggestInput() {
  324. $("input.j-method").bsSuggest({
  325. data: {value: usageDict},
  326. idField: "code",
  327. keyField: "name",
  328. getDataMethod:'data',
  329. effectiveFields: ['name'],
  330. ignorecase: true
  331. }).on('onSetSelectValue', function (e, v) {
  332. // console.log(e);
  333. })
  334. }
  335. //计算药品总量
  336. function countMediSum($box){
  337. var single = $box.find(".j-medi-single").val(),
  338. freq = $box.find(".j-selFreq").attr('data-code'),
  339. date = $box.find(".j-selDate").val(),
  340. $sum = $box.find('.j-sumMedicine'),
  341. $info = JSON.parse($box.attr('data-json'));
  342. if(!single || !freq || !date) {
  343. return ;
  344. } else {
  345. single = single.trim();
  346. freq = freq.trim();
  347. date = date.trim();
  348. }
  349. if(single && freq && date){
  350. prescriptionDetailApis.drugToRate({data:{code: freq}}).then(function(res){
  351. if(res.status == 200){
  352. var rate = res.data.rate
  353. var num = single*rate*date
  354. var sum="";
  355. if($info.pakeSpec){
  356. //新增药品
  357. sum = Math.ceil(num/$info.minDose)
  358. $sum.text(sum+$info.drugNumUnitName)
  359. $sum.attr('data-num',sum)
  360. $sum.attr('data-name',$info.drugNumUnitName);
  361. $sum.attr('data-unit',$info.drugNumUnit);
  362. $box.attr('data-class',$info.subjectClass);
  363. }else{
  364. var drugNumUnit = $info.drugNumUnit,
  365. physicDoseUnit = $info.physicDoseUnit;
  366. //请求药品信息
  367. var drugCode = $info.drugCode;
  368. prescriptionDetailApis.getPhysicInfo({data:{code: drugCode}}).then(function(res){
  369. if(res.status == 200){
  370. var msg = res.data[0]
  371. $box.attr('data-storage',msg.storageConditions);//冷藏
  372. $box.attr('data-class',msg.subjectClass);
  373. if(drugNumUnit == physicDoseUnit){
  374. sum = num
  375. }else{
  376. if(drugNumUnit == msg.pack_unit){
  377. sum = Math.ceil(num/msg.packSpec)
  378. }else{
  379. sum = Math.ceil(num/msg.minDose)
  380. }
  381. }
  382. $sum.text(sum+$info.drugNumUnitName)
  383. $sum.attr('data-num',sum)
  384. $sum.attr('data-name',$info.drugNumUnitName);
  385. $sum.attr('data-unit',$info.drugNumUnit);
  386. }
  387. })
  388. }
  389. }
  390. })
  391. }
  392. }
  393. })