A browser-based and node.js client to BloomAPI.
The following are steps to get BloomJS into your javascript-based project.
Place dist/bloom.min.js
from the GitHub project or install it with bower (bower install bloomjs
) into your project in a location accessible from the web. Include it in your site with a script tag
<script src="js/bloom.min.js"></script>
npm install bloom-js
Use it in your node project via
var bloomjs = require('bloom-js');
Create New Client
bloomjs.Client(<API Key OR options>);
- Returns: BloomJS Client Object
API Key
BloomAPI access keyoptions
object can have the follow parametersurl
root url of BloomAPI (e.g. http://www.bloomapi.com/api)apiKey
API Key
bloomClient.sources(<callback>)
- Returns nothing
callback
a function that will be called once results retrieved. Paramters to callback includeerror
an object that is set if something went wrongresponse
an array of sources available
bloomClient.search(<source>, <search params>, <options>, <callback>)
- Returns nothing
source
is a string that matches a BloomAPI data source name (e.g. 'usgov.hhs.npi')search params
is a object that represnts a query. See Example Usage for expected object structure. Optionaloptions
object with options to pass through that are not search params (e.g. 'offset' and 'limit') Optionalcallback
a function that will be called once results retrieved. Parameters to callback includeerror
an object that is set if something went wrongresponse
an array of results found given queryinfo
additional information on the query/ response. Currently includesmeta
which is the metadata from the response (e.g.rowCount
andmessages
)
bloomClient.find(<source>, <id>, <callback>)
- Returns nothing
source
is a string that matches a BloomAPI data source name (e.g. 'usgov.hhs.npi')id
a string that will be used to match the ID of the dataset (e.g. the ten-digit unique NPI or an HCPCS code)callback
a function that will be called once results retrieved. Parameters to callback includeerror
an object that is set if something went wrongresponse
an single result found given id
The following will work on both the browser (using JSONP behind the scenes) and Node.js:
Create a new client
// Basic
var bloomClient = new bloomjs.Client();
// If using an API Key
var bloomClient = new bloomjs.Client('<API Key Here>');
// If using your own server (with or without your own API keys)
var bloomClient = new bloomjs.Client({
url: "http://www.bloomapi.com/api",
apiKey: "<API Key Here>" // Optional
});
Query available datasources
bloomClient.sources(function (error, response) {
if (error) return console.log(error.stack);
var source = response[0];
console.log('=== First available source');
console.log('Name: ' + source.source);
console.log('Last Checked for Updates: ' + source.checked);
});
Search the National Provider Identifier (NPI) without parameters
bloomClient.search('usgov.hhs.npi', function (error, response, info) {
if (error) return console.log(error.stack);
console.log('=== First available NPI');
console.log('NPI: ' + response[0].npi);
console.log('Total NPIs: ' + info['meta']['rowCount']);
});
Search HCPCS Procedure Codes for the code 'C9289'
bloomClient.search('usgov.hhs.hcpcs', {
'code': 'C9289'
}, function (error, response) {
if (error) return console.log(error.stack);
console.log('=== HCPCS code found');
console.log('Code: ' + response[0].code);
});
Page through search results
var bloomjs = require('bloom-js');
var bloomClient = new bloomjs.Client();
function searchAll(dataset, query, cb) {
var offset = 0;
(function searchMore(aggregate) {
bloomClient.search(dataset, query, { 'offset': offset, 'limit': 100 }, function (err, data, info) {
if (err) return cb(err);
data = data.concat(aggregate);
if (info.meta.rowCount > data.length) {
offset += 100;
searchMore(data);
} else {
cb(null, data);
}
});
})([]);
};
searchAll('usgov.hhs.npi', {'last_name': 'murillo'}, function (err, results) {
if (err) console.log(err.stack);
console.log(results.length);
});
Search HCPCS Procedure Codes for any code with word that starts with 'ambula' in the description' This also specifies an offset and limit using the options parameter.
bloomClient.search('usgov.hhs.hcpcs', {
'long_description': {
'prefix': 'ambula'
}
}, {
'offset': 0,
'limit': 10
}, function (error, response) {
if (error) return console.log(error.stack);
console.log('=== HCPCS code starting with ambula');
console.log('Code: ' + response[0].code);
});
Search for HCPCS codes with both the prefix 'ambula' and another word 'emer'
bloomClient.search('usgov.hhs.hcpcs', [
{
'long_description': { 'prefix': 'ambula' }
},
{
'long_description': { 'prefix': 'emer' }
}
], function (error, response, info) {
if (error) return console.log(error.stack);
console.log('=== HCPCS code starting with ambula AND emer');
console.log('Code: ' + response[0].code);
});
Search HCPCS for both code 'L8410' and 'C9289' (Logical OR)
bloomClient.search('usgov.hhs.hcpcs', {
'code': ['L8410', 'C9289']
}, function (error, response) {
if (error) return console.log(error.stack);
console.log('=== HCPCS code with codes L8410 or C9289');
console.log('Code: ' + response[0].code);
console.log('Code: ' + response[1].code);
});
Find a National Provider Identifier its NPI
bloomClient.find('usgov.hhs.hcpcs', 1770707127, function (error, response) {
if (error) return console.log(error.stack);
console.log('=== NPI details for 1770707127');
console.log('NPI: ' + response.npi);
});