From 13a994b6cad0d4fc09bc963cdabf557d172dd7c6 Mon Sep 17 00:00:00 2001 From: Monk <61575072+MonkNo1@users.noreply.github.com> Date: Wed, 17 May 2023 23:07:19 +0530 Subject: [PATCH] Create contract.sol --- contract.sol | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 contract.sol diff --git a/contract.sol b/contract.sol new file mode 100644 index 0000000..7ab40d3 --- /dev/null +++ b/contract.sol @@ -0,0 +1,206 @@ +pragma solidity ^0.8.14; +contract drugcompany +{ + struct product + { + uint avail; + uint threosold; + uint rate; + } + mapping (uint => product)drugs; + address producer; + address drugmanager; + address hospitalmanager; + // uint public prodid=0; + uint orderdid=0; + struct order + { + uint hospid; + uint time; + uint drugid; + uint quantity; + uint amount; + } + mapping (uint => order)orders; + uint [] hospitals; + uint public income=0; + struct patient + { + uint hospid; + } + struct patient_log + { + uint patientid; + uint docid; + uint timestamp; + uint drugid; + uint amount; + } + event produced_drug_event(uint pid,uint a); + event added_drug_event(uint p,uint a,uint t,uint r); + event drug_bought_event(uint h,uint porid,uint req_amount,uint did,uint patid); + uint [] patientarr; + uint [] doctors; + mapping (uint => patient) patients; + mapping (uint => patient_log) logs; + uint logid=1; + modifier onlydm(address d) + { + require(d==drugmanager,"only drug manager is allowed"); + _; + } + modifier onlyhm(address d) + { + require(d==hospitalmanager,"only hospital manager is allowed"); + _; + } + function reg_producer(address w) public onlydm(msg.sender) + { + producer=w; + } + constructor(address hm) + { + drugmanager=msg.sender; + hospitalmanager=hm; + } + struct producer_content + { + uint amount; + } + mapping (uint => producer_content) produced_drug; + modifier onlyproducer(address j) + { + require(j==producer,"only producer is allowed"); + _; + } + function add_produced_drug(uint pid,uint a) public onlyproducer(msg.sender) + { + produced_drug[pid].amount=a; + emit produced_drug_event(pid,a); + } + function reg_hos(uint y) public onlyhm(msg.sender) + { + hospitals.push(y); + } + function reg_patient(uint y,uint hi) public onlyhm(msg.sender) + { + patientarr.push(y); + patients[y].hospid=hi; + } + function reg_doctor(uint y) public onlyhm(msg.sender) + { + doctors.push(y); + } + modifier validam(uint d,uint p) + { + require(produced_drug[p].amount==d,"not correct data is entered"); + _; + } + function add_drug(uint p,uint a,uint t,uint r) public onlydm(msg.sender) validam(a,p) + { + drugs[p].avail=a; + drugs[p].threosold=t; + drugs[p].rate=r; + // prodid+=1; + emit added_drug_event(p,a,t,r); + } + function update_avail(uint pi,uint k) public onlydm(msg.sender) validam(k,pi) + { + drugs[pi].avail+=k; + } + function valid_hos(uint j) private view returns(bool) + { + uint flag=0; + for(uint i=0;i