Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Generate HL7 Message

Posted on 2006-07-24
5
Medium Priority
?
578 Views
Last Modified: 2006-11-18
I'd like to create a C# program that generate the HL7 messages by rooping through the table in database.
I have two tables: Patient and lab result.

I am trying to looping through this tables and generate the HL7 message. some fields are default and some fields are comeing from the actaul table

Please see the comments

For example,

Here is the data in the tables:
PId                 lastname firstname
19191919       John        Rick

Test         Result    name
URR        79          John, rick
HGB       11.2        John, rick


and the HL 7 message should look like:

MSH|^&\~|NAPPY|||4|20060705003913||DFT^P03|0|P|2.2
EVN|P03|20060705003913||OVR
PID|||19191919||John^Rick  -- -----------> Patient Id 19191919 , and last and first name John^Rick comes from the dataabse
OBX||ST|URR^URR||79||||||R ------------>Lab value: 79 comes from the database
OBX||ST|HCT^HGB||11.2||||||R ----------------->Lab value:11.2 comes from the database
FT1||||20060601||C|ZZ^Load Lab Results^^N^N|||1|||A230||||||586.6 ----------------> A230 comes from the database
BTS|1 -------------------> count of message in file
FTS|1


what is the best way to do this? can you show me some examples?
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
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:tokabi
ID: 17170769
This is an example of something similar, I've just hacked it a bit to see if it fits your requirements:

// retrieve a datatable with all required data from database

sqlcon = new SqlConnection("server=ODIN; database=teststuff; uid=sa; pwd=????????");

string sqlcmd = "select pid, firstname, lastname, test, result, name from Patient"
      + " inner join Labresult on name = rtrim(lastname) + ', ' + rtrim(firstname)";

sqlda = new SqlDataAdapter(sqlcmd, sqlcon);
DataSet ds = new DataSet();
sqlda.Fill(ds, "Patients");
dataGrid1.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(@"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();
      
      // 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
            // (need to determine where the A230 value comes from)

            if (msgCount > 0)
            {
                  sb.Append(@"FT1||||" + curDate + @"||C|ZZ^Load Lab Results^^"
                        + @"N^N|||1|||A230||||||" + "586.6" + "\r\n");
            }

            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().Trim())
      {
            case "URR" :
                  sb.Append(@"OBX||ST|URR^URR||");
                  break;
            case "HGB" :
                  sb.Append(@"OBX||ST|HCT^HGB||");
                  break;
      }

      sb.Append(dr["result"].ToString().Trim() + @"||||||R" + "\r\n");
}

// add trailer for last patient and file trailers with patient count

sb.Append(@"FT1||||" + curDate + @"||C|ZZ^Load Lab Results^^"
      + @"N^N|||1|||A230||||||" + "586.6" + "\r\n");

sb.Append(@"BTS|" + msgCount.ToString() + "\r\n");
sb.Append(@"FTS|" + msgCount.ToString() + "\r\n");

// show generated string

textBox1.Text = sb.ToString();

It seems to work ok, but there's a few things to consider. Firstly it's setup for SQl Server, which may not be the databse you're using but that's easily fixed. Also it's assuming the records for multiple patients will be in the format:

Header
Patient Header
Patient Test
Patient Test
Patient Trailer
Patient Header
Patient Test
Patient Trailer
e.t.c.
Trailer

it will need rearranging a little if this is not the case. Finally you haven't said where the A230 value comes from. This will obviously need adding to the SQL query.
0
 

Author Comment

by:jung1975
ID: 17170948
Thank you very much.. A230 is comming from the database as well
Can I save the result to text file? result.txt instead of showing in the textbox?
0
 
LVL 5

Accepted Solution

by:
tokabi earned 2000 total points
ID: 17171263
something simple like:

System.IO.StreamWriter writer = new System.IO.StreamWriter(@"C:\result.txt",false);
writer.Write(sb.ToString());
writer.Close();

will write the output to a file, if the output is huge it will be safer to break it up into smaller blocks but for a few thousand characters it should be fine.

Is A230 a column in patients or is it another test in Lab result? or something else altogether?
0
 

Author Comment

by:jung1975
ID: 17171661
It's  comming from the patient table( unit_id).

I will try your code and let you know if I have a questions in another Q, so I can give you more points.
thank you for all your help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 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