comparison OrthancServer/OrthancExplorer/query-retrieve.js @ 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 OrthancExplorer/query-retrieve.js@6dba4fa8a6cb
children 160ec8417874
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 function JavascriptDateToDicom(date)
2 {
3 var s = date.toISOString();
4 return s.substring(0, 4) + s.substring(5, 7) + s.substring(8, 10);
5 }
6
7 function GenerateDicomDate(days)
8 {
9 var today = new Date();
10 var other = new Date(today);
11 other.setDate(today.getDate() + days);
12 return JavascriptDateToDicom(other);
13 }
14
15
16 $('#query-retrieve').live('pagebeforeshow', function() {
17 var targetDate;
18
19 $.ajax({
20 url: '../modalities',
21 dataType: 'json',
22 async: false,
23 cache: false,
24 success: function(modalities) {
25 var targetServer = $('#qr-server');
26 var option;
27
28 $('option', targetServer).remove();
29
30 for (var i = 0; i < modalities.length; i++) {
31 option = $('<option>').text(modalities[i]);
32 targetServer.append(option);
33 }
34
35 targetServer.selectmenu('refresh');
36 }
37 });
38
39 targetDate = $('#qr-date');
40 $('option', targetDate).remove();
41 targetDate.append($('<option>').attr('value', '').text('Any date'));
42 targetDate.append($('<option>').attr('value', GenerateDicomDate(0)).text('Today'));
43 targetDate.append($('<option>').attr('value', GenerateDicomDate(-1)).text('Yesterday'));
44 targetDate.append($('<option>').attr('value', GenerateDicomDate(-7) + '-').text('Last 7 days'));
45 targetDate.append($('<option>').attr('value', GenerateDicomDate(-31) + '-').text('Last 31 days'));
46 targetDate.append($('<option>').attr('value', GenerateDicomDate(-31 * 3) + '-').text('Last 3 months'));
47 targetDate.append($('<option>').attr('value', GenerateDicomDate(-365) + '-').text('Last year'));
48 targetDate.selectmenu('refresh');
49 });
50
51
52 $('#qr-echo').live('click', function() {
53 var server = $('#qr-server').val();
54 var message = 'Error: The C-Echo has failed!';
55
56 $.ajax({
57 url: '../modalities/' + server + '/echo',
58 type: 'POST',
59 cache: false,
60 async: false,
61 success: function() {
62 message = 'The C-Echo has succeeded!';
63 }
64 });
65
66 $('<div>').simpledialog2({
67 mode: 'button',
68 headerText: 'Echo result',
69 headerClose: true,
70 buttonPrompt: message,
71 animate: false,
72 buttons : {
73 'OK': { click: function () { } }
74 }
75 });
76
77 return false;
78 });
79
80
81 $('#qr-submit').live('click', function() {
82 var query, server, modalities, field;
83
84 query = {
85 'Level' : 'Study',
86 'Query' : {
87 'AccessionNumber' : '',
88 'PatientBirthDate' : '',
89 'PatientID' : '',
90 'PatientName' : '',
91 'PatientSex' : '',
92 'StudyDate' : $('#qr-date').val(),
93 'StudyDescription' : ''
94 }
95 };
96
97 modalities = '';
98
99 field = $('#qr-fields input:checked').val();
100 query['Query'][field] = $('#qr-value').val().toUpperCase();
101
102 $('#qr-modalities input:checked').each(function() {
103 var s = $(this).attr('name');
104 if (modalities == '')
105 modalities = s;
106 else
107 modalities += '\\' + s;
108 });
109
110 if (modalities.length > 0) {
111 query['Query']['ModalitiesInStudy'] = modalities;
112 }
113
114
115 server = $('#qr-server').val();
116 $.ajax({
117 url: '../modalities/' + server + '/query',
118 type: 'POST',
119 data: JSON.stringify(query),
120 dataType: 'json',
121 async: false,
122 error: function() {
123 alert('Error during query (C-Find)');
124 },
125 success: function(result) {
126 ChangePage('query-retrieve-2', {
127 'server' : server,
128 'uuid' : result['ID']
129 });
130 }
131 });
132
133 return false;
134 });
135
136
137
138 $('#query-retrieve-2').live('pagebeforeshow', function() {
139 var pageData, uri;
140
141 if ($.mobile.pageData) {
142 pageData = DeepCopy($.mobile.pageData);
143
144 uri = '../queries/' + pageData.uuid + '/answers';
145
146 $.ajax({
147 url: uri,
148 dataType: 'json',
149 async: false,
150 success: function(answers) {
151 var target = $('#query-retrieve-2 ul');
152 $('li', target).remove();
153
154 for (var i = 0; i < answers.length; i++) {
155 $.ajax({
156 url: uri + '/' + answers[i] + '/content?simplify',
157 dataType: 'json',
158 async: false,
159 success: function(study) {
160 var series = '#query-retrieve-3?server=' + pageData.server + '&uuid=' + study['StudyInstanceUID'];
161
162 var content = ($('<div>')
163 .append($('<h3>').text(study['PatientID'] + ' - ' + study['PatientName']))
164 .append($('<p>').text('Accession number: ')
165 .append($('<b>').text(study['AccessionNumber'])))
166 .append($('<p>').text('Birth date: ')
167 .append($('<b>').text(study['PatientBirthDate'])))
168 .append($('<p>').text('Patient sex: ')
169 .append($('<b>').text(study['PatientSex'])))
170 .append($('<p>').text('Study description: ')
171 .append($('<b>').text(study['StudyDescription'])))
172 .append($('<p>').text('Study date: ')
173 .append($('<b>').text(FormatDicomDate(study['StudyDate'])))));
174
175 var info = $('<a>').attr('href', series).html(content);
176
177 var answerId = answers[i];
178 var retrieve = $('<a>').text('Retrieve all study').click(function() {
179 ChangePage('query-retrieve-4', {
180 'query' : pageData.uuid,
181 'answer' : answerId,
182 'server' : pageData.server
183 });
184 });
185
186 target.append($('<li>').append(info).append(retrieve));
187 }
188 });
189 }
190
191 target.listview('refresh');
192 }
193 });
194 }
195 });
196
197
198 $('#query-retrieve-3').live('pagebeforeshow', function() {
199 var pageData, query;
200
201 if ($.mobile.pageData) {
202 pageData = DeepCopy($.mobile.pageData);
203
204 query = {
205 'Level' : 'Series',
206 'Query' : {
207 'Modality' : '',
208 'ProtocolName' : '',
209 'SeriesDescription' : '',
210 'SeriesInstanceUID' : '',
211 'StudyInstanceUID' : pageData.uuid
212 }
213 };
214
215 $.ajax({
216 url: '../modalities/' + pageData.server + '/query',
217 type: 'POST',
218 data: JSON.stringify(query),
219 dataType: 'json',
220 async: false,
221 error: function() {
222 alert('Error during query (C-Find)');
223 },
224 success: function(answer) {
225 var queryUuid = answer['ID'];
226 var uri = '../queries/' + answer['ID'] + '/answers';
227
228 $.ajax({
229 url: uri,
230 dataType: 'json',
231 async: false,
232 success: function(answers) {
233
234 var target = $('#query-retrieve-3 ul');
235 $('li', target).remove();
236
237 for (var i = 0; i < answers.length; i++) {
238 $.ajax({
239 url: uri + '/' + answers[i] + '/content?simplify',
240 dataType: 'json',
241 async: false,
242 success: function(series) {
243 var content = ($('<div>')
244 .append($('<h3>').text(series['SeriesDescription']))
245 .append($('<p>').text('Modality: ')
246 .append($('<b>').text(series['Modality'])))
247 .append($('<p>').text('ProtocolName: ')
248 .append($('<b>').text(series['ProtocolName']))));
249
250 var info = $('<a>').html(content);
251
252 var answerId = answers[i];
253 info.click(function() {
254 ChangePage('query-retrieve-4', {
255 'query' : queryUuid,
256 'study' : pageData.uuid,
257 'answer' : answerId,
258 'server' : pageData.server
259 });
260 });
261
262 target.append($('<li>').attr('data-icon', 'arrow-d').append(info));
263 }
264 });
265 }
266
267 target.listview('refresh');
268 }
269 });
270 }
271 });
272 }
273 });
274
275
276
277 $('#query-retrieve-4').live('pagebeforeshow', function() {
278 var pageData, uri;
279
280 if ($.mobile.pageData) {
281 var pageData = DeepCopy($.mobile.pageData);
282 var uri = '../queries/' + pageData.query + '/answers/' + pageData.answer + '/retrieve';
283
284 $.ajax({
285 url: '../system',
286 dataType: 'json',
287 async: false,
288 cache: false,
289 success: function(system) {
290 $('#retrieve-target').val(system['DicomAet']);
291
292 $('#retrieve-form').submit(function(event) {
293 var aet;
294
295 event.preventDefault();
296
297 aet = $('#retrieve-target').val();
298 if (aet.length == 0) {
299 aet = system['DicomAet'];
300 }
301
302 $.ajax({
303 url: uri,
304 type: 'POST',
305 async: true, // Necessary to block UI
306 dataType: 'text',
307 data: aet,
308 beforeSend: function() {
309 $.blockUI({ message: $('#info-retrieve') });
310 },
311 complete: function(s) {
312 $.unblockUI();
313 },
314 success: function() {
315 if (pageData.study) {
316 // Go back to the list of series
317 ChangePage('query-retrieve-3', {
318 'server' : pageData.server,
319 'uuid' : pageData.study
320 });
321 } else {
322 // Go back to the list of studies
323 ChangePage('query-retrieve-2', {
324 'server' : pageData.server,
325 'uuid' : pageData.query
326 });
327 }
328 },
329 error: function() {
330 alert('Error during retrieve');
331 }
332 });
333 });
334 }
335 });
336 }
337 });