OFFIS DCMTK  Version 3.6.0
i2doutpl.h
1 /*
2  *
3  * Copyright (C) 2001-2010, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: dcmdata
15  *
16  * Author: Michael Onken
17  *
18  * Purpose: Base class for converter from image file to DICOM
19  *
20  * Last Update: $Author: uli $
21  * Update Date: $Date: 2010-11-01 10:42:44 $
22  * CVS/RCS Revision: $Revision: 1.11 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 #ifndef I2DOUTPL_H
30 #define I2DOUTPL_H
31 
32 #include "dcmtk/config/osconfig.h"
33 #include "dcmtk/dcmdata/dcdatset.h"
34 #include "dcmtk/dcmdata/dcelem.h"
35 #include "dcmtk/oflog/oflog.h"
36 
37 
38 OFLogger DCM_dcmdataLibi2dGetLogger();
39 
40 #define DCMDATA_LIBI2D_TRACE(msg) OFLOG_TRACE(DCM_dcmdataLibi2dGetLogger(), msg)
41 #define DCMDATA_LIBI2D_DEBUG(msg) OFLOG_DEBUG(DCM_dcmdataLibi2dGetLogger(), msg)
42 #define DCMDATA_LIBI2D_INFO(msg) OFLOG_INFO(DCM_dcmdataLibi2dGetLogger(), msg)
43 #define DCMDATA_LIBI2D_WARN(msg) OFLOG_WARN(DCM_dcmdataLibi2dGetLogger(), msg)
44 #define DCMDATA_LIBI2D_ERROR(msg) OFLOG_ERROR(DCM_dcmdataLibi2dGetLogger(), msg)
45 #define DCMDATA_LIBI2D_FATAL(msg) OFLOG_FATAL(DCM_dcmdataLibi2dGetLogger(), msg)
46 
47 
49 {
50 
51 public:
52 
58  {};
59 
63  virtual OFString ident() =0;
64 
69  virtual void supportedSOPClassUIDs(OFList<OFString> suppSOPs) =0;
70 
75  virtual OFCondition convert(DcmDataset &dataset) const =0;
76 
82  virtual OFString isValid(DcmDataset& dataset) const = 0;
83 
87  virtual ~I2DOutputPlug() {};
88 
99  virtual void setValidityChecking(OFBool doChecks,
100  OFBool insertMissingType2 = OFTrue,
101  OFBool inventMissingType1 = OFTrue)
102  {
103  m_doAttribChecking = doChecks;
104  m_inventMissingType2Attribs = insertMissingType2;
105  m_inventMissingType1Attribs = inventMissingType1;
106  };
107 
108 protected:
109 
119  DcmDataset* targetDset,
120  const OFString& defaultValue ="") const
121  {
122  OFBool exists = targetDset->tagExists(key);
123  if (!exists && !m_inventMissingType1Attribs)
124  {
125  OFString err = "I2DOutputPlug: Missing type 1 attribute: "; err += DcmTag(key).getTagName(); err += "\n";
126  return err;
127  }
128  DcmElement *elem;
129  OFCondition cond = targetDset->findAndGetElement(key, elem);
130  if (cond.bad() || !elem || (elem->getLength() == 0))
131  {
133  {
134  OFString err;
135  err += "I2DOutputPlug: Empty value for type 1 attribute: ";
136  err += DcmTag(key).getTagName();
137  err += "\n";
138  return err;
139  }
140  //holds element to insert in item
141  elem = NULL;
142  DcmTag tag(key); OFBool wasError = OFFalse;
143  //if dicom element could be created, insert in to item and modify to value
144  if ( newDicomElement(elem, tag).good())
145  {
146  if (targetDset->insert(elem, OFTrue).good())
147  {
148  if (elem->putString(defaultValue.c_str()).good())
149  {
150  DCMDATA_LIBI2D_DEBUG("I2DOutputPlug: Inserting missing type 1 attribute: " << tag.getTagName() << " with value " << defaultValue);
151  } else wasError = OFTrue;
152  } else wasError = OFTrue;
153  } else wasError = OFTrue;
154  if (wasError)
155  {
156  OFString err = "Unable to insert type 1 attribute ";
157  err += tag.getTagName(); err += " with value "; err += defaultValue; err += "\n";
158  return err;
159  }
160  }
161  return "";
162  };
163 
164 
172  DcmDataset* targetDset,
173  const OFString& defaultValue ="") const
174  {
175  OFString err;
176  OFBool exists = targetDset->tagExists(key);
177  if (!exists)
178  {
180  {
181  //holds element to insert in item
182  DcmElement *elem = NULL;
183  DcmTag tag(key); OFBool wasError = OFFalse;
184  //if dicom element could be created, insert in to item and modify to value
185  if ( newDicomElement(elem, tag).good())
186  {
187  if (targetDset->insert(elem, OFTrue).good())
188  {
189  OFCondition result;
190  if (!defaultValue.empty()) // only insert value if not empty(e. g. empty type 2 sequences)
191  {
192  result = elem->putString(defaultValue.c_str());
193  }
194  if (result.good())
195  {
196  DCMDATA_LIBI2D_DEBUG("I2DOutputPlug: Inserting missing type 2 attribute: " << tag.getTagName() << " with value " << (defaultValue.empty() ? "<empty>" : defaultValue));
197  } else wasError = OFTrue;
198  } else wasError = OFTrue;
199  } else wasError = OFTrue;
200  if (wasError)
201  {
202  err += "Unable to insert type 2 attribute "; err += tag.getTagName(); err += " with value "; err += defaultValue; err += "\n";
203  }
204  }
205  else
206  {
207  err = "Image2Dcm: Missing type 2 attribute: "; err += DcmTag(key).getTagName(); err += "\n";
208  return err;
209  }
210  }
211  return err;
212  };
213 
216  OFBool m_doAttribChecking;
217 
221 
225 
226 };
227 
228 #endif // #ifndef I2DOUTPL_H
229 
230 /*
231  * CVS/RCS Log:
232  * $Log: i2doutpl.h,v $
233  * Revision 1.11 2010-11-01 10:42:44 uli
234  * Fixed some compiler warnings reported by gcc with additional flags.
235  *
236  * Revision 1.10 2010-10-14 13:15:46 joergr
237  * Updated copyright header. Added reference to COPYRIGHT file.
238  *
239  * Revision 1.9 2010-03-01 09:08:45 uli
240  * Removed some unnecessary include directives in the headers.
241  *
242  * Revision 1.8 2009-11-04 09:58:08 uli
243  * Switched to logging mechanism provided by the "new" oflog module
244  *
245  * Revision 1.7 2009-09-30 08:05:25 uli
246  * Stop including dctk.h in libi2d's header files.
247  *
248  * Revision 1.6 2009-03-31 11:31:05 onken
249  * Corrected commit message.
250  *
251  * Revision 1.5 2009-03-31 11:29:54 onken
252  * Added possibility to also insert type 2 elements with a default value
253  * when automatically inserting missing values (feature currently not in use).
254  *
255  * Revision 1.4 2009-01-16 09:51:55 onken
256  * Completed doxygen documentation for libi2d.
257  *
258  * Revision 1.3 2008-01-16 16:32:23 onken
259  * Fixed some empty or doubled log messages in libi2d files.
260  *
261  * Revision 1.2 2008-01-16 15:10:20 onken
262  * Moved library "i2dlib" from /dcmdata/libsrc/i2dlib to /dcmdata/libi2d
263  *
264  * Revision 1.2 2008-01-11 14:17:53 onken
265  * Added various options to i2dlib. Changed logging to use a configurable
266  * logstream. Added output plugin for the new Multiframe Secondary Capture SOP
267  * Classes. Added mode for JPEG plugin to copy exsiting APPn markers (except
268  * JFIF). Changed img2dcm default behaviour to invent type1/type2 attributes (no
269  * need for templates any more). Added some bug fixes.
270  *
271  * Revision 1.1 2007/11/08 15:58:55 onken
272  * Initial checkin of img2dcm application and corresponding library i2dlib.
273  *
274  *
275  */
276 


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2