Class: ResourceWrapper

ResourceWrapper(_config)

new ResourceWrapper(_config)

Represents a wrapper for a SanteDB resource

A static instance of this API can be accessed on the SanteDB.resource property. This provides a convenient way to use this wrapper with all the built-in SanteDB resource types. Constructing this class should only be used when you are accessing a custom resource or extended resource which is not in the default SanteDB REST API.
Parameters:
Name Type Description
_config any The configuration object
Properties
Name Type Description
resource string The resource that is being wrapped
api APIWrapper The API to use for this resource
Source:

Methods

(static) addAssociatedAsync(id, property, data, state, upstream) → {Promise}

Adds a new association to the specified parent object at the specified path

Parameters:
Name Type Description
id string The identifier of the container
property string The associative property you want to add the value to
data any The data to be added as an associative object (note: Most resources require that this object already exist)
state any A stateful object for callback correlation
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
See:
Returns:
A promise which is fulfilled when the request is complete
Type
Promise

(static) cancelAsync(id, state, upstream) → {Promise}

Performs a cancel on the specified object

A cancel differs from a delete in that a cancel triggers a state change from NORMAL>CANCELLED
Parameters:
Name Type Description
id string The unique identifier for the object to be cancelled
state any A unique state object which is passed back to the caller
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise

(static) cancelAsync(id, upstream, state) → {Promise}

Performs an obsolete on the specified object

An obsolete differs from a delete in that a cancel triggers a state change from NORMAL>OBSOLETE
Parameters:
Name Type Description
id string The unique identifier for the object to be cancelled
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
state any A unique state object which is passed back to the caller
Source:
Returns:
The promise for the operation
Type
Promise

(static) copyAsync(id, state) → {Promise}

Performs a COPY operation on the specified resource (creating a copy from remote)

The copy method is used by the dCDR to download a resource which has been fetched from an upstream iCDR server and create a local dCDR instance of the object.
Parameters:
Name Type Description
id string The unique identifier for the object on which the invokation is to be called
state any A unique state object which is passed back to the caller
Source:
Returns:
The promise for the operation
Type
Promise

(static) deleteAsync(id, state, upstream) → {Promise}

Performs an obsolete (delete) operation on the server

Parameters:
Name Type Description
id string The unique identifier for the object to be deleted
state any A unique state object which is passed back to the caller
upstream boolean True if the delete should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise

(static) find(query) → {Promise}

Queries for instances of the resource this wrapper wraps in a synchronous fashion

Parameters:
Name Type Description
query any The query for the object that you are looking for
Source:
See:
  • {SanteDBWrapper.findAsync} For asynchronous method
Returns:
A promise which is blocked and not executed until the operation is complete
Type
Promise

(static) findAssociatedAsync(id, property, query, upstream) → {Promise}

Performs a find operation on an associated object

In the HDSI REST interface, an "associated" object is a sub-property or chained property on a parent resource. The resource has to support this type of relationship, and must have a registered child property. This method will allow the JavaScript API to access these chained resources. Like the findAsync method, the result of this operation is usually a Bundle
Parameters:
Name Type Description
id string The identifier of the object whose children you want query
property string The property path you would like to filter on
query any The query you want to execute
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
See:
Returns:
A promise for when the request completes
Type
Promise
Example
Get Groups a User belongs to
async getGroups(userName) {
 try {
     var users = await SanteDB.resources.securityUser.findAsync({ "userName" : userName });
     var userId = users.resource[0].id;
     // Fetch the groups
     var groups = await SanteDB.resources.securityUser.findAssociatedAsync(userId, 'groups');
     console.info(groups.resource)
 }
 catch(e) {
     console.error(e);
 }
}

(static) findAsync(query, viewModel, state, upstream) → {Promise}

Queries for instances of the resource this wrapper wraps

This method will execute a full HDSI or AMI query against the SanteDB REST API. The HDSI query https://help.santesuite.org/developers/service-apis/health-data-service-interface-hdsi/hdsi-query-syntax is represented as a JavaScript object with the property path being the key and filter value being the value. Multiple values for the filter property can be expressed as an array. The result of this is a Bundle.
Parameters:
Name Type Description
query any The HDSI query to filter on
viewModel any The view model definition to use when loading
state any A unique state object which is passed back to the caller
upstream boolean True if the query should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise
Example
Query for John or Jane Smith
  async function queryForJohnOrJane() {
      try {
          var results = await SanteDB.resources.patient.findAsync({
              "name.component[Given].value" : [ 'John', 'Jane' ],
              "name.component[Family].value" : 'Smith'
          }, 'full', false);
          console.info("Found " + results.total + " matching results");
          results.resource.forEach(r => console.info(r)); // output results
      }
      catch(e) {
          console.error(e);
      }
  }

(static) getAssociatedAsync(id, property, associatedId, state) → {Promise}

Retrieves an existing associated object from the specified scoper

Parameters:
Name Type Description
id string The identifier of the container object
property string The property path from which the object is to be retrieved
associatedId string The identifier of the sub-object to be retrieved
state any A state for correlating multiple requests
Source:
See:
Returns:
A promise which is fulfilled when the request comletes
Type
Promise

(static) getAsync(id, viewModel, parms, state, upstream) → {Promise}

Retrieves a specific instance of the resource this wrapper wraps

Parameters:
Name Type Description
id string The unique identifier of the resource to retrieve
viewModel string A unique state object which is passed back to the caller
parms any Extra parameters to pass to the get function
state any A unique state object which is passed back to the caller
upstream boolean True if the get should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise
Example
Fetch a patient by ID
  async function fetchPatient(id) {
      try {
          // fetch from local dCDR repository
          var local = await SanteDB.resource.patient.getAsync(id, "_full", null, false);
          // fetch from remote dCDR repository
          var remote = await SanteDB.resource.patient.getAsync(id, "_fall", null, true);
          console.info({ "local" : local, "remote" : remote });
      }
      catch(e) {
          console.error(e);
      }
  }

(static) getUrl()

Gets the URL to this resource base

Source:

(static) insertAsync(data, state, upstream) → {Promise}

Inserts a specific instance of the wrapped resource

When inserting data into the CDR, it is important that the object passed into {@param data} has an appropriate $type which matches the type of data being sent. This check is done to ensure that a Patient is not submitted to the Act endpoint.
Parameters:
Name Type Description
data any The data / resource which is to be created
state any A unique state object which is passed back to the caller
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise
Example
Register a new Place
async function registerNewPlace(name) {
  try {
      var place = await SanteDB.resources.place.insertAsync(new Place({
          classConcept: EntityClassKeys.CityOrTown,
          name : {    
              OfficialRecord : [
                  {
                      component : {   
                          $other : [
                              name
                          ]
                      }
                  }
              ]
          }
      }));
      console.info("Registered place successfully!", place);
  }
  catch (e) {
      console.error(e);
  }
}

(static) invokeOperationAsync(id, operation, parameters, upstream, state) → {Promise}

Invokes the specified method on the specified object

SanteDB's iCDR and dCDR HDSI interfaces allow for the invokation of operations (https://help.santesuite.org/developers/service-apis/health-data-service-interface-hdsi/http-request-verbs#operations). Operations aren't resources per-se, rather they are remote procedure calls where a caller can pass parameters to the operation. Invokable operations can be bound to specific instances (they operate on a single instance of an object, in which case the id parameter is required), or on a class (in which case id should be undefined).
Parameters:
Name Type Description
id string The identifier of the container (null if global execute)
operation string The operation you want to execute
parameters any The parameters to the operation being executes (example: { clear: true, softFind: true })
upstream bool True if the operation shold be executed opstream
state object A tracking state to send to the callback
Source:
Returns:
A promise which is fulfilled when the request is complete
Type
Promise
Example
Start all Jobs
async function startAllJobs() {
  try {
      var jobs = await SanteDB.resources.jobInfo.findAsync();
      await Promise.all(jobs.resource.map(j => SanteDB.resources.jobInfo.invokeOperationAsync(j.id, "start")));
  }
  catch(e) {
      console.error(e);
  }
}

(static) lockAsync(id, state, upstream) → {Promise}

Performs the specified CHECKOUT operation on the server

The checkout and checkinAsync methods are used to control concurrent editing of a resource. It is typically recommended to checkout a resource when a user begins editing an object and perform a checkin when the operation is complete. The iCDR and dCDR will do this automatically when a PUT request is submitted, however this occurs after the data is submitted. By performing interactive CHECKOUT and CHECKIN commands you can add an indicator to your user interface to inform th euser that another user is editing the object.
Parameters:
Name Type Description
id string The unique identifier for the object on which the invokation is to be called
state any A unique state object which is passed back to the caller
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise
Example
Checkout / Update / Checkin

async loadPatient(id) {
  try {
      await SanteDB.resource.patient.checkoutAsync(id); // attempt to get a lock - this will throw an exception if unsuccessful
      var patient = await SanteDB.resources.patient.getAsync(id); // get the latest version no we're checked out
      $timeout(s => s.patient = patient); // Add to scope    
  }
  catch(e) {
      $timeout(s => s.isLockedOut = true);
  }
}

async savePatient(id, patient) {
  try {
      var patient = await SanteDB.resources.patient.updateAsync(id, patient);
      await SanteDB.resources.checkinAsync(id);
  }
  catch(e) {
      console.error(e);
  }
}

(static) lockAsync(id, state, upstream) → {Promise}

Performs the specified LOCK operation on the server

Parameters:
Name Type Description
id string The unique identifier for the object on which the invokation is to be called
state any A unique state object which is passed back to the caller
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise

(static) nullifyAsync(id, state, upstream) → {Promise}

Performs a nullify on the specified object

A nullify differs from a delete in that a nullify marks an object as "never existed"
Parameters:
Name Type Description
id string The unique identifier for the object to be nullified
state any A unique state object which is passed back to the caller
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise

(static) patchAsync(id, etag, upstream, patch, state) → {Promise}

Sends a patch to the service

The patching operation is used to update a portion of the resource without subimtting the entirety of the object to the dCDR or iCDR server (https://help.santesuite.org/developers/service-apis/health-data-service-interface-hdsi/patching)
Parameters:
Name Type Description
id string The identifier of the object to patch
etag string The e-tag to assert
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
patch Patch The patch to be applied
state any A unique state object which is passed back to the caller
Source:
Returns:
The promise for the operation
Type
Promise

(static) removeAssociatedAsync(id, property, associatedId, state, upstream) → {Promise}

Removes an existing associated object from the specified scoper

Parameters:
Name Type Description
id string The identifier of the container object
property string The property path from which the object is to be removed
associatedId string The identifier of the sub-object to be removed
state any A state for correlating multiple requests
upstream Boolean True if the query should be sent to upstream service
Source:
See:
Returns:
A promise which is fulfilled when the request comletes
Type
Promise

(static) touchAsync(id, upstream, state) → {Promise}

Performs a TOUCH operation on the specified resource (updating it's modfiedOn time)

The touch method is useful when a user or administrator wants to force the modifiedOn time to be changed on the dCDR or iCDR service. Any subsequenet synchronization request will see the object as changed, and will re-download the resource. This is especially useful if the data was updated using the database and SQL.
Parameters:
Name Type Description
id string The unique identifier for the object on which the invokation is to be called
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
state any A unique state object which is passed back to the caller
Source:
Returns:
The promise for the operation
Type
Promise

(static) unLockAsync(id, state, upstream) → {Promise}

Performs the specified CHECKIN operation on the server

Parameters:
Name Type Description
id string The unique identifier for the object on which the invokation is to be called
state any A unique state object which is passed back to the caller
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise

(static) unLockAsync(id, state, upstream) → {Promise}

Performs the specified UNLOCK operation on the server

Parameters:
Name Type Description
id string The unique identifier for the object on which the invokation is to be called
state any A unique state object which is passed back to the caller
upstream boolean True if the registration should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise

(static) updateAsync(id, data, state, upstream) → {Promise}

Updates the identified instance of the wrapped resource

Parameters:
Name Type Description
id string The unique identifier for the object to be updated
data any The data / resource which is to be updated
state any A unique state object which is passed back to the caller
upstream boolean True if the update should be directly submitted to the upstream iCDR server
Source:
Returns:
The promise for the operation
Type
Promise