Folks,
I am relatively new to HAPI.
Please help me extending HAPI for the custom Z Segment.
The message that i have is:
"MSH|^~\\&|VENDOR|LC999999|1100|LC|200501011201||ORM^O01||P|2.3\r" +
"PID|1|89300043|||PATIENT^JOHN^MIDDLE||19600505|M|||99 MAIN
STREET^^MYTOWN^NC^111119999|||||||99999999^^^05|999008888\r" +
"ZCC|A^12345678^University Medical Center~A^95857465^Dr.
Hopkins~F^3365552121^Dr. Brown~P\r"+
"IN1|1||^MR1|MEDICARE/COMERCIAL|P.O. BOX C32086^SECOND LINE OF
ADDRESS^RICHMOND^VA^232619999||||||EMPLOYER
NAME||||MC||1||||||||||||||N|||||499032980-A\r"+
"GT1|1||ODONNELL^RICHARD^W||7982 WELLINGTON
DR^^WARRENTON^VA^221869999||||||3|||||Employer Name\r"+
"DG1|1|19|54.5\r"+
"ORC|NW|L2435^LAB|||||||200501011200|||A12345^LNAME^FNAME^M^^^^U~23462^LNAME^FNAME^M^^^^L~
0123456789^LNAME^FNAME^M^^^^N~1234567890^LNAME^FNAME^MI^^^^P\r"+
"OBR|1|L2435^LAB||001479^VITAMIN
C^L|||20050101120101||||N||^SICK|||A12345^LNAME^FNAME^M^^^^U~23462^LNAME^FNAME^M
^^^^L~0123456789^LNAME^FNAME^M^^^^N~1234567890^LNAME^FNAME^MI^^^^P||
99999999999";
In this, i have one segment "ZCC".
I could successfully extend "AbstractSegment" to create this particular
segment.
But when i am trying to get the values from field(1), i don't get any
results or null results.
I then tried creating a new DataType having three fields of Type SI. But i
still had the same problem.
Can somebody throw some pointers on where i have been doing wrong.
The code that i have is:
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.AbstractSegment;
import ca.uhn.hl7v2.model.Group;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.Type;
import ca.uhn.hl7v2.model.v23.datatype.CE;
import ca.uhn.hl7v2.model.v23.datatype.SI;
import ca.uhn.hl7v2.parser.ModelClassFactory;
import com.etipl.v23.datatype.ZDT;
public class ZCC extends AbstractSegment{
/**
*
*/
private static final long serialVersionUID = -1837490858393615628L;
public ZCC(Group parent, ModelClassFactory factory) {
super(parent,factory);
Message message = getMessage();
try {
this.add(ZDT.class, true, 4, 60, new Object[]{message});
}
catch(HL7Exception hl7e) {
System.out.println("Can't instantiate");
}
}
public ZDT getDetails() {
ZDT ret = null;
try {
Type t2 = this.getField(1,0);
ret = (ZDT)ret;
} catch (ClassCastException cce) {
throw new RuntimeException(cce);
} catch (HL7Exception he) {
throw new RuntimeException(he);
}
return ret;
}
}
-------------------------------------------------
package com.etipl.v23.datatype;
import ca.uhn.hl7v2.model.AbstractType;
import ca.uhn.hl7v2.model.Composite;
import ca.uhn.hl7v2.model.DataTypeException;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.Type;
import ca.uhn.hl7v2.model.v23.datatype.ST;
public class ZDT extends AbstractType implements Composite{
private Type[] data;
public ZDT(Message message) {
super(message);
data = new Type[8];
data[0] = new ST(message);
data[1] = new ST(message);
data[2] = new ST(message);
}
public Type getComponent(int number) throws DataTypeException {
try {
return this.data[number];
} catch (ArrayIndexOutOfBoundsException e) {
throw new DataTypeException("Element " + number + " doesn't exist in 8
element XON composite");
}
}
public Type[] getComponents() {
return this.data;
}
public ST getFirstName() {
ST ret = null;
try {
ret = (ST)getComponent(0);
} catch (DataTypeException e) {
throw new RuntimeException(e);
}
return ret;
}
public ST getSecondName() {
ST ret = null;
try {
ret = (ST)getComponent(1);
} catch (DataTypeException e) {
throw new RuntimeException(e);
}
return ret;
}
public ST getThirdName() {
ST ret = null;
try {
ret = (ST)getComponent(2);
} catch (DataTypeException e) {
throw new RuntimeException(e);
}
return ret;
}
}
--------------------------------------------------
Main class:
public static void main(String args[]) {
String msg2
="MSH|^~\\&|VENDOR|LC999999|1100|LC|200501011201||ORM^O01||P|2.3\r" +
"PID|1|89300043|||PATIENT^JOHN^MIDDLE||19600505|M|||99 MAIN
STREET^^MYTOWN^NC^111119999|||||||99999999^^^05|999008888\r" +
"ZCC|A^12345678^University Medical Center~A^95857465^Dr.
Hopkins~F^3365552121^Dr. Brown~P\r"+
"IN1|1||^MR1|MEDICARE/COMERCIAL|P.O. BOX C32086^SECOND LINE OF
ADDRESS^RICHMOND^VA^232619999||||||EMPLOYER
NAME||||MC||1||||||||||||||N|||||499032980-A\r"+
"GT1|1||ODONNELL^RICHARD^W||7982 WELLINGTON
DR^^WARRENTON^VA^221869999||||||3|||||Employer Name\r"+
"DG1|1|19|54.5\r"+
"ORC|NW|L2435^LAB|||||||200501011200|||A12345^LNAME^FNAME^M^^^^U~23462^LNAME^FNAME^M^^^^L~
0123456789^LNAME^FNAME^M^^^^N~1234567890^LNAME^FNAME^MI^^^^P\r"+
"OBR|1|L2435^LAB||001479^VITAMIN
C^L|||20050101120101||||N||^SICK|||A12345^LNAME^FNAME^M^^^^U~23462^LNAME^FNAME^M
^^^^L~0123456789^LNAME^FNAME^M^^^^N~1234567890^LNAME^FNAME^MI^^^^P||
99999999999";
Parser P = new GenericParser();
Message hapiMsg;
try {
hapiMsg = P.parse(msg2);
ZCC zcc = (ZCC)hapiMsg.get("ZCC");
ZDT z= zcc.getFirst();
System.out.println(z.getFirstName().getValue());
System.out.println(z.getSecondName().getValue());
System.out.println(z.getThirdName().getValue());
}
catch(EncodingNotSupportedException ense) {
ense.printStackTrace();
}
catch(HL7Exception hl7e) {
hl7e.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
}
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel