Skip to content

Commit

Permalink
Changes made
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishchal-007 committed Jul 1, 2021
1 parent f2e70b5 commit 29ec9bb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
24 changes: 4 additions & 20 deletions modules/cold-extraction/ColdDataRetriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ def initialize_Values(valuesDict):
global storescp_processes, niffler_processes, nifflerscp_str, qbniffler_str
global storage_folder, file_path, csv_file, extraction_type, accession_index, patient_index, date_index, date_type, date_format, email, send_email, system_json
global DCM4CHE_BIN, SRC_AET, QUERY_AET, DEST_AET, NIGHTLY_ONLY, START_HOUR, END_HOUR, IS_EXTRACTION_NOT_RUNNING, NIFFLER_ID, MAX_PROCESSES, SEPARATOR
global accessions, patients, dates, niffler_log, resume, upload_folder

logs = [] # For showing logs on frontend if any error occurs
global accessions, patients, dates, niffler_log, resume

upload_folder = '../cold-extraction/csv/' # This is a check for frontend only,it won't conflict when program is run from terminal
if not os.path.exists(upload_folder):
os.makedirs(upload_folder)
storage_folder = valuesDict['storage_folder']
file_path = valuesDict['file_path']
csv_file = valuesDict['CsvFile']
Expand All @@ -38,21 +33,11 @@ def initialize_Values(valuesDict):
email = valuesDict['email']
send_email = bool(valuesDict['send_email'])
system_json = valuesDict['NifflerSystem']

csv_file = upload_folder + csv_file

# Reads the system_json file.
# This is a check as if user enters wrong json then the frontend would notify user
system_json_file = '../cold-extraction/' + system_json
try:
with open(system_json_file, 'r') as f:
niffler = json.load(f)
except:
err = "Error could not load given " + system_json + " file !!"
logs.append(err)
logging.shutdown()
return logs

with open(system_json, 'r') as f:
niffler = json.load(f)

# Get constants from system.json
DCM4CHE_BIN = niffler['DCM4CHEBin']
SRC_AET = niffler['SrcAet']
Expand Down Expand Up @@ -101,7 +86,6 @@ def initialize_Values(valuesDict):
# record the start time
t_start = time.time()
run_cold_extraction()
return logs

# Check and kill the StoreScp processes.
def check_kill_process():
Expand Down
57 changes: 37 additions & 20 deletions modules/frontend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
PEOPLE_FOLDER = os.path.join('static','styles')
UPLOAD_FOLDER = '../cold-extraction/csv' # Need to change this to a particular server path
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

COLD_UPLOAD_FOLDER = '../cold-extraction/' # Need to change this to a particular server path
app.config['COLD_UPLOAD_FOLDER'] = COLD_UPLOAD_FOLDER
# app = Flask(__name__)

login_manager = LoginManager(app)
Expand Down Expand Up @@ -116,6 +119,7 @@ def extract_png():
@app.route('/cold-extraction', methods=['GET', 'POST'])
@login_required
def cold_extraction():
logs = []
csv_folder = UPLOAD_FOLDER
if not os.path.exists(csv_folder):
os.makedirs(csv_folder)
Expand All @@ -128,9 +132,9 @@ def cold_extraction():
if(f1):
filename = secure_filename(f1.filename)
f1.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
cold_extraction_values['CsvFile'] = filename
cold_extraction_values['CsvFile'] = os.path.join(app.config['UPLOAD_FOLDER'],filename)
else:
cold_extraction_values['CsvFile'] = f2
cold_extraction_values['CsvFile'] = os.path.join(app.config['UPLOAD_FOLDER'],f2)

NifflerSystem = request.form['NifflerSystem']
if(NifflerSystem == '' or len(NifflerSystem) == 0):
Expand All @@ -151,24 +155,37 @@ def cold_extraction():
if(date_format == '' or len(date_format) == 0):
date_format = '%Y%m%d'

cold_extraction_values['NifflerSystem'] = NifflerSystem
cold_extraction_values['storage_folder'] = request.form['StorageFolder']
cold_extraction_values['file_path'] = file_path
cold_extraction_values['extraction_type'] = request.form['ExtractionType']
cold_extraction_values['accession_index'] = accession_index
cold_extraction_values['patient_index'] = patient_index
cold_extraction_values['date_index'] = date_index
cold_extraction_values['date_type'] = request.form['DateType']
cold_extraction_values['date_format'] = date_format
cold_extraction_values['send_email'] = request.form['sendEmail']
cold_extraction_values['email'] = request.form['email']

import sys
import io
sys.path.append("../cold-extraction/")
import ColdDataRetriever
x = ColdDataRetriever.initialize_Values(cold_extraction_values)
return render_template('cold_extraction.html', logs = x, files_list = files_present_in_server)
NifflerSystem_File = COLD_UPLOAD_FOLDER + NifflerSystem
checkfile = True
try:
with open(NifflerSystem_File, 'r') as f:
checkfile = True
except:
err = "Error could not load given " + NifflerSystem + " file !!"
logs.append(err)
checkfile = False

if checkfile:
cold_extraction_values['NifflerSystem'] = NifflerSystem_File
cold_extraction_values['storage_folder'] = request.form['StorageFolder']
cold_extraction_values['file_path'] = file_path
cold_extraction_values['extraction_type'] = request.form['ExtractionType']
cold_extraction_values['accession_index'] = accession_index
cold_extraction_values['patient_index'] = patient_index
cold_extraction_values['date_index'] = date_index
cold_extraction_values['date_type'] = request.form['DateType']
cold_extraction_values['date_format'] = date_format
cold_extraction_values['send_email'] = request.form['sendEmail']
cold_extraction_values['email'] = request.form['email']

import sys
import io
sys.path.append("../cold-extraction/")
import ColdDataRetriever
x = ColdDataRetriever.initialize_Values(cold_extraction_values)
return render_template('cold_extraction.html', logs = logs, files_list = files_present_in_server)
else:
return render_template('cold_extraction.html', logs = logs, files_list = files_present_in_server)
return render_template('cold_extraction.html', files_list = files_present_in_server)
#JUST DO IT!!!
if __name__=="__main__":
Expand Down

0 comments on commit 29ec9bb

Please sign in to comment.