Mercurial > hg > orthanc
annotate OrthancExplorer/explorer.js @ 342:a58a8be26aff
generation of random uid in the rest api
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Jan 2013 10:17:11 +0100 |
parents | f2286c741109 |
children | cd6749e53a03 |
rev | line source |
---|---|
0 | 1 // http://stackoverflow.com/questions/1663741/is-there-a-good-jquery-drag-and-drop-file-upload-plugin |
2 | |
3 | |
4 // Forbid the access to IE | |
5 if ($.browser.msie) | |
6 { | |
7 alert("Please use Mozilla Firefox or Google Chrome. Microsoft Internet Explorer is not supported."); | |
8 } | |
9 | |
10 // http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html | |
11 //$.mobile.ajaxEnabled = false; | |
12 //$.mobile.page.prototype.options.addBackBtn = true; | |
13 //$.mobile.defaultPageTransition = 'slide'; | |
14 | |
15 // http://stackoverflow.com/a/4673436 | |
16 String.prototype.format = function() { | |
17 var args = arguments; | |
18 return this.replace(/{(\d+)}/g, function(match, number) { | |
19 /*return typeof args[number] != 'undefined' | |
20 ? args[number] | |
21 : match;*/ | |
22 | |
23 return args[number]; | |
24 }); | |
25 }; | |
26 | |
27 | |
28 $(document).ready(function() { | |
29 var $tree = $('#dicom-tree'); | |
30 $tree.tree({ | |
31 autoEscape: false | |
32 }); | |
33 | |
34 $('#dicom-tree').bind( | |
35 'tree.click', | |
36 function(event) { | |
37 if (event.node.is_open) | |
38 $tree.tree('closeNode', event.node, true); | |
39 else | |
40 $tree.tree('openNode', event.node, true); | |
41 } | |
42 ); | |
43 }); | |
44 | |
45 | |
46 function SplitLongUid(s) | |
47 { | |
48 return '<span>' + s.substr(0, s.length / 2) + '</span> <span>' + s.substr(s.length / 2, s.length - s.length / 2) + '</span>'; | |
49 } | |
50 | |
51 | |
52 function ParseDicomDate(s) | |
53 { | |
54 y = parseInt(s.substr(0, 4), 10); | |
55 m = parseInt(s.substr(4, 2), 10) - 1; | |
56 d = parseInt(s.substr(6, 2), 10); | |
57 | |
58 if (y == null || m == null || d == null || | |
59 !isFinite(y) || !isFinite(m) || !isFinite(d)) | |
60 { | |
61 return null; | |
62 } | |
63 | |
64 if (y < 1900 || y > 2100 || | |
65 m < 0 || m >= 12 || | |
66 d <= 0 || d >= 32) | |
67 { | |
68 return null; | |
69 } | |
70 | |
71 return new Date(y, m, d); | |
72 } | |
73 | |
74 | |
75 function FormatDicomDate(s) | |
76 { | |
77 if (s == undefined) | |
78 return "No date"; | |
79 | |
80 var d = ParseDicomDate(s); | |
81 if (d == null) | |
82 return '?'; | |
83 else | |
84 return d.toString('dddd, MMMM d, yyyy'); | |
85 } | |
86 | |
87 | |
80 | 88 function Sort(arr, fieldExtractor, isInteger, reverse) |
0 | 89 { |
33 | 90 var defaultValue; |
91 if (isInteger) | |
92 defaultValue = 0; | |
93 else | |
94 defaultValue = ''; | |
95 | |
0 | 96 arr.sort(function(a, b) { |
80 | 97 var ta = fieldExtractor(a); |
98 var tb = fieldExtractor(b); | |
0 | 99 var order; |
100 | |
33 | 101 if (ta == undefined) |
102 ta = defaultValue; | |
103 | |
104 if (tb == undefined) | |
105 tb = defaultValue; | |
106 | |
0 | 107 if (isInteger) |
108 { | |
109 ta = parseInt(ta, 10); | |
110 tb = parseInt(tb, 10); | |
111 order = ta - tb; | |
112 } | |
113 else | |
114 { | |
115 if (ta < tb) | |
116 order = -1; | |
117 else if (ta > tb) | |
118 order = 1; | |
119 else | |
120 order = 0; | |
121 } | |
122 | |
123 if (reverse) | |
124 return -order; | |
125 else | |
126 return order; | |
127 }); | |
128 } | |
129 | |
130 | |
80 | 131 function SortOnDicomTag(arr, tag, isInteger, reverse) |
132 { | |
133 return Sort(arr, function(a) { | |
134 return a.MainDicomTags[tag]; | |
135 }, isInteger, reverse); | |
136 } | |
137 | |
138 | |
0 | 139 |
140 function GetSingleResource(type, uuid, callback) | |
141 { | |
142 var resource = null; | |
143 $.ajax({ | |
83 | 144 url: '../' + type + '/' + uuid, |
0 | 145 dataType: 'json', |
146 async: false, | |
147 success: function(s) { | |
148 callback(s); | |
149 } | |
150 }); | |
151 } | |
152 | |
153 | |
154 function GetMultipleResources(type, uuids, callback) | |
155 { | |
156 if (uuids == null) | |
157 { | |
158 $.ajax({ | |
83 | 159 url: '../' + type, |
0 | 160 dataType: 'json', |
161 async: false, | |
162 success: function(s) { | |
163 uuids = s; | |
164 } | |
165 }); | |
166 } | |
167 | |
168 var resources = []; | |
169 var ajaxRequests = uuids.map(function(uuid) { | |
170 return $.ajax({ | |
83 | 171 url: '../' + type + '/' + uuid, |
0 | 172 dataType: 'json', |
173 async: true, | |
174 success: function(s) { | |
175 resources.push(s); | |
176 } | |
177 }); | |
178 }); | |
179 | |
180 // Wait for all the AJAX requests to end | |
181 $.when.apply($, ajaxRequests).then(function() { | |
182 callback(resources); | |
183 }); | |
184 } | |
185 | |
186 | |
187 | |
188 function CompleteFormatting(s, link, isReverse) | |
189 { | |
190 if (link != null) | |
191 { | |
192 s = 'href="' + link + '">' + s + '</a>'; | |
193 | |
194 if (isReverse) | |
195 s = 'data-direction="reverse" '+ s; | |
196 | |
197 s = '<a ' + s; | |
198 } | |
199 | |
200 if (isReverse) | |
201 return '<li data-icon="back">' + s + '</li>'; | |
202 else | |
203 return '<li>' + s + '</li>'; | |
204 } | |
205 | |
206 | |
38 | 207 function FormatMainDicomTags(tags, tagsToIgnore) |
208 { | |
209 var s = ''; | |
210 | |
211 for (var i in tags) | |
212 { | |
213 if (tagsToIgnore.indexOf(i) == -1) | |
214 { | |
215 var v = tags[i]; | |
216 | |
40 | 217 if (i == "PatientBirthDate" || |
218 i == "StudyDate" || | |
219 i == "SeriesDate") | |
38 | 220 { |
221 v = FormatDicomDate(v); | |
222 } | |
40 | 223 else if (i == "DicomStudyInstanceUID" || |
224 i == "DicomSeriesInstanceUID") | |
38 | 225 { |
226 v = SplitLongUid(v); | |
227 } | |
228 | |
229 | |
230 s += ('<p>{0}: <strong>{1}</strong></p>').format(i, v); | |
231 } | |
232 } | |
233 | |
234 return s; | |
235 } | |
236 | |
0 | 237 |
238 function FormatPatient(patient, link, isReverse) | |
239 { | |
40 | 240 var s = ('<h3>{0}</h3>{1}' + |
241 '<span class="ui-li-count">{2}</span>' | |
0 | 242 ).format |
38 | 243 (patient.MainDicomTags.PatientName, |
40 | 244 FormatMainDicomTags(patient.MainDicomTags, [ |
245 "PatientName", | |
246 "OtherPatientIDs" | |
247 ]), | |
0 | 248 patient.Studies.length |
249 ); | |
250 | |
251 return CompleteFormatting(s, link, isReverse); | |
252 } | |
253 | |
254 | |
255 | |
256 function FormatStudy(study, link, isReverse) | |
257 { | |
40 | 258 var s = ('<h3>{0}</h3>{1}' + |
0 | 259 '<span class="ui-li-count">{2}</span>' |
260 ).format | |
261 (study.MainDicomTags.StudyDescription, | |
40 | 262 FormatMainDicomTags(study.MainDicomTags, [ |
263 "StudyDescription", | |
264 "StudyTime" | |
265 ]), | |
0 | 266 study.Series.length |
267 ); | |
268 | |
269 return CompleteFormatting(s, link, isReverse); | |
270 } | |
271 | |
272 | |
273 | |
274 function FormatSeries(series, link, isReverse) | |
275 { | |
80 | 276 var c; |
82 | 277 if (series.ExpectedNumberOfInstances == null || |
278 series.Instances.length == series.ExpectedNumberOfInstances) | |
80 | 279 { |
82 | 280 c = series.Instances.length; |
80 | 281 } |
282 else | |
283 { | |
284 c = series.Instances.length + '/' + series.ExpectedNumberOfInstances; | |
285 } | |
286 | |
287 var s = ('<h3>{0}</h3>' + | |
288 '<p><em>Status: <strong>{1}</strong></em></p>{2}' + | |
289 '<span class="ui-li-count">{3}</span>').format | |
0 | 290 (series.MainDicomTags.SeriesDescription, |
80 | 291 series.Status, |
40 | 292 FormatMainDicomTags(series.MainDicomTags, [ |
293 "SeriesDescription", | |
294 "SeriesTime", | |
41
c1097a676eca
better naming for preview images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
295 "Manufacturer", |
c1097a676eca
better naming for preview images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
296 "ImagesInAcquisition", |
40 | 297 "SeriesDate" |
298 ]), | |
80 | 299 c |
0 | 300 ); |
301 | |
302 return CompleteFormatting(s, link, isReverse); | |
303 } | |
304 | |
305 | |
306 function FormatInstance(instance, link, isReverse) | |
307 { | |
40 | 308 var s = ('<h3>Instance {0}</h3>{1}').format |
80 | 309 (instance.IndexInSeries, |
40 | 310 FormatMainDicomTags(instance.MainDicomTags, [ |
311 "AcquisitionNumber", | |
312 "InstanceNumber", | |
313 "InstanceCreationDate", | |
314 "InstanceCreationTime" | |
315 ]) | |
0 | 316 ); |
317 | |
318 return CompleteFormatting(s, link, isReverse); | |
319 } | |
320 | |
321 | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
322 $('[data-role="page"]').live('pagebeforeshow', function() { |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
323 $.ajax({ |
153 | 324 url: '../system', |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
325 dataType: 'json', |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
326 async: false, |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
327 success: function(s) { |
165 | 328 if (s.Name != "") { |
329 $('.orthanc-name').html('<a class="ui-link" href="explorer.html">' + s.Name + '</a> » '); | |
330 } | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
331 } |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
332 }); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
333 }); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
334 |
0 | 335 |
336 | |
337 $('#find-patients').live('pagebeforeshow', function() { | |
338 GetMultipleResources('patients', null, function(patients) { | |
339 var target = $('#all-patients'); | |
340 $('li', target).remove(); | |
341 | |
342 SortOnDicomTag(patients, 'PatientName', false, false); | |
343 | |
344 for (var i = 0; i < patients.length; i++) { | |
345 var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID); | |
346 target.append(p); | |
347 } | |
348 | |
349 target.listview('refresh'); | |
350 }); | |
351 }); | |
352 | |
353 | |
354 | |
355 $('#patient').live('pagebeforeshow', function() { | |
356 if ($.mobile.pageData) { | |
357 GetSingleResource('patients', $.mobile.pageData.uuid, function(patient) { | |
358 GetMultipleResources('studies', patient.Studies, function(studies) { | |
359 SortOnDicomTag(studies, 'StudyDate', false, true); | |
360 | |
361 $('#patient-info li').remove(); | |
362 $('#patient-info') | |
363 .append('<li data-role="list-divider">Patient</li>') | |
364 .append(FormatPatient(patient)) | |
365 .listview('refresh'); | |
366 | |
367 var target = $('#list-studies'); | |
368 $('li', target).remove(); | |
369 | |
370 for (var i = 0; i < studies.length; i++) { | |
371 if (i == 0 || studies[i].MainDicomTags.StudyDate != studies[i - 1].MainDicomTags.StudyDate) | |
372 { | |
373 target.append('<li data-role="list-divider">{0}</li>'.format | |
374 (FormatDicomDate(studies[i].MainDicomTags.StudyDate))); | |
375 } | |
376 | |
377 target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID)); | |
378 } | |
379 | |
380 target.listview('refresh'); | |
274
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
381 |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
382 // Check whether this patient is protected |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
383 $.ajax({ |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
384 url: '../patients/' + $.mobile.pageData.uuid + '/protected', |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
385 type: 'GET', |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
386 dataType: 'text', |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
387 async: false, |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
388 success: function (s) { |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
389 var v = (s == '1') ? 'on' : 'off'; |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
390 $('#protection').val(v).slider('refresh'); |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
391 } |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
392 }); |
0 | 393 }); |
394 }); | |
395 } | |
396 }); | |
397 | |
398 | |
399 $('#study').live('pagebeforeshow', function() { | |
400 if ($.mobile.pageData) { | |
401 GetSingleResource('studies', $.mobile.pageData.uuid, function(study) { | |
402 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
403 GetMultipleResources('series', study.Series, function(series) { | |
404 SortOnDicomTag(series, 'SeriesDate', false, true); | |
405 | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
406 $('#study .patient-link').attr('href', '#patient?uuid=' + patient.ID); |
0 | 407 $('#study-info li').remove(); |
408 $('#study-info') | |
409 .append('<li data-role="list-divider">Patient</li>') | |
410 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
411 .append('<li data-role="list-divider">Study</li>') | |
412 .append(FormatStudy(study)) | |
413 .listview('refresh'); | |
414 | |
415 var target = $('#list-series'); | |
416 $('li', target).remove(); | |
417 for (var i = 0; i < series.length; i++) { | |
418 if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate) | |
419 { | |
420 target.append('<li data-role="list-divider">{0}</li>'.format | |
421 (FormatDicomDate(series[i].MainDicomTags.SeriesDate))); | |
422 } | |
423 target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID)); | |
424 } | |
425 target.listview('refresh'); | |
426 }); | |
427 }); | |
428 }); | |
429 } | |
430 }); | |
431 | |
432 | |
433 $('#series').live('pagebeforeshow', function() { | |
434 if ($.mobile.pageData) { | |
435 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { | |
436 GetSingleResource('studies', series.ParentStudy, function(study) { | |
437 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
438 GetMultipleResources('instances', series.Instances, function(instances) { | |
80 | 439 Sort(instances, function(x) { return x.IndexInSeries; }, true, false); |
0 | 440 |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
441 $('#series .patient-link').attr('href', '#patient?uuid=' + patient.ID); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
442 $('#series .study-link').attr('href', '#study?uuid=' + study.ID); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
443 |
0 | 444 $('#series-info li').remove(); |
445 $('#series-info') | |
446 .append('<li data-role="list-divider">Patient</li>') | |
447 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
448 .append('<li data-role="list-divider">Study</li>') | |
449 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) | |
450 .append('<li data-role="list-divider">Series</li>') | |
451 .append(FormatSeries(series)) | |
452 .listview('refresh'); | |
453 | |
454 var target = $('#list-instances'); | |
455 $('li', target).remove(); | |
456 for (var i = 0; i < instances.length; i++) { | |
457 target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID)); | |
458 } | |
459 target.listview('refresh'); | |
460 }); | |
461 }); | |
462 }); | |
463 }); | |
464 } | |
465 }); | |
466 | |
467 | |
468 | |
469 function ConvertForTree(dicom) | |
470 { | |
471 var result = []; | |
472 | |
473 for (var i in dicom) { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
474 if (dicom[i] != null) { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
475 var label = i + '<span class="tag-name"> (<i>' + dicom[i]["Name"] + '</i>)</span>: '; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
476 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
477 if (dicom[i]["Type"] == 'String') |
0 | 478 { |
479 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
480 label: label + '<strong>' + dicom[i]["Value"] + '</strong>', |
0 | 481 children: [] |
482 }); | |
483 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
484 else if (dicom[i]["Type"] == 'TooLong') |
0 | 485 { |
486 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
487 label: label + '<i>Too long</i>', |
0 | 488 children: [] |
489 }); | |
490 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
491 else if (dicom[i]["Type"] == 'Null') |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
492 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
493 result.push({ |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
494 label: label + '<i>Null</i>', |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
495 children: [] |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
496 }); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
497 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
498 else if (dicom[i]["Type"] == 'Sequence') |
0 | 499 { |
500 var c = []; | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
501 for (var j = 0; j < dicom[i]["Value"].length; j++) { |
0 | 502 c.push({ |
503 label: 'Item ' + j, | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
504 children: ConvertForTree(dicom[i]["Value"][j]) |
0 | 505 }); |
506 } | |
507 | |
508 result.push({ | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
509 label: label + '[]', |
0 | 510 children: c |
511 }); | |
512 } | |
513 } | |
514 } | |
515 | |
516 return result; | |
517 } | |
518 | |
519 | |
520 $('#instance').live('pagebeforeshow', function() { | |
521 if ($.mobile.pageData) { | |
522 GetSingleResource('instances', $.mobile.pageData.uuid, function(instance) { | |
523 GetSingleResource('series', instance.ParentSeries, function(series) { | |
524 GetSingleResource('studies', series.ParentStudy, function(study) { | |
525 GetSingleResource('patients', study.ParentPatient, function(patient) { | |
152
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
526 |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
527 $('#instance .patient-link').attr('href', '#patient?uuid=' + patient.ID); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
528 $('#instance .study-link').attr('href', '#study?uuid=' + study.ID); |
4829c054751a
improved navigation in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
529 $('#instance .series-link').attr('href', '#series?uuid=' + series.ID); |
0 | 530 |
531 $('#instance-info li').remove(); | |
532 $('#instance-info') | |
533 .append('<li data-role="list-divider">Patient</li>') | |
534 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) | |
535 .append('<li data-role="list-divider">Study</li>') | |
536 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) | |
537 .append('<li data-role="list-divider">Series</li>') | |
538 .append(FormatSeries(series, '#series?uuid=' + series.ID, true)) | |
539 .append('<li data-role="list-divider">Instance</li>') | |
540 .append(FormatInstance(instance)) | |
541 .listview('refresh'); | |
542 | |
543 $.ajax({ | |
83 | 544 url: '../instances/' + instance.ID + '/tags', |
0 | 545 dataType: 'json', |
546 success: function(s) { | |
547 $('#dicom-tree').tree('loadData', ConvertForTree(s)); | |
548 } | |
549 }); | |
550 | |
551 }); | |
552 }); | |
553 }); | |
554 }); | |
555 } | |
556 }); | |
557 | |
558 | |
559 | |
560 function DeleteResource(path) | |
561 { | |
562 $.ajax({ | |
563 url: path, | |
564 type: 'DELETE', | |
565 dataType: 'json', | |
566 async: false, | |
567 success: function(s) { | |
568 var ancestor = s.RemainingAncestor; | |
569 if (ancestor == null) | |
570 $.mobile.changePage('#find-patients'); | |
571 else | |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
165
diff
changeset
|
572 $.mobile.changePage('#' + ancestor.Type.toLowerCase() + '?uuid=' + ancestor.ID); |
0 | 573 } |
574 }); | |
575 } | |
576 | |
577 | |
578 | |
579 function OpenDeleteResourceDialog(path, title) | |
580 { | |
581 $(document).simpledialog2({ | |
582 // http://dev.jtsage.com/jQM-SimpleDialog/demos2/ | |
583 // http://dev.jtsage.com/jQM-SimpleDialog/demos2/options.html | |
584 mode: 'button', | |
585 animate: false, | |
586 headerText: title, | |
587 headerClose: true, | |
588 width: '500px', | |
589 buttons : { | |
590 'OK': { | |
591 click: function () { | |
592 DeleteResource(path); | |
593 }, | |
594 icon: "delete", | |
595 theme: "c" | |
596 }, | |
597 'Cancel': { | |
598 click: function () { | |
599 } | |
600 } | |
601 } | |
602 }); | |
603 } | |
604 | |
605 | |
606 | |
607 $('#instance-delete').live('click', function() { | |
83 | 608 OpenDeleteResourceDialog('../instances/' + $.mobile.pageData.uuid, |
0 | 609 'Delete this instance?'); |
610 }); | |
611 | |
612 $('#study-delete').live('click', function() { | |
83 | 613 OpenDeleteResourceDialog('../studies/' + $.mobile.pageData.uuid, |
0 | 614 'Delete this study?'); |
615 }); | |
616 | |
617 $('#series-delete').live('click', function() { | |
83 | 618 OpenDeleteResourceDialog('../series/' + $.mobile.pageData.uuid, |
0 | 619 'Delete this series?'); |
620 }); | |
621 | |
622 $('#patient-delete').live('click', function() { | |
83 | 623 OpenDeleteResourceDialog('../patients/' + $.mobile.pageData.uuid, |
0 | 624 'Delete this patient?'); |
625 }); | |
626 | |
627 | |
628 $('#instance-download-dicom').live('click', function(e) { | |
629 // http://stackoverflow.com/a/1296101 | |
630 e.preventDefault(); //stop the browser from following | |
83 | 631 window.location.href = '../instances/' + $.mobile.pageData.uuid + '/file'; |
0 | 632 }); |
633 | |
634 $('#instance-download-json').live('click', function(e) { | |
635 // http://stackoverflow.com/a/1296101 | |
636 e.preventDefault(); //stop the browser from following | |
83 | 637 window.location.href = '../instances/' + $.mobile.pageData.uuid + '/tags'; |
0 | 638 }); |
639 | |
640 | |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
641 |
0 | 642 $('#instance-preview').live('click', function(e) { |
54
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
643 if ($.mobile.pageData) { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
644 GetSingleResource('instances', $.mobile.pageData.uuid + '/frames', function(frames) { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
645 if (frames.length == 1) |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
646 { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
647 // Viewing a single-frame image |
83 | 648 jQuery.slimbox('../instances/' + $.mobile.pageData.uuid + '/preview', '', { |
54
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
649 overlayFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
650 resizeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
651 imageFadeDuration : 1 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
652 }); |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
653 } |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
654 else |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
655 { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
656 // Viewing a multi-frame image |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
657 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
658 var images = []; |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
659 for (var i = 0; i < frames.length; i++) { |
83 | 660 images.push([ '../instances/' + $.mobile.pageData.uuid + '/frames/' + i + '/preview' ]); |
54
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
661 } |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
662 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
663 jQuery.slimbox(images, 0, { |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
664 overlayFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
665 resizeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
666 imageFadeDuration : 1, |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
667 loop : true |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
668 }); |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
669 } |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
670 }); |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
671 |
42a449dac415
multi-frame images in the explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
672 } |
0 | 673 }); |
674 | |
675 $('#series-preview').live('click', function(e) { | |
676 if ($.mobile.pageData) { | |
677 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { | |
678 GetMultipleResources('instances', series.Instances, function(instances) { | |
80 | 679 Sort(instances, function(x) { return x.IndexInSeries; }, true, false); |
0 | 680 |
681 var images = []; | |
682 for (var i = 0; i < instances.length; i++) { | |
83 | 683 images.push([ '../instances/' + instances[i].ID + '/preview', |
0 | 684 '{0}/{1}'.format(i + 1, instances.length) ]) |
685 } | |
686 | |
687 jQuery.slimbox(images, 0, { | |
688 overlayFadeDuration : 1, | |
689 resizeDuration : 1, | |
690 imageFadeDuration : 1, | |
691 loop : true | |
692 }); | |
693 }) | |
694 }); | |
695 } | |
696 }); | |
697 | |
698 | |
699 | |
700 | |
701 | |
702 | |
703 function ChooseDicomModality(callback) | |
704 { | |
705 $.ajax({ | |
83 | 706 url: '../modalities', |
0 | 707 type: 'GET', |
708 dataType: 'json', | |
709 async: false, | |
710 success: function(modalities) { | |
711 var clickedModality = ''; | |
712 var items = $('<ul>') | |
713 .attr('data-role', 'listview'); | |
714 | |
715 for (var i = 0; i < modalities.length; i++) { | |
716 var modality = modalities[i]; | |
717 var item = $('<li>') | |
718 .html('<a href="#" rel="close">' + modality + '</a>') | |
719 .attr('modality', modality) | |
720 .click(function() { | |
721 clickedModality = $(this).attr('modality'); | |
722 }); | |
723 items.append(item); | |
724 } | |
725 | |
726 $('#dialog').simpledialog2({ | |
727 mode: 'blank', | |
728 animate: false, | |
729 headerText: 'DICOM modality', | |
730 headerClose: true, | |
731 width: '100%', | |
732 blankContent: items, | |
733 callbackClose: function() { | |
734 var timer; | |
735 function WaitForDialogToClose() { | |
736 if (!$('#dialog').is(':visible')) { | |
737 clearInterval(timer); | |
738 callback(clickedModality); | |
739 } | |
740 } | |
741 timer = setInterval(WaitForDialogToClose, 100); | |
742 } | |
743 }); | |
744 } | |
745 }); | |
746 } | |
747 | |
748 | |
749 $('#instance-store,#series-store').live('click', function(e) { | |
750 ChooseDicomModality(function(modality) { | |
751 if (modality != '') { | |
752 $.ajax({ | |
83 | 753 url: '../modalities/' + modality + '/store', |
0 | 754 type: 'POST', |
755 dataType: 'text', | |
756 data: $.mobile.pageData.uuid, | |
757 async: true, // Necessary to block UI | |
758 beforeSend: function() { | |
759 $.blockUI({ message: $('#loading') }); | |
760 }, | |
761 complete: function(s) { | |
762 $.unblockUI(); | |
763 }, | |
764 success: function(s) { | |
765 console.log('done !'); | |
766 }, | |
767 error: function() { | |
768 alert('Error during C-Store'); | |
769 } | |
770 }); | |
771 | |
772 } | |
773 }); | |
774 }); | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
775 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
776 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
777 $('#show-tag-name').live('change', function(e) { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
778 var checked = e.currentTarget.checked; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
779 if (checked) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
780 $('.tag-name').show(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
781 else |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
782 $('.tag-name').hide(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
783 }); |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
784 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
785 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
786 $('#patient-archive').live('click', function(e) { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
787 e.preventDefault(); //stop the browser from following |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
788 window.location.href = '../patients/' + $.mobile.pageData.uuid + '/archive'; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
789 }); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
790 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
791 $('#study-archive').live('click', function(e) { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
792 e.preventDefault(); //stop the browser from following |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
793 window.location.href = '../studies/' + $.mobile.pageData.uuid + '/archive'; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
794 }); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
795 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
796 $('#series-archive').live('click', function(e) { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
797 e.preventDefault(); //stop the browser from following |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
798 window.location.href = '../series/' + $.mobile.pageData.uuid + '/archive'; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
799 }); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
800 |
274
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
801 $('#protection').live('change', function(e) { |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
802 var isProtected = e.target.value == "on"; |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
803 $.ajax({ |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
804 url: '../patients/' + $.mobile.pageData.uuid + '/protected', |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
805 type: 'PUT', |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
806 dataType: 'text', |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
807 data: isProtected ? '1' : '0', |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
808 async: false |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
809 }); |
f2286c741109
patient protection in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
250
diff
changeset
|
810 }); |