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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
|
/*
*
* Copyright (C) 2003-2016, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmsr
*
* Author: Joerg Riesmeier
*
* Purpose:
* classes: DSRCodingSchemeIdentificationList
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmsr/dsrcsidl.h"
#include "dcmtk/dcmsr/dsrxmld.h"
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcuid.h"
#include "dcmtk/dcmdata/dcvrcs.h"
#include "dcmtk/dcmdata/dcvrlo.h"
#include "dcmtk/dcmdata/dcvrsh.h"
#include "dcmtk/dcmdata/dcvrst.h"
#include "dcmtk/dcmdata/dcvrui.h"
DSRCodingSchemeIdentificationList::DSRCodingSchemeIdentificationList()
: ItemList(),
Iterator(),
SpecificCharacterSet()
{
/* initialize list cursor */
Iterator = ItemList.end();
}
DSRCodingSchemeIdentificationList::~DSRCodingSchemeIdentificationList()
{
/* clear list and delete allocated memory */
clear();
}
void DSRCodingSchemeIdentificationList::clear()
{
Iterator = ItemList.begin();
const OFListIterator(ItemStruct *) last = ItemList.end();
/* delete all items and free memory */
while (Iterator != last)
{
delete (*Iterator);
Iterator = ItemList.erase(Iterator);
}
/* make sure that the list is empty */
ItemList.clear();
Iterator = ItemList.end();
/* also clear other members */
SpecificCharacterSet.clear();
}
OFBool DSRCodingSchemeIdentificationList::isEmpty() const
{
return ItemList.empty();
}
size_t DSRCodingSchemeIdentificationList::getNumberOfItems() const
{
return ItemList.size();
}
OFCondition DSRCodingSchemeIdentificationList::read(DcmItem &dataset,
const size_t /*flags*/)
{
/* first, check whether sequence is present and non-empty */
DcmSequenceOfItems *sequence = NULL;
OFCondition result = dataset.findAndGetSequence(DCM_CodingSchemeIdentificationSequence, sequence);
checkElementValue(sequence, DCM_CodingSchemeIdentificationSequence, "1-n", "3", result, "SOPCommonModule");
if (result.good())
{
ItemStruct *item = NULL;
OFString codingSchemeDesignator;
/* iterate over all sequence items */
DcmObject *dobj = NULL;
while ((dobj = sequence->nextInContainer(dobj)) != NULL)
{
DcmItem *ditem = OFstatic_cast(DcmItem *, dobj);
/* get the coding scheme designator */
if (getAndCheckStringValueFromDataset(*ditem, DCM_CodingSchemeDesignator, codingSchemeDesignator, "1", "1", "CodingSchemeIdentificationSequence").good())
{
/* add new item to the list */
if (addItem(codingSchemeDesignator, item).good())
{
/* read additional information */
getAndCheckStringValueFromDataset(*ditem, DCM_CodingSchemeRegistry, item->CodingSchemeRegistry, "1", "1C", "CodingSchemeIdentificationSequence");
getAndCheckStringValueFromDataset(*ditem, DCM_CodingSchemeUID, item->CodingSchemeUID, "1", "1C", "CodingSchemeIdentificationSequence");
getAndCheckStringValueFromDataset(*ditem, DCM_CodingSchemeExternalID, item->CodingSchemeExternalID, "1", "2C", "CodingSchemeIdentificationSequence");
getAndCheckStringValueFromDataset(*ditem, DCM_CodingSchemeName, item->CodingSchemeName, "1", "3", "CodingSchemeIdentificationSequence");
getAndCheckStringValueFromDataset(*ditem, DCM_CodingSchemeVersion, item->CodingSchemeVersion, "1", "3", "CodingSchemeIdentificationSequence");
getAndCheckStringValueFromDataset(*ditem, DCM_CodingSchemeResponsibleOrganization, item->CodingSchemeResponsibleOrganization, "1", "3", "CodingSchemeIdentificationSequence");
}
}
}
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::write(DcmItem &dataset) const
{
OFCondition result = EC_Normal;
/* iterate over all list items */
OFListConstIterator(ItemStruct *) iter = ItemList.begin();
const OFListConstIterator(ItemStruct *) last = ItemList.end();
while ((iter != last) && result.good())
{
ItemStruct *item = *iter;
/* check whether list item really exists and is valid */
if ((item != NULL) && !item->CodingSchemeDesignator.empty())
{
DcmItem *ditem = NULL;
/* create a new item (and a sequence if required) */
result = dataset.findOrCreateSequenceItem(DCM_CodingSchemeIdentificationSequence, ditem, -2 /*append new*/);
/* write item data */
if (result.good())
{
putStringValueToDataset(*ditem, DCM_CodingSchemeDesignator, item->CodingSchemeDesignator);
putStringValueToDataset(*ditem, DCM_CodingSchemeRegistry, item->CodingSchemeRegistry, OFFalse /*allowEmpty*/);
putStringValueToDataset(*ditem, DCM_CodingSchemeUID, item->CodingSchemeUID, OFFalse /*allowEmpty*/);
if (item->CodingSchemeUID.empty())
putStringValueToDataset(*ditem, DCM_CodingSchemeExternalID, item->CodingSchemeExternalID, OFFalse /*allowEmpty*/);
else if (!item->CodingSchemeExternalID.empty())
{
DCMSR_WARN("Both Coding Scheme UID and Coding Scheme External ID present for \""
<< item->CodingSchemeDesignator << "\", the latter will be ignored");
}
putStringValueToDataset(*ditem, DCM_CodingSchemeName, item->CodingSchemeName, OFFalse /*allowEmpty*/);
putStringValueToDataset(*ditem, DCM_CodingSchemeVersion, item->CodingSchemeVersion, OFFalse /*allowEmpty*/);
putStringValueToDataset(*ditem, DCM_CodingSchemeResponsibleOrganization, item->CodingSchemeResponsibleOrganization, OFFalse /*allowEmpty*/);
}
}
++iter;
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::readXML(const DSRXMLDocument &doc,
DSRXMLCursor cursor,
const size_t /*flags*/)
{
OFCondition result = SR_EC_InvalidDocument;
ItemStruct *item = NULL;
OFString codingSchemeDesignator;
/* iterate over all nodes */
while (cursor.valid())
{
/* check for known element tags */
if (doc.checkNode(cursor, "scheme").good())
{
/* retrieve coding scheme designator */
if (!doc.getStringFromAttribute(cursor, codingSchemeDesignator, "designator", OFTrue /*encoding*/).empty())
{
result = addItem(codingSchemeDesignator, item);
if (result.good())
{
DSRXMLCursor childCursor = cursor.getChild();
/* clear any previously stored information */
item->clear();
while (childCursor.valid())
{
/* check for known element tags */
doc.getStringFromNodeContent(childCursor, item->CodingSchemeRegistry, "registry", OFTrue /*encoding*/, OFFalse /*clearString*/);
doc.getStringFromNodeContent(childCursor, item->CodingSchemeUID, "uid", OFFalse /*encoding*/, OFFalse /*clearString*/);
doc.getStringFromNodeContent(childCursor, item->CodingSchemeExternalID, "id", OFTrue /*encoding*/, OFFalse /*clearString*/);
doc.getStringFromNodeContent(childCursor, item->CodingSchemeName, "name", OFTrue /*encoding*/, OFFalse /*clearString*/);
doc.getStringFromNodeContent(childCursor, item->CodingSchemeVersion, "version", OFTrue /*encoding*/, OFFalse /*clearString*/);
doc.getStringFromNodeContent(childCursor, item->CodingSchemeResponsibleOrganization, "organization", OFTrue /*encoding*/, OFFalse /*clearString*/);
/* proceed with next node */
childCursor.gotoNext();
}
}
}
}
/* proceed with next node */
cursor.gotoNext();
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::writeXML(STD_NAMESPACE ostream &stream,
const size_t flags) const
{
OFString tmpString;
/* iterate over all list items */
OFListConstIterator(ItemStruct *) iter = ItemList.begin();
const OFListConstIterator(ItemStruct *) last = ItemList.end();
while (iter != last)
{
ItemStruct *item = *iter;
/* check whether list item really exists */
if (item != NULL)
{
stream << "<scheme designator=\"" << convertToXMLString(item->CodingSchemeDesignator, tmpString) << "\">" << OFendl;
writeStringValueToXML(stream, convertToXMLString(item->CodingSchemeRegistry, tmpString), "registry", (flags & DSRTypes::XF_writeEmptyTags) > 0);
writeStringValueToXML(stream, item->CodingSchemeUID, "uid", (flags & DSRTypes::XF_writeEmptyTags) > 0);
writeStringValueToXML(stream, convertToXMLString(item->CodingSchemeExternalID, tmpString), "identifier", (flags & DSRTypes::XF_writeEmptyTags) > 0);
writeStringValueToXML(stream, convertToXMLString(item->CodingSchemeName, tmpString), "name", (flags & DSRTypes::XF_writeEmptyTags) > 0);
writeStringValueToXML(stream, convertToXMLString(item->CodingSchemeVersion, tmpString), "version", (flags & DSRTypes::XF_writeEmptyTags) > 0);
writeStringValueToXML(stream, convertToXMLString(item->CodingSchemeResponsibleOrganization, tmpString), "organization", (flags & DSRTypes::XF_writeEmptyTags) > 0);
stream << "</scheme>" << OFendl;
}
++iter;
}
return EC_Normal;
}
OFCondition DSRCodingSchemeIdentificationList::setSpecificCharacterSet(const OFString &value,
const OFBool check)
{
OFCondition result = (check) ? DcmCodeString::checkStringValue(value, "1-n") : EC_Normal;
if (result.good())
SpecificCharacterSet = value;
return result;
}
OFCondition DSRCodingSchemeIdentificationList::addPrivateDcmtkCodingScheme()
{
/* add private coding scheme (if not already existent) */
return addItem(OFFIS_CODING_SCHEME_DESIGNATOR, OFFIS_CODING_SCHEME_UID, OFFIS_CODING_SCHEME_NAME, OFFIS_CODING_SCHEME_RESPONSIBLE_ORGANIZATION);
}
OFCondition DSRCodingSchemeIdentificationList::addItem(const OFString &codingSchemeDesignator,
ItemStruct *&item)
{
OFCondition result = EC_IllegalParameter;
/* check parameter first */
if (!codingSchemeDesignator.empty())
{
result = EC_Normal;
OFListIterator(ItemStruct *) oldCursor = Iterator;
/* check whether item already exists */
if (gotoItem(codingSchemeDesignator).bad())
{
/* if not create new item and add it to the list */
item = new ItemStruct(codingSchemeDesignator);
if (item != NULL)
{
ItemList.push_back(item);
/* set cursor to new position */
Iterator = --ItemList.end();
} else {
/* restore old cursor */
Iterator = oldCursor;
result = EC_MemoryExhausted;
}
} else {
DCMSR_WARN("Coding Scheme Designator \"" << codingSchemeDesignator
<< "\" already exists in Coding Scheme Identification Sequence ... overwriting");
/* gotoItem() was successful, set item pointer */
item = *Iterator;
}
} else
item = NULL;
return result;
}
OFCondition DSRCodingSchemeIdentificationList::addItem(const OFString &codingSchemeDesignator,
const OFBool check)
{
OFCondition result = EC_Normal;
/* make sure that the mandatory value is non-empty */
if (codingSchemeDesignator.empty())
result = EC_IllegalParameter;
else if (check)
{
/* check whether the passed value is valid */
result = DcmShortString::checkStringValue(codingSchemeDesignator, "1", SpecificCharacterSet);
}
if (result.good())
{
ItemStruct *item = NULL;
/* call the "real" function */
result = addItem(codingSchemeDesignator, item);
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::addItem(const OFString &codingSchemeDesignator,
const OFString &codingSchemeUID,
const OFString &codingSchemeName,
const OFString &responsibleOrganization,
const OFBool check)
{
OFCondition result = EC_Normal;
/* make sure that the mandatory designator value is non-empty */
if (codingSchemeDesignator.empty())
result = EC_IllegalParameter;
else if (check)
{
/* check whether the passed values are valid */
result = DcmShortString::checkStringValue(codingSchemeDesignator, "1", SpecificCharacterSet);
if (result.good())
result = DcmUniqueIdentifier::checkStringValue(codingSchemeUID, "1");
if (result.good())
result = DcmShortText::checkStringValue(codingSchemeName, SpecificCharacterSet);
if (result.good())
result = DcmShortText::checkStringValue(responsibleOrganization, SpecificCharacterSet);
}
if (result.good())
{
ItemStruct *item = NULL;
/* add coding scheme (if not already existent) */
result = addItem(codingSchemeDesignator, item);
if (result.good())
{
/* set additional information */
item->CodingSchemeRegistry.clear();
item->CodingSchemeUID = codingSchemeUID;
item->CodingSchemeExternalID.clear();
item->CodingSchemeName = codingSchemeName;
item->CodingSchemeVersion.clear();
item->CodingSchemeResponsibleOrganization = responsibleOrganization;
}
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::removeItem()
{
OFCondition result = EC_IllegalCall;
/* check whether list is empty or iterator is invalid */
if (!ItemList.empty() && (Iterator != ItemList.end()))
{
/* free memory */
delete (*Iterator);
/* remove item from list */
Iterator = ItemList.erase(Iterator);
result = EC_Normal;
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::removeItem(const OFString &codingSchemeDesignator)
{
/* goto specified item ... */
OFCondition result = gotoItem(codingSchemeDesignator);
/* ... and remove it */
if (result.good())
result = removeItem();
return result;
}
OFCondition DSRCodingSchemeIdentificationList::gotoItem(const OFString &codingSchemeDesignator)
{
OFCondition result = EC_IllegalParameter;
/* check parameter first */
if (!codingSchemeDesignator.empty())
{
result = SR_EC_CodingSchemeNotFound;
/* start with first item */
Iterator = ItemList.begin();
const OFListIterator(ItemStruct *) last = ItemList.end();
/* search for given item */
while ((Iterator != last) && result.bad())
{
if ((*Iterator != NULL) && ((*Iterator)->CodingSchemeDesignator == codingSchemeDesignator))
result = EC_Normal;
else
++Iterator;
}
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::gotoFirstItem()
{
OFCondition result = EC_IllegalCall;
/* check for empty item list */
if (!ItemList.empty())
{
/* set cursor to first list item */
Iterator = ItemList.begin();
result = EC_Normal;
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::gotoNextItem()
{
OFCondition result = EC_IllegalCall;
/* goto next list item */
if (++Iterator != ItemList.end())
{
/* check whether list item is valid */
if (*Iterator != NULL)
result = EC_Normal;
else
result = EC_CorruptedData;
}
return result;
}
DSRCodingSchemeIdentificationList::ItemStruct *DSRCodingSchemeIdentificationList::getCurrentItem() const
{
ItemStruct *item = NULL;
/* check whether current item is valid */
OFListConstIterator(ItemStruct *) it = Iterator;
if (it != ItemList.end())
item = *Iterator;
return item;
}
const OFString &DSRCodingSchemeIdentificationList::getCodingSchemeDesignator(OFString &stringValue) const
{
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
/* get requested value or clear string if invalid */
if (item != NULL)
stringValue = item->CodingSchemeDesignator;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRCodingSchemeIdentificationList::getCodingSchemeRegistry(OFString &stringValue) const
{
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
/* get requested value or clear string if invalid */
if (item != NULL)
stringValue = item->CodingSchemeRegistry;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRCodingSchemeIdentificationList::getCodingSchemeUID(OFString &stringValue) const
{
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
/* get requested value or clear string if invalid */
if (item != NULL)
stringValue = item->CodingSchemeUID;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRCodingSchemeIdentificationList::getCodingSchemeExternalID(OFString &stringValue) const
{
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
/* get requested value or clear string if invalid */
if (item != NULL)
stringValue = item->CodingSchemeExternalID;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRCodingSchemeIdentificationList::getCodingSchemeName(OFString &stringValue) const
{
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
/* get requested value or clear string if invalid */
if (item != NULL)
stringValue = item->CodingSchemeName;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRCodingSchemeIdentificationList::getCodingSchemeVersion(OFString &stringValue) const
{
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
/* get requested value or clear string if invalid */
if (item != NULL)
stringValue = item->CodingSchemeVersion;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRCodingSchemeIdentificationList::getCodingSchemeResponsibleOrganization(OFString &stringValue) const
{
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
/* get requested value or clear string if invalid */
if (item != NULL)
stringValue = item->CodingSchemeResponsibleOrganization;
else
stringValue.clear();
return stringValue;
}
OFCondition DSRCodingSchemeIdentificationList::setCodingSchemeRegistry(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
if (item != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmLongString::checkStringValue(value, "1", SpecificCharacterSet) : EC_Normal;
if (result.good())
item->CodingSchemeRegistry = value;
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::setCodingSchemeUID(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
if (item != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmUniqueIdentifier::checkStringValue(value, "1") : EC_Normal;
if (result.good())
item->CodingSchemeUID = value;
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::setCodingSchemeExternalID(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
if (item != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmShortText::checkStringValue(value, SpecificCharacterSet) : EC_Normal;
if (result.good())
item->CodingSchemeExternalID = value;
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::setCodingSchemeName(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
if (item != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmShortText::checkStringValue(value, SpecificCharacterSet) : EC_Normal;
if (result.good())
item->CodingSchemeName = value;
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::setCodingSchemeVersion(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
if (item != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmShortString::checkStringValue(value, "1", SpecificCharacterSet) : EC_Normal;
if (result.good())
item->CodingSchemeVersion = value;
}
return result;
}
OFCondition DSRCodingSchemeIdentificationList::setCodingSchemeResponsibleOrganization(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current item is valid */
ItemStruct *item = getCurrentItem();
if (item != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmShortText::checkStringValue(value, SpecificCharacterSet) : EC_Normal;
if (result.good())
item->CodingSchemeResponsibleOrganization = value;
}
return result;
}
|