comparison Plugin/SeriesInformationAdapter.cpp @ 0:02f7a0400a91

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Feb 2015 13:45:35 +0100
parents
children a6492d20b2a8
comparison
equal deleted inserted replaced
-1:000000000000 0:02f7a0400a91
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public License
8 * as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20
21 #include "SeriesInformationAdapter.h"
22
23 #include "ViewerToolbox.h"
24 #include "SeriesVolumeSorter.h"
25
26 #include "../Orthanc/OrthancException.h"
27
28 namespace OrthancPlugins
29 {
30 bool SeriesInformationAdapter::Create(std::string& content,
31 const std::string& seriesId)
32 {
33 std::string message = "Ordering instances of series: " + seriesId;
34 OrthancPluginLogInfo(context_, message.c_str());
35
36 Json::Value series, study, patient;
37 if (!GetJsonFromOrthanc(series, context_, "/series/" + seriesId) ||
38 !GetJsonFromOrthanc(study, context_, "/studies/" + series["ID"].asString() + "/module?simplify") ||
39 !GetJsonFromOrthanc(patient, context_, "/studies/" + series["ID"].asString() + "/module-patient?simplify") ||
40 !series.isMember("Instances") ||
41 series["Instances"].type() != Json::arrayValue)
42 {
43 return false;
44 }
45
46 Json::Value result;
47 result["ID"] = seriesId;
48 result["SeriesDescription"] = series["MainDicomTags"]["SeriesDescription"].asString();
49 result["StudyDescription"] = study["StudyDescription"].asString();
50 result["PatientID"] = patient["PatientID"].asString();
51 result["PatientName"] = patient["PatientName"].asString();
52 result["SortedInstances"] = Json::arrayValue;
53
54 SeriesVolumeSorter sorter;
55 sorter.Reserve(series["Instances"].size());
56
57 for (Json::Value::ArrayIndex i = 0; i < series["Instances"].size(); i++)
58 {
59 const std::string instanceId = series["Instances"][i].asString();
60 std::string tmp;
61
62 if (!cache_.Access(tmp, CacheBundle_InstanceInformation, instanceId))
63 {
64 throw Orthanc::OrthancException("The cache is corrupted. Delete it to reconstruct it.");
65 }
66
67 InstanceInformation instance(tmp);
68 sorter.AddInstance(instanceId, instance);
69 }
70
71 for (size_t i = 0; i < sorter.GetSize(); i++)
72 {
73 result["SortedInstances"].append(sorter.GetInstance(i));
74 }
75
76 content = result.toStyledString();
77
78 return true;
79 }
80 }