Solved

Write the FT1 segement to another text file

Posted on 2006-11-29
15
259 Views
Last Modified: 2010-04-16
I have a hl7 messgae like below ( HL7.txt)

MSH|^~\&|TIME-Db|sssssss-rainsrv|FOCUS 2000|4|20061129||DFT^P03|1|P|2.2|||SU|SU|
EVN|P03|20061129||APP|
PID|1||1000179||ffff^ffff||1967889|F||A|22222 ggggg^^^CA^92666||11111111|||M|||111111111||||||||
OBX|1|ST|HGB^Hemoglobin||12.7|||||||||20061113
OBX|2||HGT||154.94|||||||||
FT1|1|||20061120|20061129|CG|CAPD^CAPD DAILY EXCHANGE (METHOD I)^^N^N|||1|0||A01||||||585.6^^||||
MSH|^~\&|TIME-Db|sssssss-rainsrv|FOCUS 2000|4|20061129||DFT^P03|2|P|2.2|||SU|SU|
EVN|P03|20061129||APP|
PID|1||1000179||DddddE^ddd||194444|F||A|222 gggg^^^CA^92666||666666666|||M|||5555555||||||||
OBX|1|ST|HGB^Hemoglobin||12.7|||||||||20061113
OBX|2||HGT||154.94|||||||||
FT1|1|||20061121|20061129|CG|CAPD^CAPD DAILY EXCHANGE (METHOD I)^^N^N|||1|0||A01||||||585.6^^||||
..
..etc

I would like to grab only the line start with FT1 and write it to another text file ( result.txt).

the result should look like below
FT1|1|||20061120|20061129|CG|CAPD^CAPD DAILY EXCHANGE (METHOD I)^^N^N|||1|0||A01||||||585.6^^||||
FT1|1|||20061121|20061129|CG|CAPD^CAPD DAILY EXCHANGE (METHOD I)^^N^N|||1|0||A01||||||585.6^^||||

How can I do this?
0
Comment
Question by:jung1975
  • 5
  • 5
  • 3
15 Comments
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 200 total points
ID: 18040618
Well if you have it in a string you can do a split on the return character

string textfile; // Load your textfile into this one
string results = "";
foreach(string line in textfile.split(Environment.NewLine))
{
if line.StartsWith("FT1")
results += line + Environment.NewLine;
}

results now contains only lines starting with FT1
0
 

Author Comment

by:jung1975
ID: 18040634
thanks...

How can I load the source text file ( it;s in c:\hl7.txt) ?

how cna I write result to the text file ( c:\result.txt)?

0
 

Author Comment

by:jung1975
ID: 18040802
If I do like below , I am getting errors:  what am i doing wrong?
Error      1      The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
Error      2      Argument '1': cannot convert from 'string' to 'char[]'      


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string textfile = @"C:\HL7.txt"; // Load your textfile into this one
         string results = "";
           foreach(string line in textfile.Split(Environment.NewLine))
        {
             if (line.StartsWith("FT1"))
                results += line + Environment.NewLine;
          }

          TextBox1.Text = results;
    }
}
-

Error      1      The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
\Error      2      Argument '1': cannot convert from 'string' to 'char[]'      
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 300 total points
ID: 18041279
You may try to pass:

Environment.NewLine.ToCharArray();

This should work.

However, I'm a bit concern about Enviroment.NewLine.

I am not 100% sure, but from my little experience with Hl7 I'd say lines are separatedby "\r" (or "\n" ?) character,
not by "\r\n" (which is Enviroment.NewLine).
New line is the last character in the entire message (messages are separated by "\r\n").
This may cause some problems later if you neglect proper separation characters.
I can't remember details however definitely had some bad experience :)
0
 

Author Comment

by:jung1975
ID: 18041345
thanks it doesn't give any errors,but it doesnt write anything in textbox1???
0
 

Author Comment

by:jung1975
ID: 18041569
i think it;s becuase Enviroment.NewLine..... how can i fix this issue?
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 200 total points
ID: 18042122
It is possible depending on the source that there is only \r or \n as mentioned by anarki_jimbel.

Try playing with different characters for the split.
0
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 300 total points
ID: 18042715
Yeah, just change to :

          textfile.split("\n")
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 18046461
Use single quotes not double quotes:

textfile.split('\n');
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 18048684
Yes, sorry :)
0
 

Author Comment

by:jung1975
ID: 18055799
I didi something like below but still no result in the textbox. it;s just blank
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string textfile = @"C:\hl7test.txt"; // Load your textfile into this one
         string results = "";
         foreach (string line in textfile.Split('\n'))
        {
            if (line.StartsWith("FT1"))
                results += line;
          }

          TextBox1.Text = results;
    }
}
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 300 total points
ID: 18064416

Did you try same with '\r' ("carriage return") character?:
foreach (string line in textfile.Split('\r'))

According to
http://publib.boulder.ibm.com/infocenter/wbihelp/v6rxmx/index.jsp?topic=/com.ibm.wbia_adapters.doc/doc/healthcare/hl7mst73.htm they use <cr> as a line delimeter.
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 18064460
Checked some more. From

http://www.microsoft.com/technet/prodtechnol/biztalk/2006/library/hl7/c92e2f70-0bfa-4bc8-8044-4a6e62cabee3.mspx?mfr=true

it follows:

"... the segment delimiter is <CR> or <CR><LF> (optional for the last segment)"

<cr> == '\r', <lf>=='\n'

Enviroment.NewLine == '\r\n'

I believe the first case is most probable..
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question