FHIR/bower-fhir

Name: bower-fhir

Owner: FHIR

Description: null

Created: 2015-02-12 13:19:13.0

Updated: 2017-04-04 04:47:43.0

Pushed: 2017-07-08 11:01:46.0

Homepage: null

Size: 46

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits
BazZy2015-02-12 16:04:55.02

Other Committers

UserEmailMost Recent Commit# Commits
Travis CI Deployerrobot@health-samurai.io2017-07-08 11:01:43.015

README

fhir.js

npm version

Build Status

Gitter chat

JavaScript client for FHIR

Goals:
Development

Node.js is required for build.

We recommend installling Node.js using nvm

Build & test:

clone https://github.com/FHIR/fhir.js
hir.js
install

ld fhir.js
run-script build

n tests in node
run-script test

n tests in phantomjs
run-script integrate
API
Create instance of the FHIR client

To communicate with concrete FHIR server, you can create instance of the FHIR client, passing a configuration object & adapter object. Adapters are implemented for concrete frameworks/libs (see below).

config = {
 FHIR server base url
seUrl: 'http://myfhirserver.com',
th: {
 bearer: 'token',
 // OR for basic auth
 user: 'user',
 pass: 'secret'

 Valid Options are 'same-origin', 'include'
edentials: 'same-origin',
aders: {
'X-Custom-Header': 'Custom Value',
'X-Another-Custom': 'Another Value',



ient = fhir(config, adapter)
Config Object

The config object is an object that is passed through the middleware chain. Any values in the config object that are not mutated by middleware will be available to the adapter.

Because middleware mutates the config, it is strongly recommended when implementing an adapter to not directly rely on config passed in.

baseUrl

This is the full url to your FHIR server. Resources will be appended to the end of it.

auth

This is an object representing your authentication requirements. Possible options include:

bearer

This is your Bearer token when provided, it will add an Authorization: Bearer <token> header to your requests.

user

This is your Basic auth Username.

When you provide both user name and password, basic auth will be used.

pass

This is your basic auth password.

When you provide both user name and password, basic auth will be used.

credentials

This option controls the behaviour of sending cookies to the remote server. Refer to the table below for how to configure the option for your desired adapter.

| Adapter | credentials | Result | |———-|—————|—————————| | Native | 'same-origin' | Cookies are sent to the server, if it is on the same host as the origin sender | | Native | 'include' | Send cookies to all hosts | | jQuery | 'same-origin' | ignored | | jQuery | 'include' | Send cookies to all hosts | | yui | 'same-origin' | ignored | | yui | 'include' | Send cookies to all hosts | | angular | 'same-origin' | ignored | | angular | 'include' | ignored | | node | 'same-origin' | ignored | | node | 'include' | ignored |

headers

A key:value object that represents headers. This object is passed through to you configured adapter.

If you choose to add custom headers to your requests, you should ensure that the server that you are talking to supplies the appropriate headers. Further reading on Allowed Headers: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

t config = {
aders: {
'X-Custom-Header': 'Custom Value',
'X-Another-Custom': 'Another Value',


Adapter implementation

Currently each adapter must implement an http(requestObj) function:

Structure of requestObj:

and return promise (A+)

http(requestObj).then(success, error)

where: success - success callback, which should be called with (data, status, headersFn, config)

error - error callback, which should be called with (data, status, headerFn, config)

Here are implementations for:

Conformance & Profiles
Resource's CRUD

To create a FHIR resource, call myClient.create(entry, callback, errback), passing an object that contains the following properties:

In case of success,the callback function will be invoked with an object that contains the following attributes:

entry = {
tegory: [{term: 'TAG term', schema: 'TAG schema', label: 'TAG label'}, ...]
source: {
resourceType: 'Patient',
//...



ient.create(entry,
ction(entry){
console.log(entry.id)

ction(error){
onsole.error(error)


Search

fhir.search({type: resourceType, query: queryObject}), where queryObject syntax fhir.js adopts mongodb-like query syntax (see):

e: 'maud'}
 name=maud

e: {$exact: 'maud'}}
 name:exact=maud

e: {$or: ['maud','dave']}}
 name=maud,dave

e: {$and: ['maud',{$exact: 'dave'}]}}
 name=maud&name:exact=Dave

thDate: {$gt: '1970', $lte: '1980'}}
 birthDate=gt1970&birthDate=lte1980

ject: {$type: 'Patient', name: 'maud', birthDate: {$gt: '1970'}}}
 subject:Patient.name=maud&subject:Patient.birthDate=gt1970

bject.name': {$exact: 'maud'}}
 subject.name:exact=maud

For more information see tests

AngularJS adapter: ng-fhir

AngularJS adapter after npm run-script build can be found at dist/ngFhir.js

Usage:

lar.module('app', ['ng-fhir'])
onfig(['$fhirProvider', function ($fhirProvider) {
$fhirProvider.baseUrl = 'http://try-fhirplace.hospital-systems.com';
$fhirProvider.auth = {
  user: 'user',
  pass: 'secret'
};
$fhirProvider.credentials = 'same-origin'
)
ontroller('mainCtrl', ['$scope', '$fhir', function ($scope, $fhir) {
$fhir.search(
  {
    type: 'Patient',
    query: {name: 'emerald'}
  }).then(
  function (successData) {
    $scope.patients = successData.data.entry;

  },
  function (failData) {
    $scope.error = failData;
  }
);
);  
jQuery adapter: jqFhir

jQuery build can be found at dist/jqFhir.js

Example app

Usage:

ipt src="./jquery-???.min.js"> </script>
ipt src="./jqFhir.js"> </script>
avascript
reate fhir instance
fhir = jqFhir({
baseUrl: 'https://ci-api.fhir.me',
auth: {user: 'client', pass: 'secret'}


.search({type: 'Patient', query: {name: 'maud'}})
n(function(bundle){
nsole.log('Search patients', bundle)

Node.js adapter: npm install fhir.js

Via NPM you can npm install fhir.js. (If you want to work on the source code, you can compile coffee to js via npm install, and use ./lib/adapters/node as an entrypoint.)

mkFhir = require('fhir.js');

client = mkFhir({
baseUrl: 'http://try-fhirplace.hospital-systems.com'


nt
.search( {type: 'Patient', query: { 'birthdate': '1974' }})
.then(function(res){
    var bundle = res.data;
    var count = (bundle.entry && bundle.entry.length) || 0;
    console.log("# Patients born in 1974: ", count);
})
.catch(function(res){
    //Error responses
    if (res.status){
        console.log('Error', res.status);
    }

    //Errors
    if (res.message){
        console.log('Error', res.message);
    }
});
YUI adapter: yuiFhir

YUI build can be found at dist/yuiFhir.js

NOTE: The current implementation creates a YUI sandbox per request which is expensive.

Usage:

ipt src="./yui-???.min.js"> </script>
ipt src="./yuiFhir.js"> </script>
avascript
reate fhir instance
fhir = jqFhir({
baseUrl: 'https://ci-api.fhir.me',
auth: {user: 'client', pass: 'secret'}


.search(type: 'Patient', query: {name: 'maud'}, success: function(bundle) {}, error: function() {})
Native adapter: npm install fhir.js

The Native adapter is part of fhir.js npm module. The adapter can be consumed in a few ways, the simplest is documented below.

Usage

This assumes use of browserify or similar bundler.

  1. npm install fhir.js
  2. In your js somewhere use the following snippet.
nclude the adapter
nativeFhir = require('fhir.js/src/adapters/native');

reate fhir instance
fhir = nativeFhir({
baseUrl: 'https://ci-api.fhir.me',
auth: {user: 'client', pass: 'secret'}


xecute the search
.search({type: 'Patient', query: {name: 'maud'}}).then(function(response){
//manipulate your data here.

For Developers

FHIR.js is built on top of middleware concept. What is middleware? This is a high order function of shape:

mw  = function(next){
eturn function(args){
 if (...) // some logic{
    return next(args); //next mw in chain
 } else {
    return promise; //short circuit chain
 }


Using function Middleware(mw) you can get composable middle-ware (with .and(mw) method):

mposition = Middleware(mw).and(anotherMw).and(anotherMw);

Every API function is built as chain of middlewares with end handler in the end:

ormance = $GET.and(BaseUrl.slash("metadata")).end(http)
te =  $POST.and($resourceTypePath).and($ReturnHeader).and($JsonData).end(http),
Release Notes
release 0.1

API changes history is split into 3 fns:

TODO
Contribute

Join us by github issues or pull-requests

License

Released under the MIT license.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.