HL7 to Database


An example of a simple interface that saves patient information from HL7 messages to the Patient and Kin tables in a SQLite database.

We  suggest that you click on the Purple function call links in the annotation blocks on the right to navigate around the code and discover how it works:

You can also open up dialogs to see the data in it’s various stages, for example you can click ADT to see the parsed message, or Result Set to see a SQL query result:

To learn how this works just to try clicking on things in the annotation pane, or you can read our Annotations article.

If you have any questions please contact us at support@interfaceware.com.

Using the Code [top]

There are three main points:

  1. Understanding the code: We suggest you experiment with the code until you understand it, see the next section Trying out the code. Don’t worry if you make mistakes because you can always use Iguana’s builtin version control to revert to a previous commit. And if you like something that you did you can just make a new commit and then continue experimenting.
  2. Adapting the code your requirements: Though this example is simple it contains the most important components of an HL7 to database channel: Reading and  parsing an HL7 message, mapping the HL7 message to a database table structure, and finally saving data to the database. You will need to change the mappings to match your database structure. And you will almost certainly be using a different database from SQLite, see the db.connect API help.

    Tip: Creating  is usually a one-off process, so usually it is easier to create tables “manually” using the Create DB Tables option from the VMD files menu (rather than using SQL create statements like we did in this example). This method of creating tables works with all databases supported by Iguana, not just SQLite.

  3. Modifying the VMD files to match your database table structure: You will need to use Chameleon to modify the database table structures in your VMD files, see Understanding VMD Files for more information.
  4.  And finally remember that we always here to help: We actually regard support as an integral part of Iguana. So if you have any questions please contact us at support@interfaceware.com.

Trying out the code [top]

We suggest that you try out the code by doing the following three things:

How it works [top]

  • The first two functions MapPatient() and MapKin() are used to map data to the database
    Note: They are called from the main() function further down in the code
  • So lets scroll down and look how the main() function works:
    • First we connect to the database using the db.connect{} function
    • Then we use a little function we created to show the database location
      Note: You can click purple link to see how it works:
    • We use hl7.parse{} to parse the incoming message into an hl7 message node tree
    • We use db.tables{} to create a table node tree matching the database structure
      Note: In this case the node tree contains the tables Patient and Kin
    • We call the MapPatient() function to map patient data from the message to the Patient table structure
    • We call the MapKin() function to map kin data from the message to the Kin table structure
    • Before we can save data, we must ensure that the Patient and Kin tables exist in the database. To ensure that everything just “works out of the box” we use the CreateTables() function to create the tables automatically:
      Note: This method is very safe and will only create tables if they do not exist and will not delete existing tables.
      Note: After the first time you run the code you should comment out the call to the CreateTables() function (even though it does not cause any problems), it is good practice not to call unnecessary code:

      Tip: You can also use the generic CreateVMDTables() function from the code repository, which will create database SQLite tables matching the table definitions in any VMD.

    • We use the DB:merge{} function to save (insert or update) the patient and kin data to the database
      • To prevent inserts in the Editor set live=false:
    • We use the DB:query{} function to view the patient and kin data from the database
    • And finally we use DB:execute{} to delete the data from the patient and/or table
      • The execute function is disabled in the code, to allow deletes in the Editor set live=true

Tip: You can also create table(s) “manually” using the Create DB Tables option from the VMD files menu.

This method of creating tables will work with all databases supported by Iguana, not just SQLite.

More information [top]

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.