jung1975
asked on
HL7 message
I've used following code to generate HL7 message
{
// show generated string
// retrieve a datatable with all required data from database
SqlConnection sqlcon = new SqlConnection("server=test ; database=Lab; uid=sa; pwd=sa");
string sqlcmd = "select (substring(clinic,4,1) + substring(clinic,2,2) )as clinic,[External Code] as pid, firstname, lastname, test, result from Patients a inner join Lab_result b on a.[external code] = b.MRN order by PID, draw_date";
SqlDataAdapter sqlda = new SqlDataAdapter(sqlcmd, sqlcon);
DataSet ds = new DataSet();
sqlda.Fill(ds, "Patients");
GridView1.DataSource = ds;
DataTable dt = ds.Tables["Patients"];
// need to add code to set date in correct format
string curDate = "20060705003913";
string oldPID = "";
int msgCount = 0;
System.Text.StringBuilder sb = new System.Text.StringBuilder( );
// build file headers
sb.Append(@"FHS|^&\~|4||hh h ver. 3.4.05|4|20060705003912" + "\r\n");
sb.Append(@"BHS|^&\~|4||hh h ver. 3.4.05|4|20060705003912||| |200600750 03912" + "\r\n");
sb.Append(@"MSH|^&\~|NAPPY |||4|" + curDate + @"||DFT^P03|0|P|2.2" + "\r\n");
sb.Append(@"EVN|P03|" + curDate + @"||OVR" + "\r\n");
foreach (DataRow dr in dt.Rows)
{
string PID = dr["pid"].ToString();
string clinic = dr["clinic"].ToString();
// if this is a different patient than the last one, we need a patient header
if (PID != oldPID)
{
if (msgCount != 0)
{
sb.Append(@"FT1||||" + curDate + @"||C|ZZ^Load Lab Results^^"
+ @"N^N|||1|||" + clinic+"||||||" + "586.6" + "\r\n");
}
// and if its not the first patient we need a patient trailer record
// (need to determine where the A230 value comes from)
sb.Append(@"PID|||" + PID + @"||" + dr["lastname"].ToString(). Trim()
+ @"^" + dr["firstname"].ToString() .Trim() + "\r\n");
msgCount++;
oldPID = PID;
}
// determine which test it is (could just substitiue test name from
// database if that's appropriate
switch (dr["test"].ToString().Tri m())
{
case "%URR":
sb.Append(@"OBX||ST|URR^UR R||");
break;
case "HGB":
sb.Append(@"OBX||ST|HCT^HG B||");
break;
}
sb.Append(dr["result"].ToS tring().Tr im() + @"||||||R" + "\r\n");
}
// add trailer for last patient and file trailers with patient count
sb.Append(@"BTS|" + msgCount.ToString() + "\r\n");
sb.Append(@"FTS|1" + "\r\n");
TextBox1.Text = sb.ToString();
}
How can I repeat the message header every time there is a new PID
MSH
EVN
~~
also, FT1 is not write in the last PID not sure why??
In the last PID
PID
OBX||ST|URR^URR||54.0||||| |R
OBX||ST|HCT^HGB||12.8||||| |R
~~noFT1 here
BTS|1123
FTS|1
and how can I binding the clinicID into clinc field in FT1 line?
the output should looks like
FHS
BHS
MSH
EVN
PID
OBX
OBX
OBX
FT1
MSH
EVN
PID
OBX
OBX
OBX
FT1
---
etc
BTS|1123
FTS|1
{
// show generated string
// retrieve a datatable with all required data from database
SqlConnection sqlcon = new SqlConnection("server=test
string sqlcmd = "select (substring(clinic,4,1) + substring(clinic,2,2) )as clinic,[External Code] as pid, firstname, lastname, test, result from Patients a inner join Lab_result b on a.[external code] = b.MRN order by PID, draw_date";
SqlDataAdapter sqlda = new SqlDataAdapter(sqlcmd, sqlcon);
DataSet ds = new DataSet();
sqlda.Fill(ds, "Patients");
GridView1.DataSource = ds;
DataTable dt = ds.Tables["Patients"];
// need to add code to set date in correct format
string curDate = "20060705003913";
string oldPID = "";
int msgCount = 0;
System.Text.StringBuilder sb = new System.Text.StringBuilder(
// build file headers
sb.Append(@"FHS|^&\~|4||hh
sb.Append(@"BHS|^&\~|4||hh
sb.Append(@"MSH|^&\~|NAPPY
sb.Append(@"EVN|P03|" + curDate + @"||OVR" + "\r\n");
foreach (DataRow dr in dt.Rows)
{
string PID = dr["pid"].ToString();
string clinic = dr["clinic"].ToString();
// if this is a different patient than the last one, we need a patient header
if (PID != oldPID)
{
if (msgCount != 0)
{
sb.Append(@"FT1||||" + curDate + @"||C|ZZ^Load Lab Results^^"
+ @"N^N|||1|||" + clinic+"||||||" + "586.6" + "\r\n");
}
// and if its not the first patient we need a patient trailer record
// (need to determine where the A230 value comes from)
sb.Append(@"PID|||" + PID + @"||" + dr["lastname"].ToString().
+ @"^" + dr["firstname"].ToString()
msgCount++;
oldPID = PID;
}
// determine which test it is (could just substitiue test name from
// database if that's appropriate
switch (dr["test"].ToString().Tri
{
case "%URR":
sb.Append(@"OBX||ST|URR^UR
break;
case "HGB":
sb.Append(@"OBX||ST|HCT^HG
break;
}
sb.Append(dr["result"].ToS
}
// add trailer for last patient and file trailers with patient count
sb.Append(@"BTS|" + msgCount.ToString() + "\r\n");
sb.Append(@"FTS|1" + "\r\n");
TextBox1.Text = sb.ToString();
}
How can I repeat the message header every time there is a new PID
MSH
EVN
~~
also, FT1 is not write in the last PID not sure why??
In the last PID
PID
OBX||ST|URR^URR||54.0|||||
OBX||ST|HCT^HGB||12.8|||||
~~noFT1 here
BTS|1123
FTS|1
and how can I binding the clinicID into clinc field in FT1 line?
the output should looks like
FHS
BHS
MSH
EVN
PID
OBX
OBX
OBX
FT1
MSH
EVN
PID
OBX
OBX
OBX
FT1
---
etc
BTS|1123
FTS|1
ASKER
Hi! tokabi,
Actually I fogot to mention about the Lab_date. The query has to be group by pid and labdate
clinic pid labdate test result
B76 1000006195 06/12/06 John doe %URR 70.5
B76 1000006195 06/12/06 John doe HGB 11.3
B76 1000006195 06/26/06 John doe HGB 11.9
,so there is more than one lab test like above , it has to write another message for 06/26/06 lab date
MSH
EVN
PID
OBX %UPR
OBX HGB
FT1
MSH
EVN
OBX HGB
FT1
..
..
Alo, I would like to write the incremental number between OBX||ST
, so if there are two OBX,
OBX|1|ST
OBX|2|ST
..
and
I'd like to put the labdate next to FT1 segment
so, it looks FT1||||20060612||
How can I do this?
Actually I fogot to mention about the Lab_date. The query has to be group by pid and labdate
clinic pid labdate test result
B76 1000006195 06/12/06 John doe %URR 70.5
B76 1000006195 06/12/06 John doe HGB 11.3
B76 1000006195 06/26/06 John doe HGB 11.9
,so there is more than one lab test like above , it has to write another message for 06/26/06 lab date
MSH
EVN
PID
OBX %UPR
OBX HGB
FT1
MSH
EVN
OBX HGB
FT1
..
..
Alo, I would like to write the incremental number between OBX||ST
, so if there are two OBX,
OBX|1|ST
OBX|2|ST
..
and
I'd like to put the labdate next to FT1 segment
so, it looks FT1||||20060612||
How can I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks, i will try it and let you know if i have a question..
ASKER
tokabi,
the output returns slightly different result than it supposed be..
I put the question on here
https://www.experts-exchange.com/questions/21931822/HL7-message.html
the output returns slightly different result than it supposed be..
I put the question on here
https://www.experts-exchange.com/questions/21931822/HL7-message.html
for (int i = 0; i < dt.Rows.Count; i++)
{
string PID = dt.Rows[i]["pid"].ToString
// if this is a different patient than the last one, we need a patient header
if (PID != oldPID)
{
// and if its not the first patient we need a patient trailer record
if (msgCount != 0)
{
sb.Append(@"FT1||||" + curDate + @"||C|ZZ^Load Lab Results^^"
+ @"N^N|||1|||" + dt.Rows[i-1]["clinic"] + "||||||"
+ dt.Rows[i-1]["unit_id"] + "\r\n");
}
// add patient headers
sb.Append(@"MSH|^&\~|NAPPY
sb.Append(@"EVN|P03|" + curDate + @"||OVR" + "\r\n");
sb.Append(@"PID|||" + PID + @"||" + dt.Rows[i]["lastname"].ToS
+ @"^" + dt.Rows[i]["firstname"].To
msgCount++;
oldPID = PID;
}
// determine which test it is (could just substitiue test name from
// database if that's appropriate
switch (dt.Rows[i]["test"].ToStri
{
case "%URR":
sb.Append(@"OBX||ST|URR^UR
break;
case "HGB":
sb.Append(@"OBX||ST|HCT^HG
break;
}
sb.Append(dt.Rows[i]["resu
// add trailer for last patient
if (i == dt.Rows.Count - 1)
{
sb.Append(@"FT1||||" + curDate + @"||C|ZZ^Load Lab Results^^"
+ @"N^N|||1|||" + dt.Rows[i]["clinic"] + "||||||"
+ dt.Rows[i]["unit_id"] + "\r\n");
}
}