Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/ResourcesContent.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 | d9473bd5ed43 |
children | f0038043fb97 7053502fbf97 |
comparison
equal
deleted
inserted
replaced
4622:9086aeb9d9d2 | 4623:95ffe3b6ef7c |
---|---|
33 | 33 |
34 #include "../PrecompiledHeadersServer.h" | 34 #include "../PrecompiledHeadersServer.h" |
35 #include "ResourcesContent.h" | 35 #include "ResourcesContent.h" |
36 | 36 |
37 #include "Compatibility/ISetResourcesContent.h" | 37 #include "Compatibility/ISetResourcesContent.h" |
38 #include "../ServerToolbox.h" | |
39 | |
40 #include "../../../OrthancFramework/Sources/DicomFormat/DicomArray.h" | |
41 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
38 | 42 |
39 #include <cassert> | 43 #include <cassert> |
40 | 44 |
41 | 45 |
42 namespace Orthanc | 46 namespace Orthanc |
43 { | 47 { |
48 static void StoreMainDicomTagsInternal(ResourcesContent& target, | |
49 int64_t resource, | |
50 const DicomMap& tags) | |
51 { | |
52 DicomArray flattened(tags); | |
53 | |
54 for (size_t i = 0; i < flattened.GetSize(); i++) | |
55 { | |
56 const DicomElement& element = flattened.GetElement(i); | |
57 const DicomTag& tag = element.GetTag(); | |
58 const DicomValue& value = element.GetValue(); | |
59 if (!value.IsNull() && | |
60 !value.IsBinary()) | |
61 { | |
62 target.AddMainDicomTag(resource, tag, element.GetValue().GetContent()); | |
63 } | |
64 } | |
65 } | |
66 | |
67 | |
68 static void StoreIdentifiers(ResourcesContent& target, | |
69 int64_t resource, | |
70 ResourceType level, | |
71 const DicomMap& map) | |
72 { | |
73 const DicomTag* tags; | |
74 size_t size; | |
75 | |
76 ServerToolbox::LoadIdentifiers(tags, size, level); | |
77 | |
78 for (size_t i = 0; i < size; i++) | |
79 { | |
80 // The identifiers tags are a subset of the main DICOM tags | |
81 assert(DicomMap::IsMainDicomTag(tags[i])); | |
82 | |
83 const DicomValue* value = map.TestAndGetValue(tags[i]); | |
84 if (value != NULL && | |
85 !value->IsNull() && | |
86 !value->IsBinary()) | |
87 { | |
88 std::string s = ServerToolbox::NormalizeIdentifier(value->GetContent()); | |
89 target.AddIdentifierTag(resource, tags[i], s); | |
90 } | |
91 } | |
92 } | |
93 | |
94 | |
95 void ResourcesContent::AddMetadata(int64_t resourceId, | |
96 MetadataType metadata, | |
97 const std::string& value) | |
98 { | |
99 if (isNewResource_) | |
100 { | |
101 metadata_.push_back(Metadata(resourceId, metadata, value)); | |
102 } | |
103 else | |
104 { | |
105 // This would require to handle the incrementation of revision | |
106 // numbers in the database backend => only allow setting | |
107 // metadata on new resources | |
108 throw OrthancException(ErrorCode_NotImplemented); | |
109 } | |
110 } | |
111 | |
112 | |
113 void ResourcesContent::AddResource(int64_t resource, | |
114 ResourceType level, | |
115 const DicomMap& dicomSummary) | |
116 { | |
117 StoreIdentifiers(*this, resource, level, dicomSummary); | |
118 | |
119 DicomMap tags; | |
120 | |
121 switch (level) | |
122 { | |
123 case ResourceType_Patient: | |
124 dicomSummary.ExtractPatientInformation(tags); | |
125 break; | |
126 | |
127 case ResourceType_Study: | |
128 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6) | |
129 dicomSummary.ExtractPatientInformation(tags); | |
130 StoreMainDicomTagsInternal(*this, resource, tags); | |
131 | |
132 dicomSummary.ExtractStudyInformation(tags); | |
133 break; | |
134 | |
135 case ResourceType_Series: | |
136 dicomSummary.ExtractSeriesInformation(tags); | |
137 break; | |
138 | |
139 case ResourceType_Instance: | |
140 dicomSummary.ExtractInstanceInformation(tags); | |
141 break; | |
142 | |
143 default: | |
144 throw OrthancException(ErrorCode_InternalError); | |
145 } | |
146 | |
147 StoreMainDicomTagsInternal(*this, resource, tags); | |
148 } | |
149 | |
150 | |
44 void ResourcesContent::Store(Compatibility::ISetResourcesContent& compatibility) const | 151 void ResourcesContent::Store(Compatibility::ISetResourcesContent& compatibility) const |
45 { | 152 { |
46 for (std::list<TagValue>::const_iterator | 153 for (std::list<TagValue>::const_iterator |
47 it = tags_.begin(); it != tags_.end(); ++it) | 154 it = tags_.begin(); it != tags_.end(); ++it) |
48 { | 155 { |
57 } | 164 } |
58 | 165 |
59 for (std::list<Metadata>::const_iterator | 166 for (std::list<Metadata>::const_iterator |
60 it = metadata_.begin(); it != metadata_.end(); ++it) | 167 it = metadata_.begin(); it != metadata_.end(); ++it) |
61 { | 168 { |
62 compatibility.SetMetadata(it->resourceId_, it->metadata_, it->value_); | 169 assert(isNewResource_); |
170 compatibility.SetMetadata(it->resourceId_, it->metadata_, it->value_, 0 /* initial revision number */); | |
63 } | 171 } |
64 } | 172 } |
65 } | 173 } |