Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/FindResponse.h @ 5586:fc3914c07dd3 find-refactoring
refactoring FindResponse
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 03 May 2024 17:02:02 +0200 |
parents | 74cc31c8db2b |
children | 0f5586c498d1 |
comparison
equal
deleted
inserted
replaced
5583:74cc31c8db2b | 5586:fc3914c07dd3 |
---|---|
38 | 38 |
39 namespace Orthanc | 39 namespace Orthanc |
40 { | 40 { |
41 class FindResponse : public boost::noncopyable | 41 class FindResponse : public boost::noncopyable |
42 { | 42 { |
43 private: | |
44 class DicomTagsAtLevel : public boost::noncopyable | |
45 { | |
46 private: | |
47 class DicomValue; | |
48 | |
49 typedef std::map<DicomTag, DicomValue*> Content; | |
50 | |
51 Content content_; | |
52 | |
53 public: | |
54 ~DicomTagsAtLevel(); | |
55 | |
56 void AddNullValue(uint16_t group, | |
57 uint16_t element); | |
58 | |
59 void AddStringValue(uint16_t group, | |
60 uint16_t element, | |
61 const std::string& value); | |
62 | |
63 void Fill(DicomMap& target) const; | |
64 }; | |
65 | |
66 | |
67 class ChildrenAtLevel : public boost::noncopyable | |
68 { | |
69 private: | |
70 std::set<std::string> identifiers_; | |
71 | |
72 public: | |
73 void AddIdentifier(const std::string& identifier); | |
74 | |
75 const std::set<std::string>& GetIdentifiers() const | |
76 { | |
77 return identifiers_; | |
78 } | |
79 }; | |
80 | |
81 | |
43 public: | 82 public: |
44 | 83 class Item : public boost::noncopyable |
45 // TODO-FIND: does it actually make sense to retrieve revisions for metadata and attachments ? | |
46 class StringWithRevision | |
47 { | 84 { |
48 private: | 85 private: |
49 std::string value_; | 86 ResourceType level_; |
50 int64_t revision_; | 87 std::string identifier_; |
51 public: | 88 std::unique_ptr<std::string> parentIdentifier_; |
52 StringWithRevision(const std::string& value, | 89 DicomTagsAtLevel patientTags_; |
53 int64_t revision) : | 90 DicomTagsAtLevel studyTags_; |
54 value_(value), | 91 DicomTagsAtLevel seriesTags_; |
55 revision_(revision) | 92 DicomTagsAtLevel instanceTags_; |
56 { | 93 ChildrenAtLevel childrenStudies_; |
57 } | 94 ChildrenAtLevel childrenSeries_; |
58 | 95 ChildrenAtLevel childrenInstances_; |
59 StringWithRevision(const StringWithRevision& other) : | |
60 value_(other.value_), | |
61 revision_(other.revision_) | |
62 { | |
63 } | |
64 | |
65 StringWithRevision() : | |
66 revision_(-1) | |
67 { | |
68 } | |
69 | |
70 const std::string& GetValue() const | |
71 { | |
72 return value_; | |
73 } | |
74 | |
75 int64_t GetRevision() const | |
76 { | |
77 return revision_; | |
78 } | |
79 }; | |
80 | |
81 | |
82 class Item : public boost::noncopyable | |
83 { | |
84 private: | |
85 OrthancIdentifiers identifiers_; | |
86 std::unique_ptr<DicomMap> dicomMap_; | |
87 std::list<std::string> children_; | |
88 std::string childInstanceId_; | |
89 std::set<std::string> labels_; | 96 std::set<std::string> labels_; |
90 std::map<MetadataType, std::string> metadata_; | 97 std::map<MetadataType, std::string> metadata_; |
91 std::map<FileContentType, FileInfo> attachments_; | 98 std::map<FileContentType, FileInfo> attachments_; |
92 | 99 |
100 DicomTagsAtLevel& GetDicomTagsAtLevel(ResourceType level); | |
101 | |
102 ChildrenAtLevel& GetChildrenAtLevel(ResourceType level); | |
103 | |
93 public: | 104 public: |
94 explicit Item(const OrthancIdentifiers& identifiers) : | 105 explicit Item(ResourceType level, |
95 identifiers_(identifiers) | 106 const std::string& identifier) : |
96 { | 107 level_(level), |
97 } | 108 identifier_(identifier) |
98 | 109 { |
99 Item(ResourceType level, | 110 } |
100 DicomMap* dicomMap /* takes ownership */); | 111 |
101 | 112 ResourceType GetLevel() const |
102 const OrthancIdentifiers& GetIdentifiers() const | 113 { |
103 { | 114 return level_; |
104 return identifiers_; | 115 } |
105 } | 116 |
106 | 117 const std::string& GetIdentifier() const |
107 void AddDicomTag(uint16_t group, uint16_t element, const std::string& value, bool isBinary); | 118 { |
119 return identifier_; | |
120 } | |
121 | |
122 const std::string& GetParentIdentifier() const; | |
123 | |
124 void SetParentIdentifier(const std::string& id); | |
125 | |
126 bool HasParentIdentifier() const; | |
127 | |
128 void AddStringDicomTag(ResourceType level, | |
129 uint16_t group, | |
130 uint16_t element, | |
131 const std::string& value) | |
132 { | |
133 GetDicomTagsAtLevel(level).AddStringValue(group, element, value); | |
134 } | |
135 | |
136 // The "Null" value could be used in the future to indicate a | |
137 // value that is not available, typically a new "ExtraMainDicomTag" | |
138 void AddNullDicomTag(ResourceType level, | |
139 uint16_t group, | |
140 uint16_t element, | |
141 const std::string& value) | |
142 { | |
143 GetDicomTagsAtLevel(level).AddNullValue(group, element); | |
144 } | |
145 | |
146 void GetDicomTagsAtLevel(DicomMap& target, | |
147 ResourceType level) const | |
148 { | |
149 const_cast<Item&>(*this).GetDicomTagsAtLevel(level).Fill(target); | |
150 } | |
151 | |
152 void AddChildIdentifier(ResourceType level, | |
153 const std::string& childId) | |
154 { | |
155 GetChildrenAtLevel(level).AddIdentifier(childId); | |
156 } | |
157 | |
158 const std::set<std::string>& GetChildrenIdentifiers(ResourceType level) const | |
159 { | |
160 return const_cast<Item&>(*this).GetChildrenAtLevel(level).GetIdentifiers(); | |
161 } | |
162 | |
163 void AddLabel(const std::string& label); | |
164 | |
165 const std::set<std::string>& GetLabels() const | |
166 { | |
167 return labels_; | |
168 } | |
108 | 169 |
109 void AddMetadata(MetadataType metadata, | 170 void AddMetadata(MetadataType metadata, |
110 const std::string& value); | 171 const std::string& value); |
111 //int64_t revision); | |
112 | 172 |
113 const std::map<MetadataType, std::string>& GetMetadata() const | 173 const std::map<MetadataType, std::string>& GetMetadata() const |
114 { | 174 { |
115 return metadata_; | 175 return metadata_; |
116 } | 176 } |
118 bool HasMetadata(MetadataType metadata) const | 178 bool HasMetadata(MetadataType metadata) const |
119 { | 179 { |
120 return metadata_.find(metadata) != metadata_.end(); | 180 return metadata_.find(metadata) != metadata_.end(); |
121 } | 181 } |
122 | 182 |
123 bool LookupMetadata(std::string& value, /* int64_t revision, */ | 183 bool LookupMetadata(std::string& value, |
124 MetadataType metadata) const; | 184 MetadataType metadata) const; |
125 | 185 |
126 void ListMetadata(std::set<MetadataType>& metadata) const; | 186 void ListMetadata(std::set<MetadataType>& metadata) const; |
127 | 187 |
128 bool HasDicomMap() const | 188 void AddAttachment(const FileInfo& attachment); |
129 { | 189 |
130 return dicomMap_.get() != NULL; | 190 bool LookupAttachment(FileInfo& target, |
131 } | 191 FileContentType type) const; |
132 | |
133 const DicomMap& GetDicomMap() const; | |
134 | |
135 void AddChild(const std::string& childId); | |
136 | |
137 const std::list<std::string>& GetChildren() const | |
138 { | |
139 return children_; | |
140 } | |
141 | |
142 void AddLabel(const std::string& label) | |
143 { | |
144 labels_.insert(label); | |
145 } | |
146 | |
147 const std::set<std::string>& GetLabels() const | |
148 { | |
149 return labels_; | |
150 } | |
151 | |
152 void AddAttachment(const FileInfo& attachment) | |
153 { | |
154 attachments_[attachment.GetContentType()] = attachment; | |
155 } | |
156 | |
157 const std::map<FileContentType, FileInfo>& GetAttachments() const | |
158 { | |
159 return attachments_; | |
160 } | |
161 | |
162 bool LookupAttachment(FileInfo& target, FileContentType type) const | |
163 { | |
164 std::map<FileContentType, FileInfo>::const_iterator it = attachments_.find(type); | |
165 if (it != attachments_.end()) | |
166 { | |
167 target = it->second; | |
168 return true; | |
169 } | |
170 | |
171 return false; | |
172 } | |
173 | |
174 void SetIdentifier(ResourceType level, | |
175 const std::string& id) | |
176 { | |
177 identifiers_.SetLevel(level, id); | |
178 } | |
179 | |
180 // TODO-FIND: add other getters and setters | |
181 }; | 192 }; |
182 | 193 |
183 private: | 194 private: |
195 typedef std::map<std::string, Item*> Index; | |
196 | |
184 std::deque<Item*> items_; | 197 std::deque<Item*> items_; |
198 Index index_; | |
185 | 199 |
186 public: | 200 public: |
187 ~FindResponse(); | 201 ~FindResponse(); |
188 | 202 |
189 void Add(Item* item /* takes ownership */); | 203 void Add(Item* item /* takes ownership */); |
192 { | 206 { |
193 return items_.size(); | 207 return items_.size(); |
194 } | 208 } |
195 | 209 |
196 const Item& GetItem(size_t index) const; | 210 const Item& GetItem(size_t index) const; |
211 | |
212 const Item* LookupItem(const std::string& id) const; | |
197 }; | 213 }; |
198 } | 214 } |