jeffcoughlin.com

Hospital ER Wait Times

Last fall I helped a client of mine (Middlesex Hospital) release a new website to display their ER wait times for their three locations. It received national news. At the time they were one of only three hospitals (that we knew of) that were doing it in the nation. Since then many other hospitals have followed suit, but MHS still gets critical acclaim for it.

Two weeks ago we launched a new main hospital website for them (http://middlesexhospital.org) and placed the ER wait times on the homepage (as well a few key places on the website).

I've been getting a lot of questions lately asking how we did it. So I thought I'd walk through the process for those who might be interested. First the data itself comes from the hospital's clinical systems (specifically a system called Cerner). I don't know the process they use to get the actual numbers. Unfortunately Cerner isn't designed to distribute data (ie. web service, XML, or any other type of data feed), so we had to find a loop hole. One of the guys at MHS figured out a way to do it using Cerner's custom query system where he runs a custom query and outputs it to an ASCII-based file (text file) which is sort-of like a CSV format. It's very messy, but with a little Regex I'm able to clean it up to be pretty decent (but I'm getting ahead of myself :) ). Next they FTP the file every 5 minutes to the web server through the DMZ. Now it's in my domain and I get to use ColdFusion to do the rest.

Once on the server I have a ColdFusion directory watcher that detects the file and triggers a script to run. The script runs the regex to cleanup the data and allow the CSV file to be easily consumable. Then it consumes the data from that file into a DB. From there it queries the DB and outputs the data to a static XML file for which I have an API (Thanks to my friend Simon Free for the lessons on proper API coding and documentation). Why an API you ask? Because it allows us to use the data for other devices, systems, and apps (and an iPhone app that I believe is in development).

The final piece is to display the data. To do that I do it in two parts. Let's take the MHS homepage for example. Since we know the data gets updated every five minutes they wanted the data on the homepage to auto-update every five minutes. So, since we use jQuery quite heavily on that website I made a jQuery script (using jQuery's get() function to consume XML data) to grab and display the data every five minutes.

But what if the user doesn't have javascript enabled? No problem. I have a separate ColdFusion script that runs before jQuery has access to the DOM where it runs against a CFC to grab the data and display it in HTML with no help from javascript. That CFC script gets a little trickier since the client wanted the items returned in a different order than they appear in the XML. Sure I could have hit the XML three separate times per page load, but since this is the homepage (which gets more hits than any other page on the site) that would just be poor programming on my part. So I figured out a way to hit the XML feed once and sort the data in a desired fashion (and allow the client to change the order easily at any time).

What about the font? Did I use Flash? Nope :). At first I wrote the whole thing to work in sIFR which allows you to display custom fonts on a website using Flash. It worked great, but I wasn't really happy with it. For one, we don't use Flash anywhere else on the homepage, so why load it for just this one item? (note: we do use Flash elsewhere on the site for things like videos. Don't think I have anything against Flash like Mr. Jobs. In fact, I love Flash.). Okay, so how did I get a custom font on the website and get it to still work in things like the iPhone that doesn't support Flash? I used a feature called @font-face{} which allows you to have your clients browser download and use a custom font of your choosing in their browser. There is lots of documentation and how-to's on the web for implementing @font-face{}, but if you really want to jump in and play with it quickly I strongly suggest checking out fontsquirrel.com's font-face generator (you can use one of their free fonts or use their tool to upload one of your own). Not only do they convert your font into the appropriate format, they'll create sample code based on your font... pretty cool. Once you get your testing done though there are some things you need to be smart about, like cleaner code, small/condensed font size (try to keep the font size under 20k if possible. I try to shoot for 12k or better. There are tutorials on how to do this if you search the web), and a few other common sense developer things to keep in mind. Most importantly you want to make sure you have a fallback font (and font size) that will work well for those people with older browsers that don't support @font-face{}. Also, for legal reasons make sure you are allowed to use the font on your website (font licensing can get pretty expensive). I was lucky enough to find an open-source font that allowed us to use the font freely on the website.

Here's an interesting tidbit to know for @font-face{}. Of all the major browsers to support the feature, Firefox was the last one to the party (not supporting it until v3.5) and Microsoft's IE6 was the browser that actually first supported the feature (I know... weird). However, I have to give Mozilla props. They have a slightly better implementation for it where it allows you to offer FF browsers a much smaller/compact file size for the user to download (if you use the fontsquirrel @font-face generator mentioned above, it creates all of these files for you, including a pretty cool font just for the iPhone).

Side Note: When I created the XML files (I'll probably offer JSON soon as well if they ask for it) I decided to make the file static instead of dynamically created on each page hit. Normally you want to dynamically create the XML on each page load, however the reason I chose to statically save the XML file was because the hospital only sends the data to me once every five minutes. Since this data is requested a lot from many sources, it would be unwise programming to hit the database repeatedly for the same information. Sure I could have cached the query, but technically this uses less resources.


UPDATE: For those interested, I made a quick little video showing off a few of the features of the site. I tried to keep the video to one minute, so it only shows a small percentage of the site's features. It was a huge project that involved a lot of people. Thanks everyone who contributed. Your efforts are greatly appreciated. Special thanks go out to Sean Coyne and Marco Pace for their endless hours and dedication to get the project done on a tight deadline. With their help and the coding speed of a good CF framework we were able to release the website with a plethora of features beyond the client's expectations.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Aaron West's Gravatar Jeff, thanks for writing a post describing your app. This is a great use of ColdFusion's many different features.
#1 by Aaron West | 7/3/10 12:43 PM
utah-mortgage-rates's Gravatar ha until i found your blog I dindt realize peeps still used cfm....
#2 by utah-mortgage-rates | 7/21/10 10:47 PM
Jeff Coughlin's Gravatar @utah Yup. And still as powerful as ever (and as always about 5 years ahead of its competitors in features and functionality) and cost of ownership is far less than any other major web language. But don't take my word for it, see some real statistics for yourself http://www.terrenceryan.com/blog/post.cfm/dear-col...
#3 by Jeff Coughlin | 7/25/10 2:00 AM
utah's Gravatar Nice Jeff.... I read the article although the part about cfm developers bacoming "an angry mob of flame warriors." made the most sense to me.... actually the graphic and statistics seemed compelling although no source info was provided... So excluding flame warriors and a superfluous graph why choose cfm over php, when php seems to be the language of choice of many a content management system?
#4 by utah | 7/27/10 9:45 AM
Jeff Coughlin's Gravatar @utah: For me it's a personal choice. For my clients it's because they've seen the cost of ownership for themselves. Given that CF is so much faster to code in (so many less lines of code) it saves them thousands of dollars (USD) per project using CF developers rather than PHP. For some of their huge projects that would take, say, 12 months to code in PHP takes less than half that time to develop in CF and less than half the developers (this is from their experience - at least the ones who've used PHP on large-scale projects as well as CF).

Sorry, I don't have images and graphs for that info nor do I have data to back it up. You'll just have to take my word on it :).

But please don't think I have anything against PHP. As a matter of fact I think it's a great language (as are other top web languages and frameworks like ASP, JSP, Rails, etc). I've worked in several languages now and appreciate many of them for what they have to offer. In the end I always turn back to CF for it's speed of programming, processing, platform coverage, and cutting-edge releases.

And for the nay-sayers who don't like the up-front cost of $1200 USD to get all these great features and cost-savings pre project, there are Open Source CF alternatives (free) that are great options and have large communities (such as Railo and OpenBD). They are also updated more frequently (ColdFusion has an average 2-year life cycle per major release and about 1-year major patch releases, where Railo and OpenBD are updated almost daily due to less license restrictions - similar to licenses on other open source projects).
#5 by Jeff Coughlin | 8/12/10 4:38 AM
Liz's Gravatar Thanks for posting. We want to do something similar at our University.
#6 by Liz | 9/27/12 8:26 PM



BlogCFC 5.9.8.007 by Raymond Camden | RSS | Contact Blog Owner