-
Notifications
You must be signed in to change notification settings - Fork 0
/
hospital_details.html
184 lines (163 loc) · 5.56 KB
/
hospital_details.html
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
179
180
181
182
183
184
<html>
<head>
<title>Hospital Details</title>
<style>
body{
background-image: url('image.jpg');
background-size: 2000px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
</style>
</head>
<body>
<p><a href="hospital.html"><button type="submit" class="hidden" style='margin-right:16px'>Hospital Registration</button></a><a href="doctor.html"><button type="submit" class="hidden" style='margin-right:16px'>Doctor Registration</button></a><a href="patient.html"><button type="submit" class="hidden" style='margin-right:16px'>Patient Registration</button></a><a href="patient_details.html"><button type="submit" class="hidden" style='margin-right:16px'>View Patient Details</button></a><a href="record_details.html"><button type="submit" class="hidden" style='margin-right:16px'>View Medical Record</button></a><a href="examine_details.html"><button type="submit" class="hidden" style='margin-right:16px'>View Patient Examine details</button></a></p>
<h1> Display Hospital Details </h1>
<script src="https://cdn.jsdelivr.net/npm/web3@1.2.8/dist/web3.js"></script>
<script>
var account;
window.addEventListener('load', async () => {
if (typeof window.ethereum !== 'undefined') {
console.log("MetaMask is Available :) !");
}
// Modern DApp browsers
if (window.ethereum) {
window.web3 = new Web3(ethereum);
// To prevent the page reloading when the MetaMask network changes
ethereum.autoRefreshOnNetworkChange = false;
// To Capture the account details from MetaMask
const accounts = await ethereum.enable();
account = accounts[0];
}
// Legacy DApp browsers
else if (window.web3) {
//window.web3 = new Web3(web3.currentProvider);
window.web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/cbd9dc11b30147e9a2cc974be655ef7c"));
}
// Non-DApp browsers
else {
console.log('Non-Ethereum browser detected. Please install MetaMask');
}
});
var abi = [
{
"inputs": [
{
"internalType": "uint256",
"name": "hospital_id",
"type": "uint256"
},
{
"internalType": "string",
"name": "_hospital_name",
"type": "string"
},
{
"internalType": "string",
"name": "_hospital_address",
"type": "string"
},
{
"internalType": "string",
"name": "_hospital_spec",
"type": "string"
}
],
"name": "store_doctor_details",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "hospital_id",
"type": "uint256"
}
],
"name": "retreive_hospital_details",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
]
var contractaddress = '0x16bebd092c97150101fc0d8e5a573e0af28709f4';
function add_details() {
var myContract = new web3.eth.Contract(abi,contractaddress, {from: account, gasPrice: '5000000', gas: '500000'});
var ds1 = document.getElementById("addr").value;
var ds2 = document.getElementById("spec").value;
var tname = document.getElementById("name1").value;
var id = document.getElementById("id1").value;
var result = myContract.methods.store_doctor_details(id,tname,ds1,ds2).send(function (err, result) {
if (err) { console.log(err); }
if (result) { document.getElementById("result").innerHTML = result; }
});
}
function show_details() {
var myContract = new web3.eth.Contract(abi,contractaddress, {from: account, gasPrice: '5000000', gas: '500000'});
var idd = document.getElementById("tid").value;
var result = myContract.methods.retreive_hospital_details(idd).call(function (err, result) {
if (err) { console.log(err); }
if (result) {
document.getElementById("get_name").innerHTML = result[0];
document.getElementById("get_addr").innerHTML = result[1];
document.getElementById("get_spec").innerHTML = result[2];
}
});
}
function del_details() {
var myContract = new web3.eth.Contract(abi,contractaddress, {from: account, gasPrice: '5000000', gas: '500000'});
var bid = document.getElementById("bid1").value;
var result = myContract.methods.burnMyToken(bid).send(function (err, result) {
if (err) { console.log(err); }
if (result) {
document.getElementById("result1").innerHTML = result;
}
});
}
</script>
<h3>Hospital Details:</h3>
<form>
<table style="width:25%">
<tr>
<td>Enter Hospital Id:</td>
<td><input type="text" id="tid" name="tid"></td>
</tr>
<tr><td><input type="button" onclick="show_details()" value="Get Details"></td></tr>
<tr>
<td> Hospital Name:</td>
<td><div id="get_name"></div></td>
</tr>
<tr>
<td>Hospital Address:</td>
<td><div id="get_addr"></div></td>
</tr>
<tr>
<td>Hospital Specification:</td>
<td><div id="get_spec"></div></td>
</tr>
</table>
</form>
</body>
</html>