Overview

The Sunwave API allows customers to automate the process of loading completed forms from their applications into Sunwave.

This API should only be used to attach documents to N-Forms. When an attachment is made to an N-Form using the API, it will display as a new instance of that form. For example, if I use this to attach a document to my Master Treatment Plan form, it will look like this:

Configuring Sunwave API

The following steps must be completed on the parent realm in order to enable can configure the Sunwave API for ERP Health:

NOTE: These steps must be performed by the Product team. Contact Product Management to request enabling the ERP health API integration for a given realm.

Register the External App

  1. Go to Practice Setup > External Apps.

  2. Click + Create Registry.

  3. Click the refresh button for Client ID.

  4. Click the refresh button for Client Secret.

  5. Copy the generated Client ID and Client Secret, provide these to the Customer for use when calling the API.

  6. Click Save.

Set API Call Limit Per Day

  1. Go to Manage Realms.

  2. Set API Call Limit Per Day to a value of -1. This allows for unlimited API calls.

Enable IP Access

  1. Go to Practice Setup > IP Access.

  2. Click the New Access button (top-right) and configure as follows, then click Save:

Enable Forms to Allow Attachments via the API

NOTE: You should only add attachments to N-Forms. Do NOT attempt to use the API to make attachments to singular forms like the Face Sheet.

Sunwave API for attaching forms

Syntax

POST https://emr.sunwavehealth.com/SunwaveEMR/api/addforminpatientchart
Content-Type: application/json
Authorization: Digest $token
seed = user_id:client_id:dateTimeBase64:clinic_id:unique_transaction_id:Base64Encode(md5Hex(payload))
token = seed:JWT.hmac(seed, privateKey)

Parameters

Body

{
"account_id": "string",
"service_date":"string",
"patient_first_name": "string",
"patient_last_name": "string",
"patient_dob": "string",
"form_id": "string",
"pdf_payload": "<base64-pdf>"
}

NOTE: Please limit the size of PDF attachments to 200KB or smaller.

Example Payload

{
"account_id": "133038",
"service_date":"2022-05-11",
"patient_first_name": "Arnold",
"patient_last_name": "Sullivan",
"patient_dob": "1999-01-01",
"form_id": "236",
"pdf_payload": "data:application/pdf;base64,JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwogIC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAvTWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0KPj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAgL1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9udAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2JqCgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4gCjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAwMDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9vdCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G"
}

Generating unique_transaction_id

You MUST generate a unique_transaction_id for every call. If you send multiple requests using the same unique_transaction_id, they will be rejected as duplicate transactions.

The following example illustrates how to create a unique_transaction_id using HMAC:

Syntax

hmac(seed, privateKey):

Apex Example

public static String hmac(String message, String privateKey){  
       String algorithmName = 'hmacSHA512';
       Blob hmacData = Crypto.generateMac(algorithmName, Blob.valueOf(message), Blob.valueOf(privateKey));      
       String output =  EncodingUtil.base64Encode(hmacData);
       output = output.replace('+', '-');
       output = output.replace('/', '_');
        return output;
     }