Bell Eapen MD, PhD.

Bringing Digital health & Gen AI research to life!

How to visualize PKPD models

PKPD Visualization

Image credit: Farmacist at ro.wikipedia [Public domain], from Wikimedia Commons. (Image altered and text added)

A couple of my friends asked me about ideas for PKPD visualization for their projects. I am not a PKPD expert, but I have tried to organize some of the tools for this purpose that I have found during my search. Maybe it will help someone to avoid reinventing the wheel.

First a brief introduction to the problem as I understand:

Pharmacokinetics (PK) is what the body does to the drug (elimination or redistribution). Pharmacodynamics (PD) is what the drug does to the body (Its effect). PKPD models conceptually link both into a composite time-effect graph. Calculations associated with this conceptual linking can be quite complicated, but computers simplify this considerably.

Now a brief consideration of the variables in this calculation, again as I understand.

The calculation depends on elimination process, number of compartments, route and the regimen of drug administration.

You need clearance rate (CL), the volume of compartments V1…V3 and the intercompartmental clearance (Q1 & Q2).

A PKPD model can be described as systems of ordinary differential equations in PharmML for the number of compartments and the route of administration.

Now to the emerging concept of population pharmacokinetics:

In the above model, individual variations are not taken into account. You can calculate between-subject variability matrix if you have enough data available from various sources.

Now to the visualization options:

Visualization is important for patients to understand the need for dosage requirements in life threatening conditions like haemophilia and for doctors to plan appropriate dosage regimens.

PKPDSim by Ron Keizer (UCSF) – This is an R library that also provides a model exploration tool that dynamically generates a Shiny app from the specified model and parameters. ODEs for One, two and three model for various routes of administration is available in the library. Custom ODEs and between-subject variability can be defined. Shiny allows interactive exploration of the model, and it also generates the R code for any plot created in the interface. Shiny is R’s web application framework that turns your analyses into interactive web applications.

The example code to run shiny after installing all dependencies is below:

install.packages("devtools", dependencies = TRUE)
install.packages("ggplot2")
install.packages("shiny")
library(devtools)
install_github("ronkeizer/PKPDsim")
library(PKPDsim)

p <- list(CL = 38.48,
          V  = 7.4,
          Q2 = 7.844,
          V2 = 5.19,
          Q3 = 9.324,
          V3 = 111)

omega <- c(0.3,       # IIV CL
           0.1, 0.3)  # IIV V

sim_ode_shiny(ode = "pk_3cmt_iv",
              par = p,
              omega = omega)

 

Simulx: (A R function of the mlxR package for computing predictions and sampling longitudinal data from Mlxtran and PharmML models.). Details are available on their website: Here is a PKPD example for warfarin. Simulx also supports interactive visualization through Shiny

Plotly is an innovative Canadian startup founded by Alex Johnson, Chris Parmer, Jack Parmer, and Matt Sundquist headquartered in Montreal, Quebec. Plotly is an online analytics and data visualization tool that has a variety of tools such as API libraries for various programming languages, and a javascript library. Plotly may be the ideal tool for fast visualization of PKPD data.

To sum up:

R libraries and hosted shiny applications may be ideal for physician level PKPD interface. plotly may be ideal for prototyping patient education tools that can be later converted into a web application using the various APIs.

P.S. Shiny example for PKPDsim is not functional at the time of writing. Ron has promised to fix it soon.

Phonegap and AppPharmacy – Just what the doctor ordered!

Phonegap for mHealth

Image credit: Unsplash@pixabay

Health Care is getting swathed in mobility and mHealth. Though the term is not yet adequately defined, mHealth is the new buzzword. mHealth, unlike many other eHealth specialities, has provider/doctor and consumer/patient aspects. This dual nature helps mHealth to be instrumental in improving the quality of care delivery and patient empowerment. mHealth will also play a major role in population health.

With more than 100,000 mobile Apps available for download from Google play and Apple App store, it is difficult for consumers to choose what may be of benefit to them. It is hardly surprising that only a handful of these 100,000 apps is being used in a meaningful way. Very soon, apps may make their foray into a doctor’s prescription. There may even be App-Pharmacists who would create/reconstitute and dispense an app that the doctor ordered. Custom made apps may also be needed for clinical trials in population health such as HOPE-4 of PHRI.

The App-Pharmacists must be able to prototype an app within a short time with a highly ‘agile’ software development cycle. This article is an introduction to ‘phonegap’, which I believe would be the ideal tool for the App-Pharmacists of tomorrow. A basic idea of phonegap would help eHealth professionals to evaluate the opportunities and limitations of this platform!

Healthcare apps could be Web apps, Hybrid Apps or Native Apps. Web apps are just responsive websites that fit the mobile device well, using any of the frameworks such as jQuery mobile. Obviously it is the easiest to build and maintain, but it cannot access mobile specific features such as camera and GPS. If the app is used only to display information (as in ClinicalConnect™) this is the best solution.

Hybrid apps are packaged in a full-screen browser to resemble a native mobile app, with extensions that provide access to some hardware features, but your user interface is still written in HTML/CSS and rendered by a web browser. Phonegap is a popular framework to create hybrid apps. Phonegap was initially called Cordova after a street in Vancouver where the parent company Nitobi was based.  Adobe bought phonegap and licensed it under Apache. Though you don’t generally associate open-source with Adobe, phonegap for all practical purposes remains free and (hopefully) will remain so in the future.

So why should you use phonegap?

  1. It is free.
  2. Nothing new to learn, You program in HTML, CSS and javascript.
  3. Compile in the cloud (Free if your project is on github and open-source!)
  4. Fast prototyping with basic debugging in the browser.
  5. Fast build cycle, with a single interface for all major platforms.

Where can you get Phonegap?
Get it here: http://phonegap.com/

OR install using npm

sudo apt-get install nodejs nodejs-dev npm
sudo npm install -g phonegap
phonegap create my-app
cd my-app
phonegap run android

You may have to revert the ownership of .npm folder back to the user after global install.

 

chown -R <username> ~/.npm/

Want to see a simple, but working project to learn fast?
Try my Charm!: https://github.com/dermatologist/phonegap-charm
Want to know about Charm?: http://gulfdoctor.net/charm/

Do you want a step by step tutorial on how to start using phonegap. Please comment below!

Not happy with phonegap? Will discuss Titanium soon!

AngularJS and Electronic Health Records

I am not an Angular expert (as yet) though I used it for one of my successful applications called LesionMapper™. For the uninitiated, AngularJS is (yet another) javascript framework that is different in many ways. It extends HTML and implements the exciting concept of two-way data binding for dynamic web apps. If you are still skeptical about whether angular is big, please take a note of their logo that has a small (in)significant subscript: ‘by Google’. My intention here is not to dissect AngularJS and compare its many features or to disambiguate the diverse terminologies such as ‘directives’ and ‘expressions’ that makes it seem more daunting than it actually is.

Photocredit AngularJS @ github and jfcherry @ flikr (Images altered)

For health professionals, the bottom line is that AngularJS makes browsers powerful and can perform some of the tasks that are traditionally relegated to the server. So how is it going to improve our EMRs? During my student days, I have seen a popular regional EMR with a dismal user-interface. I have also seen a health analytics platform with more than 100 dropdowns on a single page. I have seen doctors returning to paper after failed EMR experiments. I have seen regional clinical viewers reeling under usability concerns. Can angularJS make any difference?

when I see a company mentioning they use angular, I read it as: no tech insight, no vision, hates life. #AngularJS
— Fredrik Carlsson (@fizk) November 15, 2014

A tool cannot change everything. Angular as a tool is not going to be a panacea. But the concept may change the way we think and organize our electronic health record systems. The traditional way of seeing EMRs as data-centric models was rejected by us, health professionals. Blame it on technology averse senior doctors or blame it on the inefficient healthcare system not learning from banks and airline industry, the fact is, eHealth failed to deliver! Will a new version with an improved interface change this? Unlikely!

EHealth has to accommodate our workflow, not the other way round. Because EMR is the tool, not us, physicians!

I know this is not my idea, and we have discussed this here before. How can AngularJS change this?

AngularJS could effectively separate presentation from storage. Our data scientists could work on the data layer (let me call it enterprise EHR) and concentrate on interoperability and population health. Our interface experts could work on the presentation layer customizing it for each department and each doctor, accommodating their workflow. (Let me call it Bring Your Own EMR #BYOE). We need a glue to bring both sides together. My vote is  for JSON/REST in the short term and RDF in the long term.

I am a huge fan of reverse innovation, and I am excited to see initiatives such as http://www.bahmni.org/ building AngularJS based customization layer on top of OpenMRS.org. True open source projects such as OpenMRS foster innovation (reverse or not).. It should open the eyes of others calling themselves open-source without being truly open! (Well.. that is another story..)

Related articles

Facebook and Ajax

Christmas pudding decorated with skimmia rathe...
Christmas pudding decorated with skimmia rather than holly. (Photo credit: Wikipedia)

Today is the last day of my Christmas break and the winter term will officially start tomorrow. I did use my break in a productive way as I mentioned in my post last week. To continue with my exploration, I found out two more things the hard way. So I thought I would share it here so that you guys can probably save some time.

I decided to learn how to make a facebook app. So I registered for a developer account and got my AppID and secret key. I made a word game in php for dermatology and decided to port it to the facebook canvas. The facebook interface asked for the normal application URL and the https URL. Near the https field, it is mentioned that https is a requirement from Oct 11th onwards. Since it is only the beginning of 2014 with a good 10 months to October, I decided to leave the https blank. The form submission was accepted without any problems and I was given a new ‘blank’ canvas.

Despite my best efforts at debugging, the canvas remained perpetually blank. After hours of googling, I found out the bitter truth. The October 11 is not Oct 2014, but Oct 2011 and is over 2 years back! So facebook needs a secure https URL for displaying external apps in the facebook canvas and it is mandatory for the last 2 years. I have no complaints about facebook’s security policies and probably this is a good thing. But why the Oct 11 is still mentioned there without the year, and why the form is getting validated without an https url still!!

The other thing I found out the hard way was the (simple fact 🙂 ) that: Ajax is basically javascript obeying the Same-origin policy. Your backend php script (or any other script) should be on the same server. Again no complaints, but……

Here is my DermGame who could never make it to the facebook, but got a facelift with Ajax. Sorry for the mangled interface and template.

Deploying Java applications with embedded derby database

Ruby on Rails
Ruby on Rails (Photo credit: Wikipedia)

I have been trying to brush up my programming skills during the christmas break. I recently added the tagline “Dermatologist who codes” to my elevator speech. My plan is to sharpen my java skills and to learn python and ruby on rails. I believe coding real world applications is the best way to learn/sharpen any programming language.

Here is the first innovative application, Dermatology Image Tagger that I made. I believe this would be quite useful to dermatologists for organizing clinical images. Afterwards I made a simple java database application for a colleague. I never explored the deployment of java applications before. I hit google to find useful resources, but found only very few. The one I found most useful was Aparna’s blog. Here she succinctly explains how to use the Java embedded derby database. The only thing I had to figure out the hard way was to use the connection string as below to force creation of the database in the working directory. I also added a ‘create table’ button for initial deployment.

 String host = “jdbc:derby:imfdb;create=true”;
            String uName = “your_username”;
            String uPass= “your_password”;
            con = DriverManager.getConnection(host, uName, uPass);
            stmt = con.createStatement();

She has also written an very useful article on deploying java desktop applications. I followed her instructions to package all required files into a single executable jar file for Mac and an exe file for windows. I have used this for DIT. Thanks Aparna for making life easy for me!

Pink in honor of breast cancer awareness programs
Pink in honor of breast cancer awareness programs (Photo credit: beapen)

I am still exploring python and Ruby on Rails. So far I have been really impressed by the way Ruby on Rails managed to make web application development intuitive. I also learnt git for version tracking and joined github. I have added few learning projects for python and RoR that may be useful applications if developed properly. Feel free to fork, watch or star them and if you are on github too, a follow will not hurt.

So this will be my last post for 2013. Will meet you all again in 2014.