Blog archive

Nemsis XML Element Lookup Values with C Sharp

When working with Nemsis XML you very quickly discover that many of the fields are numeric codes instead of normal names and addresses.


In the image below there is a sample patient.  Some of the elements are human readable.  Notice with ePatient.14 that there are two values with seven digit codes.



Sample XML



What does "2514009" mean?

These are codes which must be referenced by using a Nemsis dictionary file.  We will work with Nemsis dictionaries in this article.



Source Data

Nemsis downloads are located at


I will be using the Test Cases & XML Samples and the Dataset Dictionaries.

Nemsis Downloads


The Dataset Dictionaries are located here




Nemsis Element List

The Nemsis element list is data separated by vertical bars.  The first line is the header definition.  There are 2,944 lines in the file Combined_ElementEnumerations.txt.

'DEMDataSet'|'dCustomConfiguration.03'|'Custom Data Type'|'9902001'|'Binary'|
'DEMDataSet'|'dCustomConfiguration.03'|'Custom Data Type'|'9902003'|'Date/Time'|
'DEMDataSet'|'dCustomConfiguration.03'|'Custom Data Type'|'9902005'|'Integer/Number'|
'DEMDataSet'|'dCustomConfiguration.03'|'Custom Data Type'|'9902007'|'Other'|
'DEMDataSet'|'dCustomConfiguration.03'|'Custom Data Type'|'9902009'|'Text/String'|
'DEMDataSet'|'dCustomConfiguration.03'|'Custom Data Type'|'9902011'|'Boolean'|



Source Code

The source code for these examples is available on my GitHub page


The project is written in Visual Studio 2017 using a .NET Core 1.1 Console application.


Execution beings in Program.cs. I begin by populating a local variable elementEnumerations.  This contains by Nemsis dictionary data.




Lookup Class

I use a Lookup class to import all the data from the Combined_ElementEnumerations.txt file.

I define a file path where the target file will be found.  I use File.ReadAllLines to load all the data into a string array named enumerationArray. Next a results List collection is used to return the values.

Lookup Generate



Element Enumerations

I use a custom type named ElementEnumerations to store the data as these property names.  The names, ordering, and types must match the dictionary file headers.




Parse Line

Each line in the Nemsis dictionary file is parsed by this function.  I used string methods to trim and split each row into a string array.  I use these values to create the ElementEnumerations.  System.Linq is used to skip columns and pick either the first or last records.




Example Program

Navigating back to the Program.cs file, we write a simple example demonstrating the capability added.  The lookups are loaded into memory which is queried using System.Linq. Codes from the Nemsis XML sample can be entered and the values are returned.




Example Output

The results of the program show the code 2514009 is the patient race of Native Hawaiian or Other Pacific Islander.





Has this post been useful to you?

Support me via a PayPal donation

Share this article to social media:

Leave your comment
5/7/2017 1:03 AM
fields is already an array because you used string.split. Why is fields.Skip(1).FirstOrDefault() better than fields[1]?
5/7/2017 7:51 AM
Why do you declare all your methods as static?  Even those that update the class.
5/7/2017 9:01 AM
fields[1] would also work.  They are static because I started coding everything inside static Main.