Sie sind auf Seite 1von 110

FRAUD MEDICINE PREVENTION USING

BLOCKCHAIN
PROJECT REPORT

submitted by

ELIZABETH GEORGE
Reg. No: MAC16CS021
MANACY JOHN
Reg. No: MAC16CS064
SHANET VARGHESE
Reg. No: MAC16CS066

to
the APJ Abdul Kalam Technological University
in partial fulfillment of the requirements for the award of the Degree
of

Bachelor of Technology
in
Computer Science and Engineering

Department of Computer Science and Engineering


Mar Athanasius College of Engineering
Kothamangalam, Kerala, India 686 666
APRIL 2020

2
DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING
MAR ATHANASIUS COLLEGE OF ENGINEERING
KOTHAMANGALAM

CERTIFICATE
This is to certify that the report entitled Fraud Medicine Prevention Us-
ing Blockchain submitted by Ms. Elizabeth George, Ms. Manacy John,
Ms. Shanet Varghese to the APJ Abdul Kalam Technological University in partial
fulfillment of the requirements for the award of the Degree of Bachelor of Technology
in Computer Science and Engineering is a bonafide record of the project carried out
by them under our guidance and supervision. This report in any form has not been
submitted to any other University or Institute for any purpose.

Prof. Aby Abahai T


Prof. Neetha Joseph Prof. Leya Elizabeth Sunny Prof. Joby George

Project Guide Project Coordinator Head of the Dept.

Internal Examiner(s) External Examiner(s)

Dept. Seal

03.04.2020
ACKNOWLEDGEMENT

First and foremost, I sincerely thank the ‘God Almighty’ for his grace for the suc-
cessful and timely completion of the project.
I express my sincere gratitude and thanks to Dr. Mathew K, Principal and Prof.
Joby George, Head of the Department for providing the necessary facilities and their
encouragement and support.
I owe special thanks to the staff-in-charge Prof. Neetha Joseph and Prof. Leya
Elizabeth Sunny for their corrections, suggestions and sincere efforts to co-ordinate the
project under a tight schedule.
I express my sincere thanks to staff members in the department of Computer Science
and Engineering who have taken sincere efforts in helping me to conduct this project.
Finally, I would like to acknowledge the heartfelt efforts, comments, criticisms, co-
operation and tremendous support given to me by my dear friends during the prepara-
tion of the project and also during the presentation without whose support this work
would have been all the more difficult to accomplish.

i
ABSTRACT

Falsified and substandard drugs could contain inactive ingredients, active ingredi-
ents but in the wrong dosage or potential contaminants that could be lethal. The use
of antimicrobials of low quality may result in treatment failures and may increase an-
tibiotic resistance in individuals resulting in the spread of highly-resistant pathogens.
It can also cause allergic reactions and adverse drug reactions. When a drug package
change ownership from manufacturer to wholesaler, or from wholesaler to retailer, no
information is exchanged between parties that enable parties to track the drugs. Thus
there exist a lack of transparency about the original source of drugs. The problem can
be solved by tracking and tracing drug products and reagents and fake medicine de-
tection through information verification of supply chain participants using blockchain.
This option will be helpful when medications are distributed and become sensitive to
outer attacks. Drugs move across a distribution chain that involves several participants.
These usually include a manufacturer, a wholesaler, a retailer, a regulatory body and
the end-user. The regulating authority monitors quality standards. End-user can view
the drug distribution history .

ii
CONTENTS

LIST OF FIGURES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
LIST OF ABBREVIATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi

1 INTRODUCTION 2
1.1 Effects of counterfeits . . . . . . . . . . . . . . . . . . . . . . 3

2 SYSTEM ANALYSIS 5
2.1 FEASIBILITY STUDY . . . . . . . . . . . . . . . . . . . . . 6
2.1.1 Operational Feasibility . . . . . . . . . . . . . . . . . 6
2.1.2 Technical Feasibility . . . . . . . . . . . . . . . . . . . 6
2.1.3 Economic Feasibility . . . . . . . . . . . . . . . . . . . 7
2.2 EXISTING SYSTEM . . . . . . . . . . . . . . . . . . . . . . 7
2.2.1 Supplychain . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.2 Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.3 Problems in Existing System . . . . . . . . . . . . . 10
2.3 PROPOSED SYSTEM . . . . . . . . . . . . . . . . . . . . . 11

3 SYSTEM REQUIREMENTS 13
3.1 SOFTWARE REQUIREMENTS . . . . . . . . . . . . . . . 13
3.1.1 Ethereum . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1.2 HTML and CSS . . . . . . . . . . . . . . . . . . . . . 14
3.1.3 Smart Contract . . . . . . . . . . . . . . . . . . . . . . 16
3.1.4 JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.1.5 Solidity . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.1.6 Truffle . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.1.7 Ganache . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1.8 Metamask . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1.9 Infura . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1.10 npm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1.11 web3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.1.12 Node.js . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.1.13 AngularJS . . . . . . . . . . . . . . . . . . . . . . . . 21
3.1.14 lite-server . . . . . . . . . . . . . . . . . . . . . . . . . 21

4 SYSTEM DESIGN 23
4.1 INPUT DESIGN . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2 MODULE DESIGN . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.1 Batch-Id System . . . . . . . . . . . . . . . . . . . . 24
4.2.2 Traceability . . . . . . . . . . . . . . . . . . . . . . . . 26
4.2.3 Administrator . . . . . . . . . . . . . . . . . . . . . . 27

iii
4.2.4 Data Acquisition and Logging . . . . . . . . . . . . . 27
4.2.5 Complaint Tracking . . . . . . . . . . . . . . . . . . 28
4.2.6 Signing and Verifying Signatures . . . . . . . . . . . 28
4.3 OUTPUT DESIGN . . . . . . . . . . . . . . . . . . . . . . . 30

5 IMPLEMENTATION 32
5.1 Data Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.2 Data Processing . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.3 OUTPUT DATA . . . . . . . . . . . . . . . . . . . . . . . . . 35

6 RESULT 36

7 CONCLUSION 37
REFERENCES 56
ANNEXURE I 57

iv
LIST OF FIGURES

4.1 Digital Signature . . . . . . . . . . . . . . . . . . . . . . . . . . 29


4.2 Signature And Verification . . . . . . . . . . . . . . . . . . . . . 29
4.3 An Elliptic Curve Cryptosystem . . . . . . . . . . . . . . . . . . 30

v
LIST OF ABBREVIATIONS

ECDSA Elliptic Curve Digital Signature Algorithm

HTML Hypertext Markup Language

CGMP Current Good Manufacturing Practice

dApp Decentralized Application

ECMA European Computer Manufacturer’s Association

CSS Cascading Style Sheets

EVM Ethereum Virtual Machine

IDE Integrated Development Environment

RPC Remote Procedure Call

SASS Syntactically Awesome Style Sheets

ES6 ECMA Script version 6

XML Extensible Markup Language

JSX JavaScript XML

vi
Fraud Medicine Prevention Using Blockchain

54

B.Tech 2020 1 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

CHAPTER 1

INTRODUCTION

Counterfeit drugs are products that are deliberately made or labelled to


look alike a genuine product. The number of counterfeit medications has been
increasing subsequently over the years and the World Health Organization
(WHO) estimates that 10 percent of global pharmaceutical commerce is coun-
terfeit drugs. Patients suffering from various diseases intake these medicines
in the hope it would cure their illness. But on the contrary, tens of thousands
of deaths occur in developing countries due to fake drugs, and many of the
victims are children. Individuals, families and health systems are staggering
every year due to fake medicines.
A blockchain solution can make a significant difference to the pharmaceu-
tical supply chain. It is a decentralized network that shares information in
real-time with participants. And can be used as a solution to tracking and
tracing the products, by the pharmaceutical industry making sure there’s ver-
ifiable provenance of what is delivered to the users. Attaching a unique code
to each product they manufacture and registering the same in the blockchain,
would help to make this whole process transparent and secure. At each stage,
stakeholders could check about the authenticity of the product they have with
them.
The top priority in any health system is delivering of medicine as a strategic
product. In the present context of a health-conscious society, management of
pharmaceutical supply chains has become more complex because it involves the
life-saving interest of human being and requires the participation of different
stakeholders such as pharmaceutical manufacturers, wholesalers, distributors,
customers, information service providers and regulatory agencies. Limited re-
search is available in the area of pharmaceutical supply chains. Pharmaceutical
companies, a most important player of the drug supply chain, are subject to
many risks. These risks interrupt the quantity and quality of supply of medicine
and their delivery to the accurate place and customers and at the correct time
According to some estimates, more than 10 percent of all pharmaceuticals in
the global supply chain are counterfeit. In some countries, fake pharmaceuticals
account for 70 percent of all drugs in the supply chain. In the United States, the
number is much lower than average, but the U.S. supply chain is susceptible to
unauthorized diversion, which impacts drug makers significantly and calls into

B.Tech 2020 2 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

question the quality of any product that circumvents lawful trade channels.
Further, use of so-called Internet pharmacies by U.S. consumers introduces
substantial risk of spurious and fake medicine into the country, as more than
95 percent of such websites were found to not be in compliance with laws or
pharmacy practice standards, according to a recent survey by the National
Association of Boards of Pharmacy.
Counterfeiting of goods is widespread across many sectors like FMCG, elec-
tronics and apparel. But nowhere is its impact as profound and devastating as
the counterfeiting of pharmaceuticals. There is a severe economic and social
practice to be paid by patients. Counterfeiters are criminal opportunists. They
target markets in countries where the capacity to detect defective products and
the penalty for engaging in counterfeiting are low.
Compounding the magnitude of the problem is the complex nature of the
current pharmaceutical supply chains where drug development, API manu-
facturing, formulation, packaging and final consumption may often circle the
globe multiple times. The low investment high return aspect, difficulty in de-
tection of counterfeits, multiple potential points of leakage into the legitimate
drug supply chain and limited visibility of movement of inventory and stocks
offer an added incentive to criminal elements to pursue this activity.

1.1 Effects of counterfeits


The counterfeiting of pharmaceuticals has serious consequences for consumers,
health care providers, drug manufacturers and governments.10 Consumers can
be affected when there is illness or death, as has already happened on several
occasions in the developing world. Additionally, due to lost revenue, exposure
to huge damage claims (especially in the USA) and higher insurance rates,
consumers will be subject to higher prices for drugs.10 Health-care providers
are in a particularly difficult situation as there can be a decline in confidence
in public health systems, health care professionals and in government agencies
involved in distributing drugs.
In the USA and several other countries, there is greater possibility of litiga-
tion against health care professionals should consumer illness or death occur.
These workers will “need to prove that they have taken every step possible to
protect the integrity of the pharmaceuticals they administer.”
Drug manufacturers face similar issues to those described above especially
with respect to liability and the potential for lawsuits. Adam Scheer of Amer-
ican Bank Note Holographics Inc. has described the situation as follows:10
“Plaintiffs are holding drug manufacturers accountable, not only for the au-
thenticity of the products they manufacture, but the safeguards they have put
in place to prevent tampering in the field.” In addition, drug manufactur-
ers face damage to brand integrity as a single unsavoury incident can tarnish
reputations for many years. Also, there is considerable lost revenue to the
companies who have spent USD 500–800 million to develop a single drug.
Governments also face the critical issues of public health confidence and
widespread illnesses which could strain health care systems, lost tax revenues

B.Tech 2020 3 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

since counterfeit drugs bypass traditional sales avenues, and increased costs of
monitoring the efficacy and safety of pharmaceuticals.

B.Tech 2020 4 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

CHAPTER 2

SYSTEM ANALYSIS

System analysis is the process of gathering and interpreting facts, diag-


nosing the problem and using the information to recommend improvements on
the system. System analysis is problem solving activity that requires intensive
communication between the system users and the system developers. This is
an important phase of any system development process. The system is studied
in the minutest detail and analyzed.
The system analyst plays the role of an interrogator and dwells into the
working of the present system. The system is viewed as a whole and inputs
to the system are identified. Outputs from system are traced through various
phases of the processing of the inputs. The process of the system analysis
is largely concerned with determining, developing and agreeing users require-
ments perceived in business term. The system analysis phase is the prime
opportunity to communicate the users has conceived the join understanding
to determine the system features. A detailed study of these processes must be
made by the various techniques like interviews, questionnaires etc. The data
collected by these sources must be scrutinized to arrive to a conclusion. The
conclusion is an understanding of how the system functions.
In IT, systems analysis can include looking at end-user implementation of
a software package or product; looking in-depth at source code to define the
methodologies used in building software; or taking feasibility studies and other
types of research to support the use and production of a software product,
among other things.
Now this existing system is subjected to close study and the problem areas
are identified. The designer now functions as a problem solver and tries to
sort out the difficulties that the enterprise faces. The solutions are given as a
proposal. The proposal is the weighted with the existing system analytically
and the best one is selected. The proposal is presented to the user for an
endorsement by the user. This is a repeating process that ends as soon as the
user is satisfied with this proposal.

B.Tech 2020 5 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

2.1 FEASIBILITY STUDY


All projects are feasible when given unlimited resources and indefinite time.
It is both necessary and prudent to evaluate the feasibility of a project at the
earliest possible time. A feasible study is not warranted for system in which
economic justification is observed, technical risk is low, few legal problems
are expected and no reasonable alternatives exist. An alternative is made of
whether the identified user needs may be satisfied using our recent software
and hardware technologies. The study will decide if the proposed system will
be cost effective, from the business point of view and it can be developed in the
existing budgetary constraints. The feasibility study should be relatively sharp
and quick. The gesture should inform the decision of whether to go ahead with
a more detailed analysis. Feasibility study may be documented as a separated
report to higher officials of the top-level management and can be included as
appendices to the system specification. Feasibility and risk analysis is detailed
in many worries. If there is more project risk then the feasibility of producing
the quality software is reduced. The study is done in three phases.

• Operational Feasibility

• Operational Technical Feasibility

• Economic Feasibility

2.1.1 Operational Feasibility


Proposed projects are beneficial only if they can be turned into informa-
tion systems that will meet the organizations operating requirements. Simply
stated, the test of feasibility asks if the system will work when it is devel-
oped and installed. Are there any major barriers to implementations? Is there
sufficient support for the project from the management? Are current business
methods acceptable to the users? Have the users been involved in the planning
and development of the project? Will the proposed system cause any harm?
The purpose of the operational feasibility study is to determine whether the
new system will be used if it is developed and installed and whether there will
be resistance from users that will be resistance from users that will undermine
the possible application benefit. There was no difficulty in implemented the
software and proposed system is so effective, user friendly, functionally reliable
so that the users in the company will find that the new system reduces the
hard steps.

2.1.2 Technical Feasibility


A study of function, performances and constraints and improve the ability
to create an acceptable system. Technical feasibility is frequently the most dif-
ficult area to achieve at the stage of product engineering process. Considering
that are normally associated with the technical feasibility includes:

B.Tech 2020 6 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

• Development risk

• Resource availability

• Technology

Technical feasibility study deals with the hardware as well as the software
requirements. The scope was whether the work for the project is done with the
current requirements and the existing software technology has to be examined
in the feasibility study. The outcome was found to be positive.

2.1.3 Economic Feasibility


The cost evaluation is weighted against ultimate income or benefit derived
from the developed system or project. Economic justification is generally the
”Button line” consideration that includes cost benefit analysis, long term cor-
porate income strategies, impact on other profit centers or products, cost of
resources needed for development and potential market growth. When com-
pared to the advantage obtained from implementing the system its cost is
affordable. Also the system is designed to meet the modification required in
the future. Therefore most of the modifications can be done without much
re-work.

2.2 EXISTING SYSTEM


After a drug is launched, a completely different set of objectives, drivers,
and constraints become dominant. The key stakeholders in Main Issues Re-
lated to Pharmaceutical Supply Chain final product. The Pharmaceutical
Supply Chain include multiple government agencies, hospitals, clinics, drug
manufacturers, drug distributors, pharmacy chains, retailers, research orga-
nizations, and the FDA. Pharmaceutical organizations, globally, are facing
challenges meeting global quality standards, meet healthcare standards and
include reforms, and increased service requirements. To address such chal-
lenges, pharmaceutical companies must reduce costs, increase swiftness, and
improve speed to meet the market requirements. They need to define key
issues such as process and design development, capacity estimation, and logis-
tics management since they play a significant role in pharmaceutical supply
chain management. To compound matters further, the same supply chain is
responsible for the distribution of prescription drugs, over-the-counter (OTC)
medicines, generics, as well as biologics having different handling needs and op-
erational objectives. Indeed, there are numerous other organizations, such as
insurance companies, healthcare management organizations, and GPOs, that
further increase the complexity.
Due to very different business objectives, these organizations make the
task of managing supply chain all the more difficult. Furthermore, due to the
regulatory nature of the industry and numerous merger and acquisitions to
acquire more RD expertise, many pharmaceutical supply networks have grown

B.Tech 2020 7 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

in an uncontrolled fashion rather than being planned for optimal performance.


Visibility in supply chain is of utmost importance for firms to address pharma-
ceutical supply chain challenges. Drug shortages, fake products, and opioids is
pressuring firms in the pharmaceutical industry to track-and-trace goods for
the consumers’ protection and improve visibility of transactions. At times,
improving supply chain visibility in pharmaceutical industry may also increase
profit margins and result in safer products for customers.

2.2.1 Supplychain
The pharmaceutical industry is riddled with fundamental problems which
inhibits its rapid transformation. As a result of its peculiar environment, these
problems have a debilitating effect on every aspect of the industry, especially
the supply chain operations.Two issues that are fast becoming very worrisome
are counterfeiting and drug shortages. The FDA is extremely worried about
the growing problem of counterfeits .
While pharmaceutical manufacturers play a crucial role in ensuring ade-
quate supply, wholesalers, pharmacies, and hospitals play an equally critical
role in ensuring that patients are served effectively.

2.2.2 Roles
Admin
This guidance describes Admin’s current thinking on defining, establishing,
and documenting manufacturing activities of the parties involved in contract
drug manufacturing subject to current good manufacturing practice (CGMP)
requirements. In particular, we describe how parties involved in contract drug
manufacturing can use quality agreements to delineate their manufacturing
activities to ensure compliance with CGMP. This guidance describes how con-
tract manufacturing operations fit within the larger scheme of pharmaceutical
quality systems. It also presents the Agency’s current thinking on the roles
and manufacturing activities of the parties involved in contract manufacturing
arrangements. Specifically, this guidance addresses the relationship between
owners and contract facilities. For purposes of this guidance, we define owners
as manufacturers of APIs, drug substances, inprocess materials, finished drug
products, including biological products, and combination products. The term
owner does not apply to retail pharmacies, drug stores, supermarkets, discount
warehouse stores, or other retailers who purchase finished drug products to sell
over the counter as a store brand. For purposes of this guidance, we define con-
tract facilities as parties that perform one or more manufacturing operations
on behalf of an owner or owners.
The following three ICH guidances for industry contain relevant and valu-
able CGMP recommendations with respect to contract manufacturing arrange-
ments:

• Good Manufacturing Practice Guidance for Active Pharmaceutical In-


gredients

B.Tech 2020 8 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

• Quality Risk Management

• Pharmaceutical Quality System

Manufacturer
The pharmaceutical and medicine manufacturing industry develops and
produces a variety of medicinal and other health-related products that save
the lives of millions of people from various diseases and permits many people
suffering from illness to recover to lead productive lives.Drug manufacturing is
the process of industrial-scale synthesis of pharmaceutical drugs as part of the
pharmaceutical industry. The process of drug manufacturing can be broken
down into a series of unit operations, such as milling, granulation, coating,
tablet pressing, and others.
The pharmaceutical industry discovers, develops, produces, and markets
drugs or pharmaceutical drugs for use as medications to be administered (or
self-administered) to patients, with the aim to cure them, vaccinate them, or
alleviate the symptoms.[1][2] Pharmaceutical companies may deal in generic
or brand medications and medical devices. They are subject to a variety of
laws and regulations that govern the patenting, testing, safety, efficacy and
marketing of drugs.

Wholesaler
Wholesalers of medicines will be able to co-operate to facilitate distribu-
tion of essential medication and pharmacy products after being granted. This
follows an application by the National Pharmaceutical Services Association
(NPSA) to enable businesses to co-ordinate the supply, inventory management,
distribution, logistics, and import of pharmaceuticals needed by consumers and
hospitals.
A wholesale drug licensed firm can’t sell drugs unless such drug is purchased
under a cash or credit memo from a duly licensed dealer or a duly licensed
manufacturer.
A wholesale drug licensed firm can sell drugs only to a person having req-
uisite licence to sell stock or exhibit for sale, or distribute the drug. No sale
of any drug shall be made to a person not holding the requisite licence to sell
stock or exhibit for sale, or distribute the drug.

Pharmacists
Pharmacists should be more involved in all stages of medicines supply to
improve drugs availability because they have the knowledge of the stability pa-
rameters of particular drugs and the importance of the supply and distribution
of quality medicine.
Investment in training and education are needed if pharmacists are to
strengthen their roles within the medicines/biological supply chain. Pharma-
cists engaged, or interested in being engaged, in the supply chain may need
special courses, which are not provided by the basic curriculum for Pharma
Biotech Graduates.

B.Tech 2020 9 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

For example, the pharmacists often assume leadership roles, and so courses
in leadership and management should be provided in addition to courses in
logistics, Pharma Cold Chain Management, and Serialization as per the Good
Storage Distribution Practice guidelines and Drug Supply Chain Security Act.
To strengthen supply chain management in delivering quality medicine, the
government should establish a structured supply chain management system
with responsible Pharmacists, ensuring to monitor the entire distribution sys-
tem from Manufacturer till the end user (Patients).

2.2.3 Problems in Existing System

Shipment visibility makes transport processes transparent. Deliveries can


be tracked on their way to the customer - from collection to end-point delivery.
The carrier can immediately report any delay to the customer. In this way,
the goods recipient is informed even before they notice the delay.
Expiration-Improper disposal of unwanted medications can be very costly
and harmful to the environment and people’s health. Drug shortages, fake
products, and opioids is pressuring firms in the pharmaceutical industry to
track-and-trace goods for the consumers’ protection and improve visibility of
transactions. At times, improving supply chain visibility in pharmaceutical
industry may also increase profit margins and result in safer products for cus-
tomers.
Though counterfeiting of goods is prevalent across many sectors, its impact
is most profound in the healthcare sector. Counterfeiters target markets in
countries where the capacity to detect defective products and the penalty for
engaging in counterfeiting are low. This is one of the key pharmaceutical
supply chain challenges that needs immediate attention. Improving supply
chain management in pharmaceutical industry can help companies to respond
quickly to the actions of counterfeiters while minimizing the effort of policing.
Mutable and Invalid source is a major problem. Complex supply chains
and poor supply chain management in the pharmaceutical industry are mak-
ing it difficult for companies to address the demands of a rapidly evolving
marketplace. The under-utilization and inefficiency of supply chains to cope
with the sort of products coming down the pipeline are forcing pharmaceutical
companies to undergo a radical overhaul, creating challenges for companies.
Most of the top-soling medicines are biologics i.e., either they are pro-
duced from living organisms or contain components of living organisms. Such
medicines are heat sensitive and susceptible to contamination. Maintaining a
desired low-temperature range becomes one of the major pharmaceutical sup-
ply chain challenges that such companies face nowadays. Cold-chain shipping
is expected to be adopted more widely by companies. Some medicines are
manufactured from a patient’s own immune cells and need to be kept frosty
which can be a major challenge for companies. Cold-chain shipping will take
on an even greater role as more and more cell and gene therapies progress
through clinical testing and onto markets worldwide.
Many countries import a major portion of active pharmaceutical ingredi-

B.Tech 2020 10 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

ents from manufacturers in India and China. However, there have been certain
instances when the Food and Drug Administration has issued warning letters
to improve compliance. Suppliers and distributors need to abide by the norms
set by the Drug Supply Chain Security Act and ensure traceability of prod-
ucts, creating one of the major pharmaceutical supply chain challenges for
companies.
A lack of coordination occurs either because different stages of the supply
chain have objectives that conflict or because information moving between
stages is delayed and distorted. Different stages of a supply chain may have
conflicting objectives if each stage has a different owner. As a result, each stage
tries to maximize its own profits, resulting in actions that often diminish total
supply chain profits.
Slow Process and Error prone paper work

2.3 PROPOSED SYSTEM


The proposed blockchain based solution maintains transactional records of
all the participants involved in the drug supply chain. The supply chain par-
ticipants request their corresponding roles as a manufacturer, supplier, whole-
saler, distributor to the admin by providing with relevant documents to prove
and support it. The admin verifies the documents and assigns roles to the
requested supply chain participants. The admin has the privilege to revoke
the role assigned to the involved participants in case of fraudulent activities.
The supplier provides the manufacturer with raw materials required to
manufacture the medicines and provide with the description of raw materials,
location, farmer name, etc. The manufacturer will manufacture the drug with
details such as drug name, location, timestamp, ingredients, usage of the drug,
etc. and get authorized by the regulatory authority. The Shipper associated
with the supplier and the manufacturer ships the raw materials to the required
location. When the smart contract between supplier and manufacturer is de-
ployed, the ethereum addresses of the involved supplier, manufacturer, and
the shipper is given. These addresses cannot be changed once the smart con-
tract gets deployed. Thus ensuring that a fraudulent node cannot perform
transactions as their ethereum network addresses are different.
When the manufacture adds the information it gets stored to the blockchain
making it possible to trace the drugs’ supply chain transparently for other
stakeholders. A hash ID is produced that can be used for tracking back the
transactions, once the information is added to the blockchain. Once the shipper
service providers deliver the drugs to wholesalers, they can verify the origin
of medicines with the help of a unique ID stored on the blockchain. The
manufacturer provides the wholesaler with the medicines.
The distributor gets the medicines from the wholesaler who in turn supplies
it to the pharmacies. Pickup can be done only by an associated transporter and
is involved with the transactions of wholesalers, distributors, and pharmacies.
Illegitimate users cannot access the blockchain and only associated legitimate
users can participate in transactions.

B.Tech 2020 11 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

What we are providing

• Accurate information across the entire chain at any point and at any
location

• access to real-time updates and alerts if issues are detected

• Visibility of all handovers in the supply chain.

• Traceability back to source of all materials.

• Seamless collaboration between all parties.

• Reduce paper work and Speedup process.

B.Tech 2020 12 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

CHAPTER 3

SYSTEM REQUIREMENTS

To understand the nature of the software to be built, the software engi-


neer must understand the information domain of the software, as well as the
required function, performance, and interface. Requirement definition is the
activity of translating information gathered during analysis activity into a doc-
ument that defines a set of requirements. Requirement definition is the high
abstract description of requirements. Requirements may be functional or non-
functional. Most software defines two sets of system requirements: minimum
and recommended. With increasing demand for higher processing power and
resources in newer versions of software, system requirements tend to increase
over time. Industry analysts suggest that this trend plays a bigger part in driv-
ing upgrades to existing computer systems than technological advancements.
A second meaning of the term of System requirements, is a generalisation of
this first definition, giving the requirements to be met in the design of a sys-
tem or sub-system. Typically an organisation starts with a set of Business
requirements and then derives the System requirements from there.

3.1 SOFTWARE REQUIREMENTS


The software requirements explain the software components that we need to
develop our project. It is selected such a way that it reduces our work and easy
to implement the project anywhere. Software requirements deal with defining
software resource requirements and prerequisites that need to be installed on a
computer to provide optimal functioning of an application. These requirements
or prerequisites are generally not included in the software installation package
and need to be installed separately before the software is installed.

3.1.1 Ethereum
Ethereum is a global, decentralized platform for money and new kinds of
applications. On Ethereum, one could write code that controls the money,
and build applications which is accessible across the world. In the Ethereum
platform, instead of mining for bitcoin, miners work to earn Ether, which is a

B.Tech 2020 13 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

type of crypto token that fuels for the network. Beyond an exchangable cryp-
tocurrency, Ether is also used by application developers to pay for transaction
fees and services on the ethereum network.
There is a second type of token that is used to pay miners fees for including
transactions in their block, it is called gas, and every smart contract execution
requires a certain amount of gas to be sent along with it to entice miners to
put it in the blockchain.
Ethereum enables developers to make and deploy decentralized applica-
tions. A decentralized application or Dapp serve some particular purpose to
its users. Bitcoin, for example, is a Dapp that provides its users with a peer to
peer electronic cash system that enables online Bitcoin payments. Because de-
centralized applications are made up of code that runs on a blockchain network,
they are not controlled by any individual or central entity.
Any services that are centralized can be decentralized using ethereum.
Think about all the intermediary services that exist across hundreds of different
industries. From obvious services like loans provided by banks to intermedi-
ary services rarely thought about by most people like title registries, voting
systems, regulatory compliance and much more. Ethereum can also be used
to build Decentralized Autonomous Organizations (DAO). A DAO is a fully
autonomous, decentralized organization with no single leader. DAO’s are run
by programming code, on a collection of smart contracts written on ethereum.
The code is designed to replace the rules and structure of a traditional orga-
nization, eliminating the need for people and centralized control. A DAO is
owned by everyone who purchases tokens, but instead of each token equating
to equity shares ownership, tokens act as contributions that give people vot-
ing rights. Ethereum has recently created a new standard called the ERC721
token for tracking unique digital assets. One of the biggest use cases currently
for such tokens is digital collectibles, as the infrastructure allows for people to
prove ownership of scarce digital goods. Many games are currently being built
using this technology, such as the overnight hit CryptoKitties, a game where
you can collect and breed digital cats.
Since decentralized applications run on the blockchain, they have the fol-
lowing benefits.
• Immutability – A third party cannot make any changes to data.
• Corruption tamper proof – Apps are based on a network formed around
the principle of consensus, making censorship impossible.
• Secure – With no central point of failure and secured using cryptography,
applications are well protected against hacking attacks and fraudulent
activities.
• Zero downtime – Apps never go down and can never be switched off.

3.1.2 HTML and CSS


Hypertext Markup Language (HTML) is the standard markup language
for documents designed to be displayed in a web browser. It can be assisted

B.Tech 2020 14 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

by technologies such as Cascading Style Sheets (CSS) and scripting languages


such as JavaScript.Web browsers receive HTML documents from a web server
or from local storage and render the documents into multimedia web pages.
HTML describes the structure of a web page semantically and originally in-
cluded cues for the appearance of the document.
HTML elements are the building blocks of HTML pages. With HTML con-
structs, images and other objects such as interactive forms may be embedded
into the rendered page. HTML provides a means to create structured docu-
ments by denoting structural semantics for text such as headings, paragraphs,
lists, links, quotes and other items. HTML elements are delineated by tags,
written using angle brackets. Tags such as ¡img /¿ and ¡input /¿ directly in-
troduce content into the page. Other tags such as ¡p¿ surround and provide
information about document text and may include other tags as sub-elements.
Browsers do not display the HTML tags, but use them to interpret the content
of the page.
Different features of html are,

• It is a very easy and simple language. It can be easily understood and


modified.

• It is very easy to make an effective presentation with HTML because it


has a lot of formatting tags.

• It is a markup language, so it provides a flexible way to design web pages


along with the text.

• It facilitates programmers to add a link on the web pages (by html anchor
tag), so it enhances the interest of browsing of the user.

• It is platform-independent because it can be displayed on any platform


like Windows, Linux, and Macintosh, etc.

• It facilitates the programmer to add Graphics, Videos, and Sound to the


web pages which makes it more attractive and interactive.

• HTML is a case-insensitive language, which means we can use tags either


in lower-case or upper-case.

Cascading Style Sheets, fondly referred to as CSS, is a simple design lan-


guage intended to simplify the process of making web pages presentable.
CSS handles the look and feel part of a web page. Using CSS, you can
control the color of the text, the style of fonts, the spacing between paragraphs,
how columns are sized and laid out, what background images or colors are used,
layout designs,variations in display for different devices and screen sizes as well
as a variety of other effects.
CSS is easy to learn and understand but it provides powerful control over
the presentation of an HTML document. Most commonly, CSS is combined
with the markup languages HTML or XHTML.
Advantages CSS are:

B.Tech 2020 15 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

• CSS saves time: You can write CSS once and then reuse same sheet in
multiple HTML pages. You can define a style for each HTML element
and apply it to as many Web pages as you want.

• Pages load faster: If you are using CSS, you do not need to write
HTML tag attributes every time. Just write one CSS rule of a tag and
apply it to all the occurrences of that tag. So less code means faster
download times.

• Easy maintenance:To make a global change, simply change the style,


and all elements in all the web pages will be updated automatically.

• Superior styles to HTML:CSS has a much wider array of attributes


than HTML, so you can give a far better look to your HTML page in
comparison to HTML attributes.

3.1.3 Smart Contract


Smart contracts are lines of code that are stored on a blockchain and
automatically execute when predetermined terms and conditions are met. At
the most basic level, they are programs that run as they’ve been set up to run
by the people who developed them. The benefits of smart contracts are most
apparent in business collaborations, in which they are typically used to enforce
some type of agreement so that all participants can be certain of the outcome
without an intermediary’s involvement.
Smart contracts can:

• Function as ’multi-signature’ accounts, so that funds are spent only when


a required percentage of people agree

• Manage agreements between users, say, if one buys insurance from the
other

• Provide utility to other contracts (similar to how a software library works)

• Store information about an application, such as domain registration in-


formation or membership records.

Smart contracts work by following simple “if/when. . . then. . . ” statements


that are written into code on a blockchain. A network of computers executes
the actions (releasing funds to the appropriate parties; registering a vehicle;
sending notifications; issuing a ticket) when predetermined conditions have
been met and verified. The blockchain is then updated when the transaction
is completed.

3.1.4 JavaScript
JavaScript is a very powerful client-side scripting language. JavaScript is
used mainly for enhancing the interaction of a user with the webpage. In other

B.Tech 2020 16 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

words, we can make your webpage more lively and interactive, with the help
of JavaScript.Being a scripting language, JavaScript cannot run on its own.
In fact, the browser is responsible for running JavaScript code. When a user
requests an HTML page with JavaScript in it, the script is sent to the browser
and it is up to the browser to execute it. The main advantage of JavaScript
is that all modern web browsers support JavaScript. So, you do not have to
worry about whether your site visitor uses Internet Explorer, Google Chrome,
Firefox or any other browser, JavaScript will be supported. Also, JavaScript
runs on any operating system including Windows, Linux or Mac.
Alongside HTML and CSS, JavaScript is one of the core technologies of the
World Wide Web. JavaScript enables interactive web pages and is an essential
part of web applications. The vast majority of websites use it for client-side
page behavior, and all major web browsers have a dedicated JavaScript engine
to execute it.
JavaScript language consists of several different features. Some of the gen-
eral JavaScript features are as follows ,

• Validating User’s Input: JavaScript is very useful while using forms.


It has the capability to validate user input for errors and also saves time.
If the user leaves a required field empty or the information is incorrect,
JavaScript checks for them before sending the data over to the server

• Simple Client-side Calculations:Since JavaScript is a client-side tech-


nology, it can perform basic calculations on the browser. The browser
does not need to ask server time for every task. This is especially help-
ful when a user needs to perform these calculations repeatedly. In these
cases, connecting to the server would take a lot more time than perform-
ing the actual calculations.

• Greater Control:JavaScript provides greater control to the browser


rather than being completely dependent on the web servers. JavaScript
provides various browsers with additional functionalities that help reduce
server load and network traffic.

• Platform Independent:Since browsers interpret JavaScript, it solves


the problem of compilation and compatibility. Thus it can run on Win-
dows, Macintosh, and other Netscape-supported systems. Also, it is pos-
sible to embedd them in any other script like HTML that keeps JavaScript
into use.

• Handling Dates and Time:Unlike other programming languages, JavaScript


has built-in functions to determine the date and time. Thus it is very
easy to code only by using methods like .getDate().

• Generating HTML Content:JavaScript has very handy features to


dynamically generate HTML content for the web. It allows us to add
text, links, images, tables, etc after an event occurrence (eg – mouse
click).

B.Tech 2020 17 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

JavaScript has become amusing as well as a really exciting space to work in


recent years. JavaScript has accomplished a well-organized, sustainable code
base to language that gives great productivity, readability and accessibility
which is also pretty fun to work with.

3.1.5 Solidity
Solidity is a contract-oriented, high-level programming language for imple-
menting smart contracts. Solidity is highly influenced by C++, Python and
JavaScript and has been designed to target the Ethereum Virtual Machine
(EVM).
Solidity is a statically-typed curly-braces programming language designed
for developing smart contracts that run on the Ethereum Virtual Machine.
Smart contracts are programs that are executed inside a peer-to-peer network
where nobody has special authority over the execution, and thus they allow to
implement tokens of value, ownership, voting and other kinds of logics.

3.1.6 Truffle
Truffle is a development environment, testing framework and asset pipeline
for Ethereum, aiming to make life as an Ethereum developer easier. It is one
of the most widely used IDEs in the Ethereum community. Developers can
use it to build and deploy DApps for testing purposes with many features that
make it more attractive to users with a Web 3.0 dev background.
Anyone who wants to dive into Ethereum development and needs a frame-
work so they can better organize their DApp development assets and not have
to worry about manually setting up a test environment.The advantages include
:

• Automated contract testing with Mocha and Chai.

• A configurable build pipeline that supports both web apps and console
apps.

• Generators for creating new contracts and tests (like rails generate)

• Instant rebuilding of assets during development (truffle watch)

• Console to easily work with your compiled contracts (truffle console)


Script runner that lets you run JS/Coffee files with your contracts in-
cluded (truffle exec)

• Contract compilation and deployment using the RPC client of your choice.

• Support for JavaScript, CoffeeScript, SASS, ES6 and JSX built-in.

B.Tech 2020 18 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

3.1.7 Ganache
Ganache is a personal blockchain for rapid Ethereum and Corda distributed
application development. You can use Ganache across the entire development
cycle; enabling you to develop, deploy, and test your dApps in a safe and
deterministic environment.
Ganache UI is desktop application supporting both Ethereum and Corda
technology. In addition, an Ethereum version of ganache is available as a
command-line tool: ganache-cli (formerly known as the TestRPC). All versions
of Ganache are available for Windows, Mac, and Linux.

3.1.8 Metamask
MetaMask is the easiest way to interact with dapps in a browser. It is an
extension for Chrome or Firefox that connects to an Ethereum network without
running a full node on the browser’s machine. It can connect to the main
Ethereum network, any of the testnets (Ropsten, Kovan, and Rinkeby), or a
local blockchain such as the one created by Ganache or Truffle Develop.
MetaMask manages your Ethereum wallet, which contains your Ethers (or
money), and allows you to send and receive Ethers through a dApp of interest.

3.1.9 Infura
Infura is a platform as a service for Ethereum networks. Using Infura, you
can connect to Ethereum Test or Main networks by exposing an URL. If you
want to connect your DApp with any of the Ethereum networks (test or Main)
without setting the Ethereum Network
2. If you want to focus only on the application features for a while without
having to care about which network it will run on

3.1.10 npm
It is an online repository for the publishing of open-source Node.js projects.
It is a command-line utility for interacting with said repository that aids in
package installation, version management, and dependency management. A
large number of Node.js libraries and applications are published on npm. Many
more are added every day. It consists of a command line client, also called npm
and an online database of public and paid-for private packages. This is called
the npm registry. The registry is accessed via the client, and the npm website
can be browsed and searched for available packages. The package manager and
the registry are managed by npm.
npm can manage packages that are local dependencies of a particular project
and also globally-installed JavaScript tools. When used as a dependency man-
ager for a local project, npm can install all the dependencies of a project in one
command through the package.json file. Each dependency can specify a range

B.Tech 2020 19 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

of valid versions using the semantic versioning scheme. This allows develop-
ers to auto-update their packages and at the same time avoiding unwanted
breaking changes. npm also provides version-bumping tools for developers to
tag their packages with a particular version. npm also provides the package-
lock.json file which has the entry of the exact version. This is used by the
project after evaluating semantic versioning in package.json.

3.1.11 web3
web3.js is a collection of libraries which allow you to interact with a local or
remote ethereum node, using a HTTP or IPC connection. The web3 JavaScript
library interacts with the Ethereum blockchain. It can retrieve user accounts,
send transactions, interact with smart contracts, and more.
Web3.js talks to The Ethereum Blockchain with JSON RPC, which stands
for ”Remote Procedure Call” protocol. Ethereum is a peer-to-peer network of
nodes that stores a copy of all the data and code on the blockchain. Web3.js
allows us to make requests to an individual Ethereum node with JSON RPC
in order to read and write data to the network. It’s kind of like using jQuery
with a JSON API to read and write data with a web server.

3.1.12 Node.js
Node.js is an open-source, cross-platform, JavaScript runtime environment
that executes JavaScript code outside of a web browser. Node.js allows develop-
ers to use JavaScript to write command line tools and for server-side scripting
i.e running scripts server-side to produce dynamic web page content before
the page is sent to the user’s web browser. Consequently, Node.js represents
a ”JavaScript everywhere” paradigm. It unifies web-application development
around a single programming language, rather than different languages for
server- and client-side scripts.
Though .js is the standard filename extension for JavaScript code, the name
”Node.js” doesn’t refer to a particular file in this context and is merely the
name of the product. Node.js has an event-driven architecture. It is capable
of asynchronous I/O. These design choices aim to optimize throughput and
scalability in web applications. It has many input/output operations and also
for real-time Web applications.
Node.js allows the creation of Web servers and networking tools using
JavaScript and a collection of modules that handle various core functional-
ities. Modules are provided for file system I/O, networking (DNS, HTTP,
TCP, TLS/SSL, or UDP), binary data (buffers), cryptography functions, data
streams, and other core functions. Node.js’s modules use an API designed to
reduce the complexity of writing server applications.
Node.js allows querying the ledger. The ledger is queried using the invoke.js
program. This program will call the query method in the model class which
will in turn call the function of the chaincode to query data. In this way we
can either retrieve data from the ledger or edit it(only if all users agree upon

B.Tech 2020 20 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

it).

3.1.13 AngularJS
AngularJS is a JavaScript-based open-source front-end web framework
mainly maintained by Google and by a community of individuals and corpora-
tions to address many of the challenges encountered in developing single-page
applications. It aims to simplify both the development and the testing of such
applications by providing a framework for client-side model–view–controller
(MVC) and model–view–viewmodel (MVVM) architectures, along with com-
ponents commonly used in rich Internet applications.
AngularJS is the frontend part of the MEAN stack, consisting of MongoDB
database, Express.js web application server framework, Angular.js itself, and
Node.js server runtime environment. Version 1.7.x is on Long Term Support
until July 1st 2021. After that date AngularJS will no longer be updated and
Angular (2.0+) is suggested instead.
The AngularJS framework works by first reading the Hypertext Markup
Language (HTML) page, which has an additional custom HTML attributes
embedded into it. Angular interprets those attributes as directives to bind
input or output parts of the page to a model that is represented by standard
JavaScript variables. The values of those JavaScript variables can be manually
set within the code, or retrieved from static or dynamic JSON resources.
AngularJS is built on the belief that declarative programming should be
used to create user interfaces and connect software components, while im-
perative programming is better suited to defining an application’s business
logic.[5] The framework adapts and extends traditional HTML to present dy-
namic content through two-way data-binding that allows for the automatic
synchronization of models and views. As a result, AngularJS de-emphasizes
explicit Document Object Model (DOM) manipulation with the goal of im-
proving testability and performance.

3.1.14 lite-server
Lite-server is a lightweight node server that serves a web app, opens it in
the browser, refreshes when the page content changes in html or javascript,
injects CSS changes using sockets, and has a redirected page when a route is
not to be found.
BrowserSync does most of what is required in a fast lightweight development
server. It renders the static content, detects the changes made, refreshes the
browser, and offers customizations that can be incorporated by user. When
creating a Single Page Application there are routes that are known only to the
browser. For example, /book/21 may be a route for an Angular app at the
client side. If this route is entered manually as the entry point of the Angular
app the static server will receive the request and handle the request. This is
because Angular is not loaded yet. Since the route requested cannot be found,
the server will not find a match for it and thus return a page not found error of

B.Tech 2020 21 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

404. The desired behavior in this case is to return the index.html (or whatever
starting page of the app was defined). BrowserSync does not automatically
allow for a redirected page. But it does allow for custom middleware. This is
where the use of lite-server arises. Lite-server is an easy customized wrapper
around BrowserSync to make it easy to provide SPAs.

B.Tech 2020 22 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

CHAPTER 4

SYSTEM DESIGN

Systems design is the process of defining the architecture, modules, inter-


faces, and data for a system to satisfy specified requirements. Systems design
could be seen as the application of systems theory to product development.
This is the phase in which the details of the system selected in the study phase
is designed. Software design is the preliminary step and is also building block
of software engineering. The efficiency software is promoted through design
phase. The design phase begins when the requirement specification document
for the software to be developed is available. Design is the first step to moving
from the problem domain to the solution domain. Design is essentially the
bridge between requirement specification and the final solution for satisfying
the requirements.

4.1 INPUT DESIGN


It is the part of the overall system design. The input methods can be broadly
classified into batch and online. Internal control must be established for mon-
itoring number of inputs and for ensuring that the data is valid. The basic
steps involved in the system design are:

• Review input requirements.

• Decide how the input data flow will be maintained.

• Design the source document.

• Prototype online input screens.

The quality of the system input determines the quality of the system output.
Input specification describes the manner in which data enter the system for
processing. Input design features can ensure the reliability of the system and
produce results from the accurate data, or they can result in production. The
input design also determines whether the user can interact efficiently with the
system.

B.Tech 2020 23 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

Input design is the process of converting a user oriented description to a


computer based system. Input design is designed on estimating what the inputs
are and how often they are to be arranged on the input screen, how frequently
the data are to be collected etc. The input in this project is taken from the
evaluators and entered into the blockchain.

4.2 MODULE DESIGN


Modular design is a design theory and practice that subdivides a system
into smaller parts called modules, which can be independently created, modi-
fied, replaced or exchanged between different systems. A modular design can
be characterized by functional partitioning into discrete scalable and reusable
modules, rigorous use of well-defined modular interfaces, and making use of
industry standards for interfaces. A modular system with this limited modu-
larity is generally known as a platform system that uses modular components.
Modularity offers many advantages to designers. It allows us to work out solu-
tions to common problems independently of projects. This independent work
enables us to consistently improve our solutions and it leads to an efficiency
in development through reuse. Since the functionality of the software have
been broken down into atomic levels, thus developers get a clear requirement
of each and every functions and hence designing of the software becomes easy
and error free. As the modules are independent they have limited or almost
no dependency on other modules. So, making changes in a module without
affecting the whole system is possible in this approach. Error propagation from
one module to another and further in whole system can be neglected and it
saves time during testing and debugging.
The modular design can shrink production and management costs by quick
procession of the specific needs of individual end users. Modularisation en-
ables breaking up of a greater whole into interchangeable parts that fit to-
gether seamlessly and together in many different combinations and permuta-
tions make many different wholes. The gradual evolution towards modulari-
sation of supply chains is being spearheaded by the customers who demand
control and flexibility in their supply chains coupled with low cost. Modulari-
sation is preceded by Standardisation – achieving commonality in terminology,
in measurements and in activities. Standardisation is essential to modularisa-
tion because it helps simplify the complexity and bring uniformity. Modularity
offers many advantages to designers. It allows us to work out solutions to com-
mon problems independently of projects. This independent work enables us to
consistently improve our solutions and it leads to an efficiency in development
through reuse.
The major modules in this project are listed as follows.

4.2.1 Batch-Id System


There is a need to identify each product uniquely. This is achieved by the
process of serialization. Serialization is a technique by which which identifiers

B.Tech 2020 24 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

can be generated from data that is relevant to the system.


Serialization goes beyond traditional lot and batch level traceability to iden-
tify individual items as they are manufactured and distributed through retail or
other end points to the end consumer. As such, serialization provides item-level
traceability and potentially the ability to authenticate whether any individual
item is authentic and/or whether that item has been distributed through le-
gitimate channels.
Serialization in the supply chain provides many business benefits for both
manufacturers and consumers. Serialization separates the good from the bad
without disrupting the entire manufacturing process. Serialization leads to
better inventory management. Plus, it yields greater chain integrity, and the
ability to process returns. Supply chain managers with access to serialized data
can track an item’s real-time status. As a result, manufacturers can streamline
their operations through enhanced accuracy and efficiency. The benefits of
serialization go far beyond cost savings. Being able to track and trace the
source of recalled products, results in quick removal from store shelves.To date,
the use of serialization as an anti-theft tool is not widespread, but the potential
is there. Batch-id is generated using serialization technique to uniquely identify
medicines. The unique identifier is assigned to each unit of medicine.
Without a way to pinpoint the locations that received tainted product,
manufacturers must recall all items shipped within a particular time frame.
Serialization can help with that. However, organizations that focus their seri-
alization efforts on recall management will experience some benefits, but they
will lack the granular end details that can support more effective solutions,
more precise recalls, tighter inventory control and better identification of fraud-
ulent activity. A serialization strategy that provides the infrastructure to allow
transparency across trading partners enables the timely track-and-trace capa-
bilities that can help reduce this type of counterfeit risk, fraud and diversion.
Regulatory compliance should be the byproduct, not the goal, of serializa-
tion. Ideally, organizations should look for enterprise-wide solutions that will
ultimately support sharing serialization information across the internal supply
chain as well as among trading partners. This requires integrating serialization
data with the system and adding context or business data, ultimately tying
it all to the serial number. This end-to-end approach not only enables timely
track-and-trace capabilities, but it also expands advantages throughout the en-
tire supply chain as it enables synergistic benefits from the business data in the
system. This connection between the serialization system and the supplychain
makes it possible gain visibility of product from the point of manufacturer to
the patient.
It is the ability to use the business information stored with each serial num-
ber that makes product serialization valuable. A serialization strategy provides
real-time visibility throughout the entire supply chain offers significant bene-
fits for the entire organization. An enterprise-wide serialization strategy could
provide the necessary level of visibility to allow companies to control various
costs by ensuring that returned product is credited at the cost at which it was
sold. An enterprise-wide serialization solution could also integrate the infor-
mation in warehousing, order fulfillment, etc., providing a level of granularity

B.Tech 2020 25 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

that increases shipping accuracy and reduces the likelihood of taking back in-
eligible returns. Extending information capture to trading partners enhances
the benefits. A serialization strategy that extends to trading partners also ad-
dresses issues with special pricing, controlling who gets the price and how those
chargebacks are executed and also preventing the problem of duplicate charge-
backs. Manufacturers save the costs associated with manually investigating
discrepancies in chargeback requests and resolve disputes more quickly.

4.2.2 Traceability
Traceability is a key component of the modern supply chain. It lets supply
chain providers understand how inventory moves across the network. Traceabil-
ity adds visibility from a material’s origin to the product’s delivery.To ensure
patient safety, companies and distributors need to identify and track items
throughout the supply chain. This gives supply chain providers real-time in-
sights into a serialized product’s history, including chain of custody. Manufac-
turers and distributors can ensure regulatory compliance to mandates.
Full product traceability is perhaps the most important result of serializa-
tion. In instances needing recall management, it’s possible for the manufac-
turing run to remain intact. This is possible by recalling only the defective
batches with specific serial numbers. Traceability keeps owners and retailers
completely up to date with all volumes passing through the supply chain. This
allows products to be tracked back to source at any time and related batches
and shipments to be easily identified. Automated tracking throughout the
supply chain is critical for efficient response to events, and an end-to-end seri-
alization solution supports more effective recalls. Companies that can promise
recall integrity increase patient safety. This may help differentiate their prod-
uct, boost their brand image in the eyes of customers and end users, and help
protect the reputation from negative consequences.
Traceability provides a number of benefits. It improve the integrity of your
supply chain and helps to track products from source to consumer. It also
helps to trace products back to their origin with support for multiple Chain of
Custody models. Serialization technique implemented on batch-id generation
reduces the risk of mislabeling products. Traceability of supply chain products
enables to perform more effective audits by having full information at hand
and helps to perform rapid traceability analysis in crisis situations. Drawing a
real-time picture of where product is at any point in the supply chain enables
tighter inventory control, especially in short-supply situations, and drives bet-
ter understanding of the impact of disruptions or process changes, ultimately
supporting better decision making.
An end-to-end system can capture key information and metrics as the prod-
uct moves through production, associate it with the serial number and make
appropriate information available to trading partners. This information could
include anything from quality assurance data to special handling requirements
to business data. For example, manufacturers could share information to help
ensure that specifications—such as required storage temperature—are met as
the product moves through the supply chain. This benefit becomes increasingly

B.Tech 2020 26 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

important as the industry increasingly moves toward specialty drugs, many of


which have high degrees of control requirements.

4.2.3 Administrator
In supplychain, a participant needs to be verified and authenticated in
order to participate in transactions. This role is carried out by the administra-
tor. Each supplychain participant must verify their authenticity and register
through the administrator nodes. Each stakeholder has a unique identifier
facilitated by their ethereum accounts. Each entity in the supply chain that
handles these medicines, including prescribers, dispensers, manufacturers and
distributors, is a registrant of the administrator. The stakeholder requests
to register as an authentic participant in blockchain transactions using their
ethereum accounts and the administrator upon verification allows the partic-
ipant to register successfully. The participant role can be altered or assigned
only by the administrator. Upon the discovery of any illegal activities, the
participant role can be revoked or suspended by the administrator. The ad-
ministrator has has the authority to impose regulations regarding the design,
monitoring, control, and maintenance of drug manufacturing processes and
facilities and can formulate policies to be followed accross the supplychain.

4.2.4 Data Acquisition and Logging


The transactions that are carried out by the supplychain participants are
logged into the blockchain whenever the transactions are carried out. This en-
sures that the transactions are immutable and cannot be tampered by anyone.
A hash is generated from the data in a particular node. This hash value and
the hash of the previous node is also stored in a particular node. The hash
generated for a particular node is the sum up or a gist of the contents in the
node. So if transactions are altered by any fraud participant its hash value will
change and will not match with that stored in the node and in this way all the
other participants will come to know about it.
Blockchain is an online ledger that lends decentralized and transparent
data sharing. Data of various types are distributed in distinct blocks, enabling
verifications to be made without the use of intermediaries. All the blocks then
form a blockchain with timestamps. The whole procedure is open to the public,
transparent, and secure. So blockchain provides a secure way of entering data.
Blockchain can be explained as a growing list of records called blocks. Each
block in a blockchain contains a cryptographic hash of the previous block,
data and a timestamp. The data in blockchain is tamper proof. It is an open
distributed ledger that records data in a permanent and verifiable way.
Blockchain is managed by a peer-to-peer network adhering to a protocol for
internode communication and validating new blocks. Once the data is recorded
in a block, it can’t be altered without alteration of all successive blocks in
blockchain, which requires permission of the network majority. Blockchain can
be used in digital identity, tokenization, financial, markets, inter-organizational

B.Tech 2020 27 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

data management and many more.

4.2.5 Complaint Tracking


With the tracking and tracing of medicines, user can verify whether the
medicine he posses is a real one and/or is from the legitimate manufacture.
User enters the unique serial code that identifies the medicine unit to fetch the
transaction history of the item. User is provided with the whole travelled path
of that medicine. If there is any complaint regarding the quality or authentic-
ity of the product, a complaint can be raised to the admin node. The admin
node receives the request and fetch the transaction details of the corresponding
medicine. The admin node analyses the complaint using the details fetched and
if relevant raises an enquiry to the authorities to inquire into the matters. First
of all, record the issue when and where it arises. The next step is to capture
supporting information like supplier, batch id, nature of complaint, details,
date of complaint, quantity affected, and quantity received.Attach related doc-
uments which include the supplier certificates, delivery notes, photographs of
defects etc. Send emails to notify people/groups internally or direct with sup-
pliers. Manage the complaint and change its status as it moves through the
process to keep the user informed about the updates. Track the progress of
the complaint and any associated actions on a timely manner.
With the help of the efficient tracking mechanism, the point of failure can
be isolated with precision which helps the authorities to solve the complaint
with ease. By putting in place a robust participant non-conformance manage-
ment system you can benchmark suppliers and drive them to deliver better
quality. Raising and resolving complaints help to record issues and all related
information. The system can be build to automatically notify various people
/ groups and helps to enforce the business process to manage the complaint
through to resolution. It develops a history of issues against each supplier to
assess performance. It can be used to analyse the nature and frequency of
complaints to evaluate suppliers’ performance over time.

4.2.6 Signing and Verifying Signatures


Cryptographic signatures are a foundational computer science primitive
that enables all blockchain technology. Signatures can be used to authorize
transactions on behalf of the signer. It can also be used to prove to a smart
contract that a certain account approved a certain message. Cryptographic sig-
natures can be used to validate the origin and integrity of messages. Senders
signs messages detailing their order using their private key. Modern cryptog-
raphy is founded on the idea that the key that you use to encrypt your data
can be made public while the key that is used to to decrypt your data can be
kept private. As such, these systems are known as public-key cryptographic
systems.

B.Tech 2020 28 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

Figure 4.1: Digital Signature

Each account in the Ethereum network has a public key and a private key.
An Ethereum address is essentially a hashed version of the public key. Accounts
can use their private key to sign a piece of data, returning a signature of that
data. Anyone can verify the generated signature to recover the public key /
address of the signer and to verify the integrity of the message, that it is the
same message that was signed by the signer. Signing and the verification of
ECDSA-signed messages allows tamper proof communications outside of the
blockchain.

Figure 4.2: Signature And Verification

Elliptic Curve Digital Signature Algorithm(ECDSA) was proposed to ad-


dress the drawbacks of RSA, which is an alternative cryptographic algorithms
proposed around the mathematics of elliptic curves. An elliptic curve cryp-
tosystem can be defined by picking a prime number as a maximum, a curve
equation, and a public point A on the curve.

B.Tech 2020 29 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

Take any two points on the curve above and draw a line through them;
the line will intersect the curve at exactly one more place. Like a game of
billiards, take a ball from point A and shoot it towards point B. When it hits
the curve, the ball ‘bounces’ either straight up when it’s below the x-axis or
straight down when it’s above the x-axis. Repeat this process n times (this
process represents a dot product.)
If you have two points, an initial point ‘bounced’ with itself n times to
arrive at a final point, finding out n when you only know the final point and
the first point is hard. At the same time, it’s easy to repeat over and over the
procedure described above. This is a fine candidate for a trapdoor function.

Figure 4.3: An Elliptic Curve Cryptosystem

In an elliptic curve cryptosystem, a private key is a number n, and a public


key is the public point ‘bounced’ with itself n times. ECDSA’s elliptic curve
logarithm problem is harder to compute than prime factorization. Since a
more computationally intensive hard problem means a stronger cryptographic
system, it follows that elliptic curve cryptosystems are harder to break than
RSA and Diffie-Hellman.

4.3 OUTPUT DESIGN


It is the part of overall system design. The goal of the output design is
to capture the output and get the data into format suitable for the computer.
Data flow diagram identifies the data tone captured and the output to the sys-
tem. Output is the information delivered to the users through the information
system. Without quality output the entire system appears to be unnecessary
that users will avoid using it. Users generally merit the system solely by its
output in order to create the most useful output possible. One works closely
with the user through an interactive process until the result is considered to
be satisfactory.

B.Tech 2020 30 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

The output here is the result of various transactions that the supplychain
participants can view. After each successful transaction, blockchain is updated
and the changes are reflected in the status of the product. When a product is
manufactured, a unique identifier is assigned to it, with the help of which, the
status of the product changes to manufactured. The details of the concerned
manufacturer is visible at this stage. Once the medicine is purchased by a
wholesaler, the package is assigned to a transporter. The transporter ships the
medicine package and the medicine status changes to, picked up by transporter,
at this stage. Once the wholesaler receives the package, the status changes
to, received by wholesaler. All the supplychain transactions and associated
stakeholder information of the medicine to be traced can be viewed as the
output of the system. So the output of a complex system is converted to a
user friendly form in this way.

B.Tech 2020 31 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

CHAPTER 5

IMPLEMENTATION

Implementation comprises of detailed modular design of the system, how


various functions work, their core algorithm. Detailed design of a project deals
with the entire functionality it handles. A well-defined detailed description in-
cludes major functional components in that application along with sub modules
included and table handled. It shows actual data flow within the system and
how each function handles the data. In computer science, an implementation
is a realization of a technical specification or algorithm as a program, soft-
ware component, or other computer system through computer programming
and deployment. Many implementations may exist for a given specification
or standard. In an information technology context, software or hardware im-
plementation encompasses all the post-sale processes involved in something
operating properly in its environment, including analysing requirements, in-
stallation, configuration, customization, running, testing, systems integrations,
user training, delivery and making necessary changes. The word ”deployment”
is sometimes used to mean the same thing.
For an implementation process to be successful, many tasks between differ-
ent departments need to be accomplished in sequence. Companies strive to use
proven methodologies and enlist professional help to guide them through the
implementation of a system but the failure of many implementation processes
often stems from the lack of accurate planning in the beginning stages of the
project due to inadequate resources or unforeseen problems that arise. Soft-
ware/hardware implementations should always be designed with the end user
in mind and the implementation process usually benefits from user involve-
ment and support from managers and other top executives in the company. If
users participate in the design and implementation of the system, ideally it will
serve their business objectives more accurately and reflect their priorities and
the ways in which they prefer to work. Software/hardware implementations
should always be designed with the end user in mind and the implementation
process usually benefits from user involvement. Their involvement in the pro-
cess also makes them more receptive to changes that need to be implemented
because they have first hand experience of what the system comprises.
The proposed system is implemented by mainly dividing the entire process
into three tasks : (a) Valid user registration, (b) Supplychain flow and (c)

B.Tech 2020 32 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

Tracking of medicine

5.1 Data Entry


Ethereum is a decentralized open source blockchain featuring smart con-
tract functionality. It is an open software platform based on blockchain tech-
nology that enables developers to build and deploy decentralized applications.
Ether is the cryptocurrency generated by Ethereum miners as a reward for
computations performed to secure the blockchain. These decentralized appli-
cations gain the benefits of cryptocurrency and blockchain technology. They
are reliable and predictable, meaning that once they are uploaded to Ethereum,
they will always run as programmed. They can control digital assets in order to
create new kinds of financial applications. They can be decentralized, mean-
ing that no single entity or person controls them. There is no company or
centralized organization that controls Ethereum. Ethereum is maintained and
improved over time by a diverse global community of contributors who work
on everything from the core protocol to consumer applications.
Data is often described as the new oil in economic parlance. It is the reason
why leading businesses including the famed GAFAs (Google, Amazon, Face-
book, and Apple) are in control of loads of data. Some common applications of
data science are seen in internet engine protocols, digital advertisements, and
recommender services. Data analysis has been found relevant in the health-
care industry to track patient treatment and equipment flow,in travel gaming
to improve consumer experience, for energy management as well as many other
sectors.
Data science, just like any technological advancement, has its own chal-
lenges and limitations. These when addressed will unleash its full capabilities.
Some major challenges to data science include inaccessible data, privacy issues,
and dirty data. The control of dirty data (or erroneous information) is one area
that blockchain technology can positively impact the data science field in large
measures.
Blockchain validates data through decentralized consensus algorithms and
cryptography, making it almost impossible to be manipulated. This is due
to the huge amount of computing power that will be required. Through a
decentralized system, blockchain technology ensures the security and privacy
of data. Most of the data are stored in centralized servers. These are often the
target of cyber attackers. The several reports of hacks and security breaches
goes to show the extent of the threat. Blockchain, however, restores the control
of data to the individuals generating the data making. This makes it difficult
for cyber criminals to access and manipulate data on a large scale.
Blockchain has brought a whole new way of managing and operating with
data. Here, data is no longer in a central perspective where all data should
be brought together, but a decentralized manner where data may be analyzed
right off the edges of individual devices. In addition to that , validated data
generated via blockchain technology comes structured and complete.As men-
tioned earlier, data is immutable. Another important area where blockchain

B.Tech 2020 33 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

generated data becomes a boost for big data is in data integrity since blockchain
ascertains the origin of data though its linked chains.
The fake medicine prevention system can be implemented using blockchain
by creating blocks of data of various transactions made by the participants.
The details of the medicine produced is stored from the very first stage of its
production , till its sold to a customer. For the data to be safe and secure its
necessary that it must be stored somewhere that is tamper proof.
Data in a Blockchain gets stored in batches called blocks. These blocks are
linked together chronologically and form a metaphorical chain of blocks—hence
the name blockchain. If someone wants to change data, they do not change
the block but, rather, add a new block to the end of the chain containing
the information of which change occurred at a specific point in time. It is a
non-destructive way of tracking changes over time.
As mentioned before the data entered into the blockchain is immutable.
This property of immutability is provided using the hash value generated from
the contents of a block. Since the hash value is generated from the contents
any change in the content will lead to a change in hash value. Since the hash
value is a unique combination, altering the data and getting the same hash
value again is near to impossible. Therefore any change in data will lead to
a different hash value thereby notifying all users connected to the blockchain
about this change.

5.2 Data Processing


Pharmaceutical supply chains are particularly complex, requiring the in-
put of multiple stakeholders with a number of important requirements placed
upon them. Currently the supply chain must allow multiple parties to up-
date and share data, it must verify that such information can be trusted and
it may have to interact with national and international verification systems,
transport systems and regulatory bodies. A blockchain based supply chain has
a number of benefits. Firstly, it allows for a comprehensive overview of the
entire end to end process. The full supply chain can be managed through one
piece of software. It also gives enhanced transparency between the authorized
stakeholders. Each party can see the stages of the drug journey to ensure
authenticity and quality.
Another important benefit of blockchain is the added traceability and secu-
rity. Using a blockchain system, products can be tracked, traced and recalled
when necessary. The system itself is also under a higher level of scrutiny and
protection therefore is more secure. An audit trail created through the block
system is an added benefit. With all relevant information stacked and recorded
chronologically, both internal and external parties can review the entire chain
when necessary.
The entire supplychain is considered to be a legitimate one.For that, a
trustworthy authority must give the permission to the users or the nodes in
this blockchain. The participants in the blockchain are namely a supplier, a
transporter,a manufacturer, a wholesaler,a distributor.

B.Tech 2020 34 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

The above mentioned stake holders are registered to this legitimate blockchain
. This process is handled by an authority similar to Food and Drugs Author-
ity. The authority registers the stakeholders. Only these people can access the
chain and enter relevant data. Once entered , these data cannot be changed.
Once the administrator register various users to the blockchain, each of
these users can access through their account and see the pages which are meant
for them . A stakeholder wont be able to read or write a page another stake-
holder has access to. Each person can enter the product related details like
for example a manufacturer enters the medicine description ,its expiry date,
batchid whereas a wholesaler requests for a batch of medicines.
The details associated with a batch of medicines get stored in the blockchain
throughout its journey to the end user.The details in the blockchain are im-
mutable therefore no one can access or tamper the details, which makes this sys-
tem more reliable than the conventional system of storing in a normal database.

5.3 OUTPUT DATA


The output of the system is the detailed history of the transactions and the
details regarding the stakeholders associated with the medicine. This informa-
tion can be fetched by the end user to verify the authenticity of the product.
Since only participants approved by the regulating authority can make trans-
actions in the blockchain, illegal sources cannot add products into the system,
thus preventing fake medicines from entering the system. Since all transac-
tions are logged into blockchain as soon as the transactions take place, the
history is permanently stored in the blockchain. No participant, including the
regulating authority, can tamper the transactions logged into the blockchain.
This property of immutability is provided using the hash value generated from
the contents of a block. Since the hash value is generated from the contents
any change in the content will lead to a change in hash value. Since the hash
value is a unique combination, altering the data and getting the same hash
value again is near to impossible. Therefore any change in data will lead to
a different hash value thereby notifying all users connected to the blockchain
about this change.

B.Tech 2020 35 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

CHAPTER 6

RESULT

A system has been developed to overcome the increasing problem of fake


medicines in the market. The system assigns unique identification to each
unit of medicine using the technique of serialisation. The resultant unique
identification is hashed and cannot be forged by illegal manufacturers. All the
participants in the network register with the regulating authority who verifies if
the requesting participant is authentic. Only these registered participants can
take part in the supplychain transactions thus ensuring that no illegal organi-
sations can make transactions in the blockchain. Each registered participant is
identified by a unique ethereum address. Each account in the Ethereum net-
work has a public key and a private key. An Ethereum address is essentially
a hashed version of the public key. Accounts can use their private key to sign
a piece of data, returning a signature of that data thus ensuring credibility
and holding responsibility. Whenever a medicine products is handed over to
the next stakeholder, its ownership changes to the corresponding stakeholder
and the transaction is permanently stored in the blockchain along with the
sender and the receiver involved. The users can trace these medicines, from
the pharmacy to the source and fetch the details of the stakeholders involved,
thus ensuring the authenticity of the product.

B.Tech 2020 36 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

CHAPTER 7

CONCLUSION

The pharmaceutical industry has been under intense pressure to stop coun-
terfeiting and manipulation. Blockchain’s inherent qualities such as trans-
parency and auditability, enhanced automatization, resilience, and data in-
tegrity help to find a solution to fight counterfeit issues. A smart contract
is a tamper-proof piece of code, hosted on the blockchain, that represents a
contractual agreement and can autonomously execute upon external inputs.
Smart contracts are used to code the handling of transactions in blockchain.
Existing counterfeit solutions have several shortcomings and vulnerabilities as
they can be hacked or duplicated. The proposed solution includes the cre-
ation of a unique ID for each package. The tag is used at all stages of the
supply chain to record the entire history of transfers, ownership and locations
permanently on the blockchain.
Regular databases store data on a single server, maintained by a centralised
authority that manages access and verifies entries. This structure relies on the
trust of a single person and is, therefore, prone to failure, manipulation or
corruption. A blockchain network is a distributed system; that means, that
the database and its content is split over several computers. Since there is no
centralised authority to manage access or verify entries, the blockchain network
needs a system to ensure that all participants converge towards one single
version of the database. This way of reaching consensus in a decentralised
network is called consensus protocol and describes a set of steps that need to
happen before a block gets added to the chain. The huge computational power
needed to add a block combined with the interchaining of data via timestamps
is what makes blockchain so secure. If someone would want to manipulate a
block he would need to redo all the computations to calculate the cryptographic
hash for the block as well as all subsequent blocks in the chain and, finally,
control more than 51 percentage of all computers in the network to agree on
the new version of the database.
The proposed system allows for a comprehensive overview of the entire end
to end process. The full supply chain can be managed through one piece of soft-
ware. It also gives enhanced transparency between the authorized stakeholders.
Each party can see the stages of the drug journey to ensure authenticity and
quality. Using a blockchain system, products can be tracked, traced and re-

B.Tech 2020 37 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

called when necessary. The system itself is also under a higher level of scrutiny
and protection therefore is more secure. With all relevant information stacked
and recorded chronologically, both internal and external parties can review
the entire chain when necessary. The entire supplychain is considered to be a
legitimate one.For that, a trustworthy authority must give the permission to
the users or the nodes in this blockchain.
The participants in the blockchain are namely a supplier, a transporter,a
manufacturer, a wholesaler,a distributor. The system assigns unique identifica-
tion to each unit of medicine. Whenever a medicine products is handed over to
the next stakeholder, its ownership changes to the corresponding stakeholder
and the transaction is permanently stored in the blockchain. The details as-
sociated with a batch of medicines get stored in the blockchain throughout its
journey to the end user.The details in the blockchain are immutable therefore
no one can access or tamper the details, which makes this system more reliable.

B.Tech 2020 38 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

REFERENCES

bibitemb1 Nida Khan, Abdelkader Lahmadi, Jérôme Francois,Radu State,


“ NOMS 2018 - 2018 IEEE/IFIP Network Operations and Management
Symposium,” ISSN: 2374-9709, 09 July 2018.Zibin Zheng1, Shaoan Xie1,
Hongning Dai2, Xiangping Chen4, and Huaimin Wang31. An Overview
of Blockchain Technology:Architecture, Consensus, and Future Trends L.
M. Bach , B. Mihaljevic , M. Zagar, ”Comparative analysis of blockchain
consensus algorithms”, 2018 41st International Convention on Informa-
tion and Communication Technology, Electronics and Microelectronics
(MIPRO), 02 July 2018 Yining Hu, Madhusanka Liyanage,Ahsan Man-
zoor, Kanchana Thilakarathna, Aruna Seneviratne. ”Blockchain-based
Smart Contracts -Applications and Challenges ”, June 11, 2019

B.Tech 2020 39 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

ANNEXURES I

BLOCKCHAIN

pragma s o l i d i t y >=0.4.25 < 0 . 6 . 0 ;

import ’ . / RawMatrials . s o l ’ ;
import ’ . / Madicine . s o l ’ ;
import ’ . / MadicineW D . s o l ’ ;
import ’ . / MadicineD P . s o l ’ ;

c o n t r a c t SupplyChain {
a d d r e s s p u b l i c Owner ;
/// I n i t i a t e SupplyChain Contract
constructor () public {
Owner = msg . s e n d e r ;
}
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Owner S e c t i o n ∗∗∗∗∗∗∗∗
/// V a l i d a t e Owner
m o d i f i e r onlyOwner ( ) {
require (
msg . s e n d e r == Owner ,
”Only owner can c a l l t h i s f u n c t i o n . ”
);
;
}
enum r o l e s {
norole ,
supplier ,
transporter ,
manufacturer ,
wholesaler ,
distributer ,
pharma ,

B.Tech 2020 40 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

revoke ,
consumer
}

e v e n t U s e r R e g i s t e r ( a d d r e s s i n d e x e d EthAddress , b y t e s 3 2 Name ) ;
e v e n t UserRoleRevoked ( a d d r e s s i n d e x e d EthAddress , b y t e s 3 2 Name , u i
e v e n t U s e r R o l e R e s s i g n e ( a d d r e s s i n d e x e d EthAddress , b y t e s 3 2 Name , u

/// R e g i s t e r New u s e r by Owner

function registerUser (
a d d r e s s EthAddress ,
b y t e s 3 2 Name ,
b y t e s 3 2 Location ,
u i n t Role
) public
onlyOwner
{
r e q u i r e ( U s e r s D e t a i l s [ EthAddress ] . r o l e == r o l e s . n o r o l e , ” User A
U s e r s D e t a i l s [ EthAddress ] . name = Name ;
U s e r s D e t a i l s [ EthAddress ] . l o c a t i o n = L o c a t i o n ;
U s e r s D e t a i l s [ EthAddress ] . e th Add re ss = EthAddress ;
U s e r s D e t a i l s [ EthAddress ] . r o l e = r o l e s ( Role ) ;
u s e r s . push ( EthAddress ) ;
emit U s e r R e g i s t e r ( EthAddress , Name ) ;
}

/// Revoke u s e r s r o l e

f u n c t i o n r e v o k e R o l e ( a d d r e s s u s e r A d d r e s s ) p u b l i c onlyOwner {
r e q u i r e ( U s e r s D e t a i l s [ u s e r A d d r e s s ] . r o l e != r o l e s . n o r o l e , ” User
emit UserRoleRevoked ( u ser Ad dr es s , U s e r s D e t a i l s [ u s e r A d d r e s s ] . na
UsersDetails [ userAddress ] . r o l e = r o l e s ( 7 ) ;
}

/// R e a s s i g n e new r o l e t o User


/// u s e r A d d r e s s User Ethereum Network Address

B.Tech 2020 41 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

/// Role Role t o a s s i g n e


f u n c t i o n r e a s s i g n e R o l e ( a d d r e s s us erA dd re ss , u i n t Role ) p u b l i c only
r e q u i r e ( U s e r s D e t a i l s [ u s e r A d d r e s s ] . r o l e != r o l e s . n o r o l e , ” User
U s e r s D e t a i l s [ u s e r A d d r e s s ] . r o l e = r o l e s ( Role ) ;
emit U s e r R o l e R e s s i g n e ( us er Add re ss , U s e r s D e t a i l s [ u s e r A d d r e s s ] . n
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ User S e c t i o n ∗∗∗∗∗∗∗∗∗


struct UserInfo {
b y t e s 3 2 name ;
bytes32 l o c a t i o n ;
a d d r e s s et hA dd res s ;
roles role ;
}

mapping ( a d d r e s s => U s e r I n f o ) U s e r s D e t a i l s ;

address [ ] users ;

/// Get User I n f o r m a t i o n / P r o f i l e


/// User User Ethereum Network Address
/// @return User D e t a i l s
f u n c t i o n g e t U s e r I n f o ( a d d r e s s User ) p u b l i c view r e t u r n s (
b y t e s 3 2 name ,
bytes32 location ,
a d d r e s s ethAddress ,
roles role
) {
return (
U s e r s D e t a i l s [ User ] . name ,
U s e r s D e t a i l s [ User ] . l o c a t i o n ,
U s e r s D e t a i l s [ User ] . ethAddress ,
U s e r s D e t a i l s [ User ] . r o l e ) ;
}

B.Tech 2020 42 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

/// Get Number o f r e g i s t e r e d U s e r s


/// @return Number o f r e g i s t e r e d U s e r s
f u n c t i o n getUsersCount ( ) p u b l i c view r e t u r n s ( u i n t count ){
return users . length ;
}

/// Get User by Index v a l u e o f s t o r e d data


/// i n d e x Indexed Number
/// @return User D e t a i l s
f u n c t i o n g e t U s e r b y I n d e x ( u i n t i n d e x ) p u b l i c view r e t u r n s (
b y t e s 3 2 name ,
bytes32 location ,
a d d r e s s ethAddress ,
roles role
) {
return getUserInfo ( users [ index ] ) ;
}
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ S u p p l i e r S e c t i o n ∗∗∗∗∗

mapping ( a d d r e s s => a d d r e s s [ ] ) s u p p l i e r R a w P r o d u c t I n f o ;
e v e n t RawSupplyInit (
a d d r e s s i n d e x e d ProductID ,
address indexed Supplier ,
a d d r e s s Shipper ,
address indexed Receiver
);

/// Create new raw package by S u p p l i e r


/// Des T r a n s p o r t e r Ethereum Network Address
/// Rcvr Manufacturer Ethereum Network Address
f u n c t i o n createRawPackage (
b y t e s 3 2 Des ,
b y t e s 3 2 FN,
b y t e s 3 2 Loc ,
u i n t Quant ,
a d d r e s s Shpr ,

B.Tech 2020 43 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

a d d r e s s Rcvr
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . s u p p l i e r ,
”Only S u p p l i e r Can c a l l t h i s f u n c t i o n ”
);
RawMatrials rawData = new RawMatrials (
msg . sender ,
Des ,
FN,
Loc ,
Quant ,
Shpr ,
Rcvr
);
s u p p l i e r R a w P r o d u c t I n f o [ msg . s e n d e r ] . push ( a d d r e s s ( rawData ) ) ;
emit RawSupplyInit ( a d d r e s s ( rawData ) , msg . sender , Shpr , Rcvr ) ;
}

/// Get Count o f c r e a t e d package by s u p p l i e r ( c a l l e r )


/// @return Number o f p a c k a g e s
f u n c t i o n getPackagesCountS ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . s u p p l i e r ,
”Only S u p p l i e r Can c a l l t h i s f u n c t i o n ”
);
r e t u r n s u p p l i e r R a w P r o d u c t I n f o [ msg . s e n d e r ] . l e n g t h ;
}

/// Get PackageID by Indexed v a l u e o f s t o r e d data


/// i n d e x Indexed Value
/// @return PackageID
f u n c t i o n getPackageIdByIndexS ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . s u p p l i e r ,
”Only S u p p l i e r Can c a l l t h i s f u n c t i o n ”

B.Tech 2020 44 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

);
r e t u r n s u p p l i e r R a w P r o d u c t I n f o [ msg . s e n d e r ] [ i n d e x ] ;
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ T r a n s p o r t e r S e c t i o n ∗∗

/// Load Consingment f o t t r a n s p o r t one l o c a t i o n t o a n o t h e r .


/// pi d PackageID o r MadicineID
/// t r a n s p o r t e r t y p e T r a n s p o r t e r Type on th e b a s i c o f tx between
/// c i d Sub Contract ID f o r Consingment t r a n s a c t i o n
/∗ s t r u c t t r a n s i n f o {
address cid1 ;
uint transportertype1 ;
a d d r e s s pid1 ;
} ∗/
mapping ( a d d r e s s => a d d r e s s [ ] ) t r a n s b a t c h i d c i d ;
mapping ( a d d r e s s => u i n t [ ] ) t r a n s b a t c h i d t x t y p e ;
mapping ( a d d r e s s => a d d r e s s [ ] ) t r a n s b a t c h i d p i d ;

f u n c t i o n loadConsingment (
a d d r e s s pid ,
uint transportertype ,
address cid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . t r a n s p o r t e r ,
”Only T r a n s p o r t e r can c a l l t h i s f u n c t i o n ”
);
require (
transportertype > 0 ,
” T r a n s p o r t e r Type must be d e f i n e ”
);

i f ( t r a n s p o r t e r t y p e == 1 ) { // S u p p l i e r t o Manufacturer
RawMatrials ( pi d ) . pickPackage ( msg . s e n d e r ) ;
t r a n s b a t c h i d c i d [ msg . s e n d e r ] . push ( a d d r e s s ( c i d ) ) ;
t r a n s b a t c h i d p i d [ msg . s e n d e r ] . push ( a d d r e s s ( p id ) ) ;

B.Tech 2020 45 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

t r a n s b a t c h i d t x t y p e [ msg . s e n d e r ] . push ( u i n t ( t r a n s p o r t e r t y p e ) )

} e l s e i f ( t r a n s p o r t e r t y p e == 2 ) { // Manufacturer t o W h o l e s
Madicine ( p id ) . pickPackage ( msg . s e n d e r ) ;
t r a n s b a t c h i d c i d [ msg . s e n d e r ] . push ( a d d r e s s ( c i d ) ) ;
t r a n s b a t c h i d p i d [ msg . s e n d e r ] . push ( a d d r e s s ( p id ) ) ;
t r a n s b a t c h i d t x t y p e [ msg . s e n d e r ] . push ( u i n t ( t r a n s p o r t e r t y p e ) )

} e l s e i f ( t r a n s p o r t e r t y p e == 3 ) { // W h o l e s a l e r t o D i s t r i b u t
MadicineW D ( c i d ) . pickWD ( pid , msg . s e n d e r ) ;
t r a n s b a t c h i d c i d [ msg . s e n d e r ] . push ( a d d r e s s ( c i d ) ) ;
t r a n s b a t c h i d p i d [ msg . s e n d e r ] . push ( a d d r e s s ( p id ) ) ;
t r a n s b a t c h i d t x t y p e [ msg . s e n d e r ] . push ( u i n t ( t r a n s p o r t e r t y p e ) )
} e l s e i f ( t r a n s p o r t e r t y p e == 4 ) { // D i s t r u b u t e r t o Pharma
MadicineD P ( c i d ) . pickDP ( pid , msg . s e n d e r ) ;
t r a n s b a t c h i d c i d [ msg . s e n d e r ] . push ( a d d r e s s ( c i d ) ) ;
t r a n s b a t c h i d p i d [ msg . s e n d e r ] . push ( a d d r e s s ( p id ) ) ;
t r a n s b a t c h i d t x t y p e [ msg . s e n d e r ] . push ( u i n t ( t r a n s p o r t e r t y p e ) )
}
}

f u n c t i o n t r a n s p o r t C o u n t ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . t r a n s p o r t e r ,
”Only t r a n s p o r t e r Can c a l l t h i s f u n c t i o n ”
);
r e t u r n t r a n s b a t c h i d c i d [ msg . s e n d e r ] . l e n g t h ;
}
/∗ f u n c t i o n g e t t r a n s p o r t e r i n f o ( a d d r e s s User ) p u b l i c view r e t u r n s (
address cid1 ,
uint transportertype1 ,
a d d r e s s pid1
){
return (
t r a n s b a t c h i d [ User ] . c i d 1 ,
t r a n s b a t c h i d [ User ] . t r a n s p o r t e r t y p e 1 ,
t r a n s b a t c h i d [ User ] . pid1

B.Tech 2020 46 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

);
}∗/

f u n c t i o n getTransportBatchIdByIndex ( u i n t i n d e x ) p u b l i c view r e t u r n
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . t r a n s p o r t e r ,
”Only t r a n s p o r t e r Can c a l l t h i s f u n c t i o n ”
);
r e t u r n ( t r a n s b a t c h i d c i d [ msg . s e n d e r ] [ i n d e x ] , t r a n s b a t c h i d t x t y p e [
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Manufacturer S e c t i o n ∗

// s t r u c t Item added by e l i
s t r u c t Item {

address batchid ; // U n i v e r s a l Product Code (UPC) , g e n e


address ownerID ; // Metamask−Ethereum a d d r e s s o f t h
bytes32 Des ;
bytes32 manuname ;
uint256 productDate ; // Product Date NOTE: MIGHT NEED T
uint256 expiryDate ;
// u i n t productPrice ;

address wholesaler ; // Metamask−Ethereum a d d r e s s o f t h


address d i s t r i b u t o r ; // Metamask−Ethereum a d d r e s s o f t h e
a d d r e s s pharma ; // Metamask−Ethereum a d d r e s s o f t he Co
}

mapping ( a d d r e s s => Item ) i t e m s ; // added by e l i

mapping ( a d d r e s s => a d d r e s s [ ] ) RawPackagesAtManufacturer ;

/// Update Package / Madicine batch r e c i e v e d s t a t u s by e t h i e r


/// pi d PackageID o r MadicineID

B.Tech 2020 47 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

f u n c t i o n rawPackageReceived (
address pid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only m a nu f a c tu r e r can c a l l t h i s f u n c t i o n ”
);

RawMatrials ( pi d ) . r e c e i v e d P a c k a g e ( msg . s e n d e r ) ;
RawPackagesAtManufacturer [ msg . s e n d e r ] . push ( pi d ) ;
}

/// Get Package Count a t Manufacturer


/// @return Number o f Packages a t Manufacturer
f u n c t i o n getPackagesCountM ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only m a nu f a c tu r e r can c a l l t h i s f u n c t i o n ”
);
r e t u r n RawPackagesAtManufacturer [ msg . s e n d e r ] . l e n g t h ;
}

/// Get PackageID by Indexed v a l u e o f s t o r e d data


/// i n d e x Indexed Value
/// @return PackageID
f u n c t i o n getPackageIDByIndexM ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only m a nu f a c tu r e r can c a l l t h i s f u n c t i o n ”
);
r e t u r n RawPackagesAtManufacturer [ msg . s e n d e r ] [ i n d e x ] ;
}

mapping ( a d d r e s s => a d d r e s s [ ] ) ManufactureredMadicineBatches ;


e v e n t MadicineNewBatch (

B.Tech 2020 48 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

address i n d e x e d BatchId ,
address i n d e x e d Manufacturer ,
address shipper ,
address indexed Receiver
);

/// Create Madicine Batch


/// Des D e s c r i p t i o n o f madicine batch
/// RM RawMatrials I n f o r m a t i o n
/// Quant Number o f U n i t s
/// Shpr T r a n s p o r t e r Ethereum Network Address
/// Rcvr R e c e i v e r Ethereum Network Address
/// RcvrType R e c e i v e r Type E t h i e r W h o l e s a l e r ( 1 ) o r D i s t r i b u t e r (
f u n c t i o n manufacturMadicine (
b y t e s 3 2 Des ,
b y t e s 3 2 RM,
u i n t Quant ,
a d d r e s s Shpr ,
a d d r e s s Rcvr ,
u i n t RcvrType
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only m a nu f a c tu r e r can c a l l t h i s f u n c t i o n ”
);
require (
RcvrType != 0 ,
” R e c e i v e r Type must be d e f i n e ”
);

Madicine m = new Madicine (


msg . sender ,
Des ,
RM,
Quant ,
Shpr ,
Rcvr ,

B.Tech 2020 49 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

RcvrType
);

ManufactureredMadicineBatches [ msg . s e n d e r ] . push ( a d d r e s s (m) ) ;

// a d d r e s s w h o l e s a l e r ; // added by e l i from h e r e
// a d d r e s s d i s t r i b u t o r ;
// a d d r e s s pharma ;
Item memory newProduce ; // Create a new s t r u c t Item i n memory
newProduce . b a t c h i d = a d d r e s s (m) ;
newProduce . ownerID = msg . s e n d e r ; // Metamask−Ethereum a d d r e s s
newProduce . manuname = U s e r s D e t a i l s [ msg . s e n d e r ] . name ;
newProduce . productDate = now ;
newProduce . e x p i r y D a t e = now + 7 3 0 ;
// newProduce . p r o d u c t P r i c e = p r i c e ;
newProduce . w h o l e s a l e r = Madicine ( a d d r e s s (m) ) . getWDP ( ) [ 0 ] ;
newProduce . d i s t r i b u t o r = Madicine ( a d d r e s s (m) ) . getWDP ( ) [ 1 ] ;
newProduce . pharma = Madicine ( a d d r e s s (m) ) . getWDP ( ) [ 2 ] ;
i t e m s [ a d d r e s s (m) ] = newProduce ;
emit MadicineNewBatch ( a d d r e s s (m) , msg . sender , Shpr , Rcvr ) ;
}

f u n c t i o n f e t c h d e t a i l s ( a d d r e s s b a t c h i d d ) p u b l i c view r e t u r n s // adde
(

address ba tch id ,
address ownerID , // c u r r e n t owner o f m e d i c i n e
bytes32 manuname ,
// u i n t productPrice ,
uint256 productDate ,
uint256 expiryDate ,
address wholesaler ,
address distributor ,
address pharma
)
{

Item memory item = i t e m s [ b a t c h i d d ] ;

B.Tech 2020 50 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

return
(

item . bat chi d ,


item . ownerID ,
item . manuname ,
// item . p r o d u c t P r i c e ,
item . productDate ,
item . expiryDate ,
item . w h o l e s a l e r ,
item . d i s t r i b u t o r ,
item . pharma
);

/// Get Madicine Batch Count


/// @return Number o f Batches
f u n c t i o n getBatchesCountM ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only Manufacturer Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n ManufactureredMadicineBatches [ msg . s e n d e r ] . l e n g t h ;
}

/// Get Madicine BatchID by i n d e x e d v a l u e o f s t o r e d data


/// i n d e x Indexed Number
/// @return Madicine BatchID
f u n c t i o n getBatchIdByIndexM ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e s
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only Manufacturer Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n ManufactureredMadicineBatches [ msg . s e n d e r ] [ i n d e x ] ;

B.Tech 2020 51 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ W h o l e s a l e r S e c t i o n ∗∗∗

mapping ( a d d r e s s => a d d r e s s [ ] ) MadicineBatchesAtWholesaler ;


mapping ( a d d r e s s => a d d r e s s [ ] ) M a d i c i n e B a t c h A t D i s t r i b u t e r ;

/// Madicine Batch Re c ei ve d


/// b a t c h i d Madicine BatchID
/// param c i d Sub Contract ID f o r Madicine ( i f t r a n s a c t i o n W h o l e s
function madicineReceived (
a d d r e s s ba tch id ,
address cid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r | | U s e r
”Only W h o l e s a l e r and D i s t r i b u t e r can c a l l t h i s f u n c t i o n ”
);

u i n t r t y p e = Madicine ( b a t c h i d ) . r e c e i v e d P a c k a g e ( msg . s e n d e r ) ;

i f ( r t y p e == 1 ) {

MadicineBatchesAtWholesaler [ msg . s e n d e r ] . push ( b a t c h i d ) ;


}

e l s e i f ( r t y p e == 2){
M a d i c i n e B a t c h A t D i s t r i b u t e r [ msg . s e n d e r ] . push ( b a t c h i d ) ;
i f ( Madicine ( b a t c h i d ) . getWDP ( ) [ 0 ] != a d d r e s s ( 0 ) ) {
MadicineW D ( c i d ) . recieveWD ( b atc hid , msg . s e n d e r ) ;
}

}
}
f u n c t i o n g e t r e c e i v e d B a t c h e s C o u n t ( ) p u b l i c view r e t u r n s ( u i n t count

B.Tech 2020 52 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
”Only w h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineBatchesAtWholesaler [ msg . s e n d e r ] . l e n g t h ;
}

f u n c t i o n g e t r e c e i v e d B a t c h e s b y i n d e x ( u i n t i n d e x ) p u b l i c view r e t u r n s
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
”Only w h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineBatchesAtWholesaler [ msg . s e n d e r ] [ i n d e x ] ;
}

mapping ( a d d r e s s => a d d r e s s [ ] ) MadicineWtoD ;

mapping ( a d d r e s s => a d d r e s s ) MadicineWtoDTxContract ;

/// Sub Contract f o r Madicine T r a n s f e r from W h o l e s a l e r t o D i s


/// BatchID Madicine BatchID
/// S h i p p e r T r a n s p o r t e r Ethereum Network Address
/// R e c e i v e r D i s t r i b u t e r Ethereum Network Address
f u n c t i o n transferMadicineWtoD (
a d d r e s s BatchID ,
a d d r e s s Shipper ,
address Receiver
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r &&
msg . s e n d e r == Madicine ( BatchID ) . getWDP ( ) [ 0 ] ,
”Only W h o l e s a l e r o r c u r r e n t owner o f package can c a l l t h i s
);
MadicineW D wd = new MadicineW D (
BatchID ,
msg . sender ,

B.Tech 2020 53 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

Shipper ,
Receiver
);
// MadicineWtoD [ msg . s e n d e r ] . push ( a d d r e s s (wd ) ) ;
MadicineWtoD [ msg . s e n d e r ] . push ( BatchID ) ;

MadicineWtoDTxContract [ BatchID ] = a d d r e s s (wd ) ;


}

/// Get Madicine Batch Count


/// @return Number o f Batches
f u n c t i o n getBatchesCountWD ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
”Only W h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineWtoD [ msg . s e n d e r ] . l e n g t h ;
}

/// Get Madicine BatchID by i n d e x e d v a l u e o f s t o r e d data


/// i n d e x Indexed Number
/// @return Madicine BatchID
f u n c t i o n getBatchIdByIndexWD ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
”Only W h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineWtoD [ msg . s e n d e r ] [ i n d e x ] ;
}

/// Get Sub Contract ID o f Madicine Batch T r a n s f e r i n between


/// BatchID Madicine BatchID
/// @return SubContract ID
f u n c t i o n getSubContractWD ( a d d r e s s BatchID ) p u b l i c view r e t u r n s ( a d
// r e q u i r e (

B.Tech 2020 54 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

// U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
// ”Only W h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
// ) ;
r e t u r n MadicineWtoDTxContract [ BatchID ] ;
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ D i s t r i b u t e r S e c t i o n ∗∗

// mapping ( a d d r e s s => a d d r e s s [ ] ) M a d i c i n e B a t c h A t D i s t r i b u t e r ;

mapping ( a d d r e s s => a d d r e s s [ ] ) MadicineDtoP ;

mapping ( a d d r e s s => a d d r e s s ) MadicineDtoPTxContract ;

f u n c t i o n madicineReceivedatD (
a d d r e s s ba tch id ,
address cid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only Pharma Can c a l l t h i s f u n c t i o n . ”
);
MadicineW D ( c i d ) . recieveWD ( b atc hid , msg . s e n d e r ) ;
M a d i c i n e B a t c h A t D i s t r i b u t e r [ msg . s e n d e r ] . push ( b a t c h i d ) ;
// s a l e [ b a t c h i d ] = s a l e s t a t u s ( 1 ) ;
}

f u n c t i o n g e t r e c e i v e d B a t c h e s C o u n t D ( ) p u b l i c view r e t u r n s ( u i n t coun
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only d i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n M a d i c i n e B a t c h A t D i s t r i b u t e r [ msg . s e n d e r ] . l e n g t h ;
}

B.Tech 2020 55 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

f u n c t i o n g e t r e c e i v e d B a t c h e s b y i n d e x D ( u i n t i n d e x ) p u b l i c view r e t u r n
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only d i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n M a d i c i n e B a t c h A t D i s t r i b u t e r [ msg . s e n d e r ] [ i n d e x ] ;
}

/// T r a n s f e r Madicine BatchID i n between D i s t r i b u t e r t o Pharma


/// BatchID Madicine BatchID
/// S h i p p e r T r a n s p o r t e r Ethereum Network Address
/// R e c e i v e r Pharma Ethereum Network Address
function transferMadicineDtoP (
a d d r e s s BatchID ,
a d d r e s s Shipper ,
address Receiver
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r &&
msg . s e n d e r == Madicine ( BatchID ) . getWDP ( ) [ 1 ] ,
”Only D i s t r i b u t e r o r c u r r e n t owner o f package can c a l l t h i
);
MadicineD P dp = new MadicineD P (
BatchID ,
msg . sender ,
Shipper ,
Receiver
);
MadicineDtoP [ msg . s e n d e r ] . push ( BatchID ) ;
MadicineDtoPTxContract [ BatchID ] = a d d r e s s ( dp ) ;
}

/// Get Madicine BatchID Count


/// @return Number o f Batches
f u n c t i o n getBatchesCountDP ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (

B.Tech 2020 56 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only D i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineDtoP [ msg . s e n d e r ] . l e n g t h ;
}

/// Get Madicine BatchID by i n d e x e d v a l u e o f s t o r e d data


/// i n d e x Index Number
/// @return Madicine BatchID
f u n c t i o n getBatchIdByIndexDP ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only D i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineDtoP [ msg . s e n d e r ] [ i n d e x ] ;
}

/// Get SubContract ID o f Madicine Batch T r a n s f e r i n between D


/// BatchID Madicine BatchID
/// @return SubContract ID
f u n c t i o n getSubContractDP ( a d d r e s s BatchID ) p u b l i c view r e t u r n s ( a d
// r e q u i r e (
// U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
// ”Only D i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
// ) ;
r e t u r n MadicineDtoPTxContract [ BatchID ] ;
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Pharma S e c t i o n ∗∗∗∗∗∗∗

mapping ( a d d r e s s => a d d r e s s [ ] ) MadicineBatchAtPharma ;


mapping ( a d d r e s s => a d d r e s s [ ] ) M a d i c i n e s a l e ;

/// Madicine Batch Re c ie ve d


/// b a t c h i d Madicine BatchID
/// c i d SubContract ID

B.Tech 2020 57 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

f u n c t i o n madicineRecievedAtPharma (
a d d r e s s ba tch id ,
address cid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only Pharma Can c a l l t h i s f u n c t i o n . ”
);
MadicineD P ( c i d ) . recieveDP ( batc hid , msg . s e n d e r ) ;
MadicineBatchAtPharma [ msg . s e n d e r ] . push ( b a t c h i d ) ;
s a l e [ batchid ] = s a l e s t a t u s ( 1 ) ;
}

enum s a l e s t a t u s {
notfound ,
atpharma ,
sold ,
expire ,
damaged
}

mapping ( a d d r e s s => s a l e s t a t u s ) s a l e ;

event MadicineStatus (
a d d r e s s BatchID ,
a d d r e s s i n d e x e d Pharma ,
uint status
);

/// Update Madicine Batch s t a t u s


/// BatchID Madicine BatchID
/// S t a t u s Madicine Batch S t a t u s ( s o l d , e x p i r e e t c . )
function updateSaleStatus (
a d d r e s s BatchID ,
uint Status
) public {

B.Tech 2020 58 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma &&
msg . s e n d e r == Madicine ( BatchID ) . getWDP ( ) [ 2 ] ,
”Only Pharma o r c u r r e n t owner o f package can c a l l t h i s f u n
);
r e q u i r e ( s a l e [ BatchID ] == s a l e s t a t u s ( 1 ) , ” madicine Must be a t P
s a l e [ BatchID ] = s a l e s t a t u s ( S t a t u s ) ;
M a d i c i n e s a l e [ msg . s e n d e r ] . push ( BatchID ) ;

emit M a d i c i n e S t a t u s ( BatchID , msg . sender , S t a t u s ) ;


}

f u n c t i o n g e t s a l e c o u n t P ( ) p u b l i c view r e t u r n s ( u i n t count ){
// added by e l i
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only pharma Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n M a d i c i n e s a l e [ msg . s e n d e r ] . l e n g t h ;
}

f u n c t i o n g e t s a l e i n d e x P ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e s s pac
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only pharma Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n M a d i c i n e s a l e [ msg . s e n d e r ] [ i n d e x ] ;
}

/// Get Madicine Batch s t a t u s


/// BatchID Madicine BatchID
/// @return S t a t u s
function salesInfo (
a d d r e s s BatchID

B.Tech 2020 59 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

) public
view
returns (
uint Status
){
r e t u r n u i n t ( s a l e [ BatchID ] ) ;
}

/// Get Madicine Batch count


/// @return Number o f Batches
f u n c t i o n getBatchesCountP ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only W h o l e s a l e r o r c u r r e n t owner o f package can c a l l t h i s
);
r e t u r n MadicineBatchAtPharma [ msg . s e n d e r ] . l e n g t h ;
}

/// Get Madicine BatchID by i n d e x e d v a l u e o f s t o r e d data


/// i n d e x Index Number
/// @return Madicine BatchID
f u n c t i o n getBatchIdByIndexP ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e s
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only W h o l e s a l e r o r c u r r e n t owner o f package can c a l l t h i s
);
r e t u r n MadicineBatchAtPharma [ msg . s e n d e r ] [ i n d e x ] ;
}
}

/∗−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
# Medicine F u n c t i o n s Code
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗/

pragma s o l i d i t y >=0.4.25 < 0 . 6 . 0 ;

B.Tech 2020 60 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

import ’ . / RawMatrials . s o l ’ ;
import ’ . / Madicine . s o l ’ ;
import ’ . / MadicineW D . s o l ’ ;
import ’ . / MadicineD P . s o l ’ ;

c o n t r a c t SupplyChain {

a d d r e s s p u b l i c Owner ;

/// I n i t i a t e SupplyChain Contract


constructor () public {
Owner = msg . s e n d e r ;
}
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Owner S e c t i o n ∗∗∗∗∗∗∗∗
/// V a l i d a t e Owner
m o d i f i e r onlyOwner ( ) {
require (
msg . s e n d e r == Owner ,
”Only owner can c a l l t h i s f u n c t i o n . ”
);
;
}

enum r o l e s {
norole ,
supplier ,
transporter ,
manufacturer ,
wholesaler ,
distributer ,
pharma ,
revoke ,
consumer
}

B.Tech 2020 61 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

e v e n t U s e r R e g i s t e r ( a d d r e s s i n d e x e d EthAddress , b y t e s 3 2 Name ) ;
e v e n t UserRoleRevoked ( a d d r e s s i n d e x e d EthAddress , b y t e s 3 2 Name , u i
e v e n t U s e r R o l e R e s s i g n e ( a d d r e s s i n d e x e d EthAddress , b y t e s 3 2 Name , u

/// R e g i s t e r New u s e r by Owner


/// EthAddress Ethereum Network Address o f User
/// Name User name
/// L o c a t i o n User L o c a t i o n
/// Role User Role
function registerUser (
a d d r e s s EthAddress ,
b y t e s 3 2 Name ,
b y t e s 3 2 Location ,
u i n t Role
) public
onlyOwner
{
r e q u i r e ( U s e r s D e t a i l s [ EthAddress ] . r o l e == r o l e s . n o r o l e , ” User A
U s e r s D e t a i l s [ EthAddress ] . name = Name ;
U s e r s D e t a i l s [ EthAddress ] . l o c a t i o n = L o c a t i o n ;
U s e r s D e t a i l s [ EthAddress ] . e th Add re ss = EthAddress ;
U s e r s D e t a i l s [ EthAddress ] . r o l e = r o l e s ( Role ) ;
u s e r s . push ( EthAddress ) ;
emit U s e r R e g i s t e r ( EthAddress , Name ) ;
}

/// Revoke u s e r s r o l e
/// u s e r A d d r e s s User Ethereum Network Address
f u n c t i o n r e v o k e R o l e ( a d d r e s s u s e r A d d r e s s ) p u b l i c onlyOwner {
r e q u i r e ( U s e r s D e t a i l s [ u s e r A d d r e s s ] . r o l e != r o l e s . n o r o l e , ” User
emit UserRoleRevoked ( u ser Ad dr es s , U s e r s D e t a i l s [ u s e r A d d r e s s ] . na
UsersDetails [ userAddress ] . r o l e = r o l e s ( 7 ) ;
}

/// R e a s s i g n e new r o l e t o User


/// u s e r A d d r e s s User Ethereum Network Address

B.Tech 2020 62 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

/// Role Role t o a s s i g n e


f u n c t i o n r e a s s i g n e R o l e ( a d d r e s s us erA dd re ss , u i n t Role ) p u b l i c only
r e q u i r e ( U s e r s D e t a i l s [ u s e r A d d r e s s ] . r o l e != r o l e s . n o r o l e , ” User
U s e r s D e t a i l s [ u s e r A d d r e s s ] . r o l e = r o l e s ( Role ) ;
emit U s e r R o l e R e s s i g n e ( us er Add re ss , U s e r s D e t a i l s [ u s e r A d d r e s s ] . n
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ User S e c t i o n ∗∗∗∗∗∗∗∗∗


struct UserInfo {
b y t e s 3 2 name ;
bytes32 l o c a t i o n ;
a d d r e s s et hA dd res s ;
roles role ;
}

mapping ( a d d r e s s => U s e r I n f o ) U s e r s D e t a i l s ;

address [ ] users ;

/// Get User I n f o r m a t i o n / P r o f i l e


/// User User Ethereum Network Address
/// @return User D e t a i l s
f u n c t i o n g e t U s e r I n f o ( a d d r e s s User ) p u b l i c view r e t u r n s (
b y t e s 3 2 name ,
bytes32 location ,
a d d r e s s ethAddress ,
roles role
) {
return (
U s e r s D e t a i l s [ User ] . name ,
U s e r s D e t a i l s [ User ] . l o c a t i o n ,
U s e r s D e t a i l s [ User ] . ethAddress ,
U s e r s D e t a i l s [ User ] . r o l e ) ;
}

B.Tech 2020 63 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

/// Get Number o f r e g i s t e r e d U s e r s


/// @return Number o f r e g i s t e r e d U s e r s
f u n c t i o n getUsersCount ( ) p u b l i c view r e t u r n s ( u i n t count ){
return users . length ;
}

/// Get User by Index v a l u e o f s t o r e d data


/// i n d e x Indexed Number
/// @return User D e t a i l s
f u n c t i o n g e t U s e r b y I n d e x ( u i n t i n d e x ) p u b l i c view r e t u r n s (
b y t e s 3 2 name ,
bytes32 location ,
a d d r e s s ethAddress ,
roles role
) {
return getUserInfo ( users [ index ] ) ;
}
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ S u p p l i e r S e c t i o n ∗∗∗∗∗

mapping ( a d d r e s s => a d d r e s s [ ] ) s u p p l i e r R a w P r o d u c t I n f o ;
e v e n t RawSupplyInit (
a d d r e s s i n d e x e d ProductID ,
address indexed Supplier ,
a d d r e s s Shipper ,
address indexed Receiver
);

/// Create new raw package by S u p p l i e r


/// Des T r a n s p o r t e r Ethereum Network Address
/// Rcvr Manufacturer Ethereum Network Address
f u n c t i o n createRawPackage (
b y t e s 3 2 Des ,
b y t e s 3 2 FN,
b y t e s 3 2 Loc ,
u i n t Quant ,
a d d r e s s Shpr ,

B.Tech 2020 64 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

a d d r e s s Rcvr
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . s u p p l i e r ,
”Only S u p p l i e r Can c a l l t h i s f u n c t i o n ”
);
RawMatrials rawData = new RawMatrials (
msg . sender ,
Des ,
FN,
Loc ,
Quant ,
Shpr ,
Rcvr
);
s u p p l i e r R a w P r o d u c t I n f o [ msg . s e n d e r ] . push ( a d d r e s s ( rawData ) ) ;
emit RawSupplyInit ( a d d r e s s ( rawData ) , msg . sender , Shpr , Rcvr ) ;
}

/// Get Count o f c r e a t e d package by s u p p l i e r ( c a l l e r )


/// @return Number o f p a c k a g e s
f u n c t i o n getPackagesCountS ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . s u p p l i e r ,
”Only S u p p l i e r Can c a l l t h i s f u n c t i o n ”
);
r e t u r n s u p p l i e r R a w P r o d u c t I n f o [ msg . s e n d e r ] . l e n g t h ;
}

/// Get PackageID by Indexed v a l u e o f s t o r e d data


/// i n d e x Indexed Value
/// @return PackageID
f u n c t i o n getPackageIdByIndexS ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . s u p p l i e r ,
”Only S u p p l i e r Can c a l l t h i s f u n c t i o n ”

B.Tech 2020 65 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

);
r e t u r n s u p p l i e r R a w P r o d u c t I n f o [ msg . s e n d e r ] [ i n d e x ] ;
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ T r a n s p o r t e r S e c t i o n ∗∗

/// Load Consingment f o t t r a n s p o r t one l o c a t i o n t o a n o t h e r .


/// pi d PackageID o r MadicineID
/// t r a n s p o r t e r t y p e T r a n s p o r t e r Type on th e b a s i c o f tx between
/// c i d Sub Contract ID f o r Consingment t r a n s a c t i o n
/∗ s t r u c t t r a n s i n f o {
address cid1 ;
uint transportertype1 ;
a d d r e s s pid1 ;
} ∗/
mapping ( a d d r e s s => a d d r e s s [ ] ) t r a n s b a t c h i d c i d ;
mapping ( a d d r e s s => u i n t [ ] ) t r a n s b a t c h i d t x t y p e ;
mapping ( a d d r e s s => a d d r e s s [ ] ) t r a n s b a t c h i d p i d ;

f u n c t i o n loadConsingment (
a d d r e s s pid ,
uint transportertype ,
address cid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . t r a n s p o r t e r ,
”Only T r a n s p o r t e r can c a l l t h i s f u n c t i o n ”
);
require (
transportertype > 0 ,
” T r a n s p o r t e r Type must be d e f i n e ”
);

i f ( t r a n s p o r t e r t y p e == 1 ) { // S u p p l i e r t o Manufacturer
RawMatrials ( pi d ) . pickPackage ( msg . s e n d e r ) ;
t r a n s b a t c h i d c i d [ msg . s e n d e r ] . push ( a d d r e s s ( c i d ) ) ;
t r a n s b a t c h i d p i d [ msg . s e n d e r ] . push ( a d d r e s s ( p id ) ) ;

B.Tech 2020 66 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

t r a n s b a t c h i d t x t y p e [ msg . s e n d e r ] . push ( u i n t ( t r a n s p o r t e r t y p e ) )

} e l s e i f ( t r a n s p o r t e r t y p e == 2 ) { // Manufacturer t o W h o l e s
Madicine ( p id ) . pickPackage ( msg . s e n d e r ) ;
t r a n s b a t c h i d c i d [ msg . s e n d e r ] . push ( a d d r e s s ( c i d ) ) ;
t r a n s b a t c h i d p i d [ msg . s e n d e r ] . push ( a d d r e s s ( p id ) ) ;
t r a n s b a t c h i d t x t y p e [ msg . s e n d e r ] . push ( u i n t ( t r a n s p o r t e r t y p e ) )

} e l s e i f ( t r a n s p o r t e r t y p e == 3 ) { // W h o l e s a l e r t o D i s t r i b u t
MadicineW D ( c i d ) . pickWD ( pid , msg . s e n d e r ) ;
t r a n s b a t c h i d c i d [ msg . s e n d e r ] . push ( a d d r e s s ( c i d ) ) ;
t r a n s b a t c h i d p i d [ msg . s e n d e r ] . push ( a d d r e s s ( p id ) ) ;
t r a n s b a t c h i d t x t y p e [ msg . s e n d e r ] . push ( u i n t ( t r a n s p o r t e r t y p e ) )
} e l s e i f ( t r a n s p o r t e r t y p e == 4 ) { // D i s t r u b u t e r t o Pharma
MadicineD P ( c i d ) . pickDP ( pid , msg . s e n d e r ) ;
t r a n s b a t c h i d c i d [ msg . s e n d e r ] . push ( a d d r e s s ( c i d ) ) ;
t r a n s b a t c h i d p i d [ msg . s e n d e r ] . push ( a d d r e s s ( p id ) ) ;
t r a n s b a t c h i d t x t y p e [ msg . s e n d e r ] . push ( u i n t ( t r a n s p o r t e r t y p e ) )
}
}

f u n c t i o n t r a n s p o r t C o u n t ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . t r a n s p o r t e r ,
”Only t r a n s p o r t e r Can c a l l t h i s f u n c t i o n ”
);
r e t u r n t r a n s b a t c h i d c i d [ msg . s e n d e r ] . l e n g t h ;
}
/∗ f u n c t i o n g e t t r a n s p o r t e r i n f o ( a d d r e s s User ) p u b l i c view r e t u r n s (
address cid1 ,
uint transportertype1 ,
a d d r e s s pid1
){
return (
t r a n s b a t c h i d [ User ] . c i d 1 ,
t r a n s b a t c h i d [ User ] . t r a n s p o r t e r t y p e 1 ,
t r a n s b a t c h i d [ User ] . pid1

B.Tech 2020 67 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

);
}∗/

f u n c t i o n getTransportBatchIdByIndex ( u i n t i n d e x ) p u b l i c view r e t u r n
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . t r a n s p o r t e r ,
”Only t r a n s p o r t e r Can c a l l t h i s f u n c t i o n ”
);
r e t u r n ( t r a n s b a t c h i d c i d [ msg . s e n d e r ] [ i n d e x ] , t r a n s b a t c h i d t x t y p e [
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Manufacturer S e c t i o n ∗

// s t r u c t Item added by e l i
s t r u c t Item {

address batchid ; // U n i v e r s a l Product Code (UPC) , g e n e


address ownerID ; // Metamask−Ethereum a d d r e s s o f t h
bytes32 Des ;
bytes32 manuname ;
uint256 productDate ; // Product Date NOTE: MIGHT NEED T
uint256 expiryDate ;
// u i n t productPrice ;

address wholesaler ; // Metamask−Ethereum a d d r e s s o f t h


address d i s t r i b u t o r ; // Metamask−Ethereum a d d r e s s o f t h e
a d d r e s s pharma ; // Metamask−Ethereum a d d r e s s o f t he Co
}

mapping ( a d d r e s s => Item ) i t e m s ; // added by e l i

mapping ( a d d r e s s => a d d r e s s [ ] ) RawPackagesAtManufacturer ;

/// Update Package / Madicine batch r e c i e v e d s t a t u s by e t h i e r


/// pi d PackageID o r MadicineID

B.Tech 2020 68 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

f u n c t i o n rawPackageReceived (
address pid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only m a nu f a c tu r e r can c a l l t h i s f u n c t i o n ”
);

RawMatrials ( pi d ) . r e c e i v e d P a c k a g e ( msg . s e n d e r ) ;
RawPackagesAtManufacturer [ msg . s e n d e r ] . push ( pi d ) ;
}

/// Get Package Count a t Manufacturer


/// @return Number o f Packages a t Manufacturer
f u n c t i o n getPackagesCountM ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only m a nu f a c tu r e r can c a l l t h i s f u n c t i o n ”
);
r e t u r n RawPackagesAtManufacturer [ msg . s e n d e r ] . l e n g t h ;
}

/// Get PackageID by Indexed v a l u e o f s t o r e d data


/// i n d e x Indexed Value
/// @return PackageID
f u n c t i o n getPackageIDByIndexM ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only m a nu f a c tu r e r can c a l l t h i s f u n c t i o n ”
);
r e t u r n RawPackagesAtManufacturer [ msg . s e n d e r ] [ i n d e x ] ;
}

mapping ( a d d r e s s => a d d r e s s [ ] ) ManufactureredMadicineBatches ;


e v e n t MadicineNewBatch (

B.Tech 2020 69 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

address i n d e x e d BatchId ,
address i n d e x e d Manufacturer ,
address shipper ,
address indexed Receiver
);

/// Create Madicine Batch


/// Des D e s c r i p t i o n o f madicine batch
/// RM RawMatrials I n f o r m a t i o n
/// Quant Number o f U n i t s
/// Shpr T r a n s p o r t e r Ethereum Network Address
/// Rcvr R e c e i v e r Ethereum Network Address
/// RcvrType R e c e i v e r Type E t h i e r W h o l e s a l e r ( 1 ) o r D i s t r i b u t e r (
f u n c t i o n manufacturMadicine (
b y t e s 3 2 Des ,
b y t e s 3 2 RM,
u i n t Quant ,
a d d r e s s Shpr ,
a d d r e s s Rcvr ,
u i n t RcvrType
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only m a nu f a c tu r e r can c a l l t h i s f u n c t i o n ”
);
require (
RcvrType != 0 ,
” R e c e i v e r Type must be d e f i n e ”
);

Madicine m = new Madicine (


msg . sender ,
Des ,
RM,
Quant ,
Shpr ,
Rcvr ,

B.Tech 2020 70 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

RcvrType
);

ManufactureredMadicineBatches [ msg . s e n d e r ] . push ( a d d r e s s (m) ) ;

// a d d r e s s w h o l e s a l e r ; // added by e l i from h e r e
// a d d r e s s d i s t r i b u t o r ;
// a d d r e s s pharma ;
Item memory newProduce ; // Create a new s t r u c t Item i n memory
newProduce . b a t c h i d = a d d r e s s (m) ;
newProduce . ownerID = msg . s e n d e r ; // Metamask−Ethereum a d d r e s s
newProduce . manuname = U s e r s D e t a i l s [ msg . s e n d e r ] . name ;
newProduce . productDate = now ;
newProduce . e x p i r y D a t e = now + 7 3 0 ;
// newProduce . p r o d u c t P r i c e = p r i c e ;
newProduce . w h o l e s a l e r = Madicine ( a d d r e s s (m) ) . getWDP ( ) [ 0 ] ;
newProduce . d i s t r i b u t o r = Madicine ( a d d r e s s (m) ) . getWDP ( ) [ 1 ] ;
newProduce . pharma = Madicine ( a d d r e s s (m) ) . getWDP ( ) [ 2 ] ;
i t e m s [ a d d r e s s (m) ] = newProduce ;
emit MadicineNewBatch ( a d d r e s s (m) , msg . sender , Shpr , Rcvr ) ;
}

f u n c t i o n f e t c h d e t a i l s ( a d d r e s s b a t c h i d d ) p u b l i c view r e t u r n s // adde
(

address ba tch id ,
address ownerID , // c u r r e n t owner o f m e d i c i n e
bytes32 manuname ,
// u i n t productPrice ,
uint256 productDate ,
uint256 expiryDate ,
address wholesaler ,
address distributor ,
address pharma
)
{

Item memory item = i t e m s [ b a t c h i d d ] ;

B.Tech 2020 71 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

return
(

item . bat chi d ,


item . ownerID ,
item . manuname ,
// item . p r o d u c t P r i c e ,
item . productDate ,
item . expiryDate ,
item . w h o l e s a l e r ,
item . d i s t r i b u t o r ,
item . pharma
);

/// Get Madicine Batch Count


/// @return Number o f Batches
f u n c t i o n getBatchesCountM ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only Manufacturer Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n ManufactureredMadicineBatches [ msg . s e n d e r ] . l e n g t h ;
}

/// Get Madicine BatchID by i n d e x e d v a l u e o f s t o r e d data


/// i n d e x Indexed Number
/// @return Madicine BatchID
f u n c t i o n getBatchIdByIndexM ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e s
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . manufacturer ,
”Only Manufacturer Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n ManufactureredMadicineBatches [ msg . s e n d e r ] [ i n d e x ] ;

B.Tech 2020 72 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ W h o l e s a l e r S e c t i o n ∗∗∗

mapping ( a d d r e s s => a d d r e s s [ ] ) MadicineBatchesAtWholesaler ;


mapping ( a d d r e s s => a d d r e s s [ ] ) M a d i c i n e B a t c h A t D i s t r i b u t e r ;

/// Madicine Batch Re c ei ve d


/// b a t c h i d Madicine BatchID
/// param c i d Sub Contract ID f o r Madicine ( i f t r a n s a c t i o n W h o l e s
function madicineReceived (
a d d r e s s ba tch id ,
address cid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r | | U s e r
”Only W h o l e s a l e r and D i s t r i b u t e r can c a l l t h i s f u n c t i o n ”
);

u i n t r t y p e = Madicine ( b a t c h i d ) . r e c e i v e d P a c k a g e ( msg . s e n d e r ) ;

i f ( r t y p e == 1 ) {

MadicineBatchesAtWholesaler [ msg . s e n d e r ] . push ( b a t c h i d ) ;


}

e l s e i f ( r t y p e == 2){
M a d i c i n e B a t c h A t D i s t r i b u t e r [ msg . s e n d e r ] . push ( b a t c h i d ) ;
i f ( Madicine ( b a t c h i d ) . getWDP ( ) [ 0 ] != a d d r e s s ( 0 ) ) {
MadicineW D ( c i d ) . recieveWD ( b atc hid , msg . s e n d e r ) ;
}

}
}
f u n c t i o n g e t r e c e i v e d B a t c h e s C o u n t ( ) p u b l i c view r e t u r n s ( u i n t count

B.Tech 2020 73 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
”Only w h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineBatchesAtWholesaler [ msg . s e n d e r ] . l e n g t h ;
}

f u n c t i o n g e t r e c e i v e d B a t c h e s b y i n d e x ( u i n t i n d e x ) p u b l i c view r e t u r n s
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
”Only w h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineBatchesAtWholesaler [ msg . s e n d e r ] [ i n d e x ] ;
}

mapping ( a d d r e s s => a d d r e s s [ ] ) MadicineWtoD ;

mapping ( a d d r e s s => a d d r e s s ) MadicineWtoDTxContract ;

/// Sub Contract f o r Madicine T r a n s f e r from W h o l e s a l e r t o D i s


/// BatchID Madicine BatchID
/// S h i p p e r T r a n s p o r t e r Ethereum Network Address
/// R e c e i v e r D i s t r i b u t e r Ethereum Network Address
f u n c t i o n transferMadicineWtoD (
a d d r e s s BatchID ,
a d d r e s s Shipper ,
address Receiver
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r &&
msg . s e n d e r == Madicine ( BatchID ) . getWDP ( ) [ 0 ] ,
”Only W h o l e s a l e r o r c u r r e n t owner o f package can c a l l t h i s
);
MadicineW D wd = new MadicineW D (
BatchID ,
msg . sender ,

B.Tech 2020 74 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

Shipper ,
Receiver
);
// MadicineWtoD [ msg . s e n d e r ] . push ( a d d r e s s (wd ) ) ;
MadicineWtoD [ msg . s e n d e r ] . push ( BatchID ) ;

MadicineWtoDTxContract [ BatchID ] = a d d r e s s (wd ) ;


}

/// Get Madicine Batch Count


/// @return Number o f Batches
f u n c t i o n getBatchesCountWD ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
”Only W h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineWtoD [ msg . s e n d e r ] . l e n g t h ;
}

/// Get Madicine BatchID by i n d e x e d v a l u e o f s t o r e d data


/// i n d e x Indexed Number
/// @return Madicine BatchID
f u n c t i o n getBatchIdByIndexWD ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
”Only W h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineWtoD [ msg . s e n d e r ] [ i n d e x ] ;
}

/// Get Sub Contract ID o f Madicine Batch T r a n s f e r i n between


/// BatchID Madicine BatchID
/// @return SubContract ID
f u n c t i o n getSubContractWD ( a d d r e s s BatchID ) p u b l i c view r e t u r n s ( a d
// r e q u i r e (

B.Tech 2020 75 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

// U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . w h o l e s a l e r ,
// ”Only W h o l e s a l e r Can c a l l t h i s f u n c t i o n . ”
// ) ;
r e t u r n MadicineWtoDTxContract [ BatchID ] ;
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ D i s t r i b u t e r S e c t i o n ∗∗

// mapping ( a d d r e s s => a d d r e s s [ ] ) M a d i c i n e B a t c h A t D i s t r i b u t e r ;

mapping ( a d d r e s s => a d d r e s s [ ] ) MadicineDtoP ;

mapping ( a d d r e s s => a d d r e s s ) MadicineDtoPTxContract ;

f u n c t i o n madicineReceivedatD (
a d d r e s s ba tch id ,
address cid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only Pharma Can c a l l t h i s f u n c t i o n . ”
);
MadicineW D ( c i d ) . recieveWD ( b atc hid , msg . s e n d e r ) ;
M a d i c i n e B a t c h A t D i s t r i b u t e r [ msg . s e n d e r ] . push ( b a t c h i d ) ;
// s a l e [ b a t c h i d ] = s a l e s t a t u s ( 1 ) ;
}

f u n c t i o n g e t r e c e i v e d B a t c h e s C o u n t D ( ) p u b l i c view r e t u r n s ( u i n t coun
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only d i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n M a d i c i n e B a t c h A t D i s t r i b u t e r [ msg . s e n d e r ] . l e n g t h ;
}

B.Tech 2020 76 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

f u n c t i o n g e t r e c e i v e d B a t c h e s b y i n d e x D ( u i n t i n d e x ) p u b l i c view r e t u r n
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only d i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n M a d i c i n e B a t c h A t D i s t r i b u t e r [ msg . s e n d e r ] [ i n d e x ] ;
}

/// T r a n s f e r Madicine BatchID i n between D i s t r i b u t e r t o Pharma


/// BatchID Madicine BatchID
/// S h i p p e r T r a n s p o r t e r Ethereum Network Address
/// R e c e i v e r Pharma Ethereum Network Address
function transferMadicineDtoP (
a d d r e s s BatchID ,
a d d r e s s Shipper ,
address Receiver
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r &&
msg . s e n d e r == Madicine ( BatchID ) . getWDP ( ) [ 1 ] ,
”Only D i s t r i b u t e r o r c u r r e n t owner o f package can c a l l t h i
);
MadicineD P dp = new MadicineD P (
BatchID ,
msg . sender ,
Shipper ,
Receiver
);
MadicineDtoP [ msg . s e n d e r ] . push ( BatchID ) ;
MadicineDtoPTxContract [ BatchID ] = a d d r e s s ( dp ) ;
}

/// Get Madicine BatchID Count


/// @return Number o f Batches
f u n c t i o n getBatchesCountDP ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (

B.Tech 2020 77 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only D i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineDtoP [ msg . s e n d e r ] . l e n g t h ;
}

/// Get Madicine BatchID by i n d e x e d v a l u e o f s t o r e d data


/// i n d e x Index Number
/// @return Madicine BatchID
f u n c t i o n getBatchIdByIndexDP ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
”Only D i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n MadicineDtoP [ msg . s e n d e r ] [ i n d e x ] ;
}

/// Get SubContract ID o f Madicine Batch T r a n s f e r i n between D


/// BatchID Madicine BatchID
/// @return SubContract ID
f u n c t i o n getSubContractDP ( a d d r e s s BatchID ) p u b l i c view r e t u r n s ( a d
// r e q u i r e (
// U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . d i s t r i b u t e r ,
// ”Only D i s t r i b u t e r Can c a l l t h i s f u n c t i o n . ”
// ) ;
r e t u r n MadicineDtoPTxContract [ BatchID ] ;
}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Pharma S e c t i o n ∗∗∗∗∗∗∗

mapping ( a d d r e s s => a d d r e s s [ ] ) MadicineBatchAtPharma ;


mapping ( a d d r e s s => a d d r e s s [ ] ) M a d i c i n e s a l e ;

/// Madicine Batch Re c ie ve d


/// b a t c h i d Madicine BatchID
/// c i d SubContract ID

B.Tech 2020 78 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

f u n c t i o n madicineRecievedAtPharma (
a d d r e s s ba tch id ,
address cid
) public {
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only Pharma Can c a l l t h i s f u n c t i o n . ”
);
MadicineD P ( c i d ) . recieveDP ( batc hid , msg . s e n d e r ) ;
MadicineBatchAtPharma [ msg . s e n d e r ] . push ( b a t c h i d ) ;
s a l e [ batchid ] = s a l e s t a t u s ( 1 ) ;
}

enum s a l e s t a t u s {
notfound ,
atpharma ,
sold ,
expire ,
damaged
}

mapping ( a d d r e s s => s a l e s t a t u s ) s a l e ;

event MadicineStatus (
a d d r e s s BatchID ,
a d d r e s s i n d e x e d Pharma ,
uint status
);

/// Update Madicine Batch s t a t u s


/// BatchID Madicine BatchID
/// S t a t u s Madicine Batch S t a t u s ( s o l d , e x p i r e e t c . )
function updateSaleStatus (
a d d r e s s BatchID ,
uint Status
) public {
require (

B.Tech 2020 79 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma &&


msg . s e n d e r == Madicine ( BatchID ) . getWDP ( ) [ 2 ] ,
”Only Pharma o r c u r r e n t owner o f package can c a l l t h i s f u n
);
r e q u i r e ( s a l e [ BatchID ] == s a l e s t a t u s ( 1 ) , ” madicine Must be a t P
s a l e [ BatchID ] = s a l e s t a t u s ( S t a t u s ) ;
M a d i c i n e s a l e [ msg . s e n d e r ] . push ( BatchID ) ;

emit M a d i c i n e S t a t u s ( BatchID , msg . sender , S t a t u s ) ;


}

f u n c t i o n g e t s a l e c o u n t P ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only pharma Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n M a d i c i n e s a l e [ msg . s e n d e r ] . l e n g t h ;
}

f u n c t i o n g e t s a l e i n d e x P ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e s s pac
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only pharma Can c a l l t h i s f u n c t i o n . ”
);
r e t u r n M a d i c i n e s a l e [ msg . s e n d e r ] [ i n d e x ] ;
}

/// Get Madicine Batch s t a t u s


/// BatchID Madicine BatchID
/// @return S t a t u s
function salesInfo (
a d d r e s s BatchID
) public
view
returns (
uint Status

B.Tech 2020 80 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

){
r e t u r n u i n t ( s a l e [ BatchID ] ) ;
}

/// Get Madicine Batch count


/// @return Number o f Batches
f u n c t i o n getBatchesCountP ( ) p u b l i c view r e t u r n s ( u i n t count ){
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only W h o l e s a l e r o r c u r r e n t owner o f package can c a l l t h i s
);
r e t u r n MadicineBatchAtPharma [ msg . s e n d e r ] . l e n g t h ;
}

/// Get Madicine BatchID by i n d e x e d v a l u e o f s t o r e d data


/// i n d e x Index Number
/// @return Madicine BatchID
f u n c t i o n getBatchIdByIndexP ( u i n t i n d e x ) p u b l i c view r e t u r n s ( a d d r e s
require (
U s e r s D e t a i l s [ msg . s e n d e r ] . r o l e == r o l e s . pharma ,
”Only W h o l e s a l e r o r c u r r e n t owner o f package can c a l l t h i s
);
r e t u r n MadicineBatchAtPharma [ msg . s e n d e r ] [ i n d e x ] ;
}
}

/∗−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
# D i s t r i b u t o r −Pharma F u c n t i o n s
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗/

pragma s o l i d i t y >=0.4.25 < 0 . 6 . 0 ;

import ’ . / Madicine . s o l ’ ;

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ MadicineD P ∗∗∗∗∗∗∗∗∗∗

B.Tech 2020 81 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

/// Sub Contract f o r Madicine T r a n s a c t i o n between D i s t r i b u t e r and


c o n t r a c t MadicineD P {

a d d r e s s Owner ;

enum p a c k a g e S t a t u s { a t c r e a t o r , picked , d e l i v e r e d }

address batchid ;

address sender ;

address shipper ;

address r e c e i v e r ;

packageStatus status ;

/// Create SubContract f o r Madicine T r a n s a c t i o n


/// BatchID Madicine BatchID
/// Sender D i s t r i b u t e r Ethereum Network Address
/// S h i p p e r T r a n s p o r t e r Ethereum Network Address
/// R e c e i v e r Pharma Ethereum Network Address
constructor (
a d d r e s s BatchID ,
a d d r e s s Sender ,
a d d r e s s Shipper ,
address Receiver
) public {
Owner = Sender ;
b a t c h i d = BatchID ;
s e n d e r = Sender ;
shipper = Shipper ;
r e c e i v e r = Receiver ;
status = packageStatus ( 0 ) ;
}

B.Tech 2020 82 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

/// Pick Madicine Batch by A s s o c i a t e d T r a n s p o r t e r


/// BatchID Madicine BatchID
/// S h i p p e r T r a n s p o r t e r Ethereum Network Address
f u n c t i o n pickDP (
a d d r e s s BatchID ,
address Shipper
) public {
require (
S h i p p e r == s h i p p e r ,
”Only A s s o c i a t e d s h i p p e r can c a l l t h i s f u n c t i o n . ”
);
status = packageStatus ( 1 ) ;

Madicine ( BatchID ) . sendDP (


receiver ,
sender
);
}

f u n c t i o n recieveDP (
a d d r e s s BatchID ,
address Receiver
) public {
require (
R e c e i v e r == r e c e i v e r ,
”Only A s s o c i a t e d r e c e i v e r can c a l l t h i s f u n c t i o n . ”
);
status = packageStatus ( 2 ) ;

Madicine ( BatchID ) . recievedDP (


Receiver
);
}

f u n c t i o n g e t B a t c h I D S t a t u s ( ) p u b l i c view r e t u r n s (
uint

B.Tech 2020 83 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

) {
return uint ( status ) ;
}

pragma s o l i d i t y >=0.4.25 < 0 . 6 . 0 ;

import ’ . / Madicine . s o l ’ ;

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ MadicineW D ∗∗∗∗∗∗∗∗∗∗

c o n t r a c t MadicineW D {

a d d r e s s Owner ;

enum p a c k a g e S t a t u s { a t c r e a t o r , picked , d e l i v e r e d }

address batchid ;

address sender ;

address shipper ;

address r e c e i v e r ;

packageStatus status ;

constructor (
a d d r e s s BatchID ,
a d d r e s s Sender ,

B.Tech 2020 84 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

a d d r e s s Shipper ,
address Receiver
) public {
Owner = Sender ;
b a t c h i d = BatchID ;
s e n d e r = Sender ;
shipper = Shipper ;
r e c e i v e r = Receiver ;
status = packageStatus ( 0 ) ;

f u n c t i o n pickWD (
a d d r e s s BatchID ,
address Shipper
) public {
require (
S h i p p e r == s h i p p e r ,
”Only A s s o c i a t e d s h i p p e r can c a l l t h i s f u n c t i o n . ”
);
status = packageStatus ( 1 ) ;

Madicine ( BatchID ) . sendWD(


receiver ,
sender
);
}

f u n c t i o n recieveWD (
a d d r e s s BatchID ,
address Receiver
) public {
require (
R e c e i v e r == r e c e i v e r ,
”Only A s s o c i a t e d r e c e i v e r can c a l l t h i s f u n c t i o n . ”

B.Tech 2020 85 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

);
status = packageStatus ( 2 ) ;

Madicine ( BatchID ) . recievedWD (


Receiver
);
}

f u n c t i o n g e t B a t c h I D S t a t u s ( ) p u b l i c view r e t u r n s (
uint
) {
return uint ( status ) ;
}

/∗−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
# Wholesaler−D i s t r i b u t o r F u n c t i o n s
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗/

pragma s o l i d i t y >=0.4.25 < 0 . 6 . 0 ;

import ’ . / Madicine . s o l ’ ;

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ MadicineW D ∗∗∗∗∗∗∗∗∗∗

c o n t r a c t MadicineW D {

a d d r e s s Owner ;

enum p a c k a g e S t a t u s { a t c r e a t o r , picked , d e l i v e r e d }

address batchid ;

address sender ;

B.Tech 2020 86 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

address shipper ;

address r e c e i v e r ;

packageStatus status ;

constructor (
a d d r e s s BatchID ,
a d d r e s s Sender ,
a d d r e s s Shipper ,
address Receiver
) public {
Owner = Sender ;
b a t c h i d = BatchID ;
s e n d e r = Sender ;
shipper = Shipper ;
r e c e i v e r = Receiver ;
status = packageStatus ( 0 ) ;

f u n c t i o n pickWD (
a d d r e s s BatchID ,
address Shipper
) public {
require (
S h i p p e r == s h i p p e r ,
”Only A s s o c i a t e d s h i p p e r can c a l l t h i s f u n c t i o n . ”
);
status = packageStatus ( 1 ) ;

Madicine ( BatchID ) . sendWD(


receiver ,
sender

B.Tech 2020 87 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

);
}

f u n c t i o n recieveWD (
a d d r e s s BatchID ,
address Receiver
) public {
require (
R e c e i v e r == r e c e i v e r ,
”Only A s s o c i a t e d r e c e i v e r can c a l l t h i s f u n c t i o n . ”
);
status = packageStatus ( 2 ) ;

Madicine ( BatchID ) . recievedWD (


Receiver
);
}

f u n c t i o n g e t B a t c h I D S t a t u s ( ) p u b l i c view r e t u r n s (
uint
) {
return uint ( status ) ;
}

pragma s o l i d i t y >=0.4.25 < 0 . 6 . 0 ;

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ RawMatrials ∗∗∗∗∗∗∗∗∗∗

c o n t r a c t RawMatrials {

a d d r e s s Owner ;

enum p a c k a g e S t a t u s { a t c r e a t o r , picked , d e l i v e r e d }
e v e n t ShippmentUpdate (

B.Tech 2020 88 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

a d d r e s s i n d e x e d BatchID ,
a d d r e s s i n d e x e d Shipper ,
a d d r e s s i n d e x e d Manufacturer ,
u i n t TransporterType ,
uint Status
);
address productid ;

bytes32 d e s c r i p t i o n ;
b y t e s 3 2 farmer name ;
bytes32 l o c a t i o n ;
uint quantity ;
address shipper ;
a d d r e s s ma n u f ac t u r e r ;
address supplier ;
packageStatus status ;
bytes32 packageReceiverDescription ;

constructor (
address Splr ,
b y t e s 3 2 Des ,
b y t e s 3 2 FN,
b y t e s 3 2 Loc ,
u i n t Quant ,
a d d r e s s Shpr ,
a d d r e s s Rcvr
) public {
Owner = S p l r ;
productid = address ( t h i s ) ;
d e s c r i p t i o n = Des ;
farmer name = FN;
l o c a t i o n = Loc ;
q u a n t i t y = Quant ;
s h i p p e r = Shpr ;
m a nu f a c t ur e r = Rcvr ;
supplier = Splr ;
status = packageStatus ( 0 ) ;

B.Tech 2020 89 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

f u n c t i o n g e t S u p p l i e d R a w M a t r i a l s ( ) p u b l i c view r e t u r n s (
b y t e s 3 2 Des ,
b y t e s 3 2 FN,
b y t e s 3 2 Loc ,
u i n t Quant ,
a d d r e s s Shpr ,
a d d r e s s Rcvr ,
address Splr
) {
return (
description ,
farmer name ,
location ,
quantity ,
shipper ,
manufacturer ,
supplier
);
}

f u n c t i o n g e t R a w M a t r i a l s S t a t u s ( ) p u b l i c view r e t u r n s (
uint
) {
return uint ( status ) ;
}

f u n c t i o n pickPackage (
a d d r e s s shpr
) public {
require (
shpr == s h i p p e r ,
”Only A s s o c i a t e S h i p p e r can c a l l t h i s f u n c t i o n ”
);

B.Tech 2020 90 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

require (
s t a t u s == p a c k a g e S t a t u s ( 0 ) ,
” Package must be a t S u p p l i e r . ”
);
status = packageStatus ( 1 ) ;
emit ShippmentUpdate ( a d d r e s s ( t h i s ) , s h i p p e r , manufacturer , 1 , 1 ) ;
}

function receivedPackage (
a d d r e s s manu
) public {

require (
manu == manufacturer ,
”Only A s s o c i a t e Manufacturer can c a l l t h i s f u n c t i o n ”
);

require (
s t a t u s == p a c k a g e S t a t u s ( 1 ) ,
” Product not p i c k e d up y e t ”
);
status = packageStatus ( 2 ) ;
emit ShippmentUpdate ( a d d r e s s ( t h i s ) , s h i p p e r , manufacturer , 1 , 2 ) ;
}
}

Ethereum Contract Service Code

import { I n j e c t a b l e } from ’ @angular / c o r e ’ ;


// import ∗ as Web3 from ’ web3 ’ ;
c o n s t Web3 = r e q u i r e ( ’ web3 ’ ) ;
import ∗ as T r u f f l e C o n t r a c t from ’ t r u f f l e −c o n t r a c t ’ ;
import { r e s o l v e , r e j e c t } from ’ q ’ ;
import { ConstantPool } from ’ @angular / c o m p i l e r ’ ;
// import { c o p y F i l e S y n c } from ’ f s ’ ;
d e c l a r e l e t r e q u i r e : any ;

B.Tech 2020 91 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

d e c l a r e l e t window : any ;
l e t c o n t r a c t = r e q u i r e ( ’ . / s h a r e d / C o n t r a c t s / SupplyChain . j s o n ’ ) ;
l e t c o n t r a c t S u p p l y C h a i n = r e q u i r e ( ’ . / s h a r e d / C o n t r a c t s / SupplyChain . j s o
l e t c o n t r a c t R a w M a t r i a l s = r e q u i r e ( ’ . / s h a r e d / C o n t r a c t s / RawMatrials . j s o
l e t contract MedicineW D = r e q u i r e ( ’ . / s h a r e d / C o n t r a c t s /MadicineW D . j s o
l e t c o n t r a c t M e d i c i n e D P = r e q u i r e ( ’ . / s h a r e d / C o n t r a c t s / MadicineD P . j s o
l e t c o n t r a c t M e d i c i n e = r e q u i r e ( ’ . / s h a r e d / C o n t r a c t s / Madicine . j s o n ’ ) ;

@ I n j e c t a b l e ({
providedIn : ’ root ’
})
export c l a s s EthcontractService {

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ V a r i a b l e s ∗∗∗∗∗∗∗
p r i v a t e web3 : any ;
p r i v a t e web3Provider : n u l l ;
// p r i v a t e c o n t r a c t s : any ;
p r i v a t e c o i n b a s e : ”0 x0000000000000000000000000000000000000000 ” ;

p r i v a t e c o n t r a c t s S u p p l y C h a i n : any ;

p r i v a t e c o n t r a c t A d d r e s s S u p p l y C h a i n : ”0 x0000000000000000000000000000

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ C o n s t r u c t o r ∗∗∗∗∗
constructor () {
try {

i f ( t y p e o f window . web3 !== ’ u n d e f i n e d ’ ) {


t h i s . web3Provider = window . web3 . c u r r e n t P r o v i d e r ;
} else {
t h i s . web3Provider = new Web3 . p r o v i d e r s . H t t p P r o v i d e r ( ’ http : / / l o
}
window . web3 = new Web3( t h i s . web3Provider ) ;
t h i s . web3 = window . web3 ;

t h i s . c o n t r a c t s S u p p l y C h a i n = t h i s . web3 . e th . c o n t r a c t (

B.Tech 2020 92 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

contract SupplyChain . abi


) . a t ( c o n t r a c t S u p p l y C h a i n . networks [ t h i s . web3 . c u r r e n t P r o v i d e r . n e t

t h i s . c o n t r a c t A d d r e s s S u p p l y C h a i n = c o n t r a c t S u p p l y C h a i n . networks

// window . c o n t r a c t = c o n t r a c t ;
window . c o n t r a c t s = t h i s . c o n t r a c t s S u p p l y C h a i n ;
this . getcoinbase ( ) ;
console . log ( t h i s . contracts SupplyChain ) ;
} catch ( e r r ) {
return err ;
}
}
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ B a s i c ∗∗∗∗∗∗∗∗∗∗∗
g e t c o i n b a s e = ( ) => {
l e t that = t h i s ;
t h a t . web3 . e t h . g e t C o i n b a s e ( f u n c t i o n ( e r r , account ) {
i f ( e r r === n u l l ) {
t h a t . c o i n b a s e = account ;
}
});
}

g e t A c c o u n t I n f o = ( ) => {
l e t that = t h i s ;
r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
t h a t . web3 . e t h . g e t C o i n b a s e ( f u n c t i o n ( e r r , account ) {
i f ( e r r === n u l l ) {
t h a t . web3 . e t h . g e t B a l a n c e ( account , f u n c t i o n ( e r r , b a l a n c e ) {
i f ( e r r === n u l l ) {
r e t u r n r e s o l v e ({ Account : account , Balance : t h a t . web3 . fr
} else {
return r e j e c t (” e r r o r ! ” ) ;
}
});
}
});
});

B.Tech 2020 93 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

f e t c h d e t a i l s = ( formdata ) => {
c o n s o l e . l o g ( ’ i n s i d e e thc ont ’ ) ;
l e t that = t h i s ;
r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
l e t c o n t r a c t s S u p p l y C h a i n = t h i s . web3 . e th . c o n t r a c t ( c o n t r a c t S u p p
c o n t r a c t s S u p p l y C h a i n . f e t c h d e t a i l s ( formdata . bat chi d , { } ,
function ( error , result ) {
i f ( ! e r r o r ){
let jsonres = {
” Batchid ” : r e s u l t [ 0 ] ,
// ” d e s c r i p t i o n ” : r e s u l t [ 1 ] ,
”OwnerID ” : r e s u l t [ 1 ] ,
”Manuname ” : t h a t . web3 . t o A s c i i ( r e s u l t [ 2 ] . r e p l a c e (/0+\b /
” Productdate ” : r e s u l t [ 3 ] ,
” Expirydate ” : r e s u l t [ 4 ] ,
” Wholesaler ” : r e s u l t [ 5 ] ,
” Distributor ”: result [6] ,
”Pharma ” : r e s u l t [ 7 ]
// ” S a l e s t a t u s ” : r e s u l t [ 9 ]
}
resolve ( jsonres );
console . log ( jsonres ) ;
c on so l e . log ( ’ anything ? ? ? ’ ) ;
console . log ( result [ 1 ] ) ;
console . log ( result ) ;
}else {
console . log ( ’ i t s else ’ ) ;
return r e j e c t ( error );}
});
});
}
// }
// ) ;

B.Tech 2020 94 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

// } ) ;

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Admin ∗∗∗∗∗∗∗∗∗∗∗


getOwner = ( ) => {
l e t that = t h i s ;
r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
t h a t . web3 . e t h . g e t C o i n b a s e ( f u n c t i o n ( e r r , account ) {
i f ( e r r === n u l l ) {
t h a t . web3 . e t h . g e t B a l a n c e ( account , f u n c t i o n ( e r r , b a l a n c e ) {
i f ( e r r === n u l l ) {
t h a t . c o n t r a c t s S u p p l y C h a i n . Owner ( f u n c t i o n ( e r r o r , ownerA
i f (! error ) {
i f ( ownerAddress == account ) {
// t h a t . c o n t r a c t s S u p p l y C h a i n . getUsersCount ( f u n c t i
t h a t . c o n t r a c t s S u p p l y C h a i n . getUsersCount ( f u n c t i o n
i f (! error ) {
r e t u r n r e s o l v e ({ Account : account , Balance : t h
}
else
r e t u r n r e s o l v e ({ Account : account , Balance : t h
})
}
else {
r e t u r n r e s o l v e ({ Role : ’ F a i l u r e ’ } ) ;
}
}
else
reject ( error );
})
} else {
return r e j e c t (” e r r o r ! ” ) ;
}
});
} else {
r e t u r n r e j e c t ( ”No Coinbase ! ” ) ;
}
});
});

B.Tech 2020 95 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

r e g i s t e r N e w U s e r = ( formdata ) => {
l e t that = t h i s ;
formdata . Name = t h a t . web3 . padRight ( t h a t . web3 . f r o m A s c i i ( formdata . Na
formdata . L o c a t i o n = t h a t . web3 . padRight ( t h a t . web3 . f r o m A s c i i ( formdat

r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {


t h a t . web3 . e t h . g e t C o i n b a s e ( f u n c t i o n ( e r r , account ) {
i f ( e r r === n u l l ) {

// t h a t . c o n t r a c t s S u p p l y C h a i n . r e g i s t e r U s e r ( formdata . EthAddr
t h a t . c o n t r a c t s S u p p l y C h a i n . r e g i s t e r U s e r ( formdata . EthAddress ,
from : account
} , function ( error , result ) {
i f (! error )
resolve ( result )
else
reject ( error );
});
}
});
});
}

r e v o k e R o l e = ( formdata ) => {
l e t that = t h i s ;
r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
t h a t . web3 . e t h . g e t C o i n b a s e ( f u n c t i o n ( e r r , account ) {
i f ( e r r === n u l l ) {

// t h a t . c o n t r a c t s S u p p l y C h a i n . r e g i s t e r U s e r ( formdata . EthAddr
t h a t . c o n t r a c t s S u p p l y C h a i n . r e v o k e R o l e ( formdata . EthAddress , {
from : account
} , function ( error , result ) {
i f (! error )
resolve ( result )
else

B.Tech 2020 96 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

reject ( error );
});
}
});
});
}
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ U s e r s ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/
g e t R o l e = ( ) => {
l e t that = t h i s ;
r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
t h a t . web3 . e t h . g e t C o i n b a s e ( f u n c t i o n ( e r r , account ) {
i f ( e r r === n u l l ) {
t h a t . web3 . e t h . g e t B a l a n c e ( account , f u n c t i o n ( e r r , b a l a n c e ) {
i f ( e r r === n u l l ) {
// t h a t . c o n t r a c t s S u p p l y C h a i n . g e t U s e r I n f o (
that . contracts SupplyChain . getUserInfo (
account ,
{
from : account
} , function ( error , res ) {
i f ( res ) {
// c o n s o l e . l o g ( r e s [ 0 ] . s u b s t r i n g ( 0 , 3 4 ) )
var j s o n r e s = {
”Name ” : t h a t . web3 . t o A s c i i ( r e s [ 0 ] . r e p l a c e (/0+\b / ,
” L o c a t i o n ” : t h a t . web3 . t o A s c i i ( r e s [ 1 ] . r e p l a c e (/0+
” EthAddress ” : r e s [ 2 ] ,
” Role ” : JSON . p a r s e ( r e s [ 3 ] )
}
r e t u r n r e s o l v e ({ Account : account , Balance : t h a t . w
}
else {
return r e j e c t ( error ) ;
}
});
} else {
return r e j e c t ( err ) ;
}
});

B.Tech 2020 97 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

} else {
return r e j e c t ( err ) ;
}
});
});
}
getUserCount = ( ) => {
l e t that = t h i s ;
r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
// t h a t . c o n t r a c t s S u p p l y C h a i n . getUsersCount ( f u n c t i o n ( e r r o r , use
t h a t . c o n t r a c t s S u p p l y C h a i n . getUsersCount ( f u n c t i o n ( e r r o r , userCo
i f (! error ) {
r e t u r n r e s o l v e ({ UserCount : JSON . p a r s e ( userCount ) } ) ;
}
else
return r e j e c t ( error ) ;
});
});
}
g e t U s e r P r o f i l e = ( formdata ) => {
l e t that = t h i s ;
r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
// t h a t . c o n t r a c t s S u p p l y C h a i n . g e t U s e r b y I n d e x ( index , {
t h a t . c o n t r a c t s S u p p l y C h a i n . g e t U s e r b y I n d e x ( formdata . Index , {
from : t h a t . c o i n b a s e
} , function ( error , uinfo ) {
i f (! error ) {
var j s o n r e s = {
”Name ” : t h a t . web3 . t o A s c i i ( u i n f o [ 0 ] . r e p l a c e (/0+\b / , ” ” ) ) ,
” L o c a t i o n ” : t h a t . web3 . t o A s c i i ( u i n f o [ 1 ] . r e p l a c e (/0+\b / , ” ” )
” EthAddress ” : u i n f o [ 2 ] ,
” Role ” : JSON . p a r s e ( u i n f o [ 3 ] )
}
console . log ( jsonres ) ;
r e s o l v e ({ r e s u l t : j s o n r e s } ) ;
}
else
reject ( error );

B.Tech 2020 98 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

})
});
}

g e t U s e r s = ( formdata ) => {
l e t that = t h i s ;
r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
// t h a t . c o n t r a c t s S u p p l y C h a i n . g e t U s e r I n f o ( account ,
t h a t . c o n t r a c t s S u p p l y C h a i n . g e t U s e r I n f o ( formdata . AccountAddress ,
function ( error , uinfo ) {
i f (! error ) {
var j s o n r e s = {
”Name ” : t h a t . web3 . t o A s c i i ( u i n f o [ 0 ] . r e p l a c e (/0+\b / , ” ” ) ) ,
” L o c a t i o n ” : t h a t . web3 . t o A s c i i ( u i n f o [ 1 ] . r e p l a c e (/0+\b / , ”
” EthAddress ” : u i n f o [ 2 ] ,
” Role ” : JSON . p a r s e ( u i n f o [ 3 ] )
}
console . log ( jsonres ) ;
r e s o l v e ({ r e s u l t : j s o n r e s } ) ;
}
else
reject ( error );
});
});
}

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
App r o u t i n g page
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
import { NgModule } from ’ @angular / c o r e ’ ;
import { Routes , RouterModule } from ’ @angular / r o u t e r ’ ;

import { HomeComponent } from ’ . / components /home/home . component ’ ;


import { AdminComponent } from ’ . / components /admin/admin . component ’ ;
import { UserComponent } from ’ . / components / u s e r / u s e r . component ’ ;
import { SupplierComponent } from ’ . / components / s u p p l i e r / s u p p l i e r . comp
import { ManufacturerComponent } from ’ . / components / m a nu f a c t ur e r / ma n u

B.Tech 2020 99 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

import { TransporterComponent } from ’ . / components / t r a n s p o r t e r / t r a n s p o


import { TestComponent } from ’ . / components / t e s t c o m p o n e n t s / testcompone
import { w h o l e s a l e r c o m p o n e n t } from ’ . / components / w h o l e s a l e r / w h o l e s a l e
import { d i s t r i b u t o r c o m p o n e n t } from ’ . / components / d i s t r i b u t o r / d i s t r i b
import { pharmacomponent } from ’ . / components /pharma/pharma . component ’

c o n s t r o u t e s : Routes = [
{
path : ’ home ’ ,
component : HomeComponent ,
data : { t i t l e : ’Home Page ’ }
},
{
path : ’ u s er ’ ,
component : UserComponent ,
data : { t i t l e : ’ User Page ’ }
},
{
path : ’ s u p p l i e r ’ ,
component : SupplierComponent ,
data : { t i t l e : ’ S u p p l i e r Page ’ }
},
{
path : ’ manufacturer ’ ,
component : ManufacturerComponent ,
data : { t i t l e : ’ Manufacturer Page ’ }
},
{
path : ’ t r a n s p o r t e r ’ ,
component : TransporterComponent ,
data : { t i t l e : ’ T r a n s p o r t e r Page ’ }
},
{
path : ’ w h o l e s a l e r ’ ,
component : wholesalercomponent ,
data : { t i t l e : ’ w h o l e s a l e r Page ’ }
},
{

B.Tech 2020 100 Dept. of CSE


Fraud Medicine Prevention Using Blockchain

path : ’ d i s t r i b u t o r ’ ,
component : d i s t r i b u t o r c o m p o n e n t ,
data : { t i t l e : ’ D i s t r i b u t o r Page ’ }
},
{
path : ’ pharma ’ ,
component : pharmacomponent ,
data : { t i t l e : ’ Pharma Page ’ }
},
{
path : ’ admin ’ ,
component : AdminComponent ,
data : { t i t l e : ’ Admin Page ’ }
},
{
path : ’ t e s t ’ ,
component : TestComponent ,
data : { t i t l e : ’ Test Page ’ }
},
{
path : ’ ’ ,
r e d i r e c t T o : ’ / home ’ ,
pathMatch : ’ f u l l ’
},
{ path : ’ ∗ ∗ ’ , r e d i r e c t T o : ’ / home ’ }

];
@NgModule ({
imports : [
RouterModule . f o r R o o t (
routes ,
{ e n a b l e T r a c i n g : t r u e } // <−− debugging p u r p o s e s o n l y
)
],
e x p o r t s : [ RouterModule ]
})
e x p o r t c l a s s AppRoutingModule { }

B.Tech 2020 101 Dept. of CSE

Das könnte Ihnen auch gefallen