1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
/*
*
* Copyright (C) 2015-2024, Open Connections GmbH
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation are maintained by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmiod
*
* Author: Michael Onken
*
* Purpose: Class representing IODs by exposing common DICOM module attributes
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmiod/iodcommn.h"
#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmdata/dctypes.h" // logger
DcmIODCommon::DcmIODCommon()
: m_Item(new DcmItem())
, m_Rules(new IODRules)
, m_Patient(m_Item, m_Rules)
, m_PatientStudy(m_Item, m_Rules)
, m_Study(m_Item, m_Rules)
, m_Equipment(m_Item, m_Rules)
, m_Series(m_Item, m_Rules)
, m_FrameOfReference(m_Item, m_Rules)
, m_SOPCommon(m_Item, m_Rules)
, m_CommonInstanceReferenceModule(m_Item, m_Rules)
, m_Modules()
, m_CheckValueOnWrite(OFTrue)
{
// Set initial values for a new SOP instance
ensureInstanceUIDs(OFFalse);
// push this first so Specific Character Set will be written in the beginning
m_Modules.push_back(&m_SOPCommon);
m_Modules.push_back(&m_Patient);
m_Modules.push_back(&m_PatientStudy);
m_Modules.push_back(&m_Study);
m_Modules.push_back(&m_Equipment);
m_Modules.push_back(&m_Series);
m_Modules.push_back(&m_FrameOfReference);
m_Modules.push_back(&m_CommonInstanceReferenceModule);
}
DcmIODCommon::DcmIODCommon(const DcmIODCommon& rhs)
: m_Item(rhs.m_Item)
, m_Rules(rhs.m_Rules)
, m_Patient(m_Item, m_Rules)
, m_PatientStudy(m_Item, m_Rules)
, m_Study(m_Item, m_Rules)
, m_Equipment(m_Item, m_Rules)
, m_Series(m_Item, m_Rules)
, m_FrameOfReference(m_Item, m_Rules)
, m_SOPCommon(m_Item, m_Rules)
, m_CommonInstanceReferenceModule(m_Item, m_Rules)
, m_Modules()
{
// Set initial values for a new SOP instance
ensureInstanceUIDs(OFFalse);
// push this first so Specific Character Set will be written in the beginning
m_Modules.push_back(&m_SOPCommon);
m_Modules.push_back(&m_Patient);
m_Modules.push_back(&m_PatientStudy);
m_Modules.push_back(&m_Study);
m_Modules.push_back(&m_Equipment);
m_Modules.push_back(&m_Series);
m_Modules.push_back(&m_FrameOfReference);
m_Modules.push_back(&m_CommonInstanceReferenceModule);
}
DcmIODCommon::~DcmIODCommon()
{
}
void DcmIODCommon::clearData()
{
// Clear data in all modules
OFVector<IODModule*>::iterator it = m_Modules.begin();
while (it != m_Modules.end())
{
(*it)->clearData();
it++;
}
}
IODPatientModule& DcmIODCommon::getPatient()
{
return m_Patient;
}
IODPatientStudyModule& DcmIODCommon::getPatientStudy()
{
return m_PatientStudy;
}
IODGeneralStudyModule& DcmIODCommon::getStudy()
{
return m_Study;
}
IODGeneralEquipmentModule& DcmIODCommon::getEquipment()
{
return m_Equipment;
}
IODGeneralSeriesModule& DcmIODCommon::getSeries()
{
return m_Series;
}
IODFoRModule& DcmIODCommon::getFrameOfReference()
{
return m_FrameOfReference;
}
IODSOPCommonModule& DcmIODCommon::getSOPCommon()
{
return m_SOPCommon;
}
IODCommonInstanceReferenceModule& DcmIODCommon::getCommonInstanceReference()
{
return m_CommonInstanceReferenceModule;
}
OFshared_ptr<IODRules> DcmIODCommon::getRules()
{
return m_Rules;
}
OFshared_ptr<DcmItem> DcmIODCommon::getData()
{
return m_Item;
}
OFCondition DcmIODCommon::read(DcmItem& dataset)
{
/* re-initialize object */
DcmIODCommon::clearData();
OFVector<IODModule*>::iterator it = m_Modules.begin();
while (it != m_Modules.end())
{
(*it)->read(dataset, OFTrue /* clear old data */);
it++;
}
// we do not report errors here (only logger output)
return EC_Normal;
}
OFCondition DcmIODCommon::importHierarchy(DcmItem& dataset,
const OFBool readPatient,
const OFBool readStudy,
const OFBool readFoR,
const OFBool readSeries,
const OFBool takeOverCharset)
{
if (readPatient)
{
m_Patient.read(dataset, OFFalse /* do not clear old data */);
}
if (readStudy)
{
m_Study.read(dataset, OFFalse /* do not clear old data */);
m_Equipment.read(dataset, OFFalse /* do not clear old data */);
m_PatientStudy.read(dataset, OFFalse /* do not clear old data */);
}
if (readSeries)
{
m_Series.read(dataset, OFFalse /* do not clear old data */);
m_FrameOfReference.read(dataset, OFFalse /* do not clear old data */);
}
if (readFoR)
{
m_FrameOfReference.read(dataset, OFFalse /* do not clear old data */);
}
// Take over character set from the dataset imported, if desired
if (takeOverCharset)
{
OFString charset;
dataset.findAndGetOFStringArray(DCM_SpecificCharacterSet, charset);
if (!charset.empty())
{
DCMIOD_DEBUG("Taking over Specific Character Set " << charset << " on import");
OFCondition result = m_SOPCommon.setSpecificCharacterSet(charset);
if (result.bad())
{
DCMIOD_ERROR("Could not set Specific Character Set " << charset << " on import: " << result.text());
}
}
else
{
DCMIOD_DEBUG("Taking over Default Specific Character Set (ASCII) on import");
m_SOPCommon.getData().findAndDeleteElement(DCM_SpecificCharacterSet);
}
}
return EC_Normal;
}
OFCondition DcmIODCommon::importHierarchy(const OFString& filename,
const OFBool readPatient,
const OFBool readStudy,
const OFBool readFoR,
const OFBool readSeries,
const OFBool takeOverCharset)
{
DcmFileFormat dcmff;
OFCondition result = dcmff.loadFile(filename.c_str());
if (result.good())
{
DcmDataset* dset = dcmff.getDataset();
if (dset != NULL)
{
result = importHierarchy(*dset, readPatient, readStudy, readFoR, readSeries, takeOverCharset);
}
else
{
DCMIOD_ERROR("Unable to get dataset from file for copying patient, study, series and/or frame of reference "
"information");
result = EC_IllegalCall;
}
}
return result;
}
void DcmIODCommon::ensureInstanceUIDs(const OFBool correctInvalid)
{
m_Study.ensureInstanceUID(correctInvalid);
m_Series.ensureInstanceUID(correctInvalid);
m_SOPCommon.ensureInstanceUID(correctInvalid);
}
OFCondition DcmIODCommon::write(DcmItem& dataset)
{
OFCondition result;
OFVector<IODModule*>::iterator it = m_Modules.begin();
while ((it != m_Modules.end() && result.good()))
{
result = (*it)->write(dataset);
it++;
}
return result;
}
void DcmIODCommon::setValueCheckOnWrite(const OFBool check)
{
m_CheckValueOnWrite = check;
// set value checking policy for all modules
OFVector<IODModule*>::iterator it = m_Modules.begin();
while (it != m_Modules.end())
{
(*it)->setValueCheckOnWrite(check);
it++;
}
}
OFBool DcmIODCommon::getValueCheckOnWrite() const
{
return m_CheckValueOnWrite;
}
void DcmIODCommon::createNewStudy(const OFBool clearEquipment)
{
// clear all study-related attributes
m_Study.clearData();
m_PatientStudy.clearData();
if (clearEquipment)
m_Equipment.clearData();
// make sure we have a valid Study Instance UID
m_Study.ensureInstanceUID();
// reset series- and instance related attributes
createNewSeries();
}
void DcmIODCommon::createNewSeries(const OFBool clearFoR)
{
// clear all series-related attributes
m_Series.clearData();
// create new Series Instance UID
m_Series.ensureInstanceUID();
// clear frame of reference-related attributes if desired
if (clearFoR)
m_FrameOfReference.clearData();
/* also creates new series (since UID is empty) */
createNewSOPInstance();
}
void DcmIODCommon::createNewSOPInstance()
{
m_SOPCommon.clearData();
m_SOPCommon.ensureInstanceUID();
}
|