comparison OrthancServer/FromDcmtkBridge.cpp @ 788:7ebe4bf87196

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 May 2014 18:39:36 +0200
parents efd0215736d9
children 55dae8c5a6ab
comparison
equal deleted inserted replaced
787:ac18946afa74 788:7ebe4bf87196
782 } 782 }
783 783
784 784
785 void ParsedDicomFile::Replace(const DicomTag& tag, 785 void ParsedDicomFile::Replace(const DicomTag& tag,
786 const std::string& value, 786 const std::string& value,
787 DicomReplaceMode mode) 787 FromDcmtkBridge::ReplaceMode mode)
788 { 788 {
789 DcmTagKey key(tag.GetGroup(), tag.GetElement()); 789 DcmTagKey key(tag.GetGroup(), tag.GetElement());
790 DcmElement* element = NULL; 790 DcmElement* element = NULL;
791 791
792 if (!file_->getDataset()->findAndGetElement(key, element).good() || 792 if (!file_->getDataset()->findAndGetElement(key, element).good() ||
793 element == NULL) 793 element == NULL)
794 { 794 {
795 // This field does not exist, act wrt. the specified "mode" 795 // This field does not exist, act wrt. the specified "mode"
796 switch (mode) 796 switch (mode)
797 { 797 {
798 case DicomReplaceMode_InsertIfAbsent: 798 case FromDcmtkBridge::ReplaceMode_InsertIfAbsent:
799 Insert(tag, value); 799 Insert(tag, value);
800 break; 800 break;
801 801
802 case DicomReplaceMode_ThrowIfAbsent: 802 case FromDcmtkBridge::ReplaceMode_ThrowIfAbsent:
803 throw OrthancException(ErrorCode_InexistentItem); 803 throw OrthancException(ErrorCode_InexistentItem);
804 804
805 case DicomReplaceMode_IgnoreIfAbsent: 805 case FromDcmtkBridge::ReplaceMode_IgnoreIfAbsent:
806 return; 806 return;
807 } 807 }
808 } 808 }
809 else 809 else
810 { 810 {
818 * you make changes to the related tags in the dataset ('SOP Class 818 * you make changes to the related tags in the dataset ('SOP Class
819 * UID' and 'SOP Instance UID') via insert or modify mode 819 * UID' and 'SOP Instance UID') via insert or modify mode
820 * options. You can disable this behaviour by using the -nmu 820 * options. You can disable this behaviour by using the -nmu
821 * option. 821 * option.
822 **/ 822 **/
823
823 if (tag == DICOM_TAG_SOP_CLASS_UID) 824 if (tag == DICOM_TAG_SOP_CLASS_UID)
824 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, DicomReplaceMode_InsertIfAbsent); 825 {
826 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value,
827 FromDcmtkBridge::ReplaceMode_InsertIfAbsent);
828 }
825 829
826 if (tag == DICOM_TAG_SOP_INSTANCE_UID) 830 if (tag == DICOM_TAG_SOP_INSTANCE_UID)
827 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, DicomReplaceMode_InsertIfAbsent); 831 {
832 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value,
833 FromDcmtkBridge::ReplaceMode_InsertIfAbsent);
834 }
828 } 835 }
829 836
830 837
831 void ParsedDicomFile::Answer(RestApiOutput& output) 838 void ParsedDicomFile::Answer(RestApiOutput& output)
832 { 839 {
1651 result[GetName(it->first)] = it->second->AsString(); 1658 result[GetName(it->first)] = it->second->AsString();
1652 } 1659 }
1653 } 1660 }
1654 1661
1655 1662
1656 std::string FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel level) 1663 std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level)
1657 { 1664 {
1658 char uid[100]; 1665 char uid[100];
1659 1666
1660 switch (level) 1667 switch (level)
1661 { 1668 {
1662 case DicomRootLevel_Patient: 1669 case ResourceType_Patient:
1663 // The "PatientID" field is of type LO (Long String), 64 1670 // The "PatientID" field is of type LO (Long String), 64
1664 // Bytes Maximum. An UUID is of length 36, thus it can be used 1671 // Bytes Maximum. An UUID is of length 36, thus it can be used
1665 // as a random PatientID. 1672 // as a random PatientID.
1666 return Toolbox::GenerateUuid(); 1673 return Toolbox::GenerateUuid();
1667 1674
1668 case DicomRootLevel_Instance: 1675 case ResourceType_Instance:
1669 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT); 1676 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
1670 1677
1671 case DicomRootLevel_Series: 1678 case ResourceType_Series:
1672 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT); 1679 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT);
1673 1680
1674 case DicomRootLevel_Study: 1681 case ResourceType_Study:
1675 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT); 1682 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT);
1676 1683
1677 default: 1684 default:
1678 throw OrthancException(ErrorCode_ParameterOutOfRange); 1685 throw OrthancException(ErrorCode_ParameterOutOfRange);
1679 } 1686 }
1744 1751
1745 1752
1746 ParsedDicomFile::ParsedDicomFile() 1753 ParsedDicomFile::ParsedDicomFile()
1747 { 1754 {
1748 file_.reset(new DcmFileFormat); 1755 file_.reset(new DcmFileFormat);
1749 Replace(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient)); 1756 Replace(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient));
1750 Replace(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study)); 1757 Replace(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study));
1751 Replace(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series)); 1758 Replace(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series));
1752 Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance)); 1759 Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
1753 } 1760 }
1754 1761
1755 } 1762 }