Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi.cpp @ 648:bcf5c9a767a9
use filenames with 8 characters in ZIP files for maximum compatibility
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Oct 2013 09:34:21 +0100 |
parents | fb49bf72ac2d |
children | 3a74026fc1b1 |
comparison
equal
deleted
inserted
replaced
647:a9ea5e311ec5 | 648:bcf5c9a767a9 |
---|---|
529 return true; | 529 return true; |
530 } | 530 } |
531 | 531 |
532 static bool ArchiveInstance(HierarchicalZipWriter& writer, | 532 static bool ArchiveInstance(HierarchicalZipWriter& writer, |
533 ServerContext& context, | 533 ServerContext& context, |
534 const std::string& instancePublicId) | 534 const std::string& instancePublicId, |
535 const char* filename) | |
535 { | 536 { |
536 Json::Value instance; | 537 Json::Value instance; |
537 if (!context.GetIndex().LookupResource(instance, instancePublicId, ResourceType_Instance)) | 538 if (!context.GetIndex().LookupResource(instance, instancePublicId, ResourceType_Instance)) |
538 { | 539 { |
539 return false; | 540 return false; |
540 } | 541 } |
541 | 542 |
542 std::string filename = instance["MainDicomTags"]["SOPInstanceUID"].asString() + ".dcm"; | 543 writer.OpenFile(filename); |
543 writer.OpenFile(filename.c_str()); | |
544 | 544 |
545 std::string dicom; | 545 std::string dicom; |
546 context.ReadFile(dicom, instancePublicId, FileContentType_Dicom); | 546 context.ReadFile(dicom, instancePublicId, FileContentType_Dicom); |
547 writer.Write(dicom); | 547 writer.Write(dicom); |
548 | 548 |
592 } | 592 } |
593 } | 593 } |
594 break; | 594 break; |
595 | 595 |
596 case ResourceType_Series: | 596 case ResourceType_Series: |
597 { | |
598 // Create a filename prefix, depending on the modality | |
599 char format[16] = "%08d"; | |
600 | |
601 if (resource["MainDicomTags"].isMember("Modality")) | |
602 { | |
603 std::string modality = resource["MainDicomTags"]["Modality"].asString(); | |
604 | |
605 if (modality.size() == 1) | |
606 { | |
607 snprintf(format, sizeof(format) - 1, "%c%%07d", toupper(modality[0])); | |
608 } | |
609 else if (modality.size() >= 2) | |
610 { | |
611 snprintf(format, sizeof(format) - 1, "%c%c%%06d", toupper(modality[0]), toupper(modality[1])); | |
612 } | |
613 } | |
614 | |
615 char filename[16]; | |
616 | |
597 for (Json::Value::ArrayIndex i = 0; i < resource["Instances"].size(); i++) | 617 for (Json::Value::ArrayIndex i = 0; i < resource["Instances"].size(); i++) |
598 { | 618 { |
599 if (!ArchiveInstance(writer, context, resource["Instances"][i].asString())) | 619 snprintf(filename, sizeof(filename) - 1, format, i); |
620 | |
621 std::string publicId = resource["Instances"][i].asString(); | |
622 | |
623 // This was the implementation up to Orthanc 0.7.0: | |
624 // std::string filename = instance["MainDicomTags"]["SOPInstanceUID"].asString() + ".dcm"; | |
625 | |
626 if (!ArchiveInstance(writer, context, publicId, filename)) | |
600 { | 627 { |
601 return false; | 628 return false; |
602 } | 629 } |
603 } | 630 } |
631 | |
604 break; | 632 break; |
633 } | |
605 | 634 |
606 default: | 635 default: |
607 throw OrthancException(ErrorCode_InternalError); | 636 throw OrthancException(ErrorCode_InternalError); |
608 } | 637 } |
609 | 638 |