-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpioidManager.sol
More file actions
140 lines (111 loc) · 4.54 KB
/
OpioidManager.sol
File metadata and controls
140 lines (111 loc) · 4.54 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
pragma solidity ^0.4.2;
contract OpioidManager{
struct Pharma{
bool registered;
}
mapping(address => Pharma) public pharmas;
function registerPharma(address _addr){
pharmas[_addr] = Pharma({registered: true});
}
//structure of an opioid prescription
struct MedicinePrescription{
string name;
string doi;
uint8 capsules;
uint8 density;
address patient;
bool distributed;
}
//presecriptions sill be mapped to addresses
uint256 public prescription_count = 0;
mapping (uint256 => bytes32) public prescription_hashes;
mapping (bytes32 => MedicinePrescription) public prescriptions;
//should only be callable by the physician
//DOESN'T ADD TO PATIENT MAPPING
//WORKS
function createPrescription(string _name, string _doi, uint8 _capsules, uint8 _density, address _patient){
prescription_count ++;
bytes32 _prescription_hash = keccak256(now, _doi, _name, _patient,_capsules,_density);
prescriptions[_prescription_hash] = MedicinePrescription({name: _name, doi: _doi, capsules: _capsules, density: _density, patient: _patient, distributed: false});
prescription_hashes[prescription_count] = _prescription_hash;
}
//WORKS
//this is the qr code that is generated
function getLatestPrescription() constant returns (bytes32){
return prescription_hashes[prescription_count];
}
//WORKS
function getTotalPrescriptionCount() constant returns (uint256){
return prescription_count;
}
//only callable by pharmacists
function distributePrescription(bytes32 _prescription_addr, address _patient){
//return true and add the prescription to the patients received prescriptions
//assert(pharmas[msg.sender].registered);
if(prescriptions[_prescription_addr].patient == _patient && !prescriptions[_prescription_addr].distributed){
prescriptions[_prescription_addr].distributed = true;
patients[_patient].prescription_count++;
patients[_patient].prescriptions[patients[_patient].prescription_count] = _prescription_addr;
}
}
//get functions for scanning status of the prescription callable by everyone?
function getCapsules(bytes32 _prescription_addr) constant returns (uint8){
return prescriptions[_prescription_addr].capsules;
}
function getDensity(bytes32 _prescription_addr) constant returns (uint8){
return prescriptions[_prescription_addr].density;
}
function getPatient(bytes32 _prescription_addr) constant returns (address){
return prescriptions[_prescription_addr].patient;
}
function getDistributed(bytes32 _prescription_addr) constant returns (bool){
return prescriptions[_prescription_addr].distributed;
}
function getPrescriptionName(bytes32 _prescription_addr) constant returns(string){
return prescriptions[_prescription_addr].name;
}
function getPrescriptionDOI(bytes32 _prescription_addr) constant returns(string){
return prescriptions[_prescription_addr].doi;
}
struct Patient{
string name;
bool registered;
uint256 prescription_count;
//maps index to prescription hashes
mapping(uint256 => bytes32) prescriptions;
}
mapping(address => Patient) public patients;
function registerPatient(address _patientAddress, string _name){
patients[_patientAddress] = Patient({name: _name, registered: true, prescription_count: 0});
}
//WORKS
function getPatientName(address _address) constant returns(string){
return patients[_address].name;
}
//WORKS
function getPatientRegistered(address _address) constant returns(bool){
return patients[_address].registered;
}
//Works
function getPrescriptionCount(address _address) constant returns(uint256){
return patients[_address].prescription_count;
}
//Works
function getPatientPrescriptionCapsules(address _address, uint256 _num) constant returns(uint8){
return getCapsules(patients[_address].prescriptions[_num]);
}
//Works
function getPatientPrescriptionDensity(address _address, uint256 _num) constant returns(uint8){
return getDensity(patients[_address].prescriptions[_num]);
}
function getPatientPrescriptionName(address _address, uint256 _num) constant returns(string){
return getPrescriptionName(patients[_address].prescriptions[_num]);
}
function getPatientPrescriptionDOI(address _address, uint256 _num) constant returns(string){
return getPrescriptionDOI(patients[_address].prescriptions[_num]);
}
//Works
function getPatientLatestPrescriptionHash(address _address) constant returns (bytes32){
return patients[_address].prescriptions[patients[_address].prescription_count];
}
}