Solved

Write the FT1 segement to another text file

Posted on 2006-11-29
15
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 30

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 30

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 30

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 30

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 30

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

751 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