Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Groovy SOAP client which connects to Mirth and adds a subject to a subject group. This was created as a proof-of-concept of the SOAP interface for a 3rd-party integration project.
@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.0')
import groovy.xml.*
import wslite.soap.*
import wslite.http.auth.*
def client = new SOAPClient('https://dummy:11443/ClinicalDocumentWSService/ClinicalDocumentWS?wsdl')
client.authorization = new HTTPBasicAuthorization("mirth", "password")
// Grab the latest member list
def members = getSubjectGroupMemberIds(client, 'GROUP001', 'NEW').results
def memberCount = members.list.size()
println "There are ${memberCount} members initially"
// Get a patient
def retrievedSubject = getPatientsByFilterWithoutClinicalItems(client, {
def subjectId =
println "Subject ID: ${subjectId}, name: ${} ${} ${}"
// Add the patient to the subjects of interest list (NEW, ACTIVE, EXCLUDED, RETIRED)
println XmlUtil.serialize( createSubjectGroupMember(client, 'GROUP001', 'NEW', 'MYSTATUS', subjectId) )
// Grab the latest member list
members = getSubjectGroupMemberIds(client, 'GROUP001', 'NEW').results
assert members.list.size() == (memberCount + 1)
println XmlUtil.serialize(members)
// SOAP call methods
def getSubjectGroupMemberIds(client, groupId, groupStatusId){
doSOAPRequest( client, 'getSubjectGroupMemberIds', {
subjectGroupId( groupId )
subjectGroupStatusId( groupStatusId )
* Typically search by forename, surname, dob and gender
* also by patient alias (NHS # or MRN #)
def getPatientsByFilterWithoutClinicalItems(client, subjectFilter){
doSOAPRequest( client, 'getPatientsByFilterWithoutClinicalItems', {
subjectFilterModel subjectFilter
def createSubjectGroupMember(client, groupId, groupStatusId, recFacilityId, patientId){
doSOAPRequest( client, 'createSubjectGroupMember', {
subjectGroupId( groupId )
subjectGroupStatusId( groupStatusId )
subjectId( patientId )
receivingFacilityId ( recFacilityId )
createSubjectGroupMemberExt( 0 ) // '0' causes an update to fail silently if it exists already.
* Do a SOAP request with the given command and payload.
* Doesn't massage the payload, this method is just to reduce copy/paste for the SOAP request.
def doSOAPRequest(client, command, commandBody){
def response = client.send(
sslTrustAllCerts:true) {
envelopeAttributes "xmlns:ejb":""
body {
okStatus(response) ? response."${command}Response".'return' : null
* Check that the HTTP response is good.
* Shamelessly lifted from
def okStatus( SOAPResponse response ){
return response.httpResponse.statusMessage=="OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.