Friday, May 31, 2013

A cool post for those of us who know multiple languages

I read this cool post on Hacker News about kids who learn multiple languages from birth compared to those who learn languages later in life. The author then goes on to explain the correlation to learning programming languages.

I totally relate.  I mix Java, C# and VB.net up all the time. C# is my primary language so I usually will try to force that language into other languages with of course horrible results.

Here is the post a good read.

https://www.ibm.com/developerworks/community/blogs/c06ef551-0127-483d-a104-cdd02b1cee31/entry/how_multi_lingual_children_learn_languages9?lang=en

Jeff

Monday, May 20, 2013

HealthVault - What we learned

In the end we decided not to use HealthVault but we did learn a lot. Here are some items we learned.

Off Line connections
One of the hardest concepts to learn is the concept of online and offline connections.  Maybe it was just us but we had a difficult time learning this concept.  I am not going into the specifics however it all depends on how items are authorized with your appid and what information you are trying to get.  Make sure in your appid that you have both Offline and Online item types checked before you try to access the objects and you will save yourself a lot of headaches.  This of course is done at healthvault.com under the application configuration center.

We had patients authorize our apps and then did everything offline.  This meant we gained a few pieces of information from the persons HealthVault record and stored them in our database. We than accessed that record when we needed the record.

We wrote a little function to return the HealthRecordAccessor you need this to access the patients record here is ours


  protected HealthRecordAccessor GetOffLineAccessor()
        {
            patientObj = patientHandler.GetaPatientObj(lblpi.Text);
            OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(patientObj.Personid);
            offlineConn.Authenticate();
            HealthRecordAccessor offlineAccessor = new HealthRecordAccessor(offlineConn, patientObj.Recordguid);
            return offlineAccessor;
        }

Let me go over this code real quick

-PatientObj is an object with the patient info
-OfflineWebApplicationConnection this is the HealthVault offline connection instance important
-HealthRecordAccessor HealthVault Record Accessor you need this

Notice we passed the info we had stored in the database through the PatientObj

So now I am going to add some medication to the patients record


            Medication hvMedication = new Medication();
            GeneralMeasurement generalMeasurement = new GeneralMeasurement();
            generalMeasurement.Display = txtDose.Text + "mg";
            hvMedication.Strength = generalMeasurement;
            Microsoft.Health.ItemTypes.CodableValue codedValue = new CodableValue(txtMedication.Text);
            hvMedication.Name = codedValue;

            generalMeasurement = new GeneralMeasurement();
            generalMeasurement.Display = times;
            hvMedication.Frequency = generalMeasurement;
            AddMedicationToHV(hvMedication);

Lets go over this code real quick it is simple

Medication is a HealthVault object representing medications.
GeneralMeasurements - notice this you do this a lot in HealthVault you attempt to standardize a "coding" although we never figured out where the standard came from
Again for strength
Notice how you add the codedValue to the Medication object?
Then we add the medication object to HealthVault lets look at that code


 HealthRecordAccessor accessor = new HealthRecordAccessor(HealthVaultConnectionManager.CreateConnection(patientObj.Applicationpatientid, patientObj.Personid), patientObj.Recordguid);      
           accessor.NewItem(medication);
          return true;

Ok I skipped a few steps, but this is the gist.

I create a new HealthRecordAccessor and HealthVaultConnectionManage grab my record info from my patientobj and add a new item

How do I delete the medication?


 HealthRecordAccessor accessor = new HealthRecordAccessor(HealthVaultConnectionManager.CreateConnection(patientObj.Applicationpatientid, patientObj.Personid), patientObj.Recordguid);
           HealthRecordFilter filter = new HealthRecordFilter(key.Id,Medication.TypeId);
           HealthRecordItem item = accessor.GetItem(key.Id);
           accessor.RemoveItem(item.Key);
           return true;

Using the save items only using the method .Removeitem and the item.key

One last item and this one drove me crazy, if you want to place a file on HealthVault and then find the file again how do you do it?  Seems easy?

We did it this way

First we added the file


 string extensionName = "somename";
           HealthRecordItemExtension healthRecordItemExtension = new HealthRecordItemExtension(extensionName);
           file.CommonData.Extensions.Add(healthRecordItemExtension);
           //add the XML
           XPathNavigator navigator = healthRecordItemExtension.ExtensionData.CreateNavigator();
           navigator.InnerXml = @"<extension source=""" + extensionName + @"""><consultid>" + consultid + "</consultid></extension>";
           HealthRecordAccessor accessor = new HealthRecordAccessor(HealthVaultConnectionManager.CreateConnection(patientObj.Applicationpatientid, patientObj.Personid), patientObj.Recordguid);
           accessor.NewItem(file);
           return true;


-You have to create an extension name and a unique number for the file

So how to find it?



  HealthRecordSearcher searcher = offlineAccessor.CreateSearcher();
            HealthRecordFilter filter = new HealthRecordFilter(Microsoft.Health.ItemTypes.File.TypeId);

 filter.View.Sections = HealthRecordItemSections.All;
            searcher.Filters.Add(filter);
            HealthRecordItemCollection files = searcher.GetMatchingItems()[0];




make sure you check for nulls

 foreach (var item in files)
            {
                if (item.Key != null)
                {
                    fileGenObj.Key = item.Key.Id;
                }
                foreach (HealthRecordItemExtension extension in item.CommonData.Extensions)
                {
                    if (extension.Source == "your file name") //
                    {
                        if (string.IsNullOrEmpty(recFile))
                        {
                            foreach (Microsoft.Health.ItemTypes.File file in files)
                            {
                                if (file.Name == filename)
                                {
                                    //should be the same
                                    byte[] array = file.Content;
                                   read your file here
                                 
                                }
                            }
                        }
                    }
                }

            }

-I took some stuff out that was specific to our code
-This is .Net and >net does not like nulls check for nulls often
-Check for nulls often

Hopefully I will make a longer more complete post later.  However I wanted to make a post before we completely moved away from HealthVault.

Jeff

Thursday, May 2, 2013

Session Varibles are so easy to use

We are primarily a .Net shop so most of our technical post will be from the .Net perspective, with emphasis on C#. When you start an application most developers, myself included are tempted to use the Session variables that are oh so easy to use.  You simply store your information in the Session["object"] = object,  to retrieve your information you just remember to properly cast your object and call the Session["object"]. It is one of the easiest functions in .Net programming.

Nothing in development comes free. Open Source is free but usually cost you in other ways.  When you first create your application the default for storing your Session is in-proc which means the sessions are stored on the machine, which is no problem.  However what happens when you scale? The session does not survive from one web server to another, you must create another method to store your Session variables. The most common are Sql and state server. I am going to cover SQL, the most common. 

I honestly thought this was the best solution, then I got to examining exactly how the Sessions work.  Let's say you have a Customer object serialized to store in the SQL State Server. You store it using the simple syntax

Session["customerobj"] = customerObj;

This is what happened probably happened.
-You built the object from a database
-You stored the Session, which then stored the object in the SqlState database
-When you recalled the Session["customerobj"] then you hit the SqlState database again

So you are really hitting the database multiple times for a single Session object.  Which is why some experts say Session objects decrease performance by 15%.

The next problem, the Session object takes up RAM on the server, one of the most expensive components of a cloud solution.

So what is the solution? That will be covered in another post. I just wanted to give my perspective on a simple but costly item of .Net development.

Jeffrey