Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FHIRPath CLI #1283

Closed
lmsurpre opened this issue Jun 25, 2020 · 7 comments
Closed

FHIRPath CLI #1283

lmsurpre opened this issue Jun 25, 2020 · 7 comments
Assignees
Labels
good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed

Comments

@lmsurpre
Copy link
Member

lmsurpre commented Jun 25, 2020

Is your feature request related to a problem? Please describe.
Currently, java project can use our fhirpath implementation by

  1. including a dependency like this:
<dependency>
    <groupId>com.ibm.fhir:fhir-path</groupId>
    <artifactId>fhir-path</artifactId>
    <version>4.3.0</version>
</dependency>

and
2. writing code like this:

FHIRPathEvaluator.evaluator().evaluate(resource, fhirpath);

This works ok, but I think would be cool to build an all-in-one shaded cli jar for our fhirpath module so that we can execute this more easily from the command line:

java -jar fhir-path-$VERSION.jar resource fhirpath

Describe the solution you'd like
Introduce a main that takes arguments for the resource content and the fhirpath string to execute.

Ideally, we could pass resource content from

  • a file
  • a string (raw command line arg); or
  • stdin (so we can pipe to it)

One convention I've seen used is to interpret - as an indicator that we should read from stdin instead of a string or file, but I'm not tied to that.

Look at the fhir-persistence-schema and fhir-swagger-generator projects for examples on how to create the shaded all-in-one jar.

Describe alternatives you've considered
The alternative is to let clients do this themselves or use a different fhirpath engine for simple command-line stuff (e.g. the node fhirpath module).

Additional context
Add any other context or screenshots about the feature request here.

@lmsurpre lmsurpre added good first issue Good for newcomers help wanted Extra attention is needed labels Jun 25, 2020
@lmsurpre
Copy link
Member Author

It would also be nice to:

  1. allow some way to pass jar files to extend the registry for fhirpath operations like memberOf; and
  2. provide some way to see supplemental issues that were generated during the evaluation, maybe by printing those to System.error by default (with an option to suppress that)

@erodrago
Copy link

erodrago commented Oct 8, 2020

Would like to try out this issue @lmsurpre

@prb112
Copy link
Contributor

prb112 commented Oct 8, 2020

@erodrago please go right ahead. if you have any questions, come find us on Zulip. https://chat.fhir.org/#narrow/stream/212434-ibm

@erodrago
Copy link

erodrago commented Oct 9, 2020

Alright thanks @prb112

prb112 added a commit that referenced this issue Mar 23, 2021
Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
@prb112
Copy link
Contributor

prb112 commented Mar 23, 2021

PR #2130

@prb112 prb112 self-assigned this Mar 23, 2021
@prb112 prb112 added this to the Sprint 2021-04 milestone Mar 23, 2021
prb112 added a commit that referenced this issue Mar 24, 2021
@lmsurpre
Copy link
Member Author

lmsurpre commented Mar 31, 2021

Confirmed that, after #2186, we now print usage info when invalid args are passed (and suppress the stacktrace by default):

$ java -jar fhir-path/target/fhir-path-4.7.0-SNAPSHOT-cli.jar
Error: Invalid parameters were set for the fhir path client
--path 'fhir-path'
--format ['json'|'xml'] . Default is 'json'
--file path-to-file . The file that is accessible and read.
--resource 'resource-payload'. The FHIR resource as a well formed string.
--pretty adds columns and start time and end time of the fhir path request
--throw-error print the stacktrace
--help

I also confirmed that I was able to invoke the cli via both stdin and also via file:

$ curl -s 'https://localhost:9443/fhir-server/api/v4/metadata' | java -jar fhir-path/target/fhir-path-4.7.0-SNAPSHOT-cli.jar --path 'CapabilityStatement.rest.resource.type.count()'
146
$ java -jar fhir-path/target/fhir-path-4.7.0-SNAPSHOT-cli.jar --path 'CapabilityStatement.rest.resource.type.count()' --file tmp.json
146

@lmsurpre
Copy link
Member Author

Java isn't the best for quick little cli utilities like this because the JVM is still a bit heavy to start. I'd love to see if we could compile it to a native image using graalvm sometime...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants