Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 4937:3f9b9865c8cc more-tags
include requested tags from storage if needed
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 14 Mar 2022 13:13:29 +0100 |
parents | 8422e4f99a18 |
children | e8a2e145c80e |
comparison
equal
deleted
inserted
replaced
4936:8422e4f99a18 | 4937:3f9b9865c8cc |
---|---|
1394 | 1394 |
1395 std::unique_ptr<Json::Value> dicomAsJson; | 1395 std::unique_ptr<Json::Value> dicomAsJson; |
1396 | 1396 |
1397 bool hasOnlyMainDicomTags; | 1397 bool hasOnlyMainDicomTags; |
1398 DicomMap dicom; | 1398 DicomMap dicom; |
1399 DicomMap allMainDicomTagsFromDB; | |
1399 | 1400 |
1400 if (findStorageAccessMode_ == FindStorageAccessMode_DatabaseOnly || | 1401 if (findStorageAccessMode_ == FindStorageAccessMode_DatabaseOnly || |
1401 findStorageAccessMode_ == FindStorageAccessMode_DiskOnAnswer || | 1402 findStorageAccessMode_ == FindStorageAccessMode_DiskOnAnswer || |
1402 lookup.HasOnlyMainDicomTags()) | 1403 lookup.HasOnlyMainDicomTags()) |
1403 { | 1404 { |
1404 // Case (1): The main DICOM tags, as stored in the database, | 1405 // Case (1): The main DICOM tags, as stored in the database, |
1405 // are sufficient to look for match | 1406 // are sufficient to look for match |
1406 | 1407 |
1407 DicomMap tmp; | 1408 if (!GetIndex().GetAllMainDicomTags(allMainDicomTagsFromDB, instances[i])) // MORE_TAGS: TODO: we could read only the current and upper level to reduce the number of SQL queries |
1408 if (!GetIndex().GetAllMainDicomTags(tmp, instances[i])) | |
1409 { | 1409 { |
1410 // The instance has been removed during the execution of the | 1410 // The instance has been removed during the execution of the |
1411 // lookup, ignore it | 1411 // lookup, ignore it |
1412 continue; | 1412 continue; |
1413 } | 1413 } |
1416 // level of interest for the query | 1416 // level of interest for the query |
1417 switch (queryLevel) | 1417 switch (queryLevel) |
1418 { | 1418 { |
1419 // WARNING: Don't reorder cases below, and don't add "break" | 1419 // WARNING: Don't reorder cases below, and don't add "break" |
1420 case ResourceType_Instance: | 1420 case ResourceType_Instance: |
1421 dicom.MergeMainDicomTags(tmp, ResourceType_Instance); | 1421 dicom.MergeMainDicomTags(allMainDicomTagsFromDB, ResourceType_Instance); |
1422 | 1422 |
1423 case ResourceType_Series: | 1423 case ResourceType_Series: |
1424 dicom.MergeMainDicomTags(tmp, ResourceType_Series); | 1424 dicom.MergeMainDicomTags(allMainDicomTagsFromDB, ResourceType_Series); |
1425 | 1425 |
1426 case ResourceType_Study: | 1426 case ResourceType_Study: |
1427 dicom.MergeMainDicomTags(tmp, ResourceType_Study); | 1427 dicom.MergeMainDicomTags(allMainDicomTagsFromDB, ResourceType_Study); |
1428 | 1428 |
1429 case ResourceType_Patient: | 1429 case ResourceType_Patient: |
1430 dicom.MergeMainDicomTags(tmp, ResourceType_Patient); | 1430 dicom.MergeMainDicomTags(allMainDicomTagsFromDB, ResourceType_Patient); |
1431 break; | 1431 break; |
1432 | 1432 |
1433 default: | 1433 default: |
1434 throw OrthancException(ErrorCode_InternalError); | 1434 throw OrthancException(ErrorCode_InternalError); |
1435 } | 1435 } |
1474 } | 1474 } |
1475 | 1475 |
1476 if (hasOnlyMainDicomTags) | 1476 if (hasOnlyMainDicomTags) |
1477 { | 1477 { |
1478 // This is Case (1): The variable "dicom" only contains the main DICOM tags | 1478 // This is Case (1): The variable "dicom" only contains the main DICOM tags |
1479 visitor.Visit(resources[i], instances[i], dicom, dicomAsJson.get()); | 1479 visitor.Visit(resources[i], instances[i], allMainDicomTagsFromDB, dicomAsJson.get()); |
1480 } | 1480 } |
1481 else | 1481 else |
1482 { | 1482 { |
1483 // Remove the non-main DICOM tags from "dicom" if Case (2) | 1483 // Remove the non-main DICOM tags from "dicom" if Case (2) |
1484 // was used, for consistency with Case (1) | 1484 // was used, for consistency with Case (1) |
2260 const std::string& publicId, | 2260 const std::string& publicId, |
2261 ResourceType level, | 2261 ResourceType level, |
2262 DicomToJsonFormat format, | 2262 DicomToJsonFormat format, |
2263 const std::set<DicomTag>& requestedTags) | 2263 const std::set<DicomTag>& requestedTags) |
2264 { | 2264 { |
2265 std::string unusedInstanceId; | |
2266 Json::Value unusedValue; | |
2267 | |
2268 return ExpandResource(target, publicId, unusedInstanceId, unusedValue, level, format, requestedTags); | |
2269 } | |
2270 | |
2271 bool ServerContext::ExpandResource(Json::Value& target, | |
2272 const std::string& publicId, | |
2273 const std::string& instanceId, // optional: the id of an instance for the resource | |
2274 const Json::Value& dicomAsJson, // optional: the dicom-as-json for the resource | |
2275 ResourceType level, | |
2276 DicomToJsonFormat format, | |
2277 const std::set<DicomTag>& requestedTags) | |
2278 { | |
2265 ExpandedResource resource; | 2279 ExpandedResource resource; |
2266 | 2280 |
2267 if (GetIndex().ExpandResource(resource, publicId, level, format, requestedTags)) | 2281 if (GetIndex().ExpandResource(resource, publicId, level, format, requestedTags)) |
2268 { | 2282 { |
2269 // check the main dicom tags list has not changed since the resource was stored | 2283 // check the main dicom tags list has not changed since the resource was stored |
2270 | |
2271 if (resource.mainDicomTagsSignature_ != DicomMap::GetMainDicomTagsSignature(resource.type_)) | 2284 if (resource.mainDicomTagsSignature_ != DicomMap::GetMainDicomTagsSignature(resource.type_)) |
2272 { | 2285 { |
2273 OrthancConfiguration::ReaderLock lock; | 2286 OrthancConfiguration::ReaderLock lock; |
2274 if (lock.GetConfiguration().IsInconsistentDicomTagsLogsEnabled()) | 2287 if (lock.GetConfiguration().IsInconsistentDicomTagsLogsEnabled()) |
2275 { | 2288 { |
2276 LOG(WARNING) << Orthanc::GetResourceTypeText(resource.type_, false , false) << " has been stored with another version of Main Dicom Tags list, you should POST to /" << Orthanc::GetResourceTypeText(resource.type_, true, false) << "/" << resource.id_ << "/reconstruct to update the list of tags saved in DB. Some MainDicomTags might be missing from this answer."; | 2289 LOG(WARNING) << Orthanc::GetResourceTypeText(resource.type_, false , false) << " has been stored with another version of Main Dicom Tags list, you should POST to /" << Orthanc::GetResourceTypeText(resource.type_, true, false) << "/" << resource.id_ << "/reconstruct to update the list of tags saved in DB. Some MainDicomTags might be missing from this answer."; |
2277 } | 2290 } |
2278 } | 2291 } |
2279 | 2292 |
2280 // MORE_TAGS: TODO: possibly merge missing requested tags from /tags | 2293 // possibly merge missing requested tags from dicom-as-json |
2281 // log warning | 2294 if (!resource.missingRequestedTags_.empty()) |
2282 // use resource.missingRequestedTags_ | 2295 { |
2296 std::string instanceId_ = instanceId; | |
2297 Json::Value dicomAsJson_ = dicomAsJson; | |
2298 if (dicomAsJson_.isNull()) | |
2299 { | |
2300 if (instanceId_.empty()) | |
2301 { | |
2302 if (level == ResourceType_Instance) | |
2303 { | |
2304 instanceId_ = publicId; | |
2305 } | |
2306 else | |
2307 { | |
2308 std::list<std::string> instancesIds; | |
2309 GetIndex().GetChildInstances(instancesIds, publicId); | |
2310 if (instancesIds.size() < 1) | |
2311 { | |
2312 throw OrthancException(ErrorCode_InternalError, "ExpandResource: no instances found"); | |
2313 } | |
2314 instanceId_ = instancesIds.front(); | |
2315 } | |
2316 } | |
2317 | |
2318 // MORE_TAGS :TODO: log warning (add an option to disable them) | |
2319 ReadDicomAsJson(dicomAsJson_, instanceId_); | |
2320 } | |
2321 | |
2322 DicomMap allTags; | |
2323 allTags.FromDicomAsJson(dicomAsJson_); | |
2324 | |
2325 resource.tags_.Merge(allTags); | |
2326 } | |
2283 | 2327 |
2284 SerializeExpandedResource(target, resource, format, requestedTags); | 2328 SerializeExpandedResource(target, resource, format, requestedTags); |
2285 | 2329 |
2286 return true; | 2330 return true; |
2287 } | 2331 } |