-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatientRecordContract.sol
More file actions
80 lines (63 loc) · 2.45 KB
/
patientRecordContract.sol
File metadata and controls
80 lines (63 loc) · 2.45 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
pragma solidity >=0.8.0 < 0.9.0;
//pragma experimental ABIEncoderV2
contract PatientRecord {
uint256 privatePasswordDigits = 16;
uint256 passwordModulus = 10 ** privatePasswordDigits;
uint256 index = 0;
uint256 tempPasswordStore = 0;
struct People {
uint256 id;
uint8 covid19_Res;
string aggregation;
}
People[] public people;
mapping(uint256 => People) public idToPeople;
mapping(uint256 => People) public privatePasswordToPeople;
function helloWorld() external pure returns(string memory) {
return "Hello World! This smart contract is writen by Jiayue Zhou.";
}
// Use sender address, current time, current index, and the aggregation to generate a 16 bits integer
// random password
function _generateRandomPrivatePassword(string memory _str) internal view returns (uint256) {
uint256 rand = uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp, index, _str)));
return rand % passwordModulus;
}
// Upload a datapoint
function storeData(uint8 covid19_Res, string memory aggregation)
external {
People memory newPeople = People(index, covid19_Res, aggregation);
people.push(newPeople);
idToPeople[index] = newPeople;
uint256 password = _generateRandomPrivatePassword(aggregation);
privatePasswordToPeople[password] = newPeople;
tempPasswordStore = password;
index++;
}
function getPassword() external returns(uint256){
uint256 temp = tempPasswordStore;
// Burn(Delete) after reading
tempPasswordStore = 0;
return temp;
}
function getData(uint256 id) external view returns(string memory) {
return idToPeople[id].aggregation;
}
function getDataByPassword(uint256 pw) external view returns(People memory) {
return privatePasswordToPeople[pw];
}
function getCovidResult(uint256 id) internal view returns(uint8) {
return idToPeople[id].covid19_Res;
}
function getCovidResultByPassword(uint256 pw) external view returns(uint8) {
return privatePasswordToPeople[pw].covid19_Res;
}
function getPeopleRecordNum(uint256 pw) internal view returns(uint256) {
return privatePasswordToPeople[pw].id;
}
function getPeopleRecordTotalNum() external view returns(uint256) {
return index;
}
function getTotal() external view returns(People[] memory) {
return people;
}
}