Skip to content

Getting Started

cleeDev edited this page Jun 28, 2018 · 13 revisions

Quick Overview

The core FHIR server is intended to simplify the process of standing up your own FHIR server. We try to abstract a lot of the security and boilerplate away so all you need to do is setup some basic configurations, and make queries. In this getting started guide, we will walk through installing all the dependencies, configuring the server, adding support for a profile, and querying for your FHIR data.

Creating a server

Installation

You must have Node >= 7.7 installed. You can use Homebrew (macOS), nvm (macOS/Linux), or nvm-windows to easily install Node. If you prefer to download directly from node, you can find the download links here.

Once you have node installed, install node-fhir-server-core.

## Install with yarn
yarn add git+https://github.com/Asymmetrik/node-fhir-server-core.git

## For npm users
npm install --save git+https://github.com/Asymmetrik/node-fhir-server-core.git

Profile Setup

Now that you have all of your dependencies installed, it's time to start building our server. We'll start by deciding what profiles and interactions to support. For complete documentation on profiles and how they work, please see the Profile wiki.

For the sake of this guide, we are going to only support one profile and we will support only the read interaction for that profile. Let's create a file called patient.service.js. The interactions are how people can interact with a profile, essentially the basic CRUD (create, read, update, and delete) operations. Copy the following javascript code to 'patient.service.js' file.

// Each method must return a promise and will receive a set of sanitized arguments and a logger instance
// The implementations here change depending on your backend, this is where you need to do your queries
// to retrieve data, for the example, we are going to return json objects to keep things simple.

// This method is required for any profile because the server needs it to generate a conformance statement
module.exports.count = (args, logger) => new Promise ((resolve, reject) => {
  // Let's assume we only have one patient currently, this method needs to return a number
  resolve(1);
});

// This method is for searching
module.exports.search = (args, logger) => new Promise ((resolve, reject) => {
  // This method needs to return an array of patients
  // You will need to implement findPatientsWithArgs yourself
  let patients = findPatientsWithArgs(args);
  // Make sure to return an array
  resolve(patients);
});

// This method is for searching by id
module.exports.searchById = (args, logger) => new Promise ((resolve, reject) => {
  // This method needs to return a single patient
  // You will need to implement findPatientsWithArgs yourself
  let patient = findPatientById(args.id);
  // Make sure to return an array
  resolve(patient);
});

Setting up config and starting the server

Now that you have a profile service ready to go, let's create an app.js file where we can configure and start the server. Copy the following javascript code to app.js file.

let path = require('path');
const FHIRServer = require('@asymmetrik/node-fhir-server-core');
const { VERSIONS } = FHIRServer.constants;

// Here we set up our config, you can find a listing of all your options available at
// https://github.com/Asymmetrik/node-fhir-server-core/wiki/Configuration
const config = {
	profiles: {
                // See https://github.com/Asymmetrik/node-fhir-server-core/wiki/Profile#supported-profiles
                // for all the profiles we support and what the keys are, for the Patient profile it is
                // patient, so we provide the service we created and the FHIR version we want it available on
		patient: {
			service: path.resolve('./patient.service.js'),
			versions: [ VERSIONS.STU3 ]
		}
	},
        server: {
                corsOptions: {}
        }
};

// Let's create an instance of our server, there are more advanced ways to create the server if you need
// more flexibility, documentation for that is coming soon
let server = FHIRServer.initialize(config);
server.logger.info('FHIR Server successfully validated.');
// Start our server on port 3000
server.listen(3000, () =>
	server.logger.info('FHIR Server listening on localhost:' + 3000)
);

Start the server:

node app.js

You should be able to visit localhost:3000/stu3/metadata and see a conformance statement that says you support the patient profile.

Clone this wiki locally