Solved

Write the FT1 segement to another text file

Posted on 2006-11-29
15
250 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 300 total points
Comment Utility
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
Comment Utility
thanks it doesn't give any errors,but it doesnt write anything in textbox1???
0
 

Author Comment

by:jung1975
Comment Utility
i think it;s becuase Enviroment.NewLine..... how can i fix this issue?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 200 total points
Comment Utility
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
Comment Utility
Yeah, just change to :

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

Expert Comment

by:mrichmon
Comment Utility
Use single quotes not double quotes:

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

Expert Comment

by:anarki_jimbel
Comment Utility
Yes, sorry :)
0
 

Author Comment

by:jung1975
Comment Utility
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
Comment Utility

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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now