// dclientDlg.cpp : implementation file // #include "stdafx.h" #include "dclient.h" #include #include "dclientDlg.h" #include "ConnList.h" #include "ResLog.h" #include "AbortDlg.h" #include "ViewAss.h" #include "UIDList.h" #include "AssDlg.h" #include "PortDlg.h" #include "FindP.h" #include "FindS.h" #include "EncScur.h" #include "InfoScu.h" #include "AuthScur.h" #include "leadraster.h" #include "DicomNetSink.h" extern CDclientApp theApp; #define IDC_TIMER 800 #ifndef COMMAND_STATUS_PENDING #define COMMAND_STATUS_PENDING 0xFF00 #endif const WCHAR BASED_CODE _szLicString[] = L"LEADTOOLS OCX Copyright (c) 1991-2004 LEAD Technologies, Inc."; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif static UINT MSGBITMAPS[] = { IDB_SEND, IDB_RECEIVE, IDB_ITEM, }; ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDclientDlg dialog CDclientDlg::CDclientDlg(CWnd* pParent /*=NULL*/) : CDialog(CDclientDlg::IDD, pParent) { //{{AFX_DATA_INIT(CDclientDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hParent=NULL; m_hMsgParent=NULL; m_hKey=0; m_hDisplay=0; m_pLEADDicomNet1=NULL; m_pLEADDicomNet2=NULL; m_pReceiveDS=NULL; m_pLEADDicomDS1=NULL; m_pLEADDicomDS2=NULL; m_pLEADDicomCS=NULL; } void CDclientDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDclientDlg) DDX_Control(pDX, IDC_PROGRESS, m_Progress); DDX_Control(pDX, IDC_RESULTSLIST, m_ResultsList); DDX_Control(pDX, IDC_ABSTRACTLIST, m_AbstractList); DDX_Control(pDX, IDC_KEYVIEW, m_KeyView); DDX_Control(pDX, IDC_MSGLIST, m_MsgList); DDX_Control(pDX, IDC_FINDRESULTS, m_FindResults); DDX_Control(pDX, IDC_LEADRASTERVIEW1, m_LEADRasterView1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDclientDlg, CDialog) //{{AFX_MSG_MAP(CDclientDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_COMMAND(ID_PREFERENCES_VIEWMESSAGES, OnPreferencesViewmessages) ON_WM_CLOSE() ON_COMMAND(ID_NETWORK_CONNECT, OnNetworkConnect) ON_WM_TIMER() ON_COMMAND(ID_NETWORK_CONNECTIONSTATUS, OnNetworkConnectionstatus) ON_COMMAND(ID_NETWORK_DISCONNECT, OnNetworkDisconnect) ON_COMMAND(ID_NETWORK_RESTMESSAGELOG, OnNetworkRestmessagelog) ON_COMMAND(ID_NETWORK_RESULTSLOG, OnNetworkResultslog) ON_COMMAND(ID_NETWORK_ABORTASSOCIATION, OnNetworkAbortassociation) ON_COMMAND(ID_NETWORK_EXIT, OnNetworkExit) ON_COMMAND(ID_NETWORK_VIEWASSOCIATION, OnNetworkViewassociation) ON_COMMAND(ID_SERVICES_VERIFICATION, OnServicesVerification) ON_COMMAND(ID_SERVICES_STORAGE, OnServicesStorage) ON_COMMAND(ID_PREFERENCES_UIDS, OnPreferencesUids) ON_COMMAND(ID_PREFERENCES_ASSOCIATION, OnPreferencesAssociation) ON_COMMAND(ID_SERVICES_QUERYPATIENTROOT, OnServicesQuerypatientroot) ON_COMMAND(ID_SERVICES_QUERYSTUDYROOT, OnServicesQuerystudyroot) ON_NOTIFY(NM_CLICK, IDC_FINDRESULTS, OnClickFindresults) ON_NOTIFY(NM_DBLCLK, IDC_FINDRESULTS, OnDblclkFindresults) ON_NOTIFY(TVN_SELCHANGED, IDC_FINDRESULTS, OnSelchangedFindresults) ON_NOTIFY(NM_CLICK, IDC_KEYVIEW, OnClickKeyview) ON_NOTIFY(TVN_SELCHANGED, IDC_KEYVIEW, OnSelchangedKeyview) ON_COMMAND(ID_NETWORK_SAVEENTIREDATASET, OnNetworkSaveentiredataset) ON_COMMAND(ID_NETWORK_SAVESELECTEDAS, OnNetworkSaveselectedas) ON_COMMAND(ID_SERVICES_QUERYPATIENTSTUDYONLY, OnServicesQuerypatientstudyonly) ON_COMMAND(ID_PREFERENCES_VIEWFIT, OnPreferencesViewfit) ON_COMMAND(ID_PREFERENCES_VIEWNORMAL, OnPreferencesViewnormal) ON_COMMAND(ID_SERVICES_CANCEL, OnServicesCancel) ON_COMMAND(ID_SECRUTIY_NONSECUREMODE , OnSecureNone) ON_COMMAND(ID_SECRUTIY_ISCLSECUREMODE, OnSecureISCL) ON_COMMAND(ID_SECRUTIY_TLSSECUREMODE , OnSecureTLS) ON_COMMAND(ID_SECRUTIY_SETTINGS, OnSecureSettings) ON_WM_INITMENU() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDclientDlg message handlers BOOL CDclientDlg::OnInitDialog() { short nRet; CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon BSTR lpLic = SysAllocString(_szLicString); ILEADDicomFactory *pFactory=NULL; CoCreateInstance(CLSID_LEADDicomFactory, NULL, CLSCTX_ALL, IID_ILEADDicomFactory, (void**)&pFactory); ILEADDicomKernelPtr pLEADDicomKrn=NULL; pLEADDicomKrn = pFactory->CreateObject("LEADDicomKernel.LEADDicomKernel", lpLic); pLEADDicomKrn->UnlockSupport(L_SUPPORT_MEDICAL, L_KEY_MEDICAL); pLEADDicomKrn->UnlockSupport(L_SUPPORT_MEDICAL_NET, L_KEY_MEDICAL_NET); #if _MSC_VER < 1200 m_pLEADDicomNet1 = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomNet.LEADDicomNet", lpLic); #else ILEADDicomNetPtr spLEADDicomNet1=NULL; spLEADDicomNet1 = pFactory->CreateObject("LEADDicomNet.LEADDicomNet", lpLic); m_pLEADDicomNet1 = spLEADDicomNet1; m_pLEADDicomNet1->AddRef();//because when spLEADDicomNet1 goes out of scope, it will auto Release()! #endif #if _MSC_VER < 1200 m_pLEADDicomNet2 = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomNet.LEADDicomNet", lpLic); #else ILEADDicomNetPtr spLEADDicomNet2=NULL; spLEADDicomNet2 = pFactory->CreateObject("LEADDicomNet.LEADDicomNet", lpLic); m_pLEADDicomNet2 = spLEADDicomNet2; m_pLEADDicomNet2->AddRef();//because when spLEADDicomNet1 goes out of scope, it will auto Release()! #endif #if _MSC_VER < 1200 m_pLEADDicomDS1 = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); #else ILEADDicomDSPtr spLEADDicomDS1=NULL; spLEADDicomDS1 = pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); m_pLEADDicomDS1 = spLEADDicomDS1; m_pLEADDicomDS1->AddRef();//because when spLEADDicomDS1 goes out of scope, it will auto Release()! #endif #if _MSC_VER < 1200 m_pLEADDicomDS2 = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); #else ILEADDicomDSPtr spLEADDicomDS2=NULL; spLEADDicomDS2 = pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); m_pLEADDicomDS2 = spLEADDicomDS2; m_pLEADDicomDS2->AddRef();//because when spLEADDicomDS2 goes out of scope, it will auto Release()! #endif #if _MSC_VER < 1200 m_pLEADDicomCS = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); #else ILEADDicomDSPtr spLEADDicomCS=NULL; spLEADDicomCS = pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); m_pLEADDicomCS = spLEADDicomCS; m_pLEADDicomCS->AddRef();//because when spLEADDicomCS goes out of scope, it will auto Release()! #endif #if _MSC_VER < 1200 m_pReceiveDS = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); #else ILEADDicomDSPtr spRecieveDS=NULL; spRecieveDS = pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); m_pReceiveDS = spRecieveDS; m_pReceiveDS->AddRef();//because when spRecieveDS goes out of scope, it will auto Release()! #endif SysFreeString(lpLic); pFactory->Release();//we are done with this now //Instantiate the sink class and hold a pointer to it. m_pDicomNetSink1 = new CDicomNetSink; m_pDicomNetSink1->m_pDlg = this; m_pDicomNetSink1->m_bSCU = TRUE; //Establish a connection between source and sink. LPUNKNOWN pUnkSink = m_pDicomNetSink1->GetIDispatch(FALSE); AfxConnectionAdvise(m_pLEADDicomNet1, DIID__LEADDicomNetEvents, pUnkSink, FALSE, &m_dwCookie1); m_pDicomNetSink2 = new CDicomNetSink; m_pDicomNetSink2->m_pDlg = this; m_pDicomNetSink2->m_bSCU = FALSE; //Establish a connection between source and sink. pUnkSink = m_pDicomNetSink2->GetIDispatch(FALSE); AfxConnectionAdvise(m_pLEADDicomNet2, DIID__LEADDicomNetEvents, pUnkSink, FALSE, &m_dwCookie2); m_LEADRasterView1.SetPaintSizeMode(PAINTSIZEMODE_FIT); m_pReceiveDS->InitDS(DICOM_CLASS_BASIC_DIRECTORY, 0); // image list for send/receive icons int i; CBitmap Bitmap; m_Image.Create(16, 16, ILC_MASK, 0, sizeof(MSGBITMAPS) / sizeof(MSGBITMAPS[0])); for (i = 0; i < sizeof(MSGBITMAPS) / sizeof(MSGBITMAPS[0]); i++) { Bitmap.LoadBitmap(MSGBITMAPS[i]); m_Image.Add(&Bitmap, (COLORREF)0xFFFFFF); Bitmap.DeleteObject(); } m_MsgList.SetImageList(&m_Image, TVSIL_NORMAL); // disable method errors m_pLEADDicomNet1->EnableMethodErrors = FALSE; m_pLEADDicomNet2->EnableMethodErrors = FALSE; m_pLEADDicomDS1->EnableMethodErrors = FALSE; m_pLEADDicomDS2->EnableMethodErrors = FALSE; m_pLEADDicomCS->EnableMethodErrors = FALSE; m_pReceiveDS->EnableMethodErrors = FALSE; // create the status bar CRect rcStatus; rcStatus.top = 0; rcStatus.bottom = 20;//set height rcStatus.left = 0; rcStatus.right = 10; //width and position are set by Create m_StatusBar.Create( WS_CHILD|WS_VISIBLE | CCS_BOTTOM, rcStatus, this, IDC_STATUSBAR); // size and position the other controls CRect rcDlg; CRect rcFind; CRect rcMsg; GetClientRect(&rcDlg); m_StatusBar.GetWindowRect(&rcStatus); ScreenToClient(&rcStatus); m_FindResults.SetWindowPos(NULL, 0, 0, rcDlg.Width()/2 - 2, rcDlg.Height()/2 - 2, SWP_SHOWWINDOW); m_FindResults.GetWindowRect(&rcFind); m_MsgList.SetWindowPos(NULL, 0, rcFind.bottom-rcFind.top + 2, rcFind.Width(), (rcStatus.top - 2) - (rcFind.bottom-rcFind.top + 2), SWP_SHOWWINDOW); m_MsgList.GetWindowRect(&rcMsg); CRect rcKeyView; m_KeyView.SetWindowPos(NULL, rcDlg.Width()/2 + 2, 0, rcFind.Width(), rcFind.Height() + rcMsg.Height() + 2, SWP_SHOWWINDOW); m_KeyView.GetWindowRect(&rcKeyView); m_LEADRasterView1.SetWindowPos(NULL, rcKeyView.left, 0, rcKeyView.Width(), rcKeyView.Height(), SWP_SHOWWINDOW); m_LEADRasterView1.ShowWindow(SW_HIDE); // startup the network nRet = m_pLEADDicomNet1->StartUp(); //this control will be the SCU or Client nRet = m_pLEADDicomNet2->StartUp(); //this control will be the SCP for the C-STORE sub-operations //are generated by the C-MOVE operation if(nRet != 0) { AfxMessageBox("Error starting network!\nClosing Application!"); EndDialog(nRet); } m_lSent = 0; m_lReceived = 0; int aWidth[4]={250,375,500,-1}; m_StatusBar.SetParts(4,aWidth); m_StatusBar.SetText("Ready", 0,0); m_StatusBar.SetText("Received: 0",1,0); m_StatusBar.SetText("Sent: 0", 2,0); CRect rcProgress; m_StatusBar.GetRect(3, rcProgress); m_Progress.SetParent(&m_StatusBar); m_Progress.MoveWindow(&rcProgress); m_Progress.SetPos(0); // when the program starts, we must load the UID List and Abstract List LoadDefault(); //Security Defaults OnSecureNone(); // init security menu m_lEncrAlgorithmIndex = 1; // DICOM_ISCL_ENCRYPT_DESCBC m_lEncrAlgorithm[0] = DICOM_ISCL_ENCRYPT_NONE; m_lEncrAlgorithm[1] = DICOM_ISCL_ENCRYPT_DESCBC; m_lSigningAlgorithmIndex = 1; // DICOM_ISCL_MAC_MD5 m_lSigningAlgorithm[0] = DICOM_ISCL_MAC_NONE; m_lSigningAlgorithm[1] = DICOM_ISCL_MAC_MD5; m_lSigningAlgorithm[2] = DICOM_ISCL_MAC_DESMAC; m_ISCLAuthKeys[0] = 0x002948231925CEE1; m_ISCLAuthKeys[1] = 0x007990F7B05BDEFF; m_ISCLAuthKeys[2] = 0x16496DF15B32E1E9; m_ISCLAuthKeys[3] = 0x01EB0BB32EB8F03C; m_ISCLAuthKeys[4] = 0x7E87390C0F3E9A24; m_ISCLAuthKeys[5] = 0x305E440D496953B7; m_ISCLAuthKeys[6] = 0x154754DE39E0194D; m_ISCLAuthKeys[7] = 0x4DC8644366FDB1A6; m_lCurrentISCLAuthKey = 2; m_ISCLEncrKeys[0] = 0x701F5D037AD0C209; m_ISCLEncrKeys[1] = 0x12383B251E8D77D4; m_ISCLEncrKeys[2] = 0x63CB6BFC80164345; m_ISCLEncrKeys[3] = 0x323B221326788C0A; m_ISCLEncrKeys[4] = 0x301C0BDB56B53320; m_ISCLEncrKeys[5] = 0x759A235023399878; m_ISCLEncrKeys[6] = 0x6B365CFD3E2CA832; m_ISCLEncrKeys[7] = 0x3BF63A9E79DC56DC; m_lCurrentISCLEncrKey = 2; theApp.m_bValidPrivateKeyPassword = FALSE; theApp.m_strPrivateKeyPassword = ""; return TRUE; // return TRUE unless you set the focus to a control } void CDclientDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CDclientDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CDclientDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CDclientDlg::OnPreferencesViewmessages() { CMenu *pMenu=NULL; // size and position the other controls CRect rcDlg; GetClientRect(&rcDlg); CRect rcStatus; m_StatusBar.GetWindowRect(&rcStatus); ScreenToClient(&rcStatus); pMenu = GetMenu(); if(pMenu) { if(pMenu->GetMenuState(ID_PREFERENCES_VIEWMESSAGES, MF_BYCOMMAND) & MF_CHECKED) { pMenu->CheckMenuItem(ID_PREFERENCES_VIEWMESSAGES, MF_UNCHECKED|MF_BYCOMMAND); m_MsgList.ShowWindow(SW_HIDE); m_FindResults.SetWindowPos(NULL, 0, 0, rcDlg.Width()/2 - 2, rcStatus.top - 2, SWP_SHOWWINDOW|SWP_NOMOVE); } else { pMenu->CheckMenuItem(ID_PREFERENCES_VIEWMESSAGES, MF_CHECKED|MF_BYCOMMAND); m_MsgList.ShowWindow(SW_SHOW); m_FindResults.SetWindowPos(NULL, 0, 0, rcDlg.Width()/2 - 2, rcDlg.Height()/2 - 2, SWP_SHOWWINDOW|SWP_NOMOVE); } } } ////////// ini file stuff ////////////////// void CDclientDlg::GetDefaultFile(CString &strName) { char pszPath[_MAX_PATH]; if (GetModuleFileName(AfxGetInstanceHandle(), pszPath, _MAX_PATH) == 0) { strName = ""; return; } char *p = strrchr(pszPath, '.'); if (p != NULL) { *p = 0; } strName = pszPath; strName += ".ini"; } void CDclientDlg::LoadDefault() { BOOL bResult; short nRet; long i; CFile File; CString strCode; CString strName; long nCount1; long nType; m_nTimeout = 60; m_nConnection = 0; m_pConnection = 0; m_pReceiveDS->DefaultUID(); GetDefaultFile(strName); bResult = File.Open(strName, CFile::modeRead | CFile::typeBinary | CFile::modeNoInherit | CFile::shareDenyWrite); if (bResult == FALSE) { nRet = m_pReceiveDS->MoveFirstUID(); while(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pReceiveDS->GetCurrentUID(); nType = pCurrentUID->GetType(); BSTR bstr = pCurrentUID->GetCode(); strCode = bstr; SysFreeString(bstr); if((nType == DICOM_UID_TYPE_CLASS)||(nType == DICOM_UID_TYPE_META_CLASS))// Is it an Abstract Syntax? m_AbstractList.AddString(strCode); nRet = m_pReceiveDS->MoveNextUID(); } return; } bResult = LoadNumber(&File, &m_nTimeout, sizeof(m_nTimeout)); if (bResult == FALSE) { m_nTimeout = 10; return; } bResult = LoadNumber(&File, &m_nConnection, sizeof(m_nConnection)); if (bResult == FALSE) { MessageBox("Please add at least one server!", "Notice", MB_OK); m_nConnection = 0; return; } if (m_nConnection != 0) { m_pConnection = (pNETCONNECTION)GlobalAllocPtr(GMEM_MOVEABLE, sizeof(NETCONNECTION)*m_nConnection); if (m_pConnection == NULL) { m_nConnection = 0; return; } } if (m_pConnection != NULL) { for (i = 0; i < m_nConnection; i++) { bResult = LoadNumber(&File, &m_pConnection[i], sizeof(NETCONNECTION)); if (bResult == FALSE) { GlobalFreePtr(m_pConnection); m_pConnection = NULL; m_nConnection = 0; return; } } } bResult = LoadNumber(&File, &nCount1, sizeof(nCount1)); if (bResult == FALSE) return; if (nCount1 != 0) { m_pReceiveDS->ResetUID(); for (i = 0; i < nCount1; i++) { bResult = LoadString(&File, strCode); if (bResult == FALSE) { m_pReceiveDS->DefaultUID(); return; } bResult = LoadString(&File, strName); if (bResult == FALSE) { m_pReceiveDS->DefaultUID(); return; } bResult = LoadNumber(&File, &nType, sizeof(nType)); if (bResult == FALSE) { m_pReceiveDS->DefaultUID(); return; } BSTR bstr1=strCode.AllocSysString(); BSTR bstr2=strName.AllocSysString(); nRet = m_pReceiveDS->InsertUID(bstr1, bstr2, nType); SysFreeString(bstr1); SysFreeString(bstr2); if(nRet == 0) { IDicomUIDItemPtr pCurrentUID=NULL; short iType = (short)nType; pCurrentUID = m_pReceiveDS->GetCurrentUID(); pCurrentUID->Type = iType; if((iType == DICOM_UID_TYPE_CLASS)||(iType == DICOM_UID_TYPE_META_CLASS))// Is it an Abstract Syntax? m_AbstractList.AddString(strCode); } } } } BOOL CDclientDlg::LoadString(CFile *File, CString &strText) { long nSize; long nLength; char *pBuffer; nLength = File->Read(&nSize, sizeof(nSize)); if (nLength != sizeof(nSize)) return FALSE; pBuffer = (char *)GlobalAllocPtr(GMEM_MOVEABLE, nSize); if (pBuffer == NULL) return FALSE; nLength = File->Read(pBuffer, nSize); if (nLength != nSize) { GlobalFreePtr(pBuffer); return FALSE; } strText = pBuffer; GlobalFreePtr(pBuffer); return TRUE; } BOOL CDclientDlg::LoadNumber(CFile *File, void *pNumber, long nSize) { long nLength; nLength = File->Read(pNumber, nSize); return (nLength != nSize) ? FALSE : TRUE; } void CDclientDlg::SaveDefault() { CStdioFile File; BOOL bResult; short nRet; long i; CString strName; long nCount1; GetDefaultFile(strName); bResult = File.Open(strName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary | CFile::modeNoInherit | CFile::shareExclusive); if (bResult == FALSE) return; SaveNumber(&File, &m_nTimeout, sizeof(m_nTimeout)); SaveNumber(&File, &m_nConnection, sizeof(m_nConnection)); for (i = 0; i < m_nConnection; i++) { SaveNumber(&File, &m_pConnection[i], sizeof(NETCONNECTION)); } if (m_pConnection != NULL) { GlobalFreePtr(m_pConnection); m_pConnection = NULL; } nCount1 = m_pReceiveDS->GetUIDCount(); SaveNumber(&File, &nCount1, sizeof(nCount1)); nRet = m_pReceiveDS->MoveFirstUID(); while(nRet == 0) { IDicomUIDItemPtr pCurrentUID=NULL; long nType; pCurrentUID = m_pReceiveDS->GetCurrentUID(); BSTR bstr = pCurrentUID->GetCode(); CString cs = bstr; SaveString(&File, cs); SysFreeString(bstr); bstr = pCurrentUID->GetName(); cs = bstr; SaveString(&File, cs); SysFreeString(bstr); nType = pCurrentUID->GetType(); SaveNumber(&File, &nType, sizeof(nType)); nRet = m_pReceiveDS->MoveNextUID(); } } void CDclientDlg::SaveString(CFile *File, CString strText) { long nSize; nSize = strText.GetLength() + 1; File->Write(&nSize, sizeof(nSize)); File->Write((char *)(LPCTSTR)strText, nSize); } void CDclientDlg::SaveString(CFile *File, char *pszText) { long nSize; nSize = strlen(pszText) + 1; File->Write(&nSize, sizeof(nSize)); File->Write(pszText, nSize); } void CDclientDlg::SaveNumber(CFile *File, void *pNumber, long nSize) { File->Write(pNumber, nSize); } //////////////////////////////////////////// void CDclientDlg::OnCancel() { if(m_pLEADDicomNet1) { if(m_pLEADDicomNet1->GethNet() && m_pLEADDicomNet1->IsConnected(m_pLEADDicomNet1->GethNet())) { MessageBox("Please close the connection first!", "Warning", MB_OK); return; } } KillTimer(IDC_TIMER); if(m_pConnection)//no need to do this if we already did OnClose SaveDefault(); CleanUp(); CDialog::OnCancel(); } void CDclientDlg::OnClose() { if(m_pLEADDicomNet1->GethNet() && m_pLEADDicomNet1->IsConnected(m_pLEADDicomNet1->GethNet())) { MessageBox("Please close the connection first!", "Warning", MB_OK); return; } KillTimer(IDC_TIMER); SaveDefault(); CleanUp(); CDialog::OnClose(); } void CDclientDlg::OnNetworkConnect() { CConnectList dlg; m_lSent = 0; m_lReceived = 0; if(m_pLEADDicomNet1->GethNet() && m_pLEADDicomNet1->IsConnected(m_pLEADDicomNet1->GethNet())) { MessageBox("Already Connected!", "Notice", MB_OK); return; } if(!m_pLEADDicomNet1->GethPDU()) { m_pLEADDicomNet1->CreateAssociate(TRUE); OnPreferencesAssociation(); } m_StatusBar.SetText("Ready", 0,0); m_StatusBar.SetText("Received: 0",1,0); m_StatusBar.SetText("Sent: 0", 2,0); m_pReceiveDS->ResetDS(); m_FindResults.DeleteAllItems(); m_KeyView.DeleteAllItems(); m_MsgList.DeleteAllItems(); dlg.m_nTimeout = m_nTimeout; dlg.m_nConnection = m_nConnection; dlg.m_pConnection = m_pConnection; dlg.m_nIndex = m_nIndex; if (dlg.DoModal() != IDOK) return; else { // connect to the remote server m_nTimeout = dlg.m_nTimeout; m_nConnection = dlg.m_nConnection; m_pConnection = dlg.m_pConnection; m_nIndex = dlg.m_nIndex; if(m_nIndex != -1) { StartStatusBar("Connecting to server..."); if (m_pLEADDicomNet1->hNet != 0) m_pLEADDicomNet1->ShutDown(); if(m_pLEADDicomNet1->GethNet() == 0) { CMenu* pMenu=GetMenu(); if(pMenu) { if(pMenu->GetMenuState(ID_SECRUTIY_NONSECUREMODE, MF_BYCOMMAND) & MF_CHECKED) m_pLEADDicomNet1->NetworkSecurityMode = DICOM_SECURE_NONE; if(pMenu->GetMenuState(ID_SECRUTIY_ISCLSECUREMODE, MF_BYCOMMAND) & MF_CHECKED) m_pLEADDicomNet1->NetworkSecurityMode = DICOM_SECURE_ISCL; if(pMenu->GetMenuState(ID_SECRUTIY_TLSSECUREMODE, MF_BYCOMMAND) & MF_CHECKED) m_pLEADDicomNet1->NetworkSecurityMode = DICOM_SECURE_TLS; } if (DICOM_SECURE_NONE == m_pLEADDicomNet1->NetworkSecurityMode) { m_pLEADDicomNet1->StartUp(); } else if(DICOM_SECURE_ISCL == m_pLEADDicomNet1->NetworkSecurityMode) { m_pLEADDicomNet1->SetMutualAuthAlgISCL(m_pLEADDicomNet1->GethNet(), DICOM_ISCL_MUTUAL_AUTH_3P4W); for(int j=1; j<=8; ++j) { if(m_ISCLAuthKeys[j-1]) { COleCurrency cy; cy.m_cur.int64 = m_ISCLAuthKeys[j-1]; COleVariant vCy(cy); m_pLEADDicomNet1->SetMutualAuthKeyISCL(m_pLEADDicomNet1->GethNet(), j, vCy); } } m_pLEADDicomNet1->SetIndexForMutualAuthISCL(m_pLEADDicomNet1->GethNet(), m_lCurrentISCLAuthKey); m_pLEADDicomNet1->SetDefaultEncryptionISCL(m_pLEADDicomNet1->GethNet(), m_lEncrAlgorithm[m_lEncrAlgorithmIndex]); m_pLEADDicomNet1->SetDefaultSigningISCL(m_pLEADDicomNet1->GethNet(), m_lSigningAlgorithm[m_lSigningAlgorithmIndex]); for(j=1; j<=8; ++j) { if(m_ISCLEncrKeys[j-1]) { COleCurrency cy; cy.m_cur.int64 = m_ISCLEncrKeys[j-1]; COleVariant vCy(cy); m_pLEADDicomNet1->SetEncryptKeyISCL(m_pLEADDicomNet1->GethNet(), j, vCy); } } m_pLEADDicomNet1->SetIndexForEncryptISCL(m_pLEADDicomNet1->GethNet(), m_lCurrentISCLEncrKey); m_pLEADDicomNet1->SetMaxMessageLengthISCL(m_pLEADDicomNet1->GethNet(), 1024000); m_pLEADDicomNet1->SetMaxCommBlockLengthISCL(m_pLEADDicomNet1->GethNet(), 8160); COleVariant vBuf("client Ana are mere"); m_pLEADDicomNet1->SetAuthDataISCL(m_pLEADDicomNet1->GethNet(), vBuf, 20); } else if(DICOM_SECURE_TLS == m_pLEADDicomNet1->GetNetworkSecurityMode()) { m_pLEADDicomNet1->StartUp(); m_pLEADDicomNet1->SetCipherToIndexTLS(m_pLEADDicomNet1->GethNet(), 0, DICOM_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA); char szpath[_MAX_PATH]; char szdrive[_MAX_PATH]; char szdir[_MAX_PATH]; CString strPEMPath; GetModuleFileName(AfxGetInstanceHandle(), szpath, _MAX_PATH); _splitpath(szpath, szdrive, szdir, NULL, NULL ); strPEMPath.Format("%s%s%s", szdrive, szdir, "client.pem"); BSTR bstr = strPEMPath.AllocSysString(); BSTR bstrnull = NULL; int nRet = m_pLEADDicomNet1->SetClientCertificateTLS(m_pLEADDicomNet1->GethNet(), bstr, L_TLS_FILETYPE_PEM, bstrnull); // reset the password so reprompted next secure connect if (nRet != 0) { theApp.m_bValidPrivateKeyPassword = FALSE; theApp.m_strPrivateKeyPassword = ""; MessageBox("Error Setting TLS Certificate - Non-Secure", "Error", MB_OK | MB_ICONERROR); m_pLEADDicomNet1->NetworkSecurityMode = DICOM_SECURE_NONE; OnSecureNone(); } else { theApp.m_bValidPrivateKeyPassword = TRUE;; } } } m_pLEADDicomNet1->Connect(m_pConnection[m_nIndex].szHostAddress, 0, m_pConnection[m_nIndex].szPeerAddress, m_pConnection[m_nIndex].nPeerPort); m_szCalledAE = m_pConnection[m_nIndex].szCalled; m_szCallingAE = m_pConnection[m_nIndex].szCalling; m_szServerName = m_pConnection[m_nIndex].szName; RecordMessage(TRUE, "Connect", FALSE, NULL); } } } void CDclientDlg::OnNetworkDisconnect() { if(m_pLEADDicomNet1->GethNet() && m_pLEADDicomNet1->IsConnected(m_pLEADDicomNet1->GethNet())) { CloseClientConnection(); return; } else MessageBox("Client is not Connected!", "Notice", MB_OK); } void CDclientDlg::StartTimer() { m_nTime = GetTickCount() / 1000; m_nDelta = 10; m_Progress.SetPos(0); SetTimer(IDC_TIMER, 100, NULL); } void CDclientDlg::ResetTimer() { m_nTime = GetTickCount() / 1000; } void CDclientDlg::StopTimer() { KillTimer(IDC_TIMER); m_Progress.SetPos(0); } void CDclientDlg::StartStatusBar(CString szText) { m_bWorking=TRUE; m_StatusBar.SetText(szText, 0 ,0); StartTimer(); } void CDclientDlg::StopStatusBar(CString szText) { m_bWorking=FALSE; m_StatusBar.SetText(szText, 0, 0); StopTimer(); } void CDclientDlg::OnTimer(UINT nIDEvent) { if (m_nDelta > 0) { if (m_Progress.OffsetPos(m_nDelta) == 100) { m_nDelta = -10; m_Progress.OffsetPos(m_nDelta); } } else { if (m_Progress.OffsetPos(m_nDelta) == 0) { m_nDelta = 10; m_Progress.OffsetPos(m_nDelta); } } if ((int(GetTickCount()) / 1000 - m_nTime > m_nTimeout) && (m_nTimeout != 0)) { StopTimer(); m_ResultsList.AddString("Operation has Timed Out!"); StopStatusBar("Operation Has Timed Out"); CloseClientConnection(); } CDialog::OnTimer(nIDEvent); } void CDclientDlg::CloseClientConnection() { // close the connection m_FindResults.DeleteAllItems(); m_KeyView.DeleteAllItems(); m_LEADRasterView1.GetRaster().SetBitmap(0); m_pReceiveDS->ResetDS(); m_pReceiveDS->InitDS(DICOM_CLASS_BASIC_DIRECTORY, 0); StopStatusBar("Ready"); if(m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { RecordMessage(TRUE, "Release Request", FALSE, 0); StartStatusBar("Waiting for Release Response..."); m_pLEADDicomNet1->SendReleaseRequest(m_pLEADDicomNet1->GethNet()); } else { RecordMessage(TRUE, "Close", FALSE, 0); m_pLEADDicomNet1->Close(m_pLEADDicomNet1->GethNet()); m_pLEADDicomNet1->ShutDown(); m_ResultsList.AddString("Connection Closed"); } } HTREEITEM CDclientDlg::RecordMessage(BOOL bOutgoing, CString szMsg, BOOL bChild, HTREEITEM hParent) { HTREEITEM hNode=NULL; CString szOut; int nImage=0; szOut = szMsg; if(bOutgoing) nImage = 0; else nImage = 1; if(!bChild) hNode = m_MsgList.InsertItem(szOut, nImage, nImage, TVI_ROOT, TVI_LAST); else hNode = m_MsgList.InsertItem(szOut, nImage, nImage, hParent, TVI_LAST); return hNode; } void CDclientDlg::OnNetworkConnectionstatus() { CString szOut; // test the local computer's connection if (m_pLEADDicomNet1->IsActivated(m_pLEADDicomNet1->GethNet())) szOut = szOut + "Activated: Yes"; else szOut = szOut + "Activated: No"; szOut = szOut + "\n"; if (m_pLEADDicomNet1->GethNet() && m_pLEADDicomNet1->IsConnected(m_pLEADDicomNet1->GethNet())) szOut = szOut + "Connected: Yes"; else szOut = szOut + "Connected: No"; szOut = szOut + "\n"; if (m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) szOut = szOut + "Associated: Yes"; else szOut = szOut + "Associated: No"; MessageBox(szOut, "Client Network Status", MB_OK); } BEGIN_EVENTSINK_MAP(CDclientDlg, CDialog) //{{AFX_EVENTSINK_MAP(CDclientDlg) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CDclientDlg::DisplayAssociate(long hPDU, HTREEITEM hParent) { CString szType; HTREEITEM hNewNode=NULL; HTREEITEM hTempParent=NULL; HTREEITEM hTempParent2=NULL; long x; CString szOut; CString szTemp; CString szTest; short nID; CString szAbstract; long lCount; long y; CString szTransfer; CString szClass; CString szVersion; short nRet; szOut.Format("Version: %d", m_pLEADDicomNet1->GetVersion(hPDU)); //display version hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); BSTR bstr = m_pLEADDicomNet1->GetCalled(hPDU); CString cs = bstr; SysFreeString(bstr); szOut = "Called: " + cs; //display called application hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); bstr = m_pLEADDicomNet1->GetCalling(hPDU); cs = bstr; SysFreeString(bstr); szOut = "Calling: " + cs; //display calling application hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); bstr = m_pLEADDicomNet1->GetApplication(hPDU); cs = bstr; szTest = cs; nRet = m_pLEADDicomDS1->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurUID=NULL; pCurUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurUID->GetName(); CString cs = bstr; SysFreeString(bstr); szOut = "Application Context: " + cs + " - " + szTest; //display application context hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); } else { szOut = "Application Context: - " + szTest; //display application context hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); } //get each Presentation Context for(x=0; xGetPresentationCount(hPDU); x++) { nID = m_pLEADDicomNet1->GetPresentationID(hPDU, x); switch(m_pLEADDicomNet1->GetPresentationResult(hPDU, nID)) { case PDU_ACCEPT_RESULT_SUCCESS: szOut = "Acceptance"; break; case PDU_ACCEPT_RESULT_USER_REJECT: szOut = "User Rejection"; break; case PDU_ACCEPT_RESULT_PROVIDER_REJECT: szOut = "Provider Rejection"; break; case PDU_ACCEPT_RESULT_ABSTRACT_SYNTAX: szOut = "Abstract Syntax Not Supported"; break; case PDU_ACCEPT_RESULT_TRANSFER_SYNTAX: szOut = "Transfer Syntax(es) Not Supported"; break; default: szOut.Format("Unknown Reason - %d", m_pLEADDicomNet1->GetPresentationResult(hPDU, nID)); break; } szTemp.Format("ID: %d - %s", nID, szOut); hNewNode = m_MsgList.InsertItem(szTemp, 2, 2, hParent, TVI_LAST); hTempParent = hNewNode; //each Presentation Context can have one Abstract Syntax BSTR bstr = m_pLEADDicomNet1->GetPresentationAbstract(hPDU, nID); szAbstract = bstr; SysFreeString(bstr); if(szAbstract.GetLength() > 0) { BSTR bstr = szAbstract.AllocSysString(); nRet = m_pLEADDicomDS1->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurUID=NULL; pCurUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurUID->GetName(); CString cs = bstr; SysFreeString(bstr); szOut = "Abstract Syntax: " + cs + " - " + szAbstract; } else szOut = "Abstract Syntax: " + szAbstract; hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent, TVI_LAST); } //each Presentation Context can have one or more Transfer Syntax(es) lCount = m_pLEADDicomNet1->GetTransferCount(hPDU, nID); if(lCount > 0) { for(y=0; yGetTransferSyntax(hPDU, nID, y); szTransfer = bstr; if(szTransfer.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindUID(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurUID=NULL; pCurUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurUID->GetName(); CString cs = bstr; SysFreeString(bstr); szOut = "Transfer Syntax: " + cs + " - " + szTransfer; } else szOut = "Transfer Syntax: - " + szTransfer; hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent, TVI_LAST); } SysFreeString(bstr); } } } szOut = "User Information"; hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); hTempParent = hNewNode; if(m_pLEADDicomNet1->IsMaxLengthEnabled(hPDU)) { szOut.Format("Maximum Length = %ld", m_pLEADDicomNet1->GetMaxLength(hPDU)); hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent, TVI_LAST); } if(m_pLEADDicomNet1->IsImplementClass(hPDU)) { BSTR bstr = m_pLEADDicomNet1->GetImplementClass(hPDU); szClass = bstr; nRet = m_pLEADDicomDS1->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurUID=NULL; pCurUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurUID->GetName(); CString cs = bstr; SysFreeString(bstr); szOut = "Implementation Class: " + cs + " - " + szClass; } else szOut = "Implementation Class: - " + szClass; hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent, TVI_LAST); } if(m_pLEADDicomNet1->IsAsyncOperations(hPDU)) { szOut = "Asynchronous Operations"; hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent, TVI_LAST); hTempParent2 = hNewNode; szOut.Format("Invoked Operations: %ld", m_pLEADDicomNet1->GetInvokedOperationsCount(hPDU)); hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent2, TVI_LAST); szOut.Format("Performed Operations: %ld", m_pLEADDicomNet1->GetPerformedOperationsCount(hPDU)); hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent2, TVI_LAST); } if(m_pLEADDicomNet1->IsImplementVersion(hPDU)) { BSTR bstr = m_pLEADDicomNet1->GetImplementVersion(hPDU); szVersion = bstr; SysFreeString(bstr); szOut = "Implementation Version: " + szVersion; hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent, TVI_LAST); } lCount = m_pLEADDicomNet1->GetUserInfoCount(hPDU); if(lCount > 0) { for(y=0; yGetUserInfoType(hPDU, y), m_pLEADDicomNet1->GetUserInfoLength(hPDU, y)); hNewNode = m_MsgList.InsertItem(szOut, 2, 2, hTempParent, TVI_LAST); } } } void CDclientDlg::OnNetworkRestmessagelog() { m_ResultsList.ResetContent(); m_lSent = 0; m_lReceived = 0; m_MsgList.DeleteAllItems(); m_hMsgParent=NULL; m_StatusBar.SetText("Ready", 0,0); m_StatusBar.SetText("Received: 0",1,0); m_StatusBar.SetText("Sent: 0", 2,0); } void CDclientDlg::OnNetworkResultslog() { CResultsLog dlg; dlg.m_pResList = &m_ResultsList; dlg.DoModal(); if(dlg.m_bClear) m_ResultsList.ResetContent(); } void CDclientDlg::OnNetworkAbortassociation() { CAbortDlg dlg; if(!m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { MessageBox("Connection Not Associated!", "Notice", MB_OK); return; } // let user pick Abort Parameters if(dlg.DoModal() == IDOK) { // send Abort message to server m_pLEADDicomNet1->SendAbort(m_pLEADDicomNet1->GethNet(), dlg.m_nSource, dlg.m_nReason); m_ResultsList.AddString("Abort Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "Abort", FALSE, NULL); } } void CDclientDlg::OnNetworkExit() { if(m_pLEADDicomNet1->GethNet() && m_pLEADDicomNet1->IsConnected(m_pLEADDicomNet1->GethNet())) { MessageBox("Please close the connection first!", "Warning", MB_OK); return; } OnClose(); DestroyWindow(); } void CDclientDlg::OnNetworkViewassociation() { CViewAssociate AssDlg; long hNet=0; long hPDU=0; hNet = m_pLEADDicomNet1->GethNet(); if(m_pLEADDicomNet1->IsAssociated(hNet)) hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(hPDU) { AssDlg.m_hPDU = hPDU; AssDlg.DoModal(); } else { MessageBox("Connection Not Associated!", "Notice", MB_OK); return; } } void CDclientDlg::OnServicesVerification() { short nRet; long hPDU; CString szUID; CString szOut; if(!m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(hPDU == 0) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } //send an Echo Request Command to the server szUID = UID_VERIFICATION_CLASS; BSTR bstr = szUID.AllocSysString(); m_pLEADDicomDS1->FindUID(bstr); m_CancelPresentationID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if((m_CancelPresentationID == 0) || (m_pLEADDicomNet1->GetPresentationResult(hPDU, m_CancelPresentationID) != PDU_ACCEPT_RESULT_SUCCESS)) { IDicomUIDItemPtr pCurrentUID=m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurrentUID->GetName(); CString cs = bstr; SysFreeString(bstr); m_ResultsList.AddString("Abstract Syntax, " + cs + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + cs + ", Not Supported by Association!", "Notice", MB_OK); return; } //now, use the high-level method to send the command set bstr = szUID.AllocSysString(); nRet = m_pLEADDicomNet1->SendCEchoRequest(m_pLEADDicomNet1->GethNet(), m_CancelPresentationID, 1, bstr); SysFreeString(bstr); m_CancelMessageID = 1; if(nRet != 0) { szOut.Format("C-ECHO-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for ECHO Response..."); m_ResultsList.AddString("Echo Request Command Set Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "C-ECHO-RQ", FALSE, NULL); } } void CDclientDlg::DisplayCommandSet(HTREEITEM hParent) { short nRet; HTREEITEM hNode=NULL; CString szText; long lCount; long x; CString szTemp; //move to root of tree nRet = m_pLEADDicomCS->MoveFirstElement(FALSE); //move to first Element in Data Set if(nRet != 0) { MessageBox("Error Reading Data Set!", "Error", MB_OK); return; } while(nRet == 0) { //add the node to the tree IDicomDSElementPtr pCurrentElement = m_pLEADDicomCS->GetCurrentElement(); nRet = m_pLEADDicomCS->FindTag(pCurrentElement->GetTag()); if(nRet == 0) { ILEADDicomTagPtr pCurrentTag = m_pLEADDicomCS->GetCurrentTag(); BSTR bstr = pCurrentTag->GetName(); szText = bstr; SysFreeString(bstr); } else szText = "Item"; //get the values and display them if(pCurrentElement->GetLength() < 10000) // I don't display anything > 10K { nRet = m_pLEADDicomCS->GetConvertValue(); szText = szText + ": "; if(nRet == 0) { lCount = m_pLEADDicomCS->GetStringValueCount(); for(x=0; xGetStringValues(x); CString cs = bstr; SysFreeString(bstr); szText = szText + cs; if(x != lCount - 1) szText = szText + ", "; } } } else szText = szText + ": Value too large to display!"; hNode = m_MsgList.InsertItem(szText, 2, 2, hParent, TVI_LAST); //move to next node in same level (if one) nRet = m_pLEADDicomCS->MoveNextElement(FALSE); } } void CDclientDlg::OnServicesStorage() { short nRet; long hPDU; short nID; CString szClassUID; CString szInstanceUID; CString szOut; //send a store request to the server if(!m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(hPDU == 0) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } //pick the data set to send // m_LEADDlg1.SetFilter("AllFiles (*.*)|*.*|Dicom Files (*.dic)|*.dic"); // m_LEADDlg1.SetUIFlags(0); // m_LEADDlg1.SetDialogTitle("Pick a Dicom Data Set"); // m_LEADDlg1.SetEnableMethodErrors(FALSE); // nRet = m_LEADDlg1.FileOpen((long)this->m_hWnd); CFileDialog MSCommDlg(TRUE); MSCommDlg.m_ofn.lpstrTitle = "Pick a Dicom Data Set"; // if(nRet==0) if(MSCommDlg.DoModal()==IDOK) { //load the data set // nRet = m_pLEADDicomDS1->LoadDS(m_LEADDlg1.GetFileName(), 0); BSTR bstr = MSCommDlg.GetFileName().AllocSysString(); nRet = m_pLEADDicomDS1->LoadDS(bstr, 0); SysFreeString(bstr); if(nRet != 0) { MessageBox("Error Loading Data Set!", "Error", MB_OK); szOut.Format("Error Loading Data Set - %d", nRet); m_ResultsList.AddString(szOut); return; } nRet = m_pLEADDicomDS1->FindFirstElement(TAG_SOP_INSTANCE_UID, FALSE); if(nRet == 0) { nRet = m_pLEADDicomDS1->GetStringValue(0, 1); if(nRet == 0) { BSTR bstr = m_pLEADDicomDS1->GetStringValues(0); szInstanceUID = bstr; SysFreeString(bstr); } } if(nRet != 0) { MessageBox("Error - Data Set does not contain SOP Instance UID", "Error", MB_OK); m_ResultsList.AddString("Error - Data Set does not contain SOP Instance UID"); return; } nRet = m_pLEADDicomDS1->MoveFirstElement(FALSE); nRet = m_pLEADDicomDS1->FindFirstElement(TAG_SOP_CLASS_UID, FALSE); if(nRet == 0) { nRet = m_pLEADDicomDS1->GetStringValue(0, 1); if(nRet == 0) { BSTR bstr = m_pLEADDicomDS1->GetStringValues(0); szClassUID = bstr; SysFreeString(bstr); } } if(nRet != 0) { MessageBox("Error - Data Set does not contain SOP Class UID", "Error", MB_OK); m_ResultsList.AddString("Error - Data Set does not contain SOP Class UID"); return; } //send the command set bstr = szClassUID.AllocSysString(); nID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if(nID == 0) { BSTR bstr = szClassUID.AllocSysString(); nRet = m_pLEADDicomDS1->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurrentUID->GetName(); CString cs = bstr; SysFreeString(bstr); m_ResultsList.AddString("Abstract Syntax, " + cs + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + cs + ", Not Supported by Association!", "Error", MB_OK); } else { m_ResultsList.AddString("Abstract Syntax, " + szClassUID + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + szClassUID + ", Not Supported by Association!", "Error", MB_OK); } return; } BSTR bstr1 = szClassUID.AllocSysString(); BSTR bstr2 = szInstanceUID.AllocSysString(); nRet = m_pLEADDicomNet1->SendCStoreRequest(m_pLEADDicomNet1->GethNet(), nID, 1, bstr1, bstr2, COMMAND_PRIORITY_MEDIUM, "", 0, m_pLEADDicomDS1->GethDicomDS()); SysFreeString(bstr1); SysFreeString(bstr2); if(nRet != 0) { szOut.Format("C-STORE-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for STORE Response..."); m_ResultsList.AddString("Store Request Command Set Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "C-STORE-RQ", FALSE, NULL); } m_pLEADDicomDS1->ResetDS(); } } void CDclientDlg::OnPreferencesUids() { CUIDList dlg; dlg.m_pAbstractList = &m_AbstractList; dlg.DoModal(); } void CDclientDlg::OnPreferencesAssociation() { CAssociateDlg AssReqDlg; if(m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { m_ResultsList.AddString("Already Associated!"); MessageBox("Already Associated!", "Notice", MB_OK); return; } //set called and calling AssReqDlg.m_hPDU = m_pLEADDicomNet1->GethPDU(); BSTR bstr1 = m_szCalledAE.AllocSysString(); BSTR bstr2 = m_szCallingAE.AllocSysString(); m_pLEADDicomNet1->SetCalled(m_pLEADDicomNet1->GethPDU(), bstr1); m_pLEADDicomNet1->SetCalling(m_pLEADDicomNet1->GethPDU(), bstr2); m_pLEADDicomNet1->SetApplication(m_pLEADDicomNet1->GethPDU(), UID_APPLICATION_CONTEXT_NAME); //display dialog box AssReqDlg.m_hPDU = m_pLEADDicomNet1->GethPDU(); AssReqDlg.m_pAbstractList = &m_AbstractList; if(AssReqDlg.DoModal() != IDOK) { //set called and calling m_pLEADDicomNet1->SetCalled(m_pLEADDicomNet1->GethPDU(), bstr1); m_pLEADDicomNet1->SetCalling(m_pLEADDicomNet1->GethPDU(), bstr2); m_pLEADDicomNet1->SetApplication(m_pLEADDicomNet1->GethPDU(), UID_APPLICATION_CONTEXT_NAME); } SysFreeString(bstr1); SysFreeString(bstr2); } void CDclientDlg::OnServicesQuerypatientroot() { short nRet; CString szUID; long hPDU; CFindPatient dlg; m_FindResults.DeleteAllItems(); m_KeyView.DeleteAllItems(); m_pReceiveDS->ResetDS(); m_pReceiveDS->InitDS(DICOM_CLASS_BASIC_DIRECTORY, 0); m_hParent = NULL; m_hMsgParent = NULL; m_hKey = 0; m_hDisplay = 0; m_bPatientLevel = TRUE; m_bPatientStudyOnly = FALSE; if(!m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(!hPDU) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } szUID = UID_PATIENT_ROOT_QUERY_FIND; BSTR bstr = szUID.AllocSysString(); m_CancelPresentationID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if((m_CancelPresentationID == 0) || (m_pLEADDicomNet1->GetPresentationResult(hPDU, m_CancelPresentationID) != PDU_ACCEPT_RESULT_SUCCESS)) { BSTR bstr = szUID.AllocSysString(); nRet = m_pLEADDicomDS1->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurrentUID->GetName(); CString cs = bstr; SysFreeString(bstr); m_ResultsList.AddString("Abstract Syntax, " + cs + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + cs + ", Not Supported by Association!", "Error", MB_OK); } else { m_ResultsList.AddString("Abstract Syntax, " + szUID + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + szUID + ", Not Supported by Association!", "Error", MB_OK); } return; } //create a find attribute data set m_pLEADDicomDS1->ResetDS(); m_pLEADDicomDS1->InitDS(DICOM_CLASS_PATIENT_ROOT_QUERY_PATIENT, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); //add the required fields for this seach nRet = m_pLEADDicomDS1->FindFirstElement(TAG_QUERY_RETRIEVE_LEVEL, TRUE); m_pLEADDicomDS1->StringValueCount = 1; m_pLEADDicomDS1->StringValues[0] = "PATIENT"; //we are searching at the patient level m_pLEADDicomDS1->SetStringValue(1); //get the user input if(dlg.DoModal() != IDOK) return; //set the search if(dlg.m_sz1.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_NAME, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_NAME, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = dlg.m_sz1.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; m_pLEADDicomDS1->SetStringValue(1); SysFreeString(bstr); } if(dlg.m_sz2.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_ID, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_ID, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = dlg.m_sz2.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; m_pLEADDicomDS1->SetStringValue(1); SysFreeString(bstr); } m_nFindType = COMMAND_C_FIND_PATIENT_ROOT; m_CancelMessageID = 1; nRet = m_pLEADDicomNet1->SendCFindRequest(m_pLEADDicomNet1->GethNet(), m_CancelPresentationID, m_CancelMessageID, UID_PATIENT_ROOT_QUERY_FIND, COMMAND_PRIORITY_MEDIUM, m_pLEADDicomDS1->GethDicomDS()); if(nRet != 0) { CString szOut; szOut.Format("C-FIND-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for FIND Response..."); m_ResultsList.AddString("Find Request Command Set Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "C-FIND-RQ", FALSE, NULL); } } void CDclientDlg::OnServicesQuerystudyroot() { short nRet; CString szUID; long hPDU; CFindStudy dlg; m_FindResults.DeleteAllItems(); m_KeyView.DeleteAllItems(); m_pReceiveDS->ResetDS(); m_pReceiveDS->InitDS(DICOM_CLASS_BASIC_DIRECTORY, 0); m_hParent = NULL; m_hMsgParent = NULL; m_hKey = 0; m_hDisplay = 0; m_bPatientLevel = FALSE; m_bPatientStudyOnly = FALSE; if(!m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(!hPDU) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } szUID = UID_STUDY_ROOT_QUERY_FIND; BSTR bstr = szUID.AllocSysString(); m_CancelPresentationID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if((m_CancelPresentationID == 0) || (m_pLEADDicomNet1->GetPresentationResult(hPDU, m_CancelPresentationID) != PDU_ACCEPT_RESULT_SUCCESS)) { BSTR bstr = szUID.AllocSysString(); nRet = m_pLEADDicomDS1->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurrentUID->GetName(); CString cs = bstr; SysFreeString(bstr); m_ResultsList.AddString("Abstract Syntax, " + cs + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + cs + ", Not Supported by Association!", "Error", MB_OK); } else { m_ResultsList.AddString("Abstract Syntax, " + szUID + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + szUID + ", Not Supported by Association!", "Error", MB_OK); } return; } //create a find attribute data set m_pLEADDicomDS1->ResetDS(); m_pLEADDicomDS1->InitDS(DICOM_CLASS_STUDY_ROOT_QUERY_STUDY, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); //add the required fields for this seach nRet = m_pLEADDicomDS1->FindFirstElement(TAG_QUERY_RETRIEVE_LEVEL, TRUE); m_pLEADDicomDS1->StringValueCount = 1; m_pLEADDicomDS1->StringValues[0] = "STUDY"; //we are searching at the study level m_pLEADDicomDS1->SetStringValue(1); //get the user input if(dlg.DoModal() != IDOK) return; //set the search if(dlg.m_sz1.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_STUDY_INSTANCE_UID, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_STUDY_INSTANCE_UID, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount= 1; BSTR bstr = dlg.m_sz1.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } if(dlg.m_sz2.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_STUDY_ID, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_STUDY_ID, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = dlg.m_sz2.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } if(dlg.m_sz3.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_ACCESSION_NUMBER, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_ACCESSION_NUMBER, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = dlg.m_sz3.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } if(dlg.m_sz4.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_NAME, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_NAME, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = dlg.m_sz4.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } if(dlg.m_sz5.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_ID, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_ID, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = dlg.m_sz5.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } m_nFindType = COMMAND_C_FIND_STUDY_ROOT; m_CancelMessageID = 1; nRet = m_pLEADDicomNet1->SendCFindRequest(m_pLEADDicomNet1->GethNet(), m_CancelPresentationID, m_CancelMessageID, UID_STUDY_ROOT_QUERY_FIND, COMMAND_PRIORITY_MEDIUM, m_pLEADDicomDS1->GethDicomDS()); if(nRet != 0) { CString szOut; szOut.Format("C-FIND-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for FIND Response..."); m_ResultsList.AddString("Find Request Command Set Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "C-FIND-RQ", FALSE, NULL); } } void CDclientDlg::OnServicesQuerypatientstudyonly() { short nRet; CString szUID; long hPDU; CFindPatient dlg; m_FindResults.DeleteAllItems(); m_KeyView.DeleteAllItems(); m_pReceiveDS->ResetDS(); m_pReceiveDS->InitDS(DICOM_CLASS_BASIC_DIRECTORY, 0); m_hParent = NULL; m_hMsgParent = NULL; m_hKey = 0; m_hDisplay = 0; m_bPatientLevel = TRUE; m_bPatientStudyOnly = TRUE; if(!m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(!hPDU) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } szUID = UID_PATIENT_STUDY_QUERY_FIND; BSTR bstr = szUID.AllocSysString(); m_CancelPresentationID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if((m_CancelPresentationID == 0) || (m_pLEADDicomNet1->GetPresentationResult(hPDU, m_CancelPresentationID) != PDU_ACCEPT_RESULT_SUCCESS)) { BSTR bstr = szUID.AllocSysString(); nRet = m_pLEADDicomDS1->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurrentUID->GetName(); CString cs = bstr; SysFreeString(bstr); m_ResultsList.AddString("Abstract Syntax, " + cs + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + cs + ", Not Supported by Association!", "Error", MB_OK); } else { m_ResultsList.AddString("Abstract Syntax, " + szUID + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + szUID + ", Not Supported by Association!", "Error", MB_OK); } return; } //create a find attribute data set m_pLEADDicomDS1->ResetDS(); m_pLEADDicomDS1->InitDS(DICOM_CLASS_PATIENT_STUDY_QUERY_PATIENT, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); //add the required fields for this seach nRet = m_pLEADDicomDS1->FindFirstElement(TAG_QUERY_RETRIEVE_LEVEL, TRUE); m_pLEADDicomDS1->StringValueCount = 1; m_pLEADDicomDS1->StringValues[0] = "PATIENT"; //we are searching at the patient level m_pLEADDicomDS1->SetStringValue(1); //get the user input if(dlg.DoModal() != IDOK) return; //set the search if(dlg.m_sz1.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_NAME, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_NAME, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = dlg.m_sz1.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } if(dlg.m_sz2.GetLength() > 0) { nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_ID, FALSE); if(nRet != 0) m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_ID, 0, FALSE, 0); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = dlg.m_sz2.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } m_nFindType = COMMAND_C_FIND_PATIENT_STUDY_ONLY; m_CancelMessageID = 1; bstr = szUID.AllocSysString(); nRet = m_pLEADDicomNet1->SendCFindRequest(m_pLEADDicomNet1->GethNet(), m_CancelPresentationID, m_CancelMessageID, bstr, COMMAND_PRIORITY_MEDIUM, m_pLEADDicomDS1->GethDicomDS()); SysFreeString(bstr); if(nRet != 0) { CString szOut; szOut.Format("C-FIND-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for FIND Response..."); BSTR bstr = m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet()); CString cs = bstr; SysFreeString(bstr); m_ResultsList.AddString("Find Request Command Set Sent - " + cs); RecordMessage(TRUE, "C-FIND-RQ", FALSE, NULL); } } void CDclientDlg::OnClickFindresults(NMHDR* pNMHDR, LRESULT* pResult) { HTREEITEM hNodeX=NULL; long hTemp; short nRet; long hElement=0; CString szKey; if(m_bWorking) return; hNodeX = m_FindResults.GetSelectedItem(); if(hNodeX) { hElement = (long) m_FindResults.GetItemData(hNodeX); if(hElement != m_hDisplay) { m_hDisplay = hElement; m_pReceiveDS->SetCurrentElement(hElement); m_KeyView.DeleteAllItems(); BSTR bstr = m_pReceiveDS->GetKeyValue(); szKey = bstr; SysFreeString(bstr); if(szKey == "IMAGE") //try to display the image { nRet = m_pReceiveDS->MoveChildElement(); if(nRet == 0) { //find the image nRet = m_pReceiveDS->FindFirstElement(TAG_ICON_IMAGE_SEQUENCE, TRUE); if(nRet == 0) { nRet = m_pReceiveDS->MoveChildElement(); nRet = m_pReceiveDS->MoveChildElement(); if(nRet == 0) { nRet = m_pReceiveDS->FindFirstElement(TAG_PIXEL_DATA, TRUE); if(nRet == 0) { DisplayImageData(); return; } } } } } m_LEADRasterView1.ShowWindow(SW_HIDE); m_KeyView.ShowWindow(SW_SHOW); m_pReceiveDS->SetCurrentElement(hElement); nRet = m_pReceiveDS->MoveChildElement(); while(nRet == 0) { IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); hTemp = pCurrentElement->GethElement(); DisplayKey(hTemp, NULL); m_pReceiveDS->SetCurrentElement(hTemp); nRet = m_pReceiveDS->MoveNextElement(TRUE); } } } *pResult = 0; } void CDclientDlg::DisplayKey(long hElement, HTREEITEM hParent) { short nRet; CString szTag; HTREEITEM hNodeX=NULL; CString szName; long hTemp; CString szVal; long lCount; long x; m_LEADRasterView1.ShowWindow(SW_HIDE); m_KeyView.ShowWindow(SW_SHOW); x = 0; hTemp = hElement; m_pReceiveDS->SetCurrentElement(hElement); IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); szTag.Format("%04X:%04X", GETGROUP(pCurrentElement->GetTag()), GETELEMENT(pCurrentElement->GetTag())); nRet = m_pReceiveDS->FindTag(pCurrentElement->GetTag()); szName = "Unknown"; if(nRet == 0) { ILEADDicomTagPtr pCurrentTag = m_pReceiveDS->GetCurrentTag(); BSTR bstr = pCurrentTag->GetName(); szName = bstr; SysFreeString(bstr); } //display value(s) szVal = ""; if(pCurrentElement->GetTag() != TAG_PIXEL_DATA) { if(pCurrentElement->GetLength() < 10000)// I don't display anything > 10K { szVal = ": "; if(m_pReceiveDS->GetValueCount()>0) { nRet = m_pReceiveDS->GetConvertValue(); if (nRet == 0) { lCount = m_pReceiveDS->GetStringValueCount(); for(x=0; xStringValues[x]; CString cs = bstr; SysFreeString(bstr); szVal = szVal + cs; if (x < lCount - 1) szVal = szVal + " \\ "; } } } } else szVal = ": Value too large to display!"; } if (hParent) hNodeX = m_KeyView.InsertItem(szTag + " - " + szName + szVal, 0, 0, hParent, TVI_LAST); else hNodeX = m_KeyView.InsertItem(szTag + " - " + szName + szVal, 0, 0, TVI_ROOT, TVI_LAST); m_KeyView.SetItemData(hNodeX, hElement); hParent = hNodeX; pCurrentElement = m_pReceiveDS->GetCurrentElement(); nRet = m_pReceiveDS->MoveChildElement(); if (nRet == 0) { hTemp = pCurrentElement->GethElement(); DisplayKey(hTemp, hParent); m_pReceiveDS->SetCurrentElement(hTemp); } else m_pReceiveDS->SetCurrentElement(hTemp); } void CDclientDlg::OnDblclkFindresults(NMHDR* pNMHDR, LRESULT* pResult) { HTREEITEM hNodeX=NULL; HTREEITEM hTemp=NULL; short nRet; CString szKey; long hElement; hNodeX = m_FindResults.GetSelectedItem(); if(hNodeX) { UINT uState; uState = m_FindResults.GetItemState(hNodeX, TVIS_BOLD); if((uState&TVIS_BOLD) != TVIS_BOLD) return;//nothing to do, data has already been retrieved hElement = (long)m_FindResults.GetItemData(hNodeX); m_pReceiveDS->SetCurrentElement(hElement); BSTR bstr = m_pReceiveDS->GetKeyValue(); szKey = bstr; SysFreeString(bstr); //first, delete all current sub keys nRet = m_pReceiveDS->MoveChildKey(); while(nRet == 0) { m_pReceiveDS->DeleteKey(); m_pReceiveDS->SetCurrentElement(hElement); nRet = m_pReceiveDS->MoveNextKey(TRUE); } m_pReceiveDS->SetCurrentElement(hElement); //delete the nodes from the TreeView m_hParent = hNodeX; HTREEITEM hChild=NULL; hChild = m_FindResults.GetChildItem(hNodeX); if(hChild) m_FindResults.DeleteItem(hChild); m_hKey = hElement; m_pReceiveDS->MoveChildElement(); //move to the first child of this key if(szKey == "PATIENT") { if(m_bPatientStudyOnly) FindAllStudy(UID_PATIENT_STUDY_QUERY_FIND); else FindAllStudy(UID_PATIENT_ROOT_QUERY_FIND); } else if(szKey == "STUDY") { //must send C-FIND to find all "SERIES" for this "STUDY" //now, we can send the command and wait for the results if(m_bPatientLevel) FindAllSeries(UID_PATIENT_ROOT_QUERY_FIND); else FindAllSeries(UID_STUDY_ROOT_QUERY_FIND); } else if(szKey == "SERIES") { //must send C-FIND to find all "IMAGE" for this "SERIES" //now, we can send the command and wait for the results if(m_bPatientLevel) FindAllImage(UID_PATIENT_ROOT_QUERY_FIND); else FindAllImage(UID_STUDY_ROOT_QUERY_FIND); } else if(szKey == "IMAGE") { //now, we need to send C-MOVE to actually get the IMAGE data SendCMoveCommand(); } } *pResult = 0; } void CDclientDlg::OnSelchangedFindresults(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; HTREEITEM hNodeX=NULL; long hTemp; short nRet; long hElement=0; CString szKey; if(m_bWorking) return; m_LEADRasterView1.ShowWindow(SW_HIDE); m_KeyView.ShowWindow(SW_SHOW); hNodeX = m_FindResults.GetSelectedItem(); if(hNodeX) { hElement = (long) m_FindResults.GetItemData(hNodeX); if(hElement != m_hDisplay) { m_hDisplay = hElement; m_pReceiveDS->SetCurrentElement(hElement); m_KeyView.DeleteAllItems(); BSTR bstr = m_pReceiveDS->GetKeyValue(); szKey = bstr; SysFreeString(bstr); if(szKey == "IMAGE") //try to display the image { nRet = m_pReceiveDS->MoveChildElement(); if(nRet == 0) { //find the image nRet = m_pReceiveDS->FindFirstElement(TAG_ICON_IMAGE_SEQUENCE, TRUE); if(nRet == 0) { nRet = m_pReceiveDS->MoveChildElement(); nRet = m_pReceiveDS->MoveChildElement(); if(nRet == 0) { nRet = m_pReceiveDS->FindFirstElement(TAG_PIXEL_DATA, TRUE); if(nRet == 0) { DisplayImageData(); return; } } } } } m_pReceiveDS->SetCurrentElement(hElement); nRet = m_pReceiveDS->MoveChildElement(); while(nRet == 0) { IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); hTemp = pCurrentElement->GethElement(); DisplayKey(hTemp, NULL); m_pReceiveDS->SetCurrentElement(hTemp); nRet = m_pReceiveDS->MoveNextElement(TRUE); } } } *pResult = 0; } void CDclientDlg::FindAllStudy(CString szUID) { short nRet; long hPDU; CString szOut; CString szVal; if(!m_pLEADDicomNet1->IsAssociated(m_pLEADDicomNet1->GethNet())) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(hPDU == 0) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } BSTR bstr = szUID.AllocSysString(); m_CancelPresentationID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if((m_CancelPresentationID == 0) || (m_pLEADDicomNet1->GetPresentationResult(hPDU, m_CancelPresentationID) != PDU_ACCEPT_RESULT_SUCCESS)) { m_ResultsList.AddString("Abstract Syntax, " + szUID + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + szUID + ", Not Supported by Association!", "Error", MB_OK); return; } //create a find attribute data set m_pLEADDicomDS1->ResetDS(); if(szUID == UID_PATIENT_ROOT_QUERY_FIND) m_pLEADDicomDS1->InitDS(DICOM_CLASS_PATIENT_ROOT_QUERY_STUDY, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); else if(szUID == UID_PATIENT_STUDY_QUERY_FIND) m_pLEADDicomDS1->InitDS(DICOM_CLASS_PATIENT_STUDY_QUERY_STUDY, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); //add the required fields for this seach nRet = m_pLEADDicomDS1->FindFirstElement(TAG_QUERY_RETRIEVE_LEVEL, TRUE); m_pLEADDicomDS1->StringValueCount = 1; m_pLEADDicomDS1->StringValues[0] = "STUDY"; //we are searching at the study level m_pLEADDicomDS1->SetStringValue(1); nRet = m_pReceiveDS->FindFirstElement(TAG_PATIENT_ID, TRUE); nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_ID, FALSE); if(nRet != 0) nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_ID, 0, FALSE, 0); nRet = m_pReceiveDS->GetStringValue(0, 1); if(nRet == 0) { BSTR bstr = m_pReceiveDS->GetStringValues(0); szVal = bstr; SysFreeString(bstr); } else { MessageBox("Error, no Patient ID", "Error", MB_OK); return; } m_pLEADDicomDS1->StringValueCount = 1; bstr = szVal.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); m_nFindType = COMMAND_C_FIND_STUDY; m_CancelMessageID = 1; bstr = szUID.AllocSysString(); nRet = m_pLEADDicomNet1->SendCFindRequest(m_pLEADDicomNet1->GethNet(), m_CancelPresentationID, m_CancelMessageID, bstr, COMMAND_PRIORITY_MEDIUM, m_pLEADDicomDS1->GethDicomDS()); SysFreeString(bstr); if(nRet != 0) { CString szOut; szOut.Format("C-FIND-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for FIND Response..."); m_ResultsList.AddString("Find Request Command Set Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "C-FIND-RQ", FALSE, NULL); } } void CDclientDlg::FindAllSeries(CString szUID) { short nRet; long hPDU; CString szOut; CString szVal; long hTemp; hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(hPDU == 0) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } BSTR bstr = szUID.AllocSysString(); m_CancelPresentationID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if ((m_CancelPresentationID == 0) || (m_pLEADDicomNet1->GetPresentationResult(hPDU, m_CancelPresentationID) != PDU_ACCEPT_RESULT_SUCCESS)) { m_ResultsList.AddString("Abstract Syntax, " + szUID + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + szUID + ", Not Supported by Association!"); return; } //create a find attribute data set m_pLEADDicomDS1->ResetDS(); if(szUID == UID_STUDY_ROOT_QUERY_FIND) m_pLEADDicomDS1->InitDS(DICOM_CLASS_STUDY_ROOT_QUERY_SERIES, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); else if (szUID == UID_PATIENT_ROOT_QUERY_FIND) m_pLEADDicomDS1->InitDS(DICOM_CLASS_PATIENT_ROOT_QUERY_SERIES, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); //add the required fields for this seach nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_QUERY_RETRIEVE_LEVEL, 0, FALSE, 0); if(nRet != 0) nRet = m_pLEADDicomDS1->FindFirstElement(TAG_QUERY_RETRIEVE_LEVEL, FALSE); m_pLEADDicomDS1->StringValueCount = 1; m_pLEADDicomDS1->StringValues[0] = "SERIES"; //we are searching at the series level nRet = m_pLEADDicomDS1->SetStringValue(1); IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); hTemp = pCurrentElement->GethElement(); if(m_bPatientLevel) { nRet = m_pReceiveDS->FindFirstElement(TAG_PATIENT_ID, TRUE); nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_ID, FALSE); if (nRet != 0) nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_ID, 0, FALSE, 0); nRet = m_pReceiveDS->GetStringValue(0, 1); if(nRet == 0) { BSTR bstr = m_pReceiveDS->GetStringValues(0); szVal = bstr; SysFreeString(bstr); } else { MessageBox("Error, no Patient ID", "Error", MB_OK); return; } m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = szVal.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } nRet = m_pReceiveDS->FindFirstElement(TAG_STUDY_INSTANCE_UID, TRUE); nRet = m_pLEADDicomDS1->FindFirstElement(TAG_STUDY_INSTANCE_UID, FALSE); if(nRet != 0) nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_STUDY_INSTANCE_UID, 0, FALSE, 0); nRet = m_pReceiveDS->GetStringValue(0, 1); if(nRet == 0) { BSTR bstr = m_pReceiveDS->GetStringValues(0); szVal = bstr; SysFreeString(bstr); } else { MessageBox("Error, no Study Instance UID in this STUDY", "Error", MB_OK); return; } m_pLEADDicomDS1->StringValueCount = 1; bstr = szVal.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); m_nFindType = COMMAND_C_FIND_SERIES; m_CancelMessageID = 1; bstr = szUID.AllocSysString(); nRet = m_pLEADDicomNet1->SendCFindRequest(m_pLEADDicomNet1->GethNet(), m_CancelPresentationID, m_CancelMessageID, bstr, COMMAND_PRIORITY_MEDIUM, m_pLEADDicomDS1->GethDicomDS()); SysFreeString(bstr); if(nRet != 0) { CString szOut; szOut.Format("C-FIND-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for FIND Response..."); m_ResultsList.AddString("Find Request Command Set Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "C-FIND-RQ", FALSE, NULL); } } void CDclientDlg::FindAllImage(CString szUID) { short nRet; long hPDU; CString szOut; CString szVal; long hTemp; hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(hPDU == 0) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } BSTR bstr = szUID.AllocSysString(); m_CancelPresentationID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if((m_CancelPresentationID == 0) || (m_pLEADDicomNet1->GetPresentationResult(hPDU, m_CancelPresentationID) != PDU_ACCEPT_RESULT_SUCCESS)) { m_ResultsList.AddString("Abstract Syntax, " + szUID + ", Not Supported by Association!"); MessageBox("Abstract Syntax, " + szUID + ", Not Supported by Association!"); return; } //create a find attribute data set m_pLEADDicomDS1->ResetDS(); if(szUID == UID_STUDY_ROOT_QUERY_FIND) m_pLEADDicomDS1->InitDS(DICOM_CLASS_STUDY_ROOT_QUERY_IMAGE, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); else if(szUID == UID_PATIENT_ROOT_QUERY_FIND) m_pLEADDicomDS1->InitDS(DICOM_CLASS_PATIENT_ROOT_QUERY_IMAGE, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); //add the required fields for this seach nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_QUERY_RETRIEVE_LEVEL, 0, FALSE, 0); if(nRet != 0) nRet = m_pLEADDicomDS1->FindFirstElement(TAG_QUERY_RETRIEVE_LEVEL, FALSE); m_pLEADDicomDS1->StringValueCount = 1; m_pLEADDicomDS1->StringValues[0] = "IMAGE"; //we are searching at the IMAGE level nRet = m_pLEADDicomDS1->SetStringValue(1); IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); hTemp = pCurrentElement->GethElement(); if(m_bPatientLevel == TRUE) { nRet = m_pReceiveDS->FindFirstElement(TAG_PATIENT_ID, TRUE); nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_ID, FALSE); if(nRet != 0) nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_ID, 0, FALSE, 0); nRet = m_pReceiveDS->GetStringValue(0, 1); if(nRet == 0) { BSTR bstr = m_pReceiveDS->GetStringValues(0); szVal = bstr; SysFreeString(bstr); } else { MessageBox("Error, no Patient ID", "Error", MB_OK); return; } m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = szVal.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } m_pReceiveDS->SetCurrentElement(hTemp); nRet = m_pReceiveDS->FindFirstElement(TAG_STUDY_INSTANCE_UID, TRUE); nRet = m_pLEADDicomDS1->FindFirstElement(TAG_STUDY_INSTANCE_UID, FALSE); if(nRet != 0) nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_STUDY_INSTANCE_UID, 0, FALSE, 0); nRet = m_pReceiveDS->GetStringValue(0, 1); if(nRet == 0) { BSTR bstr = m_pReceiveDS->GetStringValues(0); szVal = bstr; SysFreeString(bstr); } else { MessageBox("Error, no Study Instance UID", "Error", MB_OK); return; } m_pLEADDicomDS1->StringValueCount = 1; bstr = szVal.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); m_pReceiveDS->SetCurrentElement(hTemp); nRet = m_pReceiveDS->FindFirstElement(TAG_SERIES_INSTANCE_UID, TRUE); nRet = m_pLEADDicomDS1->FindFirstElement(TAG_SERIES_INSTANCE_UID, FALSE); if(nRet != 0) nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_SERIES_INSTANCE_UID, 0, FALSE, 0); nRet = m_pReceiveDS->GetStringValue(0, 1); if(nRet == 0) { BSTR bstr = m_pReceiveDS->GetStringValues(0); szVal = bstr; SysFreeString(bstr); } else { MessageBox("Error, no Series Instance UID", "Error", MB_OK); return; } m_pLEADDicomDS1->StringValueCount = 1; bstr = szVal.AllocSysString(); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); m_nFindType = COMMAND_C_FIND_IMAGE; m_CancelMessageID = 1; bstr = szUID.AllocSysString(); nRet = m_pLEADDicomNet1->SendCFindRequest(m_pLEADDicomNet1->GethNet(), m_CancelPresentationID, m_CancelMessageID, bstr, COMMAND_PRIORITY_MEDIUM, m_pLEADDicomDS1->GethDicomDS()); SysFreeString(bstr); if(nRet != 0) { CString szOut; szOut.Format("C-FIND-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for FIND Response..."); m_ResultsList.AddString("Find Request Command Set Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "C-FIND-RQ", FALSE, NULL); } } void CDclientDlg::SendCMoveCommand() { short nRet; CString szClassUID; long hPDU; short nID; long hTemp; long lPort; //send a Move Request to the server hPDU = m_pLEADDicomNet1->GetAssociate(m_pLEADDicomNet1->GethNet()); if(hPDU == 0) { m_ResultsList.AddString("Connection Not Associated!"); MessageBox("Connection Not Associated!", "Warning", MB_OK); return; } IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); hTemp = pCurrentElement->GethElement(); //create the data set that encodes the identifier to be matched m_pLEADDicomDS1->ResetDS(); if(m_bPatientLevel == TRUE) { szClassUID = UID_PATIENT_ROOT_QUERY_MOVE; m_pLEADDicomDS1->InitDS(DICOM_CLASS_PATIENT_ROOT_QUERY_IMAGE, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); } else { szClassUID = UID_STUDY_ROOT_QUERY_MOVE; m_pLEADDicomDS1->InitDS(DICOM_CLASS_STUDY_ROOT_QUERY_IMAGE, DS_METAHEADER_ABSENT | DS_LITTLE_ENDIAN | DS_EXPLICIT_VR); } //add the required elements //add the required fields for this seach nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_QUERY_RETRIEVE_LEVEL, 0, FALSE, 0); if(nRet != 0) nRet = m_pLEADDicomDS1->FindFirstElement(TAG_QUERY_RETRIEVE_LEVEL, FALSE); m_pLEADDicomDS1->StringValueCount = 1; m_pLEADDicomDS1->StringValues[0] = "IMAGE"; //we are searching at the IMAGE level nRet = m_pLEADDicomDS1->SetStringValue(1); if(m_bPatientLevel == TRUE) { m_pReceiveDS->FindFirstElement(TAG_PATIENT_ID, TRUE); nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_PATIENT_ID, 0, FALSE, 0); if(nRet != 0) nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PATIENT_ID, FALSE); if(nRet == 0) { m_pReceiveDS->GetStringValue(0, 1); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = m_pReceiveDS->GetStringValues(0); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } } m_pReceiveDS->FindFirstElement(TAG_STUDY_INSTANCE_UID, TRUE); nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_STUDY_INSTANCE_UID, 0, FALSE, 0); if(nRet != 0) nRet = m_pLEADDicomDS1->FindFirstElement(TAG_STUDY_INSTANCE_UID, FALSE); if(nRet == 0) { m_pReceiveDS->GetStringValue(0, 1); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = m_pReceiveDS->GetStringValues(0); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } m_pReceiveDS->SetCurrentElement(hTemp); m_pReceiveDS->FindFirstElement(TAG_SERIES_INSTANCE_UID, TRUE); nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_SERIES_INSTANCE_UID, 0, FALSE, 0); if(nRet != 0) nRet = m_pLEADDicomDS1->FindFirstElement(TAG_SERIES_INSTANCE_UID, FALSE); if(nRet == 0) { m_pReceiveDS->GetStringValue(0, 1); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = m_pReceiveDS->GetStringValues(0); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } m_pReceiveDS->SetCurrentElement(hTemp); m_pReceiveDS->FindFirstElement(TAG_SOP_INSTANCE_UID, TRUE); nRet = m_pLEADDicomDS1->InsertElement(FALSE, TAG_SOP_INSTANCE_UID, 0, FALSE, 0); if(nRet != 0) nRet = m_pLEADDicomDS1->FindFirstElement(TAG_SOP_INSTANCE_UID, FALSE); if(nRet == 0) { m_pReceiveDS->GetStringValue(0, 1); m_pLEADDicomDS1->StringValueCount = 1; BSTR bstr = m_pReceiveDS->GetStringValues(0); m_pLEADDicomDS1->StringValues[0] = bstr; SysFreeString(bstr); m_pLEADDicomDS1->SetStringValue(1); } //now, send a request BSTR bstr = szClassUID.AllocSysString(); nID = m_pLEADDicomNet1->FindPresentationAbstract(hPDU, bstr); SysFreeString(bstr); if(nID == 0) { BSTR bstr = szClassUID.AllocSysString(); nRet = m_pLEADDicomDS1->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS1->GetCurrentUID(); BSTR bstr = pCurrentUID->GetName(); CString cs = bstr; SysFreeString(bstr); m_ResultsList.AddString("Abstract Syntax, " + cs + ", Not Supported by Association!"); } else m_ResultsList.AddString("Abstract Syntax, " + szClassUID + ", Not Supported by Association!"); return; } //we are asking the Called AE to move the SOP Instance to ourselves m_CancelPresentationID = nID; m_CancelMessageID = 1; //start our SCP lPort = 1000; CPortDlg dlg; if(dlg.DoModal() != IDOK) return; lPort = dlg.m_lPort; if(m_pLEADDicomNet2->GethNet() != 0) m_pLEADDicomNet2->Close(m_pLEADDicomNet2->GethNet()); if(m_pLEADDicomNet2->GethNet == 0) { if(GetMenu()->GetMenuState(ID_SECRUTIY_NONSECUREMODE, MF_BYCOMMAND) & MF_CHECKED) m_pLEADDicomNet2->NetworkSecurityMode = DICOM_SECURE_NONE; if(GetMenu()->GetMenuState(ID_SECRUTIY_ISCLSECUREMODE, MF_BYCOMMAND) & MF_CHECKED) m_pLEADDicomNet2->NetworkSecurityMode = DICOM_SECURE_ISCL; if(GetMenu()->GetMenuState(ID_SECRUTIY_TLSSECUREMODE, MF_BYCOMMAND) & MF_CHECKED) m_pLEADDicomNet2->NetworkSecurityMode = DICOM_SECURE_TLS; m_pLEADDicomNet2->StartUp(); } if(!m_pLEADDicomNet2->GethNet()) m_pLEADDicomNet2->StartUp(); nRet = m_pLEADDicomNet2->Listen("", lPort, 1); //only allow one connection to us if(nRet != 0) { m_ResultsList.AddString("Error Starting SCP"); MessageBox("Error Starting SCP", "Error", MB_OK); return; } m_ResultsList.AddString("SCP has been started"); BSTR bstr1 = szClassUID.AllocSysString(); BSTR bstr2 = m_szCallingAE.AllocSysString(); if(m_bPatientLevel == TRUE) nRet = m_pLEADDicomNet1->SendCMoveRequest(m_pLEADDicomNet1->GethNet(), nID, 1, bstr1, COMMAND_PRIORITY_MEDIUM, bstr2, m_pLEADDicomDS1->GethDicomDS()); else nRet = m_pLEADDicomNet1->SendCMoveRequest(m_pLEADDicomNet1->GethNet(), nID, 1, bstr1, COMMAND_PRIORITY_MEDIUM, bstr2, m_pLEADDicomDS1->GethDicomDS()); SysFreeString(bstr1); SysFreeString(bstr2); if(nRet != 0) { CString szOut; szOut.Format("C-MOVE-REQ - Error: %d", nRet); m_ResultsList.AddString(szOut); MessageBox(szOut, "Error", MB_OK); } else { StartStatusBar("Waiting for MOVE Response..."); m_ResultsList.AddString("Move Request Command Set Sent - " + m_pLEADDicomNet1->GetPeerAddress(m_pLEADDicomNet1->GethNet())); RecordMessage(TRUE, "C-MOVE-RQ", FALSE, NULL); } //we now must wait for the response and for the C-STORE sub-operations } short CDclientDlg::PerformSTORECommand(long hDicomDS) { short nRet; //stop the timeout StopTimer(); m_StatusBar.SetText("Store and View Image...", 0, 0); m_pReceiveDS->SetCurrentElement(m_hKey); nRet = m_pReceiveDS->MoveChildElement(); //make room for the image Data Set nRet = m_pReceiveDS->InsertElement(FALSE, TAG_ICON_IMAGE_SEQUENCE, 0, TRUE, 0); nRet = m_pReceiveDS->InsertElement(TRUE, TAG_ITEM, 0, TRUE, 0); //copy the DS so we can work with it HCURSOR hOld = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); m_pLEADDicomDS1->ResetDS(); m_pLEADDicomDS1->hDicomDS = hDicomDS; SetCursor(hOld); //get the image nRet = m_pLEADDicomDS1->FindFirstElement(TAG_PIXEL_DATA, FALSE); if(nRet != 0) { m_ResultsList.AddString("Error - No Image Data in DataSet!"); return(COMMAND_STATUS_PROCESSING_FAILURE); } hOld = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); m_pLEADDicomDS1->GetImageInformation(0); m_pLEADDicomDS1->GetBitmapValue(0, 0, ORDER_BGRORGRAY, DICOM_GETIMAGE_AUTO_APPLY_MODALITY_LUT| DICOM_GETIMAGE_AUTO_APPLY_VOI_LUT| DICOM_GETIMAGE_ALLOW_RANGE_EXPANSION); IDicomImageInfoPtr pImageInfo = m_pLEADDicomDS1->GetImageInfo(); m_pLEADDicomDS1->SetBitmapValue(DICOM_IMAGE_COMPRESSION_NONE, pImageInfo->GetPhotometric(), 0, 0, DICOM_SETIMAGE_AUTO_SET_VOI_LUT); SetCursor(hOld); //insert the DataSet here hOld = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); nRet = m_pReceiveDS->InsertDS(m_pLEADDicomDS1->GethDicomDS(), 0); SetCursor(hOld); //find the image position m_pReceiveDS->SetCurrentElement(m_hKey); nRet = m_pReceiveDS->MoveChildElement(); nRet = m_pReceiveDS->FindFirstElement(TAG_ICON_IMAGE_SEQUENCE, TRUE); nRet = m_pReceiveDS->MoveChildElement(); nRet = m_pReceiveDS->MoveChildElement(); nRet = m_pReceiveDS->FindFirstElement(TAG_PIXEL_DATA, TRUE); if(nRet == 0) DisplayImageData(); else { m_ResultsList.AddString("Error - Copying Image Data to DataSet!"); return(COMMAND_STATUS_PROCESSING_FAILURE); } return(0); } void CDclientDlg::DisplayImageData() { short nRet; HCURSOR hOld = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); nRet = m_pReceiveDS->GetBitmapValue(0, 0, ORDER_BGRORGRAY, DICOM_GETIMAGE_AUTO_APPLY_MODALITY_LUT| DICOM_GETIMAGE_AUTO_APPLY_VOI_LUT| DICOM_GETIMAGE_ALLOW_RANGE_EXPANSION); hOld = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); SetCursor(hOld); if(nRet == 0) { hOld = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); m_LEADRasterView1.GetRaster().SetBitmap(m_pReceiveDS->GetBitmap()); SetCursor(hOld); m_LEADRasterView1.ShowWindow(SW_SHOW); m_KeyView.ShowWindow(SW_HIDE); } else MessageBox("Error in Image Data!", "Error", MB_OK); } void CDclientDlg::OnClickKeyview(NMHDR* pNMHDR, LRESULT* pResult) { long hElement; HTREEITEM hNodeX=NULL; hNodeX = m_KeyView.GetSelectedItem(); if(hNodeX) { hElement = (long)m_KeyView.GetItemData(hNodeX); m_pReceiveDS->SetCurrentElement(hElement); IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); if(pCurrentElement->GetTag() == TAG_PIXEL_DATA) DisplayImageData(); } *pResult = 0; } void CDclientDlg::OnSelchangedKeyview(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; long hElement; HTREEITEM hNodeX=NULL; hNodeX = m_KeyView.GetSelectedItem(); if(hNodeX) { hElement = (long)m_KeyView.GetItemData(hNodeX); m_pReceiveDS->SetCurrentElement(hElement); IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); if(pCurrentElement->GetTag() == TAG_PIXEL_DATA) DisplayImageData(); } *pResult = 0; } void CDclientDlg::OnNetworkSaveentiredataset() { CFileDialog dlg(FALSE, "dic"); short nRet; nRet = m_pReceiveDS->MoveFirstElement(FALSE); if(nRet != 0) { MessageBox("Error - No DataSet to save!", "Error", MB_OK); return; } if(dlg.DoModal() == IDOK) { HCURSOR hOld = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); BSTR bstr = dlg.GetFileName().AllocSysString(); nRet = m_pReceiveDS->SaveDS(bstr, 0); SysFreeString(bstr); SetCursor(hOld); if(nRet != 0) { CString szOut; szOut.Format("Error %d saving DataSet!", nRet); MessageBox(szOut, "Error", MB_OK); } } } void CDclientDlg::OnNetworkSaveselectedas() { CFileDialog dlg(FALSE, "dic"); long hElement; short nRet; CString szKey; HTREEITEM hItem=NULL; nRet = m_pReceiveDS->MoveFirstElement(FALSE); if(nRet != 0) { MessageBox("Error - No DataSet to save!", "Error", MB_OK); return; } hElement = 0; hItem = m_FindResults.GetSelectedItem(); if(!hItem) { MessageBox("Please select an image!", "Notice", MB_OK); return; } hElement = (long)m_FindResults.GetItemData(hItem); if(hElement == 0) { MessageBox("Please select an image!", "Notice", MB_OK); return; } m_pReceiveDS->SetCurrentElement(hElement); BSTR bstr = m_pReceiveDS->GetKeyValue(); szKey = bstr; SysFreeString(bstr); if(szKey != "IMAGE") { MessageBox("Please select an image!", "Notice", MB_OK); return; } else //user has selected an IMAGE key, but is there an image { nRet = m_pReceiveDS->MoveChildElement(); if(nRet != 0) { MessageBox("Please select an image!", "Notice", MB_OK); return; } nRet = m_pReceiveDS->FindFirstElement(TAG_ICON_IMAGE_SEQUENCE, TRUE); if(nRet != 0) { MessageBox("Please select an image!", "Notice", MB_OK); return; } nRet = m_pReceiveDS->MoveChildElement(); if(nRet != 0) { MessageBox("Please select an image!", "Notice", MB_OK); return; } nRet = m_pReceiveDS->MoveChildElement(); if(nRet != 0) { MessageBox("Please select an image!", "Notice", MB_OK); return; } nRet = m_pReceiveDS->FindFirstElement(TAG_PIXEL_DATA, TRUE); if(nRet != 0) { MessageBox("Please select an image!", "Notice", MB_OK); return; } } if(dlg.DoModal() != IDOK) return; else { m_pLEADDicomDS1->ResetDS(); m_pReceiveDS->SetCurrentElement(hElement); nRet = m_pReceiveDS->MoveChildElement(); nRet = m_pReceiveDS->FindFirstElement(TAG_ICON_IMAGE_SEQUENCE, TRUE); nRet = m_pReceiveDS->MoveChildElement(); nRet = m_pReceiveDS->FindFirstElement(TAG_ITEM, TRUE); HCURSOR hOld = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); IDicomDSElementPtr pCurrentElement = m_pReceiveDS->GetCurrentElement(); nRet = m_pLEADDicomDS1->InsertDS(m_pReceiveDS->GethDicomDS(), pCurrentElement->GethElement()); BSTR bstr = dlg.GetFileName().AllocSysString(); nRet = m_pLEADDicomDS1->SaveDS(bstr, 0); SysFreeString(bstr); SetCursor(hOld); if(nRet != 0) { CString szOut; szOut.Format("Error %d saving DataSet", nRet); MessageBox(szOut, "Error", MB_OK); } m_pLEADDicomDS1->ResetDS(); } } void CDclientDlg::OnPreferencesViewfit() { CMenu* pMenu=GetMenu(); if(pMenu) { pMenu->CheckMenuItem(ID_PREFERENCES_VIEWFIT, MF_CHECKED|MF_BYCOMMAND); pMenu->CheckMenuItem(ID_PREFERENCES_VIEWNORMAL, MF_UNCHECKED|MF_BYCOMMAND); m_LEADRasterView1.SetPaintSizeMode(PAINTSIZEMODE_FIT); } } void CDclientDlg::OnPreferencesViewnormal() { CMenu* pMenu=GetMenu(); if(pMenu) { pMenu->CheckMenuItem(ID_PREFERENCES_VIEWFIT, MF_UNCHECKED|MF_BYCOMMAND); pMenu->CheckMenuItem(ID_PREFERENCES_VIEWNORMAL, MF_CHECKED|MF_BYCOMMAND); m_LEADRasterView1.SetPaintSizeMode(PAINTSIZEMODE_NORMAL); } } void CDclientDlg::OnServicesCancel() { if(m_bWorking) //a service is in progress, let's cancel it { m_pLEADDicomNet1->SendCCancelRequest(m_pLEADDicomNet1->GethNet(), m_CancelPresentationID, m_CancelMessageID); StopTimer(); //close connection CloseClientConnection(); } else MessageBox("No service in progress!", "Notice", MB_OK); } void CDclientDlg::OnSecureNone() { CMenu* pMenu=GetMenu(); if(pMenu) { pMenu->CheckMenuItem(ID_SECRUTIY_NONSECUREMODE, MF_CHECKED|MF_BYCOMMAND); pMenu->CheckMenuItem(ID_SECRUTIY_ISCLSECUREMODE, MF_UNCHECKED|MF_BYCOMMAND); pMenu->CheckMenuItem(ID_SECRUTIY_TLSSECUREMODE, MF_UNCHECKED|MF_BYCOMMAND); } } void CDclientDlg::OnSecureISCL() { CMenu* pMenu=GetMenu(); if(pMenu) { pMenu->CheckMenuItem(ID_SECRUTIY_NONSECUREMODE, MF_UNCHECKED|MF_BYCOMMAND); pMenu->CheckMenuItem(ID_SECRUTIY_ISCLSECUREMODE, MF_CHECKED|MF_BYCOMMAND); pMenu->CheckMenuItem(ID_SECRUTIY_TLSSECUREMODE, MF_UNCHECKED|MF_BYCOMMAND); } } void CDclientDlg::OnSecureTLS() { CMenu* pMenu=GetMenu(); if(pMenu) { pMenu->CheckMenuItem(ID_SECRUTIY_NONSECUREMODE, MF_UNCHECKED|MF_BYCOMMAND); pMenu->CheckMenuItem(ID_SECRUTIY_ISCLSECUREMODE, MF_UNCHECKED|MF_BYCOMMAND); pMenu->CheckMenuItem(ID_SECRUTIY_TLSSECUREMODE, MF_CHECKED|MF_BYCOMMAND); } } void CDclientDlg::OnSecureSettings() { CPropertySheet dlgPropertySheet("Simple PropertySheet"); CInfoSecurty InfoPage; CAuthSecurty AuthPage; CEncryptSecurty EncryptPage; dlgPropertySheet.AddPage(&InfoPage); dlgPropertySheet.AddPage(&AuthPage); dlgPropertySheet.AddPage(&EncryptPage); EncryptPage.m_pDclientDlg = AuthPage.m_pDclientDlg = this; dlgPropertySheet.DoModal(); } void CDclientDlg::OnInitMenu(CMenu* pMenu) { CDialog::OnInitMenu(pMenu); UINT nEnable = MF_BYCOMMAND | (m_pLEADDicomNet1->IsConnected(m_pLEADDicomNet1->GethNet()) ? MF_GRAYED : MF_ENABLED); pMenu->EnableMenuItem(ID_SECRUTIY_NONSECUREMODE, nEnable); pMenu->EnableMenuItem(ID_SECRUTIY_ISCLSECUREMODE, nEnable); pMenu->EnableMenuItem(ID_SECRUTIY_TLSSECUREMODE, nEnable); pMenu->EnableMenuItem(ID_SECRUTIY_SETTINGS, nEnable); } void CDclientDlg::CleanUp(void) { //Terminate a connection between source and sink. if(m_pDicomNetSink1) { LPUNKNOWN pUnkSink = m_pDicomNetSink1->GetIDispatch(FALSE); AfxConnectionUnadvise(m_pLEADDicomNet1, DIID__LEADDicomNetEvents, pUnkSink, FALSE, m_dwCookie1); delete m_pDicomNetSink1; m_pDicomNetSink1=NULL; } if(m_pDicomNetSink2) { LPUNKNOWN pUnkSink = m_pDicomNetSink2->GetIDispatch(FALSE); AfxConnectionUnadvise(m_pLEADDicomNet2, DIID__LEADDicomNetEvents, pUnkSink, FALSE, m_dwCookie2); delete m_pDicomNetSink2; m_pDicomNetSink2=NULL; } if(m_pLEADDicomNet1) m_pLEADDicomNet1->Release(); if(m_pLEADDicomNet2) m_pLEADDicomNet2->Release(); if(m_pLEADDicomDS1) m_pLEADDicomDS1->Release(); if(m_pLEADDicomDS2) m_pLEADDicomDS2->Release(); if(m_pLEADDicomCS) m_pLEADDicomCS->Release(); if(m_pReceiveDS) m_pReceiveDS->Release(); m_pLEADDicomNet1=NULL; m_pLEADDicomNet2=NULL; m_pReceiveDS=NULL; m_pLEADDicomDS1=NULL; m_pLEADDicomDS2=NULL; m_pLEADDicomCS=NULL; CDialog::OnDestroy(); }