def getRiMappedImage(case_id, index_1, index_2): #if username is in session then the call is web call, so use that username if 'username' in session and len(session['username']) > 0: username = session['username'] elif 'key' not in request.args or len(request.args['key']) == 0: abort(403) return "" else: auth_result = Auth.checkKeyValidity(request.args['key']) if not auth_result['valid']: abort(403) return "" username = auth_result['username'] if not PatientCases.userHasAuthentication(case_id, username): abort(403) return "" #TODO get the ri-buffer from a controller module and send it to the Response #for testing only f = PatientCases.findImage(case_id, index_1, index_2) if f == None: abort(404) buffer = Conversions(f['disk_filename']).dicomToRIColoredImage() return Response(buffer, mimetype='image/jpeg')
def getAllCaseImages(case_id): result = {'error': {}} #if username is in session then the call is web call, so use that username if 'username' in session and len(session['username']) > 0: username = session['username'] else: if 'key' not in request.args or len(request.args['key']) == 0: result['error']['error'] = True result['error']['error_msgessage'] = "key not specified" return jsonify(result) auth_result = Auth.checkKeyValidity(request.args['key']) if not auth_result['valid']: result['error']['error'] = True result['error']['error_msgessage'] = "key not valid" return jsonify(result) username = auth_result['username'] if not PatientCases.userHasAuthentication(case_id, username): result['error']['error'] = True result['error'][ 'error_msgessage'] = "logged in user do not have permission to acccess this case" return jsonify(result) case_result = PatientCases.findCase(case_id) if case_result == None: result['error']['error'] = True result['error']['error_msgessage'] = "Case id not valid" return jsonify(result) #Now that the authentication is done process the result and respond according to the api refference #take the files from the case result files = case_result['files'] result['error']['error'] = False result['images'] = [] i = 0 #to keep track of index_1 for file in files: series = {} series['series_description'] = file['series_description'] series['series_time'] = file['series_time'] series['images'] = [] j = 0 #to keep track of index_2 for image in file['images']: img = {} img['filename'] = image['org_filename'] img['url'] = BASE_URL + url_for('patient_cases_api.getImage', case_id=case_id, index_1=i, index_2=j) j += 1 series['images'].append(img) i += 1 result['images'].append(series) return jsonify(result)
def getSeriesRiImages(case_id, index_1): result = {'error': {}} #if username is in session then the call is web call, so use that username if 'username' in session and len(session['username']) > 0: username = session['username'] else: if 'key' not in request.args or len(request.args['key']) == 0: result['error']['error'] = True result['error']['error_msgessage'] = "key not specified" return jsonify(result) auth_result = Auth.checkKeyValidity(request.args['key']) if not auth_result['valid']: result['error']['error'] = True result['error']['error_msgessage'] = "key not valid" return jsonify(result) username = auth_result['username'] if not PatientCases.userHasAuthentication(case_id, username): result['error'][ 'error_msgessage'] = "logged in user do not have permission to acccess this case" return jsonify(result) series_result = PatientCases.findSeries(case_id, index_1) if series_result == None: result['error']['error'] = True result['error']['error_msgessage'] = "Case id not valid" return jsonify(result) if 't2' not in series_result[ 'series_description'] and 'T2' not in series_result[ 'series_description']: result['error']['error'] = True result['error'][ 'error_msgessage'] = "The series selected is not a T2 series. Cannot be RI mapped" return jsonify(result) result['error']['error'] = False result['images'] = [] i = 0 for image in series_result['images']: img = {} img['filename'] = image['org_filename'] img['url'] = BASE_URL + url_for('patient_cases_api.getRiMappedImage', case_id=case_id, index_1=index_1, index_2=i) i += 1 result['images'].append(img) return jsonify(result)
def getImage(case_id, index_1, index_2): # get the case from db series = PatientCases.findSeries(case_id, index_1) if series == None: abort(404) elif PatientCases.userHasAuthentication(case_id, session['username']): result = { 'status': 'success', 'series': series, 'index_1': index_1, 'index_2': index_2 } else: result = { 'status': 'error', 'msg': 'You do not have sufficient authentication to access the file' } return render_template('image-view.html', result=result)
def getImageCount(case_id, index_1): result = {'error': {}} #if username is in session then the call is web call, so use that username if 'username' in session and len(session['username']) > 0: username = session['username'] else: if 'key' not in request.args or len(request.args['key']) == 0: result['error']['error'] = True result['error']['error_msgessage'] = "key not specified" return jsonify(result) auth_result = Auth.checkKeyValidity(request.args['key']) if not auth_result['valid']: result['error']['error'] = True result['error']['error_msgessage'] = "key not valid" return jsonify(result) username = auth_result['username'] if not PatientCases.userHasAuthentication(case_id, username): result['error']['error'] = True result['error'][ 'error_msgessage'] = "logged in user do not have permission to acccess this case" return jsonify(result) series_result = PatientCases.findSeries(case_id, index_1) if series_result == None: result['error']['error'] = True result['error']['error_msgessage'] = "Case id not valid" return jsonify(result) result['error']['error'] = False result['count'] = len(series_result['images']) return jsonify(result)
def analyseSingleImage(case_id, index_1, index_2): result = {'error': {'error': False}} #if username is in session then the call is web call, so use that username if 'username' in session and len(session['username']) > 0: username = session['username'] elif 'key' not in request.args or len(request.args['key']) == 0: abort(403) return "" else: auth_result = Auth.checkKeyValidity(request.args['key']) if not auth_result['valid']: abort(403) return "" username = auth_result['username'] if not PatientCases.userHasAuthentication(case_id, username): abort(403) return "" f = PatientCases.findImage(case_id, index_1, index_2) if f == None: return abort(404) result['error']['error'] = False if 're_analysis' not in request.args or request.args[ 're_analysis'] == 'false': analysis = AnalysisResult.findByCase(case_id, index_1, index_2) if analysis == None: flag = True else: analysis['error'] = result['error'] analysis['analysis_image'] = BASE_URL + url_for( 'patient_cases_api.analysisImage', case_id=case_id, index_1=index_1, index_2=index_2, analysis_id=str(analysis['_id'])) #pop fields that are not required as response to api analysis_index = 0 for infected_area in analysis['infected_areas']: #pop fields that are not required as response to api infected_area.pop('points') infected_area.pop('box_width') infected_area.pop('box_height') #add the update url infected_area['update_actual_result_url'] = BASE_URL + url_for( 'patient_cases_api.uploadAnlysis', case_id=case_id, index_1=index_1, index_2=index_2, analysis_id=str(analysis['_id']), analysis_index=analysis_index) analysis_index += 1 #pop fields that are not required as response to api analysis.pop('_id') analysis.pop('case_id') analysis.pop('index_1') analysis.pop('index_2') return jsonify(analysis) else: flag = True if flag: dicom = Conversions(f['disk_filename']) cluster = SingleClusterer(dicom) result['infected_areas'] = [] infected_areas = [] AnalysisResult.delete(case_id, index_1, index_2) for _disease_key in cluster.diseases.keys(): disease_clusters = cluster.diseases_clusters[_disease_key] if len(disease_clusters.keys()) > 0: for disease_cluster_key in disease_clusters.keys(): c = disease_clusters[disease_cluster_key] c.compute() #c.searchForDiseases() i_area = {} i_area['detected_result'] = _disease_key i_area['coordinate'] = c.p1 i_area['area'] = c.getTightArea() i_area['tumor_width'] = c.tumorwidth i_area['tumor_height'] = c.tumorheight i_area['average_chemical_composition'] = { 'x': (0, 0.5, 0.8, 1.3, 1.4, 1.5, 1.6, 1.8, 2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.7, 3.9, 4, 4.4), 'y': c.getAverageChemicalComposition(), 'labels': ('', '', 'LIP', '', 'LAC', '', '', '', 'NAA', 'GLM', '', '', 'CR', '', 'CHO', '', 'MI', '', 'CR2', '') } infected_areas.append( InfectedAreas((c.p1[0], c.p1[1]), c.getWidth(), c.getHeight(), c.tumorwidth, c.tumorheight, i_area['average_chemical_composition'], c.getArea(), _disease_key, c.elements)) result['infected_areas'].append(i_area) #result['diseases'].append(disease) if len(infected_areas) != 0: analysisResult = AnalysisResult(case_id, index_1, index_2, infected_areas) analysis_id = analysisResult.save() result['analysis_image'] = BASE_URL + url_for( 'patient_cases_api.analysisImage', case_id=case_id, index_1=index_1, index_2=index_2, analysis_id=analysis_id) analysis_index = 0 for infected_area in result['infected_areas']: infected_area['update_actual_result_url'] = BASE_URL + url_for( 'patient_cases_api.uploadAnlysis', case_id=case_id, index_1=index_1, index_2=index_2, analysis_id=analysis_id, analysis_index=analysis_index) analysis_index += 1 return jsonify(result)
'status': 'success', 'cases': cases }) #the page to view all the series in a case #return 403 if the logged in user is not authorized to access the image @case_bp.route('/<case_id>/images/', methods=['GET']) @case_bp.route('/<case_id>/', methods=['GET']) @login_required def getCase(case_id): # get the case from db case = PatientCases.findCase(case_id) if case == None: abort(404) elif PatientCases.userHasAuthentication(case_id, session['username']): result = {'status': 'success', 'case': case} else: result = { 'status': 'error', 'msg': 'You do not have sufficient authentication to access the file' } return render_template('series-view.html', result=result) #the page to view all the images in a series #return 403 if the logged in user is not authorized to access the image @case_bp.route('/<case_id>/images/<int:index_1>/', methods=['GET']) @case_bp.route('/<case_id>/<int:index_1>/', methods=['GET']) @login_required