This is the link of oneclickapp which is working https://oneclickdapp.com/center-east/.
This is Link of Contract:https://rinkeby.etherscan.io/address/0x33febb8f192941a87d87ef70cc5f4427c44bf29e#code
Contract Source Code:
contract Patient is Hospital{
uint256 public pindex=0;
struct Records {
string hname;
string reason;
string admittedOn;
string dischargedOn;
string ipfs;
}
struct patient{
uint256 id;
string name;
string phone;
string gender;
string dob;
string bloodgroup;
string allergies;
Records[] records;
address addr;
}
address[] private patientList;
mapping(address=>mapping(address=>bool)) isAuth;
mapping(address=>patient) patients;
mapping(address=>bool) isPatient;
function addRecord(address _addr,string memory _hname,string memory _reason,string memory _admittedOn,string memory _dischargedOn,string memory _ipfs) public{
require(isPatient[_addr],"User Not registered");
require(isAuth[_addr][msg.sender],"No permission to add Records");
patients[_addr].records.push(Records(_hname,_reason,_admittedOn,_dischargedOn,_ipfs));
}
function addPatient(string memory _name,string memory _phone,string memory _gender,string memory _dob,string memory _bloodgroup,string memory _allergies) public {
require(!isPatient[msg.sender],"Already Patient account exists");
patientList.push(msg.sender);
pindex = pindex + 1;
isPatient[msg.sender]=true;
isAuth[msg.sender][msg.sender]=true;
patients[msg.sender].id=pindex;
patients[msg.sender].name=_name;
patients[msg.sender].phone=_phone;
patients[msg.sender].gender=_gender;
patients[msg.sender].dob=_dob;
patients[msg.sender].bloodgroup=_bloodgroup;
patients[msg.sender].allergies=_allergies;
patients[msg.sender].addr=msg.sender;
}
function getPatientDetails(address _addr) public view returns(string memory _name,string memory _phone,string memory _gender,string memory _dob,string memory _bloodgroup,string memory _allergies){
require(isAuth[_addr][msg.sender],"No permission to get Records");
require(isPatient[_addr],"No Patients found at the given address");
patient memory tmp = patients[_addr];
return (tmp.name,tmp.phone,tmp.gender,tmp.dob,tmp.bloodgroup,tmp.allergies);
}
function getPatientRecords(address _addr) public view returns(string[] memory _hname,string[] memory _reason,string[] memory _admittedOn,string[] memory _dischargedOn,string[] memory ipfs){
require(isAuth[_addr][msg.sender],"No permission to get Records");
require(isPatient[_addr],"patient not signed in to our network");
require(patients[_addr].records.length>0,"patient record doesn't exist");
string[] memory Hname = new string[](patients[_addr].records.length);
string[] memory Reason = new string[](patients[_addr].records.length);
string[] memory AdmOn = new string[](patients[_addr].records.length);
string[] memory DisOn = new string[](patients[_addr].records.length);
string[] memory IPFS = new string[](patients[_addr].records.length);
for(uint256 i=0;i<patients[_addr].records.length;i++){
Hname[i]=patients[_addr].records[i].hname;
Reason[i]=patients[_addr].records[i].reason;
AdmOn[i]=patients[_addr].records[i].admittedOn;
DisOn[i]=patients[_addr].records[i].dischargedOn;
IPFS[i]=patients[_addr].records[i].ipfs;
}
return(Hname,Reason,AdmOn,DisOn,IPFS);
}
function addAuth(address _addr) public returns(bool success) {
require(!isAuth[msg.sender][_addr],"Already Authorised");
require(msg.sender!=_addr,"Cant add yourself");
isAuth[msg.sender][_addr] = true;
return true;
}
function revokeAuth(address _addr) public returns(bool success) {
require(msg.sender!=_addr,"Cant remove yourself");
require(isAuth[msg.sender][_addr],"Already Not Authorised");
isAuth[msg.sender][_addr] = false;
return true;
}
function addAuthFromTo(address _from,address _to) public returns(bool success) {
require(!isAuth[_from][_to],"Already Auth!!!");
require(_from!=_to,"can't add same person");
require(isAuth[_from][msg.sender],"You don't have permission to access");
require(isPatient[_from],"User Not Registered yet");
isAuth[_from][_to] = true;
return true;
}
function removeAuthFromTo(address _from,address _to) public returns(bool success) {
require(isAuth[_from][_to],"Already No Auth!!!");
require(_from!=_to,"can't remove same person");
require(isAuth[_from][msg.sender],"You don't have permission to access");
require(isPatient[_from],"User Not Registered yet");
isAuth[_from][_to] = false;
return true;
}
}
My own ReactJs code:
try{
await this.DMR.methods.getPatientDetails(this.state.account).call().then((res)=>{
let result = res;
console.log(result);
});
}
catch(e){
await this.setState({load:false});
console.log(e);
}
Instructions to test functionality:
First You need to create Patient using addPatient function,You can use above oneclickapp link to create patient.
Then use getPatientDetails function to get patient info(should be your own address through which you created patient),You can view your details in oneclick app.
Using the oneclickapp works fine,but my own web3 source code:
Gives me Error:
Error: overflow (fault="overflow", operation="toNumber", value="3963877391197344453575983046348115674221700746820753546331534351508065746944", code=NUMERIC_FAULT, version=bignumber/5.0.7)
I don't understand why overflow occurs as the function returns all string.
Note: DMR is my contract instance which is working fine as I am able to get other functions correctly.
You shouldn't mix promise constructs together (async/await vs .then), as to the direct issue do you mind dumping the full stack trace?