Create Custom Transformers with .net
Return to Tutorial Directory
Hello and welcome to this tutorial where we take a look at creating custom transformers for HL7 Soup.
To do this we're going to create a sample custom transformer which concatenates the first name and last name of a patient together and returns it as a variable that we can then use in the rest of our workflow.
We'll start by jumping across to Visual Studio and I'm going to create a new project. I'm going to choose a class library and I'm going to call it CustomTransformersSample.
I'm going to start by renaming my class to the name of my transformer and it's going to be “ConcatenateName”.
Now we've just got to add a reference to HL7 Soup so that we can use its methods. So I add a reference and I'll browse, and we go to c:\Program Files (x86)\Popokey\HL7 Soup\ and then we look for the HL7SoupIntegrations.dll and we will add that to our project.
Now I'll add a using statement that adds the HL7 Soup namespace which is "HL7Soup.Integrations".
Now I'll just take my class and make it inherit from CustomTransformer. Because it inherits from custom transformer we have to implement our abstract class and that provides us with an inbound message for when the data has been transformed and it provides us with the details about the workflow instance, the message that was currently been processed, and a list of parameters that are being sent into the system.
I'm going to start by creating some parameters that will be passed. In order to do that, I add an attribute called “Parameter” and it takes arguments. The first one is the name of the inbound parameter, so the first one will be called FirstName and it's got a description. My second parameter is called LastName.
So now I've configured the inbound arguments for this transformer, I'm going to make it so outputs a variable as well. To do that I create a variable attribute and I give it a name, and I'm going to call it “ConcatenatedName”. I have to give it a sample value as well. Sample values are used to help with bindings so the return result is going to look like Smith comma John.
Okay, so now I have set what comes into my transform at and what goes out my transformer I can write the logic for the transformer itself. The first thing I'm going to do is get the values out of the parameters and put them into local variables. I'll create a string called “FirstName” and I'll make it equal the parameter which has been passed in, and I'm going to get the instance called “FirstName” and I'm just going to copy that from the top so I don't make any typing mistakes. Then the “LastName“, and once again I'll copy that from the top.
I didn't have to add the parameters to variables but I just prefer that in my code.
Next, I'm going to create another variable which concatenates the two together. We’ll call that “ConcatenatedName”, and we'll set that to equal “string.Format”, and I'll just join those two together and put in the last name first and the first name last.
Now that I've done my business logic for this transformer I have to return it. To return a variable we just have to add it to the workflow instance so I type “workflowInstance”, then I set the variable, and the first argument is the name of the variable which in this case “ConcatenatedName”, so once again I copy and paste in the value.
That's it our transformer is written and ready to be deployed into HL7 Soup. It's actually really easy to deploy to HL7 Soup. All I have to do is build my transformer, then navigate to the directory that our DLL was just created in. It's in the bin\debug directory, and we can see here's our CustomTransformerSample.dll. I'm just going to copy that, and then I'm going to navigate to the HL7 Soup directory and into the directory called “CustomLibraries” that's in c:\Program Files (x86)\Popokey\HL7 Soup\CustomLibraries. I'm just going to paste that file into there and that's all I have to do in order to deploy it in HL7 Soup.
I'll load up HL7 Soup and we'll try our Transformer out. I'm going to edit our existing transformer sample workflow that we created in another video
Link to Transformers video.
I just navigate to our sending activity. It has a Transformers section already set up, and what I want to do is add in our new transformer. Here's our ConcatenateName transformer. I'll place that in and automatically it has generated the first name and last name fields from the parameters. Now all I have to do, and it's easier to do this on full screen, is to bind in the patient's name. The given name to the first name, and the family name to the last name, and we're mapped.
Now that we’ve configured the Transformers, we just have to bind in that variable into the name field. The easiest way to do that is to create a connection between an arbitrary field and the name field that we're trying to populate. Then I'm just going to change the value type to Text and Variables, replace the binding that was in there, and if I click insert variable we shall find our concatenated name is now available to us. So just like that, we've created a brand new custom transformer that allows us to write and interact with the workflow in .net.
We do have other videos that show you how to debug these custom transformers, and it's very easy to do that with Visual Studio. You just attach to HL7 Soup.
Also, there is a sister video to this where we look at the general usage of transformers in HL7 Soup and that shows more about how those transformers were created and the workflow that we've used.
HL7 Soup Transformers Tutorial
Please feel free to give us any comments you might have, and if these videos are helping you out, please subscribe to our Channel.
Also, you'd help us out greatly if you like our videos.
Don't forget that the code for this is available at