comparison OrthancServer/Sources/ServerContext.cpp @ 5299:c9ea57d73603 am-experimental

New URI /instances/{id}/file-until-pixel-data
author Alain Mazy <am@osimis.io>
date Tue, 23 May 2023 17:38:26 +0200
parents c04230962098
children f26ed26a7793
comparison
equal deleted inserted replaced
5287:c04230962098 5299:c9ea57d73603
1127 } 1127 }
1128 1128
1129 void ServerContext::ReadDicomForHeader(std::string& dicom, 1129 void ServerContext::ReadDicomForHeader(std::string& dicom,
1130 const std::string& instancePublicId) 1130 const std::string& instancePublicId)
1131 { 1131 {
1132 if (!ReadDicomUntilPixelData(dicom, instancePublicId)) 1132 ReadDicomUntilPixelData(dicom, instancePublicId);
1133 {
1134 ReadDicom(dicom, instancePublicId);
1135 }
1136 } 1133 }
1137 1134
1138 bool ServerContext::ReadDicomUntilPixelData(std::string& dicom, 1135 bool ServerContext::ReadDicomUntilPixelData(std::string& dicom,
1139 const std::string& instancePublicId) 1136 const std::string& instancePublicId)
1140 { 1137 {
1141 if (!area_.HasReadRange())
1142 {
1143 return false;
1144 }
1145
1146 FileInfo attachment; 1138 FileInfo attachment;
1147 int64_t revision; // Ignored 1139 int64_t revision; // Ignored
1140
1141 // if the attachment exists as such return it directly
1142 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData))
1143 {
1144 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
1145 accessor.Read(dicom, attachment);
1146 return true;
1147 }
1148
1149 // if the storage area can not read part of files, return the whole file
1150 if (!area_.HasReadRange())
1151 {
1152 ReadDicom(dicom, instancePublicId);
1153 return true;
1154 }
1155
1156 // else, read the start of the dicom file
1157
1148 if (!index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_Dicom)) 1158 if (!index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_Dicom))
1149 { 1159 {
1150 throw OrthancException(ErrorCode_InternalError, 1160 throw OrthancException(ErrorCode_InternalError,
1151 "Unable to read the DICOM file of instance " + instancePublicId); 1161 "Unable to read the DICOM file of instance " + instancePublicId);
1162 }
1163
1164 // if the attachment is compressed, return the whole file
1165 if (attachment.GetCompressionType() != CompressionType_None)
1166 {
1167 ReadDicom(dicom, instancePublicId);
1168 return true;
1152 } 1169 }
1153 1170
1154 std::string s; 1171 std::string s;
1155 1172 if (index_.LookupMetadata(s, revision, instancePublicId, ResourceType_Instance,
1156 if (attachment.GetCompressionType() == CompressionType_None &&
1157 index_.LookupMetadata(s, revision, instancePublicId, ResourceType_Instance,
1158 MetadataType_Instance_PixelDataOffset) && 1173 MetadataType_Instance_PixelDataOffset) &&
1159 !s.empty()) 1174 !s.empty())
1160 { 1175 {
1161 try 1176 try
1162 { 1177 {
1173 { 1188 {
1174 LOG(ERROR) << "Metadata \"PixelDataOffset\" is corrupted for instance: " << instancePublicId; 1189 LOG(ERROR) << "Metadata \"PixelDataOffset\" is corrupted for instance: " << instancePublicId;
1175 } 1190 }
1176 } 1191 }
1177 1192
1178 return false; 1193 ReadDicom(dicom, instancePublicId);
1194 return true;
1179 } 1195 }
1180 1196
1181 1197
1182 void ServerContext::ReadAttachment(std::string& result, 1198 void ServerContext::ReadAttachment(std::string& result,
1183 int64_t& revision, 1199 int64_t& revision,