comparison OrthancServer/Search/DatabaseConstraint.cpp @ 3073:0e9d1731b1b0 db-changes

refactoring to reuse DatabaseConstraint in separate projects
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Jan 2019 13:44:18 +0100
parents 5ebd2ef5e7ae
children 495c5edce708
comparison
equal deleted inserted replaced
3072:1b05fd072c57 3073:0e9d1731b1b0
33 33
34 #include "../PrecompiledHeadersServer.h" 34 #include "../PrecompiledHeadersServer.h"
35 #include "DatabaseConstraint.h" 35 #include "DatabaseConstraint.h"
36 36
37 #include "../../Core/OrthancException.h" 37 #include "../../Core/OrthancException.h"
38 #include "../ServerToolbox.h"
39 38
40 namespace Orthanc 39 namespace Orthanc
41 { 40 {
42 DatabaseConstraint::DatabaseConstraint(const DicomTagConstraint& constraint, 41 DatabaseConstraint::DatabaseConstraint(ResourceType level,
43 ResourceType level, 42 const DicomTag& tag,
44 DicomTagType tagType) : 43 bool isIdentifier,
44 ConstraintType type,
45 const std::vector<std::string>& values,
46 bool caseSensitive,
47 bool mandatory) :
45 level_(level), 48 level_(level),
46 tag_(constraint.GetTag()), 49 tag_(tag),
47 constraintType_(constraint.GetConstraintType()), 50 isIdentifier_(isIdentifier),
48 mandatory_(constraint.IsMandatory()) 51 constraintType_(type),
52 values_(values),
53 caseSensitive_(caseSensitive),
54 mandatory_(mandatory)
49 { 55 {
50 switch (tagType) 56 if (type != ConstraintType_List &&
57 values_.size() != 1)
51 { 58 {
52 case DicomTagType_Identifier: 59 throw OrthancException(ErrorCode_ParameterOutOfRange);
53 isIdentifier_ = true; 60 }
54 caseSensitive_ = true; 61 }
55 break;
56 62
57 case DicomTagType_Main: 63
58 isIdentifier_ = false;
59 caseSensitive_ = constraint.IsCaseSensitive();
60 break;
61
62 default:
63 throw OrthancException(ErrorCode_InternalError);
64 }
65
66 values_.reserve(constraint.GetValues().size());
67
68 for (std::set<std::string>::const_iterator
69 it = constraint.GetValues().begin();
70 it != constraint.GetValues().end(); ++it)
71 {
72 if (isIdentifier_)
73 {
74 values_.push_back(ServerToolbox::NormalizeIdentifier(*it));
75 }
76 else
77 {
78 values_.push_back(*it);
79 }
80 }
81 }
82
83
84 const std::string& DatabaseConstraint::GetValue(size_t index) const 64 const std::string& DatabaseConstraint::GetValue(size_t index) const
85 { 65 {
86 if (index >= values_.size()) 66 if (index >= values_.size())
87 { 67 {
88 throw OrthancException(ErrorCode_ParameterOutOfRange); 68 throw OrthancException(ErrorCode_ParameterOutOfRange);