Skip to content

Instantly share code, notes, and snippets.

@fabdarice
Created February 27, 2018 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fabdarice/fa7fe25690eb619e86f1197fedd29983 to your computer and use it in GitHub Desktop.
Save fabdarice/fa7fe25690eb619e86f1197fedd29983 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.17;
import './MedicalRecord.sol';
contract Hospital {
MedicalRecord public medicalRecord;
struct Patient {
bytes32 fullName;
bool access;
}
mapping(bytes32 => Patient) patients;
modifier onlyIfGrantedAccess(bytes32 _fullName) {
require(patients[_fullName].access);
_;
}
function Hospital(address _contract) public {
medicalRecord = MedicalRecord(_contract);
}
function addPatient(bytes32 _fullName, bool _access) public {
patients[_fullName].fullName = _fullName;
patients[_fullName].access = _access;
}
function enterHospital(bytes32 _fullName) public {
medicalRecord.addAdmissionRecord(_fullName);
}
function leaveHospital(bytes32 _fullName) public {
medicalRecord.addDischargeRecord(_fullName);
}
function patientExist(bytes32 _fullName)
onlyIfGrantedAccess(_fullName)
view public returns (bool) {
return medicalRecord.recordExist(_fullName);
}
}
pragma solidity ^0.4.17;
contract MedicalRecord {
enum Symptoms {ChestPain, HeadAche, Vomiting, Sprain, Fractures}
struct Visit {
Symptoms symptoms;
uint256 admissionDate;
uint256 dischargeDate;
}
mapping(address => mapping(bytes32 => Visit)) visits;
function addAdmissionRecord(bytes32 _fullName, Symptoms _symptoms) external {
visits[msg.sender][_fullName].symptoms = _symptoms;
visits[msg.sender][_fullName].admissionDate = now;
}
function addDischargeRecord(bytes32 _fullName) external {
visits[msg.sender][_fullName].dischargeDate = now;
}
function recordExist(bytes32 _fullName) view external returns (bool) {
return visits[msg.sender][_fullName].admissionDate != 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment