Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi.cpp @ 350:8031f9cfe7fe
removal of old code
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 28 Jan 2013 15:36:44 +0100 |
parents | c5edf0cc6e95 |
children | 64625960af22 |
comparison
equal
deleted
inserted
replaced
349:c5edf0cc6e95 | 350:8031f9cfe7fe |
---|---|
867 | 867 |
868 namespace | 868 namespace |
869 { | 869 { |
870 typedef std::set<DicomTag> Removals; | 870 typedef std::set<DicomTag> Removals; |
871 typedef std::map<DicomTag, std::string> Replacements; | 871 typedef std::map<DicomTag, std::string> Replacements; |
872 typedef std::map< std::pair<DicomRootLevel, std::string>, std::string> UidMap; | |
872 } | 873 } |
873 | 874 |
874 static void ReplaceInstanceInternal(ParsedDicomFile& toModify, | 875 static void ReplaceInstanceInternal(ParsedDicomFile& toModify, |
875 const Removals& removals, | 876 const Removals& removals, |
876 const Replacements& replacements, | 877 const Replacements& replacements, |
1157 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); | 1158 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); |
1158 modified->Answer(call.GetOutput()); | 1159 modified->Answer(call.GetOutput()); |
1159 } | 1160 } |
1160 | 1161 |
1161 | 1162 |
1162 static void AnonymizeOrModifySeries(Removals& removals, | |
1163 Replacements& replacements, | |
1164 bool removePrivateTags, | |
1165 MetadataType metadataType, | |
1166 ChangeType changeType, | |
1167 RestApi::PostCall& call) | |
1168 { | |
1169 Json::Value result = Json::objectValue; | |
1170 | |
1171 { | |
1172 boost::mutex::scoped_lock lock(cacheMutex_); | |
1173 RETRIEVE_CONTEXT(call); | |
1174 | |
1175 typedef std::list<std::string> Instances; | |
1176 Instances instances; | |
1177 std::string id = call.GetUriComponent("id", ""); | |
1178 context.GetIndex().GetChildInstances(instances, id); | |
1179 | |
1180 if (instances.size() == 0) | |
1181 { | |
1182 return; | |
1183 } | |
1184 | |
1185 replacements[DICOM_TAG_SERIES_INSTANCE_UID] = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series); | |
1186 | |
1187 std::string newSeriesId, newPatientId; | |
1188 for (Instances::const_iterator it = instances.begin(); | |
1189 it != instances.end(); it++) | |
1190 { | |
1191 LOG(INFO) << "Modifying instance " << *it; | |
1192 ParsedDicomFile& original = context.GetDicomFile(*it); | |
1193 std::auto_ptr<ParsedDicomFile> modified(original.Clone()); | |
1194 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); | |
1195 | |
1196 std::string modifiedInstance; | |
1197 if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success) | |
1198 { | |
1199 LOG(ERROR) << "Error while storing a modified instance " << *it; | |
1200 return; | |
1201 } | |
1202 | |
1203 DicomInstanceHasher modifiedHasher = modified->GetHasher(); | |
1204 DicomInstanceHasher originalHasher = original.GetHasher(); | |
1205 | |
1206 if (newSeriesId.size() == 0) | |
1207 { | |
1208 assert(id == originalHasher.HashSeries()); | |
1209 newSeriesId = modifiedHasher.HashSeries(); | |
1210 context.GetIndex().SetMetadata(newSeriesId, metadataType, id); | |
1211 } | |
1212 | |
1213 if (newPatientId.size() == 0) | |
1214 { | |
1215 newPatientId = modifiedHasher.HashPatient(); | |
1216 } | |
1217 | |
1218 assert(*it == originalHasher.HashInstance()); | |
1219 assert(modifiedInstance == modifiedHasher.HashInstance()); | |
1220 context.GetIndex().SetMetadata(modifiedInstance, metadataType, *it); | |
1221 } | |
1222 | |
1223 context.GetIndex().LogChange(changeType, newSeriesId); | |
1224 | |
1225 assert(newSeriesId.size() != 0); | |
1226 result["Type"] = ToString(ResourceType_Series); | |
1227 result["ID"] = newSeriesId; | |
1228 result["Path"] = GetBasePath(ResourceType_Series, newSeriesId); | |
1229 result["PatientID"] = newPatientId; | |
1230 } | |
1231 | |
1232 // Do not answer before the lock has been released | |
1233 call.GetOutput().AnswerJson(result); | |
1234 } | |
1235 | |
1236 | |
1237 static void AnonymizeOrModifyStudy(Removals& removals, | |
1238 Replacements& replacements, | |
1239 bool removePrivateTags, | |
1240 MetadataType metadataType, | |
1241 ChangeType changeType, | |
1242 RestApi::PostCall& call) | |
1243 { | |
1244 Json::Value result = Json::objectValue; | |
1245 | |
1246 { | |
1247 boost::mutex::scoped_lock lock(cacheMutex_); | |
1248 RETRIEVE_CONTEXT(call); | |
1249 | |
1250 typedef std::list<std::string> Instances; | |
1251 typedef std::map<std::string, std::string> SeriesUidMap; | |
1252 | |
1253 Instances instances; | |
1254 std::string id = call.GetUriComponent("id", ""); | |
1255 context.GetIndex().GetChildInstances(instances, id); | |
1256 | |
1257 if (instances.size() == 0) | |
1258 { | |
1259 return; | |
1260 } | |
1261 | |
1262 std::string newPatientId; | |
1263 std::string newStudyId; | |
1264 replacements[DICOM_TAG_STUDY_INSTANCE_UID] = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study); | |
1265 | |
1266 SeriesUidMap seriesUidMap; | |
1267 for (Instances::const_iterator it = instances.begin(); | |
1268 it != instances.end(); it++) | |
1269 { | |
1270 LOG(INFO) << "Modifying instance " << *it; | |
1271 ParsedDicomFile& original = context.GetDicomFile(*it); | |
1272 | |
1273 std::string seriesUid; | |
1274 if (!original.GetTagValue(seriesUid, DICOM_TAG_SERIES_INSTANCE_UID)) | |
1275 { | |
1276 throw OrthancException(ErrorCode_InternalError); | |
1277 } | |
1278 | |
1279 bool isNewSeries; | |
1280 SeriesUidMap::const_iterator it2 = seriesUidMap.find(seriesUid); | |
1281 if (it2 == seriesUidMap.end()) | |
1282 { | |
1283 std::string newSeriesUid = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series); | |
1284 seriesUidMap[seriesUid] = newSeriesUid; | |
1285 replacements[DICOM_TAG_SERIES_INSTANCE_UID] = newSeriesUid; | |
1286 isNewSeries = true; | |
1287 } | |
1288 else | |
1289 { | |
1290 replacements[DICOM_TAG_SERIES_INSTANCE_UID] = it2->second; | |
1291 isNewSeries = false; | |
1292 } | |
1293 | |
1294 std::auto_ptr<ParsedDicomFile> modified(original.Clone()); | |
1295 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); | |
1296 | |
1297 std::string modifiedInstance; | |
1298 if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success) | |
1299 { | |
1300 LOG(ERROR) << "Error while storing a modified instance " << *it; | |
1301 return; | |
1302 } | |
1303 | |
1304 DicomInstanceHasher modifiedHasher = modified->GetHasher(); | |
1305 DicomInstanceHasher originalHasher = original.GetHasher(); | |
1306 | |
1307 if (isNewSeries) | |
1308 { | |
1309 context.GetIndex().SetMetadata | |
1310 (modifiedHasher.HashSeries(), metadataType, originalHasher.HashSeries()); | |
1311 } | |
1312 | |
1313 if (newStudyId.size() == 0) | |
1314 { | |
1315 newStudyId = modifiedHasher.HashStudy(); | |
1316 context.GetIndex().SetMetadata(newStudyId, metadataType, originalHasher.HashStudy()); | |
1317 } | |
1318 | |
1319 if (newPatientId.size() == 0) | |
1320 { | |
1321 newPatientId = modifiedHasher.HashPatient(); | |
1322 } | |
1323 | |
1324 assert(*it == originalHasher.HashInstance()); | |
1325 assert(modifiedInstance == modifiedHasher.HashInstance()); | |
1326 context.GetIndex().SetMetadata(modifiedInstance, metadataType, *it); | |
1327 } | |
1328 | |
1329 context.GetIndex().LogChange(changeType, newStudyId); | |
1330 | |
1331 assert(newStudyId.size() != 0); | |
1332 result["Type"] = ToString(ResourceType_Study); | |
1333 result["ID"] = newStudyId; | |
1334 result["Path"] = GetBasePath(ResourceType_Study, newStudyId); | |
1335 result["PatientID"] = newPatientId; | |
1336 } | |
1337 | |
1338 // Do not answer before the lock has been released | |
1339 call.GetOutput().AnswerJson(result); | |
1340 } | |
1341 | |
1342 | |
1343 | |
1344 namespace | |
1345 { | |
1346 typedef std::map< std::pair<DicomRootLevel, std::string>, std::string> UidMap; | |
1347 } | |
1348 | |
1349 static bool RetrieveMappedUid(ParsedDicomFile& dicom, | 1163 static bool RetrieveMappedUid(ParsedDicomFile& dicom, |
1350 DicomRootLevel level, | 1164 DicomRootLevel level, |
1351 Replacements& replacements, | 1165 Replacements& replacements, |
1352 UidMap& uidMap) | 1166 UidMap& uidMap) |
1353 { | 1167 { |