consentSearch.js 33 KB

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