Profile - Asymmetrik/node-fhir-server-core Wiki

Overview

We are currently focused on being fully compliant with the the latest major stable releases. In this section, we will discuss the options you have for enabling capabilities for each resource and version.

Profile Configuration

Supported Profiles

Go to src/constants.js to find a list of all supported profiles with their associated keys.

Profiles have the following configuration options:

service

versions

corsOptions

baseUrls

Profile(s) Interface

Each profile has a predefined set of methods it can implement. If you do not want to support a particular interaction, for example, delete, then just don't implement the remove method. Each method you implement must return a promise and will receive the following three arguments (see sample code below):

Available Methods

search

module.exports.search = (args, contexts, logger) => new Promise((resolve, reject) => {
        // You will need to build your query based on the sanitized args
	let query = myCustomQueryBuilder(args);
	db.patients.find(query, (err, patients) => {
		if (err) {
			logger.error('Error with Patient.search');
			return reject(err);
		}
		return resolve(patients);
	});
});

searchById

// In patient service
module.exports.searchById = (args, contexts, logger) => new Promise((resolve, reject) => {
	db.patients.find({ _id: args.id }, (err, patient) => {
		if (err) {
			logger.error('Error with Patient.searchById');
			return reject(err);
		}
		return resolve(patient);
	});
});

create

module.exports.create = (args, contexts, logger) => new Promise((resolve, reject) => {
	let { id, resource } = args;
	// This is a mongo specific thing
	resource._id = id;
	
	db.patients.insert(resource, (err, response) => {
		if (err) {
			logger.error('Error with Patient.create');
			return reject(err);
		}
		return resolve({
			id: response._id,
			// This is optional if you support versions
			resource_version: 1
		});
	});
});

update

module.exports.update = (args, contexts, logger) => new Promise((resolve, reject) => {
	let { id, resource } = args;
	// This is a mongo specific thing
	resource._id = id;
	
	db.patients.update(resource, (err, response) => {
		if (err) {
			logger.error('Error with Patient.update');
			return reject(err);
		}
		return resolve({
			id: response._id,
			// This is optional if you support versions
                        // The version is the version of the resource and not the FHIR version
			resource_version: 1
		});
	});
});

remove

module.exports.remove = (args, contexts, logger) => new Promise((resolve, reject) => {
	let { id } = args;
	
	db.patients.remove({ _id: id }, (err, response) => {
		if (err) {
			logger.error('Error with Patient.delete');
			return reject({
				// Must be 405 (Method Not Allowed) or 409 (Conflict)
				// 405 if you do not want to allow the delete
				// 409 if you can't delete because of referential
				// integrity or some other reason
				code: 409,
				message: 'Patient referenced in Observations and cannot be deleted. Please delete observations first.'
			});
		}
		return resolve();
	});
});

Profile(s) Arguments

All profiles support this set of common arguments as well as the arguments for each individual profile defined in the directories below. These come through to your service via the args argument.

Specification Directory
3.0.1 src/server/standards/3_0_1/arguments
1.0.2 src/server/standards/1_0_2/arguments

You can download the structure definitions we are using for STU3 and DSTU2 from the official FHIR website.