Skip to content

Commit

Permalink
Merge pull request #148 from taylordeatri/feature/PHD-898-add-json-qu…
Browse files Browse the repository at this point in the history
…ery-to-lo-cli-fhir-sql

add json query to lo cli fhir sql
  • Loading branch information
mschroering authored Aug 3, 2020
2 parents aef95f0 + 950eb10 commit 41000ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/cmds/fhir_cmds/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

const { post } = require('../../api');
const print = require('../../print');
const read = require('../../read');

exports.command = 'sql <statement>';
exports.desc = 'Use SQL to query FHIR resources';
exports.builder = yargs => {
yargs.positional('statement', {
describe: 'The SQL statement.',
type: 'string'
type: 'string',
required: false
}).option('project', {
describe: 'The project identifier',
type: 'string'
Expand All @@ -17,9 +19,18 @@ exports.builder = yargs => {

exports.handler = async argv => {
const project = argv.project;
const statement = argv.statement;
let statement = '';
let contentType = 'text/plain';

if (argv.statement && argv.statement !== '') {
statement = argv.statement;
} else {
statement = await read(argv);
contentType = 'application/json';
}

const url = `/v1/fhir-search/projects/${project}/`;
const options = { ...argv, ContentType: 'text/plain' };
const options = { ...argv, ContentType: contentType };
const response = await post(options, url, statement);
const data =
response.data.hits.hits
Expand Down
21 changes: 21 additions & 0 deletions lib/cmds/genomics_cmds/get-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const { get } = require('../../api');
const print = require('../../print');

exports.command = 'get-test <projectId> <testId>';
exports.desc = 'Fetch test details by <projectId> and <testId>.';
exports.builder = yargs => {
yargs.positional('projectId', {
describe: 'The project ID.',
type: 'string'
}).positional('testId', {
describe: 'The test ID.',
type: 'string'
});
};

exports.handler = async argv => {
const response = await get(argv, `/v1/genomics/projects/${argv.projectId}/tests/${argv.testId}`);
print(response.data, argv);
};

0 comments on commit 41000ad

Please sign in to comment.