ENRSignEngine.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. /**
  2. 제작일 : 2007-10-04 3:30오후
  3. 제작자 : 현대정보기술 의료기술팀, 꿈꾸는 프로그래머 이제관 (je2kwan2@naver.com)
  4. 설명 : 간호인증 공통 모듈 (version TF4 Default)
  5. */
  6. var Sign = new ENRSign;
  7. Sign.init();
  8. //
  9. function ENRSign(){
  10. this.version = "TF4"; // CMC Framework based on TrustForm 4.0 RAD Tool
  11. this.certreload = false;
  12. this.debug = false;
  13. this.kmi_name = "";
  14. this.smm_name = "";
  15. this.kmi_ip = "";
  16. this.kmi_port = "";
  17. this.CERT_YEAR = 1970;
  18. this.CERT_MONTH = 1;
  19. this.CERT_DATE = 1;
  20. this.CERT_UID = "";
  21. this.CERT_DN = "";
  22. this.errmsg = "[전자서명 에러]";
  23. this.errcode = new Array;
  24. this.xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
  25. this.xmlDoc.async = false;
  26. this.xmlDoc.resolveExternals = false;
  27. this.certchkflag = "Y";
  28. this.tempstr = "";
  29. this.signedInfos = new Array; // 외부용
  30. this.signData = ""; // 내부용
  31. this.signedData = ""; // 내부용
  32. this.emptyattname = "xml:"; // XML Text 변환시 Attribute 빈값에 대한 prefix name
  33. this.nulldatastring = "-"; // Topinfo 및 Session 데이터가 null 일때 인증데이터에 표기할 String
  34. this.XPATH_MAINNODE = "/root/main";
  35. this.XPATH_SIGNBASE = "/root/temp/SignData";
  36. this.XPATH_BASICINFO = this.XPATH_SIGNBASE + "/PatientInfo";
  37. this.XPATH_SIGNINFO = this.XPATH_SIGNBASE + "/SignInfo";
  38. this.XPATH_SESSIONINFO = this.XPATH_SIGNBASE + "/SessionInfo";
  39. // Sign KMI Communication & Verify Function
  40. this.init = enrfSign_Init;
  41. this.tfcheck = enrfSign_Check;
  42. this.chk_mm = enrfSign_ActiveXCheck;
  43. this.loadkeyandcert = enrfSign_LoadKeyAndCert;
  44. this.certcheck = enrfSign_CertCheck;
  45. this.makesigndata = enrfSign_MakeSignData;
  46. this.verifysign = enrfSign_VerifySign;
  47. // ENR Sign Create Funtion
  48. this.findnode = enrfSign_FindNode;
  49. this.makenode = enrfSign_MakeNode;
  50. this.setattnode = enrfSign_SetAttNode;
  51. this.getcommoninfo = enrfSign_GetCommonInfo;
  52. this.settaginfos = enrfSign_SetTagInfos;
  53. this.setsigninstance = enrfSign_SetSignInstance;
  54. this.removenochild = enrfSign_RemoveNoChild;
  55. this.makemainattnode = enrfSign_MakeMainAttNode;
  56. this.makeuserattnode = enrfSign_MakeUserAttNode;
  57. this.addnode = enrfSign_AddCopyNode;
  58. this.getsigndatatostr = enrfSign_GetSignDataToStr;
  59. this.getsigndataArray = enrfSign_GetSignDataArray;
  60. this.getnodenamestrvalue = enrfSign_GetNodeNameStrValue;
  61. this.signprocess = enrfSign_SignProcess; // core
  62. this.view_signprocess = enrfSign_ViewSignProcess; // core
  63. }
  64. //
  65. function enrfSign_Check(){
  66. var m_check = false;
  67. if (this.version == "TF4"){
  68. this.smm_name = "SKCOMMAX.SKCommAXCtrl.1"; // SKCommAX 객체 설치 여부 확인
  69. this.kmi_name = "KMCLIENTAX.KMClientAXCtrl.1"; // KMI 모듈 설치 여부확인
  70. this.kmi_ip = getUserInfo( "kmiip" );
  71. this.kmi_port = parseInt(getUserInfo( "kmiport" ));
  72. this.CERT_UID = getUserId();
  73. //2009-11-05 오후 1:28:31 taebum 확산병원 공통 계정 사용으로 주석처리 함.
  74. //if(this.CERT_UID == "ENR"){
  75. // this.CERT_UID = "00000001";
  76. //}
  77. m_check = true;
  78. }
  79. return m_check;
  80. }
  81. //
  82. function enrfSign_ActiveXCheck(pModule_name){
  83. var m_ClientAX;
  84. try {
  85. m_ClientAX = new ActiveXObject(pModule_name);
  86. }
  87. catch( ex ) {
  88. m_ClientAX = null;
  89. }
  90. return m_ClientAX;
  91. }
  92. //
  93. function enrfSign_Init(){
  94. var m_return = true;
  95. if (this.tfcheck()){
  96. // zesfInitSign
  97. body.createChild("xforms:object", "id:KMClientAX; clsid:{d3c608b5-b664-4962-91b7-289da892953a}; visibility:hidden; left:0px; top:0px; width:0px; height:0px; ");
  98. body.createChild("xforms:object", "id:CertManX; clsid:{ec5d5118-9fde-4a3e-84f3-c2b711740e70}; visibility:hidden; left:0px; top:0px; width:0px; height:0px; ");
  99. if((this.chk_mm(this.kmi_name) == null) || (this.chk_mm(this.kmi_name) == null)) {
  100. messageBox( "KMI / 전자서명 모듈이 설치되지", "E007" );
  101. m_return = false;
  102. }
  103. }
  104. return m_return;
  105. }
  106. // 인증서 Reload 여부 점검 Process
  107. function enrfSign_CertCheck(pUid, pReload){
  108. var dn = "";
  109. var msg = "";
  110. var m_return = "";
  111. var today = new Date();
  112. var m_Reload = false;
  113. this.errcode[3] = 362;
  114. if (pUid == null && pUid == "") pUid = getUserId();
  115. if (pReload == true) m_Reload = true;
  116. if (this.CERT_UID != pUid) m_Reload = true;
  117. if (this.CERT_YEAR != today.getFullYear()) m_Reload = true;
  118. if (this.CERT_MONTH != today.getMonth() + 1) m_Reload = true;
  119. if (this.CERT_DATE != today.getDate()) m_Reload = true;
  120. this.errcode[3] = 363;
  121. if (this.version == "TF4"){
  122. if (m_Reload) {
  123. this.errcode[3] = 364;
  124. CertManX.UnsetMatchedContext();
  125. this.errcode[3] = 365;
  126. dn = this.loadkeyandcert(pUid);
  127. this.CERT_DN = dn;
  128. } else {
  129. dn = this.CERT_DN;
  130. }
  131. }
  132. return dn;
  133. }
  134. //
  135. function enrfSign_LoadKeyAndCert(pUid) {
  136. var dn = "";
  137. var msg = "";
  138. var xpt = window.screenLeft + 400;
  139. var ypt = window.screenTop + 60;
  140. var pwd = "";
  141. var viewerObj = getViewer("sysMessage");
  142. var certloadyn = "N";
  143. certloadyn = viewerObj.window.model.getValue("/root/properties/orderbasicinfo/hardcdlist/hardcd[hardcdno = '5996']/hardcd");
  144. if ( certloadyn == "Y" ) {
  145. //이윤주 수정(20150415)
  146. viewerObj.window.model.removeNodeset("/root/main/pwdhidden");
  147. modal("SPZMS00300",xpt,ypt);
  148. pwd = viewerObj.window.model.getValue("/root/main/pwdhidden/pwd");
  149. if (pwd == null || pwd == "") {
  150. return dn;
  151. }
  152. }
  153. this.errcode[4] = 365.00;
  154. if( !KMClientAX.kmsConnect(this.kmi_ip, this.kmi_port) ) {
  155. msg = "KMI 서버( IP:" + this.kmi_ip + ",포트:" + this.kmi_port + ") 연결에";
  156. messageBox( msg, "E009", getKMIErrMsg() );
  157. return dn;
  158. }
  159. if( this.debug == true ) {
  160. alert( "KMI 서버가 연결되었습니다." );
  161. }
  162. this.errcode[4] = 365.01;
  163. var envelop = KMClientAX.kmsInit();
  164. if( envelop == "" ) {
  165. msg = "KMI 모듈의 초기화에";
  166. messageBox( msg, "E009", getKMIErrMsg() );
  167. KMClientAX.kmsDisconnect();
  168. return dn;
  169. }
  170. if( this.debug == true ) {
  171. alert( "KMI 모듈이 초기화되었습니다. \nENVELOP : " + envelop );
  172. }
  173. this.errcode[4] = 365.02;
  174. dn = KMClientAX.GetKeyAndCert( pUid );
  175. if( dn == "" ) {
  176. msg = "KMI 서버에서 인증서( " + pUid + " )를 가져오는 데.";
  177. messageBox( msg, "E009", getKMIErrMsg() );
  178. KMClientAX.kmsDisconnect();
  179. return dn;
  180. }
  181. if( this.debug == true ) {
  182. alert( "인증서를 다운로드하였습니다.\n다운로드 인증서 DN : " + dn );
  183. }
  184. this.errcode[4] = 365.03;
  185. switch( KMClientAX.IsCertNew(pUid, dn) ) {
  186. case 0 : // 현재 인증서가 유효함
  187. if( this.debug == true ) {
  188. alert( "현재 인증서가 유효합니다." );
  189. }
  190. break;
  191. case 1 : // 인증서가 갱신되어 KMI에 재등록됨
  192. msg = "인증서의 갱신이";
  193. messageBox( msg, "I002");
  194. break;
  195. case 2 : // 인증서 갱신 실패 ( 에러코드와 메시지가 리턴됨 )
  196. msg = "인증서 갱신에";
  197. messageBox( msg, "E009", getKMIErrMsg());
  198. KMClientAX.LocalDelKeyAndCert(dn);
  199. KMClientAX.kmsDisconnect();
  200. return dn;
  201. case 3 : // 인증서 갱신은 성공 하였으나 KMI 서버 등록 실패 (인증서 백업 성공)
  202. case 4 : // 인증서 갱신은 성공 하였으나 KMI 서버 등록 실패 (인증서 백업 실패)
  203. msg = "갱신된 인증서의 KMI 등록에";
  204. messageBox( msg, "E009", "관리자에게 문의하시기 바랍니다.");
  205. KMClientAX.LocalDelKeyAndCert(dn);
  206. KMClientAX.kmsDisconnect();
  207. return dn;
  208. case 5 : // 이미 만료 되었거나 폐지된 인증서
  209. msg = "인증서가 만료되어 사용";
  210. messageBox( msg, "E001", "인증서를 재발급 받으시기 바랍니다.");
  211. KMClientAX.LocalDelKeyAndCert(dn);
  212. KMClientAX.kmsDisconnect();
  213. return dn;
  214. case 6 : // 인증서의 갱신을 사용자가 취소
  215. break;
  216. case 7 :
  217. msg = "인증서 화일에 문제가 있어 인증서 읽기에.";
  218. messageBox( msg, "E009", "관리자에게 문의하시기 바랍니다.");
  219. KMClientAX.LocalDelKeyAndCert(dn);
  220. KMClientAX.kmsDisconnect();
  221. return dn;
  222. }
  223. this.errcode[4] = 365.04;
  224. // 0 * 256 : SignKorea의 인증서만 선택
  225. // 0 * 16 : 비밀번호 입력 받음
  226. // 1 : 현재의 ActiveX 인스턴스가 유효할 동안 선택한 정보 유지
  227. // dn = CertManX.SetMatchedContextExt( dn, "", "", 0 * 256 + 0 * 16 + 1 );
  228. //var matched_dn = CertManX.SetMatchedContextExt(dn, "", "", 0 * 256 + 0 * 16 + 1 );
  229. //이윤주수정(20150415)
  230. var matched_dn = CertManX.SetMatchedContextExt(dn, "", pwd, 0 * 256 + 0 * 16 + 1 );
  231. if( matched_dn == "" ) {
  232. msg = "인증서의 메모리 로드에";
  233. messageBox( msg, "E009", this.errmsg + CertManX.GetLastErrorMsg());
  234. KMClientAX.LocalDelKeyAndCert(dn);
  235. KMClientAX.kmsDisconnect();
  236. return matched_dn;
  237. }
  238. this.errcode[4] = 365.05;
  239. var today = new Date(); // Client Time 사용, But ServerTime Check 필요
  240. this.CERT_YEAR = today.getFullYear();
  241. this.CERT_MONTH = today.getMonth() + 1;
  242. this.CERT_DATE = today.getDate();
  243. this.CERT_UID = pUid;
  244. this.errcode[4] = 365.06;
  245. KMClientAX.LocalDelKeyAndCert(dn);
  246. this.errcode[4] = 365.07;
  247. KMClientAX.kmsDisconnect();
  248. return dn;
  249. }
  250. //
  251. function enrfSign_MakeSignData(pOrgData, pUid, pReload) {
  252. var m_signedData = "";
  253. if (this.version == "TF4"){
  254. this.errcode[2] = 361;
  255. if (this.certcheck(pUid, pReload) != ""){
  256. this.errcode[2] = 366;
  257. m_signedData = CertManX.SignDataB64( "", pOrgData, 0 );
  258. this.errcode[2] = 367;
  259. if (m_signedData == ""){
  260. var msg = "전자서명 생성에"
  261. messageBox( msg, "E009", this.errmsg + CertManX.GetLastErrorMsg());
  262. }
  263. }
  264. }
  265. this.signData = pOrgData;
  266. this.signedData = m_signedData;
  267. return m_signedData;
  268. }
  269. // 전자서명된 데이터 복원검증 Process
  270. function enrfSign_VerifySign(pSignedData){
  271. var orgData = "";
  272. if (this.version == "TF4"){
  273. if (pSignedData == null) pSignedData = this.signedData;
  274. if (pSignedData != ""){
  275. orgData = CertManX.VerifyDataB64(pSignedData, 0 );
  276. if( orgData == "" ) {
  277. var msg = "전자서명 검증에";
  278. messageBox( msg, "E009", this.errmsg + CertManX.GetLastErrorMsg());
  279. }
  280. }
  281. }
  282. return orgData;
  283. }
  284. //
  285. function enrfSign_FindNode(pXPath){
  286. var m_node = null;
  287. switch (this.version){
  288. case "TF4" :
  289. m_node = model.instances(0).selectSingleNode(pXPath);
  290. break;
  291. default : // TF3
  292. m_node = model.instance.selectSingleNode(pXPath);
  293. break;
  294. }
  295. return m_node;
  296. }
  297. //
  298. function enrfSign_MakeNode(pXPath)
  299. {
  300. var mNode = this.findnode(pXPath);
  301. if (mNode== null){
  302. model.makenode(pXPath); // TF3,4
  303. mNode = this.findnode(pXPath);
  304. }
  305. return mNode;
  306. }
  307. //
  308. function enrfSign_SetAttNode(pXPath, pAttrName, pValue)
  309. {
  310. var m_node = this.makenode(pXPath);
  311. m_node.setAttribute("name", pAttrName);
  312. var bHasCheck = this.findnode(pXPath).hasChildNodes();
  313. if (pValue != null){
  314. if (bHasCheck == false){ // 자식노드가 없으면
  315. model.setValue(pXPath, pValue); // TF3.4
  316. } else {
  317. var sErr = "[Debug Mode] : 인증구조 생성중 SetAttNode함수 수행시 상위노드에 값을 Setting 할수 없습니다."
  318. sErr += "\n\n[xPath] " + pXPath;
  319. sErr += "\n\n[Value] " + pValue;
  320. alert(sErr);
  321. return null;
  322. }
  323. }
  324. return m_node;
  325. }
  326. //
  327. function enrfSign_SetSignInstance()
  328. {
  329. var m_topinfo = "";
  330. var m_sessioninfo = "";
  331. this.setattnode(this.XPATH_BASICINFO, "환자정보");
  332. this.setattnode(this.XPATH_SIGNINFO, "인증정보");
  333. this.setattnode(this.XPATH_SESSIONINFO, "Session정보");
  334. switch (this.version){
  335. case "TF4" :
  336. m_topinfo = "pid▦환자번호▩pname▦환자이름▩age▦나이성별▩body▦키몸무게▩btype▦혈액형▩insukind▦보험유형▩orddept▦진료과▩apntdr▦지정의▩attndr▦주치의▩";
  337. m_sessioninfo = "userid▦사용자번호▩usernm▦사용자이름▩posinstnm▦소속기관명▩posdeptnm▦소속부서명▩dutplceinstnm▦근무지기관명▩dutplcenm▦근무지부서명▩jobkindnm▦직종명▩jobposnm▦직위명▩jobrespnm▦직책명▩prfshipflagnm▦교직구분명▩deptabbr▦부서약어▩systemnm▦시스템명칭▩systeminstnm▦시스템소속기관명▩logindt▦로그인시간▩";
  338. this.settaginfos(m_topinfo, this.XPATH_BASICINFO, "TopInfo", false); // TopInfo 정보
  339. this.settaginfos(m_sessioninfo, this.XPATH_SESSIONINFO, "SessionInfo", false); // Session 정보
  340. break;
  341. case "TF3" :
  342. m_topinfo = "HJID▦환자아이디▩HJName▦환자이름▩HJAgeSex▦환자성별▩HJBlood▦환자혈액형▩HJHeightWeight▦환자키/몸무게▩HJInOutFlag▦입원/외래환자구분▩HJBDInDay▦입원일▩HJORDay▦외래내원일▩HJBDTerm▦재원▩HJInsuranc▦보험▩HJBD▦병동정보▩HJDept▦담당부서▩AppoinmentDoctor▦지정의▩MainDoctor▦주치의▩";
  343. m_sessioninfo = "userid▦아이디▩username▦이름▩userdeptname▦부서이름▩logondatetime▦로그인시간▩empldeptgmnm▦근무부서명▩empljkcodenm▦직급명";
  344. break;
  345. }
  346. if (this.debug == true){
  347. alert("enrfSign_SetSignInstance XML View\n\n----------------------\n" + instance1.xml);
  348. }
  349. }
  350. //
  351. function enrfSign_SetTagInfos(pParStr, pPath, pMode, pClear)
  352. {
  353. var m_SessionInfo = "";
  354. var m_KeyName = "";
  355. m_SessionInfo = pParStr;
  356. m_SessionInfo = m_SessionInfo.split("▩");
  357. for (var iCnt =0; iCnt < m_SessionInfo.length; iCnt++){
  358. m_KeyName = m_SessionInfo[iCnt].split("▦");
  359. if (m_KeyName != ""){
  360. this.setattnode(pPath + "/" + m_KeyName[0],
  361. m_KeyName[1],
  362. this.getcommoninfo(pMode, m_KeyName[0]));
  363. }
  364. }
  365. if (pClear == true){
  366. this.removenochild(this.findnode(pPath));
  367. }
  368. }
  369. //
  370. function enrfSign_GetCommonInfo(pMode, pKeyInfo){
  371. var m_return = "";
  372. if (pMode == "TopInfo"){
  373. switch (this.version){
  374. case "TF4" :
  375. m_return = getPatientInfo(pKeyInfo);
  376. if (m_return == "null") m_return = this.nulldatastring;
  377. break;
  378. case "TF3" : break;
  379. }
  380. return m_return;
  381. } else if (pMode == "SessionInfo"){
  382. switch (this.version){
  383. case "TF4" :
  384. m_return = getUserInfo(pKeyInfo);
  385. if (m_return == "null") m_return = this.nulldatastring;
  386. break;
  387. case "TF3" : break;
  388. }
  389. return m_return;
  390. }
  391. }
  392. // TF4에서만 확인해봄 : 노드에 값이 없으면 제거하는 함수
  393. function enrfSign_RemoveNoChild(pNode, pDebug) {
  394. //if (pNode == null) return;
  395. var pCnt = 0;
  396. var iCnt = 0;
  397. var iCntLoop = 0;
  398. while (1){
  399. iCntLoop++;
  400. iCnt = f_removechecker(pNode, iCnt);
  401. if (pCnt != iCnt){
  402. pCnt = iCnt;
  403. } else {
  404. break;
  405. }
  406. }
  407. //
  408. if (pDebug == true){
  409. alert("[Debug] RemoveNoChild 함수 진행, 반복횟수 iCntLoop:" + iCntLoop + " 총 삭제노드건수 iCnt : " + pCnt );
  410. }
  411. }
  412. // TF4에서만 확인해봄 :
  413. function f_removechecker(pNode, iCnt){
  414. if (pNode == null ) return iCnt;
  415. var nodes = pNode.childNodes;
  416. if (nodes.length > 0){ // exist
  417. var m_node = nodes.nextNode();
  418. while (m_node != null){
  419. iCnt = f_removechecker(m_node, iCnt);
  420. m_node = nodes.nextNode();
  421. }
  422. } else {
  423. var prNode = pNode.parentNode;
  424. if (pNode.nodeTypedValue == "" || pNode.nodeValue == ""){
  425. prNode.removeChild(pNode);
  426. iCnt++;
  427. }
  428. }
  429. return iCnt;
  430. }
  431. /**
  432. [MainData가 기준인 함수]
  433. - pXPath : 화면에 구현된 /root/MainData/... 경로 path(MainData PATH는 자동으로 SignData로 변경)
  434. - pAttrName : 해당 노드에 추가될 속성 name 의 값
  435. - pNodeValue : 추가될 노드에 설정할 Value 값
  436. - pAddNodeName : pXPath에 추가될 추가노드
  437. - 사용예)
  438. Sign.makemainattnode("/root/MainData/condition/datas", "조건들", "없음", "check");
  439. 사용예 결과)
  440. <root>
  441. <SignData>
  442. <condtion>
  443. <datas>
  444. <check name="조건들">없음</check>
  445. <datas>
  446. </condtion>
  447. </SignData>
  448. </root>
  449. */
  450. function enrfSign_MakeMainAttNode(pXPath, pAttrName, pNodeValue, pAddNodeName)
  451. {
  452. var m_PathNode = this.XPATH_SIGNINFO;
  453. if (pAddNodeName != null){
  454. m_PathNode += "/" + pAddNodeName;
  455. }
  456. var re = new RegExp(this.XPATH_MAINNODE, ["gi"]);
  457. var m_Path = pXPath.replace(re, m_PathNode);
  458. var m_node = null;
  459. m_node = this.setattnode(m_Path, pAttrName, pNodeValue);
  460. if (m_node == null){
  461. throw "MakeMainAttNode return Value : Null";
  462. }
  463. return m_node;
  464. }
  465. /**
  466. 사용자가 지정한 경로(pSignPath)에 노드를 만드는 함수
  467. - 사용예)
  468. Sign.makeuserattnode("/root/SignData/emrdata", "기본", "영양별");
  469. 사용예 결과)
  470. <root>
  471. <SignData>
  472. <emrdata name="기본">영양별</emrdata>
  473. </SignData>
  474. </root>
  475. */
  476. function enrfSign_MakeUserAttNode(pSignPath, pAttrName, pNodeValue) {
  477. var m_node = null;
  478. if (pSignPath == null) return m_node;
  479. m_node = this.setattnode(pSignPath, pAttrName, pNodeValue);
  480. if (m_node == null){
  481. throw "MakeUserAttNode return Value : Null";
  482. }
  483. return m_node;
  484. }
  485. //
  486. function enrfSign_AddCopyNode(pCopyNodePath){
  487. var m_RootNode = this.findnode(pCopyNodePath);
  488. if (m_RootNode != null){
  489. if (pCopyNodePath != "" && pCopyNodePath != null){
  490. var m_temppath = this.XPATH_SIGNINFO + "/" + m_RootNode.nodeName;
  491. this.makenode(m_temppath);
  492. model.copynode(m_temppath, pCopyNodePath);
  493. }
  494. }
  495. }
  496. // 선택 node를 String 데이터로 돌려주는 함수
  497. function enrfSign_GetSignDataToStr(pXPath){
  498. this.tempstr = "";
  499. var m_RootNode = this.findnode(pXPath);
  500. var m_NowNode = m_RootNode.firstChild;
  501. if (m_NowNode == null) return;
  502. var m_txt = "";
  503. while ((m_NowNode.nodeName != m_RootNode.nodeName) &&
  504. (m_NowNode.parentNode.nodeName != m_RootNode.parentNode.nodeName)) {
  505. if (m_NowNode.getAttribute("name") != null && m_NowNode.getAttribute("name") != ""){
  506. m_txt = m_txt + "\n" + this.tempstr + m_NowNode.getAttribute("name");
  507. } else {
  508. m_txt = m_txt + "\n" + this.tempstr + this.emptyattname + m_NowNode.nodeName;
  509. }
  510. if (m_NowNode.nodeValue != null && m_NowNode.nodeValue != "") {
  511. m_txt = m_txt + ": " + m_NowNode.nodeValue;
  512. }
  513. m_NowNode = this.getnodenamestrvalue(m_NowNode, m_RootNode);
  514. if (m_NowNode == null) {
  515. break;
  516. }
  517. }
  518. return m_txt;
  519. }
  520. // GetSignDataToStr 에서 사용하는 재귀함수
  521. function enrfSign_GetNodeNameStrValue(pNowNode, pRootNode){
  522. var m_tempPath = "/root";
  523. var m_refPath = m_tempPath + "/" + pNowNode.nodeName;
  524. var m_childnode = pNowNode.firstChild;
  525. if (m_childnode != null){
  526. m_tempPath = m_refPath;
  527. this.tempstr = this.tempstr + " ";
  528. return m_childnode;
  529. }
  530. var m_sibling = pNowNode.nextSibling;
  531. if (m_sibling != null) {
  532. m_tempPath = m_refPath;
  533. return m_sibling;
  534. } else { // m_sibling == null
  535. var m_nodePT = pNowNode;
  536. while(1) {
  537. m_nodePT = m_nodePT.parentNode;
  538. this.tempstr = this.tempstr.substring(0, this.tempstr.length-2);
  539. if (m_nodePT == null) {
  540. return null;
  541. }
  542. if ((m_nodePT.nodeName == pRootNode.nodeName) && (m_nodePT.getAttribute("name") == pRootNode.getAttribute("name"))) {
  543. return m_nodePT;
  544. }
  545. if (m_nodePT.nextSibling == null){
  546. continue;
  547. } else {
  548. return m_nodePT.nextSibling;
  549. }
  550. }
  551. }
  552. }
  553. //
  554. function enrfSign_SignProcess(pClearNode){
  555. //
  556. this.errcode[0] = 0;
  557. this.errcode[1] = 0;
  558. this.errcode[2] = 0;
  559. this.errcode[3] = 0;
  560. this.errcode[4] = 0;
  561. var bCheck = true;
  562. var bResultArr = null;
  563. // 인증결과 Clear Setting
  564. this.signedInfos[0] = false;
  565. this.signedInfos[1] = "";
  566. this.signedInfos[2] = "";
  567. this.signedInfos[3] = "";
  568. this.signedInfos[4] = "";
  569. this.signedInfos[5] = "";
  570. //this.errcode[0] = 100;
  571. model.removeNodeset(this.XPATH_SIGNBASE); // TF3,4
  572. this.setsigninstance();
  573. //this.errcode[0] = 200;
  574. try{
  575. // 인증 Process "fMake_SignData" CallBack 함수 : 사용자정의
  576. fMake_SignData();
  577. } catch(E){
  578. bCheck = false;
  579. alert("[Debug Mode] : ENR 인증데이터 생성함수(fMake_SignData)에 문제가 있습니다.");
  580. }
  581. this.errcode[0] = 300;
  582. if (bCheck == true){
  583. bCheck = this.getsigndataArray(this.CERT_UID, this.certreload); // Array 구조로 생성된 데이터를 돌려줌 : this.signedInfos
  584. }
  585. if (pClearNode == true){
  586. // 3. 인증을 위해 생성된 데이터 삭제
  587. model.removeNodeset(this.XPATH_SIGNBASE);
  588. }
  589. return bCheck;
  590. }
  591. function enrfSign_ViewSignProcess(pClearNode){
  592. //
  593. this.errcode[0] = 0;
  594. this.errcode[1] = 0;
  595. this.errcode[2] = 0;
  596. this.errcode[3] = 0;
  597. this.errcode[4] = 0;
  598. var bCheck = true;
  599. var bResultArr = null;
  600. // 인증결과 Clear Setting
  601. this.signedInfos[0] = false;
  602. this.signedInfos[1] = "";
  603. this.signedInfos[2] = "";
  604. this.signedInfos[3] = "";
  605. this.signedInfos[4] = "";
  606. this.signedInfos[5] = "";
  607. //this.errcode[0] = 100;
  608. model.removeNodeset(this.XPATH_SIGNBASE); // TF3,4
  609. this.setsigninstance();
  610. //this.errcode[0] = 200;
  611. try{
  612. // 인증 Process "fMake_SignData" CallBack 함수 : 사용자정의
  613. fMake_ViewSignData();
  614. } catch(E){
  615. bCheck = false;
  616. alert("[Debug Mode] : ENR 인증데이터 생성함수(fMake_SignData)에 문제가 있습니다.");
  617. }
  618. this.errcode[0] = 300;
  619. if (bCheck == true){
  620. bCheck = this.getsigndataArray(this.CERT_UID, this.certreload); // Array 구조로 생성된 데이터를 돌려줌 : this.signedInfos
  621. }
  622. if (pClearNode == true){
  623. // 3. 인증을 위해 생성된 데이터 삭제
  624. model.removeNodeset(this.XPATH_SIGNBASE);
  625. }
  626. return bCheck;
  627. }
  628. //
  629. function enrfSign_GetSignDataArray(pUid, pReload) {
  630. var ls_enrinptsavetime = fGetEMRHardCDList("Y", 450, 3); // 진료하드코딩 조회 CareCom.js
  631. var ll_enrinptsavetime = ls_enrinptsavetime == "" ? 0 : parseInt(ls_enrinptsavetime) * -1;
  632. var mstatecheck = false;
  633. var mSignData1 = "";
  634. var mSignedData = "";
  635. var mSignData3 = "";
  636. var mViewData4 = "";
  637. var mViewData5 = "";
  638. this.errcode[1] = 300;
  639. try {
  640. this.errcode[1] = 310;
  641. mSignData3 = this.findnode(this.XPATH_SIGNBASE).xml; // 변경 xml 데이터저장패턴으로...
  642. this.errcode[1] = 320;
  643. mViewData4 = this.getsigndatatostr(this.XPATH_SIGNBASE); // 전자서명할 원문 데이터
  644. // 값이 없는것들은 제거함 (Attribute만 있는것도 날림)
  645. this.errcode[1] = 330;
  646. this.removenochild(this.findnode(this.XPATH_SIGNBASE));
  647. this.errcode[1] = 340;
  648. mSignData1 = this.findnode(this.XPATH_SIGNBASE).xml; // 변경 xml 데이터저장패턴으로...
  649. this.errcode[1] = 350;
  650. mViewData5 = this.getsigndatatostr(this.XPATH_SIGNBASE); // 전자서명할 원문 데이터
  651. this.errcode[1] = 360;
  652. // -----------------------(2010.08.18 센터)start--------------------
  653. //운영서버는 인증모듈 타고 그외서버는 인증모듈제외
  654. //if (htmlwindow.DEVSystem != "true") {
  655. if(this.certchkflag == "Y") {
  656. if(ll_enrinptsavetime < 0 && getGlobalVariable("enrinptsavetime") >= getCurrentDateTime().toDate("YYYYMMDD hhmmss").getAddDate(ll_enrinptsavetime, "m").getDateFormat("YYYYMMDD hhmmss")){
  657. mSignedData = this.makesigndata(mSignData1, pUid, false); //전자서명 없이 저장처리할 경우 설정 부분
  658. }else{
  659. mSignedData = this.makesigndata(mSignData1, pUid, pReload, true) //전자서명 popup호출
  660. }
  661. } else {
  662. mSignedData = this.findnode(this.XPATH_SIGNBASE).xml //전자서명 없이 저장처리할 경우 설정 부분
  663. }
  664. //} else {
  665. // mSignedData = this.findnode(this.XPATH_SIGNBASE).xml //전자서명 없이 저장처리할 경우 설정 부분
  666. //}
  667. // -----------------------(2010.08.18 센터)start--------------------
  668. this.errcode[1] = 370;
  669. if (mSignedData == "" || mSignedData == null) {
  670. this.signedInfos[0] = mstatecheck;
  671. this.signedInfos[1] = mSignData1; // 인증할 데이터 정보
  672. this.signedInfos[2] = mSignedData;
  673. this.signedInfos[3] = mSignData3;
  674. this.signedInfos[4] = mViewData4;
  675. this.signedInfos[5] = mViewData5;
  676. return false;
  677. }
  678. this.errcode[1] = 0;
  679. mstatecheck = true;
  680. } catch(E){
  681. alert("ENR 인증모듈 작업에 문제가 있습니다. 관리자에게 문의하세요 Code(" + this.errcode + ")...\n\n" + E);
  682. return mstatecheck;
  683. }
  684. this.signedInfos[0] = mstatecheck; // [0] : 인증성공여부
  685. this.signedInfos[1] = mSignData1; // [1] : 인증할 데이터 정보 (미기록 노드 제거된 정보)
  686. this.signedInfos[2] = mSignedData; // [2] : 공인인증 처리후 데이터
  687. this.signedInfos[3] = mSignData3; // [3] : 인증할 데이터 정보 (미기록 노드 제거전 원본 노드)
  688. this.signedInfos[4] = mViewData4; // [4] : [3]데이터(없는 노드 포함된)를 text 형태로 추출보기
  689. this.signedInfos[5] = mViewData5; // [5] : [1]데이터(없는 노드 제거된)를 text 형태로 추출보기
  690. if(mstatecheck == true){
  691. if(ll_enrinptsavetime < 0 && getGlobalVariable("enrinptsavetime") >= getCurrentDateTime().toDate("YYYYMMDD hhmmss").getAddDate(ll_enrinptsavetime, "m").getDateFormat("YYYYMMDD hhmmss")){
  692. }else{
  693. setGlobalVariable("enrinptsavetime", getCurrentDateTime());
  694. }
  695. }
  696. return mstatecheck;
  697. }
  698. // 진료 하드코딩 조회
  699. function fGetEMRHardCDList(option, hardcdno, rtnValue , rslt_ref_list) {
  700. model.makeNode(rslt_ref_list);
  701. var destNode = model.instances(0).selectSingleNode(rslt_ref_list);
  702. var sysMessageobj = getViewer("sysMessage");
  703. if (sysMessageobj != null) {
  704. if (option == "Y") {
  705. try {
  706. var hardcdno = sysMessageobj.window.instance1.selectSingleNode("/root/properties/orderbasicinfo/hardcdlist/hardcd[hardcdno='" + hardcdno + "']/hardcdno").text;
  707. var hardcodenm = sysMessageobj.window.instance1.selectSingleNode("/root/properties/orderbasicinfo/hardcdlist/hardcd[hardcdno='" + hardcdno + "']/hardcodenm").text;
  708. var hardcd = sysMessageobj.window.instance1.selectSingleNode("/root/properties/orderbasicinfo/hardcdlist/hardcd[hardcdno='" + hardcdno + "']/hardcd").text;
  709. var hardcdnm = sysMessageobj.window.instance1.selectSingleNode("/root/properties/orderbasicinfo/hardcdlist/hardcd[hardcdno='" + hardcdno + "']/hardcdnm").text;
  710. var cdseqno = sysMessageobj.window.instance1.selectSingleNode("/root/properties/orderbasicinfo/hardcdlist/hardcd[hardcdno='" + hardcdno + "']/cdseqno").text;
  711. } catch(err) {
  712. model.makeValue("/root/enrtemp/hardcd", hardcdno);
  713. mmbfGetHardCodeInfo("/root/send/reqdata", "/root/enrtemp/hardcd", hardcdno); //
  714. var hardcd = model.getValue("/root/enrtemp/hardcd/hardcd");
  715. var hardcdnm = model.getValue("/root/enrtemp/hardcd/hardcdnm");
  716. var cdseqno = model.getValue("/root/enrtemp/hardcd/cdseqno");
  717. }
  718. if (rtnValue == 1) {
  719. return hardcdno;
  720. } else if (rtnValue == 1) {
  721. return hardcodenm;
  722. } else if (rtnValue == 2) {
  723. return hardcdno;
  724. } else if (rtnValue == 3) {
  725. return hardcd;
  726. } else if (rtnValue == 4) {
  727. return hardcdnm;
  728. } else if (rtnValue == 5) {
  729. return cdseqno;
  730. } else if (rtnValue == 9) {
  731. return hardcd+ "|" + hardcdnm + "|" + cdseqno;
  732. }
  733. } else {
  734. var destListLen = destNode.childNodes.length;
  735. if (destListLen < 1 ) { // 한번이라도 복사된 내용이 있으면 다시 안하도록 수정 2011. 01.20 김영학
  736. var destNode = instance1.selectSingleNode(rslt_ref_list);
  737. var nodes = sysMessageobj.window.instance1.selectNodes("/root/properties/orderbasicinfo/hardcdlist/hardcd[hardcdno='"+hardcdno+"']");
  738. for(i=1; i<= nodes.length; i++) {
  739. destNode.appendChild(nodes.item(i-1).cloneNode(true));
  740. }
  741. }
  742. }
  743. }
  744. }
  745. function mmbfGetHardCodeInfo(ref, rsltref, hardcd){
  746. fGetEMRHardCDList("N", hardcd, 0, rsltref);
  747. model.refresh();
  748. }