A Blockchain and Machine Learning-Based Drug Supply Chain Management and Recommendation System for Smart Pharmaceutical Industry

: From the last decade, pharmaceutical companies are facing difﬁculties in tracking their products during the supply chain process, allowing the counterfeiters to add their fake medicines into the market. Counterfeit drugs are analyzed as a very big challenge for the pharmaceutical industry worldwide. As indicated by the statistics, yearly business loss of around $200 billion is reported by US pharmaceutical companies due to these counterfeit drugs. These drugs may not help the patients to recover the disease but have many other dangerous side effects. According to the World Health Organization (WHO) survey report, in under-developed countries every 10th drug use by the consumers is counterfeit and has low quality. Hence, a system that can trace and track drug delivery at every phase is needed to solve the counterfeiting problem. The blockchain has the full potential to handle and track the supply chain process very efﬁciently. In this paper, we have proposed and implemented a novel blockchain and machine learning-based drug supply chain management and recommendation system (DSCMR). Our proposed system consists of two main modules: blockchain-based drug supply chain management and machine learning-based drug recommendation system for consumers. In the ﬁrst module, the drug supply chain management system is deployed using Hyperledger fabrics which is capable of continuously monitor and track the drug delivery process in the smart pharmaceutical industry. On the other hand, the N-gram, LightGBM models are used in the machine learning module to recommend the top-rated or best medicines to the customers of the pharmaceutical industry. These models have trained on well known publicly available drug reviews dataset provided by the UCI: an open-source machine learning repository. Moreover, the machine learning module is integrated with this blockchain system with the help of the REST API. Finally, we also perform several tests to check the efﬁciency and usability of our proposed system.


Introduction
Counterfeit drugs are a very big challenge for the pharmaceutical industry worldwide. One question arises here: what does Counterfeit drug mean? According to WHO, "The drug which is manufactured fraudulently, mislabeled, with low quality, hiding the source detail or identity and does not follow the defined standard is considered to be fake or Counterfeits" [1]. The survey provided from the WHO stated that in underdeveloped countries every 10th drug use by the consumers is counterfeit and has low-quality [2]. This WHO claim may not be perfect or have more than this because there is no accurate estimation or statistics of counterfeits drugs. The use of this low quality and changed accordingly. All the blocks inside the network are strongly linked together and protected with transaction codes and crypto codes as well. The other important feature is strong mathematical algorithms which give the ability to miner nodes to validate these blocks without affecting the data of miner nodes and after validation blocks could be added to the blockchain network. That is the reason the blockchain system ensures security and transparency [14]. The blockchain network is an increasing chain of multiple blocks and stored the information according to defined rules. In the network, there are many miner nodes for adding new blocks in the chain to form a transaction; they work independently; they operate and control with a single protocol. The blockchain network is a distributed system that contains all the information about the transactions and participants and keeps track of all the record history. By the functionality, blockchain network is divided into three types; private, public and consortium blockchain, respectively. There is no admin node to check and control the transactions but all the miner nodes or participants can check and validate the transactions in permission-less or public blockchain networks [15]. The miner nodes are also capable to participate in consensus process and validity between the nodes is accomplished by consensus [16,17]. For example, Ethereum and Bitcoin networks, etc. The data and transactions are handled by one central entity known as the admin node in the consortium blockchain network. Admin can control the data by using public and private access. Some of the data could be public and some are shown to the specific type of private participants based on business terms. These kinds of networks are not fully decentralized and support both public and private data. e.g., Hyper ledger fabrics platform, etc. In the private blockchain network, all the data and transactions stored in the network are strictly private. All the information and data is only shared with the authorized members of the network. The only admin node can add the authorize members to the network which is quite similar to the consortium network in one aspect. e.g., Hyperledger, multichain networks, etc. [18].
Blockchain technology is the best option for handling and securing the process of the pharmaceutical drug supply chain. Some of the pharma companies are using blockchain in their supply chain and others are focusing to shift toward blockchain due to its diverse features [11,19]. The reason why most of the industries want to shift toward blockchain technology is because it provides a distributed decentralized ledger electronically where all the pair nodes in the network can see and validate the transactions related information. One more thing is its consensus algorithm which empowers the network to store the only validated information in the repository and eliminate the problem of the duplicate transaction. Furthermore, the network failure probability is very low because more nodes from the failure threshold are functioning and besides, fault tolerance is very strong.
This manuscript introduces blockchain using Hyperledger fabric for the secure drug supply chain management. It is capable of continuous monitoring and tracking of the drug delivery process to resolve counterfeiting issues. The goal is not only to resolve secure drug delivery, but also provide the best suitable drug to the users. To this end, we introduced a machine learning-based recommendation system that is trained using previously collected drug user reviews data-set: the data-set was collected through web crawling and contains the comments and ratings based on the disease condition of the consumers. Furthermore, machine learning models N-gram and LightGBM are trained on that dataset to recommend the best and effective drugs to the consumers of the system. The brief working of our proposed system is as follows: firstly, a blockchain-based novel drug supply chain system is developed in which the participants, supplier, manufacturer, distributor, pharmacy, hospitals and clinics of the drug delivery smart pharmaceutical network are used to store and share the information through the blockchain network efficiently and securely. The system provides a user-friendly WEB interface for handling and tracking of the drugs. Furthermore, we have utilized the Hyperledger composer REST API for the connectivity of web applications to the blockchain network. In the proposed solution, the validation and authentication of transaction requests are achieved by defining the rules in access control policy and history. In this work, Couch-DB is used for storing a large number of transaction records and is the best option to eliminate the data redundancy problem and provide separate storage for each node in the blockchain network. The final product enables the consumers e.g., patients to track the medicine origin with authenticity. The other advantage of our system is to recommend the best and top-rated drugs to the customers of the system with the help of machine learning algorithms. Further, the machine learning module is integrated with the blockchain network and the participants of the system can use both features of the proposed system together. Afterward, the models are also able to learn from the comments and ratings provided at the client web application and updates the recommendation results accordingly.
The rest of the paper is organized as follows. Section 2 contains the background literature of previously developed systems. In Section 3, the overview of the blockchain-based drug supply chain management system and detail design and architecture of the proposed system is explained. Further, a smart contract and transaction procedure of the blockchain network are also discussed. The machine learning-based drug recommendation analysis and is well explained in Section 4. Section 5 explains the implementation of the proposed system and its working. Furthermore, the experimental results of both modules: blockchain-based drug supply chain management and system and machine learning-based drug prediction and recommendation are discussed in Section 6. Finally, the paper is concluded.

Related Work
Blockchain has emerged as a revolutionary technology that stores and transmits data in a secure, fault-tolerant and transparent manner. This is possible due to distributed ledger-based technology. The blockchain has the full potential to make any organization secure, efficient, transparent and decentralized. Since the blockchain entered the public eye through Bitcoin [13], researchers have never stopped striving to extend blockchain applications to non-financial fields. Among these non-financial fields, the healthcare industry is one of the industries that have shown more impact on the blockchain. Although, the research on developing blockchain assisted applications is quite new and developing rapidly. As a result, researchers in the healthcare industry have been working hard to keep up with research fronts in this field. We summarize the blockchain applications which are currently used in the healthcare field, to give a glimpse into the mist-filled blockchain technology application field, which belongs to the future development direction of the healthcare industry [17,20].
Nowadays blockchain applications are not only restricted to cryptocurrency but also used in many other areas like agriculture [21], healthcare [22], finance [23], education [24], transportation [25], supply chain [26], etc. In 2018, Ref. [27] a blockchain-based agriculture supply chain management and traceability system were developed: named as agriBlockIoT. This system can manage the supply chain of food products and trace where it comes from. AgriBlockIoT system is developed with two separate blockchain network platforms; Hyperledger Fabrics and Ethereum. Furthermore, both networks are compared with each other in terms of latency and transaction per second. The system ensures that the data and information generated with different sensors are stored in secure, immutable, transparent manners. In the same year, Ref. [28] combine radio frequency identification (RFID) sensor technology and blockchain technology to achieve a blockchain architecture Internal wood chain traceability system, this system will trace information and wood quality Relevant information is integrated into an online system, using blockchain technology to remove features and distributed storage secure storage of data information and transaction records. In 2019,authors [29] have been proposed a blockchain and electronic product code (EPC) based information service food safety traceability system, this system uses blockchain features of technology traceability, time stamping and tamper resistance knowledge mechanism to accurately record valid data throughout the food supply chain, sharing and specific tracking to prevent data tampering and trust in the process of information interaction, information leakage and other issues for effective detection and prevention of food safety issues. Compared to the above emphasis on traceability of agricultural products, wood, food and medicine. A pseudo traceability system is required. In 2016 [30], traditional Chinese medicine (TCM) quality traceability system, which can track changes in external information such as manufacturing and distribution processes and the inherent quality of traditional Chinese medicine retrospective. In 2018, Ref. [31] comparative research proposes a data collection, storage, analytical and visual data management system that can ensure different supply chain parameters system interoperability among participants.
The traceability of medicine systems have their advantages, but can not meet the data storage decentralization at the same time. Three requirements: informationization, comprehensive and tamper-proof information and information privacy. Blockchain technology has unique advantages in the application of traceability systems: the decentralization and distributed storage characteristics of blockchain technology can ensure data reliability. Information transparency and complete reliability of data flow; the characteristics of technology traceability and data tamper resistance can effectively solve the problem in the supply chain; counterfeiting and shoddy issues; anti-tampering and time stamping of blockchain technology data. The characteristics can be used to provide evidence and accountability and resolve disputes between various parties. Not combining the technical advantages of the blockchain and the shortcomings of the current medical anti-counterfeiting traceability system, in this study [26], a blockchain assisted medicine traceability system is proposed to prevent counterfeit drug problems in the market.
Electronic medical records (EMR) systems are developed with the help of a blockchain network for securing the healthcare industry. Blockchain has the characteristics of decentralization, anti-tampering, data traceability, reliability, smart contracts, security and privacy, which are in line with the requirements of electronic medical records [32,33]. Guardtime [34], a Dutch company for data security, developed a blockchain assisted system for the patient's identities verification. All country individuals will get a card, which uses the blockchain to correlate EMR data with each other. A hash code is assigned to each update whenever a transaction is triggered in the blockchain network. Due to blockchain, the audit records in the EMR are tamper-proof and beyond modification. Tamper-resistant logs could be used to store information status in existing healthcare databases. Any updates in the database (such as registered records, etc.) will be assigned a timestamp and password while writing the transaction in a block. The blockchain system ensures the integrity and safety of medical data [35].
The second application related to EMR is MedRec [36], a project co-sponsored by MIT Laboratories and Beth Israel Medical Center. MedRec provides health care a secure and transparent way to share and transmit the data between each other. This blockchain application is designed to protect the proxy rights of each patient and the right to know others' access to their healthcare data. Patients can share these permissions on the blockchain to share the data for future research purposes. Although all the locations and data transaction logs are maintained in the blockchain network. At the same time, if you want to achieve true interaction, supporting software is also necessary. Another example is the Gem Health Network developed by Gem [37], an American startup, using the Ethereum blockchain platform. it permits various medical practitioners to use the same data which is stored in the network. There are many similar ones, such as Healthbank, which continuously works to enable patients to use the blockchain platform to fully control their data; Medicalchain has built a blockchain-based platform and promotes sharing patient medical records and working hard; Healthcoin [38] plans to build a global EMR system. In addition, other participants in different plans and projects centered on the blockchain include Factom, HealthCombix, Patiententory, SimplyVital, IBM Watson, BurstIQ, Bowhead, QBRICS, Nuco and more. Problem-solving methods are indeed necessary, but at the implementation level, these methods face the following problems: the interactivity between different EMR solutions based on the blockchain security, scalability and privacy of data are the major issues in EMR systems. The pharmaceutical industry generally faces a problem that can have direct consequences for patients: the circulation of fake or inferior drugs. Blockchain technology has proven capable of solving this problem [39][40][41]. Remote patient monitoring [42] is possible due to the emergence of internet of thing (IoT) sensors and smartphone devices. These devices can collect a large amount of biomedical data and medical professionals can easily check the condition of the patients, instruct in terms of medicine, etc. so, blockchain provides enough features to achieve this [43].
In this work, authors [44] have proposed blockchain based framework for securing the delivery of biopharmaceutical products. This system utilizes the stochastic simulation for guiding the blockchain network where the system can be able to protect the biopharmaceutical products from counterfeiting, fraud, theft and temperature diversion as well. Although, the proposed system improves the efficiency, transparency, security and reliability of the supply chain process. The smart contracts for the system were defined based on the proof of authority (PoA) mechanism. Finally, the system can provide real-time monitoring for distributed data streams within the blockchain network. The results prove that the performance of the system is satisfactory. In this paper, the authors [45] have been proposed information management and tracking system for drug delivery in the pharma industry. They have been used different technologies for securing the drug supply chain such as RFID, electronic product code information service (EPCIS). The research environment was developed by using two theoretical models collective action theory and transaction cost theory. They defined many rules for all the stakeholders that are participating in the drug delivery process. The business of counterfeiting drugs is a major problem for all pharmaceutical manufacturers and health organizations. All the international health organizations want to overcome this issue but the sales of these drugs increase day by day. The author of this paper [46] proposes a system with the help of blockchain technology for the traceability of drugs and also controls the process of the supply chain as well, where each participant of the system can be able to track and check the drug delivery at each stage. The proposed system has been based on a case study only.
In this work, authors [47] have proposed an Ethereum-based blockchain network for tracking the shipment of the products. It can manage and track the supply chain of different items while shipping in smart containers. They have developed this system based on smart contracts between the product sender and receiver without the involvement of the third party. This paper [48] explains the complete survey and existing developed approaches related to the medicine supply chain. It can also explain the multiple procedures of how counterfeits drugs enter into the system and how these medicines affect financially to original manufacturers. One of the important reasons for drug counterfeiting is improper supply chain systems. After that, they have developed a blockchain-based system for secure end to end (E2E) drug delivery but no details are given about the real-time results and implementation. The work presented in this paper [49] encounters how to eliminate the drug counterfeiting issue and provides the consumers with original medicines. The blockchain is the solution to this issue because it ensures the features of traceability, security and transparency. They have designed a blockchain-based system and also used QR code security for medicine security. After that, the original medicines which are manufactured with the authentic brand has been delivered to the consumers safely.This is another work [50] related to blockchain applicability in the supply chain procedure. The supply chain is the supply of goods from the manufacturer to consumers, so while supplying these products quality of the product should be maintained. There are some frauds, corruption occurs which enters the fake products into these supply chain process. This system encounters the fake product issue and provides a way of the secure and transparent supply chain by using blockchain technology.
In this paper, authors [51] have proposed and developed a software which connects Ethereum-based blockchain network with different information systems of enterprises. This system can be able to share information among their partners securely. The blockchain enables the system to provides a different level of data access, data integrity, data visibility and authenticity support to partner companies while sharing the information. Moreover, a simulation environment has been designed in the supply chain scenario and performs some statistical operations for testing the validity of the system. The results of this simulation show that the blockchain system is the best instrument for securing the supply chain process and also establish trust between different companies. It can also increase the performance of the system and reduced fraudulent or misconduct occurs in companies.
A blockchain-based system for the traceability of the drugs has been proposed in this paper [52] named as a Drugledger. This system ensures data authenticity, security, privacy and traceability as well. The architecture of the system is based on a service-oriented mechanism and better than peer to peer (P2P) traditional architecture. Drugledger could provide stable and efficient storage for the drug supply chain process. Overall the work presented in this paper provides a systematic and practical theme on how the blockchain system could tracks and manage the drug supply chain process. In this work [53], another blockchain-enabled drug supply chain management system to overcomes counterfeiting drug problems namely CounterChain is presented. it can extend the level of visibility of drugs at each level of the delivery process and provides the consumers with authentic and original products. It can also increase the level of trust between vendors, manufacturers, retailers and distributors because they are the major stakeholders of the CounterChain. Due to this, the system can be able to eliminate counterfeit drugs to enter the chain.
Hence, blockchain technology is not only used in healthcare, finance, agriculture, cryptocurrency, etc., but also used in every filed. Many researchers are developing the blockchain applications in many fields such as smart grid, vehicle-to-grid, connected vehicles, edge computing and cloud computing and cyber-physical systems [54,55].

Overview of Drug SCM Procedure in Smart Pharma
The decentralized distributed nature of blockchain technology has extended the security and privacy of the drug supply chain of the pharmaceutical industry. The complete drug supply chain management and recommendation (DSCMR) mechanism is presented with participants and blockchain network in Figure 1 in which users can manage and updates the whole supply chain activities. The data related to the users of the system suppliers, manufacturer, distributors, pharmacies, hospitals, doctors and patients are stored in the blockchain-based system. The assets of the DSCMR systems are drug, raw material, order and record repository. Each user of the system is provided with client application based front-end where they can easily perform their transaction and communicate with the blockchain network. During the whole DSCMR procedure all the relevant participants of the system can track the status of the drug delivery by using the client application. On the other hand, there is a data storage pool, which is a separate data library, also called stored-off blockchain. It is a great tool for analytics and visualization of data because visualization of data can not only be required for this system but medical-related institutes can also be used for their projects and in our system we have also used this store-off storage pool for the machine learning module and the machine learning model recommends the best drug to our customers. Moreover, system users get permission to check the complete details of drugs, raw materials and other relevant information like expiry date, price, manufacture date, etc.
To accomplish the purpose of the consistency of distributed ledger, there are peer nodes in the system whose responsibility has to run the consensus algorithm. In our system, the first supplier sends the raw material to the drug company. Each participant of the system has a web application portal where each user can log-in and perform the transaction. Suppose a manufacturer orders place for raw material, any peer node of the network can validate the transaction and after validating the submitted transaction, the supplier receives that order. Afterward, when the raw material order is ready to deliver then supplier performs the confirm order event. On the other hand, if a customer does a detailed check of a company's medicine data, only he/she can perform that actions which are defined as permission rules in the blockchain network. In another case, if a doctor wants to place an order to a medicine company then he/she can place the order using our proposed blockchain system as the same steps defined in the above-mentioned scenario. Firstly, authentication of that doctor, submit the transaction proposal, manufacturers validate the transaction, then confirm the transaction of the doctor and notify the order status by sending event message successful transaction.

Detail Architecture of Proposed DSCMR System
The important and primary goal of the blockchain network is to store information in a distributed way where each block contains multiple transactions. These transactions are stored in an encrypted and hashed manner for security concerns. The proposed system is a service-oriented framework for the users which provides the distributed ledger and smart contract functionalities as service. The main design of the proposed system is shown in Figure 2. The proposed system is divided into two modules; the first one is the drug supply chain management system and the second is the recommendation system. In this system, end-user (suppliers, distributors, pharmacy, doctors, manufacturer and patients) can perform the transaction by using the front-end web application where they can perform medicine orders, raw material supply, update the medicine data, update orders, update the records, deliver drugs, data sharing, track drug at every step of supply, drug management, customers management, etc. The first primary goal of this system is to prevent counterfeit drugs and provide a secure SCM system to the end-users. Our proposed system is secure because of blockchain security and integrity management features. Each user of the system can be able to track the delivery of the medicine by using this DSCMR system. Furthermore, the proposed system is able to perform the CRUD (create, read, update, delete) operations between the connected peer nodes. However, for the security between the nodes, we have introduced the channels concepts to make the whole network to separate private networks where the same channels nodes can directly share the data to particular nodes without exposing to other nodes. Due to the concept of this channel, each participant can create their own private network for security purposes. Suppose in our system, patients are not directly able to perform more transactions; only interact with the system for checking whether the drug they purchase from the pharmacy is original or fake by just scanning the bar code place at the drug packet. The information related to the drug-like manufacturer company, manufacturing date, expiry date, price, etc. are provided to the patients. This happened due to the blockchain channels concept. Even we can restrict the suppliers to only perform the transaction related to raw material with the manufacturer. These participants are in separate channels and used the system as a private network. Another module of our proposed system is the machine learning-based recommendation system, which works to recommend the best medicine to pharmaceutical company customers. In this module, we have used the machine learning algorithms Ngram, LightGBM and sentimental analysis, which has been trained on the comments data set provided by the customers on the websites about the medicine either good or bad. Based on this training our model has been recommended the best medicine to the customers like pharmacies, doctors, clinics, hospitals and patients.  There are also many drug supply chain management systems in the literature but our proposed system is not to deal only with SCM but also the recommendation of good medicines to customers. The other unique feature of our DSCMR system is that it is developed on the basis of the permissioned-blockchain system. Due to this feature, only the particular participants are able to use the system. In this network, users are validated and enrolled from user administrator by providing them confidential credentials and certificates of enrollment. Afterward, the users are able to use this secure blockchain network. Furthermore, the consensus algorithm is responsible to connect the enrolled user with the private network where they can perform the transactions and also manage the transaction orders. Each peer node of this blockchain network has a smart contract and distributed ledger in simulated environments where they can able to store the data and execute the transaction as well. Due to the smart contract, these nodes are able to validate the transaction after the execution and write that transaction block into the ledger. The main aim of the consensus algorithm is to maintain the only one history of the transaction and also make sure no invalid transaction would be stored in that history. The consensus protocol is used to keep the consistency of the ledger to provide a unique hash code and digital signature for every transaction. The disturbed ledger in the proposed system keeps all the transaction record histories transparent, event, logs of every transaction and action performed by the users. The detail design and architecture of the system is shown in Figure 2.

Smart Contract of DSCMR
Simple definition of smart contract is to provide the parties a transparent and conflict free way to exchange the property, money, shares or anything without involving a third party agent or broker. This is the best feature of blockchain platform. Technically, smart contract is multiple lines of computer code which enforce the agreement done between two parties without paying any amount to middle man. This code consists of predefined set of rules in which both groups done agreement with each other. This contract is automatically triggered when the specified condition meets same as database events. Moreover, smart contracts facilitate the users to manage the access rights and their assets among different parties. These smart contracts are stored and managed in distributed ledger of blockchain platform where they are completely protected and secured from the deletion and tampering. Smart contract is a secure way to implement business terms and conditions in some lines of computer code which could be enforced and triggered automatically by the consensus algorithm of blockchain network. Some major open challenges occur while writing smart contracts are as follows; a new programming language is used for writing the smart contract named as Solidity, that is why learning rate for this language is very low and hard to maintain. Moreover, the execution rate of transactions is low and take more time to complete because the transactions are executed among all the peer nodes of the network periodically or in sequence. We overcome this issue by deploying the smart contracts only for specified nodes not for all nodes in network. Therefore, some defined set of nodes can validate the transactions and execution performance of the proposed system is also increased drastically. Furthermore, we used Java and Node.JS popular programming languages for writing smart contracts. It is easy for developers to write business logic's in other programming languages. the procedure of smart contract execution with ledger is presented in Figure 3.

Transactions Execution Procedure in DSCMR
This section explains the transactional procedure of the drug supply chain management system: how a transaction should be accomplished in the blockchain network is shown in Figure 4. First of all, users are given the front-end of a client application that allows the user to connect to the blockchain system using their registered credentials and can complete their transaction requests. Registering all participants in the blockchain network is the responsibility of the administrator only after which a user may be able to perform the transaction. In order to submit a transaction proposal in the blockchain network, the user login on the client application and submits his transaction request using the registered credentials. After that, the transaction proposal is sent to all the peer nodes. These peer nodes are divided into two categories; either committers or endorsers. The responsibility of the endorsers is to execute or sign the transition proposals and gives the approval if it is valid and fulfill the smart contract criteria otherwise deny it. On the other hand, committer peers are to validate the results of the transactions before writing it into the transaction block of the ledger. Moreover, in order to understand the difference between these two kinds of peers is actually you can say that endorser peers are the special kind of committer peers who holds the predefined smart contract. Furthermore, these endorser peers execute the smart contract of requested transactions in their own simulated environment before updating to the ledger when they receive the transactions proposal. The endorser peers will extract the read and written data while executing the transaction in the simulated environment which is known as the RW set. In the read data of the RW set which contains the information of world state before transaction and on the other side written data is actually what is written in the world state after executing the transaction in a simulated environment. After that, the endorser peers will return back the signed transaction to the client application with RW sets. The client again submits the signed transaction with all RW sets to the consensus manager and it will deliver the transaction into the committers nodes; and also ordered the data into a block. Afterward, the committers nodes validate the transaction by matching the current world state and then transaction data is written into the ledger. Finally, the ledger is updated according to the written data. In the end, committer peers will send the notification to the client for transaction status either submitted or not. The communication of client application with blockchain network is established with the help of REST API and software development kit (SDK).

Machine Learning-Based Drug Prediction and Recommendation Module
Nowadays, the growing number of software-based applications for the health care industry continuously generates a huge amount of patient health Record data. There are many healthcare-related applications developed on the basis of these datasets for monitoring and controlling the patient's health condition. The medical health care analysts and data scientists are interested to use these datasets and develop an automated system for the healthcare industry. The medicine selection and recommendation for an automated system is a difficult task. It is possible after understanding the effects of medicines, depending on patients' conditions and symptoms, one can easily select and recommend which drugs are better and popular. However, there are many positive or negative reviews about each available medicine, the researchers are still struggling to develop a system which recommends one best medicine on the basis of these reviews.
This section, explains the second part of our system named as automated drug recommendation system which is developed using natural language processing and machine learning techniques. First of all, we use the publicly available UCI drug review [56] dataset to train the models and predict the most effective and top-rated drugs to the customers of the pharmaceutical industry. The dataset consists of public comments or reviews and ratings at different pharmaceutical websites about the medicines; either it may be positive or negative. We will explain about the dataset in detail later. The steps of our recommendation system are data analysis and preprocessing, Machine learning models and recommendation is shown in Figure 5. The dataset contains reviews, ratings from the users of the medicines on the basis of patients' medical conditions i.e., acne, pain, birth control, anesthesia, etc. After that, our data analysis and prepossessing module consist of two parts; data analysis and preprocessing. In the data analysis phase, we completely understand and analyze the data by doing some visualization plots. On the other hand, in the second preprocessing part, we used data processing techniques to remove all the missing values from the dataset and make it clean for further operations. The next module of the recommendation system is machine learning and natural language processing module where the two models N-gram and Lightgbm are used with the help of sentimental analysis techniques. These models are trained on the UCI Drug review dataset and one open-source emotion sentimental library is also used for better training purposes. After training, our models recommend the best and top-rated drugs for the specific patient conditions i.e., acne, anxiety, pain, etc. Moreover, our recommendation system is able to train itself by getting new reviews and comments from the client application of our system and update the recommendation results accordingly. when customers query in our DSCMR system for top-rated and relevant drugs according to condition; our recommendation module got active and recommends the best medicine among others. Finally, our system is able to recommend the most effective and best drug to the customers of the pharmaceutical industry i.e., pharmacist, doctors, hospitals and patients.

Dataset
In this drug recommendation module of our proposed system, we are using one of the best publicly available datasets of the drugs form UCI Machine learning datasets repository [56]; which contains the reviews and ratings provided from patients on medicines experiences. This dataset is provided from well known pharmaceutical web sites: Drug.com and Druglib.com. Hence, we used the Drug.com dataset in our experiment. According to the professionals, Drug.com is one of the large and most visited pharmaceutical related information providing websites for the customers and healthcare experts as well. It provides reviews about specific drugs on the basis of condition i.e., pain, acne, anxiety, blood pressure, etc., the user can also give the star rating points according to satisfaction level to these drugs starting from 0 to 10. The provided reviews dataset is not a big dataset but it is well structured and easy to use for the training of any deep learning models. The available reviews are categories into three groups side effects, benefits and overall comments. The dataset is gathered from these resources which contain user ratings and reviews by using an automatic web crawler and python soup library. After the crawling results, the total dataset has 215,063 drug reviews, the total number of targeted drugs are 541 [57]. Afterward, the total number of target websites to collect this dataset are 63,376. Moreover, we used this dataset for the training and testing of our machine learning models. after that, once the models are trained and used with blockchain framework with the help of REST API and recommends the medicines according to condition; after that our model will be used the customer's reviews and ratings on our own client application of our proposed framework and models will learn with the passage of time and recommends the top rating and best drugs to customers. Table 1 shows some records of the used dataset with seven attributes (unique ID, drug Name, condition, review, rating, date and useful count) for a better understanding of data. Moreover, the attribute drug name present, the names of the drugs; review attribute contains the reviews written in the form of text about the drugs; condition attribute represent the condition for the drugs, for example, blood pressure, acne, pain, etc.; star rating up to 10; the date is the date of the review entry and the last attribute useful count presents the number of persons found that comment useful.

Data Analysis and Preprocessing
To better understand the dataset we have used some methods of data analysis and visualization in which important features of the dataset are well explained using graphs. As can be seen in Table 1, our dataset has a total of seven attributes, including uniqueID, drugName, condition, review, rating, date and usefulcount. As the drugName and condition are plotted to check how many unique values there are in the dataset of these two attributes. Figure 6 illustrates the number of drugs present in the dataset on the basis of each condition and how many drugs and their weight for each condition in the dataset. You can see that birth control, pain, depression, acne and high blood pressures related medicines are more in the dataset. The amount of not listed drugs also has many records in this dataset because these drugs are presented with no condition, these values affect the training accuracy of the model. We will eliminate these drug records in the data preprocessing phase. For checking the positive and negative review effect we have used the different emotion extractions techniques but the 4-gram classifier as compared to other grams is a better option to classify the emotions from comments and shows better results whether it's a positive and negative review. Afterward, the rating provided in the dataset is analyzed by counting the weight of all the rating options: suppose how many times each value comes from 1 to 10. The rating weight according to mean is shown in Figure 7, where we can see that most of the customers gives four rating values 10, 9, 1 and 8 as well. Furthermore, most of the consumers give 10 rating points almost double than the others; it means that almost 69,000 drugs got more rating points from customers. Hence, the values of the positive comment are more than the negative. On the other hand, after analyzing the dataset, we have used preprocessing operations data cleaning, removal of missing values and sentimental analysis to eliminate some typos and errors in the dataset. After validation, all the missing values, typos and errors are removed from the dataset and its completely clean and ready to use for the machine learning module.

Deep Learning Models
In this section, we are going to explain the models used for the recommendation of drugs in our proposed system; natural language processing model (NLP) N-gram for predicting the probability of a word in a sequence [58], LightGBM for reducing the low gradient features and sentiment analysis dictionary adding for the purpose of emotional analysis [59].

N-gram
Models that are used to derive probabilities of words from a word sequence are called language models. Basically, the N-gram model is a type of language model that is used to calculate the probability distribution of any word from a sequence. It is a probability oriented model that is trained on a collection of text named as corpus. The N-gram model estimates the probability by counting how many times word sequences occur in the given corpus. Suppose an N-1 word sequence is given to an N-gram model, it will predict those words that have a high probability of occurrence in the sequence. N-gram means the sequence of N words: a bigram is a sequence of two words like "don't disturb", "my car" and "your notebook", similarly trigram is a sequence of three words like "please don't disturb", and "close the door".
For example, how the N-gram model predicts the probability of a word in a corpus? Consider we have two sequences "heavy flood" and "heavy rain"; for these kinds of sentences N-gram model will predict the probability of word heavy with rain is more than with flood in the training collection of text. However, the probability of second-word rain will be more and selected by the model [60,61]. It is useful in many natural language processing applications like speech recognition, word similarity comparison, part of speech tagging, predictive word input, natural language generation, grammar application, machine translation and sentiment extraction. The training accuracy and loss of the N-gram model in our DSCMR framework is presented in Figure 8.

Light Gradient Boosting Machine (LightGBM)
The Gradient Boosting Tree in the machine learning domain has a very popular algorithm and there are some effective ways to use it, including extreme gradient boosting (XGBOOST) and parallel gradient boosting regression tree (pGBRT). There are many engineering optimization methods used in these algorithms but when the dimensions of the features are high and the data is too large then the efficiency and scalability of these models are not satisfactory. One of the major reasons for this issue is that for any single feature it checks all the data instances for information gain which is a time-consuming process. To eliminate this issue, Microsoft has provided a novel solution that contains two new techniques, named as gradient-based one side sampling (GOSS) and exclusive feature bundle (EFB).
In the GOSS model, small gradient data instance will be excluded because only data instances with high gradients are important for the estimation of information gain. A large amount of data portion is eliminated for training the model. Hence, the data instance with a low gradient will not affect the model estimation accuracy. In our case, only data instances are used with high gradients for information gain. However, the GOSS can provide accurate estimation with small data size. On the other side, EFB is used for feature reduction, by grouping mutually exclusive features together. In EFB the greedy algorithm can be utilized to reduce the features in an effective manner without affecting the accuracy of information gain. Microsoft named these GOSS and EFB based implementations as lightGBM. Lastly, lightGBM is the more fast and accurate model than the other GBDT. They claim that it is 20 times faster than other GBDT models [59]. Some important features extracted by lightGBM model are shown in Figure 9.

Sentimental Analysis
For the third sentimental analysis part, we used a third-party open-source library provided form Harvard University for adding emotional analysis in our proposed recommendation system. This library contains the definitions of words either positive or negative. In our solution, we calculate the ratio of positive and negative if the estimated ratio is above 0.5 then the count is positive otherwise negative.

Implementation of Blockchain-Based DSCMR System
The tools and technologies used for the implementation of the proposed system test-bed are presented in Table 2 with their required configurations. We build and deploy our proposed test-bed in two separate environments. For providing the users an attractive graphical user interface, we used front-end languages like HTML, CSS, JAVASCRIPT, JQUERY and a third party framework twitter bootstrap for developing client web-based application. The open-source Hyperledger Fabrics blockchain technology is used for the deployment of this system which requires docker engine, python, node JS and VS code as prerequisites. The Linux operating system Ubuntu 18.04 LTS is used for the deployment of the blockchain network. the Hyperledger composer is utilized for building the business logic's of the proposed network where we have defined our participants, assets, access control rules and smart contracts [18,62]. The client application is connected with the blockchain business network through the composer REST server in which participants can visualize and performs all the activities at their own web-based portals. The user can generate HTTP requests using GET, POST, PUT, DELETE methods through and response will be provided through the blockchain system accordingly.

Smart Contract Development for DSCMR System
The Hyperledger composer is the best open-source option for the development of blockchain-based applications. One of the major features of this network is to design the smart contract for the business network easily and efficiently. The smart contract in the Hyperledger-based business network consists of four major components; model for defining the participants, script for business logic, access control rule for permission or security and queries for accessing the ledger database. The participants run the business network and each participants have some assets and can perform transactions. The participants of our proposed system are suppliers, manufacturers, distributors, pharmacies, doctors, hospitals and patients. Particularly, the assets of our system are drug, raw material, orders, record repository of system. The participants of the system are defined in the business network is shown in Figure 10. On the other side, transactions of the system are defined during the development of smart contracts, how a user can interact with assets, performs transactions, events, participants involved in the private network, more specifically each and every activity is defined during smart contract development. The event functions are also parts of the transaction process function and execution procedure is similar to the transaction. Moreover, some of the defined transactions and events of our system are presented in Table 3. Table 3. Transaction and events definition in proposed system.

Name of Component Type Job
Update Drug Details Transaction Update the stored drug details i.e., expiry date, manufacture date, price, etc.
Update Raw Material Transaction Update the raw material detail i.e., quantity, expiry date and price.
Update order status Transaction Update order detail from customers i.e., DrugID, quantity, Drug name, etc.

Share Drug record with Wholesalers Transaction
Share the manufacturer drug details with wholesalers and gives permission to share record i.e., drug name, price, formula, quantity and type.

Share Drug record with distributor Transaction
Share the manufacturer drug details with distributors and gives permission to share the record i.e., drug name, price, formula, quantity and type.

Share Drug record with pharmacy Transaction
Share the manufacturer drug details with pharmacy and gives permission to share the record i.e., drug name, price, formula, quantity and type.

Share Drug record with hospitals Transaction
Share the manufacturer drug details with hospitals and gives permission to share the record i.e., drug name, price, formula, quantity and type.

Share Drug record with Doctors Transaction
Share the manufacturer drug details with doctors & clinics and gives permission to share the record i.e., drug name, price, formula, quantity and type. Share order placed Notification Event share order placed notification will be sent message order is placed successfully.
Share order confirmed Notification Event share order confirmed notification will be sent the message order is confirmed and ready for delivery.

Share order detail with distributors Notification Event Notification message for order detail confirmation
There are four major things to define while building blockchain network with Hyperledger fabric: model file, for defining participants, script file for defining smart contract functions, access control rules file, for defining rule and query file, for performing some actions like select, update, etc. Figure 11 represents the one of script file function which is defined for performing a transaction. this transaction function is for updating the drug detail like expiry date, price, manufacturing date, etc. This script file contains the functions of the transactions related to create, delete and update the assets as well as participants in our blockchain-based DSCMR system. We used JavaScript language for writing these transaction functions while modeling the smart contract. The two transaction functions are presented in this diagram sharerecordwithpharmacy and sharerecordwithdistributors.  In the access control rules file, rules are defined to control the operations of users, in which all the users of the system who can perform the action and who cannot, are written using the rules access control language. In which users are given permissions to read, write and delete data. This is a great way to give users limited access to a blockchain network-based system. The queries are also required to retrieve or update the data in the world state of the blockchain network. in Hyperledger composer based business network these queries are written in a separate file by using a bespoke query language. These queries are quite similar to SQL database type statements and conditions. More specifically, the query which is written for Hyperledger composer consists of a statement and description. In the statement part statements keywords similar to SQL are used like SELECT, ORDER BY, WHERE, OR, AND, etc. for the development of rules in a query. The second part is description of that query which contains function string for deploying the specific rules.

Distributed Ledger in DSCMR System
The Hyperledger fabric is developed on the basis of distributed ledger technology which consists of two parts, a blockchain part, and the world state part. Hyperledger fabric can configure multiple world state databases to maintain the set of current values or states of the system for providing the functionality to access the current ledger states at any phase. The world state database part is capable to store the states of ledger efficiently and also retrieves when application or user needed. So, it can store the current state automatically and the developer of the system can check it easily without looking at the full log of transactions. The data are stored inside the world state database in the key-value pair [63].
The ledger communication is shown in Figure 12. The world state database automatically updated the state value when the state is changed or performed some transactions. Two appropriate options Couch DB and Level DB are available for the world state database. The first option means level DB is default state database which stored the data of smart contract in key-value pair and exists within each pair node of the network. The second option is Couch DB which is an alternative solution to level DB and provides rich queries environment and modeled the smart contracts in the JSON file format. Therefore this is the best option while storing the large data and queries the actual data instead of key values. Furthermore, the Couch DB format and indexed the data in the JSON file format and store it instead of key-value pair. The results of the query in couch DB gives real data contents. It also supports all kinds of queries to access data content through the REST API. Due to these features, we used couch DB in our proposed system to store the data related to our network. In the Figure 12 drug asset record is stored in the ledger and it has a key-value pair. It can also store simple and complex key-value pairs as single and multiple values. On the other hand, the second part is blockchain, which has the ability to store the set of operations and changes occurs in the world state database in the form of transactions log. After that, these transactions can be stored in the form of blocks and connected together in a chain-like structure. The transactions are stored in a sequence in the blockchain network. The blockchain provides data immutability features; nobody can change or delete the data once stored.

Execution Results of Drug Supply Chain Management (DSCM)
In this part, we explain the working of a DSCM system while communicating with the blockchain network. As we already discussed, the client application user interface is provided to each participant of the system where they can start their transaction after validating the identity. The client application communicates with the blockchain network by using a REST server composer in which each request is sent through the REST server and will store the transaction in the blockchain network. The client web application portal is shown in Figure 13 for drug management where manufacture can add, update and delete the drug details in the blockchain network. Afterward for adding new as well as available drug data manufacturer is given a web form to fill the entries and store the filled data in the blockchain network. For adding drug details in the blockchain system using this web form DrugID, Name, company name, manufacture date, expiry date, types are needed to be shown in Figure 14. The manufacturer also shares the drug record data repository with the other participants like distributors, pharmacies, hospitals and doctors as well. The drug management portal will allow users to perform create, read, update, and delete (CRUD) operations with the help of the application user interface. The users can also update the information on the existing drug by sending the update request through the user interface to the blockchain network [64].  Figure 15 illustrates the Hyper-ledger REST server composer front end where we can also perform queries directly. The communication between client application and blockchain network is done through this Hyper-ledger REST server composer. Moreover, the user can direct queries to this REST server for the transaction to validate; it shows the metadata of the transaction. In this Figure 15, the updatedrugdetail query is instantiated from the client application to the REST server for transaction submission. The response of the REST server is also shown in the JSON data format which contains the metadata of the updatedrugdetail transaction.
Similarly, Figure 16 shows the previous transaction history performed in our proposed blockchain-based system. This portal shows all the activities done through the web application to the blockchain network; either it should be a transaction, add some participants, assets to the system. The attributes of this history portal represent the time and date of the transaction activity performed, type of the transaction and the participants of the system who is involved in this transaction to perform. This portal shows the log of all the transactions performed in the blockchain network. From this history portal, users can see the detail of each transaction but did not able to alter the value; it is protected from the blockchain network. The user can also view the transaction detail by just clicking at view transaction button: a view only web form with transaction detail is presented in Figure 17.

Experimental Results of Machine Learning Based Drug Recommendation Module
This section contained the prediction results generated by our proposed machine learning-based drug recommendation system. Figure 18 illustrates the drug recommendation results from our proposed system on the basis of specific conditions. The drug name with their mean values for specific acne condition is presented. Our system has the ability to successfully recommend the top-rated and best medicine to the customers of the system. However, customers can easily query at our system for the recommendation, which drug is best for pain, blood pressure and any other related diseases condition. The patients can directly query to our system by using our client application and other pharmaceutical customers like pharmacists, doctors and hospitals can also use this system using their credentials.   Figure 19 illustrates the drug recommendation results from our proposed system on the basis of high blood pressure condition. The drug name with their mean values for high blood pressure is presented. Our system has the ability to successfully recommend the top-rated and best medicine to the customers of the system. For the drug recommendation, anyone could be able to use our system but for performing the transaction in our blockchain-based system only the registered users like pharmacy, manufacturer, hospitals, doctors and suppliers are eligible. Patients can also search for the better drug and also track the drug source for validation either drug is original or fake.  The drug recommendation results for anxiety conditions are presented in Figure 20, where the drug name and mean values of that drug are plotted on x and y-axis. Customers of the system can perform this operation by using our client application front end and search for the best medicine. From the back-end, our trained model can predict the drug according to its training. However, the best recommendation results for anxiety or any other condition will be provided to customers.
The drug prediction results by our system for alcohol dependence conditions are presented in Figure 21, where the drug name with mean values are plotted. Customers of the user can perform this operation by using our client application front end and search for the best medicine. However, the best recommendation results for alcohol or any other condition will be provided to customers. For testing the performance of our blockchain network we used an open-source solution Hyperledger-caliper [65] which is developed by the Linux Foundation. This framework supports many blockchain-based solutions for performance testing such as Hyperledger composer, burrow, sawtooth, etc. it can also provide many performance indicators to test the blockchain network i.e., transaction latency, throughput, success rate, etc.  Three different user groups have been used and compared to test the response of our blockchain network. We have run the simulation for a period of 100 ms to test the system as shown in Figure 22. The response time starts to increase as users grow in the network. We have tested the performance of the system by using 90 users for the first time, 270 users for the second time and 320 users for the third time. It can be seen that there was no increase in system response rate for the first two user groups but when using the third user group there was a slight increase in system response. To some extent, the system is also performing stable as users grow.  Figure 23 illustrates the execution of query transactions in the proposed system with minimum, maximum and average latency. Four different user groups are used to test the latency of the blockchain network while querying. These users groups contain 45, 90, 270 and 540 users, respectively. As shown in the Figure 23, in the first scenario with 45 users, the average latency is 53 ms, in the second scenario with 90 users, the average latency is 145 ms, in the third case with 270 users, the average latency is 167 ms and in the last case with 540 users, the average latency is 460 ms. As aforementioned, the latency rate is directly dependent on the number of users, latency rate increases if we increase the number of users in our system. The minimum and maximum latency for all four groups are presented in Figure 23. Finally, the performance of our system is satisfactory, our both the module work together and provides the users secure, transparent and immutable drug supply chain management and also predicts the best drugs for customers as well. The patients of the drug can also check the source of the drug by just scanning the bar-code on the medicine packet and the system will provide the whole source of that drug. All the customer's suppliers, distributors, manufacturers, clinics, pharmacies, hospitals and doctors are able to track the drug in the whole SCM system and also check the validate and best drugs just querying with condition acne, anxiety, etc. Table 4 presents a brief comparison of our system with the existing methodologies. It shows that our system performs better as compared to other existing works in the literature. There are many studies related to blockchain-based drug supply chain management but no one can provide the feature of drug recommendation. The novelty of our system is the machine learning module for recommendation and the integration of that module with a Hyperledger-based permissioned blockchain network where the users of the system pharmacies, doctors, hospital admins and patients can check the originality of the drugs and track the source of these medicines. All participants in this system can check the most used medicines and top-rated medicines in terms of condition. The machine-learning module of this system will recommend the best medicines according to the conditions. One of the most important things to mention here is that patients can only check the source and supply chain of the medicine so that they can track the medicine whether it is fake or not. This does not mean that patients do not have to go to doctors or an expert pharmacist. With the help of the machine learning module of this system, doctors can also check medicines according to the condition of any patient. However, it can also recommend the best medicines to the doctors or pharmacist but they have the authority of final decision while writing the medicines for the patients. It is a secure and transparent system where no one can enter fake medicines, it completely prevents counterfeiting drugs. All the participants of the system can track the medicines at every step of the supply chain.

Conclusions and Future Work
Blockchain technology has changed the traditional supply chain method to a new robust, automated, secure, audible and transparent way. It ensures that the entire supply chain process is foolproof and prevents fake drugs from entering the system completely. The main goals and novelty of our proposed scheme are implementing a blockchain and machine learning-enabled system, which has two modules: the drug supply chain system and the drug recommendation system. The system has used machine learning algorithms and blockchain technology in health care, with excellent results. Several experiments were carried for testing the performance of our system by using some performance indicators such as throughput, transaction response time and latency. The simulation results of our system shows promising performance. This system helps the pharmaceutical companies to eliminate counterfeit medicines problem and a significant increase in the business. As future work, we will increase the network size and implement it in real-time pharmaceutical companies to test the performance and validity of our system. Further, we will also improve our machine learning models in terms of accuracy and recommendation results.