Skip to content

Commit

Permalink
Merge branch 'fix-icd9-urls'
Browse files Browse the repository at this point in the history
  • Loading branch information
dwinters committed Feb 19, 2020
2 parents 3e592a3 + af35ab7 commit 214563b
Show file tree
Hide file tree
Showing 5 changed files with 1,284 additions and 912 deletions.
58 changes: 29 additions & 29 deletions lib/download-vsac.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ function downloadFromVSAC(username, password, input, output, vsDB={}) {
mkdirp.sync(output);
}
return getTicketGrantingTicket(username, password)
.then((ticketGrantingTicket) => {
const promises = oids.map(oid => {
.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)
.catch((err) => {
debug(`Error downloading valueset ${oid}`, err);
return new Error(`Error downloading valueset: ${oid}`);
return downloadValueSet(ticketGrantingTicket, oid, output, vsDB)
.catch((err) => {
debug(`Error downloading valueset ${oid}`, err);
return new Error(`Error downloading valueset: ${oid}`);
});
});
});
return Promise.all(promises);
})
.then((results) => {
const errors = results.filter(r => r instanceof Error);
if (results.length - errors.length > 0) {
return Promise.all(promises);
})
.then((results) => {
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))
.then(
(result) => errors.length == 0 ? result : Promise.reject(errors),
(err) => { errors.push(err); return Promise.reject(errors); }
);
}
if (errors.length > 0) {
return Promise.reject(errors);
}
});
return writeFile(path.join(output, 'valueset-db.json'), JSON.stringify(vsDB, null, 2))
.then(
(result) => errors.length == 0 ? result : Promise.reject(errors),
(err) => { errors.push(err); return Promise.reject(errors); }
);
}
if (errors.length > 0) {
return Promise.reject(errors);
}
});
} else {
return Promise.resolve();
}
Expand All @@ -68,13 +68,13 @@ function getTicketGrantingTicket(username, password) {

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

function getServiceTicket(ticketGrantingTicket) {
Expand Down
16 changes: 11 additions & 5 deletions lib/vsac-code-systems.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"2.16.840.1.113883.12.112": { "name": "DischargeDisposition" },
"1.3.6.1.4.1.12009.10.3.1": { "name": "UCUM", "uri": "http://unitsofmeasure.org" },
"2.16.840.1.113883.12.112": { "name": "DischargeDisposition", "uri": "http://hl7.org/fhir/v2/0112" },
"2.16.840.1.113883.12.292": { "name": "CVX", "uri": "http://hl7.org/fhir/sid/cvx" },
"2.16.840.1.113883.18.2": { "name": "AdministrativeSex" , "uri": "http://hl7.org/fhir/v2/0001" },
"2.16.840.1.113883.3.221.5": { "name": "SOP" , "uri": "http://www.nlm.nih.gov/research/umls/sop" },
"2.16.840.1.113883.3.26.1.1": { "name": "NCI" , "uri": "http://ncimeta.nci.nih.gov" },
"2.16.840.1.113883.3.26.1.5": { "name": "NDFRT", "uri": "http://hl7.org/fhir/ndfrt" },
"2.16.840.1.113883.4.9": { "name": "UNII" , "uri": "http://fdasis.nlm.nih.gov" },
"2.16.840.1.113883.5.1": { "name": "AdministrativeGender" , "uri": "http://hl7.org/fhir/v3/AdministrativeGender" },
"2.16.840.1.113883.5.1001": { "name": "ActMood" , "uri": "http://hl7.org/fhir/v3/ActMood"},
"2.16.840.1.113883.5.1002": { "name": "ActRelationshipType" , "uri": "http://hl7.org/fhir/v3/ActRelationshipType" },
Expand All @@ -24,23 +27,26 @@
"2.16.840.1.113883.5.61": { "name": "LanguageAbilityProficiency", "uri": "http://hl7.org/fhir/v3/LanguageAbilityProficiency" },
"2.16.840.1.113883.5.63": { "name": "LivingArrangement" , "uri": "http://hl7.org/fhir/v3/LivingArrangement" },
"2.16.840.1.113883.5.7": { "name": "ActPriority" , "uri": "http://hl7.org/fhir/v3/ActPriority" },
"2.16.840.1.113883.5.79": { "name": "mediaType", "uri": "http://hl7.org/fhir/v3/MediaType" },
"2.16.840.1.113883.5.8": { "name": "ActReason" , "uri": "http://hl7.org/fhir/v3/ActReason" },
"2.16.840.1.113883.5.83": { "name": "ObservationInterpretation" , "uri": "http://hl7.org/fhir/v3/ObservationInterpretation" },
"2.16.840.1.113883.5.88": { "name": "ParticipationFunction" , "uri": "http://hl7.org/fhir/v3/ParticipationFunction" },
"2.16.840.1.113883.5.90": { "name": "ParticipationType" , "uri": "http://hl7.org/fhir/v3/ParticipationType" },
"2.16.840.1.113883.6.1": { "name": "LOINC", "uri": "http://loinc.org" },
"2.16.840.1.113883.6.101": { "name": "NUCCPT" , "uri": "http://nucc.org/provider-taxonomy" },
"2.16.840.1.113883.6.103": { "name": "ICD9CM", "uri": "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" },
"2.16.840.1.113883.6.104": { "name": "ICD9CM", "uri": "http://hl7.org/fhir/sid/icd-9-cm/procedure" },
"2.16.840.1.113883.6.101": { "name": "NUCCPT" , "uri": "http://nucc.org/provider-taxonomy" },
"2.16.840.1.113883.6.103": { "name": "ICD9CM", "uri": "http://hl7.org/fhir/sid/icd-9-cm" },
"2.16.840.1.113883.6.104": { "name": "ICD9CM", "uri": "http://hl7.org/fhir/sid/icd-9-cm" },
"2.16.840.1.113883.6.12": { "name": "CPT", "uri": "http://www.ama-assn.org/go/cpt" },
"2.16.840.1.113883.6.13": { "name": "CDT" , "uri": "http://www.nlm.nih.gov/research/umls/cdt" },
"2.16.840.1.113883.6.14": { "name": "HCPCS" },
"2.16.840.1.113883.6.238": { "name": "CDCREC" },
"2.16.840.1.113883.6.259": { "name": "HSLOC" },
"2.16.840.1.113883.6.285": { "name": "HCPCS" },
"2.16.840.1.113883.6.345": { "name": "MED-RT", "uri": "http://www.nlm.nih.gov/research/umls/MED-RT" },
"2.16.840.1.113883.6.4": { "name": "ICD10PCS", "uri": "http://www.icd10data.com/icd10pcs" },
"2.16.840.1.113883.6.86": { "name": "UMLS" , "uri": "http://www.nlm.nih.gov/research/umls" },
"2.16.840.1.113883.6.88": { "name": "RXNORM", "uri": "http://www.nlm.nih.gov/research/umls/rxnorm" },
"2.16.840.1.113883.6.90": { "name": "ICD10CM", "uri": "http://hl7.org/fhir/sid/icd-10-cm" },
"2.16.840.1.113883.6.96": { "name": "SNOMEDCT", "uri": "http://snomed.info/sct" }
"2.16.840.1.113883.6.96": { "name": "SNOMEDCT", "uri": "http://snomed.info/sct" },
"2.16.840.1.113883.5.4": { "name": "ActCode", "uri": "http://hl7.org/fhir/v3/ActCode" }
}
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cql-exec-vsac",
"version": "1.0.3",
"version": "1.0.4",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand All @@ -15,20 +15,23 @@
"lint:fix": "./node_modules/.bin/eslint . --fix"
},
"dependencies": {
"debug": "^2.6.4",
"mkdirp": "^0.5.1",
"request": "^2.81.0",
"request-promise-native": "^1.0.3",
"xml2js": "^0.4.17"
"debug": "^4.1.1",
"mkdirp": "^1.0.3",
"request": "^2.88.2",
"request-promise-native": "^1.0.8",
"xml2js": "^0.4.23"
},
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"cql-execution": "^1.2.0",
"eslint": "^3.19.0",
"fs-extra": "^2.1.2",
"mocha": "^3.2.0",
"nock": "^9.0.13"
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cql-execution": "^1.3.7",
"eslint": "^6.8.0",
"fs-extra": "^8.1.0",
"mocha": "^7.0.1",
"nock": "^11.8.2"
},
"resolutions": {
"sshpk": "^1.13.2"
},
"peerDependencies": {
"cql-execution": "^1.2.0"
Expand Down
108 changes: 54 additions & 54 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,25 @@ describe('CodeService', function() {
];

return service.ensureValueSets(vsList, username, password)
.then(function() {
should.fail(0, 1, 'This code should never be executed since there were errors');
})
.catch(function(error) {
.then(function() {
should.fail(0, 1, 'This code should never be executed since there were errors');
})
.catch(function(error) {
// Test that the value sets were properly loaded into memory
service.valueSets.should.not.be.empty;
Object.keys(service.valueSets).should.have.length(3);
const vs1 = service.findValueSet('1.2.3.4.5.6.7.8.9.10');
should.not.exist(vs1);
const vs2 = service.findValueSet('2.16.840.1.113883.3.600.2390', '20170418');
vs2.codes.should.have.length(24);
// Test that the value sets were properly written to the cache
const cached = require(path.join(tmpCache, 'valueset-db.json'));
JSON.parse(JSON.stringify(service.valueSets)).should.eql(cached);
// Test that the error was thrown
error.should.have.length(1);
error[0].should.be.an('error');
error[0].message.should.contain('1.2.3.4.5.6.7.8.9.10');
});
service.valueSets.should.not.be.empty;
Object.keys(service.valueSets).should.have.length(3);
const vs1 = service.findValueSet('1.2.3.4.5.6.7.8.9.10');
should.not.exist(vs1);
const vs2 = service.findValueSet('2.16.840.1.113883.3.600.2390', '20170418');
vs2.codes.should.have.length(24);
// Test that the value sets were properly written to the cache
const cached = require(path.join(tmpCache, 'valueset-db.json'));
JSON.parse(JSON.stringify(service.valueSets)).should.eql(cached);
// Test that the error was thrown
error.should.have.length(1);
error[0].should.be.an('error');
error[0].message.should.contain('1.2.3.4.5.6.7.8.9.10');
});
});

it('should error if no username/password is supplied', function() {
Expand All @@ -263,12 +263,12 @@ describe('CodeService', function() {
{name: 'Systolic Blood Pressure', id: '2.16.840.1.113883.3.526.3.1032', version: '20170320'}
];
return service.ensureValueSets(vsList, null, null)
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.should.eql('Failed to download value sets since UMLS_USER_NAME and/or UMLS_PASSWORD is not set.');
});
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.should.eql('Failed to download value sets since UMLS_USER_NAME and/or UMLS_PASSWORD is not set.');
});
} finally {
[process.env['UMLS_USER_NAME'], process.env['UMLS_PASSWORD']] = [oldU, oldP];
}
Expand All @@ -286,12 +286,12 @@ describe('CodeService', function() {
];

return service.ensureValueSets(vsList, wrongU, wrongP)
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.statusCode.should.equal(401);
});
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.statusCode.should.equal(401);
});
});

it('should error if invalid ticket granting ticket is supplied', function() {
Expand All @@ -308,14 +308,14 @@ describe('CodeService', function() {
{name: 'Systolic Blood Pressure', id: '2.16.840.1.113883.3.526.3.1032', version: '20170320'}
];
return service.ensureValueSets(vsList, username, password)
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.should.have.length(1);
error[0].should.be.an('error');
error[0].message.should.contain('2.16.840.1.113883.3.526.3.1032');
});
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.should.have.length(1);
error[0].should.be.an('error');
error[0].message.should.contain('2.16.840.1.113883.3.526.3.1032');
});
});

it('should error if invalid service granting ticket is supplied', function() {
Expand All @@ -336,14 +336,14 @@ describe('CodeService', function() {
{name: 'Systolic Blood Pressure', id: '2.16.840.1.113883.3.526.3.1032', version: '20170320'}
];
return service.ensureValueSets(vsList, username, password)
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.should.have.length(1);
error[0].should.be.an('error');
error[0].message.should.contain('2.16.840.1.113883.3.526.3.1032');
});
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.should.have.length(1);
error[0].should.be.an('error');
error[0].message.should.contain('2.16.840.1.113883.3.526.3.1032');
});
});

it('should error if value set is not found', function() {
Expand All @@ -363,14 +363,14 @@ describe('CodeService', function() {
{name: 'Fake Value Set', id: '1.2.3.4.5.6.7.8.9.10', version: '20170320'}
];
return service.ensureValueSets(vsList, username, password)
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.should.have.length(1);
error[0].should.be.an('error');
error[0].message.should.contain('1.2.3.4.5.6.7.8.9.10');
});
.then(function() {
should.fail(0, 1, 'This code should never be executed');
})
.catch(function(error) {
error.should.have.length(1);
error[0].should.be.an('error');
error[0].message.should.contain('1.2.3.4.5.6.7.8.9.10');
});
});
});
});
Loading

0 comments on commit 214563b

Please sign in to comment.