comparison OrthancServer/DatabaseWrapper.cpp @ 1244:a0e420c5f2b8

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Dec 2014 12:31:35 +0100
parents 58e6a89c3ef4
children 54bf0f0245f4
comparison
equal deleted inserted replaced
1243:3a3e7e3e244f 1244:a0e420c5f2b8
617 void DatabaseWrapper::GetChangesInternal(std::list<ServerIndexChange>& target, 617 void DatabaseWrapper::GetChangesInternal(std::list<ServerIndexChange>& target,
618 bool& done, 618 bool& done,
619 SQLite::Statement& s, 619 SQLite::Statement& s,
620 unsigned int maxResults) 620 unsigned int maxResults)
621 { 621 {
622 target.clear();
623
622 while (target.size() < maxResults && s.Step()) 624 while (target.size() < maxResults && s.Step())
623 { 625 {
624 int64_t seq = s.ColumnInt64(0); 626 int64_t seq = s.ColumnInt64(0);
625 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1)); 627 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1));
626 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3)); 628 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3));
678 680
679 s.Run(); 681 s.Run();
680 } 682 }
681 683
682 684
683 void DatabaseWrapper::GetExportedResourcesInternal(Json::Value& target, 685 void DatabaseWrapper::GetExportedResourcesInternal(std::list<ExportedResource>& target,
686 bool& done,
684 SQLite::Statement& s, 687 SQLite::Statement& s,
685 int64_t since,
686 unsigned int maxResults) 688 unsigned int maxResults)
687 { 689 {
688 Json::Value changes = Json::arrayValue; 690 target.clear();
689 int64_t last = since; 691
690 692 while (target.size() < maxResults && s.Step())
691 while (changes.size() < maxResults && s.Step())
692 { 693 {
693 int64_t seq = s.ColumnInt64(0); 694 int64_t seq = s.ColumnInt64(0);
694 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1)); 695 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1));
695 std::string publicId = s.ColumnString(2); 696 std::string publicId = s.ColumnString(2);
696 697
702 s.ColumnString(4), // patient ID 703 s.ColumnString(4), // patient ID
703 s.ColumnString(5), // study instance UID 704 s.ColumnString(5), // study instance UID
704 s.ColumnString(6), // series instance UID 705 s.ColumnString(6), // series instance UID
705 s.ColumnString(7)); // sop instance UID 706 s.ColumnString(7)); // sop instance UID
706 707
707 Json::Value item = Json::objectValue; 708 target.push_back(resource);
708 item["Seq"] = static_cast<int>(seq); 709 }
709 item["ResourceType"] = EnumerationToString(resourceType); 710
710 item["ID"] = publicId; 711 done = !(target.size() == maxResults && s.Step());
711 item["Path"] = GetBasePath(resourceType, publicId); 712 }
712 item["RemoteModality"] = s.ColumnString(3); 713
713 item["Date"] = s.ColumnString(8); 714
714 715 void DatabaseWrapper::GetExportedResources(std::list<ExportedResource>& target,
715 // WARNING: Do not add "break" below and do not reorder the case items! 716 bool& done,
716 switch (resourceType)
717 {
718 case ResourceType_Instance:
719 item["SopInstanceUid"] = s.ColumnString(7);
720
721 case ResourceType_Series:
722 item["SeriesInstanceUid"] = s.ColumnString(6);
723
724 case ResourceType_Study:
725 item["StudyInstanceUid"] = s.ColumnString(5);
726
727 case ResourceType_Patient:
728 item["PatientId"] = s.ColumnString(4);
729 break;
730
731 default:
732 throw OrthancException(ErrorCode_InternalError);
733 }
734
735 last = seq;
736
737 changes.append(item);
738 }
739
740 target = Json::objectValue;
741 target["Exports"] = changes;
742 target["Done"] = !(changes.size() == maxResults && s.Step());
743 target["Last"] = static_cast<int>(last);
744 }
745
746
747 void DatabaseWrapper::GetExportedResources(Json::Value& target,
748 int64_t since, 717 int64_t since,
749 unsigned int maxResults) 718 unsigned int maxResults)
750 { 719 {
751 SQLite::Statement s(db_, SQLITE_FROM_HERE, 720 SQLite::Statement s(db_, SQLITE_FROM_HERE,
752 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?"); 721 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?");
753 s.BindInt64(0, since); 722 s.BindInt64(0, since);
754 s.BindInt(1, maxResults + 1); 723 s.BindInt(1, maxResults + 1);
755 GetExportedResourcesInternal(target, s, since, maxResults); 724 GetExportedResourcesInternal(target, done, s, maxResults);
756 } 725 }
757 726
758 727
759 void DatabaseWrapper::GetLastExportedResource(Json::Value& target) 728 void DatabaseWrapper::GetLastExportedResource(std::list<ExportedResource>& target)
760 { 729 {
730 bool done; // Ignored
761 SQLite::Statement s(db_, SQLITE_FROM_HERE, 731 SQLite::Statement s(db_, SQLITE_FROM_HERE,
762 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1"); 732 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1");
763 GetExportedResourcesInternal(target, s, 0, 1); 733 GetExportedResourcesInternal(target, done, s, 1);
764 } 734 }
765 735
766 736
767 737
768 738