MeVisLab Toolbox Reference
mlDicomSRSave.h
Go to the documentation of this file.
1 // Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2 // **InsertLicense** code
3 //----------------------------------------------------------------------------------
5 
39 //----------------------------------------------------------------------------------
40 #pragma once
41 
42 // Local includes
43 #include "MLDicomOutputsSystem.h"
44 
45 // ML includes
46 #include <mlModuleIncludes.h>
47 #include <mlDicomSaveBase.h>
48 
49 // Tag/Field manager.
55 
56 #include <ThirdPartyWarningsDisable.h>
57 #include "dcmtk/config/osconfig.h"
58 #include "dcmtk/ofstd/ofstream.h"
59 #include "dcmtk/dcmdata/dcfilefo.h"
60 #include <ThirdPartyWarningsRestore.h>
61 
62 // DICOM tree etc.
63 #include <DCMTree_Tree.h>
64 
65 // Forward(s).
66 class DSRDocument;
67 class OFCondition;
68 
69 ML_START_NAMESPACE
70 
71 //----------------------------------------------------------------------------------
72 // See above.
73 //----------------------------------------------------------------------------------
75 {
76 public:
77 
80 
82  static OFString toOFString(std::string str);
83 
87  static void checkOFCondition(const OFCondition &cond, const std::string &loc);
88 
89 protected:
90 
93 
95  void handleNotification(Field *field) override;
96 
99  void activateAttachments() override;
100 
103  std::string _checkConsistency() const override;
104 
107 
109  void _save() override;
111 
113 
114  inline StringField &getLongXMLInfoField() const { return *_longXMLInfoFld ; }
115  inline const BoolField &getSaveAsDCMField() const { return *_saveAsDCMFld ; }
116  inline const BoolField &getSaveAsXMLField() const { return *_saveAsXMLFld ; }
117  inline StringField &getShortInfoField() const { return *_shortInfoFld ; }
119 
120 private:
121  // ----------------------------------------------------------
122  // General tool functions.
123  // ----------------------------------------------------------
124 
126  void _addMainParameterFields();
127 
129  void _addMainDICOMTagFields();
130 
133  std::string _setUpTreeContent() override;
134 
136  void _setUpContentParameters(DSRDocument &doc) const;
137 
144  void _setUpContentTree(DSRDocument &doc,
145  const PagedImage *inImg,
146  DCMTree::Const_TreePtr dcmTree) const;
147 
149  void _doFinalDocumentSettings(DSRDocument &doc) const;
150 
153  template <typename DCMTK_OBJECT_TYPE>
154  void _setBaseTagValues(DCMTK_OBJECT_TYPE &doc) const
155  {
156  OFString studyIDODStr = toOFString(_generalStudyModule._studyIDFld->getStringValue());
157  if (!studyIDODStr.empty()){
158  doc.setStudyID(studyIDODStr);
159  doc.createNewSeriesInStudy(studyIDODStr);
160  }
161  doc.setStudyDescription (toOFString(_generalStudyModule._studyDescriptionFld ->getStringValue()));
162  doc.setSeriesDescription (toOFString(_generalSeriesModule._seriesDescriptionFld ->getStringValue()));
163  doc.setPatientName (toOFString(_patientModule._patientsNameFld ->getStringValue()));
164  doc.setPatientBirthDate (toOFString(_patientModule._patientBirthDateYearStringFld ->getStringValue() +
165  _patientModule._patientBirthDateMonthStringFld ->getStringValue() +
166  _patientModule._patientBirthDateDayStringFld ->getStringValue()));
167  doc.setPatientSex (toOFString(_patientModule._patientSexStringFld ->getStringValue()));
168  doc.setPatientID (toOFString(_patientModule._patientIDFld ->getStringValue()));
169 
170  doc.setManufacturer (toOFString(_generalEquipmentModule.manufacturerAddOn .getValueFld().getStringValue()));
171  doc.setManufacturerModelName (toOFString(_generalEquipmentModule.manufacturersModelNameAddOn.getValueFld().getStringValue()));
172  doc.setReferringPhysicianName (toOFString(_generalStudyModule._referringPhysicianNameFld ->getStringValue()));
173  doc.setDeviceSerialNumber (toOFString(_generalEquipmentModule.deviceSerialNumberAddOn .getValueFld().getStringValue()));
174  doc.setSoftwareVersions (toOFString(_generalEquipmentModule.softwareVersionsAddOn .getValueFld().getStringValue()));
175  doc.setContentDate (toOFString(_generalImageModule._contentDateFld ->getStringValue()));
176  doc.setContentTime (toOFString(_generalImageModule._contentTimeFld ->getStringValue()));
177  doc.setSeriesNumber (toOFString(_generalSeriesModule._seriesNumberFld ->getStringValue()));
178  doc.setInstanceNumber (toOFString(_generalImageModule._instanceNumberFld ->getStringValue()));
179  doc.setAccessionNumber (toOFString(_generalStudyModule._accessionNumberFld ->getStringValue()));
180  }
181 
183 #define _SR_PRINT_DOC_SAVE(A) \
184  shortStream << #A << ":" << ((doc.get##A(tmp,-1) == EC_Normal) ? tmp : "") << std::endl;
185 
186  //----------------------------------------------------------------------------------
192  //----------------------------------------------------------------------------------
193  template <typename DCMTK_OBJECT_TYPE>
194  static void _createDumps(DCMTK_OBJECT_TYPE &doc,
195  std::string &shortInfo,
196  std::string &longXMLInfo)
197  {
198 
199  // Create a full XML rendering.
200  std::ostringstream fullXMLStream;
201  fullXMLStream << "";
202  doc.writeXML(fullXMLStream, 0);
203  fullXMLStream << std::endl;
204  longXMLInfo = fullXMLStream.str();
205 
206 
207  // Compose a short overview string.
208  std::ostringstream shortStream;
209  shortStream << "DICOM Information from file:" << std::endl;
210 
211  OFString tmp;
212 
213  _SR_PRINT_DOC_SAVE(Modality );
214  _SR_PRINT_DOC_SAVE(SOPClassUID );
215  _SR_PRINT_DOC_SAVE(StudyInstanceUID );
216  _SR_PRINT_DOC_SAVE(SeriesInstanceUID );
217  _SR_PRINT_DOC_SAVE(SOPInstanceUID );
218  _SR_PRINT_DOC_SAVE(InstanceCreatorUID );
219  _SR_PRINT_DOC_SAVE(SpecificCharacterSet );
220  _SR_PRINT_DOC_SAVE(PatientName );
221  _SR_PRINT_DOC_SAVE(PatientBirthDate );
222  _SR_PRINT_DOC_SAVE(PatientSex );
223  _SR_PRINT_DOC_SAVE(ReferringPhysicianName );
224  _SR_PRINT_DOC_SAVE(StudyDescription );
225  _SR_PRINT_DOC_SAVE(SeriesDescription );
226  _SR_PRINT_DOC_SAVE(Manufacturer );
227  _SR_PRINT_DOC_SAVE(StudyDate );
228  _SR_PRINT_DOC_SAVE(StudyTime );
229  _SR_PRINT_DOC_SAVE(InstanceCreationDate );
230  _SR_PRINT_DOC_SAVE(InstanceCreationTime );
231  _SR_PRINT_DOC_SAVE(ContentDate );
232  _SR_PRINT_DOC_SAVE(ContentTime );
233  _SR_PRINT_DOC_SAVE(StudyID );
234  _SR_PRINT_DOC_SAVE(PatientID );
235  _SR_PRINT_DOC_SAVE(SeriesNumber );
236  _SR_PRINT_DOC_SAVE(InstanceNumber );
237  _SR_PRINT_DOC_SAVE(AccessionNumber );
238 
239  shortStream << std::endl;
240  shortInfo = shortStream.str();
241  }
242 
243 #undef _SR_PRINT_DOC_SAVE
244 
245  // Module field declarations:
246 
248  BoolField *_saveAsHTMLFld;
249 
251  StringField *_longHTMLInfoFld;
252 
254  BoolField *_saveAsDCMFld;
255 
257  BoolField *_saveAsXMLFld;
258 
260  StringField *_shortInfoFld;
261 
263  StringField *_longXMLInfoFld;
264 
266  EnumField *_documentTypeFld;
267 
269  DicomPatientModuleTagInterface _patientModule;
270 
272  DicomGeneralStudyModuleTagInterface _generalStudyModule;
273 
275  DicomGeneralSeriesModuleTagInterface _generalSeriesModule;
276 
278  DicomGeneralEquipmentModuleTagInterface _generalEquipmentModule;
279 
281  DicomGeneralImageModuleTagInterface _generalImageModule;
282 
285  BoolField *_completeDocumentFld;
287  StringField *_docCompletionDescriptionFld;
288 
291  BoolField *_verifyDocumentFld;
293  StringField *_verifyDocumentObserverNameFld;
295  StringField *_verifyDocumentOrganizationFld;
296 
299  BoolField *_finalizeDocumentFld;
300 
302  BoolField *_preliminaryFlagFld;
303 
305  StringField *_documentTitleFld;
306 
308  StringField *_documentIntroTitleFld;
309 
311  StringField *_documentIntroFld;
312 
314  void _addTextSectionFields();
316  enum {
317  NumDocumentSections = 5
318  };
320  EnumField *_codingValueAndMeaningFld[NumDocumentSections];
322  StringField *_codeMeaningFld[NumDocumentSections];
324  BoolField *_openSubSectionFld[NumDocumentSections];
326  BoolField *_closeSubSectionFld[NumDocumentSections];
328  StringField *_subSectionContainerTitleFld[NumDocumentSections];
330  StringField *_subSectionTitleFld[NumDocumentSections];
332  StringField *_subSectionTextFld[NumDocumentSections];
334  StringField *_sectionTextFld[NumDocumentSections];
335 
336  // Field input connections:
338  void _addInputConnectorFields();
339 
341  enum {
342  NumInputConnectorFields = 10
343  };
344 
346  StringField *_inputFld[NumInputConnectorFields];
347 
350 };
351 
352 ML_END_NAMESPACE
Project global and OS specific declarations.
#define MLDICOMOUTPUTS_EXPORT
DLL export macro definition.
Creates and composes a DICOM structured report and exports it to different file formats or fields....
Field to encapsulate a boolean value.
Definition: mlFields.h:62
std::string _checkConsistency() const override
Checks for invalid parameters which could cause problems in document creation and return textual desc...
void _save() override
Creates a structured report DICOM objects and saves it in the file given by _fileNameFld.
DicomSRSave()
Constructor.
StringField & getLongXMLInfoField() const
Field access, see corresponding field for details.
static void checkOFCondition(const OFCondition &cond, const std::string &loc)
Check the passed condition cond for bad(), and if yes, then an ML error message is generated includin...
StringField & getShortInfoField() const
void _inheritFieldValuesFromDCMTree(DCMTree::Const_TreePtr dcmTree) override
Overloads base class field inheritance and adds the additional tags needed by this class.
void activateAttachments() override
Updates the internal module state after loading or cloning the module, and enables notification handl...
const BoolField & getSaveAsXMLField() const
void handleNotification(Field *field) override
Handles field changes of the field field.
static OFString toOFString(std::string str)
Converts an std::string to an OFString and replaced tabs by four spaces.
const BoolField & getSaveAsDCMField() const
virtual std::string _setUpTreeContent()=0
Allows the user to apply changes to the tree before it is saved; called after _updateInputState() and...
Base class for all fields used in the ML.
Definition: mlField.h:73
Class which represents an image, which manages properties of an image and image data which is located...
Definition: mlPagedImage.h:70
Field to encapsulate a string value.
Definition: mlFields.h:1000
#define ML_MODULE_CLASS_HEADER(className)
Like ML_CLASS_HEADER for the usage of derived classes from Module.
Header file for the ML module base class DicomGeneralEquipmentModuleTagInterface.
Header file for the ML module base class DicomGeneralImageModuleTagInterface.
Header file for the ML module base class DicomGeneralSeriesModuleTagInterface.
Header file for the ML module base class DicomGeneralStudyModuleTagInterface.
Header file for the ML module base class DicomPatientModuleTagInterface.
#define _SR_PRINT_DOC_SAVE(A)
Helper macro to print an attribute of the document.
Header file for the ML module base class DicomSaveBase.
boost::shared_ptr< const Tree > Const_TreePtr
Definition: DCMTree_Lib.h:73