Saturday, March 4, 2017

Applying blockchain to healthcare - part 7 (filters)

In my last post, I showed how events could be added to the Patient smart contract so external systems can be notified when it has changed.  In this post I will show how these events can be detected from a web browser application using filters and then use them to look at how the state of the patient smart contract changed over time.  As previously mentioned, blockchain is immutable and update operations work differently than they do in normal databases.  Rather than overwriting the old value with the new one, ethereum records the change and keeps the old value around.  When interacting with a smart contract instance, the default behavior is to use the most recent state.  It is possible though to access historical state - much the same way you can access older versions of a file with a revision control system.  You can find the source code for this application here,  including instructions on how to run it on your local machine (if you have a Mac that is).

After starting the application, you are given the choice to create a new patient smart contract instance or attach to an existing one (assuming you know its address):



In this case, we don't have an existing instance so press "Create" to create a new one.  Metamask will prompt you to confirm the transaction - press "Accept" to do so:



After several seconds, the newly created patient smart contract instance will be created and stored in your private ethereum network.  The address for this newly created instance is displayed in the UI and controls appear to modify the properties of the patient smart contract:


At this point, you can set the values for the patient's name, dob and gender by entering the strings and pressing the corresponding "save" button.  Metamask will prompt you to confirm the transaction every time you press save.  After waiting a few seconds, you can hit the "Refresh" button to see the history of changes to this patient:



The change log shows a few things - the block number that contains the change, the timestamp of the block, the type of change and the values for name, dob and gender at that time point.  Recall that a blockchain is a series of blocks each of which has a pointer to the prior block thus creating a chain.  The blocks store transactions will cause changes to the state of the blockchain.

As stated before, the blockchain is immutable so all prior states are always accessible.  Changing the name from "DOE^JOHN" to "SMITH^WILLIAM" results in a new block being added with this change, but does not go back and modify prior blocks as the blockchain is immutable:



Immutability is an important concept of blockchain that has some interesting implications.  It means that records cannot ever be tampered with.  There is no human, corporation or government that can go remove or alter information on the blockchain.  Once data is added to the blockchain, it will be there forever!  In healthcare, there are few (if any) use cases for destructive changes to data.  This makes blockchain an excellent fit for storing medical records.  Most healthcare applications today have poor (if any) support for accessing historical changes to medical records.  With blockchain, keeping track of changes is automatic and doesn't require any special coding by developers.

You should now have a better understanding of immutability, how it applies to healthcare.  You should also have a better understanding of the ethereum event and filter mechanisms.  Next up is exploring the concept of identity management and trust with blockchain.







4 comments:

  1. Hello Chris
    I've been reading your posts about applying blockchain to healthcare and It's actually interesting.
    I tried to run the code of the ethereum events I followed the steps that you mentionned (adding metamask,running the code using meteor...).I already have my private network that I created using geth. When running http://localhost:3000 I get No web3 provider detected I looked into the code and I found that maybe I have no web3 so I ran meteor add ethereum:web3 but still the same error could you please tell me it could possibly caused by what? (PS :I'm using windows 7) Thanks

    ReplyDelete
  2. Hey Chris, Its good to see that Blockchains that support external scripting, such as Ethereum, generally make the implementation of such contracts very easy with only a few lines of code.

    ReplyDelete

  3. Heyy, Awesome Post .. Keep It Up!

    Want to invest in Crypto Currency, Invest in STECH coin Now, one of the best cryptocurrency to invest. Our reliable and robust social network allows the seamless transfer of cryptocoins within no time! Easy to use, purchase and trade. Grow your investment upto 200%. To check click or visit: https://www.stechcoin.com/

    Stech coin contact | Cryptocurrency Exchange | Stech coin Distribution | Digital Cash Cryptocurrency

    ReplyDelete
  4. Failed Metamask transactions occur when a transaction sent through the Metamask wallet fails to be confirmed on the blockchain. This can happen for a variety of reasons, including insufficient gas fees, incorrect transaction details, or network congestion.

    ReplyDelete