Skip to content

Commit

Permalink
Merge pull request #6 from cqframework/disable-caching-rebase
Browse files Browse the repository at this point in the history
Disable caching rebase
  • Loading branch information
Dylan Mahalingam authored Apr 21, 2020
2 parents 214563b + 7ef8e6f commit 4d5318d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
8 changes: 4 additions & 4 deletions lib/CodeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CodeService {
* @returns {Promise.<undefined,Error>} A promise that returns nothing when
* resolved and returns an error when rejected.
*/
ensureValueSets(valueSetList = [], umlsUserName = env['UMLS_USER_NAME'], umlsPassword = env['UMLS_PASSWORD']) {
ensureValueSets(valueSetList = [], umlsUserName = env['UMLS_USER_NAME'], umlsPassword = env['UMLS_PASSWORD'], caching = true) {
// First, filter out the value sets we already have
const filteredVSList = valueSetList.filter(vs => {
const result = this.findValueSet(vs.id, vs.version);
Expand All @@ -80,7 +80,7 @@ class CodeService {
} else if ( typeof umlsUserName === 'undefined' || umlsUserName == null ||typeof umlsPassword === 'undefined' || umlsPassword == null) {
return Promise.reject('Failed to download value sets since UMLS_USER_NAME and/or UMLS_PASSWORD is not set.');
} else {
return downloadFromVSAC(umlsUserName, umlsPassword, filteredVSList, this.cache, this.valueSets);
return downloadFromVSAC(umlsUserName, umlsPassword, filteredVSList, this.cache, this.valueSets, caching);
}
}

Expand All @@ -93,9 +93,9 @@ class CodeService {
* @param {string} umlsPassword - the UMLS password to use when downloading value sets (defaults to env "UMLS_PASSWORD")
* @returns {Promise.<undefined,Error>} A promise that returns nothing when resolved and returns an error when rejected.
*/
ensureValueSetsInLibrary(library, checkIncluded = true, umlsUserName = env['UMLS_USER_NAME'], umlsPassword = env['UMLS_PASSWORD']) {
ensureValueSetsInLibrary(library, checkIncluded = true, umlsUserName = env['UMLS_USER_NAME'], umlsPassword = env['UMLS_PASSWORD'], caching = true) {
const valueSets = extractSetOfValueSetsFromLibrary(library, checkIncluded);
return this.ensureValueSets(Array.from(valueSets), umlsUserName, umlsPassword);
return this.ensureValueSets(Array.from(valueSets), umlsUserName, umlsPassword, caching);
}

findValueSetsByOid(oid) {
Expand Down
38 changes: 21 additions & 17 deletions lib/download-vsac.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const mkdirp = require('mkdirp');
const parseVSACXML = require('./parse-vsac');
const debug = require('debug')('vsac'); // To turn on DEBUG: $ export DEBUG=vsac

function downloadFromVSAC(username, password, input, output, vsDB={}) {
function downloadFromVSAC(username, password, input, output, vsDB={}, caching=true) {
var vsJSON = {};
if (typeof(input) === 'string') {
path.resolve(input);
Expand All @@ -21,15 +21,15 @@ function downloadFromVSAC(username, password, input, output, vsDB={}) {
if (Object.keys(vsJSON).length > 0) {
output = path.resolve(output);
const oids = Object.keys(vsJSON).map(k => vsJSON[k]);
if (!fs.existsSync(output)){
if (caching && !fs.existsSync(output)){
mkdirp.sync(output);
}
return getTicketGrantingTicket(username, password)
.then((ticketGrantingTicket) => {
const promises = oids.map(oid => {
// Catch errors and convert to resolutions returning an error. This ensures Promise.all waits for all promises.
// See: http://stackoverflow.com/questions/31424561/wait-until-all-es6-promises-complete-even-rejected-promises
return downloadValueSet(ticketGrantingTicket, oid, output, vsDB)
return downloadValueSet(ticketGrantingTicket, oid, output, vsDB, caching)
.catch((err) => {
debug(`Error downloading valueset ${oid}`, err);
return new Error(`Error downloading valueset: ${oid}`);
Expand All @@ -41,7 +41,7 @@ function downloadFromVSAC(username, password, input, output, vsDB={}) {
const errors = results.filter(r => r instanceof Error);
if (results.length - errors.length > 0) {
// There were results, so write the file first before resolving/rejecting
return writeFile(path.join(output, 'valueset-db.json'), JSON.stringify(vsDB, null, 2))
return writeFile(path.join(output, 'valueset-db.json'), JSON.stringify(vsDB, null, 2), caching)
.then(
(result) => errors.length == 0 ? result : Promise.reject(errors),
(err) => { errors.push(err); return Promise.reject(errors); }
Expand All @@ -66,14 +66,14 @@ function getTicketGrantingTicket(username, password) {
return rpn(options);
}

function downloadValueSet(ticketGrantingTicket, oid, output, vsDB={}) {
function downloadValueSet(ticketGrantingTicket, oid, output, vsDB={}, caching=true) {
return getServiceTicket(ticketGrantingTicket)
.then((serviceTicket) => {
return getValueSet(serviceTicket, oid);
})
.then((data) => {
parseVSACXML(data, vsDB);
return writeFile(path.join(output, `${oid}.xml`), data);
return writeFile(path.join(output, `${oid}.xml`), data, caching);
});
}

Expand All @@ -96,18 +96,22 @@ function getValueSet(serviceTicket, oid) {
return rpn(options);
}

function writeFile(file, data) {
function writeFile(file, data, caching=true) {
return new Promise((resolve, reject) => {
debug('Writing:', file);
fs.writeFile(file, data, (err) => {
if (typeof err !== 'undefined' && err != null) {
debug('Error writing file', file);
reject(err);
} else {
debug('Wrote file', file);
resolve(file);
}
});
if (caching) {
debug('Writing:', file);
fs.writeFile(file, data, (err) => {
if (typeof err !== 'undefined' && err != null) {
debug('Error writing file', file);
reject(err);
} else {
debug('Wrote file', file);
resolve(file);
}
});
} else {
resolve();
}
});
}

Expand Down

0 comments on commit 4d5318d

Please sign in to comment.