On this page:

14.2CDA REST Operations

 

The rest operations available to use with the CDA Module are fully documented in the CDA Exchange Endpoint section of the docs.

This document will serve as a higher level overview of the available operations.

14.2.1Endpoints for configuring templates

 

After you construct a JavaScript template script to suit your Cda document needs, you will want to add it to the available templates in your Cda module instance.

POST/PUT/DELETE/GET http://localhost:9000/cda/{module_id}/template/{template_id}

module_id: This is the id of the cda module in your instance of Smile.
template_id: This is the id of the cda template you intend to create, update, delete, or view

Creating a Cda Template

POST/PUT:

You have a script you are happy with and you are ready to upload it to your cda module.

In addition to the script parameter, there are two optional parameters that we recommended you include.

  • params: An array of strings indicating which parameters the script expects for its input map. What you include here has no bearing on the actual script but serves to help the eventual consumer of your script to know what to include with their request. Example: ["patient", "author"]
  • description: A human readable description explaining the purpose of the script, how it works, and the purpose / format it expects for the params.

Example request: POST http://localhost:9000/cda/{module_id}/template/example

body:

{
   "script" : "function generateCdaExchangeComposition(inputMap) {\n    var composition = ResourceBuilder.build('Composition');\n    composition.title = inputMap['title'];\n    return composition;\n}",
   "params" : ["title"],
   "description" : "A very basic cda template script example"
}

Once posted, you can update any of these three fields with a PUT request to the same URL, delete it with DELETE, or view it with GET

In addition to being able to view a single template, you can view all templates in your Cda module with GET http://localhost:9000/cda/{module_id}/template

Help! My script has illegal unescaped characters!

If your CDA script has natural new line characters, tabs, or double-quotes, then you can't just paste it into your JSON request body. You could use a tool or manually convert your script to escape special characters and then paste those into your request.

Alternatively, the CDA module has a route designed to work around this issue: PUT http://localhost:9000/cda/{module_id}/template/{template_id}/script. This route takes an input of type "application/javascript".

This route will add/replace the script in template_id with the code you include as the body of your request. In order to also populate the description and params fields, you would have to make a call to PUT http://localhost:9000/cda/{module_id}/template/{template_id} with description and params included in your json body. If using PUT, you can make the calls in either order.

14.2.2Endpoints for applying templates

 

Once your template has been posted to your Cda module, you will likely want to use it! There is a single route for applying a template, and an additional route for creating Cda Documents from an existing Composition or Bundle.

Apply a template

POST http://localhost:9000/cda/{module_id}/template/{template_id}/apply

If your script requires no input params, then you can call successfully call this route with an empty JSON object. In fact, the simple example above would still work, but the title would not get populated because its source would be undefined.

There are many available options when calling this route. For a full list of body parameters available, please check out the Use / Apply CDA Template documentation.

Apply a resource

POST http://localhost:9000/cda/{module_id}/{resource_type}/{resource_id}/apply

If you run the "Apply a template" route and persist the Composition and/or Bundle, then you can run this route next and achieve the same CDA result as you got from the initial request.

If you persisted the Composition and Bundle, then the response from the initial request would include something like the following:

{
	"composition": "Composition/1852/_history/1",
	"fhirDocument": "Bundle/1853/_history/1",
}

Running either of the following requests would then allow you to generate a CDA document:
POST http://localhost:9000/cda/{module_id}/Composition/1852/apply
POST http://localhost:9000/cda/{module_id}/Bundle/1853/apply

For full details on how to use this route, please check out the Create CDA from Composition/Bundle documentation.