c# - HL7 text message, how to find the specific field information -


msh|^~\&|a|b|c|d|201402141402||orm^o01|33987|d|2.3 pid|1|99989392|99989392||uhcmcdo^two^^^^||19810101|m|||5678 candy cane lane^^euclid^oh^44117^united states||(212)353-6048|(212)323-6078||||99576837||||nonhispan||||||||n pv1|1|o|320|r|c||49762^abouassaly^robert||||||||||||99576837||||||||||y|||||||||||||||201402141402||||||a49417331 in1|1|43||medicaid-oh: cuyahoga county dept of children & family services|3955 euclid ave^^cleveland^oh^44115-2505||(216)431-4500|||||||||uhcmcdo^two^|s|||||1||||||||||||||123456789001|||||||m gt1|1||uhcmcdo^two^^^||5678 candy cane lane^^euclid^oh^44117|(212) 353-6048||19810101|||s orc|nw||||||||20140214140256 obr|1|36358||gc1^non gyn - cytology|r||201403281402||||||||nongync^non gyn - cytology|49762^abouassaly^robert|||||||||||^^^^^r dg1|1|i9|v70.0|routine medical exam - v70.0 obx|1|tx|pth_site1^site a|1|left||||||f||||||| obx|2|tx|pth_spec1^specimen a||c-fna^fine needle aspiration||||||f||||||| 

i have hl7 files need on pid segment patient name "uhcmcdo^two^^^^ , need traverse obr segment order id 36358 , submit database table. tired finding pid going 5th field patient name cannot.

i know how search specific value, not dynamic changing values have 100s of file , need each patient name , order id pull report. in educating here of great me.

if file format same, can use regular expressions data you're looking for.

string name = regex.match(inputstring,@"^pid([\d\|]*)\|\|(.*?)\|\|").groups[2].value; string obrid = regex.match(inputstring,@"obr\|[\d]*\|(\d*)\|").groups[1].value; 

where first looking first match between double pipes after pid, , second looking second number between pipes.

if format of files isn't consistent though, not work.

edit: here's bit of code ran @ ideone.com (http://ideone.com/0hroll) using sample "raw" string

using system; using system.text.regularexpressions;  public class test {     public static void main()     {         string raw = @""; //paste text here, new lines ,         string[] lines = raw.split(new string[] { environment.newline },  stringsplitoptions.none);          string name = "";         string obrid = "";         foreach (string line in lines)         {             if (line.contains("pid"))             {                 name = regex.match(line,@"^pid([\|]*[^\|]*){3}[\|]*([^\|]*)").groups[2].value;             }             else if (line.contains("obr"))             {                 obrid = regex.match(line,@"obr\|[\d]*\|(\d*)\|").groups[1].value;             }         }         console.writeline(name);         console.writeline(obrid);     } } 

output:

uhcmcdo^two^^^^ 36358 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -