Monthly Archives: May 2013

Understanding HL7 Messages

A project building a string of medical sites brought me to where I needed to understand the medical encoding language of HL7. This is a brief tutorial on understanding an example HL7 message:

An HL7 message consists of one or more segments. A carriage return character (r, or 0D in hexadecimal) separates one segment from another. Each segment is presented on a separate line(see below example).

An HL7 segment has one or more composites (fields). A pipe (|) character separates one composite from another.

When a composite contains other composites, known as sub-composites (sub-fields), they are usually separated by (^) characters.

Example HL7 message:

MSH|^~&|EPIC|EPICADT|SMS|SMSADT|199912271408|CHARRIS|ADT^A04|1817457|D|2.5|

PID||0493575^^^2^ID 1|454721||DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086|

NK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC|||||||||||||||||||||||||||

PV1||O|168 ~219~C~PMA^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||||||||||||||||||||199912271408||||||002376853

Message details:

In the above HL7 message, I separated each line with an empty line between them in case your browser displays them in a broken fashion. It is important to realize that each of the four blocks of text in the message is intended to be on one line and are normally separated by a r or 0D character code as explained above.

 

 

Getting on Page 1 of Google

Okay, I am going to try to get ranked in Google search results on page one if possible. I am not an SEO expert, but am experienced in SEO practices and am a seasoned web developer with over ten years experience, so I hope I can do this. If I can't, it will probably be even harder for a person with no web experience at all, but don't give up, try different methods. I am starting this journal on 5-26-2013, so let's see how long it takes to at least get ranked in Google with a brand new web page I just posted today. Also another challenge is that it is a new server too, so the odds are stacked against me from the start, but I am going to give it a try anyway.

Getting Started

The first thing I did was made a basic website to put on my server.

The second thing I did was found my target keyword phrase. T accomplish that, I used Google Analytics Keyword tool found at:

https://adwords.google.com/o/KeywordTool

 

Use the search tool to  find a keyword phrase optimal for your site. I choose a three letter phrase, but it can be a little longer if you find something with good results. My keyword had 201,000 Google search results listed for both local and global and had a competition ranking of low. I read that's what you want, so I am giving it a shot. We will have to wait a few days to see if it worked.

Include the keyword phrase in your webpage's title tag and first h1 tag at least. Then also make sure it appears in the body as well. Also insert the keyword phrase in the keyword meta tag along with other similar search terms. What you put in the title tag appears in Google search results as the site's description, so it is probably most important.

Next, I listed my webpage URL including the page name with Google at:

https://www.google.com/webmasters/tools/

 

Then I read somewhere that Google also scrapes SuperPages.com for sites to help judge their importance, so I listed my site at:

http://www.superpages.com/

 

Fix URLs and Page Names

the next thing I did to my webpage is changed any non descriptive page names in URLs to descriptive ones. For example, instead of mypage.html, for a web design site, you would want to use descriptive names for your pages such as portfolio.html or webdesign_services.html. Make sure any links in your pages contain as many keywords as possible in them instead of nonsense.

Link Building

This is always the tricky part I think. You have to get incoming links to your webpage to increase its page rank with Google, so there are all sorts of tricks for this which I am by no means an authority on, but some methods I am familiar with include:

  • Posting articles and tutorials including your link in blogs and elsewhere.
  • Yahoo Answers - search unanswered questions and answer them using a page on your website as the source gets you a link in yahoo which is handy for SEO.
  • Other quality sites - find as many as possible in your market niche and try to get your link on them.

Start a blog for your webpage and website that is directly linked to it. I installed a WordPress blog on the same server and linked to it using a "Blog" menu item in the main navigation bar at the top of the page and elsewhere throughout the site. A blog gives you an opportunity to get additional links and to build quality content that directs people to your site while they are reading valuable information regarding the topic of your website. Quality content on your webpage you want to get ranked and your blog are often two of the most overlooked important SEO quailities a webpage needs.

 Create an XML Site Map

There are a few good online services that will make you a free sitemap for Google. I found this one to be the best. Plus, they had a number one ranking in Google, so they must know what they are doing. I went to the following webpage to make my own Google XML sitemap:

http://www.xml-sitemaps.com/

 Register your sitemap with Google

Go to your Google webmaster account again and make sure your sitemap is listed by adding it. You can do so by clicking the sitemaps link the left navigation menu of Google Webmaster. You should also go over the sitemap by hand to make sure no important links are missing. For example, my blog link was missing so I added it by hand by adding a few links of XML to the sitemap.xml file.

 

Want to learn more about SEO? Check out these relative books from Amazon:

Installing Mirth on Linux Amazon EC2

For a recent health care information system integration job, I was required to learn how to use HL7 and the MIRTH integration engine. Here is how I learned to install MIRTH on an Amazon cloud server.

NOTE: some of the information in this tutorial was hard to come by. Mirth doesn't offer high level support unless you purchase it for $5000 and up depending on the type of membership you acquire, so I did a lot of trial and error to figure this out and hope it helps others in a similar situation. -Ian L. author

Set up an appropriate server

First thing you need to do is make sure your server instance can support Mirth. The main concern here is that it has JRE and proper ports. Check your instance for JRE by typing the following at the command prompt for your server:

java -version

and make sure it returns version 1.6 or better.

Next, chec  your security group from the Amazon EC2 console and make sure you allow the following ports:

SSH tcp 22 22 0.0.0.0/0
HTTPS tcp 443 443 0.0.0.0/0
HTTP tcp 80 80 0.0.0.0/0
Custom tcp 8080 8080 0.0.0.0/0
Custom tcp 8443 8443 0.0.0.0/0

If you don't have a port such as 8443, then add it or start a new instance with a new security group and manually add the proper ports indicated above.

Installing MIRTH

Installing MIRTH is simple using wget. Simply use the following commands

First login as root or use sudo in front of the command like in the following example:

It took a few minutes for it to download in my case. After it is done, use the following command to extract it:

sudo tar xvfz mirthconnect-2.0.1.5164.b404-unix.tar.gz

It will not work if you are not logged in as root or use the sudo command in front of the tar command as in the above example.

Starting Mirth Connect

Here I got a little chung up because the tutorial I read said to change to the directory like this"

cd Mirth Connect

weill that didn't work because Linux doesn't like spaces in directory names, so you have to escape it with a backslash like this:

cd Mirth/ Connect

Once you are in the Mirth Connect directory, run the following start command:

./mirthconnect_service start

Accessing Mirth from a Browser

The next thing you should do is open the GUI in your browser using your server's IP or domain name followed by a semi-colon and the port no. The default port is 8080 so I used:

http://53.241.142.64:8080/

replace the IP address with your own in the above command.

 

 

 

 

Creating a WordPress Theme From Scratch

There is a lot to learn about WordPress theme development. In this intermediate level tutorial for aspiring WordPress theme developers, I will describe the bare essentials for developing your own responsive WordPress theme from scratch.

 

What is a Responsive WordPress Theme?

When I speak of responsive WordPress themes, I mean a theme that is mobile friendly with elements that change size and sometimes position according to your current screen size. In my opinion a truly responsive web page should look good in any browser window and any elements on the page should self-adjust according to the window size.

 

Dynamic sizing of elements on the webpage is important. This means that elements should change size and sometimes even shift position while you resize the browser window. In other words, you will see the images change size as you resize the window. Other objects can resize as well,but images are often the number one concern. Divs, text and other inline or block objects can also be sized accordingly while the window size is manipulated. Of course this allows for the page to open at any size and size the elements accordingly.

 

File Infrastructure

The first thing you can do to start your theme is create a directory to house your theme in the wp_content/themes directory of your WordPress installation. Name a new directory after the theme you are creating. In this tutorial, we are creating a theme called responsive_jafty so that is what you can call the directory unless you have a more appropriate theme name in mind, in which case you are free to name it as you please of course.

 

The actual files we will be creating will be style.css, index.php, header.php, sidebar.php and footer.php, the bare essentials to get you started in theme development. These files need to be named as stated above or WordPress will not recognize them as it should.

 

Layout

Before you start coding it is crucial to know what you are doing. The very least you should do is draw a basic wireframe with the main areas of your webpage defined as in the following image:

When developing a professional theme, you will want to do a little more than a simple wireframe, but this works for our learning purposes. In real life, if you were developing a professional theme for yourself or a paying client, you would want to develop a detailed Photoshop rendering of the theme you wish to create. You should at least layout the home page or main posts page in Photoshop including all details. The finished Photoshop template should look exactly like the theme you wish to create. However, a wireframe is often a great way to start if you don't really know what you want or if you are a stronger developer then you are a designer.

 

Creating Your header.php Script

One of the essential files to create a theme is the header.php file. From looking at the above wireframe, I can tell how I will need to code heaer.php. Here is a working example:

 

<!DOCTYPE html>

<html>

<head>

<title>Jafty Responsive WordPress Theme</title>

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">

</head>

<body>

<div id="wrapper">

   <div id="header">

   <h1>Jafty Responsive Theme</h1>

   </div><!--end header-->

 

That's all there is to a simple header file. It just needs a doctype declaration, opening HTML tags an opening wrapper div and the site's header div with the contents of the header.

Creating the index.php file

The next essential page for your theme is the index.php file that includes the above header as well as the sidebar and footer files. Here is a working example of a simple index.php page:

 

<?php get_header(); ?>

 

   <div id="main">

      <div id="content">

      <?php if (have_posts()) : while (have_posts()) :     

 

   the_post(); ?>

      <h1><?php the_title(); ?></h1>

      <h4>Posted on <?php the_time('F jS, Y') ?></h4>

      <p><?php the_content(__('(more...)')); ?></p>

      <hr>

      <?php endwhile; else: ?>

          <p><?php _e('Sorry, no posts matched your criteria.');

 

?></p>

      <?php endif; ?>

      </div><!--end content-->

   </div><!--end main-->

   

 

   <div id="sidebar">

   <?php get_sidebar(); ?>

   </div><!--end sidebar-->

 

<div id="delimiter"></div>    

   

   <div id="footer">

   <?php get_footer(); ?>

   </div><!--end footer-->

</div><!--end wrapper div-->

</body>

 

</html>

That's a very basic working example which you may expand upon as necessary to get the desired results. Now lets move on to the footer and sidbar pages next.

 

Creating Your sidebar.php Script

The sidebar.php script just needs to have a few built in functions from WordPress to get your sidebar objects into your template such as categories and archives as in the following example code for sidebar.php:

 

<h2 class="sidebartitle"><?php _e('Categories'); ?></h2>

<ul class="catlist">

<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>

</ul>

<h2 class="sidebartitle"><?php _e('Archives'); ?></h2>

<ul class="archivelist">

<?php wp_get_archives('type=monthly'); ?>

</ul>

 

That concludes sidebar.php, now move on to footer.php to finish our PHP files.

 

Coding footer.php

The footer.php script just needs to have the content for the footer widget. It is nice to have footer.php file so making changes to one file will change the footer throughout the entire site.

 

<h2>Another WordPress Site created by Jafty Interactive Web

 

Development</h2>

&copy; 2013-2035 Jafty Interactive Web Development.

 

That's a start, you can add what is appropriate for your own footer.

 

The Magic is in the Style Sheet!

The style sheet is probably the single most important file for a new theme. It is what WordPress uses to recognize the theme and provide information in the WordPress admin area regarding your theme, so be careful to include all the necessary elements indicated in the below example:

/*

Theme Name: Responsive Jafty

Theme URI: http://jafty.com/

Description: A bare-bones responsive WordPress theme example.

Author: Ian L.

Author URI: http://jafty.com/

Version: 1.0

Tags: blue, white, two-columns, flexible-width, flexible-header, http://wordpress.org/extend/themes/tag-filter/

 

License:

License URI:

 

General comments (optional).

*/

body {

text-align:center;

}

 

#wrapper{

display: block;

border: 1px #000 solid;

width:90%;

max-width:1400px;

margin:0px auto;

}

 

#header{

border: 2px #000 solid;

}

 

#sidebar{

width: 35%;

height:500px;

border: 2px #000 solid;

float: left;

}

 

#main{

width: 62%;

border: 2px #000 solid;

float: right;

}

 

#delimiter{

clear:both;

}

 

#footer{

border: 2px #000 solid;

}

There you have it. Notice the tags I used. Those help people searching for themes find what they are looking for, so will help make your theme popular if people are searching for the attributes of your particular theme. There are only certain tags that will work here. For a list of working tags, see: http://wordpress.org/extend/themes/tag-filter/

 

Putting It All Together

Okay, we have laid out all the theme elements above. It is time to put it all together and have a working responsive WordPress theme. It is just a start, but you can build on this. It is fluid and adjustable. When you are done, you will probably want to add a section of JavaScript code or Jquery code to resize images on page resize.

 

Now simply upload all the files to the new theme directory we created at the start of the tutorial, then go to your WordPress installation and activate the theme from the admin console. Simple as that! When you open your site you will see a very basic wireframe responsive theme layout as in the two examples below that demonstrate the way it will look in two vastly different screen sizes:

 

 

Above is a narrow screen size and below is a wider size. Notice the way it behaves:

Using JavaScript in WordPress

How to Remove Entire Directory from Linux Command Line

There are two commands to remove a directory in Linux, there is the rmdir command that only works on an empty directory and therefore often useless, and there is the rm command that can be used with the proper arguments to remove an entire directory with all sub-directories and files within it.

Command line command to remove an empty directory:

rmdir dirname

that will remove an empty directory, but if your directory has content in it and you are sure you want to delete everything in it, use the next command.

Linux command line command to remove a directory and all of its contents:

rm -rf dirname/

Simply replace "dirname" with the directory you want to completely remove with all its content and that will do the trick. Its quick, easy and unrecoverable, so be careful!

 

Add PHP IMAP to Webserver

In this case, I had to add PHP's IMAP mail functions to an Amazon ec2 instance, but I will describe how to do it on Debian and Centos systems as well.

On Amazon's most common LInux AMIs and similar systems using YUM just use the following at the command prompt from a command line shell:

sudo yum install php-imap

On Debian servers, use:

sudo apt_get install php5-imap

Then restart your httpd service. On amazon you can do so with

sudo service httpd restart

 

Getting Various Dates using PHP Date Function

In this more complete date/time PHP tutorial, I will show you how to use the PHP getdate function. I will also demonstrate how you can get various dates from the PHP date object. For example, you can do the following to get both today and yesterday's date on any given date and time:

$d1 = date("Y-m-d");//today's date.
echo "Today: $d1<br />";
$d2 = date("Y-m-d", strtotime("yesterday"));//yesterday's date
echo "Yestarday: $d2<br />";

PHP's getdate Function:

Simply using the following line of code below will return an array with elements including various date/time values as listed in the table below:

$info = getdate();

Elements available in the returned array
Key Description Example  values
"seconds" Numeric representation of seconds 0 to 59
"minutes" Numeric representation of minutes 0 to 59
"hours" Numeric representation of hours 0 to 23
"mday" Numeric representation of the day of the month 1 to 31
"wday" Numeric representation of the day of the week 0 (for Sunday) - 6 (for Saturday)
"mon" Numeric representation of a month 1 - 12
"year" Full numeric representation of a year, 4 digits I.E.: 1999 or 2003
"yday" Numeric representation of the day of the year 0 - 365
"weekday" Full textual representation of day of the week Sunday - Saturday
"month" A full textual representation of a month January - December
0 Seconds since Unix Epoch, similar to values returned by time() and used by date(). Depending on OS, it is normally from -2147483648 to 2147483647.

Now given what you learned here and combine it with some other PHP date/time functions and you can do about anything with dates and times in PHP. I've put together a little demo script that shows a lot of the more useful functions and demonstrates how to use them. Consider the following demo code:

<?php

$info = getdate();
$date = $info['mday'];
$month = $info['mon'];
$year = $info['year'];
$hour = $info['hours'];
$min = $info['minutes'];
$sec = $info['seconds'];

//prepend a zero to the date if it is less than 10:
if($date < 10) $date = "0$date";

$current_date = $month."-".$date."-".$year."_".$hour."-".$min."-".$sec;

echo "<p>current getdate time: $current_date</p>";

//now some strtotime date/time examples:
echo "<h3>strtotime unix timestamps</h3>";
echo strtotime ("+1 day"), "<br>";
echo strtotime ("+1 week"), "<br>";
echo strtotime ("+1 week 2 days 4 hours 2 seconds"), "<br>";
echo strtotime ("next Thursday"), "<br>";
echo strtotime ("last Monday"), "<hr>";

echo "<h3>Examples of strtotime used with date:</h3>";
$d=strtotime("tomorrow");
echo "tomorrow: ".date("Y-m-d h:i:sa", $d) . "<br>";

$d=strtotime("yesterday");
echo "yesterday: ".date("Y-m-d h:i:sa", $d) . "<br>";

$d=strtotime("next Saturday");
echo "next Saturday: ". date("Y-m-d h:i:sa", $d) . "<br>";

$d=strtotime("+3 Months");
echo "+3 Months:".date("Y-m-d h:i:sa", $d) . "<br>";
?>

PHP's date function Parameters:

Here's a complete list of the parameters you can use inside the parenthesis with the date function:

  • d - The day of the month (from 01 to 31)
  • D - A textual representation of a day (three letters)
  • j - The day of the month without leading zeros (1 to 31)
  • l (lowercase 'L') - A full textual representation of a day
  • N - The ISO-8601 numeric representation of a day (1 for Monday, 7 for Sunday)
  • S - The English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)
  • w - A numeric representation of the day (0 for Sunday, 6 for Saturday)
  • z - The day of the year (from 0 through 365)
  • W - The ISO-8601 week number of year (weeks starting on Monday)
  • F - A full textual representation of a month (January through December)
  • m - A numeric representation of a month (from 01 to 12)
  • M - A short textual representation of a month (three letters)
  • n - A numeric representation of a month, without leading zeros (1 to 12)
  • t - The number of days in the given month
  • L - Whether it's a leap year (1 if it is a leap year, 0 otherwise)
  • o - The ISO-8601 year number
  • Y - A four digit representation of a year
  • y - A two digit representation of a year
  • a - Lowercase am or pm
  • A - Uppercase AM or PM
  • B - Swatch Internet time (000 to 999)
  • g - 12-hour format of an hour (1 to 12)
  • G - 24-hour format of an hour (0 to 23)
  • h - 12-hour format of an hour (01 to 12)
  • H - 24-hour format of an hour (00 to 23)
  • i - Minutes with leading zeros (00 to 59)
  • s - Seconds, with leading zeros (00 to 59)
  • u - Microseconds (added in PHP 5.2.2)
  • e - The timezone identifier (Examples: UTC, GMT, Atlantic/Azores)
  • I (capital i) - Whether the date is in daylights savings time (1 if Daylight Savings Time, 0 otherwise)
  • O - Difference to Greenwich time (GMT) in hours (Example: +0100)
  • P - Difference to Greenwich time (GMT) in hours:minutes (added in PHP 5.1.3)
  • T - Timezone abbreviations (Examples: EST, MDT)
  • Z - Timezone offset in seconds. The offset for timezones west of UTC is negative (-43200 to 50400)
  • c - The ISO-8601 date (e.g. 2013-05-05T16:34:42+00:00)
  • r - The RFC 2822 formatted date (e.g. Fri, 12 Apr 2013 12:01:05 +0200)
  • U - The seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

Since PHP 5.1.0, the following constants can also be used with the date function:

  • DATE_ATOM - Atom (example: 2013-04-12T15:52:01+00:00)
  • DATE_COOKIE - HTTP Cookies (example: Friday, 12-Apr-13 15:52:01 UTC)
  • DATE_ISO8601 - ISO-8601 (example: 2013-04-12T15:52:01+0000)
  • DATE_RFC822 - RFC 822 (example: Fri, 12 Apr 13 15:52:01 +0000)
  • DATE_RFC850 - RFC 850 (example: Friday, 12-Apr-13 15:52:01 UTC)
  • DATE_RFC1036 - RFC 1036 (example: Fri, 12 Apr 13 15:52:01 +0000)
  • DATE_RFC1123 - RFC 1123 (example: Fri, 12 Apr 2013 15:52:01 +0000)
  • DATE_RFC2822 - RFC 2822 (Fri, 12 Apr 2013 15:52:01 +0000)
  • DATE_RFC3339 - Same as DATE_ATOM (since PHP 5.1.3)
  • DATE_RSS - RSS (Fri, 12 Aug 2013 15:52:01 +0000)
  • DATE_W3C - World Wide Web Consortium (example: 2013-04-12T15:52:01+00:00)

Turn PHP Error Reporting On or Off

Sometimes it maybe convenient to enable or disable PHP error reporting from a script. Ultimately error reporting is contoroled from your server's php.ini configuration file for PHP. This is an alternative method for cases where you might not have access to php.ini. I also use it quite often for debugging scripts myself.

 

Turning Error Reporting Off

If you are getting errors showing up in your website, then you may want to turn error reporting off so users won't see any errors. To turn it off, add the following line of code to the very top of your PHP script:

error_reporting(0);

Turn On Error Reporting for PHP

To make sure error_reporting is on for testing and debugging a script, add the following line of code to the very top of your PHP script:

error_reporting(-1);

Then you can always just comment the line out when you are done testing.

 Force Error Reporting for PHP Script

If you find yourself using a server where you don't have access to php.ini and cannot view PHP errors, try adding this to the top of your file as well:

error_reporting(E_ALL);

ini_set('display_errors', '1');