comparison OrthancServer/Sources/ServerContext.cpp @ 5036:877bc3b96476

Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
author Alain Mazy <am@osimis.io>
date Fri, 24 Jun 2022 15:47:10 +0200
parents 2f30aa99c2db
children 28db9663fc2d
comparison
equal deleted inserted replaced
5035:67d98fccc850 5036:877bc3b96476
524 524
525 DicomTransferSyntax transferSyntax; 525 DicomTransferSyntax transferSyntax;
526 bool hasTransferSyntax = dicom.LookupTransferSyntax(transferSyntax); 526 bool hasTransferSyntax = dicom.LookupTransferSyntax(transferSyntax);
527 527
528 DicomMap summary; 528 DicomMap summary;
529 dicom.GetSummary(summary); 529 dicom.GetSummary(summary); // -> this includes only the leaf nodes
530
531 std::set<DicomTag> allMainDicomTags = DicomMap::GetAllMainDicomTags();
532 std::set<DicomTag> mainDicomSequences;
533 DicomMap::ExtractSequences(mainDicomSequences, allMainDicomTags);
534 std::map<DicomTag, Json::Value> sequencesToStore;
530 535
531 try 536 try
532 { 537 {
533 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); 538 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms");
534 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); 539 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
535 540
536 DicomInstanceHasher hasher(summary); 541 DicomInstanceHasher hasher(summary);
537 resultPublicId = hasher.HashInstance(); 542 resultPublicId = hasher.HashInstance();
538 543
539 Json::Value dicomAsJson; 544 Json::Value dicomAsJson; // -> this includes the sequences
540 dicom.GetDicomAsJson(dicomAsJson); 545
546 dicom.GetDicomAsJson(dicomAsJson, mainDicomSequences /*ignoreTagLength*/); // make sure that sequences that we wish to store in DB are not 'cropped'
541 547
548 for (std::set<DicomTag>::const_iterator it = mainDicomSequences.begin();
549 it != mainDicomSequences.end(); ++it)
550 {
551 if (dicomAsJson.isMember(it->Format()))
552 {
553 sequencesToStore[*it] = dicomAsJson[it->Format()];
554 }
555 }
556
542 Json::Value simplifiedTags; 557 Json::Value simplifiedTags;
543 Toolbox::SimplifyDicomAsJson(simplifiedTags, dicomAsJson, DicomToJsonFormat_Human); 558 Toolbox::SimplifyDicomAsJson(simplifiedTags, dicomAsJson, DicomToJsonFormat_Human);
544 559
545 // Test if the instance must be filtered out 560 // Test if the instance must be filtered out
546 StoreResult result; 561 StoreResult result;
614 } 629 }
615 630
616 typedef std::map<MetadataType, std::string> InstanceMetadata; 631 typedef std::map<MetadataType, std::string> InstanceMetadata;
617 InstanceMetadata instanceMetadata; 632 InstanceMetadata instanceMetadata;
618 result.SetStatus(index_.Store( 633 result.SetStatus(index_.Store(
619 instanceMetadata, summary, attachments, dicom.GetMetadata(), dicom.GetOrigin(), overwrite, 634 instanceMetadata, summary, sequencesToStore, attachments, dicom.GetMetadata(), dicom.GetOrigin(), overwrite,
620 hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset, isReconstruct)); 635 hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset, isReconstruct));
621 636
622 // Only keep the metadata for the "instance" level 637 // Only keep the metadata for the "instance" level
623 dicom.ClearMetadata(); 638 dicom.ClearMetadata();
624 639
2092 DicomMap tags; 2107 DicomMap tags;
2093 resource.tags_.ExtractTags(tags, requestedTags); 2108 resource.tags_.ExtractTags(tags, requestedTags);
2094 2109
2095 target[REQUESTED_TAGS] = Json::objectValue; 2110 target[REQUESTED_TAGS] = Json::objectValue;
2096 FromDcmtkBridge::ToJson(target[REQUESTED_TAGS], tags, format); 2111 FromDcmtkBridge::ToJson(target[REQUESTED_TAGS], tags, format);
2112
2113 // add the sequences to the requested tags
2114 resource.sequences_.ToJson(target[REQUESTED_TAGS], format);
2097 } 2115 }
2098 2116
2099 } 2117 }
2100 2118
2101 2119
2403 } 2421 }
2404 2422
2405 // possibly merge missing requested tags from dicom-as-json 2423 // possibly merge missing requested tags from dicom-as-json
2406 if (!resource.missingRequestedTags_.empty() && !DicomMap::HasOnlyComputedTags(resource.missingRequestedTags_)) 2424 if (!resource.missingRequestedTags_.empty() && !DicomMap::HasOnlyComputedTags(resource.missingRequestedTags_))
2407 { 2425 {
2426 std::set<DicomTag> missingSequences;
2427 DicomMap::ExtractSequences(missingSequences, resource.missingRequestedTags_);
2428
2408 OrthancConfiguration::ReaderLock lock; 2429 OrthancConfiguration::ReaderLock lock;
2409 if (lock.GetConfiguration().IsWarningEnabled(Warnings_001_TagsBeingReadFromStorage)) 2430 if (lock.GetConfiguration().IsWarningEnabled(Warnings_001_TagsBeingReadFromStorage))
2410 { 2431 {
2411 std::set<DicomTag> missingTags; 2432 std::set<DicomTag> missingTags;
2412 Toolbox::AppendSets(missingTags, resource.missingRequestedTags_); 2433 Toolbox::AppendSets(missingTags, resource.missingRequestedTags_);
2447 instanceId_ = instancesIds.front(); 2468 instanceId_ = instancesIds.front();
2448 } 2469 }
2449 } 2470 }
2450 2471
2451 Json::Value tmpDicomAsJson; 2472 Json::Value tmpDicomAsJson;
2452 ReadDicomAsJson(tmpDicomAsJson, instanceId_); 2473 ReadDicomAsJson(tmpDicomAsJson, instanceId_, resource.missingRequestedTags_ /* ignoreTagLength */); // read all tags from DICOM and avoid cropping requested tags
2453 tagsFromJson.FromDicomAsJson(tmpDicomAsJson); 2474 tagsFromJson.FromDicomAsJson(tmpDicomAsJson);
2475 resource.sequences_.FromDicomAsJson(tmpDicomAsJson, missingSequences);
2454 } 2476 }
2455 else 2477 else
2456 { 2478 {
2457 tagsFromJson.FromDicomAsJson(*dicomAsJson); 2479 tagsFromJson.FromDicomAsJson(*dicomAsJson);
2480 resource.sequences_.FromDicomAsJson(*dicomAsJson, missingSequences);
2458 } 2481 }
2459 2482
2460 resource.tags_.Merge(tagsFromJson); 2483 resource.tags_.Merge(tagsFromJson);
2461 } 2484 }
2462 2485