Problems to Get Data using Tesers on nHapi hl7 - c#

Hello again dear community, i am using " Tersers " to get data from an hl7 v2 messeage, its a ADT_A08 messeage.
Well the thing is that, im trying to get the PatientName with this: string test = terser.Get("PID-5-1"); and that return me nothing, instead if i use the same but changing the command for something like "MSH-16-2" i dont remember, but its work, why it still happend me that? i need to use things like PID-5-2 or EVN-2 , that commands does not work at all. The same happens when I use "MSH-152-2"; the return is the name of a medication, but that is typical of one of my hl7-v2 messages, but I would have to use "RXE-2-1" to get the same data. I apologize for my english , im spanish-language native.
using NHapi.Base.Model;
using NHapi.Base.Util;
using NHapi.Base.Parser;
using System.Diagnostics;
using NHapi.Model.V23.Message;
using System.IO;
public void someMethod()
{
string msg = txtHL7m.Text;
PipeParser pParser = new PipeParser();
var iMesseage = pParser.Parse(msg, "2.3");
try
{
var terser = new Terser(iMesseage);
string test = terser.Get(txtTerserExpression.Text);
txtTerserResults.Text = test;
}
catch
{
Console.WriteLine("ERROR");
}
}
//I expect the patientsData using the correct sintaxis of tesers

Related

how to get the current item being written by an XMLWriter

I have a series of settings being written out by an XMLWriter in C#. Here's some code:
try
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = (" ");
using (writer = XmlWriter.Create("PCOB2NET.XML", settings))
{
// Write XML data.
writer.WriteStartElement("PowerCOBOL2NETMigration");
writer.WriteStartElement("config");
writer.WriteElementString("VSVersion", selectedVSver);
writer.WriteElementString("path2SelectedVSVerProjects", path2SelectedVSVerProjects);
if (path2VSoverridden)
writer.WriteElementString("path2VSoverridden", "true");
else
writer.WriteElementString("path2VSoverridden", "false");
writer.WriteElementString("path2PRCfile", path2PRCfile);
writer.WriteElementString("path2XMLfile", path2XMLfile);
writer.WriteElementString("path2VSProject", path2VSProject);
... and so on.
My problem is that if there is an Exception (like a null field, for instance) it goes to the catch block and reports the exception as we would expect, but I don't know WHICH field it was writing at the time.
My question:
Is there any way I can get the current string being written, when an Exception occurs? I searched the web without success and I looked through every property and method of XMLWriter but I can't find a way to do it. Is there maybe a certain type of Exception trap that will give it to me? Any help or thoughts appreciated.
Try xml linq which is a new Net Library for reading and writing xml
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
string selectedVSver = "";
string path2SelectedVSVerProjects = "";
Boolean path2VSoverridden = true;
string path2PRCfile = "";
string path2XMLfile = "";
string path2VSProject = "";
XDocument doc = new XDocument();
XElement powerCOBOL2NETMigration = new XElement("PowerCOBOL2NETMigration", new object[] {
new XElement("config", new object[] {
new XElement("VSVersion", selectedVSver),
new XElement("path2SelectedVSVerProjects", path2SelectedVSVerProjects),
new XElement("path2VSoverridden", path2VSoverridden),
new XElement("path2PRCfile", path2PRCfile),
new XElement("path2XMLfile", path2XMLfile),
new XElement("path2VSProject", path2VSProject)
})
});
doc.Add(powerCOBOL2NETMigration);
doc.Save(FILENAME);
}
}
}
The simplest approach is to wrap small helper methods around XmlWriter.WriteStartElement etc. and catch your exceptions there.
It turns out I was looking for a solution at the wrong end of the problem. Instead of puzzling over XMLWriter, what I SHOULD have done was investigate the EXCEPTION.
(I did do this but only for the Exception Class, I needed to look further.) The problem looked like it could be easily solved by nesting some exception catch blocks, so:
catch (ArgumentNullException anEx)
{
// retrieve the offending field name from anEX...
badField = anEx.ParamName;
...
}
catch (ArgumentException aEx)
{
// retrieve the offending field name from aEX...
badField = aEx.ParamName;
...
}
catch (Exception ex)
{
...
However, I was misled by the "ParamName" which does not mean what I thought it did... This always returned null and I was no better off.
After spending a number of hours reading everything I could about Exception handling in C#, I am much better informed, but no wiser. I can't find a solution with the Framework so I have little recourse but to push all the settings through a method which will do the actual write and trap any exception at that moment, with the offending field available as it will have been passed into that method.
I think this inelegant, but I can't spend more time on it. Many thanks to all who responded and those who thought about responding... :-) I'll leave this open in case somebody really has a solution, for a few days.

How to fix ambiguous reference errors?

I have a web app that allows importing of contacts from Hotmail, Yahoo and GMail. I finally have it almost completed but since I added the importing of GMail, I am getting ambiguous reference errors and I am unsure how to fix them without breaking any code.
Here is a screen shot of the errors:
Try to use unique class names as much as possible. This will be the better solution in the end.
Write the entire namespace when referencing
OAuth.OAuthBase a = new ...;
Google.GData.Client.OAuthBase b = new ...;
Make an using alias for one or both:
using n2 = OAuth;
using Google.GData.Client;
n2.OAuthBase a = new ...; // referenced using namespace
OAuthBase b = new ...; // referenced through existing `using`
you can try something like this..
using GoogleOAuthBase = Google.GData.Client.OAuthBase;
namespace abc
{
public class Program
{
//make sure this Google.GData.Client.OAuthBase is instansiateable
var googleBase = new GoogleOAuthBase();
}
}
you can try entire name space as well.
var googleBase = new Google.GData.Client.OAuthBase();

How can I roll back changes with Entity Framework 5 within a Unit Test project

I'm playing with Entity Framework, and I have a Unit Test project that I want to exercise what I've done so far. I'd like to have it not actually update my test database when it's done. If I was working in SQL I would create a transaction and then roll it back at the end.
How can I do the same thing here?
As I understand it, context.SaveChanges(); is effectively doing the write to the database. And if I don't have that, then allCartTypes is empty after I assign it context.CarTypes.ToList()
Here's an example of one of my Test classes.
using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Trains;
using System.Linq;
namespace TrainsTest
{
[TestClass]
public class TestCarType : TestBase
{
[TestMethod]
public void TestCarTypeCreate_Success()
{
var tankerCarType = new CarType {Name = "Tanker"};
var boxCarType = new CarType { Name = "Box" };
using (var context = new TrainEntities())
{
context.CarTypes.Add(tankerCarType);
context.CarTypes.Add(boxCarType);
context.SaveChanges();
var allCartTypes = context.CarTypes.ToList();
foreach (var cartType in allCartTypes)
{
Debug.WriteLine(cartType.CarTypeId + " - " + cartType.Name);
}
}
}
}
}
I know I'm missing something fundamental, but I don't know what it is. and my googling has been fruitless.
There's a MSDN article about ef transactions.
http://msdn.microsoft.com/en-gb/library/vstudio/bb738523(v=vs.100).aspx

c# unit testing visual studio 2010

I'm new to c# and programming in general. Need to write some unit testing. Want to write some for this class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using teamcanada.Models;
using System.Configuration;
using teamcanada.ingestion;
/* This class writes the parsed CSV data into the database */
namespace teamcanada.dal
{
public class csvParseDAL
{
protected torontoDB db = new torontoDB();
/* if the database is empty, then do not continue with the CSV parsing */
public csvParseDAL()
{
if ((db.ElectionResults.ToList().Count() == 0) && (db.ElectionContributions.ToList().Count() == 0))
{
insertcsv();
}
}
/* Start CSV parsing */
public void insertcsv()
{
List<Results> results = null;
List<Contributions> contributions = null;
LoadCSV import = new LoadCSV();
results = import.loadResults();
foreach (Results r in results)
{
db.ElectionResults.Add(r);
}
contributions = import.loadContributions();
foreach (Contributions r in contributions)
{
db.ElectionContributions.Add(r);
}
db.SaveChanges();
}
}
}
Any help is appreciated.
D
Generally what you'll want to do is to use the Assert class to compare expected and actual values. The actual values are usually return values of methods. In your case, I would recommend testing the return values of import.loadResults(); and import.loadContributions(); to make sure they return what you expect.
I see you use EF which is not something you need to unit test, that has already been done by Microsoft. If you need to you can use integration tests, where the tests have access to the database and check whether proper values have been inserted.
It is hard to give more specific advice, just create a Test Project in Visual Studio, play a round a bit and than maybe try asking more specific questions. You can use this presentation to understanding the basics of unit testing.

LogParser crashes without error in C#

I'm trying to implement MS LogParser in a C# application. This compiles fine but inexplicably crashes on the logQuery.ExecuteBatch() method. The try/catch block doesn't catch it unless I specifically malform the szQuery, which suggests that everything is working as it should, I'm just not getting any output.
Any thoughts on why it might be crashing or where I might find some logging?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FolderLoggingLib;
using MSUtil;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
//refLog = new BinaryInputFormat();
LogQueryClass logQuery = new LogQueryClass();
ICOMCSVOutputContext output = new COMCSVOutputContextClass();
ILogParserInputContext parse = new BinaryInputFormat();
string szFileName = #"E:\Programming\FolderLogging\2012-05-13.fbl";
string szQuery = "SELECT Folder, User, Record, DB, TO_LOCALTIME(Timestamp) AS DateTime, Operation, Checked FROM " + szFileName + " ORDER BY DateTime DESC";
try
{
logQuery.ExecuteBatch(szQuery, parse, output);
}
catch
{
};
}
}
}
Use Execute instead of ExecuteBatch:
MSUtil.ILogRecordset RecordSet = logQuery.Execute(query, oInputFormat)
If you want to export to CSV in your sample code you need to change the query by adding INTO output_file_name and run ExecuteBatch:
string szQuery = "SELECT Folder, User, Record, DB, TO_LOCALTIME(Timestamp) AS DateTime, Operation, Checked **INTO c:\out\out.csv** FROM " + szFileName + " ORDER BY DateTime DESC";

Categories

Resources