build_table_series()   F
last analyzed

Complexity

Conditions 23
Paths > 20000

Size

Total Lines 215
Code Lines 197

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 23
eloc 197
c 2
b 0
f 0
nc 55297
nop 2
dl 0
loc 215
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 Copyright (C) 2018-2020 KANOUN Salim
4
 This program is free software; you can redistribute it and/or modify
5
 it under the terms of the Affero GNU General Public v.3 License as published by
6
 the Free Software Foundation;
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
 Affero GNU General Public Public for more details.
11
 You should have received a copy of the Affero GNU General Public Public along
12
 with this program; if not, write to the Free Software Foundation, Inc.,
13
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14
 */
15
16
// If Not done do not display anything
17
if ($visitObject->statusDone == Visit::NOT_DONE) {
18
	echo ("<h1>Visit Not Done</h1>");
19
	return;
20
} ?>
21
22
<script type="text/javascript">
23
    
24
	$(document).ready(function(){
25
    		$("#formInvestigator").load('/specific_form', {
26
    			id_visit : <?=$id_visit?>,
27
    			type_visit : '<?=$type_visit?>',
28
    			patient_num : <?=$patient_num?>
29
            });
30
            
31
        	//If upload validated display the detailed tables
32
            <?php
33
			if ($visitObject->uploadStatus == Visit::NOT_DONE && $role === User::INVESTIGATOR) {
34
			?>
35
36
				$.ajax({
37
					type: "GET",
38
					url: '/scripts/get_possible_import.php',
39
					dataType: 'json',
40
					success: function(data) {
41
42
						let targetVisit = data.filter((visit)=>{
43
							return visit.visitID === <?= $id_visit ?>
44
						})
45
46
						window.Gaelo_Uploader.installUploader({
47
							minNbOfInstances: 30,
48
							availableVisits : targetVisit,
49
							tusEndpoint : '/tus',
50
							isNewStudy : async (originalOrthancID) => {
51
								return new Promise( (resolve, reject) => {
52
										$.ajax({
53
										type: "POST",
54
										url: '/scripts/is_new_study.php',
55
										//Do not trigger event to avoid conflit with dicomupload listener in parallel
56
										global: false,
57
										data: {
58
											originalOrthancID : originalOrthancID
59
										},
60
										success: function(data) {
61
											resolve( (data === 'true') )
62
										},
63
										error : function(){
64
											resolve(false)
65
										}
66
									});
67
								})	
68
							},
69
							onStartUsing: ()=>{
70
								preventAjaxDivLoading()
71
							},
72
							onStudyUploaded : function validateUpload(visitID, sucessIDsUploaded, numberOfFiles, originalStudyOrthancID) {
73
								$.ajax({
74
									type: "POST",
75
									url: '/scripts/validate_dicom_upload_tus.php',
76
									//Do not trigger event to avoid conflit with dicomupload listener in parallel
77
									global: false,
78
									data: {
79
										id_visit : visitID,
80
										totalDicomFiles : numberOfFiles,
81
										sucessIDsUploaded : sucessIDsUploaded,
82
										originalOrthancStudyID : originalStudyOrthancID
83
									},
84
									success: function() {
85
										let uploadedVisit = targetVisit.filter((visit)=>{
86
											return visit.visitID == visitID
87
										})[0]
88
										
89
										alertifySuccess('Upload Validation Success Patient : '+uploadedVisit['patientCode']+' Visit : '+uploadedVisit['visitType'])
90
									
91
								},
92
								error : function(){
93
										alertifyError('Upload Validation Visit '+visitID+' Error, please contact administrator')
94
								}
95
								});		
96
97
							},
98
							onUploadComplete: ()=>{
99
								alertifySuccess('Upload Finished')
100
								allowAjaxDivLoading()
101
								refreshDivContenu()
102
							}
103
						}, 'dicomUploaderv2')
104
						checkBrowserSupportDicomUpload('#dicomUploaderv2');
105
					
106
					},
107
					error : function(){
108
						console.log('error');
109
					}
110
				});	
111
112
				$("#dicomUploaderv2").on("remove", function () {
113
					let results = window.Gaelo_Uploader.closeUploader('dicomUploaderv2')
114
					console.log('Uploader Removed '+results)
115
				})	
116
               
117
           <?php
118
			}
119
			?>
120
          
121
			//If current user is controller diplay the quality controle form, the included QC form is disabled according to QC status
122
	       <?php
123
			if ($role == User::CONTROLLER && ($visitObject->stateQualityControl == Visit::QC_NOT_DONE || $visitObject->stateQualityControl == Visit::QC_WAIT_DEFINITVE_CONCLUSION)) {
124
				?>  
125
                $("#controlerForm").load('/controller_form', {
126
                    id_visit : <?= $id_visit ?>,
127
                    type_visit : '<?= $type_visit ?>',
128
                    patient_num : <?= $patient_num ?>
129
                });
130
    
131
    	       <?php
132
				// If investigator has reponded to the quality control, display the corrective action form
133
				if ($visitObject->stateQualityControl == Visit::QC_WAIT_DEFINITVE_CONCLUSION) {
134
				?>
135
            		$("#correctiveAction").load('/corrective_action', {
136
            			id_visit : <?= $id_visit ?>,
137
            			type_visit : '<?= $type_visit ?>',
138
            			patient_num : <?= $patient_num ?>
139
            		});
140
    	       <?php
141
				}
142
			}
143
    
144
			// If corrective action is asked, display the corrective action form for investigator (or monitor)
145
			if ($visitObject->stateQualityControl == Visit::QC_CORRECTIVE_ACTION_ASKED && ($role == User::INVESTIGATOR || $role == User::MONITOR)) {
146
				?>
147
            		$("#correctiveAction").load('/corrective_action', {
148
            			id_visit : <?=$id_visit?>,
149
            			type_visit : '<?=$type_visit?>',
150
            			patient_num : <?=$patient_num?>
151
            		});
152
            	
153
            		$("#controlerForm").load('/controller_form', {
154
            			id_visit : <?=$id_visit?>,
155
            			type_visit : '<?=$type_visit?>',
156
            			patient_num : <?=$patient_num?>
157
            		});
158
        
159
            	<?php
160
			}
161
			if ($role == User::REVIEWER || ($role == User::INVESTIGATOR && $visitObject->uploadStatus == Visit::DONE) || ($role == User::CONTROLLER && ($visitObject->stateQualityControl == Visit::QC_NOT_DONE || $visitObject->stateQualityControl == Visit::QC_WAIT_DEFINITVE_CONCLUSION))) {
162
				?>
163
            		$("#reviewerDownloadDicomBtn").on('click', function() {
164
            			$("#downloadForm").submit();
165
            		});
166
            		
167
            		$("#OHIFViewer").on('click', function() {
168
            			var win = window.open('/ohif/viewer/<?=$visitObject->getStudyDicomDetails()->studyUID ?>', '_blank');
169
                        if (win) {
170
                            //Browser has allowed it to be opened
171
                            win.focus();
172
                        } else {
173
                            //Browser has blocked it
174
                            alert('Please allow popups for this website');
175
                        }
176
            		});
177
        	    <?php
178
			}
179
			?>
180
181
	});
182
	
183
	function refreshDivContenu(){
184
		$('#contenu').load('/visit_interface', {
185
				id_visit : <?=$id_visit?>,
186
				type_visit : '<?=$type_visit?>',
187
				patient_num : <?=$patient_num?>
188
		});
189
		$('#containerTree').jstree(true).refresh();
190
	};
191
192
	<?php if ($visitObject->uploadStatus == Visit::UPLOAD_PROCESSING) {
193
		
194
		?>
195
	    function refreshUploadStatus(){
196
	        $.ajax({
197
	            type: "POST",
198
	            url: '/scripts/get_upload_status.php',
199
				dataType: 'json',
200
				//Do not trigger event to avoid conflit with dicomupload listener in parallel
201
				global: false,
202
	            data: {id_visit:<?=$id_visit?>},
203
				success: function(data) {
204
		           //Update the span of the upload status
205
					var spinner=$('#spinnerUploadDiv<?=$visitObject->id_visit?>');
206
					var uploadStatusLabel=$('#uploadStatusLabel<?=$visitObject->id_visit?>');
207
					var checkIcon=$('#checkIconDiv<?=$visitObject->id_visit?>');
208
					
209
					uploadStatusLabel.html(data);
210
					
211
		        	if(data == "<?=Visit::UPLOAD_PROCESSING?>"){
212
		        		spinner.show();
213
		        		setTimeout(refreshUploadStatus, 5000);
214
		        	}else if(data=="<?= Visit::DONE ?>"){
215
		        		checkIcon.show();
216
		        		uploadStatusLabel.css("color", "green");
217
		        		spinner.hide();
218
		        		<?php if ($visitObject->stateInvestigatorForm == Visit::DONE) {
219
							?>
220
		        			refreshDivContenu();
221
		        			<?php
222
						}?>
223
		        	}else{
224
		        		spinner.hide();
225
		        		uploadStatusLabel.css("color", "red");
226
		        		checkIcon.hide();
227
		        	}
228
	           },
229
	           error : function(){
230
		           console.log('error');
231
	           }
232
			});		
233
234
		}
235
236
	    $( document ).ready(function() {
237
	    	refreshUploadStatus();
238
	    });
239
	
240
241
	<?php 
242
	    
243
	}?>
244
245
    	
246
    </script>
247
248
<?php
249
// Status reminder
250
if ($role != User::REVIEWER) {
251
	?>
252
    <div class="bloc_bordures text-center mt-3 mb-3">
253
		<label><b>Upload Status:</b> <span id="uploadStatusLabel<?=$visitObject->id_visit?>"><?=$visitObject->uploadStatus?> </span> </label>
254
    	<span id="spinnerUploadDiv<?=$visitObject->id_visit?>" class="spinner-border text-primary" role="status" style="display: none;">
255
			<span class="sr-only">Loading...</span>
256
		</span>
257
		<span id="checkIconDiv<?=$visitObject->id_visit?>" style="display: none;">
258
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="16" viewBox="0 0 12 16">
259
				<path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z"/>
260
			</svg>
261
		</span>
262
		<br>
263
		<label><b>Quality Control Status:</b> <?=$visitObject->stateQualityControl?></label>
264
    </div>
265
    <?php
266
}
267
// If reviewer or controler with awaiting QC action add an invisible form and a button to make dicom zip dowload
268
if ($role == User::REVIEWER || ($role == User::INVESTIGATOR && $visitObject->uploadStatus == Visit::DONE) || ($role == User::CONTROLLER && ($visitObject->stateQualityControl == Visit::QC_WAIT_DEFINITVE_CONCLUSION || $visitObject->stateQualityControl == Visit::QC_NOT_DONE))) {
269
	?>
270
    <div class="text-center mt-3 mb-3">
271
    	<input class="btn btn-primary" type="button"
272
    		id="reviewerDownloadDicomBtn" value="Download DICOM">
273
		<input class="btn btn-primary" type="button"
274
    		id="OHIFViewer" value="OHIF Viewer">
275
    </div>
276
    <form id="downloadForm" method="post"
277
    	action="scripts/download_dicom.php">
278
    	<input type="hidden" name="id_visit" value="<?=$id_visit?>">
279
    
280
    </form>
281
282
<?php
283
}
284
// If upload validated display the detailed tables
285
if ($visitObject->uploadStatus == Visit::DONE && $role != User::REVIEWER) {
286
	build_patient_visit_table($patientObject, $role);
287
	build_visit_details_table(array($visitObject), $_SESSION['role']);
288
	build_table_series($role, $visitObject);
289
}
290
?>
291
292
<div id="dicomUploaderv2" class="mt-3"></div>
293
<div id="correctiveAction"></div>
294
<div id="controlerForm"></div>
295
<div id="formInvestigator"></div>
296
297
<?php
298
function replaceEmpty($data) {
299
	if (empty($data)) {
300
		return ('/');
301
	}else {
302
		return (htmlspecialchars($data));
303
	}
304
}
305
/**
306
 * Generate Table of series details of a given visit for visit investigator interface
307
 */
308
function build_table_series($role, $visitObject)
309
{
310
	// Get Series Object Array with details
311
	$data_series=$visitObject->getSeriesDetails();
312
    
313
	$series_number=count($data_series);
314
    
315
	if ($series_number == 0) return;
316
    
317
	$colspan=$series_number+1;
318
	?>
319
	<div class="accordion mt-3" id="accordionExample">
320
		<div >
321
			<div id="headingOne">
322
				<h2 class="mb-0">
323
					<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#seriesDetails" aria-expanded="true" aria-controls="collapseOne">
324
						Show/Hide Series Details
325
					</button>
326
				</h2>
327
			</div>
328
329
			<div id="seriesDetails" class="show mt-3" aria-labelledby="headingOne" data-parent="#accordionExample">
330
			<div>
331
				<div style="overflow-x:auto;"> 
332
					<table id="tab_series" class="table table-striped">
333
						<tr>
334
							<th colspan=<?=$colspan ?>>Series information</th>
335
						</tr>
336
						<tr>
337
							<td>Series Number</td>
338
							<?php 
339
							for ($i=0; $i < $series_number; $i++) {
340
								if (empty($data_series[$i]->seriesNumber))
341
									?>
342
									<td> 
343
										<?=replaceEmpty($data_series[$i]->seriesNumber)?>
344
									</td>
345
							<?php 
346
							}?>
347
						</tr>
348
						<tr>
349
							<td>Manufacturer</td>
350
							<?php 
351
							for ($i=0; $i < $series_number; $i++) {
352
								?>
353
								<td>
354
									<?=replaceEmpty($data_series[$i]->manufacturer)?>
355
								</td>
356
						<?php 
357
							}?>
358
						</tr>
359
						<tr>
360
							<td>Series Description</td>
361
							<?php 
362
							for ($i=0; $i < $series_number; $i++) {
363
								?>
364
								<td>
365
									<?=replaceEmpty($data_series[$i]->seriesDescription)?>
366
								</td>
367
						<?php 
368
							}
369
							?>
370
						</tr>
371
						<tr>
372
							<td>Modality</td>
373
							<?php 
374
							for ($i=0; $i < $series_number; $i++) {
375
								?>
376
								<td>
377
									<?=replaceEmpty($data_series[$i]->modality)?>
378
								</td>
379
						<?php 
380
							}
381
							?>
382
						</tr>
383
						<tr>
384
							<td>Acquisition Date Time</td>
385
							<?php 
386
							for ($i=0; $i < $series_number; $i++) {
387
								?>
388
								<td>
389
									<?=replaceEmpty($data_series[$i]->acquisitionDateTime)?>
390
								</td>
391
						<?php 
392
							}
393
							?>
394
						</tr>
395
						<tr>
396
							<td>Total Dose (MBq)</td>
397
							<?php 
398
							for ($i=0; $i < $series_number; $i++) {
399
								?>
400
								<td>
401
								<?php if (empty($data_series[$i]->injectedDose)) {
402
									echo('/');
403
								}else {
404
									echo(htmlspecialchars($data_series[$i]->injectedDose/10 ** 6));
405
								}
406
								?>
407
								</td>
408
							<?php
409
							}
410
							?>
411
						</tr>
412
						<tr>
413
							<td>Radiopharmaceutical</td>
414
							<?php 
415
							for ($i=0; $i < $series_number; $i++) {
416
								?>
417
								<td>
418
									<?=replaceEmpty($data_series[$i]->radiopharmaceutical)?>
419
								</td>
420
						<?php 
421
							}
422
							?>
423
						</tr>
424
						<tr>
425
							<td>Injection Date Time</td>
426
							<?php 
427
							for ($i=0; $i < $series_number; $i++) {
428
								?>
429
								<td>
430
									<?=replaceEmpty($data_series[$i]->injectedDateTime)?>
431
								</td>
432
						<?php 
433
							}
434
							?>
435
						</tr>
436
						<tr>
437
							<td>Radiopharm. Specific Activity (MBq)</td>
438
							<?php 
439
							for ($i=0; $i < $series_number; $i++) {
440
								?>
441
								<td>
442
								<?php if (empty($data_series[$i]->injectedActivity)) {
443
									echo('/');
444
								}else {
445
									echo(htmlspecialchars($data_series[$i]->injectedActivity/10 ** 6));
446
								}
447
								?>
448
								</td>
449
							<?php
450
							}
451
							?>
452
						</tr>
453
						<tr>
454
							<td>Half Life (s)</td>
455
							<?php 
456
							for ($i=0; $i < $series_number; $i++) {
457
								?>
458
								<td>
459
									<?=replaceEmpty($data_series[$i]->halfLife)?>
460
								</td>
461
							<?php 
462
							}
463
							?>
464
						</tr>
465
						<tr>
466
							<td>Patient's Weight (kg)</td>
467
							<?php 
468
							for ($i=0; $i < $series_number; $i++) {
469
								?>
470
								<td>
471
									<?=replaceEmpty($data_series[$i]->patientWeight)?>
472
								</td>
473
							<?php 
474
							}
475
							?>
476
						</tr>
477
						<tr>
478
							<td>Slice Count</td>
479
							<?php 
480
							for ($i=0; $i < $series_number; $i++) {
481
								?>
482
								<td>
483
									<?=replaceEmpty($data_series[$i]->numberInstances)?>
484
								</td>
485
							<?php 
486
							}
487
							?>
488
						</tr>
489
						<tr>
490
							<td>Upload Date</td>
491
							<?php 
492
							for ($i=0; $i < $series_number; $i++) {
493
								?>
494
								<td>
495
									<?=replaceEmpty($data_series[$i]->studyDetailsObject->uploadDate)?>
496
								</td>
497
							<?php 
498
							}
499
							?>
500
						</tr>
501
						<?php 
502
						if (($role == User::INVESTIGATOR || $role == User::CONTROLLER) && ($visitObject->stateQualityControl != Visit::QC_ACCEPTED && $visitObject->stateQualityControl != Visit::QC_REFUSED)) {
503
						?><tr>
504
							<td>Delete</td>
505
						<?php 
506
						for ($i=0; $i < $series_number; $i++) {
507
							?>
508
							<td>
509
								<a href=scripts/change_series_deletion.php?action=delete&Series_Orthanc_Id=<?=htmlspecialchars($data_series[$i]->seriesOrthancID)?> class="ajaxLinkConfirm" ><input class="btn btn-danger" type="button" value="Delete Series"></a>
510
							</td>
511
						<?php 
512
						}
513
						?>
514
						</tr>
515
						<tr>
516
							<td colspan="<?=$colspan?>">
517
								<a href=scripts/change_series_deletion.php?action=delete&Series_Orthanc_Id=allVisit<?=$visitObject->id_visit?> class="ajaxLinkConfirm" ><input class="btn btn-danger" type="button" value="Delete All (Reset Upload)"></a>
518
							</td>
519
						</tr>
520
					<?php 
521
					}?>
522
					</table> 
523
				</div>
524
			</div>
525
			</div>
526
		</div>
527
	</div>
528
	
529
	
530
	
531
<?php 
532
}
533
?>