Mercurial > hg > orthanc
annotate OrthancServer/ServerToolbox.cpp @ 3058:6faf575ba9cc db-changes
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Dec 2018 17:07:58 +0100 |
parents | 5da6d1063d8f |
children | ce272138f15e |
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 | 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 |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2409
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * 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
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * 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
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * 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
|
17 * 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
|
18 * 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
|
19 * 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
|
20 * 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
|
21 * 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
|
22 * 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
|
23 * |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * 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
|
25 * 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
|
26 * 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
|
27 * 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
|
28 * |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * 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
|
30 * 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
|
31 **/ |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include "PrecompiledHeadersServer.h" |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "ServerToolbox.h" |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
1673
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1669
diff
changeset
|
37 #include "../Core/DicomFormat/DicomArray.h" |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1669
diff
changeset
|
38 #include "../Core/FileStorage/StorageAccessor.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
39 #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
|
40 #include "../Core/OrthancException.h" |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
234 | 42 #include <cassert> |
43 | |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 namespace Orthanc |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
2120 | 46 namespace ServerToolbox |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
2121 | 48 static const DicomTag patientIdentifiers[] = |
49 { | |
50 DICOM_TAG_PATIENT_ID, | |
51 DICOM_TAG_PATIENT_NAME, | |
52 DICOM_TAG_PATIENT_BIRTH_DATE | |
53 }; | |
54 | |
55 static const DicomTag studyIdentifiers[] = | |
56 { | |
57 DICOM_TAG_PATIENT_ID, | |
58 DICOM_TAG_PATIENT_NAME, | |
59 DICOM_TAG_PATIENT_BIRTH_DATE, | |
60 DICOM_TAG_STUDY_INSTANCE_UID, | |
61 DICOM_TAG_ACCESSION_NUMBER, | |
62 DICOM_TAG_STUDY_DESCRIPTION, | |
63 DICOM_TAG_STUDY_DATE | |
64 }; | |
65 | |
66 static const DicomTag seriesIdentifiers[] = | |
67 { | |
68 DICOM_TAG_SERIES_INSTANCE_UID | |
69 }; | |
70 | |
71 static const DicomTag instanceIdentifiers[] = | |
72 { | |
73 DICOM_TAG_SOP_INSTANCE_UID | |
74 }; | |
75 | |
76 | |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
77 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
|
78 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
|
79 DicomToJsonFormat format) |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
80 { |
2951
65b20d922e10
throw instead of assert when Dicom tags can not be simplified
am@osimis.io
parents:
2447
diff
changeset
|
81 if (!source.isObject()) |
65b20d922e10
throw instead of assert when Dicom tags can not be simplified
am@osimis.io
parents:
2447
diff
changeset
|
82 { |
65b20d922e10
throw instead of assert when Dicom tags can not be simplified
am@osimis.io
parents:
2447
diff
changeset
|
83 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
65b20d922e10
throw instead of assert when Dicom tags can not be simplified
am@osimis.io
parents:
2447
diff
changeset
|
84 } |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
86 target = Json::objectValue; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
87 Json::Value::Members members = source.getMemberNames(); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
88 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
89 for (size_t i = 0; i < members.size(); i++) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
90 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
91 const Json::Value& v = source[members[i]]; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
92 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
|
93 |
1859
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
94 std::string name; |
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
95 switch (format) |
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
96 { |
1860
c7d70f659190
DicomToJsonFormat_Simple -> DicomToJsonFormat_Human
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1859
diff
changeset
|
97 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
|
98 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
|
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 case DicomToJsonFormat_Short: |
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
102 name = members[i]; |
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
103 break; |
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
104 |
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
105 default: |
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
106 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
|
107 } |
4e7c318a3f69
C-FIND SCP will return tags with sequence value representation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
108 |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
109 if (type == "String") |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
110 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
111 target[name] = v["Value"].asString(); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
112 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
113 else if (type == "TooLong" || |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
114 type == "Null") |
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 target[name] = Json::nullValue; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
117 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
118 else if (type == "Sequence") |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
119 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
120 const Json::Value& array = v["Value"]; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
121 assert(array.isArray()); |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
123 Json::Value children = Json::arrayValue; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
124 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
|
125 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
126 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
|
127 SimplifyTags(c, array[i], format); |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
128 children.append(c); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
129 } |
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 target[name] = children; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
132 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
133 else |
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 assert(0); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
136 } |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 } |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
138 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
139 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
140 |
2120 | 141 static void StoreMainDicomTagsInternal(IDatabaseWrapper& database, |
142 int64_t resource, | |
143 const DicomMap& tags) | |
1716
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
144 { |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
145 DicomArray flattened(tags); |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
146 |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
147 for (size_t i = 0; i < flattened.GetSize(); i++) |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
148 { |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
149 const DicomElement& element = flattened.GetElement(i); |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
150 const DicomTag& tag = element.GetTag(); |
1737
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
151 const DicomValue& value = element.GetValue(); |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
152 if (!value.IsNull() && |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
153 !value.IsBinary()) |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
154 { |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
155 database.SetMainDicomTag(resource, tag, element.GetValue().GetContent()); |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
156 } |
1716
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
157 } |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
158 } |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
159 |
2ca7888f8600
refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1713
diff
changeset
|
160 |
2123 | 161 static void StoreIdentifiers(IDatabaseWrapper& database, |
162 int64_t resource, | |
163 ResourceType level, | |
164 const DicomMap& map) | |
165 { | |
166 const DicomTag* tags; | |
167 size_t size; | |
168 | |
169 LoadIdentifiers(tags, size, level); | |
170 | |
171 for (size_t i = 0; i < size; i++) | |
172 { | |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
173 // The identifiers tags are a subset of the main DICOM tags |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
174 assert(DicomMap::IsMainDicomTag(tags[i])); |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
175 |
2123 | 176 const DicomValue* value = map.TestAndGetValue(tags[i]); |
177 if (value != NULL && | |
178 !value->IsNull() && | |
179 !value->IsBinary()) | |
180 { | |
181 std::string s = NormalizeIdentifier(value->GetContent()); | |
182 database.SetIdentifierTag(resource, tags[i], s); | |
183 } | |
184 } | |
185 } | |
186 | |
187 | |
2120 | 188 void StoreMainDicomTags(IDatabaseWrapper& database, |
189 int64_t resource, | |
190 ResourceType level, | |
191 const DicomMap& dicomSummary) | |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
192 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
193 // WARNING: The database should be locked with a transaction! |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
194 |
2121 | 195 StoreIdentifiers(database, resource, level, dicomSummary); |
1745
38dda23c7d7d
LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1744
diff
changeset
|
196 |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
197 DicomMap tags; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
198 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
199 switch (level) |
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 case ResourceType_Patient: |
1745
38dda23c7d7d
LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1744
diff
changeset
|
202 dicomSummary.ExtractPatientInformation(tags); |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
203 break; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
204 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
205 case ResourceType_Study: |
1717
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1716
diff
changeset
|
206 // 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
|
207 dicomSummary.ExtractPatientInformation(tags); |
2120 | 208 StoreMainDicomTagsInternal(database, resource, tags); |
1717
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1716
diff
changeset
|
209 |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
210 dicomSummary.ExtractStudyInformation(tags); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
211 break; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
212 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
213 case ResourceType_Series: |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
214 dicomSummary.ExtractSeriesInformation(tags); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
215 break; |
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 case ResourceType_Instance: |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
218 dicomSummary.ExtractInstanceInformation(tags); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
219 break; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
220 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
221 default: |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
222 throw OrthancException(ErrorCode_InternalError); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
223 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
224 |
2120 | 225 StoreMainDicomTagsInternal(database, resource, tags); |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
226 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
227 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
228 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
229 bool FindOneChildInstance(int64_t& result, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
230 IDatabaseWrapper& database, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
231 int64_t resource, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
232 ResourceType type) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
233 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
234 for (;;) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
235 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
236 if (type == ResourceType_Instance) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
237 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
238 result = resource; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
239 return true; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
240 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
241 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
242 std::list<int64_t> children; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
243 database.GetChildrenInternalId(children, resource); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
244 if (children.empty()) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
245 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
246 return false; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
247 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
248 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
249 resource = children.front(); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
250 type = GetChildResourceType(type); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
251 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
252 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
253 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
254 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
255 void ReconstructMainDicomTags(IDatabaseWrapper& database, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
256 IStorageArea& storageArea, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
257 ResourceType level) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
258 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
259 // WARNING: The database should be locked with a transaction! |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
260 |
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
|
261 // 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
|
262 // 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
|
263 // 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
|
264 // 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
|
265 // 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
|
266 // 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
|
267 |
1669
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
268 const char* plural = NULL; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
269 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
270 switch (level) |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
271 { |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
272 case ResourceType_Patient: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
273 plural = "patients"; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
274 break; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
275 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
276 case ResourceType_Study: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
277 plural = "studies"; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
278 break; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
279 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
280 case ResourceType_Series: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
281 plural = "series"; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
282 break; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
283 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
284 case ResourceType_Instance: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
285 plural = "instances"; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
286 break; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
287 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
288 default: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
289 throw OrthancException(ErrorCode_InternalError); |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
290 } |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
291 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
292 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
|
293 |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
294 std::list<std::string> resources; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
295 database.GetAllPublicIds(resources, level); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
296 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
297 for (std::list<std::string>::const_iterator |
1847 | 298 it = resources.begin(); it != resources.end(); ++it) |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
299 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
300 // Locate the resource and one of its child instances |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
301 int64_t resource, instance; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
302 ResourceType tmp; |
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 if (!database.LookupResource(resource, tmp, *it) || |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
305 tmp != level || |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
306 !FindOneChildInstance(instance, database, resource, level)) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
307 { |
2955 | 308 throw OrthancException(ErrorCode_InternalError, |
309 "Cannot find an instance for " + | |
310 std::string(EnumerationToString(level)) + | |
311 " with identifier " + *it); | |
1668
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 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
314 // 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
|
315 FileInfo attachment; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
316 if (!database.LookupAttachment(attachment, instance, FileContentType_Dicom)) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
317 { |
2955 | 318 throw OrthancException(ErrorCode_InternalError, |
319 "Cannot retrieve the DICOM file associated with instance " + | |
320 database.GetPublicId(instance)); | |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
321 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
322 |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
323 try |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
324 { |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
325 // 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
|
326 StorageAccessor accessor(storageArea); |
1673
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1669
diff
changeset
|
327 |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
328 std::string content; |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
329 accessor.Read(content, attachment); |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
330 |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
331 ParsedDicomFile dicom(content); |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
332 |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
333 // Update the tags of this resource |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
334 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
|
335 dicom.ExtractDicomSummary(dicomSummary); |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
336 |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
337 database.ClearMainDicomTags(resource); |
2120 | 338 StoreMainDicomTags(database, resource, level, dicomSummary); |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
339 } |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
340 catch (OrthancException&) |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
341 { |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
342 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
|
343 << " associated with instance " << database.GetPublicId(instance); |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
344 throw; |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
345 } |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 } |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 } |
2121 | 348 |
349 | |
350 void LoadIdentifiers(const DicomTag*& tags, | |
351 size_t& size, | |
352 ResourceType level) | |
353 { | |
354 switch (level) | |
355 { | |
356 case ResourceType_Patient: | |
357 tags = patientIdentifiers; | |
358 size = sizeof(patientIdentifiers) / sizeof(DicomTag); | |
359 break; | |
360 | |
361 case ResourceType_Study: | |
362 tags = studyIdentifiers; | |
363 size = sizeof(studyIdentifiers) / sizeof(DicomTag); | |
364 break; | |
365 | |
366 case ResourceType_Series: | |
367 tags = seriesIdentifiers; | |
368 size = sizeof(seriesIdentifiers) / sizeof(DicomTag); | |
369 break; | |
370 | |
371 case ResourceType_Instance: | |
372 tags = instanceIdentifiers; | |
373 size = sizeof(instanceIdentifiers) / sizeof(DicomTag); | |
374 break; | |
375 | |
376 default: | |
377 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
378 } | |
379 } | |
380 | |
381 | |
382 std::string NormalizeIdentifier(const std::string& value) | |
383 { | |
384 std::string t; | |
385 t.reserve(value.size()); | |
386 | |
387 for (size_t i = 0; i < value.size(); i++) | |
388 { | |
389 if (value[i] == '%' || | |
390 value[i] == '_') | |
391 { | |
392 t.push_back(' '); // These characters might break wildcard queries in SQL | |
393 } | |
394 else if (isascii(value[i]) && | |
395 !iscntrl(value[i]) && | |
396 (!isspace(value[i]) || value[i] == ' ')) | |
397 { | |
398 t.push_back(value[i]); | |
399 } | |
400 } | |
401 | |
402 Toolbox::ToUpperCase(t); | |
403 | |
404 return Toolbox::StripSpaces(t); | |
405 } | |
406 | |
407 | |
408 bool IsIdentifier(const DicomTag& tag, | |
409 ResourceType level) | |
410 { | |
411 const DicomTag* tags; | |
412 size_t size; | |
413 | |
414 LoadIdentifiers(tags, size, level); | |
415 | |
416 for (size_t i = 0; i < size; i++) | |
417 { | |
418 if (tag == tags[i]) | |
419 { | |
420 return true; | |
421 } | |
422 } | |
423 | |
424 return false; | |
425 } | |
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
|
426 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
427 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
428 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
|
429 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
|
430 { |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
431 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
|
432 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
433 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
|
434 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
|
435 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
436 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
|
437 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
|
438 { |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
439 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
|
440 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
441 Json::Value dicomAsJson; |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2380
diff
changeset
|
442 locker.GetDicom().DatasetToJson(dicomAsJson); |
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
|
443 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
444 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
|
445 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
|
446 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
447 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
|
448 } |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
449 } |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
450 } |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
451 } |