-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve data export with the CLI by making a single command to run ve…
…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
Showing
6 changed files
with
178 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ pids | |
.idea | ||
|
||
build/ | ||
life-data/ | ||
work/ | ||
target/ | ||
.git/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.')); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters