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 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540
|
/*
*
* Copyright (C) 2002-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: DSRSOPInstanceReferenceList
* - InstanceStruct, SeriesStruct, StudyStruct
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmsr/dsrsoprf.h"
#include "dcmtk/dcmsr/dsrxmld.h"
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcuid.h"
#include "dcmtk/dcmdata/dcvrae.h"
#include "dcmtk/dcmdata/dcvrcs.h"
#include "dcmtk/dcmdata/dcvrsh.h"
#include "dcmtk/dcmdata/dcvrui.h"
// --- DSRSOPInstanceReferenceList::InstanceStruct ---
DSRSOPInstanceReferenceList::InstanceStruct::InstanceStruct(const OFString &sopClassUID,
const OFString &instanceUID)
: SOPClassUID(sopClassUID),
InstanceUID(instanceUID),
PurposeOfReference()
{
}
void DSRSOPInstanceReferenceList::InstanceStruct::clear()
{
PurposeOfReference.clear();
}
// --- DSRSOPInstanceReferenceList::SeriesStruct ---
DSRSOPInstanceReferenceList::SeriesStruct::SeriesStruct(const OFString &seriesUID)
: SeriesUID(seriesUID),
RetrieveAETitle(),
RetrieveLocationUID(),
StorageMediaFileSetID(),
StorageMediaFileSetUID(),
InstanceList(),
Iterator()
{
/* initialize list cursor */
Iterator = InstanceList.end();
}
DSRSOPInstanceReferenceList::SeriesStruct::~SeriesStruct()
{
Iterator = InstanceList.begin();
const OFListIterator(InstanceStruct *) last = InstanceList.end();
/* delete all items and free memory */
while (Iterator != last)
{
delete (*Iterator);
Iterator = InstanceList.erase(Iterator);
}
}
size_t DSRSOPInstanceReferenceList::SeriesStruct::getNumberOfInstances() const
{
return InstanceList.size();
}
OFCondition DSRSOPInstanceReferenceList::SeriesStruct::read(DcmItem &dataset,
const size_t flags)
{
/* first, read optional attributes on series level */
getAndCheckStringValueFromDataset(dataset, DCM_RetrieveAETitle, RetrieveAETitle, "1-n", "3", "ReferencedSeriesSequence");
getAndCheckStringValueFromDataset(dataset, DCM_RetrieveLocationUID, RetrieveLocationUID, "1", "3", "ReferencedSeriesSequence");
getAndCheckStringValueFromDataset(dataset, DCM_StorageMediaFileSetID, StorageMediaFileSetID, "1", "3", "ReferencedSeriesSequence");
getAndCheckStringValueFromDataset(dataset, DCM_StorageMediaFileSetUID, StorageMediaFileSetUID, "1", "3", "ReferencedSeriesSequence");
/* then, check whether sequence is present and non-empty */
DcmSequenceOfItems *sequence = NULL;
OFCondition result = dataset.findAndGetSequence(DCM_ReferencedSOPSequence, sequence);
checkElementValue(sequence, DCM_ReferencedSOPSequence, "1-n", "1", result);
if (result.good())
{
/* iterate over all sequence items */
DcmObject *object = NULL;
while ((object = sequence->nextInContainer(object)) != NULL)
{
DcmItem *item = OFstatic_cast(DcmItem *, object);
/* get the SOP class and SOP instance UID */
OFString sopClassUID, instanceUID;
if (getAndCheckStringValueFromDataset(*item, DCM_ReferencedSOPClassUID, sopClassUID, "1", "1", "ReferencedSOPSequence").good() &&
getAndCheckStringValueFromDataset(*item, DCM_ReferencedSOPInstanceUID, instanceUID, "1", "1", "ReferencedSOPSequence").good())
{
/* check whether instance item already exists */
InstanceStruct *instance = gotoInstance(instanceUID);
if (instance == NULL)
{
/* if not, create new instance list item */
instance = new InstanceStruct(sopClassUID, instanceUID);
if (instance != NULL)
{
/* add add it to the list of instances */
InstanceList.push_back(instance);
/* set cursor to new position */
Iterator = --InstanceList.end();
/* read additional information */
instance->PurposeOfReference.readSequence(*item, DCM_PurposeOfReferenceCodeSequence, "3", flags);
} else {
result = EC_MemoryExhausted;
break;
}
} else {
/* report a warning message and ignore this entry */
DCMSR_WARN("SOP Instance \"" << instanceUID << "\" already exists in reference list ... ignoring");
}
}
}
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::SeriesStruct::write(DcmItem &dataset) const
{
OFCondition result = EC_Normal;
/* store the series level attributes */
dataset.putAndInsertOFStringArray(DCM_SeriesInstanceUID, SeriesUID);
/* write optional attributes if non-empty */
if (!RetrieveAETitle.empty())
dataset.putAndInsertOFStringArray(DCM_RetrieveAETitle, RetrieveAETitle);
if (!RetrieveLocationUID.empty())
dataset.putAndInsertOFStringArray(DCM_RetrieveLocationUID, RetrieveLocationUID);
if (!StorageMediaFileSetID.empty())
dataset.putAndInsertOFStringArray(DCM_StorageMediaFileSetID, StorageMediaFileSetID);
if (!StorageMediaFileSetUID.empty())
dataset.putAndInsertOFStringArray(DCM_StorageMediaFileSetUID, StorageMediaFileSetUID);
/* iterate over all list items */
OFListConstIterator(InstanceStruct *) iter = InstanceList.begin();
const OFListConstIterator(InstanceStruct *) last = InstanceList.end();
while ((iter != last) && result.good())
{
InstanceStruct *instance = *iter;
/* check whether list item really exists */
if (instance != NULL)
{
DcmItem *item = NULL;
/* create a new item (and a sequence if required) */
result = dataset.findOrCreateSequenceItem(DCM_ReferencedSOPSequence, item, -2 /*append new*/);
if (result.good())
{
/* store the instance level attributes */
item->putAndInsertOFStringArray(DCM_ReferencedSOPClassUID, instance->SOPClassUID);
item->putAndInsertOFStringArray(DCM_ReferencedSOPInstanceUID, instance->InstanceUID);
if (!instance->PurposeOfReference.isEmpty()) // optional
instance->PurposeOfReference.writeSequence(*item, DCM_PurposeOfReferenceCodeSequence);
}
}
iter++;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::SeriesStruct::readXML(const DSRXMLDocument &doc,
DSRXMLCursor cursor,
const size_t flags)
{
OFCondition result = SR_EC_InvalidDocument;
if (cursor.valid())
{
/* first, read optional elements on series level */
doc.getStringFromNodeContent(doc.getNamedNode(cursor, "aetitle", OFFalse /*required*/), RetrieveAETitle);
doc.getStringFromAttribute(doc.getNamedNode(cursor, "location", OFFalse /*required*/), RetrieveLocationUID, "uid",
OFFalse /*encoding*/, OFFalse /*required*/);
const DSRXMLCursor childCursor = doc.getNamedNode(cursor, "fileset", OFFalse /*required*/);
if (childCursor.valid())
{
doc.getStringFromAttribute(childCursor, StorageMediaFileSetUID, "uid", OFFalse /*encoding*/, OFFalse /*required*/);
doc.getStringFromNodeContent(childCursor, StorageMediaFileSetID);
}
/* then proceed with instance level elements */
OFString sopClassUID, instanceUID;
do {
/* iterate over all "value" elements */
cursor = doc.getNamedNode(cursor, "value");
if (cursor.valid())
{
DSRXMLCursor instanceCursor = cursor.getChild();
if (!doc.getStringFromAttribute(doc.getNamedNode(instanceCursor, "sopclass"), sopClassUID, "uid").empty() &&
!doc.getStringFromAttribute(doc.getNamedNode(instanceCursor, "instance"), instanceUID, "uid").empty())
{
/* check whether instance item already exists,
because the internal structure is organized in a strictly hierarchical manner */
InstanceStruct *instance = gotoInstance(instanceUID);
if (instance == NULL)
{
/* if not, create a new instance list item */
instance = new InstanceStruct(sopClassUID, instanceUID);
if (instance != NULL)
{
/* and add it to the list of instances */
InstanceList.push_back(instance);
/* set cursor to new position */
Iterator = --InstanceList.end();
/* iterate over further child nodes */
while (instanceCursor.valid())
{
/* check for known element tags */
if (doc.matchNode(instanceCursor, "purpose"))
instance->PurposeOfReference.readXML(doc, instanceCursor, flags);
/* proceed with next node */
instanceCursor.gotoNext();
}
result = EC_Normal;
} else {
result = EC_MemoryExhausted;
break;
}
} else {
/* report a warning message and ignore this entry */
DCMSR_WARN("SOP Instance \"" << instanceUID << "\" already exists in reference list ... ignoring");
}
}
/* proceed with next node */
cursor.gotoNext();
}
} while (cursor.valid());
/* report a warning message if no "value" element found */
if (result.bad())
DCMSR_WARN("Series \"" << SeriesUID << "\" empty in reference list ... ignoring");
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::SeriesStruct::writeXML(STD_NAMESPACE ostream &stream,
const size_t flags) const
{
/* write the series level attributes */
stream << "<series uid=\"" << SeriesUID << "\">" << OFendl;
writeStringValueToXML(stream, RetrieveAETitle, "aetitle", (flags & XF_writeEmptyTags) > 0);
if ((flags & XF_writeEmptyTags) || !RetrieveLocationUID.empty())
{
stream << "<location";
if (!RetrieveLocationUID.empty())
stream << " uid=\"" << RetrieveLocationUID << "\"";
stream << "/>" << OFendl;
}
if ((flags & XF_writeEmptyTags) || !StorageMediaFileSetUID.empty() || !StorageMediaFileSetID.empty())
{
stream << "<fileset";
if (!StorageMediaFileSetUID.empty())
stream << " uid=\"" << StorageMediaFileSetUID << "\"";
stream << ">" << StorageMediaFileSetID << "</fileset>" << OFendl;
}
/* iterate over all list items */
OFListConstIterator(InstanceStruct *) iter = InstanceList.begin();
const OFListConstIterator(InstanceStruct *) last = InstanceList.end();
while (iter != last)
{
InstanceStruct *instance = *iter;
/* check whether list item really exists */
if (instance != NULL)
{
/* write instance level */
stream << "<value>" << OFendl;
stream << "<sopclass uid=\"" << instance->SOPClassUID << "\">";
/* retrieve name of SOP class (if known) */
stream << dcmFindNameOfUID(instance->SOPClassUID.c_str(), "" /* empty value as default */);
stream << "</sopclass>" << OFendl;
stream << "<instance uid=\"" << instance->InstanceUID << "\"/>" << OFendl;
/* purpose of reference (optional) */
if (instance->PurposeOfReference.isValid())
{
if (flags & DSRTypes::XF_codeComponentsAsAttribute)
stream << "<purpose"; // bracket ">" is closed in next writeXML() call
else
stream << "<purpose>" << OFendl;
instance->PurposeOfReference.writeXML(stream, flags);
stream << "</purpose>" << OFendl;
}
stream << "</value>" << OFendl;
}
iter++;
}
stream << "</series>" << OFendl;
return EC_Normal;
}
DSRSOPInstanceReferenceList::InstanceStruct *DSRSOPInstanceReferenceList::SeriesStruct::gotoInstance(const OFString &instanceUID)
{
InstanceStruct *instance = NULL;
/* first, check whether the current instance is the one we're searching for */
if ((Iterator != InstanceList.end()) && (*Iterator != NULL) && ((*Iterator)->InstanceUID == instanceUID))
instance = *Iterator;
else
{
/* start with the first list item */
Iterator = InstanceList.begin();
const OFListIterator(InstanceStruct *) last = InstanceList.end();
/* search for given SOP instance UID */
while ((Iterator != last) && ((*Iterator == NULL) || ((*Iterator)->InstanceUID != instanceUID)))
Iterator++;
/* item found */
if (Iterator != last)
instance = *Iterator;
}
return instance;
}
OFCondition DSRSOPInstanceReferenceList::SeriesStruct::gotoFirstItem()
{
OFCondition result = EC_IllegalCall;
/* check for empty instance list */
if (!InstanceList.empty())
{
/* set cursor to first list item */
Iterator = InstanceList.begin();
/* check whether list item is valid */
if (*Iterator != NULL)
result = EC_Normal;
else
result = EC_CorruptedData;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::SeriesStruct::gotoNextItem()
{
OFCondition result = EC_IllegalCall;
/* goto next list item */
if (++Iterator != InstanceList.end())
{
/* check whether list item is valid */
if (*Iterator != NULL)
result = EC_Normal;
else
result = EC_CorruptedData;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::SeriesStruct::addItem(const OFString &sopClassUID,
const OFString &instanceUID)
{
OFCondition result = EC_Normal;
/* check whether series already exists */
InstanceStruct *instance = gotoInstance(instanceUID);
if (instance == NULL)
{
/* if not, create new instance item and add it to the list */
instance = new InstanceStruct(sopClassUID, instanceUID);
if (instance != NULL)
{
InstanceList.push_back(instance);
/* set cursor to new position */
Iterator = --InstanceList.end();
} else
result = EC_MemoryExhausted;
} else {
/* check whether given SOP class is the same as stored */
if (instance->SOPClassUID != sopClassUID)
result = SR_EC_DifferentSOPClassesForAnInstance;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::SeriesStruct::removeItem()
{
OFCondition result = EC_IllegalCall;
/* check whether list is empty or iterator is invalid */
if (!InstanceList.empty() && (Iterator != InstanceList.end()))
{
/* free memory */
delete (*Iterator);
/* remove item from list */
Iterator = InstanceList.erase(Iterator);
result = EC_Normal;
}
return result;
}
// --- DSRSOPInstanceReferenceList::StudyStruct ---
DSRSOPInstanceReferenceList::StudyStruct::StudyStruct(const OFString &studyUID)
: StudyUID(studyUID),
SeriesList(),
Iterator()
{
/* initialize list cursor */
Iterator = SeriesList.end();
}
DSRSOPInstanceReferenceList::StudyStruct::~StudyStruct()
{
Iterator = SeriesList.begin();
const OFListIterator(SeriesStruct *) last = SeriesList.end();
/* delete all items and free memory */
while (Iterator != last)
{
delete (*Iterator);
Iterator = SeriesList.erase(Iterator);
}
}
size_t DSRSOPInstanceReferenceList::StudyStruct::getNumberOfInstances() const
{
size_t result = 0;
OFListConstIterator(SeriesStruct *) iter = SeriesList.begin();
const OFListConstIterator(SeriesStruct *) last = SeriesList.end();
/* for all series in the list */
while (iter != last)
{
/* sum up the number of instances */
if (*iter != NULL)
result += (*iter)->getNumberOfInstances();
++iter;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::StudyStruct::read(DcmItem &dataset,
const size_t flags)
{
/* first, check whether sequence is present and non-empty */
DcmSequenceOfItems *sequence = NULL;
OFCondition result = dataset.findAndGetSequence(DCM_ReferencedSeriesSequence, sequence);
checkElementValue(sequence, DCM_ReferencedSeriesSequence, "1-n", "1", result);
if (result.good())
{
/* iterate over all sequence items */
DcmObject *object = NULL;
while ((object = sequence->nextInContainer(object)) != NULL)
{
DcmItem *item = OFstatic_cast(DcmItem *, object);
/* get the series instance UID */
OFString seriesUID;
if (getAndCheckStringValueFromDataset(*item, DCM_SeriesInstanceUID, seriesUID, "1", "1", "ReferencedSeriesSequence").good())
{
/* check whether series item already exists,
because the internal structure is organized in a strictly hierarchical manner */
SeriesStruct *series = gotoSeries(seriesUID);
if (series == NULL)
{
/* if not, create a new series list item */
series = new SeriesStruct(seriesUID);
if (series != NULL)
{
/* and add it to the list of studies */
SeriesList.push_back(series);
} else {
result = EC_MemoryExhausted;
break;
}
}
if (series != NULL)
{
/* set cursor to new position */
Iterator = --SeriesList.end();
/* read further attributes on series level and the instance level */
result = series->read(*item, flags);
}
}
}
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::StudyStruct::write(DcmItem &dataset) const
{
OFCondition result = EC_Normal;
/* store the study level attributes */
dataset.putAndInsertOFStringArray(DCM_StudyInstanceUID, StudyUID);
/* iterate over all list items */
OFListConstIterator(SeriesStruct *) iter = SeriesList.begin();
const OFListConstIterator(SeriesStruct *) last = SeriesList.end();
while ((iter != last) && result.good())
{
SeriesStruct *series = *iter;
/* check whether list item really exists */
if (series != NULL)
{
DcmItem *item = NULL;
/* create a new item (and a sequence if required) */
result = dataset.findOrCreateSequenceItem(DCM_ReferencedSeriesSequence, item, -2 /*append new*/);
/* write series and instance level */
if (result.good())
result = series->write(*item);
}
iter++;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::StudyStruct::readXML(const DSRXMLDocument &doc,
DSRXMLCursor cursor,
const size_t flags)
{
OFCondition result = SR_EC_InvalidDocument;
if (cursor.valid())
{
OFString seriesUID;
while (cursor.valid())
{
/* check for known element tags */
if (doc.checkNode(cursor, "series").good())
{
if (!doc.getStringFromAttribute(cursor, seriesUID, "uid").empty())
{
/* check whether series item already exists,
because the internal structure is organized in a strictly hierarchical manner */
SeriesStruct *series = gotoSeries(seriesUID);
if (series == NULL)
{
/* if not, create a new series list item */
series = new SeriesStruct(seriesUID);
if (series != NULL)
{
/* and add it to the list of series */
SeriesList.push_back(series);
} else {
result = EC_MemoryExhausted;
break;
}
}
if (series != NULL)
{
/* set cursor to new position */
Iterator = --SeriesList.end();
/* read further attributes on series level and the instance level */
result = series->readXML(doc, cursor.getChild(), flags);
}
}
}
/* proceed with next node */
cursor.gotoNext();
}
/* report a warning message if no "value" element found */
if (result.bad())
DCMSR_WARN("Study \"" << StudyUID << "\" empty in reference list ... ignoring");
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::StudyStruct::writeXML(STD_NAMESPACE ostream &stream,
const size_t flags) const
{
OFCondition result = EC_Normal;
/* write the study level attributes */
stream << "<study uid=\"" << StudyUID << "\">" << OFendl;
/* iterate over all list items */
OFListConstIterator(SeriesStruct *) iter = SeriesList.begin();
const OFListConstIterator(SeriesStruct *) last = SeriesList.end();
while ((iter != last) && result.good())
{
SeriesStruct *series = *iter;
/* check whether list item really exists */
if (series != NULL)
{
/* write series and instance level */
result = series->writeXML(stream, flags);
}
iter++;
}
stream << "</study>" << OFendl;
return result;
}
DSRSOPInstanceReferenceList::SeriesStruct *DSRSOPInstanceReferenceList::StudyStruct::gotoSeries(const OFString &seriesUID)
{
SeriesStruct *series = NULL;
/* first, check whether the current series is the one we're searching for */
if ((Iterator != SeriesList.end()) && (*Iterator != NULL) && ((*Iterator)->SeriesUID == seriesUID))
series = *Iterator;
else
{
/* start with the first list item */
Iterator = SeriesList.begin();
const OFListIterator(SeriesStruct *) last = SeriesList.end();
/* search for given series UID */
while ((Iterator != last) && ((*Iterator == NULL) || ((*Iterator)->SeriesUID != seriesUID)))
Iterator++;
/* item found */
if (Iterator != last)
series = *Iterator;
}
return series;
}
DSRSOPInstanceReferenceList::InstanceStruct *DSRSOPInstanceReferenceList::StudyStruct::gotoInstance(const OFString &instanceUID)
{
InstanceStruct *instance = NULL;
/* start with the first list item */
Iterator = SeriesList.begin();
const OFListIterator(SeriesStruct *) last = SeriesList.end();
/* search for given series UID */
while ((Iterator != last) && (instance == NULL))
{
SeriesStruct *series = *Iterator;
/* continue search on instance level */
if (series != NULL)
instance = series->gotoInstance(instanceUID);
/* if found exit loop, else goto next */
if (instance == NULL)
Iterator++;
}
return instance;
}
OFCondition DSRSOPInstanceReferenceList::StudyStruct::gotoFirstItem()
{
OFCondition result = EC_IllegalCall;
/* check for empty series list */
if (!SeriesList.empty())
{
/* set cursor to first list item */
Iterator = SeriesList.begin();
/* check whether list item is valid */
if (*Iterator != NULL)
{
/* do the same for instance level */
result = (*Iterator)->gotoFirstItem();
} else
result = EC_CorruptedData;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::StudyStruct::gotoNextItem()
{
OFCondition result = EC_IllegalCall;
/* goto next list item */
if (Iterator != SeriesList.end())
{
/* check whether current list item is valid */
if (*Iterator != NULL)
{
/* try to go to the next instance item */
result = (*Iterator)->gotoNextItem();
/* if this fails ... */
if (result.bad())
{
/* goto to the first instance of the next series item */
if (++Iterator != SeriesList.end())
{
if (*Iterator != NULL)
result = (*Iterator)->gotoFirstItem();
}
}
} else
result = EC_CorruptedData;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::StudyStruct::addItem(const OFString &seriesUID,
const OFString &sopClassUID,
const OFString &instanceUID)
{
OFCondition result = EC_Normal;
/* check whether series already exists */
SeriesStruct *series = gotoSeries(seriesUID);
if (series == NULL)
{
/* if not create new series item and add it to the list */
series = new SeriesStruct(seriesUID);
if (series != NULL)
{
SeriesList.push_back(series);
/* set cursor to new position */
Iterator = --SeriesList.end();
} else
result = EC_MemoryExhausted;
}
/* do the same for the instance level */
if (series != NULL)
result = series->addItem(sopClassUID, instanceUID);
return result;
}
OFCondition DSRSOPInstanceReferenceList::StudyStruct::removeItem()
{
OFCondition result = EC_IllegalCall;
/* check whether list is empty or iterator is invalid */
if (!SeriesList.empty() && (Iterator != SeriesList.end()))
{
SeriesStruct *series = *Iterator;
if (series != NULL)
{
result = series->removeItem();
/* check whether lower level list has become empty */
if (result.good() && series->InstanceList.empty())
{
/* free memory */
delete series;
/* if so, remove series from list and set iterator to the next item */
Iterator = SeriesList.erase(Iterator);
}
}
}
return result;
}
void DSRSOPInstanceReferenceList::StudyStruct::removeIncompleteItems()
{
Iterator = SeriesList.begin();
const OFListIterator(SeriesStruct *) last = SeriesList.end();
/* for all series in the list */
while (Iterator != last)
{
SeriesStruct *series = *Iterator;
if (series != NULL)
{
/* check whether list of series is empty */
if (series->InstanceList.empty())
{
/* free memory */
delete series;
/* if so, remove series from list and set iterator to the next item */
Iterator = SeriesList.erase(Iterator);
} else
++Iterator;
} else
++Iterator;
}
}
// --- DSRSOPInstanceReferenceList ---
DSRSOPInstanceReferenceList::DSRSOPInstanceReferenceList(const DcmTagKey &sequence)
: SequenceTag(sequence),
StudyList(),
Iterator(),
SpecificCharacterSet()
{
/* initialize list cursor */
Iterator = StudyList.end();
}
DSRSOPInstanceReferenceList::~DSRSOPInstanceReferenceList()
{
/* clear reference list and delete allocated memory */
clear();
}
void DSRSOPInstanceReferenceList::clear()
{
Iterator = StudyList.begin();
const OFListIterator(StudyStruct *) last = StudyList.end();
/* delete all items and free memory */
while (Iterator != last)
{
delete (*Iterator);
Iterator = StudyList.erase(Iterator);
}
/* make sure that the list is empty */
StudyList.clear();
Iterator = StudyList.end();
/* also clear other members */
SpecificCharacterSet.clear();
}
OFBool DSRSOPInstanceReferenceList::isEmpty() const
{
return StudyList.empty();
}
size_t DSRSOPInstanceReferenceList::getNumberOfInstances() const
{
size_t result = 0;
OFListConstIterator(StudyStruct *) iter = StudyList.begin();
const OFListConstIterator(StudyStruct *) last = StudyList.end();
/* for all studies in the list */
while (iter != last)
{
/* sum up the number of instances */
if (*iter != NULL)
result += (*iter)->getNumberOfInstances();
++iter;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::read(DcmItem &dataset,
const size_t flags)
{
/* first, check whether sequence is present and non-empty */
DcmSequenceOfItems *sequence = NULL;
OFCondition result = dataset.findAndGetSequence(SequenceTag, sequence);
checkElementValue(sequence, SequenceTag, "1-n", "1C", result);
if (result.good())
{
OFString sequenceName = DcmTag(SequenceTag).getTagName();
/* iterate over all sequence items */
DcmObject *object = NULL;
while ((object = sequence->nextInContainer(object)) != NULL)
{
DcmItem *item = OFstatic_cast(DcmItem *, object);
/* get the study instance UID */
OFString studyUID;
if (getAndCheckStringValueFromDataset(*item, DCM_StudyInstanceUID, studyUID, "1", "1", sequenceName.c_str()).good())
{
/* check whether study item already exists,
because the internal structure is organized in a strictly hierarchical manner */
StudyStruct *study = gotoStudy(studyUID);
if (study == NULL)
{
/* if not, create a new study list item */
study = new StudyStruct(studyUID);
if (study != NULL)
{
/* and add it to the list of studies */
StudyList.push_back(study);
} else {
result = EC_MemoryExhausted;
break;
}
}
if (study != NULL)
{
/* set cursor to new position */
Iterator = --StudyList.end();
/* read attributes on series and instance level */
result = study->read(*item, flags);
}
}
}
/* remove empty/incomplete items from the list structure */
removeIncompleteItems();
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::write(DcmItem &dataset) const
{
OFCondition result = EC_Normal;
/* iterate over all list items */
OFListConstIterator(StudyStruct *) iter = StudyList.begin();
const OFListConstIterator(StudyStruct *) last = StudyList.end();
while ((iter != last) && result.good())
{
StudyStruct *study = *iter;
/* check whether list item really exists */
if (study != NULL)
{
DcmItem *item = NULL;
/* create a new item (and a sequence if required) */
result = dataset.findOrCreateSequenceItem(SequenceTag, item, -2 /*append new*/);
/* write study, series and instance level */
if (result.good())
result = study->write(*item);
}
iter++;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::readXML(const DSRXMLDocument &doc,
DSRXMLCursor cursor,
const size_t flags)
{
/* default: no error, e.g. for empty list of references */
OFCondition result = EC_Normal;
if (cursor.valid())
{
OFString studyUID;
while (cursor.valid())
{
/* check for known element tags */
if (doc.checkNode(cursor, "study").good())
{
if (!doc.getStringFromAttribute(cursor, studyUID, "uid").empty())
{
/* check whether study item already exists,
because the internal structure is organized in a strictly hierarchical manner */
StudyStruct *study = gotoStudy(studyUID);
if (study == NULL)
{
/* if not, create a new study list item */
study = new StudyStruct(studyUID);
if (study != NULL)
{
/* and add it to the list of studies */
StudyList.push_back(study);
} else {
result = EC_MemoryExhausted;
break;
}
}
if (study != NULL)
{
/* set cursor to new position */
Iterator = --StudyList.end();
/* read attributes on series and instance level */
result = study->readXML(doc, cursor.getChild(), flags);
}
}
}
/* proceed with next node */
cursor.gotoNext();
}
/* remove empty/incomplete items from the list structure */
removeIncompleteItems();
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::writeXML(STD_NAMESPACE ostream &stream,
const size_t flags) const
{
OFCondition result = EC_Normal;
/* iterate over all list items */
OFListConstIterator(StudyStruct *) iter = StudyList.begin();
const OFListConstIterator(StudyStruct *) last = StudyList.end();
while ((iter != last) && result.good())
{
StudyStruct *study = *iter;
/* check whether list item really exists */
if (study != NULL)
{
/* write study, series and instance level */
result = study->writeXML(stream, flags);
}
iter++;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::setSpecificCharacterSet(const OFString &value,
const OFBool check)
{
OFCondition result = (check) ? DcmCodeString::checkStringValue(value, "1-n") : EC_Normal;
if (result.good())
SpecificCharacterSet = value;
return result;
}
DSRSOPInstanceReferenceList::StudyStruct *DSRSOPInstanceReferenceList::gotoStudy(const OFString &studyUID)
{
StudyStruct *study = NULL;
/* first, check whether the current study is the one we're searching for */
if ((Iterator != StudyList.end()) && (*Iterator != NULL) && ((*Iterator)->StudyUID == studyUID))
study = *Iterator;
else
{
/* start with the first list item */
Iterator = StudyList.begin();
const OFListIterator(StudyStruct *) last = StudyList.end();
/* search for given study UID */
while ((Iterator != last) && ((*Iterator == NULL) || ((*Iterator)->StudyUID != studyUID)))
Iterator++;
/* item found */
if (Iterator != last)
study = *Iterator;
}
return study;
}
OFCondition DSRSOPInstanceReferenceList::addItem(const OFString &studyUID,
const OFString &seriesUID,
const OFString &sopClassUID,
const OFString &instanceUID,
const OFBool check)
{
OFCondition result = EC_Normal;
/* check parameters first */
if (check)
{
/* check whether the passed values are valid */
result = checkSOPInstance(studyUID, seriesUID, sopClassUID, instanceUID);
} else {
/* make sure that the mandatory values are non-empty */
if (studyUID.empty() || seriesUID.empty() || sopClassUID.empty() || instanceUID.empty())
result = EC_IllegalParameter;
}
if (result.good())
{
StudyStruct *study = gotoStudy(studyUID);
/* check whether study already exists */
if (study == NULL)
{
/* if not create new study item and add it to the list */
study = new StudyStruct(studyUID);
if (study != NULL)
{
StudyList.push_back(study);
/* set cursor to new position */
Iterator = --StudyList.end();
} else
result = EC_MemoryExhausted;
}
/* do the same for the series and instance level */
if (study != NULL)
result = study->addItem(seriesUID, sopClassUID, instanceUID);
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::addItem(DcmItem &dataset,
const OFBool check)
{
OFString studyUID, seriesUID, sopClassUID, instanceUID;
/* retrieve element values from dataset */
getStringValueFromDataset(dataset, DCM_StudyInstanceUID, studyUID);
getStringValueFromDataset(dataset, DCM_SeriesInstanceUID, seriesUID);
getStringValueFromDataset(dataset, DCM_SOPClassUID, sopClassUID);
getStringValueFromDataset(dataset, DCM_SOPInstanceUID, instanceUID);
/* add new item to the list of references (if valid) */
return addItem(studyUID, seriesUID, sopClassUID, instanceUID, check);
}
OFCondition DSRSOPInstanceReferenceList::removeItem()
{
OFCondition result = EC_IllegalCall;
/* check whether list is empty or iterator is invalid */
if (!StudyList.empty() && (Iterator != StudyList.end()))
{
StudyStruct *study = *Iterator;
if (study != NULL)
{
result = study->removeItem();
/* check whether lower level list has become empty */
if (result.good() && study->SeriesList.empty())
{
/* free memory */
delete study;
/* if so, remove study from list and set iterator to the next item */
Iterator = StudyList.erase(Iterator);
}
}
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::removeItem(const OFString &sopClassUID,
const OFString &instanceUID)
{
/* goto specified item ... */
OFCondition result = gotoItem(sopClassUID, instanceUID);
/* ... and remove it */
if (result.good())
result = removeItem();
return result;
}
OFCondition DSRSOPInstanceReferenceList::removeItem(const OFString &studyUID,
const OFString &seriesUID,
const OFString &instanceUID)
{
/* goto specified item ... */
OFCondition result = gotoItem(studyUID, seriesUID, instanceUID);
/* ... and remove it */
if (result.good())
result = removeItem();
return result;
}
void DSRSOPInstanceReferenceList::removeIncompleteItems()
{
Iterator = StudyList.begin();
const OFListIterator(StudyStruct *) last = StudyList.end();
/* for all studies in the list */
while (Iterator != last)
{
StudyStruct *study = *Iterator;
if (study != NULL)
{
/* remove empty/incomplete items on series/instance level */
study->removeIncompleteItems();
/* check whether list of series is empty */
if (study->SeriesList.empty())
{
/* free memory */
delete study;
/* if so, remove study from list and set iterator to the next item */
Iterator = StudyList.erase(Iterator);
} else
++Iterator;
} else
++Iterator;
}
}
OFCondition DSRSOPInstanceReferenceList::gotoItem(const OFString &sopClassUID,
const OFString &instanceUID)
{
OFCondition result = EC_IllegalParameter;
/* check parameters first */
if (!sopClassUID.empty() && !instanceUID.empty())
{
OFBool sopClassMatch = OFFalse;
result = SR_EC_SOPInstanceNotFound;
/* start with first study */
Iterator = StudyList.begin();
const OFListIterator(StudyStruct *) last = StudyList.end();
/* iterate over all studies */
while ((Iterator != last) && result.bad())
{
StudyStruct *study = *Iterator;
/* continue search on series level */
if (study != NULL)
{
InstanceStruct *instance = study->gotoInstance(instanceUID);
/* if instance found, exit loop */
if (instance != NULL)
{
/* finally, check whether SOP class matches */
sopClassMatch = (instance->SOPClassUID == sopClassUID);
result = EC_Normal;
} else
Iterator ++;
} else
Iterator++;
}
/* report an error in case of SOP class mismatch */
if (result.good() && !sopClassMatch)
result = SR_EC_DifferentSOPClassesForAnInstance;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::gotoItem(const OFString &studyUID,
const OFString &seriesUID,
const OFString &instanceUID)
{
OFCondition result = EC_IllegalParameter;
/* check parameters first */
if (!studyUID.empty() && !seriesUID.empty() && !instanceUID.empty())
{
result = SR_EC_SOPInstanceNotFound;
/* search for given study */
StudyStruct *study = gotoStudy(studyUID);
if (study != NULL)
{
/* do the same for the series ... */
SeriesStruct *series = study->gotoSeries(seriesUID);
if (series != NULL)
{
/* ... and instance level */
if (series->gotoInstance(instanceUID) != NULL)
result = EC_Normal;
}
}
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::gotoFirstItem()
{
OFCondition result = EC_IllegalCall;
/* check for empty study list */
if (!StudyList.empty())
{
/* set cursor to first list item */
Iterator = StudyList.begin();
if (*Iterator != NULL)
{
/* do the same for series and instance level */
result = (*Iterator)->gotoFirstItem();
}
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::gotoNextItem()
{
OFCondition result = EC_IllegalCall;
/* goto next list item */
if (Iterator != StudyList.end())
{
/* check whether current list item is valid */
if (*Iterator != NULL)
{
/* try to go to the next instance item */
result = (*Iterator)->gotoNextItem();
/* if this fails ... */
if (result.bad())
{
/* goto to the first series/instance of the next stidy item */
if (++Iterator != StudyList.end())
{
if (*Iterator != NULL)
result = (*Iterator)->gotoFirstItem();
}
}
} else
result = EC_CorruptedData;
}
return result;
}
DSRSOPInstanceReferenceList::StudyStruct *DSRSOPInstanceReferenceList::getCurrentStudy() const
{
StudyStruct *study = NULL;
/* check whether current study is valid */
OFListConstIterator(StudyStruct *) it = Iterator;
if (it != StudyList.end())
study = *Iterator;
return study;
}
DSRSOPInstanceReferenceList::SeriesStruct *DSRSOPInstanceReferenceList::getCurrentSeries() const
{
SeriesStruct *series = NULL;
StudyStruct *study = getCurrentStudy();
/* check whether current series is valid */
if ((study != NULL) && (study->Iterator != study->SeriesList.end()))
series = *(study->Iterator);
return series;
}
DSRSOPInstanceReferenceList::InstanceStruct *DSRSOPInstanceReferenceList::getCurrentInstance() const
{
InstanceStruct *instance = NULL;
SeriesStruct *series = getCurrentSeries();
/* check whether current instance is valid */
if ((series != NULL) && (series->Iterator != series->InstanceList.end()))
instance = *(series->Iterator);
return instance;
}
const OFString &DSRSOPInstanceReferenceList::getStudyInstanceUID(OFString &stringValue) const
{
/* check whether current study is valid */
StudyStruct *study = getCurrentStudy();
/* get study instance UID or clear string if invalid */
if (study != NULL)
stringValue = study->StudyUID;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRSOPInstanceReferenceList::getSeriesInstanceUID(OFString &stringValue) const
{
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
/* get series instance UID or clear string if invalid */
if (series != NULL)
stringValue = series->SeriesUID;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRSOPInstanceReferenceList::getSOPInstanceUID(OFString &stringValue) const
{
/* check whether current instance is valid */
InstanceStruct *instance = getCurrentInstance();
/* get SOP instance UID or clear string if invalid */
if (instance != NULL)
stringValue = instance->InstanceUID;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRSOPInstanceReferenceList::getSOPClassUID(OFString &stringValue) const
{
/* check whether current instance is valid */
InstanceStruct *instance = getCurrentInstance();
/* get SOP class UID or clear string if invalid */
if (instance != NULL)
stringValue = instance->SOPClassUID;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRSOPInstanceReferenceList::getSOPClassName(OFString &stringValue,
const OFString &defaultName) const
{
OFString sopClassUID;
/* retrieve SOP class UID of current entry */
if (!getSOPClassUID(sopClassUID).empty())
{
/* lookup name associated with the SOP class UID */
stringValue = dcmFindNameOfUID(sopClassUID.c_str(), defaultName.c_str());
} else
stringValue.clear();
return stringValue;
}
const OFString &DSRSOPInstanceReferenceList::getRetrieveAETitle(OFString &stringValue) const
{
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
/* get retrieve application entity title or clear string if invalid */
if (series != NULL)
stringValue = series->RetrieveAETitle;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRSOPInstanceReferenceList::getRetrieveLocationUID(OFString &stringValue) const
{
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
/* get retrieve location UID or clear string if invalid */
if (series != NULL)
stringValue = series->RetrieveLocationUID;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRSOPInstanceReferenceList::getStorageMediaFileSetID(OFString &stringValue) const
{
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
/* get storage media file set ID or clear string if invalid */
if (series != NULL)
stringValue = series->StorageMediaFileSetID;
else
stringValue.clear();
return stringValue;
}
const OFString &DSRSOPInstanceReferenceList::getStorageMediaFileSetUID(OFString &stringValue) const
{
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
/* get storage media file set UID or clear string if invalid */
if (series != NULL)
stringValue = series->StorageMediaFileSetUID;
else
stringValue.clear();
return stringValue;
}
OFCondition DSRSOPInstanceReferenceList::getPurposeOfReference(DSRCodedEntryValue &codeValue) const
{
OFCondition result = EC_IllegalCall;
/* check whether current instance is valid */
InstanceStruct *instance = getCurrentInstance();
if (instance != NULL)
{
codeValue = instance->PurposeOfReference;
result = EC_Normal;
} else
codeValue.clear();
return result;
}
OFCondition DSRSOPInstanceReferenceList::setRetrieveAETitle(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
if (series != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmApplicationEntity::checkStringValue(value, "1-n") : EC_Normal;
if (result.good())
series->RetrieveAETitle = value;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::setRetrieveLocationUID(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
if (series != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmUniqueIdentifier::checkStringValue(value, "1") : EC_Normal;
if (result.good())
series->RetrieveLocationUID = value;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::setStorageMediaFileSetID(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
if (series != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmShortString::checkStringValue(value, "1", SpecificCharacterSet) : EC_Normal;
if (result.good())
series->StorageMediaFileSetID = value;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::setStorageMediaFileSetUID(const OFString &value,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current series is valid */
SeriesStruct *series = getCurrentSeries();
if (series != NULL)
{
/* set the value (if valid) */
result = (check) ? DcmUniqueIdentifier::checkStringValue(value, "1") : EC_Normal;
if (result.good())
series->StorageMediaFileSetUID = value;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::setPurposeOfReference(const DSRCodedEntryValue &codeValue,
const OFBool check)
{
OFCondition result = EC_IllegalCall;
/* check whether current instance is valid */
InstanceStruct *instance = getCurrentInstance();
if (instance != NULL)
{
if (check)
{
/* check whether the passed value is valid */
result = checkPurposeOfReference(codeValue);
} else {
/* make sure that the mandatory values are non-empty */
result = codeValue.isEmpty() ? SR_EC_InvalidValue : EC_Normal;
}
if (result.good())
instance->PurposeOfReference = codeValue;
}
return result;
}
OFCondition DSRSOPInstanceReferenceList::checkSOPInstance(const OFString &studyUID,
const OFString &seriesUID,
const OFString &sopClassUID,
const OFString &instanceUID) const
{
OFCondition result = EC_Normal;
/* the four UID values should never be empty */
if (studyUID.empty() || seriesUID.empty() || sopClassUID.empty() || instanceUID.empty())
result = SR_EC_InvalidValue;
/* check for conformance with VR and VM */
if (result.good())
result = DcmUniqueIdentifier::checkStringValue(studyUID, "1");
if (result.good())
result = DcmUniqueIdentifier::checkStringValue(seriesUID, "1");
if (result.good())
result = DcmUniqueIdentifier::checkStringValue(sopClassUID, "1");
if (result.good())
result = DcmUniqueIdentifier::checkStringValue(instanceUID, "1");
return result;
}
OFCondition DSRSOPInstanceReferenceList::checkPurposeOfReference(const DSRCodedEntryValue &purposeOfReference) const
{
/* purpose of reference can be empty */
return purposeOfReference.isEmpty() ? EC_Normal
: purposeOfReference.checkCurrentValue();
}
|