annotate OrthancServer/ServerToolbox.cpp @ 2209:e3fd5bc429a2

URI to reconstruct the main DICOM tags, the JSON summary and the metadata
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Dec 2016 17:20:21 +0100
parents 0c09d1af22f3
children a3a65de1840f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
4 * Department, University Hospital of Liege, Belgium
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "PrecompiledHeadersServer.h"
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ServerToolbox.h"
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1673
0bbcfd9695e5 UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1669
diff changeset
36 #include "../Core/DicomFormat/DicomArray.h"
0bbcfd9695e5 UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1669
diff changeset
37 #include "../Core/FileStorage/StorageAccessor.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
38 #include "../Core/Logging.h"
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "../Core/OrthancException.h"
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
234
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
41 #include <cassert>
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
42
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 namespace Orthanc
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
45 namespace ServerToolbox
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
2121
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
47 static const DicomTag patientIdentifiers[] =
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
48 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
49 DICOM_TAG_PATIENT_ID,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
50 DICOM_TAG_PATIENT_NAME,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
51 DICOM_TAG_PATIENT_BIRTH_DATE
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
52 };
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
53
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
54 static const DicomTag studyIdentifiers[] =
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
55 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
56 DICOM_TAG_PATIENT_ID,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
57 DICOM_TAG_PATIENT_NAME,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
58 DICOM_TAG_PATIENT_BIRTH_DATE,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
59 DICOM_TAG_STUDY_INSTANCE_UID,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
60 DICOM_TAG_ACCESSION_NUMBER,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
61 DICOM_TAG_STUDY_DESCRIPTION,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
62 DICOM_TAG_STUDY_DATE
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
63 };
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
64
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
65 static const DicomTag seriesIdentifiers[] =
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
66 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
67 DICOM_TAG_SERIES_INSTANCE_UID
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
68 };
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
69
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
70 static const DicomTag instanceIdentifiers[] =
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
71 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
72 DICOM_TAG_SOP_INSTANCE_UID
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
73 };
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
74
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
75
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
76 void SimplifyTags(Json::Value& target,
1859
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
77 const Json::Value& source,
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
78 DicomToJsonFormat format)
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
79 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
80 assert(source.isObject());
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
82 target = Json::objectValue;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
83 Json::Value::Members members = source.getMemberNames();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
84
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
85 for (size_t i = 0; i < members.size(); i++)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
86 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
87 const Json::Value& v = source[members[i]];
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
88 const std::string& type = v["Type"].asString();
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
1859
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
90 std::string name;
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
91 switch (format)
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
92 {
1860
c7d70f659190 DicomToJsonFormat_Simple -> DicomToJsonFormat_Human
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1859
diff changeset
93 case DicomToJsonFormat_Human:
1859
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
94 name = v["Name"].asString();
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
95 break;
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
96
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
97 case DicomToJsonFormat_Short:
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
98 name = members[i];
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
99 break;
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
100
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
101 default:
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
102 throw OrthancException(ErrorCode_ParameterOutOfRange);
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
103 }
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
104
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
105 if (type == "String")
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
106 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
107 target[name] = v["Value"].asString();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
108 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
109 else if (type == "TooLong" ||
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
110 type == "Null")
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
111 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
112 target[name] = Json::nullValue;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
113 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
114 else if (type == "Sequence")
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
115 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
116 const Json::Value& array = v["Value"];
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
117 assert(array.isArray());
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
119 Json::Value children = Json::arrayValue;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
120 for (Json::Value::ArrayIndex i = 0; i < array.size(); i++)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
121 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
122 Json::Value c;
1859
4e7c318a3f69 C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
123 SimplifyTags(c, array[i], format);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
124 children.append(c);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
125 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
126
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
127 target[name] = children;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
128 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
129 else
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
130 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
131 assert(0);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
132 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
134 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
135
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
136
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
137 static std::string ValueAsString(const DicomMap& summary,
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
138 const DicomTag& tag)
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
139 {
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
140 const DicomValue& value = summary.GetValue(tag);
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
141 if (value.IsNull())
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
142 {
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
143 return "(null)";
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
144 }
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
145 else
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
146 {
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
147 return value.GetContent();
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
148 }
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
149 }
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
150
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
151
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
152 void LogMissingRequiredTag(const DicomMap& summary)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
153 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
154 std::string s, t;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
155
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
156 if (summary.HasTag(DICOM_TAG_PATIENT_ID))
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
158 if (t.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
159 t += ", ";
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
160 t += "PatientID=" + ValueAsString(summary, DICOM_TAG_PATIENT_ID);
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
162 else
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
164 if (s.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
165 s += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
166 s += "PatientID";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
167 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
169 if (summary.HasTag(DICOM_TAG_STUDY_INSTANCE_UID))
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
170 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
171 if (t.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
172 t += ", ";
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
173 t += "StudyInstanceUID=" + ValueAsString(summary, DICOM_TAG_STUDY_INSTANCE_UID);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
174 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
175 else
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
176 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
177 if (s.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
178 s += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
179 s += "StudyInstanceUID";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
180 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
182 if (summary.HasTag(DICOM_TAG_SERIES_INSTANCE_UID))
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
183 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
184 if (t.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
185 t += ", ";
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
186 t += "SeriesInstanceUID=" + ValueAsString(summary, DICOM_TAG_SERIES_INSTANCE_UID);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
187 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
188 else
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
189 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
190 if (s.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
191 s += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
192 s += "SeriesInstanceUID";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
193 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
194
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
195 if (summary.HasTag(DICOM_TAG_SOP_INSTANCE_UID))
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
196 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
197 if (t.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
198 t += ", ";
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
199 t += "SOPInstanceUID=" + ValueAsString(summary, DICOM_TAG_SOP_INSTANCE_UID);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
200 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
201 else
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
202 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
203 if (s.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
204 s += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
205 s += "SOPInstanceUID";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
206 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
207
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
208 if (t.size() == 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
209 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
210 LOG(ERROR) << "Store has failed because all the required tags (" << s << ") are missing (is it a DICOMDIR file?)";
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 else
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
214 LOG(ERROR) << "Store has failed because required tags (" << s << ") are missing for the following instance: " << t;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
215 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
216 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
217
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
218
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
219 static void StoreMainDicomTagsInternal(IDatabaseWrapper& database,
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
220 int64_t resource,
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
221 const DicomMap& tags)
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
222 {
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
223 DicomArray flattened(tags);
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
224
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
225 for (size_t i = 0; i < flattened.GetSize(); i++)
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
226 {
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
227 const DicomElement& element = flattened.GetElement(i);
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
228 const DicomTag& tag = element.GetTag();
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
229 const DicomValue& value = element.GetValue();
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
230 if (!value.IsNull() &&
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
231 !value.IsBinary())
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
232 {
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
233 database.SetMainDicomTag(resource, tag, element.GetValue().GetContent());
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
234 }
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
235 }
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
236 }
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
237
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
238
2123
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
239 static void StoreIdentifiers(IDatabaseWrapper& database,
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
240 int64_t resource,
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
241 ResourceType level,
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
242 const DicomMap& map)
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
243 {
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
244 const DicomTag* tags;
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
245 size_t size;
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
246
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
247 LoadIdentifiers(tags, size, level);
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
248
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
249 for (size_t i = 0; i < size; i++)
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
250 {
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
251 const DicomValue* value = map.TestAndGetValue(tags[i]);
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
252 if (value != NULL &&
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
253 !value->IsNull() &&
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
254 !value->IsBinary())
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
255 {
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
256 std::string s = NormalizeIdentifier(value->GetContent());
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
257 database.SetIdentifierTag(resource, tags[i], s);
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
258 }
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
259 }
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
260 }
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
261
1cf093cbdad8 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
262
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
263 void StoreMainDicomTags(IDatabaseWrapper& database,
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
264 int64_t resource,
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
265 ResourceType level,
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
266 const DicomMap& dicomSummary)
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
267 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
268 // WARNING: The database should be locked with a transaction!
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
269
2121
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
270 StoreIdentifiers(database, resource, level, dicomSummary);
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1744
diff changeset
271
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
272 DicomMap tags;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
273
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
274 switch (level)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
275 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
276 case ResourceType_Patient:
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1744
diff changeset
277 dicomSummary.ExtractPatientInformation(tags);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
278 break;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
279
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
280 case ResourceType_Study:
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
281 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6)
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1744
diff changeset
282 dicomSummary.ExtractPatientInformation(tags);
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
283 StoreMainDicomTagsInternal(database, resource, tags);
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
284
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
285 dicomSummary.ExtractStudyInformation(tags);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
286 break;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
287
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
288 case ResourceType_Series:
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
289 dicomSummary.ExtractSeriesInformation(tags);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
290 break;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
291
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
292 case ResourceType_Instance:
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
293 dicomSummary.ExtractInstanceInformation(tags);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
294 break;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
295
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
296 default:
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
297 throw OrthancException(ErrorCode_InternalError);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
298 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
299
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
300 StoreMainDicomTagsInternal(database, resource, tags);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
301 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
302
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
303
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
304 bool FindOneChildInstance(int64_t& result,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
305 IDatabaseWrapper& database,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
306 int64_t resource,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
307 ResourceType type)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
308 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
309 for (;;)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
310 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
311 if (type == ResourceType_Instance)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
312 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
313 result = resource;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
314 return true;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
315 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
316
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
317 std::list<int64_t> children;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
318 database.GetChildrenInternalId(children, resource);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
319 if (children.empty())
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
320 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
321 return false;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
322 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
323
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
324 resource = children.front();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
325 type = GetChildResourceType(type);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
326 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
327 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
328
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
329
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
330 void ReconstructMainDicomTags(IDatabaseWrapper& database,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
331 IStorageArea& storageArea,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
332 ResourceType level)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
333 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
334 // WARNING: The database should be locked with a transaction!
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
335
2129
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2123
diff changeset
336 // TODO: This function might consume much memory if level ==
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2123
diff changeset
337 // ResourceType_Instance. To improve this, first download the
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2123
diff changeset
338 // list of studies, then remove the instances for each single
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2123
diff changeset
339 // study (check out OrthancRestApi::InvalidateTags for an
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2123
diff changeset
340 // example). Take this improvement into consideration for the
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2123
diff changeset
341 // next upgrade of the database schema.
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2123
diff changeset
342
1669
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
343 const char* plural = NULL;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
344
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
345 switch (level)
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
346 {
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
347 case ResourceType_Patient:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
348 plural = "patients";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
349 break;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
350
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
351 case ResourceType_Study:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
352 plural = "studies";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
353 break;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
354
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
355 case ResourceType_Series:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
356 plural = "series";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
357 break;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
358
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
359 case ResourceType_Instance:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
360 plural = "instances";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
361 break;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
362
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
363 default:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
364 throw OrthancException(ErrorCode_InternalError);
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
365 }
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
366
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
367 LOG(WARNING) << "Upgrade: Reconstructing the main DICOM tags of all the " << plural << "...";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
368
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
369 std::list<std::string> resources;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
370 database.GetAllPublicIds(resources, level);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
371
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
372 for (std::list<std::string>::const_iterator
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
373 it = resources.begin(); it != resources.end(); ++it)
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
374 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
375 // Locate the resource and one of its child instances
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
376 int64_t resource, instance;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
377 ResourceType tmp;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
378
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
379 if (!database.LookupResource(resource, tmp, *it) ||
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
380 tmp != level ||
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
381 !FindOneChildInstance(instance, database, resource, level))
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
382 {
1870
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
383 LOG(ERROR) << "Cannot find an instance for " << EnumerationToString(level)
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
384 << " with identifier " << *it;
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
385 throw OrthancException(ErrorCode_InternalError);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
386 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
387
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
388 // Get the DICOM file attached to some instances in the resource
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
389 FileInfo attachment;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
390 if (!database.LookupAttachment(attachment, instance, FileContentType_Dicom))
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
391 {
1870
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
392 LOG(ERROR) << "Cannot retrieve the DICOM file associated with instance " << database.GetPublicId(instance);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
393 throw OrthancException(ErrorCode_InternalError);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
394 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
395
1870
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
396 try
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
397 {
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
398 // Read and parse the content of the DICOM file
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
399 StorageAccessor accessor(storageArea);
1673
0bbcfd9695e5 UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1669
diff changeset
400
1870
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
401 std::string content;
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
402 accessor.Read(content, attachment);
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
403
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
404 ParsedDicomFile dicom(content);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
405
1870
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
406 // Update the tags of this resource
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
407 DicomMap dicomSummary;
2209
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
408 dicom.ExtractDicomSummary(dicomSummary);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
409
1870
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
410 database.ClearMainDicomTags(resource);
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
411 StoreMainDicomTags(database, resource, level, dicomSummary);
1870
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
412 }
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
413 catch (OrthancException&)
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
414 {
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
415 LOG(ERROR) << "Cannot decode the DICOM file with UUID " << attachment.GetUuid()
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
416 << " associated with instance " << database.GetPublicId(instance);
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
417 throw;
a6c431193c79 Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
418 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 }
2121
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
421
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
422
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
423 void LoadIdentifiers(const DicomTag*& tags,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
424 size_t& size,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
425 ResourceType level)
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
426 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
427 switch (level)
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
428 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
429 case ResourceType_Patient:
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
430 tags = patientIdentifiers;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
431 size = sizeof(patientIdentifiers) / sizeof(DicomTag);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
432 break;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
433
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
434 case ResourceType_Study:
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
435 tags = studyIdentifiers;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
436 size = sizeof(studyIdentifiers) / sizeof(DicomTag);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
437 break;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
438
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
439 case ResourceType_Series:
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
440 tags = seriesIdentifiers;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
441 size = sizeof(seriesIdentifiers) / sizeof(DicomTag);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
442 break;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
443
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
444 case ResourceType_Instance:
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
445 tags = instanceIdentifiers;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
446 size = sizeof(instanceIdentifiers) / sizeof(DicomTag);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
447 break;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
448
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
449 default:
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
450 throw OrthancException(ErrorCode_ParameterOutOfRange);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
451 }
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
452 }
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
453
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
454
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
455 std::string NormalizeIdentifier(const std::string& value)
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
456 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
457 std::string t;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
458 t.reserve(value.size());
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
459
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
460 for (size_t i = 0; i < value.size(); i++)
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
461 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
462 if (value[i] == '%' ||
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
463 value[i] == '_')
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
464 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
465 t.push_back(' '); // These characters might break wildcard queries in SQL
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
466 }
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
467 else if (isascii(value[i]) &&
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
468 !iscntrl(value[i]) &&
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
469 (!isspace(value[i]) || value[i] == ' '))
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
470 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
471 t.push_back(value[i]);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
472 }
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
473 }
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
474
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
475 Toolbox::ToUpperCase(t);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
476
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
477 return Toolbox::StripSpaces(t);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
478 }
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
479
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
480
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
481 bool IsIdentifier(const DicomTag& tag,
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
482 ResourceType level)
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
483 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
484 const DicomTag* tags;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
485 size_t size;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
486
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
487 LoadIdentifiers(tags, size, level);
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
488
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
489 for (size_t i = 0; i < size; i++)
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
490 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
491 if (tag == tags[i])
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
492 {
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
493 return true;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
494 }
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
495 }
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
496
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
497 return false;
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
498 }
2209
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
499
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
500
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
501 void ReconstructResource(ServerContext& context,
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
502 const std::string& resource)
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
503 {
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
504 LOG(WARNING) << "Reconstructing resource " << resource;
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
505
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
506 std::list<std::string> instances;
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
507 context.GetIndex().GetChildInstances(instances, resource);
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
508
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
509 for (std::list<std::string>::const_iterator
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
510 it = instances.begin(); it != instances.end(); ++it)
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
511 {
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
512 ServerContext::DicomCacheLocker locker(context, *it);
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
513
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
514 Json::Value dicomAsJson;
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
515 locker.GetDicom().ExtractDicomAsJson(dicomAsJson);
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
516
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
517 std::string s = dicomAsJson.toStyledString();
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
518 context.AddAttachment(*it, FileContentType_DicomAsJson, s.c_str(), s.size());
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
519
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
520 context.GetIndex().ReconstructInstance(locker.GetDicom());
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
521 }
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
522 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 }