annotate OrthancServer/Search/LookupIdentifierQuery.cpp @ 1766:d178fab186dd

reminder of password
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 30 Oct 2015 08:16:53 +0100
parents 9ead18ef460a
children b1291df2f780
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
1747
ca69082ab200 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
33 #include "../PrecompiledHeadersServer.h"
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "LookupIdentifierQuery.h"
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1747
ca69082ab200 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
36 #include "../../Core/OrthancException.h"
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
37 #include "SetOfResources.h"
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
38 #include "../FromDcmtkBridge.h"
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <cassert>
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 namespace Orthanc
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 static const DicomTag patientIdentifiers[] =
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 DICOM_TAG_PATIENT_ID,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 DICOM_TAG_PATIENT_NAME,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 DICOM_TAG_PATIENT_BIRTH_DATE
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 };
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 static const DicomTag studyIdentifiers[] =
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 DICOM_TAG_PATIENT_ID,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 DICOM_TAG_PATIENT_NAME,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 DICOM_TAG_PATIENT_BIRTH_DATE,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 DICOM_TAG_STUDY_INSTANCE_UID,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 DICOM_TAG_ACCESSION_NUMBER,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 DICOM_TAG_STUDY_DESCRIPTION,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 DICOM_TAG_STUDY_DATE
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 };
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 static const DicomTag seriesIdentifiers[] =
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 DICOM_TAG_SERIES_INSTANCE_UID
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 };
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 static const DicomTag instanceIdentifiers[] =
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 DICOM_TAG_SOP_INSTANCE_UID
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 };
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
74
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
75 void LookupIdentifierQuery::LoadIdentifiers(const DicomTag*& tags,
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
76 size_t& size,
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
77 ResourceType level)
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 switch (level)
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 case ResourceType_Patient:
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 tags = patientIdentifiers;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 size = sizeof(patientIdentifiers) / sizeof(DicomTag);
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 break;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 case ResourceType_Study:
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 tags = studyIdentifiers;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 size = sizeof(studyIdentifiers) / sizeof(DicomTag);
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 break;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 case ResourceType_Series:
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 tags = seriesIdentifiers;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 size = sizeof(seriesIdentifiers) / sizeof(DicomTag);
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 break;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 case ResourceType_Instance:
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 tags = instanceIdentifiers;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 size = sizeof(instanceIdentifiers) / sizeof(DicomTag);
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 break;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 default:
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 throw OrthancException(ErrorCode_ParameterOutOfRange);
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
107 LookupIdentifierQuery::Disjunction::~Disjunction()
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
108 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
109 for (size_t i = 0; i < disjunction_.size(); i++)
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
110 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
111 delete disjunction_[i];
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
112 }
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
113 }
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
114
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
115
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
116 void LookupIdentifierQuery::Disjunction::Add(const DicomTag& tag,
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
117 IdentifierConstraintType type,
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
118 const std::string& value)
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
119 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
120 disjunction_.push_back(new Constraint(tag, type, value));
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
121 }
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
122
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
123
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
124 LookupIdentifierQuery::~LookupIdentifierQuery()
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
125 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
126 for (Constraints::iterator it = constraints_.begin();
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
127 it != constraints_.end(); ++it)
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
128 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
129 delete *it;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
130 }
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
131 }
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
132
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
133
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
134
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
135 bool LookupIdentifierQuery::IsIdentifier(const DicomTag& tag,
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
136 ResourceType level)
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 const DicomTag* tags;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 size_t size;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
141 LoadIdentifiers(tags, size, level);
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 for (size_t i = 0; i < size; i++)
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 if (tag == tags[i])
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 return true;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 return false;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 void LookupIdentifierQuery::AddConstraint(DicomTag tag,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 IdentifierConstraintType type,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 const std::string& value)
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 assert(IsIdentifier(tag));
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
160 constraints_.push_back(new Disjunction);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
161 constraints_.back()->Add(tag, type, value);
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
165 LookupIdentifierQuery::Disjunction& LookupIdentifierQuery::AddDisjunction()
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
167 constraints_.push_back(new Disjunction);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
168 return *constraints_.back();
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 std::string LookupIdentifierQuery::NormalizeIdentifier(const std::string& value)
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
1764
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
174 std::string t;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
175 t.reserve(value.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
176
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
177 for (size_t i = 0; i < value.size(); i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
178 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
179 if (value[i] == '%' ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
180 value[i] == '_')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
181 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
182 t.push_back(' '); // These characters might break wildcard queries in SQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
183 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
184 else if (isascii(value[i]) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
185 !iscntrl(value[i]) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
186 (!isspace(value[i]) || value[i] == ' '))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
187 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
188 t.push_back(value[i]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
189 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
190 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
191
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
192 Toolbox::ToUpperCase(t);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
194 return Toolbox::StripSpaces(t);
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 void LookupIdentifierQuery::StoreIdentifiers(IDatabaseWrapper& database,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 int64_t resource,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 ResourceType level,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 const DicomMap& map)
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 const DicomTag* tags;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 size_t size;
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 LoadIdentifiers(tags, size, level);
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 for (size_t i = 0; i < size; i++)
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 const DicomValue* value = map.TestAndGetValue(tags[i]);
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 if (value != NULL &&
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 !value->IsNull() &&
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 !value->IsBinary())
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 std::string s = NormalizeIdentifier(value->GetContent());
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 database.SetIdentifierTag(resource, tags[i], s);
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 }
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
220
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
221
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
222 void LookupIdentifierQuery::Apply(std::list<std::string>& result,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
223 IDatabaseWrapper& database)
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
224 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
225 SetOfResources resources(database, level_);
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
226 Apply(resources, database);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
227
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
228 resources.Flatten(result);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
229 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
230
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
231
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
232 void LookupIdentifierQuery::Apply(SetOfResources& result,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
233 IDatabaseWrapper& database)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
234 {
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
235 for (size_t i = 0; i < GetSize(); i++)
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
236 {
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
237 std::list<int64_t> a;
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
238
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
239 for (size_t j = 0; j < constraints_[i]->GetSize(); j++)
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
240 {
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
241 const Constraint& constraint = constraints_[i]->GetConstraint(j);
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
242 std::list<int64_t> b;
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
243 database.LookupIdentifier(b, level_, constraint.GetTag(), constraint.GetType(), constraint.GetValue());
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
244
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
245 a.splice(a.end(), b);
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
246 }
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
247
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
248 result.Intersect(a);
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
249 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
250 }
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
251
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
252
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
253 void LookupIdentifierQuery::Print(std::ostream& s) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
254 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
255 s << "Constraint: " << std::endl;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
256 for (Constraints::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
257 it = constraints_.begin(); it != constraints_.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
258 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
259 if (it == constraints_.begin())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
260 s << " ";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
261 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
262 s << "OR ";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
263
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
264 for (size_t j = 0; j < (*it)->GetSize(); j++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
265 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
266 const Constraint& c = (*it)->GetConstraint(j);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
267 s << FromDcmtkBridge::GetName(c.GetTag());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
268
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
269 switch (c.GetType())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
270 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
271 case IdentifierConstraintType_Equal: s << " == "; break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
272 case IdentifierConstraintType_SmallerOrEqual: s << " <= "; break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
273 case IdentifierConstraintType_GreaterOrEqual: s << " >= "; break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
274 case IdentifierConstraintType_Wildcard: s << " ~= "; break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
275 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
276 s << " ? ";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
277 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
278
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
279 s << c.GetValue() << std::endl;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
280 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
281 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
282 }
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }