1 /*=============================================================================
2
3 Library: XNAT/Core
4
5 Copyright (c) University College London,
6 Centre for Medical Image Computing
7
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20 =============================================================================*/
21
22 #include "ctkXnatScan.h"
23
24 #include "ctkXnatDefaultSchemaTypes.h"
25 #include "ctkXnatObject.h"
26 #include "ctkXnatObjectPrivate.h"
27 #include "ctkXnatScanFolder.h"
28 #include "ctkXnatSession.h"
29
30 const QString ctkXnatScan::QUALITY = "quality";
31 const QString ctkXnatScan::SERIES_DESCRIPTION = "series_description";
32 const QString ctkXnatScan::TYPE = "type";
33
34 //----------------------------------------------------------------------------
35 class ctkXnatScanPrivate : public ctkXnatObjectPrivate
36 {
37 public:
38
ctkXnatScanPrivate()39 ctkXnatScanPrivate()
40 : ctkXnatObjectPrivate()
41 {
42 }
43
reset()44 void reset()
45 {
46 uri.clear();
47 }
48
49 QString uri;
50 };
51
52
53 //----------------------------------------------------------------------------
ctkXnatScan(ctkXnatObject * parent,const QString & schemaType)54 ctkXnatScan::ctkXnatScan(ctkXnatObject* parent, const QString& schemaType)
55 : ctkXnatObject(*new ctkXnatScanPrivate(), parent, schemaType)
56 {
57 }
58
59 //----------------------------------------------------------------------------
~ctkXnatScan()60 ctkXnatScan::~ctkXnatScan()
61 {
62 }
63
64 //----------------------------------------------------------------------------
setQuality(const QString & quality)65 void ctkXnatScan::setQuality(const QString &quality)
66 {
67 this->setProperty(QUALITY, quality);
68 }
69
70 //----------------------------------------------------------------------------
quality() const71 QString ctkXnatScan::quality() const
72 {
73 return this->property(QUALITY);
74 }
75
76 //----------------------------------------------------------------------------
setSeriesDescription(const QString & seriesDescription)77 void ctkXnatScan::setSeriesDescription(const QString &seriesDescription)
78 {
79 this->setProperty(SERIES_DESCRIPTION, seriesDescription);
80 }
81
82 //----------------------------------------------------------------------------
seriesDescription() const83 QString ctkXnatScan::seriesDescription() const
84 {
85 return this->property(SERIES_DESCRIPTION);
86 }
87
88 //----------------------------------------------------------------------------
setType(const QString & type)89 void ctkXnatScan::setType(const QString &type)
90 {
91 this->setProperty(TYPE, type);
92 }
93
94 //----------------------------------------------------------------------------
type() const95 QString ctkXnatScan::type() const
96 {
97 return this->property(TYPE);
98 }
99
100 //----------------------------------------------------------------------------
resourceUri() const101 QString ctkXnatScan::resourceUri() const
102 {
103 return QString("%1/%2/resources").arg(parent()->resourceUri(), this->id());
104 }
105
106 //----------------------------------------------------------------------------
reset()107 void ctkXnatScan::reset()
108 {
109 ctkXnatObject::reset();
110 }
111
112 //----------------------------------------------------------------------------
fetchImpl()113 void ctkXnatScan::fetchImpl()
114 {
115 QString query = this->resourceUri();
116 ctkXnatSession* const session = this->session();
117 QUuid queryId = session->httpGet(query);
118
119 QList<ctkXnatObject*> resources = session->httpResults(queryId,
120 ctkXnatDefaultSchemaTypes::XSI_RESOURCE);
121
122 foreach (ctkXnatObject* resource, resources)
123 {
124 QString label = resource->name();
125 if (label.isEmpty())
126 {
127 label = "NO NAME";
128 }
129
130 resource->setName(label);
131 this->add(resource);
132 }
133 }
134
135 //----------------------------------------------------------------------------
downloadImpl(const QString & filename)136 void ctkXnatScan::downloadImpl(const QString& filename)
137 {
138 QString query = this->resourceUri() + "/files";
139 ctkXnatSession::UrlParameters parameters;
140 parameters["format"] = "zip";
141 this->session()->download(filename, query, parameters);
142 }
143