Mercurial > hg > orthanc
comparison OrthancServer/Search/LookupIdentifierQuery.cpp @ 2121:7e8889bc95c6
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Nov 2016 11:28:12 +0100 |
parents | a657f7772e69 |
children | a3a65de1840f |
comparison
equal
deleted
inserted
replaced
2120:4b02ec79728a | 2121:7e8889bc95c6 |
---|---|
41 | 41 |
42 | 42 |
43 | 43 |
44 namespace Orthanc | 44 namespace Orthanc |
45 { | 45 { |
46 static const DicomTag patientIdentifiers[] = | |
47 { | |
48 DICOM_TAG_PATIENT_ID, | |
49 DICOM_TAG_PATIENT_NAME, | |
50 DICOM_TAG_PATIENT_BIRTH_DATE | |
51 }; | |
52 | |
53 static const DicomTag studyIdentifiers[] = | |
54 { | |
55 DICOM_TAG_PATIENT_ID, | |
56 DICOM_TAG_PATIENT_NAME, | |
57 DICOM_TAG_PATIENT_BIRTH_DATE, | |
58 DICOM_TAG_STUDY_INSTANCE_UID, | |
59 DICOM_TAG_ACCESSION_NUMBER, | |
60 DICOM_TAG_STUDY_DESCRIPTION, | |
61 DICOM_TAG_STUDY_DATE | |
62 }; | |
63 | |
64 static const DicomTag seriesIdentifiers[] = | |
65 { | |
66 DICOM_TAG_SERIES_INSTANCE_UID | |
67 }; | |
68 | |
69 static const DicomTag instanceIdentifiers[] = | |
70 { | |
71 DICOM_TAG_SOP_INSTANCE_UID | |
72 }; | |
73 | |
74 | |
75 void LookupIdentifierQuery::LoadIdentifiers(const DicomTag*& tags, | |
76 size_t& size, | |
77 ResourceType level) | |
78 { | |
79 switch (level) | |
80 { | |
81 case ResourceType_Patient: | |
82 tags = patientIdentifiers; | |
83 size = sizeof(patientIdentifiers) / sizeof(DicomTag); | |
84 break; | |
85 | |
86 case ResourceType_Study: | |
87 tags = studyIdentifiers; | |
88 size = sizeof(studyIdentifiers) / sizeof(DicomTag); | |
89 break; | |
90 | |
91 case ResourceType_Series: | |
92 tags = seriesIdentifiers; | |
93 size = sizeof(seriesIdentifiers) / sizeof(DicomTag); | |
94 break; | |
95 | |
96 case ResourceType_Instance: | |
97 tags = instanceIdentifiers; | |
98 size = sizeof(instanceIdentifiers) / sizeof(DicomTag); | |
99 break; | |
100 | |
101 default: | |
102 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
103 } | |
104 } | |
105 | |
106 | |
107 LookupIdentifierQuery::Disjunction::~Disjunction() | 46 LookupIdentifierQuery::Disjunction::~Disjunction() |
108 { | 47 { |
109 for (size_t i = 0; i < disjunction_.size(); i++) | 48 for (size_t i = 0; i < disjunction_.size(); i++) |
110 { | 49 { |
111 delete disjunction_[i]; | 50 delete disjunction_[i]; |
129 delete *it; | 68 delete *it; |
130 } | 69 } |
131 } | 70 } |
132 | 71 |
133 | 72 |
134 | |
135 bool LookupIdentifierQuery::IsIdentifier(const DicomTag& tag, | |
136 ResourceType level) | |
137 { | |
138 const DicomTag* tags; | |
139 size_t size; | |
140 | |
141 LoadIdentifiers(tags, size, level); | |
142 | |
143 for (size_t i = 0; i < size; i++) | |
144 { | |
145 if (tag == tags[i]) | |
146 { | |
147 return true; | |
148 } | |
149 } | |
150 | |
151 return false; | |
152 } | |
153 | |
154 | |
155 void LookupIdentifierQuery::AddConstraint(DicomTag tag, | 73 void LookupIdentifierQuery::AddConstraint(DicomTag tag, |
156 IdentifierConstraintType type, | 74 IdentifierConstraintType type, |
157 const std::string& value) | 75 const std::string& value) |
158 { | 76 { |
159 assert(IsIdentifier(tag)); | 77 assert(IsIdentifier(tag)); |
164 | 82 |
165 LookupIdentifierQuery::Disjunction& LookupIdentifierQuery::AddDisjunction() | 83 LookupIdentifierQuery::Disjunction& LookupIdentifierQuery::AddDisjunction() |
166 { | 84 { |
167 constraints_.push_back(new Disjunction); | 85 constraints_.push_back(new Disjunction); |
168 return *constraints_.back(); | 86 return *constraints_.back(); |
169 } | |
170 | |
171 | |
172 std::string LookupIdentifierQuery::NormalizeIdentifier(const std::string& value) | |
173 { | |
174 std::string t; | |
175 t.reserve(value.size()); | |
176 | |
177 for (size_t i = 0; i < value.size(); i++) | |
178 { | |
179 if (value[i] == '%' || | |
180 value[i] == '_') | |
181 { | |
182 t.push_back(' '); // These characters might break wildcard queries in SQL | |
183 } | |
184 else if (isascii(value[i]) && | |
185 !iscntrl(value[i]) && | |
186 (!isspace(value[i]) || value[i] == ' ')) | |
187 { | |
188 t.push_back(value[i]); | |
189 } | |
190 } | |
191 | |
192 Toolbox::ToUpperCase(t); | |
193 | |
194 return Toolbox::StripSpaces(t); | |
195 } | |
196 | |
197 | |
198 void LookupIdentifierQuery::StoreIdentifiers(IDatabaseWrapper& database, | |
199 int64_t resource, | |
200 ResourceType level, | |
201 const DicomMap& map) | |
202 { | |
203 const DicomTag* tags; | |
204 size_t size; | |
205 | |
206 LoadIdentifiers(tags, size, level); | |
207 | |
208 for (size_t i = 0; i < size; i++) | |
209 { | |
210 const DicomValue* value = map.TestAndGetValue(tags[i]); | |
211 if (value != NULL && | |
212 !value->IsNull() && | |
213 !value->IsBinary()) | |
214 { | |
215 std::string s = NormalizeIdentifier(value->GetContent()); | |
216 database.SetIdentifierTag(resource, tags[i], s); | |
217 } | |
218 } | |
219 } | 87 } |
220 | 88 |
221 | 89 |
222 void LookupIdentifierQuery::Apply(std::list<std::string>& result, | 90 void LookupIdentifierQuery::Apply(std::list<std::string>& result, |
223 IDatabaseWrapper& database) | 91 IDatabaseWrapper& database) |