comparison OrthancServer/DatabaseWrapper.cpp @ 1162:1ea4094d077c db-changes

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Sep 2014 13:25:37 +0200
parents badc14fee61f
children 3b372ab992ec
comparison
equal deleted inserted replaced
1161:82cbf1480aac 1162:1ea4094d077c
537 s.ColumnString(5)); 537 s.ColumnString(5));
538 return true; 538 return true;
539 } 539 }
540 } 540 }
541 541
542
543 static void SetMainDicomTagsInternal(SQLite::Statement& s,
544 int64_t id,
545 const DicomElement& element)
546 {
547 s.BindInt64(0, id);
548 s.BindInt(1, element.GetTag().GetGroup());
549 s.BindInt(2, element.GetTag().GetElement());
550 s.BindString(3, element.GetValue().AsString());
551 s.Run();
552 }
553
554
542 void DatabaseWrapper::SetMainDicomTags(int64_t id, 555 void DatabaseWrapper::SetMainDicomTags(int64_t id,
543 const DicomMap& tags) 556 const DicomMap& tags)
544 { 557 {
545 DicomArray flattened(tags); 558 DicomArray flattened(tags);
546 for (size_t i = 0; i < flattened.GetSize(); i++) 559 for (size_t i = 0; i < flattened.GetSize(); i++)
547 { 560 {
548 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)"); 561 if (flattened.GetElement(i).GetTag().IsIdentifier())
549 s.BindInt64(0, id); 562 {
550 s.BindInt(1, flattened.GetElement(i).GetTag().GetGroup()); 563 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)");
551 s.BindInt(2, flattened.GetElement(i).GetTag().GetElement()); 564 SetMainDicomTagsInternal(s, id, flattened.GetElement(i));
552 s.BindString(3, flattened.GetElement(i).GetValue().AsString()); 565 }
553 s.Run(); 566 else
567 {
568 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifier VALUES(?, ?, ?, ?)");
569 SetMainDicomTagsInternal(s, id, flattened.GetElement(i));
570 }
554 } 571 }
555 } 572 }
556 573
557 void DatabaseWrapper::GetMainDicomTags(DicomMap& map, 574 void DatabaseWrapper::GetMainDicomTags(DicomMap& map,
558 int64_t id) 575 int64_t id)
564 while (s.Step()) 581 while (s.Step())
565 { 582 {
566 map.SetValue(s.ColumnInt(1), 583 map.SetValue(s.ColumnInt(1),
567 s.ColumnInt(2), 584 s.ColumnInt(2),
568 s.ColumnString(3)); 585 s.ColumnString(3));
586 }
587
588 SQLite::Statement s2(db_, SQLITE_FROM_HERE, "SELECT * FROM DicomIdentifiers WHERE id=?");
589 s2.BindInt64(0, id);
590 while (s2.Step())
591 {
592 map.SetValue(s2.ColumnInt(1),
593 s2.ColumnInt(2),
594 s2.ColumnString(3));
569 } 595 }
570 } 596 }
571 597
572 598
573 bool DatabaseWrapper::GetParentPublicId(std::string& result, 599 bool DatabaseWrapper::GetParentPublicId(std::string& result,
1050 s.BindInt64(0, internalId); 1076 s.BindInt64(0, internalId);
1051 return s.Step(); 1077 return s.Step();
1052 } 1078 }
1053 1079
1054 1080
1055 void DatabaseWrapper::LookupTagValue(std::list<int64_t>& result, 1081 void DatabaseWrapper::LookupIdentifier(std::list<int64_t>& result,
1056 DicomTag tag, 1082 const DicomTag& tag,
1057 const std::string& value) 1083 const std::string& value)
1058 { 1084 {
1059 SQLite::Statement s(db_, SQLITE_FROM_HERE, 1085 if (!tag.IsIdentifier())
1060 "SELECT id FROM MainDicomTags WHERE tagGroup=? AND tagElement=? and value=?"); 1086 {
1087 throw OrthancException(ErrorCode_ParameterOutOfRange);
1088 }
1089
1090 SQLite::Statement s(db_, SQLITE_FROM_HERE,
1091 "SELECT id FROM DicomIdentifiers WHERE tagGroup=? AND tagElement=? and value=?");
1061 1092
1062 s.BindInt(0, tag.GetGroup()); 1093 s.BindInt(0, tag.GetGroup());
1063 s.BindInt(1, tag.GetElement()); 1094 s.BindInt(1, tag.GetElement());
1064 s.BindString(2, value); 1095 s.BindString(2, value);
1065 1096
1070 result.push_back(s.ColumnInt64(0)); 1101 result.push_back(s.ColumnInt64(0));
1071 } 1102 }
1072 } 1103 }
1073 1104
1074 1105
1075 void DatabaseWrapper::LookupTagValue(std::list<int64_t>& result, 1106 void DatabaseWrapper::LookupIdentifier(std::list<int64_t>& result,
1076 const std::string& value) 1107 const std::string& value)
1077 { 1108 {
1078 SQLite::Statement s(db_, SQLITE_FROM_HERE, 1109 SQLite::Statement s(db_, SQLITE_FROM_HERE,
1079 "SELECT id FROM MainDicomTags WHERE value=?"); 1110 "SELECT id FROM DicomIdentifiers WHERE value=?");
1080 1111
1081 s.BindString(0, value); 1112 s.BindString(0, value);
1082 1113
1083 result.clear(); 1114 result.clear();
1084 1115