Skip to main content
. 2023 Oct 12;9:e1626. doi: 10.7717/peerj-cs.1626

Algorithm 3. Update the present policy.

Input: patientID, policyID, policy
Output: Boolean Status
async updatePolicy(ctx, patientID, policyID, policy)
{
    letpolicyAsBytes=awaitctx.stub.getState(patientID);
    if(!policyAsBytes||policyAsBytes.length==0){
      thrownewError({patientID}doesnotexist);
   }
    letehrRecord=JSON.parse(policyAsBytes.toString());
   if (!ehrRecord.policies[policyID])
   {
      thrownewError({policyId}doesnotexist);
   }
    letupdatedPolicy=JSON.parse(policy);
    ehrRecord.policies[policyID]=updatedPolicy;
   await ctx.stub.putState(ownerID, Buffer.from(JSON.stringify(ehrRecord)));
   return updatedPolicy;
}