comparison OrthancServer/Sources/ServerToolbox.cpp @ 4623:95ffe3b6ef7c db-changes

handling of revisions for metadata
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Apr 2021 17:13:03 +0200
parents ff8170d17d90
children f7d5372b59b3
comparison
equal deleted inserted replaced
4622:9086aeb9d9d2 4623:95ffe3b6ef7c
32 32
33 33
34 #include "PrecompiledHeadersServer.h" 34 #include "PrecompiledHeadersServer.h"
35 #include "ServerToolbox.h" 35 #include "ServerToolbox.h"
36 36
37 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
38 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h" 37 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
39 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h" 38 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h"
40 #include "../../OrthancFramework/Sources/Logging.h" 39 #include "../../OrthancFramework/Sources/Logging.h"
41 #include "../../OrthancFramework/Sources/OrthancException.h" 40 #include "../../OrthancFramework/Sources/OrthancException.h"
42 #include "Database/IDatabaseWrapper.h" 41 #include "Database/IDatabaseWrapper.h"
75 { 74 {
76 DICOM_TAG_SOP_INSTANCE_UID 75 DICOM_TAG_SOP_INSTANCE_UID
77 }; 76 };
78 77
79 78
80 static void StoreMainDicomTagsInternal(ResourcesContent& target,
81 int64_t resource,
82 const DicomMap& tags)
83 {
84 DicomArray flattened(tags);
85
86 for (size_t i = 0; i < flattened.GetSize(); i++)
87 {
88 const DicomElement& element = flattened.GetElement(i);
89 const DicomTag& tag = element.GetTag();
90 const DicomValue& value = element.GetValue();
91 if (!value.IsNull() &&
92 !value.IsBinary())
93 {
94 target.AddMainDicomTag(resource, tag, element.GetValue().GetContent());
95 }
96 }
97 }
98
99
100 static void StoreIdentifiers(ResourcesContent& target,
101 int64_t resource,
102 ResourceType level,
103 const DicomMap& map)
104 {
105 const DicomTag* tags;
106 size_t size;
107
108 ServerToolbox::LoadIdentifiers(tags, size, level);
109
110 for (size_t i = 0; i < size; i++)
111 {
112 // The identifiers tags are a subset of the main DICOM tags
113 assert(DicomMap::IsMainDicomTag(tags[i]));
114
115 const DicomValue* value = map.TestAndGetValue(tags[i]);
116 if (value != NULL &&
117 !value->IsNull() &&
118 !value->IsBinary())
119 {
120 std::string s = ServerToolbox::NormalizeIdentifier(value->GetContent());
121 target.AddIdentifierTag(resource, tags[i], s);
122 }
123 }
124 }
125
126
127 void ResourcesContent::AddResource(int64_t resource,
128 ResourceType level,
129 const DicomMap& dicomSummary)
130 {
131 StoreIdentifiers(*this, resource, level, dicomSummary);
132
133 DicomMap tags;
134
135 switch (level)
136 {
137 case ResourceType_Patient:
138 dicomSummary.ExtractPatientInformation(tags);
139 break;
140
141 case ResourceType_Study:
142 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6)
143 dicomSummary.ExtractPatientInformation(tags);
144 StoreMainDicomTagsInternal(*this, resource, tags);
145
146 dicomSummary.ExtractStudyInformation(tags);
147 break;
148
149 case ResourceType_Series:
150 dicomSummary.ExtractSeriesInformation(tags);
151 break;
152
153 case ResourceType_Instance:
154 dicomSummary.ExtractInstanceInformation(tags);
155 break;
156
157 default:
158 throw OrthancException(ErrorCode_InternalError);
159 }
160
161 StoreMainDicomTagsInternal(*this, resource, tags);
162 }
163
164
165 namespace ServerToolbox 79 namespace ServerToolbox
166 { 80 {
167 bool FindOneChildInstance(int64_t& result, 81 bool FindOneChildInstance(int64_t& result,
168 IDatabaseWrapper::ITransaction& transaction, 82 IDatabaseWrapper::ITransaction& transaction,
169 int64_t resource, 83 int64_t resource,
272 DicomMap dicomSummary; 186 DicomMap dicomSummary;
273 OrthancConfiguration::DefaultExtractDicomSummary(dicomSummary, dicom); 187 OrthancConfiguration::DefaultExtractDicomSummary(dicomSummary, dicom);
274 188
275 transaction.ClearMainDicomTags(resource); 189 transaction.ClearMainDicomTags(resource);
276 190
277 ResourcesContent tags; 191 ResourcesContent tags(false /* prevent the setting of metadata */);
278 tags.AddResource(resource, level, dicomSummary); 192 tags.AddResource(resource, level, dicomSummary);
279 transaction.SetResourcesContent(tags); 193 transaction.SetResourcesContent(tags);
280 } 194 }
281 catch (OrthancException&) 195 catch (OrthancException&)
282 { 196 {