0
|
1 /**
|
59
|
2 * Orthanc - A Lightweight, RESTful DICOM Store
|
398
|
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege,
|
0
|
4 * Belgium
|
|
5 *
|
|
6 * This program is free software: you can redistribute it and/or
|
|
7 * modify it under the terms of the GNU General Public License as
|
|
8 * published by the Free Software Foundation, either version 3 of the
|
|
9 * License, or (at your option) any later version.
|
136
|
10 *
|
|
11 * In addition, as a special exception, the copyright holders of this
|
|
12 * program give permission to link the code of its release with the
|
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
|
|
14 * that use the same license as the "OpenSSL" library), and distribute
|
|
15 * the linked executables. You must obey the GNU General Public License
|
|
16 * in all respects for all of the code used other than "OpenSSL". If you
|
|
17 * modify file(s) with this exception, you may extend this exception to
|
|
18 * your version of the file(s), but you are not obligated to do so. If
|
|
19 * you do not wish to do so, delete this exception statement from your
|
|
20 * version. If you delete this exception statement from all source files
|
|
21 * in the program, then also delete it here.
|
0
|
22 *
|
|
23 * This program is distributed in the hope that it will be useful, but
|
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
26 * General Public License for more details.
|
|
27 *
|
|
28 * You should have received a copy of the GNU General Public License
|
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30 **/
|
|
31
|
|
32
|
|
33 #include "DicomMap.h"
|
|
34
|
|
35 #include <stdio.h>
|
|
36 #include <memory>
|
|
37 #include "DicomString.h"
|
59
|
38 #include "../OrthancException.h"
|
0
|
39
|
|
40
|
59
|
41 namespace Orthanc
|
0
|
42 {
|
|
43 static DicomTag patientTags[] =
|
|
44 {
|
38
|
45 //DicomTag(0x0010, 0x1010), // PatientAge
|
|
46 //DicomTag(0x0010, 0x1040) // PatientAddress
|
77
|
47 DicomTag(0x0010, 0x0010), // PatientName
|
|
48 DicomTag(0x0010, 0x0030), // PatientBirthDate
|
|
49 DicomTag(0x0010, 0x0040), // PatientSex
|
|
50 DicomTag(0x0010, 0x1000), // OtherPatientIDs
|
80
|
51 DICOM_TAG_PATIENT_ID
|
0
|
52 };
|
|
53
|
|
54 static DicomTag studyTags[] =
|
|
55 {
|
38
|
56 //DicomTag(0x0010, 0x1020), // PatientSize
|
|
57 //DicomTag(0x0010, 0x1030) // PatientWeight
|
77
|
58 DicomTag(0x0008, 0x0020), // StudyDate
|
|
59 DicomTag(0x0008, 0x0030), // StudyTime
|
|
60 DicomTag(0x0008, 0x1030), // StudyDescription
|
|
61 DicomTag(0x0020, 0x0010), // StudyID
|
80
|
62 DICOM_TAG_ACCESSION_NUMBER,
|
|
63 DICOM_TAG_STUDY_INSTANCE_UID
|
0
|
64 };
|
|
65
|
|
66 static DicomTag seriesTags[] =
|
|
67 {
|
38
|
68 //DicomTag(0x0010, 0x1080), // MilitaryRank
|
77
|
69 DicomTag(0x0008, 0x0021), // SeriesDate
|
|
70 DicomTag(0x0008, 0x0031), // SeriesTime
|
|
71 DicomTag(0x0008, 0x0060), // Modality
|
|
72 DicomTag(0x0008, 0x0070), // Manufacturer
|
|
73 DicomTag(0x0008, 0x1010), // StationName
|
|
74 DicomTag(0x0008, 0x103e), // SeriesDescription
|
|
75 DicomTag(0x0018, 0x0015), // BodyPartExamined
|
|
76 DicomTag(0x0018, 0x0024), // SequenceName
|
|
77 DicomTag(0x0018, 0x1030), // ProtocolName
|
|
78 DicomTag(0x0020, 0x0011), // SeriesNumber
|
433
|
79 DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES,
|
80
|
80 DICOM_TAG_IMAGES_IN_ACQUISITION,
|
433
|
81 DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS,
|
80
|
82 DICOM_TAG_NUMBER_OF_SLICES,
|
433
|
83 DICOM_TAG_NUMBER_OF_TIME_SLICES,
|
80
|
84 DICOM_TAG_SERIES_INSTANCE_UID
|
0
|
85 };
|
|
86
|
|
87 static DicomTag instanceTags[] =
|
|
88 {
|
77
|
89 DicomTag(0x0008, 0x0012), // InstanceCreationDate
|
|
90 DicomTag(0x0008, 0x0013), // InstanceCreationTime
|
|
91 DicomTag(0x0020, 0x0012), // AcquisitionNumber
|
80
|
92 DICOM_TAG_IMAGE_INDEX,
|
|
93 DICOM_TAG_INSTANCE_NUMBER,
|
84
|
94 DICOM_TAG_NUMBER_OF_FRAMES,
|
433
|
95 DICOM_TAG_TEMPORAL_POSITION_IDENTIFIER,
|
80
|
96 DICOM_TAG_SOP_INSTANCE_UID
|
0
|
97 };
|
|
98
|
|
99
|
|
100
|
|
101
|
|
102 void DicomMap::SetValue(uint16_t group,
|
|
103 uint16_t element,
|
|
104 DicomValue* value)
|
|
105 {
|
|
106 DicomTag tag(group, element);
|
|
107 Map::iterator it = map_.find(tag);
|
|
108
|
|
109 if (it != map_.end())
|
|
110 {
|
|
111 delete it->second;
|
|
112 it->second = value;
|
|
113 }
|
|
114 else
|
|
115 {
|
|
116 map_.insert(std::make_pair(tag, value));
|
|
117 }
|
|
118 }
|
|
119
|
|
120 void DicomMap::SetValue(DicomTag tag,
|
|
121 DicomValue* value)
|
|
122 {
|
|
123 SetValue(tag.GetGroup(), tag.GetElement(), value);
|
|
124 }
|
|
125
|
|
126
|
|
127
|
|
128
|
|
129 void DicomMap::Clear()
|
|
130 {
|
|
131 for (Map::iterator it = map_.begin(); it != map_.end(); it++)
|
|
132 {
|
|
133 delete it->second;
|
|
134 }
|
|
135
|
|
136 map_.clear();
|
|
137 }
|
|
138
|
|
139
|
|
140 void DicomMap::ExtractTags(DicomMap& result,
|
|
141 const DicomTag* tags,
|
|
142 size_t count) const
|
|
143 {
|
|
144 result.Clear();
|
|
145
|
|
146 for (unsigned int i = 0; i < count; i++)
|
|
147 {
|
|
148 Map::const_iterator it = map_.find(tags[i]);
|
|
149 if (it != map_.end())
|
|
150 {
|
|
151 result.SetValue(it->first, it->second->Clone());
|
|
152 }
|
|
153 }
|
|
154 }
|
|
155
|
|
156
|
|
157 void DicomMap::ExtractPatientInformation(DicomMap& result) const
|
|
158 {
|
|
159 ExtractTags(result, patientTags, sizeof(patientTags) / sizeof(DicomTag));
|
|
160 }
|
|
161
|
|
162 void DicomMap::ExtractStudyInformation(DicomMap& result) const
|
|
163 {
|
|
164 ExtractTags(result, studyTags, sizeof(studyTags) / sizeof(DicomTag));
|
|
165 }
|
|
166
|
|
167 void DicomMap::ExtractSeriesInformation(DicomMap& result) const
|
|
168 {
|
|
169 ExtractTags(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag));
|
|
170 }
|
|
171
|
|
172 void DicomMap::ExtractInstanceInformation(DicomMap& result) const
|
|
173 {
|
|
174 ExtractTags(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag));
|
|
175 }
|
|
176
|
|
177
|
80
|
178
|
0
|
179 DicomMap* DicomMap::Clone() const
|
|
180 {
|
|
181 std::auto_ptr<DicomMap> result(new DicomMap);
|
|
182
|
|
183 for (Map::const_iterator it = map_.begin(); it != map_.end(); it++)
|
|
184 {
|
|
185 result->map_.insert(std::make_pair(it->first, it->second->Clone()));
|
|
186 }
|
|
187
|
|
188 return result.release();
|
|
189 }
|
|
190
|
|
191
|
|
192 const DicomValue& DicomMap::GetValue(const DicomTag& tag) const
|
|
193 {
|
80
|
194 const DicomValue* value = TestAndGetValue(tag);
|
|
195
|
|
196 if (value)
|
|
197 {
|
|
198 return *value;
|
|
199 }
|
|
200 else
|
|
201 {
|
|
202 throw OrthancException("Inexistent tag");
|
|
203 }
|
|
204 }
|
|
205
|
|
206
|
|
207 const DicomValue* DicomMap::TestAndGetValue(const DicomTag& tag) const
|
|
208 {
|
0
|
209 Map::const_iterator it = map_.find(tag);
|
|
210
|
|
211 if (it == map_.end())
|
|
212 {
|
80
|
213 return NULL;
|
0
|
214 }
|
|
215 else
|
|
216 {
|
80
|
217 return it->second;
|
0
|
218 }
|
|
219 }
|
|
220
|
|
221
|
|
222 void DicomMap::Remove(const DicomTag& tag)
|
|
223 {
|
|
224 Map::iterator it = map_.find(tag);
|
|
225 if (it != map_.end())
|
|
226 {
|
|
227 delete it->second;
|
|
228 map_.erase(it);
|
|
229 }
|
|
230 }
|
|
231
|
|
232
|
|
233 static void SetupFindTemplate(DicomMap& result,
|
|
234 const DicomTag* tags,
|
|
235 size_t count)
|
|
236 {
|
|
237 result.Clear();
|
|
238
|
|
239 for (size_t i = 0; i < count; i++)
|
|
240 {
|
|
241 result.SetValue(tags[i], "");
|
|
242 }
|
|
243 }
|
|
244
|
|
245 void DicomMap::SetupFindPatientTemplate(DicomMap& result)
|
|
246 {
|
|
247 SetupFindTemplate(result, patientTags, sizeof(patientTags) / sizeof(DicomTag));
|
|
248 }
|
|
249
|
|
250 void DicomMap::SetupFindStudyTemplate(DicomMap& result)
|
|
251 {
|
|
252 SetupFindTemplate(result, studyTags, sizeof(studyTags) / sizeof(DicomTag));
|
80
|
253 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "");
|
|
254 result.SetValue(DICOM_TAG_PATIENT_ID, "");
|
0
|
255 }
|
|
256
|
|
257 void DicomMap::SetupFindSeriesTemplate(DicomMap& result)
|
|
258 {
|
|
259 SetupFindTemplate(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag));
|
80
|
260 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "");
|
|
261 result.SetValue(DICOM_TAG_PATIENT_ID, "");
|
|
262 result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "");
|
0
|
263 }
|
|
264
|
|
265 void DicomMap::SetupFindInstanceTemplate(DicomMap& result)
|
|
266 {
|
|
267 SetupFindTemplate(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag));
|
80
|
268 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "");
|
|
269 result.SetValue(DICOM_TAG_PATIENT_ID, "");
|
|
270 result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "");
|
|
271 result.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "");
|
0
|
272 }
|
|
273
|
|
274
|
|
275 void DicomMap::CopyTagIfExists(const DicomMap& source,
|
|
276 const DicomTag& tag)
|
|
277 {
|
|
278 if (source.HasTag(tag))
|
|
279 {
|
|
280 SetValue(tag, source.GetValue(tag));
|
|
281 }
|
|
282 }
|
|
283 }
|