comparison OrthancServer/ServerContext.cpp @ 2409:e4045b3c9772

ignore-length argument if retrieving DICOM tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 27 Sep 2017 17:36:13 +0200
parents 7284093111b0
children 878b59270859
comparison
equal deleted inserted replaced
2408:26a0cc24d48d 2409:e4045b3c9772
381 throw; 381 throw;
382 } 382 }
383 } 383 }
384 384
385 385
386 void ServerContext::ReadDicomAsJson(std::string& result, 386 void ServerContext::ReadDicomAsJsonInternal(std::string& result,
387 const std::string& instancePublicId) 387 const std::string& instancePublicId)
388 { 388 {
389 FileInfo attachment; 389 FileInfo attachment;
390 if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) 390 if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson))
391 { 391 {
392 ReadAttachment(result, attachment); 392 ReadAttachment(result, attachment);
393 return; 393 }
394 } 394 else
395 395 {
396 // The "DICOM as JSON" summary is not available from the Orthanc 396 // The "DICOM as JSON" summary is not available from the Orthanc
397 // store (most probably deleted), reconstruct it from the DICOM file 397 // store (most probably deleted), reconstruct it from the DICOM file
398 std::string dicom; 398 std::string dicom;
399 ReadDicom(dicom, instancePublicId); 399 ReadDicom(dicom, instancePublicId);
400 400
401 LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: " << instancePublicId; 401 LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: "
402 << instancePublicId;
402 403
403 ParsedDicomFile parsed(dicom); 404 ParsedDicomFile parsed(dicom);
404 405
405 Json::Value summary; 406 Json::Value summary;
406 parsed.DatasetToJson(summary); 407 parsed.DatasetToJson(summary);
407 408
408 result = summary.toStyledString(); 409 result = summary.toStyledString();
409 410
410 if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson, result.c_str(), result.size())) 411 if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson,
411 { 412 result.c_str(), result.size()))
412 LOG(WARNING) << "Cannot associate the DICOM-as-JSON summary to instance: " << instancePublicId; 413 {
413 throw OrthancException(ErrorCode_InternalError); 414 LOG(WARNING) << "Cannot associate the DICOM-as-JSON summary to instance: " << instancePublicId;
415 throw OrthancException(ErrorCode_InternalError);
416 }
417 }
418 }
419
420
421 void ServerContext::ReadDicomAsJson(std::string& result,
422 const std::string& instancePublicId,
423 const std::set<DicomTag>& ignoreTagLength)
424 {
425 if (ignoreTagLength.empty())
426 {
427 ReadDicomAsJsonInternal(result, instancePublicId);
428 }
429 else
430 {
431 Json::Value tmp;
432 ReadDicomAsJson(tmp, instancePublicId, ignoreTagLength);
433 result = tmp.toStyledString();
414 } 434 }
415 } 435 }
416 436
417 437
418 void ServerContext::ReadDicomAsJson(Json::Value& result, 438 void ServerContext::ReadDicomAsJson(Json::Value& result,
419 const std::string& instancePublicId) 439 const std::string& instancePublicId,
420 { 440 const std::set<DicomTag>& ignoreTagLength)
421 std::string tmp; 441 {
422 ReadDicomAsJson(tmp, instancePublicId); 442 if (ignoreTagLength.empty())
423 443 {
424 Json::Reader reader; 444 std::string tmp;
425 if (!reader.parse(tmp, result)) 445 ReadDicomAsJsonInternal(tmp, instancePublicId);
426 { 446
427 throw OrthancException(ErrorCode_CorruptedFile); 447 Json::Reader reader;
448 if (!reader.parse(tmp, result))
449 {
450 throw OrthancException(ErrorCode_CorruptedFile);
451 }
452 }
453 else
454 {
455 // The "DicomAsJson" attachment might have stored some tags as
456 // "too long". We are forced to re-parse the DICOM file.
457 std::string dicom;
458 ReadDicom(dicom, instancePublicId);
459
460 ParsedDicomFile parsed(dicom);
461 parsed.DatasetToJson(result, ignoreTagLength);
428 } 462 }
429 } 463 }
430 464
431 465
432 void ServerContext::ReadAttachment(std::string& result, 466 void ServerContext::ReadAttachment(std::string& result,