@@ -540,6 +540,84 @@ def _processTriangulationAndKimLogs(self, metadata, filename, uploadMetaData, fi
540
540
)
541
541
return saveFolderPath
542
542
return ""
543
+
544
+ def _processCHIRPPresLevel (self , metadata , filename , uploadMetaData , filesSaved , fileTypeToPathMapping , formatedPath ):
545
+ uploadId :str = metadata ["upload_context" ]
546
+ relativeFolderPath = fileTypeToPathMapping [metadata ["file_type" ]].format (
547
+ clinical_trial = metadata ['clinical_trial' ],
548
+ test_centre = metadata ["test_centre" ],
549
+ centre_patient_no = int (metadata ["centre_patient_no" ])
550
+ )
551
+ relativePath = uploadId + relativeFolderPath + filename
552
+ saveFolderPath = config .UPLOAD_FOLDER + '/' + uploadId + relativeFolderPath
553
+ filesSaved .append (relativePath )
554
+
555
+ filePathAppended :bool = False
556
+ for uploadedFileRecord in uploadMetaData ["uploaded_files" ]:
557
+ if uploadedFileRecord ["file_type" ] == metadata ["file_type" ]:
558
+ uploadedFileRecord ["Files" ].append (relativePath )
559
+ filePathAppended = True
560
+ break
561
+
562
+ if not filePathAppended :
563
+ uploadMetaData ["uploaded_files" ].append (
564
+ {
565
+ "file_type" : metadata ["file_type" ],
566
+ "level" : metadata ["level" ],
567
+ "Files" : [relativePath ],
568
+ "folder_path" : [relativeFolderPath ]
569
+ }
570
+ )
571
+ return saveFolderPath
572
+
573
+ def _processCHIRPFractionLevel (self , metadata , filename , uploadMetaData , filesSaved , fileTypeToPathMapping , formatedPath ):
574
+ uploadId :str = metadata ["upload_context" ]
575
+ fractionNumber = re .search (r'(?i)fx(\d+)' , formatedPath ).group (1 )
576
+ fractionName = re .search (r'/(?P<result>[^/]+)' , formatedPath ).group ("result" )
577
+ relativeFolderPath = fileTypeToPathMapping [metadata ["file_type" ]].format (
578
+ clinical_trial = metadata ['clinical_trial' ],
579
+ test_centre = metadata ["test_centre" ],
580
+ centre_patient_no = int (metadata ["centre_patient_no" ]),
581
+ ) + fractionName + '/'
582
+ relativePath = uploadId + relativeFolderPath + filename
583
+ saveFolderPath = config .UPLOAD_FOLDER + '/' + uploadId + relativeFolderPath
584
+
585
+ filePathAppended :bool = False
586
+ for uploadedFileRecord in uploadMetaData ["uploaded_files" ]:
587
+ if uploadedFileRecord ["file_type" ] == metadata ["file_type" ]:
588
+ uploadedFileRecord ["Files" ].append (relativePath )
589
+ if fractionNumber not in uploadedFileRecord ["fraction" ]:
590
+ uploadedFileRecord ["fraction" ].append (fractionNumber )
591
+ if fractionName not in uploadedFileRecord ["fraction_name" ]:
592
+ uploadedFileRecord ["fraction_name" ].append (fractionName )
593
+ if fractionNumber not in uploadedFileRecord ["db_file_name" ].keys ():
594
+ uploadedFileRecord ["db_file_name" ][fractionNumber ] = relativeFolderPath
595
+ if relativeFolderPath not in uploadedFileRecord ["folder_path" ]:
596
+ uploadedFileRecord ["folder_path" ].append (relativeFolderPath )
597
+ filePathAppended = True
598
+ if not filePathAppended :
599
+ pack = {
600
+ fractionNumber : relativeFolderPath
601
+ }
602
+ uploadMetaData ["uploaded_files" ].append (
603
+ {
604
+ "file_type" : metadata ["file_type" ],
605
+ "level" : metadata ["level" ],
606
+ "fraction" : [fractionNumber ],
607
+ "fraction_name" : [fractionName ],
608
+ "Files" : [relativePath ],
609
+ "folder_path" : [relativeFolderPath ],
610
+ "db_file_name" : pack
611
+ }
612
+ )
613
+ return saveFolderPath
614
+
615
+ def _processCHIRP (self , metadata , filename , uploadMetaData , filesSaved , fileTypeToPathMapping , formatedPath ):
616
+ if metadata ["level" ] == "prescription" :
617
+ return self ._processCHIRPPresLevel (metadata , filename , uploadMetaData , filesSaved , fileTypeToPathMapping , formatedPath )
618
+ elif metadata ["level" ] == "fraction" :
619
+ return self ._processCHIRPFractionLevel (metadata , filename , uploadMetaData , filesSaved , fileTypeToPathMapping , formatedPath )
620
+
543
621
544
622
def acceptAndSaveFile (self , req :request ):
545
623
# print("Files:", req.files)
@@ -624,7 +702,9 @@ def acceptAndSaveFile(self, req:request):
624
702
uploadedFile = req .files [fileFieldName ]
625
703
filename = secure_filename (uploadedFile .filename )
626
704
formatedPath = os .path .basename (req .form ["file_path" ]).replace ("\\ " , "/" ).replace (filename , "" )
627
- if metadata ["file_type" ] == "fraction_folder" :
705
+ if metadata ["clinical_trial" ] == "CHIRP" :
706
+ saveFolderPath = self ._processCHIRP (metadata , filename , uploadMetaData , filesSaved , fileTypeToPathMapping , formatedPath )
707
+ elif metadata ["file_type" ] == "fraction_folder" :
628
708
saveFolderPath = self ._processImageFractionFolder (metadata , filename , uploadMetaData , filesSaved , fileTypeToPathMapping , formatedPath )
629
709
elif metadata ["file_type" ] == "DICOM_folder" or metadata ["file_type" ] == "DVH_folder" :
630
710
saveFolderPath = self ._processDoseReconstructionPlan (metadata , filename , uploadMetaData , fileTypeToPathMapping , filesSaved , formatedPath )
0 commit comments