Skip to content

Commit

Permalink
fix: default option should be url when empty options passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler J Cvetan committed Apr 16, 2024
1 parent 6caa0df commit 6168999
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/svs.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,9 @@ function parseVSACXML(xmlString, vsDB = {}, options = { svsCodeSystemType: 'url'
const systemOid = `urn:oid:${system}`;
const systemUri = getVSACCodeSystem(vsacCS, system);

// Replace oid system with the url system, if one exists
if (options.svsCodeSystemType === 'url') {
if (systemUri !== null) {
system = systemUri.uri;
} else {
system = systemOid;
}
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) {
Expand All @@ -99,8 +95,12 @@ function parseVSACXML(xmlString, vsDB = {}, options = { svsCodeSystemType: 'url'
// Include the standard oid system
system = systemOid;
} else {
// Keep the oid system as is
system = systemOid;
// Replace oid system with the url system, if one exists
if (systemUri !== null) {
system = systemUri.uri;
} else {
system = systemOid;
}
}

codeList.push({ code, system, version });
Expand Down
46 changes: 46 additions & 0 deletions test/svs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,52 @@ 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')
Expand Down

0 comments on commit 6168999

Please sign in to comment.