consentEmergency.js 31 KB

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