Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerToolbox.cpp @ 4097:99e2054d1e8d
fix unit tests for orthanc framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 01 Jul 2020 11:15:29 +0200 |
parents | 9214e3a7b0a2 |
children | a4f28efdfccf |
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 |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3099
diff
changeset
|
5 * Copyright (C) 2017-2020 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 |
4045 | 37 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h" |
38 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h" | |
39 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h" | |
40 #include "../../OrthancFramework/Sources/Logging.h" | |
41 #include "../../OrthancFramework/Sources/OrthancException.h" | |
3093
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3089
diff
changeset
|
42 #include "Database/IDatabaseWrapper.h" |
3099
9c71abbff70f
removing build dependency on plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
43 #include "Database/ResourcesContent.h" |
3083
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
44 #include "ServerContext.h" |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
234 | 46 #include <cassert> |
47 | |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 namespace Orthanc |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 { |
3083
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
50 static const DicomTag PATIENT_IDENTIFIERS[] = |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
51 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
52 DICOM_TAG_PATIENT_ID, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
53 DICOM_TAG_PATIENT_NAME, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
54 DICOM_TAG_PATIENT_BIRTH_DATE |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
55 }; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
56 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
57 static const DicomTag STUDY_IDENTIFIERS[] = |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
58 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
59 DICOM_TAG_PATIENT_ID, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
60 DICOM_TAG_PATIENT_NAME, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
61 DICOM_TAG_PATIENT_BIRTH_DATE, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
62 DICOM_TAG_STUDY_INSTANCE_UID, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
63 DICOM_TAG_ACCESSION_NUMBER, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
64 DICOM_TAG_STUDY_DESCRIPTION, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
65 DICOM_TAG_STUDY_DATE |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
66 }; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
67 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
68 static const DicomTag SERIES_IDENTIFIERS[] = |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
69 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
70 DICOM_TAG_SERIES_INSTANCE_UID |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
71 }; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
72 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
73 static const DicomTag INSTANCE_IDENTIFIERS[] = |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
74 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
75 DICOM_TAG_SOP_INSTANCE_UID |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
76 }; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
77 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
78 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
79 static void StoreMainDicomTagsInternal(ResourcesContent& target, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
80 int64_t resource, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
81 const DicomMap& tags) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
82 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
83 DicomArray flattened(tags); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
84 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
85 for (size_t i = 0; i < flattened.GetSize(); i++) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
86 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
87 const DicomElement& element = flattened.GetElement(i); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
88 const DicomTag& tag = element.GetTag(); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
89 const DicomValue& value = element.GetValue(); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
90 if (!value.IsNull() && |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
91 !value.IsBinary()) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
92 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
93 target.AddMainDicomTag(resource, tag, element.GetValue().GetContent()); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
94 } |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
95 } |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
96 } |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
97 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
98 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
99 static void StoreIdentifiers(ResourcesContent& target, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
100 int64_t resource, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
101 ResourceType level, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
102 const DicomMap& map) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
103 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
104 const DicomTag* tags; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
105 size_t size; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
106 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
107 ServerToolbox::LoadIdentifiers(tags, size, level); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
108 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
109 for (size_t i = 0; i < size; i++) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
110 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
111 // The identifiers tags are a subset of the main DICOM tags |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
112 assert(DicomMap::IsMainDicomTag(tags[i])); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
113 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
114 const DicomValue* value = map.TestAndGetValue(tags[i]); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
115 if (value != NULL && |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
116 !value->IsNull() && |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
117 !value->IsBinary()) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
118 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
119 std::string s = ServerToolbox::NormalizeIdentifier(value->GetContent()); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
120 target.AddIdentifierTag(resource, tags[i], s); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
121 } |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
122 } |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
123 } |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
124 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
125 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
126 void ResourcesContent::AddResource(int64_t resource, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
127 ResourceType level, |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
128 const DicomMap& dicomSummary) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
129 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
130 StoreIdentifiers(*this, resource, level, dicomSummary); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
131 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
132 DicomMap tags; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
133 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
134 switch (level) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
135 { |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
136 case ResourceType_Patient: |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
137 dicomSummary.ExtractPatientInformation(tags); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
138 break; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
139 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
140 case ResourceType_Study: |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
141 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6) |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
142 dicomSummary.ExtractPatientInformation(tags); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
143 StoreMainDicomTagsInternal(*this, resource, tags); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
144 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
145 dicomSummary.ExtractStudyInformation(tags); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
146 break; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
147 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
148 case ResourceType_Series: |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
149 dicomSummary.ExtractSeriesInformation(tags); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
150 break; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
151 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
152 case ResourceType_Instance: |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
153 dicomSummary.ExtractInstanceInformation(tags); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
154 break; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
155 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
156 default: |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
157 throw OrthancException(ErrorCode_InternalError); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
158 } |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
159 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
160 StoreMainDicomTagsInternal(*this, resource, tags); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
161 } |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
162 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
163 |
2120 | 164 namespace ServerToolbox |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 { |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
166 bool FindOneChildInstance(int64_t& result, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
167 IDatabaseWrapper& database, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
168 int64_t resource, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
169 ResourceType type) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
170 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
171 for (;;) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
172 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
173 if (type == ResourceType_Instance) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
174 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
175 result = resource; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
176 return true; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
177 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
178 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
179 std::list<int64_t> children; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
180 database.GetChildrenInternalId(children, resource); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
181 if (children.empty()) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
182 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
183 return false; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
184 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
185 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
186 resource = children.front(); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
187 type = GetChildResourceType(type); |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
188 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
189 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
190 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
191 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
192 void ReconstructMainDicomTags(IDatabaseWrapper& database, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
193 IStorageArea& storageArea, |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
194 ResourceType level) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
195 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
196 // WARNING: The database should be locked with a transaction! |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
197 |
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
|
198 // 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
|
199 // 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
|
200 // 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
|
201 // 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
|
202 // 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
|
203 // 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
|
204 |
1669
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
205 const char* plural = NULL; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
206 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
207 switch (level) |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
208 { |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
209 case ResourceType_Patient: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
210 plural = "patients"; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
211 break; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
212 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
213 case ResourceType_Study: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
214 plural = "studies"; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
215 break; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
216 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
217 case ResourceType_Series: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
218 plural = "series"; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
219 break; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
220 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
221 case ResourceType_Instance: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
222 plural = "instances"; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
223 break; |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
224 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
225 default: |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
226 throw OrthancException(ErrorCode_InternalError); |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
227 } |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
228 |
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
229 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
|
230 |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
231 std::list<std::string> resources; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
232 database.GetAllPublicIds(resources, level); |
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 (std::list<std::string>::const_iterator |
1847 | 235 it = resources.begin(); it != resources.end(); ++it) |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
236 { |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
237 // Locate the resource and one of its child instances |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
238 int64_t resource, instance; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
239 ResourceType tmp; |
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 if (!database.LookupResource(resource, tmp, *it) || |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
242 tmp != level || |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
243 !FindOneChildInstance(instance, database, resource, level)) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
244 { |
2955 | 245 throw OrthancException(ErrorCode_InternalError, |
246 "Cannot find an instance for " + | |
247 std::string(EnumerationToString(level)) + | |
248 " with identifier " + *it); | |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
249 } |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
250 |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
251 // 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
|
252 FileInfo attachment; |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
253 if (!database.LookupAttachment(attachment, instance, FileContentType_Dicom)) |
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
254 { |
2955 | 255 throw OrthancException(ErrorCode_InternalError, |
256 "Cannot retrieve the DICOM file associated with instance " + | |
257 database.GetPublicId(instance)); | |
1668
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 |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
260 try |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
261 { |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
262 // 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
|
263 StorageAccessor accessor(storageArea); |
1673
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1669
diff
changeset
|
264 |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
265 std::string content; |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
266 accessor.Read(content, attachment); |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
267 |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
268 ParsedDicomFile dicom(content); |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
269 |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
270 // Update the tags of this resource |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
271 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
|
272 dicom.ExtractDicomSummary(dicomSummary); |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
273 |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
274 database.ClearMainDicomTags(resource); |
3083
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
275 |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
276 ResourcesContent tags; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
277 tags.AddResource(resource, level, dicomSummary); |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
278 database.SetResourcesContent(tags); |
1870
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
279 } |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
280 catch (OrthancException&) |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
281 { |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
282 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
|
283 << " associated with instance " << database.GetPublicId(instance); |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
284 throw; |
a6c431193c79
Improved logging information if upgrade fails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1860
diff
changeset
|
285 } |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 } |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 } |
2121 | 288 |
289 | |
290 void LoadIdentifiers(const DicomTag*& tags, | |
291 size_t& size, | |
292 ResourceType level) | |
293 { | |
294 switch (level) | |
295 { | |
296 case ResourceType_Patient: | |
3083
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
297 tags = PATIENT_IDENTIFIERS; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
298 size = sizeof(PATIENT_IDENTIFIERS) / sizeof(DicomTag); |
2121 | 299 break; |
300 | |
301 case ResourceType_Study: | |
3083
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
302 tags = STUDY_IDENTIFIERS; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
303 size = sizeof(STUDY_IDENTIFIERS) / sizeof(DicomTag); |
2121 | 304 break; |
305 | |
306 case ResourceType_Series: | |
3083
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
307 tags = SERIES_IDENTIFIERS; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
308 size = sizeof(SERIES_IDENTIFIERS) / sizeof(DicomTag); |
2121 | 309 break; |
310 | |
311 case ResourceType_Instance: | |
3083
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
312 tags = INSTANCE_IDENTIFIERS; |
683d572424b6
IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
313 size = sizeof(INSTANCE_IDENTIFIERS) / sizeof(DicomTag); |
2121 | 314 break; |
315 | |
316 default: | |
317 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
318 } | |
319 } | |
320 | |
321 | |
322 std::string NormalizeIdentifier(const std::string& value) | |
323 { | |
324 std::string t; | |
325 t.reserve(value.size()); | |
326 | |
327 for (size_t i = 0; i < value.size(); i++) | |
328 { | |
329 if (value[i] == '%' || | |
330 value[i] == '_') | |
331 { | |
332 t.push_back(' '); // These characters might break wildcard queries in SQL | |
333 } | |
334 else if (isascii(value[i]) && | |
335 !iscntrl(value[i]) && | |
336 (!isspace(value[i]) || value[i] == ' ')) | |
337 { | |
338 t.push_back(value[i]); | |
339 } | |
340 } | |
341 | |
342 Toolbox::ToUpperCase(t); | |
343 | |
344 return Toolbox::StripSpaces(t); | |
345 } | |
346 | |
347 | |
348 bool IsIdentifier(const DicomTag& tag, | |
349 ResourceType level) | |
350 { | |
351 const DicomTag* tags; | |
352 size_t size; | |
353 | |
354 LoadIdentifiers(tags, size, level); | |
355 | |
356 for (size_t i = 0; i < size; i++) | |
357 { | |
358 if (tag == tags[i]) | |
359 { | |
360 return true; | |
361 } | |
362 } | |
363 | |
364 return false; | |
365 } | |
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
|
366 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
367 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
368 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
|
369 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
|
370 { |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
371 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
|
372 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
373 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
|
374 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
|
375 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
376 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
|
377 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
|
378 { |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
379 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
|
380 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
381 Json::Value dicomAsJson; |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2380
diff
changeset
|
382 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
|
383 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
384 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
|
385 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
|
386 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
387 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
|
388 } |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
389 } |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 } |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
391 } |