Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 1294:910478b2d4e4
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 06 Feb 2015 13:48:05 +0100 |
parents | 6e7e5ed91c2d |
children | 501432928727 |
comparison
equal
deleted
inserted
replaced
1293:21779cebbb96 | 1294:910478b2d4e4 |
---|---|
304 | 304 |
305 Transaction t(*this); | 305 Transaction t(*this); |
306 | 306 |
307 int64_t id; | 307 int64_t id; |
308 ResourceType type; | 308 ResourceType type; |
309 if (!db_.LookupResource(uuid, id, type) || | 309 if (!db_.LookupResource(id, type, uuid) || |
310 expectedType != type) | 310 expectedType != type) |
311 { | 311 { |
312 return false; | 312 return false; |
313 } | 313 } |
314 | 314 |
539 | 539 |
540 // Do nothing if the instance already exists | 540 // Do nothing if the instance already exists |
541 { | 541 { |
542 ResourceType type; | 542 ResourceType type; |
543 int64_t tmp; | 543 int64_t tmp; |
544 if (db_.LookupResource(hasher.HashInstance(), tmp, type)) | 544 if (db_.LookupResource(tmp, type, hasher.HashInstance())) |
545 { | 545 { |
546 assert(type == ResourceType_Instance); | 546 assert(type == ResourceType_Instance); |
547 db_.GetAllMetadata(instanceMetadata, tmp); | 547 db_.GetAllMetadata(instanceMetadata, tmp); |
548 return StoreStatus_AlreadyStored; | 548 return StoreStatus_AlreadyStored; |
549 } | 549 } |
574 bool isNewSeries = false; | 574 bool isNewSeries = false; |
575 | 575 |
576 { | 576 { |
577 ResourceType dummy; | 577 ResourceType dummy; |
578 | 578 |
579 if (db_.LookupResource(hasher.HashSeries(), series, dummy)) | 579 if (db_.LookupResource(series, dummy, hasher.HashSeries())) |
580 { | 580 { |
581 assert(dummy == ResourceType_Series); | 581 assert(dummy == ResourceType_Series); |
582 // The patient, the study and the series already exist | 582 // The patient, the study and the series already exist |
583 | 583 |
584 bool ok = (db_.LookupResource(hasher.HashPatient(), patient, dummy) && | 584 bool ok = (db_.LookupResource(patient, dummy, hasher.HashPatient()) && |
585 db_.LookupResource(hasher.HashStudy(), study, dummy)); | 585 db_.LookupResource(study, dummy, hasher.HashStudy())); |
586 assert(ok); | 586 assert(ok); |
587 } | 587 } |
588 else if (db_.LookupResource(hasher.HashStudy(), study, dummy)) | 588 else if (db_.LookupResource(study, dummy, hasher.HashStudy())) |
589 { | 589 { |
590 assert(dummy == ResourceType_Study); | 590 assert(dummy == ResourceType_Study); |
591 | 591 |
592 // New series: The patient and the study already exist | 592 // New series: The patient and the study already exist |
593 isNewSeries = true; | 593 isNewSeries = true; |
594 | 594 |
595 bool ok = db_.LookupResource(hasher.HashPatient(), patient, dummy); | 595 bool ok = db_.LookupResource(patient, dummy, hasher.HashPatient()); |
596 assert(ok); | 596 assert(ok); |
597 } | 597 } |
598 else if (db_.LookupResource(hasher.HashPatient(), patient, dummy)) | 598 else if (db_.LookupResource(patient, dummy, hasher.HashPatient())) |
599 { | 599 { |
600 assert(dummy == ResourceType_Patient); | 600 assert(dummy == ResourceType_Patient); |
601 | 601 |
602 // New study and series: The patient already exist | 602 // New study and series: The patient already exist |
603 isNewStudy = true; | 603 isNewStudy = true; |
832 boost::mutex::scoped_lock lock(mutex_); | 832 boost::mutex::scoped_lock lock(mutex_); |
833 | 833 |
834 // Lookup for the requested resource | 834 // Lookup for the requested resource |
835 int64_t id; | 835 int64_t id; |
836 ResourceType type; | 836 ResourceType type; |
837 if (!db_.LookupResource(publicId, id, type) || | 837 if (!db_.LookupResource(id, type, publicId) || |
838 type != expectedType) | 838 type != expectedType) |
839 { | 839 { |
840 return false; | 840 return false; |
841 } | 841 } |
842 | 842 |
992 { | 992 { |
993 boost::mutex::scoped_lock lock(mutex_); | 993 boost::mutex::scoped_lock lock(mutex_); |
994 | 994 |
995 int64_t id; | 995 int64_t id; |
996 ResourceType type; | 996 ResourceType type; |
997 if (!db_.LookupResource(instanceUuid, id, type)) | 997 if (!db_.LookupResource(id, type, instanceUuid)) |
998 { | 998 { |
999 throw OrthancException(ErrorCode_UnknownResource); | 999 throw OrthancException(ErrorCode_UnknownResource); |
1000 } | 1000 } |
1001 | 1001 |
1002 if (db_.LookupAttachment(attachment, id, contentType)) | 1002 if (db_.LookupAttachment(attachment, id, contentType)) |
1090 { | 1090 { |
1091 boost::mutex::scoped_lock lock(mutex_); | 1091 boost::mutex::scoped_lock lock(mutex_); |
1092 | 1092 |
1093 int64_t id; | 1093 int64_t id; |
1094 ResourceType type; | 1094 ResourceType type; |
1095 if (!db_.LookupResource(publicId, id, type)) | 1095 if (!db_.LookupResource(id, type, publicId)) |
1096 { | 1096 { |
1097 throw OrthancException(ErrorCode_InternalError); | 1097 throw OrthancException(ErrorCode_InternalError); |
1098 } | 1098 } |
1099 | 1099 |
1100 std::string patientId; | 1100 std::string patientId; |
1226 | 1226 |
1227 // Check whether other DICOM instances from this patient are | 1227 // Check whether other DICOM instances from this patient are |
1228 // already stored | 1228 // already stored |
1229 int64_t patientToAvoid; | 1229 int64_t patientToAvoid; |
1230 ResourceType type; | 1230 ResourceType type; |
1231 bool hasPatientToAvoid = db_.LookupResource(newPatientId, patientToAvoid, type); | 1231 bool hasPatientToAvoid = db_.LookupResource(patientToAvoid, type, newPatientId); |
1232 | 1232 |
1233 if (hasPatientToAvoid && type != ResourceType_Patient) | 1233 if (hasPatientToAvoid && type != ResourceType_Patient) |
1234 { | 1234 { |
1235 throw OrthancException(ErrorCode_InternalError); | 1235 throw OrthancException(ErrorCode_InternalError); |
1236 } | 1236 } |
1310 boost::mutex::scoped_lock lock(mutex_); | 1310 boost::mutex::scoped_lock lock(mutex_); |
1311 | 1311 |
1312 // Lookup for the requested resource | 1312 // Lookup for the requested resource |
1313 int64_t id; | 1313 int64_t id; |
1314 ResourceType type; | 1314 ResourceType type; |
1315 if (!db_.LookupResource(publicId, id, type) || | 1315 if (!db_.LookupResource(id, type, publicId) || |
1316 type != ResourceType_Patient) | 1316 type != ResourceType_Patient) |
1317 { | 1317 { |
1318 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1318 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1319 } | 1319 } |
1320 | 1320 |
1328 boost::mutex::scoped_lock lock(mutex_); | 1328 boost::mutex::scoped_lock lock(mutex_); |
1329 | 1329 |
1330 // Lookup for the requested resource | 1330 // Lookup for the requested resource |
1331 int64_t id; | 1331 int64_t id; |
1332 ResourceType type; | 1332 ResourceType type; |
1333 if (!db_.LookupResource(publicId, id, type) || | 1333 if (!db_.LookupResource(id, type, publicId) || |
1334 type != ResourceType_Patient) | 1334 type != ResourceType_Patient) |
1335 { | 1335 { |
1336 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1336 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1337 } | 1337 } |
1338 | 1338 |
1353 | 1353 |
1354 boost::mutex::scoped_lock lock(mutex_); | 1354 boost::mutex::scoped_lock lock(mutex_); |
1355 | 1355 |
1356 ResourceType type; | 1356 ResourceType type; |
1357 int64_t resource; | 1357 int64_t resource; |
1358 if (!db_.LookupResource(publicId, resource, type)) | 1358 if (!db_.LookupResource(resource, type, publicId)) |
1359 { | 1359 { |
1360 throw OrthancException(ErrorCode_UnknownResource); | 1360 throw OrthancException(ErrorCode_UnknownResource); |
1361 } | 1361 } |
1362 | 1362 |
1363 if (type == ResourceType_Instance) | 1363 if (type == ResourceType_Instance) |
1384 | 1384 |
1385 boost::mutex::scoped_lock lock(mutex_); | 1385 boost::mutex::scoped_lock lock(mutex_); |
1386 | 1386 |
1387 ResourceType type; | 1387 ResourceType type; |
1388 int64_t top; | 1388 int64_t top; |
1389 if (!db_.LookupResource(publicId, top, type)) | 1389 if (!db_.LookupResource(top, type, publicId)) |
1390 { | 1390 { |
1391 throw OrthancException(ErrorCode_UnknownResource); | 1391 throw OrthancException(ErrorCode_UnknownResource); |
1392 } | 1392 } |
1393 | 1393 |
1394 if (type == ResourceType_Instance) | 1394 if (type == ResourceType_Instance) |
1433 { | 1433 { |
1434 boost::mutex::scoped_lock lock(mutex_); | 1434 boost::mutex::scoped_lock lock(mutex_); |
1435 | 1435 |
1436 ResourceType rtype; | 1436 ResourceType rtype; |
1437 int64_t id; | 1437 int64_t id; |
1438 if (!db_.LookupResource(publicId, id, rtype)) | 1438 if (!db_.LookupResource(id, rtype, publicId)) |
1439 { | 1439 { |
1440 throw OrthancException(ErrorCode_UnknownResource); | 1440 throw OrthancException(ErrorCode_UnknownResource); |
1441 } | 1441 } |
1442 | 1442 |
1443 db_.SetMetadata(id, type, value); | 1443 db_.SetMetadata(id, type, value); |
1449 { | 1449 { |
1450 boost::mutex::scoped_lock lock(mutex_); | 1450 boost::mutex::scoped_lock lock(mutex_); |
1451 | 1451 |
1452 ResourceType rtype; | 1452 ResourceType rtype; |
1453 int64_t id; | 1453 int64_t id; |
1454 if (!db_.LookupResource(publicId, id, rtype)) | 1454 if (!db_.LookupResource(id, rtype, publicId)) |
1455 { | 1455 { |
1456 throw OrthancException(ErrorCode_UnknownResource); | 1456 throw OrthancException(ErrorCode_UnknownResource); |
1457 } | 1457 } |
1458 | 1458 |
1459 db_.DeleteMetadata(id, type); | 1459 db_.DeleteMetadata(id, type); |
1466 { | 1466 { |
1467 boost::mutex::scoped_lock lock(mutex_); | 1467 boost::mutex::scoped_lock lock(mutex_); |
1468 | 1468 |
1469 ResourceType rtype; | 1469 ResourceType rtype; |
1470 int64_t id; | 1470 int64_t id; |
1471 if (!db_.LookupResource(publicId, id, rtype)) | 1471 if (!db_.LookupResource(id, rtype, publicId)) |
1472 { | 1472 { |
1473 throw OrthancException(ErrorCode_UnknownResource); | 1473 throw OrthancException(ErrorCode_UnknownResource); |
1474 } | 1474 } |
1475 | 1475 |
1476 return db_.LookupMetadata(target, id, type); | 1476 return db_.LookupMetadata(target, id, type); |
1482 { | 1482 { |
1483 boost::mutex::scoped_lock lock(mutex_); | 1483 boost::mutex::scoped_lock lock(mutex_); |
1484 | 1484 |
1485 ResourceType rtype; | 1485 ResourceType rtype; |
1486 int64_t id; | 1486 int64_t id; |
1487 if (!db_.LookupResource(publicId, id, rtype)) | 1487 if (!db_.LookupResource(id, rtype, publicId)) |
1488 { | 1488 { |
1489 throw OrthancException(ErrorCode_UnknownResource); | 1489 throw OrthancException(ErrorCode_UnknownResource); |
1490 } | 1490 } |
1491 | 1491 |
1492 db_.ListAvailableMetadata(target, id); | 1492 db_.ListAvailableMetadata(target, id); |
1499 { | 1499 { |
1500 boost::mutex::scoped_lock lock(mutex_); | 1500 boost::mutex::scoped_lock lock(mutex_); |
1501 | 1501 |
1502 ResourceType type; | 1502 ResourceType type; |
1503 int64_t id; | 1503 int64_t id; |
1504 if (!db_.LookupResource(publicId, id, type) || | 1504 if (!db_.LookupResource(id, type, publicId) || |
1505 expectedType != type) | 1505 expectedType != type) |
1506 { | 1506 { |
1507 throw OrthancException(ErrorCode_UnknownResource); | 1507 throw OrthancException(ErrorCode_UnknownResource); |
1508 } | 1508 } |
1509 | 1509 |
1516 { | 1516 { |
1517 boost::mutex::scoped_lock lock(mutex_); | 1517 boost::mutex::scoped_lock lock(mutex_); |
1518 | 1518 |
1519 ResourceType type; | 1519 ResourceType type; |
1520 int64_t id; | 1520 int64_t id; |
1521 if (!db_.LookupResource(publicId, id, type)) | 1521 if (!db_.LookupResource(id, type, publicId)) |
1522 { | 1522 { |
1523 throw OrthancException(ErrorCode_UnknownResource); | 1523 throw OrthancException(ErrorCode_UnknownResource); |
1524 } | 1524 } |
1525 | 1525 |
1526 int64_t parentId; | 1526 int64_t parentId; |
1558 std::auto_ptr<SQLite::ITransaction> transaction(db_.StartTransaction()); | 1558 std::auto_ptr<SQLite::ITransaction> transaction(db_.StartTransaction()); |
1559 transaction->Begin(); | 1559 transaction->Begin(); |
1560 | 1560 |
1561 int64_t id; | 1561 int64_t id; |
1562 ResourceType type; | 1562 ResourceType type; |
1563 if (!db_.LookupResource(publicId, id, type)) | 1563 if (!db_.LookupResource(id, type, publicId)) |
1564 { | 1564 { |
1565 throw OrthancException(ErrorCode_UnknownResource); | 1565 throw OrthancException(ErrorCode_UnknownResource); |
1566 } | 1566 } |
1567 | 1567 |
1568 LogChange(id, changeType, type, publicId); | 1568 LogChange(id, changeType, type, publicId); |
1672 { | 1672 { |
1673 boost::mutex::scoped_lock lock(mutex_); | 1673 boost::mutex::scoped_lock lock(mutex_); |
1674 | 1674 |
1675 ResourceType type; | 1675 ResourceType type; |
1676 int64_t top; | 1676 int64_t top; |
1677 if (!db_.LookupResource(publicId, top, type)) | 1677 if (!db_.LookupResource(top, type, publicId)) |
1678 { | 1678 { |
1679 throw OrthancException(ErrorCode_UnknownResource); | 1679 throw OrthancException(ErrorCode_UnknownResource); |
1680 } | 1680 } |
1681 | 1681 |
1682 uint64_t uncompressedSize; | 1682 uint64_t uncompressedSize; |
1721 { | 1721 { |
1722 boost::mutex::scoped_lock lock(mutex_); | 1722 boost::mutex::scoped_lock lock(mutex_); |
1723 | 1723 |
1724 ResourceType type; | 1724 ResourceType type; |
1725 int64_t top; | 1725 int64_t top; |
1726 if (!db_.LookupResource(publicId, top, type)) | 1726 if (!db_.LookupResource(top, type, publicId)) |
1727 { | 1727 { |
1728 throw OrthancException(ErrorCode_UnknownResource); | 1728 throw OrthancException(ErrorCode_UnknownResource); |
1729 } | 1729 } |
1730 | 1730 |
1731 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies, | 1731 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies, |
1876 | 1876 |
1877 Transaction t(*this); | 1877 Transaction t(*this); |
1878 | 1878 |
1879 ResourceType resourceType; | 1879 ResourceType resourceType; |
1880 int64_t resourceId; | 1880 int64_t resourceId; |
1881 if (!db_.LookupResource(publicId, resourceId, resourceType)) | 1881 if (!db_.LookupResource(resourceId, resourceType, publicId)) |
1882 { | 1882 { |
1883 return StoreStatus_Failure; // Inexistent resource | 1883 return StoreStatus_Failure; // Inexistent resource |
1884 } | 1884 } |
1885 | 1885 |
1886 // Remove possible previous attachment | 1886 // Remove possible previous attachment |
1922 | 1922 |
1923 Transaction t(*this); | 1923 Transaction t(*this); |
1924 | 1924 |
1925 ResourceType rtype; | 1925 ResourceType rtype; |
1926 int64_t id; | 1926 int64_t id; |
1927 if (!db_.LookupResource(publicId, id, rtype)) | 1927 if (!db_.LookupResource(id, rtype, publicId)) |
1928 { | 1928 { |
1929 throw OrthancException(ErrorCode_UnknownResource); | 1929 throw OrthancException(ErrorCode_UnknownResource); |
1930 } | 1930 } |
1931 | 1931 |
1932 db_.DeleteAttachment(id, type); | 1932 db_.DeleteAttachment(id, type); |
1942 | 1942 |
1943 target = Json::objectValue; | 1943 target = Json::objectValue; |
1944 | 1944 |
1945 ResourceType type; | 1945 ResourceType type; |
1946 int64_t id; | 1946 int64_t id; |
1947 if (!db_.LookupResource(publicId, id, type)) | 1947 if (!db_.LookupResource(id, type, publicId)) |
1948 { | 1948 { |
1949 return false; | 1949 return false; |
1950 } | 1950 } |
1951 | 1951 |
1952 std::list<MetadataType> metadata; | 1952 std::list<MetadataType> metadata; |