comparison OrthancServer/Search/Compatibility/ICreateInstance.cpp @ 3084:195ba4cbac3f db-changes

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Jan 2019 16:42:55 +0100
parents OrthancServer/Search/Compatibility/ICompatibilityCreateInstance.cpp@847a0ed92654
children 476cba12c2b0
comparison
equal deleted inserted replaced
3083:683d572424b6 3084:195ba4cbac3f
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #include "../../PrecompiledHeadersServer.h"
35 #include "ICreateInstance.h"
36
37 #include "../../../Core/OrthancException.h"
38
39 namespace Orthanc
40 {
41 namespace Compatibility
42 {
43 bool ICreateInstance::Apply(ICreateInstance& compatibility,
44 IDatabaseWrapper& database,
45 IDatabaseWrapper::CreateInstanceResult& result,
46 int64_t& instanceId,
47 const std::string& hashPatient,
48 const std::string& hashStudy,
49 const std::string& hashSeries,
50 const std::string& hashInstance)
51 {
52 {
53 ResourceType type;
54 int64_t tmp;
55
56 if (database.LookupResource(tmp, type, hashInstance))
57 {
58 // The instance already exists
59 assert(type == ResourceType_Instance);
60 instanceId = tmp;
61 return false;
62 }
63 }
64
65 instanceId = compatibility.CreateResource(hashInstance, ResourceType_Instance);
66
67 result.isNewPatient_ = false;
68 result.isNewStudy_ = false;
69 result.isNewSeries_ = false;
70 result.patientId_ = -1;
71 result.studyId_ = -1;
72 result.seriesId_ = -1;
73
74 // Detect up to which level the patient/study/series/instance
75 // hierarchy must be created
76
77 {
78 ResourceType dummy;
79
80 if (database.LookupResource(result.seriesId_, dummy, hashSeries))
81 {
82 assert(dummy == ResourceType_Series);
83 // The patient, the study and the series already exist
84
85 bool ok = (database.LookupResource(result.patientId_, dummy, hashPatient) &&
86 database.LookupResource(result.studyId_, dummy, hashStudy));
87 assert(ok);
88 }
89 else if (database.LookupResource(result.studyId_, dummy, hashStudy))
90 {
91 assert(dummy == ResourceType_Study);
92
93 // New series: The patient and the study already exist
94 result.isNewSeries_ = true;
95
96 bool ok = database.LookupResource(result.patientId_, dummy, hashPatient);
97 assert(ok);
98 }
99 else if (database.LookupResource(result.patientId_, dummy, hashPatient))
100 {
101 assert(dummy == ResourceType_Patient);
102
103 // New study and series: The patient already exist
104 result.isNewStudy_ = true;
105 result.isNewSeries_ = true;
106 }
107 else
108 {
109 // New patient, study and series: Nothing exists
110 result.isNewPatient_ = true;
111 result.isNewStudy_ = true;
112 result.isNewSeries_ = true;
113 }
114 }
115
116 // Create the series if needed
117 if (result.isNewSeries_)
118 {
119 result.seriesId_ = compatibility.CreateResource(hashSeries, ResourceType_Series);
120 }
121
122 // Create the study if needed
123 if (result.isNewStudy_)
124 {
125 result.studyId_ = compatibility.CreateResource(hashStudy, ResourceType_Study);
126 }
127
128 // Create the patient if needed
129 if (result.isNewPatient_)
130 {
131 result.patientId_ = compatibility.CreateResource(hashPatient, ResourceType_Patient);
132 }
133
134 // Create the parent-to-child links
135 compatibility.AttachChild(result.seriesId_, instanceId);
136
137 if (result.isNewSeries_)
138 {
139 compatibility.AttachChild(result.studyId_, result.seriesId_);
140 }
141
142 if (result.isNewStudy_)
143 {
144 compatibility.AttachChild(result.patientId_, result.studyId_);
145 }
146
147 // Sanity checks
148 assert(result.patientId_ != -1);
149 assert(result.studyId_ != -1);
150 assert(result.seriesId_ != -1);
151 assert(instanceId != -1);
152
153 return true;
154 }
155 }
156 }