1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2014 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "gdcmNormalizedNetworkFunctions.h"
#include <socket++/echo.h>
#include "gdcmReader.h"
#include "gdcmPrinter.h"
#include "gdcmAttribute.h"
#include "gdcmULConnectionManager.h"
#include "gdcmULConnection.h"
#include "gdcmDataSet.h"
#include "gdcmVersion.h"
#include "gdcmGlobal.h"
#include "gdcmSystem.h"
#include "gdcmUIDGenerator.h"
#include "gdcmWriter.h"
#include "gdcmSimpleSubjectWatcher.h"
#include "gdcmProgressEvent.h"
#include "gdcmQueryFactory.h"
#include "gdcmULWritingCallback.h"
#include "gdcmULBasicCallback.h"
#include "gdcmPresentationContextGenerator.h"
namespace gdcm
{
BaseQuery*
NormalizedNetworkFunctions::ConstructQuery( const std::string & sopInstanceUID,
const DataSet& queryds, ENQueryType queryType /*= eMMPS*/ )
{
BaseQuery* outQuery = nullptr ;
if( queryType == eCreateMMPS || queryType == eSetMMPS )
outQuery = QueryFactory::ProduceQuery( sopInstanceUID, queryType );
if (!outQuery)
{
gdcmErrorMacro( "Specify the query" );
return nullptr;
}
outQuery->AddQueryDataSet(queryds);
// setup the special character set
std::vector<ECharSet> inCharSetType;
inCharSetType.push_back( QueryFactory::GetCharacterFromCurrentLocale() );
DataElement de = QueryFactory::ProduceCharacterSetDataElement(inCharSetType);
std::string param ( de.GetByteValue()->GetPointer(),
de.GetByteValue()->GetLength() );
outQuery->SetSearchParameter(de.GetTag(), param );
// Print info:
if (Trace::GetDebugFlag())
{
outQuery->Print( Trace::GetStream() );
}
return outQuery;
}
bool
NormalizedNetworkFunctions::NEventReport( const char *remote, uint16_t portno,
const BaseQuery* query, std::vector<DataSet> &retDataSets,
const char *aetitle, const char *call )
{
(void)remote; (void)portno; (void)query; (void)retDataSets; (void)aetitle; (void)call;
return false ;
}
bool
NormalizedNetworkFunctions::NGet( const char *remote, uint16_t portno,
const BaseQuery* query, std::vector<DataSet> &retDataSets,
const char *aetitle, const char *call )
{
(void)remote; (void)portno; (void)query; (void)retDataSets; (void)aetitle; (void)call;
return false ;
}
bool
NormalizedNetworkFunctions::NSet( const char *remote, uint16_t portno,
const BaseQuery* query, std::vector<DataSet> &retDataSets,
const char *aetitle, const char *call )
{
if( !remote ) return false;
if( !aetitle )
{
aetitle = "GDCMSCU";
}
if( !call )
{
call = "ANY-SCP";
}
// $ findscu -v -d --aetitle ACME1 --call ACME_STORE -P -k 0010,0010="X*"
// dhcp-67-183 5678 patqry.dcm
// Add a query:
// Generate the PresentationContext array from the query UID:
PresentationContextGenerator generator;
if( !generator.GenerateFromUID( query->GetAbstractSyntaxUID() ) )
{
gdcmErrorMacro( "Failed to generate pres context." );
return false;
}
network::ULConnectionManager theManager;
if (!theManager.EstablishConnection(aetitle, call, remote, 0, portno, 1000,
generator.GetPresentationContexts()))
{
gdcmErrorMacro( "Failed to establish connection." );
return false;
}
std::vector<DataSet> theDataSets;
std::vector<DataSet> theResponses;
network::ULBasicCallback theCallback;
theManager.SendNSet(query, &theCallback);
theDataSets = theCallback.GetDataSets();
theResponses = theCallback.GetResponses();
bool ret = false; // by default an error
if( theResponses.empty() )
{
gdcmErrorMacro( "Failed to GetResponses." );
return false;
}
assert( theResponses.size() >= 1 );
// take the last one:
const DataSet &ds = theResponses[ theResponses.size() - 1 ]; // FIXME
assert ( ds.FindDataElement(Tag(0x0, 0x0900)) );
Attribute<0x0,0x0900> at;
at.SetFromDataSet( ds );
// Table CC.2.1-2
// STATUS VALUES
const uint16_t theVal = at.GetValue();
switch( theVal )
{
case 0x0:
gdcmDebugMacro( "The requested modification of the attribute values is performed." );
// Append the new DataSet to the ret one:
retDataSets.insert( retDataSets.end(), theDataSets.begin(), theDataSets.end() );
ret = true;
break;
case 0x1:
{
gdcmWarningMacro( "Requested optional Attributes are not supported." );
}
break;
case 0xB305:
{
gdcmWarningMacro( "The UPS is already in the requested state of COMPLETED" );
}
break;
case 0xC310:
{
gdcmErrorMacro( "Refused: The UPS is not in the \"IN PROGRESS\" state " );
}
break;
case 0xC301:
{
gdcmErrorMacro( "Refused: The correct Transaction UID was not provided " );
}
break;
case 0xC300:
{
gdcmErrorMacro( "Refused: The UPS may no longer be updated " );
}
break;
case 0xC307:
{
gdcmErrorMacro( "Specified SOP Instance UID does not exist or is not a UPS Instance managed by this SCP " );
}
break;
default:
break ;
}
theManager.BreakConnection(-1);//wait for a while for the connection to break, ie, infinite
return ret;
}
bool
NormalizedNetworkFunctions::NAction( const char *remote, uint16_t portno,
const BaseQuery* query, std::vector<DataSet> &retDataSets,
const char *aetitle, const char *call )
{
(void)remote; (void)portno; (void)query; (void)retDataSets; (void)aetitle; (void)call;
return false ;
}
bool
NormalizedNetworkFunctions::NCreate( const char *remote, uint16_t portno,
BaseQuery* query, std::vector<DataSet> &retDataSets,
const char *aetitle, const char *call )
{
if( !remote ) return false;
if( !aetitle )
{
aetitle = "GDCMSCU";
}
if( !call )
{
call = "ANY-SCP";
}
// $ findscu -v -d --aetitle ACME1 --call ACME_STORE -P -k 0010,0010="X*"
// dhcp-67-183 5678 patqry.dcm
// Add a query:
// Generate the PresentationContext array from the query UID:
PresentationContextGenerator generator;
if( !generator.GenerateFromUID( query->GetAbstractSyntaxUID() ) )
{
gdcmErrorMacro( "Failed to generate pres context." );
return false;
}
network::ULConnectionManager theManager;
if (!theManager.EstablishConnection(aetitle, call, remote, 0, portno, 1000,
generator.GetPresentationContexts()))
{
gdcmErrorMacro( "Failed to establish connection." );
return false;
}
std::vector<DataSet> theDataSets;
std::vector<DataSet> theResponses;
//theDataSets = theManager.SendFind( query );
network::ULBasicCallback theCallback;
theManager.SendNCreate(query, &theCallback);
theDataSets = theCallback.GetDataSets();
theResponses = theCallback.GetResponses();
bool ret = false; // by default an error
if( theResponses.empty() )
{
gdcmErrorMacro( "Failed to GetResponses." );
return false;
}
assert( theResponses.size() >= 1 );
// take the last one:
const DataSet &ds = theResponses[ theResponses.size() - 1 ]; // FIXME
assert ( ds.FindDataElement(Tag(0x0, 0x0900)) );
Attribute<0x0,0x0900> at;
at.SetFromDataSet( ds );
// Table CC.2.1-2
// STATUS VALUES
const uint16_t theVal = at.GetValue();
switch( theVal )
{
case 0x0: // The requested state change was performed
gdcmDebugMacro( "The requested state change was performed." );
// Append the new DataSet to the ret one:
retDataSets.insert( retDataSets.end(), theDataSets.begin(), theDataSets.end() );
{
Attribute<0x0000,0x1000> sopInstanceUIDAt;
sopInstanceUIDAt.SetFromDataSet( ds );
query->SetSOPInstanceUID( sopInstanceUIDAt.GetValue() );
}
ret = true;
break;
case 0xB304: // The UPS is already in the requested state of CANCELED
{
gdcmWarningMacro( "Offending Element: The UPS is already in the requested state of CANCELED" );
}
break;
case 0xB306: // The UPS is already in the requested state of COMPLETED
{
gdcmWarningMacro( "The UPS is already in the requested state of COMPLETED" );
}
break;
case 0xC300:
{
gdcmErrorMacro( "Refused: The UPS may no longer be updated " );
}
break;
case 0xC301:
{
gdcmErrorMacro( "Refused: The correct Transaction UID was not provided " );
}
break;
case 0xC302:
{
gdcmErrorMacro( "Refused: The UPS is already IN PROGRESS " );
}
break;
case 0xC303:
{
gdcmErrorMacro( "Refused: The UPS may only become SCHEDULED via NCREATE, not N-SET or N-ACTION " );
}
break;
case 0xC304:
{
gdcmErrorMacro( "Refused: The UPS has not met final state requirements for the requested state change " );
}
break;
case 0xC307:
{
gdcmErrorMacro( "Specified SOP Instance UID does not exist or is not a UPS Instance managed by this SCP " );
}
break;
case 0xC310:
{
gdcmErrorMacro( "Refused: The UPS is not yet in the \"IN PROGRESS\" state " );
}
break;
default:
break ;
}
theManager.BreakConnection(-1);//wait for a while for the connection to break, ie, infinite
return ret;
}
bool
NormalizedNetworkFunctions::NDelete( const char *remote, uint16_t portno,
const BaseQuery* query, std::vector<DataSet> &retDataSets,
const char *aetitle, const char *call )
{
(void)remote; (void)portno; (void)query; (void)retDataSets; (void)aetitle; (void)call;
return false ;
}
} // end namespace gdcm
|