I am working in ASP.NET with C#. I have a text file which contains datas
with delimiters. For example:-
MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939|
I also have an XML file created with predefined tags. Some of the tags
contain child element. I need to pass the data from the text file i.e the
value within the delimiters should be passed to the corresponding tags within
the XML file. I have done this through hard code. But i need it to be
dynamic. There are also possibilities to add or delete tags from the XML file
which should not affect the code. I have created the XML using Dataset. So
the addition or deletion of tags can be done through dataset without
affecting the code.
This the XMl file
<?xml version="1.0" standalone="yes"?>
<Dataset1 xmlns="http://tempuri.org/Dataset1.xsd">
<MSH>
<FieldSeparator>|</FieldSeparator>
<EncodingCharacters>^~\$</EncodingCharacters>
<DateTimeOfMessage>200502110938</DateTimeOfMessage>
<Security />
<MessageControlID>00860</MessageControlID>
<SequenceNumber />
<ContinuationPointer />
<AcceptAcknowledgmentType />
<ApplicationAcknowledgmentType />
<CountryCode />
<CharacterSet />
<AlternateCharacterSetHandlingScheme />
<SendingApplication>
<namespaceid>ADMIT</namespaceid>
<universalid>abc</universalid>
<universalidtype>xyz</universalidtype>
</SendingApplication>
<SendingFacility>
<namespaceid>CLAY COUNTY MEMORIAL</namespaceid>
<universalid />
<universalidtype />
</SendingFacility>
<ReceivingApplication>
<namespaceid />
<universalid />
<universalidtype />
</ReceivingApplication>
<ReceivingFacility>
<namespaceid />
<universalid />
<universalidtype />
</ReceivingFacility>
<MessageType>
<messagetype>ADT</messagetype>
<triggerevent>A01</triggerevent>
<messagestructure />
</MessageType>
<ProcessingID>
<processingID>P</processingID>
<processingMode />
</ProcessingID>
<Version>
<versionID>2.2</versionID>
<internationalizationcode />
<internalversionID />
</Version>
<PrincipalLanguageOfMessage>
<identifier />
<text />
<nameofcodingsystem />
<alternateidentifier />
<alternatetext />
<nameofalternatecodingsystem />
</PrincipalLanguageOfMessage>
</MSH>
</Dataset1>
This is the hard code i have used:
/* MSH class file */
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;
using System.IO;
namespace HL7_XML
{
/// <summary>
/// Summary description for MSH.
/// </summary>
public class MSH
{
public MSH()
{}
/* Global Declarations */
string line,SA,SF,RA;
string currentLine;
string datafield = "|" + "|" + "|" + "|" + "|" + "|" + "|" + "|" + "|" +
"|" + "|" + "|" + "|" + "|" + "|" + "|" + "|";
string component = "^" + "^" + "^" + "^" + "^" + "^" + "^" + "^" + "^";
StreamReader myReader;
string[] sub_splitout=new string[20];
char[] sub_splitter={'^'};
char[] splitter = {'|'};
string[] splitout = new string[20];
public void msgheader()
{
/* Reading the HL-7 file i.e. to be converted into XML file */
try
{
myReader = File.OpenText("C:/HL7/HL7-XML/upload/input.txt");
}
catch (IOException e1)
{
Console.WriteLine(e1.ToString());
Console.WriteLine(e1.Message);
return;
}
do
{
try
{
/* Reading the HL-7 file line by line */
currentLine = myReader.ReadLine();
line = currentLine + datafield;
if (line.StartsWith("MSH"))
{
splitout = line.Split(splitter);
for (int i = 0; i <= splitout.Length; i++)
{
/* Creating Dataset for MSH */
Dataset1 ds=new Dataset1();
Dataset1.MSHRow MSH_row = ds.MSH.NewMSHRow();
/* Assigning the values of HL-7 file to MSH Table of Dataset1. */
MSH_row.FieldSeparator="|";
MSH_row.EncodingCharacters=splitout[1];
MSH_row.DateTimeOfMessage=splitout[6];
MSH_row.Security=splitout[7];
MSH_row.MessageControlID=splitout[9];
MSH_row.SequenceNumber=splitout[12];
MSH_row.ContinuationPointer=splitout[13];
MSH_row.AcceptAcknowledgmentType=splitout[14];
MSH_row.ApplicationAcknowledgmentType=splitout[15];
MSH_row.CountryCode=splitout[16];
MSH_row.CharacterSet=splitout[17];
MSH_row.AlternateCharacterSetHandlingScheme=splito ut[19];
ds.MSH.AddMSHRow(MSH_row);
ds.AcceptChanges();
/* Assigning the values of HL-7 file to Sending Application Table of
Dataset1 */
SA= splitout[2];
string new_string=SA+component;
sub_splitout=new_string.Split(sub_splitter);
for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.SendingApplicationRow sf_row =
ds.SendingApplication.NewSendingApplicationRow();
sf_row.namespaceid=sub_splitout[0];
sf_row.universalid=sub_splitout[1];
sf_row.universalidtype=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.SendingApplication.AddSendingApplicationRow(sf_ row);
ds.AcceptChanges();
}
/* Assigning the values of HL-7 file to Sending Facility Table of
Dataset1 */
SF= splitout[3];
string new_string1=SF+component;
sub_splitout=new_string1.Split(sub_splitter);
for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.SendingFacilityRow sf_row =
ds.SendingFacility.NewSendingFacilityRow();
sf_row.namespaceid=sub_splitout[0];
sf_row.universalid=sub_splitout[1];
sf_row.universalidtype=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.SendingFacility.AddSendingFacilityRow(sf_row);
ds.AcceptChanges();
}
/* Assigning the values of HL-7 file to Receiving Application Table
of Dataset1*/
RA= splitout[4];
string new_string2=RA+component;
sub_splitout=new_string2.Split(sub_splitter);
for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.ReceivingApplicationRow sf_row =
ds.ReceivingApplication.NewReceivingApplicationRow ();
sf_row.namespaceid=sub_splitout[0];
sf_row.universalid=sub_splitout[1];
sf_row.universalidtype=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.ReceivingApplication.AddReceivingApplicationRow (sf_row);
ds.AcceptChanges();
}
/* Assigning the values of HL-7 file to Receiving Facility Table of
Dataset1 */
string RF= splitout[5];
string new_string3=RF+component;
sub_splitout=new_string3.Split(sub_splitter);
for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.ReceivingFacilityRow sf_row =
ds.ReceivingFacility.NewReceivingFacilityRow();
sf_row.namespaceid=sub_splitout[0];
sf_row.universalid=sub_splitout[1];
sf_row.universalidtype=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.ReceivingFacility.AddReceivingFacilityRow(sf_ro w);
ds.AcceptChanges();
}
/* Assigning the values of HL-7 file to Message Type Table of
Dataset1 */
string MT= splitout[8];
string new_string4=MT+component;
sub_splitout=new_string4.Split(sub_splitter);
for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.MessageTypeRow sf_row = ds.MessageType.NewMessageTypeRow();
sf_row.messagetype=sub_splitout[0];
sf_row.triggerevent=sub_splitout[1];
sf_row.messagestructure=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.MessageType.AddMessageTypeRow(sf_row);
ds.AcceptChanges();
}
/* Assigning the values of HL-7 file to ProcessingID Table of
Dataset1 */
string PID= splitout[10];
string new_string5=PID+component;
sub_splitout=new_string5.Split(sub_splitter);
for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.ProcessingIDRow sf_row =
ds.ProcessingID.NewProcessingIDRow();
sf_row.processingID=sub_splitout[0];
sf_row.processingMode=sub_splitout[1];
sf_row.MSHRow=MSH_row;
ds.ProcessingID.AddProcessingIDRow(sf_row);
ds.AcceptChanges();
}
/* Assigning the values of HL-7 file to version Table of Dataset1 */
string version= splitout[11];
string new_string6=version+component;
sub_splitout=new_string6.Split(sub_splitter);
for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.VersionRow sf_row = ds.Version.NewVersionRow();
sf_row.versionID=sub_splitout[0];
sf_row.internationalizationcode=sub_splitout[1];
sf_row.internalversionID=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.Version.AddVersionRow(sf_row);
ds.AcceptChanges();
}
/* Assigning the values of HL-7 file to Principal Language Of Message
Table of Dataset1 */
string PLM= splitout[18];
string new_string7=PLM+component;
sub_splitout=new_string7.Split(sub_splitter);
for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.PrincipalLanguageOfMessageRow sf_row =
ds.PrincipalLanguageOfMessage.NewPrincipalLanguage OfMessageRow();
sf_row.identifier=sub_splitout[0];
sf_row.text=sub_splitout[1];
sf_row.nameofcodingsystem=sub_splitout[2];
sf_row.alternateidentifier=sub_splitout[3];
sf_row.alternatetext=sub_splitout[4];
sf_row.nameofalternatecodingsystem=sub_splitout[5];
sf_row.MSHRow=MSH_row;
ds.PrincipalLanguageOfMessage.AddPrincipalLanguage OfMessageRow(sf_row);
ds.AcceptChanges();
}
ds.WriteXml("C:/HL7/HL7-XML/msh.xml");
}
}
}
catch (EndOfStreamException e2)
{
Console.WriteLine(e2.Message);
}
finally
{
}
} while (currentLine != null);
myReader.Close();
myReader = null;
}
}
}
Plz provide me with a solution. Iam desperate. Thanx in advance.