annotate OrthancServer/ServerToolbox.cpp @ 1724:7e0b5e413c7c db-changes

C-Move SCP for studies using AccessionNumber tag
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Oct 2015 11:02:06 +0200
parents 3926e6317a43
children a7c05bbfaf6a
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
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
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"
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
40 #include "ParsedDicomFile.h"
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
234
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
42 #include <cassert>
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
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 {
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
46 namespace Toolbox
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
48 void SimplifyTags(Json::Value& target,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
49 const Json::Value& source)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
50 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
51 assert(source.isObject());
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
53 target = Json::objectValue;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
54 Json::Value::Members members = source.getMemberNames();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
55
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
56 for (size_t i = 0; i < members.size(); i++)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
57 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
58 const Json::Value& v = source[members[i]];
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
59 const std::string& name = v["Name"].asString();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
60 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
61
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
62 if (type == "String")
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
63 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
64 target[name] = v["Value"].asString();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
65 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
66 else if (type == "TooLong" ||
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
67 type == "Null")
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
68 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
69 target[name] = Json::nullValue;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
70 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
71 else if (type == "Sequence")
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
72 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
73 const Json::Value& array = v["Value"];
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
74 assert(array.isArray());
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
76 Json::Value children = Json::arrayValue;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
77 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
78 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
79 Json::Value c;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
80 SimplifyTags(c, array[i]);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
81 children.append(c);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
82 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
83
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
84 target[name] = children;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
85 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
86 else
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
87 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
88 assert(0);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
89 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
91 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
92
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
93
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
94 void LogMissingRequiredTag(const DicomMap& summary)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
95 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
96 std::string s, t;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
97
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
98 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
99 {
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
100 if (t.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
101 t += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
102 t += "PatientID=" + summary.GetValue(DICOM_TAG_PATIENT_ID).AsString();
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
104 else
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
106 if (s.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
107 s += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
108 s += "PatientID";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
109 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
111 if (summary.HasTag(DICOM_TAG_STUDY_INSTANCE_UID))
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 if (t.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
114 t += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
115 t += "StudyInstanceUID=" + summary.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
116 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
117 else
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
118 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
119 if (s.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
120 s += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
121 s += "StudyInstanceUID";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
122 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
124 if (summary.HasTag(DICOM_TAG_SERIES_INSTANCE_UID))
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 if (t.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
127 t += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
128 t += "SeriesInstanceUID=" + summary.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString();
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 else
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
131 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
132 if (s.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
133 s += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
134 s += "SeriesInstanceUID";
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
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
137 if (summary.HasTag(DICOM_TAG_SOP_INSTANCE_UID))
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 if (t.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
140 t += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
141 t += "SOPInstanceUID=" + summary.GetValue(DICOM_TAG_SOP_INSTANCE_UID).AsString();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
142 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
143 else
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
144 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
145 if (s.size() > 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
146 s += ", ";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
147 s += "SOPInstanceUID";
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
148 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
149
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
150 if (t.size() == 0)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
151 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
152 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
153 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 else
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
156 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
157 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
158 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
159
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
160
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
161 static void SetMainDicomTagsInternal(IDatabaseWrapper& database,
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
162 int64_t resource,
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
163 const DicomMap& tags)
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
164 {
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
165 DicomArray flattened(tags);
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
166
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
167 for (size_t i = 0; i < flattened.GetSize(); i++)
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
168 {
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
169 const DicomElement& element = flattened.GetElement(i);
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
170 const DicomTag& tag = element.GetTag();
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
171 database.SetMainDicomTag(resource, tag, element.GetValue().AsString());
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
172 }
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
173 }
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
174
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
175
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
176 static void SetIdentifierTagInternal(IDatabaseWrapper& database,
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
177 int64_t resource,
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
178 const DicomMap& tags,
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
179 const DicomTag& tag)
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
180 {
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
181 const DicomValue* value = tags.TestAndGetValue(tag);
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
182 if (value != NULL &&
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
183 !value->IsNull())
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
184 {
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
185 std::string s = value->AsString();
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
186
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
187 if (!tag.IsIdentifier())
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
188 {
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
189 s = NormalizeIdentifierTag(s);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
190 }
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
191
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
192 database.SetIdentifierTag(resource, tag, s);
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
193 }
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
194 }
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
195
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
196
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
197 static void AttachPatientInformation(IDatabaseWrapper& database,
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
198 int64_t resource,
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
199 const DicomMap& dicomSummary)
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
200 {
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
201 DicomMap tags;
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
202 dicomSummary.ExtractPatientInformation(tags);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
203 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_ID);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
204 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_NAME);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
205 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_BIRTH_DATE);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
206 SetMainDicomTagsInternal(database, resource, tags);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
207 }
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
208
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 void SetMainDicomTags(IDatabaseWrapper& database,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
211 int64_t resource,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
212 ResourceType level,
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
213 const DicomMap& dicomSummary)
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
214 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
215 // WARNING: The database should be locked with a transaction!
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 DicomMap tags;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
218
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
219 switch (level)
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 case ResourceType_Patient:
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
222 AttachPatientInformation(database, resource, dicomSummary);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
223 break;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
224
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
225 case ResourceType_Study:
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
226 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6)
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
227 AttachPatientInformation(database, resource, dicomSummary);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
228
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
229 dicomSummary.ExtractStudyInformation(tags);
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
230 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_INSTANCE_UID);
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
231 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_ACCESSION_NUMBER);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
232 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DESCRIPTION);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
233 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DATE);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
234 break;
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 case ResourceType_Series:
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
237 dicomSummary.ExtractSeriesInformation(tags);
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
238 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_SERIES_INSTANCE_UID);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
239 break;
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 case ResourceType_Instance:
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
242 dicomSummary.ExtractInstanceInformation(tags);
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
243 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_SOP_INSTANCE_UID);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
244 break;
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 default:
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
247 throw OrthancException(ErrorCode_InternalError);
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
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
250 SetMainDicomTagsInternal(database, resource, tags);
1668
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 bool FindOneChildInstance(int64_t& result,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
255 IDatabaseWrapper& database,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
256 int64_t resource,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
257 ResourceType type)
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 for (;;)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
260 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
261 if (type == ResourceType_Instance)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
262 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
263 result = resource;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
264 return true;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
265 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
266
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
267 std::list<int64_t> children;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
268 database.GetChildrenInternalId(children, resource);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
269 if (children.empty())
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
270 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
271 return false;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
272 }
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 resource = children.front();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
275 type = GetChildResourceType(type);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
276 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
277 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
278
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 void ReconstructMainDicomTags(IDatabaseWrapper& database,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
281 IStorageArea& storageArea,
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
282 ResourceType level)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
283 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
284 // WARNING: The database should be locked with a transaction!
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
285
1669
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
286 const char* plural = NULL;
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 switch (level)
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
289 {
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
290 case ResourceType_Patient:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
291 plural = "patients";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
292 break;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
293
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
294 case ResourceType_Study:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
295 plural = "studies";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
296 break;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
297
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
298 case ResourceType_Series:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
299 plural = "series";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
300 break;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
301
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
302 case ResourceType_Instance:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
303 plural = "instances";
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
304 break;
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
305
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
306 default:
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
307 throw OrthancException(ErrorCode_InternalError);
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
308 }
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
309
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
310 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
311
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
312 std::list<std::string> resources;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
313 database.GetAllPublicIds(resources, level);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
314
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
315 for (std::list<std::string>::const_iterator
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
316 it = resources.begin(); it != resources.end(); it++)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
317 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
318 // Locate the resource and one of its child instances
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
319 int64_t resource, instance;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
320 ResourceType tmp;
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 if (!database.LookupResource(resource, tmp, *it) ||
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
323 tmp != level ||
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
324 !FindOneChildInstance(instance, database, resource, level))
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
325 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
326 throw OrthancException(ErrorCode_InternalError);
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 // 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
330 FileInfo attachment;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
331 if (!database.LookupAttachment(attachment, instance, FileContentType_Dicom))
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
332 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
333 throw OrthancException(ErrorCode_InternalError);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
334 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
335
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
336 // Read and parse the content of the DICOM file
1673
0bbcfd9695e5 UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1669
diff changeset
337 StorageAccessor accessor(storageArea);
0bbcfd9695e5 UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1669
diff changeset
338
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
339 std::string content;
1673
0bbcfd9695e5 UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1669
diff changeset
340 accessor.Read(content, attachment);
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
341
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
342 ParsedDicomFile dicom(content);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
343
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
344 // Update the tags of this resource
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
345 DicomMap dicomSummary;
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
346 dicom.Convert(dicomSummary);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
347
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
348 database.ClearMainDicomTags(resource);
1716
2ca7888f8600 refactoring DicomIdentifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
349 Toolbox::SetMainDicomTags(database, resource, level, dicomSummary);
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
352
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
353
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
354 std::string NormalizeIdentifierTag(const std::string& value)
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
355 {
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
356 std::string s = Toolbox::ConvertToAscii(Toolbox::StripSpaces(value));
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
357 Toolbox::ToUpperCase(s);
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
358 return s;
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1716
diff changeset
359 }
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }