comparison OrthancServer/ServerToolbox.cpp @ 1716:2ca7888f8600 db-changes

refactoring DicomIdentifiers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 17 Oct 2015 12:16:27 +0200
parents 4db9200c7f46
children 3926e6317a43
comparison
equal deleted inserted replaced
1715:c3baf74e443f 1716:2ca7888f8600
156 LOG(ERROR) << "Store has failed because required tags (" << s << ") are missing for the following instance: " << t; 156 LOG(ERROR) << "Store has failed because required tags (" << s << ") are missing for the following instance: " << t;
157 } 157 }
158 } 158 }
159 159
160 160
161 static void SetMainDicomTagsInternal(IDatabaseWrapper& database,
162 int64_t resource,
163 const DicomMap& tags)
164 {
165 DicomArray flattened(tags);
166
167 for (size_t i = 0; i < flattened.GetSize(); i++)
168 {
169 const DicomElement& element = flattened.GetElement(i);
170 const DicomTag& tag = element.GetTag();
171 database.SetMainDicomTag(resource, tag, element.GetValue().AsString());
172 }
173 }
174
175
176 static void SetIdentifierTagInternal(IDatabaseWrapper& database,
177 int64_t resource,
178 const DicomMap& tags,
179 const DicomTag& tag)
180 {
181 const DicomValue* value = tags.TestAndGetValue(tag);
182 if (value != NULL &&
183 !value->IsNull())
184 {
185 database.SetIdentifierTag(resource, tag, value->AsString());
186 }
187 }
188
189
161 void SetMainDicomTags(IDatabaseWrapper& database, 190 void SetMainDicomTags(IDatabaseWrapper& database,
162 int64_t resource, 191 int64_t resource,
163 ResourceType level, 192 ResourceType level,
164 const DicomMap& dicomSummary, 193 const DicomMap& dicomSummary)
165 bool includeIdentifiers)
166 { 194 {
167 // WARNING: The database should be locked with a transaction! 195 // WARNING: The database should be locked with a transaction!
168 196
169 DicomMap tags; 197 DicomMap tags;
170 198
171 switch (level) 199 switch (level)
172 { 200 {
173 case ResourceType_Patient: 201 case ResourceType_Patient:
174 dicomSummary.ExtractPatientInformation(tags); 202 dicomSummary.ExtractPatientInformation(tags);
203 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_ID);
175 break; 204 break;
176 205
177 case ResourceType_Study: 206 case ResourceType_Study:
178 dicomSummary.ExtractStudyInformation(tags); 207 dicomSummary.ExtractStudyInformation(tags);
208 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_INSTANCE_UID);
209 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DESCRIPTION); // ???
210 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DATE); // ???
179 break; 211 break;
180 212
181 case ResourceType_Series: 213 case ResourceType_Series:
182 dicomSummary.ExtractSeriesInformation(tags); 214 dicomSummary.ExtractSeriesInformation(tags);
215 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_SERIES_INSTANCE_UID);
183 break; 216 break;
184 217
185 case ResourceType_Instance: 218 case ResourceType_Instance:
186 dicomSummary.ExtractInstanceInformation(tags); 219 dicomSummary.ExtractInstanceInformation(tags);
220 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_SOP_INSTANCE_UID);
187 break; 221 break;
188 222
189 default: 223 default:
190 throw OrthancException(ErrorCode_InternalError); 224 throw OrthancException(ErrorCode_InternalError);
191 } 225 }
192 226
193 DicomArray flattened(tags); 227 SetMainDicomTagsInternal(database, resource, tags);
194 for (size_t i = 0; i < flattened.GetSize(); i++) 228
195 { 229 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6)
196 const DicomElement& element = flattened.GetElement(i); 230 if (level == ResourceType_Study)
197 const DicomTag& tag = element.GetTag(); 231 {
198 232 dicomSummary.ExtractPatientInformation(tags);
199 if (tag.IsIdentifier()) 233 SetMainDicomTagsInternal(database, resource, tags);
200 { 234 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_NAME); // ???
201 if (includeIdentifiers) 235 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_BIRTH_DATE); // ???
202 {
203 database.SetIdentifierTag(resource, tag, element.GetValue().AsString());
204 }
205 }
206 else
207 {
208 database.SetMainDicomTag(resource, tag, element.GetValue().AsString());
209 }
210 } 236 }
211 } 237 }
212 238
213 239
214 bool FindOneChildInstance(int64_t& result, 240 bool FindOneChildInstance(int64_t& result,
304 // Update the tags of this resource 330 // Update the tags of this resource
305 DicomMap dicomSummary; 331 DicomMap dicomSummary;
306 dicom.Convert(dicomSummary); 332 dicom.Convert(dicomSummary);
307 333
308 database.ClearMainDicomTags(resource); 334 database.ClearMainDicomTags(resource);
309 335 Toolbox::SetMainDicomTags(database, resource, level, dicomSummary);
310 switch (level)
311 {
312 case ResourceType_Patient:
313 Toolbox::SetMainDicomTags(database, resource, ResourceType_Patient, dicomSummary, true);
314 break;
315
316 case ResourceType_Study:
317 Toolbox::SetMainDicomTags(database, resource, ResourceType_Study, dicomSummary, true);
318
319 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6)
320 Toolbox::SetMainDicomTags(database, resource, ResourceType_Patient, dicomSummary, false);
321 break;
322
323 case ResourceType_Series:
324 Toolbox::SetMainDicomTags(database, resource, ResourceType_Series, dicomSummary, true);
325 break;
326
327 case ResourceType_Instance:
328 Toolbox::SetMainDicomTags(database, resource, ResourceType_Instance, dicomSummary, true);
329 break;
330
331 default:
332 throw OrthancException(ErrorCode_InternalError);
333 }
334 } 336 }
335 } 337 }
336 } 338 }
337 } 339 }