comparison 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
comparison
equal deleted inserted replaced
1227:a1c0c9c9f9af 1228:c471a0aa137b
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23
24 #include "DicomResourcesLoader.h"
25
26 namespace OrthancStone
27 {
28 class SeriesMetadataLoader :
29 public ObserverBase<SeriesMetadataLoader>,
30 public IObservable
31 {
32 private:
33 enum State
34 {
35 State_Setup,
36 State_Default,
37 State_DicomDir,
38 State_DicomFile
39 };
40
41 typedef std::map<std::string, boost::shared_ptr<LoadedDicomResources> > Series;
42
43 boost::shared_ptr<DicomResourcesLoader> loader_;
44 State state_;
45 std::map<std::string, int> scheduled_; // Maps a "SeriesInstanceUID" to a priority
46 Series series_;
47 boost::shared_ptr<LoadedDicomResources> dicomDir_;
48 std::string dicomDirPath_;
49 std::map<std::string, unsigned int> seriesSize_;
50
51 SeriesMetadataLoader(boost::shared_ptr<DicomResourcesLoader>& loader);
52
53 bool IsScheduledWithHigherPriority(const std::string& seriesInstanceUid,
54 int priority) const;
55
56 void Handle(const DicomResourcesLoader::SuccessMessage& message);
57
58 public:
59 class SeriesLoadedMessage : public OriginMessage<SeriesMetadataLoader>
60 {
61 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
62
63 private:
64 const DicomSource& source_;
65 const std::string& studyInstanceUid_;
66 const std::string& seriesInstanceUid_;
67 LoadedDicomResources& instances_;
68 std::string dicomDirPath_;
69 boost::shared_ptr<LoadedDicomResources> dicomDir_;
70
71 public:
72 SeriesLoadedMessage(const SeriesMetadataLoader& loader,
73 const DicomSource& source,
74 const std::string& studyInstanceUid,
75 const std::string& seriesInstanceUid,
76 LoadedDicomResources& instances);
77
78 const DicomSource& GetDicomSource() const
79 {
80 return source_;
81 }
82
83 const std::string& GetStudyInstanceUid() const
84 {
85 return studyInstanceUid_;
86 }
87
88 const std::string& GetSeriesInstanceUid() const
89 {
90 return seriesInstanceUid_;
91 }
92
93 size_t GetInstancesCount() const
94 {
95 return instances_.GetSize();
96 }
97
98 const Orthanc::DicomMap& GetInstance(size_t index) const
99 {
100 return instances_.GetResource(index);
101 }
102
103 LoadedDicomResources& GetInstances() const
104 {
105 return instances_;
106 }
107
108 void SetDicomDir(const std::string& dicomDirPath,
109 boost::shared_ptr<LoadedDicomResources> dicomDir)
110 {
111 dicomDirPath_ = dicomDirPath;
112 dicomDir_ = dicomDir;
113 }
114
115 const std::string& GetDicomDirPath() const
116 {
117 return dicomDirPath_;
118 }
119
120 // Will be NULL on non-DICOMDIR sources
121 boost::shared_ptr<LoadedDicomResources> GetDicomDir() const
122 {
123 return dicomDir_;
124 }
125 };
126
127
128 class Factory : public ILoaderFactory
129 {
130 public:
131 virtual boost::shared_ptr<IObserver> Create(ILoadersContext::ILock& context);
132 };
133
134
135 class Accessor : public boost::noncopyable
136 {
137 private:
138 boost::shared_ptr<LoadedDicomResources> series_;
139
140 public:
141 Accessor(SeriesMetadataLoader& that,
142 const std::string& seriesInstanceUid);
143
144 bool IsComplete() const
145 {
146 return series_ != NULL;
147 }
148
149 size_t GetInstancesCount() const;
150
151 const Orthanc::DicomMap& GetInstance(size_t index) const;
152 };
153
154
155 void ScheduleLoadSeries(int priority,
156 const DicomSource& source,
157 const std::string& studyInstanceUid,
158 const std::string& seriesInstanceUid);
159
160 void ScheduleLoadSeries(int priority,
161 const DicomSource& source,
162 const std::string& patientId,
163 const std::string& studyInstanceUid,
164 const std::string& seriesInstanceUid);
165
166 void ScheduleLoadDicomDir(int priority,
167 const DicomSource& source,
168 const std::string& path);
169 };
170 }