Mercurial > hg > orthanc
comparison Core/DicomParsing/DicomModification.cpp @ 2662:47d812308d63 jobs
serialization of DicomModification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Jun 2018 17:47:41 +0200 |
parents | c196d76cb8fa |
children | 2540ac79ab6c |
comparison
equal
deleted
inserted
replaced
2660:27b7884512be | 2662:47d812308d63 |
---|---|
34 #include "../PrecompiledHeaders.h" | 34 #include "../PrecompiledHeaders.h" |
35 #include "DicomModification.h" | 35 #include "DicomModification.h" |
36 | 36 |
37 #include "../Logging.h" | 37 #include "../Logging.h" |
38 #include "../OrthancException.h" | 38 #include "../OrthancException.h" |
39 #include "../SerializationToolbox.h" | |
39 #include "FromDcmtkBridge.h" | 40 #include "FromDcmtkBridge.h" |
40 #include "ITagVisitor.h" | 41 #include "ITagVisitor.h" |
41 | 42 |
42 #include <memory> // For std::auto_ptr | 43 #include <memory> // For std::auto_ptr |
43 | 44 |
1236 | 1237 |
1237 patientNameReplaced = (IsReplaced(DICOM_TAG_PATIENT_NAME) && | 1238 patientNameReplaced = (IsReplaced(DICOM_TAG_PATIENT_NAME) && |
1238 GetReplacement(DICOM_TAG_PATIENT_NAME) == patientName); | 1239 GetReplacement(DICOM_TAG_PATIENT_NAME) == patientName); |
1239 } | 1240 } |
1240 | 1241 |
1242 | |
1243 | |
1244 | |
1245 static const char* REMOVE_PRIVATE_TAGS = "RemovePrivateTags"; | |
1246 static const char* LEVEL = "Level"; | |
1247 static const char* ALLOW_MANUAL_IDENTIFIERS = "AllowManualIdentifiers"; | |
1248 static const char* KEEP_STUDY_INSTANCE_UID = "KeepStudyInstanceUID"; | |
1249 static const char* KEEP_SERIES_INSTANCE_UID = "KeepSeriesInstanceUID"; | |
1250 static const char* UPDATE_REFERENCED_RELATIONSHIPS = "UpdateReferencedRelationships"; | |
1251 static const char* REMOVALS = "Removals"; | |
1252 static const char* CLEARINGS = "Clearings"; | |
1253 static const char* PRIVATE_TAGS_TO_KEEP = "PrivateTagsToKeep"; | |
1254 static const char* REPLACEMENTS = "Replacements"; | |
1255 static const char* MAP_PATIENTS = "MapPatients"; | |
1256 static const char* MAP_STUDIES = "MapStudies"; | |
1257 static const char* MAP_SERIES = "MapSeries"; | |
1258 static const char* MAP_INSTANCES = "MapInstances"; | |
1241 | 1259 |
1242 void DicomModification::Serialize(Json::Value& value) const | 1260 void DicomModification::Serialize(Json::Value& value) const |
1243 { | 1261 { |
1244 throw OrthancException(ErrorCode_NotImplemented); | 1262 if (identifierGenerator_ != NULL) |
1263 { | |
1264 LOG(ERROR) << "Cannot serialize a DicomModification with a custom identifier generator"; | |
1265 throw OrthancException(ErrorCode_InternalError); | |
1266 } | |
1267 | |
1268 value = Json::objectValue; | |
1269 value[REMOVE_PRIVATE_TAGS] = removePrivateTags_; | |
1270 value[LEVEL] = EnumerationToString(level_); | |
1271 value[ALLOW_MANUAL_IDENTIFIERS] = allowManualIdentifiers_; | |
1272 value[KEEP_STUDY_INSTANCE_UID] = keepStudyInstanceUid_; | |
1273 value[KEEP_SERIES_INSTANCE_UID] = keepSeriesInstanceUid_; | |
1274 value[UPDATE_REFERENCED_RELATIONSHIPS] = updateReferencedRelationships_; | |
1275 | |
1276 SerializationToolbox::WriteSetOfTags(value, removals_, REMOVALS); | |
1277 SerializationToolbox::WriteSetOfTags(value, clearings_, CLEARINGS); | |
1278 SerializationToolbox::WriteSetOfTags(value, privateTagsToKeep_, PRIVATE_TAGS_TO_KEEP); | |
1279 | |
1280 Json::Value& tmp = value[REPLACEMENTS]; | |
1281 | |
1282 tmp = Json::objectValue; | |
1283 | |
1284 for (Replacements::const_iterator it = replacements_.begin(); | |
1285 it != replacements_.end(); ++it) | |
1286 { | |
1287 assert(it->second != NULL); | |
1288 tmp[it->first.Format()] = *it->second; | |
1289 } | |
1290 | |
1291 Json::Value& mapPatients = value[MAP_PATIENTS]; | |
1292 Json::Value& mapStudies = value[MAP_STUDIES]; | |
1293 Json::Value& mapSeries = value[MAP_SERIES]; | |
1294 Json::Value& mapInstances = value[MAP_INSTANCES]; | |
1295 | |
1296 mapPatients = Json::objectValue; | |
1297 mapStudies = Json::objectValue; | |
1298 mapSeries = Json::objectValue; | |
1299 mapInstances = Json::objectValue; | |
1300 | |
1301 for (UidMap::const_iterator it = uidMap_.begin(); it != uidMap_.end(); ++it) | |
1302 { | |
1303 Json::Value* tmp = NULL; | |
1304 | |
1305 switch (it->first.first) | |
1306 { | |
1307 case ResourceType_Patient: | |
1308 tmp = &mapPatients; | |
1309 break; | |
1310 | |
1311 case ResourceType_Study: | |
1312 tmp = &mapStudies; | |
1313 break; | |
1314 | |
1315 case ResourceType_Series: | |
1316 tmp = &mapSeries; | |
1317 break; | |
1318 | |
1319 case ResourceType_Instance: | |
1320 tmp = &mapInstances; | |
1321 break; | |
1322 | |
1323 default: | |
1324 throw OrthancException(ErrorCode_InternalError); | |
1325 } | |
1326 | |
1327 assert(tmp != NULL); | |
1328 (*tmp) [it->first.second] = it->second; | |
1329 } | |
1330 } | |
1331 | |
1332 | |
1333 void DicomModification::UnserializeUidMap(ResourceType level, | |
1334 const Json::Value& serialized, | |
1335 const char* field) | |
1336 { | |
1337 if (!serialized.isMember(field) || | |
1338 serialized[field].type() != Json::objectValue) | |
1339 { | |
1340 throw OrthancException(ErrorCode_BadFileFormat); | |
1341 } | |
1342 | |
1343 Json::Value::Members names = serialized[field].getMemberNames(); | |
1344 | |
1345 for (Json::Value::Members::const_iterator it = names.begin(); it != names.end(); ++it) | |
1346 { | |
1347 const Json::Value& value = serialized[field][*it]; | |
1348 | |
1349 if (value.type() != Json::stringValue) | |
1350 { | |
1351 throw OrthancException(ErrorCode_BadFileFormat); | |
1352 } | |
1353 else | |
1354 { | |
1355 uidMap_[std::make_pair(level, *it)] = value.asString(); | |
1356 } | |
1357 } | |
1245 } | 1358 } |
1246 | 1359 |
1247 | 1360 |
1248 DicomModification::DicomModification(const Json::Value& serialized) | 1361 DicomModification::DicomModification(const Json::Value& serialized) |
1249 { | 1362 { |
1250 throw OrthancException(ErrorCode_NotImplemented); | 1363 removePrivateTags_ = SerializationToolbox::ReadBoolean(serialized, REMOVE_PRIVATE_TAGS); |
1364 level_ = StringToResourceType(SerializationToolbox::ReadString(serialized, LEVEL).c_str()); | |
1365 allowManualIdentifiers_ = SerializationToolbox::ReadBoolean(serialized, ALLOW_MANUAL_IDENTIFIERS); | |
1366 keepStudyInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_STUDY_INSTANCE_UID); | |
1367 keepSeriesInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SERIES_INSTANCE_UID); | |
1368 updateReferencedRelationships_ = SerializationToolbox::ReadBoolean | |
1369 (serialized, UPDATE_REFERENCED_RELATIONSHIPS); | |
1370 | |
1371 SerializationToolbox::ReadSetOfTags(removals_, serialized, REMOVALS); | |
1372 SerializationToolbox::ReadSetOfTags(clearings_, serialized, CLEARINGS); | |
1373 SerializationToolbox::ReadSetOfTags(privateTagsToKeep_, serialized, PRIVATE_TAGS_TO_KEEP); | |
1374 | |
1375 if (!serialized.isMember(REPLACEMENTS) || | |
1376 serialized[REPLACEMENTS].type() != Json::objectValue) | |
1377 { | |
1378 throw OrthancException(ErrorCode_BadFileFormat); | |
1379 } | |
1380 | |
1381 Json::Value::Members names = serialized[REPLACEMENTS].getMemberNames(); | |
1382 | |
1383 for (Json::Value::Members::const_iterator it = names.begin(); it != names.end(); ++it) | |
1384 { | |
1385 DicomTag tag(0, 0); | |
1386 if (!DicomTag::ParseHexadecimal(tag, it->c_str())) | |
1387 { | |
1388 throw OrthancException(ErrorCode_BadFileFormat); | |
1389 } | |
1390 else | |
1391 { | |
1392 const Json::Value& value = serialized[REPLACEMENTS][*it]; | |
1393 replacements_.insert(std::make_pair(tag, new Json::Value(value))); | |
1394 } | |
1395 } | |
1396 | |
1397 UnserializeUidMap(ResourceType_Patient, serialized, MAP_PATIENTS); | |
1398 UnserializeUidMap(ResourceType_Study, serialized, MAP_STUDIES); | |
1399 UnserializeUidMap(ResourceType_Series, serialized, MAP_SERIES); | |
1400 UnserializeUidMap(ResourceType_Instance, serialized, MAP_INSTANCES); | |
1251 } | 1401 } |
1252 } | 1402 } |