# Blockchain-Based Distributed Patient-Centric Image Management System
## 4 Overview of the PCIM System
### Ethereum Network: PCAC-SC Protocol  
We use the Ethereum SC to enforce access control policy on patient medical image on-chain contents. The SC stored in the Ethereum blockchain designed to contain unique image id, permissions, metadata and image integrity of the individual patient. The PCAC-SC protocol uses special functions to provide information about the blockchain and image access privileges for _IRs_. Furthermore, protocol helps in tracking all the on-chain activities of all participants. The functions of SC are triggered by a patient and _IRs_ entity using their own Ethereum addresses. Thus, transaction costs reduced by using embedded protocols to reduce administrative burdens and remove intermediaries. All triggered functions are stored within the blockchain ledger as events to allow the entity keeping track of the transaction details. This enables transparency in the triggered functions and maintains the anonymity of patients by displaying only events stored in the blockchain. In this framework, we used a single variable, and the following functions:  
_msg.sender_: the address variable of the owner who interacts with SC. _create_contract()_: this function is created and executed only by a patient to issue corresponding roles for _IRs_ and related information for accessing medical images. As shown in Algorithm 1, this function takes as input a patient's encrypted medical image hash value \(h(\overline{I_{p}})\), blockchain address \(\Phi_{P}\), image description \(\Delta_{P}\) and the timestamp when the function was executed by SC. ```
Input:\(h(\overline{I_{p}}),\Phi_{P}\), \(\Delta_{P}\) Output: bool
1:if msg.sender is not \(\Phi_{P}\)then
2: throw;
3:end
4:mapping \(h(\overline{I_{p}})\) to (\(\Phi_{P}\)) and add it to ledger
5:return true;
```  
**Algorithm 1**_create_contract()_  
_requesting_access()_: this function is executed by _IRs_ to obtain access permission from the patient. _IRs_ includes as input the patient blockchain address \(\Phi_{P}\) and _IRs_ public key \(K_{IR}^{+}\) to encrypt medical images and additional information, such as usage notes as shown in Algorithm 2. _approve_IRs()_: this function can only be executed by the patient. As shown in Algorithm 3, it grants/denies access permission by using as input the _IRs_ blockchain address \(\Phi_{IR}\), _IRs_ public key \(K_{IR}^{+}\), and notes from _IRs_. The input notes contain relevant information such as the expiration date and message for requestors. ```
Input:\(\Phi_{IR}\), Notes Output: bool
1:if msg_sender is not \(\Phi_{P}\)then
2: throw;
3:end
4:if\(\Phi_{IR}\) exist then
5:return false;
6:else
7: authorize_User[\(\Phi_{IR}\)] \(\Leftarrow\) true;
8: mapping \(h(T_{p})\) to (\(\Phi_{IR}\)), and add it to ledger
9:return true;
10:end
```  
**Algorithm 3**_approve_IRs()_  
_trace_authorization()_: this function executed by _IRs_ and patients to track the history of approved or disapproved requestors in the blockchain. Thus, participant authenticity to access patient medical images verified by calling this function. The following Algorithm 4 used by the _trace_authorization()_ function. ```
Input:\(\Phi_{P}\),\(\Phi_{IR}\) Output: bool
1:if msg_sender is not \(\Phi_{IR}\)then
2: throw;
3:end
4:if\(\Phi_{IR}\) exist then
5:return true;
6:else
7:return false;
8:end
```  
**Algorithm 4**_trace_authorization()_  
_remove_IRs()_: this function takes the approved _IRs_ blockchain address \(\Phi_{IR}\) as input and removes _IRs_ from SC upon successful execution of a function by the patient as defined in Algorithm 5. Consequently, SC is updated. Therefore, the removed _IRs_ has no privilege to access the medical image contents stored on-chain. Note that, this function used to record the log of removed entity in the blockchain as a proof. Thus, the participants are legally not allowed to access the medical images.