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
|
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "gdcmQueryFactory.h"
#include "gdcmFindPatientRootQuery.h"
#include "gdcmMovePatientRootQuery.h"
#include "gdcmFindStudyRootQuery.h"
#include "gdcmMoveStudyRootQuery.h"
#include "gdcmWLMFindQuery.h"
#include "gdcmModalityPerformedProcedureStepCreateQuery.h"
#include "gdcmModalityPerformedProcedureStepSetQuery.h"
#include <locale>
namespace gdcm
{
BaseQuery* QueryFactory::ProduceQuery( const std::string & sopInstanceUID, ENQueryType inQueryType )
{
BaseQuery* theReturn = nullptr;
switch (inQueryType)
{
case eCreateMMPS :
theReturn = new ModalityPerformedProcedureStepCreateQuery( sopInstanceUID );
break;
case eSetMMPS :
theReturn = new ModalityPerformedProcedureStepSetQuery( sopInstanceUID );
break;
}
return theReturn;
}
BaseRootQuery* QueryFactory::ProduceQuery(ERootType inRootType, EQueryType inQueryType,
EQueryLevel inQueryLevel)
{
BaseRootQuery* theReturn = nullptr;
switch (inQueryType)
{
case eFind:
switch (inRootType)
{
case ePatientRootType:
theReturn = new FindPatientRootQuery();
break;
case eStudyRootType:
if (inQueryLevel != ePatient)
theReturn = new FindStudyRootQuery();
break;
}
break;
case eMove:
switch (inRootType)
{
case ePatientRootType:
theReturn = new MovePatientRootQuery();
break;
case eStudyRootType:
if (inQueryLevel != ePatient)
theReturn = new MoveStudyRootQuery();
break;
}
break;
case eWLMFind:
theReturn = new WLMFindQuery();
break;
}
if( theReturn )
theReturn->InitializeDataSet(inQueryLevel);
return theReturn;
}
/*
LATIN1 ISO 8859-1
LATIN2 ISO 8859-2
LATIN3 ISO 8859-3
LATIN4 ISO 8859-4
ISO_8859_5 ISO 8859-5 Latin/Cyrillic
ISO_8859_6 ISO 8859-6 Latin/Arabic
ISO_8859_7 ISO 8859-7 Latin/Greek
ISO_8859_8 ISO 8859-8 Latin/Hebrew
LATIN5 ISO 8859-9
LATIN6 ISO 8859-10
LATIN7 ISO 8859-13
LATIN8 ISO 8859-14
LATIN9 ISO 8859-15
LATIN10 ISO 8859-16
*/
ECharSet QueryFactory::GetCharacterFromCurrentLocale()
{
const char *charset = System::GetLocaleCharset();
if( charset )
{
// UTF-8 (this is the default for UNIX):
if( strcmp( charset, "UTF-8" ) == 0 ) return eUTF8;
// US-ASCII, simply return latin1
else if( strcmp( charset, "US-ASCII" ) == 0 ) return eLatin1;
else if( strcmp( charset, "ANSI_X3.4-1968" ) == 0 ) return eLatin1;
// Latin-1
else if( strcmp( charset, "ISO-8859-1" ) == 0 ) return eLatin1;
else if( strcmp( charset, "ISO-8859-2" ) == 0 ) return eLatin2;
else if( strcmp( charset, "ISO-8859-3" ) == 0 ) return eLatin3;
else if( strcmp( charset, "ISO-8859-4" ) == 0 ) return eLatin4;
else if( strcmp( charset, "ISO-8859-5" ) == 0 ) return eCyrillic;
else if( strcmp( charset, "ISO-8859-6" ) == 0 ) return eArabic;
else if( strcmp( charset, "ISO-8859-7" ) == 0 ) return eGreek;
else if( strcmp( charset, "ISO-8859-8" ) == 0 ) return eHebrew;
else if( strcmp( charset, "ISO-8859-9" ) == 0 ) return eLatin5;
//
else if( strcmp( charset, "EUC-JP" ) == 0 ) return eJapanese;
else if( strcmp( charset, "TIS-620" ) == 0 ) return eThai;
else if( strcmp( charset, "EUC-JP" ) == 0 ) return eJapaneseKanjiMultibyte;
else if( strcmp( charset, "EUC-JP" ) == 0 ) return eJapaneseSupplementaryKanjiMultibyte;
else if( strcmp( charset, "EUC-KR" ) == 0 ) return eKoreanHangulHanjaMultibyte;
//else if( strcmp( charset, "UTF-8" ) == 0 ) return eUTF8;
else if( strcmp( charset, "GB18030" ) == 0 ) return eGB18030;
gdcmWarningMacro( "Problem mapping Locale Charset: " << charset );
}
gdcmWarningMacro( "Default to Latin-1" );
return eLatin1;
}
///This function will produce the appropriate dataelement given a list of charsets.
///The first charset will be used directly, while the second and subsequent
///will be prepended with "ISO2022 ". Redundant character sets are not permitted,
///so if they are encountered, they will just be skipped.
///if UTF8 or GB18030 is used, no subsequent character sets will be used
DataElement QueryFactory::ProduceCharacterSetDataElement(const std::vector<ECharSet>& inCharSetType)
{
DataElement theReturn;
//use the 'visited' array to make sure that if a redundant character set is entered,
//it's skipped rather than produce a malformed tag.
bool visited[eGB18030+1];
memset(visited, 0, (eGB18030+1)*sizeof(bool));
if (inCharSetType.empty())
return theReturn;
std::vector<ECharSet>::const_iterator itor;
std::string theOutputString;
for (itor = inCharSetType.begin(); itor < inCharSetType.end(); itor++)
{
if (itor > inCharSetType.begin())
{
theOutputString += "ISO 2022 ";
}
else
{
theOutputString += "ISO_IR ";
}
if (visited[*itor]) continue;
switch (*itor)
{
default:
case eLatin1:
theOutputString += "100";
break;
case eLatin2:
theOutputString += "101";
break;
case eLatin3:
theOutputString += "109";
break;
case eLatin4:
theOutputString += "110";
break;
case eCyrillic:
theOutputString += "144";
break;
case eArabic:
theOutputString += "127";
break;
case eGreek:
theOutputString += "126";
break;
case eHebrew:
theOutputString += "138";
break;
case eLatin5:
theOutputString += "148";
break;
case eJapanese:
theOutputString += "13";
break;
case eThai:
theOutputString += "166";
break;
case eJapaneseKanjiMultibyte:
theOutputString += "87";
break;
case eJapaneseSupplementaryKanjiMultibyte:
theOutputString += "159";
break;
case eKoreanHangulHanjaMultibyte:
theOutputString += "149";
break;
//for the next two, they are only valid if they are
//the only ones that appear
case eUTF8:
theOutputString = "ISO_IR 192";
itor = inCharSetType.end() - 1; //stop the loop
break;
case eGB18030:
theOutputString = "GB13080";
itor = inCharSetType.end() - 1; //stop the loop
break;
}
if (itor < (inCharSetType.end()-1))
{
theOutputString += "\\";
// the following code will not work for UTF-8 and eGB18030
assert( itor < inCharSetType.end() );
visited[*itor] = true;
}
}
if( theOutputString.size() % 2 )
theOutputString.push_back( ' ' ); // no \0 !
theReturn.SetByteValue(theOutputString.c_str(),
(uint32_t)theOutputString.length());
theReturn.SetTag(Tag(0x0008, 0x0005));
return theReturn;
}
void QueryFactory::ListCharSets(std::ostream& os)
{
os << "The following character sets are supported by GDCM Network Queries." << std::endl;
os << "The number in the parenthesis is the index to select." << std::endl;
os << "Note that multiple selections are possible." << std::endl;
os << "Latin1 (0): This is the default if nothing is specified." <<std::endl;
os << "Latin2 (1)" << std::endl;
os << "Latin3 (2)" << std::endl;
os << "Latin4 (3)" << std::endl;
os << "Cyrillic (4)" << std::endl;
os << "Arabic (5)" << std::endl;
os << "Greek (6)" << std::endl;
os << "Hebrew (7)" << std::endl;
os << "Latin5 (8)" << std::endl;
os << "Japanese (9)" << std::endl;
os << "Thai (10)" << std::endl;
os << "Kanji (Japanese) (11)+" << std::endl;
os << "Supplementary Kanji (12)+" << std::endl;
os << "Hangul and Hanja (Korean) (13)+" << std::endl;
os << "UTF-8 (14)++" << std::endl;
os << "GB1308 (15)++" << std::endl;
os << "+ These character sets must be chosen second or later in a set." << std::endl;
os << "++ These character sets must be chosen alone, in no set." << std::endl;
}
} // end namespace gdcm
|