简体   繁体   English

用正则表达式解析hl7

[英]parse hl7 with regex

I have the following hl7 message: MSH|^~\\&|EPIC|SMHRMC|JCAPS|QHN|20170626165726|EDILABIH|ORU^R01^LAB|00004841|P|2.3||||||||| PID|1||W00xxxxx^^^SMHRMC||mouse^Mickey^E||19860905|F||1|2601 somestreet AVE NO 8^^City^ST^zip^USA^^^county|MESA|(970)xxx-xxxx^P^PH|||Single||175375903|xxxxxxx||last^first^^|NON-HISPANIC|||||||||| PV1|1|I|MNEU^908^A^^R^^^^^^||||9999999^pcp^pcp^LYNNE^^^^^NPI^^^^NPI~999999999^last^first^LEE^^^^^NPI^^^^NPI||||||||||00000000^last^first^LYNNE^^^^^NPI^^^^NPI||000000603|CAID||||||||||||||||||||||||20170626000000 我有以下hl7消息: MSH|^~\\&|EPIC|SMHRMC|JCAPS|QHN|20170626165726|EDILABIH|ORU^R01^LAB|00004841|P|2.3||||||||| PID|1||W00xxxxx^^^SMHRMC||mouse^Mickey^E||19860905|F||1|2601 somestreet AVE NO 8^^City^ST^zip^USA^^^county|MESA|(970)xxx-xxxx^P^PH|||Single||175375903|xxxxxxx||last^first^^|NON-HISPANIC|||||||||| PV1|1|I|MNEU^908^A^^R^^^^^^||||9999999^pcp^pcp^LYNNE^^^^^NPI^^^^NPI~999999999^last^first^LEE^^^^^NPI^^^^NPI||||||||||00000000^last^first^LYNNE^^^^^NPI^^^^NPI||000000603|CAID||||||||||||||||||||||||20170626000000 MSH|^~\\&|EPIC|SMHRMC|JCAPS|QHN|20170626165726|EDILABIH|ORU^R01^LAB|00004841|P|2.3||||||||| PID|1||W00xxxxx^^^SMHRMC||mouse^Mickey^E||19860905|F||1|2601 somestreet AVE NO 8^^City^ST^zip^USA^^^county|MESA|(970)xxx-xxxx^P^PH|||Single||175375903|xxxxxxx||last^first^^|NON-HISPANIC|||||||||| PV1|1|I|MNEU^908^A^^R^^^^^^||||9999999^pcp^pcp^LYNNE^^^^^NPI^^^^NPI~999999999^last^first^LEE^^^^^NPI^^^^NPI||||||||||00000000^last^first^LYNNE^^^^^NPI^^^^NPI||000000603|CAID||||||||||||||||||||||||20170626000000

Hl7 is hard to extract with regex however I have an field that is always in the same location and feel that might be easier. 很难用正则表达式提取HL7,但是我的字段始终位于相同的位置,因此感觉会更容易。 I need to pull the encounter number which is the 'W00xxxxx' in the stream above. 我需要在上面的流中提取遭遇号码,即“ W00xxxxx”。 It is always in the 3rd pipe delimited section of the PID and stops at the ^. 它始终位于PID的第三个管道定界部分,并在^处停止。

Currently I have: select substring(column from 'PID\\|[1]\\|\\|(.)\\^') but this is not working. 目前,我有:选择子字符串(来自“ PID \\ | [1] \\ | \\ |(。)\\ ^'的列),但这不起作用。 However when I use select substring(column from 'PV1\\|[1]\\|(.)\\|') it will pull the 'I'. 但是,当我使用select子字符串(来自'PV1 \\ | [1] \\ |(。)\\ |'的列)时,它将拉出'I'。 I can't see the big differences in my regex to know why this isn't working. 我看不到我的正则表达式有很大的不同,以了解为什么这不起作用。 Thanks. 谢谢。

这个怎么样:

PID\|[1]\|\|(.+?)\^

You can't reliably parse HL7 V2.x messages using regex because the encoding characters may change in MSH-1 and MSH-2. 您不能使用正则表达式可靠地解析HL7 V2.x消息,因为MSH-1和MSH-2中的编码字符可能会更改。 Whatever language you're using there's probably already an HL7 parsing library you can use instead. 无论您使用哪种语言,都可能已经可以使用HL7解析库了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM