On this page:

20.9Composition Resource API

 

The Composition resource in the JavaScript Execution Environment has some additional functionality in addition to that already available for any resource.

To create a Composition resource, use ResourceBuilder.build('Composition').

20.9.1Method: set*(value)

 

There are several setters for basic fields of a Composition.

Inputs:

  • value: String – the value to set the field to. All setters take a single string argument.

Valid setter methods:

  • setSubject
  • setStatus
  • setEncounter
  • setCustodian
  • setAuthor (removes all other added authors)

Instead of setAuthor, you can use addAuthor to non-destructively add an author.

Outputs:

  • Populates the field with the requested value
  • Returns the same Composition object for chaining.

Example:

var composition = ResourceBuilder.build('Composition');
composition.setSubject('Patient/1');

Examples:

var composition = ResourceBuilder.build('Composition');

// Example 1: Set the subject by Patient Name
var patients = Fhir
    .search()
    .forResource('Patient')
    .where('given', 'Ron')
    .where('family', 'Howard')
    .asList();
    
composition.setSubject(patients[0].id.toString());

// Example 2: Set the Composition subject to the subject of an Observation
var observation = Fhir.read('Observation/123');
composition.setSubject(observation.subject.reference.toString());

20.9.2Method: setDate(epoch)

 

This method sets the date of the composition.

Inputs:

  • epoch – the unix timestamp to set the date of the composition to. If you have a Date object date, you can use date.getTime() to retrieve the timestamp

Outputs:

  • Sets the datetime on the composition
  • Returns the same Composition object for chaining.
var composition = ResourceBuilder.build('Composition');

var date = new Date();
var epoch = date.getTime();

composition.setDate(epoch);

20.9.3Method: setType(documentType)

 

This method can be used to auto-populate the type field with the correct coding for a C-Cda document.

Inputs:

  • documentType – the c-cda template this composition represents.

The definitive list of document types can be found in the CDA Exchange Module available types and mappings section.

Outputs:

  • Populates the Composition.type field with an appropriate Coding, including display name.
  • Returns the same Composition object for chaining.

Example usage:

var composition = ResourceBuilder.build('Composition');
composition.setType('ContinuityOfCareDocument');

Note: to set a custom document type, populate the appropriate fields using the ResourceBuilder API:

var composition = ResourceBuilder.build('Composition');
composition.type.coding.system = "My custom system";
composition.type.coding.code= "My custom code";
composition.type.coding.display = "My custom display";

20.9.4Method: addSection(sectionType)

 

This method can be used to create a new section and auto-populate its code and title appropriately for a given C-CDA section template.

Inputs:

  • documentType – the c-cda section-level template this section represents.

The definitive list of available sections can be found in the CDA Exchange Module available types and mappings section.

var composition = ResourceBuilder.build('Composition');
var allergySection = composition.addSection('allergyintolerance');

Outputs:

  • Returns a CompositionSectionBuilder resource to work with.

Note: to set custom section details, use CompositionSectionBuilder.setCode(system, code, display) or populate the appropriate fields using the ResourceBuilder API on the Composition (not on the section):

var composition = ResourceBuilder.build('Composition');
var section = composition.addSection();
composition.section[0].code.coding.system = "my custom system";
composition.section[0].code.coding.code = "my custom code";
composition.section[0].code.coding.display = "my custom display";