HAPI Conformance Classes System

User Manual

HAPI Home    Table of Contents

 

 


Sample Code

 

The following system uses a compiled profile Java Archive (JAR). When creating an HL7 application, a programmer will write something like this code when he or she wants to use conformance classes.

 

/*

 * Created on Mar 16, 2003

 *

 * Example HL7 program, which uses the "Compiled Profile JAR"

 *

 */

import test.*;

import ca.uhn.hl7v2.conf.classes.exceptions.*;

/**

 * @author Shawn Dyck

 */

public class Sample_Using_Conformance_Classes {

  

   public static void main(String[] args){

    

      MsgACK msgAck = new MsgACK();

    

     try{

        System.out.println("Here is the max length for " +

                     "the Sub-Component,Identifier\n" +

                     "that is contained within the Component, "+

                     "VersionID \nthat is contained within the Field, "+

                   "VersionID \n"+

                     "that is contained within the segment MSH: "+

          msgAck.getMSH().getVersionID()

                         .getInternationalVersionID()

                         .getIdentifier()

                         .getMaxLength());

 

        System.out.println("Constant value for Identifier:" +

        msgAck.getMSH().getVersionID()

                  .getInternationalVersionID()

                  .getIdentifier().getConstantValue());

                          

         

        System.out.println("\nAbout to set the value for the Identifyer to: 555");                

        msgAck.getMSH().getVersionID()

                  .getInternationalVersionID()

                  .getIdentifier().setValue("555");             System.out.println("\nAbout to read back the value...");

       

        try {

           ca.uhn.hl7v2.parser.XMLParser xmlParser = new ca.uhn.hl7v2.parser.DefaultXMLParser();

           String ackMessageInXML = xmlParser.encode(msgAck.getHAPIMessage());

           System.out.println("Identifier: " + ackMessageInXML);

        } catch (Exception e) {

           e.printStackTrace();

           System.out.println("\nERR: " + e.toString() );

        }

       

        System.out.println("\nHere is the max length for " +

                   "the Sub-Component,AlternateText\n" +

                   "that is contained within the Component, "+

                   "VersionID \nthat is contained within the Field, "

                   "VersionID \n"+

                   "that is contained within the segment MSH: "+

        msgAck.getMSH().getVersionID()

                  .getInternationalizationCode()

                  .getAlternateText()

                  .getMaxLength());

        // will throw an exception because the length is tool long

        System.out.println("\nAbout to set the value for the AlternateText to: 5555");

        System.out.println("please note, an exception will be thrown");                

        msgAck.getMSH().getVersionID()

                  .getInternationalVersionID()

                  .getAlternateText().setValue("5555");

 

       

     }catch(ConfRepException cre){

        System.err.println("ConformanceRepException" +

             cre.toString());

     }catch(ConfDataException cde){

        System.err.println("ConformanceDataException" + cde.toString());

       }

   }

 

}

 

 

 


HAPI Home    Table of Contents