Skip to content

Commit 3d112e7

Browse files
committed
WIP fix(image-sets-normalization): remove trailing space on tag values
1 parent acbd2e4 commit 3d112e7

File tree

2 files changed

+171
-11
lines changed

2 files changed

+171
-11
lines changed

packages/dicom/gdcm/Tags.h

Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,163 @@ const Tags SERIES_TAGS = {
198198
Tag(0x0020, 0x1040), // "Position Reference Indicator"
199199
};
200200

201-
std::pair<const char *, size_t> getTagBuffer(const gdcm::DataSet &ds, const gdcm::Tag &tag)
201+
const Tags NON_INSTANCE = {
202+
// Patient Module Elements
203+
Tag(0x0010, 0x0010), // "Patient's Name"
204+
Tag(0x0010, 0x0020), // "Patient ID"
205+
// Issuer of Patient ID Macro Elements
206+
Tag(0x0010, 0x0021), // "Issuer of Patient ID"
207+
Tag(0x0010, 0x0024), // "Issuer of Patient ID Qualifiers Sequence"
208+
Tag(0x0010, 0x0022), // "Type of Patient ID"
209+
Tag(0x0010, 0x0030), // "Patient's Birth Date"
210+
Tag(0x0010, 0x0033), // "Patient's Birth Date in Alternative Calendar"
211+
Tag(0x0010, 0x0034), // "Patient's Death Date in Alternative Calendar"
212+
Tag(0x0010, 0x0035), // "Patient's Alternative Calendar Attribute"
213+
Tag(0x0010, 0x0040), // "Patient's Sex"
214+
Tag(0x0010, 0x1100), // "Referenced Patient Photo Sequence"
215+
Tag(0x0010, 0x0200), // "Quality Control Subject"
216+
Tag(0x0008, 0x1120), // "Referenced Patient Sequence"
217+
Tag(0x0010, 0x0032), // "Patient's Birth Time"
218+
Tag(0x0010, 0x1002), // "Other Patient IDs Sequence"
219+
Tag(0x0010, 0x1001), // "Other Patient Names"
220+
Tag(0x0010, 0x2160), // "Ethnic Group"
221+
Tag(0x0010, 0x4000), // "Patient Comments"
222+
Tag(0x0010, 0x2201), // "Patient Species Description"
223+
Tag(0x0010, 0x2202), // "Patient Species Code Sequence Attribute"
224+
Tag(0x0010, 0x2292), // "Patient Breed Description"
225+
Tag(0x0010, 0x2293), // "Patient Breed Code Sequence"
226+
Tag(0x0010, 0x2294), // "Breed Registration Sequence Attribute"
227+
Tag(0x0010, 0x0212), // "Strain Description"
228+
Tag(0x0010, 0x0213), // "Strain Nomenclature Attribute"
229+
Tag(0x0010, 0x0219), // "Strain Code Sequence"
230+
Tag(0x0010, 0x0218), // "Strain Additional Information Attribute"
231+
Tag(0x0010, 0x0216), // "Strain Stock Sequence"
232+
Tag(0x0010, 0x0221), // "Genetic Modifications Sequence Attribute"
233+
Tag(0x0010, 0x2297), // "Responsible Person"
234+
Tag(0x0010, 0x2298), // "Responsible Person Role Attribute"
235+
Tag(0x0010, 0x2299), // "Responsible Organization"
236+
Tag(0x0012, 0x0062), // "Patient Identity Removed"
237+
Tag(0x0012, 0x0063), // "De-identification Method"
238+
Tag(0x0012, 0x0064), // "De-identification Method Code Sequence"
239+
// Patient Group Macro Elements
240+
Tag(0x0010, 0x0026), // "Source Patient Group Identification Sequence"
241+
Tag(0x0010, 0x0027), // "Group of Patients Identification Sequence"
242+
// Clinical Trial Subject Module
243+
Tag(0x0012, 0x0010), // "Clinical Trial Sponsor Name"
244+
Tag(0x0012, 0x0020), // "Clinical Trial Protocol ID"
245+
Tag(0x0012, 0x0021), // "Clinical Trial Protocol Name Attribute"
246+
Tag(0x0012, 0x0030), // "Clinical Trial Site ID"
247+
Tag(0x0012, 0x0031), // "Clinical Trial Site Name"
248+
Tag(0x0012, 0x0040), // "Clinical Trial Subject ID"
249+
Tag(0x0012, 0x0042), // "Clinical Trial Subject Reading ID"
250+
Tag(0x0012, 0x0081), // "Clinical Trial Protocol Ethics Committee Name"
251+
Tag(0x0012, 0x0082), // "Clinical Trial Protocol Ethics Committee Approval Number"
252+
// General Study Module
253+
Tag(0x0020, 0x000d), // "Study Instance UID"
254+
Tag(0x0008, 0x0020), // "Study Date"
255+
Tag(0x0008, 0x0030), // "Study Time"
256+
Tag(0x0008, 0x0090), // "Referring Physician's Name"
257+
Tag(0x0008, 0x0096), // "Referring Physician Identification Sequence"
258+
Tag(0x0008, 0x009c), // "Consulting Physician's Name"
259+
Tag(0x0008, 0x009d), // "Consulting Physician Identification Sequence"
260+
Tag(0x0020, 0x0010), // "Study ID"
261+
Tag(0x0008, 0x0050), // "Accession Number"
262+
Tag(0x0008, 0x0051), // "Issuer of Accession Number Sequence"
263+
Tag(0x0008, 0x1030), // "Study Description"
264+
Tag(0x0008, 0x1048), // "Physician(s) of Record"
265+
Tag(0x0008, 0x1049), // "Physician(s) of Record Identification Sequence"
266+
Tag(0x0008, 0x1060), // "Name of Physician(s) Reading Study"
267+
Tag(0x0008, 0x1062), // "Physician(s) Reading Study Identification Sequence"
268+
Tag(0x0032, 0x1033), // "Requesting Service"
269+
Tag(0x0032, 0x1034), // "Requesting Service Code Sequence"
270+
Tag(0x0008, 0x1110), // "Referenced Study Sequence"
271+
Tag(0x0008, 0x1032), // "Procedure Code Sequence"
272+
Tag(0x0040, 0x1012), // "Reason For Performed Procedure Code Sequence"
273+
// Patient Study Module
274+
Tag(0x0008, 0x1080), // "Admitting Diagnoses Description"
275+
Tag(0x0008, 0x1084), // "Admitting Diagnoses Code Sequence"
276+
Tag(0x0010, 0x1010), // "Patient's Age"
277+
Tag(0x0010, 0x1020), // "Patient's Size"
278+
Tag(0x0010, 0x1030), // "Patient's Weight"
279+
Tag(0x0010, 0x1022), // "Patient's Body Mass Index"
280+
Tag(0x0010, 0x1023), // "Measured AP Dimension"
281+
Tag(0x0010, 0x1024), // "Measured Lateral Dimension"
282+
Tag(0x0010, 0x1021), // "Patient's Size Code Sequence"
283+
Tag(0x0010, 0x2000), // "Medical Alerts"
284+
Tag(0x0010, 0x2110), // "Allergies"
285+
Tag(0x0010, 0x21a0), // "Smoking Status"
286+
Tag(0x0010, 0x21c0), // "Pregnancy Status"
287+
Tag(0x0010, 0x21d0), // "Last Menstrual Date"
288+
Tag(0x0038, 0x0500), // "Patient State"
289+
Tag(0x0010, 0x2180), // "Occupation"
290+
Tag(0x0010, 0x21b0), // "Additional Patient History"
291+
Tag(0x0038, 0x0010), // "Admission ID"
292+
Tag(0x0038, 0x0014), // "Issuer of Admission ID Sequence"
293+
Tag(0x0032, 0x1066), // "Reason for Visit"
294+
Tag(0x0032, 0x1067), // "Reason for Visit Code Sequence"
295+
Tag(0x0038, 0x0060), // "Service Episode ID"
296+
Tag(0x0038, 0x0064), // "Issuer of Service Episode ID Sequence"
297+
Tag(0x0038, 0x0062), // "Service Episode Description"
298+
Tag(0x0010, 0x2203), // "Patient's Sex Neutered"
299+
// Clinical Trial Study Module
300+
Tag(0x0012, 0x0050), // "Clinical Trial Time Point ID"
301+
Tag(0x0012, 0x0051), // "Clinical Trial Time Point Description"
302+
Tag(0x0012, 0x0052), // "Longitudinal Temporal Offset from Event"
303+
Tag(0x0012, 0x0053), // "Longitudinal Temporal Event Type"
304+
Tag(0x0012, 0x0083), // "Consent for Clinical Trial Use Sequence"
305+
306+
// General Series Module
307+
Tag(0x0008, 0x0060), // "Modality"
308+
Tag(0x0020, 0x000e), // "Series Instance UID"
309+
Tag(0x0020, 0x0011), // "Series Number"
310+
Tag(0x0020, 0x0060), // "Laterality"
311+
Tag(0x0008, 0x0021), // "Series Date"
312+
Tag(0x0008, 0x0031), // "Series Time"
313+
Tag(0x0008, 0x1050), // "Performing Physician's Name"
314+
Tag(0x0008, 0x1052), // "Performing Physician Identification Sequence"
315+
Tag(0x0018, 0x1030), // "Protocol Name"
316+
Tag(0x0008, 0x103e), // "Series Description"
317+
Tag(0x0008, 0x103f), // "Series Description Code Sequence"
318+
Tag(0x0008, 0x1070), // "Operators' Name"
319+
Tag(0x0008, 0x1072), // "Operator Identification Sequence"
320+
Tag(0x0008, 0x1111), // "Referenced Performed Procedure Step Sequence"
321+
Tag(0x0008, 0x1250), // "Related Series Sequence"
322+
Tag(0x0018, 0x0015), // "Body Part Examined"
323+
Tag(0x0018, 0x5100), // "Patient Position"
324+
Tag(0x0028, 0x0108), // "Smallest Pixel Value in Series"
325+
Tag(0x0028, 0x0109), // "Largest Pixel Value in Series"
326+
Tag(0x0040, 0x0275), // "Request Attributes Sequence"
327+
Tag(0x0010, 0x2210), // "Anatomical Orientation Type"
328+
Tag(0x300a, 0x0700), // "Treatment Session UID"
329+
// Clinical Trial Series Module
330+
Tag(0x0012, 0x0060), // "Clinical Trial Coordinating Center Name"
331+
Tag(0x0012, 0x0071), // "Clinical Trial Series ID"
332+
Tag(0x0012, 0x0072), // "Clinical Trial Series Description"
333+
// General Equipment Module
334+
Tag(0x0008, 0x0070), // "Manufacturer"
335+
Tag(0x0008, 0x0080), // "Institution Name"
336+
Tag(0x0008, 0x0081), // "Institution Address"
337+
Tag(0x0008, 0x1010), // "Station Name"
338+
Tag(0x0008, 0x1040), // "Institutional Department Name"
339+
Tag(0x0008, 0x1041), // "Institutional Department Type Code Sequence"
340+
Tag(0x0008, 0x1090), // "Manufacturer's Model Name"
341+
Tag(0x0018, 0x100b), // "Manufacturer's Device Class UID"
342+
Tag(0x0018, 0x1000), // "Device Serial Number"
343+
Tag(0x0018, 0x1020), // "Software Versions"
344+
Tag(0x0018, 0x1008), // "Gantry ID"
345+
Tag(0x0018, 0x100a), // "UDI Sequence"
346+
Tag(0x0018, 0x1002), // "Device UID"
347+
Tag(0x0018, 0x1050), // "Spatial Resolution"
348+
Tag(0x0018, 0x1200), // "Date of Last Calibration"
349+
Tag(0x0018, 0x1201), // "Time of Last Calibration"
350+
Tag(0x0028, 0x0120), // "Pixel Padding Value"
351+
// Frame of Reference Module
352+
Tag(0x0020, 0x0052), // "Frame of Reference UID"
353+
Tag(0x0020, 0x1040), // "Position Reference Indicator"
354+
};
355+
356+
std::pair<const char *, size_t>
357+
getTagBuffer(const gdcm::DataSet &ds, const gdcm::Tag &tag)
202358
{
203359
if (!ds.FindDataElement(tag) || ds.GetDataElement(tag).IsEmpty())
204360
{

packages/dicom/gdcm/image-sets-normalization.cxx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,13 @@ namespace gdcm
202202
assert(str1 && (size_t)(str1 - value) <= len);
203203
const char *sep = strchr(str1, '\\');
204204
const size_t llen = (sep != NULL) ? (sep - str1) : (value + len - str1);
205-
rapidjson::Value elementValue;
206205
// This is complex, IS/DS should not be stored as string anymore
207206
switch (vr)
208207
{
209208
case VR::IS:
210209
ss.str(std::string(str1, llen));
211210
ss >> vris;
212-
elementValue.SetInt(vris);
213-
jsonArray.PushBack(elementValue, allocator);
211+
jsonArray.PushBack(rapidjson::Value(vris), allocator);
214212
break;
215213
case VR::DS:
216214
ss.str(std::string(str1, llen));
@@ -235,7 +233,12 @@ namespace gdcm
235233
assert(str1 && (size_t)(str1 - value) <= len);
236234
const char *sep = strchr(str1, '\\');
237235
const size_t llen = (sep != NULL) ? (sep - str1) : (value + len - str1);
238-
const std::string valueUtf8 = toUtf8.convertCharStringToUTF8(str1, llen);
236+
std::string valueUtf8 = toUtf8.convertCharStringToUTF8(str1, llen);
237+
// Trim trailing space if exists
238+
if (!valueUtf8.empty() && valueUtf8.back() == ' ')
239+
{
240+
valueUtf8.pop_back();
241+
}
239242
rapidjson::Value valueString;
240243
valueString.SetString(valueUtf8.c_str(), valueUtf8.size(), allocator);
241244
jsonArray.PushBack(valueString, allocator);
@@ -246,7 +249,12 @@ namespace gdcm
246249
}
247250
else // default
248251
{
249-
const std::string valueUtf8 = toUtf8.convertCharStringToUTF8(value, len);
252+
std::string valueUtf8 = toUtf8.convertCharStringToUTF8(value, len);
253+
// Trim trailing space if exists
254+
if (!valueUtf8.empty() && valueUtf8.back() == ' ')
255+
{
256+
valueUtf8.pop_back();
257+
}
250258
rapidjson::Value valueString;
251259
valueString.SetString(valueUtf8.c_str(), valueUtf8.size(), allocator);
252260
jsonArray.PushBack(valueString, allocator);
@@ -637,10 +645,6 @@ rapidjson::Document toJson(const ImageSets &imageSets)
637645
{
638646
rapidjson::Document imageSetsJson(rapidjson::kArrayType);
639647
rapidjson::Document::AllocatorType &allocator = imageSetsJson.GetAllocator();
640-
Tags instanceSkipTags; // filter out patient, study, series tags from instance object
641-
instanceSkipTags.insert(PATIENT_TAGS.begin(), PATIENT_TAGS.end());
642-
instanceSkipTags.insert(STUDY_TAGS.begin(), STUDY_TAGS.end());
643-
instanceSkipTags.insert(SERIES_TAGS.begin(), SERIES_TAGS.end());
644648
for (const Volumes &volumes : imageSets)
645649
{
646650
gdcm::DataSet dataSet;
@@ -654,7 +658,7 @@ rapidjson::Document toJson(const ImageSets &imageSets)
654658
dataSet = dicomFile.dataSet;
655659
rapidjson::Value instanceTagsJson(rapidjson::kObjectType);
656660

657-
toJson(dataSet, EMPTY_TAGS, instanceSkipTags, instanceTagsJson, allocator);
661+
toJson(dataSet, EMPTY_TAGS, NON_INSTANCE, instanceTagsJson, allocator);
658662
rapidjson::Value instance(rapidjson::kObjectType);
659663
instance.AddMember("DICOM", instanceTagsJson, allocator);
660664

0 commit comments

Comments
 (0)