changeset 5606:6e2dad336446 find-refactoring

added "IsStable" field in expanded resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 May 2024 10:46:11 +0200
parents 3f24eb4013d8
children a3732285f8b6
files OrthancServer/Sources/Database/Compatibility/GenericFind.cpp OrthancServer/Sources/Database/FindResponse.h OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/ServerIndex.h
diffstat 4 files changed, 26 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Wed May 08 10:30:57 2024 +0200
+++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Wed May 08 10:46:11 2024 +0200
@@ -189,7 +189,7 @@
         throw OrthancException(ErrorCode_DatabasePlugin);
       }
 
-      std::unique_ptr<FindResponse::Resource> resource(new FindResponse::Resource(request.GetLevel(), identifier));
+      std::unique_ptr<FindResponse::Resource> resource(new FindResponse::Resource(request.GetLevel(), internalId, identifier));
 
       if (request.IsRetrieveParentIdentifier())
       {
--- a/OrthancServer/Sources/Database/FindResponse.h	Wed May 08 10:30:57 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.h	Wed May 08 10:46:11 2024 +0200
@@ -73,6 +73,7 @@
       typedef std::map<MetadataType, std::list<std::string>*>  ChildrenMetadata;
 
       ResourceType                          level_;
+      int64_t                               internalId_;   // Internal ID of the resource in the database
       std::string                           identifier_;
       std::unique_ptr<std::string>          parentIdentifier_;
       MainDicomTagsAtLevel                  mainDicomTagsPatient_;
@@ -98,8 +99,10 @@
 
     public:
       Resource(ResourceType level,
+               int64_t internalId,
                const std::string& identifier) :
         level_(level),
+        internalId_(internalId),
         identifier_(identifier)
       {
       }
@@ -111,6 +114,11 @@
         return level_;
       }
 
+      int64_t GetInternalId() const
+      {
+        return internalId_;
+      }
+
       const std::string& GetIdentifier() const
       {
         return identifier_;
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Wed May 08 10:30:57 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Wed May 08 10:46:11 2024 +0200
@@ -268,29 +268,10 @@
 
 
     void Expand(Json::Value& target,
-                const FindResponse::Resource& resource) const
+                const FindResponse::Resource& resource,
+                ServerIndex& index) const
     {
       /**
-
-         TODO-FIND:
-
-         - Metadata / Series / ExpectedNumberOfInstances
-
-         - Metadata / Series / Status
-
-         - Metadata / Instance / FileSize
-
-         - Metadata / Instance / FileUuid
-
-         - Metadata / Instance / IndexInSeries
-
-         - Metadata / AnonymizedFrom
-
-         - Metadata / ModifiedFrom
-
-      **/
-
-      /**
        * This method closely follows "SerializeExpandedResource()" in
        * "ServerContext.cpp" from Orthanc 1.12.3.
        **/
@@ -300,6 +281,11 @@
         throw OrthancException(ErrorCode_InternalError);
       }
 
+      if (!requestedTags_.empty())
+      {
+        throw OrthancException(ErrorCode_NotImplemented);
+      }
+
       target = Json::objectValue;
 
       target["Type"] = GetResourceTypeText(resource.GetLevel(), false, true);
@@ -428,14 +414,7 @@
           resource.GetLevel() == ResourceType_Study ||
           resource.GetLevel() == ResourceType_Series)
       {
-        // TODO-FIND: Stable
-
-        /*
-          if (resource.IsStable())
-        {
-          target["IsStable"] = true;
-        }
-        */
+        target["IsStable"] = !index.IsUnstableResource(resource.GetLevel(), resource.GetInternalId());
 
         if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_LastUpdate))
         {
@@ -444,6 +423,10 @@
       }
 
       {
+        // TODO-FIND : (expandFlags & ExpandResourceFlags_IncludeMainDicomTags)
+      }
+
+      {
         Json::Value labels = Json::arrayValue;
 
         for (std::set<std::string>::const_iterator
@@ -455,7 +438,7 @@
         target["Labels"] = labels;
       }
 
-      if (includeAllMetadata_)
+      if (includeAllMetadata_)  // new in Orthanc 1.12.4
       {
         const std::map<MetadataType, std::string>& m = resource.GetMetadata(resource.GetLevel());
 
@@ -540,7 +523,7 @@
         for (size_t i = 0; i < response.GetSize(); i++)
         {
           Json::Value item;
-          Expand(item, response.GetResource(i));
+          Expand(item, response.GetResource(i), context.GetIndex());
 
 #if 0
           target.append(item);
--- a/OrthancServer/Sources/ServerIndex.h	Wed May 08 10:30:57 2024 +0200
+++ b/OrthancServer/Sources/ServerIndex.h	Wed May 08 10:46:11 2024 +0200
@@ -59,9 +59,6 @@
                         int64_t id,
                         const std::string& publicId);
 
-    bool IsUnstableResource(ResourceType type,
-                            int64_t id);
-
   public:
     ServerIndex(ServerContext& context,
                 IDatabaseWrapper& database,
@@ -98,5 +95,8 @@
                               bool hasOldRevision,
                               int64_t oldRevision,
                               const std::string& oldMD5);
+
+    bool IsUnstableResource(ResourceType type,
+                            int64_t id);
   };
 }