Mercurial > hg > orthanc-authorization
comparison Plugin/AuthorizationParserBase.cpp @ 1:d5d3cb00556a
initial release
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 22 Mar 2017 16:13:52 +0100 |
parents | |
children | c44013681a51 |
comparison
equal
deleted
inserted
replaced
0:decac5df19c4 | 1:d5d3cb00556a |
---|---|
1 /** | |
2 * Advanced authorization plugin for Orthanc | |
3 * Copyright (C) 2017 Osimis, Belgium | |
4 * | |
5 * This program is free software: you can redistribute it and/or | |
6 * modify it under the terms of the GNU Affero General Public License | |
7 * as published by the Free Software Foundation, either version 3 of | |
8 * the License, or (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Affero General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Affero General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 **/ | |
18 | |
19 #include "AuthorizationParserBase.h" | |
20 | |
21 #include "../Resources/Orthanc/Core/OrthancException.h" | |
22 | |
23 namespace OrthancPlugins | |
24 { | |
25 void AuthorizationParserBase::AddResourceInternal(AccessedResources& target, | |
26 Orthanc::ResourceType level, | |
27 const std::string& orthancId) | |
28 { | |
29 std::string dicomUid; | |
30 | |
31 if (resourceHierarchy_->LookupDicomUid(dicomUid, level, orthancId)) | |
32 { | |
33 target.push_back(AccessedResource(level, orthancId, dicomUid)); | |
34 } | |
35 } | |
36 | |
37 | |
38 void AuthorizationParserBase::AddOrthancInstance(AccessedResources& target, | |
39 const std::string& orthancId) | |
40 { | |
41 std::string patient, study, series; | |
42 if (!resourceHierarchy_->LookupInstance(patient, study, series, orthancId)) | |
43 { | |
44 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
45 } | |
46 | |
47 AddResourceInternal(target, Orthanc::ResourceType_Patient, patient); | |
48 AddResourceInternal(target, Orthanc::ResourceType_Study, study); | |
49 AddResourceInternal(target, Orthanc::ResourceType_Series, series); | |
50 AddResourceInternal(target, Orthanc::ResourceType_Instance, orthancId); | |
51 } | |
52 | |
53 | |
54 void AuthorizationParserBase::AddOrthancSeries(AccessedResources& target, | |
55 const std::string& orthancId) | |
56 { | |
57 std::string patient, study; | |
58 if (!resourceHierarchy_->LookupSeries(patient, study, orthancId)) | |
59 { | |
60 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
61 } | |
62 | |
63 AddResourceInternal(target, Orthanc::ResourceType_Patient, patient); | |
64 AddResourceInternal(target, Orthanc::ResourceType_Study, study); | |
65 AddResourceInternal(target, Orthanc::ResourceType_Series, orthancId); | |
66 } | |
67 | |
68 | |
69 void AuthorizationParserBase::AddOrthancStudy(AccessedResources& target, | |
70 const std::string& orthancId) | |
71 { | |
72 std::string patient; | |
73 if (!resourceHierarchy_->LookupStudy(patient, orthancId)) | |
74 { | |
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
76 } | |
77 | |
78 AddResourceInternal(target, Orthanc::ResourceType_Patient, patient); | |
79 AddResourceInternal(target, Orthanc::ResourceType_Study, orthancId); | |
80 } | |
81 | |
82 | |
83 void AuthorizationParserBase::AddOrthancPatient(AccessedResources& target, | |
84 const std::string& orthancId) | |
85 { | |
86 AddResourceInternal(target, Orthanc::ResourceType_Patient, orthancId); | |
87 } | |
88 | |
89 | |
90 void AuthorizationParserBase::AddDicomStudy(AccessedResources& target, | |
91 const std::string& studyDicomUid) | |
92 { | |
93 std::string patient, study; | |
94 | |
95 if (!resourceHierarchy_->LookupOrthancId(study, Orthanc::ResourceType_Study, studyDicomUid) || | |
96 !resourceHierarchy_->LookupStudy(patient, study)) | |
97 { | |
98 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
99 } | |
100 | |
101 AddResourceInternal(target, Orthanc::ResourceType_Patient, patient); | |
102 target.push_back(AccessedResource(Orthanc::ResourceType_Study, study, studyDicomUid)); | |
103 } | |
104 | |
105 | |
106 void AuthorizationParserBase::AddDicomSeries(AccessedResources& target, | |
107 const std::string& studyDicomUid, | |
108 const std::string& seriesDicomUid) | |
109 { | |
110 std::string series; | |
111 | |
112 if (!resourceHierarchy_->LookupOrthancId(series, Orthanc::ResourceType_Series, seriesDicomUid)) | |
113 { | |
114 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
115 } | |
116 | |
117 AddDicomStudy(target, studyDicomUid); | |
118 target.push_back(AccessedResource(Orthanc::ResourceType_Series, series, seriesDicomUid)); | |
119 } | |
120 | |
121 | |
122 void AuthorizationParserBase::AddDicomInstance(AccessedResources& target, | |
123 const std::string& studyDicomUid, | |
124 const std::string& seriesDicomUid, | |
125 const std::string& instanceDicomUid) | |
126 { | |
127 std::string instance; | |
128 | |
129 if (!resourceHierarchy_->LookupOrthancId | |
130 (instance, Orthanc::ResourceType_Instance, instanceDicomUid)) | |
131 { | |
132 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
133 } | |
134 | |
135 AddDicomSeries(target, studyDicomUid, seriesDicomUid); | |
136 target.push_back(AccessedResource(Orthanc::ResourceType_Instance, instance, instanceDicomUid)); | |
137 } | |
138 | |
139 | |
140 AuthorizationParserBase::AuthorizationParserBase(OrthancPluginContext* context, | |
141 ICacheFactory& factory) | |
142 { | |
143 resourceHierarchy_.reset(new ResourceHierarchyCache(context, factory)); | |
144 | |
145 if (resourceHierarchy_.get() == NULL) | |
146 { | |
147 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
148 } | |
149 } | |
150 } | |
151 |