comparison Core/DicomParsing/ParsedDicomFile.h @ 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/ParsedDicomFile.h@96b3ec054b69
children 75c779ca948c
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 #pragma once
35
36 #include "../DicomFormat/DicomInstanceHasher.h"
37 #include "../Images/ImageAccessor.h"
38 #include "../IDynamicObject.h"
39 #include "../RestApi/RestApiOutput.h"
40 #include "../Toolbox.h"
41
42 #if !defined(ORTHANC_ENABLE_JPEG)
43 # error Macro ORTHANC_ENABLE_JPEG must be defined to use this file
44 #endif
45
46 #if !defined(ORTHANC_ENABLE_PNG)
47 # error Macro ORTHANC_ENABLE_PNG must be defined to use this file
48 #endif
49
50 class DcmDataset;
51 class DcmFileFormat;
52
53 namespace Orthanc
54 {
55 class ParsedDicomFile : public IDynamicObject
56 {
57 private:
58 struct PImpl;
59 PImpl* pimpl_;
60
61 ParsedDicomFile(ParsedDicomFile& other);
62
63 void CreateFromDicomMap(const DicomMap& source,
64 Encoding defaultEncoding);
65
66 void RemovePrivateTagsInternal(const std::set<DicomTag>* toKeep);
67
68 void UpdateStorageUid(const DicomTag& tag,
69 const std::string& value,
70 bool decodeDataUriScheme);
71
72 void InvalidateCache();
73
74 bool EmbedContentInternal(const std::string& dataUriScheme);
75
76 public:
77 ParsedDicomFile(bool createIdentifiers); // Create a minimal DICOM instance
78
79 ParsedDicomFile(const DicomMap& map,
80 Encoding defaultEncoding);
81
82 ParsedDicomFile(const DicomMap& map);
83
84 ParsedDicomFile(const void* content,
85 size_t size);
86
87 ParsedDicomFile(const std::string& content);
88
89 ParsedDicomFile(DcmDataset& dicom);
90
91 ParsedDicomFile(DcmFileFormat& dicom);
92
93 ~ParsedDicomFile();
94
95 DcmFileFormat& GetDcmtkObject() const;
96
97 ParsedDicomFile* Clone();
98
99 void SendPathValue(RestApiOutput& output,
100 const UriComponents& uri);
101
102 void Answer(RestApiOutput& output);
103
104 void Remove(const DicomTag& tag);
105
106 // Replace the DICOM tag as a NULL/empty value (e.g. for anonymization)
107 void Clear(const DicomTag& tag,
108 bool onlyIfExists);
109
110 void Replace(const DicomTag& tag,
111 const std::string& utf8Value,
112 bool decodeDataUriScheme,
113 DicomReplaceMode mode);
114
115 void Replace(const DicomTag& tag,
116 const Json::Value& value, // Assumed to be encoded with UTF-8
117 bool decodeDataUriScheme,
118 DicomReplaceMode mode);
119
120 void Insert(const DicomTag& tag,
121 const Json::Value& value, // Assumed to be encoded with UTF-8
122 bool decodeDataUriScheme);
123
124 void ReplacePlainString(const DicomTag& tag,
125 const std::string& utf8Value)
126 {
127 Replace(tag, utf8Value, false, DicomReplaceMode_InsertIfAbsent);
128 }
129
130 void RemovePrivateTags()
131 {
132 RemovePrivateTagsInternal(NULL);
133 }
134
135 void RemovePrivateTags(const std::set<DicomTag>& toKeep)
136 {
137 RemovePrivateTagsInternal(&toKeep);
138 }
139
140 // WARNING: This function handles the decoding of strings to UTF8
141 bool GetTagValue(std::string& value,
142 const DicomTag& tag);
143
144 DicomInstanceHasher GetHasher();
145
146 void SaveToMemoryBuffer(std::string& buffer);
147
148 void SaveToFile(const std::string& path);
149
150 void EmbedContent(const std::string& dataUriScheme);
151
152 void EmbedImage(const ImageAccessor& accessor);
153
154 #if (ORTHANC_ENABLE_JPEG == 1 && \
155 ORTHANC_ENABLE_PNG == 1)
156 void EmbedImage(const std::string& mime,
157 const std::string& content);
158 #endif
159
160 Encoding GetEncoding() const;
161
162 // WARNING: This function only sets the encoding, it will not
163 // convert the encoding of the tags. Use "ChangeEncoding()" if need be.
164 void SetEncoding(Encoding encoding);
165
166 void DatasetToJson(Json::Value& target,
167 DicomToJsonFormat format,
168 DicomToJsonFlags flags,
169 unsigned int maxStringLength);
170
171 // This version uses the default parameters for
172 // FileContentType_DicomAsJson
173 void DatasetToJson(Json::Value& target);
174
175 void HeaderToJson(Json::Value& target,
176 DicomToJsonFormat format);
177
178 bool HasTag(const DicomTag& tag) const;
179
180 void EmbedPdf(const std::string& pdf);
181
182 bool ExtractPdf(std::string& pdf);
183
184 void GetRawFrame(std::string& target, // OUT
185 std::string& mime, // OUT
186 unsigned int frameId); // IN
187
188 unsigned int GetFramesCount() const;
189
190 static ParsedDicomFile* CreateFromJson(const Json::Value& value,
191 DicomFromJsonFlags flags);
192
193 void ChangeEncoding(Encoding target);
194
195 void ExtractDicomSummary(DicomMap& target) const;
196
197 void ExtractDicomAsJson(Json::Value& target) const;
198
199 bool LookupTransferSyntax(std::string& result);
200
201 bool LookupPhotometricInterpretation(PhotometricInterpretation& result) const;
202 };
203 }