bleeding.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. "use strict";
  2. /**
  3. * mplus_safety_bleeding
  4. */
  5. var mplus_safety_bleeding = function() {
  6. // 상속
  7. mplus_common.call(this);
  8. //super
  9. var self = this;
  10. var curPage = "";
  11. var testId = localStorage.getItem("initLoginDtTm");
  12. console.log(testId);
  13. //==== 변수 { ====
  14. var varResultLists = [];
  15. var patientInfo = [];
  16. /* Fatima 전역 변수 */
  17. var specimenSearchCls = 0; // 실시조회 및 취소조회 검색 조건(실시 = 0, 취소 = 1)
  18. var gActSpecimenType = "Y"; // 실시조회 및 취소조회 검색 조건(처리 = Y, 취소 = C)
  19. var checkBoxArr = []; // checkBox 선택된 list를 따로 배열로 이동
  20. /* Fatima 전역 변수 */
  21. //==== 변수 } ====
  22. /**
  23. * 초기화
  24. */
  25. this.init = function() {
  26. //여기서 모든화면 콤보박스데이터를 집어넣자!!! 그래야지 화면이동할때 속도가 오래걸리지않음!!!
  27. localStorage.removeItem("defaultHomePage");
  28. localStorage.setItem("defaultHomePage", "bleeding");
  29. // 초기 화면 조건 구성
  30. initCondition();
  31. // 이벤트 초기화
  32. addEvent();
  33. // 환자 검색 실행 및 환자 정보 화면 출력
  34. //searchPatient();
  35. $("#txtBleedingPatientSearch").focus();
  36. };
  37. this.barcodeCallback = function(data){
  38. console.log("barcode read! inside bleeding.js");
  39. // null 이라면 반환
  40. if(self.util.isEmpty(data)){
  41. return;
  42. }
  43. else{
  44. var result = self.util.decodeBarcode(data);
  45. }
  46. if(self.util.isEmpty(result) || result.type == 'errBarcode'){
  47. $("#txtBleedingPatientSearch").blur();
  48. // if(result === null || result === undefined || result.type == 'errBarcode'){
  49. $("#alertBarcodeCheck").modal("show");
  50. return;
  51. }
  52. // 환자 번호라면
  53. else if(result.type == 'pid'){
  54. $("#txtBleedingPatientSearch").blur();
  55. // 최초 리딩 시 환자 정보 초기화
  56. $("#txtBleedingPatientSearch").val('');
  57. var patientId = result.data;
  58. $("#txtBleedingPatientSearch").val(patientId);
  59. if (gActSpecimenType == "Y") {
  60. $("#btnBleedingList").removeClass().addClass("btn btn-primary btn-block");
  61. $("#btnBleedingAct").removeClass().addClass("btn btn-danger btn-block");
  62. $("#btnCancleList").removeClass().addClass("btn btn-secondary btn-block");
  63. $("#btnBleedingAct").text("채혈 실시");
  64. } else {
  65. $("#btnBleedingList").removeClass().addClass("btn btn-secondary btn-block");
  66. $("#btnBleedingAct").removeClass().addClass("btn btn-danger btn-block");
  67. $("#btnCancleList").removeClass().addClass("btn btn-councel btn-block");
  68. $("#btnBleedingAct").text("채혈 취소");
  69. }
  70. getPocPatientInfo(patientId, false);
  71. }
  72. // 채혈 번호라면
  73. else if(result.type == 'specimenCd'){
  74. $("#txtBleedingPatientSearch").blur();
  75. if(self.util.isEmpty(patientInfo) || patientInfo.length == 0){
  76. $("#alertEmptyPatient").modal("show");
  77. return;
  78. }
  79. // 3 번째를 barcode
  80. //varResultLists
  81. var foundCnt = 0;
  82. for(var idx = 0; idx < varResultLists.length; idx++){
  83. if(varResultLists[idx].mainSpecimenCd == result.data){
  84. console.log("label[for='checkBleedingSel" + idx + "']");
  85. var labelObj = $("label[for='checkBleedingSel" + idx + "']");
  86. labelObj.attr('class', 'btn btn-barcode icon');
  87. var iptObj = $('input:checkbox[id="checkBleedingSel' + idx + '"]');
  88. iptObj.prop('checked', true);
  89. var li = $('li[id="listGroupItem_' + idx + '"]');
  90. li.addClass("active");
  91. foundCnt++;
  92. }
  93. }
  94. if(foundCnt == 0){
  95. $('#alertSpecimen').modal('show');
  96. }
  97. }
  98. else{
  99. $("#txtBleedingPatientSearch").blur();
  100. $("#alertBarcodeCheck").modal("show");
  101. }
  102. };
  103. //==== 초기화 설정 { ====
  104. var initCondition = function() {
  105. // 초기 화면 조건 구성
  106. //환자정보 초기화
  107. initPatientInfo();
  108. };
  109. /**
  110. * 환자 정보 초기화
  111. */
  112. var initPatientInfo = function() {
  113. $(".patient-name").text("환자명");
  114. $(".patient-gender-age").text("성별/나이");
  115. $(".patient-birthDt").text("생년월일");
  116. $("#patientInfo").text("성별/나이");
  117. $(".dept-name").text("실시부서");
  118. $(".user-name").text("실시자명");
  119. $(".user-code").text("(사원번호)");
  120. $(".patient-name button").attr("style", "display: none");
  121. };
  122. /**
  123. * 리스트 초기화
  124. */
  125. var initList = function() {
  126. $("#bleedingListGroup").empty();
  127. $("#barcodeGroup").attr("style", "display: ;");
  128. }
  129. /**
  130. * 채혈실시 초기화 및 체크된 데이터 배열에 담음
  131. */
  132. var initactSpecimen = function() {
  133. console.log('initactSpecimen');
  134. checkBoxArr = [];
  135. //CheckBoxLength 초기화
  136. // actSpecimenLength = 0;
  137. //처방번호 체크
  138. for (var fCnt = 0; fCnt < varResultLists.length; fCnt++) {
  139. if ($("#checkBleedingSel" + fCnt).is(":checked")) {
  140. // checkBoxArr.push(varResultLists[fCnt]);
  141. checkBoxArr[fCnt] = varResultLists[fCnt];
  142. // actSpecimenLength++;
  143. }
  144. }
  145. actSpecimen();
  146. // console.log("checkBoxArr -- > " + JSON.stringify(checkBoxArr));
  147. //
  148. // for (var key in checkBoxArr) {
  149. // console.log("key -- > " + key);
  150. // }
  151. //eventMakeBarcodeCondition();
  152. };
  153. /**
  154. * 환자정보 요청
  155. * @param {*} patientId 입력받은 환자 번호
  156. * @param {*} isSecondTrial 두 번째 호출 여부
  157. */
  158. var getPocPatientInfo = function(patientId, isSecondTrial) {
  159. var param = {
  160. hospitalCd: localStorage.getItem("hospitalCd"),
  161. userId: gLoginUserId,
  162. patientId: patientId,
  163. isSecondTrial: isSecondTrial
  164. };
  165. self.safety.getPocPatientInfo(param, patientId, isSecondTrial, processGetPocPatientInfo);
  166. };
  167. /**
  168. *
  169. * @param {*} lists API 반환 데이터
  170. * @param {*} barPid 입력받은 환자 번호
  171. * @param {*} isSecondTrial 두 번째 호출 여부
  172. */
  173. var processGetPocPatientInfo = function(lists, barPid, isSecondTrial) {
  174. patientInfo = [];
  175. // 반환받은 데이터가 Null 일 경우 Alert
  176. if(self.util.isEmpty(lists) || lists.length == 0){
  177. initPatientInfo();
  178. initList();
  179. $("#txtBleedingPatientSearch").blur();
  180. $("#alertSuccess .modal-body h4").text("환자정보 조회 실패");
  181. $("#alertSuccess .modal-body p").text("환자정보 조회에 실패하였습니다");
  182. $("#alertSuccess").modal("show");
  183. return;
  184. }
  185. // 입력받은 환자번호와 반환 데이터의 환자번호가 일치하는 경우
  186. if (barPid == lists[0].patientId) {
  187. patientInfo = lists;
  188. $(".patient-name").text(lists[0].patientNm);
  189. $("#patientInfo").text(lists[0].age + "/" + lists[0].gender + " " + lists[0].roomNm + "호");
  190. $("#todayDate").text("현재 날짜 : " + moment(new Date()).format("YYYY-MM-DD"));
  191. $(".patient-birthDt").text(lists[0].birthDt);
  192. $(".dept-name").text(localStorage.getItem("selectedDeptNm"));
  193. $(".user-name").text(gLoginUserNm);
  194. $(".user-code").text("(" + gLoginUserId + ")");
  195. $(".patient-name").append("<button type=\"button\" class=\"btn btn-blood\">" + lists[0].bloodType + "</button>");
  196. var summaryCd = lists[0].patientSummaryCd.split(",");
  197. var spanTag = "";
  198. for (var i = 0; i < summaryCd.length; i++) {
  199. var sCd = summaryCd[i];
  200. if (sCd == "!") {
  201. sCd = "t";
  202. } else if (sCd == "₩") {
  203. sCd = "w";
  204. }
  205. spanTag = "<span class=\"glyphicon ico ico_" + sCd.toLowerCase() + " align-middle\" aria-hidden=\"true\"></span>"
  206. $("#patientInfo").append(spanTag);
  207. }
  208. getSpecimenList(false);
  209. // 환자 정보가 일치하지 않는 경우
  210. } else {
  211. // 첫 번째 호출인 경우
  212. if (!isSecondTrial) {
  213. getPocPatientInfo(barPid, true)
  214. // 두 번째 호출인 경우
  215. } else {
  216. initPatientInfo();
  217. initList();
  218. $("#txtBleedingPatientSearch").blur();
  219. $("#alertSuccess .modal-body h4").text("환자정보 조회 실패");
  220. $("#alertSuccess .modal-body p").text("시스템 이용량이 많습니다. 다시 조회해 주세요.");
  221. $("#alertSuccess").modal("show");
  222. }
  223. }
  224. };
  225. /**
  226. * 채혈 정보 호출
  227. * @param {*} isSecondTrial 두 번째 호출 여부
  228. */
  229. var getSpecimenList = function(isSecondTrial) {
  230. var param = {
  231. hospitalCd: "",
  232. userId: gLoginUserId,
  233. patientId: patientInfo[0].patientId,
  234. specimenSearchCls: specimenSearchCls,
  235. isSecondTrial: isSecondTrial
  236. };
  237. self.safety.getSpecimenList(param, isSecondTrial, processGetSpecimenList);
  238. };
  239. /**
  240. *
  241. * @param {*} isSecondTrial 두 번째 호출 여부
  242. * @param {*} lists API 반환 데이터
  243. */
  244. var processGetSpecimenList = function(isSecondTrial, lists){
  245. checkBoxArr = [];
  246. varResultLists = [];
  247. var strDisplayTemp = "";
  248. $("#bleedingListGroup").empty();
  249. // 반환되는 데이터가 Null 인 경우
  250. if(self.util.isEmpty(lists) || lists.length == 0){
  251. // $("#alertEmptyPatient .modal-body h4").text("검체정보 조회");
  252. // $("#alertEmptyPatient .modal-body p").text("조회된 검체정보가 없습니다.");
  253. // $("#alertEmptyPatient").modal("show");
  254. return;
  255. }
  256. // 기존의 환자정보와 반환 데이터의 환자정보가 일치하는 경우
  257. if (patientInfo[0].patientId == lists[0].patientId) {
  258. varResultLists = lists;
  259. $("#barcodeGroup").attr("style", "display: none;");
  260. for( var i = 0; i < lists.length; i++){
  261. strDisplayTemp += "<li class=\"list-group-item\" id=\"listGroupItem_" + i + "\" >"
  262. + "<div class=\"row\">"
  263. + "<div class=\"col-xs-10\">"
  264. + "<p>"
  265. + lists[i].specimenCd
  266. + "</p>"
  267. + "<p>"
  268. + lists[i].specimenNm
  269. + "</p>"
  270. + "</div>"
  271. + "<div class=\"col-xs-2 p-0 text-center select_ico\">"
  272. + "<input type=\"checkbox\" class=\"checkClassBleedingSel\" id=\"checkBleedingSel" + i + "\" autocomplete=\"off\"/>"
  273. + "<div class=\"group\">"
  274. + "<label class=\"btn btn-check icon\" for=\"checkBleedingSel" + i + "\" name=\"checkedItem" + i +"\" >"
  275. + "<span class=\"glyphicon glyphicon-ok\" aria-hidden=\"true\">"
  276. + "</span>"
  277. + "</label>"
  278. + "<label class=\"btn btn-outline-check icon\" for=\"checkBleedingSel" + i + "\" >"
  279. + "<span class=\"glyphicon \" aria-hidden=\"true\">"
  280. + "</span>"
  281. + "</label>"
  282. + "</div>"
  283. + "</div>"
  284. + "</li>";
  285. }
  286. $("#bleedingListGroup").append(strDisplayTemp);
  287. eventMakeCondition();
  288. // 환자정보가 일치하지 않는 경우
  289. } else {
  290. // 첫 번째 호출인 경우
  291. if (!isSecondTrial) {
  292. getSpecimenList(true)
  293. // 두 번째 호출인 경우
  294. } else {
  295. $("#alertEmptyPatient .modal-body h4").text("채혈정보 조회 오류");
  296. $("#alertEmptyPatient .modal-body p").text("시스템 이용량이 많습니다. 다시 조회해 주세요.");
  297. $("#alertEmptyPatient").modal("show");
  298. }
  299. }
  300. };
  301. // 채혈실시
  302. var actSpecimen = function() {
  303. if (checkBoxArr.length == 0) {
  304. $("#alertSuccess .modal-body h4").text("실시할 채혈 정보가 없습니다.");
  305. $("#alertSuccess .modal-body p").text(inputCnt + "실시할 채혈 정보를 선택해주세요.");
  306. $("#alertSuccess").modal("show");
  307. } else {
  308. var cnt = 0;
  309. var count = 0;
  310. for (var key in checkBoxArr) {
  311. cnt = cnt + 1;
  312. }
  313. for (var key in checkBoxArr) {
  314. var hospitalCd = localStorage.getItem("hospitalCd"); // 병원코드
  315. var userId = gLoginUserId; // 사용자 ID
  316. var specimenCd = checkBoxArr[key].specimenCd; // 검체바코드 번호
  317. var specimenNm = checkBoxArr[key].specimenNm; // 검체명
  318. var actSpecimenType = gActSpecimenType; // 검체처리구분(처리 : Y, 취소 : C)
  319. var actSpecimenDtTm = moment(new Date).format("YYYYMMDDHHMM"); // 검체처리일시
  320. var actType = ""; // 처리구분 (POC, EMR)
  321. var checkedItem = $("label[name=checkedItem" + key + "]");
  322. if (checkedItem.hasClass("btn-barcode")) {
  323. actType = "POC";
  324. } else {
  325. actType = "EMR";
  326. }
  327. var param = {
  328. hospitalCd : hospitalCd ,
  329. userId : userId ,
  330. specimenCd : specimenCd ,
  331. specimenNm : specimenNm ,
  332. actSpecimenType : actSpecimenType,
  333. actSpecimenDtTm : actSpecimenDtTm,
  334. actType : "POC" ,
  335. actTypeCheck : actType
  336. };
  337. var result = self.safety.actSpecimen(param);
  338. count = count + 1;
  339. if (result != "") {
  340. if (cnt == count) {
  341. var succMsg = "";
  342. var failMsg = "";
  343. if (result == "failed") {
  344. if (gActSpecimenType == "Y") {
  345. failMsg = "채혈실시에 오류가 발생하였습니다.";
  346. } else {
  347. failMsg = "채혈취소에 오류가 발생하였습니다.";
  348. }
  349. alert(failMsg);
  350. } else {
  351. if (gActSpecimenType == "Y") {
  352. succMsg = "채혈실시가 처리되었습니다.";
  353. } else {
  354. succMsg = "채혈취소가 처리되었습니다.";
  355. }
  356. alert(succMsg);
  357. }
  358. getPocPatientInfo($("#txtBleedingPatientSearch").val(), false);
  359. }
  360. }
  361. }
  362. }
  363. };
  364. var cnt = 0;
  365. var outputAr = [];
  366. var processActSpecimen = function(output, size, key) {
  367. console.log("processActSpecimen -- > " + JSON.stringify(output));
  368. console.log("processActSpecimen -- > " + size);
  369. console.log("processActSpecimen -- > " + key);
  370. var param = {output, key};
  371. outputAr.push(param);
  372. if (size == outputAr.length) {
  373. var errorFlag = false;
  374. for (var i = 0; i < outputAr.length; i++) {
  375. console.log("output[i] -- > " + outputAr[i].output);
  376. if (outputAr[i].output == "0001") {
  377. errorFlag = true;
  378. }
  379. }
  380. var succMsg = "";
  381. var failMsg = "";
  382. if (gActSpecimenType == "Y") {
  383. succMsg = "채혈실시가 처리되었습니다.";
  384. failMsg = "채혈실시에 오류가 발생하였습니다.";
  385. } else {
  386. succMsg = "채혈취소가 처리되었습니다.";
  387. failMsg = "채혈취소에 오류가 발생하였습니다.";
  388. }
  389. if (errorFlag == true) {
  390. alert(failMsg);
  391. } else {
  392. alert(succMsg);
  393. }
  394. outputAr = [];
  395. getPocPatientInfo($("#txtBleedingPatientSearch").val(), false);
  396. }
  397. };
  398. // 버튼 색상 및 글자 초기화
  399. var initButtonSetting = function() {
  400. $("#btnBleedingList").removeClass().addClass("btn btn-secondary btn-block");
  401. $("#btnCancleList").removeClass().addClass("btn btn-secondary btn-block");
  402. $("#btnBleedingAct").removeClass().addClass("btn btn-secondary btn-block");
  403. $("#btnBleedingAct").text("실시/취소");
  404. }
  405. //==== 초기화 설정 } ====
  406. //==== 이벤트 설정 { ====
  407. var addEvent = function() {
  408. eventCondition();
  409. eventBackBlock();
  410. };
  411. //검색 페이지 뒤로가기 막기
  412. var eventBackBlock = function() {
  413. $(window).off("pageshow");
  414. $(window).bind("pageshow", function(event) {
  415. if (event.originalEvent.persisted) {
  416. document.location.reload();
  417. }
  418. });
  419. };
  420. var eventCondition = function() {
  421. // 실시 조회 이벤트 처리
  422. $("#btnBleedingList").off("click");
  423. $("#btnBleedingList").on("click", function() {
  424. $(this).blur();
  425. var searchTxt = $("#txtBleedingPatientSearch").val();
  426. if (searchTxt == "") {
  427. $("#alertEmptyText").modal("show");
  428. } else {
  429. specimenSearchCls = 0;
  430. gActSpecimenType = "Y";
  431. //버튼 색상 변경
  432. $("#btnBleedingList").removeClass().addClass("btn btn-primary btn-block");
  433. $("#btnBleedingAct").removeClass().addClass("btn btn-danger btn-block");
  434. $("#btnCancleList").removeClass().addClass("btn btn-secondary btn-block");
  435. $("#btnBleedingAct").text("채혈 실시");
  436. // initPatientInfo();
  437. getPocPatientInfo(searchTxt, false);
  438. }
  439. });
  440. // 취소 조회 이벤트 처리
  441. $("#btnCancleList").off("click");
  442. $("#btnCancleList").on("click", function() {
  443. $(this).blur();
  444. var searchTxt = $("#txtBleedingPatientSearch").val();
  445. if (searchTxt == "") {
  446. $("#alertEmptyText").modal("show");
  447. } else {
  448. specimenSearchCls = 1;
  449. gActSpecimenType = "C";
  450. //버튼 색상 변경
  451. $("#btnBleedingList").removeClass().addClass("btn btn-secondary btn-block");
  452. $("#btnBleedingAct").removeClass().addClass("btn btn-danger btn-block");
  453. $("#btnCancleList").removeClass().addClass("btn btn-councel btn-block");
  454. $("#btnBleedingAct").text("채혈 취소");
  455. // initPatientInfo();
  456. getPocPatientInfo(searchTxt, false);
  457. }
  458. });
  459. // 실시/취소 버튼
  460. $("#btnBleedingAct").off("click");
  461. $("#btnBleedingAct").on("click", function() {
  462. $(this).blur();
  463. if ($("input:checkbox[class=checkClassBleedingSel]:checked").length <= 0) {
  464. $("#alertEmptySpecimen").modal("show");
  465. } else {
  466. initactSpecimen();
  467. }
  468. });
  469. };
  470. // 바코드 검색
  471. $("#btnBarcodeSearch").off("click");
  472. $("#btnBarcodeSearch").on("click", function() {
  473. $("#txtBleedingNumberSearchTxt").val("");
  474. readBarcode("number");
  475. });
  476. /*
  477. * 체크박스 상태 변경
  478. * 체크박스 체크 선택 시 Background 추가
  479. *
  480. * 바코드 리딩 체크박스 해제시 원래 체크박스 클래스로 바꿔줌
  481. */
  482. var eventMakeCondition = function() {
  483. $("#bleedingListGroup li input").off("click");
  484. $("#bleedingListGroup li input").on("click", function() {
  485. var li = $(this).parent().parent().parent(); // listGroupItem_ + i
  486. var id = li.attr("id");
  487. var rowNo = id.split('_')[1];
  488. var checkBox = $("#checkBleedingSel" + rowNo);
  489. var firstLabel = checkBox.parent().children().children().eq(0);
  490. var secondLabel = checkBox.parent().children().children().eq(1);
  491. if (checkBox.is(":checked") == true) {
  492. li.toggleClass("active");
  493. console.log(checkBox.is(":checked"));
  494. } else {
  495. li.toggleClass("active");
  496. firstLabel.attr("class", "btn btn-check icon");
  497. secondLabel.attr("class", "btn btn-outline-check icon");
  498. }
  499. });
  500. };
  501. }