diff Framework/Loaders/SeriesMetadataLoader.h @ 1228:c471a0aa137b broker

adding the next generation of loaders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Dec 2019 13:58:37 +0100
parents
children 0ca50d275b9a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Loaders/SeriesMetadataLoader.h	Mon Dec 09 13:58:37 2019 +0100
@@ -0,0 +1,170 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2019 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "DicomResourcesLoader.h"
+
+namespace OrthancStone
+{
+  class SeriesMetadataLoader :
+    public ObserverBase<SeriesMetadataLoader>,
+    public IObservable
+  {
+  private:
+    enum State
+    {
+      State_Setup,
+      State_Default,
+      State_DicomDir,
+      State_DicomFile
+    };
+
+    typedef std::map<std::string, boost::shared_ptr<LoadedDicomResources> >  Series;
+
+    boost::shared_ptr<DicomResourcesLoader>  loader_;
+    State                                    state_;
+    std::map<std::string, int>               scheduled_;   // Maps a "SeriesInstanceUID" to a priority
+    Series                                   series_;
+    boost::shared_ptr<LoadedDicomResources>  dicomDir_;
+    std::string                              dicomDirPath_;
+    std::map<std::string, unsigned int>      seriesSize_;
+
+    SeriesMetadataLoader(boost::shared_ptr<DicomResourcesLoader>& loader);
+
+    bool IsScheduledWithHigherPriority(const std::string& seriesInstanceUid,
+                                       int priority) const;
+
+    void Handle(const DicomResourcesLoader::SuccessMessage& message);
+
+  public:
+    class SeriesLoadedMessage : public OriginMessage<SeriesMetadataLoader>
+    {
+      ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
+
+    private:
+      const DicomSource&     source_;
+      const std::string&     studyInstanceUid_;
+      const std::string&     seriesInstanceUid_;
+      LoadedDicomResources&  instances_;
+      std::string            dicomDirPath_;
+      boost::shared_ptr<LoadedDicomResources>  dicomDir_;
+
+    public:
+      SeriesLoadedMessage(const SeriesMetadataLoader& loader,
+                          const DicomSource& source,
+                          const std::string& studyInstanceUid,
+                          const std::string& seriesInstanceUid,
+                          LoadedDicomResources& instances);
+
+      const DicomSource& GetDicomSource() const
+      {
+        return source_;
+      }
+      
+      const std::string& GetStudyInstanceUid() const
+      {
+        return studyInstanceUid_;
+      }
+
+      const std::string& GetSeriesInstanceUid() const
+      {
+        return seriesInstanceUid_;
+      }
+
+      size_t GetInstancesCount() const
+      {
+        return instances_.GetSize();
+      }
+
+      const Orthanc::DicomMap& GetInstance(size_t index) const
+      {
+        return instances_.GetResource(index);
+      }
+
+      LoadedDicomResources& GetInstances() const
+      {
+        return instances_;
+      }
+
+      void SetDicomDir(const std::string& dicomDirPath,
+                       boost::shared_ptr<LoadedDicomResources> dicomDir)
+      {
+        dicomDirPath_ = dicomDirPath;
+        dicomDir_ = dicomDir;
+      }
+
+      const std::string& GetDicomDirPath() const
+      {
+        return dicomDirPath_;
+      }
+
+      // Will be NULL on non-DICOMDIR sources
+      boost::shared_ptr<LoadedDicomResources> GetDicomDir() const
+      {
+        return dicomDir_;
+      }
+    };
+
+  
+    class Factory : public ILoaderFactory
+    {
+    public:
+      virtual boost::shared_ptr<IObserver> Create(ILoadersContext::ILock& context);
+    };
+
+  
+    class Accessor : public boost::noncopyable
+    {
+    private:
+      boost::shared_ptr<LoadedDicomResources>  series_;
+
+    public:
+      Accessor(SeriesMetadataLoader& that,
+               const std::string& seriesInstanceUid);
+
+      bool IsComplete() const
+      {
+        return series_ != NULL;
+      }
+
+      size_t GetInstancesCount() const;
+
+      const Orthanc::DicomMap& GetInstance(size_t index) const;
+    };
+
+
+    void ScheduleLoadSeries(int priority,
+                            const DicomSource& source,
+                            const std::string& studyInstanceUid,
+                            const std::string& seriesInstanceUid);
+
+    void ScheduleLoadSeries(int priority,
+                            const DicomSource& source,
+                            const std::string& patientId,
+                            const std::string& studyInstanceUid,
+                            const std::string& seriesInstanceUid);
+
+    void ScheduleLoadDicomDir(int priority,
+                              const DicomSource& source,
+                              const std::string& path);
+  };
+}