Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #207 from standardhealth/cimpl6-import
Browse files Browse the repository at this point in the history
CIMPL6 Import
  • Loading branch information
cmoesel authored Jun 5, 2019
2 parents a487bcb + 4668613 commit f199b9b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 195 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ notifications:
secure: V7hKbKUg0W2M0InbQuYVV/f98FnuMpP+a8cvDWkLsyI4fiHwaPhq0toAoRRRd2j2Jp6AFsvvaFEW4QhbZecs9UDvFNnVWgma/mvZSs8VhnqSONcw7eD+e6ITF5H5DsPGKZ0pKR95msOyLC9OB2LL9vVxnF2uQOM0pHavCDDHptHcMjdbcBytTSuWntnRDbQ3jLhJfjzi2bjOmgr64XqEtu/0KjqaokEB4p34N9UmybLtYYrQJ+gy7TjeT1K0BDotSe9DmklCJbW51Jok3kKeNHzgymn3AHMEIo6JGY83GwHllba6SIieYnjrCjrtKtDMcxBXOxM1IGYfAEgZvXZ42SW3xHfVh6xOz/wnV8uoaqm5fpTCjQ2Owv0fOKf4Ru/4FMuX0XyVeEKDyBEtKk1O86s5XEX+m+r9vGTxi4K1I4FUq62/pqwxSeNKfoBlWixQUrHOkIn9/xhasDhAFDGOIqyTlOMAyLtpZTYTX1+XNRgFTbVsNHPlmWUsDX1Sg+h2pd5pQAIUU3pfbzOZI0bjYfSB40VOJCnvffU4PozonTa1rjEB7X1zFHIR1Xvn8Mka/MdbPYzgEmDrhFrXCUsznhhIp4GreYisAIYIo0qLxBhZY/YjPjQJA/3Cc2+xU86cyUp8TRFnnQjhfyq8H24S++Delx+X4H39/vmu87/YVgo=
before_install:
- git clone https://github.com/standardhealth/shr_spec.git
- git -C ./shr_spec checkout dev6
script:
- node . shr_spec/spec/
- node . -s es6 shr_spec/spec/
46 changes: 5 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The Standard Health Record (SHR) initiative is working to create a single, high-quality health record for every individual in the United States. For more information, see [standardhealthrecord.org](http://standardhealthrecord.org/).

This GitHub repository contains a Node.js command-line interface for parsing SHR text definitions and exporting them as FHIR profiles, [CIMCORE](https://github.com/standardhealth/shr-cli/wiki/CIMCORE-Documentation) JSON serialized files, JSON schema, ES6 classes, or a JSON document (for website generation). Future versions of the CLI may support additional capabilities.
This GitHub repository contains a Node.js command-line interface for parsing SHR text definitions and exporting them as a FHIR IG, [CIMCORE](https://github.com/standardhealth/shr-cli/wiki/CIMCORE-Documentation) JSON serialized files, JSON schema, or ES6 classes. Future versions of the CLI may support additional capabilities.

The SHR text definitions and grammar files can be found in the [shr_spec](https://github.com/standardhealth/shr_spec) repo. As the SHR text format (and content files) are still evolving, so is this toolset.

Expand All @@ -18,9 +18,9 @@ To run the command-line interface, you must perform the following steps to insta
2. Install [Yarn](https://yarnpkg.com/en/docs/install) (1.3.x or above)
3. Execute the following from this project's root directory: `yarn`

# Exporting SHR to JSON and FHIR
# Exporting SHR

After setting up the environment, you can use node to import a folder of files from CAMEO (SHR text format) and export the definitions to JSON and FHIR:
After setting up the environment, you can use node to import a folder of files from CIMPL (SHR text format) and export the definitions to other formats:
```
$ node . /path/to/shr_spec/spec
```
Expand All @@ -37,13 +37,11 @@ $ node . --help
-l, --log-level <level> the console log level <fatal,error,warn,info,debug,trace> (default: info)
-m, --log-mode <mode> the console log mode <short,long,json,off> (default: short)
-s, --skip <feature> skip an export feature <fhir,json,cimcore,json-schema,es6,model-doc,all> (default: <none>)
-a, --adl run the adl exporter (default: false)
-s, --skip <feature> skip an export feature <fhir,cimcore,json-schema,es6,model-doc,all> (default: <none>)
-o, --out <out> the path to the output folder (default: out)
-c, --config <config> the name of the config file (default: config.json)
-d, --duplicate show duplicate error messages (default: false)
-i, --import-cimcore import CIMCORE files instead of CIMPL (default: false)
-6, --export-cimpl-6 export CIMPL 6 files generated from input (default: false)
-h, --help output usage information
```

Expand Down Expand Up @@ -106,7 +104,7 @@ When using this command-line interface and IG publisher, the general order of op

1. The command-line interface (CLI) imports SHR definitions that have been written (as in the [shr_spec](https://github.com/standardhealth/shr_spec) repo) and parses them through a text importer.
2. CLI applies filters, according to the `filterStrategy` (see below).
3. CLI exports the filtered SHR definitions into desired formats, such as ES6, JSON, FHIR, etc. The exports can be selected through command line options, as explained above.
3. CLI exports the filtered SHR definitions into desired formats, such as FHIR, ES6, etc. The exports can be selected through command line options, as explained above.
4. (separate, optional step) The IG publisher takes the SHR FHIR export and generates an IG from the information in these files, following the `implementationGuide` configuration (see below).

To control this process, CLI requires a configuration file. Configuration files *must* be valid JSON, have at least the `projectName` property, and use the `.json` file extension. The configuration file must be located in the path to the SHR specification definitions.
Expand Down Expand Up @@ -234,40 +232,6 @@ Namespace: oncocore
// ... more ...
```

# Comment Preservation

When running the CIMPL 6.0 exporter, comments from the CIMPL 5 files are not preserved in the resulting
exported CIMPL 6.0 files. Thus, in order to try and best preserve the comments, the Python 3 script commentReintegration.py
can be run from the command line and it will take in the directory where the CIMPL 5 files with comments are held
and the directory where the exported CIMPL 6.0 files are present. It will then in a new directory called CommentReintegration,
place the commented CIMPL 6.0 files. One thing to note is that the program assumes that comments will be before a particular line. In addition, for multi-line comments which utilize the /* \*/ notation,
the parser assumes that no multiline comment begins in the same line as text that may pertain to an Element. Thus, for example this is not valid for the parser:
```
Element: A /* This will not be
preserved */
```

In addition, no new text should come within the same line as the \*/ symbol. Thus,

```
/* This will also not be
preserved */ Element: B
```


Note: When specifying the directory, after specifying the last part of the path, be sure to include a / at the end.
Example: If your input directory is the spec folder in the shr_spec directory, then you should give something like:
../shr_spec/spec/
The same holds for the directory of exported CIMPL 6.0 files. Make sure to include a slash at the end of the path.


This is how you can run the script.
```
python3 commentReintegration.py [Directory of CIMPL 5 Files] [Directory of Exported CIMPL 6.0 files]
```

After running this command, the CIMPL6 files with inserted comments will be available in the `CommentReintegration` folder at the root of the shr-cli project.

# License

Copyright 2016, 2017 The MITRE Corporation
Expand Down
63 changes: 2 additions & 61 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ const bps = require('@ojolabs/bunyan-prettystream');
const { sanityCheckModules } = require('shr-models');
const shrTI = require('shr-text-import');
const shrEx = require('shr-expand');
const shrJE = require('shr-json-export');
const shrJSE = require('shr-json-schema-export');
const shrEE = require('shr-es6-export');
const shrFE = require('shr-fhir-export');
const shrJDE = require('shr-json-javadoc');
const shrAE = require('shr-adl-bmm-export');
const LogCounter = require('./logcounter');
const SpecificationsFilter = require('./filter');

/* eslint-disable no-console */

sanityCheckModules({shrTI, shrEx, shrJE, shrJSE, shrEE, shrFE });
sanityCheckModules({shrTI, shrEx, shrJSE, shrEE, shrFE });

// Record the time so we can print elapsed time
const hrstart = process.hrtime();
Expand All @@ -33,13 +31,11 @@ program
.usage('<path-to-shr-defs> [options]')
.option('-l, --log-level <level>', 'the console log level <fatal,error,warn,info,debug,trace>', /^(fatal|error|warn|info|debug|trace)$/i, 'info')
.option('-m, --log-mode <mode>', 'the console log mode <short,long,json,off>', /^(short|long|json|off)$/i, 'short')
.option('-s, --skip <feature>', 'skip an export feature <fhir,json,cimcore,json-schema,es6,model-doc,all>', collect, [])
.option('-a, --adl', 'run the adl exporter (default: false)')
.option('-s, --skip <feature>', 'skip an export feature <fhir,cimcore,json-schema,es6,model-doc,all>', collect, [])
.option('-o, --out <out>', `the path to the output folder`, path.join('.', 'out'))
.option('-c, --config <config>', 'the name of the config file', 'config.json')
.option('-d, --duplicate', 'show duplicate error messages (default: false)')
.option('-i, --import-cimcore', 'import CIMCORE files instead of CIMPL (default: false)')
.option('-6, --export-cimpl-6', 'export CIMPL 6 files generated from input (default: false)')
.arguments('<path-to-shr-defs>')
.action(function (pathToShrDefs) {
input = pathToShrDefs;
Expand All @@ -53,18 +49,11 @@ if (typeof input === 'undefined') {
}
// Process the skip flags
const doFHIR = program.skip.every(a => a.toLowerCase() != 'fhir' && a.toLowerCase() != 'all');
const doJSON = program.skip.every(a => a.toLowerCase() != 'json' && a.toLowerCase() != 'all');
const doJSONSchema = program.skip.every(a => a.toLowerCase() != 'json-schema' && a.toLowerCase() != 'all');
const doES6 = program.skip.every(a => a.toLowerCase() != 'es6' && a.toLowerCase() != 'all');
const doModelDoc = program.skip.every(a => a.toLowerCase() != 'model-doc' && a.toLowerCase() != 'all');
const doCIMCORE = program.skip.every(a => a.toLowerCase() != 'cimcore' && a.toLowerCase() != 'all');

// Process the ADL flag
const doADL = program.adl;

// Process the CIMPL 6 export flag
const doCIMPL6 = program.exportCimpl6;

// Process the de-duplicate error flag

const showDuplicateErrors = program.duplicate;
Expand Down Expand Up @@ -95,9 +84,6 @@ const logger = bunyan.createLogger({

shrTI.setLogger(logger.child({module: 'shr-text-input'}));
shrEx.setLogger(logger.child({module: 'shr-expand'}));
if (doJSON) {
shrJE.setLogger(logger.child({module: 'shr-json-export'}));
}
if (doFHIR) {
shrFE.setLogger(logger.child({module: 'shr-fhir-export'}));
}
Expand All @@ -107,9 +93,6 @@ if (doJSONSchema) {
if (doModelDoc) {
shrJDE.setLogger(logger.child({ module: 'shr-json-javadoc' }));
}
if (doADL) {
shrAE.setLogger(logger.child({module: 'shr-adl-export'}));
}
if (doES6) {
shrEE.setLogger(logger.child({ module: 'shr-es6-export'}));
}
Expand Down Expand Up @@ -249,48 +232,6 @@ if (doCIMCORE) {
logger.info('Skipping CIMCORE export');
}

if (doADL) {
try {
shrAE.generateADLtoPath(expSpecifications, configSpecifications, program.out);
} catch (error) {
logger.fatal('Failure in ADL export. Aborting with error message: %s', error);
failedExports.push('shr-adl-bmm-export');
}
} else {
logger.info('Skipping ADL export');
}

if (doJSON) {
if (!importCimcore) {
try {
const jsonHierarchyResults = shrJE.exportToJSON(specifications, configSpecifications);
const hierarchyPath = path.join(program.out, 'json', 'definitions.json');
mkdirp.sync(path.dirname(hierarchyPath));
fs.writeFileSync(hierarchyPath, JSON.stringify(jsonHierarchyResults, null, ' '));
} catch (error) {
logger.fatal('Failure in JSON export. Aborting with error message: %s', error);
failedExports.push('shr-json-export');
}
} else {
//Skipping website generation legacy output for imported cimcore.
logger.info('Using imported CIMCORE, skipping JSON export');
}
} else {
logger.info('Skipping JSON export');
}

if (doCIMPL6) {
logger.info('Exporting CIMPL 6');
try {
const cimpl6Path = path.join(program.out, 'cimpl6');
expSpecifications.toCIMPL6(cimpl6Path);
logger.info('Exported %s namespaces to CIMPL 6.', expSpecifications.namespaces.all.length);
} catch (error) {
logger.fatal('Failure in CIMPL 6 export. Aborting with error message: %s', error);
failedExports.push('cimpl-6-export');
}
} // the CIMPL 6 export is opt-in, so we are omitting the 'skip' info log.

let fhirResults = null;
if (doES6 || doFHIR){
fhirResults = shrFE.exportToFHIR(expSpecifications, configSpecifications);
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shr-cli",
"version": "5.19.0",
"version": "6.0.0",
"description": "Command-line interface for SHR tools",
"author": "",
"license": "Apache-2.0",
Expand All @@ -22,15 +22,13 @@
"commander": "^2.9.0",
"fs-extra": "^7.0.0",
"mkdirp": "^0.5.1",
"shr-adl-bmm-export": "^1.0.1",
"shr-es6-export": "^5.7.2",
"shr-expand": "^5.8.1",
"shr-fhir-export": "^5.14.0",
"shr-json-export": "^5.1.5",
"shr-json-javadoc": "^1.4.5",
"shr-json-schema-export": "^5.3.2",
"shr-models": "^5.9.0",
"shr-text-import": "^5.7.1"
"shr-es6-export": "^6.0.0",
"shr-expand": "^6.0.0",
"shr-fhir-export": "^6.0.0",
"shr-json-javadoc": "^6.0.0",
"shr-json-schema-export": "^6.0.0",
"shr-models": "^6.0.0",
"shr-text-import": "^6.0.0"
},
"devDependencies": {
"eslint": "^4.6.1",
Expand Down
8 changes: 0 additions & 8 deletions pull-all
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ cd ../shr-text-import
echo "================= shr-text-import =================="
git pull

cd ../shr-json-export
echo "================= shr-json-export =================="
git pull

cd ../shr-json-schema-export
echo "============== shr-json-schema-export =============="
git pull
Expand All @@ -40,10 +36,6 @@ cd ../shr-fhir-export
echo "================= shr-fhir-export =================="
git pull

cd ../shr-adl-bmm-export
echo "================= shr-adl-bmm-export =================="
git pull

cd ../shr-cli
echo "===================== shr-cli ======================"
git pull
10 changes: 0 additions & 10 deletions rebuild-all
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ echo "================= shr-text-import =================="
rm -rf node_modules
yarn

cd ../shr-json-export
echo "================= shr-json-export =================="
rm -rf node_modules
yarn

cd ../shr-json-schema-export
echo "============== shr-json-schema-export =============="
rm -rf node_modules
Expand All @@ -45,11 +40,6 @@ echo "================= shr-fhir-export =================="
rm -rf node_modules
yarn

cd ../shr-adl-bmm-export
echo "================= shr-adl-bmm-export =================="
rm -rf node_modules
yarn

cd ../shr-cli
echo "===================== shr-cli ======================"
rm -rf node_modules
Expand Down
13 changes: 1 addition & 12 deletions yarn-link-all
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ yarn link
cd ../shr-text-import
echo "================= shr-text-import =================="
yarn link shr-models
yarn link shr-test-helpers
yarn link

cd ../shr-json-export
echo "================= shr-json-export =================="
yarn link shr-models
yarn link shr-expand
yarn link shr-test-helpers
yarn link

Expand Down Expand Up @@ -54,18 +49,12 @@ yarn link shr-test-helpers
yarn link shr-fhir-export
yarn link

cd ../shr-adl-bmm-export
echo "=============== shr-adl-bmm-export ================="
yarn link

cd ../shr-cli
echo "===================== shr-cli ======================"
yarn link shr-models
yarn link shr-expand
yarn link shr-text-import
yarn link shr-json-export
yarn link shr-json-schema-export
yarn link shr-json-javadoc
yarn link shr-es6-export
yarn link shr-fhir-export
yarn link shr-adl-bmm-export
13 changes: 1 addition & 12 deletions yarn-unlink-all
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#!/usr/bin/env bash

echo "===================== shr-cli ======================"
yarn unlink shr-adl-bmm-export
yarn unlink shr-fhir-export
yarn unlink shr-es6-export
yarn unlink shr-json-schema-export
yarn unlink shr-json-export
yarn unlink shr-json-javadoc
yarn unlink shr-text-import
yarn unlink shr-expand
yarn unlink shr-models

cd ../shr-adl-bmm-export
echo "=============== shr-adl-bmm-export ================="
yarn unlink

cd ../shr-es6-export
echo "================== shr-es6-export =================="
yarn unlink shr-models
Expand Down Expand Up @@ -42,15 +36,10 @@ cd ../shr-json-javadoc
echo "============== shr-json-javadoc ===================="
yarn unlink

cd ../shr-json-export
echo "================= shr-json-export =================="
yarn unlink shr-models
yarn unlink shr-test-helpers
yarn unlink

cd ../shr-text-import
echo "================= shr-text-import =================="
yarn unlink shr-models
yarn unlink shr-expand
yarn unlink shr-test-helpers
yarn unlink

Expand Down
Loading

0 comments on commit f199b9b

Please sign in to comment.