Mercurial > hg > orthanc
annotate OrthancServer/Sources/Database/ResourcesContent.cpp @ 5468:47334eeaaa1a
fix build on opensuse
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 18 Dec 2023 10:44:11 +0100 |
parents | 8b6da4fdf9fe |
children | 48b8dae6dc77 |
rev | line source |
---|---|
3094 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5044
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5044
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
3094 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "../PrecompiledHeadersServer.h" | |
24 #include "ResourcesContent.h" | |
25 | |
26 #include "Compatibility/ISetResourcesContent.h" | |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
27 #include "../ServerToolbox.h" |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
28 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
29 #include "../../../OrthancFramework/Sources/DicomFormat/DicomArray.h" |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
30 #include "../../../OrthancFramework/Sources/OrthancException.h" |
5044
6fed78e13233
Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
31 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" |
3094 | 32 |
33 #include <cassert> | |
34 | |
35 | |
36 namespace Orthanc | |
37 { | |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
38 static void StoreMainDicomTagsInternal(ResourcesContent& target, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
39 int64_t resource, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
40 const DicomMap& tags) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
41 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
42 DicomArray flattened(tags); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
43 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
44 for (size_t i = 0; i < flattened.GetSize(); i++) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
45 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
46 const DicomElement& element = flattened.GetElement(i); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
47 const DicomTag& tag = element.GetTag(); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
48 const DicomValue& value = element.GetValue(); |
5044
6fed78e13233
Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
49 if (value.IsString()) |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
50 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
51 target.AddMainDicomTag(resource, tag, element.GetValue().GetContent()); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
52 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
53 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
54 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
55 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
56 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
57 static void StoreIdentifiers(ResourcesContent& target, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
58 int64_t resource, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
59 ResourceType level, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
60 const DicomMap& map) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
61 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
62 const DicomTag* tags; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
63 size_t size; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
64 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
65 ServerToolbox::LoadIdentifiers(tags, size, level); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
66 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
67 for (size_t i = 0; i < size; i++) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
68 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
69 // The identifiers tags are a subset of the main DICOM tags |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
70 assert(DicomMap::IsMainDicomTag(tags[i])); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
71 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
72 const DicomValue* value = map.TestAndGetValue(tags[i]); |
5044
6fed78e13233
Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
73 if (value != NULL && value->IsString()) |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
74 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
75 std::string s = ServerToolbox::NormalizeIdentifier(value->GetContent()); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
76 target.AddIdentifierTag(resource, tags[i], s); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
77 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
78 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
79 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
80 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
81 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
82 void ResourcesContent::AddMetadata(int64_t resourceId, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
83 MetadataType metadata, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
84 const std::string& value) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
85 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
86 if (isNewResource_) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
87 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
88 metadata_.push_back(Metadata(resourceId, metadata, value)); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
89 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
90 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
91 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
92 // This would require to handle the incrementation of revision |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
93 // numbers in the database backend => only allow setting |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
94 // metadata on new resources |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
95 throw OrthancException(ErrorCode_NotImplemented); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
96 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
97 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
98 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
99 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
100 void ResourcesContent::AddResource(int64_t resource, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
101 ResourceType level, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
102 const DicomMap& dicomSummary) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
103 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
104 StoreIdentifiers(*this, resource, level, dicomSummary); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
105 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
106 DicomMap tags; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
107 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
108 switch (level) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
109 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
110 case ResourceType_Patient: |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
111 dicomSummary.ExtractPatientInformation(tags); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
112 break; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
113 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
114 case ResourceType_Study: |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
115 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
116 dicomSummary.ExtractPatientInformation(tags); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
117 StoreMainDicomTagsInternal(*this, resource, tags); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
118 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
119 dicomSummary.ExtractStudyInformation(tags); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
120 break; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
121 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
122 case ResourceType_Series: |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
123 dicomSummary.ExtractSeriesInformation(tags); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
124 break; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
125 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
126 case ResourceType_Instance: |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
127 dicomSummary.ExtractInstanceInformation(tags); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
128 break; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
129 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
130 default: |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
131 throw OrthancException(ErrorCode_InternalError); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
132 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
133 |
5044
6fed78e13233
Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
134 StoreMainDicomTagsInternal(*this, resource, tags); // saves only leaf tags, not sequences |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
135 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
136 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
137 |
3094 | 138 void ResourcesContent::Store(Compatibility::ISetResourcesContent& compatibility) const |
139 { | |
140 for (std::list<TagValue>::const_iterator | |
141 it = tags_.begin(); it != tags_.end(); ++it) | |
142 { | |
5215
8b6da4fdf9fe
cleaning ResourcesContent::TagValue and ResourcesContent::Metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
143 if (it->IsIdentifier()) |
3094 | 144 { |
5215
8b6da4fdf9fe
cleaning ResourcesContent::TagValue and ResourcesContent::Metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
145 compatibility.SetIdentifierTag(it->GetResourceId(), it->GetTag(), it->GetValue()); |
3094 | 146 } |
147 else | |
148 { | |
5215
8b6da4fdf9fe
cleaning ResourcesContent::TagValue and ResourcesContent::Metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
149 compatibility.SetMainDicomTag(it->GetResourceId(), it->GetTag(), it->GetValue()); |
3094 | 150 } |
151 } | |
152 | |
153 for (std::list<Metadata>::const_iterator | |
154 it = metadata_.begin(); it != metadata_.end(); ++it) | |
155 { | |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
156 assert(isNewResource_); |
5215
8b6da4fdf9fe
cleaning ResourcesContent::TagValue and ResourcesContent::Metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
157 compatibility.SetMetadata(it->GetResourceId(), it->GetType(), it->GetValue(), 0 /* initial revision number */); |
3094 | 158 } |
159 } | |
160 } |