SCWebCore.api provides an interface that simplifies the process of requesting Symptom Checker API resources. You can use it to request any resource available on the api. It provides a callback api that will respond with an error or the response object for any symptom checker resource.
Typically a symptom checker application's lifecycle starts with a request for an index of Symptom Checker topics. There are a couple of ways you can do this.
To get symptom checker topics for a particular age group ('adult' or 'peds') or for a specific age in days, use SCWebCore.api.getTitles
and provide a callback function to handle the returned array of titles. See the Symptom Checker API Documentation for more information on the Symptom Checker Topic Index's title model.
SCWebCore.api.getTitles('adult', function(err, titles) {
console.log(titles.length);
})
The api service will maintain an in memory cache of all of the content as it is requested from the api. This cache is cleared when you reload the page or use SCWebCore.locale.setLocale to change the locale for your instance.
- getIndex
- getBodyAreas
- getTopic
- getSpecialTopic
- getDosageTables
- getFirstAid
- getHelp
Take a look at the API class to see the parameters for each of these functions. Each of these functions requires a callback of type requestCallback. This callback has error and data properties where data is either a resource object or an array of resources of the type that you have requested.
Bonus functions
The api interface also offers a handful of other handy functions. Take a look at the API class to see the parameters for each of these functions.
- searchTitles
- searchKeywords
- hyperlinkDosageTables
- clearCache
- getUrl
Example Implementation
In our example angular application, interaction with the Symptom Checker API is handled within the app/routes/core.routes.js
file.
In our example implementation we use the angular promise object to wrap all of our requests in a promise. This is done in order to conform with the ui-router:$state.$resolve api, because it does such a fine job declaring a state map for our application.
.state('index.dosage', {
url: '/dosage?age',
templateUrl: '../views/dosagetables.view.html',
controller: 'DosageTablesController',
...,
resolve: {
titles: function(SCWebCore, $stateParams, $q) {
return $q(function(resolve, reject) {
SCWebCore.api.getDosageTables($stateParams.age, function(err, data) {
if (err) return reject(err);
return resolve(data);
});
});
}
}
})
The above state declaration makes the dosage table titles available within the controller for our index.dosage
state. The Symptom Checker API data for every state in our application is passed to its view model in this fashion.