# Smart Contract-Enabled Secure Sharing of Health Data for a Mobile Cloud-Based E-Health System
## 5 Implementations
### Design of an Access Control Mechanism  
We created a smart contract to establish the proposed access control mechanism. In addition, we created a central component that depicted the working process of the EHR distribution system, as shown in Algorithm 1.  
```
0:Transactions (Tx)
0:Authorized or block Initialization:EHR Owner
1:New transaction Tx from patient
2:Collect the Pu of the patient \(PK\gets Tx\).getSenderPublicKey0
3:Send the public key to Admin for verification
4:ifPK is available in the policy list \(p\)L(PK) \(\leftarrow\) true
5:end
6:decadeTx \(\leftarrow\) chimnaDecoder.decode (Tx)
7:Addr \(\leftarrow\) web3.eth.getData(decodeTx([Datal Index])
8:Specify AreaID and PatientID \(\leftarrow\)\(A_{ID}\)Add(Index[\(A_{ID}\)]); \(P_{ID}\)Addr(Index[\(P_{ID}\)]) EHRs Retrieval (Consensus Algorithm)
9:while true do
10:if\(p\)L(\(A_{ID}\)) \(\rightarrow\) true then
11:if\(p\)L(\(P_{ID}\)) \(\rightarrow\) true then
12:\(\textit{Result}\leftarrow\)retrieveEHRs(PK, Addr)
13:break;
14:else
15:\(\textit{Result}\leftarrow\textit{penalty(PK, action)}\)
16:break;
17:else
18:\(\textit{Result}\leftarrow\textit{penalty(PK, action)}\)
19:break;
20:end
21:end
22:return Result;
```  
**Algorithm 1** Proposed Access Control Algorithm  
To observe the transaction activity of the smart contract, we first constructed a data sharing contract managed by administrators. In the blockchain, we refer to the recipient's public key as PK, the recipient's role as userRole, and the recipient's address as Addr.  
The following tasks are performed by the contract:  
* AddUser (PK, userRole): This was processed using Admin. This procedure enables new users to be added to the primary contract. The user is authenticated by his/her public key and has been assigned a position throughout the contracts depending on his/her requests. User information is recorded and stored as an element of the database server.
* DeleteUser (PK, userRole): This is executed by Admin, who can remove the user. It is used to eliminate user access based on the public key that corresponds to the user. Consequently, all private details were removed from the data storage.
* PolicyList (PK): A sequence of policies executed by admin. A colleague of a healthcare professional and patients may consent to a protocol that describes the professional relationship. For instance, a patient may have a single doctor or several physicians who need access to a patient's electronic health records (EHRs) to provide suitable healthcare services. When a smart contract executes transactions, policy reports consisting of all parties' public keys are verified.  
* EHRsRetrieve (PK, Addr): This is executed by an EHR manager who enables health records to be retrieved from cloud services. The smart contract requires a networking operator to supply the physician's geolocation, Patient ID, and Area ID. The contracts subsequently evaluate the information and send communication to the EHR administrator, instructing him/her to retrieve and provide information to the applicant.
* Punishment (PK, action): This is executed by the administrator; whenever the EHR administrator detects an unlawful demand from the system, the contract is notified, and the user is penalized. Consequently, we issue an alert signal to an illegal mobile person in public.