joshy / meta Goto Github PK
View Code? Open in Web Editor NEWWebinterface to Apache Solr to make a PACS searchable
Webinterface to Apache Solr to make a PACS searchable
Pasting multiple names is not working. Those needs to be quoted with semicolon. For example
"Hans Mueller" "Meier Jonas" etc.
Currently the report names are given in the fomart accession_id-report.txt. It would be useful to have information about patient as well e.g. patient_id-accession_id-report.txt.
Incorporate table / pandas export in Meta
# make a simple query
from itertools import chain
from warnings import warn
from datetime import datetime
import numpy as np
conv_date = lambda x: datetime.strptime(x, '%Y-%m-%d')
as_solr_date = lambda x: x.strftime('%Y%m%d')
import dateutil.relativedelta as rd
conv_diag = lambda x: {'end_date': as_solr_date(x.to_pydatetime()+rd.relativedelta(months = 18)),
'start_date': as_solr_date(x.to_pydatetime()-rd.relativedelta(months = 18))}
str_diff = lambda seq1,seq2: sum(1 for a, b in zip(seq1, seq2) if a != b) + abs(len(seq1) - len(seq2))
def search_solr(in_query = '*:*'):
params = query.DEFAULT_PAYLOAD
params['limit'] = 2000
payload = query.query_body(params).copy()
payload['query'] = in_query
headers = {'content-type': "application/json"}
response = requests.get(solr_url(), data=json.dumps(payload), headers=headers)
data = response.json()
docs = data['grouped']['PatientID']
docs = group(docs)
return list(chain(*chain(*[cgrp['by_AccessionNumber'].values() for cgrp in docs['groups']]))), docs['matches']
def summarize_solr(in_row, in_query):
c_results, n_cnt = search_solr(in_query)
if len(c_results) != n_cnt:
warn("Results should be equal to matches, check limits {} != {}".format(len(c_results), n_cnt), RuntimeWarning)
# check the name first
onco_name = '{NACHNAME}^{VORNAME}'.format(**in_row).upper()
avg_diff = [(str_diff(x['PatientName'],onco_name),x['PatientName']) for x in c_results]
nmis_field = ', '.join(np.unique([name for cnt, name in avg_diff if cnt>0]))
n_matches = sum(map(lambda x: x[0]==0, avg_diff))
full_count = len(c_results)
if n_matches>0:
# filter the non matches out
c_results = [x for x in c_results if str_diff(x['PatientName'],onco_name)==0]
u_vals = lambda res_list, x: ', '.join(np.unique([i[x] for i in res_list]))
n_field = u_vals(c_results, 'PatientName')
mod_field = u_vals(c_results, 'Modality')
acc_num = u_vals(c_results, 'AccessionNumber')
try:
studies = [(x['Modality'], x['StudyDate'],x['AccessionNumber'],x.get('SeriesDescription',None)) for x in c_results]
except:
# show the exact result which is missing something
for x in c_results:
try:
[(x['Modality'], x['StudyDate'],x['AccessionNumber'],x['SeriesDescription'])]
except:
raise ValueError('Missing key! {}'.format(x))
return {'solr_mismatched_names': nmis_field,
'solr_modalities': mod_field,
'solr_count': full_count,
'solr_name_matches': n_matches,
'solr_accession_number': acc_num,
'solr_studies': studies,
'has_petct': (mod_field.find('PT')>=0) and (mod_field.find('CT')>=0)}
For running the command "docker-compose" with the file "./docker-compose.yml" you need the version higher then 1.4.0. Installation guide --> https://docs.docker.com/compose/install/
solr_api.search_solr({'query': 'AccessionNumber:-1'})
Should return no records (an empty dataframe) instead there is an error message
KeyError Traceback (most recent call last)
<ipython-input-103-c7e211f9f9ce> in <module>()
----> 1 solr_api.search_solr({'query': 'AccessionNumber:-1'})
/Users/pacs/meta/meta/solr_api.py in search_solr(params)
39 """
40
---> 41 results = _result(params)
42 data_frames = []
43 for page in range(0, results, INTERNAL_LIMIT):
/Users/pacs/meta/meta/solr_api.py in _result(params)
53 response = get(solr_url(app.config), data=json.dumps(payload), headers=headers)
54 data = response.json()
---> 55 docs = data['grouped']['PatientID']
56 results = int(docs['matches'])
57 # add additional request to get the remaining results
KeyError: 'grouped'
Facets are now broken, because e.g. StudyDescription is an input now. The rendered link now contains two StudyDecriptions e.g. ['', 'lorem ipsum']
Current state:
In order to get a report on the accession level, you have to uncollapse the accession and select all or one of the series.
Problems:
You have to go to series level to get the accession level report.
If you collapse the accession, you will not know what is selected.
Solution:
It would be more intuitive and more user-friendly to have check box for the whole accession when cllapsed, so no uncollapsing is needed to see what is happening inside and it would be possible to get reports in an easier way.
Suggestion:
Movescu needs the dcm.in file for transferring, downloading probably not.
Ideally there should be an option to export the results to csv. Than all results needs to be collected (use solr_api?) and returned to the user as a file. Maybe two options are needed:
This needs to be in the results and not in the form, so the user can first drill down the information they needed and then export.
Move all the transfer and download job to a separate app. Current choices are:
Celery + RabbitMQ + CouchDB to store the result.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.