Solved

Write the FT1 segement to another text file

Posted on 2006-11-29
15
258 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rest webservice call over https via c# 6 42
InputLanguage 1 27
C# winforms programmitically move panels 6 29
transaction in asp.net, sql server 6 33
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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