# Towards an Optimized Blockchain-Based Secure Medical Prescription-Management System
## 3 Blockchain-Based Prescription Management DApp Overview
### Main Process of Blockchain-Based Prescription-Management System  
The sequence diagram presented in Figure 2 depicts the main process of our proposed system with its different steps, clarifying the interactions between different actors. This prescription-management system operates on a permissioned blockchain platform, using smart contracts to manage the prescription life-cycle and user transactions. To become a member of the proposed system's blockchain network, pharmacists are required to submit a request to the National Health Services. Upon identity verification, the administrator will register the pharmacists and send a confirmation email, including their password. Once registered, pharmacists can access the platform using their wallet address and password. This access allows them to efficiently consult and manage registered prescriptions, register patients, access the list of registered pharmacists, and check the approved drugs list. When a pharmacist receives a patient, the first step is to verify whether the prescription is already registered using the QR code reader and scanner:  
* If the prescription is being served for the first time, the pharmacist will proceed to register it in the system. Figure 1: Blockchain-based prescription-management architecture. * If it is already registered, he/she will check the remaining quantity of the requested drugs and the expiration date. Subsequently, the pharmacist will update the prescription information accordingly. In case the patient is not registered yet, the pharmacist can create an account for him/her, and the system will generate a unique QR code. This QR code grants the patients access to their medication history, which remains confidential and can only be consulted by the patients. Registered patients, in addition to managing their prescriptions, have the ability to access the pharmacist users list and view the list of approved drugs. Regarding the system's level of authorization, it is important to note that the system utilizes an authoritative model that relies on users' mutual recognition and their affected roles. The smart contract, designed for this proposed system, incorporates all necessary functions to manage and modify the entire life-cycle of medical prescriptions while ensuring proper separation and management of actors' roles. Each transaction is securely published on the blockchain platform and recorded, ensuring traceability and transparency throughout the process. Table 1 presents some examples of functions used in the smart contract. For a clearer understanding of the smart contract's functionalities, we outline several algorithms employed within our proposed solution. Algorithm 1 explains the steps in registering a new pharmacist. The inputs to the smart contract, needed by the functions, are shown with their descriptions. The function addPharmacist() executes exclusively when the caller's address aligns with that of the admin. Once registered, the pharmacist will receive an email confirming that the registration was successful, along with his/her encrypted password. Algorithm 2 outlines the process of registering a new patient. The function appPatient() only executes when accessed by a registered pharmacist. Upon successful registration, the patient will receive an email confirming the process, accompanied by a QR code. This QR code grants the patient access to his/her profile and medical history. Figure 2: Sequence diagram of the proposed system. In Algorithm 3, we introduce a series of functions related to the registration and updating of prescriptions. These functions play a crucial role in the management of prescriptions within the system.