Customizing a Healthcare: HL7 to reports pattern instance

This topic contains the following sections:

Writing reports
Customization subflows

Writing reports

You can use the PHP scripting language for text based report generation. The pattern creates an example PHP report template called ADT_A01.php. Create additional PHP scripts to generate reports for other HL7 message types.

Support for the PHP scripting language is available on all operating systems on which IBM Integration Bus is supported. A wide set of PHP functions are available for report generation. These functions include accessing named elements in the HL7 message.

For information about the PHP functions supported by IBM Integration Bus, see "PHP extensions" in the IBM Integration Bus documentation.

For more information about the PHP scripting language, see the PHP: Hypertext Preprocessor web site.

The PHP examples in this topic use the following HL7 ADT A01 message:

MSH|^~\&|ADT1|MCM|LABADT|MCM|198808181126|SECURITY|ADT^A01^ADT_A01|MSG00001-
|P|
2.5
EVN|A01|198808181123
PID|1||PATID1234^5^M11^ADT1^MR^MCM~123456789^^^USSSA^SS||JONES^WILLIAM^A^III
NK1|1|JONES^BARBARA^K|WI^WIFE||||NK^NEXT OF KIN
NK1|2|JONES^MARK^K|SO^SON||||NK^NEXT OF KIN
NK1|3|JONES^SOPHIE^K|DA^DAUGHTER||||NK^NEXT OF KIN
PV1|1|I|2000^2012^01||||004777^LEBAUER^SIDNEY^J.|||SUR||||ADM|A0
    

You customize the pattern instance by adding PHP markup to report generation templates (scripts). PHP scripts often require access to data in the HL7 messages. Data in messages is accessed using a path syntax. There are two ways to work out the path to elements and fields in HL7 messages. The first approach is to use the debugger, the second approach is to use the HL7v25P message set.

Calculating paths using the debugger

The first way to calculate a path is by looking at real HL7 messages as they flow through your integration node. Set a breakpoint in the Processor message flow and send an HL7 message to your integration node:

A diagram showing a breakpoint in the Processor message flow

The following screen shot shows an HL7 message in the Variables view in the IBM Integration Toolkit:

A diagram showing the Variables view in the IBM Integration Toolkit

The path to the highlighted element in the screenshot is $input_assembly->XMLNSC->HL7->PID->{'PID.3.PatientIdentifierList'}->{'CX.1'}. Paths in the HL7v25P message set include period characters (for example PID.3.PatientIdentifierList) and so must be surrounded by parenthesis so that the PHP runtime interprets them correctly.

HL7 messages are always presented to your report scripts in the XMLNSC message domain.

Calculating paths using the HL7v25P message set

The second approach to calculate paths is to inspect the HL7v25P message set and work out the paths to elements and fields based on the message model:

A diagram showing a section of the HL7v25P message set

The paths are the same in both approaches, the only difference is whether you start from actual HL7 messages or from the HL7 message model.

The rightmost two columns in the message set screen shot show the minimum and maximum number of times that an element or field can occur in an HL7 message. Your PHP scripts must take into account whether an element or field must be present (values 1 and 1), may be present (values 0 and 1), may repeat (values 0 and -1) or will repeat at least once (values 1 and -1). All of these possibilities are common in HL7 messages.

Example PHP Code

The following code examples show you how to implement common tasks in PHP scripts.

Built-in PHP functions

A wide range of built-in functions are available to your PHP scripts.

    <?php
        date_default_timezone_set('UTC');
        echo date('n/j/Y');
    ?>
    

This snippet produces the following output in the report:

    12/9/2011
    

For information about the PHP functions supported by IBM Integration Bus, see "PHP extensions" in the IBM Integration Bus documentation (the PHP runtime in IBM Integration Bus supports a subset of the extensions implemented by the open source PHP implementation).

Environment variables

Environment variables are accessed through the PHP $_ENV super global variable.

    <?php
        echo $_ENV['MB_WORK_PATH'].'\n';
        echo $_ENV['MB_BROKER_NAME'].'\n';
        echo $_ENV['MB_EXECUTION_GROUP_NAME'].'\n';
        echo $_ENV['MB_NODE_NAME'].'\n';
        echo $_ENV['MB_MESSAGE_FLOW_NAME'].'\n';
    ?>
    

This snippet produces the following output in the report:

    C:\Documents and Settings\All Users\Application Data\IBM\MQSI
    HEALTHCARE
    Healthcare
    PHP Compute
    healthcare.ReportProcessor
    

Message data

Elements and fields in HL7 messages can be accessed using paths.

    <?php
        echo $input_assembly->XMLNSC->HL7->MSH->{'MSH.9.MessageType'}->{'MSG.1'};
    ?>
    

This snippet produces the following output in the report:

    ADT
    

Checking for missing data

PHP provides the is_null function to check whether an element or field is missing.

    <?php
        $result = is_null($input_assembly->XMLNSC->HL7->XYZ);
        echo var_dump($result);
    ?>
    

This snippet produces the following output in the report:

    bool(true)
    

Repeating elements

Repeating elements can be iterated over using the PHP foreach statement.

    <?php
        foreach ($input_assembly->XMLNSC->HL7->NK1 as $kin) {
            echo var_dump($kin);
        }
    ?>
    

This snippet produces the following output in the report:

    object(MbsElement)#26 (4) {
      ["NK1.1.SetIDNK1"]=>
      string(1) "1"
      ["NK1.2.Name"]=>
      NULL
      ["NK1.3.Relationship"]=>
      NULL
      ["NK1.7.ContactRole"]=>
      NULL
    }
    object(MbsElement)#27 (4) {
      ["NK1.1.SetIDNK1"]=>
      string(1) "2"
      ["NK1.2.Name"]=>
      NULL
      ["NK1.3.Relationship"]=>
      NULL
      ["NK1.7.ContactRole"]=>
      NULL
    }
    object(MbsElement)#28 (4) {
      ["NK1.1.SetIDNK1"]=>
      string(1) "3"
      ["NK1.2.Name"]=>
      NULL
      ["NK1.3.Relationship"]=>
      NULL
      ["NK1.7.ContactRole"]=>
      NULL
    }
    

The NULL values in the output from var_dump are expected even though there is data in those elements.

Elements and fields in HL7 messages can be accessed in repeating elements using the foreach variable:

    <?php
        foreach ($input_assembly->XMLNSC->HL7->NK1 as $kin) {
            echo var_dump($kin->{'NK1.2.Name'}->{'XPN.2'});
        }
    ?>
    

This snippet produces the following output in the report:

    string(7) "BARBARA"
    string(4) "MARK"
    string(6) "SOPHIE"
    

Customization subflows

Six main customization subflows are available to users of the pattern.

Receiver customization

The Receiver message flow calls the OnReceive subflow when an HL7 message has been received and validated.

The default OnReceive subflow has no effect on the message, but you can use this customization point to standardize data from the source to meet your requirements. For example, you might have a standard for dates in the format YYYY-MM-DD , but the source uses a different date format. You can use this customization point to modify any source data. Additionally, you might choose to include data at this point that is available from other sources, such as databases.

Processor customization

The OnProcess customization subflow called before the report is generated. By default this subflow has no effect on the message, but you can use this subflow to build an input message that matches the specifications required by your reports.

ACK and NACK customization

The OnSendACK and OnSendNACK subflows are invoked before acknowledgment messages are generated. By default these subflows have no effect on the message, but you can use these subflows to build an acknowledgment message that matches the specifications required by your source application.

Error customization

The OnErrorQueue is called when an error has been detected and an error message is written to the error queue. The default customization subflow has no effect on the message, but you can use this subflow to build an error message that matches the specifications required by your source environment.

No match customization

The Processor flow executes a PHP script called Processor.php. This PHP script determines the name of a PHP script which will generate the report for this message. The name of the PHP script uses the HL7 message event and code. For example ADT_A01.php if the HL7 message is an (ADT^A01) patient admitted message. If the PHP script is not found then the OnNoMatch subflow is called. By default this subflow has no effect on the message, but you can use this subflow to process messages which have not generated a report.

File finished customization

The OnFileFinished subflow is called when the report file has been completed and copied to the output directory. By default this subflow has no effect on the message, but you can use this subflow to extend the file finished processing. After the report has been finished, a new report file is created by the FileOutput node and that is used for subsequent generated reports.

Back to the Healthcare: HL7 to reports pattern specification