diff --git a/src/CodeService.js b/src/CodeService.js index 917e291..4db29a3 100644 --- a/src/CodeService.js +++ b/src/CodeService.js @@ -77,7 +77,8 @@ class CodeService { async ensureValueSetsWithAPIKey( valueSetList = [], umlsAPIKey = env['UMLS_API_KEY'], - caching = true + caching = true, + options = { svsCodeSystemType: 'url' } ) { // First, filter out the value sets we already have const filteredVSList = valueSetList.filter(vs => { @@ -112,7 +113,7 @@ class CodeService { // 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 this.api - .downloadValueSet(umlsAPIKey, oid, version, output, this.valueSets, caching) + .downloadValueSet(umlsAPIKey, oid, version, output, this.valueSets, caching, options) .catch(err => { debug( `Error downloading valueset ${oid}${version != null ? ` version ${version}` : ''}`, @@ -151,10 +152,11 @@ class CodeService { library, checkIncluded = true, umlsAPIKey = env['UMLS_API_KEY'], - caching = true + caching = true, + options = { svsCodeSystemType: 'url' } ) { const valueSets = extractSetOfValueSetsFromLibrary(library, checkIncluded); - return this.ensureValueSetsWithAPIKey(Array.from(valueSets), umlsAPIKey, caching); + return this.ensureValueSetsWithAPIKey(Array.from(valueSets), umlsAPIKey, caching, options); } /** diff --git a/src/fhir.js b/src/fhir.js index fb87b5c..f6ee937 100644 --- a/src/fhir.js +++ b/src/fhir.js @@ -4,7 +4,17 @@ const fetch = require('node-fetch'); const debug = require('debug')('vsac'); // To turn on DEBUG: $ export DEBUG=vsac const { Code, ValueSet } = require('cql-execution'); -async function downloadValueSet(apiKey, oid, version, output, vsDB = {}, caching = true) { +async function downloadValueSet( + apiKey, + oid, + version, + output, + vsDB = {}, + caching = true, + options = { + /* reserved for future use */ + } +) { const pages = await getValueSetPages(apiKey, oid, version); if (pages == null || pages.length === 0) { return; diff --git a/src/svs.js b/src/svs.js index 2b90541..1e630e7 100644 --- a/src/svs.js +++ b/src/svs.js @@ -6,26 +6,34 @@ const debug = require('debug')('vsac'); // To turn on DEBUG: $ export DEBUG=vsac const { Code, ValueSet } = require('cql-execution'); const vsacCS = require('./vsac-code-systems'); -async function downloadValueSet(apiKey, oid, version, output, vsDB = {}, caching = true) { +async function downloadValueSet( + apiKey, + oid, + version, + output, + vsDB = {}, + caching = true, + options = { svsCodeSystemType: 'url' } +) { debug(`Getting ValueSet: ${oid}${version != null ? ` version ${version}` : ''}`); const params = new URLSearchParams({ id: oid }); if (version != null) { params.append('version', version); } - const options = { + const requestOptions = { headers: { Authorization: `Basic ${Buffer.from(`apikey:${apiKey}`).toString('base64')}` } }; const response = await fetch( `https://vsac.nlm.nih.gov/vsac/svs/RetrieveValueSet?${params}`, - options + requestOptions ); if (!response.ok) { throw new Error(response.status); } const data = await response.text(); - parseVSACXML(data, vsDB); + parseVSACXML(data, vsDB, options); if (caching) { const file = path.join(output, `${oid}.xml`); await fs.writeFile(file, data); @@ -33,10 +41,21 @@ async function downloadValueSet(apiKey, oid, version, output, vsDB = {}, caching } } +function getVSACCodeSystem(codeSystems, system) { + if ( + typeof codeSystems[system] !== 'undefined' && + typeof codeSystems[system].uri !== 'undefined' + ) { + return codeSystems[system]; + } + + return null; +} + // Take in a string containing a string of the XML response from a VSAC SVS // response and parse it into a vsDB object. This code makes strong // assumptions about the structure of the message. See code below. -function parseVSACXML(xmlString, vsDB = {}) { +function parseVSACXML(xmlString, vsDB = {}, options = { svsCodeSystemType: 'url' }) { if (typeof xmlString === 'undefined' || xmlString == null || xmlString.trim().length == 0) { return; } @@ -59,16 +78,31 @@ function parseVSACXML(xmlString, vsDB = {}) { // Loop over the codes and build the JSON. const codeList = []; for (let concept in conceptList) { - let system; - const systemOID = conceptList[concept]['$']['codeSystem']; - if (typeof vsacCS[systemOID] !== 'undefined' && typeof vsacCS[systemOID].uri !== 'undefined') { - system = vsacCS[systemOID].uri; + let system = conceptList[concept]['$']['codeSystem']; + const code = conceptList[concept]['$']['code']; + const version = conceptList[concept]['$']['codeSystemVersion']; + const systemOid = `urn:oid:${system}`; + const systemUri = getVSACCodeSystem(vsacCS, system); + + if (options.svsCodeSystemType === 'oid') { + // Keep the oid system as is + system = systemOid; + } else if (options.svsCodeSystemType === 'both') { + // Optionally include both if they exist + if (systemUri !== null) { + codeList.push({ code, system: systemUri.uri, version }); + } + // Include the standard oid system + system = systemOid; } else { - system = `urn:oid:${systemOID}`; + // Replace oid system with the url system, if one exists + if (systemUri !== null) { + system = systemUri.uri; + } else { + system = systemOid; + } } - const code = conceptList[concept]['$']['code']; - const version = conceptList[concept]['$']['codeSystemVersion']; codeList.push({ code, system, version }); } diff --git a/test/fixtures/2.16.840.1.113883.3.526.3.1032-oid-uri-vsdb.json b/test/fixtures/2.16.840.1.113883.3.526.3.1032-oid-uri-vsdb.json new file mode 100644 index 0000000..1da919b --- /dev/null +++ b/test/fixtures/2.16.840.1.113883.3.526.3.1032-oid-uri-vsdb.json @@ -0,0 +1,20 @@ +{ + "2.16.840.1.113883.3.526.3.1032": { + "20170504": { + "oid": "2.16.840.1.113883.3.526.3.1032", + "version": "20170504", + "codes": [ + { + "code": "8480-6", + "system": "http://loinc.org", + "version": "2.74" + }, + { + "code": "8480-6", + "system": "urn:oid:2.16.840.1.113883.6.1", + "version": "2.74" + } + ] + } + } +} \ No newline at end of file diff --git a/test/fixtures/2.16.840.1.113883.3.526.3.1032-oid-vsdb.json b/test/fixtures/2.16.840.1.113883.3.526.3.1032-oid-vsdb.json new file mode 100644 index 0000000..59a3833 --- /dev/null +++ b/test/fixtures/2.16.840.1.113883.3.526.3.1032-oid-vsdb.json @@ -0,0 +1,15 @@ +{ + "2.16.840.1.113883.3.526.3.1032": { + "20170504": { + "oid": "2.16.840.1.113883.3.526.3.1032", + "version": "20170504", + "codes": [ + { + "code": "8480-6", + "system": "urn:oid:2.16.840.1.113883.6.1", + "version": "2.74" + } + ] + } + } +} \ No newline at end of file diff --git a/test/fixtures/2.16.840.1.113883.3.600.2390-oid-uri-vsdb.json b/test/fixtures/2.16.840.1.113883.3.600.2390-oid-uri-vsdb.json new file mode 100644 index 0000000..33cc1da --- /dev/null +++ b/test/fixtures/2.16.840.1.113883.3.600.2390-oid-uri-vsdb.json @@ -0,0 +1,295 @@ +{ + "2.16.840.1.113883.3.600.2390": { + "20210304": { + "oid": "2.16.840.1.113883.3.600.2390", + "version": "20210304", + "codes": [ + { + "code": "160603005", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160603005", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160604004", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160604004", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + + { + "code": "160605003", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160605003", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "160606002", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160606002", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "160619003", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160619003", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "230059006", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230059006", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "230060001", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230060001", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "230062009", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230062009", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "230063004", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230063004", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "230064005", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230064005", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "230065006", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230065006", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "266920004", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "266920004", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "365981007", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "365981007", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "365982000", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "365982000", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "428041000124106", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "428041000124106", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "428061000124105", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "428061000124105", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "428071000124103", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "428071000124103", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "449868002", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "449868002", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "450811000124104", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "450811000124104", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "450821000124107", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "450821000124107", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "56578002", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "56578002", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "56771006", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "56771006", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "59978006", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "59978006", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "65568007", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "65568007", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "77176002", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "77176002", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + + { + "code": "82302008", + "system": "http://snomed.info/sct", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "82302008", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + } + ] + } + } +} \ No newline at end of file diff --git a/test/fixtures/2.16.840.1.113883.3.600.2390-oid-vsdb.json b/test/fixtures/2.16.840.1.113883.3.600.2390-oid-vsdb.json new file mode 100644 index 0000000..ab31c07 --- /dev/null +++ b/test/fixtures/2.16.840.1.113883.3.600.2390-oid-vsdb.json @@ -0,0 +1,140 @@ +{ + "2.16.840.1.113883.3.600.2390": { + "20210304": { + "oid": "2.16.840.1.113883.3.600.2390", + "version": "20210304", + "codes": [ + { + "code": "160603005", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160604004", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160605003", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160606002", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "160619003", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230059006", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230060001", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230062009", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230063004", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230064005", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "230065006", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "266920004", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "365981007", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "365982000", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "428041000124106", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "428061000124105", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "428071000124103", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "449868002", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "450811000124104", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "450821000124107", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "56578002", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "56771006", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "59978006", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "65568007", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "77176002", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + }, + { + "code": "82302008", + "system": "urn:oid:2.16.840.1.113883.6.96", + "version": "http://snomed.info/sct/731000124108/version/20230901" + } + ] + } + } +} \ No newline at end of file diff --git a/test/svs-test.js b/test/svs-test.js index 6b303f8..b825569 100644 --- a/test/svs-test.js +++ b/test/svs-test.js @@ -7,9 +7,21 @@ const chai = require('chai'); const should = chai.should(); const temp = require('temp'); const TOBACCO_VS_DB = fixVSDBFixture(require('./fixtures/2.16.840.1.113883.3.600.2390-vsdb.json')); +const TOBACCO_OID_VS_DB = fixVSDBFixture( + require('./fixtures/2.16.840.1.113883.3.600.2390-oid-vsdb.json') +); +const TOBACCO_OID_URI_VS_DB = fixVSDBFixture( + require('./fixtures/2.16.840.1.113883.3.600.2390-oid-uri-vsdb.json') +); const SYSTOLIC_VS_DB = fixVSDBFixture( require('./fixtures/2.16.840.1.113883.3.526.3.1032-vsdb.json') ); +const SYSTOLIC_OID_VS_DB = fixVSDBFixture( + require('./fixtures/2.16.840.1.113883.3.526.3.1032-oid-vsdb.json') +); +const SYSTOLIC_OID_URI_VS_DB = fixVSDBFixture( + require('./fixtures/2.16.840.1.113883.3.526.3.1032-oid-uri-vsdb.json') +); describe('SVS', () => { let tmpCache; @@ -124,6 +136,144 @@ describe('SVS', () => { ); }); + it('should merge value sets into the value set database, using default url options when empty options is included', async () => { + nock('https://vsac.nlm.nih.gov') + .get('/vsac/svs/RetrieveValueSet') + .basicAuth({ user: 'apikey', pass: 'testkey' }) + .query({ + id: '2.16.840.1.113883.3.526.3.1032' + }) + .replyWithFile(200, path.join(__dirname, 'fixtures', '2.16.840.1.113883.3.526.3.1032.xml')) + .get('/vsac/svs/RetrieveValueSet') + .basicAuth({ user: 'apikey', pass: 'testkey' }) + .query({ + id: '2.16.840.1.113883.3.600.2390' + }) + .replyWithFile(200, path.join(__dirname, 'fixtures', '2.16.840.1.113883.3.600.2390.xml')); + + const vsDB = {}; + await Promise.all([ + svs.downloadValueSet( + 'testkey', + '2.16.840.1.113883.3.526.3.1032', + undefined, + tmpCache, + vsDB, + true, + {} + ), + svs.downloadValueSet( + 'testkey', + '2.16.840.1.113883.3.600.2390', + undefined, + tmpCache, + vsDB, + true, + {} + ) + ]); + // Should add the results to the VS DB + Object.keys(vsDB).should.have.length(2); + vsDB['2.16.840.1.113883.3.526.3.1032'].should.eql( + SYSTOLIC_VS_DB['2.16.840.1.113883.3.526.3.1032'] + ); + vsDB['2.16.840.1.113883.3.600.2390'].should.eql( + TOBACCO_VS_DB['2.16.840.1.113883.3.600.2390'] + ); + }); + + it('should merge value sets into the value set database while maintaining original system', async () => { + nock('https://vsac.nlm.nih.gov') + .get('/vsac/svs/RetrieveValueSet') + .basicAuth({ user: 'apikey', pass: 'testkey' }) + .query({ + id: '2.16.840.1.113883.3.526.3.1032' + }) + .replyWithFile(200, path.join(__dirname, 'fixtures', '2.16.840.1.113883.3.526.3.1032.xml')) + .get('/vsac/svs/RetrieveValueSet') + .basicAuth({ user: 'apikey', pass: 'testkey' }) + .query({ + id: '2.16.840.1.113883.3.600.2390' + }) + .replyWithFile(200, path.join(__dirname, 'fixtures', '2.16.840.1.113883.3.600.2390.xml')); + + const vsDB = {}; + await Promise.all([ + svs.downloadValueSet( + 'testkey', + '2.16.840.1.113883.3.526.3.1032', + undefined, + tmpCache, + vsDB, + true, + { svsCodeSystemType: 'oid' } + ), + svs.downloadValueSet( + 'testkey', + '2.16.840.1.113883.3.600.2390', + undefined, + tmpCache, + vsDB, + true, + { svsCodeSystemType: 'oid' } + ) + ]); + // Should add the results to the VS DB + Object.keys(vsDB).should.have.length(2); + vsDB['2.16.840.1.113883.3.526.3.1032'].should.eql( + SYSTOLIC_OID_VS_DB['2.16.840.1.113883.3.526.3.1032'] + ); + vsDB['2.16.840.1.113883.3.600.2390'].should.eql( + TOBACCO_OID_VS_DB['2.16.840.1.113883.3.600.2390'] + ); + }); + + it('should merge value sets into the value set database while including both uri and oid versions of codes', async () => { + nock('https://vsac.nlm.nih.gov') + .get('/vsac/svs/RetrieveValueSet') + .basicAuth({ user: 'apikey', pass: 'testkey' }) + .query({ + id: '2.16.840.1.113883.3.526.3.1032' + }) + .replyWithFile(200, path.join(__dirname, 'fixtures', '2.16.840.1.113883.3.526.3.1032.xml')) + .get('/vsac/svs/RetrieveValueSet') + .basicAuth({ user: 'apikey', pass: 'testkey' }) + .query({ + id: '2.16.840.1.113883.3.600.2390' + }) + .replyWithFile(200, path.join(__dirname, 'fixtures', '2.16.840.1.113883.3.600.2390.xml')); + + const vsDB = {}; + await Promise.all([ + svs.downloadValueSet( + 'testkey', + '2.16.840.1.113883.3.526.3.1032', + undefined, + tmpCache, + vsDB, + true, + { svsCodeSystemType: 'both' } + ), + svs.downloadValueSet( + 'testkey', + '2.16.840.1.113883.3.600.2390', + undefined, + tmpCache, + vsDB, + true, + { svsCodeSystemType: 'both' } + ) + ]); + // Should add the results to the VS DB + Object.keys(vsDB).should.have.length(2); + vsDB['2.16.840.1.113883.3.526.3.1032'].should.eql( + SYSTOLIC_OID_URI_VS_DB['2.16.840.1.113883.3.526.3.1032'] + ); + vsDB['2.16.840.1.113883.3.600.2390'].should.eql( + TOBACCO_OID_URI_VS_DB['2.16.840.1.113883.3.600.2390'] + ); + }); + it('should error if value set is not found', async () => { nock('https://vsac.nlm.nih.gov') .get('/vsac/svs/RetrieveValueSet')