## 5 Methodology
### Design of Privacy-Preserving, Patient-Centric Health Record Access Control
#### 5.4.2 Algorithm  
The flow of information and details of how the patient-centric health records access control framework uses blockchain through a generic algorithm is shown below in Algorithm 1. ```
1:The hospital HS creates or updates a patient health record PR
2:patient P chooses an appointment with doctor D during time T on date DA
3:Patient P gives permission to doctor D
4:if\(Permission==\ AllOW\ AND\ Role==\ DOCTOR\)then
5: Access is given with number of access N in time T \"read and write access\"
6:else
7: Permission=Deny
8:endif
9: Blockchain Admin B takes the permission from patient P and stores the health record in the clinic of doctor D in time T
10: Doctor performs lab tests for patient [PERSON] during same time T
11: Delegate permission to HEALTHCARE PERSONNIel HP \"such as lab technician or pharmacist\"
12:if\(Permission==\ AllOW\ AND\ Role==\ HEALTHERSON\)then
13: Give access with number of access N in time T \"read-only access\"
14:else
15: Permission=Deny
16:endif
17: HEALTHCARE PERSONNIel HP needs to update the lab results in the patient's health record \"write access\"
18:if\(Permission==\ AllOW\ AND\ Role==\ HEALTHERSON\)then
19: Give access with number of access N in time T \"read and write access\"
20:else
21: Permission=Deny
22:endif
23: Doctor D needs to change the medicine after the result is finished and time T is finished
24: Patient P gives permission to doctor D
25:if\(Permission==\ AllOW\ AND\ Role==\ DOCTOR\)then
26: Give access with number of access N in time T \"read and write access\"
27:else
28: Permission=Deny
29:endif
30: Blockchain Admin B takes the permission from the patient P and stores the health record in the clinic of doctor D in time T
31: Family member FM Gives permission to emergency doctor [PERSON] when patient [PERSON] is in an emergency situation on has had an accident
32:if\(Permission==\ AllOW\ AND\ Role==\ EMERGENCYDOCTOR\)then
33: Give access with number of access N in time T \"read and write access\"
34:else
35: Permission=Deny
36:endif
37: Blockchain Admin B takes the permission from patient [PERSON] and stores the health record in the Emergency area of emergency doctor [PERSON] in time T
38: Blockchain admin B Gives access with Number of access N in time T when Family members FM are suffer to the same accident \"read and write access\"
39:if\(Permission==\ AllOW\ AND\ Role==\ EMERGENCYDOCTOR\)then
40: Give access with number of access N in time T \"read and write access\"
41:else
42: Permission=Deny



## 6 Implementation

We chose Hyperledger Fabric to start our design, as mentioned in Section 5, due to its performance, blockchain type, integrated development environment, transaction flow, and language support; the variety of modular design of the Hyperledger operating system; and ease of smart contract development with it. Our framework was built with blockchain network entities and a smart contract called (chaincode) in Hyperledger Fabric. Chaincode is the application running in the form of a smart contract, and various transactions can be executed throw that over the blockchain network. ### Testbed Environment

The Implementations were carried out on ORACLE VM (VirtualBox Graphical User Interface version 6.1.26 r 145957 (Qt50602)) with Ubuntu virtual machine version 20.4.4 (Linux), 64-bit operating system. Table 6 shows the other configurations. #### 6.1.1 Smart Contract Installation

The first step was to install the smart contract we have created for patients, doctors, lab techs, other health personnel, and administration. As can be seen in Figure 5, Fabric release 2.3.0 was installed. After that, we needed the peer nodes and channels. As we explained in the background, the channel is a necessary component of any blockchain network, which is created as the first entity to allow communication between members, and it contains a chaincode, nodes, and clients or members created with a set of credentials assigned via (membership service). Once the channel is ready and installed, our peer nodes are initiated. The very first peer is a database.