Friday 6 May 2016

Personal Pronoun Case in Mirth

Why do older systems always seem to store every field value in capitals?  Why must John Smith be known as JOHN SMITH? - He's not an acronym!
Whatever the reason I'd like to convert these values into the proper personal pronoun casing, so it looks better in my system.
I use Mirth's transformers, so I prefer to do it in a single line of code too.
He's what I use:

msg['PID']['PID.5']['PID.5.2'].toString().toLowerCase().replace( /\b((m)(a?c))?(\w)/g, function($1, $2, $3, $4, $5) { if($2){return $3.toUpperCase()+$4+$5.toUpperCase();} return $1.toUpperCase(); })

Here I'm converting the first name of a patient with a little bit of regex so that the first character in a word will be a capital, and all the other characters are lower case.

It might seem a little overkill to just making the first character uppercase and the rest lower, after all the names each come in their own fields.  But in the case of a street name this fixes each word.
E.g.

Inbound

22 MAIN STREET
Becomes :

22 Main Street

No comments:

Post a Comment