Mercurial > hg > orthanc
changeset 2726:46061a91c88a jobs
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Jul 2018 18:01:16 +0200 |
parents | 7caf01aa4d7b |
children | 815e30657dad |
files | NEWS OrthancServer/DicomInstanceOrigin.cpp OrthancServer/DicomInstanceOrigin.h OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/ServerEnumerations.cpp OrthancServer/ServerEnumerations.h OrthancServer/ServerIndex.cpp UnitTestsSources/MultiThreadingTests.cpp |
diffstat | 8 files changed, 107 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Thu Jul 12 16:07:56 2018 +0200 +++ b/NEWS Thu Jul 12 18:01:16 2018 +0200 @@ -9,6 +9,8 @@ - "ConcurrentJobs": Max number of jobs that are simultanously running - "SynchronousCMove": Whether to run DICOM C-Move operations synchronously - "JobsHistorySize": Max number of completed jobs that are kept in memory +* New metadata automatically computed at the instance level: + "RemoteIp", "CalledAet" and "HttpUsername" Orthanc Explorer ---------------- @@ -35,6 +37,7 @@ * "/instances/.../frame/../image-uint8 and friends now accepts a "image/pam" MIME type to retrieve images in PAM format (https://en.wikipedia.org/wiki/Netpbm#PAM_graphics_format) +* New option "?expand" to "/instances/.../metadata" Plugins -------
--- a/OrthancServer/DicomInstanceOrigin.cpp Thu Jul 12 16:07:56 2018 +0200 +++ b/OrthancServer/DicomInstanceOrigin.cpp Thu Jul 12 18:01:16 2018 +0200 @@ -127,40 +127,56 @@ } } - const std::string& DicomInstanceOrigin::GetRemoteIp() const + bool DicomInstanceOrigin::LookupRemoteAet(std::string& result) const + { + if (origin_ == RequestOrigin_DicomProtocol) + { + result = dicomRemoteAet_.c_str(); + return true; + } + else + { + return false; + } + } + + bool DicomInstanceOrigin::LookupRemoteIp(std::string& result) const { if (origin_ == RequestOrigin_DicomProtocol || origin_ == RequestOrigin_RestApi) { - return remoteIp_; + result = remoteIp_; + return true; } else { - throw OrthancException(ErrorCode_ParameterOutOfRange); + return false; } } - const std::string& DicomInstanceOrigin::GetCalledAet() const + bool DicomInstanceOrigin::LookupCalledAet(std::string& result) const { if (origin_ == RequestOrigin_DicomProtocol) { - return dicomCalledAet_; + result = dicomCalledAet_; + return true; } else { - throw OrthancException(ErrorCode_ParameterOutOfRange); + return false; } } - const std::string& DicomInstanceOrigin::GetHttpUsername() const + bool DicomInstanceOrigin::LookupHttpUsername(std::string& result) const { if (origin_ == RequestOrigin_RestApi) { - return httpUsername_; + result = httpUsername_; + return true; } else { - throw OrthancException(ErrorCode_ParameterOutOfRange); + return false; } }
--- a/OrthancServer/DicomInstanceOrigin.h Thu Jul 12 16:07:56 2018 +0200 +++ b/OrthancServer/DicomInstanceOrigin.h Thu Jul 12 18:01:16 2018 +0200 @@ -85,11 +85,13 @@ const char* GetRemoteAetC() const; - const std::string& GetRemoteIp() const; - - const std::string& GetCalledAet() const; + bool LookupRemoteAet(std::string& result) const; + + bool LookupRemoteIp(std::string& result) const; - const std::string& GetHttpUsername() const; + bool LookupCalledAet(std::string& result) const; + + bool LookupHttpUsername(std::string& result) const; void Format(Json::Value& result) const;
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Jul 12 16:07:56 2018 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Jul 12 18:01:16 2018 +0200 @@ -673,12 +673,33 @@ std::list<MetadataType> metadata; OrthancRestApi::GetIndex(call).ListAvailableMetadata(metadata, publicId); - Json::Value result = Json::arrayValue; + + Json::Value result; - for (std::list<MetadataType>::const_iterator - it = metadata.begin(); it != metadata.end(); ++it) + if (call.HasArgument("expand")) { - result.append(EnumerationToString(*it)); + result = Json::objectValue; + + for (std::list<MetadataType>::const_iterator + it = metadata.begin(); it != metadata.end(); ++it) + { + std::string value; + if (OrthancRestApi::GetIndex(call).LookupMetadata(value, publicId, *it)) + { + std::string key = EnumerationToString(*it); + result[key] = value; + } + } + } + else + { + result = Json::arrayValue; + + for (std::list<MetadataType>::const_iterator + it = metadata.begin(); it != metadata.end(); ++it) + { + result.append(EnumerationToString(*it)); + } } call.GetOutput().AnswerJson(result);
--- a/OrthancServer/ServerEnumerations.cpp Thu Jul 12 16:07:56 2018 +0200 +++ b/OrthancServer/ServerEnumerations.cpp Thu Jul 12 18:01:16 2018 +0200 @@ -67,6 +67,9 @@ dictMetadataType_.Add(MetadataType_Instance_Origin, "Origin"); dictMetadataType_.Add(MetadataType_Instance_TransferSyntax, "TransferSyntax"); dictMetadataType_.Add(MetadataType_Instance_SopClassUid, "SopClassUid"); + dictMetadataType_.Add(MetadataType_Instance_RemoteIp, "RemoteIP"); + dictMetadataType_.Add(MetadataType_Instance_CalledAet, "CalledAET"); + dictMetadataType_.Add(MetadataType_Instance_HttpUsername, "HttpUsername"); dictContentType_.Add(FileContentType_Dicom, "dicom"); dictContentType_.Add(FileContentType_DicomAsJson, "dicom-as-json");
--- a/OrthancServer/ServerEnumerations.h Thu Jul 12 16:07:56 2018 +0200 +++ b/OrthancServer/ServerEnumerations.h Thu Jul 12 18:01:16 2018 +0200 @@ -104,6 +104,9 @@ MetadataType_Instance_Origin = 8, // New in Orthanc 0.9.5 MetadataType_Instance_TransferSyntax = 9, // New in Orthanc 1.2.0 MetadataType_Instance_SopClassUid = 10, // New in Orthanc 1.2.0 + MetadataType_Instance_RemoteIp = 11, // New in Orthanc 1.4.0 + MetadataType_Instance_CalledAet = 12, // New in Orthanc 1.4.0 + MetadataType_Instance_HttpUsername = 13, // New in Orthanc 1.4.0 // Make sure that the value "65535" can be stored into this enumeration MetadataType_StartUser = 1024,
--- a/OrthancServer/ServerIndex.cpp Thu Jul 12 16:07:56 2018 +0200 +++ b/OrthancServer/ServerIndex.cpp Thu Jul 12 18:01:16 2018 +0200 @@ -785,13 +785,33 @@ instanceToStore.GetOrigin().GetRemoteAetC()); SetInstanceMetadata(instanceMetadata, instance, MetadataType_Instance_Origin, EnumerationToString(instanceToStore.GetOrigin().GetRequestOrigin())); - + { std::string s; + if (instanceToStore.LookupTransferSyntax(s)) { + // New in Orthanc 1.2.0 SetInstanceMetadata(instanceMetadata, instance, MetadataType_Instance_TransferSyntax, s); } + + if (instanceToStore.GetOrigin().LookupRemoteIp(s)) + { + // New in Orthanc 1.4.0 + SetInstanceMetadata(instanceMetadata, instance, MetadataType_Instance_RemoteIp, s); + } + + if (instanceToStore.GetOrigin().LookupCalledAet(s)) + { + // New in Orthanc 1.4.0 + SetInstanceMetadata(instanceMetadata, instance, MetadataType_Instance_CalledAet, s); + } + + if (instanceToStore.GetOrigin().LookupHttpUsername(s)) + { + // New in Orthanc 1.4.0 + SetInstanceMetadata(instanceMetadata, instance, MetadataType_Instance_HttpUsername, s); + } } const DicomValue* value;
--- a/UnitTestsSources/MultiThreadingTests.cpp Thu Jul 12 16:07:56 2018 +0200 +++ b/UnitTestsSources/MultiThreadingTests.cpp Thu Jul 12 18:01:16 2018 +0200 @@ -1095,6 +1095,7 @@ TEST(JobsSerialization, DicomInstanceOrigin) { Json::Value s; + std::string t; { DicomInstanceOrigin origin; @@ -1106,10 +1107,11 @@ { DicomInstanceOrigin origin(s); ASSERT_EQ(RequestOrigin_Unknown, origin.GetRequestOrigin()); - ASSERT_THROW(origin.GetRemoteIp(), OrthancException); ASSERT_EQ("", std::string(origin.GetRemoteAetC())); - ASSERT_THROW(origin.GetCalledAet(), OrthancException); - ASSERT_THROW(origin.GetHttpUsername(), OrthancException); + ASSERT_FALSE(origin.LookupRemoteIp(t)); + ASSERT_FALSE(origin.LookupRemoteAet(t)); + ASSERT_FALSE(origin.LookupCalledAet(t)); + ASSERT_FALSE(origin.LookupHttpUsername(t)); } { @@ -1122,10 +1124,11 @@ { DicomInstanceOrigin origin(s); ASSERT_EQ(RequestOrigin_DicomProtocol, origin.GetRequestOrigin()); - ASSERT_EQ("host", origin.GetRemoteIp()); ASSERT_EQ("aet", std::string(origin.GetRemoteAetC())); - ASSERT_EQ("called", origin.GetCalledAet()); - ASSERT_THROW(origin.GetHttpUsername(), OrthancException); + ASSERT_TRUE(origin.LookupRemoteIp(t)); ASSERT_EQ("host", t); + ASSERT_TRUE(origin.LookupRemoteAet(t)); ASSERT_EQ("aet", t); + ASSERT_TRUE(origin.LookupCalledAet(t)); ASSERT_EQ("called", t); + ASSERT_FALSE(origin.LookupHttpUsername(t)); } { @@ -1138,10 +1141,11 @@ { DicomInstanceOrigin origin(s); ASSERT_EQ(RequestOrigin_RestApi, origin.GetRequestOrigin()); - ASSERT_EQ("host", origin.GetRemoteIp()); ASSERT_EQ("", std::string(origin.GetRemoteAetC())); - ASSERT_THROW(origin.GetCalledAet(), OrthancException); - ASSERT_EQ("username", origin.GetHttpUsername()); + ASSERT_TRUE(origin.LookupRemoteIp(t)); ASSERT_EQ("host", t); + ASSERT_FALSE(origin.LookupRemoteAet(t)); + ASSERT_FALSE(origin.LookupCalledAet(t)); + ASSERT_TRUE(origin.LookupHttpUsername(t)); ASSERT_EQ("username", t); } { @@ -1154,6 +1158,10 @@ { DicomInstanceOrigin origin(s); ASSERT_EQ(RequestOrigin_Lua, origin.GetRequestOrigin()); + ASSERT_FALSE(origin.LookupRemoteIp(t)); + ASSERT_FALSE(origin.LookupRemoteAet(t)); + ASSERT_FALSE(origin.LookupCalledAet(t)); + ASSERT_FALSE(origin.LookupHttpUsername(t)); } { @@ -1166,6 +1174,10 @@ { DicomInstanceOrigin origin(s); ASSERT_EQ(RequestOrigin_Plugins, origin.GetRequestOrigin()); + ASSERT_FALSE(origin.LookupRemoteIp(t)); + ASSERT_FALSE(origin.LookupRemoteAet(t)); + ASSERT_FALSE(origin.LookupCalledAet(t)); + ASSERT_FALSE(origin.LookupHttpUsername(t)); } }