|
| Sunday, 01 November 2009 07:00 |
Tricks of the Trade: MEDITECH NPR (Client Server) - Clean Code (Part 1 of 3)By: John Sharpe, President, Comstock Software, Inc. NPR reports usually start out simple. You place a few fields on the report. And roll it out to the end users. After the report has been in use for a while, someone requests a change. This time, you implement the change using a custom field. And as time goes on, the report becomes more complex and a macro evolves. The macro begins as a few lines, and the next thing you know, the code can begin to look like this.
As you looked through this example, you noticed that the majority of the code looks the same. Removing the repeated code, also known as de-duplicating the code, will make your life easier when that next change request comes through. Some of the most popular tools at our disposal for de-duplicating code - are sub-routines and parameters. Using these mechanisms will allow us to separate the information, in this case query and section, from the code that retrieves values from the MEDITECH database. Let’s talk more about sub-routines & parameters. Sub-routines work best as well named blocks of code that do one thing well. You give a sub-routine a job; it completes the task and returns. For the sub-routine do to its job, some information may be necessary to perform that job. The parameters are used to communicate the information to get the job done. Example:
The sub-routine in this example is SUM_NUMBERS. To return with the sum of 2 numbers, the parameters A & B are used to communicate the numbers to be added. While MEDITECH macros do not support parameters for sub-routines in the traditional way:
You can achieve the same thing in a MEDITECH macro like this:
Moving on from this example, let’s apply the technique to the code below. The VITAL.REPORT sub-routine receives the “VS.PULSE” & “HR” parameters and then reports on these values from the MEDITECH database. As you can see - “VS.PULSE” & “HR” are passed on to td.query & /SECTION. The parameters are used by the sub-routine to retrieve the PULSE value, to determine the documented HEART RATE for the patient.
Later down the road – the query may change, or another query may need to be added. Because you’ve organized this macro, another report writer, one with less experience than you, might be able to come in and add a couple of queries to the HR section in a timely manner. Questions? Get them answered at the MEDITECH Knowledge Exchange.
John Sharpe is President / NPR Consultant at Comstock Software, Inc. Learn more about NPR Report Writing at the MEDITECH NPR Report Writing Blog.
|
MeditechBulletin.com and MeditechCareers.com are not affiliated with MEDITECH, Inc.










