Beruflich Dokumente
Kultur Dokumente
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
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.
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
v
LIST OF ABBREVIATIONS
vi
Fraud Medicine Prevention Using Blockchain
54
CHAPTER 1
INTRODUCTION
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.
since counterfeit drugs bypass traditional sales avenues, and increased costs of
monitoring the efficacy and safety of pharmaceuticals.
CHAPTER 2
SYSTEM ANALYSIS
• Operational Feasibility
• Economic Feasibility
• 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.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:
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.
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).
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
• Accurate information across the entire chain at any point and at any
location
CHAPTER 3
SYSTEM REQUIREMENTS
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
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.
• 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.
• 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.
• Manage agreements between users, say, if one buys insurance from the
other
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
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 ,
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
:
• A configurable build pipeline that supports both web apps and console
apps.
• Generators for creating new contracts and tests (like rails generate)
• Contract compilation and deployment using the RPC client of your choice.
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
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
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
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.
CHAPTER 4
SYSTEM DESIGN
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.
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
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.
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.
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.
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.
CHAPTER 5
IMPLEMENTATION
Tracking of medicine
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.
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.
CHAPTER 6
RESULT
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-
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.
REFERENCES
ANNEXURES I
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
}
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
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 ) ;
}
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 ;
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
);
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 ) ;
}
);
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 ∗∗
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 ) ) ;
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
);
}∗/
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 {
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 ) ;
}
address i n d e x e d BatchId ,
address i n d e x e d Manufacturer ,
address shipper ,
address indexed Receiver
);
RcvrType
);
// 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
)
{
return
(
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ W h o l e s a l e r S e 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 ) {
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
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 ] ;
}
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 ) ;
// 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 ;
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 ;
}
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 ] ;
}
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 ;
}
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
);
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 ) ;
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 ] ;
}
) public
view
returns (
uint Status
){
r e t u r n u i n t ( s a l e [ BatchID ] ) ;
}
/∗−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
# Medicine F u n c t i o n s Code
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗/
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 ;
enum r o l e s {
norole ,
supplier ,
transporter ,
manufacturer ,
wholesaler ,
distributer ,
pharma ,
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
/// 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 ) ;
}
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 ;
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
);
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 ) ;
}
);
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 ∗∗
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 ) ) ;
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
);
}∗/
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 {
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 ) ;
}
address i n d e x e d BatchId ,
address i n d e x e d Manufacturer ,
address shipper ,
address indexed Receiver
);
RcvrType
);
// 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
)
{
return
(
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ W h o l e s a l e r S e 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 ) {
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
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 ] ;
}
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 ) ;
// 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 ;
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 ;
}
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 ] ;
}
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 ;
}
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
);
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 ] ;
}
){
r e t u r n u i n t ( s a l e [ BatchID ] ) ;
}
/∗−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
# D i s t r i b u t o r −Pharma F u c n t i o n s
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗/
import ’ . / Madicine . s o l ’ ;
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 ;
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 ) ;
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 ) ;
}
import ’ . / Madicine . s o l ’ ;
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 ,
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 ) ;
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 ) ;
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
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗/
import ’ . / Madicine . s o l ’ ;
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 ,
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 ) ;
);
}
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 ) ;
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 ) ;
}
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 (
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 ) ;
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 ”
);
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 ) ;
}
}
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 {
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 (
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 ! ” ) ;
}
});
}
});
});
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 );}
});
});
}
// }
// ) ;
// } ) ;
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
// 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
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 ) ;
}
});
} 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 );
})
});
}
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 ’ ;
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 ’ }
},
{
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 { }