Eliot’s Tips and Tricks

Use short functions

Keep your functions short! This is good advice for any programming language.

You should always be able to see the entire body of a function within one screen. In general if I am writing a mapping function I will try to only map one ‘node’ to another. This code is poor practice:

The problem is:

  • It is hard to reuse these mappings. If the PID segment was in a different spot in the message grammar say under a group called “PATIENT” then we have to define all the same mappings again.
  • It results in repetitive long code

A better structure is like this:

The MapPID function is modular and succinct. It can be used from any context where a PID segment needs to be mapped into the patient table. I have deliberately chosen a short variable name of “T”. This is because:

  • It makes for more compressed code giving more space for the annotations.
  • The annotations show that T is “patient Row” in this context anyway so there is no benefit in using a descriptive name.

The MapWeight function is being handled using the example code found in the HL7 to Database example.

Tagged:

One Comment

  1. Pingback: Will You Share Your Code? - iNTERFACEWARE Inc.

Leave A Comment?

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