Smile CDR v2024.08.PRE
On this page:

40.14.1Composition 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').

40.14.2Method: 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());

40.14.3Method: 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);

40.14.4Method: 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";

40.14.5Method: addAttester(mode)

 

This method can be used to add an attester to the Composition resource of the type supplied in the mode parameter.

Inputs:

  • mode – the mode which the attester is added (professional, legal etc).

Return value:

This method will return an object on which you can set the properties of the attester. Available properies are:

  • setTime(epoch) – the time at which the composition was attested.
  • setParty(value) – the reference to who did the attestation.
var composition = ResourceBuilder.build('Composition');

var attester = composition.addAttester('legal');
attester.setTime(new Date('2022-06-25').getTime());
attester.setParty('Practitioner/1501');

40.14.6Method: addEvent()

 

This method can be used to add events to the Composition resource, there are no arguments as the details can be added in the return object.

Return value:

This method will return an object on which you may set the properties of the event. Available properties are:

  • addCode(codeSystem, code, display) – the code details which apply to the event being documented.
  • setPeriod(startEpoch, endEpoch) – the start and end times (in unix timestamp) that represent the period.
  • addDetail(value) – the reference to the event being documented.
var composition = ResourceBuilder.build('Composition');

var event = composition.addEvent();
event.addCode('http://somecodesystem', '10001', 'Some display text');
event.setPeriod(new Date('2021-01-11').getTime(), new Date('2022-01-11').getTime());
event.addDetail('AllergyIntolerance/1405');

40.14.7Method: 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";