/
Use Short Functions

Use Short Functions

Keep your functions short and focussed. Avoid deep nesting!

This is good advice for any programming language. Complex or deeply nested functions can quickly become confusing and difficult to manage. Instead of nesting multiple levels of logic within a single function, break the logic into smaller, separate functions. This will:

Example: Writing a Mapping Function

You don’t want to map one ‘node’ to another.

  • 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.

This code is poor practice:

im.webp

A better structure is like this:

  • The MapPID function is modular and consice.

  • The mappings can be re-used from any context where a PID segment needs to be mapped into the patient table.

im2.webp

 

 

 

Related content

Naming Convention
Naming Convention
More like this
Using the Translator
Using the Translator
More like this
Map Entire HL7 Messages or Segments
Map Entire HL7 Messages or Segments
More like this
Key Fields and Examples
Key Fields and Examples
More like this
The Rules of Three
The Rules of Three
More like this
Reading from a Database
Reading from a Database
More like this