A Flexible Personal Health Record Library

Dylan Segna

After spending the last few months working on accessing four different health record apis from Android devices, I thought it would be an interesting idea to create a library that obfuscates the individual differences found in each api.

I imagined it like this:

You read a measurement from one record, lets say it was weight for example.

You use the returned weight measurement and immediately upload it to a different record.

No formatting changes, new object creation or individualized method calls. Just a simple, flexible way for developers to access multiple different health record apis using the exact same interface.

How will this work? Let’s continue using the weight measurement example.

By taking the values that every weight measurement has in common throughout the web api, an object can be created that can be used by every record. It could look something like:

public class WeightMeasurement{
private double weight;

View original post 278 more words


Device Plugin Library

Dylan Segna

I have finished compiling the native Android version of the bluetooth device plugin library.
Available for download here: https://cdot.senecacollege.ca/hg/seneca-health-native/raw-file/4c88796b9ce7/libs/NexjDevicePlugin.jar

To use it in an application, you need to do the following:

Create a class that extends CordovaActivity and implements MedicalDeviceActivity
ex. public class DemoActivity extends CordovaActivity implements MedicalDeviceActivity{}

The class should have two member variables, MedicalDevicePlugin and CallbackContext.
Both take the calling activity as the parameter for their constructors.

You can now call plugin.execute() to execute various bluetooth commands.
The commands and how to execute them are:

JSONArray params = new JSONArray();
plugin.execute(“enable”, params, callbackContext);
plugin.execute(“disable”, params, callbackContext);
plugin.execute(“getBonded”, params, callbackContext);

JSONArray params = new JSONArray();
JSONObject param = new JSONObject();
param.put(“brand”, “brand_name”);
param.put(“input”, new JSONArray());
param.put(“num”, NUM_MEASUREMENTS);
param.put(“type”, “device_type”);
param.put(“address”, “”);
param.put(“serial”, “”);
plugin.execute(“connect”, params, callbackContext);

JSONArray params = new JSONArray();
JSONObject param = new JSONObject();
param.put(“brand”, “brand_name”);
plugin.execute(“disconnect”, params, callbackContext);

When the plugin has…

View original post 52 more words

MyOscar – Data

Dylan Segna

After getting requests and authentication working with MyOscar, it is time to start looking into how to push medical data into a user’s account.
The way this is done is by passing a MedicalDataTransfer object that looks like this:

<xs:complexType final="extension restriction" name="medicalDataTransfer4">
        <xs:element name="active" type="xs:boolean"/>
        <xs:element name="annotationCount" type="xs:long"/>
        <xs:element name="completed" type="xs:boolean"/>
        <xs:element minOccurs="0" name="data" type="xs:string"/>
        <xs:element minOccurs="0" name="dateOfData" type="xs:dateTime"/>
        <xs:element minOccurs="0" name="editDate" type="xs:dateTime"/>
        <xs:element minOccurs="0" name="editorPersonId" type="xs:long"/>
        <xs:element minOccurs="0" name="id" type="xs:long"/>
        <xs:element minOccurs="0" name="medicalDataType" type="xs:string"/>
        <xs:element minOccurs="0" name="observationLocation" type="xs:string"/>
        <xs:element minOccurs="0" name="observerOfDataPersonId" type="xs:long"/>
        <xs:element minOccurs="0" name="observerOfDataPersonName" type="xs:string"/>
        <xs:element minOccurs="0" name="originalSourceId" type="xs:string"/>
        <xs:element minOccurs="0" name="owningPersonId" type="xs:long"/>

The most important field to look at is the data field. This is where the actual medical data is being transferred. Before I could start transferring medical data of my own, I needed to figure out how this data is supposed to be formatted for sending.

I inputted some test data…

View original post 178 more words

MyOscar Web Services – Authenticating a Request

Dylan Segna

At the end of this post :
We had a response that looked like :

			id=##;                                  //number id of the user
			userName= myusername;                  //user's username
		securityTokenKey= ?????????????;               //a security key of random characters generated by the server

Now we are going to use this login response to authenticate a soap request that accesses the user’s protected information.

private void login(String username, String pw) {
	String METHOD = "login4";
	SoapObject request = new SoapObject(NAMESPACE,METHOD);

	SoapObject response = soap.sendSoapRequest(request, METHOD, LoginWsUrl);
	securityToken = SoapHelper.getString(response, "return/securityTokenKey");
	userId = SoapHelper.getString(response, "return/person/id");
	soap.provideAuthentication(userId, securityToken);

There are some new things in this function now, so let’s go over them.
After sending the soap request and receiving a response, the two SoapHelper.getString() functions are called to fill the securityToken and userId variables. I created this function to access nested values in…

View original post 357 more words

MyOscar Web Services – Sending a Request

Dylan Segna

I have finally gotten MyOscar web services access working, so I plan to outline how I did this in my next two posts. This first post will focus on how to send a soap request to a myOscar server.

It should be noted that I am using the ksoap2 library for creating and sending soap requests.

Here is how I went about sending a login request to a myOscar server:

static final String NAMESPACE = "http://ws.myoscar_server.oscarehr.org/";
static final String LoginWsUrl = "http://demo.oscarmcmaster.org:11245/myoscar_server/ws/LoginService";
public void login(String username, String pw) {                             
	String METHOD = "login4";                                               
	SoapObject request = new SoapObject(NAMESPACE,METHOD);                  

	SoapObject response = soap.sendSoapRequest(request, METHOD, LoginWsUrl);
	response = (SoapObject) response.getProperty("return");                    

There is alot going on here, so let’s go over this one step at a time.
Where do the NAMESPACE and LoginWsUrl variables come from?
These values come from the web services definitions provided by the developer of the…

View original post 269 more words

Accessing Withings Web Api from Android

Dylan Segna

I had a lot of trouble getting Withings’ web Api access working in an Android application.
After getting in contact with one of the Withings Api developers, I was finally able to solve the issue.

The problem was that Withings unique OAuth implementation did not work as expected with the OAuth library I was using, Scribe.
After authenticating the user, Scribe was sending all the OAuth information in an Authentication header.
However, Withings was still expecting all this authentication information to remain in the URL query string.

Here’s how I worked around this issue:

This is the basic request sending code.

private Response sendRequest(String resource, String action){
        String URL = apiBase + resource;
	OAuthRequest request = new OAuthRequest(Verb.GET, URL);
	request.addQuerystringParameter("action", action);
	request.addQuerystringParameter("userid", userId);

        Response response = request.send();
	return response;

The resource and action parameters are based on what you are requesting.
They are gotten from Withings Api documentation…

View original post 94 more words

Reading Api Key and Secret from a Json File pt.2

Dylan Segna

Part 1 here : http://dylansegna.wordpress.com/2013/11/08/reading-api-key-and-secret-from-a-file/

I left off with a string of file contents that looked like:

	"fitbitApi": {
		"apiKey": "apikeyhere",
		"apiSecret": "apisecrethere"
	"withingsApi": {
		"apiKey": "apikeyhere",
		"apiSecret": "apisecrethere"

I could easily use the JSONObject type that is provided in Android to get the information I need, however something occurred to me while looking at this.
To get an apikey, it would require three lines:

JSONObject fullObj = new JSONObject(returnedString);
JSONObject fitbitApi = fullObj.getJSONObject("fitbitApi");
String apiKey = fitbitApi.getString("apiKey");

This may not seem so bad, but what happens when json objects become nested even deeper?
I had to make a way to easily get a string that was nested within multiple json objects.
So I made another helper class: JsonHelper.java
Here’s how I solved this issue:

 public static String getString(String jsonObject, String jsonPath, String seperator){ String[] paths = jsonPath.split(seperator); try { JSONObject obj = new JSONObject(jsonObject); int…

View original post 205 more words