This is a small JavaScript library that can be used with the LForms form rendering widget to allow it to display forms from the National Institutes of Health (NIH) Common Data Elements (CDE) Initiative. The input format is a JSON-based form definition from the NIH CDE Repository, and the output is the LForms-style form definition which can be given to LForms.
This package installs using the bower package manager.
bower install lforms-converter
The following example assumes you have also installed LForms.
var converter = new LFormsConverter();
converter.convert(urlToCDEForm,
function(lfData) {
scope.lfData = new LFormsData(lfData);
scope.$apply(scope.lfData);
},
function(err) {
scope.error = err;
}
);In the call to the convert function, the first argument is a URL for obtaining the CDE form definition which is to be converted to the LForms format. These URLs are in the form:
https://cde.nlm.nih.gov/form/[tinyId]
where [tinyId] is replaced by the tinyId attribute of the form. You can see tinyIds in the URLs of forms in the NIH CDE Repository.
The second argument is a callback with the translated form definition for LForms. The example shows that if you are using this with LForms, you would then constuct an LFormsData object from the form definition and assign it to the (AngularJS) scope's lfData variable, and then tell AngularJS to notice the change.
The final argument is a callback used in case of an error ocurring. Its argument is an object with the following fields (as documented in oboe):
- thrown - if an error was thrown, this will contain that
- statusCode - the status code, if the request got that far
- body - the response body for the error, if any
- jsonBody - if the server’s error response was JSON, the parsed body
See LICENSE.md.