-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmart_contract.sol
More file actions
178 lines (153 loc) · 4.96 KB
/
Smart_contract.sol
File metadata and controls
178 lines (153 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Solidity program to demonstrate
// how to create a contract
///@custom:dev-run-script file_path
//SPDX-License-Identifier: GPT-3
pragma solidity >=0.8.4;
contract Mycontract{
uint256 public peopleCount = 0;
uint256 public DoctorCount = 0;
uint256 public PatientCount = 0;
uint256 public AgentCount = 0;
uint256 public PrepCount = 0;
string[] public patient_urls;
string public verified;
mapping(uint256 => People) public people;
mapping(uint256 => Doctor) public doctor;
mapping(uint256 => Patient) public patient;
mapping(uint256 => Agent) public agent;
mapping(uint256 => Prep_Rec) public prep_rec;
struct People {
address acc;
string _type;
string password;
}
struct Doctor {
address acc;
string name;
string password;
string dep;
string position;
string sex;
string age;
}
struct Patient {
address acc;
string name;
string password;
string sex;
string age;
string dob;
}
struct Agent {
address acc;
string name;
string password;
string sex;
string age;
string location;
string agency_name;
}
struct Prep_Rec {
address doc;
address pat;
string url;
}
function register_doctor (address _acc, string memory _name, string memory _password, string memory _dep, string memory _position, string memory _sex, string memory _age) public{
doctor[DoctorCount] = Doctor(_acc, _name, _password, _dep, _position, _sex, _age);
DoctorCount += 1;
people[peopleCount] = People(_acc,"doctor",_password);
peopleCount += 1;
}
function register_patient (address _acc, string memory _name, string memory _password, string memory _sex, string memory _age, string memory _dob) public{
patient[PatientCount] = Patient(_acc, _name, _password, _sex, _age, _dob);
PatientCount += 1;
people[peopleCount] = People(_acc,"patient",_password);
peopleCount += 1;
}
function register_agent (address _acc, string memory _name, string memory _password, string memory _sex, string memory _age, string memory _loaction, string memory _agency_name) public{
agent[AgentCount] = Agent(_acc, _name, _password, _sex, _age, _loaction, _agency_name);
AgentCount += 1;
people[peopleCount] = People(_acc,"agent",_password);
peopleCount += 1;
}
function upload_prep (address _doc, address _pat, string memory _url) public{
prep_rec[PrepCount].doc = _doc;
prep_rec[PrepCount].pat = _pat;
prep_rec[PrepCount].url = _url;
PrepCount += 1;
}
function download_prep (address _pat) public {
uint256 i;
uint256 j = 0;
patient_urls = new string[](0);
for(i=0; i<PrepCount ;i++){
if(prep_rec[i].pat == _pat){
patient_urls.push(prep_rec[i].url);
j = 1;
}
}
if(j==0){
patient_urls = ["Not Found!!"];
}
}
function Is_present(address _acc) public view returns(bool){
uint256 i;
for(i=0; i<peopleCount; i++){
if(people[i].acc == _acc){
return true;
}
}
return false;
}
function log_in(address _acc, string memory _password) public view returns(string memory){
uint256 i;
for(i=0; i<peopleCount; i++){
if(people[i].acc == _acc){
if(keccak256(abi.encodePacked(people[i].password)) == keccak256(abi.encodePacked(_password))){
return people[i]._type;
}
else{
return "false";
}
}
}
return "false";
}
function verify (address _pat, string memory _url) public{
uint256 i;
uint256 j = 0;
patient_urls = new string[](0);
for(i=0; i<PrepCount ;i++){
if(prep_rec[i].pat == _pat){
patient_urls.push(prep_rec[i].url);
j = 1;
}
}
if(j==0){
patient_urls = ["Not Found!!"];
verified = "false";
}
for(i=0; i<patient_urls.length; i++){
if(keccak256(abi.encodePacked(patient_urls[i])) == keccak256(abi.encodePacked(_url))){
verified = "true";
return;
}
}
verified = "false2";
}
function person_type (address acc) public view returns(string memory){
uint256 j;
for(j=0; j<peopleCount; j++){
if(people[j].acc == acc){
return people[j]._type;
}
}
return "false";
}
function urls_return() public view returns(string[] memory){
return patient_urls;
}
function verified_return() public view returns(string memory){
return verified;
}
}