I thought I would give your example a try, because you had mentioned ‘phantom’
DG1s, something I hadn’t seen. Well, I hadn’t used getNames before, so I was
curious.
So, yes, I did see getnames listing DG1 even when the example didn’t contain
one.
I also noticed that your example message provided earlier with have zero
entries in the List of DG1s because none of them have content in the identifier
field.
My complete code is as follows, so you can check if I made an invalid
assumption. Not I did change it somewhat.
Thanks for the opportunity to learn some more about getNames.
Printstructure is your friend. ☺
Ian
package hapiexamples;
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.v24.segment.DG1;
import ca.uhn.hl7v2.parser.CanonicalModelClassFactory;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.validation.builder.support.NoValidationBuilder;
import java.util.List;
import java.util.ArrayList;
/**
*
* @author VowlesI
*/
public class Dg1ZdgExample {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws HL7Exception {
String msg =
"MSH|^~\\&|SCM|SCM|HL7ADT||20130114001147||ADT^A08|8456356603013|P|2.3\r"
+ "PID||5012223067^^^Corporate Num|50730137^^^EAST
MRN|300000003^^^EID|Moose^Bullwinkle^J||19091011|F||1|1 Roanoke St^^New
York^NY^11111^USA^Home||(888)111-1111^^^^^888^111-1111^^Home|^^^^^^^^Cellular|ENG|W|CA|3000000039^^^EAST
MRN|111165812|11119791||Hispanic Origin \r"
+
"NK1|1|Bugs^Bee|19||(888)111-1111^^^^^888^111-1111^^Home||Emergency \r"
+ "PV1||E|ERM^^^EAST
MRN|Emergency|||N20714^Chris^Bob^Bruce~1907828742^^^^^^^^^^^^NPI|||REH||||Non-Health
Care||0||Emergency|3000000039^^^EAST
MRN|||||||||||||||||||||Clean||||20130115001000 \r"
+ "PV2||^N|ABDOMINAL PAIN NAUSEA COLD SYM
OBX|1|ST|Intolerances||None Entered||||||X \r"
+ "DG1|1||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN
DEHYDRATION NAUSE||Visit Reason\r"
+ "ZDG|1||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN
DEHYDRATION NAUSE||Visit Reason\r"
+ "DG1|2||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN
DEHYDRATION NAUSE||Visit Reason\r"
+ "ZDG|2||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN
DEHYDRATION NAUSE||Visit Reason\r"
+ "DG1|3||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN
DEHYDRATION NAUSE||Visit Reason\r"
+ "ZDG|3||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN
DEHYDRATION NAUSE||Visit Reason\r"
+ "OBX|2|ST|Allergies||See Allergy Icon/Pt Info Tab||||||X \r"
+ "AL1|1|Drug|quinolone
antibiotics^^^^23^Multum|Swelling|facial swelling ZAL||||AL|Swelling \r"
+ "AL1|2|Drug|quinolone topicals^^^^70^Multum|Swelling|facial
swelling ZAL||||AL|Swelling \r"
+ "IN1|1||BLUE|BLUE CROSS^MEDICARE|PO BOX
880031^^Boston^MA^02201||(888)111-1111^^^^^888^111-1111||||||||Medicare|Bugs^Bunny^M|18|19000928|1
Roanoke St^^New York^NY^11111^USA||||||||||||||||||||||||Male||||||1112223067
\r"
+
"IN2||475846521|DISABLED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||(888)111-1111^^Phone^^^888^111-1111|||||||DISABLED\r";
HapiContext hapiContext = new DefaultHapiContext();
hapiContext.setValidationRuleBuilder(new NoValidationBuilder());
final PipeParser pipeParser = hapiContext.getPipeParser();
final Message hapiMessage = pipeParser.parse(msg);
System.out.println("hapiMsg.printStructure() = " +
hapiMessage.printStructure());
String names[] = hapiMessage.getNames();
List<DG1> dg1List = new ArrayList<DG1>();
for (String name : names) {
System.out.println("Segment Name = " + name);
if (name.startsWith("DG1")) {
DG1 dg = (DG1) hapiMessage.get(name);
if (dg != null &&
dg.getDg13_DiagnosisCodeDG1().getCe1_Identifier().getValue() != null) {
dg1List.add(dg);
}
}
}
System.out.println(dg1List.size());
}
}
From: Singh, Brijesh [mailto:sin...@advisory.com]
Sent: Wednesday, 12 November 2014 1:46 PM
To: James Agnew
Cc: hl7api-devel@lists.sourceforge.net
Subject: Re: [HAPI-devel] DG1 segments repetition.
James – Thanks so much for a quick response. I followed your suggestion and
added the code by calling getNames() as described below. I found that HAPI is
creating a phantom DG1 segment even when the Hl7 message does not have any DG1,
for that reason I’m doing an extra logic in the highlighted text below. Is it
intended behavior? If yes, what is the best way of handling it?
String Names[] = Msg.getNames();
List<DG1> LDGs = new ArrayList<DG1>();
for(String Name: Names){
if(Name == null || Name.startsWith("DG1") == false)
continue;
DG1 DG = (DG1)Msg.get(Name);
if(DG !=null &&
dg.getDiagnosisCodeDG1().getIdentifier().getValue()) !=null )
LDGs.add(DG);
}
Regards,
Brijesh
From: James Agnew [mailto:jamesag...@gmail.com]
Sent: Tuesday, November 11, 2014 6:15 PM
To: Singh, Brijesh
Cc:
hl7api-devel@lists.sourceforge.net<mailto:hl7api-devel@lists.sourceforge.net>
Subject: Re: [HAPI-devel] DG1 segments repetition.
Hi Brijesh,
You're right, the custom segments are causing an issue since the parser csn't
see subsequent DG1 repetitions as actual repetitions.
The easiest way to do this would be to call
MessageInstance.getAll("DG1")
followed by
MessageInstance.getAll("DG12")
followed by
MessageInstance.getAll("DG13")
etc.. Basically HAPI creates nonstandard segments for each of the following
DG1s by adding a sequential number to the end.
If you wanted to be more fancy, you could create a custom structure that has a
group containing the custom segment as well, or you could override the parser
and use string maniulation to remove the Z-segments before parsing.. But the
method above is definitely the least work.
Incidentally MessageInstance.getNames() will give you the names of all the
segments (including the "DG1[number]" ones) so you will know how many there are.
Cheers,
James
On Tue, Nov 11, 2014 at 2:06 PM, Singh, Brijesh
<sin...@advisory.com<mailto:sin...@advisory.com>> wrote:
Hi – I’m using HAPI library(2.2) to parse the below message and calling the
method getAll(“DG1”) ( Structure[] Structs = MessageInstance.getAll(“DG1”) ) to
retrieve the DG1 segments. I’m having issues getting all DG1 segments. From the
below message, able to retrieve only one DG1 segment. Looks like the custom
segment (ZDG) is in the middle of repeating DG1 segments and breaking the
repetition.
Can you please suggest if I can use other API methods to retrieve all DG1 ( 3
in the below case) ignoring ZDG segments?
Thanks for your help.
MSH|^~\&|SCM|SCM|HL7ADT||20130114001147||ADT^A08|8456356603013|P|2.3
PID||5012223067<tel:5012223067>^^^Corporate Num|50730137^^^EAST
MRN|300000003^^^EID|Moose^Bullwinkle^J||19091011|F||1|1 Roanoke St^^New
York^NY^11111^USA^Home||(888)111-1111^^^^^888^111-1111^^Home|^^^^^^^^Cellular|ENG|W|CA|3000000039^^^EAST
MRN|111165812|11119791||Hispanic Origin
NK1|1|Bugs^Bee|19||(888)111-1111^^^^^888^111-1111^^Home||Emergency
PV1||E|ERM^^^EAST
MRN|Emergency|||N20714^Chris^Bob^Bruce~1907828742^^^^^^^^^^^^NPI|||REH||||Non-Health
Care||0||Emergency|3000000039^^^EAST
MRN|||||||||||||||||||||Clean||||20130115001000
PV2||^N|ABDOMINAL PAIN NAUSEA COLD SYM OBX|1|ST|Intolerances||None
Entered||||||X
DG1|1||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN DEHYDRATION NAUSE||Visit
Reason
ZDG|1||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN DEHYDRATION NAUSE||Visit
Reason
DG1|2||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN DEHYDRATION NAUSE||Visit
Reason
ZDG|2||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN DEHYDRATION NAUSE||Visit
Reason
DG1|3||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN DEHYDRATION NAUSE||Visit
Reason
ZDG|3||^CHEST PAIN DEHYDRATION NAUSE|CHEST PAIN DEHYDRATION NAUSE||Visit
Reason
OBX|2|ST|Allergies||See Allergy Icon/Pt Info Tab||||||X
AL1|1|Drug|quinolone antibiotics^^^^23^Multum|Swelling|facial swelling
ZAL||||AL|Swelling
AL1|2|Drug|quinolone topicals^^^^70^Multum|Swelling|facial swelling
ZAL||||AL|Swelling
IN1|1||BLUE|BLUE CROSS^MEDICARE|PO BOX
880031^^Boston^MA^02201||(888)111-1111^^^^^888^111-1111||||||||Medicare|Bugs^Bunny^M|18|19000928|1
Roanoke St^^New York^NY^11111^USA||||||||||||||||||||||||Male||||||1112223067
IN2||475846521|DISABLED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||(888)111-1111^^Phone^^^888^111-1111|||||||DISABLED
Regards,
Brijesh Singh
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net<mailto:Hl7api-devel@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/hl7api-devel
********************************************************************************
This email, including any attachments sent with it, is confidential and for the
sole use of the intended recipient(s). This confidentiality is not waived or
lost, if you receive it and you are not the intended recipient(s), or if it is
transmitted/received in error.
Any unauthorised use, alteration, disclosure, distribution or review of this
email is strictly prohibited. The information contained in this email,
including any attachment sent with it, may be subject to a statutory duty of
confidentiality if it relates to health service matters.
If you are not the intended recipient(s), or if you have received this email in
error, you are asked to immediately notify the sender by telephone collect on
Australia +61 1800 198 175 or by return email. You should also delete this
email, and any copies, from your computer system network and destroy any hard
copies produced.
If not an intended recipient of this email, you must not copy, distribute or
take any action(s) that relies on it; any form of disclosure, modification,
distribution and/or publication of this email is also prohibited.
Although Queensland Health takes all reasonable steps to ensure this email does
not contain malicious software, Queensland Health does not accept
responsibility for the consequences if any person's computer inadvertently
suffers any disruption to services, loss of information, harm or is infected
with a virus, other malicious computer programme or code that may occur as a
consequence of receiving this email.
Unless stated otherwise, this email represents only the views of the sender and
not the views of the Queensland Government.
**********************************************************************************
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel