When the message is parsed you will always get the appropriate model objects as returned by the current ModelClassFactory (including Validation, if/as defined for the Parser). Casting a message does not hit any HAPI code.
If you need to navigate over your message in a type/version-independent way, you need to use the generic "get" methods, like this: try { Group patientResult = (Group)oruMsg.get("PATIENT_RESULT", 0); int count = patientResult.getAll("ORDER_OBSERVATION").length; } catch (HL7Exception) { // not an ORU! } or you use the ReadOnlyMessageIterator (or one of its public factory methods), implement your own subclass of FilterIterator.Predicate to select the groups or segments with the correct names, and finally count while iterating over the result. cheers Christian Carlos Oliva-3 wrote: > > Thank you for your reply. I was looking for something like this. How > would you create the oruMsg independently of the HL7 version? > > Currently I create a message by reading an HL7 file with > ca.uhn.hl7v2.util.Hl7InputStreamMessageIterator. Would I need to cast > the message to the ORU of the appropriate version of HL7? > > If I need to cast the message to ORU, would default validation kick in? > > -----Original Message----- > From: christian ohr [mailto:christian....@icw.de] > Sent: Wednesday, November 28, 2012 4:15 AM > To: hl7api-devel@lists.sourceforge.net > Subject: Re: [HAPI-devel] Terser to get data from several ORC and OBR > segments > > > The Terser cannot be used to determine the number of repetitions of a > message element. > According to the spec, ORC and OBR may appear just once in each > ORU_R01_ORDER_OBSERVATION group. So I guess you are referring to the > number of ORU_R01_ORDER_OBSERVATION groups in the ORU message? > > Maybe you can then use something like > > int count = oruMsg.getPATIENT_RESULT(0).getORDER_OBSERVATIONReps() > > This should also be stable across hl7 versions. > > cheers > Christian > > > Carlos Oliva-3 wrote: >> >> How can the Terser obtain the total number of ORC and OBR segments in >> an ORU message? I know how to use the Terser to get values from >> elements, components, and subcomponents of individual ORC and OBR >> segments by appending the number of the segment to the name of the > segment. >> Nevertheless, before loopingover these segments, I imagine that I >> would need to know how many of these segments are in the message. >> >> Moreover, if a message has several ORC segments, how can the Terser >> traverse the ORC and its associated OBR segments? >> >> I need to use the Terser because my application receives messages in >> several versions of HL7 and casting the messages to a higher version >> often fails due to some data that fails to follow the standard. >> >> >> >> >> >> ---------------------------------------------------------------------- >> -------- Monitor your physical, virtual and cloud infrastructure from >> a single web console. Get in-depth insight into apps, servers, >> databases, vmware, SAP, cloud infrastructure, etc. Download 30-day >> Free Trial. >> Pricing starts from $795 for 25 servers or applications! >> http://p.sf.net/sfu/zoho_dev2dev_nov >> _______________________________________________ >> Hl7api-devel mailing list >> Hl7api-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/hl7api-devel >> >> > > -- > View this message in context: > http://old.nabble.com/Terser-to-get-data-from-several-ORC-and-OBR-segmen > ts-tp34723309p34731514.html > Sent from the hl7api-devel mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------ > ------ > Keep yourself connected to Go Parallel: > INSIGHTS What's next for parallel hardware, programming and related > areas? > Interviews and blogs by thought leaders keep you ahead of the curve. > http://goparallel.sourceforge.net > _______________________________________________ > Hl7api-devel mailing list > Hl7api-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/hl7api-devel > > > > > ------------------------------------------------------------------------------ > Keep yourself connected to Go Parallel: > INSIGHTS What's next for parallel hardware, programming and related areas? > Interviews and blogs by thought leaders keep you ahead of the curve. > http://goparallel.sourceforge.net > _______________________________________________ > Hl7api-devel mailing list > Hl7api-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/hl7api-devel > > -- View this message in context: http://old.nabble.com/Terser-to-get-data-from-several-ORC-and-OBR-segments-tp34723309p34737891.html Sent from the hl7api-devel mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Keep yourself connected to Go Parallel: VERIFY Test and improve your parallel project with help from experts and peers. http://goparallel.sourceforge.net _______________________________________________ Hl7api-devel mailing list Hl7api-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hl7api-devel