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 #122 from standardhealth/sep_ballot_fixes
Browse files Browse the repository at this point in the history
Sep ballot fixes
  • Loading branch information
cmoesel committed Aug 31, 2018
2 parents 9a01467 + ba8e03c commit 2868823
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 72 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -39,6 +39,7 @@ $ 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)
-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)
Expand Down
90 changes: 56 additions & 34 deletions app.js
Expand Up @@ -12,6 +12,7 @@ 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');

Expand All @@ -32,8 +33,9 @@ program
.usage('<path-to-shr-defs> [options]')
.option('-l, --log-level <level>', 'the console log level <fatal,error,warn,info,debug,trace> (default: info)', /^(fatal|error|warn|info|debug|trace)$/i, 'info')
.option('-m, --log-mode <mode>', 'the console log mode <short,long,json,off> (default: short)', /^(short|long|json|off)$/i, 'short')
.option('-s, --skip <feature>', 'skip an export feature <fhir,json,cimcore,json-schema,es6,model-doc,all> (default: <none>)', collect, [])
.option('-o, --out <out>', 'the path to the output folder (default: ./out)', './out')
.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('-o, --out <out>', `the path to the output folder (default: ${path.join('.', 'out')})`, path.join('.', 'out'))
.option('-c, --config <config>', 'the name of the config file (default: config.json)', 'config.json')
.option('-d, --duplicate', 'show duplicate error messages (default: false)')
.arguments('<path-to-shr-defs>')
Expand All @@ -51,10 +53,13 @@ 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 doCIMCORE = program.skip.every(a => a.toLowerCase() != 'cimcore' && 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 de-duplicate error flag

Expand Down Expand Up @@ -95,7 +100,10 @@ if (doJSONSchema) {
shrJSE.setLogger(logger.child({module: 'shr-json-schema-export'}));
}
if (doModelDoc) {
shrJDE.setLogger(logger.child({module: 'shr-json-javadoc'}));
shrJDE.setLogger(logger.child({ module: 'shr-json-javadoc' }));
}
if (doADL) {
shrAE.setLogger(logger.child({module: 'shr-adl-export'}));
}
// NOTE: shr-es6-export does not currently support a Bunyan logger

Expand All @@ -121,16 +129,17 @@ if (filter) {

const failedExports = [];

let cimcoreSpecifications;
if (doCIMCORE) {
try {
var cimcoreSpecifications = {
cimcoreSpecifications = {
'dataElements': [],
'valueSets': [],
'mappings': [],
'namespaces': {},
//also includes 'projectInfo'
};
const baseCIMCOREPath = `${program.out}/cimcore/`;
const baseCIMCOREPath = path.join(program.out, 'cimcore');

//meta project file
let versionInfo = {
Expand All @@ -141,8 +150,8 @@ if (doCIMCORE) {
let projectMetaOutput = Object.assign({ 'fileType': 'ProjectInfo' }, configSpecifications, versionInfo); //project meta information
cimcoreSpecifications['projectInfo'] = projectMetaOutput;

const hierarchyPath = `${program.out}/cimcore/project.json`;
mkdirp.sync(hierarchyPath.substring(0, hierarchyPath.lastIndexOf('/')));
const hierarchyPath = path.join(program.out, 'cimcore', 'project.json');
mkdirp.sync(path.dirname(hierarchyPath));
fs.writeFileSync(hierarchyPath, JSON.stringify(projectMetaOutput, null, ' '));

//meta namespace files
Expand All @@ -151,9 +160,9 @@ if (doCIMCORE) {
let out = Object.assign({ 'fileType': 'Namespace' }, ns.toJSON());
cimcoreSpecifications.namespaces[ns.namespace] = out;

const hierarchyPath = `${baseCIMCOREPath}/${namespace}/${namespace}.json`;
const hierarchyPath = path.join(baseCIMCOREPath, namespace, `${namespace}.json`);
try {
mkdirp.sync(hierarchyPath.substring(0, hierarchyPath.lastIndexOf('/')));
mkdirp.sync(path.dirname(hierarchyPath));
fs.writeFileSync(hierarchyPath, JSON.stringify(out, null, ' '));
} catch (error) {
logger.error('Unable to successfully serialize namespace meta information %s into CIMCORE, failing with error "%s". ERROR_CODE:15004', namespace, error);
Expand All @@ -167,9 +176,9 @@ if (doCIMCORE) {
let out = Object.assign({ 'fileType': 'DataElement' }, de.toJSON());
cimcoreSpecifications.dataElements.push(out);

const hierarchyPath = `${baseCIMCOREPath}/${namespace}/${fqn}.json`;
const hierarchyPath = path.join(baseCIMCOREPath, namespace, `${fqn}.json`);
try {
mkdirp.sync(hierarchyPath.substring(0, hierarchyPath.lastIndexOf('/')));
mkdirp.sync(path.dirname(hierarchyPath));
fs.writeFileSync(hierarchyPath, JSON.stringify(out, null, ' '));
} catch (error) {
logger.error('Unable to successfully serialize element %s into CIMCORE, failing with error "%s". ERROR_CODE:15001', de.identifier.fqn, error);
Expand All @@ -183,28 +192,30 @@ if (doCIMCORE) {
let out = Object.assign({ 'fileType': 'ValueSet' }, vs.toJSON());
cimcoreSpecifications.valueSets.push(out);

const hierarchyPath = `${baseCIMCOREPath}/${namespace}/valuesets/${name}.json`;
const hierarchyPath = path.join(baseCIMCOREPath, namespace, 'valuesets', `${name}.json`);
try {
mkdirp.sync(hierarchyPath.substring(0, hierarchyPath.lastIndexOf('/')));
mkdirp.sync(path.dirname(hierarchyPath));
fs.writeFileSync(hierarchyPath, JSON.stringify(out, null, ' '));
} catch (error) {
logger.error('Unable to successfully serialize value set %s into CIMCORE, failing with error "%s". ERROR_CODE:15002', vs.identifier.fqn, error);
}
}

//mappings
for (const mapping of [...expSpecifications.maps._targetMap][0][1].all) {
let namespace = mapping.identifier.namespace.replace(/\./, '-');
let name = mapping.identifier.name;
let out = Object.assign({ 'fileType': 'Mapping' }, mapping.toJSON());
cimcoreSpecifications.mappings.push(out);

const hierarchyPath = `${baseCIMCOREPath}/${namespace}/mappings/${name}-mapping.json`;
try {
mkdirp.sync(hierarchyPath.substring(0, hierarchyPath.lastIndexOf('/')));
fs.writeFileSync(hierarchyPath, JSON.stringify(out, null, ' '));
} catch (error) {
logger.error('Unable to successfully serialize mapping %s into CIMCORE, failing with error "%s". ERROR_CODE:15003', mapping.identifier.fqn, error);
for (const target of expSpecifications.maps.targets) {
for (const mapping of expSpecifications.maps.getTargetMapSpecifications(target).all) {
let namespace = mapping.identifier.namespace.replace(/\./, '-');
let name = mapping.identifier.name;
let out = Object.assign({ 'fileType': 'Mapping' }, mapping.toJSON());
cimcoreSpecifications.mappings.push(out);

const hierarchyPath = path.join(baseCIMCOREPath, namespace, 'mappings', target, `${name}-mapping.json`);
try {
mkdirp.sync(path.dirname(hierarchyPath));
fs.writeFileSync(hierarchyPath, JSON.stringify(out, null, ' '));
} catch (error) {
logger.error('Unable to successfully serialize mapping %s into CIMCORE, failing with error "%s". ERROR_CODE:15003', mapping.identifier.fqn, error);
}
}
}
} catch (error) {
Expand All @@ -215,11 +226,22 @@ 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) {
try {
const jsonHierarchyResults = shrJE.exportToJSON(specifications, configSpecifications);
const hierarchyPath = `${program.out}/json/definitions.json`;
mkdirp.sync(hierarchyPath.substring(0, hierarchyPath.lastIndexOf('/')));
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);
Expand Down Expand Up @@ -301,7 +323,7 @@ if (doJSONSchema) {
const baseSchemaNamespace = 'https://standardhealthrecord.org/schema';
const baseSchemaNamespaceWithSlash = baseSchemaNamespace + '/';
const jsonSchemaResults = shrJSE.exportToJSONSchema(expSpecifications, baseSchemaNamespace, typeURL);
const jsonSchemaPath = `${program.out}/json-schema/`;
const jsonSchemaPath = path.join(program.out, 'json-schema');
mkdirp.sync(jsonSchemaPath);
for (const schemaId in jsonSchemaResults) {
const filename = `${schemaId.substring(baseSchemaNamespaceWithSlash.length).replace(/\//g, '.')}.schema.json`;
Expand All @@ -313,7 +335,7 @@ if (doJSONSchema) {
// const baseSchemaExpandedNamespace = 'https://standardhealthrecord.org/schema-expanded';
// const baseSchemaExpandedNamespaceWithSlash = baseSchemaExpandedNamespace + '/';
// const jsonSchemaExpandedResults = shrJSE.exportToJSONSchema(expSpecifications, baseSchemaExpandedNamespace, typeURL, true);
// const jsonSchemaExpandedPath = `${program.out}/json-schema-expanded/`;
// const jsonSchemaExpandedPath = path.join(program.out, 'json-schema-expanded');
// mkdirp.sync(jsonSchemaExpandedPath);
// for (const schemaId in jsonSchemaExpandedResults) {
// const filename = `${schemaId.substring(baseSchemaExpandedNamespaceWithSlash.length).replace(/\//g, '.')}.schema.json`;
Expand All @@ -331,8 +353,8 @@ if (doJSONSchema) {
if (doModelDoc) {
if (doCIMCORE) {
try {
const hierarchyPath = `${program.out}/modeldoc`;
const fhirPath = `${program.out}/fhir/guide/pages/modeldoc`;
const hierarchyPath = path.join(program.out, 'modeldoc');
const fhirPath = path.join(program.out, 'fhir', 'guide', 'pages', 'modeldoc');
const javadocResults = shrJDE.compileJavadoc(cimcoreSpecifications, hierarchyPath);
shrJDE.exportToPath(javadocResults, hierarchyPath);
if (doFHIR && configSpecifications.implementationGuide.includeModelDoc == true) {
Expand All @@ -357,7 +379,7 @@ logger.info('Finished CLI Import/Export');
const ftlCounter = logCounter.fatal;
const errCounter = logCounter.error;
const wrnCounter = logCounter.warn;
let [errColor, errLabel, wrnColor, wrnLabel, resetColor, ftlLabel] = ['\x1b[32m', 'errors', '\x1b[32m', 'warnings', '\x1b[0m', 'fatal errors'];
let [errColor, errLabel, wrnColor, wrnLabel, resetColor, ftlColor, ftlLabel] = ['\x1b[32m', 'errors', '\x1b[32m', 'warnings', '\x1b[0m', '\x1b[31m', 'fatal errors'];
if (ftlCounter.count > 0) {
// logger.fatal('');
ftlLabel = `fatal errors (${failedExports.join(', ')})`;
Expand All @@ -375,7 +397,7 @@ if (wrnCounter.count > 0) {
const hrend = process.hrtime(hrstart);
console.log('------------------------------------------------------------');
console.log('Elapsed time: %d.%ds', hrend[0], Math.floor(hrend[1]/1000000));
if (ftlCounter.count > 0) console.log('%s%d %s%s', errColor, ftlCounter.count, ftlLabel, resetColor);
if (ftlCounter.count > 0) console.log('%s%d %s%s', ftlColor, ftlCounter.count, ftlLabel, resetColor);
console.log('%s%d %s%s', errColor, errCounter.count, errLabel, resetColor);
console.log('%s%d %s%s', wrnColor, wrnCounter.count, wrnLabel, resetColor);
console.log('------------------------------------------------------------');
8 changes: 6 additions & 2 deletions filter.js
Expand Up @@ -26,8 +26,8 @@ class SpecificationsFilter {
// recursively find dependencies for each data element in specifications
// if element matches filter criteria
for (const element of this._expSpecs.dataElements.all) {
if (((strategy === "element") && (target.includes(element.identifier.name)))
|| ((strategy === "namespace") && (target.includes(element.identifier.namespace)))) {
if (((strategy === 'element') && (target.includes(element.identifier.name)))
|| ((strategy === 'namespace') && (target.includes(element.identifier.namespace)))) {
this.findDataElementDependenciesRecursive(element.identifier);
}
}
Expand Down Expand Up @@ -151,6 +151,10 @@ class SpecificationsFilter {
});
}

field.constraintsFilter.type.constraints.forEach(constraint => {
this._deDependencies.add(constraint.isA);
});

field.constraintsFilter.includesType.constraints.forEach(constraint => {
this._deDependencies.add(constraint.isA);
});
Expand Down
19 changes: 10 additions & 9 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "shr-cli",
"version": "5.9.1",
"version": "5.10.0",
"description": "Command-line interface for SHR tools",
"author": "",
"license": "Apache-2.0",
Expand All @@ -21,14 +21,15 @@
"bunyan": "^1.8.12",
"commander": "^2.9.0",
"mkdirp": "^0.5.1",
"shr-es6-export": "^5.4.1",
"shr-expand": "^5.5.1",
"shr-fhir-export": "^5.6.1",
"shr-json-export": "^5.1.4",
"shr-json-javadoc": "^1.4.2",
"shr-json-schema-export": "^5.3.0",
"shr-models": "^5.5.2",
"shr-text-import": "^5.4.1"
"shr-adl-bmm-export": "^1.0.1",
"shr-es6-export": "^5.4.2",
"shr-expand": "^5.5.2",
"shr-fhir-export": "^5.7.0",
"shr-json-export": "^5.1.5",
"shr-json-javadoc": "^1.4.3",
"shr-json-schema-export": "^5.3.1",
"shr-models": "^5.5.3",
"shr-text-import": "^5.4.2"
},
"devDependencies": {
"eslint": "^4.6.1",
Expand Down
15 changes: 13 additions & 2 deletions switch-all-branches
@@ -1,4 +1,12 @@
#!/bin/bash

# This tool helps manage the different SHR branches
# It is recommended you alias it to a shorter command to ease use.
# I have it aliased in my git config as:
# [alias]
# sa = !bash switchAllBranches
# to easily use it as "git sa feature-branch"

RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;36m'
Expand Down Expand Up @@ -146,7 +154,10 @@ function git_branches()
#check if repo is out of sync with remote
remote=$(cd $sub; git branch -a | grep remotes | grep -s -m 1 $($curr_br) 2>/dev/null | tr -d '*'' ' )
if [[ $remote != "" && -n $(cd $sub; git diff --shortstat $($curr_br)..remotes/origin/$($curr_br)) ]]; then
changed="${changed}${YLW}*${NC}";
ahead=$(cd $sub; git rev-list --left-right --count $($curr_br)...origin/$($curr_br) | cut -f 1);
behind=$(cd $sub; git rev-list --left-right --count $($curr_br)...origin/$($curr_br) | cut -f 2);

changed="${changed}${YLW}*${DIM} [$GREEN${ahead}${RED}${behind}${DIM}]$NC";
fi

# #adjust spacing if needed
Expand All @@ -165,4 +176,4 @@ function git_branches()
echo
}

git_branches
git_branches
5 changes: 5 additions & 0 deletions yarn-link-all
Expand Up @@ -53,6 +53,10 @@ yarn link shr-models
yarn link shr-test-helpers
yarn link

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

cd ../shr-cli
echo "===================== shr-cli ======================"
yarn link shr-models
Expand All @@ -63,3 +67,4 @@ 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
5 changes: 5 additions & 0 deletions yarn-unlink-all
@@ -1,6 +1,7 @@
#!/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
Expand All @@ -10,6 +11,10 @@ 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-fhir-export
echo "================= shr-fhir-export =================="
yarn unlink shr-models
Expand Down

0 comments on commit 2868823

Please sign in to comment.