Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 4511:1ec156a0da38
ServerContext::ReadDicomUntilPixelData()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 11 Feb 2021 19:06:29 +0100 |
parents | 98b7b9d21d83 |
children | 1f455b86b054 |
comparison
equal
deleted
inserted
replaced
4510:a3635a01a945 | 4511:1ec156a0da38 |
---|---|
582 | 582 |
583 ServerIndex::Attachments attachments; | 583 ServerIndex::Attachments attachments; |
584 attachments.push_back(dicomInfo); | 584 attachments.push_back(dicomInfo); |
585 | 585 |
586 FileInfo jsonInfo; | 586 FileInfo jsonInfo; |
587 if (true /* TODO - !area_.HasReadRange() || !hasPixelDataOffset */) | 587 if (true /* TODO - !area_.HasReadRange() || !hasPixelDataOffset || compression != CompressionType_DicomAsJson */) |
588 { | 588 { |
589 jsonInfo = accessor.Write(dicomAsJson.toStyledString(), | 589 jsonInfo = accessor.Write(dicomAsJson.toStyledString(), |
590 FileContentType_DicomAsJson, compression, storeMD5_); | 590 FileContentType_DicomAsJson, compression, storeMD5_); |
591 attachments.push_back(jsonInfo); | 591 attachments.push_back(jsonInfo); |
592 } | 592 } |
805 throw; | 805 throw; |
806 } | 806 } |
807 } | 807 } |
808 | 808 |
809 | 809 |
810 void ServerContext::ReadDicomAsJsonInternal(std::string& result, | 810 void ServerContext::ReadDicomAsJson(std::string& result, |
811 const std::string& instancePublicId) | 811 const std::string& instancePublicId) |
812 { | 812 { |
813 FileInfo attachment; | 813 FileInfo attachment; |
814 if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) | 814 if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) |
815 { | 815 { |
816 StorageAccessor accessor(area_, GetMetricsRegistry()); | 816 StorageAccessor accessor(area_, GetMetricsRegistry()); |
841 } | 841 } |
842 } | 842 } |
843 } | 843 } |
844 | 844 |
845 | 845 |
846 void ServerContext::ReadDicomAsJson(std::string& result, | |
847 const std::string& instancePublicId, | |
848 const std::set<DicomTag>& ignoreTagLength) | |
849 { | |
850 if (ignoreTagLength.empty()) | |
851 { | |
852 ReadDicomAsJsonInternal(result, instancePublicId); | |
853 } | |
854 else | |
855 { | |
856 Json::Value tmp; | |
857 ReadDicomAsJson(tmp, instancePublicId, ignoreTagLength); | |
858 result = tmp.toStyledString(); | |
859 } | |
860 } | |
861 | |
862 | |
863 void ServerContext::ReadDicomAsJson(Json::Value& result, | 846 void ServerContext::ReadDicomAsJson(Json::Value& result, |
864 const std::string& instancePublicId, | 847 const std::string& instancePublicId, |
865 const std::set<DicomTag>& ignoreTagLength) | 848 const std::set<DicomTag>& ignoreTagLength) |
866 { | 849 { |
867 if (ignoreTagLength.empty()) | 850 if (ignoreTagLength.empty()) |
868 { | 851 { |
869 std::string tmp; | 852 std::string tmp; |
870 ReadDicomAsJsonInternal(tmp, instancePublicId); | 853 ReadDicomAsJson(tmp, instancePublicId); |
871 | 854 |
872 if (!Toolbox::ReadJson(result, tmp)) | 855 if (!Toolbox::ReadJson(result, tmp)) |
873 { | 856 { |
874 throw OrthancException(ErrorCode_CorruptedFile); | 857 throw OrthancException(ErrorCode_CorruptedFile); |
875 } | 858 } |
885 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength); | 868 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength); |
886 } | 869 } |
887 } | 870 } |
888 | 871 |
889 | 872 |
873 void ServerContext::ReadDicomAsJson(Json::Value& result, | |
874 const std::string& instancePublicId) | |
875 { | |
876 std::set<DicomTag> ignoreTagLength; | |
877 ReadDicomAsJson(result, instancePublicId, ignoreTagLength); | |
878 } | |
879 | |
880 | |
890 void ServerContext::ReadDicom(std::string& dicom, | 881 void ServerContext::ReadDicom(std::string& dicom, |
891 const std::string& instancePublicId) | 882 const std::string& instancePublicId) |
892 { | 883 { |
893 ReadAttachment(dicom, instancePublicId, FileContentType_Dicom, true /* uncompress */); | 884 ReadAttachment(dicom, instancePublicId, FileContentType_Dicom, true /* uncompress */); |
894 } | 885 } |
895 | 886 |
887 | |
888 bool ServerContext::ReadDicomUntilPixelData(std::string& dicom, | |
889 const std::string& instancePublicId) | |
890 { | |
891 if (!area_.HasReadRange()) | |
892 { | |
893 return false; | |
894 } | |
895 | |
896 FileInfo attachment; | |
897 if (!index_.LookupAttachment(attachment, instancePublicId, FileContentType_Dicom)) | |
898 { | |
899 throw OrthancException(ErrorCode_InternalError, | |
900 "Unable to read the DICOM file of instance " + instancePublicId); | |
901 } | |
902 | |
903 std::string s; | |
904 | |
905 if (attachment.GetCompressionType() == CompressionType_None && | |
906 index_.LookupMetadata(s, instancePublicId, ResourceType_Instance, | |
907 MetadataType_Instance_PixelDataOffset) && | |
908 !s.empty()) | |
909 { | |
910 try | |
911 { | |
912 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s); | |
913 | |
914 std::unique_ptr<IMemoryBuffer> buffer( | |
915 area_.ReadRange(attachment.GetUuid(), attachment.GetContentType(), 0, pixelDataOffset)); | |
916 buffer->MoveToString(dicom); | |
917 return true; // Success | |
918 } | |
919 catch (boost::bad_lexical_cast&) | |
920 { | |
921 LOG(ERROR) << "Metadata \"PixelDataOffset\" is corrupted for instance: " << instancePublicId; | |
922 } | |
923 } | |
924 | |
925 return false; | |
926 } | |
927 | |
896 | 928 |
897 void ServerContext::ReadAttachment(std::string& result, | 929 void ServerContext::ReadAttachment(std::string& result, |
898 const std::string& instancePublicId, | 930 const std::string& instancePublicId, |
899 FileContentType content, | 931 FileContentType content, |
900 bool uncompressIfNeeded) | 932 bool uncompressIfNeeded) |