Mercurial > hg > orthanc-dicomweb
changeset 594:68aa83ffa290
fix studies/metadata
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 21 Aug 2023 16:33:27 +0200 |
parents | 0c3bc2ea0756 |
children | f9d029c56ba4 |
files | Plugin/DicomWebFormatter.cpp Plugin/DicomWebFormatter.h Plugin/WadoRs.cpp |
diffstat | 3 files changed, 49 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugin/DicomWebFormatter.cpp Mon Aug 21 15:16:23 2023 +0200 +++ b/Plugin/DicomWebFormatter.cpp Mon Aug 21 16:33:27 2023 +0200 @@ -289,8 +289,8 @@ } - void DicomWebFormatter::HttpWriter::AddDicomWebSerializedJson(const void* data, - size_t size) + void DicomWebFormatter::HttpWriter::AddDicomWebInstanceSerializedJson(const void* data, + size_t size) { if (isXml_) { @@ -318,6 +318,41 @@ jsonBuffer_.AddChunk(data, size); } + void DicomWebFormatter::HttpWriter::AddDicomWebSeriesSerializedJson(const void* data, + size_t size) + { + if (isXml_) + { + // This function can only be used in the JSON case + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + +#if !defined(NDEBUG) // In debug mode, check that the value is actually a JSON string + Json::Value json; + if (!OrthancPlugins::ReadJson(json, data, size)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); + } +#endif + + if (size <= 2 || + reinterpret_cast<const char*>(data)[0] != '[' || + reinterpret_cast<const char*>(data)[size-1] != ']') + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "The series metadata json does not contain an array."); + } + + if (first_) + { + first_ = false; + } + else + { + jsonBuffer_.AddChunk(","); + } + + jsonBuffer_.AddChunk(reinterpret_cast<const char*>(data) + 1, size - 2); // remove leading and trailing [] + } void DicomWebFormatter::HttpWriter::Send() {
--- a/Plugin/DicomWebFormatter.h Mon Aug 21 15:16:23 2023 +0200 +++ b/Plugin/DicomWebFormatter.h Mon Aug 21 16:33:27 2023 +0200 @@ -115,8 +115,11 @@ void AddOrthancJson(const Json::Value& value); - void AddDicomWebSerializedJson(const void* data, - size_t size); + void AddDicomWebInstanceSerializedJson(const void* data, + size_t size); + + void AddDicomWebSeriesSerializedJson(const void* data, + size_t size); void Send();
--- a/Plugin/WadoRs.cpp Mon Aug 21 15:16:23 2023 +0200 +++ b/Plugin/WadoRs.cpp Mon Aug 21 16:33:27 2023 +0200 @@ -882,7 +882,7 @@ { if (buffer.RestApiGet("/instances/" + orthancId + "/attachments/4444/data", false)) { - writer.AddDicomWebSerializedJson(buffer.GetData(), buffer.GetSize()); + writer.AddDicomWebInstanceSerializedJson(buffer.GetData(), buffer.GetSize()); } else if (buffer.RestApiGet("/instances/" + orthancId + "/file", false)) { @@ -898,7 +898,7 @@ } buffer.RestApiPut("/instances/" + orthancId + "/attachments/4444", dicomweb, false); - writer.AddDicomWebSerializedJson(dicomweb.c_str(), dicomweb.size()); + writer.AddDicomWebInstanceSerializedJson(dicomweb.c_str(), dicomweb.size()); } } #endif @@ -1449,7 +1449,10 @@ if (!OrthancPlugins::RestApiGetString(compressedSeriesMetadata, attachmentUrl + "/data", false)) { - CacheSeriesMetadataInternal(serializedSeriesMetadata, writer, cache, studyInstanceUid, seriesInstanceUid, seriesOrthancId); + MainDicomTagsCache tmpCache; + OrthancPlugins::DicomWebFormatter::HttpWriter tmpWriter(NULL /* output */, false /* isXml */); // we cache only the JSON format -> no need for an HttpOutput + + CacheSeriesMetadataInternal(serializedSeriesMetadata, tmpWriter, tmpCache, studyInstanceUid, seriesInstanceUid, seriesOrthancId); } else { @@ -1458,7 +1461,7 @@ boost::replace_all(serializedSeriesMetadata, WADO_BASE_PLACEHOLDER, wadoBase); - writer.AddDicomWebSerializedJson(serializedSeriesMetadata.c_str(), serializedSeriesMetadata.size()); + writer.AddDicomWebSeriesSerializedJson(serializedSeriesMetadata.c_str(), serializedSeriesMetadata.size()); } else {