Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 758:67e6400fca03 query-retrieve
integration mainline -> query-retrieve
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Apr 2014 16:34:09 +0200 |
parents | 3bdb5db8e839 ec69658b031b |
children | c2c28dd17e87 |
comparison
equal
deleted
inserted
replaced
681:3bdb5db8e839 | 758:67e6400fca03 |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
4 * Belgium | 4 * Belgium |
5 * | 5 * |
6 * This program is free software: you can redistribute it and/or | 6 * This program is free software: you can redistribute it and/or |
7 * modify it under the terms of the GNU General Public License as | 7 * modify it under the terms of the GNU General Public License as |
8 * published by the Free Software Foundation, either version 3 of the | 8 * published by the Free Software Foundation, either version 3 of the |
253 { | 253 { |
254 unsigned int sleep; | 254 unsigned int sleep; |
255 | 255 |
256 try | 256 try |
257 { | 257 { |
258 boost::mutex::scoped_lock lock(that->mutex_); | |
258 std::string sleepString = that->db_->GetGlobalProperty(GlobalProperty_FlushSleep); | 259 std::string sleepString = that->db_->GetGlobalProperty(GlobalProperty_FlushSleep); |
259 sleep = boost::lexical_cast<unsigned int>(sleepString); | 260 sleep = boost::lexical_cast<unsigned int>(sleepString); |
260 } | 261 } |
261 catch (boost::bad_lexical_cast&) | 262 catch (boost::bad_lexical_cast&) |
262 { | 263 { |
817 { | 818 { |
818 boost::mutex::scoped_lock lock(mutex_); | 819 boost::mutex::scoped_lock lock(mutex_); |
819 | 820 |
820 int64_t id; | 821 int64_t id; |
821 ResourceType type; | 822 ResourceType type; |
822 if (!db_->LookupResource(instanceUuid, id, type) || | 823 if (!db_->LookupResource(instanceUuid, id, type)) |
823 type != ResourceType_Instance) | |
824 { | 824 { |
825 throw OrthancException(ErrorCode_InternalError); | 825 throw OrthancException(ErrorCode_InternalError); |
826 } | 826 } |
827 | 827 |
828 if (db_->LookupAttachment(attachment, id, contentType)) | 828 if (db_->LookupAttachment(attachment, id, contentType)) |
1106 else | 1106 else |
1107 LOG(INFO) << "Patient " << publicId << " has been unprotected"; | 1107 LOG(INFO) << "Patient " << publicId << " has been unprotected"; |
1108 } | 1108 } |
1109 | 1109 |
1110 | 1110 |
1111 void ServerIndex::GetChildren(std::list<std::string>& result, | |
1112 const std::string& publicId) | |
1113 { | |
1114 result.clear(); | |
1115 | |
1116 boost::mutex::scoped_lock lock(mutex_); | |
1117 | |
1118 ResourceType type; | |
1119 int64_t resource; | |
1120 if (!db_->LookupResource(publicId, resource, type)) | |
1121 { | |
1122 throw OrthancException(ErrorCode_UnknownResource); | |
1123 } | |
1124 | |
1125 if (type == ResourceType_Instance) | |
1126 { | |
1127 // An instance cannot have a child | |
1128 throw OrthancException(ErrorCode_BadParameterType); | |
1129 } | |
1130 | |
1131 std::list<int64_t> tmp; | |
1132 db_->GetChildrenInternalId(tmp, resource); | |
1133 | |
1134 for (std::list<int64_t>::const_iterator | |
1135 it = tmp.begin(); it != tmp.end(); ++it) | |
1136 { | |
1137 result.push_back(db_->GetPublicId(*it)); | |
1138 } | |
1139 } | |
1140 | |
1141 | |
1111 void ServerIndex::GetChildInstances(std::list<std::string>& result, | 1142 void ServerIndex::GetChildInstances(std::list<std::string>& result, |
1112 const std::string& publicId) | 1143 const std::string& publicId) |
1113 { | 1144 { |
1114 result.clear(); | 1145 result.clear(); |
1115 | 1146 |
1206 | 1237 |
1207 return db_->LookupMetadata(target, id, type); | 1238 return db_->LookupMetadata(target, id, type); |
1208 } | 1239 } |
1209 | 1240 |
1210 | 1241 |
1211 bool ServerIndex::ListAvailableMetadata(std::list<MetadataType>& target, | 1242 void ServerIndex::ListAvailableMetadata(std::list<MetadataType>& target, |
1212 const std::string& publicId) | 1243 const std::string& publicId) |
1213 { | 1244 { |
1214 boost::mutex::scoped_lock lock(mutex_); | 1245 boost::mutex::scoped_lock lock(mutex_); |
1215 | 1246 |
1216 ResourceType rtype; | 1247 ResourceType rtype; |
1218 if (!db_->LookupResource(publicId, id, rtype)) | 1249 if (!db_->LookupResource(publicId, id, rtype)) |
1219 { | 1250 { |
1220 throw OrthancException(ErrorCode_UnknownResource); | 1251 throw OrthancException(ErrorCode_UnknownResource); |
1221 } | 1252 } |
1222 | 1253 |
1223 return db_->ListAvailableMetadata(target, id); | 1254 db_->ListAvailableMetadata(target, id); |
1255 } | |
1256 | |
1257 | |
1258 void ServerIndex::ListAvailableAttachments(std::list<FileContentType>& target, | |
1259 const std::string& publicId, | |
1260 ResourceType expectedType) | |
1261 { | |
1262 boost::mutex::scoped_lock lock(mutex_); | |
1263 | |
1264 ResourceType type; | |
1265 int64_t id; | |
1266 if (!db_->LookupResource(publicId, id, type) || | |
1267 expectedType != type) | |
1268 { | |
1269 throw OrthancException(ErrorCode_UnknownResource); | |
1270 } | |
1271 | |
1272 db_->ListAvailableAttachments(target, id); | |
1224 } | 1273 } |
1225 | 1274 |
1226 | 1275 |
1227 bool ServerIndex::LookupParent(std::string& target, | 1276 bool ServerIndex::LookupParent(std::string& target, |
1228 const std::string& publicId) | 1277 const std::string& publicId) |
1320 int64_t resource = toExplore.top(); | 1369 int64_t resource = toExplore.top(); |
1321 toExplore.pop(); | 1370 toExplore.pop(); |
1322 | 1371 |
1323 ResourceType thisType = db_->GetResourceType(resource); | 1372 ResourceType thisType = db_->GetResourceType(resource); |
1324 | 1373 |
1374 std::list<FileContentType> f; | |
1375 db_->ListAvailableAttachments(f, resource); | |
1376 | |
1377 for (std::list<FileContentType>::const_iterator | |
1378 it = f.begin(); it != f.end(); ++it) | |
1379 { | |
1380 FileInfo attachment; | |
1381 if (db_->LookupAttachment(attachment, resource, *it)) | |
1382 { | |
1383 compressedSize += attachment.GetCompressedSize(); | |
1384 uncompressedSize += attachment.GetUncompressedSize(); | |
1385 } | |
1386 } | |
1387 | |
1325 if (thisType == ResourceType_Instance) | 1388 if (thisType == ResourceType_Instance) |
1326 { | 1389 { |
1327 std::list<FileContentType> f; | |
1328 db_->ListAvailableAttachments(f, resource); | |
1329 | |
1330 for (std::list<FileContentType>::const_iterator | |
1331 it = f.begin(); it != f.end(); ++it) | |
1332 { | |
1333 FileInfo attachment; | |
1334 if (db_->LookupAttachment(attachment, resource, *it)) | |
1335 { | |
1336 compressedSize += attachment.GetCompressedSize(); | |
1337 uncompressedSize += attachment.GetUncompressedSize(); | |
1338 } | |
1339 } | |
1340 | |
1341 countInstances++; | 1390 countInstances++; |
1342 } | 1391 } |
1343 else | 1392 else |
1344 { | 1393 { |
1345 switch (thisType) | 1394 switch (thisType) |
1575 result.push_back(db_->GetPublicId(*it)); | 1624 result.push_back(db_->GetPublicId(*it)); |
1576 } | 1625 } |
1577 } | 1626 } |
1578 | 1627 |
1579 | 1628 |
1580 // TODO IS IT USEFUL??? | 1629 StoreStatus ServerIndex::AddAttachment(const FileInfo& attachment, |
1581 void ServerIndex::LookupTagValue(std::set<std::string>& result, | 1630 const std::string& publicId) |
1582 DicomTag tag, | 1631 { |
1583 const std::string& value, | 1632 boost::mutex::scoped_lock lock(mutex_); |
1584 ResourceType type) | 1633 |
1585 { | 1634 Transaction t(*this); |
1586 std::list<std::string> lst; | 1635 |
1587 LookupTagValue(lst, tag, value, type); | 1636 ResourceType resourceType; |
1588 | 1637 int64_t resourceId; |
1589 result.clear(); | 1638 if (!db_->LookupResource(publicId, resourceId, resourceType)) |
1590 for (std::list<std::string>::const_iterator | 1639 { |
1591 it = lst.begin(); it != lst.end(); it++) | 1640 return StoreStatus_Failure; // Inexistent resource |
1592 { | 1641 } |
1593 result.insert(*it); | 1642 |
1594 } | 1643 // Remove possible previous attachment |
1595 } | 1644 db_->DeleteAttachment(resourceId, attachment.GetContentType()); |
1596 | 1645 |
1597 | 1646 // Locate the patient of the target resource |
1598 // TODO IS IT USEFUL??? | 1647 int64_t patientId = resourceId; |
1599 void ServerIndex::LookupTagValue(std::set<std::string>& result, | 1648 for (;;) |
1600 DicomTag tag, | 1649 { |
1601 const std::string& value) | 1650 int64_t parent; |
1602 { | 1651 if (db_->LookupParent(parent, patientId)) |
1603 std::list<std::string> lst; | 1652 { |
1604 LookupTagValue(lst, tag, value); | 1653 // We have not reached the patient level yet |
1605 | 1654 patientId = parent; |
1606 result.clear(); | 1655 } |
1607 for (std::list<std::string>::const_iterator | 1656 else |
1608 it = lst.begin(); it != lst.end(); it++) | 1657 { |
1609 { | 1658 // We have reached the patient level |
1610 result.insert(*it); | 1659 break; |
1611 } | 1660 } |
1612 } | 1661 } |
1613 | 1662 |
1614 | 1663 // Possibly apply the recycling mechanism while preserving this patient |
1615 // TODO IS IT USEFUL??? | 1664 assert(db_->GetResourceType(patientId) == ResourceType_Patient); |
1616 void ServerIndex::LookupTagValue(std::set<std::string>& result, | 1665 Recycle(attachment.GetCompressedSize(), db_->GetPublicId(patientId)); |
1617 const std::string& value) | 1666 |
1618 { | 1667 db_->AddAttachment(resourceId, attachment); |
1619 std::list<std::string> lst; | 1668 |
1620 LookupTagValue(lst, value); | 1669 t.Commit(attachment.GetCompressedSize()); |
1621 | 1670 |
1622 result.clear(); | 1671 return StoreStatus_Success; |
1623 for (std::list<std::string>::const_iterator | 1672 } |
1624 it = lst.begin(); it != lst.end(); it++) | 1673 |
1625 { | 1674 |
1626 result.insert(*it); | 1675 void ServerIndex::DeleteAttachment(const std::string& publicId, |
1627 } | 1676 FileContentType type) |
1628 } | 1677 { |
1678 boost::mutex::scoped_lock lock(mutex_); | |
1679 listener_->Reset(); | |
1680 | |
1681 Transaction t(*this); | |
1682 | |
1683 ResourceType rtype; | |
1684 int64_t id; | |
1685 if (!db_->LookupResource(publicId, id, rtype)) | |
1686 { | |
1687 throw OrthancException(ErrorCode_UnknownResource); | |
1688 } | |
1689 | |
1690 db_->DeleteAttachment(id, type); | |
1691 | |
1692 t.Commit(0); | |
1693 } | |
1694 | |
1695 | |
1629 } | 1696 } |