def main(): """ Renders the initial page. """ url = query_indexed_dates(solr_url(app.config)) try: response = get(url) except RequestException: return render_template( "search.html", params={}, error="No response from Solr, is it running?", trace=solr_url(app.config), ) stats = response.json()["stats"] indexed_start_date = stats["stats_fields"]["StudyDate"]["min"] indexed_end_date = stats["stats_fields"]["StudyDate"]["max"] return render_template( "search.html", version=VERSION, page=0, offset=0, params={"RisReport": "*"}, indexed_start_date=indexed_start_date, indexed_end_date=indexed_end_date, mova_url=MOVA_URL, mova_dashboard_url=MOVA_DASHBOARD_URL, )
def download_all(): app.logger.info("download all called") q = request.form df = query_all(q, solr_url(app.config)) data = convert(df) download_data = {"data": data, "dir": q["download-dir"]} return download_or_transfer(MOVA_DOWNLOAD_URL, download_data)
def test_url(self): config = { 'SOLR_CORE_NAME': 'foo', 'SOLR_PORT': '8983', 'SOLR_HOSTNAME': 'http://localhost' } self.assertEqual('http://http://localhost:8983/solr/foo/query', solr_url(config))
def get_statistics(): payload = { "q": "*", "rows": "10000000", "fq": ["Category:parent"], "fl": "InstitutionName, StudyDate", } headers = {"content-type": "application/json"} response = get(solr_url(app.config), payload, headers=headers) return response.json()
def export(): q = request.form df = query_all(q, solr_url(app.config)) out = io.BytesIO() writer = pd.ExcelWriter(out) df.to_excel(writer, index=False, sheet_name="Sheet1") writer.save() writer.close() out.seek(0) return send_file(out, attachment_filename="export.xlsx", as_attachment=True)
def transfer_all(): """ Ajax post to transfer series of images to <target> PACS node. """ app.logger.info("transfer all called") q = request.form df = query_all(q, solr_url(app.config)) data = convert(df) target = q["target"] transfer_data = {"data": data, "target": q["target"]} app.logger.info(f"Transfer called and sending to AE_TITLE {target}") t = [t for t in TRANSFER_TARGETS if t["DISPLAY_NAME"] == target] if t: destination = t[0]["AE_TITLE"] transfer_data["target"] = destination return download_or_transfer(MOVA_TRANSFER_URL, transfer_data) else: return f"Error: Could not find destination AE_TITLE for {t}"
def search(): """ Renders the search results. """ params = request.form payload = query_body(params, RESULT_LIMIT) headers = {'content-type': "application/json"} try: response = get(solr_url(app.config), data=json.dumps(payload), headers=headers) if response.status_code == 400 or response.status_code == 500: result = response.json() error = result['error'] msg = result['error']['msg'] trace = error.get('trace', '') return render_template('search.html', params={}, offset='0', error='Solr failed: ' + msg, trace=trace) app.logger.debug('Calling Solr with url %s', response.url) app.logger.debug('Request body %s', json.dumps(payload)) data = response.json() docs = data['grouped']['PatientID'] docs = group(docs) facets = prepare_facets(data.get('facets', []), request.url) results = data['grouped']['PatientID']['ngroups'] paging = calc(results, params.get('offset', '0'), RESULT_LIMIT) demo = app.config['DEMO'] return render_template('result.html', docs=docs, results=results, facets=facets, payload=payload, facet_url=request.url, params=params, paging=paging, version=VERSION, modalities=params.getlist('Modality'), offset=params.get('offset', '0'), demo=demo) except RequestException: return render_template('search.html', params={}, error='No response from Solr, is it running?')
def search(): params = request.args payload = meta.query.query_body(params) headers = {'content-type': "application/json"} response = requests.get(solr_url(), data=json.dumps(payload), headers=headers) app.logger.debug('Calling Solr with url %s', response.url) app.logger.debug('Request body %s', json.dumps(payload)) try: if response.status_code == 400 or response.status_code == 500: result = response.json() error = result['error'] msg = result['error']['msg'] trace = error.get('trace', '') return render_template('search.html', params={}, error=' Call to Solr failed: ' + msg, trace=trace) data = response.json() docs = data['grouped']['PatientID'] docs = group(docs) facets = prepare_facets(data.get('facets', []), request.url) results = data['grouped']['PatientID']['ngroups'] paging = calc(results, request.url, params.get('offset', '1')) return render_template('result.html', docs=docs, results=results, facets=facets, payload=payload, facet_url=request.url, params=params, paging=paging, version=app.config['VERSION'], modalities=params.getlist('Modality')) except json.JSONDecodeError: return render_template('search.html', params={}, error='Can\'t decode JSON, is Solr running?')
def search(): """ Renders the search results. """ params = request.form payload = query_body(params, RESULT_LIMIT) headers = {"content-type": "application/json"} try: response = get(solr_url(app.config), data=json.dumps(payload), headers=headers) except RequestException: return render_template( "search.html", params=params, error="No response from Solr, is it running?", trace=solr_url(app.config), ) if response.status_code >= 400 and response.status_code < 500: logging.error(response.text) return render_template( "search.html", params=params, page=0, offset=0, error=response.reason, trace=response.url, ) elif response.status_code >= 500: result = response.json() error = result["error"] msg = result["error"]["msg"] trace = error.get("trace", "") logging.error(reposonse.text) return render_template( "search.html", params=params, page=0, offset=0, error="Solr failed: " + msg, trace=trace, ) else: app.logger.debug("Calling Solr with url %s", response.url) data = response.json() docs = data["grouped"]["PatientID"] results = data["grouped"]["PatientID"]["ngroups"] studies_result = data["grouped"]["PatientID"]["matches"] page = params.get("page", 0) offset = params.get("offset", 0) paging = calc(results, page, RESULT_LIMIT) return render_template( "result.html", docs=docs, results="{:,}".format(results), studies_result="{:,}".format(studies_result), payload=payload, facet_url=request.url, params=params, paging=paging, version=VERSION, report_show_url=REPORT_SHOW_URL, zfp_viewer=ZFP_VIEWER, modalities=params.getlist("Modality"), page=page, offset=0, show_download_options=SHOW_DOWNLOAD_OPTIONS, show_transfer_targets=SHOW_TRANSFER_TARGETS, transfer_targets=TRANSFER_TARGETS, mova_url=MOVA_URL, mova_dashboard_url=MOVA_DASHBOARD_URL, )