comparison Core/DicomFormat/DicomInstanceHasher.cpp @ 179:78e28d0098d9

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Nov 2012 11:30:16 +0100
parents 5739b4d10a4b
children fc856d175d18
comparison
equal deleted inserted replaced
178:5739b4d10a4b 179:78e28d0098d9
37 namespace Orthanc 37 namespace Orthanc
38 { 38 {
39 DicomInstanceHasher::DicomInstanceHasher(const DicomMap& instance) 39 DicomInstanceHasher::DicomInstanceHasher(const DicomMap& instance)
40 { 40 {
41 patientId_ = instance.GetValue(DICOM_TAG_PATIENT_ID).AsString(); 41 patientId_ = instance.GetValue(DICOM_TAG_PATIENT_ID).AsString();
42 studyUid_ = instance.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString();
43 seriesUid_ = instance.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString();
42 instanceUid_ = instance.GetValue(DICOM_TAG_SOP_INSTANCE_UID).AsString(); 44 instanceUid_ = instance.GetValue(DICOM_TAG_SOP_INSTANCE_UID).AsString();
43 seriesUid_ = instance.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString();
44 studyUid_ = instance.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString();
45 45
46 if (patientId_.size() == 0 || 46 if (patientId_.size() == 0 ||
47 instanceUid_.size() == 0 || 47 studyUid_.size() == 0 ||
48 seriesUid_.size() == 0 || 48 seriesUid_.size() == 0 ||
49 studyUid_.size() == 0) 49 instanceUid_.size() == 0)
50 { 50 {
51 throw OrthancException(ErrorCode_BadFileFormat); 51 throw OrthancException(ErrorCode_BadFileFormat);
52 } 52 }
53 } 53 }
54 54
55 std::string DicomInstanceHasher::HashPatient() const 55 const std::string& DicomInstanceHasher::HashPatient()
56 { 56 {
57 std::string s; 57 if (patientHash_.size() == 0)
58 Toolbox::ComputeSHA1(s, patientId_); 58 {
59 return s; 59 Toolbox::ComputeSHA1(patientHash_, patientId_);
60 }
61
62 return patientHash_;
60 } 63 }
61 64
62 std::string DicomInstanceHasher::HashStudy() const 65 const std::string& DicomInstanceHasher::HashStudy()
63 { 66 {
64 std::string s; 67 if (studyHash_.size() == 0)
65 Toolbox::ComputeSHA1(s, patientId_ + "|" + studyUid_); 68 {
66 return s; 69 Toolbox::ComputeSHA1(studyHash_, patientId_ + "|" + studyUid_);
70 }
71
72 return studyHash_;
67 } 73 }
68 74
69 std::string DicomInstanceHasher::HashSeries() const 75 const std::string& DicomInstanceHasher::HashSeries()
70 { 76 {
71 std::string s; 77 if (seriesHash_.size() == 0)
72 Toolbox::ComputeSHA1(s, patientId_ + "|" + studyUid_ + "|" + seriesUid_); 78 {
73 return s; 79 Toolbox::ComputeSHA1(seriesHash_, patientId_ + "|" + studyUid_ + "|" + seriesUid_);
80 }
81
82 return seriesHash_;
74 } 83 }
75 84
76 std::string DicomInstanceHasher::HashInstance() const 85 const std::string& DicomInstanceHasher::HashInstance()
77 { 86 {
78 std::string s; 87 if (instanceHash_.size() == 0)
79 Toolbox::ComputeSHA1(s, patientId_ + "|" + studyUid_ + "|" + seriesUid_ + "|" + instanceUid_); 88 {
80 return s; 89 Toolbox::ComputeSHA1(instanceHash_, patientId_ + "|" + studyUid_ + "|" + seriesUid_ + "|" + instanceUid_);
90 }
91
92 return instanceHash_;
81 } 93 }
82 } 94 }