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
|
82
|
79 //DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES,
|
80
|
80 DICOM_TAG_IMAGES_IN_ACQUISITION,
|
|
81 DICOM_TAG_NUMBER_OF_SLICES,
|
|
82 DICOM_TAG_SERIES_INSTANCE_UID
|
0
|
83 };
|
|
84
|
|
85 static DicomTag instanceTags[] =
|
|
86 {
|
77
|
87 DicomTag(0x0008, 0x0012), // InstanceCreationDate
|
|
88 DicomTag(0x0008, 0x0013), // InstanceCreationTime
|
|
89 DicomTag(0x0020, 0x0012), // AcquisitionNumber
|
80
|
90 DICOM_TAG_IMAGE_INDEX,
|
|
91 DICOM_TAG_INSTANCE_NUMBER,
|
84
|
92 DICOM_TAG_NUMBER_OF_FRAMES,
|
80
|
93 DICOM_TAG_SOP_INSTANCE_UID
|
0
|
94 };
|
|
95
|
|
96
|
|
97
|
|
98
|
|
99 void DicomMap::SetValue(uint16_t group,
|
|
100 uint16_t element,
|
|
101 DicomValue* value)
|
|
102 {
|
|
103 DicomTag tag(group, element);
|
|
104 Map::iterator it = map_.find(tag);
|
|
105
|
|
106 if (it != map_.end())
|
|
107 {
|
|
108 delete it->second;
|
|
109 it->second = value;
|
|
110 }
|
|
111 else
|
|
112 {
|
|
113 map_.insert(std::make_pair(tag, value));
|
|
114 }
|
|
115 }
|
|
116
|
|
117 void DicomMap::SetValue(DicomTag tag,
|
|
118 DicomValue* value)
|
|
119 {
|
|
120 SetValue(tag.GetGroup(), tag.GetElement(), value);
|
|
121 }
|
|
122
|
|
123
|
|
124
|
|
125
|
|
126 void DicomMap::Clear()
|
|
127 {
|
|
128 for (Map::iterator it = map_.begin(); it != map_.end(); it++)
|
|
129 {
|
|
130 delete it->second;
|
|
131 }
|
|
132
|
|
133 map_.clear();
|
|
134 }
|
|
135
|
|
136
|
|
137 void DicomMap::ExtractTags(DicomMap& result,
|
|
138 const DicomTag* tags,
|
|
139 size_t count) const
|
|
140 {
|
|
141 result.Clear();
|
|
142
|
|
143 for (unsigned int i = 0; i < count; i++)
|
|
144 {
|
|
145 Map::const_iterator it = map_.find(tags[i]);
|
|
146 if (it != map_.end())
|
|
147 {
|
|
148 result.SetValue(it->first, it->second->Clone());
|
|
149 }
|
|
150 }
|
|
151 }
|
|
152
|
|
153
|
|
154 void DicomMap::ExtractPatientInformation(DicomMap& result) const
|
|
155 {
|
|
156 ExtractTags(result, patientTags, sizeof(patientTags) / sizeof(DicomTag));
|
|
157 }
|
|
158
|
|
159 void DicomMap::ExtractStudyInformation(DicomMap& result) const
|
|
160 {
|
|
161 ExtractTags(result, studyTags, sizeof(studyTags) / sizeof(DicomTag));
|
|
162 }
|
|
163
|
|
164 void DicomMap::ExtractSeriesInformation(DicomMap& result) const
|
|
165 {
|
|
166 ExtractTags(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag));
|
|
167 }
|
|
168
|
|
169 void DicomMap::ExtractInstanceInformation(DicomMap& result) const
|
|
170 {
|
|
171 ExtractTags(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag));
|
|
172 }
|
|
173
|
|
174
|
80
|
175
|
0
|
176 DicomMap* DicomMap::Clone() const
|
|
177 {
|
|
178 std::auto_ptr<DicomMap> result(new DicomMap);
|
|
179
|
|
180 for (Map::const_iterator it = map_.begin(); it != map_.end(); it++)
|
|
181 {
|
|
182 result->map_.insert(std::make_pair(it->first, it->second->Clone()));
|
|
183 }
|
|
184
|
|
185 return result.release();
|
|
186 }
|
|
187
|
|
188
|
|
189 const DicomValue& DicomMap::GetValue(const DicomTag& tag) const
|
|
190 {
|
80
|
191 const DicomValue* value = TestAndGetValue(tag);
|
|
192
|
|
193 if (value)
|
|
194 {
|
|
195 return *value;
|
|
196 }
|
|
197 else
|
|
198 {
|
|
199 throw OrthancException("Inexistent tag");
|
|
200 }
|
|
201 }
|
|
202
|
|
203
|
|
204 const DicomValue* DicomMap::TestAndGetValue(const DicomTag& tag) const
|
|
205 {
|
0
|
206 Map::const_iterator it = map_.find(tag);
|
|
207
|
|
208 if (it == map_.end())
|
|
209 {
|
80
|
210 return NULL;
|
0
|
211 }
|
|
212 else
|
|
213 {
|
80
|
214 return it->second;
|
0
|
215 }
|
|
216 }
|
|
217
|
|
218
|
|
219 void DicomMap::Remove(const DicomTag& tag)
|
|
220 {
|
|
221 Map::iterator it = map_.find(tag);
|
|
222 if (it != map_.end())
|
|
223 {
|
|
224 delete it->second;
|
|
225 map_.erase(it);
|
|
226 }
|
|
227 }
|
|
228
|
|
229
|
|
230 static void SetupFindTemplate(DicomMap& result,
|
|
231 const DicomTag* tags,
|
|
232 size_t count)
|
|
233 {
|
|
234 result.Clear();
|
|
235
|
|
236 for (size_t i = 0; i < count; i++)
|
|
237 {
|
|
238 result.SetValue(tags[i], "");
|
|
239 }
|
|
240 }
|
|
241
|
|
242 void DicomMap::SetupFindPatientTemplate(DicomMap& result)
|
|
243 {
|
|
244 SetupFindTemplate(result, patientTags, sizeof(patientTags) / sizeof(DicomTag));
|
|
245 }
|
|
246
|
|
247 void DicomMap::SetupFindStudyTemplate(DicomMap& result)
|
|
248 {
|
|
249 SetupFindTemplate(result, studyTags, sizeof(studyTags) / sizeof(DicomTag));
|
80
|
250 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "");
|
|
251 result.SetValue(DICOM_TAG_PATIENT_ID, "");
|
0
|
252 }
|
|
253
|
|
254 void DicomMap::SetupFindSeriesTemplate(DicomMap& result)
|
|
255 {
|
|
256 SetupFindTemplate(result, seriesTags, sizeof(seriesTags) / sizeof(DicomTag));
|
80
|
257 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "");
|
|
258 result.SetValue(DICOM_TAG_PATIENT_ID, "");
|
|
259 result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "");
|
0
|
260 }
|
|
261
|
|
262 void DicomMap::SetupFindInstanceTemplate(DicomMap& result)
|
|
263 {
|
|
264 SetupFindTemplate(result, instanceTags, sizeof(instanceTags) / sizeof(DicomTag));
|
80
|
265 result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "");
|
|
266 result.SetValue(DICOM_TAG_PATIENT_ID, "");
|
|
267 result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "");
|
|
268 result.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "");
|
0
|
269 }
|
|
270
|
|
271
|
|
272 void DicomMap::CopyTagIfExists(const DicomMap& source,
|
|
273 const DicomTag& tag)
|
|
274 {
|
|
275 if (source.HasTag(tag))
|
|
276 {
|
|
277 SetValue(tag, source.GetValue(tag));
|
|
278 }
|
|
279 }
|
|
280 }
|