-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEmrify.sol
204 lines (194 loc) · 7.78 KB
/
Emrify.sol
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
contract Emrify {
address public owner ;
string public name;//5
mapping (address => uint256) public individualCount;
struct AllHash{
string AllergiesHash;//1 already present
string MedicationHash;//2
string ProcedureHash;//3
string FITBITHash;//4
string AccountHash;//5
}
struct RestrictedAccessUser{
bool isAllergiesShared;
bool isMedicationShared;
bool isProcedureShared;
bool isFITBITShared;
bool isNameAllowed;
bool isAccountHash;
}
mapping(address => mapping ( address => RestrictedAccessUser)) public permission;
mapping(address => string) public resAccUserName;
mapping(address => AllHash) public AllRecordHashes;
mapping(address => mapping ( uint256 =>string)) public notes ;
event DocAdded(address indexed provider, address indexed patient, string msg, string attachmentHash, string textHash );
function Emrify(){
owner = msg.sender; // Entity X is the owner of the contract
permission[owner][owner].isAllergiesShared = true;
permission[owner][owner].isMedicationShared = true;
permission[owner][owner].isProcedureShared = true;
permission[owner][owner].isFITBITShared = true;
permission[owner][owner].isAccountHash = true;
}
function setName( string _name ){
resAccUserName[msg.sender]=_name;
permission[msg.sender][msg.sender].isNameAllowed == true;
}
function setNamePerm(address _address, bool nameToggle){
permission[msg.sender][_address].isNameAllowed = nameToggle;
}
// this address here shall come after pop-up or alert
// here user shall choose, whether they want
function getName (address _address) constant returns (string ) {
if(permission[msg.sender][_address].isNameAllowed == true ){
return resAccUserName[msg.sender];
}
else {
return "not allowed";
}
}
// for his own name.
function getName() constant returns (string ) {
return resAccUserName[msg.sender];
}
function returnOwner() constant returns (address){
return owner;
}
function returnReqmaker() constant returns (address){
return msg.sender;
}
//1 setter calls
// anyone should be able to put the record on the BC
// information shall be recorded for SELF
function setPatientHashes( string _AllergiesHash,
string _MedicationHash,
string _ProcedureHash,
string _FITBITHash){
AllRecordHashes[msg.sender].AllergiesHash =_AllergiesHash;
AllRecordHashes[msg.sender].MedicationHash =_MedicationHash;
AllRecordHashes[msg.sender].ProcedureHash =_ProcedureHash;
AllRecordHashes[msg.sender].FITBITHash =_FITBITHash;
}
function setAccount(string _AccountHash){
AllRecordHashes[msg.sender].AccountHash =_AccountHash;
permission[msg.sender][msg.sender].isAccountHash = true;
permission[msg.sender][msg.sender].isAllergiesShared = true;
permission[msg.sender][msg.sender].isMedicationShared = true;
permission[msg.sender][msg.sender].isProcedureShared = true;
permission[msg.sender][msg.sender].isFITBITShared = true;
}
function getAccount() constant returns (string ) {
return AllRecordHashes[msg.sender].AccountHash;
}
//1 permission call
// this shall be called by patient
// so a permission must exist between a patient and a provider in question
function SharePermission(bool isAccount, bool isAllergies, bool isMedication,
bool isProcedure, bool isFITBIT, address DrAddress ){
permission[msg.sender][DrAddress].isAccountHash = isAccount;
permission[msg.sender][DrAddress].isAllergiesShared = isAllergies;
permission[msg.sender][DrAddress].isMedicationShared = isMedication;
permission[msg.sender][DrAddress].isProcedureShared = isProcedure;
permission[msg.sender][DrAddress].isFITBITShared = isFITBIT;
}
// 4 getter caller as per the on-chain permission to check
// wheter the permission are correctly set or not
function getBoolAllergies (address patient,address DrAddress) constant returns (bool){
if (permission[patient][DrAddress].isAllergiesShared == true){
return true;
}
else{
return false;
}
}
function getBoolMedication (address patient, address DrAddress) constant returns (bool){
if ( permission[patient][DrAddress].isMedicationShared == true){
return true;
}
else{
return false;
}
}
function getBoolProcedure (address patient, address DrAddress) constant returns (bool){
if (permission[patient][DrAddress].isProcedureShared == true){
return true;
}
else{
return false;
}
}
function getBoolFITBIT (address patient, address DrAddress) constant returns (bool){
if ( permission[patient][DrAddress].isFITBITShared == true){
return true;
}
else{
return false;
}
}
function getBoolAccount (address patient,address DrAddress) constant returns (bool){
if (permission[patient][DrAddress].isAccountHash == true){
return true;
}
else{
return false;
}
}
// 4 getter caller as per the on-chain permission to get the data stored
// reason for these many getMethod calls is that,
// currently solidity doesn't support return of array of string data type
//http://solidity.readthedocs.io/en/develop/frequently-asked-questions.html#is-it-possible-to-return-an-array-of-strings-string-from-a-solidity-function
// this shall be called by doctor. so the permission must exist between the patient
// and the doctor. Doctor shall call these 4 methods
// No third person other than the PERMISSIONED address can see this data
function getAllergies (address patient) constant returns (string ) {
if(permission[patient][msg.sender].isAllergiesShared == true ){
return AllRecordHashes[patient].AllergiesHash;
}
else {
return "not allowed";
}
}
function getMedication (address patient) constant returns (string ) {
if(permission[patient][msg.sender].isMedicationShared == true){
return AllRecordHashes[patient].MedicationHash;
}
else {
return "not allowed";
}
}
function getProcedure (address patient) constant returns (string ) {
if(permission[patient][msg.sender].isProcedureShared == true){
return AllRecordHashes[patient].ProcedureHash;
}
else {
return "not allowed";
}
}
function getFITBIT (address patient) constant returns (string ) {
if(permission[patient][msg.sender].isFITBITShared == true){
return AllRecordHashes[patient].FITBITHash;
}
else {
return "not allowed";
}
}
function getAccountReqFromProvider (address patient) constant returns (string ) {
if(permission[patient][msg.sender].isAccountHash == true){
return AllRecordHashes[patient].AccountHash;
}
else {
return "not allowed";
}
}
function providerNotes(string _AttachmentHash,string _TextHash,address patient, string _tag){
notes[patient][individualCount[patient]++]= _AttachmentHash;
notes[patient][individualCount[patient]++]= _TextHash;
DocAdded(msg.sender, patient, _tag ,_AttachmentHash,_TextHash);
}
function getIndividualCount() constant returns ( uint256 ){
return individualCount[msg.sender];
}
function fetchRecordsbyID(uint256 id)constant returns (string){
return notes[msg.sender][id];
}
}