Secure Med - Blockchain Enabled Medicine Record Management System
Secure Med - Blockchain Enabled Medicine Record Management System
CERTIFICATE
This is to certify that the project report entitled “SECURE MED -
BLOCKCHAIN ENABLED MEDICINE RECORD MANAGEMENT
SYSTEM” that is being submitted by B. Pujitha Siva Sresta (20501A0517),
Chenikala Rakesh (20501A0528), G. Siva Kiran (20501A0548), G. Naga Subha
Deepika (20501A0559) in partial fulfillment of the requirements for the award of the
Degree of Bachelor of Technology in Computer Science and Engineering during
the academic year 2023-24.
Team Members:
B. Pujitha Siva Sresta (20501A0517)
Chenikala Rakesh (20501A0528)
G. Siva Kiran (20501A0548)
G.N.S. Deepika (20501A0559)
Acknowledgement
We sincerely thank the following distinguished personalities who have given their
advice and support for successful completion of the work.
We are deeply indebted to our most respected guide [guide name], designation,
Department of computer science and engineering for his/her valuable and inspiring
guidance, comments, suggestions and encouragement.
We extend our sincere thanks to Dr. A. Jayalakshmi, Professor & Head of the
department for extending her cooperation and providing the required resources.
We would like to thank our beloved Principal, Dr K Sivaji Babu for providing the
online resources and other facilities to carry out this work.
We would like to express our sincere thanks to our Project Coordinators of the
department for their helpful suggestions in preparing this document.
We extend our sincere thanks to all other teaching and non-teaching staff of the
department, for their cooperation and encouragement.
ABSTRACT
Counterfeit drugs pose a severe threat to public health due to a lack of security
in the medical supply chain. This project proposes a Secure Med-Blockchain Enabled
Medicine Record Management System as a secure solution. Utilizing decentralized,
transparent, and irreversible ledger technology, the system guarantees the safe supply
of medical pharmaceuticals. Authenticated entities within the supply chain can
seamlessly transfer products through an event request-response mechanism using
blockchain's core features. All transactions are recorded on the blockchain via smart
contracts, ensuring complete traceability. This project reviews literature on blockchain
in the pharmaceutical sector, emphasizing safety, security, monitoring, tracing, drug
distribution, and counterfeit drug prevention. The imperfect pharmaceutical supply
chain, a key contributor to counterfeit drugs, can be addressed by incorporating
blockchain technology, promising enhanced transparency, security, and efficiency.
TABLE OF CONTENTS
CH.NO. TITLE PAGE NO
LIST OF FIGURES viii
LIST OF TABLES x
LIST OF ABBREVATIONS xi
CHAPTER 1: INTRODUCTION 1-4
1.1 Introduction to Project 1
1.2 Motivation 1
1.3 Statement of the Problem and Solution to Problem 2
1.4 Objectives 2-3
1.4.1 General Objectives 2
1.4.2 Specific Objectives 3
1.5 Scope of the Work 3
1.6 Significance of the Work 3
1.7 Outlines of the Project 4
BACKGROUND AND LITERATURE
CHAPTER 2: 5-7
REVIEW
CHAPTER 3: SYSTEM ANALYSIS 8-12
3.1 Existing System 8
3.2 Proposed System 9
3.3 Feasibility Study 12
3.3.1 Technical Feasibility 12
3.3.2 Operational Feasibility 12
3.3.3 Economic Feasibility 12
SOFTWARE REQUIREMENT
CHAPTER 4: 13-17
SPECIFICATION
4.1 Functional Requirements 13
4.2 Non-functional Requirements 13
4.3 Software & Hardware Requirements 15-17
4.3.1 Software Requirements 15
4.3.2 Hardware Requirements 17
DESIGN AND METHODOLOGY
CHAPTER 5: 18-27
OF PROPOSED SYSTEM
5.1 System Architecture or Model 18
5.2 System Design 21
5.2.1 UML Diagrams 21
5.3 Methodology 25-29
5.3.1 Process Model/Methodology 25
5.3.2 Tools and Techniques 28
CHAPTER 6: IMPLEMENTATION OF BASE PAPER 30-43
6.1 Smart Contracts 30
6.2 Description of each Smart Contract 32
6.3 Blockchain Implementation 35
CHAPTER 7: TESTING 48-53
7.1 Testing Strategy 48
7.2 Test Cases 50
CHAPTER 8: RESULTS 54-56
CHAPTER 9: CONCLUSION AND FUTURE SCOPE 57
9.1 Conclusion 57
9.2 Future Scope 57
REFERENCES & BIBLIOGRAPHY 58-59
APPENDIX A
Full Code 60-72
LIST OF FIGURES
FIG NO NAME PAGE NO
3.1 Existing System 8
6.5 Supplychain.sol 38
6.6 RawMaterial.sol 39
6.7 Medicine.sol 39
6.8 MedicineW_D.sol 39
6.9 MedicineD_P.sol 40
INTRODUCTION
1.2 MOTIVATION
Problem Statement:
Problem Solution:
1.4 OBJECTIVES
The study offers a thorough examination of the blockchain's possible uses in resolving
the issues with centralized healthcare data systems. It delves into the various benefits
that blockchain technology provides for the healthcare industry, including improved
patient consents, enhanced data ownership, strengthened information governance,
robust data auditing capabilities, heightened privacy and security measures, reliable
traceability of data, immutability of records, and flexible data access. Furthermore, the
authors highlight the essential technical features of blockchain, such consensus
methods and distributed ledgers., and discuss how these features contribute to the
suitability of Blockchain for massive data management in healthcare. The paper also
sheds light on the opportunities and obstacles related to blockchain adoption in the
healthcare industry, offering insightful information to practitioners and researchers. By
enriching the existing literature with an expanded perspective in addressing the
function of blockchain in healthcare big data management, this study seeks to further
the field's understanding and offer a framework for further investigation and use in the
healthcare sector.
Authors: Agrawal, T. K., Kumar, V., Pal, R., Wang, L., & Chen, Y.
The paper begins by offering an in-depth exploration of the complexities within the
pharmaceutical supply chain, shedding light on the prevalence of counterfeit drugs
and their detrimental impact on public health. Recognizing the limitations of
conventional supply chain mechanisms, the paper emphasizes the possible advantages
of using blockchain technology, specifically focusing on the unique attributes of smart
contracts. Key themes emerge regarding using smart contracts to battle fake
pharmaceuticals. The paper elucidates on how smart contracts contribute to enhancing
transparency, traceability, and security within the pharmaceutical supply chain. It
investigates the compatibility of smart contracts with other emerging technologies,
elucidating their seamless integration potential and the resulting synergies.
Furthermore, the systematic literature review delves into the real-time accessibility of
information throughout the supply chain facilitated by smart contracts on blockchain
platforms. This accessibility not only expedites decision-making processes but also
serves as a deterrent to counterfeiting activities, fostering a more resilient and secure
pharmaceutical supply ecosystem. Patient security, transparency, and trust are
paramount concerns in the healthcare sector, and the paper critically evaluates how the
diffusion of smart contracts on blockchain platforms positively impacts these factors
in the context of combating counterfeit drugs. Insights are drawn from the literature to
present a comprehensive understanding of the effects, highlighting instances where
smart contracts have proven instrumental in safeguarding patient interests and
bolstering trust within the pharmaceutical supply chain. In conclusion, this systematic
literature review synthesizes existing knowledge on the use of smart contracts on
blockchain platforms to combat counterfeit drugs in the pharmaceutical supply chain.
By elucidating key themes, identifying gaps in current research, and by suggesting
directions for further research, this study seeks to add to the current conversation.
surrounding the implementation of cutting-edge technologies to fortify the integrity of
pharmaceutical distribution systems.
The paper "Supply Chain Management: Strategy, Planning & Operation" by Sunil
Chopra and Peter Meindl provides a comprehensive overview of supply chain
management, including strategy, planning, and implementation of operations. It
discusses the importance of aligning business processes across internal functions and
external partners to optimize costs, lead times, and service quality for customers.
Various analytical methods and models are presented for strategic network design,
demand forecasting, inventory management, transportation planning, and cross-
functional collaboration. The authors highlight the challenges of coordinating complex
multi-entity supply chains in dynamic market environments. They emphasize the need
for integrated IT systems, joint decision making, information sharing, and minimizing
the bullwhip effect to achieve high product availability while keeping costs low.
Overall, the paper provides valuable insights and approaches for managing modern
global supply chains effectively.
CHAPTER 3
SYSTEM ANALYSIS
The Existing system in the medical industry as shown in Fig 3.1 for combating
counterfeit drugs predominantly center around insufficient and limited visibility.
While these approaches offer varying levels of data security and control, they
frequently fall short in delivering the transparency and immutability crucial for
upholding the integrity of sensitive medical data.
Blockchain provides complete secure and transparency, which also brings trust
between the various main entities of the Medicine Supply Chain, such as Suppliers
and Manufacturers, intermediaries like Wholesalers, Distributors and Pharmacies, at
last the end-users like Customers and Hospitals. Each product within the chain can be
transferred between the different authenticated entities of the chain using an event
request-response mechanism. All transactions between the different entities are
recorded into the blockchain using smart contracts.
Fig 3.3 – Architecture of the System
The economic feasibility of the project lies in its potential to improve customer
service, loyalty, and overall supply chain efficiency. While there may be initial
investment costs associated with implementing blockchain technology, the long-term
benefits, including reduced counterfeit medicines and operational efficiency,
contribute to the economic viability of the solution. The study emphasizes the
importance of a more secure system, demonstrating that the economic feasibility of
the proposed blockchain-enabled system outweighs the potential costs associated with
its implementation.
CHAPTER 4
These represent the quality limitations that the system must adhere to base on
the project agreement. The degree or priority of implementation of these factors may
differ from one project to another. They are alternatively referred to as non-
behavioural requirements.
Standard Features:
Scalability: Scalability in a blockchain-enabled medicine record management
system can be attained through techniques like sharding, off-chain
transactions, and layer 2 solutions, ensuring efficient processing of a higher
volume of transactions while preserving decentralization and security.
Additionally, optimizing smart contract code and utilizing sidechains can
further enhance scalability by reducing congestion and allowing for parallel
processing of transactions.
Maintainability: Maintainability in a blockchain-enabled medicine record
management system involves regular updates to smart contracts, ensuring
compatibility with evolving healthcare standards and regulations. Continuous
monitoring of the blockchain network's health and performance is vital,
alongside proactive bug fixes and security patches to uphold system reliability
and data integrity. Implementing modular architecture and clear documentation
facilitates easier maintenance and scalability as the system grows.
Usability: Usability in a blockchain-enabled medicine record management
system emphasizes intuitive user interfaces and streamlined workflows for
stakeholders. Providing role-based access controls and clear navigation
enhances user experience, ensuring efficient interaction with the system.
Regular user feedback and iterative design improvements contribute to a user-
centric approach, fostering adoption and usability.
Availability: Availability in a blockchain-enabled medicine record
management system is upheld by redundant network nodes and robust
consensus mechanisms, ensuring continuous access to critical medical data.
Implementing failover mechanisms and distributed storage solutions enhances
system resilience against downtime and ensures uninterrupted service delivery.
Regular monitoring and proactive maintenance practices further guarantee
high availability, minimizing disruptions to healthcare operations.
Performance: Performance in a blockchain-enabled medicine record
management system is optimized through efficient consensus algorithms like
Proof of Authority or Proof of Stake, reducing transaction processing times
and network congestion. Employing scalable blockchain solutions such as
sidechains or off-chain computation helps handle increasing transaction
volumes without sacrificing speed or throughput. Continuous optimization of
smart contracts and network infrastructure ensures responsive data retrieval
and processing, enhancing overall system performance.
Monitor - SVGA
RAM - 8GB
CHAPTER 5
The proposed system Fig 5.1 defines specific roles and functionalities for each
entity to ensure smooth operation and accountability throughout the supply chain
process. The regulatory authority serves as the overseeing entity responsible for
ensuring the integrity, compliance, and safety of the entire process. The Regular
Authority/Owner possesses administrative privileges, enabling them to manage user
accounts for validating and approving the participation of each role in the supply
chain. This validation process involves verifying credentials, adherence to regulations,
and authorization for participation.
Once the regulatory authority approves the roles, the supply chain operations
commence. The supplier, as one of the primary stakeholders, initiates the process by
creating a new product or updating the status of an existing one. This information is
then relayed to the regulatory authority for documentation and oversight.
Transporters play a pivotal role in verifying and transporting packages,
ensuring the secure delivery of raw materials and medicines between entities.
Pharmacies, the final recipients of medicines, verify their Source upon receipt
and ensure the legitimacy of the products before making them available to consumers.
Through these defined roles and functionalities, the system aims to enhance
transparency, traceability, and accountability within the medicine supply chain,
ultimately contributing to improved safety and quality of healthcare services.
Class Diagram:
The Regulatory Authority class represents the regulatory body overseeing the
supply chain.
Supplier, Manufacturer, Wholesaler, Distributor, and Pharma are the different
roles involved in the supply chain with specific associated attributes.
Transporter class represents the entity responsible for transporting products
between different roles.
The Medicine product is always being tracked in the supply chain, with associated
attributes such as ID, name, expiry date, and references to the roles involved in its
lifecycle. Status of the medicine represents the various states a product can be in, such
as created, shipped, or received.
Fig 5.2 Class Diagram
Sequence Diagram:
Fig 5.3 Sequence Diagram
The supply chain starts from the supplier, as one of the primary stakeholders,
initiates the process by creating a new product or updating the status of an existing
one. This information is then relayed to the regulatory authority for documentation
and oversight. Following this, the manufacturer receives the product details from the
supplier and proceeds with the manufacturing process. Throughout these steps, the
regulatory authority remains informed, ensuring transparency and accountability.
As the product moves through the supply chain, each subsequent role interacts
with it, updating its status and forwarding relevant information to the regulatory
authority. The wholesaler receives the product from the manufacturer, the distributor
from the wholesaler, and finally, the pharma from the distributor. Concurrently, a
transporter facilitates the physical movement of the product between these roles,
updating its status as it progresses through the supply chain.
In parallel, end users, such as patients or consumers, interact with the system
to access medicine details. They request information about specific products, and the
system retrieves relevant data from the blockchain, including product status, batch
information, and expiration dates. This ensures transparency and allows end users to
make informed decisions regarding the products they handle or consume.
Hence, Fig 5.3 demonstrates how each role interacts with the system and with
each other to track the movement and status of medicine products through the supply
chain.
5.3 METHODOLOGY
Hash: Each block in the chain must have a hash that is used to identify a block and all
of its components. As shown in Fig 5.5, It is considered as a fingerprint for each block
in the supply chain.
Proof of Work: The concept of PoW is used to make blockchain more secure and
prevent tampering through including complex cryptography that takes time and effort
to solve.
In the process, any node can have both the attributes of demand and supply. In
the product transaction formation process, an event response mechanism in Fig 5.7, is
designed in order to ensure that both parties of the transaction agree on the receipt and
delivery of medical drugs. The transaction data will be permanently stored in the
blockchain using smart contracts. The process of agreeing on the delivery and receipt
of goods by both parties of the transaction is shown using the event request response
mechanism.
1. First, the buyer initiates a purchase request. The BuyEvent() event in the Supply
Chain contract is then triggered. The event includes the buyer's and seller's
Ethereum address (EA), the address of the raw material/medicine to be
purchased, along with the timestamp of the request. The signature is sent along in
the events to confirm the identity of both parties and the authenticity of the
request. The Seller addresses are indexed so that each seller can query their
records based on their Ethereum Address (EA).
2. Then, the Seller queries the log records related to himself according to his
Ethereum address and verifies the validity of the signature contained in the
events. If the verification is passed, an event RespondEvent() is triggered by the
seller to respond to the buyer’s request along with a signature which is signed
with the private key of the seller.
3. Next, the Seller sends the product to the buyer through the Transporter. An event
SendEvent() is triggered to prove that the raw materials/medicines have been
shipped, including the Seller's and buyer's Ethereum address, the product
address. along with the timestamp of the transfer of the product.
4. Finally, an event ReceivedEvent() is triggered by the buyer upon receipt of the
goods to certify that the goods have been received.
Technologies Used:
IMPLEMENTATION
Smart contracts are self-executing contracts with the terms of the agreement
directly written into code. They run on blockchain networks and automatically execute
actions when predefined conditions are met. Smart contracts eliminate the need for
intermediaries, such as lawyers or brokers and ensure transparency, security, and
efficiency in transactions. They are commonly used in various applications, including
finance, supply chain management, decentralized finance (DeFi), voting systems, and
more.
A smart contract's structure can vary depending on its purpose, but most smart
contracts follow a similar structure:
Preamble: This section includes basic information about the contract, such as
the contract's name and version.
State Variables: These are the variables that store the contract's state. For
example, in a smart contract for a sale, there might be state variables for the
buyer, seller, price, and item status.
Functions: This section contains the functions that the contract can perform.
Functions might include actions like initiating the sale, confirming payment,
and delivering the item.
Modifiers: These are conditions that must be met for functions to be executed.
For example, a function might only be executable if the item status is 'for sale'.
Events: These are actions that trigger updates to the contract's state. Events are
logged in the blockchain, providing a transparent record of the contract's
activity.
Each file in the hierarchy plays a crucial role in the development, deployment, and
testing of the blockchain-enabled medicine record management system, contributing
to its overall functionality and security.
6.3 BLOCKCHAIN IMPLEMENTATION:
S.No Explanation
1. Owner deploys the smart contracts to the Ethereum Block-chain.
2. The Owner authenticates and registers the entities of the chain.
3. Supplier registers in Supply chain.
4. Manufacturer registers in Supply chain.
5. Wholesaler registers in Supply chain.
6. Distributor registers in Supply chain.
7. Transporter registers in Supply chain.
8. Pharmacy registers in Supply chain.
9. Creates a new Raw package by Supplier in SupplyChain.sol
10. Raw Material Contract (RawMaterial.sol) is deployed for the newly created raw
material
11. Package Status is checked and Pick Package by Associate Transporter from
Supplier.
12. Load Consignment is initiated to transport from one location to another and check
for transporter type (=1)
13. Deliver the Raw Material Package to Manufacturer.
14. Verify the source of Drug.
15. Medicine Contract (Medicine. Sol) is deployed for the newly created medicine
16. Package Status is checked and picked by Associate Transporter from
Manufacturer.
17. Check for transporter type (=2).
18. Deliver the Medicine Batch to Wholesaler.
19. Verify the source of drug and transfer ownership of drug to Wholesaler.
20. Create a Subcontract (MedicineW_D.sol) for Medicine Transaction.
21. From Wholesaler, pick the Medicine Batch by Associated Transporter.
22. Check for transporter type (=3).
23. Deliver the Medicine Batch to Distributor.
24. Verify the source of drug and transfer ownership of drug to Distributor.
25. Create a Subcontract (MedicineD_P.sol) for Medicine Transaction.
26. From Distributor, pick the Medicine Batch by Associated Transporter.
27. Check for transporter type (=4).
28. Deliver the Medicine Batch to Pharmacy.
29. Verifies the source of the medicine through a temporary node
The Fig 6.2 represents the complete process of Supplychain work flow of our
medicine record management system. It comprises of all the Stakeholders from
Supplier to Pharmacy including Customer or Patient alongside the owner also referred
as Regulatory Authority of Blockchain. It also represents the interaction of
SupplyChain Smart contract with the stakeholders and other smart contracts like
RawMaterials and Medicine. The Patient can access the medicine data from the
Blockchain network. The Table 6.1 describes the entire work flow step by step in
detail.
Whole Table 6.1 focuses on the process, that begins with the owner deploying
smart contracts to the Ethereum blockchain and authenticating and registering entities
in the chain, including Suppliers, Manufacturers, Wholesalers, Distributors,
Transporters, and Pharmacies. The Supplier creates a new Raw package, which
triggers the deployment of the Raw Material Contract. Then, an associate Transporter
picks up the package and delivers it to the Manufacturer. After verifying the source of
the Raw material, the Medicine Contract is deployed, and a similar process follows for
the Medicine batch, with it being delivered from the Manufacturer to the Wholesaler
and then to the Distributor. At each step, ownership of the drugs is transferred
accordingly. Finally, the Medicine batch reaches the Pharmacy, where its source is
verified through a temporary node.
Implementation in RemixIDE:
Fig-6.6: RawMaterial.sol
Fig-6.7: Medicine.sol
Fig-6.8: MedicineW_D.sol
Fig-6.9: MedicineD_P.sol
Ganache is a tool, part of the truffle suite, that creates a private Ethereum
based blockchain on a local system and can be used for testing contracts and
development purposes. A workspace can be created for a project by linking the
configuration file of the truffle project. By default, it creates 10 accounts with 100
ETH each and these accounts can be used to make transactions on the blockchain
network.
We can clearly observe our 10 fake Ethereum accounts with 100 ETH each in
Fig 6.23, Meanwhile Fig 6.24 represents the successful deployments of each smart
contract with the addresses in the local blockchain ganache. Fig 6.26 describes the
structure of the block in the blockchain, we can observe the transaction in that block
with the complete details like from address, created contract address, Transaction hash
and Block hash. We also encounter the Gas used, Gas limit value and block Mined
time. While Fig 6.25 represents the structure of the SupplyChain contract with the
Storage of hash maps refers to mapping function to store the details of the medicine
record management.
CHAPTER 7
TESTING
Smart contract testing is the process of verifying that the code of a smart
contract works as expected. Testing is useful for checking if a particular smart contract
satisfies requirements for reliability, usability, and security.
Methods for testing Ethereum smart contracts fall under two broad categories
automated testing and manual testing. Automated testing and manual testing offer
unique benefits and tradeoffs, but we can combine both to create a robust plan for
analyzing our contracts.
Here are the tools and libraries those we used for the Unit Testing of our smart
contracts.
The purpose of test cases in the deployment of smart contracts is to ensure that
the contracts function as intended and meet the specified requirements before being
deployed on the blockchain network. Specifically in the context of smart contracts,
test cases serve several critical purposes like Functional Verification, Security
Assurance, Gas Optimization.
Test cases play a crucial role in ensuring the quality, security, and reliability of
smart contracts before their deployment on the blockchain network. They help
mitigate risks, improve trust in the contract's performance, also contribute to the
successful deployment of our smart contracts and overall success of our proposed
system Secure Med: Blockchain Enabled Medicine Record Management System
application.
Test
Test Case Expected
S.NO Role Description Status
Name Outcome
(P/F)
Test the adding
of new user Successful
1 registerUser Owner with specific Registration of P
role to the New User
Blockchain
Test the
Successful
2 revokeRole Owner revoking of P
Revoke of User
existing user
Test the reassign Successful
of addition of
3 reassignRole Owner existing/revoked changes to the P
user with existing/revoked
specific changes User
Test the
Successful
Obtaining of
4 getUserInfo Users Obtaining of P
registered User
User details
details
Test the count
Successful
of registered
5 getUsersCount Users Obtaining of P
Users in the
User Count
Blockchain
Test the
Successful
Creation of the
Creation of Raw
6 createRawPackage Supplier Raw Materials P
Materials
Package for
Package
medicine
Test the no.of
Successful
Packages
7 packagesCountS Supplier Obtaining of P
created at
Packages Count
supplier
Test the Successful
Transportation Transportation
of Consignment of Consignment
8 loadConsignment Transporter P
from specific from specified
sender to Sender to
specific receiver Receiver
9 rawPackage Manufacturer Test the Successful P
Received collection of Conformation
Raw Materials of Received
at Manufacturer Package
Test the no.of Successful
Packages Obtaining of
10 packagesCountM Manufacturer P
received at received
Manufacturer Packages Count
Test the
Successful
Manufacture of
Manufacture of
11 manufactureMedicine Manufacturer new Medicine P
New Medicine
batch at
Batch
Manufacturer
Test the no.of Successful
Medicine Obtaining of
12 batchesCountM Manufacturer P
Batches created Medicine
at Manufacturer Batches Count
Test the Successful
Medicine collection of Conformation
13 Wholesaler P
receivedAtW Medicine batch of Received
at Wholesaler Medicine batch
Test the
Successful
Transferring of
Transfer Transportation
14 Wholesaler Medicine batch P
medicineWtoD of Medicine
to Distributor by
batch
Transporter
Test the no.of
Successful
Batches
Obtaining of
15 batchesCountWD Wholesaler Transferred to P
transferred
Distributor from
Batches Count
Wholesaler
Test the
Obtaining of Successful
Sub Contract ID Obtaining of
16 getSubContractWD Wholesaler P
between Sub Contract
Wholesaler and WD ID
Distributor
Test the Successful
Medicine collection of Conformation
17 Distributor P
receivedAtD Medicine batch of Received
at Distributor Medicine batch
18 Transfer Distributor Test the Successful P
medicineDtoP Transferring of Transportation
Medicine batch of Medicine
to Pharma by batch
Transporter
Test the no.of
Successful
Batches
Obtaining of
19 batchesCountDP Distributor Transferred to P
transferred
Pharma from
Batches Count
Distributor
Test the
Obtaining of Successful
Sub Contract ID Obtaining of
20 getSubContractDP Distributor P
between Sub Contract
Wholesaler and DP ID
Distributor
Test the Successful
Medicine collection of Conformation
21 Pharma P
receivedAtPharma Medicine batch of Received
at Pharma Medicine batch
Successful
Test the total
Obtaining of
no.of Medicines
22 batchesCountP Pharma received P
batches received
Medicine
at Pharma
batches Count
Test the
Obtaining of Successful
Medicine record Obtaining of
23 getMedicineInfo Patient/Users details from Medicine record P
Supplier to details from the
Pharma in the Blockchain
Blockchain
Test the
Updating of Successful
Medicine batch Updating of
Update
24 Pharma to specific Medicine Status P
MedicineStatus
Status like details in the
Sold/Expired to Blockchain
the Blockchain
CHAPTER 8
RESULTS
9.1 CONCLUSION:
[1] Bazel, M. A., Mohammed, F., & Ahmed, M. (2021, August). Blockchain
technology in healthcare big data management: Benefits, applications and challenges.
In 2021 1st International Conference on Emerging Smart Technologies and
Applications (eSmarTA) (pp. 1-8). IEEE.
[2] Kordestani, A., Oghazi, P., & Mostaghel, R. (2023). Smart contract diffusion in
the pharmaceutical blockchain: the battle of counterfeit drugs. Journal of Business
Research, 158, 113646.
[3] Gupta, S., Malhotra, V., & Singh, S. N. (2020). Securing IoT-driven remote
healthcare data through blockchain. In Advances in Data and Information Sciences:
Proceedings of ICDIS 2019 (pp. 47-56). Springer Singapore.
[4] Chopra, S., & Meindl, P. (2007). Supply chain management. Strategy, planning
& operation (pp. 265-275). Gabler.
[6] Alshehhi, R., Marpu, P.R., Woon, W.L., Mura, M.D., 2017. Simultaneous
extraction of roads and buildings in remote sensing imagery with convolutional neural
networks. ISPRS J. Photogramm. Remote Sens. 130, 139–149.
[9] A. Zhang and X. Lin, “Towards secure and privacy-preserving data sharing in
e-health systems via consortium blockchain,” Journal of Medical Systems, vol. 42, no.
8, 2018. doi:10.1007/s10916-018-0995-5
[16] K. N. Griggs et al., “Healthcare blockchain system using smart contracts for
secure Automated Remote Patient Monitoring,” Journal of Medical Systems, vol. 42,
no. 7, 2018. doi:10.1007/s10916-018-0982-x
Full Code:
SupplyChain.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
import './RawMaterials.sol';
import './Medicine.sol';
import './MedicineW_D.sol';
import './MedicineD_P.sol';
// Title Secure Med : Blockchain Enabled Medicine Record Management System
// Author : Chenikala Rakesh
contract SupplyChain {
address public Owner;
constructor () {
Owner = msg.sender;
}
/********* Owner Section *********/
modifier onlyOwner() {
require(
msg.sender == Owner,
"Only owner can call this function."
);
_;
}
enum roles {
norole,
supplier,
transporter,
manufacturer,
wholesaler,
Distributor,
pharma,
revoke
}
//////////////// Events ////////////////////
event UserRegister(address indexed EthAddress, string Name);
event UserRoleRevoked(address indexed EthAddress, string Name, uint Role);
event UserRoleReassign(address indexed EthAddress, string Name, uint Role);
struct UserInfo {
string name;
string location;
address ethAddress;
roles role;
}
mapping(address => UserInfo) public UsersDetails;
address [] users;
// Register New user by Owner
function registerUser(
address EthAddress,
string memory Name,
string memory Location,
uint Role
) public
onlyOwner
{
require(UsersDetails[EthAddress].role == roles.norole, "User Already registered");
UsersDetails[EthAddress].name = Name;
UsersDetails[EthAddress].location = Location;
UsersDetails[EthAddress].ethAddress = EthAddress;
UsersDetails[EthAddress].role = roles(Role);
users.push(EthAddress);
emit UserRegister(EthAddress, Name);
}
function revokeRole(address userAddress) public onlyOwner {
require(UsersDetails[userAddress].role != roles.norole, "User not registered");
emit UserRoleRevoked(userAddress,
UsersDetails[userAddress].name,uint(UsersDetails[userAddress].role));
UsersDetails[userAddress].role = roles(7);
}
function reassignRole(address userAddress, uint Role) public onlyOwner {
require(UsersDetails[userAddress].role != roles.norole, "User not registered");
UsersDetails[userAddress].role = roles(Role);
emit UserRoleReassign(userAddress,
UsersDetails[userAddress].name,uint(UsersDetails[userAddress].role));
}
/********* User Section *********/
// Get User Information/ Profile
function getUserInfo(address User) public view returns(
string memory name,
string memory location,
address ethAddress,
roles role
){
require(UsersDetails[User].role != roles.norole, "User not registered");
return (
UsersDetails[User].name,
UsersDetails[User].location,
UsersDetails[User].ethAddress,
UsersDetails[User].role);
}
function getUsersCount() public view returns(uint count){
return users.length;
}
/********* Supplier Section *********/
mapping(address => address[]) supplierRawProductInfo;
event RawSupplyInit(
address indexed ProductID,
address indexed Supplier,
address Shipper,
address indexed Receiver
);
// Create new raw package by Supplier
function createRawPackage(
string memory Des,
string memory FN,
string memory Loc,
uint Quant,
address Shpr,
address Rcvr
) public {
require(
UsersDetails[msg.sender].role == roles.supplier,
"Only Supplier Can call this function "
);
RawMaterials rawData = new RawMaterials(
msg.sender,
Des,
FN,
Loc,
Quant,
Shpr,
Rcvr
);
supplierRawProductInfo[msg.sender].push(address(rawData));
emit RawSupplyInit(address(rawData), msg.sender, Shpr, Rcvr);
}
function getPackagesCountS() public view returns (uint count){
require(
UsersDetails[msg.sender].role == roles.supplier,
"Only Supplier Can call this function "
);
return supplierRawProductInfo[msg.sender].length;
}
/********* Transporter Section *********/
// Load Consingment fot transport one location to another.
function loadConsingment(
address pid, //Package or Batch ID
uint transportertype,
address cid
) public {
require(
UsersDetails[msg.sender].role == roles.transporter,
"Only Transporter can call this function"
);
require(
transportertype > 0,
"Transporter Type must be define"
);
if(transportertype == 1) { // Supplier to Manufacturer
RawMaterials(pid).pickPackage(msg.sender);
} else if(transportertype == 2) { // Manufacturer to Wholesaler
Medicine(pid).pickPackage(msg.sender);
} else if(transportertype == 3) { // Wholesaler to Distributor
MedicineW_D(cid).pickWD(pid,msg.sender);
} else if(transportertype == 4) { // Distrubuter to Pharma
MedicineD_P(cid).pickDP(pid,msg.sender);
}
}
/********* Manufacturer Section *********/
mapping(address => address[]) RawPackagesAtManufacturer;
function rawPackageReceived(
address pid
) public {
require(
UsersDetails[msg.sender].role == roles.manufacturer,
"Only manufacturer can call this function"
);
RawMaterials(pid).receivedPackage(msg.sender);
RawPackagesAtManufacturer[msg.sender].push(pid);
}
function getPackagesCountM() public view returns(uint count){
require(
UsersDetails[msg.sender].role == roles.manufacturer,
"Only manufacturer can call this function"
);
return RawPackagesAtManufacturer[msg.sender].length;
}
mapping(address => address[]) ManufactureredMedicineBatches;
event MedicineNewBatch(
address indexed BatchId,
address indexed Manufacturer,
address shipper,
address indexed Receiver
);
// Create Medicine Batch
function manufacturMedicine(
string memory Des,
string memory RM,
uint Quant,
address Shpr,
address Rcvr
//uint RcvrType
) public returns (string memory){
require(
UsersDetails[msg.sender].role == roles.manufacturer,
"Only manufacturer can call this function"
);
Medicine m = new Medicine(
msg.sender,
Des,
RM,
Quant,
Shpr,
Rcvr
);
ManufactureredMedicineBatches[msg.sender].push(address(m));
emit MedicineNewBatch(address(m), msg.sender, Shpr, Rcvr);
return "Medicine created!";
}
function getBatchesCountM() public view returns (uint count){
require(
UsersDetails[msg.sender].role == roles.manufacturer,
"Only Manufacturer Can call this function."
);
return ManufactureredMedicineBatches[msg.sender].length;
}
/********* Wholesaler Section *********/
mapping(address => address[]) MedicineBatchesAtWholesaler;
// Medicine Batch Received
function MedicineReceivedAtW(
address batchid,
address cid
) public {
require(
UsersDetails[msg.sender].role == roles.wholesaler,
"Only Wholesaler can call this function"
);
MedicineBatchesAtWholesaler[msg.sender].push(batchid);
}
mapping(address => address[]) MedicineWtoD;
mapping(address => address) MedicineWtoDTxContract;
function transferMedicineWtoD(
address BatchID,
address Shipper,
address Receiver
) public {
require(
UsersDetails[msg.sender].role == roles.wholesaler &&
msg.sender == Medicine(BatchID).getWDP()[0],
"Only Wholesaler can call this function"
);
MedicineW_D wd = new MedicineW_D(
BatchID,
msg.sender,
Shipper,
Receiver
);
MedicineWtoD[msg.sender].push(address(wd));
MedicineWtoDTxContract[BatchID] = address(wd);
}
function getBatchesCountWD() public view returns (uint count){
require(
UsersDetails[msg.sender].role == roles.wholesaler,
"Only Wholesaler Can call this function."
);
return MedicineWtoD[msg.sender].length;
}
// Get Sub Contract ID of Medicine Batch Transfer in between Wholesaler to Distributor
function getSubContractWD(address BatchID) public view returns (address
SubContractWD) {
return MedicineWtoDTxContract[BatchID];
}
/********* Distributor Section *********/
mapping(address => address[]) MedicineBatchAtDistributor;
// Medicine Batch Recieved
function MedicineReceivedAtD(
address batchid,
address cid
) public {
require(
UsersDetails[msg.sender].role == roles.Distributor,
"Only Distributor Can call this function."
);
MedicineW_D(cid).recieveWD(batchid, msg.sender);
MedicineBatchAtDistributor[msg.sender].push(batchid);
}
mapping(address => address[]) MedicineDtoP;
mapping(address => address) MedicineDtoPTxContract;
// Transfer Medicine BatchID in between Distributor to Pharma
function transferMedicineDtoP(
address BatchID,
address Shipper,
address Receiver
) public {
require(
UsersDetails[msg.sender].role == roles.Distributor &&
msg.sender == Medicine(BatchID).getWDP()[1],
"Only Distributor can call this function"
);
MedicineD_P dp = new MedicineD_P(
BatchID,
msg.sender,
Shipper,
Receiver
);
MedicineDtoP[msg.sender].push(address(dp));
MedicineDtoPTxContract[BatchID] = address(dp);
}
function getBatchesCountDP() public view returns (uint count){
require(
UsersDetails[msg.sender].role == roles.Distributor,
"Only Distributor Can call this function."
);
return MedicineDtoP[msg.sender].length;
}
// Get SubContract ID of Medicine Batch Transfer in between Distributor to Pharma
function getSubContractDP(address BatchID) public view returns (address SubContractDP)
{
return MedicineDtoPTxContract[BatchID];
}
/********* Pharma Section *********/
mapping(address => address[]) MedicineBatchAtPharma;
// Medicine Batch Recieved
function MedicineReceivedAtPharma(
address batchid,
address cid
) public {
require(
UsersDetails[msg.sender].role == roles.pharma,
"Only Pharma Can call this function."
);
MedicineD_P(cid).recieveDP(batchid, msg.sender);
MedicineBatchAtPharma[msg.sender].push(batchid);
sale[batchid] = saleStatus(1);
}
function getBatchesCountP() public view returns(uint count){
require(
UsersDetails[msg.sender].role == roles.pharma,
"Only Pharma or current owner of package can call this function"
);
return MedicineBatchAtPharma[msg.sender].length;
}
enum saleStatus {
notfound,
atpharma,
sold,
expire,
damaged
}
mapping(address => saleStatus) sale;
event MedicineStatus(
address BatchID,
address indexed Pharma,
string status
);
/// a helper function to convert `saleStatus` to a string:
function getStatusString(saleStatus Status) internal pure returns (string memory) {
if (Status == saleStatus.notfound) return "Medicine Batch is Not Found";
if (Status == saleStatus.atpharma) return "Medicine Batch is At Pharma";
if (Status == saleStatus.sold) return "Medicine Batch is Sold";
if (Status == saleStatus.expire) return "Medicine Batch is Expired";
if (Status == saleStatus.damaged) return "Medicine Batch is Damaged";
revert("Invalid status");
}
// Get Medicine Batch status
function getMedicineInfo(
address BatchID
) public
view
returns(
string memory Status
){
return getStatusString(sale[BatchID]);
}
// Update Medicine Batch status
function updateMedicineStatus(
address BatchID,
uint Status
) public {
require(
UsersDetails[msg.sender].role == roles.pharma &&
msg.sender == Medicine(BatchID).getWDP()[2],
"Only Pharma or current owner of package can call this function"
);
require(sale[BatchID] == saleStatus(1), "Medicine Not Found at Pharma");
sale[BatchID] = saleStatus(Status);
emit MedicineStatus(BatchID, msg.sender, getStatusString(sale[BatchID]));
}
}
Deploy_Contracts.js:
module.exports = function(deployer) {
deployer.deploy(SupplyChain);
deployer.deploy(RawMaterials);
deployer.deploy(Medicine);
deployer.deploy(MedicineW_D);
deployer.deploy(MedicineD_P);
};
Truffle_Config.js:
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*",
gas: 30000000,
from: '0x84AED190Dfdd1C3D50bCC10298fd39773FAb4AA8',
},
},
compilers: {
solc: {
version: "0.8.21",
docker: true,
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
}
}
}