Examples

This example prints the content of the message that is passed in to standard output. It then creates a new message, and returns a disposition list. Then, it instructs the engine to process the new message and stop the one which was passed in.

package sample;
import com.healthvision.CLOVERLEAF.upoc.*;

public class MyTPS extends TPS
{

        public DispositionList process (
                CloverEnv cloverEnv, 
                String context, 
                String mode, 
                Message msg)
                throws CLOVERLEAFException
        {
        DispositionList dispList = new DispositionList();
        if (msg == null)
        return dispList;

        System.out.println(msg.getContent());

        dispList.add(DispositionList.CONTINUE, 							
        cloverEnv.makeMessage("New message from MyTPS"));
        dispList.add(DispositionList.KILL, msg);
        return dispList;
        }
}

This example calls a hypothetical external class method that incorporates a business logic rule, passing the message content string. It stores the returned value in userData metadata . Then, it returns a disposition list instructing the engine to continue processing the message.

package sample;
import com.healthvision.CLOVERLEAF.upoc.*;
// Business logic is defined in a separate package
import hypothetical.businesslogic.stuff.BusinessRule;

public class SetTrxidTPS extends TPS
{

        public DispositionList process (
                CloverEnv cloverEnv,
                String context,
                String mode,
                Message msg)
                throws CLOVERLEAFException
        {
        DispositionList dispList = new DispositionList();
        if (msg == null)
        return dispList;

        PropertyTree userData = msg.getUserdata();

        // obtain a transaction routing code from the Business
        // Logic package using a hypothetical static method
        userData.put("TRXID",BusinessRule.getTrxid(msg.getContent()));
        msg.setUserdata(userData);

        dispList.add(DispositionList.CONTINUE,msg);
        return dispList;
        }
}

This example uses a Fixed Record Layout Manager, frlM (a subclass of Grm) to create a new message based on the one passed in. Then, it changes and adds some fields. This instructs the engine to process both the new message and the original.

package sample;
import java.util.*;
import com.healthvision.CLOVERLEAF.upoc.*;

public class GrmSampleTPS extends TPS
{
        public DispositionList process(CloverEnv cloverEnv, \
                String context, String mode, Message msg)
        throws CLOVERLEAFException
        {
        DispositionList dispList = new DispositionList();
        if (msg == null)
        return dispList;

        System.out.println(msg.getContent());
        FrlM frlM = msg.makeFrlM("SomeFrl.frl");

        // See what's in field1 now
        Vector f1Vector = frlM.getStrings("Field1");
        Enumeration e = f1Vector.elements();
        while (e.hasMoreElements())
        System.out.println(e.nextElement());

        // Now change field called Field2 using a String value
        frlM.setString("Field2", "hello from Java");

        // Now change a field called Field3, using
        // a String to set its first subfield
        // and an Integer to set its second subfield 
        Vector v = new Vector();
        v.addElement("a value for sf1");
        v.addElement(new Integer(123));
        frlM.setObjects("Field3", v);

        dispList.add(DispositionList.CONTINUE,
        frlM.makeMessage());
        dispList.add(DispositionList.CONTINUE, msg);
        frlM.destroy();
        return dispList;
        }
}

This example uses a Grm to create a new Edifact message that is based on the message passed in. It prints field contents of the message that is passed in to standard output. It also modifies some field contents. Then, it returns a disposition list instructing the engine to process the new message and stop the original message.

/*
 * $Id:$
 * Infor
 */
import com.healthvision.CLOVERLEAF.upoc.*;
public class EdfTPS extends TPS

        /**
        * standard TPS constructors
        */
        public EdfTPS(CloverEnv cloverEnv, PropertyTree xArgs) {
        super(cloverEnv, xArgs);
        }

        public EdfTPS() { }
        /***  process a TPS*/
        public DispositionList process(CloverEnv cloverEnv, \
                String context, String mode, Message msg)
        throws CLOVERLEAFException {

        DispositionList dl = new DispositionList();
        /*** If there is no message then just return*/
        if (msg == null) return dl;

        /*Create an Edifact message */
        EdifactM grm = msg.makeEdifactM("97B",null,"MEDRPT");

        *To extract message field content with no subfield*/
        String x = grm.getString("2(0).2(0).0(0).FCA(0).1#4471(0).[0].[0]");

        /* To extract message field content with subfield */
        Vector v = grm.getStrings("2(0).3(0).0(0).PNA(0).6#C816" ); 

        /* Print it out to the log file */        
        System.out.println(x.toString());
        for (Enumeration e = v.elements(); e.hasMoreElements();) {
        System.out.print("["+e.nextElement().toString()+"] ");

        }

        Vector setValue = new Vector();
        setValue.addElement(new String("ZZZZ"));
        setValue.addElement(new String("XXXXXX,XXXXXXXX"));

        /*Call method setString and setStrings to modify message fields constant*/
        grm.setString("2(0).2(0).0(0).FCA(0).1#4471(0).[0].[0]","TTTTTT");
        grm.setStrings("2(0).3(0).0(0).PNA(0).6#C816",setValue);
        grm.setString("2(0).3(0).0(0).DTM(0).1#C507(0).[1]","YYYYYYYYYY");
        grm.setString("2(0).3(0).3(0).0(0).RFF(0).1#C506(0).[1].[0]", \
                "UUUUUUUUUU");

        //test Grm.makMessage method
        Message outMsg = grm.makeMessage();

        //retire the original message
        dl.add( DispositionList.KILL, msg );

        //Continue with a new message
        dl.add( DispositionList.CONTINUE, outMsg);

        return dl;

        }
}

This example uses a Grm to create a new X12 message that is based on the one passed in. It prints field contents of the message that is passed in to standard output. It also modifies some field contents. Then, it returns a disposition list instructing the engine to process the new message and stop the original message.

/*
 * $Id:$
 * Infor
 */
import com.healthvision.CLOVERLEAF.upoc.*;
public class X12TPS extends TPS
        /**
        * standard TPS constructors
        */

        public X12TPS(CloverEnv cloverEnv, PropertyTree xArgs) {
        super(cloverEnv, xArgs);
        }

        public X12TPS() { }
        /***  process a TPS*/
        public DispositionList process(CloverEnv cloverEnv, String context, \
                String mode, Message msg)
        throws CLOVERLEAFException {

        DispositionList dl = new DispositionList();
        /*** If there is no message then just return*/
        if (msg == null) return dl;
        /*Create an X12 message */
        X12M grm = msg.makeX12M("004010",null,"270" );

        /* To extract message field content with no subfield*/
        String x = grm.getString("1(0).1(0).0(0).NM1(0).3#1035");

        /* To extract message field content with subfield */
        Vector v = grm.getStrings("1(0).1(0).0(0).PRV(0).3#127(0)" ); 

        /* Print it out to the log file */
        System.out.println(x.toString());
        for (Enumeration e = v.elements(); e.hasMoreElements();) {
        System.out.print("["+e.nextElement().toString()+"] ");

        }

        /* call method setString and setStrings to modify the field content */

        Vector setValue = new Vector(1);
        setValue.addElement(new String("Infor X12 \
               Upoc Testing"));grm.setStrings("1(0).1(0).0(0).NM1(0).3#1035", \
               setValue);grm.setString("1(0).1(0).0(0).PRV(0).3#127(0)","000000000");

        /*Create another message*/
        Message outMsg = grm.makeMessage();

        //retire the original message
        dl.add( DispositionList.KILL, msg );

        //Continue with a new message
        dl.add( DispositionList.CONTINUE, outMsg);
        return dl;
        }

}

This example uses a Grm to create a new HL7 message that is based on the one passed in. It prints field contents of the message that is passed in to standard output. It also modifies some field contents. Thenk it returns a disposition list instructing the engine to process the new message and stop the original message.

/*
 * $Id:$
 * Infor
 */
import com.healthvision.CLOVERLEAF.upoc.*;
public class Hl7TPS extends TPS
        /**
        * standard TPS constructors
        */

        public Hl7TPS(CloverEnv cloverEnv, PropertyTree xArgs) \
                {super(cloverEnv, xArgs);
        }

        public Hl7TPS() { }
        /***  process a TPS*/
        public DispositionList process(CloverEnv cloverEnv, \
                String context, String mode, Message msg)
        throws CLOVERLEAFException {

        DispositionList dl = new DispositionList();
        /*** If there is no message then just return*/
        if (msg == null) return dl;

        /*Create an Hl7 message */
        Hl7M grm = msg.makeX12M("004010",null,"270" );

        /* To extract message field content with no subfield*/
        String x = grm.getString("1(0).1(0).0(0).OBR.00238","00000");

        /* To extract message field content with subfield */
        Vector v = grm.getStrings("1(0).1(4).1(1).OBX(0).00573"); 

        /* Print it out to the log file */        
        System.out.println(x.toString());
        for (Enumeration e = v.elements(); e.hasMoreElements();) {
        System.out.print("["+e.nextElement().toString()+"] ");
        }        

        /* call method setString and setStrings to modify the field content */

        Vector setValue = new Vector(3);
        setValue.addElement(new String("3333333333"));
        setValue.addElement(new String("4"));
        setValue.addElement(new String("Infor"));

        grm.setString("1(0).1(0).0(0).OBR.00238","00000");
        grm.setStrings("1(0).0(0).0(0).PID.00106(0)",setValue);

        /*Create another message*/
        Message outMsg = grm.makeMessage();

        //retire the original message
        dl.add( DispositionList.KILL, msg );

        //Continue with a new message
        dl.add( DispositionList.CONTINUE, outMsg);

        return dl;

        }
}