comparison OrthancServer/Sources/OrthancWebDav.cpp @ 4358:d6929f052ec4

ZIP archives containing DICOM files can be uploaded using WebDAV
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Dec 2020 15:22:28 +0100
parents 50b0c69b653a
children 79ef2b6d8e76
comparison
equal deleted inserted replaced
4357:886bc367aeb2 4358:d6929f052ec4
31 **/ 31 **/
32 32
33 33
34 #include "OrthancWebDav.h" 34 #include "OrthancWebDav.h"
35 35
36 #include "../../OrthancFramework/Sources/Compression/ZipReader.h"
36 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h" 37 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
37 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" 38 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
38 #include "../../OrthancFramework/Sources/HttpServer/WebDavStorage.h" 39 #include "../../OrthancFramework/Sources/HttpServer/WebDavStorage.h"
39 #include "../../OrthancFramework/Sources/Logging.h" 40 #include "../../OrthancFramework/Sources/Logging.h"
40 #include "Search/DatabaseLookup.h" 41 #include "Search/DatabaseLookup.h"
1264 MimeType mime; 1265 MimeType mime;
1265 std::string content; 1266 std::string content;
1266 boost::posix_time::ptime time; 1267 boost::posix_time::ptime time;
1267 if (uploads_.GetFileContent(mime, content, time, uri)) 1268 if (uploads_.GetFileContent(mime, content, time, uri))
1268 { 1269 {
1269 DicomInstanceToStore instance;
1270 instance.SetOrigin(DicomInstanceOrigin::FromWebDav());
1271 instance.SetBuffer(content.c_str(), content.size());
1272
1273 bool success = false; 1270 bool success = false;
1274 1271
1275 try 1272 if (ZipReader::IsZipMemoryBuffer(content))
1276 { 1273 {
1277 std::string publicId; 1274 // New in Orthanc 1.9.0
1278 StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default); 1275 std::unique_ptr<ZipReader> reader(ZipReader::CreateFromMemory(content));
1279 if (status == StoreStatus_Success || 1276
1280 status == StoreStatus_AlreadyStored) 1277 std::string filename, content;
1281 { 1278 while (reader->ReadNextFile(filename, content))
1282 LOG(INFO) << "Successfully imported DICOM instance from WebDAV: " 1279 {
1283 << path << " (Orthanc ID: " << publicId << ")"; 1280 if (!content.empty())
1284 success = true; 1281 {
1285 } 1282 LOG(INFO) << "Uploading DICOM file extracted from a ZIP archive in WebDAV: " << filename;
1286 } 1283
1287 catch (OrthancException& e) 1284 DicomInstanceToStore instance;
1288 { 1285 instance.SetOrigin(DicomInstanceOrigin::FromWebDav());
1286 instance.SetBuffer(content.c_str(), content.size());
1287
1288 std::string publicId;
1289
1290 try
1291 {
1292 context_.Store(publicId, instance, StoreInstanceMode_Default);
1293 }
1294 catch (OrthancException& e)
1295 {
1296 if (e.GetErrorCode() == ErrorCode_BadFileFormat)
1297 {
1298 LOG(ERROR) << "Cannot import non-DICOM file from ZIP archive: " << filename;
1299 }
1300 }
1301 }
1302 }
1303
1304 success = true;
1305 }
1306 else
1307 {
1308 DicomInstanceToStore instance;
1309 instance.SetOrigin(DicomInstanceOrigin::FromWebDav());
1310 instance.SetBuffer(content.c_str(), content.size());
1311
1312 try
1313 {
1314 std::string publicId;
1315 StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default);
1316 if (status == StoreStatus_Success ||
1317 status == StoreStatus_AlreadyStored)
1318 {
1319 LOG(INFO) << "Successfully imported DICOM instance from WebDAV: "
1320 << path << " (Orthanc ID: " << publicId << ")";
1321 success = true;
1322 }
1323 }
1324 catch (OrthancException& e)
1325 {
1326 }
1289 } 1327 }
1290 1328
1291 uploads_.DeleteItem(uri); 1329 uploads_.DeleteItem(uri);
1292 1330
1293 if (!success) 1331 if (!success)