comparison OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 3737:f29843323daf storage-commitment

accessing storage commitment reports from REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Mar 2020 20:33:01 +0100
parents 4fc24b69446a
children bff4da769f6f
comparison
equal deleted inserted replaced
3736:0540b54324f1 3737:f29843323daf
44 #include "../ServerContext.h" 44 #include "../ServerContext.h"
45 #include "../ServerJobs/DicomModalityStoreJob.h" 45 #include "../ServerJobs/DicomModalityStoreJob.h"
46 #include "../ServerJobs/DicomMoveScuJob.h" 46 #include "../ServerJobs/DicomMoveScuJob.h"
47 #include "../ServerJobs/OrthancPeerStoreJob.h" 47 #include "../ServerJobs/OrthancPeerStoreJob.h"
48 #include "../ServerToolbox.h" 48 #include "../ServerToolbox.h"
49 #include "../StorageCommitmentReports.h"
49 50
50 51
51 namespace Orthanc 52 namespace Orthanc
52 { 53 {
53 static const char* const KEY_LEVEL = "Level"; 54 static const char* const KEY_LEVEL = "Level";
1303 throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON object"); 1304 throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON object");
1304 } 1305 }
1305 } 1306 }
1306 1307
1307 1308
1308 static void StorageCommitment(RestApiPostCall& call) 1309 // Storage commitment SCU ---------------------------------------------------
1310
1311 static void StorageCommitmentScu(RestApiPostCall& call)
1309 { 1312 {
1310 ServerContext& context = OrthancRestApi::GetContext(call); 1313 ServerContext& context = OrthancRestApi::GetContext(call);
1311 1314
1312 Json::Value json; 1315 Json::Value json;
1313 if (call.ParseJsonRequest(json) || 1316 if (call.ParseJsonRequest(json) ||
1362 "JSON array or object is expected to specify one " 1365 "JSON array or object is expected to specify one "
1363 "instance to be queried, found: " + json[i].toStyledString()); 1366 "instance to be queried, found: " + json[i].toStyledString());
1364 } 1367 }
1365 } 1368 }
1366 1369
1367 const std::string transaction = Toolbox::GenerateDicomPrivateUniqueIdentifier(); 1370 const std::string transactionUid = Toolbox::GenerateDicomPrivateUniqueIdentifier();
1368 1371
1369 { 1372 {
1370 const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
1371 const RemoteModalityParameters remote = 1373 const RemoteModalityParameters remote =
1372 MyGetModalityUsingSymbolicName(call.GetUriComponent("id", "")); 1374 MyGetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
1373 1375
1376 const std::string& remoteAet = remote.GetApplicationEntityTitle();
1377 const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
1378
1379 // Create a "pending" storage commitment report BEFORE the
1380 // actual SCU call in order to avoid race conditions
1381 context.GetStorageCommitmentReports().Store(
1382 transactionUid, new StorageCommitmentReports::Report(remoteAet));
1383
1374 DicomUserConnection scu(localAet, remote); 1384 DicomUserConnection scu(localAet, remote);
1375 scu.RequestStorageCommitment(transaction, sopClassUids, sopInstanceUids); 1385 scu.RequestStorageCommitment(transactionUid, sopClassUids, sopInstanceUids);
1376 } 1386 }
1377 1387
1378 Json::Value result = Json::objectValue; 1388 Json::Value result = Json::objectValue;
1379 result["ID"] = transaction; 1389 result["ID"] = transactionUid;
1380 result["Path"] = "/storage-commitment/" + transaction; 1390 result["Path"] = "/storage-commitment/" + transactionUid;
1381 call.GetOutput().AnswerJson(result); 1391 call.GetOutput().AnswerJson(result);
1382 } 1392 }
1383 else 1393 else
1384 { 1394 {
1385 throw OrthancException(ErrorCode_BadFileFormat, 1395 throw OrthancException(ErrorCode_BadFileFormat,
1386 "Must provide a JSON array with a list of instances"); 1396 "Must provide a JSON array with a list of instances");
1387 } 1397 }
1388 } 1398 }
1389 1399
1400
1401 static void GetStorageCommitmentReport(RestApiGetCall& call)
1402 {
1403 ServerContext& context = OrthancRestApi::GetContext(call);
1404
1405 const std::string& transactionUid = call.GetUriComponent("id", "");
1406
1407 {
1408 StorageCommitmentReports::Accessor accessor(
1409 context.GetStorageCommitmentReports(), transactionUid);
1410
1411 if (accessor.IsValid())
1412 {
1413 Json::Value json;
1414 accessor.GetReport().Format(json);
1415 call.GetOutput().AnswerJson(json);
1416 }
1417 else
1418 {
1419 throw OrthancException(ErrorCode_InexistentItem,
1420 "No storage commitment transaction with UID: " + transactionUid);
1421 }
1422 }
1423 }
1424
1390 1425
1391 void OrthancRestApi::RegisterModalities() 1426 void OrthancRestApi::RegisterModalities()
1392 { 1427 {
1393 Register("/modalities", ListModalities); 1428 Register("/modalities", ListModalities);
1394 Register("/modalities/{id}", ListModalityOperations); 1429 Register("/modalities/{id}", ListModalityOperations);
1430 Register("/peers/{id}/store", PeerStore); 1465 Register("/peers/{id}/store", PeerStore);
1431 Register("/peers/{id}/system", PeerSystem); 1466 Register("/peers/{id}/system", PeerSystem);
1432 1467
1433 Register("/modalities/{id}/find-worklist", DicomFindWorklist); 1468 Register("/modalities/{id}/find-worklist", DicomFindWorklist);
1434 1469
1435 Register("/modalities/{id}/storage-commitment", StorageCommitment); 1470 Register("/modalities/{id}/storage-commitment", StorageCommitmentScu);
1471 Register("/storage-commitment/{id}", GetStorageCommitmentReport);
1436 } 1472 }
1437 } 1473 }