using System;
using System.ComponentModel;
using System.Windows.Forms;
using CLIP.eForm.Consent.UI.ConsentSvcRef;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
namespace CLIP.eForm.Consent.UI.ConsentListTabElements {
public partial class ConsentSelectTabDailySearch : UserControl {
private ConsentSvcRef.ConsentSvcSoapClient consentWebService = null;
private HospitalSvcRef.HospitalSvcSoapClient hospitalWebService = null;
private IConsentMain consentMain = null;
private ConsentCommandCtrl commandControl = null;
public ConsentSelectTabDailySearch() {
InitializeComponent();
}
///
/// 페이지 로딩 시 필요한 commandControl 및 웹 서비스 연결
///
///
///
private void ConsentSelectTabDailySearch_Load(object sender, EventArgs e) {
if (this.DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime) {
return;
}
consentMain = ConsentMainControl.GetConsentMainInterface(this);
commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;
consentWebService = WebMethodCommon.GetConsentWebService(consentMain.PluginExecuteInfo["consentSvcUrl"]);
hospitalWebService = WebMethodCommon.GetHospitalWebService(consentMain.PluginExecuteInfo["hospitalSvcUrl"]);
InitDataGrid();
this.fromdd.Value = DateTime.Now.AddMonths(-6);
}
///
/// 데이터그리드 초기화
///
private void InitDataGrid() {
// 초기 설정 추가
this.gridConsentList.AllowUserToAddRows = false;
//this.gridConsentList.CellPainting += new DataGridViewCellPaintingEventHandler(this.dataGridViewPatientSelectResult_CellPainting);
this.gridConsentList.CellDoubleClick += new DataGridViewCellEventHandler(gridConsentList_CellDoubleClick);
// 체크박스 컬럼을 추가
CommonUtil.AddNewCheckBoxColumnToDataGridView(this.gridConsentList, "□", "colCheck", true, 25, DataGridViewContentAlignment.MiddleCenter);
// 사용자에게 표시할 컬럼
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "등록번호", "pid", true, 80);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "성명", "patientName", true, 80);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "OCRTAG", "ocrTag", true, 100, DataGridViewContentAlignment.MiddleCenter);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "동의서명", "formName", true, 180, DataGridViewContentAlignment.MiddleCenter);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "상태", "consentState", true, 60, DataGridViewContentAlignment.MiddleCenter);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "작성자", "modifyUserNm", true, 70, DataGridViewContentAlignment.MiddleCenter);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "작성일시", "modifyDatetime", true, 120, DataGridViewContentAlignment.MiddleCenter);
// 사용자에게 표시하지 않을 컬럼
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "인덱스", "idx", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "서식번호", "formId", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "서식코드", "formCode", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "서식출력명", "formPrntNm", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "출력매수", "printCnt", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "마스터RID", "consentMstRid", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "작성자 ID", "modifyUserId", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "부서 약어", "deptEngName", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "certPass", "certPass", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "createDatetime", "createDatetime", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "clnDate", "clnDate", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "cretNo", "cretNo", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "ordType", "ordType", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "deptCd", "deptCd", false);
CommonUtil.AddNewColumnToDataGridView(this.gridConsentList, "mainDrId", "mainDrId", false);
// 해당 컬럼 활성화 여부 제어
//gridConsentList.Columns["idx"].Visible = false;
//gridConsentList.Columns["formId"].Visible = false;
//gridConsentList.Columns["formCode"].Visible = false;
//gridConsentList.Columns["formPrntNm"].Visible = false;
//gridConsentList.Columns["printCnt"].Visible = false;
//gridConsentList.Columns["consentMstRid"].Visible = false;
//gridConsentList.Columns["modifyUserId"].Visible = false;
//gridConsentList.Columns["deptEngName"].Visible = false;
}
///
/// 동의서 리스트 체크 박스 이벤트
///
///
///
private void dataGridViewPatientSelectResult_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
//Image InfoIcon;
//if (e.ColumnIndex == 0 && e.RowIndex == -1) {
// // 체크박스 상태에 따른 아이콘 표시
// if (gridConsentList.Columns[0].HeaderText.Equals("□")) {
// //InfoIcon = Image.FromFile(@"../../Resources/uncheck.png");
// InfoIcon = Properties.Resources.uncheck;
// } else {
// //InfoIcon = Image.FromFile(@"../../Resources/check.png");
// InfoIcon = Properties.Resources.check;
// }
// e.Paint(e.CellBounds, DataGridViewPaintParts.All);
// e.Graphics.DrawImage(InfoIcon, e.CellBounds);
// e.Handled = true;
//}
}
///
/// 동의서 선택 시 확인저장 된 동의서의 미리보기를 수행한다
///
///
///
private void gridConsentList_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
if (consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
if (commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;
// dbs227, 셀 클릭 시 더블클릭 인식되어 작동되는 경우 오류
if (e.RowIndex < 0) {
return;
}
ConsentVO vo = GetCurrentConsentSearchVO(e.RowIndex);
if (vo != null) {
// startFormCd 를 초기화 한다
consentMain.preParamClean();
// 동의서 미리보기
ExecutePreviewWithSelectedConsent(vo);
this.commandControl.setCompleteSaveTempButton(false);
string otps = "";
if (vo.consentState.Equals("임시") || vo.consentState.Equals("확인")) {
otps += "FILE_SAVE=true";
if (vo.consentState.Equals("임시")) {
otps += ";FILE_TEMP_SAVE=true;FILE_TEMP_SAVE2=true";
} else {
otps += ";FILE_TEMP_SAVE=false;FILE_TEMP_SAVE2=false";
}
} else if (vo.consentState.Equals("인증")) {
otps += "FILE_SAVE=true;FILE_TEMP_SAVE=false;FILE_TEMP_SAVE2=false";
} else {
otps += "FILE_SAVE=true;FILE_TEMP_SAVE=false;FILE_TEMP_SAVE2=false";
}
consentMain.setDualViewerButtonOtps(otps);
switch (vo.consentState) {
case "임시": // 임시
case "확인": // 확인
// 듀얼뷰어 상태일 때 동의서 로드
RunConsentDualView();
break;
}
}
}
///
/// 동의서 뷰어에 동의서 로드
///
private void RunConsentDualView() {
if (this.consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
if (this.commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;
commandControl.RunConsentDualView();
}
private void ExecutePreviewWithSelectedConsent(ConsentVO vo) {
if (consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
if (commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;
Cursor currentCursor = this.Cursor;
this.Cursor = Cursors.WaitCursor;
//consentMain.ConsentExecuteInfo["patientId"] = vo.PatientCode;
//consentMain.ConsentExecuteInfo["patientOrdtype"] = vo.VisitType;
//consentMain.ConsentExecuteInfo["patientClnDept"] = vo.ClnDate.Replace("-", "");
//consentMain.ConsentExecuteInfo["patientClnDept"] = vo.ClnDeptCd;
//consentMain.ConsentExecuteInfo["cretno"] = vo.Cretno.ToString();
//consentMain.ConsentExecuteInfo["opRsrvNo"] = vo.OpRsrvNo;
consentMain.SetPatientInfo();
commandControl.CurrentPreviewConsent = new PreviewConsent {
FormRid = vo.formId.ToString(),
FormCd = vo.formCode.ToString(),
FormName = vo.formName,
FormPrintName = vo.formPrntNm,
PrntCnt = vo.printCnt,
ConsentMstRid = vo.consentMstRid.ToString(),
ConsentState = vo.consentState,
Ocrcode = vo.ocrTag,
certPass = vo.certPass,
InputId = commandControl.CurrentEndUser.userId,
InputNm = commandControl.CurrentEndUser.userName,
ReissueConsentMstRid = 0,
RewriteConsentMstRid = 0,
OpDiagName = commandControl.CurrentTargetPatient.OpDiagName,
VisitType = commandControl.CurrentTargetPatient.ordtype,
OpName = commandControl.CurrentTargetPatient.OpName
};
try {
consentMain.PatientInfoCtrl.SetConsentDocumentName(vo.formName);
bool isReissueDocument = false;
// API 를 호출하여 해당 서식이 재인증저장이 필요한지 확인
// TODO, do something
switch (commandControl.CurrentPreviewConsent.ConsentState) {
case "임시":
commandControl.ShowTempSaveConsent(consentMain);
break;
case "인증":
// TODO, 인증저장 재인증 호출
if (isReissueDocument) {
// 재인증이 필요할 경우 호출
commandControl.ShowTempSaveConsent(consentMain);
} else {
// 재인증이 필요없을 경우 이미지 호출하는 함수
commandControl.ShowCompleteConsent(consentMain);
}
break;
case "확인":
commandControl.ShowTempSaveConsent(consentMain);
break;
default:
break;
}
//if (IsConsentStateTempSave(vo) || IsConsentStateElectronicComplete(vo)) { // 임시저장 or 작성완료
// commandControl.ShowTempSaveConsent(consentMain);
//} else if (IsConsentStatePrintOut(vo)) { // 출력
// if (this.dataGridViewConsentSelectResult.SelectedRows.Count > 0 &&
// this.dataGridViewConsentSelectResult.SelectedRows[0].Tag != null &&
// this.dataGridViewConsentSelectResult.SelectedRows[0].Tag.Equals("reissueTarget")) {
// // TODO 재출력 기능 사용하지 않음. 요구사항 확인 필요
// //재출력 하는 경우
// //commandControl.CurrentPreviewConsent.ReissueConsentMstRid = vo.ConsentMstRid;
// commandControl.CurrentPreviewConsent.RewriteConsentMstRid = 0;
// //CheckClnDateInfo(vo);
// commandControl.PreviewConsent(consentMain);
// } else {
// //CheckClnDateInfo(vo);
// commandControl.PreviewConsent(consentMain);
// }
//} else if (IsConsentStateCertifyComplete(vo)) { // 인증저장
// commandControl.ShowCompleteConsent(consentMain);//이미지 호출하는 함수
//} else if (IsConsentStateUnfinished(vo)) { //미작성
// //CheckClnDateInfo(vo);
// commandControl.PreviewConsent(consentMain); // consent_data에 데이터가 없을때 사용하는 함수
//}
} catch (Exception e) {
throw e;
} finally {
this.Cursor = currentCursor;
}
}
private ConsentVO GetCurrentConsentSearchVO(int rowIndex) {
ConsentVO vo = null;
if (rowIndex < 0) {
return vo;
}
vo = this.gridConsentList.Rows[rowIndex].DataBoundItem as ConsentVO;
return vo;
}
///
/// 컬럼 헤더 선택 시 colcheck 의 경우 전체 선택/해제 기능 동작
///
///
///
private void gridConsentList_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
if (e.ColumnIndex == 0 && e.RowIndex == -1) {
bool chkStatus = false;
if (gridConsentList.Columns[0].HeaderText.Equals("□")) {
gridConsentList.Columns[0].HeaderText = "☑";
chkStatus = true;
} else {
gridConsentList.Columns[0].HeaderText = "□";
}
foreach (DataGridViewRow r in gridConsentList.Rows) {
r.Cells["colCheck"].Value = chkStatus;
}
gridConsentList.RefreshEdit();
}
}
///
/// 동의서 목록을 조회한다.
///
public void BindDataGridRows() {
Cursor currentCursor = this.Cursor;
try {
if (this.consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
if (this.commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;
if (this.consentWebService == null) this.consentWebService = WebMethodCommon.GetConsentWebService(consentMain.PluginExecuteInfo["consentSvcUrl"]);
// 조회조건을 가져온다.
this.Cursor = Cursors.WaitCursor;
var leftFromddStr = this.fromdd.Value.ToString("yyyyMMdd");
var leftToddStr = this.todd.Value.ToString("yyyyMMdd");
// 동의서 목록을 조회한다
ConsentVO[] resultData = null;
//resultData = consentWebService.GetConsentList(patientCode
// , userId
// , sDate
// , eDate
// , consentState
// , consentMain.ConsentExecuteInfo["dutinstcd"]);
if (resultData == null) {
return;
}
// 조회 결과가 있다면 화면을 갱신한다.
this.gridConsentList.DataSource = resultData;
// 작성중인 동의서는 clear 한다.
consentMain.ClearPreviewConsent(true);
} catch (Exception e) {
MessageBox.Show(this, e.Message);
} finally {
this.Cursor = currentCursor;
}
}
///
/// 조회버튼 클릭 시 우측 조회조건을 가져온다
///
///
///
private void btnSearch_Click(object sender, EventArgs e) {
// 0 - 환자검색
// 1 - 응급
// 2 - 수술
// 3 - 입원
// 4 - 외래
// 5 - 검사
var selectedIndex = consentMain.PatientListCtrl.getSelectedTabIndex();
Hashtable queryString = consentMain.PatientListCtrl.getQueryString(selectedIndex);
string startDt = this.fromdd.Value.ToString("yyyyMMdd"); // 날짜별의 fromDd
string endDt = this.todd.Value.ToString("yyyyMMdd"); // 날짜별의 toDd
string pid = (string) queryString["pid"];
string srchDd = (string) queryString["srchDd"]; // 환조 조회 화면의 fromDd
string doctorId = (string) queryString["doctorId"];
string ordDeptCd = (string) queryString["ordDeptCd"];
string patientState = (string) queryString["patientState"];
string ordType = (string) queryString["ordType"];
string userId = this.commandControl.CurrentEndUser.userId;
string srchYN = (string) queryString["srchYN"];
string consentState = "'TEMP', 'ELECTR_CMP'";
string instCd = "101";
string toDd = "";
string mainDr = "";
string mainDrChecked = "";
string supportBaseCd = "";
string supportDeptCd = "";
string wardCd = "";
string myPatient = "";
string drKind = string.Empty;
if (selectedIndex == 3) {
wardCd = (string) queryString["wardCd"];
myPatient = (string) queryString["myPatient"];
drKind = (string) queryString["drKind"];
} else if (selectedIndex == 5) { // 검사
toDd = (string) queryString["toDd"];
mainDr = (string) queryString["mainDr"];
mainDrChecked = (string) queryString["mainDrChecked"];
supportBaseCd = (string) queryString["supportBaseCd"];
supportDeptCd = (string) queryString["supportDeptCd"];
}
ConsentVO[] result = consentWebService.GetConsentDateList(srchDd, pid, userId, startDt, endDt, consentState, instCd, doctorId, ordDeptCd, patientState,
ordType, myPatient, wardCd, drKind, srchYN, toDd, mainDr, mainDrChecked, supportBaseCd, supportDeptCd);
if (result == null) {
return;
}
this.gridConsentList.DataSource = result;
}
private void gridConsentList_CellContentClick(object sender, DataGridViewCellEventArgs e) {
if(e.ColumnIndex == 0) {
bool chkStatus = false;
int i = 0;
foreach (DataGridViewRow r in gridConsentList.Rows) {
if(i++ == e.RowIndex) {
chkStatus = (r.Cells["colCheck"].Value == null) ? false : (bool) r.Cells["colCheck"].Value;
r.Cells["colCheck"].Value = !chkStatus;
}
}
gridConsentList.RefreshEdit();
}
}
private string ConsentImageSignature(string sCertTarget, string userId, string userName) {
string resultValue = string.Empty;
try {
if (!string.IsNullOrEmpty(sCertTarget)) {
// 공인인증 서명
SignatureConfig sign = new SignatureConfig();
string rtn = "";
// 메모리에 본인 공인인증서가 아닐 경우
string sSignIp = consentMain.PluginExecuteInfo["signatureServerUrl"];
string sSignPort = consentMain.PluginExecuteInfo["signatureServerPort"];
int iPort = 0;
int.TryParse(sSignPort, out iPort);
// 공인인증 서버 접속
rtn = sign.SetSignServerInfo(sSignIp, iPort, userId);
// 공인인증 서명
resultValue = sign.SignatureExec(sCertTarget, rtn, userName, userId, this.consentMain.saveClickPoint);
if (string.IsNullOrEmpty(resultValue) || resultValue == "-1") {
// 공인인증 서명에 실패하였을 경우
return "-50";
}
}
} catch (Exception ex) {
MessageBox.Show(string.Format(ex.Message)
, string.Format(Properties.Resources.msg_caption_confirm),
MessageBoxButtons.OK, MessageBoxIcon.Information);
resultValue = "-99";
}
return resultValue;
}
private void checkUserSign() {
SignatureConfig sign = new SignatureConfig();
try {
string saveResult = string.Empty;
// 공인인증 처리용
var sCertTarget = "autosave";
// 공인인증 처리
var sCertResult = ConsentImageSignature(sCertTarget, commandControl.CurrentEndUser.userId, commandControl.CurrentEndUser.userName);
//sCertResult = "TEST";
if (sCertResult == "-10") {
// "로그인 사용자 정보를 통하여 공인인증서 정보가 정상적으로 조회되지 않았습니다."
MessageBox.Show(Properties.Resources.msg_sign_user_info_fail
, string.Format("CLIP e-Form Consent-" + Properties.Resources.msg_caption_fail),
MessageBoxButtons.OK, MessageBoxIcon.Error);
saveResult = "-99";
return;
} else if (sCertResult == "-20") {
// "공인인증 서버 접속에 실패하였을 하였습니다."
MessageBox.Show(Properties.Resources.msg_sign_server_connection_fail
, string.Format("CLIP e-Form Consent-" + Properties.Resources.msg_caption_fail),
MessageBoxButtons.OK, MessageBoxIcon.Error);
saveResult = "-99";
return;
} else if (sCertResult == "-30") {
// "공인인증 서버 접속에 실패하였을 하였습니다."
MessageBox.Show(Properties.Resources.msg_sign_server_connection_fail
, string.Format("CLIP e-Form Consent-" + Properties.Resources.msg_caption_fail),
MessageBoxButtons.OK, MessageBoxIcon.Error);
saveResult = "-99";
return;
} else if (sCertResult == "-35") {
// 공인인증 비밀번호 입력하지 않고 닫음
saveResult = "-99";
return;
} else if (sCertResult == "-40") {
// "공인인증서 비밀번호가 틀렸습니다.
MessageBox.Show(Properties.Resources.msg_sign_password_fail
, string.Format("CLIP e-Form Consent-" + Properties.Resources.msg_caption_fail),
MessageBoxButtons.OK, MessageBoxIcon.Error);
saveResult = "-99";
return;
} else if (sCertResult == "-50") {
// "공인인증서명 처리를 실패하였을 하였습니다."
MessageBox.Show(Properties.Resources.msg_sign_exec_fail
, string.Format("CLIP e-Form Consent-" + Properties.Resources.msg_caption_fail),
MessageBoxButtons.OK, MessageBoxIcon.Error);
saveResult = "-99";
return;
} else if (sCertResult == "-99") {
// "공인인증서명 처리를 실패하였을 하였습니다."
MessageBox.Show(Properties.Resources.msg_sign_exec_fail
, string.Format("CLIP e-Form Consent-" + Properties.Resources.msg_caption_fail),
MessageBoxButtons.OK, MessageBoxIcon.Error);
saveResult = "-99";
return;
}
} catch (Exception ex) {
string exMessage = ex.Message;
if (ex.InnerException != null) {
exMessage += Environment.NewLine + ex.InnerException.Message;
}
MessageBox.Show(string.Format(exMessage)
, string.Format("CLIP e-Form Consent-" + Properties.Resources.msg_caption_fail),
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void btnAllCertifyEvent(object sender, EventArgs e) {
string userId = commandControl.CurrentEndUser.userId;
string userName = commandControl.CurrentEndUser.userName;
string macAddress = Common.getMacAddress();
string result = "";
string saveAllFlag = string.Empty;
SingleReturnData singleReturn = null;
if(consentWebService != null) {
singleReturn = consentWebService.getSaveAllFlag("101", userId);
if(singleReturn != null) {
saveAllFlag = singleReturn.responseData;
}
}
if (string.IsNullOrEmpty(saveAllFlag) || !saveAllFlag.Equals("OK")) {
MessageBox.Show("일괄인증을 사용할 수 없는 사용자 입니다. 전산정보부에 문의하세요.");
return;
}
bool shouldPassCert = false;
foreach (DataGridViewRow r in gridConsentList.Rows) {
bool checkedStatus = (bool) (r.Cells["colCheck"].Value == null) ? false : (bool) r.Cells["colCheck"].Value;
if (checkedStatus == true) {
string consentState = (r.DataBoundItem as ConsentVO).consentState;
string certPass = (r.DataBoundItem as ConsentVO).certPass;
if (certPass.Equals("N")) {
shouldPassCert = true;
}
if (consentState.Equals("확인")) {
//arr.Add((r.DataBoundItem as ConsentVO));
result += fastJSON.JSON.ToJSON(r.DataBoundItem as ConsentVO) + "|%%|";
} else {
MessageBox.Show("일괄인증은 확인저장 서식만 가능합니다. \n확인저장된 서식만 선택해주세요.");
return;
}
}
}
if (shouldPassCert == true) {
checkUserSign();
}
if(result.Length < 1) {
MessageBox.Show("선택된 서식이 없습니다. 서식을 선택하여 주십시요.");
return;
}
result = result.Substring(0, result.Length-4);
consentWebService.SaveAutoCompleteAll(userId, userName, macAddress, result);
btnSearch.PerformClick();
}
}
}