我想在患者和医生之间创建一份合同,其中第一名患者填写他的详细信息,如姓名,年龄和他所面临的问题。填充上述详细信息后,会立即调用function createDoctor()
并将name, age and problems
作为参数发送给Doctor。考虑到患者填写的详细信息,医生会设置医生并更新患者面临的问题(如果有的话)。但我无法弄清楚实施上述声明的方法。以下是我询问患者详细信息并将其发送给医生的代码。现在我无法实现Doctor部分。以下是代码:
Patient.sol
pragma solidity ^0.4.6;
import './Doctor.sol';
contract Patient {
bytes private name = "";
bytes private dateOfBirth="NA";
bytes private problemFaced = "";
address public myDoctor;
// Event that is fired when patient is changed
event patientChanged(string whatChanged);
function createDoctor() public {
myDoctor = new Doctor(getName(), getDateOfBirth(), getGender(), problemFaced);
}
function ProblemFaced(string problems) public {
problemFaced = bytes(problems);
}
function getName() internal view returns (bytes) {
return name; // First_Name Last_Name
}
function getDateOfBirth() internal view returns (bytes) {
return dateOfBirth; // YYYYMMDD
}
function setName(string _name) public {
name = bytes(_name); // First_Name Last_Name
emit patientChanged("name changed"); // fire the event
}
function setDateOfBirth(string _dateOfBirth) public {
dateOfBirth = bytes(_dateOfBirth); // YYYYMMDD
emit patientChanged("dateOfBirth changed"); // fire the event
}
}
Doctor.sol
pragma solidity ^0.4.6;
contract Doctor {
// the address of the owner (the patient)
address public owner;
uint balance;
// address of physician that can add allergies
string public physician;
// name of the patient LAST^FIRST
string public patient_name;
string public patient_dob;
string public patient_gender;
string public patient_problem = '';
modifier isOwnerPatient {
require(msg.sender == owner);
_;
}
function Doctor(bytes _name, bytes _dob, bytes _gender, bytes _problems) {
owner = msg.sender;
patient_name = string(_name);
patient_dob = string(_dob);
patient_gender = string(_gender);
patient_problem = string(_problems);
}
function updateProblem(bytes _condition) {
patient_problem = strConcat(patient_problem, string(_condition));
}
// allows owner to set the physician that can add allergies
function SetPhysician(string _physician) isOwnerPatient {
physician = _physician;
}
function strConcat(string _a, string _b) internal pure returns (string){
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
string memory abcde = new string(_ba.length + 2 + _bb.length);
delete abcde;
bytes memory babcde = bytes(abcde);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
babcde[k++] = ",";
babcde[k++] = " ";
for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
return string(babcde);
}
}
在执行上述问题陈述时是否有可能使用所有者和msg.sender。