Authentic Drug Usage and Tracking with Blockchain Using Mobile Apps

Tracking drugs became more difficult using the centralized architecture. Decentralized architecture using blockchain technology overcomes the difficulties faced by the centralized network like availability and recovery. Avoiding duplicate or fake drugs created by fake manufacturers is a big challenge in the centralized network. Authentic stock is managed and the supply chain is tracked efficiently using this blockchain technology. This is addressed by using the smart contract which helps to track the movement of drugs from manufacturer to supplier, supplier to the reseller, reseller to pharmacies and finally pharmacies to patient. By default, duplicate drugs or fake drugs are completely avoided by using the blockchain technology. Patients buy drugs without any prescription and it creates a lot of problems in real life. So, Patients cannot buy drugs without authenticated doctor’s prescriptions with the help of a QR Code scanner attached with the prescription which will be implemented using a mobile application and cannot buy excess drugs which might lose someone’s life. With the help of inventory management, the maximum limit of drugs to avoid overdose and pharmacies cannot sell those overdose drugs. Consulting a doctor before buying a drug for even a simple illness is important and it is tracked by using prescriptions provided by authentic doctors. In this project, these challenges are addressed using the smart contract which is written in solidity language and runs on a public Ethereum network. Keywords—Blockchain, transactions, decentralized architecture, fake drugs, smart contract, Ethereum.


Introduction
Maintaining the drug supply chain in the centralized network is a big challenge. There might be many issues in the case of a centralized network. Many irrelevant data can be stored in the centralized network and the data might not be consistent. Back up of data is not guaranteed. A centralized network has only one central node which maintains all the data and it will fail if there is any loss of network connectivity. If the central system fails then the entire system fails. Server maintenance is very difficult in a centralized network. The availability of data is not the same as the decentralized network [19]. Tracking drugs worldwide is the biggest challenge and duplicate or fake drugs are sold by many fake manufacturers which creates life-threatening problems.
Many patients die out of having drugs that are not authentic. Fake or duplicate drugs are very similar to those of the original drugs and it cannot be identified easily by the patients. Overdosage becomes more common as people try to suicide with the help of overdosage. These problems arise mainly because of the cheating that occurs in the supply chain either by manufacturer or pharmacist or even doctor. Anyone may lead the fake drug transactions. This can be avoided with this blockchain technology. With the help of this technology, the patient's prescription details can be viewed anywhere in the world. This entire application will be implemented as a mobile application that can be accessed through both android and IOS mobile devices. A patient with the mobile application will have his prescription in his mobile which was provided by an authentic doctor and the pharmacist will scan the QR code of the patient's prescription and verify whether it is an authentic prescription provided by an authentic doctor and deliver the medicine based on that verification. If a patient is admitted to a different place that might be anywhere in the world, then the doctor can access the medical history of the patient from that location [1] and can easily treat the patient. Everything is transparent and no one can fake in this technology. Blockchain is known for its decentralization, transparency, security, privacy [15], and immutability. Blockchain has a transactional database that is globally shared and available in all the nodes. Everyone participating in the public ethereum network which includes manufacturers, doctors, pharmacists can read the data available in the transactional database. These transactions are either done completely or not done at all. When a transaction occurs, no other transaction can alter that transaction. When blockchain technology is applied to the health industry, corruption in the health industry in any format can be completely avoided and authentic drugs can be used. There is no downtime in blockchain technology, all the data is available whenever we require it. It is a zero-downtime technology. The data appended are stored redundantly in multiple databases and this is how it provides zero downtime. In this technology, writing is done only for one time and others are appended. With this, no data can be modified once it is written. Each record added in a block of the blockchain is unique and the history of those records is also unique which in turn avoids duplicate or fake drugs. The smart contract is stored in the nodes of public ethereum network which is available in multiple locations and these smart contracts can run in a decentralized fashion and can be stored in a decentralized fashion.
• Pruning the blockchain storage is done using the drug ledger with the help of the expiration date mentioned in the drugs but it is not efficient to avoid expired products. • Drug ledger concentrates on authenticity and it provides privacy for the traceability data but does not completely avoid duplicate or fake drugs. • Packaging drugs, repackaging drugs, and unpackaging drugs are the only important topic covered in this existing model.
As per paper [3], a conceptual e-Prescription system that is based on blockchain technology is identified. Cryptocurrency principles are used to develop electronic prescriptions. This project concentrates on the opioid crisis. This is not set out for creating a complete system and a fully evaluated system is not developed. It used RxCoin for e-Prescription using blockchain technology. The main functionality of the potential Prescription Drug Monitoring System (PDMP) is not shown by RxCoin and it does not show the usage of blockchain for the same functionality. RxCoin does not fully consider the privacy of personal information about the health of patients that are stored on the blockchain. Usage of RxCoin is a main disadvantage and utilization of RxCoin by blockchain technology is not full when compared with ethereum's utilization by blockchain technology.
There are many literature reviews by using the blockchain technology with the pharmaceutical industry [18]. This literature review shows that there are five main success factors [4]. Information can be found with the complete source so traceability is one of the success factors. With the help of contracts, data can be used to find where the drug is located currently so the track is one of the success factors. Transparency is maintained between everyone and transparency is one of the success factors. Transparency provides trust and trust is one of the success factors. In the medical industry, everything is real-time and so tracking everything is also real-time so realtime is also one of the success factors. Blockchain technology is known for its immutable features. Data in the blockchain cannot be modified by anyone in the network. Transaction latency and transaction throughput are concentrated more and the flow of drugs from manufacturer to patient is not concentrated [5]. The whole supply chain and the flow of drugs are not covered in this project which is the main drawback of this paper.

Proposed System
The drug is tracked from the manufacturer until it is received by the patient as shown in Fig. 1. and stock maintained using a distributed storage so that it can avoid any fake drugs or duplicate drugs created by any other fraud or fake manufacturers. The blocks along with the transactions are distributed to all the nodes so that no one can fake the transaction. If someone tries to fake a transaction or modify a transaction, then the hash of that block is changed which in turn changes the hash of the next block and it will not be as same as other nodes. This makes this technology immutable. The new data can be appended at the back and cannot be appended at the front and the middle. This makes clear that data cannot be modified in the blockchain. Patients can buy the medicine only if they have a proper prescription provided by an authenticated doctor which will be tracked by using Doctor's ID and Prescription ID in the blockchain. Prescription ID is a unique ID that is mapped with the QR code and can be scanned from any mobile. Pharmacist with this blockchain technology finds the authenticity of prescription and delivers the medicine based on all the criteria. Also, a limit will be provided by the manufacturer that a patient can have a maximum of n number of tablets in the smart contract to avoid patients getting excess tablets. The Drug is properly tracked from manufacturing so that we can identify where the drug is currently present.

Ethereum
Ethereum, a programmable blockchain which is used as the cryptocurrency to mine in blockchain for tracking drug from manufacturer to patient. This is an open-source platform that is available globally and it can be used for developing decentralized applications [3]. With the use of ethereum, code can be written on it and it controls digital value. This can be accessed anywhere from the world and this runs like a programmed application. In this technology, applications developed on it cannot steal or spy anyone. This makes it more authentic. It has many built-in functions like money and payments using that money. Ethereum is used instead of bitcoins because bitcoin flexibility is restricted. In ethereum, any contract can be written for developing any type of decentralized application with flexibility. In public ethereum networks, ether which is a type of gas and it acts as a fuel for the network and miners try to earn ether with their work. Ether is used in public ethereum network for paying transaction in this decentralized application. Ether is a token used in public ethereum network and is used for transaction fees processed for any transaction undergone by the miner. The miner works for earning this ether. Ether is very similar to bitcoin and it is digital money. Ethereum is used as an infrastructure to run many decentralized applications because of its programmable nature. Ethereum is not controlled by anyone which means there is no centralized authority or a company to control ethereum [6].

Ethereum smart contract
The supply chain of a drug tracking system is more secure and efficient when it is implemented with a smart contract. Ethereum smart contract is a digital contract and can run on the blockchain using ethereum. In the smart contract of the public ethereum network, gas used is nothing but another type of token. This is used mainly for paying fees to miners when they include the transactions to the block successfully with their proof of work. The smart contracts require this type of tokens for execution and to add it to the blockchain. This is implemented using solidity. There are many platforms where smart contracts can be implemented but ethereum is the best one among all other platforms. Smart contracts are distributed [7] among all the nodes and it is available globally with zero downtime. The availability of smart contracts is the major advantage of blockchain technology. The pharmaceutical industry is more reliable with the smart contract and privacy [16] of the patient's data is maintained. Ethereum smart contracts are created with solidity language with the help of public ethereum network. The smart contract is a computer protocol that does not involve the service of any third parties or any middleman. It is very transparent and conflict-free. The main advantages of smart contracts are autonomy, trust, backup, safety, speed, savings, and accuracy.

Solidity language
Solidity is as same as many other high-level programming languages like C++, Javascript, Python and it is mainly helpful in implementing the smart contracts in Ethereum Virtual Machine (EVM) [8]. Solidity is contract oriented and smart contracts are developed using solidity language. Smart contracts implemented using solidity language which is very similar to C++ and has a collection of functions and its variables [9]. These are present in the specific address of blockchain. The Contract is as same as a class in C++. A certain address is used on the blockchain to run any smart contract in the blockchain. Solidity code can be written in remix IDE [10] where it can be compiled, executed and debugged [11]. IDE refers to the Integrated Development Environment which itself an application and it has many built-in tools that are used to execute the program related to software development. There are many tabs available in remix ide and they are listed below. The compile tab is used to compile a smart contract, the run tab is used to send transactions to any of the configured environment, the settings tab is used to update any settings available in remix ide like the compiler version, the debugger tab is used to debug all the transactions, the analysis tab is used to get all the information about the compilation done recently, the support tab is used to connect with the remix.

Implementation
The implementation of this project is done using metamask chrome extension, remix IDE with solidity language. Metamask chrome extension is used for deploying smart contracts [12]. Ethereum public network is a software-oriented platform that is based on blockchain technology and it is used to deploy decentralized applications using metamask plugin as shown in Fig. 2. by creating smart contracts.

Fig. 2. Metamask example for a manufacturer.
Metamask is used to store the private key of the ethereum account and load private key at the backend for every transaction. The private key is loaded at the backend to get both public key and public address. To trigger any transaction in the smart contract, API is built-in in the metamask plugin and ethereum transaction is done in the same way. This extension acts as a wallet for ethereum. Ether can be made available in the wallet through any possible ways to use it for the transaction. In the smart contract, contracts can be written on our own using ethereum. There are many smart contracts in the node and one smart contract is authentic drug tracking and usage using blockchain. Solidity language is used to implement the authentic drug tracking and usage application. This is a programming language like other high-level programming languages that are used in developing smart contracts. The smart contract code is written in remix IDE [13]. Remix IDE can be accessed in different ways and one among that is from chrome browser which is used in this project.
The main difference of this project from other projects is the inclusion of doctors into the picture. Drug is tracked from manufacturer till patient where the main people involved in this drug tracking supply chain are manufacturer, doctor, patient, pharmacist as shown in Fig. 3. It is an architecture of public ethereum network with blockchain for authentic drug usage and tracking. This is mainly used to build scalable industrial applications [14]. As per this supply chain, the drug is tracked with the help of the doctor. Patient cannot buy medicines without any consultation of the doctor. Pharmacist cannot provide medicines without a doctor's prescription [17]. For users who do not use the mobile application can access the application using the webpage on mobile devices or even on the computer. The manufacturer knew the composition of medicine and he provides the maximum limit of tablets a person can take at a time. Doctor gets to know the maximum limit of the drug from the manufacturer and he can provide either the maximum limit of drug or lesser than that based on the severity and how much the patient is affected by the disease. The main modules of this project are manufacturer metamask, doctor metamask, patient metamask, and pharmacist metamask. Transactions occur between these modules. Sender always signs the transaction cryptographically. This safeguards the access and modifications in the database. In cryptocurrency, the owner of the account who has the key can only transfer money from his account. Also, the transaction and its order that is globally accepted is selected. Many transactions will be appended in the block and these bundled transactions are executed and distributed among the participating nodes who are participating globally. If two transactions are happening concurrently then the one which is completed first is accepted and it becomes the part of the block and the other is rejected. These blocks that are in a linear sequence in terms of time is termed as blockchain. For ethereum, these blocks are added to the blockchain for every 17 seconds approximately. In this proposed system, there are many nodes in the public ethereum network and all nodes have the smart contracts deployed in it. Among those smart contracts, one of the smart contracts is authentic drug tracking and usage using blockchain. Nodes are replicas so that every single data is available everywhere and anywhere in the world. Nodes are miners and all miners do the same job which is mining the block to complete the transaction. A leader is elected for each block with the help of proof of work. Miner who finds the proof of work first becomes the leader of the block. In blockchain technology, proof of work or PoW is the consensus algorithm and it is an algorithm used to append new blocks in the blockchain by confirming the transactions in the block of the blockchain. Miners always compete with other miners in the network to complete transactions and add them to the block with the proof of work. If the second block is changed by a miner then the hash of that block changes which in turn changes the third block because the second block's hash is used to connect the third block with the second block. This makes the blockchain immutable and no one can fake or duplicate drugs in this technology. There is no centralized authority to maintain the blockchain and this public ethereum network is distributed. The digital signature is used for providing authentication and to verify proper message is received or not. For providing privacy and security, encryption and decryption are used. Latency and throughput are based on the transaction fee used for mining a block. The transaction fee is mainly based on the complexity of the code in a smart contract and the size of code in the contract.

Transaction
A transaction contains the components as shown in Fig. 4. The status of the transaction is stored as a component of the transaction. Whenever a transaction is mined, the date and time at which the transaction is mined are stored at the timestamp. In the transaction's component, the sending party of the transaction is the address of the contract which is mentioned in From and the receiving party of the transaction is mentioned in To. The transacted value in ether is stored in value. The transaction fee is the fee paid for processing the transaction by the miner. Gas limit is the maximum limit of gas for the transaction and it is based on the gas limit of the block. The gas used by the transaction is the actual gas used in the transaction. Gas price is the price with which the transaction is included in the block. The chances of including the transaction in block increases when the gas price increases. Cost per unit gas in the ether as specified in the transaction.

Fig. 4. Transaction components.
Nonce is the number of address and it begins with 0 for the first transaction and 1 for the second transaction and so on. Nonce runs sequentially. Any additional information that is required to build a transaction is included in the input data.

Block
Block contains the components as shown in Fig. 5. Block height or the length of the block is also known as block number and whenever a new block is added to an old block, the block number increases whenever a block is appended. Whenever a block is mined, the date and time at which the block is mined are stored at the timestamp. Block also contains the number of transactions in the block and the transactions that are performed internally whenever a contract with ether value is executed. The block component contains the details of the one who mined the block which is found using proof of work. Block reward is rewarded whenever a new block is added by miners successfully. Security in ethereum is provided using uncle's block. Uncles reward has a lower priority than the reward of the normal block. This can be rejected if it is not in the longest chain of blockchain. This is the mechanism of blockchain technology. A difficulty algorithm is used to find out the effort made by the miner to mine the block containing all the transactions. The size of the block is calculated based on the limit of the gas in that block. The amount of gas-filled in the block and its total is found using the Gas used and the percentage is mentioned in this. The gas limit is the total amount of gas used by all the transactions in that block. Extra data is the data which is the excess information apart from normal data that can be included by the miner in the block. do not deliver medicine print "Prescription doesn't exist" else do not deliver medicine print "medicine limit more than maximum medicine limit"

Conclusion
Fake drugs are avoided in blockchain transactions and with this blockchain technology, fake drug manufacturers or duplicate drug manufacturers cannot be there in the public ethereum network which in turn completely avoids fake or duplicate drugs so that pharmacies cannot sell duplicate drugs. Both the manufacturer and pharmacies cannot make or sell any fake drugs respectively. Safety usage of drugs is maintained in this blockchain technology. Blockchain ensures authenticity by using a manufacturing ID for medicines and doctor ID for the prescription. The patient can buy drugs only after consulting a doctor along with an authenticated doctor's prescription which is implemented with mapping in blockchain and this will be implemented as a mobile application by using a scanner for scanning the prescription. The patient cannot buy excess drugs as maximum limit per patient is included by the manufacturer where the doctor will obviously give the maximum limit or even lesser than that and never more than the maximum limit. The supply chain of drugs is tracked properly using smart contracts in blockchain.

Future Work
To track the expiry date using oracle time services and avoid expired drugs and implement the entire application as a mobile application with a QR code scanner. To explore more about latency and throughput in this technology.