Unit Testing PowerScribe 360 – RadWhereCOM SDK


Of course no developer wants to write software that is not Unit Testable, else you going to spend 1 months building a project and 2 month debugging it! Why not get your Unit Tests started up front, then write all your use cases as unit tests and bang them one by one.

PowerScribe360 has allot of new features for Radiologists and we want to test when events get published or received, as well as fake all the internal dependencies of the COM e.g. Terminate require PowerScribe to be open, and of course when unit testing, this is a no no, as we want NO external dependencies.

So we will create a wrapper, here is the code, and you can get it from here as well:
Source Code

Note that PowerScribe360 is a class I created to wrap up the RadWhereCom into a public property e.g.

 public partial class Powerscribe360
        public IMyRadWhereCom radWhereCom;
        public Powerscribe360(IMyRadWhereCom myRadWhereCom)
            radWhereCom = myRadWhereCom;

        private void WireUpEvents()
            radWhereCom.UserLoggedIn += UserLoggedIn;
            radWhereCom.UserLoggedOut += UserLoggedOut;
            radWhereCom.AudioTranscribed += AudioTranscribed;
            radWhereCom.AccessionNumbersChanged += AccessionNumbersChanged;
            radWhereCom.ReportFinished += ReportFinished;
            radWhereCom.ReportClosed += ReportClosed;
            radWhereCom.ReportOpened += ReportOpened;
            radWhereCom.ReportChanged += ReportChanged;
            radWhereCom.DictationStarted += DictationStarted;
            radWhereCom.DictationStopped += DictationStopped;
            radWhereCom.Terminated += Terminated;

        public void UserLoggedIn(string userName)
        public void UserLoggedOut(string userName)

var ps = new Powerscribe360(radWhereCom);
ps.radWhereCom.UserLoggedOut += Raise.Event(“Foo”);

Source Code

Notice below, that if we did not MOCK RadWhereCOM, the call to radWhereCom.Terminate() in our event subscribe would fail.

The benefit is now that any “Cause” happening in PS360, we can fake the “effect” e.g.

        public void ShouldRaiseUserLoggedInEvent()
            // arrange
            var wasCalled = false;
            Hub.Subscribe(HubEvents.DictationSystem.LoginCompleted, () =>
                wasCalled = true;
            }, "Foo");
            var radWhereCom = Substitute.For<IMyRadWhereCom>();
            var ps = new Powerscribe360(radWhereCom);  

            // act
            ps.radWhereCom.UserLoggedIn += Raise.Event<RWC_UserLoggedInHandler>("Foo");

            // Assert

        public void ShouldRaiseUserLoggedOffEvent()
            // arrange
            var wasCalled = false;
            Hub.Subscribe(HubEvents.DictationSystem.PSInterop.LoggedOff, () =>
                wasCalled = true;
            }, "Foo");

            var radWhereCom = Substitute.For<IMyRadWhereCom>();
            var ps = new Powerscribe360(radWhereCom);

            // act 
            ps.radWhereCom.UserLoggedOut += Raise.Event<RWC_UserLoggedOutHandler>("Foo");

            // assert

Suppose this is in the constructor for our Powerscribe360 class:
radWhereCom.UserLoggedIn += UserLoggedIn;

Then the test above will fail if the line below is removed.
Now the code will never throw an exception when Terminate or any other PowerScribe 360 dependency is called:

Happy Coding!

Source Code

Medical Connections – DICOM and PACS (DICOMObjects)


After spending some time working with Medical DICOM Images, I have found that it can be a rather complex process to try get Image Counts off a PACS server, as the way to get it, is different when running a DICOM query at the STUDY or IMAGE level.

When CT Scans are being uploaded into your RIS server, it is very important to know what the number of images, especially for large studies with over 1000 images. So that you can ensure all images are received, so that Radiologists can start reporting immediately.

We leverage NService Bus to handle all the Study orders coming in, and the SAGA needs to know when to end, and part of the dependency is based on the number of images arrived during the import phase, akin to when a purchase order and all it’s items have been received by an order processor.

Basically, when you query a MASTER PACS server, the query level must be set to Study, and the way you get your image counts is based on a dataset field (0x0020, 0x1208).

When you query a Modality PACS server (Preferred), you use the Image Level query, and then can get the image count directly off the DicomDataSetCollection.

I have created a DICOM query Wrapper, that you can now use. Which can support backup servers to query, in the event the current server you are querying is not available. This can happen, if the PACS server is used allot, and it on the 50 connection limit.

Download Source Code

Below is how you would use the wrapper:

var preferredQuery =
    new DicomQueryManager(servers.DefaultPreferred, servers, workstation, port, o.AccessionNumber)

var masterQuery =
    new DicomQueryManager(servers.DefaultMaster, servers, workstation, port, o.AccessionNumber)
if (preferredQuery.Found)
    //Do SOmething
    var imageCount = preferredQuery.ImageCount;

Notice above, you execute a BuildPreferred() or BuildMaster(), this logic encapsulates how the query will be built, if it is a Modality server, it will set the query level to Image, and if it is a Master server, will set it to Study level. The logic then to find the ImageCount is automatically done for you.

You can get the source code for this here:

Download Source Code

NServiceBus – Some Benefits


I am not sure why, but in many organisation, there is allot of unnecessary complexity when looking at source code. From Programmers using try/catch blocks all over the show to unnecessary synchronous service calls with multiple threads, causing deadlocks on SQL Server.

I would like to give a simple example, consider this code

static ProcessOrder()
    const int workerCount = 4;
    WorkQueue = new ConcurrentQueue();
    Workers = new List();

    for (var index = 0; index; workerCount; index++)
        Worker = new BackgroundWorker();
        Worker.DoWork += Worker_DoWork;

The above code is extremely dangerous. You have no control over the load it will cause to backend calls, especially when it is calling Stored Procs etc. Secondly, it is not durable.

The above code, can easily be replaced by a NServiceBus Saga or handler, in the above, a Saga is appropriate, as this message is a Root Aggregate, we have an order to process. Sagas will provide an environment to preserve state and all the threading and correlation is all handled for you.

partial void HandleImplementation(ProcessOrder message)
    Logger.Info("ProcessOrder received, Saga Instance: {0} for OrderId: {1}", Data.Id, Data.OrderId);
    AlwaysRunForEveryMessage(message); //counts and extracts new order items.

    if (Data.OrderCount == 1)

    if (Data.InitialDelayPassed) //Expired workflow

From the above, you can see state is preserved for each unique OrderId. This Saga processes multiple order items for an OrderId. Which can be submitted at any time during the day. We do not have to worry about multiple threads, correlation is dealt with automatically, well we set the correlation id to the OrderId, so order items coming in can be matched to the correct Saga instance.

We can now get rid of the unreliable issues with in memory worker threads, and uncontrolled pounding of the database.

By using a MSMQ infrastructure and leveraging NServiceBus, these sort of issues, you find in code, can be easily mitigated.

Install NServiceBus as a service with Powershell


I have just completed a script that can be used to install a service bus host as a windows service. It is nice to use, when delegating the installs to the support team, this is always done via NServiceBus.Host.exe.

It can always be tricky parsing arguments in PowerShell. The trick is to use the Start-Process command, and isolate the arguments into it’s own variable.

Here is the two scripts.

Download the script

The one will install the license and the other installs your endpoints as a windows service. All you now need to do, is just type in the password.

It relies on a directory structure, where.

Root\ServiceNameA\Debug or Root\ServiceNameA\Release
Root\ServiceNameB\Debug or Root\ServiceNameB\Release

I hope this makes installing all your endpoints easy.

Download the script

Now, remember, if you install Subscriber endpoints before publishers, you will get a race condition, so with this script, add the endpoints in the array argument in the correct dependent order. First install all the publisher endpoints first, then the subscriber endpoints.


C# Binary Search Tree

Hi Folks,

I thought I would post source code for a Binary Search Tree Algorithm that I recently worked on.


In a future post, I will post source code for a Balanced Binary Search Tree (Red Black Tree RBTree).

Remember with an unbalanced Binary Search Tree, if you insert data in order, it will actually resemble a linked list and not a binary tree, hence why it is important to use a Balanced Binary Search Tree.

Of course, you can use built in .NET framework types like SortedSet and SortedDictionary, but for those of you that want to write your own implementation, then this can be a good starting point.

Remember, the rules for a Binary Search Tree, which will also return data in a sorted order, using your IComparer implementation.

I also wrote a method to delete nodes from a Binary Search Tree, which will treats leaf nodes, nodes with one child and nodes with two children differently.

There is allot of articles out there on BST’s, but it is important, that if you want to understand them, that you must understand the rules governing the Insertion, Deletion and Retrieval algorithms.

You can find the source code, at my repository here:

You will notice that there is also numerous unit tests for the solution as well.

You will notice that the way I delete nodes, uses a Random dice, so not to Degenerate the Binary Tree, if it was balanced, this would not be necessary.

One more thing, I have avoided recursive functions, why? Well, with large binary trees, if you use recursive functions, the stack is going to run out of memory, so avoid them all together.

Here is some code snippets of important algorithms, if you have any questions, or want to contribute to the code, you are welcome to do so.

public void Add(TKey key, TValue value)
            var newNode = new BinaryTreeNode { KeyValue = new KeyValuePair(key, value) };

            if (Root == null)
                Root = newNode;
                var current = Root;
                while (true)
                    var compareResult = Comparer.Compare(key, current.KeyValue.Key);
                    if (compareResult == 0)
                        throw new ArgumentException(&quot;Duplicate key found.&quot;);

                    if (compareResult  0)
                        if (current.Right != null)
                            current = current.Right;
                            current.Right = newNode;
                            newNode.Parent = current;

private void Delete(BinaryTreeNode node)
            var nodeType = GetNodeType(node);

            if (nodeType == NodeType.LeafeNode)
            if (nodeType == NodeType.HasOneChild)

        private void DeleteNodeWithTwoChildren(BinaryTreeNode node)
            // Use random delete method, to avoid degenerate tree structure.
            var replaceInOrderType = RollDiceForSuccessorOrPredecessor();

            if (replaceInOrderType == InOrderNode.Successor)

        private static void DeleteNodeWithOneChild(BinaryTreeNode node)
            var theChild = node.Left ?? node.Right;
            theChild.Parent = node.Parent;
            switch (NodeLinkedToParentAs(node))
                case NodeLinkToParentAs.Right:
                    node.Parent.Right = theChild;
                case NodeLinkToParentAs.Left:
                    node.Parent.Left = theChild;
                case NodeLinkToParentAs.Root:
                    node.Parent = null;

        private static void DeleteLeafNode(BinaryTreeNode node)
            if (NodeLinkedToParentAs(node) == NodeLinkToParentAs.Right)
                node.Parent.Right = null;
                node.Parent.Left = null;

        private void UsePredecessor(BinaryTreeNode node)
            var replaceWith = ReadLastRightNode(node.Left);
            node.KeyValue = replaceWith.KeyValue;

        private void UseSuccessor(BinaryTreeNode node)
            var replaceWith = ReadLastLeftNode(node.Right);
            node.KeyValue = replaceWith.KeyValue;

        private InOrderNode RollDiceForSuccessorOrPredecessor()
            if (ForceDeleteType.HasValue)
                return ForceDeleteType.Value;

            var random = new Random();
            var choice = random.Next(0, 2);
            return choice == 0 ? InOrderNode.Predecessor : InOrderNode.Successor;


Learning Field Guiding in Southern Africa


I have been spending the last 2 and half months living in the bush between Selati and Karongwe game reserve in Southern Africa, within the Limpopo province.

I am currently studying my FGASA level 1 with Ecotraining

We have been working on Tracking, Navigation, Survival, 4×4 Drives and learning loads about Mammals, Big 5, Insects, Trees and much more!

I was very privileged to encounter a Cheetah on foot, and here are some pictures that I would love to share with you.

Ecotraining is an awesome training provider, and the quality of training is superb, everyday, we go on drives and walks. This week, we have ben walking in the bush with a rifle for 4 hours in the morning and 4 hours in the afternoon, carrying a rifle as well, to learn rifle handling techniques and safety.

Typical day is:

  • Wake up at 4am
  • Coffee and a rusk
  • 5am Walk
  • 10:30am Breakfast
  • Theory
  • Exercise (Gay Time Gym)
  • Lunch
  • Afternoon walk/drive
  • Campfire and chilling
  • Get lucky with elephants next to your tent at night!

It can be very easy to over eat in the bush and exercise is a must. I started a gym group called Gay Time gym, where we do Yoga, sit-ups, pushups and many other core exercises. We also play ultimate Frisbee to keep fit as a fiddle!

It is awesome taking time out to live a simple and rewarding life style out in the bush.

I have produced a Game called Ranger Rom. You can download it for Tablet and Phone on both Android and Apple. Please download and have a play, it will teach you about wildlife.

Google Play

Apple Store

I will be off to Botswana for December, and hope to get some awesome experiences out there. Until then, Succulent Karoo!


MG 7068

MG 7100

MG 7156

MG 7289

MG 7317

MG 7467

MG 7490

MG 7854

MG 7821

MG 7819

MG 7781

MG 7648

IMG 8262

IMG 8502

IMG 8571

IMG 8609

Off to Africa – a life long dream

Hi Everyone!

It has been a while since I last posted any cool technical articles and so on. Well I am off to Africa!

I was surfing in Indonesia in April this year and that is when the penny dropped for me.

Romiko surfing indonesia

I realised that:

We make a Living
by what we Get
We make a Life
by what we Give

This was my answer. I realised that, I need to follow my passions, and it is possible to work and live life, in harmony!

This is where Ranger Rom was born.

Romiko thinking about Ranger Rom

I love technology. I take pride in the work that I believe in. Ranger Rom is proof of this. It uses state of the art technology from Amazon EC2, S3, CloudFront, Ruby On Rails, ImageMagick, Jekyll and all sort of cool stuff that could take 10 blogs to write on, seriously! Since working on Ranger Rom, I enjoy developing products, because it enriches peoples lives, but most of all, it’s fun.

I realised that I had a choice in life, and now is the time for change. Now is the time to step out from the sheep, pull the wool over the eyes of the wolf; and make a stab at something new and creative.

I might fail, I might fall hard, but at least I will have no regrets when I am 113 years of age, sitting on my bed, going – I wish I did that when I was young.

I encourage you all to live simple, keep the luxuries in life low. A lower carbon footprint and more money to go travel. You do not need to work 9 to 5, year in and year out. You can make a CHANGE and still WORK. You can do the same job but only for half the year, instead of the entire year. There is a will, there is a way!

But this has now changed, and I encourage you all to follow my New Adventures, but more important to follow your dreams and your heart. Today I have posted the first chapter, and yes, it is based on a true story. I am going to the bush for a long time. In between breaks, I will be doing crazy things to, like Paragliding from Mozambique to Madagascar and surfing enormous waves. However, my primary goal is to give back to nature. There will be breaks in between, to earn an income, but ultimately my goals is a balance between my career and what I do outside of it. I believe I can do both a 50/50 split.

Below is Ranger Rom’s first news report to read, so please feel free to join the world of Ranger Rom!

Ranger Rom – Off to Africa

Romiko and Ranger Rom in nature

Ranger Rom is all about promoting wildlife awareness by creating cool games for kids and adults to play. Scheduled for release on the IPhone and Android at the end of this month! IPad and Tablets will soon follow over the next couple of months.

Short Film, Roger”

It has been two weeks since we filmed “Roger”. This has been a truly inspiring experience and the professionalism demonstrated by everyone at The Central Coast Screen Co-op, check their website Central Coast Screen Co-Op

It was the first time I have done a film and found it challenging especially when playing the lead role. The first day went really well and I was impressed by the commitment and professional of the entire crew.

The first day of filming was at the house where Roger’s mother lived, Roger is picking up his childhood pet Parrot and exchanging some banter with his girlfriend Mandy. We also then shot the end of the film which involved driving a car and swerving off the side of the road. I was damn nervous not to swerve to much and slam the breaks to late and then plough into 20 crew members! So thanks guys for trusting me not to mow you all down!

The second day was all done within the car in front of a green screen. It was very exciting and a new experience as you really had to visualise and use your imagination whilst being cooped up inside a garage with 30 crew members trying their best to get the best shots. This I found the most challenging aspect for acting, here we had to create our own external stimuli.

The start of day 2 was a tad slow, until about lunch time when everything started to flow more nicely, however it was a challenge to keep emotions at bay, especially when you want to perform at your best and you know you can do better.

I have definitely learnt allot from the experience and had an amazing time with everyone from the crew. It felt like I had gone an a holiday and had a short term affair with someone special.

Here are some pictures from the day, and would like to thank all those involved on such a great weekend together.


Keep your eyes posted here and hopefully in coming months “Roger” will be ready to watch!

Of course, always good to have the crew list at the end Smile

Writer and Concept

John Blackhawk


Al Brooks


Robert Doyle


Graeme Mitchell

DoP/Camera Op

Brendan Palmer

1st Assitant Director

Mark Ferris

1st Assistant Camera

Max Gersbach

2st Assistant Camera

Kate Cornish

Sound Recordist

Peter Henskens

Boom Operator

Terry Wunsch


Daniel Grey

Prod Designer

Ty Batterham

Standby Props

Daniel Mitchell


Samantha Thompson

Script Supervisor

Liesl Bamback

Data Wrangler

Katey Freyburg

Unit Manager

Nathan Dalton

Bird Wrangler

Kylie Cooke

Stills Photographer

Stefan Sroczynsk

Production Assistant

Christopher Kaye

Production Assistant

John Blackhawk

Production Assistant

Al Brooks

Catering Assistant

Ryan Montgomery

Catering Assistant



Romiko Derbynew


Cathy Burnside

Polly (V/O)

Cathy Burnside

Samantha (V/O)

Meg Macintosh

Patricia (V/O)

Gianna Pattison

Blue One (V/O)

John Blackhawk

Blue Three (V/O)

Al Brooks


Katey Freyburg

Assistant Editor

Christopher Kaye

Assistant Editor

Mark Ferris

CGI Effects Artist

Alex Burgess


Jenny Harkin


The sight of all these people in uniforms does not prime creativity

(Kahneman, D. (2011). Thinking Fast and Slow, Allen Lane 2011 -  Noble Prize 2002 Economic Sciences).

Let’s rethink our culture so that our society can express themselves in a constructive manner and live a more fulfilling life during work hours. To promote conformity and to stifle expression is one of the intrinsic causes of our societies rebellious sub cultures.

So what do suites, ties and school uniforms do for us?  Another social “Etiquette” that hides the true intention of an individual, What are your thoughts?

First Cross Country milestone–Paragliding

It was Friday afternoon and Jamal and I checked out the charts for the weather and the conditions were looking good! We headed off to Manilla Paragliding in NSW at 4am on Saturday. I have been itching to fly after only being back at work for 3 days, all I can think of is to fly!

I took off form Mount Borah West and the wind was strong, whilst soaring the ridge I got parked and felt very uncomfortable, used a little speed bar to get out ahead and then did some figure of eights to gain height and turn and burn over the mountain to avoid rotor winds and turbulence on the lee side of the mountain.

Once I got over the mountain, it was all about looking at the ground for some trigger points where thermals would be released.

When I finally could see Barraba, it dawned on me that I have made my first real cross country flight and the feeling I had inside was fantastic, it is hard to describe, perhaps some form of euphoria!

I met some awesome pilots and some crazy pilots whilst away on the Christmas season, and learnt as much as I can about the art of flying, there is so much to learn and I am looking forward to learning as much as I can.

Paragliding has opened up a new avenue where you can be at the mercy of natures wrath and meet amazing people who are just as crazy!

Here is the flight path and data, just like life, it has it’s up’s and downs! Sunday, was not as great, but still a lovely flight, the conditions were very thermic on Sunday and stable, bombed out in the north west and had a long walk back for 4 hours in 45 degree heat, lesson learned? Carry lots of water and have a back up plan if you need a pick up!







Well, that’s it, if you would like to try out something new and exciting and challenge yourself mentally, then Paragliding is definitely worth a try!

Manilla Paragliding

I would highly recommend going to Manilla Paragliding, cool people and an awesome teacher. Check out http://www.flymanilla.com/

Into the sun