Skip to content

Commit

Permalink
Improve data export with the CLI by making a single command to run ve…
Browse files Browse the repository at this point in the history
…rsus

the current 6 step process.

`./life-export` will configure defaults, ask the user to authenticate,
and pull data locally as JSON under a directory named `life-data`.
  • Loading branch information
hemp committed Feb 26, 2020
1 parent 29cb999 commit 38c5da5
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pids
.idea

build/
life-data/
work/
target/
.git/
Expand Down
13 changes: 9 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ rm -rf target
mkdir -p target

node_modules/.bin/pkg --target node8-linux-x64 --output target/linux-x64/lo package.json
node_modules/.bin/pkg --target node8-linux-x86 --output target/linux-x86/lo package.json
node_modules/.bin/pkg --target node8-win-x64 --output target/windows-x64/lo.exe package.json
node_modules/.bin/pkg --target node8-win-x86 --output target/windows-x86/lo.exe package.json
node_modules/.bin/pkg --target node8-macos-x64 --output target/macos-x64/lo package.json

(cd target/linux-x64 && zip -q -9 ../lo-linux-x64.zip lo)
(cd target/linux-x86 && zip -q -9 ../lo-linux-x86.zip lo)
(cd target/windows-x64 && zip -q -9 ../lo-windows-x64.zip lo.exe)
(cd target/windows-x86 && zip -q -9 ../lo-windows-x86.zip lo.exe)
(cd target/macos-x64 && zip -q -9 ../lo-macos-x64.zip lo)

node_modules/.bin/pkg --target node10-linux-x64 --output target/linux-x64/life-export life-export.js
node_modules/.bin/pkg --target node10-win-x64 --output target/windows-x64/life-export.exe life-export.js
node_modules/.bin/pkg --target node10-macos-x64 --output target/macos-x64/life-export life-export.js

(cd target/linux-x64 && zip -q -9 ../life-export-linux-x64.zip life-export)
(cd target/windows-x64 && zip -q -9 ../life-export-windows-x64.zip life-export.exe)
(cd target/macos-x64 && zip -q -9 ../life-export-macos-x64.zip life-export)

2 changes: 1 addition & 1 deletion lib/cmds/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ exports.handler = async argv => {
const environment = argv.environment || answers.environment;
config.set(`defaults.environment`, environment);
config.set(`${environment}.defaults.account`, argv.account || answers.account);
config.set(`${environment}.defaults.useClientCredentials`, argv.clientId !== undefined || answers.useClientCredentials || false);
config.set(`${environment}.defaults.useClientCredentials`, (argv.clientId !== undefined && argv.clientSecret !== undefined) || answers.useClientCredentials || false);
if (argv.clientId !== undefined || answers.clientId) {
config.set(`${environment}.defaults.clientId`, argv.clientId || answers.clientId);
}
Expand Down
74 changes: 74 additions & 0 deletions life-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env node

const _get = require('lodash/get');
const chalk = require('chalk');
const execa = require('execa');
const fs = require('fs');
const mkdirp = require('mkdirp');
const os = require('os');

const DATA_DIR = 'life-data';
const LIFE_PROJECT = 'f82a69fb-3f0c-4405-9b7f-8df05aaec159';
const LO = os.platform() === 'win32' ? 'lo.exe' : './lo';

(async () => {
await mkdirp(DATA_DIR);
console.log(chalk.green('LIFE data will be exported into directory named:'), chalk.bold(DATA_DIR));

console.log(chalk.green('Configuring with defaults...'));
const defaults = execa(LO, [
'setup',
'--environment',
'prod-us',
'--account',
'lifeomiclife',
'--clientId',
'2qt93qphnctjbs9ftdpjhvgkl1'
]);
defaults.stdout.pipe(process.stdout);
await defaults;

console.log(chalk.green('Authenticating...'));
const auth = execa(LO, ['auth']);
auth.stdout.pipe(process.stdout);
await auth;

console.log(chalk.green('Fetching FHIR me...'));
const me = execa(LO, [
'fhir',
'me',
'--json',
'--account',
'lifeomiclife'
]);
// eslint-disable-next-line security/detect-non-literal-fs-filename
me.stdout.pipe(fs.createWriteStream(`${DATA_DIR}/me.json`));
const { stdout: meStdout } = await me;

const meId = _get(JSON.parse(meStdout), 'entry[0].resource.id');
console.log(chalk.green('User Identifier:'), chalk.bold(meId));
console.log(chalk.green(`Me exported: ✅`));

const FHIR_TYPES = ['Procedure', 'Observation', 'Goal'];
for (const type of FHIR_TYPES) {
console.log(chalk.green(`Fetching ${type}...`));
const subprocess = execa(LO, [
'fhir',
'list',
type,
'--project',
LIFE_PROJECT,
`--query`,
`subject=${meId}`,
'--json',
'--account',
'lifeomiclife'
]);
// eslint-disable-next-line security/detect-non-literal-fs-filename
subprocess.stdout.pipe(fs.createWriteStream(`${DATA_DIR}/${type}.json`));
await subprocess;

console.log(chalk.green(`${type} exported: ✅`));
}
console.log(chalk.green('LIFE data export complete.'));
})();
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"engines": {
"node": ">= 7.6.0"
},
"bin": {
"lo": "./lo.js"
},
"bin": "./lo.js",
"scripts": {
"prelint": "yarn --network-timeout 1000000",
"lint": "eslint .",
Expand All @@ -27,6 +25,7 @@
"configstore": "^3.1.2",
"copy-paste": "^1.3.0",
"debug": "^3.2.6",
"execa": "^4.0.0",
"get-stdin": "^6.0.0",
"inquirer": "^5.2.0",
"jmespath": "^0.15.0",
Expand Down Expand Up @@ -62,6 +61,6 @@
"access": "public"
},
"pkg": {
"scripts": "lib/cmds/**/*.js"
"scripts": "lib/**/*.js"
}
}
91 changes: 90 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,15 @@ cross-spawn@^6.0.0:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0:
version "7.0.1"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
integrity sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==
dependencies:
path-key "^3.1.0"
shebang-command "^2.0.0"
which "^2.0.1"

crypto-random-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
Expand Down Expand Up @@ -1874,6 +1883,21 @@ execa@^1.0.0:
signal-exit "^3.0.0"
strip-eof "^1.0.0"

execa@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.0.tgz#7f37d6ec17f09e6b8fc53288611695b6d12b9daf"
integrity sha512-JbDUxwV3BoT5ZVXQrSVbAiaXhXUkIwvbhPIwZ0N13kX+5yCzOhUNdocxB/UQRuYOHRYYwAxKYwJYc0T4D12pDA==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
human-signals "^1.1.1"
is-stream "^2.0.0"
merge-stream "^2.0.0"
npm-run-path "^4.0.0"
onetime "^5.1.0"
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"

expand-brackets@^0.1.4:
version "0.1.5"
resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b"
Expand Down Expand Up @@ -2236,6 +2260,13 @@ get-stream@^4.0.0:
dependencies:
pump "^3.0.0"

get-stream@^5.0.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.1.0.tgz#01203cdc92597f9b909067c3e656cc1f4d3c4dc9"
integrity sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==
dependencies:
pump "^3.0.0"

get-value@^2.0.3, get-value@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28"
Expand Down Expand Up @@ -2482,6 +2513,11 @@ hullabaloo-config-manager@^1.1.0:
resolve-from "^3.0.0"
safe-buffer "^5.0.1"

human-signals@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==

iconv-lite@^0.4.17, iconv-lite@^0.4.4, iconv-lite@^0.4.8:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down Expand Up @@ -2914,6 +2950,11 @@ is-stream@^1.0.0, is-stream@^1.1.0:
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ=

is-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3"
integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==

is-symbol@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.2.tgz#a055f6ae57192caee329e7a860118b497a950f38"
Expand Down Expand Up @@ -3456,6 +3497,11 @@ merge-descriptors@~1.0.0:
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

merge2@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.2.3.tgz#7ee99dbd69bb6481689253f018488a1b902b0ed5"
Expand Down Expand Up @@ -3516,7 +3562,7 @@ mimic-fn@^1.0.0:
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==

mimic-fn@^2.0.0:
mimic-fn@^2.0.0, mimic-fn@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==
Expand Down Expand Up @@ -3719,6 +3765,13 @@ npm-run-path@^2.0.0:
dependencies:
path-key "^2.0.0"

npm-run-path@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"
integrity sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==
dependencies:
path-key "^3.0.0"

npmlog@^4.0.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b"
Expand Down Expand Up @@ -3802,6 +3855,13 @@ onetime@^2.0.0:
dependencies:
mimic-fn "^1.0.0"

onetime@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.0.tgz#fff0f3c91617fe62bb50189636e99ac8a6df7be5"
integrity sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==
dependencies:
mimic-fn "^2.1.0"

open@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/open/-/open-6.3.0.tgz#60d0b845ee38fae0631f5d739a21bd40e3d2a527"
Expand Down Expand Up @@ -4014,6 +4074,11 @@ path-key@^2.0.0, path-key@^2.0.1:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=

path-key@^3.0.0, path-key@^3.1.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==

path-parse@^1.0.5, path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
Expand Down Expand Up @@ -4694,11 +4759,23 @@ shebang-command@^1.2.0:
dependencies:
shebang-regex "^1.0.0"

shebang-command@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==
dependencies:
shebang-regex "^3.0.0"

shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=

shebang-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==

signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
Expand Down Expand Up @@ -4993,6 +5070,11 @@ strip-eof@^1.0.0:
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=

strip-final-newline@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==

strip-indent@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2"
Expand Down Expand Up @@ -5342,6 +5424,13 @@ which@^1.2.9:
dependencies:
isexe "^2.0.0"

which@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
dependencies:
isexe "^2.0.0"

wide-align@^1.1.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"
Expand Down

0 comments on commit 38c5da5

Please sign in to comment.