ENRSignEngine.xjs 33 KB

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