Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 4513:1f455b86b054
simplification in ServerContext
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Feb 2021 12:13:19 +0100 |
parents | 1ec156a0da38 |
children | 5b929e6b3c36 |
comparison
equal
deleted
inserted
replaced
4512:cff7fdfc83a4 | 4513:1f455b86b054 |
---|---|
805 throw; | 805 throw; |
806 } | 806 } |
807 } | 807 } |
808 | 808 |
809 | 809 |
810 void ServerContext::ReadDicomAsJson(std::string& result, | |
811 const std::string& instancePublicId) | |
812 { | |
813 FileInfo attachment; | |
814 if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) | |
815 { | |
816 StorageAccessor accessor(area_, GetMetricsRegistry()); | |
817 accessor.Read(result, attachment); | |
818 } | |
819 else | |
820 { | |
821 // The "DICOM as JSON" summary is not available from the Orthanc | |
822 // store (most probably deleted), reconstruct it from the DICOM file | |
823 std::string dicom; | |
824 ReadDicom(dicom, instancePublicId); | |
825 | |
826 LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: " | |
827 << instancePublicId; | |
828 | |
829 ParsedDicomFile parsed(dicom); | |
830 | |
831 Json::Value summary; | |
832 OrthancConfiguration::DefaultDicomDatasetToJson(summary, parsed); | |
833 | |
834 result = summary.toStyledString(); | |
835 | |
836 if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson, | |
837 result.c_str(), result.size())) | |
838 { | |
839 throw OrthancException(ErrorCode_InternalError, | |
840 "Cannot associate the DICOM-as-JSON summary to instance: " + instancePublicId); | |
841 } | |
842 } | |
843 } | |
844 | |
845 | |
846 void ServerContext::ReadDicomAsJson(Json::Value& result, | 810 void ServerContext::ReadDicomAsJson(Json::Value& result, |
847 const std::string& instancePublicId, | 811 const std::string& instancePublicId, |
848 const std::set<DicomTag>& ignoreTagLength) | 812 const std::set<DicomTag>& ignoreTagLength) |
849 { | 813 { |
850 if (ignoreTagLength.empty()) | 814 if (ignoreTagLength.empty()) |
851 { | 815 { |
852 std::string tmp; | 816 std::string tmp; |
853 ReadDicomAsJson(tmp, instancePublicId); | 817 |
818 { | |
819 FileInfo attachment; | |
820 if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) | |
821 { | |
822 StorageAccessor accessor(area_, GetMetricsRegistry()); | |
823 accessor.Read(tmp, attachment); | |
824 } | |
825 else | |
826 { | |
827 // The "DICOM as JSON" summary is not available from the Orthanc | |
828 // store (most probably deleted), reconstruct it from the DICOM file | |
829 std::string dicom; | |
830 ReadDicom(dicom, instancePublicId); | |
831 | |
832 LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: " | |
833 << instancePublicId; | |
834 | |
835 ParsedDicomFile parsed(dicom); | |
836 | |
837 Json::Value summary; | |
838 OrthancConfiguration::DefaultDicomDatasetToJson(summary, parsed); | |
839 | |
840 tmp = summary.toStyledString(); | |
841 | |
842 if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson, | |
843 tmp.c_str(), tmp.size())) | |
844 { | |
845 throw OrthancException(ErrorCode_InternalError, | |
846 "Cannot associate the DICOM-as-JSON summary to instance: " + instancePublicId); | |
847 } | |
848 } | |
849 } | |
854 | 850 |
855 if (!Toolbox::ReadJson(result, tmp)) | 851 if (!Toolbox::ReadJson(result, tmp)) |
856 { | 852 { |
857 throw OrthancException(ErrorCode_CorruptedFile); | 853 throw OrthancException(ErrorCode_CorruptedFile); |
858 } | 854 } |