Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit
mitkDICOMQIPropertyHelper.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include <mitkPropertyNameHelper.h>
16 #include <mitkPropertyList.h>
17 
19 
20 namespace mitk
21 {
22  void DICOMQIPropertyHelper::DeriveDICOMSourceProperties(const BaseData *sourceDICOMImage, BaseData *derivedDICOMImage)
23  {
24  // Check if original image is a DICOM image; if so, store relevant DICOM Tags into the PropertyList of new
25  // segmentation/PM image
26 
27  PropertyList::Pointer sourcePropertyList = sourceDICOMImage->GetPropertyList();
28  bool parentIsDICOM = false;
29 
30  for (const auto &element : *(sourcePropertyList->GetMap()))
31  {
32  if (element.first.find("DICOM") == 0)
33  {
34  parentIsDICOM = true;
35  break;
36  }
37  }
38 
39  if (!parentIsDICOM)
40  return;
41 
42 
43  PropertyList::Pointer propertyList = derivedDICOMImage->GetPropertyList();
44 
45  //====== Patient information ======
46  // Add DICOM Tag (0010,0010) patient's name; default "No Name"
47  AdoptReferenceDICOMProperty(sourcePropertyList, propertyList, DICOMTag(0x0010, 0x0010), "NO NAME");
48  // Add DICOM Tag (0010,0020) patient id; default "No Name"
49  AdoptReferenceDICOMProperty(sourcePropertyList, propertyList, DICOMTag(0x0010, 0x0020), "NO NAME");
50  // Add DICOM Tag (0010,0030) patient's birth date; no default
51  AdoptReferenceDICOMProperty(sourcePropertyList, propertyList, DICOMTag(0x0010, 0x0030));
52  // Add DICOM Tag (0010,0040) patient's sex; default "U" (Unknown)
53  AdoptReferenceDICOMProperty(sourcePropertyList, propertyList, DICOMTag(0x0010, 0x0040), "U");
54 
55  //====== General study ======
56  // Add DICOM Tag (0020,000D) Study Instance UID; no default --> MANDATORY!
57  AdoptReferenceDICOMProperty(sourcePropertyList, propertyList, DICOMTag(0x0020, 0x000D));
58  // Add DICOM Tag (0080,0020) Study Date; no default (think about "today")
59  AdoptReferenceDICOMProperty(sourcePropertyList, propertyList, DICOMTag(0x0080, 0x0020));
60  // Add DICOM Tag (0008,0050) Accession Number; no default
61  AdoptReferenceDICOMProperty(sourcePropertyList, propertyList, DICOMTag(0x0008, 0x0050));
62  // Add DICOM Tag (0008,1030) Study Description; no default
63  AdoptReferenceDICOMProperty(sourcePropertyList, propertyList, DICOMTag(0x0008, 0x1030));
64 
65 
66  //====== Reference DICOM data ======
67  // Add reference file paths to referenced DICOM data
68  BaseProperty::Pointer dcmFilesProp = sourcePropertyList->GetProperty("files");
69  if (dcmFilesProp.IsNotNull())
70  propertyList->SetProperty("referenceFiles", dcmFilesProp);
71  }
72 
73  void DICOMQIPropertyHelper::AdoptReferenceDICOMProperty(PropertyList *referencedPropertyList,
74  PropertyList *propertyList,
75  const DICOMTag &tag,
76  const std::string &defaultString)
77  {
78  std::string tagString = GeneratePropertyNameForDICOMTag(tag.GetGroup(), tag.GetElement());
79 
80  // Get DICOM property from referenced image
81  BaseProperty::Pointer originalProperty = referencedPropertyList->GetProperty(tagString.c_str());
82 
83  // if property exists, copy the informtaion to the derived image
84  if (originalProperty.IsNotNull())
85  propertyList->SetProperty(tagString.c_str(), originalProperty);
86  else // use the default value, if there is one
87  {
88  if (!defaultString.empty())
89  propertyList->SetProperty(tagString.c_str(), TemporoSpatialStringProperty::New(defaultString).GetPointer());
90  }
91  }
92 }
unsigned int GetElement() const
Base of all data objects.
Definition: mitkBaseData.h:42
Representation of a DICOM tag.
Definition: mitkDICOMTag.h:32
std::string MITKCORE_EXPORT GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
DataCollection - Class to facilitate loading/accessing structured data.
Key-value list holding instances of BaseProperty.
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
static void DeriveDICOMSourceProperties(const BaseData *sourceDICOMImage, BaseData *derivedDICOMImage)
mitk::PropertyList::Pointer GetPropertyList() const
Get the data&#39;s property list.
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
unsigned int GetGroup() const