consentOperation.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /**
  2. * consent/operation
  3. */
  4. var mcare_mobile_consentOperation = function(){
  5. //상속
  6. mplus_mobile_consent.call(this);
  7. //변수
  8. var div = $("<div></div>");
  9. var tr = $("<tr></tr>");
  10. var th = $("<th></th>");
  11. var td = $("<td></td>");
  12. var table = $("<table></table>");
  13. var li = $("<li></li>");
  14. var a = $("<a></a>");
  15. var span = $("<span></span>");
  16. var button = $("<button></button>");
  17. $crudServiceBaseUrl = contextPath + "/mobile/op";
  18. var $btnSearchPatient = $('#btnSearchPatient');
  19. var $btnTotalSearchConsent = $('#btnTotalSearchConsent');
  20. var $btnSearchConsent = $('#btnSearchConsent');
  21. var $sltTreament = $('#sltTreament');
  22. var $dtpSrchdd = $('#dtpSrchdd');
  23. var $sltDoctor = $('#sltDoctor');
  24. var $txtSearchPatient = $('#txtSearchPatient');
  25. var $ulPatientList = $('#ulPatientList');
  26. var $ulAgreementCheck = $("#ulAgreementCheck");
  27. var $ulAgreementList = $("#ulAgreementList");
  28. var $ulConsentList = $("#ulConsentList");
  29. var $ulSetList = $('#ulSetList');
  30. var $tbPatientInfo = $("#tbPatientInfo");
  31. var $dtpConsentStartDt = $('#dtpConsentStartDt');
  32. var $dtpConsentEndDt = $('#dtpConsentEndDt');
  33. var $sltCategory = $('#sltCategory');
  34. var $sltCategoryLower = $('#sltCategoryLower');
  35. var $txtConsentSrch = $('#txtConsentSrch');
  36. var $tabSet = $('#tabSet');
  37. var todayDateStr = '';
  38. var $menuType = 'OP';
  39. var self = this;
  40. patientList = [];
  41. var patientInfo;
  42. var unfinishedConsentList = [];
  43. var agreementList = [];
  44. var setList = [];
  45. var totalConsentList = [];
  46. /**
  47. * 초기화
  48. */
  49. this.init = function(){
  50. formDataInit();
  51. addEvent();
  52. initDropDownList();
  53. initSetList();
  54. if((indexPage=='O'&&(jobKindCd=='1140'||jobKindCd=='1113'))
  55. ||(jobKindCd=='0330'||jobKindCd=='0640')){
  56. $sltTreament.selectpicker('val', deptCd);
  57. if($sltTreament.val()==null) {
  58. $sltTreament.selectpicker('val', '');
  59. }else{
  60. showDoctorList(deptCd);
  61. searchPatientList('Y');
  62. }
  63. };
  64. };
  65. var formDataInit = function(){
  66. // datepicker 초기화
  67. $('.datepicker').datepicker({'format': 'yyyy/mm/dd'});
  68. var today = new Date();
  69. var prevDay = new Date(Date.parse(new Date()) - 7 * 1000 * 60 * 60 * 24); //일주일전!!
  70. todayDateStr = moment(today).format('YYYY/MM/DD');
  71. var prevDayStr = moment(prevDay).format('YYYY/MM/DD');
  72. $("#divDtpSrchdd").datepicker('update', todayDateStr);
  73. $("#divDtpConsentStartDt").datepicker('update', prevDayStr);
  74. $("#divDtpConsentEndDt").datepicker('update', todayDateStr);
  75. };
  76. /**
  77. * 이벤트 등록
  78. */
  79. var addEvent = function(){
  80. $btnSearchPatient.on("click", function(e){
  81. $('span[name^="sort_"]').attr('sortType', '');
  82. searchPatientList('N');
  83. });
  84. $btnTotalSearchConsent.on("click", function(e){
  85. searchTotalConsentList('Y');
  86. });
  87. $btnSearchConsent.on("click", function(e){
  88. searchConsentList();
  89. });
  90. $tabSet.on("click", function(e){
  91. initSetList();
  92. });
  93. $('span[name^="sort_"]').on("click", function(e){
  94. self.loading("show");
  95. setTimeout(function(){
  96. var sortData = e.currentTarget.attributes.name.value.split('_');
  97. var sortKey = sortData[1];
  98. var sortType = sortData[2];
  99. var sortClassName = sortData[3];
  100. var sortOrder = $('span.'+sortClassName+'[name^="sort_"]')[0].attributes.sortType.value;
  101. $('span[name^="sort_"]').attr('sortType', '');
  102. if(sortOrder==undefined || sortOrder=='up'){
  103. sortPatientList(sortKey, sortType, 'down');
  104. $('span.'+sortClassName+'[name^="sort_"]').attr('sortType', 'down');
  105. }else{
  106. sortPatientList(sortKey, sortType, 'up');
  107. $('span.'+sortClassName+'[name^="sort_"]').attr('sortType', 'up');
  108. };
  109. self.loading("hide");
  110. }, 300);
  111. });
  112. };
  113. var initDropDownList = function(){
  114. var param = {ordtype: $menuType};
  115. var result = self.hospital.getDeptList(param);
  116. $sltTreament.empty();
  117. for(var i=0; i<result.length; i++){
  118. var option = $('<option value='+result[i].deptcd+'>'+result[i].deptnm+'</option>');
  119. $sltTreament.append(option);
  120. };
  121. $sltTreament.children(":first").attr("selected", true);
  122. $sltTreament.selectpicker('refresh');
  123. //진료과에 따른 의사조회 이벤트 연결
  124. $sltTreament.change(function() {
  125. showDoctorList(this.value);
  126. });
  127. //카테고리조회
  128. var categoryParam = {
  129. categoryId: '1'
  130. };
  131. var categoryResult = self.consent.getCategoryForDropdown(categoryParam);
  132. $sltCategory.empty();
  133. for(var i=0; i<categoryResult.length; i++){
  134. var option = $('<option value='+categoryResult[i].categoryId+'>'+categoryResult[i].categoryName+'</option>');
  135. $sltCategory.append(option);
  136. };
  137. $sltCategory.children(":first").attr("selected", true);
  138. $sltCategory.selectpicker('refresh');
  139. showCategoryLowerList(categoryResult[0].categoryId);
  140. //진료과에따른 하위 카테고리조회
  141. $sltCategory.change(function() {
  142. showCategoryLowerList(this.value);
  143. });
  144. };
  145. var showCategoryLowerList = function(categoryId){
  146. var param = {
  147. categoryId: categoryId
  148. };
  149. var result = self.consent.getCategoryForDropdown(param);
  150. $sltCategoryLower.empty();
  151. for(var i=0; i<result.length; i++){
  152. var option = $('<option value='+result[i].categoryId+'>'+result[i].categoryName+'</option>');
  153. $sltCategoryLower.append(option);
  154. };
  155. $sltCategoryLower.children(":first").attr("selected", true);
  156. $sltCategoryLower.selectpicker('refresh');
  157. };
  158. //진료과에 따른 의사조회
  159. var showDoctorList = function(doctorid){
  160. var param = {srchdd: $dtpSrchdd[0].value.replace(/\//g,''), orddeptcd: doctorid};
  161. var result = self.hospital.getDoctorList(param);
  162. $sltDoctor.empty();
  163. for(var i=0; i<result.length; i++){
  164. var option = $('<option value='+result[i].doctorid+'>'+result[i].doctornm+'</option>');
  165. $sltDoctor.append(option);
  166. };
  167. $sltDoctor.children(":first").attr("selected", true);
  168. $sltDoctor.selectpicker('refresh');
  169. };
  170. //환자리스트 조회
  171. var searchPatientList = function(firstYn){
  172. initPatientInfo();
  173. var selectedPatstat = $(":input:radio[name=searchRadio]:checked").val();
  174. var param = { srchdd: $dtpSrchdd[0].value.replace(/\//g,''),
  175. orddeptcd: $sltTreament.val(),
  176. doctorid: $sltDoctor.val(),
  177. pid: $txtSearchPatient.val(),
  178. patstat: selectedPatstat
  179. };
  180. self.patient.getPatientList($menuType, param, firstYn);
  181. };
  182. //환자리스트 정렬
  183. var sortPatientList = function(sortKey, sortType, order){
  184. self.patient.setPatientList($menuType, patientList, sortKey, sortType, order);
  185. };
  186. var initPatientInfo = function(){
  187. $ulAgreementList.empty();
  188. patientInfo = {};
  189. $("#tbPatientInfo").empty();
  190. unfinishedConsentList = [];
  191. $ulAgreementCheck.empty();
  192. $("#consentTap1 .sub-title").empty();
  193. };
  194. // 환자정보 조회
  195. getPatientInfo = function(seq){
  196. initPatientInfo();
  197. var param = { pid: patientList[seq].pid,
  198. orddd: patientList[seq].indd.replace(/\//g,''),
  199. ordtype: patientList[seq].ordtype,
  200. orddeptcd: patientList[seq].orddeptcd
  201. };
  202. var result = self.hospital.getPatientInfo(param);
  203. // target 환자 정보를 보관해 둔다
  204. patientInfo = result[0];
  205. if( patientInfo == undefined ) {return;};
  206. $("#divDtpConsentStartDt").datepicker('update', moment(patientInfo.ioaddate).format('YYYY/MM/DD'));
  207. $("#consentTap1 .sub-title").text(patientInfo.ioptID+" " + patientInfo.ioptName+" "+ editAgeToIdNum(patientInfo.iosexAgeYM) + "/"+patientInfo.iojuminNo.split('-')[0]);
  208. for(var i=0; i<result.length; i++){
  209. var trData = tr.clone().html(th.clone().text("입원일")).append(td.clone().text(moment(result[i].ioaddate).format('YYYY/MM/DD')));
  210. var trData2 = tr.clone().html(th.clone().text("집도의")).append(td.clone().text(result[i].ioopdrNm));
  211. var trData3 = tr.clone().html(th.clone().text("진단명")).append(td.clone().text(result[i].iodxNm));
  212. var tdData = td.clone();
  213. var trData4 = tr.clone().addClass("infoalert").html(th.clone().text("Alert")).append(tdData);
  214. var tableData = table.clone().addClass("patientData").html(trData).append(trData2).append(trData3).append(trData4);
  215. $tbPatientInfo.append(tableData);
  216. };
  217. // 미작성동의서 조회
  218. getUnfinishedConsentInfo(patientList[seq]);
  219. }
  220. var getUnfinishedConsentInfo = function(data){
  221. var consentParam = {
  222. patientCode: data.pid,
  223. startDt: patientInfo.ioaddate,
  224. endDt: moment(todayDateStr).format('YYYYMMDD'),
  225. consentState: "'UNFINISHED', 'TEMP'",
  226. jobKindCd: indexPage=='O'&&(jobKindCd=='1140'||jobKindCd=='1113')? 'ALL': jobKindCd
  227. };
  228. var consentResult = self.consent.getConsentList(consentParam);
  229. unfinishedConsentList = consentResult;
  230. //미작성동의서 리스트 바인딩
  231. var divCheckbox = div.clone().addClass("checkbox3 checkbox-check checkbox-light");
  232. $ulAgreementCheck.empty();
  233. for(var i=0; i<consentResult.length; i++){
  234. $ulAgreementCheck.append(
  235. li.clone().html(
  236. divCheckbox.clone().html($("<input type='checkbox' id='chkConsentUnfinished_"+(i+1)+"'></input>"))
  237. .append($("<label for='chkConsentUnfinished_"+(i+1)+"'></label>"))
  238. .append(span.clone().addClass("detail").text(consentResult[i].consentName))
  239. .append(span.clone().addClass("label "+
  240. (consentResult[i].consentState=='TEMP'? "label-temp":
  241. consentResult[i].consentState=='UNFINISHED'? "label-unfinished":
  242. consentResult[i].consentState=='ELECTR_CMP'? "label-electrCmp":
  243. consentResult[i].consentState=='CERTIFY_CMP'? "label-certifyCmp":
  244. consentResult[i].consentState=='PAPER_OUT'? "label-paperOut":
  245. consentResult[i].consentState=='VERBAL'? "label-verbal":"label-default")
  246. ).text(consentResult[i].consentStateDisp))
  247. .append(button.clone().addClass("text-right btn btn-default")
  248. .text("삭제").attr("seq", i))
  249. )
  250. )
  251. };
  252. $('#ulAgreementCheck li').on("click", function(e){
  253. if(e.toElement.localName == "label") { //체크박스클릭
  254. var input = $(this).children().children("input");
  255. $(input).prop("checked", !$(input).prop("checked"));
  256. if($(input).prop("checked")) {
  257. $(this).addClass('checked')
  258. }else {
  259. $(this).removeClass('checked')
  260. };
  261. }else if(e.toElement.localName == "button"){ //버튼클릭
  262. }else{ //동의서 내용 클릭
  263. if(!$(this).hasClass("checked")){
  264. var input = $(this).children().children("input");
  265. $(input).prop("checked", true);
  266. $(this).addClass('checked');
  267. };
  268. //선택한 동의서만 가지고오기
  269. var selectedItems = $('#ulAgreementCheck li[class="checked"] input');
  270. var selectedConsentList = [];
  271. var printOnlyList = [];
  272. for( var i = 0; i < selectedItems.length; i++ ){
  273. // sequence 추출
  274. var seq = selectedItems[i].id.split('_')[1];
  275. seq = seq - 1;
  276. // 동의서 상태 체크
  277. var param = {consentmstrid: unfinishedConsentList[seq].consentMstRid,
  278. consentState: unfinishedConsentList[seq].consentState};
  279. var state = self.consent.checkConsentState(param);
  280. if( state == undefined ) { printOnlyList.push("["+unfinishedConsentList[seq].consentName+"] - 상태 조회 실패"); }
  281. else if (state.text == '-1') { printOnlyList.push("["+unfinishedConsentList[seq].consentName+"] - 상태 조회 실패"); }
  282. else if (state.text == '1') { printOnlyList.push("["+unfinishedConsentList[seq].consentName+"] - 이미 작성된 동의서"); }
  283. else if (state.text == '0'){
  284. selectedConsentList.push(unfinishedConsentList[seq]);
  285. }
  286. }
  287. var printOnlyAlertMsg = '';
  288. for(var j=0; j<printOnlyList.length; j++){
  289. printOnlyAlertMsg = printOnlyAlertMsg + printOnlyList[j];
  290. if(j!=printOnlyList.length-1) printOnlyAlertMsg = printOnlyAlertMsg +"\n";
  291. };
  292. if(printOnlyAlertMsg.length>0) {
  293. self.confirm("작성이 불가능한 동의서입니다.\n\n" + printOnlyAlertMsg, function(confirm){
  294. if(confirm){
  295. var global = self.consent.makeGlobalParam(patientInfo, loginUserId);
  296. var consent = self.consent.makeConsentParam(patientInfo, selectedConsentList, loginUserName);
  297. var jsonssg = {
  298. "type" : "command",
  299. "functionType" : "consent",
  300. "value" : {
  301. "callbackFn" : "window.activeObj.consentCallback"
  302. },
  303. "userId": loginUserId,
  304. "globalParam" : global,
  305. "consentParam" : consent
  306. };
  307. self.toNative(jsonssg);
  308. }
  309. });
  310. }else{
  311. if(selectedConsentList.length > 0){
  312. var global = self.consent.makeGlobalParam(patientInfo, loginUserId);
  313. var consent = self.consent.makeConsentParam(patientInfo, selectedConsentList, loginUserName);
  314. var jsonssg = {
  315. "type" : "command",
  316. "functionType" : "consent",
  317. "value" : {
  318. "callbackFn" : "window.activeObj.consentCallback"
  319. },
  320. "userId" : loginUserId,
  321. "globalParam" : global,
  322. "consentParam" : consent
  323. };
  324. self.toNative(jsonssg);
  325. };
  326. };
  327. };
  328. e.stopPropagation();
  329. e.preventDefault();
  330. });
  331. $('#ulAgreementCheck li button').on("click", function(e){
  332. self.confirm("삭제하시겠습니까?", function(confirm){
  333. if(confirm){
  334. $('#txtSeq').val(e.currentTarget.attributes.seq.value);
  335. $('#mplusConsentDeleteForm').modal('show');
  336. $('#btnConsentDelete').unbind();
  337. $('#btnConsentDelete').on('click', function(){
  338. var checkVal = $('#mplusConsentDeleteForm input[name=consentDeleteRadio]:checked').val();
  339. var deleteReasonText = $('#consentDeleteTextarea').val();
  340. deleteConsent($('#txtSeq').val(),
  341. checkVal=="slt4"? deleteReasonText: $('#mplusConsentDeleteForm input[name=consentDeleteRadio]:checked')[0].attributes.dataReason.value);
  342. });
  343. }
  344. });
  345. });
  346. };
  347. //동의서 조회
  348. var searchTotalConsentList = function(alertYn){
  349. $ulAgreementList.empty();
  350. if($('#ulPatientList .list-group-item.active')[0]==undefined){
  351. self.alert('조회할 환자를 선택해주세요.');
  352. return;
  353. };
  354. if( patientInfo == undefined ){
  355. self.alert('환자 정보가 정상 조회되지 않았습니다.');
  356. return;
  357. };
  358. var seq = $('#ulPatientList .list-group-item.active')[0].attributes.seq.value;
  359. var state = self.consent.makeConsentStateParam();
  360. if(state==undefined) return;
  361. var param = { patientCode: patientList[seq].pid,
  362. startDt: $dtpConsentStartDt[0].value.replace(/\//g,''),
  363. endDt: $dtpConsentEndDt[0].value.replace(/\//g,''),
  364. consentState: state,
  365. jobKindCd: indexPage=='O'&&(jobKindCd=='1140'||jobKindCd=='1113')? 'ALL': jobKindCd
  366. };
  367. var result = self.consent.getConsentList(param);
  368. // 오른쪽 동의서 리스트 보관
  369. agreementList = result;
  370. if(alertYn=='Y'&&(result==undefined||result.length==0)) {
  371. self.alert('조회된 데이터가 없습니다.');
  372. return;
  373. }else if(alertYn=='N'&&(result==undefined||result.length==0)){return;};
  374. //동의서 조회 리스트 바인딩
  375. var divCheckbox = div.clone().addClass("checkbox3 checkbox-check checkbox-light");
  376. for(var i=0; i<result.length; i++){
  377. $ulAgreementList.addClass("agreementCheck").append(
  378. li.clone().html(
  379. divCheckbox.clone().html($("<input type='checkbox' id='chkConsentPatient_"+(i+1)+"'></input>"))
  380. .append($("<label for='chkConsentPatient_"+(i+1)+"'></label>"))
  381. .append(span.clone().addClass("document").text(result[i].consentName)
  382. .append(span.clone().addClass("label "+
  383. (result[i].consentState=='TEMP'? "label-temp":
  384. result[i].consentState=='UNFINISHED'? "label-unfinished":
  385. result[i].consentState=='ELECTR_CMP'? "label-electrCmp":
  386. result[i].consentState=='CERTIFY_CMP'? "label-certifyCmp":
  387. result[i].consentState=='PAPER_OUT'? "label-paperOut":
  388. result[i].consentState=='VERBAL'? "label-verbal":"label-default")
  389. ).text(result[i].consentStateDisp))
  390. )
  391. ));
  392. };
  393. $('#ulAgreementList li').on("click", function(e){
  394. // 체크박스 클릭했을 때
  395. if(e.toElement.localName == "label") {
  396. var input = $(this).children().children("input");
  397. $(input).prop("checked", !$(input).prop("checked"));
  398. if($(input).prop("checked")) $(this).addClass('checked')
  399. else $(this).removeClass('checked')
  400. }else{
  401. // 동의서 내용을 클릭했을 때
  402. if(!$(this).hasClass("checked")){
  403. var input = $(this).children().children("input");
  404. $(input).prop("checked", true);
  405. $(this).addClass('checked');
  406. };
  407. var selectedSeq = $(this).children().children("input").attr('id').split('_')[1];
  408. var lastSelectedItem = agreementList[selectedSeq - 1];
  409. // 클릭한 동의서의 상태 체크
  410. // 환자서명이거나 전자인증의 경우 모두 체크해제 하고, 해당 동의서의 이미지를 띄움
  411. if( lastSelectedItem.consentState == 'ELECTR_CMP' || lastSelectedItem.consentState == 'CERTIFY_CMP' ) {
  412. // 체크해제
  413. $('#ulAgreementList li[class="checked"] input').prop("checked", false);
  414. $('#ulAgreementList li[class="checked"]').removeClass("checked");
  415. var param = {consentMstRid : lastSelectedItem.consentMstRid};
  416. var consentImageList = self.consent.getConsentImage(param);
  417. if(consentImageList == undefined || consentImageList.length==0) {
  418. self.alert("동의서 이미지 조회 실패");
  419. return;
  420. };
  421. var imagePathList = [];
  422. $('#consentImgBox').empty();
  423. for( var i = 0; i < consentImageList.length; i++ ) {
  424. $('#consentImgBox').append(
  425. div.clone().append(
  426. "<img data-u='image' src='"+consentImageList[i].imagePath+"' width='100%'>"
  427. )
  428. )
  429. }
  430. $('.modal-backdrop').removeClass('in');
  431. $('.modal').modal('hide');
  432. $('#mplusConsentImageForm').modal("show");
  433. };
  434. //선택한 동의서만 가지고오기
  435. var selectedItems = $('#ulAgreementList li[class="checked"] input');
  436. var selectedConsentList = [];
  437. var printOnlyList = [];
  438. for( var i = 0; i < selectedItems.length; i++ ){
  439. // sequence 추출
  440. var seq = selectedItems[i].id.split('_')[1];
  441. seq = seq - 1;
  442. // data add
  443. if(agreementList[seq].consentState=="PAPER_OUT" || agreementList[seq].consentState=="FNU_PRINT"){
  444. //동의서 상태가 출력/FNU출력인 경우 걸러내기
  445. printOnlyList.push("["+agreementList[seq].consentName+"] - "+agreementList[seq].consentStateDisp);
  446. }else{
  447. // 동의서 상태 체크
  448. var param = {consentmstrid: agreementList[seq].consentMstRid,
  449. consentState: agreementList[seq].consentState};
  450. var state = self.consent.checkConsentState(param);
  451. if( state == undefined ) { printOnlyList.push("["+agreementList[seq].consentName+"] - 상태 조회 실패"); }
  452. else if (state.text == '-1') { printOnlyList.push("["+agreementList[seq].consentName+"] - 상태 조회 실패"); }
  453. else if (state.text == '1') { printOnlyList.push("["+agreementList[seq].consentName+"] - 이미 작성된 동의서"); }
  454. else if (state.text == '0'){
  455. selectedConsentList.push(agreementList[seq]);
  456. }
  457. };
  458. }
  459. var printOnlyAlertMsg = '';
  460. for(var j=0; j<printOnlyList.length; j++){
  461. printOnlyAlertMsg = printOnlyAlertMsg +printOnlyList[j];
  462. if(j!=printOnlyList.length-1) printOnlyAlertMsg = printOnlyAlertMsg +"\n";
  463. };
  464. if(printOnlyAlertMsg.length>0) {
  465. self.confirm("출력전용 및 작성이 불가능한 동의서입니다.\n\n" + printOnlyAlertMsg, function(confirm){
  466. if(confirm){
  467. if(selectedConsentList.length > 0){
  468. var global = self.consent.makeGlobalParam(patientInfo, loginUserId);
  469. var consent = self.consent.makeConsentParam(patientInfo, selectedConsentList, loginUserName);
  470. // 유효성 검사 추가할 것
  471. var jsonssg = {
  472. "type" : "command",
  473. "functionType" : "consent",
  474. "value" : {
  475. "callbackFn" : "window.activeObj.consentCallback"
  476. },
  477. "userId" : loginUserId,
  478. "globalParam" : global,
  479. "consentParam" : consent
  480. };
  481. self.toNative(jsonssg);
  482. };
  483. }
  484. });
  485. }else{
  486. if(selectedConsentList.length > 0){
  487. var global = self.consent.makeGlobalParam(patientInfo, loginUserId);
  488. var consent = self.consent.makeConsentParam(patientInfo, selectedConsentList, loginUserName);
  489. var jsonssg = {
  490. "type" : "command",
  491. "functionType" : "consent",
  492. "value" : {
  493. "callbackFn" : "window.activeObj.consentCallback"
  494. },
  495. "userId" : loginUserId,
  496. "globalParam" : global,
  497. "consentParam" : consent
  498. };
  499. self.toNative(jsonssg);
  500. };
  501. };
  502. };
  503. e.stopPropagation();
  504. e.preventDefault();
  505. });
  506. };
  507. //즐겨찾기리스트 조회
  508. var initSetList = function(){
  509. $ulSetList.empty();
  510. var param = {};
  511. var result = self.consent.getConsentSetList(param);
  512. setList = result;
  513. var divCheckbox = div.clone().addClass("checkbox3 checkbox-check checkbox-light");
  514. for(var i=0; i<result.length; i++){
  515. $ulSetList.addClass("agreementCheck").append(
  516. li.clone().html(
  517. divCheckbox.clone().html($("<input type='checkbox' id='chkSetList_"+(i+1)+"'></input>"))
  518. .append($("<label for='chkSetList_"+(i+1)+"'></label>"))
  519. .append(span.clone().addClass("document").text(result[i].formName))
  520. .append(button.clone().addClass("text-right btn btn-default")
  521. .text("삭제").attr("formCd", result[i].formCd))
  522. ));
  523. };
  524. $('#ulSetList li').on("click", function(e){
  525. if(e.toElement.localName == "label") { //체크박스 클릭
  526. var input = $(this).children().children("input");
  527. $(input).prop("checked", !$(input).prop("checked"));
  528. if($(input).prop("checked")) $(this).addClass('checked')
  529. else $(this).removeClass('checked')
  530. }else if(e.toElement.localName == "button"){ //버튼클릭
  531. }else{ //동의서 내용 클릭
  532. if(!$(this).hasClass("checked")){
  533. var input = $(this).children().children("input");
  534. $(input).prop("checked", true);
  535. $(this).addClass('checked');
  536. };
  537. if($('#ulPatientList .list-group-item.active').parent()[0]==undefined){
  538. self.alert('환자를 선택해주세요.');
  539. return;
  540. };
  541. //선택한 동의서만 가지고오기
  542. var selectedItems = $('#ulSetList li[class="checked"] input');
  543. var selectedConsentList = [];
  544. var printOnlyList = [];
  545. for( var i = 0; i < selectedItems.length; i++ ){
  546. // sequence 추출
  547. var seq = selectedItems[i].id.split('_')[1];
  548. seq = seq - 1;
  549. if(setList[seq].printOnly=="Y"){
  550. printOnlyList.push(setList[seq].formName);
  551. }else{
  552. //data add
  553. selectedConsentList.push(setList[seq]);
  554. };
  555. };
  556. var printOnlyAlertMsg = '';
  557. for(var j=0; j<printOnlyList.length; j++){
  558. printOnlyAlertMsg = printOnlyAlertMsg +"["+printOnlyList[j]+"]";
  559. if(j!=printOnlyList.length-1) printOnlyAlertMsg = printOnlyAlertMsg +"\n";
  560. };
  561. if(printOnlyAlertMsg.length>0) {
  562. self.confirm(printOnlyAlertMsg+"\n출력전용 동의서 입니다. \nPC에서 출력하세요.", function(confirm){
  563. if(confirm){
  564. if(selectedConsentList.length > 0){
  565. var global = self.consent.makeGlobalParam(patientInfo, loginUserId);
  566. var consent = self.consent.makeNewConsentParam(patientInfo, selectedConsentList, loginUserName);
  567. // 유효성 검사 추가할 것
  568. var jsonssg = {
  569. "type" : "command",
  570. "functionType" : "consent",
  571. "value" : {
  572. "callbackFn" : "window.activeObj.consentCallback"
  573. },
  574. "userId": loginUserId,
  575. "globalParam" : global,
  576. "consentParam" : consent
  577. };
  578. self.toNative(jsonssg);
  579. };
  580. }
  581. });
  582. }else{
  583. if(selectedConsentList.length > 0){
  584. var global = self.consent.makeGlobalParam(patientInfo, loginUserId);
  585. var consent = self.consent.makeNewConsentParam(patientInfo, selectedConsentList, loginUserName);
  586. // 유효성 검사 추가할 것
  587. var jsonssg = {
  588. "type" : "command",
  589. "functionType" : "consent",
  590. "value" : {
  591. "callbackFn" : "window.activeObj.consentCallback"
  592. },
  593. "userId": loginUserId,
  594. "globalParam" : global,
  595. "consentParam" : consent
  596. };
  597. self.toNative(jsonssg);
  598. };
  599. };
  600. };
  601. e.stopPropagation();
  602. e.preventDefault();
  603. });
  604. $('#ulSetList li button').on("click", function(e){
  605. delUserFormSetList(e);
  606. });
  607. };
  608. //동의서 검색
  609. var searchConsentList = function(){
  610. var param = {
  611. categoryId: $sltCategoryLower.val(),
  612. keyWord: $txtConsentSrch.val()
  613. };
  614. var result = self.consent.getConsentBySearch(param);
  615. // 오른쪽 동의서 리스트 보관
  616. totalConsentList = result;
  617. $ulConsentList.empty();
  618. if(result==undefined||result.length==0) {
  619. self.alert('조회된 데이터가 없습니다.');
  620. return;
  621. };
  622. //동의서 조회 리스트 바인딩
  623. var divCheckbox = div.clone().addClass("checkbox3 checkbox-check checkbox-light");
  624. for(var i=0; i<result.length; i++){
  625. $ulConsentList.addClass("agreementCheck").append(
  626. li.clone().html(
  627. divCheckbox.clone().html($("<input type='checkbox' id='chkConsentSearch_"+(i+1)+"'></input>"))
  628. .append($("<label for='chkConsentSearch_"+(i+1)+"'></label>"))
  629. .append(span.clone().addClass("document").text(result[i].formName)
  630. )
  631. .append(button.clone().addClass("text-right btn btn-default")
  632. .text("추가").attr("formCd", result[i].formCd))
  633. ));
  634. };
  635. $('#ulConsentList li').on("click", function(e){
  636. if(e.toElement.localName == "label") { //체크박스클릭
  637. var input = $(this).children().children("input");
  638. $(input).prop("checked", !$(input).prop("checked"));
  639. if($(input).prop("checked")) {
  640. $(this).addClass('checked')
  641. } else {
  642. $(this).removeClass('checked')
  643. };
  644. }else if(e.toElement.localName == "button"){ //버튼클릭
  645. }else{
  646. if(!$(this).hasClass("checked")){
  647. var input = $(this).children().children("input");
  648. $(input).prop("checked", true);
  649. $(this).addClass('checked');
  650. };
  651. if($('#ulPatientList .list-group-item.active').parent()[0]==undefined){
  652. self.alert('환자를 선택해주세요.');
  653. return;
  654. };
  655. //선택한 동의서만 가지고오기
  656. var selectedItems = $('#ulConsentList li[class="checked"] input');
  657. var selectedConsentList = [];
  658. var printOnlyList = [];
  659. for( var i = 0; i < selectedItems.length; i++ ){
  660. // sequence 추출
  661. var seq = selectedItems[i].id.split('_')[1];
  662. seq = seq - 1;
  663. if(totalConsentList[seq].prntOnly=="Y"){
  664. printOnlyList.push(totalConsentList[seq].formName);
  665. }else{
  666. //data add
  667. selectedConsentList.push(totalConsentList[seq]);
  668. };
  669. };
  670. var printOnlyAlertMsg = '';
  671. for(var j=0; j<printOnlyList.length; j++){
  672. printOnlyAlertMsg = printOnlyAlertMsg +"["+printOnlyList[j]+"]";
  673. if(j!=printOnlyList.length-1) printOnlyAlertMsg = printOnlyAlertMsg +"\n";
  674. };
  675. if(printOnlyAlertMsg.length>0) {
  676. self.confirm(printOnlyAlertMsg+"\n출력전용 동의서 입니다. \nPC에서 출력하세요.", function(confirm){
  677. if(confirm){
  678. if(selectedConsentList.length > 0){
  679. var global = self.consent.makeGlobalParam(patientInfo, loginUserId);
  680. var consent = self.consent.makeNewConsentParam(patientInfo, selectedConsentList, loginUserName);
  681. // 유효성 검사 추가할 것
  682. var jsonssg = {
  683. "type" : "command",
  684. "functionType" : "consent",
  685. "value" : {
  686. "callbackFn" : "window.activeObj.consentCallback"
  687. },
  688. "userId": loginUserId,
  689. "globalParam" : global,
  690. "consentParam" : consent
  691. };
  692. self.toNative(jsonssg);
  693. };
  694. }
  695. });
  696. }else{
  697. if(selectedConsentList.length > 0){
  698. var global = self.consent.makeGlobalParam(patientInfo, loginUserId);
  699. var consent = self.consent.makeNewConsentParam(patientInfo, selectedConsentList, loginUserName);
  700. // 유효성 검사 추가할 것
  701. var jsonssg = {
  702. "type" : "command",
  703. "functionType" : "consent",
  704. "value" : {
  705. "callbackFn" : "window.activeObj.consentCallback"
  706. },
  707. "userId": loginUserId,
  708. "globalParam" : global,
  709. "consentParam" : consent
  710. };
  711. self.toNative(jsonssg);
  712. };
  713. };
  714. };
  715. e.stopPropagation();
  716. e.preventDefault();
  717. });
  718. $('#ulConsentList li button').on("click", function(e){
  719. setUserFormSetList(e);
  720. });
  721. }
  722. //즐겨찾기 삭제
  723. var delUserFormSetList = function(e){
  724. self.confirm("삭제하시겠습니까?", function(confirm){
  725. if(confirm){
  726. var result = self.consent.delUserFormSetList({"formcd": e.currentTarget.attributes.formCd.value});
  727. if(result.formcd!=null){
  728. initSetList();
  729. /*self.alert("삭제되었습니다.");*///16.11.12 고객사요청으로 제거
  730. }else{
  731. self.alert("실패했습니다.");
  732. }
  733. };
  734. })
  735. }
  736. //즐겨찾기 추가
  737. var setUserFormSetList = function(e){
  738. self.confirm("즐겨찾기로 추가하시겠습니까?", function(confirm){
  739. if(confirm){
  740. var result = self.consent.setUserFormSetList({"formcd": e.currentTarget.attributes.formCd.value});
  741. if(result.formcd!=null){
  742. /*self.alert("추가되었습니다.");*///16.11.12 고객사요청으로 제거
  743. }else{
  744. self.alert("실패했습니다.");
  745. }
  746. };
  747. })
  748. }
  749. //동의서 삭제
  750. var deleteConsent = function(seq, reason){
  751. $("#mplusConsentDeleteForm").modal("hide");
  752. var delConsentInfo = unfinishedConsentList[seq];
  753. var delConsentParam = { "consentMstRid": delConsentInfo.consentMstRid,
  754. "patientCode": delConsentInfo.patientCode,
  755. "clnDeptCode": delConsentInfo.clnDeptCd,
  756. "ward": delConsentInfo.ward==null? "": delConsentInfo.ward,
  757. "roomcd": delConsentInfo.roomCd==null? "": delConsentInfo.roomCd,
  758. "formRid": delConsentInfo.formRid==null? "":delConsentInfo.formRid,
  759. "consentState": delConsentInfo.consentState==null? "":delConsentInfo.consentState,
  760. "reasonForUseN": reason
  761. }
  762. var result = self.consent.delConsent(delConsentParam);
  763. if(result.text==delConsentInfo.consentMstRid){
  764. /*self.alert("삭제되었습니다.");*///16.11.12 고객사요청으로 제거
  765. getUnfinishedConsentInfo(patientList[$('#ulPatientList li a.active')[0].attributes.seq.value]);
  766. }else{
  767. self.alert("실패했습니다.");
  768. }
  769. }
  770. // 단말기에서 호출할 콜백
  771. this.consentCallback = function(data) {
  772. //self.alert(data);
  773. // 미작성 동의서 리프레쉬
  774. getUnfinishedConsentInfo(patientList[$('#ulPatientList li a.active')[0].attributes.seq.value]);
  775. // 오른쪽 동의서 리스트 리프레쉬
  776. // 동의서 리스트가 오픈되어있을 떄만 해야하나?
  777. searchTotalConsentList('N');
  778. }
  779. };