comparison Core/DicomNetworking/DicomFindAnswers.cpp @ 2382:7284093111b0

big reorganization to cleanly separate framework vs. server
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Aug 2017 21:17:35 +0200
parents OrthancServer/DicomProtocol/DicomFindAnswers.cpp@b8969010b534
children 878b59270859
comparison
equal deleted inserted replaced
2381:b8969010b534 2382:7284093111b0
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017 Osimis, Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #include "../PrecompiledHeaders.h"
35 #include "DicomFindAnswers.h"
36
37 #include "../DicomParsing/FromDcmtkBridge.h"
38 #include "../OrthancException.h"
39
40 #include <memory>
41 #include <dcmtk/dcmdata/dcfilefo.h>
42 #include <boost/noncopyable.hpp>
43
44
45 namespace Orthanc
46 {
47 void DicomFindAnswers::AddAnswerInternal(ParsedDicomFile* answer)
48 {
49 std::auto_ptr<ParsedDicomFile> protection(answer);
50
51 if (isWorklist_)
52 {
53 // These lines are necessary when serving worklists, otherwise
54 // Orthanc does not behave as "wlmscpfs"
55 protection->Remove(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID);
56 protection->Remove(DICOM_TAG_SOP_INSTANCE_UID);
57 }
58
59 protection->ChangeEncoding(encoding_);
60
61 answers_.push_back(protection.release());
62 }
63
64
65 DicomFindAnswers::DicomFindAnswers(bool isWorklist) :
66 encoding_(GetDefaultDicomEncoding()),
67 isWorklist_(isWorklist),
68 complete_(true)
69 {
70 }
71
72
73 void DicomFindAnswers::SetEncoding(Encoding encoding)
74 {
75 for (size_t i = 0; i < answers_.size(); i++)
76 {
77 assert(answers_[i] != NULL);
78 answers_[i]->ChangeEncoding(encoding);
79 }
80
81 encoding_ = encoding;
82 }
83
84
85 void DicomFindAnswers::SetWorklist(bool isWorklist)
86 {
87 if (answers_.empty())
88 {
89 isWorklist_ = isWorklist;
90 }
91 else
92 {
93 // This set of answers is not empty anymore, cannot change its type
94 throw OrthancException(ErrorCode_BadSequenceOfCalls);
95 }
96 }
97
98
99 void DicomFindAnswers::Clear()
100 {
101 for (size_t i = 0; i < answers_.size(); i++)
102 {
103 assert(answers_[i] != NULL);
104 delete answers_[i];
105 }
106
107 answers_.clear();
108 }
109
110
111 void DicomFindAnswers::Reserve(size_t size)
112 {
113 if (size > answers_.size())
114 {
115 answers_.reserve(size);
116 }
117 }
118
119
120 void DicomFindAnswers::Add(const DicomMap& map)
121 {
122 AddAnswerInternal(new ParsedDicomFile(map, encoding_));
123 }
124
125
126 void DicomFindAnswers::Add(ParsedDicomFile& dicom)
127 {
128 AddAnswerInternal(dicom.Clone());
129 }
130
131 void DicomFindAnswers::Add(const void* dicom,
132 size_t size)
133 {
134 AddAnswerInternal(new ParsedDicomFile(dicom, size));
135 }
136
137
138 ParsedDicomFile& DicomFindAnswers::GetAnswer(size_t index) const
139 {
140 if (index < answers_.size())
141 {
142 return *answers_[index];
143 }
144 else
145 {
146 throw OrthancException(ErrorCode_ParameterOutOfRange);
147 }
148 }
149
150
151 DcmDataset* DicomFindAnswers::ExtractDcmDataset(size_t index) const
152 {
153 return new DcmDataset(*GetAnswer(index).GetDcmtkObject().getDataset());
154 }
155
156
157 void DicomFindAnswers::ToJson(Json::Value& target,
158 size_t index,
159 bool simplify) const
160 {
161 DicomToJsonFormat format = (simplify ? DicomToJsonFormat_Human : DicomToJsonFormat_Full);
162 GetAnswer(index).DatasetToJson(target, format, DicomToJsonFlags_None, 0);
163 }
164
165
166 void DicomFindAnswers::ToJson(Json::Value& target,
167 bool simplify) const
168 {
169 target = Json::arrayValue;
170
171 for (size_t i = 0; i < GetSize(); i++)
172 {
173 Json::Value answer;
174 ToJson(answer, i, simplify);
175 target.append(answer);
176 }
177 }
178 }