comparison OrthancServer/Sources/Database/Compatibility/ICreateInstance.cpp @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents OrthancServer/Database/Compatibility/ICreateInstance.cpp@94f4a18a79cc
children 05b8fd21089c
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
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-2020 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& database,
44 IDatabaseWrapper::CreateInstanceResult& result,
45 int64_t& instanceId,
46 const std::string& hashPatient,
47 const std::string& hashStudy,
48 const std::string& hashSeries,
49 const std::string& hashInstance)
50 {
51 {
52 ResourceType type;
53 int64_t tmp;
54
55 if (database.LookupResource(tmp, type, hashInstance))
56 {
57 // The instance already exists
58 assert(type == ResourceType_Instance);
59 instanceId = tmp;
60 return false;
61 }
62 }
63
64 instanceId = database.CreateResource(hashInstance, ResourceType_Instance);
65
66 result.isNewPatient_ = false;
67 result.isNewStudy_ = false;
68 result.isNewSeries_ = false;
69 result.patientId_ = -1;
70 result.studyId_ = -1;
71 result.seriesId_ = -1;
72
73 // Detect up to which level the patient/study/series/instance
74 // hierarchy must be created
75
76 {
77 ResourceType dummy;
78
79 if (database.LookupResource(result.seriesId_, dummy, hashSeries))
80 {
81 assert(dummy == ResourceType_Series);
82 // The patient, the study and the series already exist
83
84 bool ok = (database.LookupResource(result.patientId_, dummy, hashPatient) &&
85 database.LookupResource(result.studyId_, dummy, hashStudy));
86 assert(ok);
87 }
88 else if (database.LookupResource(result.studyId_, dummy, hashStudy))
89 {
90 assert(dummy == ResourceType_Study);
91
92 // New series: The patient and the study already exist
93 result.isNewSeries_ = true;
94
95 bool ok = database.LookupResource(result.patientId_, dummy, hashPatient);
96 assert(ok);
97 }
98 else if (database.LookupResource(result.patientId_, dummy, hashPatient))
99 {
100 assert(dummy == ResourceType_Patient);
101
102 // New study and series: The patient already exist
103 result.isNewStudy_ = true;
104 result.isNewSeries_ = true;
105 }
106 else
107 {
108 // New patient, study and series: Nothing exists
109 result.isNewPatient_ = true;
110 result.isNewStudy_ = true;
111 result.isNewSeries_ = true;
112 }
113 }
114
115 // Create the series if needed
116 if (result.isNewSeries_)
117 {
118 result.seriesId_ = database.CreateResource(hashSeries, ResourceType_Series);
119 }
120
121 // Create the study if needed
122 if (result.isNewStudy_)
123 {
124 result.studyId_ = database.CreateResource(hashStudy, ResourceType_Study);
125 }
126
127 // Create the patient if needed
128 if (result.isNewPatient_)
129 {
130 result.patientId_ = database.CreateResource(hashPatient, ResourceType_Patient);
131 }
132
133 // Create the parent-to-child links
134 database.AttachChild(result.seriesId_, instanceId);
135
136 if (result.isNewSeries_)
137 {
138 database.AttachChild(result.studyId_, result.seriesId_);
139 }
140
141 if (result.isNewStudy_)
142 {
143 database.AttachChild(result.patientId_, result.studyId_);
144 }
145
146 database.TagMostRecentPatient(result.patientId_);
147
148 // Sanity checks
149 assert(result.patientId_ != -1);
150 assert(result.studyId_ != -1);
151 assert(result.seriesId_ != -1);
152 assert(instanceId != -1);
153
154 return true;
155 }
156 }
157 }