How Eliminating Geography is Disrupting Healthcare

by Martin Westin in


My first article over at the Trice blog:

From smoke signals to Skype, humans have always tried to invent communication tools to transcend geography. Today, the internet is our most versatile technology that allows us to communicate without physical implications.

At Trice, we leverage the power of the internet, also known as the cloud, to help physicians optimize financial, clinical, and patient outcomes by making geography irrelevant.

In order to optimize outcomes, we had to eliminate 3 major restrictions caused by geography...

Read the whole thing at http://triceimaging.com/2015/eliminating-geography-disrupting-healthcare/


Odd Map-Reduce failure with MongoDB and Mongoid

by Martin Westin in


I just want to document this for future reference. Google was very unhelpful so this is likely a rare error condition.

 

While making an innocent change to the query portion of a Mongoid map-reduce job it started throwing an exception. This exception: 

failed with error "ns doesn't exist"

Internet wizdom suggested a missing collection. One hit suggested a missing field as the cause. But my collection most decidedly was there. Other map-reduce jobs ran over it just fine. Other map-reduce jobs even ran fine using the exact same query "constraint".

Rails log showed all being well. Even the exception (displaying the map-reduce)  showed the expected query. Nothing indicated what was wrong.

Not to go too deep into the troubleshooting, the cause turned out to be a laziness an scope issue. The value for the query was out of scope when the lazy Mongoid processing got to it.

This would throw the exception.

Modelname.mongo_session.command(
mapreduce: Modelname.collection.name,
map: map_function,
reduce: reduce_function,
query: {"value.deep_value" => current_user.associated_thing.some_value},
out: {inline:1}
)

While this would not. 

deep_value = current_user.associated_thing.some_value
Modelname.mongo_session.command(
mapreduce: Modelname.collection.name,
map: map_function,
reduce: reduce_function,
query: {"value.deep_value" => deep_value},
out: {inline:1}
)

My guess is that it failed because the results were just put into an instance variable and not accessed until we were out in the view. Weird, yes. Reading Mongoid's and Moped's source might confirm or provide some other reason. From a practical standpoint though, assigning a local variable worked and I have better things to do right now :)

 

 

 

Rails link_to with urls

by Martin Westin in


Being something I do seldom this little gotcha caught me today.

So, you want to put a link into an email template or a rendered pdf or something similar that requires the full url of your route. Being an email or a pdf it is also likely that the contents will be printed to just rendering our the entire url in the template can be a good thing. However...

# the basic
link_to something_url
# is not the same as
link_to something_url, something_url

The first one looks good. You get the full url including https:// and all. The gotcha is that Rails, being the opinionated and free-thinking framework it is, will strip out the url-part and just put the path part into the href. To make the visible link match the href you actually need to tell Rails explicitly that's what you want.


Writing Specifications

by Martin Westin in


I have been looking for a good workflow for writing structured text. Techincal specifications and other texts that will eventually become a pdf, Word document or similar. This post will be an overview of what I have that works pretty well. I will use Omni Outliner, MultiMarkdown, Pandoc and Rake in glorious harmony to produce the final document.

What I want is...

  • Good control over the structure
  • Flexible options for the writing environment
  • Automatically generated and updated table of contents
  • Separation of content and styling
  • Version control using Git
  • A painless "build process"

Let's see how I ended up working.

Omni Outliner

I have been outlining, and writing, in Omni Outliner for over 5 years and love it as a general purpose list-maker and organizer. In this context, each item is a heading and the notes for that heading is the body text. This works really well but is limiting on larger documents. I installed Fletcher Penney's MultiMarkdown exporter. This spits out an MD file more of less exactly as I want it. Any Markdown syntax I add into Omni Outliner will of-course be treated as markdown. Bold, italic, lists... all can be marked up in Omni Outliner.

Sadly the iOS version of Omni Outliner is more or less useless to me because of the limited file sharing support. I keep everything in Dropbox and without support for that the workflow becomes very problematic. I hope for this in a new version soon. (Yes I have used DropDAV. No good for me.)

Markdown Editors

I am still evaluating the iOS options. My favorite Markdown app for the Mac, though, is ByWord. It just feels like I am typing fast and am being productive when I am in ByWord.

Another essential (as will become evident soon) app is MultiMarkdown Composer by the aforementioned Fletcher. This app has the killer feature of being able to understand MultiMarkdown and to faithfully export that to many formats. It also has a very nice structure view in the sidebar that makes an OO-refugee feel more at home.

You can also do the trick of exporting you Markdown back to OO by exporting OPML from MMC and opening that again in OO... great stuff. Let's say that again: Using OPML as the file format allows me to instantly jump back and forth between MultiMarkdown Composer (for writing long form) and Omni Outliner (for structuring the document). Shuffling sections (chapters) around has never been easier.

The Multi in Markdown

MultiMarkdown is best explained as Markdown with a few things added to it to better support things that I have found I need in technical documents. One main feature is support for internal references allowing me to reference a section elsewhere in a large specification. E.G. "This uses Feature X which is described in [Common UI Features][]" Those brackets generate an internal link to that section and the extra brackets even allow be to be more casual in my naming of the reference and put the actual heading name inside the second pair of brackets.

Getting It Into Word, or not

I have found a good workflow where I can completely avoid using Microsoft Word. It has been a big win for me to be able to instead use a toolchain more familiar to a software developer.

If you really want to end up in Word

MultiMarkdown Composer does not handle internal references when exporting to a Word document. You have to do a round-trip into Libre Office first if you want to keep those. Yes Libre Office. OpenOffice.org couldn't open the file MMC exported. Neither could Pages or Word itself. NeoOffice cost money these days and I had no desire to pay just to try this one thing.

You open this Flat Open Document and immediately save it again as a Word document and it is ready for Word. The version I downloaded crashed every time when saving a modern Word docx document. Saving as the older doc format (for Word 2003) worked. Good Times™

Pandoc Pipeline With Rake

If you are not a Ruby developer you are probably wondering how I ended up writing about gardening. Rake is actually framework in Ruby to run tasks or macros. In this context it allows you to write pretty advanced automation for converting your Marcdown texts into formatted pdf documents with table of contents, nice design and all sorts of good stuff.

Pandoc is a document format converter. It can take Markdown, for example, and turn it into html, pdf and even a word document. Notably with a little help it can give you a pretty solid E-book build process by taking the pdf and processing it into Epub and Mobi formats for iPads and Kindles respectively.

My rake task locates all markdown documents in a certain folder and processes them all using Pandoc finally outputting nice looking pdfs in a separate folder.

Standing On The Sholders of Giants

I have based my Rake and Pandoc pipeline heavily on that used by Thoughtbot for their E-books. Go to their products page and buy any one of their books and you will get acces to the "source code". That is their entire markdown source text and their rake tools to build the books. Awesome.

Latex, The Not So Fun Part

I leaned heavily on the Latex documentation and examples to hack my way towards to document that looks the way I want. Latex is a horrible nasty markup language for electronic book layouts. It is very powerful but oh so strange and hard to read. If you grit your teeth enough you will be able to style your documents to look pretty much the way you want them to. It is just not a lot of fun but once done that template can be applied to any future document you write.

Version Control

Markdown is just text. Rake is just source code. Latex is also code/text. All this is very well suited to version control. Using Git I get all the conflict resulition help you can ask for and a solid system for tracking changes over time.

Quick Note On Pages

Pages does have a structure mode that looks pretty good. I havent played with it extensively but if you don't want the massive conversion mess described above, then Pages may support enough structure manipulation for you to be happy there... if the iOS integration is to your liking that is. Which is my other reason for going with Markdown.

Disclaimer

Some readers may shake their head and say: I can do all that, and more, in Microsoft Word. Well, good for you. I couldn't figure out that program if my life depended on it. If you know it well and can operate on the structure of your document, move things around, automatically re-assign formatting based on the relative position of something in the overall hierarchy... I'm happy for you and would actually love to know how you work. Personally, I cannot even get Word to properly paste text without going to through the menu using 4-5 clicks.


Shelling out from a ruby app to a ruby app without bundler conflicts

by Martin Westin in


My case is that I have a Rails app. It uses Bundler to manage its Gems. I also need to run some processing using an old version of one of my own libraries which also has dependencies and gems that need resolving. I chose to make this a small command line app with an executable ruby file. This little tool uses Bundler to manage its Gems.

I will shell out to this executable from my Rails app. Simple, right? I thought it would, but there was a gotcha. The Rails app executes the external ruby file within the same "bundle" as the Rails app. I.E. I got the current versions of my lib and all gems.

After much Googling I combined one Stack Overflow answer with a note on some blog (lost both references).

some_result_value = ""
Bundler.with_clean_env do
  Dir.chdir "/path/to/rubytool"
  some_result_value = `./bin/rubytool param1 param2`
end

The key details here are the clean environment AND that I change directory before executing. I don't understand why changing the folder would be significant. It may even have been bad late-night mojo.

Anyway, as long as the command line tool being called uses bundler correctly it works ar intended. It is run with its own bundle of gems.

I would like to find a way to control this from the receiving ruby script but I have not looked into that yet.


Winning Two GSMA Global Mobile Awards

by Martin Westin in


Yesterday, Feb 28 2012, Great Connection Inc, the company I co-founded and work for, won two GSMA Global Mobile Awards. We won both categories relating to healthcare and both our nominations. As this is the equivalent to an Oscar or a Grammy in our industry, but far less glamourous, it's pretty awesome.

We won for Best Mobile Health Innovation and mWomen Best Mobile Product or Service for Women in Emerging Markets. As the product designer, lead developer and inventor I am most touched by the the fact that the Judges comments seem to recognize the work of my co-developer and myself.

Good initiative concerning maternal health. Nice convergence of a number of technologies in a critical area of need.

It is not easy to grasp a technical system and product like ours. Mobile Baby spans two very different industries: healthcare and mobile, and also cross many "glass walls". Professional and consumer, men and women, rural and urban and many others. We have built a product that is irreverent towards pre-conceived notions in both healthcare IT and mobile communications and struggle to be understood and accepted in either industry.

The TL;DR or what Mobile Baby is that we connect medical imaging equipment, mainly ultrasound, to the internet and run a hosted "cloud" system tailored to making geography and time a non-issue in the healthcare workflow. Images are available in clinical grade formats online in our web-based application and can be downloaded and opened in Imaging workstation software on iPhones, iPads or "real" computers.

The feature that most people can relate to is the systems ability to provide expecting parents with high-rez images and videos in consumer-friendly digital formats for viewing at home and forwarding to family and friends. The same messaging features that give parents images on their phones is also used to alert doctors of new cases and examinations.

Anyway. I am proud, both for myself but most for my colleges and partners at Qualcomm and Etisalat. Without all these people (too many to mention) and their ability to connect with people and generate interest, hype and trust, I would still be designing this product in even more obscurity than today. :)


Looping through large and slow datasets in Ruby

by Martin Westin in ,


I recently had the pleasure of needing to load 30'000 records from MongoDB and then performing slow and memory intensive processing on them. Basically you can imagine it as a database of videos and MongoDB was holding the metadata and other bits but the actual video files were on disk somewhere. My parsing involved loading in the entire video in memory and doing "stuff" with it as part of my model object. This is how I did it.

Take 1

At first I just did the normal Model.all.each... This worked fine for smaller datasets but on larger sets the whole thing would crash after 40 to 60 minutes (I never timed this in detail). MongoDB had timed out and I figured out that my ODM (Mongoid) was keeping an open iterator in MongoDB and fetching one document at a time from the DB... and after an hour or so the DB had had enough.

Take 2

It was of-course trivial to force Mongoid to load the whole dataset in one go using Model.all.to_a.each... Before thinking further I set this version going. It crashed a lot faster than the first version. The reason is that each of my objects stay in the array, and in memory, and adding anywhere from 5 to 500 MB of videodata to each quickly ate all RAM I had.

Take 3

The small and funky change fixed this, making my script both time and ram "proof". This is how I will start out next time I have a long-running task.

all = Model.all.to_a # these are just simple Rails models
while one = all.pop # this is memory management
    one.do_heavy_processing # this loads in a ton of crap
end

By popping them off one by one and re-using the local variable Ruby's GC takes pretty good care of keeping the memory to a minimum.


Quick Tip: iOS and web graphics in Illustrator

by Martin Westin in


I wanted to make a note of one of these things I keep forgetting in Adobe Illustrator. It is very simple, obvious and keeps me sane while drawing UI elements.

Make sure "Align to Pixel Grid" is actually selected!

That gets you out of so much trouble. Problem is, you need to keep an eye on the transform pane since this is a per-object setting. It is nog global to everything on your canvas.

Of-course the old-school technique of placing the strokes outside (or inside) the object bounds still works and can actually help you in transferring dimensions from the canvas into CSS (which puts borders "outside" when working correctly).

(I can't believe they still haven't fixed the rounding errors that randomly occur when drawing and moving objects around.)


Patents Gone Crazy

by Martin Westin in


I am in the middle of some patent applications in the US at the same time as all the recent press about patent "trolls" going after small (and large) iOS developers. These things have made me think more than usual about the patent system. I think the root problems are the following:

  1. Legal costs or defending your patent or yourself from someone else's patent affect the whole patent system. And not for the better.
  2. Patents were meant to protect an inventor from copycats... under the aparent assumption that nonone could independently come up with something near-identical to another invention. That is: you should really only be able to patent things where the likelihood of an independent near-identical invention are slim-to-none. There is nothing in the system that requires you to prove something is a copy... it is just assumed and this works really poorly today, especially in software, where people come up with the same thing independently all the time.
  3. The key term defining what is patentable, "non-obvious to someone skilled in the arts", has eroded significantly. I believe that both the level of "skill" and how much research is required for something to be "non-obvious" have been lowered. Sometimes to ridiculous levels.

I believe the only long-term solution is to invalidate a whole lot of patents and to create a body doing these invalidations without the economic problems associated with lawsuits and courts. This is going to mess things up for a lot of companies and I am skeptical that we'll ever see a significant change.

The applications I have written should probably not be granted patents, ethically speaking. On the other hand they are no worse than many many patents already granted and the lawyers see it as a sure thing that we'll be granted these patents.

It is a very wired position to be in.