...
Code Block | ||
---|---|---|
| ||
using System;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections.Generic;
using Connexion.Core;
using Connexion.Core.HL7;
using Connexion.Share;
namespace Connexion.Device
{
// ** This is pseudo-code **
[ClientRunnable(true)]
public partial class CustomFunctions : BaseHL7CustomFunctions
{
public void TableLookup(IMessageContext context)
{
MapTable mt;
if(!MapTablesByName.TryGetValue("New MapTable", out mt))
throw new Exception("Maptable 'New MapTable' not found");
var message = context.GetAsHL7Message();
// put the values to search for in a dictionary where the key is
// the column name and the value is the value to search for.
// In production, cache the dictionary and just change the values.
var lookup = new Dictionary<string, string>();
lookup.Add("Modality", message["MSH-9"]);
lookup.Add("Body Part", message["MSH-10"]);
// set the value of MSH-11 to whatever the map table lookup returned
message["MSH-11"] = mt.Lookup(lookup, "Loinc Part Code");
}
public void DatatableLookup(IMessageContext context)
{
MapTable mt;
if(!MapTablesByName.TryGetValue("New MapTable", out mt))
throw new Exception("Maptable 'New MapTable' not found");
var message = context.GetAsHL7Message();
// SQL syntax - careful this can be slow
// https://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
var datatable = mt.DataTable;
var result = datatable.Select($"Modality = '{message["MSH-9"]}' AND [Body Part] Like '{message["MSH-10"]}%'");
var row = result.FirstOrDefault();
if(row == null)
{
message["MSH-11"] = "Not Matched";
}
else
{
message["MSH-11"] = row["LOINC Part Code"].ToString();
}
}
}
} |
...