Angela Gilhotra / Writings



24 May 2019

Health Insurance ft. The Blockchain

by Angela Gilhotra

Last September, I was tasked with the development of a Prototype of a Health Insurance Network on the Blockchain, in 30 days. The aim for building the prototype was to identify fraud in insurance claims or prescription.

Through this post, I’d like to share the important building blocks that went into the development of the final prototype.

Defining key players

To keep the implementation as crisp and simple as possible the key players were reduced to the following:

  1. An Insurance Provider - maintainer of the network
  2. A doctor
  3. A patient
  4. A medical shop owner

Note that there can be several instances of a doctor, patient or medical shop owner, but there exists a single Insurance provider, who also acts as the maintainer of the network.

Choosing tools

There were quite a few options and criteria I considered while choosing a blockchain framework. My major constraint being time, I prioritized familiarity with the code-base and quick prototyping over everything else.

I chose Hyperledger Composer because of:

(a) its simplicity

(b) clear framework and division of the network into: assets, transactions and participants

(c) easily extensible to a more robust network on Hyperledger Fabric

(d) easily testable

Taken from Hyperledger Composer Documentation

The files are very clearly organized into separate directories concerning model of the network, transaction logic of the functions, access control of the participants and a query file (wasn’t used in this prototype).

Determining Transactions and Assets

The working of the entire system can be broken down into the following set of ‘transactions’ or functions that perform transfer of an asset from one participant to another participant, or the creation of a new asset.

The following is code for defining transactions from the .cto file, that stands as a model file for assets, participants, transactions and events.

the --> represents an asset while an o represents a data type that the transaction function would take as input. (Transaction functions are defined in the logic.js file.)

  1. Initiated by the patient to the medical shop owner
    
     transaction GetMeds {
     --> Prescription prescription
     --> Claim claim
     --> Patient patient
     o String reqId
     }
    
  2. Initiated by the medical shop owner on completion of medicines request
    
     transaction CompleteMedReq {
     --> MedReq request
     }
    
  3. Initiated by the insurance provider to create an insurance product
    
     transaction CreateProduct {
      String productId
     o Double premium
     o Double cover
     --> InsuranceProvider provider
     }
    
  4. Initiated by a patient to buy a particular insurance product
    
     transaction BuyProduct {
     --> Product product
     --> Patient patient
     }
    
  5. Initiated by the doctor
    
     transaction CreateDiagnosis {
     --> Doctor doctor
     --> Patient patient
     o String description
     o String diagnosisId
     }
    
  6. Initiated by the doctor
    
     transaction CreatePrescription {
     --> Doctor doctor
     --> Patient patient
     o String description
     o String prescriptionId
     o Integer validityDays optional
     }
    
  7. Initiated by the doctor
    
     transaction GenerateBill {
     o String billId
     o String description
     --> Patient patient
     --> Doctor doctor
     o Double amount
     }
    
  8. Initiated by the patient to File a claim; Can be filed once prescription, diagnosis and bill have been received; Creates a new Claim asset, with status PENDING
    
     transaction FileClaim {
     o String claimId
     --> Prescription prescription optional
     --> Bill bill optional
     --> Patient patient
     --> Product product
     --> Doctor doctor
     o ClaimStatus status
     o ClaimType type
     }
    
  9. Initiated by the doctor; sets claim status to APPROVED, unless it has previously been rejected
    
     transaction ApproveClaim {
     --> Claim claim
     }
    
  10. Initiated by the doctor; sets claim status to REJECTED
    
    transaction RejectClaim {
    --> Claim claim
    }
    
  11. Initiated by the insurance provider; sets claim status to SETTLED, unless the status was REJECTED and only if the status was APPROVED
    
    transaction SettleClaim {
    --> Claim claim
    }
    
  12. Initiated by the insurance provider sets claim status to REJECTED
    
    transaction RejectClaimFromProvider {
    --> Claim claim
    }
    

Events

Currently the demo emits four events:

  1. Claim is filed by the patient
    
         /*
         this event is emitted when a claim is filed 
         by the patient and subscribed to by the doctor 
         and the insurance provider
         */
         event FileClaimEvent {
         --> Claim claim
         --> Patient patient
         --> Doctor doctor
         }
    
  2. Claim is Approved by the doctor
    
         /* emitted when a claim is approved by the doctor, 
         subscribed to by the patient and the insurance provider
         */
         event ClaimApproved {
    
  3. Claim is rejected by the doctor or the provider
    
         /* 
         emitted when a claim is rejected 
         by the doctor or the provider, subscribed to 
         by the patient and the insurance provider
         */
         event ClaimRejected {
         --> Claim claim
         --> Patient patient
         }
    
  4. Claim is settled by the provider
    
         /*
         emitted when a claim is settled 
         by the provider, subscribed to by the patient
         */
         event ClaimSettled {
         --> Claim claim
         --> Patient patient
         }
    

Starting and Stopping the Network

If you’d like to go through the prototype or build upon it (I’d highly appreciate that), follow the steps given here to install the dependencies.

Once the dependencies and development environment are set up, and the repository has been cloned and cd’d into, follow the steps below:

Start Fabric

  1. Start Fabric Dev server cd fabric-dev-servers && ./startFabric.sh
  2. Create a Peer Admin Card ./createPeerAdminCard.sh
  3. Increment the version number in package.json
  4. create a cd .. && composer archive composer archive create -t dir -n .
  5. Install network composer network install --card PeerAdmin@hlfv1 --archiveFile ensure@0.0.1.bna (change version number)
  6. Start the network composer network start --networkName ensure --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card (change version number)
  7. Import card file composer card import --file networkadmin.card
  8. Ping the network composer network ping --card admin@ensure

Once the prototyping is done, follow the steps below to kill docker images

Stop Fabric

  1. Kill 8080/tcp process sudo fuser -k 8080/tcp
  2. Run stop fabric script cd fabric-dev-servers && ./stopFabric.sh
  3. Teardown data structures ./teardownFabric.sh
  4. Kill docker containers docker kill $(docker ps -q)docker rm $(docker ps -aq)docker rmi $(docker images dev-* -q)
  5. Delete cards from composer cards composer card delete -c admin@ensure
  6. Delete .bna file and .card file from the folder

tags: hyperledger - blockchain - health insurance - prototype