Last active
November 6, 2018 08:50
-
-
Save dracula92107/fadba3e1fbb6da677646d9d096824ae6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
pragma experimental ABIEncoderV2; | |
contract Hospital { | |
string name; | |
Receipt[] public receipts; | |
constructor (string _name) public payable{ | |
name = _name; | |
} | |
function add(Receipt newReceipt) public { | |
receipts.push(newReceipt); | |
} | |
function verify (Receipt verifyingReceipt) public returns (bool) { | |
for (uint256 i = 0; i < receipts.length; i++) { | |
if (receipts[i] == verifyingReceipt) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
contract Receipt { | |
string examination; | |
string treatment; | |
uint256 cost; | |
int id; | |
address patient; | |
constructor(uint256 _cost, string _examination, string _treatment, address _patient) public payable { | |
cost = _cost; | |
examination = _examination; | |
treatment = _treatment; | |
id = 1; | |
patient = _patient; | |
} | |
function getPatientAddress() public returns (address) { | |
return patient; | |
} | |
function getCost() public returns (uint256) { | |
return cost; | |
} | |
} | |
contract Claim { | |
Receipt receipt; | |
string status; | |
constructor(Receipt patientReceipt, string _status) public payable{ | |
receipt = patientReceipt; | |
status = _status; | |
} | |
function updateStatus(string _status) public { | |
status = _status; | |
} | |
function getReceipt() public returns(Receipt) { | |
return receipt; | |
} | |
function getStatus() public returns(string) { | |
return status; | |
} | |
} | |
contract Patient { | |
string name; | |
//InsuranceCompany insuranceCompany; | |
constructor(string _name) public payable{ | |
name = _name; | |
} | |
function requestReceipt(Receipt _receipt, InsuranceCompany insuranceCompany) public { | |
// submit claim | |
insuranceCompany.submit(_receipt); | |
} | |
} | |
contract InsuranceCompany { | |
string name; | |
Claim[] public claims; | |
constructor(string _name) public payable { | |
name = _name; | |
} | |
function submit(Receipt _receipt) public { | |
Claim claim = new Claim(_receipt, "pending"); | |
claims.push(claim); | |
} | |
function loadAllPendingClaims() public returns(Claim[] claims) { | |
Claim[] result; | |
for (uint256 i = 0; i < claims.length; i++) { | |
if (keccak256(claims[i].getStatus()) == keccak256("pending")) { | |
result.push(claims[i]); | |
} | |
} | |
return (result); | |
} | |
function verify(Hospital hospital, Receipt receipt) public payable returns (bool){ | |
Claim newClaim = new Claim(receipt, "pending"); | |
if(hospital.verify(newClaim.getReceipt()) == true) { | |
newClaim.updateStatus("Approved"); | |
receipt.getPatientAddress().transfer(receipt.getCost()); | |
return true; | |
} else { | |
newClaim.updateStatus("Reject"); | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment