medicine.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. "use strict";
  2. /**
  3. * mplus_medicine
  4. */
  5. var mplus_medicine = function() {
  6. // 상속
  7. mplus_common.call(this);
  8. var self = this;
  9. var patientData = [];
  10. var medicineList = [];
  11. var medicineSelectItem = [];
  12. var myTimer;
  13. var actTypeCheck = "EMR";
  14. this.init = function() {
  15. //여기서 모든화면 콤보박스데이터를 집어넣자!!! 그래야지 화면이동할때 속도가 오래걸리지않음!!!
  16. // 접근 권한 체크
  17. localStorage.removeItem("defaultHomePage");
  18. localStorage.setItem("defaultHomePage", "medicine");
  19. checkAccessPermission();
  20. // 초기 화면 조건 구성
  21. initCondition();
  22. // 이벤트 초기화
  23. addEvent();
  24. // 환자 검색 실행 및 환자 정보 화면 출력
  25. //searchPatient();
  26. // $("#txtPatientId").focus();
  27. //gLoginUserId
  28. //gLoginUserNm
  29. };
  30. //==== 접근 권한 체크 { ====
  31. var checkAccessPermission = function() {
  32. //if( !self.common.checkAccessJobKind( "1000")){
  33. // self.alertTrue("접근 권한이 없습니다.", self.common.gotoDefaultHomePage);
  34. //}
  35. //if( !self.common.checkAccessUserAuth( "01")){
  36. // self.alertTrue("접근 권한이 없습니다.", self.common.gotoDefaultHomePage);
  37. //}
  38. //self.common.disableElements( $("#myModalBtn"));
  39. };
  40. //==== 접근 권한 체크 } ====
  41. //==== 초기화 설정 { ====
  42. var initCondition = function() {
  43. // 초기 화면 조건 구성
  44. //환자정보 초기화
  45. initPatientInfo();
  46. StartTimer();
  47. // 콤보박스 시간 Setting
  48. actionHourSetting();
  49. // 콤보박스 시간 Setting
  50. var strCurDate = self.util.toDate(new Date());
  51. $("#spanDate").text(strCurDate);
  52. $("#todayDate").text(strCurDate);
  53. };
  54. /**
  55. * 콤보박스 시간과 분을 세팅
  56. */
  57. function actionHourSetting() {
  58. var today = new Date();
  59. var todayHH = today.getHours();
  60. var todayMM = today.getMinutes();
  61. if (todayHH < 10) {
  62. todayHH = "0" + todayHH
  63. }
  64. if (todayMM < 10) {
  65. todayMM = "0" + todayMM
  66. }
  67. var time = "";
  68. var value = "";
  69. // SelectBox Hour Setting
  70. for (var i = 0; i < 24; i++) {
  71. if (i < 10) {
  72. value = "0" + i;
  73. }
  74. else {
  75. value = i;
  76. }
  77. time += "<option value=" + value + ">" + value + "</option>";
  78. }
  79. $("#actionHour").empty();
  80. $("#actionHour").append(time);
  81. $("#actionHour").val(todayHH);
  82. $("#actionHour").off("focus");
  83. // SelectBox Minute Setting
  84. time = "";
  85. for (var i = 0; i < 60; i++) {
  86. if (i < 10) {
  87. value = "0" + i;
  88. }
  89. else {
  90. value = i;
  91. }
  92. time += "<option value=" + value + ">" + value + "</option> ";
  93. }
  94. $("#actionMinute").empty();
  95. $("#actionMinute").append(time);
  96. $("#actionMinute").val(todayMM);
  97. $("#actionMinute").off("focus");
  98. };
  99. function StartTimer() {
  100. clearInterval(myTimer);
  101. myTimer = setInterval(actingTimer ,1000);
  102. }
  103. function ClearTimer() {
  104. clearInterval(myTimer);
  105. }
  106. var actingTimer = function() {
  107. var today = new Date();
  108. var todayHH = today.getHours();
  109. var todayMM = today.getMinutes();
  110. if (todayHH < 10) {
  111. todayHH = "0" + todayHH
  112. }
  113. if (todayMM < 10) {
  114. todayMM = "0" + todayMM
  115. }
  116. if (String(todayHH) + String(todayMM) > $("#actionHour").val() + $("#actionMinute").val(todayMM)) {
  117. $("#actionMinute").val(todayMM);
  118. $("#actionHour").val(todayHH);
  119. }
  120. };
  121. /**
  122. * 환자 정보 초기화
  123. */
  124. var initPatientInfo = function() {
  125. $("#txtPatientId").val("");
  126. $("#patientName").text("환자명");
  127. $("#patientName button").attr("style", "display: none");
  128. $("#patient-gender-age").text("환자정보");
  129. $("#spanWard").text("실시부서");
  130. $("#spanAcrionUserName").text("실시자명 (사번)");
  131. };
  132. /**
  133. * 리스트 초기화
  134. */
  135. function emptyMedicine() {
  136. $("#listItem").remove();
  137. $("#divScanMsg").attr("style", "display: ;");
  138. StartTimer();
  139. }
  140. //==== 이벤트 설정 { ====
  141. var addEvent = function() {
  142. // 컬럼 클릭의 정렬 이벤트
  143. // eventColumnClick();
  144. //
  145. // eventRowClick();
  146. //
  147. eventCondition();
  148. medicineActionEvent();
  149. eventBackBlock();
  150. //
  151. // eventBackBlock();
  152. };
  153. //검색 페이지 뒤로가기 막기
  154. var eventBackBlock = function(){
  155. $(window).off("backbutton");
  156. $(window).bind("backbutton", function(event) {
  157. alert("clickable true");
  158. if (event.originalEvent.persisted) {
  159. document.location.reload();
  160. }
  161. });
  162. };
  163. this.barcodeCallback = function(data){
  164. if(data.includes("PO@") == true){
  165. var tempData = data.split("@");
  166. var param = {
  167. hospitalCd: localStorage.getItem("hospitalCd"),
  168. AtcBarCodeData: tempData[1],
  169. };
  170. self.safety.getAtcPrescriptionList(param, processGetAtcPrescriptionList);
  171. return;
  172. }
  173. var result = self.util.decodeBarcode(data);
  174. if(self.util.isEmpty(result)){
  175. // modal 호출
  176. emptyData("정보조회에 실패하였습니다.", "다시 시도해주세요.");
  177. return;
  178. }
  179. else if(result.type == 'pid'){
  180. // 환자 바코드 스캔
  181. var patientId = result.data;
  182. $("#txtPatientId").val(patientId);
  183. getPocPatientInfo(patientId, false);
  184. $("#txtPatientId").blur();
  185. }
  186. else if(result.type == 'medicine'){
  187. $("#txtPatientId").blur();
  188. if(self.util.isEmpty(patientData) || patientData.length == 0){
  189. emptyData('환자정보가 조회되지 않았습니다.', '환자정보를 조회하여 주세요');
  190. return;
  191. }
  192. // 단일 투약 스캔
  193. var aaa = [result.data];
  194. barCodeMedicineListToggle(aaa);
  195. }
  196. // poBarcode
  197. else if (result.type == "poBarcode") {
  198. $("#txtPatientId").blur();
  199. if(self.util.isEmpty(patientData) || patientData.length == 0){
  200. emptyData('환자정보가 조회되지 않았습니다.', '환자정보를 조회하여 주세요');
  201. return;
  202. }
  203. var spanDate = $("#spanDate").text().trim().split("-");
  204. var dateStr = spanDate[0] + spanDate[1] + spanDate[2];
  205. var dataList = new Array();
  206. result.data.forEach(barData =>{
  207. if(barData.date.toString() == dateStr){
  208. dataList.push(barData.item);
  209. }
  210. });
  211. // 투약 리스트 스캔
  212. console.log("origndataList -- > " + dataList);
  213. barCodeMedicineListToggle(dataList);
  214. }
  215. else if (result.type == "medicineList") {
  216. if (self.util.isEmpty(result.data)) {
  217. emptyData('투약실시 바코드가 아닙니다.', '바코드를 다시 확인해주세요');
  218. } else {
  219. barCodeMedicineListToggle(result.data);
  220. }
  221. }
  222. else{
  223. $("#txtPatientId").blur();
  224. emptyData('투약실시 바코드가 아닙니다.', '바코드를 다시 확인해주세요');
  225. // $("#Modal01").modal("show");
  226. }
  227. // // null 이라면 반환
  228. // if(self.util.isEmpty(data)){
  229. // return;
  230. // }
  231. // else{
  232. // var result = self.util.decodeBarcode(data);
  233. // }
  234. //
  235. // // 환자 번호라면
  236. // if(result.type == 'pid'){
  237. // // 최초 리딩 시 환자 정보 초기화
  238. // $("#txtBleedingPatientSearch").val('');
  239. //
  240. // console.log('data: ' + result.data);
  241. // // 환자번호 표시
  242. // $("#txtBleedingPatientSearch").val(result.data);
  243. // // 환자 정보 호출
  244. // var param = {
  245. // hospitalCd: localStorage.getItem("hospitalCd"),
  246. // userId: gLoginUserId,
  247. // patientId: $("#txtBleedingPatientSearch").val()
  248. // };
  249. //
  250. // self.medical.getPatientInfo(param, processGetPatientInfo);
  251. // }
  252. // // 투약 번호라면
  253. // else if(result.type == 'specimenCd'){
  254. //
  255. // }
  256. };
  257. var processGetAtcPrescriptionList = function(output) {
  258. console.log("output -- > " + output);
  259. if(self.util.isEmpty(output)){
  260. // modal 호출
  261. emptyData("정보조회에 실패하였습니다.", "다시 시도해주세요.");
  262. return;
  263. }
  264. $("#txtPatientId").blur();
  265. if(self.util.isEmpty(patientData) || patientData.length == 0){
  266. emptyData('환자정보가 조회되지 않았습니다.', '환자정보를 조회하여 주세요');
  267. return;
  268. }
  269. var outputTempData = output[0].prescriptionData.slice(0, -1);
  270. var outputData = outputTempData.split("*");
  271. console.log("outputData -- > " + outputData);
  272. var dataList = new Array();
  273. for (var i = 0; i < outputData.length; i++) {
  274. var result = self.util.decodeBarcode(outputData[i]);
  275. console.log("result -- > " + JSON.stringify(result));
  276. if (result.type == "poBarcode") {
  277. var spanDate = $("#spanDate").text().trim().split("-");
  278. var dateStr = spanDate[0] + spanDate[1] + spanDate[2];
  279. result.data.forEach(barData =>{
  280. if(barData.date.toString() == dateStr){
  281. console.log("barData -- > " + barData.item);
  282. dataList.push(barData.item);
  283. }
  284. });
  285. }
  286. }
  287. // 투약 리스트 스캔
  288. console.log("dataList -- > " + dataList);
  289. barCodeMedicineListToggle(dataList);
  290. // for (var i = 0; i < output.length; i++) {
  291. // var result = self.util.decodeBarcode(output[i].prescriptionData);
  292. // console.log("result -- > " + JSON.stringify(result));
  293. // if (result.type == "poBarcode") {
  294. // var spanDate = $("#spanDate").text().trim().split("-");
  295. // var dateStr = spanDate[0] + spanDate[1] + spanDate[2];
  296. // result.data.forEach(barData =>{
  297. // if(barData.date.toString() == dateStr){
  298. // dataList.push(barData.item);
  299. // }
  300. // });
  301. // }
  302. }
  303. var eventCondition = function() {
  304. //투약일자 현재의 전 날짜를 가져온다
  305. $("#dateMinus").off("click");
  306. $("#dateMinus").on("click", function() {
  307. $(this).blur();
  308. $("#spanDate").text(minusDate());
  309. $("#medicineSearchBtn").click();
  310. });
  311. //투약일자 현재 이후 날짜를 가져온다 단 현재일 보다 커질 수 없다
  312. $("#datePlus").off("click");
  313. $("#datePlus").on("click", function() {
  314. $(this).blur();
  315. var changeDate = plusDate();
  316. if (changeDate == "") {
  317. } else {
  318. $("#spanDate").text(changeDate);
  319. $("#medicineSearchBtn").click();
  320. }
  321. });
  322. /**
  323. * 조회 버튼 클릭 이벤트
  324. */
  325. $("#medicineSearchBtn").off("click");
  326. $("#medicineSearchBtn").on("click", function() {
  327. $(this).blur();
  328. var txtSearch = $("#txtPatientId").val();
  329. if (txtSearch == "") {
  330. $("#Modal01 .modal-body h4").text("입력된 환자번호가 없습니다.");
  331. $("#Modal01 .modal-body p").text("환자번호를 입력해주세요.");
  332. $("#Modal01").modal("show");
  333. } else {
  334. // $("#medicineSearchBtn").removeClass("btn-secondary").addClass("btn-primary");
  335. getPocPatientInfo($("#txtPatientId").val(), false);
  336. }
  337. });
  338. };
  339. $("#actionHour").change(function() {
  340. $("#actionHour option:selected").each(function() {
  341. ClearTimer();
  342. var today = new Date();
  343. var todayHH = today.getHours();
  344. var todayMM = today.getMinutes();
  345. // patientData[0].dschYn = "Y";
  346. if (todayHH < 10) {
  347. todayHH = "0" + todayHH
  348. }
  349. if (todayMM < 10) {
  350. todayMM = "0" + todayMM
  351. }
  352. var nowActTime = String(todayHH) + String(todayMM);
  353. var selectHourValue = String($("#actionHour option:selected").val());
  354. var nowMinVal = String($("#actionMinute").val());
  355. if (selectHourValue + nowMinVal > nowActTime) {
  356. if (patientData.length > 0 && patientData[0].dschYn == "Y") {
  357. $("#actionHour").val(selectHourValue);
  358. } else {
  359. emptyData("시간변경 오류", "현재시간 이후로는 변경할 수 없습니다");
  360. $("#actionMinute").val(todayMM);
  361. $("#actionHour").val(todayHH);
  362. }
  363. }
  364. });
  365. });
  366. $("#actionMinute").change(function() {
  367. $("#actionMinute option:selected").each(function() {
  368. ClearTimer();
  369. var today = new Date();
  370. var todayHH = today.getHours();
  371. var todayMM = today.getMinutes();
  372. // patientData[0].dschYn = "Y";
  373. if (todayHH < 10) {
  374. todayHH = "0" + todayHH
  375. }
  376. if (todayMM < 10) {
  377. todayMM = "0" + todayMM
  378. }
  379. var nowActTime = String(todayHH) + String(todayMM);
  380. var selectMinValue = String($("#actionMinute option:selected").val());
  381. var nowHourVal = String($("#actionHour").val());
  382. if (nowHourVal + selectMinValue > nowActTime) {
  383. if (patientData.length > 0 && patientData[0].dschYn == "Y") {
  384. $("#actionMinute").val(selectMinValue);
  385. } else {
  386. emptyData("시간변경 오류", "현재시간 이후로는 변경할 수 없습니다");
  387. $("#actionMinute").val(todayMM);
  388. $("#actionHour").val(todayHH);
  389. }
  390. }
  391. });
  392. });
  393. /**
  394. * 환자 조회
  395. * @param {*} patientId 입력받은 환자번호
  396. * @param {*} isSecondTrial 두 번째 호출 여부
  397. */
  398. var getPocPatientInfo = function(patientId, isSecondTrial) {
  399. var param = {
  400. hospitalCd: localStorage.getItem("hospitalCd"),
  401. userId: gLoginUserId,
  402. patientId: patientId,
  403. isSecondTrial: isSecondTrial
  404. };
  405. self.safety.getPocPatientInfo(param, patientId, isSecondTrial, processGetPocPatientInfo);
  406. };
  407. /**
  408. * 호출된 기본정보를 화면에 매핑
  409. * @param {*} lists API 반환 데이터
  410. * @param {*} barPid 입력받은 환자번호
  411. * @param {*} isSecondTrial 두 번째 호출 여부
  412. */
  413. var processGetPocPatientInfo = function(lists, barPid, isSecondTrial) {
  414. patientData = [];
  415. actionHourSetting();
  416. if (lists == "undefined" || lists == null || lists.length == 0) {
  417. $("#txtPatientId").val('');
  418. $("#txtPatientId").blur();
  419. initPatientInfo();
  420. emptyMedicine();
  421. emptyData("환자정보 조회 실패", "환자정보 조회에 실패하였습니다.");
  422. return;
  423. }
  424. // 1. 만일 환자 정보가 맞다면 환자 정보를 보여준다.
  425. if (barPid == lists[0].patientId) {
  426. patientData = lists;
  427. $("#patientName").text(patientData[0].patientNm);
  428. $("#patient-gender-age").text(patientData[0].age + "/" + patientData[0].gender + " " + patientData[0].roomNm + "호");
  429. $("#spanWard").text(localStorage.getItem("selectedDeptNm"));
  430. $("#spanAcrionUserName").text(gLoginUserNm + "(" + gLoginUserId + ")");
  431. $("#patientName").append("<button type=\"button\" class=\"btn btn-blood\">" + patientData[0].bloodType + "</button>");
  432. var summaryCd = patientData[0].patientSummaryCd.split(",");
  433. var spanTag = "";
  434. for (var i = 0; i < summaryCd.length; i++) {
  435. var sCd = summaryCd[i];
  436. if (sCd == "!") {
  437. sCd = "t";
  438. } else if (sCd == "₩") {
  439. sCd = "w";
  440. }
  441. spanTag = "<span class=\"glyphicon ico ico_" + sCd.toLowerCase() + " align-middle\" aria-hidden=\"true\"></span>"
  442. $("#patient-gender-age").append(spanTag);
  443. }
  444. // getPrescriptionList(lists, "");
  445. getPrescriptionList(false);
  446. // 2. 환자 정보가 맞지 않으면
  447. } else {
  448. // 2.1 2번째 호출이 아니면 다시 환자 정보 조회
  449. if (!isSecondTrial) {
  450. getPocPatientInfo(barPid, true)
  451. // 2.2 2번째 호출이면 Alert
  452. } else {
  453. initPatientInfo();
  454. emptyMedicine();
  455. emptyData("환자정보 조회 실패", "시스템 이용량이 많습니다. 다시 조회해 주세요.");
  456. }
  457. }
  458. }
  459. /**
  460. *
  461. * @param {*} isSecondTrial 두 번째 호출 여부
  462. */
  463. var getPrescriptionList = function(isSecondTrial) {
  464. var medicationDt = $("#spanDate").text().split("-");
  465. var inDd = patientData[0].inDd;
  466. var param = {
  467. hospitalCd : patientData[0].hospitalCd,
  468. userId : gLoginUserId,
  469. patientId : patientData[0].patientId,
  470. medicationDt : medicationDt[0]+medicationDt[1]+medicationDt[2],
  471. inDd : inDd,
  472. cretNo : patientData[0].cretNo,
  473. isSecondTrial: isSecondTrial
  474. }
  475. self.safety.getPrescriptionList(param, isSecondTrial, processGetPrescriptionList);
  476. }
  477. /**
  478. *
  479. * @param {*} isSecondTrial 두 번째 호출 여부
  480. * @param {*} result API 반환 데이터
  481. */
  482. var processGetPrescriptionList = function(isSecondTrial, result) {
  483. medicineList = [];
  484. medicineSelectItem = [];
  485. console.log("result -- > " + JSON.stringify(result));
  486. $("#listItem").empty();
  487. // $("#listItem").remove();
  488. // 반환되는 데이터가 Null 일 경우
  489. if(self.util.isEmpty(result) || result.length == 0){
  490. $("#divScanMsg").css("display", "");
  491. // return emptyData("처방정보 조회", "조회된 처방정보가 없습니다.");
  492. return;
  493. }
  494. // 기존 환자정보와 반환 데이터 환자정보가 일치할 경우
  495. if (patientData[0].patientId == result[0].patientId) {
  496. for (var i = 0; i < result.length; i++) {
  497. if (result[i].flag == "N") {
  498. medicineList.push(result[i]);
  499. }
  500. }
  501. if (medicineList.length == 0) {
  502. $("#divScanMsg").css("display", "");
  503. return emptyData("처방정보 조회", "조회된 처방정보가 없습니다.");
  504. }
  505. // medicineList = result;
  506. $("#divScanMsg").attr("style", "display: none");
  507. $("#con").append("<ul id=\"listItem\" class=\"list-group\"></ul>");
  508. var actionTime = [];
  509. for (var i = 0; i < medicineList.length; i++) {
  510. actionTime.push(medicineList[i].actMedicationTm);
  511. var frontAct = medicineList[i].actMedicationTm.substring(0, 2) % 24;
  512. if (frontAct < 10) {
  513. frontAct = "0" + frontAct;
  514. } else {
  515. frontAct = frontAct;
  516. }
  517. var item = "<li id=\"medicine_" + i + "\"class=\"list-group-item\">"
  518. + " <div class=\"row\">"
  519. + " <div class=\"col-xs-3\">"
  520. + " <p>"
  521. + " <span class=\"glyphicon glyphicon-time\" aria-hidden=\"true\">"
  522. + frontAct + ":" + medicineList[i].actMedicationTm.substring(2, 4) // 투여시간 hh:mm
  523. + " </span>"
  524. + " </p>"
  525. + " <p>"
  526. + " <strong class=\"text-color1\" style=\"font-size: 13px !important;\">"
  527. + medicineList[i].prcpCd // 처방코드
  528. + " </strong>"
  529. + " </p>"
  530. + " <p style=\"font-size: 13px !important;\">"
  531. + medicineList[i].prescriptionNo // 처방 번호
  532. + " </p>"
  533. + " </div>"
  534. + " <div class=\"col-xs-7\">"
  535. + " <p style=\"font-size: 14px;\">"
  536. + medicineList[i].prcpNm // 처방명
  537. + " </p>"
  538. + " <p>"
  539. + " <strong class=\"text-color1\">"
  540. + medicineList[i].prescriptionCapaDay + medicineList[i].prescriptionCapaDayUnit // 1일 용량 + 1일 용량 단위
  541. + " </strong>"
  542. + " <span class=\"text-muted px-1\">|</span>"
  543. + medicineList[i].prescriptionTmDay // 일일 횟수
  544. + " <span class=\"text-muted px-1\">|</span>"
  545. + medicineList[i].actMedicationInfo // 용법
  546. + " </p>"
  547. + " </div>"
  548. + " <div class=\"col-xs-2 text-color1\">"
  549. + " <strong>"
  550. + medicineList[i].prescriptionQtyDay + medicineList[i].prescriptionQtyDayUnit // 일일 수량 + 일일 수량 단위
  551. + " </strong>"
  552. + " </div>"
  553. + " </div>"
  554. + "</li>";
  555. $("#listItem").append(item);
  556. }
  557. medicienToggleEvent();
  558. // 환자정보가 일치하지 않을 경우
  559. } else {
  560. // 첫 번째 호출일 경우
  561. if (!isSecondTrial) {
  562. getPrescriptionList(true);
  563. // 두 번째 호출하는 경우
  564. } else {
  565. emptyData("처방정보 조회 실패", "시스템 이용량이 많습니다. 다시 조회해 주세요.");
  566. emptyMedicine();
  567. }
  568. }
  569. StartTimer();
  570. }
  571. function emptyData(title, message) {
  572. $("#Modal01 .modal-body h4").text(title);
  573. $("#Modal01 .modal-body p").text(message);
  574. $("#Modal01").modal("show");
  575. }
  576. function medicienToggleEvent() {
  577. $(".list-group .list-group-item").off("dblclick");
  578. $(".list-group .list-group-item").on("dblclick", function () {
  579. actTypeCheck = "EMR";
  580. $(this).toggleClass('active');
  581. var id = $(this).attr("id");
  582. // var index = id.charAt(id.length - 1);
  583. var index = id.split("_")[1];
  584. if ($(this).hasClass("active") == true) {
  585. medicineSelectItem[index] = medicineList[index];
  586. } else {
  587. delete medicineSelectItem[index];
  588. }
  589. });
  590. }
  591. function makeCheckedItem(medicineObj, index){
  592. var frontAct = medicineObj.actMedicationTm.substring(0, 2) % 24;
  593. if (frontAct < 10) {
  594. frontAct = "0" + frontAct;
  595. }
  596. return "<li id=\"medicine_" + index + "\"class=\"list-group-item\">"
  597. + " <div class=\"row\">"
  598. + " <div class=\"col-xs-3\">"
  599. + " <p>"
  600. + " <span class=\"glyphicon glyphicon-time\" aria-hidden=\"true\">"
  601. + frontAct + ":" + medicineObj.actMedicationTm.substring(2, 4) // 투여시간 hh:mm
  602. + " </span>"
  603. + " </p>"
  604. + " <p>"
  605. + " <strong class=\"text-color1\" style=\"font-size: 13px !important;\">"
  606. + medicineObj.prcpCd // 처방코드
  607. + " </strong>"
  608. + " </p>"
  609. + " <p style=\"font-size: 13px !important;\">"
  610. + medicineObj.prescriptionNo // 처방 번호
  611. + " </p>"
  612. + " <p>"
  613. + medicineObj.prescriptionTypeNm // 처방종류명 (경구, 주사, 마약, 수액)
  614. + " </p>"
  615. + " </div>"
  616. + " <div class=\"col-xs-7\">"
  617. + " <p>"
  618. + medicineObj.prcpNm // 처방명
  619. + " </p>"
  620. + " <p>"
  621. + " <strong class=\"text-color1\">"
  622. + medicineObj.prescriptionCapaDay + medicineObj.prescriptionCapaDayUnit // 1일 용량 + 1일 용량 단위
  623. + " </strong>"
  624. + " <span class=\"text-muted px-1\">|</span>"
  625. + medicineObj.prescriptionTmDay // 일일 횟수
  626. + " <span class=\"text-muted px-1\">|</span>"
  627. + medicineObj.actMedicationInfo // 용법
  628. + " </p>"
  629. + " </div>"
  630. + " <div class=\"col-xs-2 text-color1\">"
  631. + " <strong>"
  632. + medicineObj.prescriptionQtyDay + medicineObj.prescriptionQtyDayUnit // 일일 수량 + 일일 수량 단위
  633. + " </strong>"
  634. + " </div>"
  635. + " </div>"
  636. + "</li>";
  637. }
  638. /**
  639. * ----------------------------------------------------
  640. * List 프로토 타입 정의 시작
  641. */
  642. function List() {
  643. this.elements = {};
  644. this.idx = 0;
  645. this.length = 0;
  646. }
  647. List.prototype.add = function(element) {
  648. this.length++;
  649. this.elements[this.idx++] = element;
  650. };
  651. List.prototype.get = function(idx) {
  652. return this.elements[idx];
  653. };
  654. /**
  655. * LIST 프로토 타입 정의 끝
  656. * -----------------------------------------------------
  657. */
  658. /**
  659. * 중복 아이템을 검사하고 중복되어 있다면 최근 시간에 가까운
  660. * 아니라면 검색된 아이템을 반환
  661. * @param {Array} prescriptionNo
  662. */
  663. function checkDupItem(prescriptionNo){
  664. var item = {
  665. index: new List(),
  666. obj: new List()
  667. };
  668. medicineList.forEach(function(element, idx){
  669. if(prescriptionNo == element.prescriptionNo){
  670. item.index.add(idx);
  671. item.obj.add(element);
  672. // resultList.add(element);
  673. }
  674. });
  675. var minIndex = 0;
  676. // 중복 발생 시 최근 아이템만
  677. if(item.obj.length != 1){
  678. var dayDelta = 0;
  679. var timeDelta = 0;
  680. var todayObj = moment();
  681. var today = todayObj.format('YYYYMMDD');
  682. var currentTime = todayObj.format('HHmm');
  683. var toDateTime = new Date(todayObj.format('YYYY-MM-DD HH:mm'));
  684. var calDate = 0;
  685. for(var i = 0; i < item.obj.length; i++){
  686. var tempItemObj = item.obj.get(i);
  687. var spanDate = $("#spanDate").text().trim().split("-");
  688. var dateStr = spanDate[0] + spanDate[1] + spanDate[2];
  689. var actMedicationTmDate = dateParse(dateStr+tempItemObj.actMedicationTm.trim());
  690. if (i == 0) {
  691. calDate = Math.abs((toDateTime.getTime() - actMedicationTmDate.getTime()));
  692. } else {
  693. var tempValue = Math.abs(toDateTime.getTime() - actMedicationTmDate.getTime());
  694. if(calDate > tempValue) {
  695. minIndex = i;
  696. }
  697. // if (toDateTime.getTime() > Math.abs(calDate)) {
  698. // console.log("222 -- > " + i);
  699. //
  700. // }
  701. }
  702. }
  703. }
  704. var retObj = {
  705. index: item.index.get(minIndex),
  706. obj: item.obj.get(minIndex)
  707. };
  708. return retObj;
  709. }
  710. /**
  711. * 처방번호 스캔시 아이템 토글
  712. * @param {String} prescriptionNo 수신 바코드
  713. */
  714. function barCodeMedicineListToggle(prescriptionNo) {
  715. // console.log("prescriptionNo -- > " + prescriptionNo);
  716. medicineSelectItem = [];
  717. var selectPrescription = [];
  718. // 선택된 아이템이 없다면
  719. if(self.util.isEmpty(medicineSelectItem) || medicineSelectItem.length == 0){
  720. $("#listItem").children().remove();
  721. }
  722. for (var j = 0; j < prescriptionNo.length; j++) {
  723. for (var i = 0; i < medicineList.length; i++) {
  724. if (medicineList[i].prescriptionNo == prescriptionNo[j]) {
  725. selectPrescription.push(prescriptionNo[j]);
  726. }
  727. }
  728. }
  729. if (selectPrescription.length > 0) {
  730. var foundCnt = 0;
  731. for (var x = 0; x < selectPrescription.length; x++) {
  732. var medicineObj = checkDupItem(selectPrescription[x]);
  733. if (!self.util.isEmpty(medicineObj) && self.util.isEmpty(medicineSelectItem[medicineObj.index])) {
  734. medicineSelectItem[medicineObj.index] = medicineList[medicineObj.index];
  735. var listStr = makeCheckedItem(medicineObj.obj, medicineObj.index);
  736. $("#divScanMsg").attr("style", "display: none");
  737. $("#listItem").append(listStr);
  738. $("#medicine_" + medicineObj.index).addClass("active");
  739. foundCnt++;
  740. }
  741. }
  742. if(foundCnt == 0){
  743. emptyData("실시할 수 없는 투약 바코드 입니다.", "");
  744. }
  745. } else {
  746. emptyData("조회된 처방이 없습니다.", "처방번호를 확인해주세요.");
  747. $("#divScanMsg").attr("style", "display: ;");
  748. }
  749. actTypeCheck = "POC";
  750. medicienToggleEvent();
  751. };
  752. function medicineActionEvent() {
  753. $("#medicineActionBtn").on("click", function() {
  754. $(this).blur();
  755. var cnt = 0;
  756. var count = 0;
  757. var spanDate = $("#todayDate").text().split("-");
  758. var actionDate = spanDate[0] + spanDate[1] + spanDate[2];
  759. var inDdTm = patientData[0].inDd + patientData[0].inTm;
  760. var actDate = actionDate + $("#actionHour").val() + $("#actionMinute").val();
  761. if (medicineSelectItem == null || medicineSelectItem.length == 0) {
  762. emptyData("투약할 처방을 선택하지 않았습니다.", "투약할 처방을 선택해주세요.");
  763. } else {
  764. if (inDdTm > actDate) {
  765. emptyData("실시시간이 입원일보다 빠릅니다.", "다시 확인해주시기 바랍니다.");
  766. } else {
  767. for (var key in medicineSelectItem) {
  768. cnt = cnt + 1;
  769. }
  770. for (var key in medicineSelectItem) {
  771. // console.log("asdfasdf -- > " + JSON.stringify(medicineSelectItem[i]));
  772. var hospitalCd = patientData[0].hospitalCd; // 병원코드
  773. var userId = gLoginUserId; // 사용자 ID
  774. var prescriptionNo = medicineSelectItem[key].prescriptionNo; // 처방번호
  775. // var actMedicationTm = $('#actionTimeCombo').val(); // 선택시간 -- >
  776. var actMedicationTm = $("#actionHour").val() + $("#actionMinute").val(); // -- > 콤보박스 수정 + 날짜
  777. var prescriptionTypeCd = medicineSelectItem[key].prescriptionTypeCd; // 처방종류코드 (경구, 주사, 마약, 수액)
  778. var actMedicationDtTm = self.util.toDatetimeFatima2(new Date());// 현재시간 yyyy mm dd hh miss -- > spanDate.val + actMedicationTm
  779. var actTypeCheck = actTypeCheck; // 처리구분 (POC, EMR)
  780. var actType = "POC"; // 처리구분 (POC, EMR)
  781. console.log("actType -- > " + actType);
  782. var patientId = patientData[0].patientId; // 환자번호
  783. var inDd = patientData[0].inDd; // 입원일자
  784. var cretNo = patientData[0].cretNo; // 수진생성번호
  785. var prcpDd = medicineSelectItem[key].prcpDd; // 처방일자
  786. var prcpHistNo = medicineSelectItem[key].prcpHistNo; // 처방이력번호
  787. var execPrcpNo = medicineSelectItem[key].execPrcpNo; // 실시번호(아점저구분)
  788. var prescriptionTmDay = medicineSelectItem[key].prescriptionTmDay; // 1일 횟수
  789. var prcpCd = medicineSelectItem[key].prcpCd; // 처방코드
  790. var prcpNm = medicineSelectItem[key].prcpNm; // 처방명
  791. var prescriptionCapaDay = medicineSelectItem[key].prescriptionCapaDay; // 1일 용량
  792. var drugBaseTmSpec = medicineSelectItem[key].drugBaseTmSpec; // 실시 기준시간
  793. var execPrcpUniqNo = medicineSelectItem[key].execPrcpUniqNo; // 실시처방키(아점저구분)
  794. var execDeptCd = localStorage.getItem("selectedDeptCd"); // 로그인 로컬스토리지 사용자 선택
  795. console.log(execDeptCd);
  796. var carecFact = medicineSelectItem[key].carecFact; // 상용구
  797. var carecFactCd = medicineSelectItem[key].carecFactCd; // 상용구 코드
  798. var prcpMixNo = medicineSelectItem[key].prcpMixNo; // 처방믹스번호
  799. var prcpMixYn = medicineSelectItem[key].prcpMixYn; // 처방믹스여부
  800. var tims = medicineSelectItem[key].tims.replace("#", ""); // 횟수(#제거)
  801. var actTm = medicineSelectItem[key].actMedicationTm;
  802. var param = {
  803. hospitalCd : hospitalCd ,
  804. userId : userId ,
  805. prescriptionNo : prescriptionNo ,
  806. actMedicationTm : actMedicationTm ,
  807. prescriptionTypeCd : prescriptionTypeCd ,
  808. actMedicationDtTm : actMedicationDtTm ,
  809. actType : actType ,
  810. patientId : patientId ,
  811. inDd : inDd ,
  812. cretNo : cretNo ,
  813. prcpDd : prcpDd ,
  814. prcpHistNo : prcpHistNo ,
  815. execPrcpNo : execPrcpNo ,
  816. prescriptionTmDay : prescriptionTmDay ,
  817. prcpCd : prcpCd ,
  818. prcpNm : prcpNm ,
  819. prescriptionCapaDay : prescriptionCapaDay,
  820. drugBaseTmSpec : drugBaseTmSpec ,
  821. execPrcpUniqNo : execPrcpUniqNo ,
  822. execDeptCd : execDeptCd,
  823. carecFact : carecFact ,
  824. carecFactCd : carecFactCd ,
  825. prcpMixNo : prcpMixNo ,
  826. prcpMixYn : prcpMixYn ,
  827. tims : tims ,
  828. actTm : actTm
  829. }
  830. var result = self.safety.actMedication(param);
  831. count = count + 1;
  832. if (result != "") {
  833. if (result == "failed") {
  834. alert("투약실시에 오류가 발생하였습니다. \n" + prcpNm);
  835. } else {
  836. if (cnt == count) {
  837. alert("투약 실시가 처리되었습니다.");
  838. getPocPatientInfo($("#txtPatientId").val(), false);
  839. }
  840. }
  841. }
  842. // self.safety.actMedication(param, medicineActionCallbak, cnt, key);
  843. }
  844. }
  845. }
  846. });
  847. }
  848. // var cnt = 0
  849. // var outputAr = [];
  850. // var medicineActionCallbak = function(output, size, key) {
  851. // var param = {output, key};
  852. // outputAr.push(param);
  853. //
  854. // if (size == outputAr.length) {
  855. // var errorFlag = false;
  856. // for (var i = 0; i < outputAr.length; i++) {
  857. // console.log("output[i] -- > " + outputAr[i].output);
  858. // if (outputAr[i].output == "0001") {
  859. // errorFlag = true;
  860. // }
  861. // }
  862. // if (errorFlag == true) {
  863. // alert("투약 실시에 오류가 발생하였습니다");
  864. //
  865. // } else {
  866. // alert("투약 실시가 처리되었습니다.");
  867. // }
  868. //
  869. // getPocPatientInfo($("#txtPatientId").val());
  870. // outputAr = [];
  871. // }
  872. //// location.reload();
  873. // }
  874. function minusDate() {
  875. var dateAr = $("#spanDate").text().split("-");
  876. var nowDate = new Date(dateAr[0], dateAr[1] - 1, dateAr[2]);
  877. var dateStr = nowDate.setDate(nowDate.getDate() - 1);
  878. $("#dateMinus").off("focus");
  879. return moment(dateStr).format("YYYY-MM-DD");
  880. }
  881. function plusDate() {
  882. var varCurDate = self.util.toDate(new Date());
  883. // console.log("varCurDate -- > " + varCurDate);
  884. var dateAr = $("#spanDate").text().split("-");
  885. var nowDate = new Date(dateAr[0], dateAr[1] - 1, dateAr[2]);
  886. var dateStr = nowDate.setDate(nowDate.getDate() + 1);
  887. dateStr = moment(dateStr).format("YYYY-MM-DD");
  888. // console.log("dateStr -- > " + dateStr);
  889. $("#datePlus").off("focus");
  890. if (varCurDate < dateStr) {
  891. if (patientData.length > 0) {
  892. var dschYn = patientData[0].dschYn;
  893. if (dschYn == "Y") {
  894. return moment(dateStr).format("YYYY-MM-DD");
  895. } else {
  896. return "";
  897. }
  898. } else {
  899. return "";
  900. }
  901. } else {
  902. return moment(dateStr).format("YYYY-MM-DD");
  903. }
  904. }
  905. /**
  906. * 문자열 일자 Date로 변환
  907. * ex) 202002121430
  908. */
  909. function dateParse(str) {
  910. if(!/^(\d){12}$/.test(str) || str == "") return "";
  911. var y = str.substr(0, 4);
  912. var m = str.substr(4, 2) - 1;
  913. var d = str.substr(6, 2);
  914. var h = str.substr(8, 2);
  915. var mm = str.substr(10, 2);
  916. return new Date(y,m,d,h,mm);
  917. }
  918. };