Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 5044:6fed78e13233
Refactored DicomMap to handle sequences when needed
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 28 Jun 2022 17:45:09 +0200 |
parents | ec5c203a97ea |
children | 22966345eaba |
comparison
equal
deleted
inserted
replaced
5043:ec5c203a97ea | 5044:6fed78e13233 |
---|---|
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); // -> this includes only the leaf nodes | 529 dicom.GetSummary(summary); // -> from Orthanc 1.11.1, this includes the leaf nodes and sequences |
530 | 530 |
531 std::set<DicomTag> allMainDicomTags = DicomMap::GetAllMainDicomTags(); | 531 std::set<DicomTag> allMainDicomTags = DicomMap::GetAllMainDicomTags(); |
532 std::set<DicomTag> mainDicomSequences; | |
533 DicomMap::ExtractSequences(mainDicomSequences, allMainDicomTags); | |
534 DicomSequencesMap sequencesToStore; | |
535 | 532 |
536 try | 533 try |
537 { | 534 { |
538 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); | 535 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); |
539 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 536 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
540 | 537 |
541 DicomInstanceHasher hasher(summary); | 538 DicomInstanceHasher hasher(summary); |
542 resultPublicId = hasher.HashInstance(); | 539 resultPublicId = hasher.HashInstance(); |
543 | 540 |
544 Json::Value dicomAsJson; // -> this includes the sequences | 541 Json::Value dicomAsJson; |
545 | 542 dicom.GetDicomAsJson(dicomAsJson, allMainDicomTags); // don't crop any main dicom tags |
546 dicom.GetDicomAsJson(dicomAsJson, mainDicomSequences /*ignoreTagLength*/); // make sure that sequences that we wish to store in DB are not 'cropped' | |
547 sequencesToStore.FromDicomAsJson(dicomAsJson, mainDicomSequences); | |
548 | 543 |
549 Json::Value simplifiedTags; | 544 Json::Value simplifiedTags; |
550 Toolbox::SimplifyDicomAsJson(simplifiedTags, dicomAsJson, DicomToJsonFormat_Human); | 545 Toolbox::SimplifyDicomAsJson(simplifiedTags, dicomAsJson, DicomToJsonFormat_Human); |
551 | 546 |
552 // Test if the instance must be filtered out | 547 // Test if the instance must be filtered out |
621 } | 616 } |
622 | 617 |
623 typedef std::map<MetadataType, std::string> InstanceMetadata; | 618 typedef std::map<MetadataType, std::string> InstanceMetadata; |
624 InstanceMetadata instanceMetadata; | 619 InstanceMetadata instanceMetadata; |
625 result.SetStatus(index_.Store( | 620 result.SetStatus(index_.Store( |
626 instanceMetadata, summary, sequencesToStore, attachments, dicom.GetMetadata(), dicom.GetOrigin(), overwrite, | 621 instanceMetadata, summary, attachments, dicom.GetMetadata(), dicom.GetOrigin(), overwrite, |
627 hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset, isReconstruct)); | 622 hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset, isReconstruct)); |
628 | 623 |
629 // Only keep the metadata for the "instance" level | 624 // Only keep the metadata for the "instance" level |
630 dicom.ClearMetadata(); | 625 dicom.ClearMetadata(); |
631 | 626 |
1899 } | 1894 } |
1900 | 1895 |
1901 const std::string& ServerContext::GetDeidentifiedContent(const DicomElement &element) const | 1896 const std::string& ServerContext::GetDeidentifiedContent(const DicomElement &element) const |
1902 { | 1897 { |
1903 static const std::string redactedContent = "*** POTENTIAL PHI ***"; | 1898 static const std::string redactedContent = "*** POTENTIAL PHI ***"; |
1899 static const std::string emptyContent = ""; | |
1904 | 1900 |
1905 const DicomTag& tag = element.GetTag(); | 1901 const DicomTag& tag = element.GetTag(); |
1902 if (element.GetValue().IsSequence()) | |
1903 { | |
1904 return emptyContent; | |
1905 } | |
1906 | |
1906 if (deidentifyLogs_ && | 1907 if (deidentifyLogs_ && |
1907 !element.GetValue().GetContent().empty() && | 1908 !element.GetValue().GetContent().empty() && |
1908 logsDeidentifierRules_.IsAlteredTag(tag)) | 1909 logsDeidentifierRules_.IsAlteredTag(tag)) |
1909 { | 1910 { |
1910 return redactedContent; | 1911 return redactedContent; |
2081 resource.tags_.ExtractResourceInformation(mainDicomTags, resource.type_); | 2082 resource.tags_.ExtractResourceInformation(mainDicomTags, resource.type_); |
2082 | 2083 |
2083 target[MAIN_DICOM_TAGS] = Json::objectValue; | 2084 target[MAIN_DICOM_TAGS] = Json::objectValue; |
2084 FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], mainDicomTags, format); | 2085 FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], mainDicomTags, format); |
2085 | 2086 |
2086 {// add the main DICOM sequences to the main dicom tags | |
2087 const std::set<DicomTag>& mainDicomTags = DicomMap::GetMainDicomTags(resource.type_); | |
2088 std::set<DicomTag> mainDicomSequences; | |
2089 DicomMap::ExtractSequences(mainDicomSequences, mainDicomTags); | |
2090 resource.sequences_.ToJson(target[MAIN_DICOM_TAGS], format, mainDicomSequences); | |
2091 } | |
2092 | |
2093 if (resource.type_ == ResourceType_Study) | 2087 if (resource.type_ == ResourceType_Study) |
2094 { | 2088 { |
2095 DicomMap patientMainDicomTags; | 2089 DicomMap patientMainDicomTags; |
2096 resource.tags_.ExtractPatientInformation(patientMainDicomTags); | 2090 resource.tags_.ExtractPatientInformation(patientMainDicomTags); |
2097 | 2091 |
2106 DicomMap tags; | 2100 DicomMap tags; |
2107 resource.tags_.ExtractTags(tags, requestedTags); | 2101 resource.tags_.ExtractTags(tags, requestedTags); |
2108 | 2102 |
2109 target[REQUESTED_TAGS] = Json::objectValue; | 2103 target[REQUESTED_TAGS] = Json::objectValue; |
2110 FromDcmtkBridge::ToJson(target[REQUESTED_TAGS], tags, format); | 2104 FromDcmtkBridge::ToJson(target[REQUESTED_TAGS], tags, format); |
2111 | |
2112 {// add the requested sequences to the requested tags | |
2113 std::set<DicomTag> requestedDicomSequences; | |
2114 DicomMap::ExtractSequences(requestedDicomSequences, requestedTags); | |
2115 resource.sequences_.ToJson(target[REQUESTED_TAGS], format, requestedDicomSequences); | |
2116 } | |
2117 | 2105 |
2118 } | 2106 } |
2119 | 2107 |
2120 } | 2108 } |
2121 | 2109 |
2424 } | 2412 } |
2425 | 2413 |
2426 // possibly merge missing requested tags from dicom-as-json | 2414 // possibly merge missing requested tags from dicom-as-json |
2427 if (!resource.missingRequestedTags_.empty() && !DicomMap::HasOnlyComputedTags(resource.missingRequestedTags_)) | 2415 if (!resource.missingRequestedTags_.empty() && !DicomMap::HasOnlyComputedTags(resource.missingRequestedTags_)) |
2428 { | 2416 { |
2429 std::set<DicomTag> missingSequences; | |
2430 DicomMap::ExtractSequences(missingSequences, resource.missingRequestedTags_); | |
2431 | |
2432 OrthancConfiguration::ReaderLock lock; | 2417 OrthancConfiguration::ReaderLock lock; |
2433 if (lock.GetConfiguration().IsWarningEnabled(Warnings_001_TagsBeingReadFromStorage)) | 2418 if (lock.GetConfiguration().IsWarningEnabled(Warnings_001_TagsBeingReadFromStorage)) |
2434 { | 2419 { |
2435 std::set<DicomTag> missingTags; | 2420 std::set<DicomTag> missingTags; |
2436 Toolbox::AppendSets(missingTags, resource.missingRequestedTags_); | 2421 Toolbox::AppendSets(missingTags, resource.missingRequestedTags_); |
2472 } | 2457 } |
2473 } | 2458 } |
2474 | 2459 |
2475 Json::Value tmpDicomAsJson; | 2460 Json::Value tmpDicomAsJson; |
2476 ReadDicomAsJson(tmpDicomAsJson, instanceId_, resource.missingRequestedTags_ /* ignoreTagLength */); // read all tags from DICOM and avoid cropping requested tags | 2461 ReadDicomAsJson(tmpDicomAsJson, instanceId_, resource.missingRequestedTags_ /* ignoreTagLength */); // read all tags from DICOM and avoid cropping requested tags |
2477 tagsFromJson.FromDicomAsJson(tmpDicomAsJson); | 2462 tagsFromJson.FromDicomAsJson(tmpDicomAsJson, false /* append */, true /* parseSequences*/); |
2478 resource.sequences_.FromDicomAsJson(tmpDicomAsJson, missingSequences); | |
2479 } | 2463 } |
2480 else | 2464 else |
2481 { | 2465 { |
2482 tagsFromJson.FromDicomAsJson(*dicomAsJson); | 2466 tagsFromJson.FromDicomAsJson(*dicomAsJson, false /* append */, true /* parseSequences*/); |
2483 resource.sequences_.FromDicomAsJson(*dicomAsJson, missingSequences); | |
2484 } | 2467 } |
2485 | 2468 |
2486 resource.tags_.Merge(tagsFromJson); | 2469 resource.tags_.Merge(tagsFromJson); |
2487 } | 2470 } |
2488 | 2471 |