@karmadata/kdtest

Core JavaScript library for KarmaData API

Stats

StarsIssuesVersionUpdatedCreatedSize
@karmadata/kdtest
0.0.244 years ago4 years agoMinified + gzip package size for @karmadata/kdtest in KB

Readme

kd.js - Core library for KarmaData API

npm package

Usage

Documents

Examples

KarmaData provides a versatile API to access our database of healthcare data. Here are examples of how to use the kd.js library to access KD API, starting from the simplest.

Example 1: retrieving a random list of 10 physicians

// create a kd request
const request = kd.Request('Search', 'KdPhysician');
request.setUrlBase('https://api.karmadata.com');
request.setApiKey('-----'); // Please obtain API key by contacting KarmaData

// request data and wait for output
// API defaults to returning 10 results
request.requestData();
request.setAjaxDone((data) => {
  console.log(data);
});

Example 2: retrieving physicians that are female sole proprietors (using filters)

// create filters
const filter1 = kd.FilterItem('KdPhysician', 'Gender', 'String', 'Eq', ['Female']);
const filter2 = kd.FilterItem('KdPhysician', 'IsSoleProprietor', 'Boolean', 'Eq', [true]);

// create request and add those filters
const request = kd.Request('Search', 'KdPhysician');
request.setUrlBase('https://api.karmadata.com');
request.setApiKey('-----'); // Please obtain API key by contacting KarmaData
request.addFilterItem(filter1);
request.addFilterItem(filter2);

// request data and wait for output
request.requestData();
request.setAjaxDone((data) => {
  console.log(data);
});

Example 3: retrieving physicians that are female and belong to physician groups of size 5-10 (using FilterGroup)

// create filters
const filter1 = kd.FilterItem('KdPhysician', 'Gender', 'String', 'Eq', ['Female']);
const filter2 = kd.FilterItem('KdPhysicianGroup', 'NumberOfPhysicians', 'Number', 'Between', [5, 10]);

// create request and add those filters
const request = kd.Request('Search', 'KdPhysician');
request.setUrlBase('https://api.karmadata.com');
request.setApiKey('-----'); // Please obtain API key by contacting KarmaData
request.addFilterItem(filter1)
const group = request.createFilterGroup('And');
request.addFilterItem(filter2, group);

// request data and wait for output
request.requestData();
request.setAjaxDone((data) => {
  console.log(data);
});

Example 4: retrieve physicians that are sole proprietors and sort by graduation year

// create filters
const filter = kd.FilterItem('KdPhysician', 'IsSoleProprietor', 'Boolean', 'Eq', [true]);

// create request and add those filters
const request = kd.Request('Search', 'KdPhysician');
request.setUrlBase('https://api.karmadata.com');
request.setApiKey('-----'); // Please obtain API key by contacting KarmaData
request.addFilterItem(filter);

// adds sorting, then request data and wait for output
request.addSortOrderItem('GraduationYear', 'desc');
request.requestData();
request.setAjaxDone((data) => {
  console.log(data);
});

Fluent Style

kd.js now supports fluent style of constructing a request

let query = KdQuery('Search', 'KdCounty')
  .setUrlBase('https://api.karmadata.com')
  .setApiKey('-----') // Please obtain API key by contacting KarmaData
  .rows(1, 10)
  .where([
    FilterItem('KdCounty', 'GeoName', 'String', 'Eq', ['Plymouth'])
  ])
  .andExists({mainEntity: 'KdCounty'}, [
    FilterItem('KdState', 'GeoName', 'String', 'Eq', ['Massachusetts'])
  ]);
query.requestData()
  .then((data) => {
    console.log(data);
  })

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.