prescription-adjustment.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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-code')){
  152. showErrorMsg('请完善药品信息')
  153. return
  154. }
  155. }
  156. }else{
  157. return
  158. }
  159. var msgArr = [],
  160. $box = $('#drugs .ibox-content');
  161. for(var i=0;i<$box.length;i++){
  162. var data = {};
  163. var saveData = JSON.parse($box.eq(i).attr('data-json'));
  164. data.prescriptionCode = prescriptionCode;
  165. data.drugCode = saveData.drugCode;
  166. data.drugName = $box.eq(i).find('.j-drugName').val().replace(/\(/,'(').replace(/\)/,')');
  167. data.drugRate = $box.eq(i).find('.j-selFreq').attr('data-code');
  168. data.drugRateName = $box.eq(i).find('.j-selFreq').val();
  169. data.drugFormat=saveData.drugFormat.replace(/\(/,'(').replace(/\)/,')');
  170. data.subjectClass = $box.eq(i).attr('data-class');
  171. data.isRefrigerate = $box.eq(i).attr('data-storage')==2?1:0;
  172. data.physicAmount = "";
  173. data.physicAmountUnit = saveData.physicAmountUnit;
  174. data.physicAmountUnitName = saveData.physicAmountUnitName;
  175. data.physicDose = $box.eq(i).find('.j-medi-single').val().trim();
  176. data.physicDoseUnit = $box.eq(i).find('.j-dose-unit').attr('data-unit');
  177. data.physicDoseUnitName = $box.eq(i).find('.j-dose-unit').text();
  178. data.drugNumUnit = $box.eq(i).find('.j-sumMedicine').attr('data-unit');//取当次用量单位
  179. data.drugNumUnitName = $box.eq(i).find('.j-sumMedicine').attr('data-name');
  180. data.drugUsage= $box.eq(i).find('.j-method').attr('data-code');
  181. data.usageName= $box.eq(i).find('.j-method').val();
  182. data.num= $box.eq(i).find(".j-sumMedicine").attr('data-num');//取总量
  183. data.dayCount=$box.eq(i).find('.j-selDate').val();
  184. msgArr.push(data);
  185. }
  186. //调整CODE
  187. var reasonCode= _.map($('#adjustReason li.active'),function(el) {
  188. return $(el).attr('data-code')
  189. }).join(',')
  190. var params= {
  191. code:prescriptionCode,
  192. infos:JSON.stringify(msgArr),
  193. reason:$('#adjustReasonTextarea').val().trim()?$('#adjustReasonTextarea').val().trim():'-',
  194. reasonCode:reasonCode,
  195. diagnosis:(function(){
  196. // TODO
  197. var diagnosis = [];
  198. if(isChangeDiagnosis) {
  199. diagnosis = _.map($('#diagnosis li'),function(el) {
  200. var data = JSON.parse($(el).attr('data-json'))
  201. return {
  202. code: data.code,
  203. name: data.name
  204. }
  205. })
  206. return JSON.stringify(diagnosis)
  207. }
  208. return ""
  209. })()
  210. }
  211. if(!params.diagnosis || params.diagnosis == "[]") {
  212. showErrorMsg('请添加诊断结果')
  213. return ;
  214. }
  215. prescriptionDetailApis.updatePresInfo({
  216. data: params
  217. }).then(function(res) {
  218. if(res.status == 200){
  219. showSuccessMsg("保存成功")
  220. setTimeout(function() {
  221. location.reload(true)
  222. }, 2000)
  223. } else {
  224. showErroeMsg("保存失败")
  225. }
  226. })
  227. })
  228. }
  229. function setAdjustReason() {
  230. var reasons = _.map($('#adjustReason li.active'),function(el) {
  231. return $.trim($(el).text())
  232. });
  233. if(reasons && reasons.length) {
  234. $('#adjustReasonTextarea').val(reasons.join(','))
  235. $('#adjustReasonTextarea').focus()
  236. }
  237. }
  238. function initDiagnosisSuggestInput() {
  239. $('#diagnosisInput').bsSuggest({
  240. url: APIService.server+'doctor/prescriptionInfo/getIcd10Info?nameKey=',
  241. getDataMethod:'url',
  242. idField: "code",
  243. keyField: "name",
  244. effectiveFields: ['name'],
  245. ignorecase: true,
  246. fnProcessData: function(res) {
  247. return {
  248. value: res.data
  249. }
  250. }
  251. }).on('onSetSelectValue', function (e, v) {
  252. $(this).attr('data-code', v.id)
  253. })
  254. }
  255. function initDrugNameSuggestInput() {
  256. $("input.j-drugName").bsSuggest({
  257. url: APIService.server+'doctor/prescriptionInfo/findDictByName?name=',
  258. getDataMethod:'url',
  259. idField: "drugCode",
  260. keyField: "drugName",
  261. effectiveFields: ['drugName','drugFormat'],
  262. effectiveFieldsAlias:{drugName: "药品名称",drugFormat:"规格"},
  263. ignorecase: true,
  264. fnProcessData: function(res) {
  265. return {
  266. value: res.data
  267. }
  268. }
  269. }).on('onSetSelectValue', function (e, v) {
  270. var $box = $(this).closest('.ibox-content'),
  271. $single = $box.find(".j-medi-single"),
  272. $doseUnit = $box.find('.j-dose-unit'),
  273. $freq = $box.find(".j-selFreq"),
  274. $date = $box.find(".j-selDate");
  275. var json = v.json;
  276. $box.attr('data-json',JSON.stringify(json))
  277. $single.val(json.physicDose)
  278. $single.attr('data-code', json.physicDoseUnit)
  279. $doseUnit.text(json.physicDoseUnitName)
  280. $doseUnit.attr('data-unit', json.physicDoseUnit)
  281. $freq.val(json.drugRateName||"")
  282. $freq.attr('data-code', json.drugRate)
  283. $date.val(json.dayCount||"")
  284. })
  285. }
  286. function initFreqSuggestInput() {
  287. $("input.j-selFreq").bsSuggest({
  288. data: {value: medicineFreqData},
  289. idField: "code",
  290. keyField: "name",
  291. getDataMethod:'data',
  292. effectiveFields: ['name'],
  293. ignorecase: true
  294. }).on('onSetSelectValue', function (e, v) {
  295. $(this).attr('data-code', v.id)
  296. var $box = $(this).closest('.ibox-content')
  297. countMediSum($box)
  298. })
  299. }
  300. function initDaySuggestInput() {
  301. $("input.j-selDate").bsSuggest({
  302. data: {value: _.map(_.range(1, 31),function(v) {
  303. return {
  304. day: v
  305. }
  306. })},
  307. idField: "day",
  308. keyField: "day",
  309. getDataMethod:'data',
  310. effectiveFields: ['day'],
  311. ignorecase: true
  312. }).on('onSetSelectValue', function (e, v) {
  313. var $box = $(this).closest('.ibox-content')
  314. countMediSum($box)
  315. })
  316. }
  317. function initUsageSuggestInput() {
  318. $("input.j-method").bsSuggest({
  319. data: {value: usageDict},
  320. idField: "code",
  321. keyField: "name",
  322. getDataMethod:'data',
  323. effectiveFields: ['name'],
  324. ignorecase: true
  325. }).on('onSetSelectValue', function (e, v) {
  326. })
  327. }
  328. //计算药品总量
  329. function countMediSum($box){
  330. var single = $box.find(".j-medi-single").val(),
  331. freq = $box.find(".j-selFreq").attr('data-code'),
  332. date = $box.find(".j-selDate").val(),
  333. $sum = $box.find('.j-sumMedicine'),
  334. $info = JSON.parse($box.attr('data-json'));
  335. if(!single || !freq || !date) {
  336. return ;
  337. } else {
  338. single = single.trim();
  339. freq = freq.trim();
  340. date = date.trim();
  341. }
  342. if(single && freq && date){
  343. prescriptionDetailApis.drugToRate({data:{code: freq}}).then(function(res){
  344. if(res.status == 200){
  345. var rate = res.data.rate
  346. var num = single*rate*date
  347. var sum="";
  348. if($info.pakeSpec){
  349. //新增药品
  350. sum = Math.ceil(num/$info.minDose)
  351. $sum.text(sum+$info.drugNumUnitName)
  352. $sum.attr('data-num',sum)
  353. $sum.attr('data-name',$info.drugNumUnitName);
  354. $sum.attr('data-unit',$info.drugNumUnit);
  355. }else{
  356. var drugNumUnit = $info.drugNumUnit,
  357. physicDoseUnit = $info.physicDoseUnit;
  358. //请求药品信息
  359. var drugCode = $info.drugCode;
  360. prescriptionDetailApis.getPhysicInfo({data:{code: drugCode}}).then(function(res){
  361. if(res.status == 200){
  362. var msg = res.data[0]
  363. $box.attr('data-storage',msg.storageConditions);//冷藏
  364. $box.attr('data-class',msg.subjectClass);
  365. if(drugNumUnit == physicDoseUnit){
  366. sum = num
  367. }else{
  368. if(drugNumUnit == msg.pack_unit){
  369. sum = Math.ceil(num/msg.packSpec)
  370. }else{
  371. sum = Math.ceil(num/msg.minDose)
  372. }
  373. }
  374. $sum.text(sum+$info.drugNumUnitName)
  375. $sum.attr('data-num',sum)
  376. $sum.attr('data-name',$info.drugNumUnitName);
  377. $sum.attr('data-unit',$info.drugNumUnit);
  378. }
  379. })
  380. }
  381. }
  382. })
  383. }
  384. }
  385. })