Mercurial > hg > orthanc
comparison Core/DicomFormat/DicomMap.cpp @ 3496:109631ed3564
DicomMap::FromDicomWeb()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 21 Aug 2019 16:47:17 +0200 |
parents | 4e43e67f8ecf |
children | 957e06cbe76a |
comparison
equal
deleted
inserted
replaced
3495:cc3e408165eb | 3496:109631ed3564 |
---|---|
38 #include <memory> | 38 #include <memory> |
39 | 39 |
40 #include "../Endianness.h" | 40 #include "../Endianness.h" |
41 #include "../Logging.h" | 41 #include "../Logging.h" |
42 #include "../OrthancException.h" | 42 #include "../OrthancException.h" |
43 #include "../Toolbox.h" | |
43 | 44 |
44 | 45 |
45 namespace Orthanc | 46 namespace Orthanc |
46 { | 47 { |
47 static DicomTag patientTags[] = | 48 static DicomTag patientTags[] = |
1131 value->Unserialize(source[tags[i]]); | 1132 value->Unserialize(source[tags[i]]); |
1132 | 1133 |
1133 map_[tag] = value.release(); | 1134 map_[tag] = value.release(); |
1134 } | 1135 } |
1135 } | 1136 } |
1137 | |
1138 | |
1139 void DicomMap::FromDicomWeb(const Json::Value& source) | |
1140 { | |
1141 static const char* const ALPHABETIC = "Alphabetic"; | |
1142 static const char* const IDEOGRAPHIC = "Ideographic"; | |
1143 static const char* const INLINE_BINARY = "InlineBinary"; | |
1144 static const char* const PHONETIC = "Phonetic"; | |
1145 static const char* const VALUE = "Value"; | |
1146 static const char* const VR = "vr"; | |
1147 | |
1148 Clear(); | |
1149 | |
1150 if (source.type() != Json::objectValue) | |
1151 { | |
1152 throw OrthancException(ErrorCode_BadFileFormat); | |
1153 } | |
1154 | |
1155 Json::Value::Members tags = source.getMemberNames(); | |
1156 | |
1157 for (size_t i = 0; i < tags.size(); i++) | |
1158 { | |
1159 const Json::Value& item = source[tags[i]]; | |
1160 DicomTag tag(0, 0); | |
1161 | |
1162 if (item.type() != Json::objectValue || | |
1163 !item.isMember(VR) || | |
1164 item[VR].type() != Json::stringValue || | |
1165 !DicomTag::ParseHexadecimal(tag, tags[i].c_str())) | |
1166 { | |
1167 throw OrthancException(ErrorCode_BadFileFormat); | |
1168 } | |
1169 | |
1170 ValueRepresentation vr = StringToValueRepresentation(item[VR].asString(), false); | |
1171 | |
1172 if (item.isMember(INLINE_BINARY)) | |
1173 { | |
1174 const Json::Value& value = item[INLINE_BINARY]; | |
1175 | |
1176 if (value.type() == Json::stringValue) | |
1177 { | |
1178 std::string decoded; | |
1179 Toolbox::DecodeBase64(decoded, value.asString()); | |
1180 SetValue(tag, decoded, true /* binary data */); | |
1181 } | |
1182 } | |
1183 else if (!item.isMember(VALUE)) | |
1184 { | |
1185 // Tag is present, but it has a null value | |
1186 SetValue(tag, "", false /* not binary */); | |
1187 } | |
1188 else | |
1189 { | |
1190 const Json::Value& value = item[VALUE]; | |
1191 | |
1192 if (value.type() == Json::arrayValue) | |
1193 { | |
1194 bool supported = true; | |
1195 | |
1196 std::string s; | |
1197 for (Json::Value::ArrayIndex i = 0; i < value.size() && supported; i++) | |
1198 { | |
1199 if (!s.empty()) | |
1200 { | |
1201 s += '\\'; | |
1202 } | |
1203 | |
1204 switch (value[i].type()) | |
1205 { | |
1206 case Json::objectValue: | |
1207 if (vr == ValueRepresentation_PersonName && | |
1208 value[i].type() == Json::objectValue) | |
1209 { | |
1210 if (value[i].isMember(ALPHABETIC) && | |
1211 value[i][ALPHABETIC].type() == Json::stringValue) | |
1212 { | |
1213 s += value[i][ALPHABETIC].asString(); | |
1214 } | |
1215 | |
1216 bool hasIdeographic = false; | |
1217 | |
1218 if (value[i].isMember(IDEOGRAPHIC) && | |
1219 value[i][IDEOGRAPHIC].type() == Json::stringValue) | |
1220 { | |
1221 s += '=' + value[i][IDEOGRAPHIC].asString(); | |
1222 hasIdeographic = true; | |
1223 } | |
1224 | |
1225 if (value[i].isMember(PHONETIC) && | |
1226 value[i][PHONETIC].type() == Json::stringValue) | |
1227 { | |
1228 if (!hasIdeographic) | |
1229 { | |
1230 s += '='; | |
1231 } | |
1232 | |
1233 s += '=' + value[i][PHONETIC].asString(); | |
1234 } | |
1235 } | |
1236 else | |
1237 { | |
1238 // This is the case of sequences | |
1239 supported = false; | |
1240 } | |
1241 | |
1242 break; | |
1243 | |
1244 case Json::stringValue: | |
1245 s += value[i].asString(); | |
1246 break; | |
1247 | |
1248 case Json::intValue: | |
1249 s += boost::lexical_cast<std::string>(value[i].asInt()); | |
1250 break; | |
1251 | |
1252 case Json::uintValue: | |
1253 s += boost::lexical_cast<std::string>(value[i].asUInt()); | |
1254 break; | |
1255 | |
1256 case Json::realValue: | |
1257 s += boost::lexical_cast<std::string>(value[i].asDouble()); | |
1258 break; | |
1259 | |
1260 default: | |
1261 break; | |
1262 } | |
1263 } | |
1264 | |
1265 if (supported) | |
1266 { | |
1267 SetValue(tag, s, false /* not binary */); | |
1268 } | |
1269 } | |
1270 } | |
1271 } | |
1272 } | |
1136 } | 1273 } |