Skip to content

Commit

Permalink
mfind compatability adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasyi17 committed Nov 25, 2024
1 parent 06d8e0a commit 32fea5f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions package/diana/cli/commands/mfind.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import logging
from pprint import pformat
import click
import json
from crud.cli.utils import ClickEndpoint, CLICK_ARRAY, CLICK_MAPPING
from crud.utils import SmartJSONEncoder
from diana.apis import Montage
from diana.dixel import RadiologyReport, LungScreeningReport

Expand All @@ -23,6 +25,7 @@
@click.option('--extraction', '-e', multiple=True,
type=click.Choice(['radcat', 'lungrads']),
help="Perform a data extraction on each report")
@click.option('--json', '-j', "as_json", is_flag=True, default=False, help="Output as json")
@click.pass_context
def mfind(ctx,
source: Montage,
Expand All @@ -31,7 +34,8 @@ def mfind(ctx,
end_date,
today,
_query,
extraction):
extraction,
as_json):
"""Find items in Montage by query for chaining.
\b
Expand All @@ -41,6 +45,8 @@ def mfind(ctx,
$ diana-cli mfind -a @my_accessions.txt -e lungrads -e radcat montage print jsonl > output.jsonl
$ cat output.jsonl
{ ... lungrads='2', current_smoker=False, pack_years=15, radcat=(3,true) ... }
$ diana-cli mfind -j --start_date="2024-11-21" --end_date="2024-11-21" -q "report text" montage
"""

click.echo(click.style('Montage Find', underline=True, bold=True))
Expand All @@ -65,8 +71,8 @@ def do_query(q):

if _query:
query["q"] = _query
query["start_date"] = datetime.strptime(str(start_date), "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
query["end_date"] = datetime.strptime(str(end_date), "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
query["start_date"] = start_date.strftime("%Y-%m-%d") # datetime.strptime(str(start_date), "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
query["end_date"] = end_date.strftime("%Y-%m-%d")
result = do_query(query)

elif accession_numbers:
Expand All @@ -93,3 +99,6 @@ def do_query(q):
len(result),
"" if len(result) == 1 else "s"
))

if as_json:
click.echo(json.dumps([d.asdict() for d in result], cls=SmartJSONEncoder, sort_keys=True, indent=4, separators=(',', ': ')))

0 comments on commit 32fea5f

Please sign in to comment.