comparison OrthancServer/RadiotherapyRestApi.cpp @ 526:e318e9d49815 dicom-rt

rt-struct
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Aug 2013 17:33:33 +0200
parents
children bd2087bb6450
comparison
equal deleted inserted replaced
523:68451838fb2c 526:e318e9d49815
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege,
4 * Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * In addition, as a special exception, the copyright holders of this
12 * program give permission to link the code of its release with the
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
14 * that use the same license as the "OpenSSL" library), and distribute
15 * the linked executables. You must obey the GNU General Public License
16 * in all respects for all of the code used other than "OpenSSL". If you
17 * modify file(s) with this exception, you may extend this exception to
18 * your version of the file(s), but you are not obligated to do so. If
19 * you do not wish to do so, delete this exception statement from your
20 * version. If you delete this exception statement from all source files
21 * in the program, then also delete it here.
22 *
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 **/
31
32
33 #include "RadiotherapyRestApi.h"
34
35 #include "ServerToolbox.h"
36
37 #define RETRIEVE_CONTEXT(call) \
38 OrthancRestApi& contextApi = \
39 dynamic_cast<OrthancRestApi&>(call.GetContext()); \
40 ServerContext& context = contextApi.GetContext()
41
42
43 #define REFERENCED_STUDY_SEQUENCE "0008,1110"
44 #define REFERENCED_SOP_INSTANCE_UID "0008,1155"
45 #define FRAME_OF_REFERENCE_UID "0020,0052"
46 #define REFERENCED_FRAME_OF_REFERENCE_SEQUENCE "3006,0010"
47
48 namespace Orthanc
49 {
50 static bool CheckSeriesModality(Json::Value& study,
51 Json::Value& series,
52 Json::Value& content,
53 ServerContext& context,
54 const std::string& seriesId,
55 const std::string& modality)
56 {
57 if (!context.GetIndex().LookupResource(series, seriesId, ResourceType_Series))
58 {
59 return false;
60 }
61
62 // Retrieve the parent study
63 std::string studyId = series["ParentStudy"].asString();
64 if (!context.GetIndex().LookupResource(study, studyId, ResourceType_Study))
65 {
66 return false;
67 }
68
69 // Check the modality and that there is a single instance inside the series
70 if (!series["MainDicomTags"].isMember("Modality") ||
71 series["MainDicomTags"]["Modality"].asString() != modality ||
72 series["Instances"].size() != 1)
73 {
74 return false;
75 }
76
77 // Retrieve the instance data
78 std::string instanceId = series["Instances"][0].asString();
79
80 Json::Value info;
81 context.ReadJson(content, instanceId);
82
83 return true;
84 }
85
86
87 static bool GetRtStructuresInfo(Json::Value& study,
88 Json::Value& series,
89 Json::Value& content,
90 std::string& frameOfReference,
91 ServerContext& context,
92 const std::string& seriesId)
93 {
94 if (!CheckSeriesModality(study, series, content, context, seriesId, "RTSTRUCT"))
95 {
96 return false;
97 }
98
99 // Check that the "ReferencedStudySequence" is the same as the parent study.
100 if (!content.isMember(REFERENCED_STUDY_SEQUENCE) ||
101 content[REFERENCED_STUDY_SEQUENCE]["Value"].size() != 1 ||
102 !content[REFERENCED_STUDY_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID) ||
103 content[REFERENCED_STUDY_SEQUENCE]["Value"][0][REFERENCED_SOP_INSTANCE_UID]["Value"].asString() !=
104 study["MainDicomTags"]["StudyInstanceUID"].asString())
105 {
106 return false;
107 }
108
109 // Lookup for the frame of reference. Orthanc does not support
110 // RTSTRUCT with multiple frames of reference.
111 if (!content.isMember(REFERENCED_FRAME_OF_REFERENCE_SEQUENCE) ||
112 content[REFERENCED_FRAME_OF_REFERENCE_SEQUENCE]["Value"].size() != 1 ||
113 !content[REFERENCED_FRAME_OF_REFERENCE_SEQUENCE]["Value"][0].isMember(FRAME_OF_REFERENCE_UID))
114 {
115 return false;
116 }
117
118 frameOfReference = content[REFERENCED_FRAME_OF_REFERENCE_SEQUENCE]["Value"][0][FRAME_OF_REFERENCE_UID]["Value"].asString();
119
120 return true;
121 }
122
123
124 static void GetRtStructuresInfo(RestApi::GetCall& call)
125 {
126 RETRIEVE_CONTEXT(call);
127
128 Json::Value study, series, content;
129 std::string frameOfReference;
130 if (GetRtStructuresInfo(study, series, content, frameOfReference, context, call.GetUriComponent("id", "")))
131 {
132 Json::Value result;
133
134 result["Study"] = study["ID"];
135
136
137 // Lookup the series with the same frame of reference inside this study
138 result["RelatedSeries"] = Json::arrayValue;
139
140 for (Json::Value::ArrayIndex i = 0; i < study["Series"].size(); i++)
141 {
142 Json::Value otherSeries;
143 if (context.GetIndex().LookupResource(otherSeries, study["Series"][i].asString(), ResourceType_Series) &&
144 otherSeries["Instances"].size() > 0)
145 {
146 Json::Value info;
147 context.ReadJson(info, otherSeries["Instances"][0].asString());
148
149 if (info.isMember(FRAME_OF_REFERENCE_UID))
150 {
151 result["RelatedSeries"].append(study["Series"][i].asString());
152 }
153 }
154 }
155
156 call.GetOutput().AnswerJson(result);
157 }
158 }
159
160
161 RadiotherapyRestApi::RadiotherapyRestApi(ServerContext& context) : OrthancRestApi(context)
162 {
163 Register("/series/{id}/rt-structures", GetRtStructuresInfo);
164 }
165 }
166
167
168 // curl http://localhost:8042/series/0b9e2bb2-605a59aa-f27c0260-9cc4faf6-9d8bf457/rt-structures
169 // curl http://localhost:8042/series/ef041e6b-c855e775-f7e0f7fe-dc3c17dc-533cb8c5/rt-structures