Business services are powerful components that pull data in from external sources. In most cases, pre-built components do the job, but sometimes you need to code custom business services. There are a few best practices to keep in mind when doing this:
 
1. Lean and Mean - Business services should be coded to have minimal processing. This is due to the fact that if any errors occur within the business service, no message will be sent, and thus no trace will be created. This makes it very difficult to troubleshoot. Instead, populate an Ensemble message as quickly as possible and pass it on to the appropriate target. Some would argue that if a stream comes in, the Ensemble message should include one stream property where a business process would then parse that stream. (See [Example 3 in docs](http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=EFIL_inbound#EFIL_busserv_examples)) Others would say that minimal processing is OK as long as good error checking is included. In either case, keep in mind that data transformations exist and can be used within a business process to do further translation of this data. These transformations should NOT be called from a business service. (See Example 1 in docs) 2. Configurable Target - In most cases, business services should be coded to have a configurable target instead of hardcoding this into the business service. To do this, you can create a property within the business service class called TargetConfigNames with the type Ens.DataType.ConfigName and use the SETTINGS parameter and place this setting on the Configuration Page.

While the property does not need to be named TargetConfigNames - using this name is in concert with the built-in setting used in HL7 components and doing so, maintains consistency within your components. Using the code above only allows you to select one target. If you need to send the message to multiple components, there are options to make this setting multi-select. Refer to Adding and Removing Settings in documentation for more information on how to do this.

You can code the method to handle multiple targets using the following code:

For iTarget=1:1:$L(..TargetConfigNames, ",") {
     Set tOneTarget=$ZStrip($P(..TargetConfigNames,",",iTarget),"<>W")
      Continue:""=tOneTarget
     $$$sysTRACE("Sending input Stream ...")
     set tSC = ..SendRequestAsync(tOneTarget, pRequest)
}</p>

 

Do you have any other best practices you'd add?

</body></html>