Mercurial > hg > orthanc
annotate OrthancServer/DicomProtocol/DicomFindAnswers.cpp @ 1794:bdfae6e17d23 worklists
integration mainline->worklists
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Nov 2015 16:02:35 +0100 |
parents | bdcc1dba4a53 |
children | 23722a191e4e |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
0 | 5 * |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "../PrecompiledHeadersServer.h" |
0 | 34 #include "DicomFindAnswers.h" |
35 | |
36 #include "../FromDcmtkBridge.h" | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
37 #include "../ToDcmtkBridge.h" |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
38 #include "../../Core/OrthancException.h" |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
39 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
40 #include <memory> |
1789 | 41 #include <dcmtk/dcmdata/dcfilefo.h> |
42 | |
0 | 43 |
62 | 44 namespace Orthanc |
0 | 45 { |
1789 | 46 class DicomFindAnswers::Answer |
47 { | |
48 private: | |
49 ParsedDicomFile* dicom_; | |
50 DicomMap* map_; | |
51 | |
52 public: | |
53 Answer(ParsedDicomFile& dicom) : | |
54 dicom_(dicom.Clone()), | |
55 map_(NULL) | |
56 { | |
57 } | |
58 | |
59 Answer(const char* dicom, | |
60 size_t size) : | |
61 dicom_(new ParsedDicomFile(dicom, size)), | |
62 map_(NULL) | |
63 { | |
64 } | |
65 | |
66 Answer(const DicomMap& map) : | |
67 dicom_(NULL), | |
68 map_(map.Clone()) | |
69 { | |
70 } | |
71 | |
72 ~Answer() | |
73 { | |
74 if (dicom_ != NULL) | |
75 { | |
76 delete dicom_; | |
77 } | |
78 | |
79 if (map_ != NULL) | |
80 { | |
81 delete map_; | |
82 } | |
83 } | |
84 | |
85 ParsedDicomFile& GetDicomFile() | |
86 { | |
87 if (dicom_ == NULL) | |
88 { | |
89 assert(map_ != NULL); | |
90 dicom_ = new ParsedDicomFile(*map_); | |
91 } | |
92 | |
93 return *dicom_; | |
94 } | |
95 | |
96 DcmDataset* ExtractDcmDataset() const | |
97 { | |
98 if (dicom_ != NULL) | |
99 { | |
100 return new DcmDataset(*dicom_->GetDcmtkObject().getDataset()); | |
101 } | |
102 else | |
103 { | |
104 assert(map_ != NULL); | |
105 return ToDcmtkBridge::Convert(*map_); | |
106 } | |
107 } | |
108 }; | |
109 | |
110 | |
0 | 111 void DicomFindAnswers::Clear() |
112 { | |
1789 | 113 for (size_t i = 0; i < answers_.size(); i++) |
0 | 114 { |
1789 | 115 assert(answers_[i] != NULL); |
116 delete answers_[i]; | |
0 | 117 } |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
118 |
1789 | 119 answers_.clear(); |
0 | 120 } |
121 | |
1789 | 122 |
0 | 123 void DicomFindAnswers::Reserve(size_t size) |
124 { | |
1789 | 125 if (size > answers_.size()) |
0 | 126 { |
1789 | 127 answers_.reserve(size); |
0 | 128 } |
129 } | |
130 | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
131 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
132 void DicomFindAnswers::Add(const DicomMap& map) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
133 { |
1789 | 134 answers_.push_back(new Answer(map)); |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
135 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
136 |
1789 | 137 |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
138 void DicomFindAnswers::Add(ParsedDicomFile& dicom) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
139 { |
1789 | 140 answers_.push_back(new Answer(dicom)); |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
141 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
142 |
1789 | 143 |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
144 void DicomFindAnswers::Add(const char* dicom, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
145 size_t size) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
146 { |
1789 | 147 answers_.push_back(new Answer(dicom, size)); |
148 } | |
149 | |
150 | |
151 DicomFindAnswers::Answer& DicomFindAnswers::GetAnswerInternal(size_t index) const | |
152 { | |
153 if (index < answers_.size()) | |
154 { | |
155 return *answers_.at(index); | |
156 } | |
157 else | |
158 { | |
159 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
160 } | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
161 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
162 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
163 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
164 ParsedDicomFile& DicomFindAnswers::GetAnswer(size_t index) const |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
165 { |
1789 | 166 return GetAnswerInternal(index).GetDicomFile(); |
167 } | |
168 | |
169 | |
170 DcmDataset* DicomFindAnswers::ExtractDcmDataset(size_t index) const | |
171 { | |
172 return GetAnswerInternal(index).ExtractDcmDataset(); | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
173 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
174 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
175 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
176 void DicomFindAnswers::ToJson(Json::Value& target, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
177 size_t index, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
178 bool simplify) const |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
179 { |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
180 DicomToJsonFormat format = (simplify ? DicomToJsonFormat_Simple : DicomToJsonFormat_Full); |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
181 GetAnswer(index).ToJson(target, format, DicomToJsonFlags_None, 0); |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
182 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
183 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
184 |
1368 | 185 void DicomFindAnswers::ToJson(Json::Value& target, |
186 bool simplify) const | |
0 | 187 { |
188 target = Json::arrayValue; | |
189 | |
190 for (size_t i = 0; i < GetSize(); i++) | |
191 { | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
192 Json::Value answer; |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
193 ToJson(answer, i, simplify); |
0 | 194 target.append(answer); |
195 } | |
196 } | |
197 } |