annotate OrthancFramework/Sources/DicomFormat/DicomInstanceHasher.cpp @ 4870:43e613a7756b

upgrade to year 2022
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Jan 2022 11:15:42 +0100
parents 7053502fbf97
children c767035fff77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1228
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * the License, or (at your option) any later version.
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * Lesser General Public License for more details.
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * <http://www.gnu.org/licenses/>.
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
23
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
24 #include "../PrecompiledHeaders.h"
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "DicomInstanceHasher.h"
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../OrthancException.h"
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../Toolbox.h"
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace Orthanc
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
32 void DicomInstanceHasher::Setup(const std::string& patientId,
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
33 const std::string& studyUid,
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
34 const std::string& seriesUid,
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
35 const std::string& instanceUid)
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
37 patientId_ = patientId;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
38 studyUid_ = studyUid;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
39 seriesUid_ = seriesUid;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
40 instanceUid_ = instanceUid;
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
1228
e0f7014d39a4 Instances without PatientID are now allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
42 if (studyUid_.size() == 0 ||
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 seriesUid_.size() == 0 ||
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
44 instanceUid_.size() == 0)
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
2971
62b07b30e3db error details
amazy
parents: 2447
diff changeset
46 throw OrthancException(ErrorCode_BadFileFormat, "missing StudyInstanceUID, SeriesInstanceUID or SOPInstanceUID");
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
50 DicomInstanceHasher::DicomInstanceHasher(const DicomMap& instance)
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
51 {
1228
e0f7014d39a4 Instances without PatientID are now allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
52 const DicomValue* patientId = instance.TestAndGetValue(DICOM_TAG_PATIENT_ID);
e0f7014d39a4 Instances without PatientID are now allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
53
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
54 Setup(patientId == NULL ? "" : patientId->GetContent(),
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
55 instance.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).GetContent(),
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
56 instance.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).GetContent(),
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
57 instance.GetValue(DICOM_TAG_SOP_INSTANCE_UID).GetContent());
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
58 }
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
59
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4296
diff changeset
60 DicomInstanceHasher::DicomInstanceHasher(const std::string &patientId,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4296
diff changeset
61 const std::string &studyUid,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4296
diff changeset
62 const std::string &seriesUid,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4296
diff changeset
63 const std::string &instanceUid)
4296
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
64 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
65 Setup(patientId, studyUid, seriesUid, instanceUid);
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
66 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
67
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
68 const std::string &DicomInstanceHasher::GetPatientId() const
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
69 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
70 return patientId_;
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
71 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
72
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
73 const std::string &DicomInstanceHasher::GetStudyUid() const
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
74 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
75 return studyUid_;
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
76 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
77
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
78 const std::string &DicomInstanceHasher::GetSeriesUid() const
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
79 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
80 return seriesUid_;
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
81 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
82
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
83 const std::string &DicomInstanceHasher::GetInstanceUid() const
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
84 {
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
85 return instanceUid_;
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
86 }
3b70a2e6a06c moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
87
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
88 const std::string& DicomInstanceHasher::HashPatient()
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
90 if (patientHash_.size() == 0)
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
91 {
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
92 Toolbox::ComputeSHA1(patientHash_, patientId_);
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
93 }
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
94
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
95 return patientHash_;
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
98 const std::string& DicomInstanceHasher::HashStudy()
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
100 if (studyHash_.size() == 0)
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
101 {
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
102 Toolbox::ComputeSHA1(studyHash_, patientId_ + "|" + studyUid_);
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
103 }
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
104
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
105 return studyHash_;
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
108 const std::string& DicomInstanceHasher::HashSeries()
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
110 if (seriesHash_.size() == 0)
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
111 {
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
112 Toolbox::ComputeSHA1(seriesHash_, patientId_ + "|" + studyUid_ + "|" + seriesUid_);
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
113 }
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
114
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
115 return seriesHash_;
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
118 const std::string& DicomInstanceHasher::HashInstance()
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
179
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
120 if (instanceHash_.size() == 0)
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
121 {
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
122 Toolbox::ComputeSHA1(instanceHash_, patientId_ + "|" + studyUid_ + "|" + seriesUid_ + "|" + instanceUid_);
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
123 }
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
124
78e28d0098d9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 178
diff changeset
125 return instanceHash_;
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }