annotate OrthancServer/Sources/DicomInstanceToStore.cpp @ 4506:ac69c9f76c71

refactoring ServerIndex::Store()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Feb 2021 17:01:44 +0100
parents 97d103b57cd1
children b4c58795f3a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1854
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4385
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
1624
0a2ad4a6858f fix missing precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1573
diff changeset
34 #include "PrecompiledHeadersServer.h"
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "DicomInstanceToStore.h"
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
4140
0ddc5297a8ab centralization of default parameters for JSON/DicomMap conversions from DCMTK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4137
diff changeset
37 #include "OrthancConfiguration.h"
0ddc5297a8ab centralization of default parameters for JSON/DicomMap conversions from DCMTK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4137
diff changeset
38
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
39 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
40 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
41 #include "../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
42 #include "../../OrthancFramework/Sources/OrthancException.h"
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1003
diff changeset
43
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1003
diff changeset
44 #include <dcmtk/dcmdata/dcfilefo.h>
2189
c4b3259c8bce New metadata automatically computed at the instance level: "TransferSyntax"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2131
diff changeset
45 #include <dcmtk/dcmdata/dcdeftag.h>
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1003
diff changeset
46
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1003
diff changeset
47
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 namespace Orthanc
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
50 // Anonymous namespace to avoid clashes between compilation modules
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
51 namespace
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
52 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
53 template <typename T>
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
54 class SmartContainer
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
55 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
56 private:
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
57 T* content_;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
58 bool toDelete_;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
59 bool isReadOnly_;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
60
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
61 void Deallocate()
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
62 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
63 if (content_ && toDelete_)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
64 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
65 delete content_;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
66 toDelete_ = false;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
67 content_ = NULL;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
68 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
69 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
70
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
71 public:
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
72 SmartContainer() : content_(NULL), toDelete_(false), isReadOnly_(true)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
73 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
74 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
75
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
76 ~SmartContainer()
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
77 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
78 Deallocate();
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
79 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
80
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
81 void Allocate()
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
82 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
83 Deallocate();
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
84 content_ = new T;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
85 toDelete_ = true;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
86 isReadOnly_ = false;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
87 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
88
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
89 void TakeOwnership(T* content)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
90 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
91 if (content == NULL)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
92 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
93 throw OrthancException(ErrorCode_ParameterOutOfRange);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
94 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
95
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
96 Deallocate();
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
97 content_ = content;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
98 toDelete_ = true;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
99 isReadOnly_ = false;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
100 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
101
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
102 void SetReference(T& content) // Read and write assign, without transfering ownership
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
103 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
104 Deallocate();
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
105 content_ = &content;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
106 toDelete_ = false;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
107 isReadOnly_ = false;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
108 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
109
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
110 void SetConstReference(const T& content) // Read-only assign, without transfering ownership
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
111 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
112 Deallocate();
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
113 content_ = &const_cast<T&>(content);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
114 toDelete_ = false;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
115 isReadOnly_ = true;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
116 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
117
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
118 bool HasContent() const
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
119 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
120 return content_ != NULL;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
121 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
122
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
123 T& GetContent()
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
124 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
125 if (content_ == NULL)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
126 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
127 throw OrthancException(ErrorCode_BadSequenceOfCalls);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
128 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
129
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
130 if (isReadOnly_)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
131 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
132 throw OrthancException(ErrorCode_ReadOnly);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
133 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
134
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
135 return *content_;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
136 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
137
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
138 const T& GetConstContent() const
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
139 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
140 if (content_ == NULL)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
141 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
142 throw OrthancException(ErrorCode_BadSequenceOfCalls);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
143 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
144
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
145 return *content_;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
146 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
147 };
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
148 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
149
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
150
2898
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
151 class DicomInstanceToStore::PImpl
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
152 {
2898
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
153 public:
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
154 DicomInstanceOrigin origin_;
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
155 bool hasBuffer_;
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
156 std::unique_ptr<std::string> ownBuffer_;
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
157 const void* bufferData_;
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
158 size_t bufferSize_;
2898
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
159 SmartContainer<ParsedDicomFile> parsed_;
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
160 MetadataMap metadata_;
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
161
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
162 PImpl() :
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
163 hasBuffer_(false),
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
164 bufferData_(NULL),
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
165 bufferSize_(0)
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
166 {
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
167 }
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
168
2898
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
169 private:
4505
97d103b57cd1 removed cached dicom summary from DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4504
diff changeset
170 void ComputeParsedDicomFileIfMissing()
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
171 {
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
172 if (!parsed_.HasContent())
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
173 {
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
174 if (!hasBuffer_)
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
175 {
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
176 throw OrthancException(ErrorCode_InternalError);
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
177 }
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
178
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
179 if (ownBuffer_.get() != NULL)
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
180 {
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
181 parsed_.TakeOwnership(new ParsedDicomFile(*ownBuffer_));
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
182 }
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
183 else
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
184 {
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
185 parsed_.TakeOwnership(new ParsedDicomFile(bufferData_, bufferSize_));
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
186 }
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
187 }
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
188 }
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
189
4505
97d103b57cd1 removed cached dicom summary from DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4504
diff changeset
190 void ComputeDicomBufferIfMissing()
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
191 {
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
192 if (!hasBuffer_)
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
193 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
194 if (!parsed_.HasContent())
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
195 {
4505
97d103b57cd1 removed cached dicom summary from DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4504
diff changeset
196 throw OrthancException(ErrorCode_NotImplemented);
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
197 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
198
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
199 // Serialize the parsed DICOM file
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
200 ownBuffer_.reset(new std::string);
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
201 if (!FromDcmtkBridge::SaveToMemoryBuffer(*ownBuffer_,
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
202 *parsed_.GetContent().GetDcmtkObject().getDataset()))
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
203 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2898
diff changeset
204 throw OrthancException(ErrorCode_InternalError,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2898
diff changeset
205 "Unable to serialize a DICOM file to a memory buffer");
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
206 }
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
207
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
208 hasBuffer_ = true;
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
209 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
210 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
211
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
212
2898
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
213 public:
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
214 void SetBuffer(const void* data,
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
215 size_t size)
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
216 {
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
217 ownBuffer_.reset(NULL);
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
218 bufferData_ = data;
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
219 bufferSize_ = size;
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
220 hasBuffer_ = true;
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
221 }
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
222
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
223 const void* GetBufferData()
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
224 {
4505
97d103b57cd1 removed cached dicom summary from DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4504
diff changeset
225 ComputeDicomBufferIfMissing();
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
226
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
227 if (!hasBuffer_)
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
228 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
229 throw OrthancException(ErrorCode_InternalError);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
230 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
231
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
232 if (ownBuffer_.get() != NULL)
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
233 {
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
234 if (ownBuffer_->empty())
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
235 {
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
236 return NULL;
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
237 }
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
238 else
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
239 {
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
240 return ownBuffer_->c_str();
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
241 }
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
242 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
243 else
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
244 {
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
245 return bufferData_;
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
246 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
247 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
248
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
249
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
250 size_t GetBufferSize()
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
251 {
4505
97d103b57cd1 removed cached dicom summary from DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4504
diff changeset
252 ComputeDicomBufferIfMissing();
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
253
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
254 if (!hasBuffer_)
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
255 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
256 throw OrthancException(ErrorCode_InternalError);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
257 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
258
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
259 if (ownBuffer_.get() != NULL)
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
260 {
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
261 return ownBuffer_->size();
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
262 }
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
263 else
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
264 {
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
265 return bufferSize_;
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
266 }
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
267 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
268
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
269
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
270 bool LookupTransferSyntax(std::string& result)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
271 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
272 DicomMap header;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
273 if (DicomMap::ParseDicomMetaInformation(header, GetBufferData(), GetBufferSize()))
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
274 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
275 const DicomValue* value = header.TestAndGetValue(DICOM_TAG_TRANSFER_SYNTAX_UID);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
276 if (value != NULL &&
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
277 !value->IsBinary() &&
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
278 !value->IsNull())
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
279 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
280 result = Toolbox::StripSpaces(value->GetContent());
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
281 return true;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
282 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
283 }
4385
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
284 else
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
285 {
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
286 // This is a DICOM file without a proper meta-header. Fallback
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
287 // to DCMTK, which will fully parse the dataset to retrieve
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
288 // the transfer syntax. Added in Orthanc 1.8.2.
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
289 std::string transferSyntax;
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
290 if (GetParsedDicomFile().LookupTransferSyntax(transferSyntax))
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
291 {
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
292 result = Toolbox::StripSpaces(transferSyntax);
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
293 return true;
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
294 }
92737070b301 If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
295 }
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
296
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
297 return false;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
298 }
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
299
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
300
3912
7610af1532c3 prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3847
diff changeset
301 ParsedDicomFile& GetParsedDicomFile()
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
302 {
4505
97d103b57cd1 removed cached dicom summary from DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4504
diff changeset
303 ComputeParsedDicomFileIfMissing();
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
304
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
305 if (parsed_.HasContent())
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
306 {
3912
7610af1532c3 prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3847
diff changeset
307 return parsed_.GetContent();
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
308 }
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
309 else
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
310 {
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
311 throw OrthancException(ErrorCode_InternalError);
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
312 }
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
313 }
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
314 };
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
315
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
316
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
317 DicomInstanceToStore::DicomInstanceToStore() :
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
318 pimpl_(new PImpl)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
319 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
320 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
321
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
322
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
323 void DicomInstanceToStore::SetOrigin(const DicomInstanceOrigin& origin)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
324 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
325 pimpl_->origin_ = origin;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
326 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
327
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
328
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
329 const DicomInstanceOrigin& DicomInstanceToStore::GetOrigin() const
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
330 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
331 return pimpl_->origin_;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
332 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
333
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
334
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
335 void DicomInstanceToStore::SetBuffer(const void* dicom,
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
336 size_t size)
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
337 {
3841
be7df7fe3d80 avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
338 pimpl_->SetBuffer(dicom, size);
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
339 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
340
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
341
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
342 void DicomInstanceToStore::SetParsedDicomFile(ParsedDicomFile& parsed)
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
343 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
344 pimpl_->parsed_.SetReference(parsed);
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
345 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
346
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
347
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
348 const DicomInstanceToStore::MetadataMap& DicomInstanceToStore::GetMetadata() const
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
349 {
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
350 return pimpl_->metadata_;
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
351 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
352
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
353
4506
ac69c9f76c71 refactoring ServerIndex::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4505
diff changeset
354 void DicomInstanceToStore::ClearMetadata()
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
355 {
4506
ac69c9f76c71 refactoring ServerIndex::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4505
diff changeset
356 pimpl_->metadata_.clear();
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
357 }
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
358
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
359
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1003
diff changeset
360 void DicomInstanceToStore::AddMetadata(ResourceType level,
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 MetadataType metadata,
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 const std::string& value)
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 {
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
364 pimpl_->metadata_[std::make_pair(level, metadata)] = value;
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
3847
1491d501836a actual implementation of OrthancPluginRegisterIncomingDicomInstanceFilter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3845
diff changeset
368 const void* DicomInstanceToStore::GetBufferData() const
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 {
3847
1491d501836a actual implementation of OrthancPluginRegisterIncomingDicomInstanceFilter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3845
diff changeset
370 return const_cast<PImpl&>(*pimpl_).GetBufferData();
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
3847
1491d501836a actual implementation of OrthancPluginRegisterIncomingDicomInstanceFilter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3845
diff changeset
374 size_t DicomInstanceToStore::GetBufferSize() const
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
3847
1491d501836a actual implementation of OrthancPluginRegisterIncomingDicomInstanceFilter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3845
diff changeset
376 return const_cast<PImpl&>(*pimpl_).GetBufferSize();
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1003
diff changeset
377 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1003
diff changeset
378
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1003
diff changeset
379
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
380 bool DicomInstanceToStore::LookupTransferSyntax(std::string& result) const
2189
c4b3259c8bce New metadata automatically computed at the instance level: "TransferSyntax"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2131
diff changeset
381 {
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
382 return const_cast<PImpl&>(*pimpl_).LookupTransferSyntax(result);
2189
c4b3259c8bce New metadata automatically computed at the instance level: "TransferSyntax"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2131
diff changeset
383 }
2898
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
384
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
385
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
386 bool DicomInstanceToStore::HasPixelData() const
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
387 {
3912
7610af1532c3 prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3847
diff changeset
388 return const_cast<PImpl&>(*pimpl_).GetParsedDicomFile().HasTag(DICOM_TAG_PIXEL_DATA);
7610af1532c3 prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3847
diff changeset
389 }
7610af1532c3 prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3847
diff changeset
390
7610af1532c3 prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3847
diff changeset
391 ParsedDicomFile& DicomInstanceToStore::GetParsedDicomFile() const
7610af1532c3 prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3847
diff changeset
392 {
7610af1532c3 prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3847
diff changeset
393 return const_cast<PImpl&>(*pimpl_).GetParsedDicomFile();
3845
281045a1e6db new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3841
diff changeset
394 }
1003
1d35281d967c DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }