Rhapsody uses a language called XPATH to manipulate the data in an XML message. For additional information on what XPATH is and how to use it, refer to the following links for details:
Example
This scenario involves extracting the value of surgery
from the <procedure>
element, and extracting the value of 5555
from the pid
attribute of the <patient> element in the following sample XML message:
<patient pid="5555"> <name> <surname>Stone</surname> <firstname>Green</firstname> </name> <procedure>surgery</procedure> </patient>
XPATH can be used within the JavaScript filter. To extract the value from the sample XML message, the JavaScript filter can be configured as shown in the following screenshot:
The output from the JavaScript filter after it parses the sample XML message would be:
Patient 5555 is undergoing procedure: surgery
In this example, the XPATH is used as a parameter within the getField()
method. The value surgery
is extracted from within the XML message from /patient/procedure
into a variable, called proc
, which can then be used later. The value of an attribute is extracted in a similar way, except that the @
symbol is used to specify the attribute name in the path: /patient/@pid
. It is not necessary to have any XML definitions on the route for this to work.
Namespaces cannot be used in the getField()
method.
Handling Namespaces
To handle namespaces in your XML message, use E4X:
//Get the message body as E4X XML object. var msg_as_xml = next.xml; //Make the most repeating namespace as default so that we don't need to prefix every element within default namespace. //In this case make 'sci' as default namespace. default xml namespace = "http://www.show.scot.nhs.uk/isd/SCIStore"; //Another namespace in the xml doc. var ns_1 = new Namespace("du","http://www.show.scot.nhs.uk/isd/DocumentUpload"); //Yet another namespace in the xml doc. var ns_2 = new Namespace("gen", "http://www.show.scot.nhs.uk/isd/General"); //Don't have to prefix namespaces for MessageData, ClinicalData and DocumentSpecialty elements as 'sci' is declared as default namespace on line 7. var pSpecialty = msg_as_xml.MessageData.ClinicalData.DocumentSpecialty; //Using gen namespace available in varible ns_2. var pCategory = msg_as_xml.DocumentData.ns_2::DocumentCategory; //Another example using 'gen' namespace. var orgName = msg_as_xml.MessageData.PatientDemographics.ns_2::RegisteredGp.ns_2::EmployingOrganisation.ns_2::OrganisationName; //Access indexed field. var tel_2 = msg_as_xml.MessageData.PatientDemographics.ns_2::RegisteredGp.ns_2::EmployingOrganisation.ns_2::OrganisationTelecom[0].ns_2::UnstructuredTelecom; next.setProperty("pSpecialty", pSpecialty); next.setProperty("pCategory",pCategory); next.setProperty("orgName", orgName); next.setProperty("telephone2", tel_2);